diff options
12 files changed, 403 insertions, 87 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/WorkflowsController.java b/vid-app-common/src/main/java/org/onap/vid/controller/WorkflowsController.java index b8f033c95..a94481b9e 100644 --- a/vid-app-common/src/main/java/org/onap/vid/controller/WorkflowsController.java +++ b/vid-app-common/src/main/java/org/onap/vid/controller/WorkflowsController.java @@ -21,10 +21,11 @@ package org.onap.vid.controller; import java.util.List; -import org.onap.portalsdk.core.controller.RestrictedBaseController; +import org.onap.vid.model.LocalWorkflowParameterDefinitions; import org.onap.vid.model.SOWorkflow; import org.onap.vid.model.SOWorkflowParameterDefinitions; -import org.onap.vid.services.ExtWorkflowsService; +import org.onap.vid.services.ExternalWorkflowsService; +import org.onap.vid.services.LocalWorkflowsService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; @@ -34,24 +35,31 @@ import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping(WorkflowsController.WORKFLOWS_MANAGEMENT) -public class WorkflowsController extends RestrictedBaseController { +public class WorkflowsController extends VidRestrictedBaseController { static final String WORKFLOWS_MANAGEMENT = "workflows-management"; - private ExtWorkflowsService extWorkflowsService; + private ExternalWorkflowsService externalWorkflowsService; + private LocalWorkflowsService localWorkflowsService; @Autowired - public WorkflowsController(ExtWorkflowsService extWorkflowsService) { - this.extWorkflowsService = extWorkflowsService; + public WorkflowsController(ExternalWorkflowsService externalWorkflowsService, LocalWorkflowsService localWorkflowsService) { + this.externalWorkflowsService = externalWorkflowsService; + this.localWorkflowsService = localWorkflowsService; } @RequestMapping(value = "workflows", method = RequestMethod.GET) public List<SOWorkflow> getWorkflows(@RequestParam(value = "vnfName") String vnfName){ - return extWorkflowsService.getWorkflows(vnfName); + return externalWorkflowsService.getWorkflows(vnfName); } - @RequestMapping(value = "workflow-parameters/{id}", method = RequestMethod.GET) + @RequestMapping(value = "remote-workflow-parameters/{id}", method = RequestMethod.GET) SOWorkflowParameterDefinitions getParameters(@PathVariable Long id) { - return extWorkflowsService.getWorkflowParameterDefinitions(id); + return externalWorkflowsService.getWorkflowParameterDefinitions(id); + } + + @RequestMapping(value = "local-workflow-parameters/{name}", method = RequestMethod.GET) + LocalWorkflowParameterDefinitions getParameters(@PathVariable String name) { + return localWorkflowsService.getWorkflowParameterDefinitions(name); } } diff --git a/vid-app-common/src/main/java/org/onap/vid/model/SOWorkflows.kt b/vid-app-common/src/main/java/org/onap/vid/model/SOWorkflows.kt index 9fbae0612..b88c3f6f6 100644 --- a/vid-app-common/src/main/java/org/onap/vid/model/SOWorkflows.kt +++ b/vid-app-common/src/main/java/org/onap/vid/model/SOWorkflows.kt @@ -2,14 +2,14 @@ * ============LICENSE_START======================================================= * VID * ================================================================================ - * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019 Nokia Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -20,27 +20,62 @@ package org.onap.vid.model -data class SOWorkflow constructor(val id: Long, val name: String) { +data class SOWorkflow constructor( + val id: Long, + val name: String) { fun clone(): SOWorkflow { return copy() } } -data class SOWorkflows @JvmOverloads constructor(val workflows: List<SOWorkflow> = emptyList()) { +data class SOWorkflows @JvmOverloads constructor( + val workflows: List<SOWorkflow> = emptyList()) { fun clone(): SOWorkflows { return copy(workflows.toMutableList()) } } -enum class SOWorkflowType(val type: String) { +enum class SOWorkflowType( + val type: String) { STRING("STRING") } -data class SOWorkflowParameterDefinition constructor(val id: Long, val name: String, val pattern: String, - val type: SOWorkflowType, val required: Boolean) +enum class LocalWorkflowType( + val type: String) { + STRING("STRING"), + FILE("FILE") +} + +data class SOWorkflowParameterDefinition constructor( + val id: Long, + val name: String, + val pattern: String, + val type: SOWorkflowType, + val required: Boolean) -data class SOWorkflowParameterDefinitions constructor(val parameterDefinitions: List<SOWorkflowParameterDefinition> = emptyList()) { +data class SOWorkflowParameterDefinitions constructor( + val parameterDefinitions: List<SOWorkflowParameterDefinition> = emptyList()) { fun clone(): SOWorkflowParameterDefinitions { return copy(parameterDefinitions.toMutableList()) } } + +data class LocalWorkflowParameterDefinition @JvmOverloads constructor( + val id: Long, + val name: String, + val required: Boolean, + val type: LocalWorkflowType, + val pattern: String? = null, + val msgOnPatternError: String? = null, + val msgOnContentError: String? = null, + val acceptableFileType: String? = null +) + +data class LocalWorkflowParameterDefinitions constructor( + val parameterDefinitions: List<LocalWorkflowParameterDefinition> = emptyList() +) { + fun clone(): LocalWorkflowParameterDefinitions { + return copy(parameterDefinitions.toMutableList()) + } +} + diff --git a/vid-app-common/src/main/java/org/onap/vid/services/ExtWorkflowsService.java b/vid-app-common/src/main/java/org/onap/vid/services/ExternalWorkflowsService.java index a4450ca01..da909a54d 100644 --- a/vid-app-common/src/main/java/org/onap/vid/services/ExtWorkflowsService.java +++ b/vid-app-common/src/main/java/org/onap/vid/services/ExternalWorkflowsService.java @@ -24,7 +24,7 @@ import java.util.List; import org.onap.vid.model.SOWorkflow; import org.onap.vid.model.SOWorkflowParameterDefinitions; -public interface ExtWorkflowsService { +public interface ExternalWorkflowsService { List<SOWorkflow> getWorkflows(String vnfName); SOWorkflowParameterDefinitions getWorkflowParameterDefinitions(Long workflowId); diff --git a/vid-app-common/src/main/java/org/onap/vid/services/ExtWorkflowsServiceImpl.java b/vid-app-common/src/main/java/org/onap/vid/services/ExternalWorkflowsServiceImpl.java index 61ed2da67..1da03f0ac 100644 --- a/vid-app-common/src/main/java/org/onap/vid/services/ExtWorkflowsServiceImpl.java +++ b/vid-app-common/src/main/java/org/onap/vid/services/ExternalWorkflowsServiceImpl.java @@ -30,12 +30,12 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @Service -public class ExtWorkflowsServiceImpl implements ExtWorkflowsService { +public class ExternalWorkflowsServiceImpl implements ExternalWorkflowsService { private MockedWorkflowsRestClient mockedWorkflowsRestClient; @Autowired - public ExtWorkflowsServiceImpl(MockedWorkflowsRestClient mockedWorkflowsRestClient) { + public ExternalWorkflowsServiceImpl(MockedWorkflowsRestClient mockedWorkflowsRestClient) { this.mockedWorkflowsRestClient = mockedWorkflowsRestClient; } diff --git a/vid-app-common/src/main/java/org/onap/vid/services/LocalWorkflowsService.java b/vid-app-common/src/main/java/org/onap/vid/services/LocalWorkflowsService.java new file mode 100644 index 000000000..b0674f0e3 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/services/LocalWorkflowsService.java @@ -0,0 +1,26 @@ +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * Copyright (C) 2019 Nokia Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.vid.services; + +import org.onap.vid.model.LocalWorkflowParameterDefinitions; + +public interface LocalWorkflowsService { + LocalWorkflowParameterDefinitions getWorkflowParameterDefinitions(String workflowName); +} diff --git a/vid-app-common/src/main/java/org/onap/vid/services/LocalWorkflowsServiceImpl.java b/vid-app-common/src/main/java/org/onap/vid/services/LocalWorkflowsServiceImpl.java new file mode 100644 index 000000000..733d275d8 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/services/LocalWorkflowsServiceImpl.java @@ -0,0 +1,58 @@ +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * Copyright (C) 2019 Nokia Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.vid.services; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import java.util.Map; +import org.onap.vid.model.LocalWorkflowParameterDefinition; +import org.onap.vid.model.LocalWorkflowParameterDefinitions; +import org.onap.vid.model.LocalWorkflowType; +import org.springframework.stereotype.Service; + +@Service +public class LocalWorkflowsServiceImpl implements LocalWorkflowsService { + + Map<String, LocalWorkflowParameterDefinitions> WORKFLOWS_WITH_PARAMETERS = ImmutableMap.<String, LocalWorkflowParameterDefinitions>builder() + .put("VNF Scale Out", new LocalWorkflowParameterDefinitions( + ImmutableList.of( + new LocalWorkflowParameterDefinition(1, "Configuration Parameters", true, LocalWorkflowType.STRING,".*") + ) + )) + .put("VNF In Place Software Update", new LocalWorkflowParameterDefinitions( + ImmutableList.of( + new LocalWorkflowParameterDefinition(2, "Operations timeout",true, LocalWorkflowType.STRING,"[0-9]+"), + new LocalWorkflowParameterDefinition(3, "Existing software version", true, LocalWorkflowType.STRING, "[-a-zA-Z0-9.]+"), + new LocalWorkflowParameterDefinition(4, "New software version", true, LocalWorkflowType.STRING, "[-a-zA-Z0-9.]+") + ) + )) + .put("VNF Config Update", new LocalWorkflowParameterDefinitions( + ImmutableList.of( + new LocalWorkflowParameterDefinition(5, "Attach configuration file", true, LocalWorkflowType.FILE, ".*", "Invalid file type. Please select a file with a CSV extension.", "Invalid file structure.", ".csv") + ) + )) + .build(); + + @Override + public LocalWorkflowParameterDefinitions getWorkflowParameterDefinitions(String workflowName) { + return WORKFLOWS_WITH_PARAMETERS.get(workflowName); + } + +} diff --git a/vid-app-common/src/main/webapp/app/vid/scripts/constants/componentConstants.js b/vid-app-common/src/main/webapp/app/vid/scripts/constants/componentConstants.js index 4ac5f85ac..dbf6588ce 100755 --- a/vid-app-common/src/main/webapp/app/vid/scripts/constants/componentConstants.js +++ b/vid-app-common/src/main/webapp/app/vid/scripts/constants/componentConstants.js @@ -116,7 +116,8 @@ appDS2 CHANGE_MANAGEMENT_OPERATION_NO_SCHEDULER: "change-management/workflow/@vnfName", GET_WORKFLOW: "change-management/get_vnf_workflow_relation", GET_SO_WORKFLOWS: "workflows-management/workflows", - GET_SO_WORKFLOW_PARAMETER: "workflows-management/workflow-parameters/@workflowID", + GET_SO_WORKFLOW_PARAMETER: "workflows-management/remote-workflow-parameters/@workflowID", + GET_LOCAL_WORKFLOW_PARAMETER: "workflows-management/local-workflow-parameters/@workflowName", GET_MSO_WORKFLOWS: "change-management/mso", GET_SCHEDULER_CHANGE_MANAGEMENTS: "change-management/scheduler", CANCEL_SCHEDULE_REQUEST: "change-management/scheduler/schedules", diff --git a/vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.controller.js b/vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.controller.js index e525f0f5c..8a7d59a62 100644 --- a/vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.controller.js +++ b/vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.controller.js @@ -28,8 +28,6 @@ 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(){ @@ -202,7 +200,7 @@ }] }) .then(function (configUpdateResponse) { - vm.changeManagement.configUpdateFile = configUpdateResponse && JSON.parse(configUpdateResponse.data).payload; + vm.getInternalWorkFlowParameter("VNF Config Update", "FILE", "Attach configuration file").value = configUpdateResponse && JSON.parse(configUpdateResponse.data).payload; defer.resolve(true); }) .catch(function (error) { @@ -218,7 +216,6 @@ var result = {}; result.requestType = changeManagement.workflow; var workflowType = changeManagement.workflow; - var configurationParameters = changeManagement.configurationParameters; result.requestDetails = []; _.forEach(changeManagement.vnfNames, function (vnf) { @@ -246,51 +243,50 @@ } }else if(workflowType=="VNF In Place Software Update"){ var payloadObj = { - 'existing_software_version':changeManagement.existingSoftwareVersion, - 'new_software_version':changeManagement.newSoftwareVersion, - 'operations_timeout':changeManagement.operationTimeout + 'existing_software_version':vm.getInternalWorkFlowParameter(workflowType, 'STRING', 'Existing software version').value, + 'new_software_version':vm.getInternalWorkFlowParameter(workflowType, 'STRING', 'New software version').value, + 'operations_timeout':vm.getInternalWorkFlowParameter(workflowType, 'STRING', 'Operations timeout').value }; requestParametersData = { payload: JSON.stringify(payloadObj) } }else if(workflowType=="VNF Config Update"){ requestParametersData = { - payload: changeManagement.configUpdateFile + payload: vm.getInternalWorkFlowParameter("VNF Config Update", "FILE", "Attach configuration file").value } - }else if(workflowType=="VNF Scale Out"){ - if(!moduleToScale) return null; - - if(moduleToScale.userParams) { - requestParametersData = { - userParams: moduleToScale.userParams - //,usePreload: true - } - }else{ - requestParametersData = { - userParams: [] - //,usePreload: false - } - } - } + }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 + 'existing_software_version':vm.getInternalWorkFlowParameter(workflowType, 'STRING', 'Existing software version').value, + 'new_software_version':vm.getInternalWorkFlowParameter(workflowType, 'STRING', 'New software version').value, + 'operations_timeout':vm.getInternalWorkFlowParameter(workflowType, 'STRING', 'Operations timeout').value }; requestParametersData = { payload: JSON.stringify(payloadObj) } }else if(workflowType=="VNF Config Update"){ requestParametersData = { - payload: changeManagement.configUpdateFile + payload: vm.getInternalWorkFlowParameter("VNF Config Update", "FILE", "Attach configuration file").value } } - var data; if(workflowType=="VNF Scale Out") { data = { @@ -309,7 +305,7 @@ requestInfo: requestInfoData, relatedInstanceList: [], requestParameters:requestParametersData, - configurationParameters: JSON.parse(configurationParameters) + configurationParameters: JSON.parse(vm.getInternalWorkFlowParameter("VNF Scale Out", "STRING", "Configuration Parameters").value) }; requestInfoData.instanceName = vnf.name + "_" + (moduleToScale.currentCount + 1); }else{ @@ -641,6 +637,7 @@ // 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.loadLocalWorkFlowsParameters) .then(vm.loadRemoteWorkFlows) .then(function () { vm.workflows = vm.localWorkflows.concat(vm.remoteWorkflows.map(item => item.name)); @@ -668,6 +665,28 @@ }); }; + vm.loadLocalWorkFlowsParameters = function () { + vm.localWorkflowsParameters = new Map(); + vm.localWorkflows.forEach(function(workflow) { + vm.loadLocalWorkFlowParameters(workflow); + }); + }; + + vm.loadLocalWorkFlowParameters = function (workflow) { + changeManagementService.getLocalWorkflowParameter(workflow) + .then(function (response) { + let fileParameters = response.data.parameterDefinitions.filter(item => item.type === 'FILE'); + let textParameters = response.data.parameterDefinitions.filter(item => item.type === 'STRING'); + let parameters = new Map(); + parameters.set('FILE', fileParameters); + parameters.set('STRING', textParameters); + vm.localWorkflowsParameters.set(workflow, parameters); + }) + .catch(function (error) { + $log.error(error); + }); + }; + vm.loadRemoteWorkFlowsParameters = function () { vm.remoteWorkflowsParameters = new Map(); vm.remoteWorkflows.forEach(function(workflow) { @@ -692,6 +711,19 @@ return []; }; + vm.getInternalWorkFlowParameters = function (workflow, type) { + if (workflow && vm.localWorkflowsParameters.has(workflow) && vm.localWorkflowsParameters.get(workflow).has(type)) { + return vm.localWorkflowsParameters.get(workflow).get(type) + } + return []; + }; + + vm.getInternalWorkFlowParameter = function (workflow, type, parameterName) { + if (workflow && vm.localWorkflowsParameters.has(workflow) && vm.localWorkflowsParameters.get(workflow).has(type)) { + return vm.localWorkflowsParameters.get(workflow).get(type).filter(parameter => parameter.name === parameterName)[0] + } + }; + //Must be $scope because we bind to the onchange of the html (cannot attached to vm variable). $scope.selectFileForVNFName = function (fileInput) { if (fileInput && fileInput.id) { diff --git a/vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.controller.test.js b/vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.controller.test.js index c271b7505..5f3669152 100644 --- a/vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.controller.test.js +++ b/vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.controller.test.js @@ -80,11 +80,13 @@ describe('Testing workFlows from SO', () => { test('Verify load workflows will call load from SO and join workflow lists', () => { // given let getWorkflowsStub = Promise.resolve({"data": {"workflows": ["workflow 0"]}}); + let getLocalWorkflowsParametersStub = Promise.resolve({"data": {}}); let getSOWorkflowsPromiseStub = Promise.resolve({"data": [{"id": "1", "name": "workflow 1"}, {"id": "2", "name": "workflow 2"}]}); let getSOWorkflowsParametersPromiseStub = Promise.resolve({"data":{"parameterDefinitions": []}}); $controller.changeManagement.vnfNames = [{name: 'test1'}, {name: "test2"}]; $changeManagementService.getWorkflows = () => getWorkflowsStub; + $changeManagementService.getLocalWorkflowParameter = () => getLocalWorkflowsParametersStub; $changeManagementService.getSOWorkflows = () => getSOWorkflowsPromiseStub; $changeManagementService.getSOWorkflowParameter = () => getSOWorkflowsParametersPromiseStub; // when @@ -98,6 +100,7 @@ describe('Testing workFlows from SO', () => { test('Verify load workflows will call load workflows parameters from SO', () => { // given let getWorkflowsStub = Promise.resolve({"data": {"workflows": ["workflow 0"]}}); + let getLocalWorkflowsParametersStub = Promise.resolve({"data": {}}); let getSOWorkflowsPromiseStub = Promise.resolve({"data": [{"id": "1", "name": "workflow 0"}]}); let getSOWorkflowsParametersPromiseStub = Promise.resolve({"data":{"parameterDefinitions": [ {"id": 1, "name": "parameter 1", "required": true, "type": "STRING", "pattern": "[0-9]*"}, @@ -106,6 +109,7 @@ describe('Testing workFlows from SO', () => { $controller.changeManagement.vnfNames = [{name: 'test1'}, {name: "test2"}]; $changeManagementService.getWorkflows = () => getWorkflowsStub; + $changeManagementService.getLocalWorkflowParameter = () => getLocalWorkflowsParametersStub; $changeManagementService.getSOWorkflows = () => getSOWorkflowsPromiseStub; $changeManagementService.getSOWorkflowParameter = () => getSOWorkflowsParametersPromiseStub; // when @@ -118,6 +122,56 @@ describe('Testing workFlows from SO', () => { }); }); + test('Verify load workflows will call load workflows parameters from local service', () => { + // given + let getWorkflowsStub = Promise.resolve({"data": {"workflows": ["VNF Scale Out"]}}); + let getLocalWorkflowsParametersStub = Promise.resolve({"data":{ + "parameterDefinitions": [ + { + "id": 1, + "name": "Configuration Parameters", + "required": true, + "type": "STRING", + "pattern": ".*", + "msgOnPatternError": null, + "msgOnContentError": null, + "acceptableFileType": null + } + ], + }}); + let getSOWorkflowsPromiseStub = Promise.resolve({"data": [{}]}); + let getSOWorkflowsParametersPromiseStub = Promise.resolve({"data":{}}); + + $controller.changeManagement.vnfNames = [{name: 'test1'}]; + $changeManagementService.getWorkflows = () => getWorkflowsStub; + $changeManagementService.getLocalWorkflowParameter = () => getLocalWorkflowsParametersStub; + $changeManagementService.getSOWorkflows = () => getSOWorkflowsPromiseStub; + $changeManagementService.getSOWorkflowParameter = () => getSOWorkflowsParametersPromiseStub; + // when + + let result = new Map(); + const scaleOutResult = new Map(); + scaleOutResult.set("FILE", []); + scaleOutResult.set("STRING", [ + { + "acceptableFileType": null, + "id": 1, + "msgOnContentError": null, + "msgOnPatternError": null, + "name": "Configuration Parameters", + "pattern": ".*", + "required": true, + "type": "STRING", + } + ]); + result.set("VNF Scale Out", scaleOutResult); + + return $controller.loadWorkFlows() + .then(() => { + expect($controller.localWorkflowsParameters).toEqual(result); + }); + }); + test('Verify broken SO workflows wont change content of local workflows', () => { // given let getWorkflowsStub = Promise.resolve({"data": {"workflows": ["workflow 0"]}}); @@ -132,5 +186,114 @@ describe('Testing workFlows from SO', () => { expect($controller.workflows).toEqual(['workflow 0']); }); }); -}); + test('Verify get internal workflow parameters should return an empty list if not such workflow exist', () => { + // given + let getWorkflowsStub = Promise.resolve({"data": {"workflows": ["VNF Scale Out"]}}); + let getLocalWorkflowsParametersStub = Promise.resolve({"data":{ + "parameterDefinitions": [ + { + "id": 1, + "name": "Configuration Parameters", + "required": true, + "type": "STRING", + "pattern": ".*", + "msgOnPatternError": null, + "msgOnContentError": null, + "acceptableFileType": null + } + ], + }}); + let getSOWorkflowsPromiseStub = Promise.resolve({"data": [{}]}); + let getSOWorkflowsParametersPromiseStub = Promise.resolve({"data":{}}); + + $controller.changeManagement.vnfNames = [{name: 'test1'}]; + $changeManagementService.getWorkflows = () => getWorkflowsStub; + $changeManagementService.getLocalWorkflowParameter = () => getLocalWorkflowsParametersStub; + $changeManagementService.getSOWorkflows = () => getSOWorkflowsPromiseStub; + $changeManagementService.getSOWorkflowParameter = () => getSOWorkflowsParametersPromiseStub; + // when + return $controller.loadWorkFlows() + .then(() => { + let internalWorkFlowParameters = $controller.getInternalWorkFlowParameters("NON-EXISTENT WF", "STRING"); + expect(internalWorkFlowParameters).toEqual([]); + }); + }); + + test('Verify get internal workflow parameters should return an empty list if not such type exist', () => { + // given + let getWorkflowsStub = Promise.resolve({"data": {"workflows": ["VNF Scale Out"]}}); + let getLocalWorkflowsParametersStub = Promise.resolve({"data":{ + "parameterDefinitions": [ + { + "id": 1, + "name": "Configuration Parameters", + "required": true, + "type": "STRING", + "pattern": ".*", + "msgOnPatternError": null, + "msgOnContentError": null, + "acceptableFileType": null + } + ], + }}); + let getSOWorkflowsPromiseStub = Promise.resolve({"data": [{}]}); + let getSOWorkflowsParametersPromiseStub = Promise.resolve({"data":{}}); + + $controller.changeManagement.vnfNames = [{name: 'test1'}]; + $changeManagementService.getWorkflows = () => getWorkflowsStub; + $changeManagementService.getLocalWorkflowParameter = () => getLocalWorkflowsParametersStub; + $changeManagementService.getSOWorkflows = () => getSOWorkflowsPromiseStub; + $changeManagementService.getSOWorkflowParameter = () => getSOWorkflowsParametersPromiseStub; + // when + return $controller.loadWorkFlows() + .then(() => { + let internalWorkFlowParameters = $controller.getInternalWorkFlowParameters("VNF Scale Out", "FILE"); + expect(internalWorkFlowParameters).toEqual([]); + }); + }); + + test('Verify get internal workflow parameters should return a list if such workflow and type exist', () => { + // given + let getWorkflowsStub = Promise.resolve({"data": {"workflows": ["VNF Scale Out"]}}); + let getLocalWorkflowsParametersStub = Promise.resolve({"data":{ + "parameterDefinitions": [ + { + "id": 1, + "name": "Configuration Parameters", + "required": true, + "type": "STRING", + "pattern": ".*", + "msgOnPatternError": null, + "msgOnContentError": null, + "acceptableFileType": null + } + ], + }}); + let getSOWorkflowsPromiseStub = Promise.resolve({"data": [{}]}); + let getSOWorkflowsParametersPromiseStub = Promise.resolve({"data":{}}); + + $controller.changeManagement.vnfNames = [{name: 'test1'}]; + $changeManagementService.getWorkflows = () => getWorkflowsStub; + $changeManagementService.getLocalWorkflowParameter = () => getLocalWorkflowsParametersStub; + $changeManagementService.getSOWorkflows = () => getSOWorkflowsPromiseStub; + $changeManagementService.getSOWorkflowParameter = () => getSOWorkflowsParametersPromiseStub; + + let result = [{ + "acceptableFileType": null, + "id": 1, + "msgOnContentError": null, + "msgOnPatternError": null, + "name": "Configuration Parameters", + "pattern": ".*", + "required": true, + "type": "STRING", + }]; + // when + return $controller.loadWorkFlows() + .then(() => { + let internalWorkFlowParameters = $controller.getInternalWorkFlowParameters("VNF Scale Out", "STRING"); + expect(internalWorkFlowParameters).toEqual(result); + }); + }); +}); diff --git a/vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.html b/vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.html index 2cf879001..9fb978c42 100644 --- a/vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.html +++ b/vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.html @@ -78,38 +78,26 @@ <option value="" disabled>Select workflow</option> </select> </div> - <div class="form-group" ng-if="vm.isScaleOut()"> - <label class="control-label">Configuration Parameters</label> - <input type="text" name="configurationParameters" ng-model="vm.changeManagement.configurationParameters" id="configuration-parameters" required> - </div> - <div class="form-group" ng-if="vm.isConfigUpdate()"> - <label class="control-label">Attach configuration file</label> + + <div class="form-group" ng-if="vm.changeManagement.workflow" ng-repeat="item in vm.getInternalWorkFlowParameters(vm.changeManagement.workflow, 'FILE')"> + <label class="control-label">{{item.name}}</label> <div class="file-wrapper"> - <input id="config-update-input" class="file-input" type="file" ngf-select ng-model="vm.configUpdateFile" ngf-validate-async-fn="vm.uploadConfigFile($file)" name="configUpdateFile" - accept=".csv" ngf-pattern=".csv" required> </input> - <label id="config-update-label" class="file-input-label">{{vm.configUpdateFile&&vm.configUpdateFile.name||"Select File"}} </label> - <label for="config-update-input"><span class="icon-browse"></span></label> + <input id="internal-workflow-parameter-file-{{item.id}}" class="file-input" type="file" ngf-select ng-model="item.value" ngf-validate-async-fn="vm.uploadConfigFile($file)" name="configUpdateFile" accept="{{item.acceptableFileType}}" ngf-pattern="{{item.acceptableFileType}}" ng-required="{{item.required}}"/> + <label id="internal-workflow-parameter-file-{{item.id}}-label" class="file-input-label">{{item.value&&item.value.name||"Select File"}} </label> + <label for="internal-workflow-parameter-file-{{item.id}}"><span class="icon-browse"></span></label> </div> - <label id="errorLabel" class="icon-alert error" ng-if="newChangeManagement.configUpdateFile.$error.pattern">{{vm.configUpdatePatternError}}</label> - <label id="errorContentLabel" class="icon-alert error" ng-if="newChangeManagement.configUpdateFile.$error.validateAsyncFn">{{vm.configUpdateContentError}}</label> + <label id="errorLabel" class="icon-alert error" ng-if="item.value.$error.pattern">{{item.msgOnPatternError}}</label> + <label id="errorContentLabel" class="icon-alert error" ng-if="item.value.$error.validateAsyncFn">{{item.msgOnContentError}}</label> </div> - <div ng-if="vm.shouldShowVnfInPlaceFields()"> - <div class="form-group"> - <label class="control-label">Operations timeout</label> - <input class="form-control" ng-model="vm.changeManagement.operationTimeout" name="operationTimeout" type="text" id="operations-timeout" pattern="[0-9]+" required> - </div> - <div class="form-group"> - <label class="control-label">Existing software version</label> - <input class="form-control" ng-model="vm.changeManagement.existingSoftwareVersion" name="existingSoftwareVersion" type="text" id="existing-software-version" pattern="{{vm.softwareVersionRegex}}" required> - </div> - <div class="form-group"> - <label class="control-label">New software version</label> - <input class="form-control" ng-model="vm.changeManagement.newSoftwareVersion" name="newSoftwareVersion" type="text" id="new-software-version" pattern="{{vm.softwareVersionRegex}}" required> - </div> + + <div class="form-group" ng-if="vm.changeManagement.workflow" ng-repeat="item in vm.getInternalWorkFlowParameters(vm.changeManagement.workflow, 'STRING')"> + <label for="internal-workflow-parameter-text-{{item.id}}" class="control-label">{{item.name}}</label> + <input ng-model="item.value" type="text" id="internal-workflow-parameter-text-{{item.id}}" pattern="{{item.pattern}}" ng-required="{{item.required}}"> </div> + <div class="form-group" ng-if="vm.changeManagement.workflow" ng-repeat="item in vm.getRemoteWorkFlowParameters(vm.changeManagement.workflow)"> <label for="so-workflow-parameter-{{item.id}}" class="control-label">{{item.name}}</label> - <input class="form-control" ng-model="item.value" type="text" id="so-workflow-parameter-{{item.id}}" pattern="{{item.pattern}}" ng-required="{{item.required}}"> + <input ng-model="item.value" type="text" id="so-workflow-parameter-{{item.id}}" pattern="{{item.pattern}}" ng-required="{{item.required}}"> </div> </div> diff --git a/vid-app-common/src/main/webapp/app/vid/scripts/services/change-management.service.js b/vid-app-common/src/main/webapp/app/vid/scripts/services/change-management.service.js index 5820ae212..45aedd1a1 100644 --- a/vid-app-common/src/main/webapp/app/vid/scripts/services/change-management.service.js +++ b/vid-app-common/src/main/webapp/app/vid/scripts/services/change-management.service.js @@ -36,7 +36,7 @@ .success(function (response) { return {data: response}; }) - .catch(function (err) { + .catch(function () { return {data: []}; }); }; @@ -57,6 +57,13 @@ }); }; + this.getLocalWorkflowParameter = function (workflowName){ + return $http.get(COMPONENT.GET_LOCAL_WORKFLOW_PARAMETER.replace('@workflowName', encodeURIComponent(workflowName))) + .success(function (response) { + return {data: response.parameterDefinitions} + }); + }; + this.getMSOChangeManagements = function() { var deferred = $q.defer(); diff --git a/vid-app-common/src/test/java/org/onap/vid/services/ExtWorkflowServiceImplTest.java b/vid-app-common/src/test/java/org/onap/vid/services/ExternalWorkflowServiceImplTest.java index d8d8552ec..160ba97a5 100644 --- a/vid-app-common/src/test/java/org/onap/vid/services/ExtWorkflowServiceImplTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/services/ExternalWorkflowServiceImplTest.java @@ -38,13 +38,11 @@ import org.onap.vid.model.SOWorkflowType; import org.onap.vid.model.SOWorkflows; import org.onap.vid.mso.MsoResponseWrapper2; import org.onap.vid.mso.rest.MockedWorkflowsRestClient; -import org.onap.vid.services.ExtWorkflowsServiceImpl.BadResponseFromMso; +import org.onap.vid.services.ExternalWorkflowsServiceImpl.BadResponseFromMso; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; - - -public class ExtWorkflowServiceImplTest { +public class ExternalWorkflowServiceImplTest { @Mock private MockedWorkflowsRestClient client; @@ -63,7 +61,7 @@ public class ExtWorkflowServiceImplTest { @Test public void shouldReturnWorkflowsOnValidResponse(){ // given - ExtWorkflowsService extWorkflowsService = new ExtWorkflowsServiceImpl(client); + ExternalWorkflowsService extWorkflowsService = new ExternalWorkflowsServiceImpl(client); Mockito.when(response.getStatus()).thenReturn(200); Mockito.when(response.getBody()).thenReturn(new SOWorkflows(Collections.singletonList(new SOWorkflow(1L, "xyz")))); MsoResponseWrapper2<SOWorkflows> msoResponseStub = new MsoResponseWrapper2<>(response); @@ -78,7 +76,7 @@ public class ExtWorkflowServiceImplTest { @Test(expectedExceptions = BadResponseFromMso.class) public void shouldThrowBadResponseOnInvalidResponse(){ // given - ExtWorkflowsService extWorkflowsService = new ExtWorkflowsServiceImpl(client); + ExternalWorkflowsService extWorkflowsService = new ExternalWorkflowsServiceImpl(client); Mockito.when(response.getStatus()).thenReturn(500); Mockito.when(response.getBody()).thenReturn(new SOWorkflows(Collections.singletonList(new SOWorkflow(1L, "xyz")))); MsoResponseWrapper2<SOWorkflows> msoResponseStub = new MsoResponseWrapper2<>(response); @@ -90,7 +88,7 @@ public class ExtWorkflowServiceImplTest { @Test public void shouldReturnWorkflowParametersOnValidResponse() { SOWorkflowParameterDefinitions parameters = new SOWorkflowParameterDefinitions(Collections.singletonList(new SOWorkflowParameterDefinition(1L, "sample", "[0-9]", SOWorkflowType.STRING, true))); - ExtWorkflowsService extWorkflowsService = new ExtWorkflowsServiceImpl(client); + ExternalWorkflowsService extWorkflowsService = new ExternalWorkflowsServiceImpl(client); Mockito.when(parameterDefinitionsHttpResponse.getStatus()).thenReturn(200); Mockito.when(parameterDefinitionsHttpResponse.getBody()).thenReturn(parameters); MsoResponseWrapper2<SOWorkflowParameterDefinitions> msoResponseWrapper = new MsoResponseWrapper2<>(parameterDefinitionsHttpResponse); @@ -104,7 +102,7 @@ public class ExtWorkflowServiceImplTest { @Test public void shouldProperlyHandleEmptyParametersList(){ - ExtWorkflowsService extWorkflowsService = new ExtWorkflowsServiceImpl(client); + ExternalWorkflowsService extWorkflowsService = new ExternalWorkflowsServiceImpl(client); Mockito.when(parameterDefinitionsHttpResponse.getStatus()).thenReturn(200); Mockito.when(parameterDefinitionsHttpResponse.getBody()).thenReturn(new SOWorkflowParameterDefinitions(Lists.newArrayList())); |