Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Storage functions for the migration phases #6529

Merged
merged 10 commits into from
Jan 24, 2022
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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