From dd16f93e9ab1c35a74b3ed7317b5337faa2156eb Mon Sep 17 00:00:00 2001 From: Durgesh1988 Date: Tue, 27 Sep 2016 17:17:27 +0530 Subject: [PATCH 1/3] CAT-2355/CAT-2356 Fixed --- client/htmls/private/js/blueprintLaunch.js | 2 +- .../cronjobs/provider-sync/AWSProviderSync.js | 6 +- .../aws-blueprint/aws-blueprint.js | 2 +- server/app/model/classes/instance/instance.js | 18 +++++ server/app/services/instanceService.js | 70 ++++++++++++++++--- server/app/services/resourceService.js | 9 ++- 6 files changed, 91 insertions(+), 16 deletions(-) diff --git a/client/htmls/private/js/blueprintLaunch.js b/client/htmls/private/js/blueprintLaunch.js index 491630aa1..9bd357592 100644 --- a/client/htmls/private/js/blueprintLaunch.js +++ b/client/htmls/private/js/blueprintLaunch.js @@ -228,7 +228,7 @@ function blueprintLaunchDesign(data) { } else { var blueprintId = $('#modalSelectEnvironment').find('#selectedVersion').val(); launchBP(blueprintId, stackName,domainName); - $('#cftContainer').modal('hide'); + $('#domainNameContainer').modal('hide'); e.preventDefault(); return false; } diff --git a/server/app/cronjobs/provider-sync/AWSProviderSync.js b/server/app/cronjobs/provider-sync/AWSProviderSync.js index 39affbfcc..3a6ddc203 100644 --- a/server/app/cronjobs/provider-sync/AWSProviderSync.js +++ b/server/app/cronjobs/provider-sync/AWSProviderSync.js @@ -62,7 +62,7 @@ function awsProviderSyncForProvider(provider,orgName) { resourceService.getEC2InstancesInfo(provider,orgName, next); }, function (instances, next) { - saveEC2Data(instances, next); + saveEC2Data(instances,provider, next); }, function(instances,next){ async.parallel({ @@ -105,7 +105,7 @@ function awsProviderSyncForProvider(provider,orgName) { }); }; -function saveEC2Data(ec2Info, callback){ +function saveEC2Data(ec2Info,provider, callback){ var count = 0; if(ec2Info.length === 0) { return callback(null, ec2Info); @@ -118,7 +118,7 @@ function saveEC2Data(ec2Info, callback){ count++; return; }else if (managedInstances.length > 0) { - instanceService.instanceSyncWithAWS(managedInstances[0]._id,ec2, function(err, updateInstanceData) { + instanceService.instanceSyncWithAWS(managedInstances[0]._id,ec2,provider, function(err, updateInstanceData) { if (err) { logger.error(err); count++; diff --git a/server/app/model/blueprint/blueprint-types/instance-blueprint/aws-blueprint/aws-blueprint.js b/server/app/model/blueprint/blueprint-types/instance-blueprint/aws-blueprint/aws-blueprint.js index 885577f14..cfbc2c0a5 100755 --- a/server/app/model/blueprint/blueprint-types/instance-blueprint/aws-blueprint/aws-blueprint.js +++ b/server/app/model/blueprint/blueprint-types/instance-blueprint/aws-blueprint/aws-blueprint.js @@ -560,7 +560,7 @@ AWSInstanceBlueprintSchema.methods.launch = function(launchParams, callback) { timestamp: timestampEnded }); if(typeof domainName !== 'undefined' && domainName !== '' && domainName !== null && domainName !== 'null') { - resourceService.updateDomainNameForInstance(domainName, instance.instanceIP, awsSettings, function (err, updateDomainName) { + resourceService.updateDomainNameForInstance(domainName, instance.instanceIP,instance.id, awsSettings, function (err, updateDomainName) { if (err) { logger.error("resourceService.updateDomainNameForInstance Failed ==>", err); return; diff --git a/server/app/model/classes/instance/instance.js b/server/app/model/classes/instance/instance.js index db7b94993..80ca1c0ef 100755 --- a/server/app/model/classes/instance/instance.js +++ b/server/app/model/classes/instance/instance.js @@ -331,6 +331,7 @@ var InstanceSchema = new Schema({ required: false, trim: true }, + route53HostedParams: [Schema.Types.Mixed], isDeleted: { type: Boolean, required: false, @@ -2176,6 +2177,23 @@ var InstancesDao = function() { } }); }; + + this.updatedRoute53HostedZoneParam = function(instanceId,route53HostedZoneParams,callback){ + Instances.update({ + "_id": ObjectId(instanceId) + }, { + $set: { + route53HostedParams:route53HostedZoneParams + } + }, function(err, data) { + if (err) { + logger.error("Failed to update managed Instance status data", err); + callback(err, null); + return; + } + callback(null, data); + }); + }; }; module.exports = new InstancesDao(); diff --git a/server/app/services/instanceService.js b/server/app/services/instanceService.js index d34241015..820ac88b9 100644 --- a/server/app/services/instanceService.js +++ b/server/app/services/instanceService.js @@ -26,6 +26,7 @@ var Cryptography = require('../lib/utils/cryptography'); var tagsModel = require('_pr/model/tags/tags.js'); var resourceCost = require('_pr/model/resource-costs-deprecated/resource-costs-deprecated.js'); var resourceUsage = require('_pr/model/resource-metrics/resource-metrics.js'); +var Route53 = require('_pr/lib/route53.js'); var async = require('async'); var logsDao = require('_pr/model/dao/logsdao.js'); @@ -1305,13 +1306,14 @@ function removeInstancesByProviderId(providerId, callback) { }) } -function instanceSyncWithAWS(instanceId,instanceData,callback){ +function instanceSyncWithAWS(instanceId,instanceData,providerDetails,callback){ async.waterfall([ function(next){ instancesModel.getInstanceById(instanceId,next); }, function(instances,next){ var instance = instances[0]; + var routeHostedZoneParamList = []; if(instance.instanceState !== instanceData.state && instance.bootStrapStatus ==='success') { var timestampStarted = new Date().getTime(); var user = instance.catUser ? instance.catUser : 'superadmin'; @@ -1319,9 +1321,12 @@ function instanceSyncWithAWS(instanceId,instanceData,callback){ if(instanceData.state === 'stopped' || instanceData.state === 'stopping'){ action = 'Stop'; }else if(instanceData.state === 'terminated'){ - action ='Terminated' + action ='Terminated'; + if(instance.route53HostedParams){ + routeHostedZoneParamList = instance.route53HostedParams; + } }else if(instanceData.state === 'shutting-down'){ - action ='Shutting-Down' + action ='Shutting-Down'; }else{ action ='Start'; }; @@ -1347,18 +1352,63 @@ function instanceSyncWithAWS(instanceId,instanceData,callback){ logger.error("Failed to create or update instanceLog: ", err); next(err, null); } - next(null, logData); + next(null, routeHostedZoneParamList); }); }) }else { - createOrUpdateInstanceLogs(instance,instanceData.state,action,user,timestampStarted,next); + createOrUpdateInstanceLogs(instance,instanceData.state,action,user,timestampStarted,routeHostedZoneParamList,next); } }else{ - next(null,instances); + next(null,routeHostedZoneParamList); } }, - function(instanceLogData,next) { - instancesModel.updateInstanceStatus(instanceId,instanceData, next); + function(paramList,next) { + async.parallel({ + instanceDataSync: function(callback){ + instancesModel.updateInstanceStatus(instanceId,instanceData,callback); + }, + route53Sync: function(callback){ + if(paramList.length > 0){ + var cryptoConfig = appConfig.cryptoSettings; + var cryptography = new Cryptography(cryptoConfig.algorithm, cryptoConfig.password); + var decryptedAccessKey = cryptography.decryptText(providerDetails.accessKey, + cryptoConfig.decryptionEncoding, cryptoConfig.encryptionEncoding); + var decryptedSecretKey = cryptography.decryptText(providerDetails.secretKey, + cryptoConfig.decryptionEncoding, cryptoConfig.encryptionEncoding); + var route53Config = { + access_key: decryptedAccessKey, + secret_key: decryptedSecretKey, + region:'us-west-1' + }; + var route53 = new Route53(route53Config); + var count = 0; + for(var i = 0; i < paramList.length;i++){ + (function(params){ + params.ChangeBatch.Changes[0].Action = 'DELETE'; + route53.changeResourceRecordSets(params,function(err,data){ + count++; + if(err){ + callback(err,null); + } + if(count === paramList.length){ + callback(null,paramList); + } + }); + })(paramList[i]); + + } + }else{ + callback(null,paramList); + } + } + },function(err,results){ + if(err){ + next(err); + }else{ + next(null,results); + } + }) + } ], function(err,results){ if (err) { @@ -1369,7 +1419,7 @@ function instanceSyncWithAWS(instanceId,instanceData,callback){ }) } -function createOrUpdateInstanceLogs(instance,instanceState,action,user,timestampStarted,next){ +function createOrUpdateInstanceLogs(instance,instanceState,action,user,timestampStarted,routeHostedZoneParamList,next){ var actionLog = instancesModel.insertInstanceStatusActionLog(instance._id, user, instanceState, timestampStarted); var actionStatus = 'success'; var logReferenceIds = [instance._id, actionLog._id]; @@ -1409,6 +1459,6 @@ function createOrUpdateInstanceLogs(instance,instanceState,action,user,timestamp logger.error("Failed to create or update instanceLog: ", err); next(err, null); } - next(null, logData); + next(null, routeHostedZoneParamList); }); } diff --git a/server/app/services/resourceService.js b/server/app/services/resourceService.js index 13f3491db..6c42a6157 100644 --- a/server/app/services/resourceService.js +++ b/server/app/services/resourceService.js @@ -1103,7 +1103,7 @@ function getStartTime(endTime, period){ return dateUtil.getDateInUTC(subtractedDate); } -function updateDomainNameForInstance(domainName,publicIP,awsSettings,callback){ +function updateDomainNameForInstance(domainName,publicIP,instanceId,awsSettings,callback){ var route53 = new Route53(awsSettings); async.waterfall([ function(next){ @@ -1206,6 +1206,13 @@ function updateDomainNameForInstance(domainName,publicIP,awsSettings,callback){ }else{ next(null,paramList); } + }, + function(hostedParamList,next){ + if(hostedParamList.length > 0){ + instancesModel.updatedRoute53HostedZoneParam(instanceId,hostedParamList,next); + }else{ + next(null,hostedParamList); + } } ],function(err,results){ if(err){ From ca621fb33d6dd847f098bbbcab2aef14fcada5e0 Mon Sep 17 00:00:00 2001 From: Durgesh1988 Date: Tue, 27 Sep 2016 18:01:17 +0530 Subject: [PATCH 2/3] CAT-2359 Fixed --- .../workzone/blueprint/popups/blueprintLaunchParams.html | 2 +- .../workzone/blueprint/popups/blueprintLaunchParamsCtrl.js | 7 +------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/client/cat3/src/partials/sections/dashboard/workzone/blueprint/popups/blueprintLaunchParams.html b/client/cat3/src/partials/sections/dashboard/workzone/blueprint/popups/blueprintLaunchParams.html index a39f27c99..1e9c339da 100644 --- a/client/cat3/src/partials/sections/dashboard/workzone/blueprint/popups/blueprintLaunchParams.html +++ b/client/cat3/src/partials/sections/dashboard/workzone/blueprint/popups/blueprintLaunchParams.html @@ -46,7 +46,7 @@ - +