Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
keeleliin
keeleliin-wrapper
Commits
8c197676
Commit
8c197676
authored
Aug 14, 2015
by
priit
Browse files
Utiliidi töö katkestamine
parent
0f360a37
Changes
6
Hide whitespace changes
Inline
Side-by-side
controllers/api/v1/service.js
View file @
8c197676
...
...
@@ -33,7 +33,7 @@ router.get('/:sessionId', function(req, res) {
});
});
router
.
get
(
'
/:sessionId/:fileId
'
,
function
(
req
,
res
)
{
router
.
get
(
'
/:sessionId/
download/
:fileId
'
,
function
(
req
,
res
)
{
logger
.
debug
({
request
:
'
Get file
'
,
instance
:
req
.
params
.
sessionId
,
file
:
req
.
params
.
fileId
});
...
...
@@ -59,4 +59,13 @@ router.get('/:sessionId/:fileId', function(req, res) {
});
});
router
.
get
(
'
/:sessionId/kill
'
,
function
(
req
,
res
)
{
wrapperService
.
kill
(
req
.
params
.
sessionId
,
function
(
err
,
data
)
{
if
(
err
){
return
res
.
status
(
404
).
send
({
errors
:
err
});
}
res
.
send
(
data
);
});
});
module
.
exports
=
router
;
src/model/session.js
View file @
8c197676
...
...
@@ -13,13 +13,14 @@ var Session = function( id ){
this
.
data
=
null
;
this
.
outputFiles
=
{};
this
.
errors
=
null
;
this
.
pid
=
null
;
//system process id
};
Session
.
prototype
.
addOutputFile
=
function
(
key
,
path
){
this
.
outputFiles
[
key
]
=
path
;
};
Session
.
prototype
.
setErrors
=
function
(
errors
,
path
){
Session
.
prototype
.
setErrors
=
function
(
errors
){
this
.
errors
=
errors
;
this
.
isSuccess
=
false
;
this
.
message
=
Session
.
messages
.
ERROR
...
...
src/service/executor/localExecutor.js
View file @
8c197676
...
...
@@ -3,23 +3,26 @@ var sessionService = require('../../service/sessionService');
var
LocalCommand
=
require
(
'
../../mapper/localCommand
'
);
var
spawn
=
require
(
'
child_process
'
).
spawn
;
var
fs
=
require
(
'
fs
'
);
var
async
=
require
(
'
async
'
);
function
LocalExecutor
()
{
var
self
=
this
;
this
.
execute
=
function
(
commandModel
,
callback
)
{
this
.
execute
=
function
(
commandModel
,
session
,
callback
)
{
var
response
=
{
isSuccess
:
true
,
stdOutPath
:
sessionService
.
getNewSessionFilePath
(
commandModel
.
session
,
{
extension
:
commandModel
.
stdOutExtension
}),
errors
:
[]
errors
:
[],
pid
:
null
};
var
localCommand
=
new
LocalCommand
(
commandModel
).
generate
();
self
.
_executeLocalCommand
(
localCommand
,
response
,
callback
);
self
.
_executeLocalCommand
(
localCommand
,
session
,
response
,
callback
);
};
this
.
_executeLocalCommand
=
function
(
localCommand
,
response
,
c
allback
)
{
this
.
_executeLocalCommand
=
function
(
localCommand
,
session
,
response
,
c
b
)
{
var
command
=
localCommand
.
command
;
var
commandParams
=
localCommand
.
commandParams
;
...
...
@@ -27,13 +30,29 @@ function LocalExecutor() {
logger
.
debug
(
localCommand
.
command
);
logger
.
debug
(
localCommand
.
commandParams
);
try
{
var
process
=
spawn
(
command
,
commandParams
);
self
.
_run
(
response
,
process
,
callback
);
}
catch
(
e
)
{
logger
.
error
(
e
);
callback
(
e
.
message
);
}
var
process
=
spawn
(
command
,
commandParams
);
async
.
waterfall
([
function
(
callback
)
{
session
.
pid
=
process
.
pid
;
sessionService
.
saveSession
(
session
,
function
(
err
,
session
)
{
callback
();
});
},
function
(
callback
)
{
self
.
_run
(
response
,
process
,
function
(
err
,
response
)
{
callback
(
err
,
response
);
});
},
function
(
response
,
callback
)
{
session
.
pid
=
null
;
sessionService
.
saveSession
(
session
,
function
(
err
,
session
)
{
callback
(
err
,
response
);
});
}
],
function
(
err
,
response
)
{
cb
(
err
,
response
);
});
};
this
.
_run
=
function
(
response
,
process
,
callback
)
{
...
...
@@ -59,14 +78,34 @@ function LocalExecutor() {
if
(
code
&&
code
>
0
){
response
.
isSuccess
=
false
;
process
.
kill
();
}
});
process
.
on
(
'
close
'
,
function
(
code
,
signal
)
{
logger
.
debug
(
'
child process terminated due to receipt of signal:
'
+
signal
+
'
code:
'
+
code
);
if
(
signal
==
'
SIGKILL
'
){
response
.
isSuccess
=
false
;
response
.
errors
.
push
({
util
:
'
Utiliidi töö katkestati!
'
});
}
callback
(
null
,
response
);
});
};
this
.
kill
=
function
(
session
,
callback
)
{
logger
.
debug
(
'
Kill system process
'
);
if
(
session
.
pid
){
try
{
process
.
kill
(
session
.
pid
,
'
SIGKILL
'
);
callback
(
null
,
'
Katkestamise signaal saadetud
'
);
}
catch
(
e
){
callback
(
'
Katkestamisel tekkis viga:
'
+
e
.
message
);
}
}
else
{
callback
(
'
Protsessi ei leitud
'
);
}
}
}
module
.
exports
=
new
LocalExecutor
();
\ No newline at end of file
src/service/wrapperService.js
View file @
8c197676
...
...
@@ -57,6 +57,41 @@ function WrapperService() {
callback
(
null
,
outputFile
);
});
};
this
.
kill
=
function
(
sessionId
,
callback
)
{
var
mapResponse
=
function
(
err
,
message
)
{
var
data
=
{};
data
.
sessionId
=
sessionId
;
if
(
err
){
data
.
success
=
false
;
data
.
message
=
err
;
}
else
{
data
.
success
=
true
;
data
.
message
=
message
;
}
var
response
=
{
response
:
data
};
return
response
;
};
sessionService
.
getSession
(
sessionId
,
function
(
err
,
session
)
{
if
(
err
){
return
callback
(
err
);
}
var
processor
=
new
Processor
();
if
(
processor
.
kill
!=
undefined
){
processor
.
kill
(
session
,
function
(
err
,
response
)
{
callback
(
null
,
mapResponse
(
err
,
response
));
});
}
else
{
callback
(
null
,
mapResponse
(
'
Teenusele ei ole katkestamise meetodit implementeeritud
'
));
}
});
};
}
module
.
exports
=
new
WrapperService
();
\ No newline at end of file
wrapper/inputOutputLocalCommand.js
View file @
8c197676
...
...
@@ -22,11 +22,11 @@ function InputOutputLocalCommand(){
return
callback
(
err
,
session
);
}
self
.
getCommandModel
(
session
,
function
(
err
,
model
)
{
self
.
_
getCommandModel
(
session
,
function
(
err
,
model
)
{
logger
.
debug
(
'
getCommandModel callback
'
);
if
(
err
)
return
callback
(
err
);
localExecutor
.
execute
(
model
,
function
(
err
,
response
)
{
localExecutor
.
execute
(
model
,
session
,
function
(
err
,
response
)
{
if
(
err
)
return
callback
(
err
);
logger
.
debug
(
'
Program is finished
'
);
...
...
@@ -50,7 +50,7 @@ function InputOutputLocalCommand(){
});
};
this
.
getCommandModel
=
function
(
session
,
callback
)
{
this
.
_
getCommandModel
=
function
(
session
,
callback
)
{
var
model
=
new
CommandModel
();
model
.
serviceProperties
.
commandTemplate
=
config
.
wrapper
.
command
.
commandTemplate
;
...
...
@@ -61,7 +61,9 @@ function InputOutputLocalCommand(){
logger
.
debug
(
'
Render callback
'
);
callback
(
err
,
model
);
});
}
};
this
.
kill
=
localExecutor
.
kill
;
}
module
.
exports
=
InputOutputLocalCommand
;
\ No newline at end of file
wrapper/simpleLocalCommand.js
View file @
8c197676
...
...
@@ -14,14 +14,14 @@ function SimpleLocalCommand(){
this
.
process
=
function
(
session
,
callback
)
{
self
.
getCommandModel
(
session
,
function
(
err
,
model
)
{
self
.
_
getCommandModel
(
session
,
function
(
err
,
model
)
{
logger
.
debug
(
'
GetCommandModel callback
'
);
if
(
err
){
logger
.
error
(
err
);
return
callback
(
err
);
}
localExecutor
.
execute
(
model
,
function
(
err
,
response
)
{
localExecutor
.
execute
(
model
,
session
,
function
(
err
,
response
)
{
if
(
err
)
return
callback
(
err
);
logger
.
debug
(
'
Program is finished
'
);
...
...
@@ -43,7 +43,7 @@ function SimpleLocalCommand(){
});
};
this
.
getCommandModel
=
function
(
session
,
callback
)
{
this
.
_
getCommandModel
=
function
(
session
,
callback
)
{
var
model
=
new
CommandModel
();
model
.
serviceProperties
.
commandTemplate
=
config
.
wrapper
.
command
.
commandTemplate
;
model
.
init
(
session
);
...
...
@@ -52,7 +52,9 @@ function SimpleLocalCommand(){
logger
.
debug
(
'
Render callback
'
);
callback
(
err
,
model
);
});
}
};
this
.
kill
=
localExecutor
.
kill
;
}
module
.
exports
=
SimpleLocalCommand
;
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment