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
67 changes: 44 additions & 23 deletions server/app/model/classes/instance/instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,8 @@ var InstanceSchema = new Schema({
},
subnetId: {
type: String,
required: false,
trim: true
required: false,
trim: true
},
vpcId: {
type: String,
Expand All @@ -342,7 +342,7 @@ var InstanceSchema = new Schema({
required: false,
default: false
},
tagServer:{
tagServer: {
type: String,
required: false,
trim: true
Expand Down Expand Up @@ -490,7 +490,13 @@ var InstancesDao = function() {
err.status = 500;
return callback(err);
} else {
databaseCall.queryObj['$or'] = [{ "instanceState": "running" }, { "instanceState": "stopped" }, { "instanceState": "pending" }];
databaseCall.queryObj['$or'] = [{
"instanceState": "running"
}, {
"instanceState": "stopped"
}, {
"instanceState": "pending"
}];
Instances.paginate(databaseCall.queryObj, databaseCall.options, function(err, instances) {
if (err) {
logger.error(err);
Expand Down Expand Up @@ -722,7 +728,7 @@ var InstancesDao = function() {
});
};

this.checkInstancesDependencyByFieldName = function(fieldName,id, callback) {
this.checkInstancesDependencyByFieldName = function(fieldName, id, callback) {
logger.debug("Enter checkInstancesDependencyByFieldName (%s,)", id);
var queryObj = {
$or: [{
Expand All @@ -732,7 +738,7 @@ var InstancesDao = function() {
}, {
serviceIds: id
}],
isDeleted:false
isDeleted: false
}
Instances.find(queryObj, function(err, data) {
if (err) {
Expand Down Expand Up @@ -1538,7 +1544,7 @@ var InstancesDao = function() {
};


this.insertDockerActionLog = function(instanceId, user,action,actionId, timestampStarted, callback) {
this.insertDockerActionLog = function(instanceId, user, action, actionId, timestampStarted, callback) {
logger.debug("Enter insertDockerActionLog ", instanceId, user, timestampStarted);
var log = {
type: actionId,
Expand Down Expand Up @@ -1708,8 +1714,8 @@ var InstancesDao = function() {
return log;
};

this.insertInstanceStatusActionLog = function(instanceId,user,instanceState, timestampStarted, callback) {
logger.debug("Enter insertInstanceStatusActionLog ", instanceId,user,instanceState, timestampStarted);
this.insertInstanceStatusActionLog = function(instanceId, user, instanceState, timestampStarted, callback) {
logger.debug("Enter insertInstanceStatusActionLog ", instanceId, user, instanceState, timestampStarted);
var log = {
completed: true,
success: true,
Expand All @@ -1719,21 +1725,21 @@ var InstancesDao = function() {
'instance-State': instanceState
}
};
if(instanceState === 'terminated'){
if (instanceState === 'terminated') {
log.type = ACTION_LOG_TYPES.TERMINATED.type;
log.name = ACTION_LOG_TYPES.TERMINATED.name
}else if(instanceState === 'deleted'){
} else if (instanceState === 'deleted') {
log.type = ACTION_LOG_TYPES.DELETE.type;
log.name = ACTION_LOG_TYPES.DELETE.name
}else if(instanceState === 'stopped'){
} else if (instanceState === 'stopped') {
log.type = ACTION_LOG_TYPES.STOP.type;
log.name = ACTION_LOG_TYPES.STOP.name
}else if(instanceState === 'shutting-down'){
} else if (instanceState === 'shutting-down') {
log.type = ACTION_LOG_TYPES.SHUTDOWN.type;
log.name = ACTION_LOG_TYPES.SHUTDOWN.name
}else{
} else {
log.type = ACTION_LOG_TYPES.START.type;
log.name = ACTION_LOG_TYPES.START.name
log.name = ACTION_LOG_TYPES.START.name
}
var logId = insertActionLog(instanceId, log, callback);
log._id = logId;
Expand Down Expand Up @@ -2128,16 +2134,16 @@ var InstancesDao = function() {

this.updateInstanceStatus = function(instanceId, instance, callback) {
var updateObj = {};
if(instance.status && instance.status === 'shutting-down'){
if (instance.status && instance.status === 'shutting-down') {
updateObj['instanceState'] = instance.status;
updateObj['isDeleted'] = true;
}else if(instance.state === 'terminated' || instance.state === 'shutting-down'){
} else if (instance.state === 'terminated' || instance.state === 'shutting-down') {
updateObj['instanceState'] = instance.state;
updateObj['isDeleted'] = true;
}else{
} else {
updateObj['instanceState'] = instance.state;
updateObj['isDeleted'] = false;
updateObj['subnetId']= instance.subnetId;
updateObj['subnetId'] = instance.subnetId;
updateObj['instanceIP'] = instance.ip;
updateObj['vpcId'] = instance.vpcId;
updateObj['hostName'] = instance.hostName;
Expand Down Expand Up @@ -2179,7 +2185,10 @@ var InstancesDao = function() {
};

this.getAllTerminatedInstances = function(orgId, callback) {
Instances.find({ "orgId": orgId, "instanceState": "terminated" }, function(err, data) {
Instances.find({
"orgId": orgId,
"instanceState": "terminated"
}, function(err, data) {
if (err) {
return callback(err, null);
} else {
Expand All @@ -2188,12 +2197,12 @@ var InstancesDao = function() {
});
};

this.updatedRoute53HostedZoneParam = function(instanceId,route53HostedZoneParams,callback){
this.updatedRoute53HostedZoneParam = function(instanceId, route53HostedZoneParams, callback) {
Instances.update({
"_id": ObjectId(instanceId)
}, {
$set: {
route53HostedParams:route53HostedZoneParams
route53HostedParams: route53HostedZoneParams
}
}, function(err, data) {
if (err) {
Expand All @@ -2204,6 +2213,18 @@ var InstancesDao = function() {
callback(null, data);
});
};

this.getInstancesByTagServer = function(tagServer, callback) {
Instances.find({
"tagServer": tagServer
}, function(err, data) {
if (err) {
return callback(err, null);
} else {
callback(null, data);
}
});
};
};

module.exports = new InstancesDao();
module.exports = new InstancesDao();
30 changes: 24 additions & 6 deletions server/app/model/classes/tasks/taskTypeChef.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ chefTaskSchema.methods.getNodes = function() {
};

// Instance Method :- run task
chefTaskSchema.methods.execute = function(userName, baseUrl, choiceParam, appData, blueprintIds, envId, paramOptions, onExecute, onComplete) {
chefTaskSchema.methods.execute = function(userName, baseUrl, choiceParam, appData, blueprintIds, envId, onExecute, onComplete) {
logger.debug("chef appData: ", JSON.stringify(appData));
var self = this;

Expand Down Expand Up @@ -192,14 +192,18 @@ chefTaskSchema.methods.execute = function(userName, baseUrl, choiceParam, appDat
//merging attributes Objects
var attributeObj = {};
var objectArray = [];
for (var i = 0; i < self.attributes.length; i++) {
objectArray.push(self.attributes[i].jsonObj);
var attr = self.attributes;
if (self.botParams && self.botParams.cookbookAttributes) {
attr = self.botParams.cookbookAttributes;
}
for (var i = 0; i < attr.length; i++) {
objectArray.push(attr[i].jsonObj);
}

var instanceIds = this.nodeIds;


function getInstances(role, instanceIds, callback) {
function getInstances(role, instanceIds, tagServer, callback) {
if (role) {
configmgmtDao.getChefServerDetailsByOrgname(self.orgId, function(err, chefDetails) {
if (err) {
Expand Down Expand Up @@ -265,6 +269,19 @@ chefTaskSchema.methods.execute = function(userName, baseUrl, choiceParam, appDat
});
});

} else if (tagServer) {
logger.debug('in tagServer',tagServer);
instancesDao.getInstancesByTagServer(tagServer, function(err, instances) {
if (err) {
logger.error(err);
if (typeof onExecute === 'function') {
onExecute(err, null);
}
return;
}
callback(null, instances);
});

} else {

if (!(instanceIds && instanceIds.length)) {
Expand All @@ -289,7 +306,8 @@ chefTaskSchema.methods.execute = function(userName, baseUrl, choiceParam, appDat

}
logger.debug('role ==>', self.role);
getInstances(self.role, instanceIds, function(err, instances) {
getInstances(self.role, instanceIds, self.botTagServer, function(err, instances) {
logger.debug("instance length ==>",instances.length);
if (err) {
logger.error(err);
if (typeof onExecute === 'function') {
Expand Down Expand Up @@ -1282,4 +1300,4 @@ chefTaskSchema.methods.execute = function(userName, baseUrl, choiceParam, appDat

var ChefTask = mongoose.model('chefTask', chefTaskSchema);

module.exports = ChefTask;
module.exports = ChefTask;
2 changes: 1 addition & 1 deletion server/app/model/classes/tasks/taskTypeJenkins.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var jenkinsTaskSchema = taskTypeSchema.extend({
});

// Instance Method :- run task
jenkinsTaskSchema.methods.execute = function(userName, baseUrl, choiceParam, nexusData, blueprintIds, envId, paramOptions, onExecute, onComplete) {
jenkinsTaskSchema.methods.execute = function(userName, baseUrl, choiceParam, nexusData, blueprintIds, envId, onExecute, onComplete) {
logger.debug("Choice Param in::: ", choiceParam);
var self = this;
// For now removed blueprint launch via jenkins, later will use this
Expand Down
Loading