Return details from restore function (#4712)
Minor cleanup that will also help reduce diff for future changes. Instead of taking in a details builder and adding to it during restore, just create a local details builder and return the built details to the caller --- #### Does this PR need a docs update or release note? - [ ] ✅ Yes, it's included - [ ] 🕐 Yes, but in a later PR - [x] ⛔ No #### Type of change - [ ] 🌻 Feature - [ ] 🐛 Bugfix - [ ] 🗺️ Documentation - [ ] 🤖 Supportability/Tests - [ ] 💻 CI/Deployment - [x] 🧹 Tech Debt/Cleanup #### Issue(s) * #4254 #### Test Plan - [ ] 💪 Manual - [x] ⚡ Unit test - [x] 💚 E2E
This commit is contained in:
parent
a3fe9d8d2e
commit
dac4c70f61
@ -44,49 +44,45 @@ func (ctrl *Controller) ConsumeRestoreCollections(
|
|||||||
var (
|
var (
|
||||||
service = rcc.Selector.PathService()
|
service = rcc.Selector.PathService()
|
||||||
status *support.ControllerOperationStatus
|
status *support.ControllerOperationStatus
|
||||||
deets = &details.Builder{}
|
deets *details.Details
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
|
|
||||||
switch service {
|
switch service {
|
||||||
case path.ExchangeService:
|
case path.ExchangeService:
|
||||||
status, err = exchange.ConsumeRestoreCollections(
|
deets, status, err = exchange.ConsumeRestoreCollections(
|
||||||
ctx,
|
ctx,
|
||||||
ctrl.AC,
|
ctrl.AC,
|
||||||
rcc,
|
rcc,
|
||||||
dcs,
|
dcs,
|
||||||
deets,
|
|
||||||
errs,
|
errs,
|
||||||
ctr)
|
ctr)
|
||||||
case path.OneDriveService:
|
case path.OneDriveService:
|
||||||
status, err = onedrive.ConsumeRestoreCollections(
|
deets, status, err = onedrive.ConsumeRestoreCollections(
|
||||||
ctx,
|
ctx,
|
||||||
drive.NewUserDriveRestoreHandler(ctrl.AC),
|
drive.NewUserDriveRestoreHandler(ctrl.AC),
|
||||||
rcc,
|
rcc,
|
||||||
ctrl.backupDriveIDNames,
|
ctrl.backupDriveIDNames,
|
||||||
dcs,
|
dcs,
|
||||||
deets,
|
|
||||||
errs,
|
errs,
|
||||||
ctr)
|
ctr)
|
||||||
case path.SharePointService:
|
case path.SharePointService:
|
||||||
status, err = sharepoint.ConsumeRestoreCollections(
|
deets, status, err = sharepoint.ConsumeRestoreCollections(
|
||||||
ctx,
|
ctx,
|
||||||
rcc,
|
rcc,
|
||||||
ctrl.AC,
|
ctrl.AC,
|
||||||
ctrl.backupDriveIDNames,
|
ctrl.backupDriveIDNames,
|
||||||
dcs,
|
dcs,
|
||||||
deets,
|
|
||||||
errs,
|
errs,
|
||||||
ctr)
|
ctr)
|
||||||
case path.GroupsService:
|
case path.GroupsService:
|
||||||
status, err = groups.ConsumeRestoreCollections(
|
deets, status, err = groups.ConsumeRestoreCollections(
|
||||||
ctx,
|
ctx,
|
||||||
rcc,
|
rcc,
|
||||||
ctrl.AC,
|
ctrl.AC,
|
||||||
ctrl.backupDriveIDNames,
|
ctrl.backupDriveIDNames,
|
||||||
ctrl.backupSiteIDWebURL,
|
ctrl.backupSiteIDWebURL,
|
||||||
dcs,
|
dcs,
|
||||||
deets,
|
|
||||||
errs,
|
errs,
|
||||||
ctr)
|
ctr)
|
||||||
default:
|
default:
|
||||||
@ -96,5 +92,5 @@ func (ctrl *Controller) ConsumeRestoreCollections(
|
|||||||
ctrl.incrementAwaitingMessages()
|
ctrl.incrementAwaitingMessages()
|
||||||
ctrl.UpdateStatus(status)
|
ctrl.UpdateStatus(status)
|
||||||
|
|
||||||
return deets.Details(), err
|
return deets, err
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,15 +24,15 @@ func ConsumeRestoreCollections(
|
|||||||
ac api.Client,
|
ac api.Client,
|
||||||
rcc inject.RestoreConsumerConfig,
|
rcc inject.RestoreConsumerConfig,
|
||||||
dcs []data.RestoreCollection,
|
dcs []data.RestoreCollection,
|
||||||
deets *details.Builder,
|
|
||||||
errs *fault.Bus,
|
errs *fault.Bus,
|
||||||
ctr *count.Bus,
|
ctr *count.Bus,
|
||||||
) (*support.ControllerOperationStatus, error) {
|
) (*details.Details, *support.ControllerOperationStatus, error) {
|
||||||
if len(dcs) == 0 {
|
if len(dcs) == 0 {
|
||||||
return support.CreateStatus(ctx, support.Restore, 0, support.CollectionMetrics{}, ""), nil
|
return nil, support.CreateStatus(ctx, support.Restore, 0, support.CollectionMetrics{}, ""), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
deets = &details.Builder{}
|
||||||
resourceID = rcc.ProtectedResource.ID()
|
resourceID = rcc.ProtectedResource.ID()
|
||||||
directoryCache = make(map[path.CategoryType]graph.ContainerResolver)
|
directoryCache = make(map[path.CategoryType]graph.ContainerResolver)
|
||||||
handlers = exchange.RestoreHandlers(ac)
|
handlers = exchange.RestoreHandlers(ac)
|
||||||
@ -62,7 +62,7 @@ func ConsumeRestoreCollections(
|
|||||||
if directoryCache[category] == nil {
|
if directoryCache[category] == nil {
|
||||||
gcr := handler.NewContainerCache(resourceID)
|
gcr := handler.NewContainerCache(resourceID)
|
||||||
if err := gcr.Populate(ictx, errs, handler.DefaultRootContainer()); err != nil {
|
if err := gcr.Populate(ictx, errs, handler.DefaultRootContainer()); err != nil {
|
||||||
return nil, clues.Wrap(err, "populating container cache")
|
return nil, nil, clues.Wrap(err, "populating container cache")
|
||||||
}
|
}
|
||||||
|
|
||||||
directoryCache[category] = gcr
|
directoryCache[category] = gcr
|
||||||
@ -119,5 +119,5 @@ func ConsumeRestoreCollections(
|
|||||||
metrics,
|
metrics,
|
||||||
rcc.RestoreConfig.Location)
|
rcc.RestoreConfig.Location)
|
||||||
|
|
||||||
return status, el.Failure()
|
return deets.Details(), status, el.Failure()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,11 +32,11 @@ func ConsumeRestoreCollections(
|
|||||||
backupDriveIDNames idname.Cacher,
|
backupDriveIDNames idname.Cacher,
|
||||||
backupSiteIDWebURL idname.Cacher,
|
backupSiteIDWebURL idname.Cacher,
|
||||||
dcs []data.RestoreCollection,
|
dcs []data.RestoreCollection,
|
||||||
deets *details.Builder,
|
|
||||||
errs *fault.Bus,
|
errs *fault.Bus,
|
||||||
ctr *count.Bus,
|
ctr *count.Bus,
|
||||||
) (*support.ControllerOperationStatus, error) {
|
) (*details.Details, *support.ControllerOperationStatus, error) {
|
||||||
var (
|
var (
|
||||||
|
deets = &details.Builder{}
|
||||||
restoreMetrics support.CollectionMetrics
|
restoreMetrics support.CollectionMetrics
|
||||||
caches = drive.NewRestoreCaches(backupDriveIDNames)
|
caches = drive.NewRestoreCaches(backupDriveIDNames)
|
||||||
lrh = drive.NewSiteRestoreHandler(ac, rcc.Selector.PathService())
|
lrh = drive.NewSiteRestoreHandler(ac, rcc.Selector.PathService())
|
||||||
@ -97,7 +97,7 @@ func ConsumeRestoreCollections(
|
|||||||
|
|
||||||
err = caches.Populate(ictx, lrh, srcc.ProtectedResource.ID())
|
err = caches.Populate(ictx, lrh, srcc.ProtectedResource.ID())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, clues.Wrap(err, "initializing restore caches")
|
return nil, nil, clues.Wrap(err, "initializing restore caches")
|
||||||
}
|
}
|
||||||
|
|
||||||
metrics, err = drive.RestoreCollection(
|
metrics, err = drive.RestoreCollection(
|
||||||
@ -114,7 +114,7 @@ func ConsumeRestoreCollections(
|
|||||||
// Message cannot be restored as of now using Graph API.
|
// Message cannot be restored as of now using Graph API.
|
||||||
logger.Ctx(ictx).Debug("Skipping restore for channel messages")
|
logger.Ctx(ictx).Debug("Skipping restore for channel messages")
|
||||||
default:
|
default:
|
||||||
return nil, clues.NewWC(ictx, "data category not supported").
|
return nil, nil, clues.NewWC(ictx, "data category not supported").
|
||||||
With("category", category)
|
With("category", category)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,7 +136,7 @@ func ConsumeRestoreCollections(
|
|||||||
restoreMetrics,
|
restoreMetrics,
|
||||||
rcc.RestoreConfig.Location)
|
rcc.RestoreConfig.Location)
|
||||||
|
|
||||||
return status, el.Failure()
|
return deets.Details(), status, el.Failure()
|
||||||
}
|
}
|
||||||
|
|
||||||
func getSiteName(
|
func getSiteName(
|
||||||
|
|||||||
@ -53,14 +53,13 @@ func (suite *GroupsUnitSuite) TestConsumeRestoreCollections_noErrorOnGroups() {
|
|||||||
mock.Collection{Path: pth},
|
mock.Collection{Path: pth},
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = ConsumeRestoreCollections(
|
_, _, err = ConsumeRestoreCollections(
|
||||||
ctx,
|
ctx,
|
||||||
rcc,
|
rcc,
|
||||||
api.Client{},
|
api.Client{},
|
||||||
idname.NewCache(map[string]string{}),
|
idname.NewCache(map[string]string{}),
|
||||||
idname.NewCache(map[string]string{}),
|
idname.NewCache(map[string]string{}),
|
||||||
dcs,
|
dcs,
|
||||||
nil,
|
|
||||||
fault.New(false),
|
fault.New(false),
|
||||||
nil)
|
nil)
|
||||||
assert.NoError(t, err, "Groups Channels restore")
|
assert.NoError(t, err, "Groups Channels restore")
|
||||||
|
|||||||
@ -26,11 +26,11 @@ func ConsumeRestoreCollections(
|
|||||||
rcc inject.RestoreConsumerConfig,
|
rcc inject.RestoreConsumerConfig,
|
||||||
backupDriveIDNames idname.Cacher,
|
backupDriveIDNames idname.Cacher,
|
||||||
dcs []data.RestoreCollection,
|
dcs []data.RestoreCollection,
|
||||||
deets *details.Builder,
|
|
||||||
errs *fault.Bus,
|
errs *fault.Bus,
|
||||||
ctr *count.Bus,
|
ctr *count.Bus,
|
||||||
) (*support.ControllerOperationStatus, error) {
|
) (*details.Details, *support.ControllerOperationStatus, error) {
|
||||||
var (
|
var (
|
||||||
|
deets = &details.Builder{}
|
||||||
restoreMetrics support.CollectionMetrics
|
restoreMetrics support.CollectionMetrics
|
||||||
el = errs.Local()
|
el = errs.Local()
|
||||||
caches = drive.NewRestoreCaches(backupDriveIDNames)
|
caches = drive.NewRestoreCaches(backupDriveIDNames)
|
||||||
@ -41,7 +41,7 @@ func ConsumeRestoreCollections(
|
|||||||
|
|
||||||
err := caches.Populate(ctx, rh, rcc.ProtectedResource.ID())
|
err := caches.Populate(ctx, rh, rcc.ProtectedResource.ID())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, clues.Wrap(err, "initializing restore caches")
|
return nil, nil, clues.Wrap(err, "initializing restore caches")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reorder collections so that the parents directories are created
|
// Reorder collections so that the parents directories are created
|
||||||
@ -91,7 +91,7 @@ func ConsumeRestoreCollections(
|
|||||||
restoreMetrics,
|
restoreMetrics,
|
||||||
rcc.RestoreConfig.Location)
|
rcc.RestoreConfig.Location)
|
||||||
|
|
||||||
return status, el.Failure()
|
return deets.Details(), status, el.Failure()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Augment restore path to add extra files(meta) needed for restore as
|
// Augment restore path to add extra files(meta) needed for restore as
|
||||||
|
|||||||
@ -28,11 +28,11 @@ func ConsumeRestoreCollections(
|
|||||||
ac api.Client,
|
ac api.Client,
|
||||||
backupDriveIDNames idname.Cacher,
|
backupDriveIDNames idname.Cacher,
|
||||||
dcs []data.RestoreCollection,
|
dcs []data.RestoreCollection,
|
||||||
deets *details.Builder,
|
|
||||||
errs *fault.Bus,
|
errs *fault.Bus,
|
||||||
ctr *count.Bus,
|
ctr *count.Bus,
|
||||||
) (*support.ControllerOperationStatus, error) {
|
) (*details.Details, *support.ControllerOperationStatus, error) {
|
||||||
var (
|
var (
|
||||||
|
deets = &details.Builder{}
|
||||||
lrh = drive.NewSiteRestoreHandler(ac, rcc.Selector.PathService())
|
lrh = drive.NewSiteRestoreHandler(ac, rcc.Selector.PathService())
|
||||||
restoreMetrics support.CollectionMetrics
|
restoreMetrics support.CollectionMetrics
|
||||||
caches = drive.NewRestoreCaches(backupDriveIDNames)
|
caches = drive.NewRestoreCaches(backupDriveIDNames)
|
||||||
@ -41,7 +41,7 @@ func ConsumeRestoreCollections(
|
|||||||
|
|
||||||
err := caches.Populate(ctx, lrh, rcc.ProtectedResource.ID())
|
err := caches.Populate(ctx, lrh, rcc.ProtectedResource.ID())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, clues.Wrap(err, "initializing restore caches")
|
return nil, nil, clues.Wrap(err, "initializing restore caches")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reorder collections so that the parents directories are created
|
// Reorder collections so that the parents directories are created
|
||||||
@ -97,7 +97,7 @@ func ConsumeRestoreCollections(
|
|||||||
errs)
|
errs)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return nil, clues.Wrap(clues.New(category.String()), "category not supported").With("category", category)
|
return nil, nil, clues.Wrap(clues.New(category.String()), "category not supported").With("category", category)
|
||||||
}
|
}
|
||||||
|
|
||||||
restoreMetrics = support.CombineMetrics(restoreMetrics, metrics)
|
restoreMetrics = support.CombineMetrics(restoreMetrics, metrics)
|
||||||
@ -118,5 +118,5 @@ func ConsumeRestoreCollections(
|
|||||||
restoreMetrics,
|
restoreMetrics,
|
||||||
rcc.RestoreConfig.Location)
|
rcc.RestoreConfig.Location)
|
||||||
|
|
||||||
return status, el.Failure()
|
return deets.Details(), status, el.Failure()
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user