CloudMigrations: Remove unused code from sync migration approach (#94016)
This commit is contained in:
@@ -8,7 +8,6 @@ import (
|
|||||||
|
|
||||||
type Client interface {
|
type Client interface {
|
||||||
ValidateKey(context.Context, cloudmigration.CloudMigrationSession) error
|
ValidateKey(context.Context, cloudmigration.CloudMigrationSession) error
|
||||||
MigrateData(context.Context, cloudmigration.CloudMigrationSession, cloudmigration.MigrateDataRequest) (*cloudmigration.MigrateDataResponse, error)
|
|
||||||
StartSnapshot(context.Context, cloudmigration.CloudMigrationSession) (*cloudmigration.StartSnapshotResponse, error)
|
StartSnapshot(context.Context, cloudmigration.CloudMigrationSession) (*cloudmigration.StartSnapshotResponse, error)
|
||||||
GetSnapshotStatus(context.Context, cloudmigration.CloudMigrationSession, cloudmigration.CloudMigrationSnapshot, int) (*cloudmigration.GetSnapshotStatusResponse, error)
|
GetSnapshotStatus(context.Context, cloudmigration.CloudMigrationSession, cloudmigration.CloudMigrationSnapshot, int) (*cloudmigration.GetSnapshotStatusResponse, error)
|
||||||
CreatePresignedUploadUrl(context.Context, cloudmigration.CloudMigrationSession, cloudmigration.CloudMigrationSnapshot) (string, error)
|
CreatePresignedUploadUrl(context.Context, cloudmigration.CloudMigrationSession, cloudmigration.CloudMigrationSnapshot) (string, error)
|
||||||
|
|||||||
@@ -71,52 +71,6 @@ func (c *gmsClientImpl) ValidateKey(ctx context.Context, cm cloudmigration.Cloud
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated
|
|
||||||
func (c *gmsClientImpl) MigrateData(ctx context.Context, cm cloudmigration.CloudMigrationSession, request cloudmigration.MigrateDataRequest) (result *cloudmigration.MigrateDataResponse, err error) {
|
|
||||||
path := fmt.Sprintf("%s/api/v1/migrate-data", c.buildBasePath(cm.ClusterSlug))
|
|
||||||
|
|
||||||
reqDTO := convertRequestToDTO(request)
|
|
||||||
body, err := json.Marshal(reqDTO)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("error marshaling request: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send the request to GMS with the associated auth token
|
|
||||||
req, err := http.NewRequest(http.MethodPost, path, bytes.NewReader(body))
|
|
||||||
if err != nil {
|
|
||||||
c.log.Error("error creating http request for cloud migration run", "err", err.Error())
|
|
||||||
return nil, fmt.Errorf("http request error: %w", err)
|
|
||||||
}
|
|
||||||
req.Header.Set("Content-Type", "application/json")
|
|
||||||
req.Header.Set("Authorization", fmt.Sprintf("Bearer %d:%s", cm.StackID, cm.AuthToken))
|
|
||||||
|
|
||||||
client := &http.Client{}
|
|
||||||
resp, err := client.Do(req)
|
|
||||||
if err != nil {
|
|
||||||
c.log.Error("error sending http request for cloud migration run", "err", err.Error())
|
|
||||||
return nil, fmt.Errorf("http request error: %w", err)
|
|
||||||
}
|
|
||||||
defer func() {
|
|
||||||
if closeErr := resp.Body.Close(); closeErr != nil {
|
|
||||||
err = errors.Join(err, fmt.Errorf("closing response body: %w", closeErr))
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
if resp.StatusCode >= 400 {
|
|
||||||
c.log.Error("received error response for cloud migration run", "statusCode", resp.StatusCode)
|
|
||||||
return nil, fmt.Errorf("http request error: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
var respDTO MigrateDataResponseDTO
|
|
||||||
if err := json.NewDecoder(resp.Body).Decode(&respDTO); err != nil {
|
|
||||||
c.log.Error("unmarshalling response body", "err", err.Error())
|
|
||||||
return nil, fmt.Errorf("unmarshalling migration run response: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
res := convertResponseFromDTO(respDTO)
|
|
||||||
return &res, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *gmsClientImpl) StartSnapshot(ctx context.Context, session cloudmigration.CloudMigrationSession) (out *cloudmigration.StartSnapshotResponse, err error) {
|
func (c *gmsClientImpl) StartSnapshot(ctx context.Context, session cloudmigration.CloudMigrationSession) (out *cloudmigration.StartSnapshotResponse, err error) {
|
||||||
path := fmt.Sprintf("%s/api/v1/start-snapshot", c.buildBasePath(session.ClusterSlug))
|
path := fmt.Sprintf("%s/api/v1/start-snapshot", c.buildBasePath(session.ClusterSlug))
|
||||||
|
|
||||||
@@ -302,37 +256,3 @@ func (c *gmsClientImpl) buildBasePath(clusterSlug string) string {
|
|||||||
}
|
}
|
||||||
return fmt.Sprintf("https://cms-%s.%s/cloud-migrations", clusterSlug, domain)
|
return fmt.Sprintf("https://cms-%s.%s/cloud-migrations", clusterSlug, domain)
|
||||||
}
|
}
|
||||||
|
|
||||||
func convertRequestToDTO(request cloudmigration.MigrateDataRequest) MigrateDataRequestDTO {
|
|
||||||
items := make([]MigrateDataRequestItemDTO, len(request.Items))
|
|
||||||
for i := 0; i < len(request.Items); i++ {
|
|
||||||
item := request.Items[i]
|
|
||||||
items[i] = MigrateDataRequestItemDTO{
|
|
||||||
Type: MigrateDataType(item.Type),
|
|
||||||
RefID: item.RefID,
|
|
||||||
Name: item.Name,
|
|
||||||
Data: item.Data,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
r := MigrateDataRequestDTO{
|
|
||||||
Items: items,
|
|
||||||
}
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
func convertResponseFromDTO(result MigrateDataResponseDTO) cloudmigration.MigrateDataResponse {
|
|
||||||
items := make([]cloudmigration.CloudMigrationResource, len(result.Items))
|
|
||||||
for i := 0; i < len(result.Items); i++ {
|
|
||||||
item := result.Items[i]
|
|
||||||
items[i] = cloudmigration.CloudMigrationResource{
|
|
||||||
Type: cloudmigration.MigrateDataType(item.Type),
|
|
||||||
RefID: item.RefID,
|
|
||||||
Status: cloudmigration.ItemStatus(item.Status),
|
|
||||||
Error: item.Error,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return cloudmigration.MigrateDataResponse{
|
|
||||||
RunUID: result.RunUID,
|
|
||||||
Items: items,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user