CloudMigrations: remove unused code from sync migration approach (#93430)
This commit is contained in:
@@ -51,11 +51,6 @@ func (cma *CloudMigrationAPI) registerEndpoints() {
|
||||
cloudMigrationRoute.Get("/migration/:uid", routing.Wrap(cma.GetSession))
|
||||
cloudMigrationRoute.Delete("/migration/:uid", routing.Wrap(cma.DeleteSession))
|
||||
|
||||
// sync approach to data migration
|
||||
cloudMigrationRoute.Post("/migration/:uid/run", routing.Wrap(cma.RunMigration))
|
||||
cloudMigrationRoute.Get("/migration/:uid/run", routing.Wrap(cma.GetMigrationRunList))
|
||||
cloudMigrationRoute.Get("/migration/run/:runUID", routing.Wrap(cma.GetMigrationRun))
|
||||
|
||||
// async approach to data migration using snapshots
|
||||
cloudMigrationRoute.Post("/migration/:uid/snapshot", routing.Wrap(cma.CreateSnapshot))
|
||||
cloudMigrationRoute.Get("/migration/:uid/snapshot/:snapshotUid", routing.Wrap(cma.GetSnapshot))
|
||||
@@ -239,101 +234,6 @@ func (cma *CloudMigrationAPI) CreateSession(c *contextmodel.ReqContext) response
|
||||
})
|
||||
}
|
||||
|
||||
// swagger:route POST /cloudmigration/migration/{uid}/run migrations runCloudMigration
|
||||
//
|
||||
// Trigger the run of a migration to the Grafana Cloud.
|
||||
//
|
||||
// It returns migrations that has been created.
|
||||
//
|
||||
// Responses:
|
||||
// 200: cloudMigrationRunResponse
|
||||
// 400: badRequestError
|
||||
// 401: unauthorisedError
|
||||
// 403: forbiddenError
|
||||
// 500: internalServerError
|
||||
func (cma *CloudMigrationAPI) RunMigration(c *contextmodel.ReqContext) response.Response {
|
||||
ctx, span := cma.tracer.Start(c.Req.Context(), "MigrationAPI.RunMigration")
|
||||
defer span.End()
|
||||
|
||||
uid := web.Params(c.Req)[":uid"]
|
||||
if err := util.ValidateUID(uid); err != nil {
|
||||
return response.ErrOrFallback(http.StatusBadRequest, "invalid migration uid", err)
|
||||
}
|
||||
|
||||
result, err := cma.cloudMigrationService.RunMigration(ctx, uid)
|
||||
if err != nil {
|
||||
return response.ErrOrFallback(http.StatusInternalServerError, "migration run error", err)
|
||||
}
|
||||
|
||||
return response.JSON(http.StatusOK, convertMigrateDataResponseToDTO(*result))
|
||||
}
|
||||
|
||||
// swagger:route GET /cloudmigration/migration/run/{runUID} migrations getCloudMigrationRun
|
||||
//
|
||||
// Get the result of a single migration run.
|
||||
//
|
||||
// Responses:
|
||||
// 200: cloudMigrationRunResponse
|
||||
// 400: badRequestError
|
||||
// 401: unauthorisedError
|
||||
// 403: forbiddenError
|
||||
// 500: internalServerError
|
||||
func (cma *CloudMigrationAPI) GetMigrationRun(c *contextmodel.ReqContext) response.Response {
|
||||
ctx, span := cma.tracer.Start(c.Req.Context(), "MigrationAPI.GetMigrationRun")
|
||||
defer span.End()
|
||||
|
||||
runUid := web.Params(c.Req)[":runUID"]
|
||||
if err := util.ValidateUID(runUid); err != nil {
|
||||
return response.ErrOrFallback(http.StatusBadRequest, "invalid runUID", err)
|
||||
}
|
||||
|
||||
migrationStatus, err := cma.cloudMigrationService.GetMigrationStatus(ctx, runUid)
|
||||
if err != nil {
|
||||
return response.ErrOrFallback(http.StatusInternalServerError, "migration status error", err)
|
||||
}
|
||||
|
||||
result, err := migrationStatus.GetResult()
|
||||
if err != nil {
|
||||
cma.log.Error("could not return migration run", "err", err)
|
||||
return response.Error(http.StatusInternalServerError, "migration run get error", err)
|
||||
}
|
||||
|
||||
return response.JSON(http.StatusOK, convertMigrateDataResponseToDTO(*result))
|
||||
}
|
||||
|
||||
// swagger:route GET /cloudmigration/migration/{uid}/run migrations getCloudMigrationRunList
|
||||
//
|
||||
// Get a list of migration runs for a migration.
|
||||
//
|
||||
// Responses:
|
||||
// 200: cloudMigrationRunListResponse
|
||||
// 400: badRequestError
|
||||
// 401: unauthorisedError
|
||||
// 403: forbiddenError
|
||||
// 500: internalServerError
|
||||
func (cma *CloudMigrationAPI) GetMigrationRunList(c *contextmodel.ReqContext) response.Response {
|
||||
ctx, span := cma.tracer.Start(c.Req.Context(), "MigrationAPI.GetMigrationRunList")
|
||||
defer span.End()
|
||||
|
||||
uid := web.Params(c.Req)[":uid"]
|
||||
if err := util.ValidateUID(uid); err != nil {
|
||||
return response.ErrOrFallback(http.StatusBadRequest, "invalid migration uid", err)
|
||||
}
|
||||
|
||||
runList, err := cma.cloudMigrationService.GetMigrationRunList(ctx, uid)
|
||||
if err != nil {
|
||||
return response.ErrOrFallback(http.StatusInternalServerError, "list migration status error", err)
|
||||
}
|
||||
|
||||
runs := make([]MigrateDataResponseListDTO, len(runList.Runs))
|
||||
for i := 0; i < len(runList.Runs); i++ {
|
||||
runs[i] = MigrateDataResponseListDTO{runList.Runs[i].RunUID}
|
||||
}
|
||||
return response.JSON(http.StatusOK, CloudMigrationRunListDTO{
|
||||
Runs: runs,
|
||||
})
|
||||
}
|
||||
|
||||
// swagger:route DELETE /cloudmigration/migration/{uid} migrations deleteSession
|
||||
//
|
||||
// Delete a migration session by its uid.
|
||||
|
||||
@@ -253,132 +253,6 @@ func TestCloudMigrationAPI_CreateMigration(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCloudMigrationAPI_RunMigration(t *testing.T) {
|
||||
tests := []TestCase{
|
||||
{
|
||||
desc: "should return 200 if everything is ok",
|
||||
requestHttpMethod: http.MethodPost,
|
||||
requestUrl: "/api/cloudmigration/migration/1234/run",
|
||||
basicRole: org.RoleAdmin,
|
||||
expectedHttpResult: http.StatusOK,
|
||||
expectedBody: `{"uid":"fake_uid","items":[{"type":"type","refId":"make_refid","status":"ok","message":"none"}]}`,
|
||||
},
|
||||
{
|
||||
desc: "should return 403 if no used is not admin",
|
||||
requestHttpMethod: http.MethodPost,
|
||||
requestUrl: "/api/cloudmigration/migration/1234/run",
|
||||
basicRole: org.RoleEditor,
|
||||
expectedHttpResult: http.StatusForbidden,
|
||||
expectedBody: "",
|
||||
},
|
||||
{
|
||||
desc: "should return 500 if service returns an error",
|
||||
requestHttpMethod: http.MethodPost,
|
||||
requestUrl: "/api/cloudmigration/migration/1234/run",
|
||||
basicRole: org.RoleAdmin,
|
||||
serviceReturnError: true,
|
||||
expectedHttpResult: http.StatusInternalServerError,
|
||||
expectedBody: "",
|
||||
},
|
||||
{
|
||||
desc: "should return 400 if uid is invalid",
|
||||
requestHttpMethod: http.MethodPost,
|
||||
requestUrl: "/api/cloudmigration/migration/***/run",
|
||||
basicRole: org.RoleAdmin,
|
||||
serviceReturnError: true,
|
||||
expectedHttpResult: http.StatusBadRequest,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.desc, runSimpleApiTest(tt))
|
||||
}
|
||||
}
|
||||
|
||||
func TestCloudMigrationAPI_GetMigrationRun(t *testing.T) {
|
||||
tests := []TestCase{
|
||||
{
|
||||
desc: "should return 200 if everything is ok",
|
||||
requestHttpMethod: http.MethodGet,
|
||||
requestUrl: "/api/cloudmigration/migration/run/1234",
|
||||
basicRole: org.RoleAdmin,
|
||||
expectedHttpResult: http.StatusOK,
|
||||
expectedBody: `{"uid":"fake_uid","items":[{"type":"type","refId":"make_refid","status":"ok","message":"none"}]}`,
|
||||
},
|
||||
{
|
||||
desc: "should return 403 if no used is not admin",
|
||||
requestHttpMethod: http.MethodGet,
|
||||
requestUrl: "/api/cloudmigration/migration/run/1234",
|
||||
basicRole: org.RoleEditor,
|
||||
expectedHttpResult: http.StatusForbidden,
|
||||
expectedBody: "",
|
||||
},
|
||||
{
|
||||
desc: "should return 500 if service returns an error",
|
||||
requestHttpMethod: http.MethodGet,
|
||||
requestUrl: "/api/cloudmigration/migration/run/1234",
|
||||
basicRole: org.RoleAdmin,
|
||||
serviceReturnError: true,
|
||||
expectedHttpResult: http.StatusInternalServerError,
|
||||
expectedBody: "",
|
||||
},
|
||||
{
|
||||
desc: "should return 400 if uid is invalid",
|
||||
requestHttpMethod: http.MethodGet,
|
||||
requestUrl: "/api/cloudmigration/migration/run/****",
|
||||
basicRole: org.RoleAdmin,
|
||||
serviceReturnError: true,
|
||||
expectedHttpResult: http.StatusBadRequest,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.desc, runSimpleApiTest(tt))
|
||||
}
|
||||
}
|
||||
|
||||
func TestCloudMigrationAPI_GetMigrationRunList(t *testing.T) {
|
||||
tests := []TestCase{
|
||||
{
|
||||
desc: "should return 200 if everything is ok",
|
||||
requestHttpMethod: http.MethodGet,
|
||||
requestUrl: "/api/cloudmigration/migration/1234/run",
|
||||
basicRole: org.RoleAdmin,
|
||||
expectedHttpResult: http.StatusOK,
|
||||
expectedBody: `{"runs":[{"uid":"fake_run_uid_1"},{"uid":"fake_run_uid_2"}]}`,
|
||||
},
|
||||
{
|
||||
desc: "should return 403 if no used is not admin",
|
||||
requestHttpMethod: http.MethodGet,
|
||||
requestUrl: "/api/cloudmigration/migration/1234/run",
|
||||
basicRole: org.RoleEditor,
|
||||
expectedHttpResult: http.StatusForbidden,
|
||||
expectedBody: "",
|
||||
},
|
||||
{
|
||||
desc: "should return 500 if service returns an error",
|
||||
requestHttpMethod: http.MethodGet,
|
||||
requestUrl: "/api/cloudmigration/migration/1234/run",
|
||||
basicRole: org.RoleAdmin,
|
||||
serviceReturnError: true,
|
||||
expectedHttpResult: http.StatusInternalServerError,
|
||||
expectedBody: "",
|
||||
},
|
||||
{
|
||||
desc: "should return 400 if uid is invalid",
|
||||
requestHttpMethod: http.MethodGet,
|
||||
requestUrl: "/api/cloudmigration/migration/****/run",
|
||||
basicRole: org.RoleAdmin,
|
||||
serviceReturnError: true,
|
||||
expectedHttpResult: http.StatusBadRequest,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.desc, runSimpleApiTest(tt))
|
||||
}
|
||||
}
|
||||
|
||||
func TestCloudMigrationAPI_DeleteMigration(t *testing.T) {
|
||||
tests := []TestCase{
|
||||
{
|
||||
|
||||
@@ -188,23 +188,6 @@ func convertSessionListToDTO(sl cloudmigration.CloudMigrationSessionListResponse
|
||||
}
|
||||
}
|
||||
|
||||
func convertMigrateDataResponseToDTO(r cloudmigration.MigrateDataResponse) MigrateDataResponseDTO {
|
||||
items := make([]MigrateDataResponseItemDTO, len(r.Items))
|
||||
for i := 0; i < len(r.Items); i++ {
|
||||
item := r.Items[i]
|
||||
items[i] = MigrateDataResponseItemDTO{
|
||||
Type: MigrateDataType(item.Type),
|
||||
RefID: item.RefID,
|
||||
Status: ItemStatus(item.Status),
|
||||
Message: item.Error,
|
||||
}
|
||||
}
|
||||
return MigrateDataResponseDTO{
|
||||
RunUID: r.RunUID,
|
||||
Items: items,
|
||||
}
|
||||
}
|
||||
|
||||
// Base snapshot without results
|
||||
type SnapshotDTO struct {
|
||||
SnapshotUID string `json:"uid"`
|
||||
|
||||
@@ -21,10 +21,6 @@ type Service interface {
|
||||
DeleteSession(ctx context.Context, migUID string) (*CloudMigrationSession, error)
|
||||
GetSessionList(context.Context) (*CloudMigrationSessionListResponse, error)
|
||||
|
||||
RunMigration(ctx context.Context, migUID string) (*MigrateDataResponse, error)
|
||||
GetMigrationStatus(ctx context.Context, runUID string) (*CloudMigrationSnapshot, error)
|
||||
GetMigrationRunList(ctx context.Context, migUID string) (*CloudMigrationRunList, error)
|
||||
|
||||
CreateSnapshot(ctx context.Context, signedInUser *user.SignedInUser, sessionUid string) (*CloudMigrationSnapshot, error)
|
||||
GetSnapshot(ctx context.Context, query GetSnapshotsQuery) (*CloudMigrationSnapshot, error)
|
||||
GetSnapshotList(ctx context.Context, query ListSnapshotsQuery) ([]CloudMigrationSnapshot, error)
|
||||
|
||||
@@ -6,14 +6,12 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/api/routing"
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/infra/kvstore"
|
||||
@@ -401,74 +399,6 @@ func (s *Service) CreateSession(ctx context.Context, cmd cloudmigration.CloudMig
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *Service) RunMigration(ctx context.Context, uid string) (*cloudmigration.MigrateDataResponse, error) {
|
||||
// Get migration to read the auth token
|
||||
migration, err := s.GetSession(ctx, uid)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("migration get error: %w", err)
|
||||
}
|
||||
|
||||
// Get migration data JSON
|
||||
request, err := s.getMigrationDataJSON(ctx, &user.SignedInUser{})
|
||||
if err != nil {
|
||||
s.log.Error("error getting the json request body for migration run", "err", err.Error())
|
||||
return nil, fmt.Errorf("migration data get error: %w", err)
|
||||
}
|
||||
|
||||
// Call the gms service
|
||||
resp, err := s.gmsClient.MigrateData(ctx, *migration, *request)
|
||||
if err != nil {
|
||||
s.log.Error("error migrating data: %w", err)
|
||||
return nil, fmt.Errorf("migrate data error: %w", err)
|
||||
}
|
||||
|
||||
// save the result of the migration
|
||||
runUID, err := s.createMigrationRun(ctx, cloudmigration.CloudMigrationSnapshot{
|
||||
SessionUID: migration.UID,
|
||||
Resources: resp.Items,
|
||||
})
|
||||
if err != nil {
|
||||
response.Error(http.StatusInternalServerError, "migration run save error", err)
|
||||
}
|
||||
|
||||
resp.RunUID = runUID
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *Service) createMigrationRun(ctx context.Context, cmr cloudmigration.CloudMigrationSnapshot) (string, error) {
|
||||
uid, err := s.store.CreateMigrationRun(ctx, cmr)
|
||||
if err != nil {
|
||||
s.log.Error("Failed to save migration run", "err", err)
|
||||
return "", err
|
||||
}
|
||||
return uid, nil
|
||||
}
|
||||
|
||||
func (s *Service) GetMigrationStatus(ctx context.Context, runUID string) (*cloudmigration.CloudMigrationSnapshot, error) {
|
||||
cmr, err := s.store.GetMigrationStatus(ctx, runUID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("retrieving migration status from db: %w", err)
|
||||
}
|
||||
return cmr, nil
|
||||
}
|
||||
|
||||
func (s *Service) GetMigrationRunList(ctx context.Context, migUID string) (*cloudmigration.CloudMigrationRunList, error) {
|
||||
runs, err := s.store.GetMigrationStatusList(ctx, migUID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("retrieving migration statuses from db: %w", err)
|
||||
}
|
||||
|
||||
runList := &cloudmigration.CloudMigrationRunList{Runs: []cloudmigration.MigrateDataResponseList{}}
|
||||
for _, s := range runs {
|
||||
runList.Runs = append(runList.Runs, cloudmigration.MigrateDataResponseList{
|
||||
RunUID: s.UID,
|
||||
})
|
||||
}
|
||||
|
||||
return runList, nil
|
||||
}
|
||||
|
||||
func (s *Service) DeleteSession(ctx context.Context, sessionUID string) (*cloudmigration.CloudMigrationSession, error) {
|
||||
session, snapshots, err := s.store.DeleteMigrationSessionByUID(ctx, sessionUID)
|
||||
if err != nil {
|
||||
|
||||
@@ -41,26 +41,10 @@ func (s *NoopServiceImpl) CreateSession(ctx context.Context, cm cloudmigration.C
|
||||
return nil, cloudmigration.ErrFeatureDisabledError
|
||||
}
|
||||
|
||||
func (s *NoopServiceImpl) GetMigrationStatus(ctx context.Context, runUID string) (*cloudmigration.CloudMigrationSnapshot, error) {
|
||||
return nil, cloudmigration.ErrFeatureDisabledError
|
||||
}
|
||||
|
||||
func (s *NoopServiceImpl) GetMigrationRunList(ctx context.Context, uid string) (*cloudmigration.CloudMigrationRunList, error) {
|
||||
return nil, cloudmigration.ErrFeatureDisabledError
|
||||
}
|
||||
|
||||
func (s *NoopServiceImpl) DeleteSession(ctx context.Context, uid string) (*cloudmigration.CloudMigrationSession, error) {
|
||||
return nil, cloudmigration.ErrFeatureDisabledError
|
||||
}
|
||||
|
||||
func (s *NoopServiceImpl) CreateMigrationRun(context.Context, cloudmigration.CloudMigrationSnapshot) (string, error) {
|
||||
return "", cloudmigration.ErrInternalNotImplementedError
|
||||
}
|
||||
|
||||
func (s *NoopServiceImpl) RunMigration(context.Context, string) (*cloudmigration.MigrateDataResponse, error) {
|
||||
return nil, cloudmigration.ErrFeatureDisabledError
|
||||
}
|
||||
|
||||
func (s *NoopServiceImpl) CreateSnapshot(ctx context.Context, user *user.SignedInUser, sessionUid string) (*cloudmigration.CloudMigrationSnapshot, error) {
|
||||
return nil, cloudmigration.ErrFeatureDisabledError
|
||||
}
|
||||
|
||||
@@ -65,71 +65,6 @@ func Test_CreateGetAndDeleteToken(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func Test_CreateGetRunMigrationsAndRuns(t *testing.T) {
|
||||
s := setUpServiceTest(t, true)
|
||||
|
||||
createTokenResp, err := s.CreateToken(context.Background())
|
||||
assert.NoError(t, err)
|
||||
assert.NotEmpty(t, createTokenResp.Token)
|
||||
|
||||
cmd := cloudmigration.CloudMigrationSessionRequest{
|
||||
AuthToken: createTokenResp.Token,
|
||||
}
|
||||
|
||||
createResp, err := s.CreateSession(context.Background(), cmd)
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, createResp.UID)
|
||||
require.NotEmpty(t, createResp.Slug)
|
||||
|
||||
getMigResp, err := s.GetSession(context.Background(), createResp.UID)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, getMigResp)
|
||||
require.Equal(t, createResp.UID, getMigResp.UID)
|
||||
require.Equal(t, createResp.Slug, getMigResp.Slug)
|
||||
|
||||
listResp, err := s.GetSessionList(context.Background())
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, listResp)
|
||||
require.Equal(t, 1, len(listResp.Sessions))
|
||||
require.Equal(t, createResp.UID, listResp.Sessions[0].UID)
|
||||
require.Equal(t, createResp.Slug, listResp.Sessions[0].Slug)
|
||||
|
||||
runResp, err := s.RunMigration(ctxWithSignedInUser(), createResp.UID)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, runResp)
|
||||
resultItemsByType := make(map[string]int)
|
||||
for _, item := range runResp.Items {
|
||||
resultItemsByType[string(item.Type)] = resultItemsByType[string(item.Type)] + 1
|
||||
}
|
||||
require.Equal(t, 1, resultItemsByType["DASHBOARD"])
|
||||
require.Equal(t, 2, resultItemsByType["DATASOURCE"])
|
||||
require.Equal(t, 2, len(resultItemsByType))
|
||||
|
||||
runStatusResp, err := s.GetMigrationStatus(context.Background(), runResp.RunUID)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, runResp.RunUID, runStatusResp.UID)
|
||||
|
||||
listRunResp, err := s.GetMigrationRunList(context.Background(), createResp.UID)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 1, len(listRunResp.Runs))
|
||||
require.Equal(t, runResp.RunUID, listRunResp.Runs[0].RunUID)
|
||||
|
||||
/**
|
||||
-- This is not working at the moment since it is a mix of old and new methods
|
||||
will be fixed later when we clean the old functions and stick to the new ones.
|
||||
|
||||
delMigResp, err := s.DeleteSession(context.Background(), createResp.UID)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, createResp.UID, delMigResp.UID)
|
||||
|
||||
// after deleting the session, the snapshots and resources should not exist anymore.
|
||||
// we check the snapshot for now
|
||||
listRunResp2, err := s.GetMigrationRunList(context.Background(), createResp.UID)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 0, len(listRunResp2.Runs))
|
||||
*/
|
||||
}
|
||||
|
||||
func Test_GetSnapshotStatusFromGMS(t *testing.T) {
|
||||
s := setUpServiceTest(t, false).(*Service)
|
||||
|
||||
|
||||
@@ -82,54 +82,6 @@ func (m FakeServiceImpl) GetSessionList(_ context.Context) (*cloudmigration.Clou
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (m FakeServiceImpl) RunMigration(_ context.Context, _ string) (*cloudmigration.MigrateDataResponse, error) {
|
||||
if m.ReturnError {
|
||||
return nil, fmt.Errorf("mock error")
|
||||
}
|
||||
r := fakeMigrateDataResponseDTO()
|
||||
return &r, nil
|
||||
}
|
||||
|
||||
func fakeMigrateDataResponseDTO() cloudmigration.MigrateDataResponse {
|
||||
return cloudmigration.MigrateDataResponse{
|
||||
RunUID: "fake_uid",
|
||||
Items: []cloudmigration.CloudMigrationResource{
|
||||
{Type: "type", RefID: "make_refid", Status: "ok", Error: "none"},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (m FakeServiceImpl) CreateMigrationRun(ctx context.Context, run cloudmigration.CloudMigrationSnapshot) (string, error) {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (m FakeServiceImpl) GetMigrationStatus(_ context.Context, _ string) (*cloudmigration.CloudMigrationSnapshot, error) {
|
||||
if m.ReturnError {
|
||||
return nil, fmt.Errorf("mock error")
|
||||
}
|
||||
return &cloudmigration.CloudMigrationSnapshot{
|
||||
ID: 0,
|
||||
UID: "fake_uid",
|
||||
SessionUID: "fake_mig_uid",
|
||||
Resources: fakeMigrateDataResponseDTO().Items,
|
||||
Created: fixedDate,
|
||||
Updated: fixedDate,
|
||||
Finished: fixedDate,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (m FakeServiceImpl) GetMigrationRunList(_ context.Context, _ string) (*cloudmigration.CloudMigrationRunList, error) {
|
||||
if m.ReturnError {
|
||||
return nil, fmt.Errorf("mock error")
|
||||
}
|
||||
return &cloudmigration.CloudMigrationRunList{
|
||||
Runs: []cloudmigration.MigrateDataResponseList{
|
||||
{RunUID: "fake_run_uid_1"},
|
||||
{RunUID: "fake_run_uid_2"},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (m FakeServiceImpl) CreateSnapshot(ctx context.Context, user *user.SignedInUser, sessionUid string) (*cloudmigration.CloudMigrationSnapshot, error) {
|
||||
if m.ReturnError {
|
||||
return nil, fmt.Errorf("mock error")
|
||||
|
||||
@@ -14,11 +14,6 @@ type store interface {
|
||||
// the work is done in a transaction.
|
||||
DeleteMigrationSessionByUID(ctx context.Context, uid string) (*cloudmigration.CloudMigrationSession, []cloudmigration.CloudMigrationSnapshot, error)
|
||||
|
||||
CreateMigrationRun(ctx context.Context, cmr cloudmigration.CloudMigrationSnapshot) (string, error)
|
||||
GetMigrationStatus(ctx context.Context, cmrUID string) (*cloudmigration.CloudMigrationSnapshot, error)
|
||||
// GetMigrationStatusList Deprecated: true - use GetSnapshotList instead
|
||||
GetMigrationStatusList(ctx context.Context, migrationUID string) ([]*cloudmigration.CloudMigrationSnapshot, error)
|
||||
|
||||
CreateSnapshot(ctx context.Context, snapshot cloudmigration.CloudMigrationSnapshot) (string, error)
|
||||
UpdateSnapshot(ctx context.Context, snapshot cloudmigration.UpdateSnapshotCmd) error
|
||||
GetSnapshotByUID(ctx context.Context, sessUid, id string, resultPage int, resultLimit int) (*cloudmigration.CloudMigrationSnapshot, error)
|
||||
|
||||
@@ -51,22 +51,6 @@ func (ss *sqlStore) GetMigrationSessionByUID(ctx context.Context, uid string) (*
|
||||
return &cm, err
|
||||
}
|
||||
|
||||
func (ss *sqlStore) CreateMigrationRun(ctx context.Context, cmr cloudmigration.CloudMigrationSnapshot) (string, error) {
|
||||
err := ss.db.WithDbSession(ctx, func(sess *db.Session) error {
|
||||
cmr.Created = time.Now()
|
||||
cmr.Updated = time.Now()
|
||||
cmr.Finished = time.Now()
|
||||
cmr.UID = util.GenerateShortUID()
|
||||
|
||||
_, err := sess.Insert(&cmr)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return cmr.UID, nil
|
||||
}
|
||||
|
||||
func (ss *sqlStore) CreateMigrationSession(ctx context.Context, migration cloudmigration.CloudMigrationSession) (*cloudmigration.CloudMigrationSession, error) {
|
||||
if err := ss.encryptToken(ctx, &migration); err != nil {
|
||||
return nil, fmt.Errorf("encrypting token: %w", err)
|
||||
@@ -176,34 +160,6 @@ func (ss *sqlStore) DeleteMigrationSessionByUID(ctx context.Context, uid string)
|
||||
return &c, snapshots, nil
|
||||
}
|
||||
|
||||
func (ss *sqlStore) GetMigrationStatus(ctx context.Context, cmrUID string) (*cloudmigration.CloudMigrationSnapshot, error) {
|
||||
var c cloudmigration.CloudMigrationSnapshot
|
||||
err := ss.db.WithDbSession(ctx, func(sess *db.Session) error {
|
||||
exist, err := sess.Where("uid=?", cmrUID).Get(&c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !exist {
|
||||
return cloudmigration.ErrMigrationRunNotFound
|
||||
}
|
||||
return nil
|
||||
})
|
||||
return &c, err
|
||||
}
|
||||
|
||||
func (ss *sqlStore) GetMigrationStatusList(ctx context.Context, migrationUID string) ([]*cloudmigration.CloudMigrationSnapshot, error) {
|
||||
var runs = make([]*cloudmigration.CloudMigrationSnapshot, 0)
|
||||
err := ss.db.WithDbSession(ctx, func(sess *db.Session) error {
|
||||
return sess.Find(&runs, &cloudmigration.CloudMigrationSnapshot{
|
||||
SessionUID: migrationUID,
|
||||
})
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return runs, nil
|
||||
}
|
||||
|
||||
func (ss *sqlStore) CreateSnapshot(ctx context.Context, snapshot cloudmigration.CloudMigrationSnapshot) (string, error) {
|
||||
if snapshot.SessionUID == "" {
|
||||
return "", fmt.Errorf("sessionUID is required")
|
||||
|
||||
@@ -111,61 +111,6 @@ func Test_DeleteMigrationSession(t *testing.T) {
|
||||
}
|
||||
*/
|
||||
|
||||
func Test_CreateMigrationRun(t *testing.T) {
|
||||
_, s := setUpTest(t)
|
||||
ctx := context.Background()
|
||||
|
||||
t.Run("creates a session run and retrieves it from db", func(t *testing.T) {
|
||||
cmr := cloudmigration.CloudMigrationSnapshot{
|
||||
SessionUID: "asdfg",
|
||||
Status: cloudmigration.SnapshotStatusFinished,
|
||||
}
|
||||
|
||||
createResp, err := s.CreateMigrationRun(ctx, cmr)
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, createResp)
|
||||
|
||||
getMRResp, err := s.GetMigrationStatus(ctx, createResp)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, cmr.Status, getMRResp.Status)
|
||||
})
|
||||
}
|
||||
|
||||
func Test_GetMigrationStatus(t *testing.T) {
|
||||
_, s := setUpTest(t)
|
||||
ctx := context.Background()
|
||||
|
||||
t.Run("gets a migration status by uid", func(t *testing.T) {
|
||||
getMRResp, err := s.GetMigrationStatus(ctx, "poiuy")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "poiuy", getMRResp.UID)
|
||||
})
|
||||
|
||||
t.Run("returns error if migration run was not found", func(t *testing.T) {
|
||||
getMRResp, err := s.GetMigrationStatus(ctx, "fake_uid")
|
||||
require.ErrorIs(t, cloudmigration.ErrMigrationRunNotFound, err)
|
||||
require.Equal(t, int64(0), getMRResp.ID)
|
||||
require.Equal(t, "", getMRResp.UID)
|
||||
})
|
||||
}
|
||||
|
||||
func Test_GetMigrationStatusList(t *testing.T) {
|
||||
_, s := setUpTest(t)
|
||||
ctx := context.Background()
|
||||
|
||||
t.Run("gets migration status list from db", func(t *testing.T) {
|
||||
list, err := s.GetMigrationStatusList(ctx, "qwerty")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 2, len(list))
|
||||
})
|
||||
|
||||
t.Run("returns no error if migration was not found, just empty list", func(t *testing.T) {
|
||||
list, err := s.GetMigrationStatusList(ctx, "fake_migration")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 0, len(list))
|
||||
})
|
||||
}
|
||||
|
||||
func Test_SnapshotManagement(t *testing.T) {
|
||||
_, s := setUpTest(t)
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -2326,41 +2326,6 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"/cloudmigration/migration/run/{runUID}": {
|
||||
"get": {
|
||||
"tags": [
|
||||
"migrations"
|
||||
],
|
||||
"summary": "Get the result of a single migration run.",
|
||||
"operationId": "getCloudMigrationRun",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "RunUID of a migration run",
|
||||
"name": "runUID",
|
||||
"in": "path",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"$ref": "#/responses/cloudMigrationRunResponse"
|
||||
},
|
||||
"400": {
|
||||
"$ref": "#/responses/badRequestError"
|
||||
},
|
||||
"401": {
|
||||
"$ref": "#/responses/unauthorisedError"
|
||||
},
|
||||
"403": {
|
||||
"$ref": "#/responses/forbiddenError"
|
||||
},
|
||||
"500": {
|
||||
"$ref": "#/responses/internalServerError"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/cloudmigration/migration/{uid}": {
|
||||
"get": {
|
||||
"tags": [
|
||||
@@ -2426,75 +2391,6 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"/cloudmigration/migration/{uid}/run": {
|
||||
"get": {
|
||||
"tags": [
|
||||
"migrations"
|
||||
],
|
||||
"summary": "Get a list of migration runs for a migration.",
|
||||
"operationId": "getCloudMigrationRunList",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "UID of a migration",
|
||||
"name": "uid",
|
||||
"in": "path",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"$ref": "#/responses/cloudMigrationRunListResponse"
|
||||
},
|
||||
"400": {
|
||||
"$ref": "#/responses/badRequestError"
|
||||
},
|
||||
"401": {
|
||||
"$ref": "#/responses/unauthorisedError"
|
||||
},
|
||||
"403": {
|
||||
"$ref": "#/responses/forbiddenError"
|
||||
},
|
||||
"500": {
|
||||
"$ref": "#/responses/internalServerError"
|
||||
}
|
||||
}
|
||||
},
|
||||
"post": {
|
||||
"description": "It returns migrations that has been created.",
|
||||
"tags": [
|
||||
"migrations"
|
||||
],
|
||||
"summary": "Trigger the run of a migration to the Grafana Cloud.",
|
||||
"operationId": "runCloudMigration",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "UID of a migration",
|
||||
"name": "uid",
|
||||
"in": "path",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"$ref": "#/responses/cloudMigrationRunResponse"
|
||||
},
|
||||
"400": {
|
||||
"$ref": "#/responses/badRequestError"
|
||||
},
|
||||
"401": {
|
||||
"$ref": "#/responses/unauthorisedError"
|
||||
},
|
||||
"403": {
|
||||
"$ref": "#/responses/forbiddenError"
|
||||
},
|
||||
"500": {
|
||||
"$ref": "#/responses/internalServerError"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/cloudmigration/migration/{uid}/snapshot": {
|
||||
"post": {
|
||||
"description": "If the snapshot initialization is successful, the snapshot uid is returned.",
|
||||
|
||||
@@ -15499,43 +15499,6 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"/cloudmigration/migration/run/{runUID}": {
|
||||
"get": {
|
||||
"operationId": "getCloudMigrationRun",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "RunUID of a migration run",
|
||||
"in": "path",
|
||||
"name": "runUID",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"$ref": "#/components/responses/cloudMigrationRunResponse"
|
||||
},
|
||||
"400": {
|
||||
"$ref": "#/components/responses/badRequestError"
|
||||
},
|
||||
"401": {
|
||||
"$ref": "#/components/responses/unauthorisedError"
|
||||
},
|
||||
"403": {
|
||||
"$ref": "#/components/responses/forbiddenError"
|
||||
},
|
||||
"500": {
|
||||
"$ref": "#/components/responses/internalServerError"
|
||||
}
|
||||
},
|
||||
"summary": "Get the result of a single migration run.",
|
||||
"tags": [
|
||||
"migrations"
|
||||
]
|
||||
}
|
||||
},
|
||||
"/cloudmigration/migration/{uid}": {
|
||||
"delete": {
|
||||
"operationId": "deleteSession",
|
||||
@@ -15605,79 +15568,6 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"/cloudmigration/migration/{uid}/run": {
|
||||
"get": {
|
||||
"operationId": "getCloudMigrationRunList",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "UID of a migration",
|
||||
"in": "path",
|
||||
"name": "uid",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"$ref": "#/components/responses/cloudMigrationRunListResponse"
|
||||
},
|
||||
"400": {
|
||||
"$ref": "#/components/responses/badRequestError"
|
||||
},
|
||||
"401": {
|
||||
"$ref": "#/components/responses/unauthorisedError"
|
||||
},
|
||||
"403": {
|
||||
"$ref": "#/components/responses/forbiddenError"
|
||||
},
|
||||
"500": {
|
||||
"$ref": "#/components/responses/internalServerError"
|
||||
}
|
||||
},
|
||||
"summary": "Get a list of migration runs for a migration.",
|
||||
"tags": [
|
||||
"migrations"
|
||||
]
|
||||
},
|
||||
"post": {
|
||||
"description": "It returns migrations that has been created.",
|
||||
"operationId": "runCloudMigration",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "UID of a migration",
|
||||
"in": "path",
|
||||
"name": "uid",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"$ref": "#/components/responses/cloudMigrationRunResponse"
|
||||
},
|
||||
"400": {
|
||||
"$ref": "#/components/responses/badRequestError"
|
||||
},
|
||||
"401": {
|
||||
"$ref": "#/components/responses/unauthorisedError"
|
||||
},
|
||||
"403": {
|
||||
"$ref": "#/components/responses/forbiddenError"
|
||||
},
|
||||
"500": {
|
||||
"$ref": "#/components/responses/internalServerError"
|
||||
}
|
||||
},
|
||||
"summary": "Trigger the run of a migration to the Grafana Cloud.",
|
||||
"tags": [
|
||||
"migrations"
|
||||
]
|
||||
}
|
||||
},
|
||||
"/cloudmigration/migration/{uid}/snapshot": {
|
||||
"post": {
|
||||
"description": "If the snapshot initialization is successful, the snapshot uid is returned.",
|
||||
|
||||
Reference in New Issue
Block a user