+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/client/htmls/private/js/scriptList.js b/client/htmls/private/js/scriptList.js
index 649ede1dc..133118463 100644
--- a/client/htmls/private/js/scriptList.js
+++ b/client/htmls/private/js/scriptList.js
@@ -7,6 +7,8 @@ function setfilename(val){
//calling the global track functionality when track params are available..
$(document).ready(function(e) {
getScriptList();
+ $('#divParam').hide();
+ $('#checkScriptParam').hide();
});
//when the user clicks on the new button the setting the value to 'new' for the hidden field to know that user is creating the new item..
@@ -23,6 +25,18 @@ $('.addScriptItem').click(function(e) {
$('#scriptEditHiddenInput').val('new');
getOrganizationList();
});
+
+$("input[name='isParametrized']:radio").change(function(){
+ if($(this).val() === 'Yes') {
+ $('#noOfParams').addClass("required");
+ $('#divParam').show();
+ $('#checkScriptParam').show();
+ } else {
+ $('#noOfParams').removeClass("required");
+ $('#divParam').hide();
+ $('#checkScriptParam').hide();
+ }
+});
//to list down the organization for creating the script item.
function getOrganizationList() {
$.get('/d4dMasters/readmasterjsonnew/1', function(data) {
@@ -46,7 +60,7 @@ var validator = $('#scriptForm').validate({
ignore: [],
rules: {
scriptFile: {
- extension: "sh"
+ extension: "sh|py"
},
scriptName: {
maxlength: 15
@@ -54,7 +68,7 @@ var validator = $('#scriptForm').validate({
},
messages: {
scriptFile: {
- extension: "Only .sh files can be uploaded"
+ extension: "Only .sh and .py files can be uploaded"
},
scriptName: {
maxlength: "Limited to 15 chars"
@@ -84,7 +98,10 @@ function getScriptList() {
"serverSide": true,
"destroy":true,
"createdRow": function( row, data ) {
- $( row ).attr({"scriptId" : data.scriptId,"scriptName":data.name,"scriptType":data.type, "scriptDesc" : data.description, "orgId" : data.orgDetails.id ,"orgName" : data.orgDetails.name,"scriptFileName" : data.fileName,"scriptFileId" : data.fileId});
+ $( row ).attr({"scriptId" : data.scriptId,"scriptName":data.name,"scriptType":data.type,
+ "scriptDesc" : data.description, "orgId" : data.orgDetails.id ,"orgName" : data.orgDetails.name,
+ "scriptFileName" : data.fileName,"scriptFileId" : data.fileId,
+ "isParametrized" : data.isParametrized,"noOfParams":data.noOfParams});
},
"ajax": '/scripts',
"columns": [
@@ -143,6 +160,18 @@ $('#scriptListTable tbody').on( 'click', 'button.editRowScriptItem', function(){
$editModal.find('#scriptHiddenInputId').val($this.parents('tr').attr('scriptId'));
$editModal.find('#fileHiddenInputId').val($this.parents('tr').attr('scriptFileId'));
$editModal.find('#fileNameDisplay').append($this.parents('tr').attr('scriptFileName'));
+ if($this.parents('tr').attr('isParametrized') === true || $this.parents('tr').attr('isParametrized') === 'true'){
+ $('input:radio[name="isParametrized"][value="Yes"]').prop('checked', true);
+ $('#noOfParams').addClass("required");
+ $('#divParam').show();
+ $('#checkScriptParam').show();
+ $editModal.find('#noOfParams').val($this.parents('tr').attr('noOfParams'));
+ }else{
+ $('input:radio[name="isParametrized"][value="No"]').prop('checked', true);
+ $('#noOfParams').removeClass("required");
+ $('#divParam').hide();
+ $('#checkScriptParam').hide();
+ }
$editModal.find('#scriptFileNameHidden').empty().append($this.parents('tr').attr('scriptFileName'));
return false;
});
@@ -224,6 +253,11 @@ $('#scriptForm').submit(function(e) {
var $form = $('#scriptForm');
var scriptData = {};
var $this = $(this);
+ var isParametrized = false, noOfParams=0;
+ if($("input[name='isParametrized']:checked").val() === 'Yes'){
+ isParametrized =true;
+ noOfParams=parseInt($('#noOfParams').find(":selected").val());
+ }
var name = $this.find('#scriptName').val().trim();
var description = $this.find('#scriptDescription').val().trim();
var type = $form.find('#scriptType').val();
@@ -263,7 +297,9 @@ $('#scriptForm').submit(function(e) {
"type": type,
"description": description,
"orgDetails": orgDetails,
- "fileId": data.fileId
+ "fileId": data.fileId,
+ "isParametrized":isParametrized,
+ "noOfParams":noOfParams
};
} else {
url = '../scripts/update/scriptData';
@@ -274,7 +310,9 @@ $('#scriptForm').submit(function(e) {
"type": type,
"description": description,
"orgDetails": orgDetails,
- "fileId": data.fileId
+ "fileId": data.fileId,
+ "isParametrized":isParametrized,
+ "noOfParams":noOfParams
};
}
formSave(methodName,url,reqBody);
diff --git a/server/app/cronjobs/catalyst-scheduler/catalystScheduler.js b/server/app/cronjobs/catalyst-scheduler/catalystScheduler.js
index 692c57037..bedbc9be7 100644
--- a/server/app/cronjobs/catalyst-scheduler/catalystScheduler.js
+++ b/server/app/cronjobs/catalyst-scheduler/catalystScheduler.js
@@ -101,8 +101,6 @@ catalystSync.executeSerialScheduledTasks = function executeSerialScheduledTasks(
}
if(serialTaskList.length === tasks.length){
if(serialTaskList.length > 0) {
- console.log(serialTaskList.length);
- console.log(serialTaskList);
async.waterfall(serialTaskList, function (err, data) {
if (err) {
logger.error(err);
diff --git a/server/app/lib/utils/apiUtil.js b/server/app/lib/utils/apiUtil.js
index 0ac9e89cd..17ef5a022 100644
--- a/server/app/lib/utils/apiUtil.js
+++ b/server/app/lib/utils/apiUtil.js
@@ -34,62 +34,53 @@ var ApiUtil = function() {
}
this.createCronJobPattern= function(scheduler){
scheduler.cronRepeatEvery = parseInt(scheduler.cronRepeatEvery);
+ var startOn = null,endOn = null;
+ if(scheduler.cronStartOn === scheduler.cronEndOn){
+ startOn = new Date();
+ endOn = new Date()
+ endOn.setHours(23);
+ endOn.setMinutes(59);
+ }else{
+ startOn = scheduler.cronStartOn;
+ endOn = scheduler.cronEndOn;
+ }
if(scheduler.cronFrequency ==='Minutes'){
scheduler.pattern = '*/'+scheduler.cronRepeatEvery+' * * * *';
}else if(scheduler.cronFrequency ==='Hourly'){
scheduler.pattern = '0 */'+scheduler.cronRepeatEvery+' * * *';
}else if(scheduler.cronFrequency ==='Daily'){
- var startOn = Date.parse(scheduler.cronStartOn);
- var startHours= startOn.getHours();
- var startMinutes= startOn.getMinutes();
- scheduler.pattern = startMinutes+' '+startHours+' */'+scheduler.cronRepeatEvery+' * *';
+ scheduler.pattern = parseInt(scheduler.cronMinute)+' '+parseInt(scheduler.cronHour)+' */'+scheduler.cronRepeatEvery+' * *';
}else if(scheduler.cronFrequency ==='Weekly') {
- var startOn = Date.parse(scheduler.cronStartOn);
- var startDay= startOn.getDay();
- var startHours= startOn.getHours();
- var startMinutes= startOn.getMinutes();
if(scheduler.cronRepeatEvery === 2) {
- scheduler.pattern = startMinutes+' '+startHours+' 8-14 * ' + startDay;
+ scheduler.pattern = parseInt(scheduler.cronMinute)+' '+parseInt(scheduler.cronHour)+' 8-14 * ' + parseInt(scheduler.cronWeekDay);
}else if(scheduler.cronRepeatEvery === 3) {
- scheduler.pattern = startMinutes+' '+startHours+' 15-21 * ' + startDay;
+ scheduler.pattern = parseInt(scheduler.cronMinute)+' '+parseInt(scheduler.cronHour)+' 15-21 * ' + parseInt(scheduler.cronWeekDay);
}else if(scheduler.cronRepeatEvery === 4) {
- scheduler.pattern = startMinutes+' '+startHours+' 22-28 * ' + startDay;
+ scheduler.pattern = parseInt(scheduler.cronMinute)+' '+parseInt(scheduler.cronHour)+' 22-28 * ' + parseInt(scheduler.cronWeekDay);
}else{
- scheduler.pattern = startMinutes+' '+startHours+' * * ' + startDay;
+ scheduler.pattern = parseInt(scheduler.cronMinute)+' '+parseInt(scheduler.cronHour)+' * * ' + parseInt(scheduler.cronWeekDay);
}
- }
- if(scheduler.cronFrequency ==='Monthly') {
- var startOn = Date.parse(scheduler.cronStartOn);
- var startDate= startOn.getDate();
- var startMonth= startOn.getMonth();
- var startDay= startOn.getDay();
- var startHours= startOn.getHours();
- var startMinutes= startOn.getMinutes();
+ }else if(scheduler.cronFrequency ==='Monthly') {
if(scheduler.cronRepeatEvery === 1) {
- scheduler.pattern = startMinutes+' '+startHours+' '+startDate+' * *';
+ scheduler.pattern = parseInt(scheduler.cronMinute)+' '+parseInt(scheduler.cronHour)+' '+parseInt(scheduler.cronDate)+' * *';
}else{
- scheduler.pattern = startMinutes+' '+startHours+' '+startDate+' */'+scheduler.cronRepeatEvery+' *';
+ scheduler.pattern = parseInt(scheduler.cronMinute)+' '+parseInt(scheduler.cronHour)+' '+parseInt(scheduler.cronDate)+' */'+scheduler.cronRepeatEvery+' *';
}
- }
- if(scheduler.cronFrequency ==='Yearly') {
- var startOn = Date.parse(scheduler.cronStartOn);
- var startDate= startOn.getDate();
- var startYear= startOn.getFullYear();
- var startMonth= startOn.getMonth();
- var startHours= startOn.getHours();
- var startMinutes= startOn.getMinutes();
- scheduler.pattern ='0 '+startMinutes+' '+startHours+' '+startDate+' '+startMonth+' ? '+startYear/scheduler.cronRepeatEvery;
+ }else if(scheduler.cronFrequency ==='Yearly') {
+ scheduler.pattern ='0 '+parseInt(scheduler.cronMinute)+' '+parseInt(scheduler.cronHour)+' '+parseInt(scheduler.cronDate)+' '+parseInt(scheduler.cronMonth)+' ? '+parseInt(scheduler.cronYear)/scheduler.cronRepeatEvery;
}
var cronScheduler = {
"cronFrequency": scheduler.cronFrequency,
"cronRepeatEvery": scheduler.cronRepeatEvery,
"cronPattern":scheduler.pattern,
- "cronStartOn":Date.parse(scheduler.cronStartOn),
- "cronEndOn":Date.parse(scheduler.cronEndOn),
- "cronTime":scheduler.cronTime,
- "cronDays":scheduler.cronDays,
- "cronMonths":scheduler.cronMonths,
- "cronYears":scheduler.cronYears
+ "cronStartOn":Date.parse(startOn),
+ "cronEndOn":Date.parse(endOn),
+ "cronHour":scheduler.cronHour,
+ "cronMinute":scheduler.cronMinute,
+ "cronDate":scheduler.cronDate,
+ "cronWeekDay":scheduler.cronWeekDay ? parseInt(scheduler.cronWeekDay):0,
+ "cronMonth":scheduler.cronMonth ? scheduler.cronMonth: null,
+ "cronYear":scheduler.cronYear ? scheduler.cronYear: null
}
return cronScheduler;
}
diff --git a/server/app/model/blueprint/blueprint.js b/server/app/model/blueprint/blueprint.js
index b68228526..63c91ec4b 100755
--- a/server/app/model/blueprint/blueprint.js
+++ b/server/app/model/blueprint/blueprint.js
@@ -168,6 +168,16 @@ var BlueprintSchema = new Schema({
},
botCategory: {
type: String
+ },
+ executionCount:{
+ type: Number,
+ required: false,
+ default:0
+ },
+ manualExecutionTime:{
+ type: Number,
+ required: false,
+ default:10
}
});
@@ -1465,6 +1475,23 @@ BlueprintSchema.statics.checkBPDependencyByFieldName = function(fieldName,id, ca
callback(null, data);
});
};
+BlueprintSchema.statics.updateBlueprintExecutionCount = function updateBlueprintExecutionCount(blueprintId,count,callback) {
+ Blueprints.update({
+ "_id": new ObjectId(blueprintId),
+ }, {
+ $set: {
+ executeCount: count
+ }
+ }, {
+ upsert: false
+ }, function (err, data) {
+ if (err) {
+ callback(err, null);
+ return;
+ }
+ callback(null, data);
+ });
+};
var Blueprints = mongoose.model('blueprints', BlueprintSchema);
diff --git a/server/app/model/classes/tasks/taskTypeScript.js b/server/app/model/classes/tasks/taskTypeScript.js
index 8158dbc07..e8bf81c8c 100644
--- a/server/app/model/classes/tasks/taskTypeScript.js
+++ b/server/app/model/classes/tasks/taskTypeScript.js
@@ -42,9 +42,18 @@ var scriptTaskSchema = taskTypeSchema.extend({
scriptDetails: [{
scriptId: {
type: String,
- requred: true
+ required: true
},
- scriptParameters: [String]
+ scriptParameters: [{
+ paramVal:{
+ type: String,
+ required: false
+ },
+ paramDesc:{
+ type: String,
+ required: false
+ }
+ }]
}]
});
@@ -62,7 +71,7 @@ scriptTaskSchema.methods.execute = function(userName, baseUrl, choiceParam, nexu
function getInstances(instanceIds, tagServer, callback) {
if (tagServer) {
logger.debug('in tagServer', tagServer);
- instancesDao.getInstancesByTagServer(tagServer, function(err, instances) {
+ instancesDao.getInstancesByTagServer(tagServer, function (err, instances) {
if (err) {
logger.error(err);
if (typeof onExecute === 'function') {
@@ -83,7 +92,7 @@ scriptTaskSchema.methods.execute = function(userName, baseUrl, choiceParam, nexu
}
return;
}
- instancesDao.getInstances(instanceIds, function(err, instances) {
+ instancesDao.getInstances(instanceIds, function (err, instances) {
if (err) {
logger.error(err);
if (typeof onExecute === 'function') {
@@ -97,13 +106,13 @@ scriptTaskSchema.methods.execute = function(userName, baseUrl, choiceParam, nexu
}
- getInstances(instanceIds, self.botTagServer, function(err, instances) {
+ getInstances(instanceIds, self.botTagServer, function (err, instances) {
if (err) {
logger.error(err);
return;
}
for (var i = 0; i < instances.length; i++) {
- (function(instance) {
+ (function (instance) {
var timestampStarted = new Date().getTime();
var actionLog = instancesDao.insertOrchestrationActionLog(instance._id, null, userName, timestampStarted);
instance.tempActionLogId = actionLog._id;
@@ -146,7 +155,7 @@ scriptTaskSchema.methods.execute = function(userName, baseUrl, choiceParam, nexu
log: "Instance IP is not defined. Chef Client run failed",
timestamp: new Date().getTime()
};
- instanceLogModel.createOrUpdate(actionLog._id, instance._id, instanceLog, function(err, logData) {
+ instanceLogModel.createOrUpdate(actionLog._id, instance._id, instanceLog, function (err, logData) {
if (err) {
logger.error("Failed to create or update instanceLog: ", err);
}
@@ -157,7 +166,7 @@ scriptTaskSchema.methods.execute = function(userName, baseUrl, choiceParam, nexu
}, 1, instance._id, null, actionLog._id);
return;
}
- credentialCryptography.decryptCredential(instance.credentials, function(err, decryptedCredentials) {
+ credentialCryptography.decryptCredential(instance.credentials, function (err, decryptedCredentials) {
var sshOptions = {
username: decryptedCredentials.username,
host: instance.instanceIP,
@@ -169,8 +178,8 @@ scriptTaskSchema.methods.execute = function(userName, baseUrl, choiceParam, nexu
sshOptions.password = decryptedCredentials.password;
}
for (var j = 0; j < scriptDetails.length; j++) {
- (function(script) {
- scriptService.getScriptById(script.scriptId, function(err, scripts) {
+ (function (script) {
+ scriptService.getScriptById(script.scriptId, function (err, scripts) {
if (err) {
logger.error(err);
return;
@@ -183,7 +192,13 @@ scriptTaskSchema.methods.execute = function(userName, baseUrl, choiceParam, nexu
if (self.botParams && self.botParams.scriptParams) {
params = self.botParams.scriptParams;
}
- executeBashScript(scripts, sshOptions, logsReferenceIds, params, instanceLog);
+ executeScriptOnNode(scripts, sshOptions, logsReferenceIds, params, instanceLog,'bash');
+ } else if (scripts.type === 'Python') {
+ var params = script.scriptParameters;
+ if (self.botParams && self.botParams.scriptParams) {
+ params = self.botParams.scriptParams;
+ }
+ executeScriptOnNode(scripts, sshOptions, logsReferenceIds, params, instanceLog,'python');
} else {
return;
}
@@ -235,19 +250,19 @@ scriptTaskSchema.methods.execute = function(userName, baseUrl, choiceParam, nexu
}
}
- function executeBashScript(script, sshOptions, logsReferenceIds, scriptParameters, instanceLog) {
+ function executeScriptOnNode(script, sshOptions, logsReferenceIds, scriptParameters, instanceLog,scriptType) {
var fileName = uuid.v4() + '_' + script.fileName
var desPath = appConfig.scriptDir + fileName;
var sshExec = new SSHExec(sshOptions);
var cryptoConfig = appConfig.cryptoSettings;
var cryptography = new Cryptography(cryptoConfig.algorithm, cryptoConfig.password);
- fileIo.writeFile(desPath, script.file, false, function(err) {
+ fileIo.writeFile(desPath, script.file, false, function (err) {
if (err) {
logger.error("Unable to write file");
return;
} else {
var scp = new SCP(sshOptions);
- scp.upload(desPath, '/tmp', function(err) {
+ scp.upload(desPath, '/tmp', function (err) {
if (err) {
var timestampEnded = new Date().getTime();
logsDao.insertLog({
@@ -264,7 +279,7 @@ scriptTaskSchema.methods.execute = function(userName, baseUrl, choiceParam, nexu
log: "Unable to upload script file " + script.name,
timestamp: new Date().getTime()
};
- instanceLogModel.createOrUpdate(logsReferenceIds[1], logsReferenceIds[0], instanceLog, function(err, logData) {
+ instanceLogModel.createOrUpdate(logsReferenceIds[1], logsReferenceIds[0], instanceLog, function (err, logData) {
if (err) {
logger.error("Failed to create or update instanceLog: ", err);
}
@@ -273,17 +288,17 @@ scriptTaskSchema.methods.execute = function(userName, baseUrl, choiceParam, nexu
return;
}
if (sudoFlag === true) {
- var cmdLine = 'sudo bash /tmp/' + fileName;
+ var cmdLine = 'sudo '+scriptType+' /tmp/' + fileName;
} else {
- var cmdLine = 'bash /tmp/' + fileName;
+ var cmdLine = scriptType +' /tmp/' + fileName;
}
- if (scriptParameters.length > 0) {
+ if (script.isParameterized === true) {
for (var j = 0; j < scriptParameters.length; j++) {
- var decryptedText = cryptography.decryptText(scriptParameters[j], cryptoConfig.decryptionEncoding, cryptoConfig.encryptionEncoding);
+ var decryptedText = cryptography.decryptText(scriptParameters[j].paramVal, cryptoConfig.decryptionEncoding, cryptoConfig.encryptionEncoding);
cmdLine = cmdLine + ' "' + decryptedText + '"';
}
}
- sshExec.exec(cmdLine, function(err, retCode) {
+ sshExec.exec(cmdLine, function (err, retCode) {
if (err) {
var timestampEnded = new Date().getTime();
logsDao.insertLog({
@@ -300,7 +315,7 @@ scriptTaskSchema.methods.execute = function(userName, baseUrl, choiceParam, nexu
log: 'Unable to run script ' + script.name,
timestamp: new Date().getTime()
};
- instanceLogModel.createOrUpdate(logsReferenceIds[1], logsReferenceIds[0], instanceLog, function(err, logData) {
+ instanceLogModel.createOrUpdate(logsReferenceIds[1], logsReferenceIds[0], instanceLog, function (err, logData) {
if (err) {
logger.error("Failed to create or update instanceLog: ", err);
}
@@ -325,7 +340,7 @@ scriptTaskSchema.methods.execute = function(userName, baseUrl, choiceParam, nexu
log: 'Task execution success for script ' + script.name,
timestamp: new Date().getTime()
};
- instanceLogModel.createOrUpdate(logsReferenceIds[1], logsReferenceIds[0], instanceLog, function(err, logData) {
+ instanceLogModel.createOrUpdate(logsReferenceIds[1], logsReferenceIds[0], instanceLog, function (err, logData) {
if (err) {
logger.error("Failed to create or update instanceLog: ", err);
}
@@ -349,7 +364,7 @@ scriptTaskSchema.methods.execute = function(userName, baseUrl, choiceParam, nexu
log: 'Host Unreachable',
timestamp: new Date().getTime()
};
- instanceLogModel.createOrUpdate(logsReferenceIds[1], logsReferenceIds[0], instanceLog, function(err, logData) {
+ instanceLogModel.createOrUpdate(logsReferenceIds[1], logsReferenceIds[0], instanceLog, function (err, logData) {
if (err) {
logger.error("Failed to create or update instanceLog: ", err);
}
@@ -370,7 +385,7 @@ scriptTaskSchema.methods.execute = function(userName, baseUrl, choiceParam, nexu
log: 'Invalid credentials',
timestamp: new Date().getTime()
};
- instanceLogModel.createOrUpdate(logsReferenceIds[1], logsReferenceIds[0], instanceLog, function(err, logData) {
+ instanceLogModel.createOrUpdate(logsReferenceIds[1], logsReferenceIds[0], instanceLog, function (err, logData) {
if (err) {
logger.error("Failed to create or update instanceLog: ", err);
}
@@ -391,7 +406,7 @@ scriptTaskSchema.methods.execute = function(userName, baseUrl, choiceParam, nexu
log: 'Unknown error occured. ret code = ' + retCode,
timestamp: new Date().getTime()
};
- instanceLogModel.createOrUpdate(logsReferenceIds[1], logsReferenceIds[0], instanceLog, function(err, logData) {
+ instanceLogModel.createOrUpdate(logsReferenceIds[1], logsReferenceIds[0], instanceLog, function (err, logData) {
if (err) {
logger.error("Failed to create or update instanceLog: ", err);
}
@@ -414,7 +429,7 @@ scriptTaskSchema.methods.execute = function(userName, baseUrl, choiceParam, nexu
log: 'Error in running script ' + script.name,
timestamp: new Date().getTime()
};
- instanceLogModel.createOrUpdate(logsReferenceIds[1], logsReferenceIds[0], instanceLog, function(err, logData) {
+ instanceLogModel.createOrUpdate(logsReferenceIds[1], logsReferenceIds[0], instanceLog, function (err, logData) {
if (err) {
logger.error("Failed to create or update instanceLog: ", err);
}
@@ -422,7 +437,7 @@ scriptTaskSchema.methods.execute = function(userName, baseUrl, choiceParam, nexu
removeScriptFile(desPath);
return;
}
- }, function(stdOut) {
+ }, function (stdOut) {
logsDao.insertLog({
referenceId: logsReferenceIds,
err: false,
@@ -434,12 +449,12 @@ scriptTaskSchema.methods.execute = function(userName, baseUrl, choiceParam, nexu
log: stdOut.toString('ascii'),
timestamp: new Date().getTime()
};
- instanceLogModel.createOrUpdate(logsReferenceIds[1], logsReferenceIds[0], instanceLog, function(err, logData) {
+ instanceLogModel.createOrUpdate(logsReferenceIds[1], logsReferenceIds[0], instanceLog, function (err, logData) {
if (err) {
logger.error("Failed to create or update instanceLog: ", err);
}
});
- }, function(stdErr) {
+ }, function (stdErr) {
logsDao.insertLog({
referenceId: logsReferenceIds,
err: true,
@@ -451,17 +466,19 @@ scriptTaskSchema.methods.execute = function(userName, baseUrl, choiceParam, nexu
log: stdErr.toString('ascii'),
timestamp: new Date().getTime()
};
- instanceLogModel.createOrUpdate(logsReferenceIds[1], logsReferenceIds[0], instanceLog, function(err, logData) {
+ instanceLogModel.createOrUpdate(logsReferenceIds[1], logsReferenceIds[0], instanceLog, function (err, logData) {
if (err) {
logger.error("Failed to create or update instanceLog: ", err);
}
});
});
})
- };
+ }
+ ;
});
};
-};
+}
+
function removeScriptFile(filePath) {
fileIo.removeFile(filePath, function(err, result) {
diff --git a/server/app/model/classes/tasks/tasks.js b/server/app/model/classes/tasks/tasks.js
index 8423d4fe6..0e7c6329d 100755
--- a/server/app/model/classes/tasks/tasks.js
+++ b/server/app/model/classes/tasks/tasks.js
@@ -159,23 +159,29 @@ var taskSchema = new Schema({
},
cronRepeatEvery: {
type: Number,
- required: false,
- trim: true
+ required: false
},
cronFrequency: {
type: String,
required: false,
trim: true
},
- cronTime:{
- type: String,
+ cronMinute:{
+ type: Number,
required: false,
trim: true
},
- cronDays:{
- type: String,
- required: false,
- trim: true
+ cronHour:{
+ type: Number,
+ required: false
+ },
+ cronWeekDay:{
+ type: Number,
+ required: false
+ },
+ cronDate:{
+ type: Number,
+ required: false
},
cronMonth:{
type: String,
@@ -183,15 +189,24 @@ var taskSchema = new Schema({
trim: true
},
cronYear:{
- type: String,
- required: false,
- trim: true
+ type: Number,
+ required: false
}
},
cronJobId:{
type: String,
required: false,
trim: true
+ },
+ executionCount:{
+ type: Number,
+ required: false,
+ default:0
+ },
+ manualExecutionTime:{
+ type: Number,
+ required: false,
+ default:10
}
});
taskSchema.plugin(mongoosePaginate);
@@ -751,7 +766,8 @@ taskSchema.statics.updateTaskById = function(taskId, taskData, callback) {
blueprintIds: taskData.blueprintIds,
executionOrder:taskData.executionOrder,
taskScheduler:taskData.taskScheduler,
- isTaskScheduled:taskData.isTaskScheduled
+ isTaskScheduled:taskData.isTaskScheduled,
+ manualExecutionTime:taskData.manualExecutionTime
}
}, {
upsert: false
@@ -967,6 +983,23 @@ taskSchema.statics.updateTaskScheduler = function updateTaskScheduler(taskId, ca
callback(null, data);
});
};
+taskSchema.statics.updateTaskExecutionCount = function updateTaskExecutionCount(taskId,count,callback) {
+ Tasks.update({
+ "_id": new ObjectId(taskId),
+ }, {
+ $set: {
+ executionCount: count
+ }
+ }, {
+ upsert: false
+ }, function (err, data) {
+ if (err) {
+ callback(err, null);
+ return;
+ }
+ callback(null, data);
+ });
+};
function filterScriptTaskData(data,callback){
var taskList = [];
diff --git a/server/app/model/scripts/scripts.js b/server/app/model/scripts/scripts.js
index 01f91b714..6f562f0b5 100644
--- a/server/app/model/scripts/scripts.js
+++ b/server/app/model/scripts/scripts.js
@@ -55,6 +55,16 @@ var ScriptSchema = new Schema({
type:String,
required:true,
trim:true
+ },
+ isParametrized:{
+ type:Boolean,
+ required:false,
+ default:false
+ },
+ noOfParams:{
+ type:Number,
+ required:false,
+ default:0
}
});
ScriptSchema.plugin(mongoosePaginate);
@@ -88,7 +98,9 @@ ScriptSchema.statics.updateScript = function(scriptData, callback) {
$set: {
"name": scriptData.name,
"description": scriptData.description,
- "fileId": scriptData.fileId
+ "fileId": scriptData.fileId,
+ "isParametrized":scriptData.isParametrized,
+ "noOfParams":scriptData.noOfParams
},
},{
upsert: false
diff --git a/server/app/routes/v1.0/routes_blueprints.js b/server/app/routes/v1.0/routes_blueprints.js
index f9298ab30..90b9d8d13 100755
--- a/server/app/routes/v1.0/routes_blueprints.js
+++ b/server/app/routes/v1.0/routes_blueprints.js
@@ -384,6 +384,17 @@ module.exports.setRoutes = function(app, sessionVerificationFunc) {
}
var stackName = null;
var domainName = null;
+ var blueprintLaunchCount = 0;
+ if(blueprint.executionCount) {
+ blueprintLaunchCount = blueprint.executionCount + 1;
+ }else{
+ blueprintLaunchCount = 1;
+ }
+ Blueprints.updateBlueprintExecutionCount(blueprint._id,blueprintLaunchCount,function(err,data){
+ if(err){
+ logger.error("Error while updating Blueprint Execution Count");
+ }
+ });
if (blueprint.blueprintType === 'aws_cf' || blueprint.blueprintType === 'azure_arm') {
stackName = req.query.stackName;
if (!stackName) {
diff --git a/server/app/routes/v1.0/routes_organizations.js b/server/app/routes/v1.0/routes_organizations.js
index dda4b727a..3c458a04f 100755
--- a/server/app/routes/v1.0/routes_organizations.js
+++ b/server/app/routes/v1.0/routes_organizations.js
@@ -434,6 +434,7 @@ module.exports.setRoutes = function(app, sessionVerification) {
var category = 'blueprints';
var permissionto = 'create';
var domainNameCheck = false;
+ var manualExecutionTime = 10;
var orgId = req.params.orgId;
var bgId = req.params.bgId;
var projectId = req.params.projectId;
@@ -452,6 +453,9 @@ module.exports.setRoutes = function(app, sessionVerification) {
var botType = req.body.blueprintData.botType;
var botCategory = req.body.blueprintData.botCategory;
var serviceDeliveryCheck = req.body.blueprintData.serviceDeliveryCheck;
+ if(req.body.blueprintData.manualExecutionTime && req.body.blueprintData.manualExecutionTime !== null){
+ manualExecutionTime = req.body.blueprintData.manualExecutionTime;
+ }
if(req.body.blueprintData.domainNameCheck === 'true'){
domainNameCheck = true;
}
@@ -502,7 +506,8 @@ module.exports.setRoutes = function(app, sessionVerification) {
botType:botType,
botCategory:botCategory,
serviceDeliveryCheck:serviceDeliveryCheck,
- domainNameCheck:domainNameCheck
+ domainNameCheck:domainNameCheck,
+ manualExecutionTime:manualExecutionTime
};
//adding bluerpintID if present (edit mode)
if (blueprintId)
@@ -1043,19 +1048,22 @@ module.exports.setRoutes = function(app, sessionVerification) {
var count = 0;
var encryptedList = [];
for(var i = 0; i < paramDetails.length; i++){
- (function(param){
- if(param.scriptParameters.length > 0){
+ (function(paramDetail){
+ if(paramDetail.scriptParameters.length > 0){
count++;
- for(var j = 0; j < param.scriptParameters.length; j++){
+ for(var j = 0; j < paramDetail.scriptParameters.length; j++){
(function(scriptParameter){
- var encryptedText = cryptography.encryptText(scriptParameter, cryptoConfig.encryptionEncoding,
+ var encryptedText = cryptography.encryptText(scriptParameter.paramVal, cryptoConfig.encryptionEncoding,
cryptoConfig.decryptionEncoding);
- encryptedList.push(encryptedText);
- if(encryptedList.length === param.scriptParameters.length){
- param.scriptParameters = encryptedList;
+ encryptedList.push({
+ paramVal:encryptedText,
+ paramDesc:scriptParameter.paramDesc
+ });
+ if(encryptedList.length === paramDetail.scriptParameters.length){
+ paramDetail.scriptParameters = encryptedList;
encryptedList = [];
}
- })(param.scriptParameters[j]);
+ })(paramDetail.scriptParameters[j]);
}
}else{
count++;
diff --git a/server/app/routes/v1.0/routes_tasks.js b/server/app/routes/v1.0/routes_tasks.js
index 0779a60f0..34298868b 100755
--- a/server/app/routes/v1.0/routes_tasks.js
+++ b/server/app/routes/v1.0/routes_tasks.js
@@ -634,25 +634,28 @@ function encryptedParam(paramDetails, existingParams, callback) {
var count = 0;
var encryptedList = [];
for (var i = 0; i < paramDetails.length; i++) {
- (function(param) {
- if (param.scriptParameters.length > 0) {
+ (function(paramDetail) {
+ if (paramDetail.scriptParameters.length > 0) {
count++;
- for (var j = 0; j < param.scriptParameters.length; j++) {
+ for (var j = 0; j < paramDetail.scriptParameters.length; j++) {
(function(scriptParameter) {
if (scriptParameter === '') {
encryptedList.push(existingParams[i].scriptParameters[j]);
- } else if (scriptParameter === existingParams[i].scriptParameters[j]) {
+ } else if (scriptParameter.paramVal === existingParams[i].scriptParameters[j].paramVal) {
encryptedList.push(scriptParameter);
} else {
- var encryptedText = cryptography.encryptText(scriptParameter, cryptoConfig.encryptionEncoding,
+ var encryptedText = cryptography.encryptText(scriptParameter.paramVal, cryptoConfig.encryptionEncoding,
cryptoConfig.decryptionEncoding);
- encryptedList.push(encryptedText);
+ encryptedList.push({
+ paramVal:encryptedText,
+ paramVal:scriptParameter.paramVal
+ });
}
- if (encryptedList.length === param.scriptParameters.length) {
- param.scriptParameters = encryptedList;
+ if (encryptedList.length === paramDetail.scriptParameters.length) {
+ paramDetail.scriptParameters = encryptedList;
encryptedList = [];
}
- })(param.scriptParameters[j]);
+ })(paramDetail.scriptParameters[j]);
}
} else {
count++;
diff --git a/server/app/services/instanceService.js b/server/app/services/instanceService.js
index ed4555535..c165911fc 100644
--- a/server/app/services/instanceService.js
+++ b/server/app/services/instanceService.js
@@ -1487,12 +1487,22 @@ function updateScheduler(instanceScheduler, callback) {
function generateCronPattern(cronInterval,startDate,endDate,callback){
var startIntervalList =[],stopIntervalList=[],count = 0;
+ var startOn = null,endOn = null;
+ if(startDate === endDate){
+ startOn = new Date();
+ endOn = new Date()
+ endOn.setHours(23);
+ endOn.setMinutes(59);
+ }else{
+ startOn = startDate;
+ endOn = endDate;
+ }
if(cronInterval.length === 0){
var scheduler= {
instanceStartScheduler: startIntervalList,
instanceStopScheduler: stopIntervalList,
- schedulerStartOn: Date.parse(startDate),
- schedulerEndOn: Date.parse(endDate),
+ schedulerStartOn: Date.parse(startOn),
+ schedulerEndOn: Date.parse(endOn),
isScheduled: false
}
callback(null,scheduler);
@@ -1522,8 +1532,8 @@ function generateCronPattern(cronInterval,startDate,endDate,callback){
var scheduler= {
instanceStartScheduler: startIntervalList,
instanceStopScheduler: stopIntervalList,
- schedulerStartOn: Date.parse(startDate),
- schedulerEndOn: Date.parse(endDate),
+ schedulerStartOn: Date.parse(startOn),
+ schedulerEndOn: Date.parse(endOn),
isScheduled: true
}
callback(null,scheduler);
@@ -1551,8 +1561,8 @@ function generateCronPattern(cronInterval,startDate,endDate,callback){
var scheduler= {
instanceStartScheduler: startIntervalList,
instanceStopScheduler: stopIntervalList,
- schedulerStartOn: Date.parse(startDate),
- schedulerEndOn: Date.parse(endDate),
+ schedulerStartOn: Date.parse(startOn),
+ schedulerEndOn: Date.parse(endOn),
isScheduled: true
}
callback(null,scheduler);
diff --git a/server/app/services/schedulerService.js b/server/app/services/schedulerService.js
index a5b137bad..7b10aefaf 100644
--- a/server/app/services/schedulerService.js
+++ b/server/app/services/schedulerService.js
@@ -183,14 +183,13 @@ schedulerService.startStopInstance= function startStopInstance(instanceId,catUse
},
function(instanceDetails,next){
var currentDate = new Date();
- var dateToString = currentDate.toDateString();
if(instanceDetails[0].instanceState === 'terminated'){
callback({
errCode:201,
errMsg:"Instance is already in "+instanceDetails[0].instanceState+" state. So no need to do any action."
})
return;
- }else if (instanceDetails[0].isScheduled && instanceDetails[0].isScheduled === true && Date.parse(dateToString) > instanceDetails[0].schedulerEndOn) {
+ }else if (instanceDetails[0].isScheduled && instanceDetails[0].isScheduled === true && currentDate > instanceDetails[0].schedulerEndOn) {
instancesDao.updateInstanceScheduler(instanceDetails[0]._id,function(err, updatedData) {
if (err) {
logger.error("Failed to update Instance Scheduler: ", err);
diff --git a/server/app/services/scriptService.js b/server/app/services/scriptService.js
index ce2e76910..3d65aea2d 100644
--- a/server/app/services/scriptService.js
+++ b/server/app/services/scriptService.js
@@ -98,14 +98,16 @@ scriptService.getScriptById=function getScriptById(scriptId,callback){
next(err,null);
}else{
var scriptObj= {
- scriptId: scripts[0]._id,
- name: scripts[0].name,
- type: scripts[0].type,
- description: scripts[0].description,
- orgDetails: scripts[0].orgDetails,
- fileId: scripts[0].fileId,
- fileName: file.fileName,
- file: file.fileData
+ scriptId: scripts[0]._id,
+ name: scripts[0].name,
+ type: scripts[0].type,
+ description: scripts[0].description,
+ orgDetails: scripts[0].orgDetails,
+ isParametrized: scripts[0].isParametrized,
+ noOfParams: scripts[0].noOfParams,
+ fileId: scripts[0].fileId,
+ fileName: file.fileName,
+ file: file.fileData
};
next(null,scriptObj);
}
@@ -208,13 +210,15 @@ function addFileDetailsForScripts(scripts,callback){
return callback(err,null);
}else{
scriptObj = {
- scriptId:script._id,
- name:script.name,
- type:script.type,
- description:script.description,
- orgDetails:script.orgDetails,
- fileId:script.fileId,
- fileName:file.filename
+ scriptId:script._id,
+ name:script.name,
+ type:script.type,
+ description:script.description,
+ orgDetails:script.orgDetails,
+ isParametrized: script.isParametrized,
+ noOfParams: script.noOfParams,
+ fileId:script.fileId,
+ fileName:file.filename
}
scriptList.push(scriptObj);
scriptObj={};
diff --git a/server/app/services/taskService.js b/server/app/services/taskService.js
index a9186a6c4..afb6f5c96 100644
--- a/server/app/services/taskService.js
+++ b/server/app/services/taskService.js
@@ -151,6 +151,17 @@ taskService.executeTask = function executeTask(taskId, user, hostProtocol, choic
task.botParams = paramOptions;
task.botTagServer = botTagServer;
var auditTrailId = null;
+ var taskExecutionCount = 0;
+ if(task.executionCount){
+ taskExecutionCount = task.taskExecutionCount + 1
+ }else{
+ taskExecutionCount = 1;
+ }
+ taskDao.updateTaskExecutionCount(task._id,taskExecutionCount,function(err,data){
+ if(err){
+ logger.error("Error while updating Task Execution Count");
+ }
+ });
if(task.serviceDeliveryCheck === true){
var actionObj={
auditType:'BOTs',