Make restoreConfigJson, oldConfigJson, updateConfigJson as task args
This commit is contained in:
+5
-18
@@ -64,7 +64,7 @@ var assert = require('assert'),
|
||||
|
||||
var APPS_FIELDS_PREFIXED = [ 'apps.id', 'apps.appStoreId', 'apps.installationState', 'apps.installationProgress', 'apps.runState',
|
||||
'apps.health', 'apps.containerId', 'apps.manifestJson', 'apps.httpPort', 'subdomains.subdomain AS location', 'subdomains.domain',
|
||||
'apps.accessRestrictionJson', 'apps.restoreConfigJson', 'apps.oldConfigJson', 'apps.updateConfigJson', 'apps.memoryLimit',
|
||||
'apps.accessRestrictionJson', 'apps.memoryLimit',
|
||||
'apps.label', 'apps.tagsJson', 'apps.taskId',
|
||||
'apps.sso', 'apps.debugModeJson', 'apps.robotsTxt', 'apps.enableBackup',
|
||||
'apps.creationTime', 'apps.updateTime', 'apps.mailboxName', 'apps.enableAutomaticUpdate',
|
||||
@@ -81,18 +81,6 @@ function postProcess(result) {
|
||||
result.manifest = safe.JSON.parse(result.manifestJson);
|
||||
delete result.manifestJson;
|
||||
|
||||
assert(result.oldConfigJson === null || typeof result.oldConfigJson === 'string');
|
||||
result.oldConfig = safe.JSON.parse(result.oldConfigJson);
|
||||
delete result.oldConfigJson;
|
||||
|
||||
assert(result.updateConfigJson === null || typeof result.updateConfigJson === 'string');
|
||||
result.updateConfig = safe.JSON.parse(result.updateConfigJson);
|
||||
delete result.updateConfigJson;
|
||||
|
||||
assert(result.restoreConfigJson === null || typeof result.restoreConfigJson === 'string');
|
||||
result.restoreConfig = safe.JSON.parse(result.restoreConfigJson);
|
||||
delete result.restoreConfigJson;
|
||||
|
||||
assert(result.tagsJson === null || typeof result.tagsJson === 'string');
|
||||
result.tags = safe.JSON.parse(result.tagsJson) || [];
|
||||
delete result.tagsJson;
|
||||
@@ -275,7 +263,6 @@ function add(id, appStoreId, manifest, location, domain, portBindings, data, cal
|
||||
const accessRestrictionJson = JSON.stringify(accessRestriction);
|
||||
const memoryLimit = data.memoryLimit || 0;
|
||||
const installationState = data.installationState || exports.ISTATE_PENDING_INSTALL;
|
||||
const restoreConfigJson = data.restoreConfig ? JSON.stringify(data.restoreConfig) : null; // used when cloning
|
||||
const sso = 'sso' in data ? data.sso : null;
|
||||
const robotsTxt = 'robotsTxt' in data ? data.robotsTxt : null;
|
||||
const debugModeJson = data.debugMode ? JSON.stringify(data.debugMode) : null;
|
||||
@@ -288,9 +275,9 @@ function add(id, appStoreId, manifest, location, domain, portBindings, data, cal
|
||||
|
||||
queries.push({
|
||||
query: 'INSERT INTO apps (id, appStoreId, manifestJson, installationState, accessRestrictionJson, memoryLimit, '
|
||||
+ 'restoreConfigJson, sso, debugModeJson, robotsTxt, mailboxName, label, tagsJson) '
|
||||
+ ' VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
|
||||
args: [ id, appStoreId, manifestJson, installationState, accessRestrictionJson, memoryLimit, restoreConfigJson,
|
||||
+ 'sso, debugModeJson, robotsTxt, mailboxName, label, tagsJson) '
|
||||
+ ' VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
|
||||
args: [ id, appStoreId, manifestJson, installationState, accessRestrictionJson, memoryLimit,
|
||||
sso, debugModeJson, robotsTxt, mailboxName, label, tagsJson ]
|
||||
});
|
||||
|
||||
@@ -456,7 +443,7 @@ function updateWithConstraints(id, app, constraints, callback) {
|
||||
|
||||
var fields = [ ], values = [ ];
|
||||
for (var p in app) {
|
||||
if (p === 'manifest' || p === 'oldConfig' || p === 'updateConfig' || p === 'restoreConfig' || p === 'tags' || p === 'accessRestriction' || p === 'debugMode') {
|
||||
if (p === 'manifest' || p === 'tags' || p === 'accessRestriction' || p === 'debugMode') {
|
||||
fields.push(`${p}Json = ?`);
|
||||
values.push(JSON.stringify(app[p]));
|
||||
} else if (p !== 'portBindings' && p !== 'location' && p !== 'domain' && p !== 'alternateDomains' && p !== 'env') {
|
||||
|
||||
+21
-23
@@ -573,9 +573,9 @@ function mailboxNameForLocation(location, manifest) {
|
||||
return (location ? location : manifest.title.toLowerCase().replace(/[^a-zA-Z0-9]/g, '')) + '.app';
|
||||
}
|
||||
|
||||
function startAppTask(appId, callback) {
|
||||
function startAppTask(appId, args, callback) {
|
||||
const logFile = path.join(paths.LOG_DIR, appId, 'apptask.log');
|
||||
let task = tasks.startTask(tasks.TASK_APP, [ appId ], { logFile });
|
||||
let task = tasks.startTask(tasks.TASK_APP, [ appId, args ], { logFile });
|
||||
task.on('start', function (taskId) {
|
||||
appdb.update(appId, { taskId: taskId }, function (error) {
|
||||
if (error) return callback(new AppsError(AppsError.INTERNAL_ERROR, error));
|
||||
@@ -696,7 +696,6 @@ function install(data, user, auditSource, callback) {
|
||||
sso: sso,
|
||||
debugMode: debugMode,
|
||||
mailboxName: mailboxName,
|
||||
restoreConfig: backupId ? { backupId: backupId, backupFormat: backupFormat } : null,
|
||||
enableBackup: enableBackup,
|
||||
enableAutomaticUpdate: enableAutomaticUpdate,
|
||||
robotsTxt: robotsTxt,
|
||||
@@ -718,7 +717,9 @@ function install(data, user, auditSource, callback) {
|
||||
if (error) return callback(new AppsError(AppsError.INTERNAL_ERROR, 'Error setting cert: ' + error.message));
|
||||
}
|
||||
|
||||
startAppTask(appId, function (error, result) {
|
||||
const restoreConfig = backupId ? { backupId: backupId, backupFormat: backupFormat } : null;
|
||||
|
||||
startAppTask(appId, { restoreConfig }, function (error, result) {
|
||||
if (error) return callback(error);
|
||||
|
||||
eventlog.add(eventlog.ACTION_APP_INSTALL, auditSource, { appId: appId, app: result });
|
||||
@@ -857,8 +858,6 @@ function configure(appId, data, user, auditSource, callback) {
|
||||
if ('enableBackup' in data) values.enableBackup = data.enableBackup;
|
||||
if ('enableAutomaticUpdate' in data) values.enableAutomaticUpdate = data.enableAutomaticUpdate;
|
||||
|
||||
values.oldConfig = getAppConfig(app);
|
||||
|
||||
debug(`configure: id:${appId}`);
|
||||
|
||||
appdb.setInstallationCommand(appId, appdb.ISTATE_PENDING_CONFIGURE, values, function (error) {
|
||||
@@ -866,7 +865,7 @@ function configure(appId, data, user, auditSource, callback) {
|
||||
if (error && error.reason === DatabaseError.NOT_FOUND) return callback(new AppsError(AppsError.BAD_STATE));
|
||||
if (error) return callback(new AppsError(AppsError.INTERNAL_ERROR, error));
|
||||
|
||||
startAppTask(appId, function (error, result) {
|
||||
startAppTask(appId, { oldConfig: getAppConfig(app) }, function (error, result) {
|
||||
if (error) return callback(error);
|
||||
|
||||
eventlog.add(eventlog.ACTION_APP_CONFIGURE, auditSource, { appId: appId, app: result });
|
||||
@@ -938,11 +937,11 @@ function update(appId, data, auditSource, callback) {
|
||||
updateConfig.memoryLimit = updateConfig.manifest.memoryLimit;
|
||||
}
|
||||
|
||||
appdb.setInstallationCommand(appId, data.force ? appdb.ISTATE_PENDING_FORCE_UPDATE : appdb.ISTATE_PENDING_UPDATE, { updateConfig: updateConfig }, function (error) {
|
||||
appdb.setInstallationCommand(appId, data.force ? appdb.ISTATE_PENDING_FORCE_UPDATE : appdb.ISTATE_PENDING_UPDATE, { }, function (error) {
|
||||
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, function (error) {
|
||||
startAppTask(appId, { updateConfig: updateConfig }, function (error) {
|
||||
if (error) return callback(error);
|
||||
|
||||
eventlog.add(eventlog.ACTION_APP_UPDATE, auditSource, { appId: appId, toManifest: manifest, fromManifest: app.manifest, force: data.force, app: app });
|
||||
@@ -1037,17 +1036,15 @@ function restore(appId, data, auditSource, callback) {
|
||||
if (error) return callback(error);
|
||||
|
||||
var values = {
|
||||
restoreConfig: data.backupId ? { backupId: data.backupId, backupFormat: backupInfo.format } : null, // when null, apptask simply reinstalls
|
||||
manifest: backupInfo.manifest,
|
||||
|
||||
oldConfig: getAppConfig(app)
|
||||
manifest: backupInfo.manifest
|
||||
};
|
||||
|
||||
appdb.setInstallationCommand(appId, appdb.ISTATE_PENDING_RESTORE, values, function (error) {
|
||||
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, function (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) {
|
||||
if (error) return callback(error);
|
||||
|
||||
eventlog.add(eventlog.ACTION_APP_RESTORE, auditSource, { app: app, backupId: backupInfo.id, fromManifest: app.manifest, toManifest: backupInfo.manifest });
|
||||
@@ -1141,7 +1138,6 @@ function clone(appId, data, user, auditSource, callback) {
|
||||
installationState: appdb.ISTATE_PENDING_CLONE,
|
||||
memoryLimit: app.memoryLimit,
|
||||
accessRestriction: app.accessRestriction,
|
||||
restoreConfig: { backupId: backupId, backupFormat: backupInfo.format },
|
||||
sso: !!app.sso,
|
||||
mailboxName: mailboxName,
|
||||
enableBackup: app.enableBackup,
|
||||
@@ -1156,7 +1152,9 @@ function clone(appId, data, user, auditSource, callback) {
|
||||
purchaseApp({ appId: newAppId, appstoreId: app.appStoreId, manifestId: manifest.id }, function (error) {
|
||||
if (error) return callback(error);
|
||||
|
||||
startAppTask(newAppId, function (error, result) {
|
||||
const restoreConfig = { backupId: backupId, backupFormat: backupInfo.format };
|
||||
|
||||
startAppTask(newAppId, { restoreConfig }, function (error, result) {
|
||||
if (error) return callback(error);
|
||||
|
||||
eventlog.add(eventlog.ACTION_APP_CLONE, auditSource, { appId: newAppId, oldAppId: appId, backupId: backupId, oldApp: app, newApp: result });
|
||||
@@ -1191,7 +1189,7 @@ function uninstall(appId, auditSource, callback) {
|
||||
if (error && error.reason === DatabaseError.NOT_FOUND) return callback(new AppsError(AppsError.NOT_FOUND, 'No such app'));
|
||||
if (error) return callback(new AppsError(AppsError.INTERNAL_ERROR, error));
|
||||
|
||||
startAppTask(appId, function (error, result) {
|
||||
startAppTask(appId, {}, function (error, result) {
|
||||
if (error) return callback(error);
|
||||
|
||||
eventlog.add(eventlog.ACTION_APP_UNINSTALL, auditSource, { appId: appId, app: result });
|
||||
@@ -1213,7 +1211,7 @@ function start(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, {}, callback);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1227,7 +1225,7 @@ function stop(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, {}, callback);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1375,7 +1373,7 @@ 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, {}, callback);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -1408,11 +1406,11 @@ function restoreInstalledApps(callback) {
|
||||
|
||||
async.map(apps, function (app, iteratorDone) {
|
||||
backups.getByAppIdPaged(1, 1, app.id, function (error, results) {
|
||||
var restoreConfig = !error && results.length ? { backupId: results[0].id, backupFormat: results[0].format } : null;
|
||||
const restoreConfig = !error && results.length ? { backupId: results[0].id, backupFormat: results[0].format } : null;
|
||||
|
||||
debug(`marking ${app.fqdn} for restore using restore config ${JSON.stringify(restoreConfig)}`);
|
||||
|
||||
appdb.setInstallationCommand(app.id, appdb.ISTATE_PENDING_RESTORE, { restoreConfig: restoreConfig, oldConfig: getAppConfig(app) }, function (error) {
|
||||
appdb.setInstallationCommand(app.id, appdb.ISTATE_PENDING_RESTORE, { restoreConfig: restoreConfig }, function (error) {
|
||||
if (error) debug(`Error marking ${app.fqdn} for restore: ${JSON.stringify(error)}`);
|
||||
|
||||
iteratorDone(); // always succeed
|
||||
@@ -1431,7 +1429,7 @@ function configureInstalledApps(callback) {
|
||||
async.map(apps, function (app, iteratorDone) {
|
||||
debug(`marking ${app.fqdn} for reconfigure`);
|
||||
|
||||
appdb.setInstallationCommand(app.id, appdb.ISTATE_PENDING_CONFIGURE, { oldConfig: null }, function (error) {
|
||||
appdb.setInstallationCommand(app.id, appdb.ISTATE_PENDING_CONFIGURE, { }, function (error) {
|
||||
if (error) debug(`Error marking ${app.fqdn} for reconfigure: ${JSON.stringify(error)}`);
|
||||
|
||||
iteratorDone(); // always succeed
|
||||
|
||||
+34
-28
@@ -499,12 +499,13 @@ function downloadImage(manifest, callback) {
|
||||
// - setup the container (requires image, volumes, addons)
|
||||
// - setup collectd (requires container id)
|
||||
// restore is also handled here since restore is just an install with some oldConfig to clean up
|
||||
function install(app, progressCallback, callback) {
|
||||
function install(app, restoreConfig, progressCallback, callback) {
|
||||
assert.strictEqual(typeof app, 'object');
|
||||
assert.strictEqual(typeof restoreConfig, 'object');
|
||||
assert.strictEqual(typeof progressCallback, 'function');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
const restoreConfig = app.restoreConfig, isRestoring = app.installationState === appdb.ISTATE_PENDING_RESTORE;
|
||||
const isRestoring = app.installationState === appdb.ISTATE_PENDING_RESTORE;
|
||||
|
||||
async.series([
|
||||
// this protects against the theoretical possibility of an app being marked for install/restore from
|
||||
@@ -520,7 +521,7 @@ function install(app, progressCallback, callback) {
|
||||
deleteContainers.bind(null, app, { managedOnly: true }),
|
||||
function teardownAddons(next) {
|
||||
// when restoring, app does not require these addons anymore. remove carefully to preserve the db passwords
|
||||
var addonsToRemove = !isRestoring ? app.manifest.addons : _.omit(app.oldConfig.manifest.addons, Object.keys(app.manifest.addons));
|
||||
var addonsToRemove = !isRestoring ? app.manifest.addons : _.omit(restoreConfig.oldManifest.addons, Object.keys(app.manifest.addons));
|
||||
|
||||
addons.teardownAddons(app, addonsToRemove, next);
|
||||
},
|
||||
@@ -528,9 +529,11 @@ function install(app, progressCallback, callback) {
|
||||
|
||||
// for restore case
|
||||
function deleteImageIfChanged(done) {
|
||||
if (!app.oldConfig || (app.oldConfig.manifest.dockerImage === app.manifest.dockerImage)) return done();
|
||||
if (!restoreConfig.oldManifest) return done();
|
||||
|
||||
docker.deleteImage(app.oldConfig.manifest, done);
|
||||
if (restoreConfig.oldManifest.dockerImage === app.manifest.dockerImage) return done();
|
||||
|
||||
docker.deleteImage(restoreConfig.oldManifest, done);
|
||||
},
|
||||
|
||||
reserveHttpPort.bind(null, app),
|
||||
@@ -551,7 +554,7 @@ function install(app, progressCallback, callback) {
|
||||
createAppDir.bind(null, app),
|
||||
|
||||
function restoreFromBackup(next) {
|
||||
if (!restoreConfig) {
|
||||
if (!restoreConfig.backupId) {
|
||||
async.series([
|
||||
progressCallback.bind(null, { percent: 60, message: 'Setting up addons' }),
|
||||
addons.setupAddons.bind(null, app, app.manifest.addons),
|
||||
@@ -619,14 +622,15 @@ function backup(app, progressCallback, callback) {
|
||||
}
|
||||
|
||||
// note that configure is called after an infra update as well
|
||||
function configure(app, progressCallback, callback) {
|
||||
function configure(app, oldConfig, progressCallback, callback) {
|
||||
assert.strictEqual(typeof app, 'object');
|
||||
assert.strictEqual(typeof oldConfig, 'object');
|
||||
assert.strictEqual(typeof progressCallback, 'function');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
// oldConfig can be null during an infra update
|
||||
const locationChanged = app.oldConfig && (app.oldConfig.fqdn !== app.fqdn);
|
||||
const dataDirChanged = app.oldConfig && (app.oldConfig.dataDir !== app.dataDir);
|
||||
const locationChanged = oldConfig.fqdn !== app.fqdn;
|
||||
const dataDirChanged = oldConfig.dataDir !== app.dataDir;
|
||||
|
||||
async.series([
|
||||
progressCallback.bind(null, { percent: 10, message: 'Cleaning up old install' }),
|
||||
@@ -639,7 +643,7 @@ function configure(app, progressCallback, callback) {
|
||||
function (next) {
|
||||
if (!locationChanged) return next();
|
||||
|
||||
unregisterSubdomain(app, app.oldConfig.location, app.oldConfig.domain, next);
|
||||
unregisterSubdomain(app, oldConfig.location, oldConfig.domain, next);
|
||||
},
|
||||
|
||||
reserveHttpPort.bind(null, app),
|
||||
@@ -667,7 +671,7 @@ function configure(app, progressCallback, callback) {
|
||||
function (next) {
|
||||
if (!dataDirChanged) return next();
|
||||
|
||||
migrateDataDir(app, app.oldConfig.dataDir, next);
|
||||
migrateDataDir(app, oldConfig.dataDir, next);
|
||||
},
|
||||
|
||||
progressCallback.bind(null, { percent: 60, message: 'Creating container' }),
|
||||
@@ -699,16 +703,17 @@ function configure(app, progressCallback, callback) {
|
||||
}
|
||||
|
||||
// nginx configuration is skipped because app.httpPort is expected to be available
|
||||
function update(app, progressCallback, callback) {
|
||||
function update(app, updateConfig, progressCallback, callback) {
|
||||
assert.strictEqual(typeof app, 'object');
|
||||
assert.strictEqual(typeof updateConfig, 'object');
|
||||
assert.strictEqual(typeof progressCallback, 'function');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
debugApp(app, `Updating to ${app.updateConfig.manifest.version}`);
|
||||
debugApp(app, `Updating to ${updateConfig.manifest.version}`);
|
||||
|
||||
// app does not want these addons anymore
|
||||
// FIXME: this does not handle option changes (like multipleDatabases)
|
||||
var unusedAddons = _.omit(app.manifest.addons, Object.keys(app.updateConfig.manifest.addons));
|
||||
var unusedAddons = _.omit(app.manifest.addons, Object.keys(updateConfig.manifest.addons));
|
||||
|
||||
const FORCED_UPDATE = (app.installationState === appdb.ISTATE_PENDING_FORCE_UPDATE);
|
||||
|
||||
@@ -716,7 +721,7 @@ function update(app, progressCallback, callback) {
|
||||
// this protects against the theoretical possibility of an app being marked for update from
|
||||
// a previous version of box code
|
||||
progressCallback.bind(null, { percent: 0, message: 'Verify manifest' }),
|
||||
verifyManifest.bind(null, app.updateConfig.manifest),
|
||||
verifyManifest.bind(null, updateConfig.manifest),
|
||||
|
||||
function (next) {
|
||||
if (FORCED_UPDATE) return next(null);
|
||||
@@ -736,7 +741,7 @@ function update(app, progressCallback, callback) {
|
||||
// download new image before app is stopped. this is so we can reduce downtime
|
||||
// and also not remove the 'common' layers when the old image is deleted
|
||||
progressCallback.bind(null, { percent: 25, message: 'Downloading image' }),
|
||||
downloadImage.bind(null, app.updateConfig.manifest),
|
||||
downloadImage.bind(null, updateConfig.manifest),
|
||||
|
||||
// note: we cleanup first and then backup. this is done so that the app is not running should backup fail
|
||||
// we cannot easily 'recover' from backup failures because we have to revert manfest and portBindings
|
||||
@@ -746,7 +751,7 @@ function update(app, progressCallback, callback) {
|
||||
stopApp.bind(null, app),
|
||||
deleteContainers.bind(null, app, { managedOnly: true }),
|
||||
function deleteImageIfChanged(done) {
|
||||
if (app.manifest.dockerImage === app.updateConfig.manifest.dockerImage) return done();
|
||||
if (app.manifest.dockerImage === updateConfig.manifest.dockerImage) return done();
|
||||
|
||||
docker.deleteImage(app.manifest, done);
|
||||
},
|
||||
@@ -757,8 +762,8 @@ function update(app, progressCallback, callback) {
|
||||
// free unused ports
|
||||
function (next) {
|
||||
const currentPorts = app.portBindings || {};
|
||||
const newTcpPorts = app.updateConfig.manifest.tcpPorts || {};
|
||||
const newUdpPorts = app.updateConfig.manifest.udpPorts || {};
|
||||
const newTcpPorts = updateConfig.manifest.tcpPorts || {};
|
||||
const newUdpPorts = updateConfig.manifest.udpPorts || {};
|
||||
|
||||
async.each(Object.keys(currentPorts), function (portName, callback) {
|
||||
if (newTcpPorts[portName] || newUdpPorts[portName]) return callback(); // port still in use
|
||||
@@ -776,13 +781,13 @@ function update(app, progressCallback, callback) {
|
||||
},
|
||||
|
||||
// switch over to the new config. manifest, memoryLimit, portBindings, appstoreId are updated here
|
||||
updateApp.bind(null, app, app.updateConfig),
|
||||
updateApp.bind(null, app, updateConfig),
|
||||
|
||||
progressCallback.bind(null, { percent: 45, message: 'Downloading icon' }),
|
||||
downloadIcon.bind(null, app),
|
||||
|
||||
progressCallback.bind(null, { percent: 70, message: 'Updating addons' }),
|
||||
addons.setupAddons.bind(null, app, app.updateConfig.manifest.addons),
|
||||
addons.setupAddons.bind(null, app, updateConfig.manifest.addons),
|
||||
|
||||
progressCallback.bind(null, { percent: 80, message: 'Creating container' }),
|
||||
createContainer.bind(null, app),
|
||||
@@ -905,8 +910,9 @@ function handleRunCommand(app, progressCallback, callback) {
|
||||
return callback(null);
|
||||
}
|
||||
|
||||
function run(appId, progressCallback, callback) {
|
||||
function run(appId, args, progressCallback, callback) {
|
||||
assert.strictEqual(typeof appId, 'string');
|
||||
assert.strictEqual(typeof args, 'object');
|
||||
assert.strictEqual(typeof progressCallback, 'function');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
@@ -917,13 +923,13 @@ function run(appId, progressCallback, callback) {
|
||||
debugApp(app, 'startTask installationState: %s runState: %s', app.installationState, app.runState);
|
||||
|
||||
switch (app.installationState) {
|
||||
case appdb.ISTATE_PENDING_INSTALL: return install(app, progressCallback, callback);
|
||||
case appdb.ISTATE_PENDING_CONFIGURE: return configure(app, progressCallback, callback);
|
||||
case appdb.ISTATE_PENDING_INSTALL: return install(app, args.restoreConfig || {}, progressCallback, callback);
|
||||
case appdb.ISTATE_PENDING_CONFIGURE: return configure(app, args.oldConfig, progressCallback, callback);
|
||||
case appdb.ISTATE_PENDING_UNINSTALL: return uninstall(app, progressCallback, callback);
|
||||
case appdb.ISTATE_PENDING_CLONE: return install(app, progressCallback, callback);
|
||||
case appdb.ISTATE_PENDING_RESTORE: return install(app, progressCallback, callback);
|
||||
case appdb.ISTATE_PENDING_UPDATE: return update(app, progressCallback, callback);
|
||||
case appdb.ISTATE_PENDING_FORCE_UPDATE: return update(app, progressCallback, callback);
|
||||
case appdb.ISTATE_PENDING_CLONE: return install(app, args.restoreConfig || {}, progressCallback, callback);
|
||||
case appdb.ISTATE_PENDING_RESTORE: return install(app, args.restoreConfig || {}, progressCallback, callback);
|
||||
case appdb.ISTATE_PENDING_UPDATE: return update(app, args.updateConfig, progressCallback, callback);
|
||||
case appdb.ISTATE_PENDING_FORCE_UPDATE: return update(app, args.updateConfig, progressCallback, callback);
|
||||
case appdb.ISTATE_PENDING_BACKUP: return backup(app, progressCallback, callback);
|
||||
case appdb.ISTATE_INSTALLED: return handleRunCommand(app, progressCallback, callback);
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ describe('Apps', function () {
|
||||
appStoreId: 'appStoreId-0',
|
||||
location: 'some-location-0',
|
||||
domain: DOMAIN_0.domain,
|
||||
fqdn: 'some-location-0.' + DOMAIN_0.domain, // required for oldConfig
|
||||
fqdn: 'some-location-0.' + DOMAIN_0.domain,
|
||||
manifest: {
|
||||
version: '0.1', dockerImage: 'docker/app0', healthCheckPath: '/', httpPort: 80, title: 'app0',
|
||||
tcpPorts: {
|
||||
@@ -123,7 +123,7 @@ describe('Apps', function () {
|
||||
appStoreId: 'appStoreId-1',
|
||||
location: 'some-location-1',
|
||||
domain: DOMAIN_0.domain,
|
||||
fqdn: 'some-location-1.' + DOMAIN_0.domain, // required for oldConfig
|
||||
fqdn: 'some-location-1.' + DOMAIN_0.domain,
|
||||
manifest: {
|
||||
version: '0.1', dockerImage: 'docker/app1', healthCheckPath: '/', httpPort: 80, title: 'app1',
|
||||
tcpPorts: {}
|
||||
@@ -140,7 +140,7 @@ describe('Apps', function () {
|
||||
appStoreId: 'appStoreId-2',
|
||||
location: 'some-location-2',
|
||||
domain: DOMAIN_1.domain,
|
||||
fqdn: 'some-location-2.' + DOMAIN_1.domain, // required for oldConfig
|
||||
fqdn: 'some-location-2.' + DOMAIN_1.domain,
|
||||
manifest: {
|
||||
version: '0.1', dockerImage: 'docker/app2', healthCheckPath: '/', httpPort: 80, title: 'app2',
|
||||
tcpPorts: {}
|
||||
@@ -375,11 +375,8 @@ describe('Apps', function () {
|
||||
|
||||
apps.getAll(function (error, apps) {
|
||||
expect(apps[0].installationState).to.be(appdb.ISTATE_PENDING_CONFIGURE);
|
||||
expect(apps[0].oldConfig).to.be(null);
|
||||
expect(apps[1].installationState).to.be(appdb.ISTATE_PENDING_CONFIGURE); // erorred app can be reconfigured after restore
|
||||
expect(apps[1].oldConfig).to.be(null);
|
||||
expect(apps[2].installationState).to.be(appdb.ISTATE_PENDING_CONFIGURE);
|
||||
expect(apps[2].oldConfig).to.be(null);
|
||||
|
||||
done();
|
||||
});
|
||||
@@ -402,10 +399,8 @@ describe('Apps', function () {
|
||||
|
||||
apps.getAll(function (error, result) {
|
||||
expect(result[0].installationState).to.be(appdb.ISTATE_PENDING_RESTORE);
|
||||
expect(result[0].oldConfig).to.eql(apps.getAppConfig(APP_0));
|
||||
expect(result[1].installationState).to.be(appdb.ISTATE_PENDING_RESTORE);
|
||||
expect(result[2].installationState).to.be(appdb.ISTATE_PENDING_RESTORE);
|
||||
expect(result[2].oldConfig).to.eql(apps.getAppConfig(APP_2));
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
@@ -400,8 +400,6 @@ describe('database', function () {
|
||||
health: null,
|
||||
accessRestriction: null,
|
||||
lastBackupId: null,
|
||||
oldConfig: null,
|
||||
newConfig: null,
|
||||
memoryLimit: 4294967296,
|
||||
sso: true,
|
||||
debugMode: null,
|
||||
@@ -979,9 +977,6 @@ describe('database', function () {
|
||||
portBindings: { port: { hostPort: 5678, type: 'tcp' } },
|
||||
health: null,
|
||||
accessRestriction: null,
|
||||
restoreConfig: null,
|
||||
oldConfig: null,
|
||||
updateConfig: null,
|
||||
memoryLimit: 4294967296,
|
||||
sso: true,
|
||||
debugMode: null,
|
||||
@@ -1013,9 +1008,6 @@ describe('database', function () {
|
||||
portBindings: { },
|
||||
health: null,
|
||||
accessRestriction: { users: [ 'foobar' ] },
|
||||
restoreConfig: null,
|
||||
oldConfig: null,
|
||||
updateConfig: null,
|
||||
memoryLimit: 0,
|
||||
sso: true,
|
||||
debugMode: null,
|
||||
|
||||
@@ -74,8 +74,6 @@ var APP_0 = {
|
||||
portBindings: { port: 5678 },
|
||||
health: null,
|
||||
accessRestriction: null,
|
||||
restoreConfig: null,
|
||||
oldConfig: null,
|
||||
memoryLimit: 4294967296,
|
||||
mailboxName: 'some-location-0.app'
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user