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:
@@ -0,0 +1,45 @@
|
||||
package gmsclient
|
||||
|
||||
import (
|
||||
"context"
|
||||
"math/rand"
|
||||
|
||||
"github.com/grafana/grafana/pkg/services/cloudmigration"
|
||||
)
|
||||
|
||||
// NewInMemoryClient returns an implementation of Client that returns canned responses
|
||||
func NewInMemoryClient() Client {
|
||||
return &memoryClientImpl{}
|
||||
}
|
||||
|
||||
type memoryClientImpl struct{}
|
||||
|
||||
func (c *memoryClientImpl) ValidateKey(ctx context.Context, cm cloudmigration.CloudMigrationSession) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *memoryClientImpl) MigrateData(
|
||||
ctx context.Context,
|
||||
cm cloudmigration.CloudMigrationSession,
|
||||
request cloudmigration.MigrateDataRequest,
|
||||
) (*cloudmigration.MigrateDataResponse, error) {
|
||||
result := cloudmigration.MigrateDataResponse{
|
||||
Items: make([]cloudmigration.MigrateDataResponseItem, len(request.Items)),
|
||||
}
|
||||
|
||||
for i, v := range request.Items {
|
||||
result.Items[i] = cloudmigration.MigrateDataResponseItem{
|
||||
Type: v.Type,
|
||||
RefID: v.RefID,
|
||||
Status: cloudmigration.ItemStatusOK,
|
||||
}
|
||||
}
|
||||
|
||||
// simulate flakiness on one random item
|
||||
i := rand.Intn(len(result.Items))
|
||||
failedItem := result.Items[i]
|
||||
failedItem.Status, failedItem.Error = cloudmigration.ItemStatusError, "simulated random error"
|
||||
result.Items[i] = failedItem
|
||||
|
||||
return &result, nil
|
||||
}
|
||||
Reference in New Issue
Block a user