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 errors = arangodb.errors;
|
||||||
var ArangoError = arangodb.ArangoError;
|
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
|
/// @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';
|
'use strict';
|
||||||
|
|
||||||
var aal = getStorage();
|
var mounts = tmp_getStorage();
|
||||||
var cursor = aal.byExample({ type: "mount" });
|
var cursor;
|
||||||
|
if (onlyDevelopment) {
|
||||||
|
cursor = mounts.byExample({isDevelopment: true});
|
||||||
|
} else {
|
||||||
|
cursor = mounts.all();
|
||||||
|
}
|
||||||
var result = [];
|
var result = [];
|
||||||
|
var doc, res;
|
||||||
|
|
||||||
while (cursor.hasNext()) {
|
while (cursor.hasNext()) {
|
||||||
var doc = cursor.next();
|
doc = cursor.next();
|
||||||
|
|
||||||
var version = doc.app.replace(/^.+:(\d+(\.\d+)*)$/g, "$1");
|
res = {
|
||||||
|
|
||||||
var res = {
|
|
||||||
mountId: doc._key,
|
mountId: doc._key,
|
||||||
mount: doc.mount,
|
mount: doc.mount,
|
||||||
appId: doc.app,
|
|
||||||
name: doc.name,
|
name: doc.name,
|
||||||
description: doc.description,
|
description: doc.manifest.description,
|
||||||
author: doc.author,
|
author: doc.manifest.author,
|
||||||
system: doc.isSystem ? "yes" : "no",
|
system: doc.isSystem ? "yes" : "no",
|
||||||
active: doc.active ? "yes" : "no",
|
development: doc.isDevelopment ? "yes" : "no",
|
||||||
version: version
|
version: doc.version
|
||||||
};
|
};
|
||||||
|
|
||||||
if (showPrefix) {
|
if (showPrefix) {
|
||||||
|
@ -285,6 +313,52 @@ function listJson (showPrefix) {
|
||||||
return result;
|
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
|
/// @brief validate an app name and fail if it is invalid
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -308,13 +382,18 @@ function validateAppName (name) {
|
||||||
/// @brief Exports
|
/// @brief Exports
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
exports.list = list;
|
||||||
exports.listJson = listJson;
|
exports.listJson = listJson;
|
||||||
|
exports.listDevelopment = listDevelopment;
|
||||||
|
exports.listDevelopmentJson = listDevelopmentJson;
|
||||||
exports.buildGithubUrl = buildGithubUrl;
|
exports.buildGithubUrl = buildGithubUrl;
|
||||||
exports.repackZipFile = repackZipFile;
|
exports.repackZipFile = repackZipFile;
|
||||||
exports.processDirectory = processDirectory;
|
exports.processDirectory = processDirectory;
|
||||||
exports.processGithubRepository = processGithubRepository;
|
exports.processGithubRepository = processGithubRepository;
|
||||||
exports.validateAppName = validateAppName;
|
exports.validateAppName = validateAppName;
|
||||||
|
|
||||||
|
exports.tmp_getStorage = tmp_getStorage;
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// --SECTION-- END-OF-FILE
|
// --SECTION-- END-OF-FILE
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
///
|
///
|
||||||
/// Copyright holder is triAGENS GmbH, Cologne, Germany
|
/// Copyright holder is triAGENS GmbH, Cologne, Germany
|
||||||
///
|
///
|
||||||
/// @author Dr. Frank Celler
|
/// @author Dr. Frank Celler, Michael Hackstein
|
||||||
/// @author Copyright 2013, triAGENS GmbH, Cologne, Germany
|
/// @author Copyright 2013, triAGENS GmbH, Cologne, Germany
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
@ -1209,16 +1209,6 @@ exports.fetchFromGithub = function (url, name, version) {
|
||||||
return "app:" + source.name + ":" + source.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
|
/// @brief initializes the Foxx apps
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -1294,6 +1284,8 @@ exports.initializeFoxx = function () {
|
||||||
// --CHAPTER-- used code
|
// --CHAPTER-- used code
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
var db = require("internal").db;
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// --SECTION-- private variables
|
// --SECTION-- private variables
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
@ -1348,16 +1340,22 @@ var validateManifestFile = function(file) {
|
||||||
return mf;
|
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
|
/// @brief returns the root path for application. Knows about system apps
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
var computeRootAppPath = function(mount) {
|
var computeRootAppPath = function(mount) {
|
||||||
if (/^\/_/.test(mount)) {
|
if (isSystemMount(mount)) {
|
||||||
// Must be a system app
|
|
||||||
return module.systemAppPath();
|
return module.systemAppPath();
|
||||||
}
|
}
|
||||||
// A standard app
|
|
||||||
return module.appPath();
|
return module.appPath();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1366,7 +1364,9 @@ var computeRootAppPath = function(mount) {
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
var transformMountToPath = 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]);
|
app.loadAppScript(appContext, desc[name]);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief sets up an app
|
/// @brief sets up an app
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
function setupApp (app, mount, prefix) {
|
var setupApp = function (app, mount, prefix) {
|
||||||
"use strict";
|
return executeAppScript(app, "setup", mount, prefix);
|
||||||
|
};
|
||||||
return executeAppScript(app, "setup", mount, prefix);
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief tears down an app
|
/// @brief tears down an app
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
function teardownApp (app, mount, prefix) {
|
var teardownApp = function (app, mount, prefix) {
|
||||||
"use strict";
|
return executeAppScript(app, "teardown", mount, prefix);
|
||||||
|
};
|
||||||
return executeAppScript(app, "teardown", mount, prefix);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief returns the app path and manifest
|
/// @brief returns the app path and manifest
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
var appDescription = function (mount, options) {
|
var appConfig = function (mount, options) {
|
||||||
|
|
||||||
var root = computeRootAppPath(mount);
|
var root = computeRootAppPath(mount);
|
||||||
var path = transformMountToPath(mount);
|
var path = transformMountToPath(mount);
|
||||||
|
@ -1462,7 +1455,10 @@ function teardownApp (app, mount, prefix) {
|
||||||
root: root,
|
root: root,
|
||||||
path: path,
|
path: path,
|
||||||
manifest: manifest,
|
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 createApp = function(mount, options) {
|
||||||
var description = appDescription(mount);
|
var config = appConfig(mount);
|
||||||
var app = module.createApp(description, options || {});
|
config.options = options || {};
|
||||||
|
var app = module.createApp(config);
|
||||||
if (app === null) {
|
if (app === null) {
|
||||||
console.errorLines(
|
console.errorLines(
|
||||||
"Cannot find application '%s'", mount);
|
"Cannot find application '%s'", mount);
|
||||||
|
@ -1662,7 +1659,9 @@ var setup = function (mount) {
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
var scanFoxx = function(mount, options) {
|
var scanFoxx = function(mount, options) {
|
||||||
delete appCache[mount];
|
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);
|
fs.makeDirectoryRecursive(targetPath);
|
||||||
// Remove the empty APP folder.
|
// Remove the empty APP folder.
|
||||||
// Ohterwise move will fail.
|
// Ohterwise move will fail.
|
||||||
fs.removeDirectoryRecursive(targetPath);
|
fs.removeDirectory(targetPath);
|
||||||
|
|
||||||
if (appInfo === "EMPTY") {
|
if (appInfo === "EMPTY") {
|
||||||
// Make Empty app
|
// Make Empty app
|
||||||
|
@ -1704,25 +1703,38 @@ var install = function(appInfo, mount, options) {
|
||||||
setup(mount);
|
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
|
/// @brief Exports
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
exports.install = install;
|
exports.install = install;
|
||||||
|
exports.setup = setup;
|
||||||
|
exports.scanFoxx = scanFoxx;
|
||||||
/*
|
/*
|
||||||
exports.uninstall = uninstall;
|
exports.uninstall = uninstall;
|
||||||
exports.setup = setup;
|
|
||||||
exports.teardown = teardown;
|
exports.teardown = teardown;
|
||||||
exports.list = list;
|
|
||||||
exports.listJson = listJson;
|
|
||||||
exports.replace = replace;
|
exports.replace = replace;
|
||||||
exports.mountedApp = mountedApp;
|
|
||||||
exports.upgrade = upgrade;
|
exports.upgrade = upgrade;
|
||||||
exports.scanFoxx = scanFoxx;
|
|
||||||
exports.developmentMounts = developmentMounts;
|
exports.mountedApp = utils.mountedApp;
|
||||||
exports.developmentMountsJson = developmentMountsJson;
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
exports.list = utils.list;
|
||||||
|
exports.listJson = utils.listJson;
|
||||||
|
exports.listDevelopment = utils.listDevelopment;
|
||||||
|
exports.listDevelopmentJson = utils.listDevelopmentJson;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief Exports from foxx store module.
|
/// @brief Exports from foxx store module.
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
Loading…
Reference in New Issue