summaryrefslogtreecommitdiffstats
path: root/appc-config/appc-flow-controller/provider/src
diff options
context:
space:
mode:
Diffstat (limited to 'appc-config/appc-flow-controller/provider/src')
-rw-r--r--appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/FlowControlNode.java52
-rw-r--r--appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/FlowControlNodeTest.java29
2 files changed, 58 insertions, 23 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 16e869040..28130e777 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
@@ -66,7 +66,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import java.io.IOException;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -150,11 +149,21 @@ public class FlowControlNode implements SvcLogicJavaPlugin {
String fn = "FlowExecutorNode.processflowSequence";
log.debug(fn + "Received model for flow : " + localContext.toString());
-
+
+ localContext
+ .getAttributeKeySet()
+ .forEach(key -> log.debug(key + "=" + ctx.getAttribute(key)));
+
+ String flowSequence = getFlowSequence(inParams, ctx, localContext);
+
+ log.debug("Received Flow Sequence : " + flowSequence);
+ HashMap<Integer, Transaction> transactionMap = createTransactionMap(flowSequence, localContext);
+ executeAllTransaction(transactionMap, ctx);
+ log.info("Executed all the transaction successfully");
+ }
+
+ String getFlowSequence(Map<String, String> inParams, SvcLogicContext ctx, SvcLogicContext localContext) throws Exception {
String flowSequence = null;
- for (String key : localContext.getAttributeKeySet()) {
- log.debug(key + "=" + ctx.getAttribute(key));
- }
if (localContext.getAttribute(SEQUENCE_TYPE) != null) {
if (localContext.getAttribute(GENERATION_NODE) != null) {
GraphExecutor transactionExecutor = new GraphExecutor();
@@ -225,11 +234,7 @@ public class FlowControlNode implements SvcLogicJavaPlugin {
flowSequence = mapper.writeValueAsString(trans);
log.debug("Single step Flow Sequence : " + flowSequence);
}
-
- log.debug("Received Flow Sequence : " + flowSequence);
- HashMap<Integer, Transaction> transactionMap = createTransactionMap(flowSequence, localContext);
- executeAllTransaction(transactionMap, ctx);
- log.info("Executed all the transaction successfully");
+ return flowSequence;
}
private void executeAllTransaction(HashMap<Integer, Transaction> transactionMap, SvcLogicContext ctx)
@@ -448,28 +453,29 @@ public class FlowControlNode implements SvcLogicJavaPlugin {
return inputData;
}
- private DependencyInfo getDependencyInfo(SvcLogicContext ctx) throws Exception {
+ DependencyInfo getDependencyInfo(SvcLogicContext ctx) throws SvcLogicException, IOException {
String fn = "FlowExecutorNode.getDependencyInfo";
- DependencyInfo dependencyInfo = new DependencyInfo();
String dependencyData = dbService.getDependencyInfo(ctx);
log.info(fn + "dependencyDataInput:" + dependencyData);
- if (dependencyData != null) {
- ObjectMapper mapper = new ObjectMapper();
- mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
- mapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
- //JsonNode dependencyInfoData = mapper.readTree(dependencyData).get("dependencyInfo");
- JsonNode vnfcData = mapper.readTree(dependencyData).get("vnfcs");
- List<Vnfcs> vnfclist = Arrays.asList(mapper.readValue(vnfcData.toString(), Vnfcs[].class));
- dependencyInfo.getVnfcs().addAll(vnfclist);
-
- log.info("Dependency Output:" + dependencyInfo.toString());
+ DependencyInfo dependencyInfo = new DependencyInfo();
+ if (dependencyData == null) {
+ return dependencyInfo;
}
+
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+ mapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
+ //JsonNode dependencyInfoData = mapper.readTree(dependencyData).get("dependencyInfo");
+ JsonNode vnfcData = mapper.readTree(dependencyData).get("vnfcs");
+ dependencyInfo.getVnfcs().addAll(mapper.readValue(vnfcData.toString(), new TypeReference<List<Vnfcs>>(){}));
+
+ log.info("Dependency Output:" + dependencyInfo.toString());
return dependencyInfo;
}
- Capabilities getCapabilitiesData(SvcLogicContext ctx) throws Exception {
+ Capabilities getCapabilitiesData(SvcLogicContext ctx) throws SvcLogicException, IOException {
String fn = "FlowExecutorNode.getCapabilitiesData";
String capabilitiesData = dbService.getCapabilitiesData(ctx);
diff --git a/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/FlowControlNodeTest.java b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/FlowControlNodeTest.java
index 200a02615..d171f5f8b 100644
--- a/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/FlowControlNodeTest.java
+++ b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/FlowControlNodeTest.java
@@ -27,11 +27,18 @@ package org.onap.appc.flow.controller.node;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.onap.appc.flow.controller.dbervices.FlowControlDBService;
import org.onap.appc.flow.controller.interfaceData.Capabilities;
+import org.onap.appc.flow.controller.interfaceData.DependencyInfo;
+import org.onap.appc.flow.controller.interfaceData.Vnfcs;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
public class FlowControlNodeTest {
@@ -70,4 +77,26 @@ public class FlowControlNodeTest {
Assert.assertEquals("Capabilities [vnf=[vnf-1, vnf-2], vfModule=[vf-module-1], vm=[], vnfc=[]]", capabilitiesData.toString());
}
+ @Test
+ public void should_handle_dependency_config() throws Exception {
+
+ Vnfcs vnfcs = new Vnfcs();
+ vnfcs.setVnfcType("some-type");
+ vnfcs.setResilience("some-resilence");
+ vnfcs.setMandatory("some-mandatory");
+ Map<String, List<Vnfcs>> input = new HashMap<>();
+ List<Vnfcs> list = new ArrayList<>();
+ list.add(vnfcs);
+ list.add(vnfcs);
+ input.put("vnfcs", list);
+
+ String jsonPayload = new ObjectMapper().writeValueAsString(input);
+
+ when(dbService.getDependencyInfo(ctx)).thenReturn(jsonPayload);
+
+ FlowControlNode flowControlNode = new FlowControlNode(null, dbService);
+ DependencyInfo dependencyInfo = flowControlNode.getDependencyInfo(ctx);
+
+ Assert.assertEquals("DependencyInfo [vnfcs=[Vnfcs [vnfcType=some-type, mandatory=some-mandatory, resilience=some-resilence, parents=[]], Vnfcs [vnfcType=some-type, mandatory=some-mandatory, resilience=some-resilence, parents=[]]]]", dependencyInfo.toString());
+ }
}