mirror of https://gitee.com/bigwinds/arangodb
The new foxx apps now store themselfes in a collection. One can list all applications and all development applications.
This commit is contained in:
parent
5cf56013f5
commit
efc6737743
|
@ -39,6 +39,31 @@ var throwDownloadError = arangodb.throwDownloadError;
|
|||
var errors = arangodb.errors;
|
||||
var ArangoError = arangodb.ArangoError;
|
||||
|
||||
// TODO Only temporary
|
||||
var tmp_getStorage = function() {
|
||||
var c = db._tmp_aal;
|
||||
if (c === undefined) {
|
||||
c = db._create("_tmp_aal", {isSystem: true});
|
||||
c.ensureUniqueConstraint("mount");
|
||||
}
|
||||
return c;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief comparator for mount points
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
var compareMounts = function(l, r) {
|
||||
var left = l.mount.toLowerCase();
|
||||
var right = r.mount.toLowerCase();
|
||||
|
||||
if (left < right) {
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief builds a github repository URL
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -248,31 +273,34 @@ function getStorage () {
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief returns all installed FOXX applications
|
||||
/// @brief returns all running Foxx applications
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
function listJson (showPrefix) {
|
||||
function listJson (showPrefix, onlyDevelopment) {
|
||||
'use strict';
|
||||
|
||||
var aal = getStorage();
|
||||
var cursor = aal.byExample({ type: "mount" });
|
||||
var mounts = tmp_getStorage();
|
||||
var cursor;
|
||||
if (onlyDevelopment) {
|
||||
cursor = mounts.byExample({isDevelopment: true});
|
||||
} else {
|
||||
cursor = mounts.all();
|
||||
}
|
||||
var result = [];
|
||||
var doc, res;
|
||||
|
||||
while (cursor.hasNext()) {
|
||||
var doc = cursor.next();
|
||||
doc = cursor.next();
|
||||
|
||||
var version = doc.app.replace(/^.+:(\d+(\.\d+)*)$/g, "$1");
|
||||
|
||||
var res = {
|
||||
res = {
|
||||
mountId: doc._key,
|
||||
mount: doc.mount,
|
||||
appId: doc.app,
|
||||
name: doc.name,
|
||||
description: doc.description,
|
||||
author: doc.author,
|
||||
description: doc.manifest.description,
|
||||
author: doc.manifest.author,
|
||||
system: doc.isSystem ? "yes" : "no",
|
||||
active: doc.active ? "yes" : "no",
|
||||
version: version
|
||||
development: doc.isDevelopment ? "yes" : "no",
|
||||
version: doc.version
|
||||
};
|
||||
|
||||
if (showPrefix) {
|
||||
|
@ -285,6 +313,52 @@ function listJson (showPrefix) {
|
|||
return result;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief prints all running Foxx applications
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
function list(onlyDevelopment) {
|
||||
var apps = listJson(undefined, onlyDevelopment);
|
||||
|
||||
arangodb.printTable(
|
||||
apps.sort(compareMounts),
|
||||
[ "mount", "name", "author", "description", "version", "development" ],
|
||||
{
|
||||
prettyStrings: true,
|
||||
totalString: "%s application(s) found",
|
||||
emptyString: "no applications found",
|
||||
rename: {
|
||||
"mount": "Mount",
|
||||
"name" : "Name",
|
||||
"author" : "Author",
|
||||
"description" : "Description",
|
||||
"version" : "Version",
|
||||
"development" : "Development"
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief returns all running Foxx applications in development mode
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
function listDevelopmentJson (showPrefix) {
|
||||
'use strict';
|
||||
return listJson(showPrefix, true);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief prints all running Foxx applications
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
function listDevelopment() {
|
||||
'use strict';
|
||||
return list(true);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief validate an app name and fail if it is invalid
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -308,13 +382,18 @@ function validateAppName (name) {
|
|||
/// @brief Exports
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
exports.list = list;
|
||||
exports.listJson = listJson;
|
||||
exports.listDevelopment = listDevelopment;
|
||||
exports.listDevelopmentJson = listDevelopmentJson;
|
||||
exports.buildGithubUrl = buildGithubUrl;
|
||||
exports.repackZipFile = repackZipFile;
|
||||
exports.processDirectory = processDirectory;
|
||||
exports.processGithubRepository = processGithubRepository;
|
||||
exports.validateAppName = validateAppName;
|
||||
|
||||
exports.tmp_getStorage = tmp_getStorage;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- END-OF-FILE
|
||||
// -----------------------------------------------------------------------------
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
///
|
||||
/// Copyright holder is triAGENS GmbH, Cologne, Germany
|
||||
///
|
||||
/// @author Dr. Frank Celler
|
||||
/// @author Dr. Frank Celler, Michael Hackstein
|
||||
/// @author Copyright 2013, triAGENS GmbH, Cologne, Germany
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
@ -1209,16 +1209,6 @@ exports.fetchFromGithub = function (url, name, version) {
|
|||
return "app:" + source.name + ":" + source.version;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
///// @brief returns all installed FOXX applications
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
exports.listJson = function () {
|
||||
"use strict";
|
||||
|
||||
return utils.listJson();
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief initializes the Foxx apps
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -1294,6 +1284,8 @@ exports.initializeFoxx = function () {
|
|||
// --CHAPTER-- used code
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
var db = require("internal").db;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- private variables
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@ -1348,16 +1340,22 @@ var validateManifestFile = function(file) {
|
|||
return mf;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Checks if the mountpoint is reserved for system apps
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
var isSystemMount = function(mount) {
|
||||
return (/^\/_/).test(mount);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief returns the root path for application. Knows about system apps
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
var computeRootAppPath = function(mount) {
|
||||
if (/^\/_/.test(mount)) {
|
||||
// Must be a system app
|
||||
if (isSystemMount(mount)) {
|
||||
return module.systemAppPath();
|
||||
}
|
||||
// A standard app
|
||||
return module.appPath();
|
||||
};
|
||||
|
||||
|
@ -1366,7 +1364,9 @@ var computeRootAppPath = function(mount) {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
var transformMountToPath = function(mount) {
|
||||
return fs.join.apply(this, mount.split("/").push("APP"));
|
||||
var list = mount.split("/");
|
||||
list.push("APP");
|
||||
return fs.join.apply(this, list);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -1415,36 +1415,29 @@ var executeAppScript = function(app, name, mount, prefix) {
|
|||
|
||||
app.loadAppScript(appContext, desc[name]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief sets up an app
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
function setupApp (app, mount, prefix) {
|
||||
"use strict";
|
||||
|
||||
return executeAppScript(app, "setup", mount, prefix);
|
||||
}
|
||||
var setupApp = function (app, mount, prefix) {
|
||||
return executeAppScript(app, "setup", mount, prefix);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief tears down an app
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
function teardownApp (app, mount, prefix) {
|
||||
"use strict";
|
||||
|
||||
return executeAppScript(app, "teardown", mount, prefix);
|
||||
}
|
||||
|
||||
|
||||
|
||||
var teardownApp = function (app, mount, prefix) {
|
||||
return executeAppScript(app, "teardown", mount, prefix);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief returns the app path and manifest
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
var appDescription = function (mount, options) {
|
||||
var appConfig = function (mount, options) {
|
||||
|
||||
var root = computeRootAppPath(mount);
|
||||
var path = transformMountToPath(mount);
|
||||
|
@ -1462,7 +1455,10 @@ function teardownApp (app, mount, prefix) {
|
|||
root: root,
|
||||
path: path,
|
||||
manifest: manifest,
|
||||
options: options
|
||||
options: options,
|
||||
mount: mount,
|
||||
isSystem: isSystemMount(mount),
|
||||
isDevelopment: false
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -1473,8 +1469,9 @@ function teardownApp (app, mount, prefix) {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
var createApp = function(mount, options) {
|
||||
var description = appDescription(mount);
|
||||
var app = module.createApp(description, options || {});
|
||||
var config = appConfig(mount);
|
||||
config.options = options || {};
|
||||
var app = module.createApp(config);
|
||||
if (app === null) {
|
||||
console.errorLines(
|
||||
"Cannot find application '%s'", mount);
|
||||
|
@ -1662,7 +1659,9 @@ var setup = function (mount) {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
var scanFoxx = function(mount, options) {
|
||||
delete appCache[mount];
|
||||
createApp(mount, options);
|
||||
var app = createApp(mount, options);
|
||||
utils.tmp_getStorage().save(app.toJSON());
|
||||
// TODO Routing?
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -1685,7 +1684,7 @@ var install = function(appInfo, mount, options) {
|
|||
fs.makeDirectoryRecursive(targetPath);
|
||||
// Remove the empty APP folder.
|
||||
// Ohterwise move will fail.
|
||||
fs.removeDirectoryRecursive(targetPath);
|
||||
fs.removeDirectory(targetPath);
|
||||
|
||||
if (appInfo === "EMPTY") {
|
||||
// Make Empty app
|
||||
|
@ -1704,25 +1703,38 @@ var install = function(appInfo, mount, options) {
|
|||
setup(mount);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Get information for app mounted at mount
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
var mountedApp = function(mount) {
|
||||
var app = lookupApp(mount);
|
||||
if (app === undefined) {
|
||||
throw "No app found for mount " + mount;
|
||||
}
|
||||
return app;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Exports
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
exports.install = install;
|
||||
exports.setup = setup;
|
||||
exports.scanFoxx = scanFoxx;
|
||||
/*
|
||||
exports.uninstall = uninstall;
|
||||
exports.setup = setup;
|
||||
exports.teardown = teardown;
|
||||
exports.list = list;
|
||||
exports.listJson = listJson;
|
||||
exports.replace = replace;
|
||||
exports.mountedApp = mountedApp;
|
||||
exports.upgrade = upgrade;
|
||||
exports.scanFoxx = scanFoxx;
|
||||
exports.developmentMounts = developmentMounts;
|
||||
exports.developmentMountsJson = developmentMountsJson;
|
||||
|
||||
exports.mountedApp = utils.mountedApp;
|
||||
*/
|
||||
|
||||
exports.list = utils.list;
|
||||
exports.listJson = utils.listJson;
|
||||
exports.listDevelopment = utils.listDevelopment;
|
||||
exports.listDevelopmentJson = utils.listDevelopmentJson;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Exports from foxx store module.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Reference in New Issue