[v11.2.x] CloudMigration: Removes snapshot and resources when deleting a session (#92250)
CloudMigration: Removes snapshot and resources when deleting a session (#91548)
(cherry picked from commit e20c7342a9)
Co-authored-by: lean.dev <34773040+leandro-deveikis@users.noreply.github.com>
This commit is contained in:
co-authored by
lean.dev
parent
4115a67a42
commit
a37d107c58
@@ -7,6 +7,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -468,15 +469,16 @@ func (s *Service) GetMigrationRunList(ctx context.Context, migUID string) (*clou
|
||||
return runList, nil
|
||||
}
|
||||
|
||||
func (s *Service) DeleteSession(ctx context.Context, uid string) (*cloudmigration.CloudMigrationSession, error) {
|
||||
c, err := s.store.DeleteMigrationSessionByUID(ctx, uid)
|
||||
func (s *Service) DeleteSession(ctx context.Context, sessionUID string) (*cloudmigration.CloudMigrationSession, error) {
|
||||
session, snapshots, err := s.store.DeleteMigrationSessionByUID(ctx, sessionUID)
|
||||
if err != nil {
|
||||
return c, fmt.Errorf("deleting migration from db: %w", err)
|
||||
s.report(ctx, session, gmsclient.EventDisconnect, 0, err)
|
||||
return nil, fmt.Errorf("deleting migration from db: %w", err)
|
||||
}
|
||||
|
||||
s.report(ctx, c, gmsclient.EventDisconnect, 0, nil)
|
||||
|
||||
return c, nil
|
||||
err = s.deleteLocalFiles(snapshots)
|
||||
s.report(ctx, session, gmsclient.EventDisconnect, 0, err)
|
||||
return session, nil
|
||||
}
|
||||
|
||||
func (s *Service) CreateSnapshot(ctx context.Context, signedInUser *user.SignedInUser, sessionUid string) (*cloudmigration.CloudMigrationSnapshot, error) {
|
||||
@@ -789,6 +791,18 @@ func (s *Service) getLocalEventId(ctx context.Context) (string, error) {
|
||||
return anonId, nil
|
||||
}
|
||||
|
||||
func (s *Service) deleteLocalFiles(snapshots []cloudmigration.CloudMigrationSnapshot) error {
|
||||
var err error
|
||||
for _, snapshot := range snapshots {
|
||||
err = os.RemoveAll(snapshot.LocalDir)
|
||||
if err != nil {
|
||||
// in this case we only log the error, don't return it to continue with the process
|
||||
s.log.Error("deleting migration snapshot files", "err", err)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// getResourcesWithPluginWarnings iterates through each resource and, if a non-core datasource, applies a warning that we only support core
|
||||
func (s *Service) getResourcesWithPluginWarnings(ctx context.Context, results []cloudmigration.CloudMigrationResource) ([]cloudmigration.CloudMigrationResource, error) {
|
||||
dsList, err := s.dsService.GetAllDataSources(ctx, &datasources.GetAllDataSourcesQuery{})
|
||||
|
||||
Reference in New Issue
Block a user