aboutsummaryrefslogtreecommitdiffstats
path: root/appc-config/appc-flow-controller/provider/src/main
diff options
context:
space:
mode:
authorkurczews <krzysztof.kurczewski@nokia.com>2018-03-05 15:39:47 +0100
committerTakamune Cho <tc012c@att.com>2018-03-22 19:34:50 +0000
commit04d834a8258742f4c4acc4fb59224f255e953d75 (patch)
tree55d7aee54ed1665cd5f4bb0e370bb2a3c94c1cb6 /appc-config/appc-flow-controller/provider/src/main
parentbcc0324b5862a1d1bc46a4d5f8564431e8b3862e (diff)
Split sequence generation to classess
* Delegate original logic to separate clasess * Introduce InputParamsCollector * Introduce CapabilitiesDataExtractor * Add coverage for changes Change-Id: Ibb35dfb67306f789950c3b77362c5d79a3b6da63 Issue-ID: APPC-440 Signed-off-by: kurczews <krzysztof.kurczewski@nokia.com>
Diffstat (limited to 'appc-config/appc-flow-controller/provider/src/main')
-rw-r--r--appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/CapabilitiesDataExtractor.java95
-rw-r--r--appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/EnvVariables.java30
-rw-r--r--appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/FlowControlNode.java225
-rw-r--r--appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/FlowSequenceGenerator.java149
-rw-r--r--appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/InputParamsCollector.java193
-rw-r--r--appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/JsonValidator.java19
-rw-r--r--appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/PropertiesLoader.java19
-rw-r--r--appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/ResourceUriExtractor.java19
-rw-r--r--appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/TransactionHandler.java19
9 files changed, 540 insertions, 228 deletions
diff --git a/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/CapabilitiesDataExtractor.java b/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/CapabilitiesDataExtractor.java
new file mode 100644
index 000000000..b740e4feb
--- /dev/null
+++ b/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/CapabilitiesDataExtractor.java
@@ -0,0 +1,95 @@
+/*
+ * ============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.onap.appc.flow.controller.utils.FlowControllerConstants.VF_MODULE;
+import static org.onap.appc.flow.controller.utils.FlowControllerConstants.VM;
+import static org.onap.appc.flow.controller.utils.FlowControllerConstants.VNF;
+import static org.onap.appc.flow.controller.utils.FlowControllerConstants.VNFC;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import org.onap.appc.flow.controller.dbervices.FlowControlDBService;
+import org.onap.appc.flow.controller.interfaceData.Capabilities;
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+
+public class CapabilitiesDataExtractor {
+
+ private static final EELFLogger log = EELFManager.getInstance().getLogger(CapabilitiesDataExtractor.class);
+
+ private final FlowControlDBService dbService;
+ private final ObjectMapper mapper;
+
+ public CapabilitiesDataExtractor() {
+ this(FlowControlDBService.initialise());
+ }
+
+ /**
+ * Ctor for tests, prefer to use default one
+ */
+ public CapabilitiesDataExtractor(FlowControlDBService dbService) {
+ this.dbService = dbService;
+
+ mapper = new ObjectMapper();
+ mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+ mapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
+ }
+
+ Capabilities getCapabilitiesData(SvcLogicContext ctx) throws SvcLogicException, IOException {
+
+ String fn = "FlowExecutorNode.getCapabilitiesData";
+ String capabilitiesData = dbService.getCapabilitiesData(ctx);
+ log.info(fn + "capabilitiesDataInput:" + capabilitiesData);
+
+ Capabilities capabilities = new Capabilities();
+ if (capabilitiesData == null) {
+ return capabilities;
+ }
+
+ JsonNode capabilitiesNode = mapper.readTree(capabilitiesData);
+ log.info("capabilitiesNode:" + capabilitiesNode.toString());
+
+ capabilities.getVfModule().addAll(extractParameterList(capabilitiesNode, VF_MODULE));
+ capabilities.getVnfc().addAll(extractParameterList(capabilitiesNode, VNFC));
+ capabilities.getVnf().addAll(extractParameterList(capabilitiesNode, VNF));
+ capabilities.getVm().addAll(extractParameterList(capabilitiesNode, VM));
+
+ log.info("Capabilities Output:" + capabilities.toString());
+
+ return capabilities;
+ }
+
+ private <T> List<T> extractParameterList(JsonNode root, String parameter) throws IOException {
+ JsonNode parameterNode = root.get(parameter);
+ if (parameterNode == null) {
+ return new ArrayList<>();
+ }
+ return mapper.readValue(parameterNode.toString(), new TypeReference<List<T>>() {});
+ }
+
+} \ No newline at end of file
diff --git a/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/EnvVariables.java b/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/EnvVariables.java
index 6cc3b7550..bac1f6cb0 100644
--- a/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/EnvVariables.java
+++ b/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/EnvVariables.java
@@ -1,9 +1,30 @@
+/*
+ * ============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 java.util.function.Function;
/**
- * Wrapper for accessing environment variables
+ * Wrapper which allows to mock static calls of System.getenv()
+ *
+ * @see System#getenv()
*/
class EnvVariables {
@@ -13,13 +34,6 @@ class EnvVariables {
envSupplier = System::getenv;
}
- /**
- * Allows to override environment variables in tests, prefer to use default constructor
- */
- EnvVariables(Function<String, String> envSupplier) {
- this.envSupplier = envSupplier;
- }
-
String getenv(String variable) {
return envSupplier.apply(variable);
}
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 28130e777..fd883601f 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
@@ -97,19 +97,18 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
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;
+ private final FlowSequenceGenerator flowSequenceGenerator;
public FlowControlNode() {
- this.envVariables = new EnvVariables();
this.dbService = FlowControlDBService.initialise();
+ this.flowSequenceGenerator = new FlowSequenceGenerator();
}
- FlowControlNode(EnvVariables envVariables, FlowControlDBService dbService) {
- this.envVariables = envVariables;
+ FlowControlNode(FlowControlDBService dbService, FlowSequenceGenerator flowSequenceGenerator) {
this.dbService = dbService;
+ this.flowSequenceGenerator = flowSequenceGenerator;
}
public void processFlow(Map<String, String> inParams, SvcLogicContext ctx)
@@ -154,7 +153,7 @@ public class FlowControlNode implements SvcLogicJavaPlugin {
.getAttributeKeySet()
.forEach(key -> log.debug(key + "=" + ctx.getAttribute(key)));
- String flowSequence = getFlowSequence(inParams, ctx, localContext);
+ String flowSequence = flowSequenceGenerator.getFlowSequence(inParams, ctx, localContext);
log.debug("Received Flow Sequence : " + flowSequence);
HashMap<Integer, Transaction> transactionMap = createTransactionMap(flowSequence, localContext);
@@ -162,81 +161,6 @@ public class FlowControlNode implements SvcLogicJavaPlugin {
log.info("Executed all the transaction successfully");
}
- String getFlowSequence(Map<String, String> inParams, SvcLogicContext ctx, SvcLogicContext localContext) throws Exception {
- String flowSequence = null;
- if (localContext.getAttribute(SEQUENCE_TYPE) != null) {
- if (localContext.getAttribute(GENERATION_NODE) != null) {
- GraphExecutor transactionExecutor = new GraphExecutor();
- Boolean generatorExists = transactionExecutor.hasGraph(
- "APPC_COMMOM",
- localContext.getAttribute(GENERATION_NODE),
- null,
- "sync"
- );
-
- if (generatorExists) {
- flowSequence = transactionExecutor.executeGraph(
- "APPC_COMMOM",
- localContext.getAttribute(GENERATION_NODE),
- null, "sync", null)
- .getProperty(FLOW_SEQUENCE);
- } else {
- throw new Exception("Can not find Custom defined Flow Generator for "
- + localContext.getAttribute(GENERATION_NODE));
- }
-
- } else if ((localContext.getAttribute(SEQUENCE_TYPE)).equalsIgnoreCase(DESINGTIME)) {
-
- localContext.setAttribute(VNFC_TYPE, ctx.getAttribute(VNFC_TYPE));
- flowSequence = dbService.getDesignTimeFlowModel(localContext);
-
- if (flowSequence == null) {
- throw new Exception("Flow Sequence is not found User Designed VNF " + ctx.getAttribute(VNF_TYPE));
- }
-
- } else if ((localContext.getAttribute(SEQUENCE_TYPE)).equalsIgnoreCase(RUNTIME)) {
-
- Transaction transaction = new Transaction();
- String input = collectInputParams(ctx, transaction);
- log.info("CollectInputParamsData-Input: " + input);
-
- RestExecutor restExe = new RestExecutor();
- Map<String, String> flowSeq = restExe.execute(transaction, localContext);
-
- JSONObject sequence = new JSONObject(flowSeq.get("restResponse"));
- if (sequence.has("output")) {
- flowSequence = sequence.getJSONObject("output").toString();
- }
- log.info("MultistepSequenceGenerator-Output: " + flowSequence);
-
- if (flowSequence == null) {
- throw new Exception("Failed to get the Flow Sequece runtime for VNF type"
- + ctx.getAttribute(VNF_TYPE));
- }
-
- } else if ((localContext.getAttribute(SEQUENCE_TYPE)).equalsIgnoreCase(EXTERNAL)) {
- //String input = collectInputParams(localContext);
- // flowSequnce = ""; //get it from the External interface calling the Rest End point - TBD
- //if(flowSequnce == null)
-
- throw new Exception("Flow Sequence not found for " + ctx.getAttribute(VNF_TYPE));
-
- } else {
- //No other type of model supported...
- //in Future can get flowModel from other generators which will be included here
- throw new Exception("No information found for sequence Owner Design-Time Vs Run-Time");
- }
-
- } else {
- FlowGenerator flowGenerator = new FlowGenerator();
- Transactions trans = flowGenerator.createSingleStepModel(inParams, ctx);
- ObjectMapper mapper = new ObjectMapper();
- flowSequence = mapper.writeValueAsString(trans);
- log.debug("Single step Flow Sequence : " + flowSequence);
- }
- return flowSequence;
- }
-
private void executeAllTransaction(HashMap<Integer, Transaction> transactionMap, SvcLogicContext ctx)
throws Exception {
@@ -380,143 +304,4 @@ public class FlowControlNode implements SvcLogicJavaPlugin {
//get a field in transction class as transactionhandle interface and register the Handler here for each trnactions
}
- private String collectInputParams(SvcLogicContext ctx, Transaction transaction) throws Exception {
-
- String fn = "FlowExecuteNode.collectInputParams";
- Properties prop = loadProperties();
- log.info("Loaded Properties " + prop.toString());
-
- String vnfId = ctx.getAttribute(VNF_ID);
- String inputData = null;
- log.debug(fn + "vnfId :" + vnfId);
-
- if (StringUtils.isBlank(vnfId)) {
- throw new Exception("VnfId is missing");
- }
-
- try {
- ActionIdentifier actionIdentifier = new ActionIdentifier();
- log.debug("Enter ActionIdentifier");
- if (StringUtils.isNotBlank(vnfId)) {
- actionIdentifier.setVnfId(vnfId);
- }
- if (StringUtils.isNotBlank(ctx.getAttribute(VSERVER_ID))) {
- actionIdentifier.setVserverId(ctx.getAttribute(VSERVER_ID));
- }
- if (StringUtils.isNotBlank(ctx.getAttribute(VNFC_NAME))) {
- actionIdentifier.setVnfcName(ctx.getAttribute(VNFC_NAME));
- }
- log.info("ActionIdentifierData" + actionIdentifier.toString());
-
- RequestInfo requestInfo = new RequestInfo();
- log.info("Enter RequestInfo");
- requestInfo.setAction(ctx.getAttribute(REQUEST_ACTION));
- requestInfo.setActionLevel(ctx.getAttribute(ACTION_LEVEL));
- requestInfo.setPayload(ctx.getAttribute(PAYLOAD));
- requestInfo.setActionIdentifier(actionIdentifier);
- log.debug("RequestInfo: " + requestInfo.toString());
-
- InventoryInfo inventoryInfo = new InventoryInfoExtractor().getInventoryInfo(ctx, vnfId);
- DependencyInfo dependencyInfo = getDependencyInfo(ctx);
- Capabilities capabilities = getCapabilitiesData(ctx);
-
- Input input = new Input();
- log.info("Enter InputData");
- input.setRequestInfo(requestInfo);
- input.setInventoryInfo(inventoryInfo);
- input.setDependencyInfo(dependencyInfo);
- input.setCapabilities(capabilities);
- log.info(fn + "Input parameters:" + input.toString());
-
- ObjectMapper mapper = new ObjectMapper();
- mapper.setSerializationInclusion(Include.NON_NULL);
- mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, true);
- inputData = mapper.writeValueAsString(input);
- log.info("InputDataJson:" + inputData);
-
- } catch (Exception e) {
- log.error("Error occurred in " + fn, e);
- }
-
- String resourceUri = prop.getProperty(SEQ_GENERATOR_URL);
- log.info(fn + "resourceUri= " + resourceUri);
-
- EncryptionTool et = EncryptionTool.getInstance();
- String pass = et.decrypt(prop.getProperty(SEQ_GENERATOR_PWD));
-
- transaction.setPayload(inputData);
- transaction.setExecutionRPC("POST");
- transaction.setuId(prop.getProperty(SEQ_GENERATOR_UID));
- transaction.setPswd(pass);
- transaction.setExecutionEndPoint(resourceUri);
-
- return inputData;
- }
-
- DependencyInfo getDependencyInfo(SvcLogicContext ctx) throws SvcLogicException, IOException {
-
- String fn = "FlowExecutorNode.getDependencyInfo";
- String dependencyData = dbService.getDependencyInfo(ctx);
- log.info(fn + "dependencyDataInput:" + dependencyData);
-
- 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 SvcLogicException, IOException {
-
- String fn = "FlowExecutorNode.getCapabilitiesData";
- String capabilitiesData = dbService.getCapabilitiesData(ctx);
- log.info(fn + "capabilitiesDataInput:" + capabilitiesData);
-
- Capabilities capabilities = new Capabilities();
- if (capabilitiesData == null) {
- return capabilities;
- }
-
- ObjectMapper mapper = new ObjectMapper();
- mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
- mapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
-
- JsonNode capabilitiesNode = mapper.readTree(capabilitiesData);
- log.info("capabilitiesNode:" + capabilitiesNode.toString());
-
- capabilities.getVfModule().addAll(extractParameterList(mapper, capabilitiesNode, VF_MODULE));
- capabilities.getVnfc().addAll(extractParameterList(mapper, capabilitiesNode, VNFC));
- capabilities.getVnf().addAll(extractParameterList(mapper, capabilitiesNode, VNF));
- capabilities.getVm().addAll(extractParameterList(mapper, capabilitiesNode, VM));
-
- log.info("Capabilities Output:" + capabilities.toString());
-
- return capabilities;
- }
-
- private <T> List<T> extractParameterList(ObjectMapper mapper, JsonNode root, String parameter) throws IOException {
- JsonNode parameterNode = root.get(parameter);
- if (parameterNode == null) {
- return new ArrayList<>();
- }
- return mapper.readValue(parameterNode.toString(), new TypeReference<List<T>>() {});
- }
-
- 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 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/FlowSequenceGenerator.java b/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/FlowSequenceGenerator.java
new file mode 100644
index 000000000..db5791305
--- /dev/null
+++ b/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/FlowSequenceGenerator.java
@@ -0,0 +1,149 @@
+/*
+ * ============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.onap.appc.flow.controller.utils.FlowControllerConstants.DESINGTIME;
+import static org.onap.appc.flow.controller.utils.FlowControllerConstants.EXTERNAL;
+import static org.onap.appc.flow.controller.utils.FlowControllerConstants.FLOW_SEQUENCE;
+import static org.onap.appc.flow.controller.utils.FlowControllerConstants.GENERATION_NODE;
+import static org.onap.appc.flow.controller.utils.FlowControllerConstants.RUNTIME;
+import static org.onap.appc.flow.controller.utils.FlowControllerConstants.SEQUENCE_TYPE;
+import static org.onap.appc.flow.controller.utils.FlowControllerConstants.VNFC_TYPE;
+import static org.onap.appc.flow.controller.utils.FlowControllerConstants.VNF_TYPE;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import java.util.Map;
+import org.json.JSONObject;
+import org.onap.appc.flow.controller.data.Transaction;
+import org.onap.appc.flow.controller.data.Transactions;
+import org.onap.appc.flow.controller.dbervices.FlowControlDBService;
+import org.onap.appc.flow.controller.executorImpl.GraphExecutor;
+import org.onap.appc.flow.controller.executorImpl.RestExecutor;
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+
+/**
+ * Helper class for FlowControlNode
+ */
+class FlowSequenceGenerator {
+
+ private static final EELFLogger log = EELFManager.getInstance().getLogger(FlowSequenceGenerator.class);
+
+ static final String MODULE = "APPC_COMMOM";
+
+ private final FlowControlDBService dbService;
+ private final FlowGenerator flowGenerator;
+ private final GraphExecutor transactionExecutor;
+ private final RestExecutor restExecutor;
+ private final InputParamsCollector inputParamsCollector;
+
+ FlowSequenceGenerator() {
+ this.dbService = FlowControlDBService.initialise();
+ this.flowGenerator = new FlowGenerator();
+ this.transactionExecutor = new GraphExecutor();
+ this.restExecutor = new RestExecutor();
+ this.inputParamsCollector = new InputParamsCollector();
+ }
+
+ /**
+ * Constructor for tests, prefer to use default one
+ */
+ FlowSequenceGenerator(FlowControlDBService dbService, FlowGenerator flowGenerator,
+ GraphExecutor graphExecutor, RestExecutor restExecutor, EnvVariables envVariables) {
+ this.dbService = dbService;
+ this.flowGenerator = flowGenerator;
+ this.transactionExecutor = graphExecutor;
+ this.restExecutor = restExecutor;
+ this.inputParamsCollector = new InputParamsCollector(envVariables, dbService);
+ }
+
+ String getFlowSequence(Map<String, String> inParams, SvcLogicContext ctx, SvcLogicContext localContext)
+ throws Exception {
+
+ String flowSequence;
+ if (localContext.getAttribute(SEQUENCE_TYPE) == null) {
+ Transactions trans = flowGenerator.createSingleStepModel(inParams, ctx);
+ ObjectMapper mapper = new ObjectMapper();
+ flowSequence = mapper.writeValueAsString(trans);
+ log.debug("Single step Flow Sequence : " + flowSequence);
+
+ return flowSequence;
+ }
+
+ if (localContext.getAttribute(GENERATION_NODE) != null) {
+ flowSequence = generationNode(localContext.getAttribute(GENERATION_NODE));
+ } else {
+ flowSequence = getFlowSequenceFromType(ctx, localContext, localContext.getAttribute(SEQUENCE_TYPE));
+ }
+ return flowSequence;
+ }
+
+ private String generationNode(String generationNode) throws Exception {
+ if (!transactionExecutor.hasGraph(MODULE, generationNode, null, "sync")) {
+ throw new Exception("Can not find Custom defined Flow Generator for " + generationNode);
+ }
+ return transactionExecutor
+ .executeGraph(MODULE, generationNode, null, "sync", null)
+ .getProperty(FLOW_SEQUENCE);
+ }
+
+ private String getFlowSequenceFromType(SvcLogicContext ctx, SvcLogicContext localContext,
+ String sequenceType) throws Exception {
+ String flowSequence;
+ String vnfType = ctx.getAttribute(VNF_TYPE);
+ if (sequenceType.equalsIgnoreCase(DESINGTIME)) {
+
+ localContext.setAttribute(VNFC_TYPE, ctx.getAttribute(VNFC_TYPE));
+ flowSequence = dbService.getDesignTimeFlowModel(localContext);
+
+ if (flowSequence == null) {
+ throw new Exception("Flow Sequence is not found User Designed VNF " + vnfType);
+ }
+ } else if (sequenceType.equalsIgnoreCase(RUNTIME)) {
+
+ Transaction transaction = inputParamsCollector.collectInputParams(ctx);
+ log.info("CollectInputParamsData-Input: " + transaction.getPayload());
+
+ Map<String, String> flowSeq = restExecutor.execute(transaction, localContext);
+
+ JSONObject output = new JSONObject(flowSeq.get("restResponse")).optJSONObject("output");
+ if (output == null) {
+ throw new Exception("Failed to get the Flow Sequence runtime for VNF type " + vnfType);
+ }
+ flowSequence = output.toString();
+ log.info("MultistepSequenceGenerator-Output: " + flowSequence);
+
+ } else if (sequenceType.equalsIgnoreCase(EXTERNAL)) {
+ //String input = collectInputParams(localContext);
+ // flowSequnce = ""; //get it from the External interface calling the Rest End point - TBD
+ //if(flowSequnce == null)
+
+ throw new Exception("Flow Sequence not found for " + vnfType);
+
+ } else {
+ //No other type of model supported...
+ //in Future can get flowModel from other generators which will be included here
+ throw new Exception("No information found for sequence Owner Design-Time Vs Run-Time");
+ }
+ return flowSequence;
+ }
+
+}
diff --git a/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/InputParamsCollector.java b/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/InputParamsCollector.java
new file mode 100644
index 000000000..1a7e2bc00
--- /dev/null
+++ b/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/InputParamsCollector.java
@@ -0,0 +1,193 @@
+/*
+ * ============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.onap.appc.flow.controller.utils.FlowControllerConstants.ACTION_LEVEL;
+import static org.onap.appc.flow.controller.utils.FlowControllerConstants.APPC_FLOW_CONTROLLER;
+import static org.onap.appc.flow.controller.utils.FlowControllerConstants.PAYLOAD;
+import static org.onap.appc.flow.controller.utils.FlowControllerConstants.REQUEST_ACTION;
+import static org.onap.appc.flow.controller.utils.FlowControllerConstants.SEQ_GENERATOR_PWD;
+import static org.onap.appc.flow.controller.utils.FlowControllerConstants.SEQ_GENERATOR_UID;
+import static org.onap.appc.flow.controller.utils.FlowControllerConstants.SEQ_GENERATOR_URL;
+import static org.onap.appc.flow.controller.utils.FlowControllerConstants.VNFC_NAME;
+import static org.onap.appc.flow.controller.utils.FlowControllerConstants.VNF_ID;
+import static org.onap.appc.flow.controller.utils.FlowControllerConstants.VSERVER_ID;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+import com.fasterxml.jackson.core.type.TypeReference;
+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.IOException;
+import java.util.List;
+import java.util.Properties;
+import java.util.function.Consumer;
+import org.apache.commons.lang3.StringUtils;
+import org.onap.appc.flow.controller.data.Transaction;
+import org.onap.appc.flow.controller.dbervices.FlowControlDBService;
+import org.onap.appc.flow.controller.interfaceData.ActionIdentifier;
+import org.onap.appc.flow.controller.interfaceData.Capabilities;
+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.Vnfcs;
+import org.onap.appc.flow.controller.utils.EncryptionTool;
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+
+class InputParamsCollector {
+
+ private static final EELFLogger log = EELFManager.getInstance().getLogger(InputParamsCollector.class);
+
+ private final EnvVariables envVariables;
+ private final FlowControlDBService dbService;
+
+ static final String SDNC_CONFIG_DIR_VAR = "SDNC_CONFIG_DIR";
+
+ InputParamsCollector() {
+ this.envVariables = new EnvVariables();
+ this.dbService = FlowControlDBService.initialise();
+ }
+
+ InputParamsCollector(EnvVariables envVariables, FlowControlDBService dbService) {
+ this.envVariables = envVariables;
+ this.dbService = dbService;
+ }
+
+ Transaction collectInputParams(SvcLogicContext ctx) throws Exception {
+
+ String fn = "FlowExecuteNode.collectInputParams";
+ Properties prop = loadProperties();
+ log.info("Loaded Properties " + prop.toString());
+
+ String vnfId = ctx.getAttribute(VNF_ID);
+ log.debug(fn + "vnfId :" + vnfId);
+
+ if (StringUtils.isBlank(vnfId)) {
+ throw new Exception("VnfId is missing");
+ }
+
+ String resourceUri = prop.getProperty(SEQ_GENERATOR_URL);
+ log.info(fn + "resourceUri= " + resourceUri);
+
+ String pass = EncryptionTool.getInstance().decrypt(prop.getProperty(SEQ_GENERATOR_PWD));
+
+ Transaction transaction = new Transaction();
+ transaction.setPayload(getInputData(ctx, fn, vnfId));
+ transaction.setExecutionRPC("POST");
+ transaction.setuId(prop.getProperty(SEQ_GENERATOR_UID));
+ transaction.setPswd(pass);
+ transaction.setExecutionEndPoint(resourceUri);
+
+ return transaction;
+ }
+
+ private String getInputData(SvcLogicContext ctx, String fn, String vnfId) throws IOException, SvcLogicException {
+ ActionIdentifier actionIdentifier = new ActionIdentifier();
+ log.debug("Enter ActionIdentifier");
+
+ applyIfNotBlank(vnfId, actionIdentifier::setVnfId);
+ applyIfNotBlank(ctx.getAttribute(VSERVER_ID), actionIdentifier::setVserverId);
+ applyIfNotBlank(ctx.getAttribute(VNFC_NAME), actionIdentifier::setVnfcName);
+
+ log.info("ActionIdentifierData" + actionIdentifier.toString());
+
+ log.info("Enter RequestInfo");
+ RequestInfo requestInfo = getRequestInfo(ctx, actionIdentifier);
+ log.debug("RequestInfo: " + requestInfo.toString());
+
+ InventoryInfo inventoryInfo = new InventoryInfoExtractor().getInventoryInfo(ctx, vnfId);
+ Capabilities capabilities = new CapabilitiesDataExtractor(dbService).getCapabilitiesData(ctx);
+ DependencyInfo dependencyInfo = getDependencyInfo(ctx);
+
+ log.info("Enter InputData");
+ Input input = getInput(requestInfo, inventoryInfo, dependencyInfo, capabilities);
+ log.info(fn + "Input parameters:" + input.toString());
+
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.setSerializationInclusion(Include.NON_NULL);
+ mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, true);
+ String inputData = mapper.writeValueAsString(input);
+ log.info("InputDataJson:" + inputData);
+
+ return inputData;
+ }
+
+ private Input getInput(RequestInfo requestInfo, InventoryInfo inventoryInfo,
+ DependencyInfo dependencyInfo, Capabilities capabilities) {
+ Input input = new Input();
+ input.setRequestInfo(requestInfo);
+ input.setInventoryInfo(inventoryInfo);
+ input.setDependencyInfo(dependencyInfo);
+ input.setCapabilities(capabilities);
+ return input;
+ }
+
+ private RequestInfo getRequestInfo(SvcLogicContext ctx, ActionIdentifier actionIdentifier) {
+ RequestInfo requestInfo = new RequestInfo();
+ requestInfo.setAction(ctx.getAttribute(REQUEST_ACTION));
+ requestInfo.setActionLevel(ctx.getAttribute(ACTION_LEVEL));
+ requestInfo.setPayload(ctx.getAttribute(PAYLOAD));
+ requestInfo.setActionIdentifier(actionIdentifier);
+ return requestInfo;
+ }
+
+ DependencyInfo getDependencyInfo(SvcLogicContext ctx) throws SvcLogicException, IOException {
+
+ String fn = "FlowExecutorNode.getDependencyInfo";
+ String dependencyData = dbService.getDependencyInfo(ctx);
+ log.info(fn + "dependencyDataInput:" + dependencyData);
+
+ 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;
+ }
+
+ 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 path = directory + APPC_FLOW_CONTROLLER;
+ return PropertiesLoader.load(path);
+ }
+
+ private void applyIfNotBlank(String parameter, Consumer<String> consumer) {
+ if (StringUtils.isNotBlank(parameter)) {
+ consumer.accept(parameter);
+ }
+ }
+
+}
diff --git a/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/JsonValidator.java b/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/JsonValidator.java
index 78d530533..038d35b5d 100644
--- a/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/JsonValidator.java
+++ b/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/JsonValidator.java
@@ -1,3 +1,22 @@
+/*
+ * ============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;
diff --git a/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/PropertiesLoader.java b/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/PropertiesLoader.java
index 28792bb10..854f476a1 100644
--- a/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/PropertiesLoader.java
+++ b/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/PropertiesLoader.java
@@ -1,3 +1,22 @@
+/*
+ * ============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 java.io.FileInputStream;
diff --git a/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/ResourceUriExtractor.java b/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/ResourceUriExtractor.java
index cd07952cf..c36a74be7 100644
--- a/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/ResourceUriExtractor.java
+++ b/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/ResourceUriExtractor.java
@@ -1,3 +1,22 @@
+/*
+ * ============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.onap.appc.flow.controller.utils.FlowControllerConstants.HTTP;
diff --git a/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/TransactionHandler.java b/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/TransactionHandler.java
index af9e84589..b4becd9b1 100644
--- a/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/TransactionHandler.java
+++ b/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/TransactionHandler.java
@@ -1,3 +1,22 @@
+/*
+ * ============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.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_REQUEST_ACTION;