Cloudmigration: Sets the runID correctly when saving (#85661)

Sets the runID correctly instead of setting it to the same as the migration id.
This commit is contained in:
Leonard Gram 2024-04-05 18:03:45 +02:00 committed by GitHub
parent 58f32150c2
commit 1332d8ba24
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 10 additions and 8 deletions

View File

@ -199,7 +199,7 @@ func (cma *CloudMigrationAPI) RunMigration(c *contextmodel.ReqContext) response.
return response.Error(http.StatusInternalServerError, "migration data get error", err) return response.Error(http.StatusInternalServerError, "migration data get error", err)
} }
req, err := http.NewRequest("POST", path, bytes.NewReader(body)) req, err := http.NewRequest(http.MethodPost, path, bytes.NewReader(body))
if err != nil { if err != nil {
cma.log.Error("error creating http request for cloud migration run", "err", err.Error()) cma.log.Error("error creating http request for cloud migration run", "err", err.Error())
return response.Error(http.StatusInternalServerError, "http request error", err) return response.Error(http.StatusInternalServerError, "http request error", err)
@ -235,7 +235,7 @@ func (cma *CloudMigrationAPI) RunMigration(c *contextmodel.ReqContext) response.
return response.Error(http.StatusInternalServerError, "unmarshalling migration run response", err) return response.Error(http.StatusInternalServerError, "unmarshalling migration run response", err)
} }
_, err = cma.cloudMigrationService.SaveMigrationRun(ctx, &cloudmigration.CloudMigrationRun{ runID, err := cma.cloudMigrationService.SaveMigrationRun(ctx, &cloudmigration.CloudMigrationRun{
CloudMigrationUID: stringID, CloudMigrationUID: stringID,
Result: respData, Result: respData,
}) })
@ -243,6 +243,8 @@ func (cma *CloudMigrationAPI) RunMigration(c *contextmodel.ReqContext) response.
response.Error(http.StatusInternalServerError, "migration run save error", err) response.Error(http.StatusInternalServerError, "migration run save error", err)
} }
result.RunID = runID
return response.JSON(http.StatusOK, result) return response.JSON(http.StatusOK, result)
} }

View File

@ -16,7 +16,7 @@ type Service interface {
GetMigrationStatus(context.Context, string, string) (*CloudMigrationRun, error) GetMigrationStatus(context.Context, string, string) (*CloudMigrationRun, error)
GetMigrationStatusList(context.Context, string) ([]*CloudMigrationRun, error) GetMigrationStatusList(context.Context, string) ([]*CloudMigrationRun, error)
DeleteMigration(context.Context, int64) (*CloudMigration, error) DeleteMigration(context.Context, int64) (*CloudMigration, error)
SaveMigrationRun(context.Context, *CloudMigrationRun) (string, error) SaveMigrationRun(context.Context, *CloudMigrationRun) (int64, error)
ParseCloudMigrationConfig() (string, error) ParseCloudMigrationConfig() (string, error)
} }

View File

@ -442,16 +442,16 @@ func (s *Service) getDashboards(ctx context.Context, id int64) ([]dashboards.Das
return result, nil return result, nil
} }
func (s *Service) SaveMigrationRun(ctx context.Context, cmr *cloudmigration.CloudMigrationRun) (string, error) { func (s *Service) SaveMigrationRun(ctx context.Context, cmr *cloudmigration.CloudMigrationRun) (int64, error) {
cmr.Created = time.Now() cmr.Created = time.Now()
cmr.Updated = time.Now() cmr.Updated = time.Now()
cmr.Finished = time.Now() cmr.Finished = time.Now()
err := s.store.SaveMigrationRun(ctx, cmr) err := s.store.SaveMigrationRun(ctx, cmr)
if err != nil { if err != nil {
s.log.Error("Failed to save migration run", "err", err) s.log.Error("Failed to save migration run", "err", err)
return "", err return -1, err
} }
return cmr.CloudMigrationUID, nil return cmr.ID, nil
} }
func (s *Service) GetMigrationStatus(ctx context.Context, id string, runID string) (*cloudmigration.CloudMigrationRun, error) { func (s *Service) GetMigrationStatus(ctx context.Context, id string, runID string) (*cloudmigration.CloudMigrationRun, error) {

View File

@ -50,8 +50,8 @@ func (s *NoopServiceImpl) DeleteMigration(ctx context.Context, id int64) (*cloud
return nil, cloudmigration.ErrFeatureDisabledError return nil, cloudmigration.ErrFeatureDisabledError
} }
func (s *NoopServiceImpl) SaveMigrationRun(ctx context.Context, cmr *cloudmigration.CloudMigrationRun) (string, error) { func (s *NoopServiceImpl) SaveMigrationRun(ctx context.Context, cmr *cloudmigration.CloudMigrationRun) (int64, error) {
return "", cloudmigration.ErrInternalNotImplementedError return -1, cloudmigration.ErrInternalNotImplementedError
} }
func (s *NoopServiceImpl) GetMigrationDataJSON(ctx context.Context, id int64) ([]byte, error) { func (s *NoopServiceImpl) GetMigrationDataJSON(ctx context.Context, id int64) ([]byte, error) {