Commit 4058ad4f authored by priit's avatar priit

Utiliidi töö katkestamine

parent 04171f4e
......@@ -6,6 +6,11 @@ var wrapperService = require(__base + '/src/service/wrapperService');
var fs = require('fs');
var installService = require(__base + '/src/service/integration/installService');
router.get('/config', function(req, res) {
return res.send(installService.getConfiguration());
});
router.post('/', function ( req, res ) {
logger.debug(req.body);
......@@ -69,10 +74,6 @@ router.get('/:sessionId/kill', function(req, res) {
});
});
router.get('/install/external', function(req, res) {
installService.install(function(err, result) {
return res.send({errors: err, data: result});
});
});
module.exports = router;
......@@ -7,32 +7,26 @@ var InstallService = function() {
var self = this;
this.install = function(cb) {
var wrapper = config.wrapper;
var serviceConfig = self.getConfiguration();
serviceConfig.apiKey = config.integration.apiKey;
request.post({
url: self._composeInstallUrl(config.integration.installUrl, wrapper.id, self._getApiKey()),
json: self.getConfiguration()
url: config.integration.installUrl,
json: serviceConfig
}, function(error, response, body) {
logger.error('1 ',error);
logger.error('2 ',response);
logger.error('3 ',body);
if (error) {
logger.error(error);
return cb(error);
}
var data = {
errors: null,
data: null
};
if (body != undefined) {
if (body.errors) {
data.errors = body.errors;
}
if (body.data) {
data.data = body.data;
}
}
logger.debug(data);
return cb(data.errors, data.data);
});
};
......@@ -44,7 +38,7 @@ var InstallService = function() {
configuration.sid = wrapper.id;
configuration.name = wrapper.title;
configuration.description = wrapper.description;
configuration.url = self._composeUrl(config.serverUrl, wrapper.port);
configuration.url = config.serverUrl + ':' + wrapper.port + '/api/v1/';
configuration.inputTypes = [];
configuration.outputTypes = [];
......@@ -72,14 +66,12 @@ var InstallService = function() {
var requestBodyTemplate = wrapper.requestConf.requestBodyTemplate;
for(var property in requestBodyTemplate){
if (requestBodyTemplate.hasOwnProperty(property)) {
if (wrapper.requestConf.requestBodyParamsMappings[property].usageType != config.paramUsageTypes.META) {
configuration.parameters.push({
key: property,
type: wrapper.requestConf.requestBodyParamsMappings[property].type,
value: requestBodyTemplate[property]
});
}
configuration.parameters.push({
key: property,
type: wrapper.requestConf.requestBodyParamsMappings[property].type,
options: wrapper.requestConf.requestBodyParamsMappings[property].options,
value: requestBodyTemplate[property]
});
}
}
}
......@@ -87,31 +79,6 @@ var InstallService = function() {
return configuration;
};
this._composeUrl = function(serverUrl, port) {
return serverUrl + (port ? ':' + port : '') + '/api/v1/';
};
this._composeInstallUrl = function(installUrl, serviceId, apiKey) {
return installUrl + '/sid/' + serviceId + '/apiKey/' + apiKey;
};
// Gets API key as argv, i.e., "apiKey=somethingsomething"
this._getApiKey = function() {
var apiKey = '';
if (process.argv.length > 0) {
for (var i = 0; i < process.argv.length; i++) {
var arg = process.argv[i];
var s = 'apiKey';
if (arg.indexOf(s) > -1) {
apiKey = arg.substring(s.length + 1);
}
}
}
return apiKey;
}
};
module.exports = new InstallService();
\ No newline at end of file
......@@ -6,7 +6,13 @@ config.redis = {
port: 6379
};
config.serverUrl = 'http://dev.bitweb.ee';
config.serverUrl = 'http://localhost';
config.integration = {
installUrl: 'http://dev.bitweb.ee:8000/api/v1/service/install',
apiKey: 'server-wrapper-api-key'
};
config.fs = {
storagePath: "/var/www/bitweb.ee/keeleliin.bitweb.ee/wrapper/tmp",
......@@ -29,10 +35,6 @@ config.wrapper = {
requestConf: null
};
config.integration = {
installUrl: 'http://localhost:3000/api/v1/service/install'
};
config.log4js = {
appenders: [
{
......@@ -120,13 +122,17 @@ var simpleCommandRequest = {
},
requestBodyParamsMappings: {
isAsync: {
type: 'select',
options: ['0','1'],
usageType: config.paramUsageTypes.META,
filter: function(value){
filter: function (value) {
return value == 1;
},
required: true,
allowEmpty: false,
validator: function(value, request){ return true; }
validator: function (value, request) {
return true;
}
}
/**
* , key: {
......@@ -200,7 +206,8 @@ config.availableWrappers = {
port: 3001,
class: 'simpleLocalCommand',
command: config.availableCommands.LAUSESTAJA,
requestConf: simpleCommandRequest
requestConf: simpleCommandRequest,
outputTypes: [ { type: 'text', key: 'output' }]
},
MORFANALYSAATOR : {
title: 'Morfoloogiline analüüs',
......@@ -209,7 +216,8 @@ config.availableWrappers = {
port: 3002,
class: 'simpleLocalCommand',
command: config.availableCommands.MORFANALYSAATOR,
requestConf: simpleCommandRequest
requestConf: simpleCommandRequest,
outputTypes: [ { type: 'text', key: 'output' }]
},
OSALAUSESTAJA : {
title: 'Osalausestaja',
......@@ -218,7 +226,8 @@ config.availableWrappers = {
port: 3003,
class: 'simpleLocalCommand',
command: config.availableCommands.OSALAUSESTAJA,
requestConf: simpleCommandRequest
requestConf: simpleCommandRequest,
outputTypes: [ { type: 'text', key: 'output' }]
},
MORFYHESTAJA: {
title: 'Morfoloogiline ühestamine (kitsenduste grammatika)',
......@@ -227,7 +236,8 @@ config.availableWrappers = {
port: 3004,
class: 'simpleLocalCommand',
command: config.availableCommands.MORFYHESTAJA,
requestConf: simpleCommandRequest
requestConf: simpleCommandRequest,
outputTypes: [ { type: 'text', key: 'output' }]
},
PIND_SYN: {
title: 'Pindsüntaktiline analüüs',
......@@ -236,7 +246,8 @@ config.availableWrappers = {
port: 3005,
class: 'simpleLocalCommand',
command: config.availableCommands.PIND_SYN,
requestConf: simpleCommandRequest
requestConf: simpleCommandRequest,
outputTypes: [ { type: 'text', key: 'output' }]
},
S6LT_SYN: {
title: 'Sõltuvussüntaktiline analüüs (ja järeltöötlus)',
......@@ -245,7 +256,8 @@ config.availableWrappers = {
port: 3006,
class: 'simpleLocalCommand',
command: config.availableCommands.S6LT_SYN,
requestConf: simpleCommandRequest
requestConf: simpleCommandRequest,
outputTypes: [ { type: 'text', key: 'output' }]
},
ARCHIVE_EXTRACTOR: {
......@@ -260,14 +272,17 @@ config.availableWrappers = {
},
requestBodyParamsMappings: {
isAsync: {
type: 'text',
type: 'select',
options: ['0','1'],
usageType: config.paramUsageTypes.META,
filter: function(value){
filter: function (value) {
return value == 1;
},
required: true,
allowEmpty: false,
validator: function(value, request){ return true; }
validator: function (value, request) {
return true;
}
}
},
requestFiles: {
......@@ -283,12 +298,7 @@ config.availableWrappers = {
isAsync: 0
}
},
outputTypes: [
{
type: 'text',
key: 'output'
}
]
outputTypes: [ { type: 'text', key: 'output' }]
},
TOKENIZER : {
title: 'Sõnestaja pipe',
......@@ -297,7 +307,8 @@ config.availableWrappers = {
port: 3008,
class: 'inputOutputLocalCommand',
command: config.availableCommands.TOKENIZER,
requestConf: simpleCommandRequest
requestConf: simpleCommandRequest,
outputTypes: [ { type: 'text', key: 'output' }]
},
CONCAT : {
title: 'Lihtne konkateneerija',
......@@ -312,6 +323,8 @@ config.availableWrappers = {
},
requestBodyParamsMappings: {
isAsync: {
type: 'select',
options: ['0','1'],
usageType: config.paramUsageTypes.META,
filter: function (value) {
return value == 1;
......@@ -343,14 +356,9 @@ config.availableWrappers = {
staticParams: {
sessionMaxLifetime: 600,
isAsync: undefined
},
outputTypes: [
{
type: 'text',
key: 'output'
}
]
}
}
},
outputTypes: [ { type: 'text', key: 'output' }]
},
MORPH_TAGGER : {
title: 'Morfoloogiline ühestaja pipe',
......@@ -358,7 +366,8 @@ config.availableWrappers = {
port: 3010,
class: 'inputOutputLocalCommand',
command: config.availableCommands.MORPH_TAGGER,
requestConf: simpleCommandRequest
requestConf: simpleCommandRequest,
outputTypes: [ { type: 'text', key: 'output' }]
}
};
......
......@@ -24,6 +24,8 @@ var errorhandlerMiddleware = require('./../middlewares/errorhandler');
var ServerUtil = require('./../src/util/server');
var cleanerService = require('./../src/service/cleanerService');
var installService = require('./../src/service/integration/installService');
app.set('views', path.join(__base, 'views'));// view engine setup
app.set('view engine', 'jade');// view engine setup
app.use(express.static(__base + '/public'));
......@@ -32,8 +34,15 @@ log4js.configure(config.log4js);
var log4jsLogger = log4js.getLogger('wrapper_server_js');
app.use(logger('dev'));
app.use(bodyParser.json({limit: '1000mb'})); // for parsing application/json
app.use(multer({ dest: config.fs.tmpPath})); // for parsing multipart/form-data
app.use(bodyParser.json({limit: '1mb'})); // for parsing application/json
app.use(multer({
dest: config.fs.tmpPath,
/*limits: { fileSize: 1* 1024 * 1024}, //1mb
onFileUploadStart: function (file, req, res) {
console.error(file.fieldname + ' fileupload is starting ...', file);
}*/
})); // for parsing multipart/form-data
app.use(express.static(path.join(__dirname, 'public')));
app.use(routerMiddleware.routeLogger);
app.use(controllers);
......@@ -67,6 +76,9 @@ function startCluster( instanceCount, cb ){
});
cleanerService.init();
installService.install(function () {
log4jsLogger.error('Instal callback');
})
} else {
startInstance(cb)
}
......
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