Commit b6297c5f authored by Nilanjan Daw's avatar Nilanjan Daw

Changed args passing from file to commandline

Bug Fix. Passing startup data like port etc via config.json caused concurrency issues. Moved to passing variable through commandline
parent 283b7f36
...@@ -17,6 +17,7 @@ function runIsolate(local_repository, metadata) { ...@@ -17,6 +17,7 @@ function runIsolate(local_repository, metadata) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const worker = new Worker(filename, { const worker = new Worker(filename, {
argv: [resource_id, functionHash, port, "isolate"],
resourceLimits: { resourceLimits: {
maxOldGenerationSizeMb: memory maxOldGenerationSizeMb: memory
} }
...@@ -42,7 +43,7 @@ function runProcess(local_repository, metadata) { ...@@ -42,7 +43,7 @@ function runProcess(local_repository, metadata) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let timeStart = Date.now() let timeStart = Date.now()
const process = spawn('node', [`--max-old-space-size=${memory}`, filename, port]); const process = spawn('node', [filename, resource_id, functionHash, port, "process", `--max-old-space-size=${memory}` ]);
process.stdout.on('data', (data) => { process.stdout.on('data', (data) => {
console.log(`stdout: ${data}`); console.log(`stdout: ${data}`);
let timeDifference = Math.ceil((Date.now() - timeStart)) let timeDifference = Math.ceil((Date.now() - timeStart))
...@@ -90,7 +91,7 @@ function runContainer(metadata) { ...@@ -90,7 +91,7 @@ function runContainer(metadata) {
if (code != 0) if (code != 0)
reject("error") reject("error")
else { else {
const process = spawn('docker', ["run", "--rm", "-p", `${port}:5000`, "--name", resource_id, registry_url + imageName, const process = spawn('docker', ["run", "--rm", "-p", `${port}:${port}`, "--name", resource_id, registry_url + imageName,
resource_id, imageName, port, "container"]); resource_id, imageName, port, "container"]);
let result = ""; let result = "";
// timeStart = Date.now() // timeStart = Date.now()
...@@ -117,7 +118,7 @@ function runContainer(metadata) { ...@@ -117,7 +118,7 @@ function runContainer(metadata) {
} else { } else {
logger.info("container starting at port", port); logger.info("container starting at port", port);
const process = spawn('docker', ["run", "--rm", "-p", `${port}:5000`, "--name", resource_id, const process = spawn('docker', ["run", "--rm", "-p", `${port}:${port}`, "--name", resource_id,
registry_url + imageName, resource_id, imageName, port, "container"]); registry_url + imageName, resource_id, imageName, port, "container"]);
let result = ""; let result = "";
// timeStart = Date.now() // timeStart = Date.now()
......
...@@ -113,50 +113,43 @@ function startWorker(local_repository, producer, metadata) { ...@@ -113,50 +113,43 @@ function startWorker(local_repository, producer, metadata) {
let runtime = metadata.runtime let runtime = metadata.runtime
console.log(metadata); console.log(metadata);
logger.info(`Using port ${metadata.port} for functionHash ${metadata.functionHash}`); logger.info(`Using port ${metadata.port} for functionHash ${metadata.functionHash}`)
fs.writeFile('./local_repository/config.json', JSON.stringify({
port: metadata.port, if (runtime === "isolate")
functionHash: metadata.functionHash, execute.runIsolate(local_repository, metadata)
resource_id: metadata.resource_id, .catch(err => {
runtime: metadata.runtime, logger.error("=====================deployment failed=========================");
memory: metadata.resources.memory producer.send([{
}), () => { topic: "deployed",
if (runtime === "isolate") messages: JSON.stringify({
execute.runIsolate(local_repository, metadata) "status": false,
.catch(err => {
logger.error("=====================deployment failed=========================");
producer.send([{
topic: "deployed",
messages: JSON.stringify({
"status": false,
resource_id: metadata.resource_id,
"reason": "isolate exit"
})
}], () => { })
})
else if (runtime === "process")
execute.runProcess(local_repository, metadata)
.catch(err => {
logger.error("=====================deployment failed=========================");
producer.send([{ topic: "deployed",
messages: JSON.stringify({
"status": false,
resource_id: metadata.resource_id, resource_id: metadata.resource_id,
"reason": "process exit" "reason": "isolate exit"
}) }], () => { }) })
}) }], () => { })
else if (runtime === "container") })
execute.runContainer(metadata) else if (runtime === "process")
else { execute.runProcess(local_repository, metadata)
producer.send( .catch(err => {
[{ logger.error("=====================deployment failed=========================");
topic: "response", producer.send([{ topic: "deployed",
messages: JSON.stringify({ status: "unknown runtime" }) messages: JSON.stringify({
}], () => { }) "status": false,
resource_id: metadata.resource_id,
return "reason": "process exit"
} }) }], () => { })
}); })
else if (runtime === "container")
execute.runContainer(metadata)
else {
producer.send(
[{
topic: "response",
messages: JSON.stringify({ status: "unknown runtime" })
}], () => { })
return
}
} }
......
...@@ -2,21 +2,12 @@ ...@@ -2,21 +2,12 @@
const express = require('express') const express = require('express')
const bodyParser = require('body-parser') const bodyParser = require('body-parser')
const app = express() const app = express()
let port = 5000, resource_id, functionHash, portExternal, runtime let port = 5000, resource_id, functionHash, runtime
let config = null;
try { resource_id = process.argv[2]
config = require('./config.json') functionHash = process.argv[3]
port = config.port port = process.argv[4]
resource_id = config.resource_id runtime = process.argv[5]
functionHash = config.functionHash
runtime = config.runtime
} catch (e) {
port = 5000
resource_id = process.argv[2]
functionHash = process.argv[3]
portExternal = process.argv[4]
runtime = process.argv[5]
}
let kafka = require('kafka-node'), let kafka = require('kafka-node'),
Producer = kafka.Producer, Producer = kafka.Producer,
...@@ -47,7 +38,7 @@ app.listen(port, () => { ...@@ -47,7 +38,7 @@ app.listen(port, () => {
producer.send( producer.send(
[{ [{
topic: "deployed", topic: "deployed",
messages: JSON.stringify({ functionHash, portExternal, runtime, resource_id }), messages: JSON.stringify({ functionHash, portExternal: port, runtime, resource_id }),
"status": true "status": true
}], () => { }) }], () => { })
}) })
...@@ -59,7 +50,7 @@ function shouldDie() { ...@@ -59,7 +50,7 @@ function shouldDie() {
producer.send( producer.send(
[{ [{
topic: "removeWorker", topic: "removeWorker",
messages: JSON.stringify({ functionHash, portExternal, runtime, resource_id }) messages: JSON.stringify({ functionHash, portExternal: port, runtime, resource_id })
}], () => { }], () => {
console.log("Ending worker for function", functionHash, "resource_id", resource_id); console.log("Ending worker for function", functionHash, "resource_id", resource_id);
process.exit(0) process.exit(0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment