Skip to content

Commit

Permalink
Merge branch 'machine-plus-human-identifiers' into uploadsBugFixing
Browse files Browse the repository at this point in the history
  • Loading branch information
NelsonPereira1991 committed Aug 2, 2017
2 parents dc47961 + 222ff3d commit bc7ca45
Show file tree
Hide file tree
Showing 11 changed files with 149 additions and 195 deletions.
25 changes: 14 additions & 11 deletions conf/deployment_configs.json
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,12 @@
"reload_ontologies_on_startup": true,
"reload_descriptors_on_startup": true,
"reload_research_domains_on_startup": true,
"reload_descriptor_validation_data" : false,
"reload_descriptor_validation_data" : true,
"clear_session_store": true,
"clear_caches" : true,
"log_bootup_actions" : true,
"destroy_all_graphs_on_startup": false
"destroy_all_graphs": false,
"destroy_all_indexes": false
},
"baselines": {
},
Expand Down Expand Up @@ -582,17 +583,18 @@
}
},
"startup": {
"load_databases": false,
"load_databases": true,
"reload_administrators_on_startup": true,
"reload_demo_users_on_startup": true,
"reload_demo_users_on_startup": false,
"reload_ontologies_on_startup": true,
"reload_descriptors_on_startup": true,
"reload_research_domains_on_startup": true,
"reload_descriptor_validation_data" : false,
"reload_descriptor_validation_data" : true,
"clear_session_store": true,
"clear_caches" : true,
"log_bootup_actions" : false,
"destroy_all_graphs_on_startup": true
"log_bootup_actions" : true,
"destroy_all_graphs": true,
"destroy_all_indexes": true
},
"baselines": {
},
Expand Down Expand Up @@ -929,15 +931,16 @@
"startup": {
"load_databases": true,
"reload_administrators_on_startup": true,
"reload_demo_users_on_startup": true,
"reload_demo_users_on_startup": false,
"reload_ontologies_on_startup": true,
"reload_descriptors_on_startup": true,
"reload_research_domains_on_startup": true,
"reload_descriptor_validation_data" : false,
"reload_descriptor_validation_data" : true,
"clear_session_store": true,
"clear_caches" : true,
"log_bootup_actions" : false,
"destroy_all_graphs_on_startup": true
"log_bootup_actions" : true,
"destroy_all_graphs": true,
"destroy_all_indexes": true
},
"baselines": {
},
Expand Down
29 changes: 15 additions & 14 deletions conf/scripts/install.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
#!/usr/bin/env bash

#install NVM, Node 6.10, Node Automatic Version switcher
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.1/install.sh | bash &&
export NVM_DIR="$HOME/.nvm" &&
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"

# Want NVM to be loaded on every terminal you open? Add to ~/.bash_profile this:

#export NVM_DIR="$HOME/.nvm" &&
#[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"


INITIAL_DIR=`pwd`
NODE_VERSION=`cat .node-version`

Expand All @@ -19,10 +8,18 @@ then
echo "Unable to determine the version of NodeJS to install!"
exit 1
else
#install NVM, Node, Node Automatic Version switcher
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.1/install.sh | bash &&
export NVM_DIR="$HOME/.nvm" &&
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" && # This loads nvm

nvm install $NODE_VERSION
npm install -g avn avn-nvm avn-n
avn setup
nvm install $NODE_VERSION &&
npm install -g avn avn-nvm avn-n &&
avn setup &&

[[ -s "$HOME/.avn/bin/avn.sh" ]] && source "$HOME/.avn/bin/avn.sh" && # load avn

echo "loaded NVM and AVN."

#update npm
npm install npm
Expand All @@ -41,3 +38,7 @@ else
grunt
fi

# Want NVM to be loaded on every terminal you open? Add to ~/.bash_profile this:

