1
0
Fork 0

Improved upgrade procedure, it now runs smoothly, at least once

This commit is contained in:
Michael Hackstein 2015-02-03 15:44:29 +01:00
parent 1f2f33cf17
commit aa72dacefd
3 changed files with 42 additions and 52 deletions

View File

@ -41,12 +41,11 @@ var ArangoError = arangodb.ArangoError;
var mountRegEx = /^(\/[a-zA-Z0-9_\-%]+)+$/;
var mountAppRegEx = /\/APP(\/|$)/i;
// TODO Only temporary
var tmp_getStorage = function() {
var getStorage = function() {
"use strict";
var c = db._tmp_aal;
var c = db._apps;
if (c === undefined) {
c = db._create("_tmp_aal", {isSystem: true});
c = db._create("_apps", {isSystem: true});
c.ensureUniqueConstraint("mount");
}
return c;
@ -282,7 +281,7 @@ function getStorage () {
function listJson (showPrefix, onlyDevelopment) {
'use strict';
var mounts = tmp_getStorage();
var mounts = getStorage();
var cursor;
if (onlyDevelopment) {
cursor = mounts.byExample({isDevelopment: true});
@ -406,7 +405,7 @@ function validateAppName (name) {
////////////////////////////////////////////////////////////////////////////////
function mountedApp (mount) {
"use strict";
return tmp_getStorage().firstExample({mount: mount});
return getStorage().firstExample({mount: mount});
}
////////////////////////////////////////////////////////////////////////////////
@ -414,7 +413,7 @@ function mountedApp (mount) {
////////////////////////////////////////////////////////////////////////////////
function updateApp (mount, update) {
"use strict";
return tmp_getStorage().updateByExample({mount: mount}, update);
return getStorage().updateByExample({mount: mount}, update);
}
////////////////////////////////////////////////////////////////////////////////
@ -475,8 +474,7 @@ exports.validateAppName = validateAppName;
exports.validateMount = validateMount;
exports.typeToRegex = typeToRegex;
exports.zipDirectory = zipDirectory;
exports.tmp_getStorage = tmp_getStorage;
exports.getStorage = getStorage;
// -----------------------------------------------------------------------------
// --SECTION-- END-OF-FILE

View File

@ -94,7 +94,7 @@
var refillCaches = function() {
appCache = {};
var cursor = utils.tmp_getStorage().all();
var cursor = utils.getStorage().all();
var config, app;
var routes = [];
@ -467,11 +467,14 @@
// .............................................................................
// throw away temporary app folder
// .............................................................................
try {
fs.removeDirectoryRecursive(tempFile);
}
catch (err1) {
arangodb.printf("Cannot remove temporary folder '%s'\n Stack: %s", tempFile, err1.stack || String(err1));
if (found !== mf) {
try {
require("console").log(tempFile);
fs.removeDirectoryRecursive(tempFile);
}
catch (err1) {
arangodb.printf("Cannot remove temporary folder '%s'\n Stack: %s", tempFile, err1.stack || String(err1));
}
}
};
@ -596,7 +599,7 @@
var _scanFoxx = function(mount, options, activateDevelopment) {
delete appCache[mount];
var app = createApp(mount, options, activateDevelopment);
utils.tmp_getStorage().save(app.toJSON());
utils.getStorage().save(app.toJSON());
return app;
};
@ -629,7 +632,7 @@
[ mount ] );
var old = lookupApp(mount);
var collection = utils.tmp_getStorage();
var collection = utils.getStorage();
db._executeTransaction({
collections: {
write: collection.name()
@ -650,7 +653,7 @@
var _install = function(appInfo, mount, options, runSetup) {
var targetPath = computeAppPath(mount, true);
var app;
var collection = utils.tmp_getStorage();
var collection = utils.getStorage();
if (fs.exists(targetPath)) {
throw new Error("An app is already installed at this location.");
}
@ -710,7 +713,7 @@
var _uninstall = function(mount) {
var app = lookupApp(mount);
var collection = utils.tmp_getStorage();
var collection = utils.getStorage();
var targetPath = computeAppPath(mount, true);
if (!fs.exists(targetPath)) {
throw "No foxx app found at this location.";

View File

@ -1416,31 +1416,6 @@ function updateGlobals() {
// --SECTION-- upgrade 2.4 - 2.5
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @brief create new application collection
///
/// Setup the collection _apps
////////////////////////////////////////////////////////////////////////////////
addTask({
name: "setupApps",
description: "setup _apps collection",
mode: [ MODE_PRODUCTION, MODE_DEVELOPMENT ],
cluster: [ CLUSTER_NONE, CLUSTER_COORDINATOR_GLOBAL ],
database: [ DATABASE_INIT, DATABASE_UPGRADE ],
task: function () {
var created = createSystemCollection("_apps");
if (!created) {
return false;
}
var apps = getCollection("_apps");
apps.ensureUniqueConstraint("mount");
return true;
}
});
////////////////////////////////////////////////////////////////////////////////
/// @brief move applications
///
@ -1474,7 +1449,12 @@ function updateGlobals() {
while (appsToZip.hasNext()) {
tmp = appsToZip.next();
path = fs.join(module.oldAppPath(), tmp.path);
mapAppZip[tmp.app] = fmUtils.zipDirectory(path);
try {
mapAppZip[tmp.app] = fmUtils.zipDirectory(path);
} catch (e) {
logger.errorLines("Tried to move app " + tmp.app + " but it was not found at app-path" + path +
" : " +(e.stack || String(e)));
}
}
// 2. If development mode, Zip all development APPs and create a map name => zipFile
@ -1486,8 +1466,13 @@ function updateGlobals() {
appsToZip = fs.list(devPath);
for (i = 0; i < appsToZip.length; ++i) {
path = fs.join(devPath, appsToZip[i]);
if (fs.exists() && fs.isDirectory(path)) {
mapDevAppZip[appsToZip[i]] = fmUtils.zipDirectory(path);
if (fs.exists(path) && fs.isDirectory(path)) {
try {
mapDevAppZip[appsToZip[i]] = fmUtils.zipDirectory(path);
} catch (e) {
logger.errorLines("Tried to move app " + appsToZip[i] + " but it was not found at app-path" + path +
" : " + (e.stack || String(e)));
}
}
}
}
@ -1503,6 +1488,7 @@ function updateGlobals() {
tmp = appsToInstall.next();
if (mapAppZip.hasOwnProperty(tmp.app)) {
foxxManager.install(mapAppZip[tmp.app], tmp.mount, {}, false);
logger.log("Upgraded app '" + tmp.app + "' on mount: " + tmp.mount);
}
}
@ -1514,10 +1500,12 @@ function updateGlobals() {
name = appsToInstall[i];
foxxManager.install(mapDevAppZip[name], "/dev/" + name, {}, false);
foxxManager.development("/dev/" + name);
logger.log("Upgraded dev app '" + name + "' on mount: /dev/" + name);
try {
fs.remove(mapDevAppZip[name]);
} catch (err1) {
require("org/arangodb").printf("Cannot remove temporary file '%s'\n", mapDevAppZip[name]);
logger.errorLines("Could not remove temporary file '%s'\n%s",
mapDevAppZip[name], err1.stack || String(err1));
}
}
@ -1527,12 +1515,12 @@ function updateGlobals() {
try {
fs.remove(mapAppZip[appsToInstall[i]]);
} catch (err1) {
require("org/arangodb").printf("Cannot remove temporary file '%s'\n", mapAppZip[appsToInstall[i]]);
logger.errorLines("Could not remove temporary file '%s'\n%s",
mapDevAppZip[name], err1.stack || String(err1));
}
}
return true;
}
});
@ -1549,7 +1537,8 @@ function updateGlobals() {
if (!aal) {
return true;
}
return aal.drop();
aal.drop();
return true;
}
});