Introduced dynamic workflow properties in VID FE
[vid.git] / vid-app-common / src / main / webapp / app / vid / scripts / modals / new-change-management / new-change-management.controller.js
index 3918219..c85f0fc 100644 (file)
@@ -10,7 +10,7 @@
         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.controllers = VIDCONFIGURATION.SCALE_OUT_CONTROLLERS;
+
         vm.wizardStep = 1;
         vm.nextStep = function(){
             vm.wizardStep++;
@@ -43,6 +43,7 @@
 
         var init = function () {
             vm.changeManagement = {};
+            vm.changeManagement.workflowParameters = new Map();
 
             loadServicesCatalog();
             fetchAttUid().then(registerVNFNamesWatcher);
 
                                                 _.forEach(newVNFName.vfModules, function (mdl, key) {
                                                     mdl.scale = false; //defaults to not scale unless user changes it
-                                                    if(mdl.properties && mdl.properties.max_vf_module_instances) {
+                                                    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.max_vf_module_instances.value - mdl.currentCount > 0;
+                                                        mdl.scalable = mdl.properties.maxCountInstances - mdl.currentCount > 0;
                                                     }else{
                                                         mdl.scalable = false;
                                                     }
         };
 
         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,
                             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
                             }
                         }
                     }
                        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 ={};
                     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
                                                        'operations_timeout':changeManagement.operationTimeout
                                                };
                                                requestParametersData = {
-                            controllerType: changeManagement.controllerType,
                             payload: JSON.stringify(payloadObj)
                                                }
                                        }else if(workflowType=="VNF Config Update"){
 
                         if(moduleToScale.userParams) {
                             requestParametersData = {
-                                controllerType: changeManagement.controllerType,
                                 userParams: moduleToScale.userParams
                                 //,usePreload: true
                             }
                         }else{
                             requestParametersData = {
-                                controllerType: changeManagement.controllerType,
                                 userParams: []
                                 //,usePreload: false
                             }
                                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
+                        requestParameters:requestParametersData,
+                        configurationParameters: JSON.parse(configurationParameters)
                     };
                     requestInfoData.instanceName = vnf.name + "_" + (moduleToScale.currentCount + 1);
                 }else{
                         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,
                        });
                        return JSON.stringify(result);
                }
-               
         vm.openModal = function () {
             if(vm.hasScheduler) { //scheduling supported
                                $scope.widgetParameter = ""; // needed by the 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) {
-
-                    if(vm.changeManagement.workflow==="VNF Scale Out") {
-                        dataToSo = JSON.parse(dataToSo);
-                        dataToSo = {requestDetails: dataToSo.requestDetails[0]};
-                        changeManagementService.postChangeManagementScaleOutNow(dataToSo, vm.changeManagement.vnfNames[0]["service-instance-node"][0].properties["service-instance-id"], vm.changeManagement.vnfNames[0].id);
-                    }else{
-                        //TODO: foreach
-                        var vnfName = vm.changeManagement.vnfNames[0].name;
-                        changeManagementService.postChangeManagementNow(dataToSo, vnfName);
-                    }
+                    var vnfName = vm.changeManagement.vnfNames[0].name;
+                    changeManagementService.postChangeManagementNow(dataToSo, vnfName);
                 }
                        }
         };
         };
 
         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));
+          }).then(function () {
+            vm.loadRemoteWorkFlowsParameters();
+          });
+        };
+
+        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);
+          });
+        };
+
+        vm.loadRemoteWorkFlowsParameters = function () {
+          vm.remoteWorkflowsParameters = new Map();
+          vm.remoteWorkflows.forEach(function(workflow) {
+            vm.loadRemoteWorkFlowParameters(workflow);
+          });
+        };
+
+        vm.loadRemoteWorkFlowParameters = function (workflow) {
+          changeManagementService.getSOWorkflowParameter(workflow.id)
+          .then(function (response) {
+            vm.remoteWorkflowsParameters.set(workflow.name, response.data.parameterDefinitions);
+          })
+          .catch(function (error) {
+            $log.error(error);
+          });
+        };
+
+        vm.getRemoteWorkFlowParameters = function (workflow) {
+          if (workflow && vm.remoteWorkflowsParameters.has(workflow)) {
+            return vm.remoteWorkflowsParameters.get(workflow)
+          }
+          return [];
         };
 
         //Must be $scope because we bind to the onchange of the html (cannot attached to vm variable).
 
         vm.isConfigUpdate = function () {
             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;