Skip to content

Commit

Permalink
now end to end "works"
Browse files Browse the repository at this point in the history
  • Loading branch information
dmolchanenko committed Feb 1, 2013
1 parent 7859294 commit ed8fb5f
Show file tree
Hide file tree
Showing 7 changed files with 362 additions and 67 deletions.
88 changes: 70 additions & 18 deletions agent/routes/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ exports.Post = function(req, res){
}
else if(command.command == "cleanup"){
console.log("cleaning up");
cleanUpBinDir(function(){
res.send("{error:null,success:true}");
stopLauncher(function(){
cleanUpBinDir(function(){
res.send("{error:null,success:true}");
});
});
}
else if (command.command == "start launcher"){
Expand All @@ -35,24 +37,55 @@ exports.Post = function(req, res){
}
};


function startLauncher_debug(callback){
launcherConn = net.connect(3002, function(){
callback(null);
var cache = "";
launcherConn.on('data', function(data) {
cache += data.toString();

console.log('data:', data.toString());
if (cache.indexOf("--EOM--") != -1){
var msg = JSON.parse(cache.substring(0,cache.length - 7));
if (msg.command == "action finished"){
sendActionResult(msg);
}
cache = "";
}
});

launcherConn.on('error', function(err) {
callback(err);
});
});
}



function startLauncher(callback){
//callback();
//return
launcherProc = spawn("../Java/bin/java.exe",["-cp",'../lib/*;../launcher/*',"redwood.launcher.Launcher"],{cwd:path.resolve(__dirname,"../bin/")});
launcherProc = spawn("../Java/bin/java.exe",["-cp",'../lib/*;../launcher/*',"-Xmx512m","redwood.launcher.Launcher"],{cwd:path.resolve(__dirname,"../bin/")});
launcherProc.stderr.on('data', function (data) {
console.log("error:"+data.toString());
launcherProc = null;
callback(data.toString());
});
launcherProc.stdout.on('data', function (data) {
console.log('stdout: ' + data.toString());
if (data.toString() == "launcher running.\r\n"){
callback(null);
if (data.toString().indexOf("launcher running.") != -1){
launcherConn = net.connect(3002, function(){
callback(null);
var cache = "";
launcherConn.on('data', function(data) {
cache += data.toString();

console.log('data:', data.toString());
var msg = JSON.parse(data.toString());
if (msg.command == "action finished"){
sendActionResult(msg);
if (cache.indexOf("--EOM--") != -1){
var msg = JSON.parse(cache.substring(0,cache.length - 7));
if (msg.command == "action finished"){
sendActionResult(msg);
}
cache = "";
}
});

Expand All @@ -62,15 +95,29 @@ function startLauncher(callback){
});
}
});


}

function cleanUpBinDir(callback){
function stopLauncher(callback){
if (launcherProc != null){
launcherProc.kill();
launcherProc = null;
//sendLauncherCommand({command:"exit"},function(){
launcherProc.kill();
launcherProc = null;
callback();
//});
}
//if there is runaway launcher try to kill it
else{
var conn;
conn = net.connect(3002, function(){
conn.write(JSON.stringify({command:"exit"})+"\r\n");
setTimeout(function() { callback();}, 1000);
}).on('error', function(err) {
callback();
});
}
}

function cleanUpBinDir(callback){
deleteDir(path.resolve(__dirname,"../bin/"),callback)
}

Expand Down Expand Up @@ -107,16 +154,21 @@ function deleteDir(dir,callback){
}

function sendLauncherCommand(command,callback){
launcherConn.write(JSON.stringify(command)+"\n");
launcherConn.end();
if (launcherConn == null){
console.log("unable to connect to launcher");
return;
}
launcherConn.write(JSON.stringify(command)+"\r\n");
//launcherConn.end();
callback(null);
}


function sendActionResult(result){
var options = {
hostname: "localhost",
port: 3000,
path: 'executionengine/actionresult',
path: '/executionengine/actionresult',
method: 'POST',
agent:false,
headers: {
Expand Down
1 change: 1 addition & 0 deletions agent/routes/fileupload.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ exports.Post = function(req, res){
fs.rename(tmp_path, target_path, function(err) {
if (err){
res.send('{error:"'+err+'"}');
console.log("ERROR:"+err);
fs.unlink(tmp_path);
return;
}
Expand Down
6 changes: 3 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var express = require('express')
, methodFinder = require('./routes/methodFinder');


var app = module.exports = express.createServer(
var app = express.createServer(
//express.bodyParser(),
//express.cookieParser(),
//express.session({ secret: 'redwoodsecrect' })
Expand Down Expand Up @@ -80,7 +80,7 @@ app.post('/variableTags',auth.auth, variableTags.variableTagsPost);

//start execution
app.post('/executionengine/startexecution',auth.auth, executionengine.startexecutionPost);
app.post('/executionengine/actionresult',auth.auth, executionengine.actionresultPost);
app.post('/executionengine/actionresult',executionengine.actionresultPost);

//machines
app.get('/machines',auth.auth, machines.machinesGet);
Expand Down Expand Up @@ -182,5 +182,5 @@ app.post('/methodFinder',auth.auth, methodFinder.methodFinderPost);
realtime.initSocket(app);

app.listen(3000, function(){
console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
console.log("Express server listening on port %d in %s mode", 3000, app.settings.env);
});
6 changes: 3 additions & 3 deletions routes/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ exports.logInSucess = function(req,res){
if ((project == null) && ((req.cookies.project === undefined)||(req.cookies.project == "") )){
projects.allProjects(function(projects){
res.cookie('project', projects[0].name, {maxAge: 2592000000, httpOnly: false });
res.json({error:null,redirect:"/index.html"});
res.json({error:null,redirect:"./index.html"});
});
}
else if (project == null){
Expand All @@ -42,14 +42,14 @@ exports.logInSucess = function(req,res){
if (found == false){
res.cookie('project', projects[0].name, {maxAge: 2592000000, httpOnly: false });
}
res.json({error:null,redirect:"/index.html"});
res.json({error:null,redirect:"./index.html"});
});
}
else{
if ((req.cookies.project === undefined)||(req.cookies.project == "")){
res.cookie('project', project, {maxAge: 2592000000, httpOnly: false });
}
res.json({error:null,redirect:"/index.html"});
res.json({error:null,redirect:"./index.html"});
}
})
};
Expand Down
4 changes: 3 additions & 1 deletion routes/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ exports.operation = function(msg, id,callback,onFinish){
//}
//else{
delete compileProcs[id];
onFinish();
if (onFinish){
onFinish();
}
//}
});
callback("");
Expand Down
Loading

0 comments on commit ed8fb5f

Please sign in to comment.