2016-04-14 23:09:07 +08:00
|
|
|
var camshaft = require('camshaft');
|
2016-09-23 23:11:04 +08:00
|
|
|
var fs = require('fs');
|
2016-04-14 23:09:07 +08:00
|
|
|
|
2016-09-23 23:11:04 +08:00
|
|
|
function AnalysisBackend (options) {
|
|
|
|
options = options || {};
|
|
|
|
this.setBatchConfig(options.batch);
|
|
|
|
this.setLoggerConfig(options.logger);
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = AnalysisBackend;
|
|
|
|
|
|
|
|
AnalysisBackend.prototype.setBatchConfig = function (options) {
|
|
|
|
var batchConfig = options || {};
|
2016-04-14 23:25:08 +08:00
|
|
|
batchConfig.endpoint = batchConfig.endpoint || 'http://127.0.0.1:8080/api/v1/sql/job';
|
|
|
|
batchConfig.inlineExecution = batchConfig.inlineExecution || false;
|
2016-04-20 22:36:29 +08:00
|
|
|
batchConfig.hostHeaderTemplate = batchConfig.hostHeaderTemplate || '{{=it.username}}.localhost.lan';
|
2016-04-14 23:25:08 +08:00
|
|
|
this.batchConfig = batchConfig;
|
2016-09-23 23:11:04 +08:00
|
|
|
};
|
2016-04-14 23:09:07 +08:00
|
|
|
|
2016-09-23 23:11:04 +08:00
|
|
|
AnalysisBackend.prototype.setLoggerConfig = function (options) {
|
|
|
|
var loggerConfig = options || {};
|
|
|
|
loggerConfig.filename = loggerConfig.filename;
|
|
|
|
|
|
|
|
this.loggerConfig = loggerConfig;
|
|
|
|
};
|
2016-04-14 23:09:07 +08:00
|
|
|
|
|
|
|
AnalysisBackend.prototype.create = function(analysisConfiguration, analysisDefinition, callback) {
|
2016-04-14 23:25:08 +08:00
|
|
|
analysisConfiguration.batch.endpoint = this.batchConfig.endpoint;
|
|
|
|
analysisConfiguration.batch.inlineExecution = this.batchConfig.inlineExecution;
|
2016-04-20 22:36:29 +08:00
|
|
|
analysisConfiguration.batch.hostHeaderTemplate = this.batchConfig.hostHeaderTemplate;
|
2016-09-23 23:11:04 +08:00
|
|
|
analysisConfiguration.logger = {
|
|
|
|
stream: this.loggerConfig.filename ? fs.createWriteStream(this.loggerConfig.filename) : process.stdout
|
|
|
|
};
|
2016-04-14 23:25:08 +08:00
|
|
|
|
|
|
|
camshaft.create(analysisConfiguration, analysisDefinition, callback);
|
2016-04-14 23:09:07 +08:00
|
|
|
};
|