| 
									
										
										
										
											2024-01-23 00:09:08 +08:00
										 |  |  | package api | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"net/http" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	"github.com/grafana/grafana/pkg/api/response" | 
					
						
							|  |  |  | 	"github.com/grafana/grafana/pkg/api/routing" | 
					
						
							|  |  |  | 	"github.com/grafana/grafana/pkg/infra/log" | 
					
						
							| 
									
										
										
										
											2024-03-25 23:43:28 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/infra/tracing" | 
					
						
							| 
									
										
										
										
											2024-01-23 00:09:08 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/middleware" | 
					
						
							| 
									
										
										
										
											2024-02-26 21:52:16 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/cloudmigration" | 
					
						
							| 
									
										
										
										
											2024-01-23 00:09:08 +08:00
										 |  |  | 	contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model" | 
					
						
							| 
									
										
										
										
											2024-05-02 00:29:25 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/util" | 
					
						
							| 
									
										
										
										
											2024-01-23 00:09:08 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/web" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-25 20:30:47 +08:00
										 |  |  | type CloudMigrationAPI struct { | 
					
						
							| 
									
										
										
										
											2024-04-03 19:36:13 +08:00
										 |  |  | 	cloudMigrationService cloudmigration.Service | 
					
						
							|  |  |  | 	routeRegister         routing.RouteRegister | 
					
						
							|  |  |  | 	log                   log.Logger | 
					
						
							|  |  |  | 	tracer                tracing.Tracer | 
					
						
							| 
									
										
										
										
											2024-01-23 00:09:08 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func RegisterApi( | 
					
						
							|  |  |  | 	rr routing.RouteRegister, | 
					
						
							| 
									
										
										
										
											2024-02-26 21:52:16 +08:00
										 |  |  | 	cms cloudmigration.Service, | 
					
						
							| 
									
										
										
										
											2024-03-25 23:43:28 +08:00
										 |  |  | 	tracer tracing.Tracer, | 
					
						
							| 
									
										
										
										
											2024-03-25 20:30:47 +08:00
										 |  |  | ) *CloudMigrationAPI { | 
					
						
							|  |  |  | 	api := &CloudMigrationAPI{ | 
					
						
							| 
									
										
										
										
											2024-04-03 19:36:13 +08:00
										 |  |  | 		log:                   log.New("cloudmigrations.api"), | 
					
						
							|  |  |  | 		routeRegister:         rr, | 
					
						
							|  |  |  | 		cloudMigrationService: cms, | 
					
						
							|  |  |  | 		tracer:                tracer, | 
					
						
							| 
									
										
										
										
											2024-01-23 00:09:08 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	api.registerEndpoints() | 
					
						
							|  |  |  | 	return api | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-02 00:29:25 +08:00
										 |  |  | // registerEndpoints Registers Endpoints on Grafana Router
 | 
					
						
							| 
									
										
										
										
											2024-03-25 20:30:47 +08:00
										 |  |  | 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)) | 
					
						
							| 
									
										
										
										
											2024-05-02 00:29:25 +08:00
										 |  |  | 		cloudMigrationRoute.Get("/migration/:uid", routing.Wrap(cma.GetMigration)) | 
					
						
							|  |  |  | 		cloudMigrationRoute.Delete("/migration/:uid", routing.Wrap(cma.DeleteMigration)) | 
					
						
							|  |  |  | 		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)) | 
					
						
							| 
									
										
										
										
											2024-03-25 23:43:28 +08:00
										 |  |  | 		cloudMigrationRoute.Post("/token", routing.Wrap(cma.CreateToken)) | 
					
						
							| 
									
										
										
										
											2024-04-04 03:43:48 +08:00
										 |  |  | 	}, middleware.ReqOrgAdmin) | 
					
						
							| 
									
										
										
										
											2024-01-23 00:09:08 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-02 19:57:42 +08:00
										 |  |  | // swagger:route POST /cloudmigration/token migrations createCloudMigrationToken
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Create gcom access token.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Responses:
 | 
					
						
							|  |  |  | // 200: cloudMigrationCreateTokenResponse
 | 
					
						
							|  |  |  | // 401: unauthorisedError
 | 
					
						
							|  |  |  | // 403: forbiddenError
 | 
					
						
							|  |  |  | // 500: internalServerError
 | 
					
						
							| 
									
										
										
										
											2024-03-25 20:30:47 +08:00
										 |  |  | func (cma *CloudMigrationAPI) CreateToken(c *contextmodel.ReqContext) response.Response { | 
					
						
							| 
									
										
										
										
											2024-03-25 23:43:28 +08:00
										 |  |  | 	ctx, span := cma.tracer.Start(c.Req.Context(), "MigrationAPI.CreateAccessToken") | 
					
						
							|  |  |  | 	defer span.End() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	logger := cma.log.FromContext(ctx) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-03 19:36:13 +08:00
										 |  |  | 	resp, err := cma.cloudMigrationService.CreateToken(ctx) | 
					
						
							| 
									
										
										
										
											2024-03-25 20:30:47 +08:00
										 |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2024-03-25 23:43:28 +08:00
										 |  |  | 		logger.Error("creating gcom access token", "err", err.Error()) | 
					
						
							| 
									
										
										
										
											2024-05-13 12:22:46 +08:00
										 |  |  | 		return response.ErrOrFallback(http.StatusInternalServerError, "creating gcom access token", err) | 
					
						
							| 
									
										
										
										
											2024-03-25 20:30:47 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2024-03-25 23:43:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-13 12:22:19 +08:00
										 |  |  | 	return response.JSON(http.StatusOK, CreateAccessTokenResponseDTO(resp)) | 
					
						
							| 
									
										
										
										
											2024-03-25 20:30:47 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-02 19:57:42 +08:00
										 |  |  | // swagger:route GET /cloudmigration/migration migrations getMigrationList
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Get a list of all cloud migrations.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Responses:
 | 
					
						
							|  |  |  | // 200: cloudMigrationListResponse
 | 
					
						
							|  |  |  | // 401: unauthorisedError
 | 
					
						
							|  |  |  | // 403: forbiddenError
 | 
					
						
							|  |  |  | // 500: internalServerError
 | 
					
						
							| 
									
										
										
										
											2024-03-25 20:30:47 +08:00
										 |  |  | func (cma *CloudMigrationAPI) GetMigrationList(c *contextmodel.ReqContext) response.Response { | 
					
						
							| 
									
										
										
										
											2024-04-03 19:36:13 +08:00
										 |  |  | 	ctx, span := cma.tracer.Start(c.Req.Context(), "MigrationAPI.GetMigrationList") | 
					
						
							|  |  |  | 	defer span.End() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	cloudMigrations, err := cma.cloudMigrationService.GetMigrationList(ctx) | 
					
						
							| 
									
										
										
										
											2024-03-25 20:30:47 +08:00
										 |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2024-05-13 12:22:46 +08:00
										 |  |  | 		return response.ErrOrFallback(http.StatusInternalServerError, "migration list error", err) | 
					
						
							| 
									
										
										
										
											2024-03-25 20:30:47 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2024-04-02 19:57:42 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-25 20:30:47 +08:00
										 |  |  | 	return response.JSON(http.StatusOK, cloudMigrations) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-02 00:29:25 +08:00
										 |  |  | // swagger:route GET /cloudmigration/migration/{uid} migrations getCloudMigration
 | 
					
						
							| 
									
										
										
										
											2024-04-02 19:57:42 +08:00
										 |  |  | //
 | 
					
						
							|  |  |  | // Get a cloud migration.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // It returns migrations that has been created.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Responses:
 | 
					
						
							|  |  |  | // 200: cloudMigrationResponse
 | 
					
						
							|  |  |  | // 401: unauthorisedError
 | 
					
						
							|  |  |  | // 403: forbiddenError
 | 
					
						
							|  |  |  | // 500: internalServerError
 | 
					
						
							| 
									
										
										
										
											2024-03-25 20:30:47 +08:00
										 |  |  | func (cma *CloudMigrationAPI) GetMigration(c *contextmodel.ReqContext) response.Response { | 
					
						
							| 
									
										
										
										
											2024-04-03 19:36:13 +08:00
										 |  |  | 	ctx, span := cma.tracer.Start(c.Req.Context(), "MigrationAPI.GetMigration") | 
					
						
							|  |  |  | 	defer span.End() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-02 00:29:25 +08:00
										 |  |  | 	uid := web.Params(c.Req)[":uid"] | 
					
						
							|  |  |  | 	if err := util.ValidateUID(uid); err != nil { | 
					
						
							|  |  |  | 		return response.Error(http.StatusBadRequest, "invalid migration uid", err) | 
					
						
							| 
									
										
										
										
											2024-03-25 20:30:47 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2024-05-02 00:29:25 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	cloudMigration, err := cma.cloudMigrationService.GetMigration(ctx, uid) | 
					
						
							| 
									
										
										
										
											2024-03-25 20:30:47 +08:00
										 |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2024-05-13 12:22:46 +08:00
										 |  |  | 		return response.ErrOrFallback(http.StatusNotFound, "migration not found", err) | 
					
						
							| 
									
										
										
										
											2024-03-25 20:30:47 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	return response.JSON(http.StatusOK, cloudMigration) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-02 19:57:42 +08:00
										 |  |  | // swagger:parameters getCloudMigration
 | 
					
						
							|  |  |  | type GetCloudMigrationRequest struct { | 
					
						
							| 
									
										
										
										
											2024-05-02 00:29:25 +08:00
										 |  |  | 	// UID of a migration
 | 
					
						
							| 
									
										
										
										
											2024-04-02 19:57:42 +08:00
										 |  |  | 	//
 | 
					
						
							|  |  |  | 	// in: path
 | 
					
						
							| 
									
										
										
										
											2024-05-02 00:29:25 +08:00
										 |  |  | 	UID string `json:"uid"` | 
					
						
							| 
									
										
										
										
											2024-04-02 19:57:42 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // swagger:route POST /cloudmigration/migration migrations createMigration
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Create a migration.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Responses:
 | 
					
						
							|  |  |  | // 200: cloudMigrationResponse
 | 
					
						
							|  |  |  | // 401: unauthorisedError
 | 
					
						
							|  |  |  | // 403: forbiddenError
 | 
					
						
							|  |  |  | // 500: internalServerError
 | 
					
						
							| 
									
										
										
										
											2024-03-25 20:30:47 +08:00
										 |  |  | func (cma *CloudMigrationAPI) CreateMigration(c *contextmodel.ReqContext) response.Response { | 
					
						
							| 
									
										
										
										
											2024-04-03 19:36:13 +08:00
										 |  |  | 	ctx, span := cma.tracer.Start(c.Req.Context(), "MigrationAPI.CreateMigration") | 
					
						
							|  |  |  | 	defer span.End() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-25 20:30:47 +08:00
										 |  |  | 	cmd := cloudmigration.CloudMigrationRequest{} | 
					
						
							|  |  |  | 	if err := web.Bind(c.Req, &cmd); err != nil { | 
					
						
							| 
									
										
										
										
											2024-05-13 12:22:46 +08:00
										 |  |  | 		return response.ErrOrFallback(http.StatusBadRequest, "bad request data", err) | 
					
						
							| 
									
										
										
										
											2024-01-23 00:09:08 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2024-04-03 19:36:13 +08:00
										 |  |  | 	cloudMigration, err := cma.cloudMigrationService.CreateMigration(ctx, cmd) | 
					
						
							| 
									
										
										
										
											2024-03-25 20:30:47 +08:00
										 |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2024-05-13 12:22:46 +08:00
										 |  |  | 		return response.ErrOrFallback(http.StatusInternalServerError, "migration creation error", err) | 
					
						
							| 
									
										
										
										
											2024-03-25 20:30:47 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	return response.JSON(http.StatusOK, cloudMigration) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-02 00:29:25 +08:00
										 |  |  | // swagger:route POST /cloudmigration/migration/{uid}/run migrations runCloudMigration
 | 
					
						
							| 
									
										
										
										
											2024-04-02 19:57:42 +08:00
										 |  |  | //
 | 
					
						
							|  |  |  | // Trigger the run of a migration to the Grafana Cloud.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // It returns migrations that has been created.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Responses:
 | 
					
						
							|  |  |  | // 200: cloudMigrationRunResponse
 | 
					
						
							|  |  |  | // 401: unauthorisedError
 | 
					
						
							|  |  |  | // 403: forbiddenError
 | 
					
						
							|  |  |  | // 500: internalServerError
 | 
					
						
							| 
									
										
										
										
											2024-03-25 20:30:47 +08:00
										 |  |  | func (cma *CloudMigrationAPI) RunMigration(c *contextmodel.ReqContext) response.Response { | 
					
						
							| 
									
										
										
										
											2024-04-03 19:36:13 +08:00
										 |  |  | 	ctx, span := cma.tracer.Start(c.Req.Context(), "MigrationAPI.RunMigration") | 
					
						
							|  |  |  | 	defer span.End() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-02 00:29:25 +08:00
										 |  |  | 	uid := web.Params(c.Req)[":uid"] | 
					
						
							|  |  |  | 	if err := util.ValidateUID(uid); err != nil { | 
					
						
							| 
									
										
										
										
											2024-05-13 12:22:46 +08:00
										 |  |  | 		return response.ErrOrFallback(http.StatusBadRequest, "invalid migration uid", err) | 
					
						
							| 
									
										
										
										
											2024-04-03 19:36:13 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-02 00:29:25 +08:00
										 |  |  | 	result, err := cma.cloudMigrationService.RunMigration(ctx, uid) | 
					
						
							| 
									
										
										
										
											2024-04-03 19:36:13 +08:00
										 |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2024-05-13 12:22:46 +08:00
										 |  |  | 		return response.ErrOrFallback(http.StatusInternalServerError, "migration run error", err) | 
					
						
							| 
									
										
										
										
											2024-04-03 19:36:13 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return response.JSON(http.StatusOK, result) | 
					
						
							| 
									
										
										
										
											2024-03-25 20:30:47 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2024-01-23 00:09:08 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-02 19:57:42 +08:00
										 |  |  | // swagger:parameters runCloudMigration
 | 
					
						
							|  |  |  | type RunCloudMigrationRequest struct { | 
					
						
							| 
									
										
										
										
											2024-05-02 00:29:25 +08:00
										 |  |  | 	// UID of a migration
 | 
					
						
							| 
									
										
										
										
											2024-04-02 19:57:42 +08:00
										 |  |  | 	//
 | 
					
						
							|  |  |  | 	// in: path
 | 
					
						
							| 
									
										
										
										
											2024-05-02 00:29:25 +08:00
										 |  |  | 	UID string `json:"uid"` | 
					
						
							| 
									
										
										
										
											2024-04-02 19:57:42 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-02 00:29:25 +08:00
										 |  |  | // swagger:route GET /cloudmigration/migration/run/{runUID} migrations getCloudMigrationRun
 | 
					
						
							| 
									
										
										
										
											2024-04-02 19:57:42 +08:00
										 |  |  | //
 | 
					
						
							|  |  |  | // Get the result of a single migration run.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Responses:
 | 
					
						
							|  |  |  | // 200: cloudMigrationRunResponse
 | 
					
						
							|  |  |  | // 401: unauthorisedError
 | 
					
						
							|  |  |  | // 403: forbiddenError
 | 
					
						
							|  |  |  | // 500: internalServerError
 | 
					
						
							| 
									
										
										
										
											2024-03-25 20:30:47 +08:00
										 |  |  | func (cma *CloudMigrationAPI) GetMigrationRun(c *contextmodel.ReqContext) response.Response { | 
					
						
							| 
									
										
										
										
											2024-04-03 19:36:13 +08:00
										 |  |  | 	ctx, span := cma.tracer.Start(c.Req.Context(), "MigrationAPI.GetMigrationRun") | 
					
						
							|  |  |  | 	defer span.End() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-02 00:29:25 +08:00
										 |  |  | 	runUid := web.Params(c.Req)[":runUID"] | 
					
						
							|  |  |  | 	if err := util.ValidateUID(runUid); err != nil { | 
					
						
							| 
									
										
										
										
											2024-05-13 12:22:46 +08:00
										 |  |  | 		return response.ErrOrFallback(http.StatusBadRequest, "invalid runUID", err) | 
					
						
							| 
									
										
										
										
											2024-05-02 00:29:25 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	migrationStatus, err := cma.cloudMigrationService.GetMigrationStatus(ctx, runUid) | 
					
						
							| 
									
										
										
										
											2024-01-23 00:09:08 +08:00
										 |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2024-05-13 12:22:46 +08:00
										 |  |  | 		return response.ErrOrFallback(http.StatusInternalServerError, "migration status error", err) | 
					
						
							| 
									
										
										
										
											2024-01-23 00:09:08 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2024-04-04 00:47:49 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	runResponse, err := migrationStatus.ToResponse() | 
					
						
							|  |  |  | 	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) | 
					
						
							| 
									
										
										
										
											2024-03-25 20:30:47 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2024-01-23 00:09:08 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-02 19:57:42 +08:00
										 |  |  | // swagger:parameters getCloudMigrationRun
 | 
					
						
							|  |  |  | type GetMigrationRunParams struct { | 
					
						
							| 
									
										
										
										
											2024-05-02 00:29:25 +08:00
										 |  |  | 	// RunUID of a migration run
 | 
					
						
							| 
									
										
										
										
											2024-04-02 19:57:42 +08:00
										 |  |  | 	//
 | 
					
						
							|  |  |  | 	// in: path
 | 
					
						
							| 
									
										
										
										
											2024-05-02 00:29:25 +08:00
										 |  |  | 	RunUID string `json:"runUID"` | 
					
						
							| 
									
										
										
										
											2024-04-02 19:57:42 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-02 00:29:25 +08:00
										 |  |  | // swagger:route GET /cloudmigration/migration/{uid}/run migrations getCloudMigrationRunList
 | 
					
						
							| 
									
										
										
										
											2024-04-02 19:57:42 +08:00
										 |  |  | //
 | 
					
						
							|  |  |  | // Get a list of migration runs for a migration.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Responses:
 | 
					
						
							|  |  |  | // 200: cloudMigrationRunListResponse
 | 
					
						
							|  |  |  | // 401: unauthorisedError
 | 
					
						
							|  |  |  | // 403: forbiddenError
 | 
					
						
							|  |  |  | // 500: internalServerError
 | 
					
						
							| 
									
										
										
										
											2024-03-25 20:30:47 +08:00
										 |  |  | func (cma *CloudMigrationAPI) GetMigrationRunList(c *contextmodel.ReqContext) response.Response { | 
					
						
							| 
									
										
										
										
											2024-04-03 19:36:13 +08:00
										 |  |  | 	ctx, span := cma.tracer.Start(c.Req.Context(), "MigrationAPI.GetMigrationRunList") | 
					
						
							|  |  |  | 	defer span.End() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-02 00:29:25 +08:00
										 |  |  | 	uid := web.Params(c.Req)[":uid"] | 
					
						
							|  |  |  | 	if err := util.ValidateUID(uid); err != nil { | 
					
						
							| 
									
										
										
										
											2024-05-13 12:22:46 +08:00
										 |  |  | 		return response.ErrOrFallback(http.StatusBadRequest, "invalid migration uid", err) | 
					
						
							| 
									
										
										
										
											2024-05-02 00:29:25 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	runList, err := cma.cloudMigrationService.GetMigrationRunList(ctx, uid) | 
					
						
							| 
									
										
										
										
											2024-03-25 20:30:47 +08:00
										 |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2024-05-13 12:22:46 +08:00
										 |  |  | 		return response.ErrOrFallback(http.StatusInternalServerError, "list migration status error", err) | 
					
						
							| 
									
										
										
										
											2024-04-03 19:36:13 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-02 19:57:42 +08:00
										 |  |  | 	return response.JSON(http.StatusOK, runList) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // swagger:parameters getCloudMigrationRunList
 | 
					
						
							|  |  |  | type GetCloudMigrationRunList struct { | 
					
						
							| 
									
										
										
										
											2024-05-02 00:29:25 +08:00
										 |  |  | 	// UID of a migration
 | 
					
						
							| 
									
										
										
										
											2024-04-02 19:57:42 +08:00
										 |  |  | 	//
 | 
					
						
							|  |  |  | 	// in: path
 | 
					
						
							| 
									
										
										
										
											2024-05-02 00:29:25 +08:00
										 |  |  | 	UID string `json:"uid"` | 
					
						
							| 
									
										
										
										
											2024-03-25 20:30:47 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-02 00:29:25 +08:00
										 |  |  | // swagger:route DELETE /cloudmigration/migration/{uid} migrations deleteCloudMigration
 | 
					
						
							| 
									
										
										
										
											2024-04-02 19:57:42 +08:00
										 |  |  | //
 | 
					
						
							|  |  |  | // Delete a migration.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Responses:
 | 
					
						
							|  |  |  | // 200
 | 
					
						
							|  |  |  | // 401: unauthorisedError
 | 
					
						
							|  |  |  | // 403: forbiddenError
 | 
					
						
							|  |  |  | // 500: internalServerError
 | 
					
						
							| 
									
										
										
										
											2024-03-25 20:30:47 +08:00
										 |  |  | func (cma *CloudMigrationAPI) DeleteMigration(c *contextmodel.ReqContext) response.Response { | 
					
						
							| 
									
										
										
										
											2024-04-03 19:36:13 +08:00
										 |  |  | 	ctx, span := cma.tracer.Start(c.Req.Context(), "MigrationAPI.DeleteMigration") | 
					
						
							|  |  |  | 	defer span.End() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-02 00:29:25 +08:00
										 |  |  | 	uid := web.Params(c.Req)[":uid"] | 
					
						
							|  |  |  | 	if err := util.ValidateUID(uid); err != nil { | 
					
						
							| 
									
										
										
										
											2024-05-13 12:22:46 +08:00
										 |  |  | 		return response.ErrOrFallback(http.StatusBadRequest, "invalid migration uid", err) | 
					
						
							| 
									
										
										
										
											2024-04-03 19:36:13 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2024-05-02 00:29:25 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	_, err := cma.cloudMigrationService.DeleteMigration(ctx, uid) | 
					
						
							| 
									
										
										
										
											2024-03-25 20:30:47 +08:00
										 |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2024-05-13 12:22:46 +08:00
										 |  |  | 		return response.ErrOrFallback(http.StatusInternalServerError, "migration delete error", err) | 
					
						
							| 
									
										
										
										
											2024-03-25 20:30:47 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	return response.Empty(http.StatusOK) | 
					
						
							| 
									
										
										
										
											2024-01-23 00:09:08 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2024-04-02 19:57:42 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | // swagger:parameters deleteCloudMigration
 | 
					
						
							|  |  |  | type DeleteMigrationRequest struct { | 
					
						
							| 
									
										
										
										
											2024-05-02 00:29:25 +08:00
										 |  |  | 	// UID of a migration
 | 
					
						
							| 
									
										
										
										
											2024-04-02 19:57:42 +08:00
										 |  |  | 	//
 | 
					
						
							|  |  |  | 	// in: path
 | 
					
						
							| 
									
										
										
										
											2024-05-02 00:29:25 +08:00
										 |  |  | 	UID string `json:"uid"` | 
					
						
							| 
									
										
										
										
											2024-04-02 19:57:42 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // swagger:response cloudMigrationRunResponse
 | 
					
						
							|  |  |  | type CloudMigrationRunResponse struct { | 
					
						
							|  |  |  | 	// in: body
 | 
					
						
							| 
									
										
										
										
											2024-04-03 19:36:13 +08:00
										 |  |  | 	Body cloudmigration.MigrateDataResponseDTO | 
					
						
							| 
									
										
										
										
											2024-04-02 19:57:42 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // swagger:response cloudMigrationListResponse
 | 
					
						
							|  |  |  | type CloudMigrationListResponse struct { | 
					
						
							|  |  |  | 	// in: body
 | 
					
						
							|  |  |  | 	Body cloudmigration.CloudMigrationListResponse | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // swagger:response cloudMigrationResponse
 | 
					
						
							|  |  |  | type CloudMigrationResponse struct { | 
					
						
							|  |  |  | 	// in: body
 | 
					
						
							|  |  |  | 	Body cloudmigration.CloudMigrationResponse | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // swagger:response cloudMigrationRunListResponse
 | 
					
						
							|  |  |  | type CloudMigrationRunListResponse struct { | 
					
						
							|  |  |  | 	// in: body
 | 
					
						
							|  |  |  | 	Body cloudmigration.CloudMigrationRunList | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // swagger:response cloudMigrationCreateTokenResponse
 | 
					
						
							|  |  |  | type CloudMigrationCreateTokenResponse struct { | 
					
						
							|  |  |  | 	// in: body
 | 
					
						
							| 
									
										
										
										
											2024-05-13 12:22:19 +08:00
										 |  |  | 	Body CreateAccessTokenResponseDTO | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type CreateAccessTokenResponseDTO struct { | 
					
						
							|  |  |  | 	Token string `json:"token"` | 
					
						
							| 
									
										
										
										
											2024-04-02 19:57:42 +08:00
										 |  |  | } |