Fix repair

If a task fails, we can either:
* allow other task ops to be called - we cannot do this because the ops are fine-grained. for example,
  a restore failure removes many things and calling set-memory or set-location in that state won't
  make sense.

* provide a generic repair route - this allows one to override args and call the failed task
  again. this is what we have now but has the issue that this repair function has to know about all
  the other op functions. for example, for argument validation. we can do some complicated refactoring
  to make it work if we want.

* just a generic total re-configure - this does not work because clone/restore/backup/datadir/uninstall/update
  failure leaves the app in a state which re-configure cannot do anything about.

* allow the failed op to be called again - this seems the easiest. we just allow the route to be called again
  in the error state.

* if we hit a state where even providing extra args, cannot get you out of this "error" state, we have to provide
  some repair route. for example, maybe the container disappeared by some docke error. user clicks 'repair' to
  recreate the container. this route does not have to take any args.

The final solution is:
* a failed task can be called again via the route. so we can resubmit any args and we get validation
* repair route just re-configures and can be called in any state to just rebuild container. re-configure is also
  doing only local changes (docker, nginx)
* install/clone failures are fixed using repair route. updated manifest can be passed in.
* UI shows backup selector for restore failures
* UI shows domain selector for change location failulre
This commit is contained in:
Girish Ramakrishnan
2019-11-23 18:35:51 -08:00
parent 37d7be93b5
commit 6a64f24e98
2 changed files with 25 additions and 35 deletions

View File

@@ -349,19 +349,10 @@ function repairApp(req, res, next) {
const data = req.body;
if (data.backupId && typeof data.backupId !== 'string') return next(new HttpError(400, 'backupId must be string or null'));
if (data.backupFormat && typeof data.backupFormat !== 'string') return next(new HttpError(400, 'backupFormat must be string or null'));
if (data.location && typeof data.location !== 'string') return next(new HttpError(400, 'location is required'));
if (data.domain && typeof data.domain !== 'string') return next(new HttpError(400, 'domain is required'));
if ('alternateDomains' in data) {
if (!Array.isArray(data.alternateDomains)) return next(new HttpError(400, 'alternateDomains must be an array'));
if (data.alternateDomains.some(function (d) { return (typeof d.domain !== 'string' || typeof d.subdomain !== 'string'); })) return next(new HttpError(400, 'alternateDomains array must contain objects with domain and subdomain strings'));
if ('manifest' in data) {
if (!data.manifest || typeof data.manifest !== 'object') return next(new HttpError(400, 'backupId must be an object'));
}
if ('overwriteDns' in req.body && typeof req.body.overwriteDns !== 'boolean') return next(new HttpError(400, 'overwriteDns must be boolean'));
apps.repair(req.params.id, data, auditSource.fromRequest(req), function (error, result) {
if (error) return next(BoxError.toHttpError(error));