| 
									
										
										
										
											2024-02-26 21:52:16 +08:00
										 |  |  | package cloudmigrationimpl | 
					
						
							| 
									
										
										
										
											2024-01-23 00:09:08 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"context" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	"github.com/grafana/grafana/pkg/api/routing" | 
					
						
							|  |  |  | 	"github.com/grafana/grafana/pkg/infra/db" | 
					
						
							|  |  |  | 	"github.com/grafana/grafana/pkg/infra/log" | 
					
						
							| 
									
										
										
										
											2024-02-26 21:52:16 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/cloudmigration" | 
					
						
							|  |  |  | 	"github.com/grafana/grafana/pkg/services/cloudmigration/api" | 
					
						
							| 
									
										
										
										
											2024-01-23 00:09:08 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/datasources" | 
					
						
							|  |  |  | 	"github.com/grafana/grafana/pkg/services/featuremgmt" | 
					
						
							|  |  |  | 	"github.com/grafana/grafana/pkg/setting" | 
					
						
							|  |  |  | 	"github.com/prometheus/client_golang/prometheus" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // CloudMigrationsServiceImpl Define the Service Implementation.
 | 
					
						
							| 
									
										
										
										
											2024-02-26 21:52:16 +08:00
										 |  |  | type Service struct { | 
					
						
							|  |  |  | 	store store | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-23 00:09:08 +08:00
										 |  |  | 	log log.Logger | 
					
						
							|  |  |  | 	cfg *setting.Cfg | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	features  featuremgmt.FeatureToggles | 
					
						
							|  |  |  | 	dsService datasources.DataSourceService | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-25 20:30:47 +08:00
										 |  |  | 	api *api.CloudMigrationAPI | 
					
						
							| 
									
										
										
										
											2024-02-26 21:52:16 +08:00
										 |  |  | 	// metrics *Metrics
 | 
					
						
							| 
									
										
										
										
											2024-01-23 00:09:08 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-26 21:52:16 +08:00
										 |  |  | var LogPrefix = "cloudmigration.service" | 
					
						
							| 
									
										
										
										
											2024-01-23 00:09:08 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-26 21:52:16 +08:00
										 |  |  | var _ cloudmigration.Service = (*Service)(nil) | 
					
						
							| 
									
										
										
										
											2024-01-23 00:09:08 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | // ProvideService Factory for method used by wire to inject dependencies.
 | 
					
						
							|  |  |  | // builds the service, and api, and configures routes
 | 
					
						
							|  |  |  | func ProvideService( | 
					
						
							|  |  |  | 	cfg *setting.Cfg, | 
					
						
							|  |  |  | 	features featuremgmt.FeatureToggles, | 
					
						
							| 
									
										
										
										
											2024-02-26 21:52:16 +08:00
										 |  |  | 	db db.DB, | 
					
						
							| 
									
										
										
										
											2024-01-23 00:09:08 +08:00
										 |  |  | 	dsService datasources.DataSourceService, | 
					
						
							|  |  |  | 	routeRegister routing.RouteRegister, | 
					
						
							|  |  |  | 	prom prometheus.Registerer, | 
					
						
							| 
									
										
										
										
											2024-02-26 21:52:16 +08:00
										 |  |  | ) cloudmigration.Service { | 
					
						
							| 
									
										
										
										
											2024-01-23 00:09:08 +08:00
										 |  |  | 	if !features.IsEnabledGlobally(featuremgmt.FlagOnPremToCloudMigrations) { | 
					
						
							|  |  |  | 		return &NoopServiceImpl{} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-26 21:52:16 +08:00
										 |  |  | 	s := &Service{ | 
					
						
							|  |  |  | 		store:     &sqlStore{db: db}, | 
					
						
							| 
									
										
										
										
											2024-01-23 00:09:08 +08:00
										 |  |  | 		log:       log.New(LogPrefix), | 
					
						
							|  |  |  | 		cfg:       cfg, | 
					
						
							|  |  |  | 		features:  features, | 
					
						
							|  |  |  | 		dsService: dsService, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	s.api = api.RegisterApi(routeRegister, s) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-26 21:52:16 +08:00
										 |  |  | 	if err := s.registerMetrics(prom); err != nil { | 
					
						
							| 
									
										
										
										
											2024-01-23 00:09:08 +08:00
										 |  |  | 		s.log.Warn("error registering prom metrics", "error", err.Error()) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return s | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-25 20:30:47 +08:00
										 |  |  | func (s *Service) CreateToken(ctx context.Context) error { | 
					
						
							|  |  |  | 	// TODO: Implement method
 | 
					
						
							|  |  |  | 	return nil | 
					
						
							| 
									
										
										
										
											2024-01-23 00:09:08 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2024-03-25 20:30:47 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | func (s *Service) ValidateToken(ctx context.Context, token string) error { | 
					
						
							|  |  |  | 	// TODO: Implement method
 | 
					
						
							|  |  |  | 	return nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (s *Service) SaveEncryptedToken(ctx context.Context, token string) error { | 
					
						
							|  |  |  | 	// TODO: Implement method
 | 
					
						
							|  |  |  | 	return nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (s *Service) GetMigration(ctx context.Context, id int64) (*cloudmigration.CloudMigrationResponse, error) { | 
					
						
							|  |  |  | 	// TODO: Implement method
 | 
					
						
							|  |  |  | 	return nil, nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (s *Service) GetMigrationList(ctx context.Context) ([]cloudmigration.CloudMigrationResponse, error) { | 
					
						
							|  |  |  | 	// TODO: Implement method
 | 
					
						
							|  |  |  | 	return nil, nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (s *Service) CreateMigration(ctx context.Context, cm cloudmigration.CloudMigrationRequest) (*cloudmigration.CloudMigrationResponse, error) { | 
					
						
							|  |  |  | 	// TODO: Implement method
 | 
					
						
							|  |  |  | 	return nil, nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (s *Service) UpdateMigration(ctx context.Context, id int64, cm cloudmigration.CloudMigrationRequest) (*cloudmigration.CloudMigrationResponse, error) { | 
					
						
							|  |  |  | 	// TODO: Implement method
 | 
					
						
							|  |  |  | 	return nil, nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (s *Service) RunMigration(ctx context.Context, uid string) (*cloudmigration.CloudMigrationRun, error) { | 
					
						
							|  |  |  | 	// TODO: Implement method
 | 
					
						
							|  |  |  | 	return nil, nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (s *Service) GetMigrationStatus(ctx context.Context, id string, runID string) (*cloudmigration.CloudMigrationRun, error) { | 
					
						
							|  |  |  | 	// TODO: Implement method
 | 
					
						
							|  |  |  | 	return nil, nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (s *Service) GetMigrationStatusList(ctx context.Context, id string) ([]cloudmigration.CloudMigrationRun, error) { | 
					
						
							|  |  |  | 	// TODO: Implement method
 | 
					
						
							|  |  |  | 	return nil, nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (s *Service) DeleteMigration(ctx context.Context, id string) error { | 
					
						
							|  |  |  | 	// TODO: Implement method
 | 
					
						
							|  |  |  | 	return nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // func (s *Service) MigrateDatasources(ctx context.Context, request *cloudmigration.MigrateDatasourcesRequest) (*cloudmigration.MigrateDatasourcesResponse, error) {
 | 
					
						
							|  |  |  | // 	return s.store.MigrateDatasources(ctx, request)
 | 
					
						
							|  |  |  | // }
 |