Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions server/app/model/classes/tasks/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ taskSchema.plugin(mongoosePaginate);


// Executes a task
taskSchema.methods.execute = function(userName, baseUrl, choiceParam, appData, blueprintIds, envId, callback, onComplete) {
taskSchema.methods.execute = function(userName, baseUrl, choiceParam, appData, blueprintIds, envId, paramOptions, callback, onComplete) {
logger.debug('Executing');
var task;
var self = this;
Expand All @@ -155,12 +155,13 @@ taskSchema.methods.execute = function(userName, baseUrl, choiceParam, appData, b

taskHistoryData.nodeIds = this.taskConfig.nodeIds;
taskHistoryData.runlist = this.taskConfig.runlist;
taskHistoryData.attributes = this.taskConfig.attributes;

//taskHistoryData.attributes = this.taskConfig.attributes;
taskHistoryData.attributes = (!paramOptions) ? this.taskConfig.attributes : paramOptions;
} else if (this.taskType === TASK_TYPE.JENKINS_TASK) {
task = new JenkinsTask(this.taskConfig);
taskHistoryData.jenkinsServerId = this.taskConfig.jenkinsServerId;
taskHistoryData.jobName = this.taskConfig.jobName;
taskHistoryData.parameterized = (!paramOptions) ? this.taskConfig.parameterized : paramOptions;
} else if (this.taskType === TASK_TYPE.PUPPET_TASK) {
task = new PuppetTask(this.taskConfig);
taskHistoryData.nodeIds = this.taskConfig.nodeIds;
Expand All @@ -179,7 +180,8 @@ taskSchema.methods.execute = function(userName, baseUrl, choiceParam, appData, b
} else if (this.taskType === TASK_TYPE.SCRIPT_TASK) {
task = new ScriptTask(this.taskConfig);
taskHistoryData.nodeIds = this.taskConfig.nodeIds;
taskHistoryData.scriptDetails = this.taskConfig.scriptDetails;
//taskHistoryData.scriptDetails = this.taskConfig.scriptDetails;
taskHistoryData.scriptDetails = (!paramOptions) ? this.taskConfig.scriptDetails : paramOptions;
} else {
callback({
message: "Invalid Task Type"
Expand Down
12 changes: 11 additions & 1 deletion server/app/routes/v1.0/routes_tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,17 @@ module.exports.setRoutes = function(app, sessionVerification) {
});
});
*/
taskService.executeTask(taskId, user, hostProtocol, choiceParam, appData, function(err, historyData) {

var attributes = req.body.attributes;
var parameterized = req.body.parameterized;
var scriptDetails = req.body.scriptDetails;
var paramOptions = {
attributes : attributes,
parameterized : parameterized,
scriptDetails : scriptDetails
};

taskService.executeTask(taskId, user, hostProtocol, choiceParam, appData, paramOptions, function(err, historyData) {
if (err === 404) {
res.status(404).send("Task not found.");
return;
Expand Down
13 changes: 11 additions & 2 deletions server/app/services/taskService.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ taskService.getChefTasksByOrgBgProjectAndEnvId = function getChefTasksByOrgBgPro
});
};

taskService.executeTask = function executeTask(taskId, user, hostProtocol, choiceParam, appData, callback) {
taskService.executeTask = function executeTask(taskId, user, hostProtocol, choiceParam, appData, paramOptions, callback) {
if (appData) {
appData['taskId'] = taskId;
}
Expand All @@ -89,11 +89,20 @@ taskService.executeTask = function executeTask(taskId, user, hostProtocol, choic
return callback(error, null);
}
if (task) {

if(task.taskType.CHEF_TASK){
paramOptions = paramOptions.attributes;
}else if(task.taskType.JENKINS_TASK){
paramOptions = paramOptions.parameterized;
}else if(task.taskType.SCRIPT_TASK) {
paramOptions = paramOptions.scriptDetails;
}

var blueprintIds = [];
if (task.blueprintIds && task.blueprintIds.length) {
blueprintIds = task.blueprintIds;
}
task.execute(user, hostProtocol, choiceParam, appData, blueprintIds, task.envId, function(err, taskRes, historyData) {
task.execute(user, hostProtocol, choiceParam, appData, blueprintIds, task.envId, paramOptions, function(err, taskRes, historyData) {
if (err) {
var error = new Error('Failed to execute task.');
error.status = 500;
Expand Down