#export NVM_DIR="$HOME/.nvm" &&
#[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
"reinstall": "rm -rf node_modules && npm cache clean && npm install",
"preinstall": "npm i -g npm && npm i -g gladstone && npm install -g istanbul && npm i -g nyc && npm i -g coveralls",
"post-install": "",
"test": "cross-env NODE_ENV=test node node_modules/.bin/_mocha ./test/index.Test.js -t 60000 --ui bdd",
"test": "cross-env NODE_ENV=test node node_modules/.bin/_mocha ./test/index.Test.js -t 15000 --ui bdd --bail",
"watch": "npm test -w",
"calculate-coverage": "nyc --temp-directory=coverage --reporter=lcov npm test",
"report-coverage": "node ./node_modules/coveralls/bin/coveralls.js < ./coverage/lcov.info && node ./node_modules/codeclimate-test-reporter/bin/codeclimate.js < ./coverage/lcov.info && rm -rf coverage",
"everything": "rm -rf node_modules && npm cache verify && npm install && npm run test && npm run calculate-coverage && npm run report-coverage",
"remote_debug": "node app.js --debug=5858",
"profile": "cross-env NODE_ENV=test node --prof node_modules/.bin/_mocha ./test/index.Test.js -t 60000 --ui bdd"
"profile": "cross-env NODE_ENV=test node --prof node_modules/.bin/_mocha ./test/index.Test.js -t 15000 --ui bdd"
},
"dependencies": {
"archiver": "*",
Expand Down
14 changes: 2 additions & 12 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,10 @@ let express = require('express'),
Q = require('q');

/**
* Promises for reporting the progress of the bootup operation.
* Promise for reporting the bootup operation.
*/

let bootupCompletePromise = Q.defer();
let serverListeningPromise = Q.defer();
let connectionsInitializedPromise = Q.defer();

self.app = express();

Expand Down Expand Up @@ -121,15 +119,10 @@ const prepareEnvironment = function(callback)
}
],function(err, results)
{
if(isNull(err))
{
connectionsInitializedPromise.resolve();
}
else
if(!isNull(err))
{
console.error("There was an error performing preliminary setup operations during Dendro bootup!");
console.error(err.stack);
connectionsInitializedPromise.reject(results);
}

return callback(err, results);
Expand Down Expand Up @@ -205,7 +198,6 @@ const startWebServer = function(callback)
function(app, server, callback)
{
self.server = server;
bootupCompletePromise.resolve({server: self.server, app: self.app});

if (process.env.NODE_ENV !== "test")
{
Expand Down Expand Up @@ -260,6 +252,4 @@ async.series([
}]
);

exports.bootupComplete = bootupCompletePromise.promise;
exports.connectionsInitialized = connectionsInitializedPromise.promise;
exports.serverListening = serverListeningPromise.promise;
4 changes: 2 additions & 2 deletions src/bootup/init/setup_graceful_close.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ const Config = require(Pathfinder.absPathInSrcFolder("models/meta/config.js")).C
const nodeCleanup = require('node-cleanup');
const npid = require('npid');
const async = require('async');
let pid;

const setupGracefulClose = function(app, server, callback)
{
//setup graceful server close
if(process.env.NODE_ENV !== 'test')
{
const pid = npid.create(Pathfinder.absPathInApp('running.pid'), true); //second arg = overwrite pid if exists
pid = npid.create(Pathfinder.absPathInApp('running.pid'), true); //second arg = overwrite pid if exists
pid.removeOnExit();
}

Expand Down Expand Up @@ -111,7 +112,6 @@ const setupGracefulClose = function(app, server, callback)
haltHTTPServer,
removePIDFile
], function(err, results){
// calling process.exit() won't inform parent process of signal
callback(err, results);
});
};
Expand Down
49 changes: 28 additions & 21 deletions src/bootup/init/setup_passport.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const Pathfinder = global.Pathfinder;
const Config = require(Pathfinder.absPathInSrcFolder("models/meta/config.js")).Config;
const User = require(Pathfinder.absPathInSrcFolder("models/user.js")).User;
const Logger = require(Pathfinder.absPathInSrcFolder("utils/logger.js")).Logger;
const isNull = require(Pathfinder.absPathInSrcFolder("utils/null.js")).isNull;

let slug = require('slug'),
session_key = "dendro_" + slug(Config.host) + "_sessionKey",
Expand All @@ -18,29 +19,35 @@ const setupPassport = function(app, callback)

