diff --git a/dispatch_system/constants.json b/dispatch_system/constants.json index 6d4a1ca65236ff86b03c5936ba22d48d03625825..d52072c6b7ba7a4145a37164e7e67d158d7bbd92 100644 --- a/dispatch_system/constants.json +++ b/dispatch_system/constants.json @@ -4,9 +4,11 @@ "master_address": "localhost", "grunt_host": "https://www.namandixit.net/lovecraftian_nightmares/grunt", "couchdb_host": "localhost:5984", - "function_db_name": "serverless", - "metrics_db_name": "metrics", - "implicit_chain_db_name": "implicit_chain", + "db": { + "function_meta": "serverless", + "metrics": "metrics", + "implicit_chain_meta": "implicit_chain" + }, "network": { "network_bridge": "hybrid_kafka-serverless", "internal": { diff --git a/dispatch_system/dispatch_manager/explicit_chain_handler.js b/dispatch_system/dispatch_manager/explicit_chain_handler.js index 7f07948a724d40f07d8b29a1a5e8487684b0a34d..e23351b93671478a4a3af7799c8b5c2da983eac7 100644 --- a/dispatch_system/dispatch_manager/explicit_chain_handler.js +++ b/dispatch_system/dispatch_manager/explicit_chain_handler.js @@ -6,22 +6,18 @@ const fs = require('fs') const { spawn } = require('child_process') const fetch = require('node-fetch') const constants = require('../constants.json') -const secrets = require('./secrets.json') const operator = require('./operator') -const sharedStructures = require('./shared_structures') - -let metadataDB = `http://${secrets.couchdb_username}:${secrets.couchdb_password}@${constants.couchdb_host}` -metadataDB = metadataDB + "/" + constants.function_db_name + "/" - -let metricsDB = `http://${secrets.couchdb_username}:${secrets.couchdb_password}@${constants.couchdb_host}` -metricsDB = metricsDB + "/" + constants.metrics_db_name + "/" +const sharedMeta = require('./shared_meta') const logger = libSupport.logger const registry_url = constants.registry_url -let functionToResource = sharedStructures.functionToResource, - db = sharedStructures.db, - conditionProbabilityExpilict = sharedStructures.conditionProbabilityExpilict +let functionToResource = sharedMeta.functionToResource, + db = sharedMeta.db, + conditionProbabilityExpilict = sharedMeta.conditionProbabilityExpilict, + + metricsDB = sharedMeta.metricsDB, + metadataDB = sharedMeta.metadataDB router.post('/deploy', (req, res) => { @@ -478,10 +474,7 @@ function createDirectory(path) { }) } -function initialise(functionToResource) { - this.functionToResource = functionToResource -} module.exports = { - router, initialise + router } diff --git a/dispatch_system/dispatch_manager/index.js b/dispatch_system/dispatch_manager/index.js index 1187da41ff8817bc5ccd03279c3a69569c30f624..39f51be9f5592a068c07fed59f4ef9cf2d9665ad 100644 --- a/dispatch_system/dispatch_manager/index.js +++ b/dispatch_system/dispatch_manager/index.js @@ -10,19 +10,11 @@ const { spawn } = require('child_process'); const morgan = require('morgan'); const heap = require('heap'); const fetch = require('node-fetch'); -const swStats = require('swagger-stats'); -const apiSpec = require('./swagger.json'); +// const swStats = require('swagger-stats'); +// const apiSpec = require('./swagger.json'); const util = require('util') -const sharedStructures = require('./shared_structures') +const sharedMeta = require('./shared_meta') -/** - * URL to the couchdb database server used to store function metadata - */ -let metadataDB = `http://${secrets.couchdb_username}:${secrets.couchdb_password}@${constants.couchdb_host}` -metadataDB = metadataDB + "/" + constants.function_db_name + "/" - -let metricsDB = `http://${secrets.couchdb_username}:${secrets.couchdb_password}@${constants.couchdb_host}` -metricsDB = metricsDB + "/" + constants.metrics_db_name + "/" const app = express() const libSupport = require('./lib') @@ -31,14 +23,16 @@ let date = new Date(); let log_channel = constants.topics.log_channel let usedPort = new Map(), // TODO: remove after integration with RM - db = sharedStructures.db, // queue holding request to be dispatched - resourceMap = sharedStructures.resourceMap, // map between resource_id and resource details like node_id, port, associated function etc - functionToResource = sharedStructures.functionToResource, // a function to resource map. Each map contains a minheap of + db = sharedMeta.db, // queue holding request to be dispatched + resourceMap = sharedMeta.resourceMap, // map between resource_id and resource details like node_id, port, associated function etc + functionToResource = sharedMeta.functionToResource, // a function to resource map. Each map contains a minheap of // resources associated with the function - workerNodes = sharedStructures.workerNodes, // list of worker nodes currently known to the DM - functionBranchTree = sharedStructures.functionBranchTree // a tree to store function branch predictions - -chainHandler.initialise(functionToResource) + workerNodes = sharedMeta.workerNodes, // list of worker nodes currently known to the DM + functionBranchTree = sharedMeta.functionBranchTree, // a tree to store function branch predictions + + metricsDB = sharedMeta.metricsDB, + metadataDB = sharedMeta.metadataDB + let kafka = require('kafka-node'), Producer = kafka.Producer, client = new kafka.KafkaClient({ @@ -67,7 +61,7 @@ app.use(express.urlencoded({ extended: true })); const file_path = __dirname + "/repository/" app.use('/repository', express.static(file_path)); // file server hosting deployed functions app.use(fileUpload()) -app.use(swStats.getMiddleware({ swaggerSpec: apiSpec })); // statistics middleware +// app.use(swStats.getMiddleware({ swaggerSpec: apiSpec })); // statistics middleware app.use('/serverless/chain', chainHandler.router); // chain router (explicit_chain_handler.js) for handling explicit chains let requestQueue = [] diff --git a/dispatch_system/dispatch_manager/lib.js b/dispatch_system/dispatch_manager/lib.js index edcba6b4903bc4ddf9b9e31509fa2ddee32c864c..4b5a16995df30bb4b08cf82729761ea2e22f2fc1 100644 --- a/dispatch_system/dispatch_manager/lib.js +++ b/dispatch_system/dispatch_manager/lib.js @@ -6,10 +6,11 @@ const winston = require('winston') const constants = require('.././constants.json') const secrets = require('./secrets.json') const metrics = require('./metrics') +const sharedMeta = require('./shared_meta') const { createLogger, format, transports } = winston; const heap = require('heap') - +let implicitChainDB = sharedMeta.implicitChainDB let kafka = require('kafka-node'), Producer = kafka.Producer, client = new kafka.KafkaClient({ @@ -18,8 +19,7 @@ let kafka = require('kafka-node'), }), producer = new Producer(client) -let implicitChainDB = `http://${secrets.couchdb_username}:${secrets.couchdb_password}@${constants.couchdb_host}` -implicitChainDB = implicitChainDB + "/" + constants.implicit_chain_db_names + "/" + /** * Generates unique IDs of arbitrary length diff --git a/dispatch_system/dispatch_manager/shared_meta.js b/dispatch_system/dispatch_manager/shared_meta.js new file mode 100644 index 0000000000000000000000000000000000000000..45866938bbb53c5f6c45895db8b245b1de823230 --- /dev/null +++ b/dispatch_system/dispatch_manager/shared_meta.js @@ -0,0 +1,30 @@ +const secrets = require('./secrets.json') +const constants = require('.././constants.json') + +let db = new Map(), // queue holding request to be dispatched + resourceMap = new Map(), // map between resource_id and resource details like node_id, port, associated function etc + functionToResource = new Map(), // a function to resource map. Each map contains a minheap of + // resources associated with the function + workerNodes = new Map(), // list of worker nodes currently known to the DM + functionBranchTree = new Map(), // a tree to store function branch predictions + conditionProbabilityExpilict = new Map() // tree holding conditional probabilities for explicit chains + +/** + * URL to the couchdb database server used to store data + */ + +let metadataDB = `http://${secrets.couchdb_username}:${secrets.couchdb_password}@${constants.couchdb_host}` +metadataDB = metadataDB + "/" + constants.db.function_meta + "/" + +let metricsDB = `http://${secrets.couchdb_username}:${secrets.couchdb_password}@${constants.couchdb_host}` +metricsDB = metricsDB + "/" + constants.db.metrics + "/" + +let implicitChainDB = `http://${secrets.couchdb_username}:${secrets.couchdb_password}@${constants.couchdb_host}` +implicitChainDB = implicitChainDB + "/" + constants.db.implicit_chain_meta + "/" + + +module.exports = { + db, functionBranchTree, functionToResource, workerNodes, resourceMap, + conditionProbabilityExpilict, + metadataDB, metricsDB, implicitChainDB +} \ No newline at end of file diff --git a/dispatch_system/dispatch_manager/shared_structures.js b/dispatch_system/dispatch_manager/shared_structures.js deleted file mode 100644 index e4a4022eb08c45f05ecc3faeb914c4a82257d04b..0000000000000000000000000000000000000000 --- a/dispatch_system/dispatch_manager/shared_structures.js +++ /dev/null @@ -1,13 +0,0 @@ -let db = new Map(), // queue holding request to be dispatched - resourceMap = new Map(), // map between resource_id and resource details like node_id, port, associated function etc - functionToResource = new Map(), // a function to resource map. Each map contains a minheap of - // resources associated with the function - workerNodes = new Map(), // list of worker nodes currently known to the DM - functionBranchTree = new Map(), // a tree to store function branch predictions - conditionProbabilityExpilict = new Map() // tree holding conditional probabilities for explicit chains - - -module.exports = { - db, functionBranchTree, functionToResource, workerNodes, resourceMap, - conditionProbabilityExpilict -} \ No newline at end of file