Commit bb3f9eb1 authored by Nilanjan Daw's avatar Nilanjan Daw

Added download and run for grunt

Added download  / execute capabilities for grunt. Added better support for RM at DM level
parent 72a72d4b
......@@ -5,7 +5,6 @@ const libSupport = require('./lib')
libSupport.updateConfig()
const node_id = config.id
const {spawn } = require('child_process')
let grunt = spawn('./grunt', [node_id])
const execute = require('./execute')
const fs = require('fs')
const kafka = require('kafka-node')
......@@ -53,6 +52,32 @@ libSupport.makeTopic(node_id).then(() => {
})
})
/**
* download and start grunt
*/
libSupport.download(host_url + '/repository/grunt', "grunt").then(() => {
logger.info("Downloaded grunt binary from repository")
fs.chmod('grunt', 0o555, (err) => {
logger.info("grunt made executable. Starting grunt")
let grunt = spawn('./grunt', [node_id])
grunt.stdout.on('data', data => {
logger.info(data.toString());
})
grunt.stderr.on('data', data => {
logger.info(data.toString());
})
grunt.on('close', (code) => {
logger.info("Grunt exited with exit code", code);
})
})
})
/**
* Start a worker executor of the runtime type
......@@ -95,21 +120,4 @@ function heartbeat() {
}
grunt.stdout.on('data', data => {
logger.info(data.toString());
})
grunt.stderr.on('data', data => {
logger.info(data.toString());
})
grunt.on('close', (code) => {
logger.info("Grunt exited with exit code", code);
})
setInterval(heartbeat, 1000);
......@@ -329,12 +329,12 @@ consumer.on('message', function (message) {
if (payload != null) {
payload[0].topic = message.nodes[0]
logger.info(payload);
/** get port and other resources
resourceMap.set(resource_id, {
runtime, functionHash, port, node_id
})
/** get port and other resources */
let resource = resourceMap.get(message.id)
resource.node_id = message.nodes[0] // TODO: update this to message.nodes[0].node_id
// resource.port = message.nodes[0].port TODO: update after RM supports port allocation
resourceMap.set(message.id, resource)
logger.info(resourceMap);
*/
producer.send(payload, () => { })
} else {
logger.error("something went wrong");
......@@ -345,15 +345,4 @@ consumer.on('message', function (message) {
});
setInterval(dispatch, 2000);
app.listen(port, () => logger.info(`Server listening on port ${port}!`))
// {
// id: "!!!!!",
// "grunts": [{
// id: "a",
// port: 12121
// },{
// id: "b",
// port: 123445
// }]
// }
\ No newline at end of file
app.listen(port, () => logger.info(`Server listening on port ${port}!`))
\ No newline at end of file
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