const MongoStore = require('connect-mongo')(expressSession);

const sessionMongoStore = new MongoStore(
const expressSessionParameters = {
secret: Config.crypto.secret,
genid: function ()
{
"host": Config.mongoDBHost,
"port": Config.mongoDbPort,
"db": Config.mongoDBSessionStoreCollection,
"url": 'mongodb://' + Config.mongoDBHost + ":" + Config.mongoDbPort + "/" + Config.mongoDBSessionStoreCollection
});
const uuid = require('uuid');
return uuid.v4()
},
key: session_key,
cookie: {maxAge: 1000 * 60 * 60 * 24 * 5}, //5 days max session age
resave: false,
saveUninitialized: false
};

app.use(expressSession(
{
secret: Config.crypto.secret,
genid: function ()

let sessionMongoStore;
if(process.env.NODE_ENV !== "test")
{
sessionMongoStore = new MongoStore(
{
const uuid = require('uuid');
return uuid.v4()
},
key: session_key,
cookie: {maxAge: 1000 * 60 * 60 * 24 * 5}, //5 days max session age
store: sessionMongoStore,
resave: false,
saveUninitialized: false
})
);
"host": Config.mongoDBHost,
"port": Config.mongoDbPort,
"db": Config.mongoDBSessionStoreCollection,
"url": 'mongodb://' + Config.mongoDBHost + ":" + Config.mongoDbPort + "/" + Config.mongoDBSessionStoreCollection
});

expressSessionParameters.store = sessionMongoStore;
}

app.use(expressSession(expressSessionParameters));

const passport = require('passport');
//set serialization and deserialization methods
Expand All @@ -61,7 +68,7 @@ const setupPassport = function(app, callback)
next(null, req, res);
});

if (Config.startup.clear_session_store)
if (Config.startup.clear_session_store && !isNull(sessionMongoStore))
{
Logger.log_boot_message("info", "Clearing session store!");
sessionMongoStore.clear(function (err, result)
Expand Down
2 changes: 1 addition & 1 deletion src/bootup/load/create_indexes.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const createIndexes = function(app, index, callback)
{
Logger.log_boot_message("info","Now trying to connect to ElasticSearch Cluster to check if the required indexes exist or need to be created...");

index.create_new_index(1, 1, false, function(error, result)
index.create_new_index(1, 1, Config.startup.destroy_indexes, function(error, result)
{
if(!isNull(error))
{
Expand Down
61 changes: 27 additions & 34 deletions src/bootup/load/destroy_all_graphs.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,38 @@ const Config = require(Pathfinder.absPathInSrcFolder("models/meta/config.js")).C

const destroyAllGraphs = function(app, callback)
{
if(Config.startup.load_databases && Config.startup.destroy_all_graphs_on_startup)
if(Config.startup.load_databases && Config.startup.destroy_all_graphs)
{
if(Config.debug.database.destroy_all_graphs_on_startup)
{
const graphs = Object.keys(GLOBAL.db);
const conn = GLOBAL.db.default.connection;
const graphs = Object.keys(Config.db);
const conn = Config.db.default.connection;

async.map(graphs, function(graph, cb){
async.map(graphs, function(graph, cb){

const graphUri = GLOBAL.db[graph].graphUri;
conn.deleteGraph(graphUri, function(err){
if(err)
{
return callback(err);
}
else
{
conn.graphExists(graphUri, function(err, exists){
if(exists)
{
console.error("Tried to delete graph " + graphUri + " but it still exists!");
process.exit(1);
}
else
{
cb(null, exists);
}
});
}
});
}, function(err, res)
{
return callback(err);
const graphUri = Config.db[graph].graphUri;
conn.deleteGraph(graphUri, function(err){
if(err)
{
return callback(err);
}
else
{
conn.graphExists(graphUri, function(err, exists){
if(exists)
{
console.error("Tried to delete graph " + graphUri + " but it still exists!");
process.exit(1);
}
else
{
cb(null, exists);
}
});
}
});
}
else
}, function(err, res)
{
return callback(null);
}
return callback(err);
});
}
else
{
Expand Down
Loading

0 comments on commit bc7ca45

Please sign in to comment.