Skip to content

Commit

Permalink
Storage functions for the migration phases (#6529)
Browse files Browse the repository at this point in the history
* Get organisation API changes added

Signed-off-by: sonali wale <sonali.wale@progress.com>

* minor changes added

Signed-off-by: sonali wale <sonali.wale@progress.com>

* Remove command to create an orgs

Signed-off-by: sonali wale <sonali.wale@progress.com>

* Client Mock changes

Signed-off-by: Yashvi Jain <Yashvi.jain@progress.com>

* Storage function for all the phases of migration

Signed-off-by: sonali wale <sonali.wale@progress.com>

* Minor changes added

Signed-off-by: sonali wale <sonali.wale@progress.com>

* Incorporated review comments

Signed-off-by: sonali wale <sonali.wale@progress.com>

* Minor changes added

Signed-off-by: sonali wale <sonali.wale@progress.com>

* Changes for review comments

Signed-off-by: sonali wale <sonali.wale@progress.com>

* Comments removed

Signed-off-by: sonali wale <sonali.wale@progress.com>

Co-authored-by: Yashvi Jain <Yashvi.jain@progress.com>
  • Loading branch information
2 people authored and vinay033 committed Apr 19, 2022
1 parent 9c32a64 commit 6e0bfa9
Show file tree
Hide file tree
Showing 16 changed files with 495 additions and 137 deletions.
9 changes: 3 additions & 6 deletions api/external/infra_proxy/infra_proxy.swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

73 changes: 35 additions & 38 deletions api/external/infra_proxy/response/orgs.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions api/external/infra_proxy/response/orgs.proto
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ message GetOrg {
}

message GetInfraServerOrgs {
// Chef organization list from chef server
repeated Org orgs = 1;
// id of organisation migration
string migration_id = 1;
}

message Org {
Expand Down
75 changes: 36 additions & 39 deletions api/interservice/infra_proxy/response/orgs.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions api/interservice/infra_proxy/response/orgs.proto
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ message GetOrg {
}

message GetInfraServerOrgs {
// Chef organization list from chef server
repeated Org orgs = 1;
// id of organisation migration
string migration_id = 1;
}

message Org {
Expand Down
9 changes: 3 additions & 6 deletions components/automate-gateway/api/infra_proxy.pb.swagger.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion components/automate-gateway/handler/infra_proxy/orgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (c *InfraProxyServer) GetInfraServerOrgs(ctx context.Context, r *gwreq.GetI
return nil, err
}
return &gwres.GetInfraServerOrgs{
Orgs: fromUpstreamOrgs(res.Orgs),
MigrationId: res.MigrationId,
}, nil
}
func fromUpstreamOrg(t *infra_res.Org) *gwres.Org {
Expand Down
42 changes: 42 additions & 0 deletions components/infra-proxy-service/constants/constants.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,48 @@
package constants

// MigrationPhase: enum of migration phases
type MigrationPhase int64

// Migration phases id should be between 100 & 5000
const (
StartMigration = 100
CompleteMigration = 5000
)

// MigrationStatus: enum of migration status
type MigrationStatus int64

// IAM default project ID
const (
UnassignedProjectID = "(unassigned)"
)

const (
StartFileUpload MigrationPhase = iota + 1000
CompleteFileUpload
FailedFileUpload
StartUnzip
ComplteUnzip
FailedUnzip
StartZipParsing
CompleteZipParsing
FailedZipParsing
StartOrgMigration
CompleteOrgMigration
FailedOrgMigration
StartUserMigration
CompleteUserMigration
FailedUserMigration
StartAssciation
CompleteAssciation
FailedAssciation
StartPermissionMigration
CompletePermissionMigration
FailedPermissionMigration
)

const (
InProgress MigrationStatus = iota + 100
Completed
Failed
)
38 changes: 38 additions & 0 deletions components/infra-proxy-service/server/migration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package server

import (
"context"
"errors"

secrets "github.com/chef/automate/api/external/secrets"
"github.com/chef/automate/components/infra-proxy-service/service"
)

var IsMigrationAlreadyRunning bool

func setMigrationStatus(status bool) {
IsMigrationAlreadyRunning = status
}

// getChefClient: creates the chef client
func (s *Server) getChefClient(ctx context.Context, serverId string) (*ChefClient, error) {
// Get the credential ID from servers table
server, err := s.service.Storage.GetServer(ctx, serverId)
if err != nil {
return nil, service.ParseStorageError(err, serverId, "server")
}
if server.CredentialID == "" {
return nil, errors.New("webui key is not available with server")
}
// Get web ui key from secrets service
secret, err := s.service.Secrets.Read(ctx, &secrets.Id{Id: server.CredentialID})
if err != nil {
return nil, err
}

c, err := s.createChefServerClient(ctx, serverId, GetAdminKeyFrom(secret), "pivotal", true)
if err != nil {
return nil, err
}
return c, nil
}
Loading

0 comments on commit 6e0bfa9

Please sign in to comment.