CloudMigrations: Refactor API for async work (#89084)
* rename some stuff * more renaming * clean up api * rename more functions * rename cms -> gms * update comment * update swagger gen * update endpoints * overzealous * final touches * dont modify existing migrations * break structs into domain and dtos * add some conversion funcs * fix build * update frontend * try to make swagger happy
This commit is contained in:
@@ -40,14 +40,16 @@ func RegisterApi(
|
||||
// registerEndpoints Registers Endpoints on Grafana Router
|
||||
func (cma *CloudMigrationAPI) registerEndpoints() {
|
||||
cma.routeRegister.Group("/api/cloudmigration", func(cloudMigrationRoute routing.RouteRegister) {
|
||||
// migration
|
||||
cloudMigrationRoute.Get("/migration", routing.Wrap(cma.GetMigrationList))
|
||||
cloudMigrationRoute.Post("/migration", routing.Wrap(cma.CreateMigration))
|
||||
cloudMigrationRoute.Get("/migration/:uid", routing.Wrap(cma.GetMigration))
|
||||
cloudMigrationRoute.Delete("/migration/:uid", routing.Wrap(cma.DeleteMigration))
|
||||
cloudMigrationRoute.Get("/migration", routing.Wrap(cma.GetSessionList))
|
||||
cloudMigrationRoute.Post("/migration", routing.Wrap(cma.CreateSession))
|
||||
cloudMigrationRoute.Get("/migration/:uid", routing.Wrap(cma.GetSession))
|
||||
cloudMigrationRoute.Delete("/migration/:uid", routing.Wrap(cma.DeleteSession))
|
||||
|
||||
// TODO new APIs for snapshot management to replace these
|
||||
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))
|
||||
|
||||
cloudMigrationRoute.Get("/token", routing.Wrap(cma.GetToken))
|
||||
cloudMigrationRoute.Post("/token", routing.Wrap(cma.CreateToken))
|
||||
cloudMigrationRoute.Delete("/token/:uid", routing.Wrap(cma.DeleteToken))
|
||||
@@ -141,84 +143,88 @@ func (cma *CloudMigrationAPI) DeleteToken(c *contextmodel.ReqContext) response.R
|
||||
return response.Empty(http.StatusNoContent)
|
||||
}
|
||||
|
||||
// swagger:route GET /cloudmigration/migration migrations getMigrationList
|
||||
// swagger:route GET /cloudmigration/migration migrations getSessionList
|
||||
//
|
||||
// Get a list of all cloud migrations.
|
||||
// Get a list of all cloud migration sessions that have been created.
|
||||
//
|
||||
// Responses:
|
||||
// 200: cloudMigrationListResponse
|
||||
// 200: cloudMigrationSessionListResponse
|
||||
// 401: unauthorisedError
|
||||
// 403: forbiddenError
|
||||
// 500: internalServerError
|
||||
func (cma *CloudMigrationAPI) GetMigrationList(c *contextmodel.ReqContext) response.Response {
|
||||
ctx, span := cma.tracer.Start(c.Req.Context(), "MigrationAPI.GetMigrationList")
|
||||
func (cma *CloudMigrationAPI) GetSessionList(c *contextmodel.ReqContext) response.Response {
|
||||
ctx, span := cma.tracer.Start(c.Req.Context(), "MigrationAPI.GetSessionList")
|
||||
defer span.End()
|
||||
|
||||
cloudMigrations, err := cma.cloudMigrationService.GetMigrationList(ctx)
|
||||
sl, err := cma.cloudMigrationService.GetSessionList(ctx)
|
||||
if err != nil {
|
||||
return response.ErrOrFallback(http.StatusInternalServerError, "migration list error", err)
|
||||
return response.ErrOrFallback(http.StatusInternalServerError, "session list error", err)
|
||||
}
|
||||
|
||||
return response.JSON(http.StatusOK, cloudMigrations)
|
||||
return response.JSON(http.StatusOK, convertSessionListToDTO(*sl))
|
||||
}
|
||||
|
||||
// swagger:route GET /cloudmigration/migration/{uid} migrations getCloudMigration
|
||||
// swagger:route GET /cloudmigration/migration/{uid} migrations getSession
|
||||
//
|
||||
// Get a cloud migration.
|
||||
//
|
||||
// It returns migrations that has been created.
|
||||
// Get a cloud migration session by its uid.
|
||||
//
|
||||
// Responses:
|
||||
// 200: cloudMigrationResponse
|
||||
// 200: cloudMigrationSessionResponse
|
||||
// 401: unauthorisedError
|
||||
// 403: forbiddenError
|
||||
// 500: internalServerError
|
||||
func (cma *CloudMigrationAPI) GetMigration(c *contextmodel.ReqContext) response.Response {
|
||||
ctx, span := cma.tracer.Start(c.Req.Context(), "MigrationAPI.GetMigration")
|
||||
func (cma *CloudMigrationAPI) GetSession(c *contextmodel.ReqContext) response.Response {
|
||||
ctx, span := cma.tracer.Start(c.Req.Context(), "MigrationAPI.GetSession")
|
||||
defer span.End()
|
||||
|
||||
uid := web.Params(c.Req)[":uid"]
|
||||
if err := util.ValidateUID(uid); err != nil {
|
||||
return response.Error(http.StatusBadRequest, "invalid migration uid", err)
|
||||
return response.Error(http.StatusBadRequest, "invalid session uid", err)
|
||||
}
|
||||
|
||||
cloudMigration, err := cma.cloudMigrationService.GetMigration(ctx, uid)
|
||||
s, err := cma.cloudMigrationService.GetSession(ctx, uid)
|
||||
if err != nil {
|
||||
return response.ErrOrFallback(http.StatusNotFound, "migration not found", err)
|
||||
return response.ErrOrFallback(http.StatusNotFound, "session not found", err)
|
||||
}
|
||||
return response.JSON(http.StatusOK, cloudMigration)
|
||||
|
||||
return response.JSON(http.StatusOK, CloudMigrationSessionResponseDTO{
|
||||
UID: s.UID,
|
||||
Slug: s.Slug,
|
||||
Created: s.Created,
|
||||
Updated: s.Updated,
|
||||
})
|
||||
}
|
||||
|
||||
// swagger:parameters getCloudMigration
|
||||
type GetCloudMigrationRequest struct {
|
||||
// UID of a migration
|
||||
//
|
||||
// in: path
|
||||
UID string `json:"uid"`
|
||||
}
|
||||
|
||||
// swagger:route POST /cloudmigration/migration migrations createMigration
|
||||
// swagger:route POST /cloudmigration/migration migrations createSession
|
||||
//
|
||||
// Create a migration.
|
||||
// Create a migration session.
|
||||
//
|
||||
// Responses:
|
||||
// 200: cloudMigrationResponse
|
||||
// 200: cloudMigrationSessionResponse
|
||||
// 401: unauthorisedError
|
||||
// 403: forbiddenError
|
||||
// 500: internalServerError
|
||||
func (cma *CloudMigrationAPI) CreateMigration(c *contextmodel.ReqContext) response.Response {
|
||||
ctx, span := cma.tracer.Start(c.Req.Context(), "MigrationAPI.CreateMigration")
|
||||
func (cma *CloudMigrationAPI) CreateSession(c *contextmodel.ReqContext) response.Response {
|
||||
ctx, span := cma.tracer.Start(c.Req.Context(), "MigrationAPI.CreateSession")
|
||||
defer span.End()
|
||||
|
||||
cmd := cloudmigration.CloudMigrationRequest{}
|
||||
cmd := CloudMigrationSessionRequestDTO{}
|
||||
if err := web.Bind(c.Req, &cmd); err != nil {
|
||||
return response.ErrOrFallback(http.StatusBadRequest, "bad request data", err)
|
||||
}
|
||||
cloudMigration, err := cma.cloudMigrationService.CreateMigration(ctx, cmd)
|
||||
s, err := cma.cloudMigrationService.CreateSession(ctx, cloudmigration.CloudMigrationSessionRequest{
|
||||
AuthToken: cmd.AuthToken,
|
||||
})
|
||||
if err != nil {
|
||||
return response.ErrOrFallback(http.StatusInternalServerError, "migration creation error", err)
|
||||
return response.ErrOrFallback(http.StatusInternalServerError, "session creation error", err)
|
||||
}
|
||||
return response.JSON(http.StatusOK, cloudMigration)
|
||||
|
||||
return response.JSON(http.StatusOK, CloudMigrationSessionResponseDTO{
|
||||
UID: s.UID,
|
||||
Slug: s.Slug,
|
||||
Created: s.Created,
|
||||
Updated: s.Updated,
|
||||
})
|
||||
}
|
||||
|
||||
// swagger:route POST /cloudmigration/migration/{uid}/run migrations runCloudMigration
|
||||
@@ -246,15 +252,7 @@ func (cma *CloudMigrationAPI) RunMigration(c *contextmodel.ReqContext) response.
|
||||
return response.ErrOrFallback(http.StatusInternalServerError, "migration run error", err)
|
||||
}
|
||||
|
||||
return response.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
// swagger:parameters runCloudMigration
|
||||
type RunCloudMigrationRequest struct {
|
||||
// UID of a migration
|
||||
//
|
||||
// in: path
|
||||
UID string `json:"uid"`
|
||||
return response.JSON(http.StatusOK, convertMigrateDataResponseToDTO(*result))
|
||||
}
|
||||
|
||||
// swagger:route GET /cloudmigration/migration/run/{runUID} migrations getCloudMigrationRun
|
||||
@@ -280,21 +278,13 @@ func (cma *CloudMigrationAPI) GetMigrationRun(c *contextmodel.ReqContext) respon
|
||||
return response.ErrOrFallback(http.StatusInternalServerError, "migration status error", err)
|
||||
}
|
||||
|
||||
runResponse, err := migrationStatus.ToResponse()
|
||||
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, runResponse)
|
||||
}
|
||||
|
||||
// swagger:parameters getCloudMigrationRun
|
||||
type GetMigrationRunParams struct {
|
||||
// RunUID of a migration run
|
||||
//
|
||||
// in: path
|
||||
RunUID string `json:"runUID"`
|
||||
return response.JSON(http.StatusOK, convertMigrateDataResponseToDTO(*result))
|
||||
}
|
||||
|
||||
// swagger:route GET /cloudmigration/migration/{uid}/run migrations getCloudMigrationRunList
|
||||
@@ -320,118 +310,36 @@ func (cma *CloudMigrationAPI) GetMigrationRunList(c *contextmodel.ReqContext) re
|
||||
return response.ErrOrFallback(http.StatusInternalServerError, "list migration status error", err)
|
||||
}
|
||||
|
||||
return response.JSON(http.StatusOK, runList)
|
||||
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, SnapshotListDTO{
|
||||
Runs: runs,
|
||||
})
|
||||
}
|
||||
|
||||
// swagger:parameters getCloudMigrationRunList
|
||||
type GetCloudMigrationRunList struct {
|
||||
// UID of a migration
|
||||
//
|
||||
// in: path
|
||||
UID string `json:"uid"`
|
||||
}
|
||||
|
||||
// swagger:route DELETE /cloudmigration/migration/{uid} migrations deleteCloudMigration
|
||||
// swagger:route DELETE /cloudmigration/migration/{uid} migrations deleteSession
|
||||
//
|
||||
// Delete a migration.
|
||||
// Delete a migration session by its uid.
|
||||
//
|
||||
// Responses:
|
||||
// 200
|
||||
// 401: unauthorisedError
|
||||
// 403: forbiddenError
|
||||
// 500: internalServerError
|
||||
func (cma *CloudMigrationAPI) DeleteMigration(c *contextmodel.ReqContext) response.Response {
|
||||
ctx, span := cma.tracer.Start(c.Req.Context(), "MigrationAPI.DeleteMigration")
|
||||
func (cma *CloudMigrationAPI) DeleteSession(c *contextmodel.ReqContext) response.Response {
|
||||
ctx, span := cma.tracer.Start(c.Req.Context(), "MigrationAPI.DeleteSession")
|
||||
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)
|
||||
return response.ErrOrFallback(http.StatusBadRequest, "invalid session uid", err)
|
||||
}
|
||||
|
||||
_, err := cma.cloudMigrationService.DeleteMigration(ctx, uid)
|
||||
_, err := cma.cloudMigrationService.DeleteSession(ctx, uid)
|
||||
if err != nil {
|
||||
return response.ErrOrFallback(http.StatusInternalServerError, "migration delete error", err)
|
||||
return response.ErrOrFallback(http.StatusInternalServerError, "session delete error", err)
|
||||
}
|
||||
return response.Empty(http.StatusOK)
|
||||
}
|
||||
|
||||
// swagger:parameters deleteCloudMigration
|
||||
type DeleteMigrationRequest struct {
|
||||
// UID of a migration
|
||||
//
|
||||
// in: path
|
||||
UID string `json:"uid"`
|
||||
}
|
||||
|
||||
// swagger:response cloudMigrationRunResponse
|
||||
type CloudMigrationRunResponse struct {
|
||||
// in: body
|
||||
Body cloudmigration.MigrateDataResponseDTO
|
||||
}
|
||||
|
||||
// swagger:response cloudMigrationListResponse
|
||||
type CloudMigrationListResponse struct {
|
||||
// in: body
|
||||
Body cloudmigration.CloudMigrationListResponse
|
||||
}
|
||||
|
||||
// swagger:parameters createMigration
|
||||
type CreateMigration struct {
|
||||
// in:body
|
||||
// required:true
|
||||
Body cloudmigration.CloudMigrationRequest
|
||||
}
|
||||
|
||||
// swagger:response cloudMigrationResponse
|
||||
type CloudMigrationResponse struct {
|
||||
// in: body
|
||||
Body cloudmigration.CloudMigrationResponse
|
||||
}
|
||||
|
||||
// swagger:response cloudMigrationRunListResponse
|
||||
type CloudMigrationRunListResponse struct {
|
||||
// in: body
|
||||
Body cloudmigration.CloudMigrationRunList
|
||||
}
|
||||
|
||||
// swagger:parameters getCloudMigrationToken
|
||||
type GetCloudMigrationToken struct {
|
||||
}
|
||||
|
||||
// swagger:response cloudMigrationGetTokenResponse
|
||||
type CloudMigrationGetTokenResponse struct {
|
||||
// in: body
|
||||
Body GetAccessTokenResponseDTO
|
||||
}
|
||||
|
||||
type GetAccessTokenResponseDTO struct {
|
||||
ID string `json:"id"`
|
||||
DisplayName string `json:"displayName"`
|
||||
ExpiresAt string `json:"expiresAt"`
|
||||
FirstUsedAt string `json:"firstUsedAt"`
|
||||
LastUsedAt string `json:"lastUsedAt"`
|
||||
CreatedAt string `json:"createdAt"`
|
||||
}
|
||||
|
||||
// swagger:response cloudMigrationCreateTokenResponse
|
||||
type CloudMigrationCreateTokenResponse struct {
|
||||
// in: body
|
||||
Body CreateAccessTokenResponseDTO
|
||||
}
|
||||
|
||||
type CreateAccessTokenResponseDTO struct {
|
||||
Token string `json:"token"`
|
||||
}
|
||||
|
||||
// swagger:parameters deleteCloudMigrationToken
|
||||
type DeleteCloudMigrationToken struct {
|
||||
// UID of a cloud migration token
|
||||
//
|
||||
// in: path
|
||||
UID string `json:"uid"`
|
||||
}
|
||||
|
||||
// swagger:response cloudMigrationDeleteTokenResponse
|
||||
type CloudMigrationDeleteTokenResponse struct {
|
||||
}
|
||||
|
||||
@@ -181,7 +181,7 @@ func TestCloudMigrationAPI_GetMigrationList(t *testing.T) {
|
||||
requestUrl: "/api/cloudmigration/migration",
|
||||
basicRole: org.RoleAdmin,
|
||||
expectedHttpResult: http.StatusOK,
|
||||
expectedBody: `{"migrations":[{"uid":"mock_uid_1","stack":"mock_stack_1","created":"2024-06-05T17:30:40Z","updated":"2024-06-05T17:30:40Z"},{"uid":"mock_uid_2","stack":"mock_stack_2","created":"2024-06-05T17:30:40Z","updated":"2024-06-05T17:30:40Z"}]}`,
|
||||
expectedBody: `{"sessions":[{"uid":"mock_uid_1","slug":"mock_stack_1","created":"2024-06-05T17:30:40Z","updated":"2024-06-05T17:30:40Z"},{"uid":"mock_uid_2","slug":"mock_stack_2","created":"2024-06-05T17:30:40Z","updated":"2024-06-05T17:30:40Z"}]}`,
|
||||
},
|
||||
{
|
||||
desc: "should return 403 if no used is not admin",
|
||||
@@ -216,7 +216,7 @@ func TestCloudMigrationAPI_CreateMigration(t *testing.T) {
|
||||
requestBody: `{"auth_token":"asdf"}`,
|
||||
basicRole: org.RoleAdmin,
|
||||
expectedHttpResult: http.StatusOK,
|
||||
expectedBody: `{"uid":"fake_uid","stack":"fake_stack","created":"2024-06-05T17:30:40Z","updated":"2024-06-05T17:30:40Z"}`,
|
||||
expectedBody: `{"uid":"fake_uid","slug":"fake_stack","created":"2024-06-05T17:30:40Z","updated":"2024-06-05T17:30:40Z"}`,
|
||||
},
|
||||
{
|
||||
desc: "should return 403 if no used is not admin",
|
||||
|
||||
@@ -0,0 +1,209 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/grafana/grafana/pkg/services/cloudmigration"
|
||||
)
|
||||
|
||||
// swagger:parameters getCloudMigrationToken
|
||||
type GetCloudMigrationToken struct {
|
||||
}
|
||||
|
||||
// swagger:response cloudMigrationGetTokenResponse
|
||||
type CloudMigrationGetTokenResponse struct {
|
||||
// in: body
|
||||
Body GetAccessTokenResponseDTO
|
||||
}
|
||||
|
||||
type GetAccessTokenResponseDTO struct {
|
||||
ID string `json:"id"`
|
||||
DisplayName string `json:"displayName"`
|
||||
ExpiresAt string `json:"expiresAt"`
|
||||
FirstUsedAt string `json:"firstUsedAt"`
|
||||
LastUsedAt string `json:"lastUsedAt"`
|
||||
CreatedAt string `json:"createdAt"`
|
||||
}
|
||||
|
||||
// swagger:response cloudMigrationCreateTokenResponse
|
||||
type CloudMigrationCreateTokenResponse struct {
|
||||
// in: body
|
||||
Body CreateAccessTokenResponseDTO
|
||||
}
|
||||
|
||||
type CreateAccessTokenResponseDTO struct {
|
||||
Token string `json:"token"`
|
||||
}
|
||||
|
||||
// swagger:parameters deleteCloudMigrationToken
|
||||
type DeleteCloudMigrationToken struct {
|
||||
// UID of a cloud migration token
|
||||
//
|
||||
// in: path
|
||||
UID string `json:"uid"`
|
||||
}
|
||||
|
||||
// swagger:response cloudMigrationDeleteTokenResponse
|
||||
type CloudMigrationDeleteTokenResponse struct {
|
||||
}
|
||||
|
||||
// swagger:response cloudMigrationSessionListResponse
|
||||
type CloudMigrationSessionListResponse struct {
|
||||
// in: body
|
||||
Body CloudMigrationSessionListResponseDTO
|
||||
}
|
||||
|
||||
type CloudMigrationSessionResponseDTO struct {
|
||||
UID string `json:"uid"`
|
||||
Slug string `json:"slug"`
|
||||
Created time.Time `json:"created"`
|
||||
Updated time.Time `json:"updated"`
|
||||
}
|
||||
|
||||
type CloudMigrationSessionListResponseDTO struct {
|
||||
Sessions []CloudMigrationSessionResponseDTO `json:"sessions"`
|
||||
}
|
||||
|
||||
// swagger:parameters getSession
|
||||
type GetCloudMigrationSessionRequest struct {
|
||||
// UID of a migration session
|
||||
//
|
||||
// in: path
|
||||
UID string `json:"uid"`
|
||||
}
|
||||
|
||||
// swagger:response cloudMigrationSessionResponse
|
||||
type CloudMigrationSessionResponse struct {
|
||||
// in: body
|
||||
Body CloudMigrationSessionResponseDTO
|
||||
}
|
||||
|
||||
// swagger:parameters createSession
|
||||
type CreateSession struct {
|
||||
// in:body
|
||||
// required:true
|
||||
Body CloudMigrationSessionRequestDTO
|
||||
}
|
||||
|
||||
type CloudMigrationSessionRequestDTO struct {
|
||||
AuthToken string `json:"authToken"`
|
||||
}
|
||||
|
||||
// swagger:parameters runCloudMigration
|
||||
type RunCloudMigrationRequest struct {
|
||||
// UID of a migration
|
||||
//
|
||||
// in: path
|
||||
UID string `json:"uid"`
|
||||
}
|
||||
|
||||
// swagger:response cloudMigrationRunResponse
|
||||
type CloudMigrationRunResponse struct {
|
||||
// in: body
|
||||
Body MigrateDataResponseDTO
|
||||
}
|
||||
|
||||
type MigrateDataResponseDTO struct {
|
||||
RunUID string `json:"uid"`
|
||||
Items []MigrateDataResponseItemDTO `json:"items"`
|
||||
}
|
||||
|
||||
type MigrateDataResponseItemDTO struct {
|
||||
// required:true
|
||||
Type MigrateDataType `json:"type"`
|
||||
// required:true
|
||||
RefID string `json:"refId"`
|
||||
// required:true
|
||||
Status ItemStatus `json:"status"`
|
||||
Error string `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
// swagger:enum MigrateDataType
|
||||
type MigrateDataType string
|
||||
|
||||
const (
|
||||
DashboardDataType MigrateDataType = "DASHBOARD"
|
||||
DatasourceDataType MigrateDataType = "DATASOURCE"
|
||||
FolderDataType MigrateDataType = "FOLDER"
|
||||
)
|
||||
|
||||
// swagger:enum ItemStatus
|
||||
type ItemStatus string
|
||||
|
||||
const (
|
||||
ItemStatusOK ItemStatus = "OK"
|
||||
ItemStatusError ItemStatus = "ERROR"
|
||||
)
|
||||
|
||||
// swagger:parameters getCloudMigrationRun
|
||||
type GetMigrationRunParams struct {
|
||||
// RunUID of a migration run
|
||||
//
|
||||
// in: path
|
||||
RunUID string `json:"runUID"`
|
||||
}
|
||||
|
||||
// swagger:parameters getCloudMigrationRunList
|
||||
type GetCloudMigrationRunList struct {
|
||||
// UID of a migration
|
||||
//
|
||||
// in: path
|
||||
UID string `json:"uid"`
|
||||
}
|
||||
|
||||
// swagger:response cloudMigrationRunListResponse
|
||||
type CloudMigrationRunListResponse struct {
|
||||
// in: body
|
||||
Body SnapshotListDTO
|
||||
}
|
||||
|
||||
type SnapshotListDTO struct {
|
||||
Runs []MigrateDataResponseListDTO `json:"runs"`
|
||||
}
|
||||
|
||||
type MigrateDataResponseListDTO struct {
|
||||
RunUID string `json:"uid"`
|
||||
}
|
||||
|
||||
// swagger:parameters deleteSession
|
||||
type DeleteMigrationSessionRequest struct {
|
||||
// UID of a migration session
|
||||
//
|
||||
// in: path
|
||||
UID string `json:"uid"`
|
||||
}
|
||||
|
||||
// utility funcs for converting to/from DTO
|
||||
|
||||
func convertSessionListToDTO(sl cloudmigration.CloudMigrationSessionListResponse) CloudMigrationSessionListResponseDTO {
|
||||
slDTOs := make([]CloudMigrationSessionResponseDTO, len(sl.Sessions))
|
||||
for i := 0; i < len(slDTOs); i++ {
|
||||
s := sl.Sessions[i]
|
||||
slDTOs[i] = CloudMigrationSessionResponseDTO{
|
||||
UID: s.UID,
|
||||
Slug: s.Slug,
|
||||
Created: s.Created,
|
||||
Updated: s.Updated,
|
||||
}
|
||||
}
|
||||
return CloudMigrationSessionListResponseDTO{
|
||||
Sessions: slDTOs,
|
||||
}
|
||||
}
|
||||
|
||||
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),
|
||||
Error: item.Error,
|
||||
}
|
||||
}
|
||||
return MigrateDataResponseDTO{
|
||||
RunUID: r.RunUID,
|
||||
Items: items,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user