diff --git a/src/apps.js b/src/apps.js index 3b245f696..d98a11223 100644 --- a/src/apps.js +++ b/src/apps.js @@ -727,7 +727,7 @@ function install(data, user, auditSource, callback) { eventlog.add(eventlog.ACTION_APP_INSTALL, auditSource, { appId: appId, app: result }); - callback(null, { id : appId }); + callback(null, { id : appId, taskId: result.taskId }); }); }); }); @@ -873,7 +873,7 @@ function configure(appId, data, user, auditSource, callback) { eventlog.add(eventlog.ACTION_APP_CONFIGURE, auditSource, { appId: appId, app: result }); - callback(null); + callback(null, { taskId: result.taskId }); }); }); }); @@ -944,7 +944,7 @@ function update(appId, data, auditSource, callback) { if (error && error.reason === DatabaseError.NOT_FOUND) return callback(new AppsError(AppsError.BAD_STATE)); // might be a bad guess if (error) return callback(new AppsError(AppsError.INTERNAL_ERROR, error)); - startAppTask(appId, { updateConfig: updateConfig }, function (error) { + startAppTask(appId, { updateConfig: updateConfig }, function (error, result) { if (error) return callback(error); eventlog.add(eventlog.ACTION_APP_UPDATE, auditSource, { appId: appId, toManifest: manifest, fromManifest: app.manifest, force: data.force, app: app }); @@ -952,7 +952,7 @@ function update(appId, data, auditSource, callback) { // clear update indicator, if update fails, it will come back through the update checker updateChecker.resetAppUpdateInfo(appId); - callback(null); + callback(null, { taskId: result.taskId }); }); }); }); @@ -1047,12 +1047,12 @@ function restore(appId, data, auditSource, callback) { if (error) return callback(new AppsError(AppsError.INTERNAL_ERROR, error)); const restoreConfig = data.backupId ? { backupId: data.backupId, backupFormat: backupInfo.format, oldManifest: app.manifest } : null; // when null, apptask simply reinstalls - startAppTask(appId, { restoreConfig }, function (error) { + startAppTask(appId, { restoreConfig }, function (error, result) { if (error) return callback(error); eventlog.add(eventlog.ACTION_APP_RESTORE, auditSource, { app: app, backupId: backupInfo.id, fromManifest: app.manifest, toManifest: backupInfo.manifest }); - callback(null); + callback(null, { taskId: result.taskId }); }); }); }); @@ -1162,7 +1162,7 @@ function clone(appId, data, user, auditSource, callback) { eventlog.add(eventlog.ACTION_APP_CLONE, auditSource, { appId: newAppId, oldAppId: appId, backupId: backupId, oldApp: app, newApp: result }); - callback(null, { id: newAppId }); + callback(null, { id: newAppId, taskId: result.taskId }); }); }); }); @@ -1197,7 +1197,7 @@ function uninstall(appId, auditSource, callback) { eventlog.add(eventlog.ACTION_APP_UNINSTALL, auditSource, { appId: appId, app: result }); - callback(null); + callback(null, { taskId: result.taskId }); }); }); }); @@ -1376,7 +1376,11 @@ function backup(appId, callback) { if (error && error.reason === DatabaseError.NOT_FOUND) return callback(new AppsError(AppsError.BAD_STATE)); // might be a bad guess if (error) return callback(new AppsError(AppsError.INTERNAL_ERROR, error)); - startAppTask(appId, {}, callback); + startAppTask(appId, { }, (error, result) => { + if (error) return callback(error); + + callback(null, { taskId: result.taskId }); + }); }); }); } diff --git a/src/routes/apps.js b/src/routes/apps.js index f86aaa36b..2b34a8929 100644 --- a/src/routes/apps.js +++ b/src/routes/apps.js @@ -126,7 +126,7 @@ function installApp(req, res, next) { debug('Installing app :%j', data); - apps.install(data, req.user, auditSource.fromRequest(req), function (error, app) { + apps.install(data, req.user, auditSource.fromRequest(req), function (error, result) { if (error && error.reason === AppsError.NOT_FOUND) return next(new HttpError(404, error.message)); if (error && error.reason === AppsError.ALREADY_EXISTS) return next(new HttpError(409, error.message)); if (error && error.reason === AppsError.PORT_RESERVED) return next(new HttpError(409, 'Port ' + error.message + ' is reserved.')); @@ -137,7 +137,7 @@ function installApp(req, res, next) { if (error && error.reason === AppsError.EXTERNAL_ERROR) return next(new HttpError(424, error.message)); if (error) return next(new HttpError(500, error)); - next(new HttpSuccess(202, app)); + next(new HttpSuccess(202, { id: result.id, taskId: result.taskId })); }); } @@ -189,7 +189,7 @@ function configureApp(req, res, next) { debug('Configuring app id:%s data:%j', req.params.id, data); - apps.configure(req.params.id, data, req.user, auditSource.fromRequest(req), function (error) { + apps.configure(req.params.id, data, req.user, auditSource.fromRequest(req), function (error, result) { if (error && error.reason === AppsError.ALREADY_EXISTS) return next(new HttpError(409, error.message)); if (error && error.reason === AppsError.PORT_RESERVED) return next(new HttpError(409, 'Port ' + error.message + ' is reserved.')); if (error && error.reason === AppsError.PORT_CONFLICT) return next(new HttpError(409, 'Port ' + error.message + ' is already in use.')); @@ -199,7 +199,7 @@ function configureApp(req, res, next) { if (error && error.reason === AppsError.BAD_CERTIFICATE) return next(new HttpError(400, error.message)); if (error) return next(new HttpError(500, error)); - next(new HttpSuccess(202, { })); + next(new HttpSuccess(202, { taskId: result.taskId })); }); } @@ -214,14 +214,14 @@ function restoreApp(req, res, next) { if (!('backupId' in req.body)) return next(new HttpError(400, 'backupId is required')); if (data.backupId !== null && typeof data.backupId !== 'string') return next(new HttpError(400, 'backupId must be string or null')); - apps.restore(req.params.id, data, auditSource.fromRequest(req), function (error) { + apps.restore(req.params.id, data, auditSource.fromRequest(req), function (error, result) { if (error && error.reason === AppsError.NOT_FOUND) return next(new HttpError(404, 'No such app')); if (error && error.reason === AppsError.BAD_FIELD) return next(new HttpError(400, error.message)); if (error && error.reason === AppsError.BAD_STATE) return next(new HttpError(409, error.message)); if (error && error.reason === AppsError.EXTERNAL_ERROR) return next(new HttpError(424, error.message)); if (error) return next(new HttpError(500, error)); - next(new HttpSuccess(202, { })); + next(new HttpSuccess(202, { taskId: result.taskId })); }); } @@ -250,7 +250,7 @@ function cloneApp(req, res, next) { if (error && error.reason === AppsError.EXTERNAL_ERROR) return next(new HttpError(424, error.message)); if (error) return next(new HttpError(500, error)); - next(new HttpSuccess(201, { id: result.id })); + next(new HttpSuccess(201, { id: result.id, taskId: result.taskId })); }); } @@ -259,13 +259,13 @@ function backupApp(req, res, next) { debug('Backup app id:%s', req.params.id); - apps.backup(req.params.id, function (error) { + apps.backup(req.params.id, function (error, result) { if (error && error.reason === AppsError.NOT_FOUND) return next(new HttpError(404, 'No such app')); if (error && error.reason === AppsError.BAD_STATE) return next(new HttpError(409, error.message)); if (error && error.reason === AppsError.EXTERNAL_ERROR) return next(new HttpError(424, error)); if (error) return next(new HttpError(500, error)); - next(new HttpSuccess(202, { })); + next(new HttpSuccess(202, { taskId: result.taskId })); }); } @@ -274,12 +274,12 @@ function uninstallApp(req, res, next) { debug('Uninstalling app id:%s', req.params.id); - apps.uninstall(req.params.id, auditSource.fromRequest(req), function (error) { + apps.uninstall(req.params.id, auditSource.fromRequest(req), function (error, result) { if (error && error.reason === AppsError.EXTERNAL_ERROR) return next(new HttpError(424, error)); if (error && error.reason === AppsError.NOT_FOUND) return next(new HttpError(404, 'No such app')); if (error) return next(new HttpError(500, error)); - next(new HttpSuccess(202, { })); + next(new HttpSuccess(202, { taskId: result.taskId })); }); } @@ -326,13 +326,13 @@ function updateApp(req, res, next) { debug('Update app id:%s to manifest:%j', req.params.id, data.manifest); - apps.update(req.params.id, req.body, auditSource.fromRequest(req), function (error) { + apps.update(req.params.id, req.body, auditSource.fromRequest(req), function (error, result) { if (error && error.reason === AppsError.NOT_FOUND) return next(new HttpError(404, 'No such app')); if (error && error.reason === AppsError.BAD_FIELD) return next(new HttpError(400, error.message)); if (error && error.reason === AppsError.BAD_STATE) return next(new HttpError(409, error.message)); if (error) return next(new HttpError(500, error)); - next(new HttpSuccess(202, { })); + next(new HttpSuccess(202, { taskId: result.taskId })); }); }