'use strict';
appDS2.controller("newChangeManagementModalController", ["$uibModalInstance", "$uibModal",'$q', "AaiService", "changeManagementService", "Upload",
- "$log", "$scope", "_", "COMPONENT", "VIDCONFIGURATION", newChangeManagementModalController]);
+ "$log", "$scope", "_", "COMPONENT", "VIDCONFIGURATION","DataService","featureFlags", newChangeManagementModalController]);
- function newChangeManagementModalController($uibModalInstance, $uibModal,$q, AaiService, changeManagementService, Upload, $log, $scope, _, COMPONENT, VIDCONFIGURATION) {
+ function newChangeManagementModalController($uibModalInstance, $uibModal,$q, AaiService, changeManagementService, Upload, $log, $scope, _, COMPONENT, VIDCONFIGURATION, DataService, featureFlags) {
var vm = this;
+ vm.hasScheduler = !!VIDCONFIGURATION.SCHEDULER_PORTAL_URL;
vm.configUpdatePatternError = "Invalid file type. Please select a file with a CSV extension.";
vm.configUpdateContentError = "Invalid file structure.";
+ vm.wizardStep = 1;
+ vm.nextStep = function(){
+ vm.wizardStep++;
+ $(".modal-dialog").animate({"width":"1200px"},400,'linear');
+ };
+ vm.prevStep = function(){
+ vm.wizardStep--;
+ $(".modal-dialog").animate({"width":"600px"},400,'linear');
+ };
+
vm.softwareVersionRegex = "[-a-zA-Z0-9\.]+";
+ var attuid;
+
+ function fetchAttUid() {
+ var defer = $q.defer();
+ if (attuid) {
+ defer.resolve(attuid);
+ } else {
+ AaiService.getLoggedInUserID(function (response) {
+ attuid = response.data;
+ defer.resolve(attuid);
+ },
+ function (err) {
+ defer.reject(err);
+ });
+ }
+ return defer.promise;
+ }
+
var init = function () {
vm.changeManagement = {};
loadServicesCatalog();
- registerVNFNamesWatcher();
+ fetchAttUid().then(registerVNFNamesWatcher);
vm.loadSubscribers();
};
_.each(response.data.vnfs, function (vnf) {
if (newVNFName["invariant-id"] === vnf.invariantUuid) {
availableVersions.push(extractVNFModel(vnf, response.data.service, newVNFName));
+
+ //for scale out screen
+ if(service.uuid === newVNFName["service-instance-node"][0].properties["model-version-id"]) {
+ newVNFName.vfModules = vnf.vfModules;
+ newVNFName.category = response.data.service.category;
+ newVNFName.groupModules = _.groupBy(newVNFName.vfModules, "customizationUuid");
+
+ //list vfmodules ids in AAI that belong to that vnf instance
+ var modulesAaiIds = _.filter(newVNFName.relatedTo, function(item){
+ return item["node-type"] === "vf-module";
+ }).map(function(item){
+ return item.id;
+ });
+
+ _.forEach(newVNFName.vfModules, function (mdl, key) {
+ mdl.scale = false; //defaults to not scale unless user changes it
+ if(mdl.properties && mdl.properties.maxCountInstances) {
+
+ //how many vf modules of the same customizationId belong to that vnf instance
+ mdl.currentCount = _.filter(vm.vfModules, function(item){
+ return modulesAaiIds.indexOf(item.id) > -1 && item.properties["model-customization-id"] === mdl.customizationUuid;
+ }).length;
+
+ mdl.scalable = mdl.properties.maxCountInstances - mdl.currentCount > 0;
+ }else{
+ mdl.scalable = false;
+ }
+ });
+ }
}
});
var versions = _.uniqBy(availableVersions, 'modelInfo.modelVersion');
};
var extractVNFModel = function (csarVNF, sdcService, selectionVNF) {
+ /**
+ @param selectionVNF A vnf *instance* selected in "available VNF" drop-down box
+ @param csarVNF A VNF *MODEL* that has an invariantUuid same as selectionVNF (might be
+ a different version; i.e. selectionVNF.modelVersionId <> csarVNF.uuid)
+ @param sdcService The Service *MODEL* which has the related VNF `csarVNF`.
+ */
var versionCsarData = {
vnfInstanceId: "",
vnfName: csarVNF.name,
modelInfo: {
modelType: "vnf",
modelInvariantId: csarVNF.invariantUuid,
- modelVersionId: selectionVNF.modelVersionId,
+ modelVersionId: csarVNF.uuid,
modelName: csarVNF.name,
modelVersion: csarVNF.version,
modelCustomizationName: csarVNF.modelCustomizationName,
modelCustomizationId: csarVNF.customizationUuid
},
- cloudConfiguration: {
- lcpCloudRegionId: "mdt1",
- tenantId: "88a6ca3ee0394ade9403f075db23167e"
- },
+ cloudConfiguration: selectionVNF.cloudConfiguration || {},
requestInfo: {
source: "VID",
suppressRollback: false,
- requestorId: "az2016"
+ requestorId: attuid
},
relatedInstanceList: [
{
instanceId: selectionVNF["service-instance-node"]["0"].properties['service-instance-id'],
modelInfo: {
modelType: "service",
- modelInvariantId: selectionVNF["service-instance-node"]["0"].properties['model-invariant-id'],
- modelVersionId: selectionVNF.modelVersionId,
+ modelInvariantId: sdcService.invariantUuid,
+ modelVersionId: sdcService.uuid,
modelName: sdcService.name,
- modelVersion: sdcService.version,
- modelCustomizationName: selectionVNF["service-instance-node"]["0"].properties['model-customization-name'], //TODO: Missing
- modelCustomizationId: selectionVNF["service-instance-node"]["0"].properties['model-customization-id']
+ modelVersion: sdcService.version
}
}
}
return data;
}]
})
- .then(function (configUpdateResponse) {
- vm.changeManagement.configUpdateFile = configUpdateResponse && JSON.parse(configUpdateResponse.data).payload;
- defer.resolve(true);
- })
- .catch(function (error) {
- defer.resolve(false);
- });
+ .then(function (configUpdateResponse) {
+ vm.changeManagement.configUpdateFile = configUpdateResponse && JSON.parse(configUpdateResponse.data).payload;
+ defer.resolve(true);
+ })
+ .catch(function (error) {
+ defer.resolve(false);
+ });
return defer.promise;
};
- vm.openModal = function () {
- $scope.widgetParameter = ""; // needed by the scheduler?
-
- // properties needed by the scheduler so it knows whether to show
- // policy or sniro related features on the scheduler UI or not.
- vm.changeManagement.policyYN = "Y";
- vm.changeManagement.sniroYN = "Y";
-
- var data = {
- widgetName: 'Portal-Common-Scheduler',
- widgetData: vm.changeManagement,
- widgetParameter: $scope.widgetParameter
- };
+ /***converting objects to scheduler format (taken from IST) - was altered for Scale out support ***/
+ function extractChangeManagementCallbackDataStr(changeManagement) {
+ console.log(changeManagement);
+ var result = {};
+ result.requestType = changeManagement.workflow;
+ var workflowType = changeManagement.workflow;
+ var configurationParameters = changeManagement.configurationParameters;
+ result.requestDetails = [];
+ _.forEach(changeManagement.vnfNames, function (vnf) {
+
+ try{
+ var requestInfoData ={};
+ var requestParametersData ={};
+ var moduleToScale = _.find(vnf.vfModules, function(key, item){
+ return !item.scale;
+ });
+ if (vnf.availableVersions && vnf.availableVersions.length!=0){
+
+ requestInfoData ={
+ source: vnf.availableVersions[0].requestInfo.source,
+ suppressRollback: vnf.availableVersions[0].requestInfo.suppressRollback,
+ requestorId: vnf.availableVersions[0].requestInfo.requestorId
+ }
+
+ if(workflowType=='Update'){
+ requestParametersData = {
+ usePreload: vnf.availableVersions[0].requestParameters.usePreload
+ }
+ }else if(workflowType=="Replace"){
+ requestParametersData = {
+ rebuildVolumeGroups: vnf.availableVersions[0].requestParameters.usePreload
+ }
+ }else if(workflowType=="VNF In Place Software Update"){
+ var payloadObj = {
+ 'existing_software_version':changeManagement.existingSoftwareVersion,
+ 'new_software_version':changeManagement.newSoftwareVersion,
+ 'operations_timeout':changeManagement.operationTimeout
+ };
+ requestParametersData = {
+ payload: JSON.stringify(payloadObj)
+ }
+ }else if(workflowType=="VNF Config Update"){
+ requestParametersData = {
+ payload: changeManagement.configUpdateFile
+ }
+ }else if(workflowType=="VNF Scale Out"){
+ if(!moduleToScale) return null;
+
+ if(moduleToScale.userParams) {
+ requestParametersData = {
+ userParams: moduleToScale.userParams
+ //,usePreload: true
+ }
+ }else{
+ requestParametersData = {
+ userParams: []
+ //,usePreload: false
+ }
+ }
+ }
+ $log.info('SchedulerWidgetCtrl:extractChangeManagementCallbackDataStr info:: workflowType '+ workflowType);
+ $log.info('SchedulerWidgetCtrl:extractChangeManagementCallbackDataStr info:: requestParametersData '+ requestParametersData);
+
+ }else if(workflowType=="VNF In Place Software Update"){
+ var payloadObj = {
+ 'existing_software_version':changeManagement.existingSoftwareVersion,
+ 'new_software_version':changeManagement.newSoftwareVersion,
+ 'operations_timeout':changeManagement.operationTimeout
+ };
+ requestParametersData = {
+ payload: JSON.stringify(payloadObj)
+ }
+ }else if(workflowType=="VNF Config Update"){
+ requestParametersData = {
+ payload: changeManagement.configUpdateFile
+ }
+ }
+
+
+ var data;
+ if(workflowType=="VNF Scale Out") {
+ data = {
+ vnfName: vnf.name,
+ vnfInstanceId: vnf.id,
+ modelInfo: {
+ modelType: 'vfModule',
+ modelInvariantId: moduleToScale.invariantUuid,
+ modelName: moduleToScale.modelCustomizationName,
+ modelVersion: moduleToScale.version,
+ modelCustomizationName: moduleToScale.modelCustomizationName,
+ modelCustomizationId: moduleToScale.customizationUuid,
+ modelVersionId: moduleToScale.uuid
+ },
+ cloudConfiguration: vnf.cloudConfiguration,
+ requestInfo: requestInfoData,
+ relatedInstanceList: [],
+ requestParameters:requestParametersData,
+ configurationParameters: JSON.parse(configurationParameters)
+ };
+ requestInfoData.instanceName = vnf.name + "_" + (moduleToScale.currentCount + 1);
+ }else{
+ data = {
+ vnfName: vnf.name,
+ vnfInstanceId: vnf.id,
+ modelInfo: {
+ modelType: 'vnf',
+ modelInvariantId: vnf.properties['model-invariant-id'],
+ modelVersionId: vnf.modelVersionId,
+ modelName: vnf.properties['vnf-name'],
+ modelVersion: vnf.version,
+ modelCustomizationName: vnf.properties['model-customization-name'],
+ modelCustomizationId: vnf.properties['model-customization-id']
+ },
+ cloudConfiguration: vnf.cloudConfiguration,
+ requestInfo: requestInfoData,
+ relatedInstanceList: [],
+ requestParameters:requestParametersData
+ };
+ }
- window.parent.postMessage(data, VIDCONFIGURATION.SCHEDULER_PORTAL_URL);
+ var serviceInstanceId = '';
+ _.forEach(vnf['service-instance-node'], function (instanceNode) {
+ if(instanceNode['node-type'] === 'service-instance'){
+ serviceInstanceId = instanceNode.properties['service-instance-id'];
+ }
+ });
+
+ if (vnf.availableVersions && vnf.availableVersions.length!=0){
+ _.forEach(vnf.availableVersions[0].relatedInstanceList, function (related) {
+ var rel = related.relatedInstance;
+ var relatedInstance = {
+ instanceId: serviceInstanceId,
+ modelInfo: {
+ modelType: rel.modelInfo.modelType,
+ modelInvariantId: rel.modelInfo.modelInvariantId,
+ modelVersionId: rel.modelInfo.modelVersionId,
+ modelName: rel.modelInfo.modelName,
+ modelVersion: rel.modelInfo.modelVersion,
+ modelCustomizationName: rel.modelInfo.modelCustomizationName,
+ modelCustomizationId: rel.modelInfo.modelCustomizationId
+ }
+ };
+ if (rel.vnfInstanceId)
+ relatedInstance.instanceId = rel.vnfInstanceId;
+
+ data.relatedInstanceList.push({relatedInstance: relatedInstance});
+ });
+ if(workflowType=="VNF Scale Out") {
+ //push vnf to related as well as the service instance
+ var relatedInstance = {
+ instanceId: vnf.id,
+ modelInfo: {
+ modelCustomizationId: vnf.availableVersions[0].modelInfo.modelCustomizationId,
+ modelCustomizationName: vnf.availableVersions[0].modelInfo.modelCustomizationName,
+ modelInvariantId: vnf.availableVersions[0].modelInfo.modelInvariantId,
+ modelName: vnf.availableVersions[0].modelInfo.modelName,
+ modelType: vnf.availableVersions[0].modelInfo.modelType,
+ modelVersion: vnf.availableVersions[0].modelInfo.modelVersion,
+ modelVersionId: vnf.availableVersions[0].modelInfo.modelVersionId
+ }
+ };
+ data.relatedInstanceList.push({relatedInstance: relatedInstance});
+ }
+ }
+ }catch(err){
+ $log.error('SchedulerCtrl::extractChangeManagementCallbackDataStr error: ' + err);
+ }
+
+ result.requestDetails.push(data);
+ });
+ return JSON.stringify(result);
+ }
+ vm.openModal = function () {
+ if(vm.hasScheduler) { //scheduling supported
+ $scope.widgetParameter = ""; // needed by the scheduler?
+
+ // properties needed by the scheduler so it knows whether to show
+ // policy or sniro related features on the scheduler UI or not.
+ vm.changeManagement.policyYN = "Y";
+ vm.changeManagement.sniroYN = "Y";
+
+ if (featureFlags.isOn(COMPONENT.FEATURE_FLAGS.FLAG_ADD_MSO_TESTAPI_FIELD)) {
+ vm.changeManagement.testApi = DataService.getMsoRequestParametersTestApi();
+ }
+ var data = {
+ widgetName: 'Portal-Common-Scheduler',
+ widgetData: vm.changeManagement,
+ widgetParameter: $scope.widgetParameter
+ };
+
+ window.parent.postMessage(data, VIDCONFIGURATION.SCHEDULER_PORTAL_URL);
+ } else {
+ //no scheduling support
+ var dataToSo = extractChangeManagementCallbackDataStr(vm.changeManagement);
+ if(dataToSo) {
+ var vnfName = vm.changeManagement.vnfNames[0].name;
+ changeManagementService.postChangeManagementNow(dataToSo, vnfName);
+ }
+ }
};
vm.loadSubscribers = function () {
// var promiseArrOfGetVnfs = preparePromiseArrOfGetVnfs(instances);
vm.vnfs = [];
+ vm.vfModules = [];
AaiService.getVnfsByCustomerIdAndServiceType(
vm.changeManagement.subscriberId,
}
} else if (nodeType === "service-instance") {
vm.serviceInstances.push(vnfsData[i]);
+ } else if (nodeType === "vf-module") {
+ vm.vfModules.push(vnfsData[i]);
}
}
}
vm.serviceInstancesToGetVersions = [];
var versions = [];
_.forEach(vm.vnfs, function (vnf) {
- if (vnf.properties['nf-role'] === vm.changeManagement['vnfType']) {
-
+ if (vnf.properties['nf-role'] === vm.changeManagement['vnfType']
+ && vnf.properties["model-invariant-id"]
+ && vnf.properties["model-version-id"]) {
vm.serviceInstancesToGetVersions.push({
- "model-invariant-id": vnf.properties["model-invariant-id"],
- "model-version-id": vnf.properties["model-version-id"] }
+ "model-invariant-id": vnf.properties["model-invariant-id"],
+ "model-version-id": vnf.properties["model-version-id"]
+ }
);
versions.push(vnf.properties["model-invariant-id"]);
};
vm.loadWorkFlows = function () {
- changeManagementService.getWorkflows(vm.changeManagement.vnfNames)
- .then(function(response) {
- vm.workflows = response.data.workflows;
- })
- .catch(function(error) {
- $log.error(error);
- });
+ // Should be corrected when VID-397 will be closed. At the moment there is a need
+ // to merge local and remote workflows not to broke current functionality.
+ return vm.loadLocalWorkFlows()
+ .then(vm.loadRemoteWorkFlows)
+ .then(function () {
+ vm.workflows = vm.localWorkflows.concat(vm.remoteWorkflows.map(item => item.name));
+ });
+ };
+
+ vm.loadLocalWorkFlows = function () {
+ return changeManagementService.getWorkflows(vm.changeManagement.vnfNames)
+ .then(function (response) {
+ vm.localWorkflows = response.data.workflows || [];
+ }).catch(function (error) {
+ $log.error(error);
+ });
+ };
+
+ vm.loadRemoteWorkFlows = function () {
+ let vnfNames = vm.changeManagement.vnfNames.map(vnfName => vnfName.name);
+ return changeManagementService.getSOWorkflows(vnfNames)
+ .then(function (response) {
+ vm.remoteWorkflows = response.data || [];
+ }).catch(function (error) {
+ $log.error(error);
+ });
};
//Must be $scope because we bind to the onchange of the html (cannot attached to vm variable).
return vm.changeManagement.workflow === COMPONENT.WORKFLOWS.vnfConfigUpdate;
}
+ vm.isScaleOut = function () {
+ return vm.changeManagement.workflow === COMPONENT.WORKFLOWS.vnfScaleOut;
+ }
+
vm.shouldShowVnfInPlaceFields = function () {
return vm.changeManagement.workflow === COMPONENT.WORKFLOWS.vnfInPlace;
};
+ vm.setPreload = function (fileEl) {
+ var files = fileEl.files;
+ var file = files[0];
+ var reader = new FileReader();
+
+ reader.onloadend = function(evt) {
+ if (evt.target.readyState === FileReader.DONE) {
+ $scope.$apply(function () {
+ $scope.moduleArr[0].userParams = JSON.parse(evt.target.result);
+ });
+ }
+ };
+
+ reader.readAsText(file);
+ };
+
init();
}
})();
\ No newline at end of file