diff options
4 files changed, 257 insertions, 74 deletions
diff --git a/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/FlowControlNode.java b/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/FlowControlNode.java index b2f4039c6..35a99a9ea 100644 --- a/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/FlowControlNode.java +++ b/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/FlowControlNode.java @@ -63,9 +63,7 @@ import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; -import java.io.FileInputStream; import java.io.IOException; -import java.io.InputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -89,10 +87,7 @@ import org.onap.appc.flow.controller.interfaceData.DependencyInfo; import org.onap.appc.flow.controller.interfaceData.Input; import org.onap.appc.flow.controller.interfaceData.InventoryInfo; import org.onap.appc.flow.controller.interfaceData.RequestInfo; -import org.onap.appc.flow.controller.interfaceData.Vm; -import org.onap.appc.flow.controller.interfaceData.VnfInfo; import org.onap.appc.flow.controller.interfaceData.Vnfcs; -import org.onap.appc.flow.controller.interfaceData.Vnfcslist; import org.onap.appc.flow.controller.interfaces.FlowExecutorInterface; import org.onap.appc.flow.controller.utils.EncryptionTool; import org.onap.ccsdk.sli.core.sli.SvcLogicContext; @@ -104,6 +99,19 @@ public class FlowControlNode implements SvcLogicJavaPlugin { private static final EELFLogger log = EELFManager.getInstance().getLogger(FlowControlNode.class); private static final String SDNC_CONFIG_DIR_VAR = "SDNC_CONFIG_DIR"; + private final EnvVariables envVariables; + private final FlowControlDBService dbService; + + public FlowControlNode() { + this.envVariables = new EnvVariables(); + this.dbService = FlowControlDBService.initialise(); + } + + FlowControlNode(EnvVariables envVariables, FlowControlDBService dbService) { + this.envVariables = envVariables; + this.dbService = dbService; + } + public void processFlow(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException { log.debug("Received processParamKeys call with params : " + inParams); @@ -119,7 +127,6 @@ public class FlowControlNode implements SvcLogicJavaPlugin { localContext.setAttribute(RESPONSE_PREFIX, responsePrefix); ctx.setAttribute(RESPONSE_PREFIX, responsePrefix); - FlowControlDBService dbService = FlowControlDBService.initialise(); dbService.getFlowReferenceData(ctx, inParams, localContext); for (String key : localContext.getAttributeKeySet()) { @@ -142,7 +149,7 @@ public class FlowControlNode implements SvcLogicJavaPlugin { String fn = "FlowExecutorNode.processflowSequence"; log.debug(fn + "Received model for flow : " + localContext.toString()); - FlowControlDBService dbService = FlowControlDBService.initialise(); + String flowSequence = null; for (String key : localContext.getAttributeKeySet()) { log.debug(key + "=" + ctx.getAttribute(key)); @@ -352,7 +359,6 @@ public class FlowControlNode implements SvcLogicJavaPlugin { private void compileFlowDependencies(Transaction transaction, SvcLogicContext localContext) throws Exception { - FlowControlDBService dbService = FlowControlDBService.initialise(); dbService.populateModuleAndRPC(transaction, localContext.getAttribute(VNF_TYPE)); ObjectMapper mapper = new ObjectMapper(); log.debug("Individual Transaction Details :" + transaction.toString()); @@ -404,7 +410,7 @@ public class FlowControlNode implements SvcLogicJavaPlugin { requestInfo.setActionIdentifier(actionIdentifier); log.debug("RequestInfo: " + requestInfo.toString()); - InventoryInfo inventoryInfo = getInventoryInfo(ctx, vnfId); + InventoryInfo inventoryInfo = new InventoryInfoExtractor().getInventoryInfo(ctx, vnfId); DependencyInfo dependencyInfo = getDependencyInfo(ctx); Capabilities capabilities = getCapabilitiesData(ctx); @@ -445,7 +451,6 @@ public class FlowControlNode implements SvcLogicJavaPlugin { String fn = "FlowExecutorNode.getDependencyInfo"; DependencyInfo dependencyInfo = new DependencyInfo(); - FlowControlDBService dbService = FlowControlDBService.initialise(); String dependencyData = dbService.getDependencyInfo(ctx); log.info(fn + "dependencyDataInput:" + dependencyData); @@ -467,7 +472,6 @@ public class FlowControlNode implements SvcLogicJavaPlugin { String fn = "FlowExecutorNode.getCapabilitiesData"; Capabilities capabilities = new Capabilities(); - FlowControlDBService dbService = FlowControlDBService.initialise(); String capabilitiesData = dbService.getCapabilitiesData(ctx); log.info(fn + "capabilitiesDataInput:" + capabilitiesData); @@ -524,54 +528,12 @@ public class FlowControlNode implements SvcLogicJavaPlugin { return capabilities; } - private InventoryInfo getInventoryInfo(SvcLogicContext ctx, String vnfId) throws Exception { - String fn = "FlowExecutorNode.getInventoryInfo"; - - VnfInfo vnfInfo = new VnfInfo(); - vnfInfo.setVnfId(vnfId); - vnfInfo.setVnfName(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-name")); - vnfInfo.setVnfType(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-type")); - - String vmcount = ctx.getAttribute("tmp.vnfInfo.vm-count"); - if (StringUtils.isNotBlank(vmcount)) { - int vmCount = Integer.parseInt(vmcount); - log.info(fn + "vmcount:" + vmCount); - - Vm vm = new Vm(); - Vnfcslist vnfc = new Vnfcslist(); - for (int i = 0; i < vmCount; i++) { - vm.setVserverId(ctx.getAttribute("tmp.vnfInfo.vm[" + i + "].vserver-id")); - String vnfccount = ctx.getAttribute("tmp.vnfInfo.vm[" + i + "].vnfc-count"); - int vnfcCount = Integer.parseInt(vnfccount); - if (vnfcCount > 0) { - vnfc.setVnfcName(ctx.getAttribute("tmp.vnfInfo.vm[" + i + "].vnfc-name")); - vnfc.setVnfcType(ctx.getAttribute("tmp.vnfInfo.vm[" + i + "].vnfc-type")); - vm.setVnfc(vnfc); - } - vnfInfo.getVm().add(vm); - } - } - InventoryInfo inventoryInfo = new InventoryInfo(); - inventoryInfo.setVnfInfo(vnfInfo); - log.info(fn + "Inventory Output:" + inventoryInfo.toString()); - - return inventoryInfo; - } - - private static Properties loadProperties() throws Exception { - Properties props = new Properties(); - String propDir = System.getenv(SDNC_CONFIG_DIR_VAR); - if (propDir == null) { + private Properties loadProperties() throws Exception { + String directory = envVariables.getenv(SDNC_CONFIG_DIR_VAR); + if (directory == null) { throw new Exception("Cannot find Property file -" + SDNC_CONFIG_DIR_VAR); } - String propFile = propDir + APPC_FLOW_CONTROLLER; - try (InputStream propStream = new FileInputStream(propFile)) { - - props.load(propStream); - - } catch (Exception e) { - throw new Exception("Could not load properties file " + propFile, e); - } - return props; + String path = directory + APPC_FLOW_CONTROLLER; + return PropertiesLoader.load(path); } } diff --git a/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/InventoryInfoExtractor.java b/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/InventoryInfoExtractor.java new file mode 100644 index 000000000..79a8635ab --- /dev/null +++ b/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/InventoryInfoExtractor.java @@ -0,0 +1,75 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2018 Nokia. 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.appc.flow.controller.node; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.apache.commons.lang3.StringUtils; +import org.onap.appc.flow.controller.interfaceData.InventoryInfo; +import org.onap.appc.flow.controller.interfaceData.Vm; +import org.onap.appc.flow.controller.interfaceData.VnfInfo; +import org.onap.appc.flow.controller.interfaceData.Vnfcslist; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; + +/** + * Helper class for FlowControlNode + */ +class InventoryInfoExtractor { + + private static final EELFLogger log = EELFManager.getInstance().getLogger(InventoryInfoExtractor.class); + + InventoryInfo getInventoryInfo(SvcLogicContext ctx, String vnfId) { + String fn = "InventoryInfoExtractor.getInventoryInfo"; + + VnfInfo vnfInfo = new VnfInfo(); + vnfInfo.setVnfId(vnfId); + vnfInfo.setVnfName(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-name")); + vnfInfo.setVnfType(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-type")); + + String vmcount = ctx.getAttribute("tmp.vnfInfo.vm-count"); + log.info(fn + "vmcount:" + vmcount); + + int vmCount = (StringUtils.isNotBlank(vmcount)) ? Integer.parseInt(vmcount) : 0; + + for (int i = 0; i < vmCount; i++) { + processVm(ctx, vnfInfo, i); + } + + InventoryInfo inventoryInfo = new InventoryInfo(); + inventoryInfo.setVnfInfo(vnfInfo); + log.info(fn + "Inventory Output:" + inventoryInfo.toString()); + + return inventoryInfo; + } + + private void processVm(SvcLogicContext ctx, VnfInfo vnfInfo, int index) { + Vm vm = new Vm(); + vm.setVserverId(ctx.getAttribute("tmp.vnfInfo.vm[" + index + "].vserver-id")); + int vnfcCount = Integer.parseInt(ctx.getAttribute("tmp.vnfInfo.vm[" + index + "].vnfc-count")); + if (vnfcCount > 0) { + Vnfcslist vnfc = new Vnfcslist(); + vnfc.setVnfcName(ctx.getAttribute("tmp.vnfInfo.vm[" + index + "].vnfc-name")); + vnfc.setVnfcType(ctx.getAttribute("tmp.vnfInfo.vm[" + index + "].vnfc-type")); + vm.setVnfc(vnfc); + } + vnfInfo.getVm().add(vm); + } + +} diff --git a/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/InventoryInfoExtractorTest.java b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/InventoryInfoExtractorTest.java new file mode 100644 index 000000000..66484da1e --- /dev/null +++ b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/InventoryInfoExtractorTest.java @@ -0,0 +1,162 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2018 Nokia. 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.appc.flow.controller.node; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.onap.appc.flow.controller.interfaceData.InventoryInfo; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; + +public class InventoryInfoExtractorTest { + + private SvcLogicContext ctx; + private InventoryInfoExtractor inventoryInfoExtractor; + + @Before + public void setUp() { + inventoryInfoExtractor = new InventoryInfoExtractor(); + ctx = mock(SvcLogicContext.class); + } + + @Test + public void full_config() throws Exception { + when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-name")).thenReturn("some-vnf-name"); + when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-type")).thenReturn("some-vnf-type"); + when(ctx.getAttribute("tmp.vnfInfo.vm-count")).thenReturn("2"); + + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-id")).thenReturn("some-id-0"); + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-count")).thenReturn("2"); + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-name")).thenReturn("some-vnfc-name-0"); + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-type")).thenReturn("some-vnfc-type-0"); + + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vserver-id")).thenReturn("some-id-1"); + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-count")).thenReturn("1"); + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-name")).thenReturn("some-vnfc-name-1"); + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-type")).thenReturn("some-vnfc-type-1"); + + String vnfId = "some-vnf-id"; + InventoryInfo inventoryInfo = inventoryInfoExtractor.getInventoryInfo(ctx, vnfId); + + Assert.assertEquals( + "InventoryInfo [vnfInfo=VnfInfo [vnfId=some-vnf-id, vnfName=some-vnf-name, vnfType=some-vnf-type, vm=[Vm [vserverId=some-id-0, vnfc=Vnfcslist [vnfcType=some-vnfc-type-0, vnfcName=some-vnfc-name-0]], Vm [vserverId=some-id-1, vnfc=Vnfcslist [vnfcType=some-vnfc-type-1, vnfcName=some-vnfc-name-1]]]]]", + inventoryInfo.toString()); + } + + @Test + public void full_config__with_zero__vnfc_count() throws Exception { + when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-name")).thenReturn("some-vnf-name"); + when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-type")).thenReturn("some-vnf-type"); + when(ctx.getAttribute("tmp.vnfInfo.vm-count")).thenReturn("2"); + + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-id")).thenReturn("some-id-0"); + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-count")).thenReturn("2"); + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-name")).thenReturn("some-vnfc-name-0"); + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-type")).thenReturn("some-vnfc-type-0"); + + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vserver-id")).thenReturn("some-id-1"); + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-count")).thenReturn("0"); + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-name")).thenReturn("some-vnfc-name-1"); + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-type")).thenReturn("some-vnfc-type-1"); + + String vnfId = "some-vnf-id"; + InventoryInfo inventoryInfo = inventoryInfoExtractor.getInventoryInfo(ctx, vnfId); + + Assert.assertEquals( + "InventoryInfo [vnfInfo=VnfInfo [vnfId=some-vnf-id, vnfName=some-vnf-name, vnfType=some-vnf-type, vm=[Vm [vserverId=some-id-0, vnfc=Vnfcslist [vnfcType=some-vnfc-type-0, vnfcName=some-vnfc-name-0]], Vm [vserverId=some-id-1, vnfc=null]]]]", + inventoryInfo.toString()); + } + + @Test + public void full_config__with_zero__vm_count() throws Exception { + when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-name")).thenReturn("some-vnf-name"); + when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-type")).thenReturn("some-vnf-type"); + when(ctx.getAttribute("tmp.vnfInfo.vm-count")).thenReturn("0"); + + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-id")).thenReturn("some-id-0"); + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-count")).thenReturn("2"); + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-name")).thenReturn("some-vnfc-name-0"); + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-type")).thenReturn("some-vnfc-type-0"); + + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vserver-id")).thenReturn("some-id-1"); + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-count")).thenReturn("0"); + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-name")).thenReturn("some-vnfc-name-1"); + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-type")).thenReturn("some-vnfc-type-1"); + + String vnfId = "some-vnf-id"; + InventoryInfo inventoryInfo = inventoryInfoExtractor.getInventoryInfo(ctx, vnfId); + + Assert.assertEquals( + "InventoryInfo [vnfInfo=VnfInfo [vnfId=some-vnf-id, vnfName=some-vnf-name, vnfType=some-vnf-type, vm=null]]", + inventoryInfo.toString()); + } + + @Test + public void full_config__with_empty__vm_count() throws Exception { + when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-name")).thenReturn("some-vnf-name"); + when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-type")).thenReturn("some-vnf-type"); + when(ctx.getAttribute("tmp.vnfInfo.vm-count")).thenReturn(""); + + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-id")).thenReturn("some-id-0"); + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-count")).thenReturn("2"); + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-name")).thenReturn("some-vnfc-name-0"); + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-type")).thenReturn("some-vnfc-type-0"); + + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vserver-id")).thenReturn("some-id-1"); + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-count")).thenReturn("0"); + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-name")).thenReturn("some-vnfc-name-1"); + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-type")).thenReturn("some-vnfc-type-1"); + + String vnfId = "some-vnf-id"; + InventoryInfo inventoryInfo = inventoryInfoExtractor.getInventoryInfo(ctx, vnfId); + + Assert.assertEquals( + "InventoryInfo [vnfInfo=VnfInfo [vnfId=some-vnf-id, vnfName=some-vnf-name, vnfType=some-vnf-type, vm=null]]", + inventoryInfo.toString()); + } + + @Test + public void full_config__with_null__vm_count() throws Exception { + when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-name")).thenReturn("some-vnf-name"); + when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-type")).thenReturn("some-vnf-type"); + when(ctx.getAttribute("tmp.vnfInfo.vm-count")).thenReturn(null); + + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-id")).thenReturn("some-id-0"); + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-count")).thenReturn("2"); + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-name")).thenReturn("some-vnfc-name-0"); + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-type")).thenReturn("some-vnfc-type-0"); + + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vserver-id")).thenReturn("some-id-1"); + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-count")).thenReturn("0"); + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-name")).thenReturn("some-vnfc-name-1"); + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-type")).thenReturn("some-vnfc-type-1"); + + String vnfId = "some-vnf-id"; + InventoryInfo inventoryInfo = inventoryInfoExtractor.getInventoryInfo(ctx, vnfId); + + Assert.assertEquals( + "InventoryInfo [vnfInfo=VnfInfo [vnfId=some-vnf-id, vnfName=some-vnf-name, vnfType=some-vnf-type, vm=null]]", + inventoryInfo.toString()); + } + +}
\ No newline at end of file diff --git a/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/executor/node/FlowControlNodeTest.java b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/executor/node/FlowControlNodeTest.java index 32525c587..ba6f0c7ce 100644 --- a/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/executor/node/FlowControlNodeTest.java +++ b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/executor/node/FlowControlNodeTest.java @@ -91,22 +91,6 @@ public class FlowControlNodeTest { } - @Test - public void testgetInventoryInfo() throws Exception - { - SvcLogicContext ctx = new SvcLogicContext(); - String vnfid = "test"; - ctx.setAttribute( " tmp.vnfInfo.vnf.vnf-name","test"); - ctx.setAttribute("tmp.vnfInfo.vm-count", "0"); - ctx.setAttribute( " tmp.vnfInfo.vnf.vnf-type","test"); - ctx.setAttribute( "tmp.vnfInfo.vm[0 ].vserverId","test" ); - ctx.setAttribute( "tmp.vnfInfo.vm[0 ].vnfc-name","test" ); - ctx.setAttribute( "tmp.vnfInfo.vm[0].vnfc-type","test" ); - ctx.setAttribute( " tmp.vnfInfo.vm[0].vnfc-count","1"); - - Whitebox.invokeMethod(f, "getInventoryInfo", ctx, vnfid); - - } @Ignore("Test is taking 60 seconds") @Test(expected=Exception.class) public void testprocessFlowSequence() throws Exception |