summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkurczews <krzysztof.kurczewski@nokia.com>2018-03-01 10:52:36 +0100
committerTakamune Cho <tc012c@att.com>2018-03-06 16:49:43 +0000
commit88b8adc6bfe201f338425ee27c0922a6da4765b1 (patch)
tree10c1d8fd2a235b61183728a4a926d058535875ac
parent16529076b3c306c2a4d35004bbec6c561578e819 (diff)
Improve coverage FlowControlNode #5
* cleanup formatting shorten constants * Change-Id: Iddc632ae9c3893622c1ba0ce937c2971b792fe37 Issue-ID: APPC-440 Signed-off-by: kurczews <krzysztof.kurczewski@nokia.com>
-rw-r--r--appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/FlowControlNode.java916
-rw-r--r--appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/JsonParsingNode.java78
-rw-r--r--appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/executor/node/FlowControlNodeTest.java2
3 files changed, 498 insertions, 498 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 baca94b36..b2f4039c6 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
@@ -22,6 +22,40 @@
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.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.GRAPH;
+import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_PARAM_RESPONSE_PREFIX;
+import static org.onap.appc.flow.controller.utils.FlowControllerConstants.NODE;
+import static org.onap.appc.flow.controller.utils.FlowControllerConstants.OUTPUT_PARAM_ERROR_MESSAGE;
+import static org.onap.appc.flow.controller.utils.FlowControllerConstants.OUTPUT_PARAM_STATUS;
+import static org.onap.appc.flow.controller.utils.FlowControllerConstants.OUTPUT_STATUS_FAILURE;
+import static org.onap.appc.flow.controller.utils.FlowControllerConstants.OUTPUT_STATUS_MESSAGE;
+import static org.onap.appc.flow.controller.utils.FlowControllerConstants.OUTPUT_STATUS_SUCCESS;
+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.REQUEST_ID;
+import static org.onap.appc.flow.controller.utils.FlowControllerConstants.RESPONSE_PREFIX;
+import static org.onap.appc.flow.controller.utils.FlowControllerConstants.REST;
+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.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.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 static org.onap.appc.flow.controller.utils.FlowControllerConstants.VNFC_NAME;
+import static org.onap.appc.flow.controller.utils.FlowControllerConstants.VNFC_TYPE;
+import static org.onap.appc.flow.controller.utils.FlowControllerConstants.VNF_ID;
+import static org.onap.appc.flow.controller.utils.FlowControllerConstants.VNF_TYPE;
+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;
@@ -61,509 +95,483 @@ 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.appc.flow.controller.utils.FlowControllerConstants;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
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";
-
- public void processFlow(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
- log.debug("Received processParamKeys call with params : " + inParams);
- String responsePrefix = inParams.get(FlowControllerConstants.INPUT_PARAM_RESPONSE_PREFIX);
- try {
- responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
- SvcLogicContext localContext = new SvcLogicContext();
-
- localContext.setAttribute(FlowControllerConstants.REQUEST_ID,
- ctx.getAttribute(FlowControllerConstants.REQUEST_ID));
- localContext.setAttribute(FlowControllerConstants.VNF_TYPE,
- ctx.getAttribute(FlowControllerConstants.VNF_TYPE));
- localContext.setAttribute(FlowControllerConstants.REQUEST_ACTION,
- ctx.getAttribute(FlowControllerConstants.REQUEST_ACTION));
- localContext.setAttribute(FlowControllerConstants.ACTION_LEVEL,
- ctx.getAttribute(FlowControllerConstants.ACTION_LEVEL));
- localContext.setAttribute(FlowControllerConstants.RESPONSE_PREFIX,
- responsePrefix);
- ctx.setAttribute(FlowControllerConstants.RESPONSE_PREFIX,
- responsePrefix);
-
- FlowControlDBService dbservice = FlowControlDBService.initialise();
- dbservice.getFlowReferenceData(ctx, inParams, localContext);
-
- for (Object key : localContext.getAttributeKeySet()) {
- String parmName = (String) key;
- String parmValue = ctx.getAttribute(parmName);
- log.debug("processFlow " + parmName + "=" + parmValue);
-
- }
- processFlowSequence(inParams, ctx, localContext);
- if (!ctx.getAttribute(responsePrefix + FlowControllerConstants.OUTPUT_PARAM_STATUS)
- .equals(FlowControllerConstants.OUTPUT_STATUS_SUCCESS)) {
-
- throw new SvcLogicException(
- ctx.getAttribute(responsePrefix + FlowControllerConstants.OUTPUT_STATUS_MESSAGE));
- }
-
- } catch (Exception e) {
- ctx.setAttribute(responsePrefix + FlowControllerConstants.OUTPUT_PARAM_STATUS,
- FlowControllerConstants.OUTPUT_STATUS_FAILURE);
- ctx.setAttribute(responsePrefix + FlowControllerConstants.OUTPUT_PARAM_ERROR_MESSAGE,
- e.getMessage());
- log.error("Error occured in processFlow ", e);
- throw new SvcLogicException(e.getMessage());
- }
+ private static final EELFLogger log = EELFManager.getInstance().getLogger(FlowControlNode.class);
+ private static final String SDNC_CONFIG_DIR_VAR = "SDNC_CONFIG_DIR";
+
+ public void processFlow(Map<String, String> inParams, SvcLogicContext ctx)
+ throws SvcLogicException {
+ log.debug("Received processParamKeys call with params : " + inParams);
+ String responsePrefix = inParams.get(INPUT_PARAM_RESPONSE_PREFIX);
+ try {
+ responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
+ SvcLogicContext localContext = new SvcLogicContext();
+
+ localContext.setAttribute(REQUEST_ID, ctx.getAttribute(REQUEST_ID));
+ localContext.setAttribute(VNF_TYPE, ctx.getAttribute(VNF_TYPE));
+ localContext.setAttribute(REQUEST_ACTION, ctx.getAttribute(REQUEST_ACTION));
+ localContext.setAttribute(ACTION_LEVEL, ctx.getAttribute(ACTION_LEVEL));
+ localContext.setAttribute(RESPONSE_PREFIX, responsePrefix);
+ ctx.setAttribute(RESPONSE_PREFIX, responsePrefix);
+
+ FlowControlDBService dbService = FlowControlDBService.initialise();
+ dbService.getFlowReferenceData(ctx, inParams, localContext);
+
+ for (String key : localContext.getAttributeKeySet()) {
+ log.debug("processFlow " + key + "=" + ctx.getAttribute(key));
+ }
+ processFlowSequence(inParams, ctx, localContext);
+ if (!ctx.getAttribute(responsePrefix + OUTPUT_PARAM_STATUS).equals(OUTPUT_STATUS_SUCCESS)) {
+ throw new SvcLogicException(ctx.getAttribute(responsePrefix + OUTPUT_STATUS_MESSAGE));
+ }
+ } catch (Exception e) {
+ ctx.setAttribute(responsePrefix + OUTPUT_PARAM_STATUS, OUTPUT_STATUS_FAILURE);
+ ctx.setAttribute(responsePrefix + OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
+ log.error("Error occurred in processFlow ", e);
+ throw new SvcLogicException(e.getMessage());
}
+ }
- private void processFlowSequence(Map<String, String> inParams, SvcLogicContext ctx, SvcLogicContext localContext)
- throws Exception {
-
- String fn = "FlowExecutorNode.processflowSequence";
- log.debug(fn + "Received model for flow : " + localContext.toString());
- FlowControlDBService dbservice = FlowControlDBService.initialise();
- String flowSequnce = null;
- for (Object key : localContext.getAttributeKeySet()) {
- String parmName = (String) key;
- String parmValue = ctx.getAttribute(parmName);
- log.debug(parmName + "=" + parmValue);
+ private void processFlowSequence(Map<String, String> inParams, SvcLogicContext ctx, SvcLogicContext localContext)
+ throws Exception {
+ 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));
+ }
+ 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));
}
- if (localContext.getAttribute(FlowControllerConstants.SEQUENCE_TYPE) != null) {
- if (localContext.getAttribute(FlowControllerConstants.GENERATION_NODE) != null) {
- GraphExecutor transactionExecutor = new GraphExecutor();
- Boolean generatorExists = transactionExecutor.hasGraph(
- "APPC_COMMOM",
- localContext.getAttribute(FlowControllerConstants.GENERATION_NODE),
- null,
- "sync");
-
- if (generatorExists) {
- flowSequnce = transactionExecutor.executeGraph(
- "APPC_COMMOM",
- localContext.getAttribute(FlowControllerConstants.GENERATION_NODE),
- null, "sync", null)
- .getProperty(FlowControllerConstants.FLOW_SEQUENCE);
- } else {
- throw new Exception("Can not find Custom defined Flow Generator for "
- + localContext.getAttribute(FlowControllerConstants.GENERATION_NODE));
- }
-
- } else if ((localContext.getAttribute(FlowControllerConstants.SEQUENCE_TYPE))
- .equalsIgnoreCase(FlowControllerConstants.DESINGTIME)) {
-
- localContext.setAttribute(FlowControllerConstants.VNFC_TYPE,
- ctx.getAttribute(FlowControllerConstants.VNFC_TYPE));
- flowSequnce = dbservice.getDesignTimeFlowModel(localContext);
-
- if (flowSequnce == null) {
- throw new Exception("Flow Sequence is not found User Desinged VNF "
- + ctx.getAttribute(FlowControllerConstants.VNF_TYPE));
- }
-
- } else if ((localContext.getAttribute(FlowControllerConstants.SEQUENCE_TYPE))
- .equalsIgnoreCase(FlowControllerConstants.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")) {
- flowSequnce = sequence.getJSONObject("output").toString();
- }
- log.info("MultistepSequenceGenerator-Output: " + flowSequnce);
-
- if (flowSequnce == null) {
- throw new Exception("Failed to get the Flow Sequece runtime for VNF type"
- + ctx.getAttribute(FlowControllerConstants.VNF_TYPE));
- }
-
- } else if ((localContext.getAttribute(FlowControllerConstants.SEQUENCE_TYPE))
- .equalsIgnoreCase(FlowControllerConstants.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(FlowControllerConstants.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();
- flowSequnce = mapper.writeValueAsString(trans);
- log.debug("Single step Flow Sequence : " + flowSequnce);
+ } 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));
}
- log.debug("Received Flow Sequence : " + flowSequnce);
- HashMap<Integer, Transaction> transactionMap = createTransactionMap(flowSequnce, localContext);
- exeuteAllTransaction(transactionMap, ctx);
- log.info("Executed all the transacstion successfully");
- }
+ } else if ((localContext.getAttribute(SEQUENCE_TYPE)).equalsIgnoreCase(RUNTIME)) {
+
+ Transaction transaction = new Transaction();
+ String input = collectInputParams(ctx, transaction);
+ log.info("CollectInputParamsData-Input: " + input);
- private void exeuteAllTransaction(HashMap<Integer, Transaction> transactionMap, SvcLogicContext ctx)
- throws Exception {
-
- String fn = "FlowExecutorNode.exeuteAllTransaction ";
- int retry = 0;
- FlowExecutorInterface flowExecutor;
- for (int key = 1; key <= transactionMap.size() ; key++) {
- log.debug(fn + "Starting transactions ID " + key + " :)=" + retry);
- Transaction transaction = transactionMap.get(key);
- if (!preProcessor(transactionMap, transaction)) {
- log.info("Skipping Transaction ID " + transaction.getTransactionId());
- continue;
- }
- if (transaction.getExecutionType() != null) {
- switch (transaction.getExecutionType()) {
- case FlowControllerConstants.GRAPH :
- flowExecutor = new GraphExecutor();
- break;
- case FlowControllerConstants.NODE :
- flowExecutor = new NodeExecutor();
- break;
- case FlowControllerConstants.REST :
- flowExecutor = new RestExecutor();
- break;
- default :
- throw new Exception("No Executor found for transaction ID" + transaction.getTransactionId());
- }
- flowExecutor.execute(transaction, ctx);
- ResponseAction responseAction = handleResponse(transaction);
-
- if (responseAction.getWait() != null && Integer.parseInt(responseAction.getWait()) > 0) {
- log.debug(fn + "Going to Sleep .... " + responseAction.getWait());
- Thread.sleep(Integer.parseInt(responseAction.getWait()) * 1000L);
- }
- if (responseAction.isIntermediateMessage()) {
- log.debug(fn + "Sending Intermediate Message back .... ");
- sendIntermediateMessage();
- }
- if (responseAction.getRetry() != null && Integer.parseInt(responseAction.getRetry()) > retry ) {
- log.debug(fn + "Ooppss!!! We will retry again ....... ");
- key--;
- retry++;
- log.debug(fn + "key =" + key + "retry =" + retry);
- }
- if (responseAction.isIgnore()) {
- log.debug(fn + "Ignoring this Error and moving ahead ....... ");
- continue;
- }
- if (responseAction.isStop()) {
- log.debug(fn + "Need to Stop ....... ");
- break;
- }
- if (responseAction.getJump() != null && Integer.parseInt(responseAction.getJump()) > 0 ) {
- key = Integer.parseInt(responseAction.getJump());
- key --;
- }
- log.debug(fn + "key =" + key + "retry =" + retry);
-
- } else {
- throw new Exception("Don't know how to execute transaction ID " + transaction.getTransactionId());
- }
+ 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));
+ }
- private void sendIntermediateMessage() {
- // TODO Auto-generated method stub
+ } 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);
}
- private ResponseAction handleResponse(Transaction transaction) {
- log.info("Handling Response for transaction Id " + transaction.getTransactionId());
- DefaultResponseHandler defaultHandler = new DefaultResponseHandler();
- return defaultHandler.handlerResponse(transaction);
- }
+ log.debug("Received Flow Sequence : " + flowSequence);
+ HashMap<Integer, Transaction> transactionMap = createTransactionMap(flowSequence, localContext);
+ executeAllTransaction(transactionMap, ctx);
+ log.info("Executed all the transaction successfully");
+ }
+
+ private void executeAllTransaction(HashMap<Integer, Transaction> transactionMap, SvcLogicContext ctx)
+ throws Exception {
+
+ String fn = "FlowExecutorNode.executeAllTransaction ";
+ int retry = 0;
+ FlowExecutorInterface flowExecutor;
+ for (int key = 1; key <= transactionMap.size(); key++) {
+ log.debug(fn + "Starting transactions ID " + key + " :)=" + retry);
+ Transaction transaction = transactionMap.get(key);
+ if (!preProcessor(transactionMap, transaction)) {
+ log.info("Skipping Transaction ID " + transaction.getTransactionId());
+ continue;
+ }
+ if (transaction.getExecutionType() != null) {
+ switch (transaction.getExecutionType()) {
+ case GRAPH:
+ flowExecutor = new GraphExecutor();
+ break;
+ case NODE:
+ flowExecutor = new NodeExecutor();
+ break;
+ case REST:
+ flowExecutor = new RestExecutor();
+ break;
+ default:
+ throw new Exception("No Executor found for transaction ID" + transaction.getTransactionId());
+ }
+ flowExecutor.execute(transaction, ctx);
+ ResponseAction responseAction = handleResponse(transaction);
- private boolean preProcessor(HashMap<Integer, Transaction> transactionMap, Transaction transaction)
- throws IOException {
-
- log.debug("Starting Preprocessing Logic ");
- boolean runthisStep = false;
- try {
- if (transaction.getPrecheck() != null
- && transaction.getPrecheck().getPrecheckOptions() != null
- && !transaction.getPrecheck().getPrecheckOptions().isEmpty()) {
-
- List<PrecheckOption> precheckOptions = transaction.getPrecheck().getPrecheckOptions();
- for (PrecheckOption precheck : precheckOptions) {
- Transaction trans = transactionMap.get(precheck.getpTransactionID());
- ObjectMapper mapper = new ObjectMapper();
- log.info("Mapper= " + mapper.writeValueAsString(trans));
- HashMap trmap = mapper.readValue(mapper.writeValueAsString(trans), HashMap.class);
- if (trmap.get(precheck.getParamName()) != null
- && ((String) trmap.get(precheck.getParamName())).equalsIgnoreCase(precheck.getParamValue())) {
- runthisStep = true;
- } else {
- runthisStep = false;
- }
-
- if (("any").equalsIgnoreCase(transaction.getPrecheck().getPrecheckOperator()) && runthisStep) {
- break;
- }
- }
- } else {
- log.debug("No Pre check defined for transaction ID " + transaction.getTransactionId());
- runthisStep = true;
- }
- } catch(Exception e) {
- log.error("Error occured when Preprocessing Logic ", e);
- throw e;
+ if (responseAction.getWait() != null && Integer.parseInt(responseAction.getWait()) > 0) {
+ log.debug(fn + "Going to Sleep .... " + responseAction.getWait());
+ Thread.sleep(Integer.parseInt(responseAction.getWait()) * 1000L);
}
- log.debug("Returing process current Transaction = " + runthisStep);
- return runthisStep ;
- }
+ if (responseAction.isIntermediateMessage()) {
+ log.debug(fn + "Sending Intermediate Message back .... ");
+ sendIntermediateMessage();
+ }
+ if (responseAction.getRetry() != null && Integer.parseInt(responseAction.getRetry()) > retry) {
+ log.debug(fn + "Ooppss!!! We will retry again ....... ");
+ key--;
+ retry++;
+ log.debug(fn + "key =" + key + "retry =" + retry);
+ }
+ if (responseAction.isIgnore()) {
+ log.debug(fn + "Ignoring this Error and moving ahead ....... ");
+ continue;
+ }
+ if (responseAction.isStop()) {
+ log.debug(fn + "Need to Stop ....... ");
+ break;
+ }
+ if (responseAction.getJump() != null && Integer.parseInt(responseAction.getJump()) > 0) {
+ key = Integer.parseInt(responseAction.getJump());
+ key--;
+ }
+ log.debug(fn + "key =" + key + "retry =" + retry);
- private HashMap<Integer, Transaction> createTransactionMap(String flowSequnce, SvcLogicContext localContext)
- throws Exception {
-
- ObjectMapper mapper = new ObjectMapper();
- Transactions transactions = mapper.readValue(flowSequnce,Transactions.class);
- HashMap<Integer, Transaction> transMap = new HashMap<>();
- for (Transaction transaction : transactions.getTransactions()) {
- compileFlowDependencies(transaction, localContext);
- //parse the Transactions Object and create records in process_flow_status table
- //loadTransactionIntoStatus(transactions, ctx);
- transMap.put(transaction.getTransactionId(), transaction);
+ } else {
+ throw new Exception("Don't know how to execute transaction ID " + transaction.getTransactionId());
+ }
+ }
+ }
+
+ private void sendIntermediateMessage() {
+ // TODO Auto-generated method stub
+ }
+
+ private ResponseAction handleResponse(Transaction transaction) {
+ log.info("Handling Response for transaction Id " + transaction.getTransactionId());
+ DefaultResponseHandler defaultHandler = new DefaultResponseHandler();
+ return defaultHandler.handlerResponse(transaction);
+ }
+
+ private boolean preProcessor(HashMap<Integer, Transaction> transactionMap, Transaction transaction)
+ throws IOException {
+
+ log.debug("Starting Preprocessing Logic ");
+ boolean runThisStep = false;
+ try {
+ if (transaction.getPrecheck() != null
+ && transaction.getPrecheck().getPrecheckOptions() != null
+ && !transaction.getPrecheck().getPrecheckOptions().isEmpty()) {
+
+ List<PrecheckOption> precheckOptions = transaction.getPrecheck().getPrecheckOptions();
+ for (PrecheckOption precheck : precheckOptions) {
+ Transaction trans = transactionMap.get(precheck.getpTransactionID());
+ ObjectMapper mapper = new ObjectMapper();
+ log.info("Mapper= " + mapper.writeValueAsString(trans));
+ HashMap trmap = mapper.readValue(mapper.writeValueAsString(trans), HashMap.class);
+ runThisStep = trmap.get(precheck.getParamName()) != null
+ && ((String) trmap.get(precheck.getParamName()))
+ .equalsIgnoreCase(precheck.getParamValue());
+
+ if (("any").equalsIgnoreCase(transaction.getPrecheck().getPrecheckOperator()) && runThisStep) {
+ break;
+ }
}
- return transMap;
+ } else {
+ log.debug("No Pre check defined for transaction ID " + transaction.getTransactionId());
+ runThisStep = true;
+ }
+ } catch (Exception e) {
+ log.error("Error occured when Preprocessing Logic ", e);
+ throw e;
+ }
+ log.debug("Returing process current Transaction = " + runThisStep);
+ return runThisStep;
+ }
+
+ private HashMap<Integer, Transaction> createTransactionMap(String flowSequence, SvcLogicContext localContext)
+ throws Exception {
+
+ ObjectMapper mapper = new ObjectMapper();
+ Transactions transactions = mapper.readValue(flowSequence, Transactions.class);
+ HashMap<Integer, Transaction> transMap = new HashMap<>();
+ for (Transaction transaction : transactions.getTransactions()) {
+ compileFlowDependencies(transaction, localContext);
+ //parse the Transactions Object and create records in process_flow_status table
+ //loadTransactionIntoStatus(transactions, ctx);
+ transMap.put(transaction.getTransactionId(), transaction);
}
+ return transMap;
+ }
- private void compileFlowDependencies(Transaction transaction, SvcLogicContext localContext) throws Exception {
+ private void compileFlowDependencies(Transaction transaction, SvcLogicContext localContext)
+ throws Exception {
- FlowControlDBService dbservice = FlowControlDBService.initialise();
- dbservice.populateModuleAndRPC(transaction, localContext.getAttribute(FlowControllerConstants.VNF_TYPE));
- ObjectMapper mapper = new ObjectMapper();
- log.debug("Indivisual Transaction Details :" + transaction.toString());
+ FlowControlDBService dbService = FlowControlDBService.initialise();
+ dbService.populateModuleAndRPC(transaction, localContext.getAttribute(VNF_TYPE));
+ ObjectMapper mapper = new ObjectMapper();
+ log.debug("Individual Transaction Details :" + transaction.toString());
- if ((localContext.getAttribute(FlowControllerConstants.SEQUENCE_TYPE) == null)
- || (localContext.getAttribute(FlowControllerConstants.SEQUENCE_TYPE) != null
- && ! localContext.getAttribute(FlowControllerConstants.SEQUENCE_TYPE)
- .equalsIgnoreCase(FlowControllerConstants.DESINGTIME))) {
+ if ((localContext.getAttribute(SEQUENCE_TYPE) == null)
+ || (localContext.getAttribute(SEQUENCE_TYPE) != null
+ && !localContext.getAttribute(SEQUENCE_TYPE)
+ .equalsIgnoreCase(DESINGTIME))) {
- localContext.setAttribute("artifact-content", mapper.writeValueAsString(transaction));
- dbservice.loadSequenceIntoDB(localContext);
- }
- //get a field in transction class as transactionhandle interface and register the Handler here for each trnactions
+ localContext.setAttribute("artifact-content", mapper.writeValueAsString(transaction));
+ dbService.loadSequenceIntoDB(localContext);
}
+ //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 {
+ private String collectInputParams(SvcLogicContext ctx, Transaction transaction) throws Exception {
- String fn = "FlowExecuteNode.collectInputParams";
- Properties prop = loadProperties();
- log.info("Loaded Properties " + prop.toString());
+ String fn = "FlowExecuteNode.collectInputParams";
+ Properties prop = loadProperties();
+ log.info("Loaded Properties " + prop.toString());
- String vnfId = ctx.getAttribute(FlowControllerConstants.VNF_ID);
- String inputData = null;
- log.debug(fn + "vnfId :" + vnfId);
+ String vnfId = ctx.getAttribute(VNF_ID);
+ String inputData = null;
+ log.debug(fn + "vnfId :" + vnfId);
- if (StringUtils.isBlank(vnfId)) {
- throw new Exception("VnfId is missing");
- }
+ 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(FlowControllerConstants.VSERVER_ID))) {
- actionIdentifier.setVserverId(ctx.getAttribute(FlowControllerConstants.VSERVER_ID));
- }
- if (StringUtils.isNotBlank(ctx.getAttribute(FlowControllerConstants.VNFC_NAME))) {
- actionIdentifier.setVnfcName(ctx.getAttribute(FlowControllerConstants.VNFC_NAME));
- }
- log.info("ActionIdentifierData" + actionIdentifier.toString());
-
- RequestInfo requestInfo = new RequestInfo();
- log.info("Enter RequestInfo");
- requestInfo.setAction(ctx.getAttribute(FlowControllerConstants.REQUEST_ACTION));
- requestInfo.setActionLevel(ctx.getAttribute(FlowControllerConstants.ACTION_LEVEL));
- requestInfo.setPayload(ctx.getAttribute(FlowControllerConstants.PAYLOAD));
- requestInfo.setActionIdentifier(actionIdentifier);
- log.debug("RequestInfo: " + requestInfo.toString());
-
- InventoryInfo inventoryInfo = getInventoryInfo(ctx, vnfId);
- DependencyInfo dependencyInfo = getDependencyInfo(ctx);
- Capabilities capabilites = getCapabilitesData(ctx);
-
- Input input = new Input();
- log.info("Enter InputData");
- input.setRequestInfo(requestInfo);
- input.setInventoryInfo(inventoryInfo);
- input.setDependencyInfo(dependencyInfo);
- input.setCapabilities(capabilites);
- 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 occured in " + fn, e);
- }
+ 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 = 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(FlowControllerConstants.SEQ_GENERATOR_URL);
- log.info(fn + "resourceUri= " + resourceUri);
+ String resourceUri = prop.getProperty(SEQ_GENERATOR_URL);
+ log.info(fn + "resourceUri= " + resourceUri);
- EncryptionTool et = EncryptionTool.getInstance();
- String pass = et.decrypt(prop.getProperty(FlowControllerConstants.SEQ_GENERATOR_PWD));
+ EncryptionTool et = EncryptionTool.getInstance();
+ String pass = et.decrypt(prop.getProperty(SEQ_GENERATOR_PWD));
- transaction.setPayload(inputData);
- transaction.setExecutionRPC("POST");
- transaction.setuId(prop.getProperty(FlowControllerConstants.SEQ_GENERATOR_UID));
- transaction.setPswd(pass);
- transaction.setExecutionEndPoint(resourceUri);
+ transaction.setPayload(inputData);
+ transaction.setExecutionRPC("POST");
+ transaction.setuId(prop.getProperty(SEQ_GENERATOR_UID));
+ transaction.setPswd(pass);
+ transaction.setExecutionEndPoint(resourceUri);
- return inputData;
- }
+ return inputData;
+ }
- private DependencyInfo getDependencyInfo(SvcLogicContext ctx) throws Exception {
+ private DependencyInfo getDependencyInfo(SvcLogicContext ctx) throws Exception {
- String fn = "FlowExecutorNode.getDependencyInfo";
- DependencyInfo dependencyInfo = new DependencyInfo();
- FlowControlDBService dbservice = FlowControlDBService.initialise();
- String dependencyData = dbservice.getDependencyInfo(ctx);
- log.info(fn + "dependencyDataInput:" + dependencyData);
+ String fn = "FlowExecutorNode.getDependencyInfo";
+ DependencyInfo dependencyInfo = new DependencyInfo();
+ FlowControlDBService dbService = FlowControlDBService.initialise();
+ 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);
+ 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());
- }
- return dependencyInfo;
+ log.info("Dependency Output:" + dependencyInfo.toString());
}
-
- private Capabilities getCapabilitesData(SvcLogicContext ctx) throws Exception {
-
- String fn = "FlowExecutorNode.getCapabilitesData";
- Capabilities capabilities = new Capabilities();
- FlowControlDBService dbservice = FlowControlDBService.initialise();
- String capabilitiesData = dbservice.getCapabilitiesData(ctx);
- log.info(fn + "capabilitiesDataInput:" + capabilitiesData);
-
- if (capabilitiesData != null) {
- ObjectMapper mapper = new ObjectMapper();
- mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,false);
- mapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
- JsonNode capabilitiesNode = mapper.readValue(capabilitiesData,JsonNode.class);
- log.info("capabilitiesNode:" + capabilitiesNode.toString());
-
- JsonNode vnfs = capabilitiesNode.findValue(FlowControllerConstants.VNF);
- List<String> vnfsList = new ArrayList<>();
- if (vnfs != null) {
- for (int i = 0; i < vnfs.size(); i++) {
- String vnf = vnfs.get(i).asText();
- vnfsList.add(vnf);
- }
- }
-
- JsonNode vfModules = capabilitiesNode.findValue(FlowControllerConstants.VF_MODULE);
- List<String> vfModulesList = new ArrayList<>();
- if (vfModules != null) {
- for (int i = 0; i < vfModules.size(); i++) {
- String vfModule = vfModules.get(i).asText();
- vfModulesList.add(vfModule);
- }
- }
-
- JsonNode vnfcs = capabilitiesNode.findValue(FlowControllerConstants.VNFC);
- List<String> vnfcsList = new ArrayList<>();
- if (vnfcs != null) {
- for (int i = 0; i < vnfcs.size(); i++) {
- String vnfc1 = vnfcs.get(i).asText();
- vnfcsList.add(vnfc1);
- }
- }
-
- JsonNode vms = capabilitiesNode.findValue(FlowControllerConstants.VM);
- List<String> vmList = new ArrayList<>();
- if (vms != null) {
- for (int i = 0; i < vms.size(); i++) {
- String vm1 = vms.get(i).asText();
- vmList.add(vm1);
- }
- }
-
- capabilities.getVnfc().addAll(vnfcsList);
- capabilities.getVnf().addAll(vnfsList);
- capabilities.getVfModule().addAll(vfModulesList);
- capabilities.getVm().addAll(vmList);
-
- log.info("Capabilities Output:" + capabilities.toString());
+ return dependencyInfo;
+ }
+
+ private Capabilities getCapabilitiesData(SvcLogicContext ctx) throws Exception {
+
+ String fn = "FlowExecutorNode.getCapabilitiesData";
+ Capabilities capabilities = new Capabilities();
+ FlowControlDBService dbService = FlowControlDBService.initialise();
+ String capabilitiesData = dbService.getCapabilitiesData(ctx);
+ log.info(fn + "capabilitiesDataInput:" + capabilitiesData);
+
+ if (capabilitiesData != null) {
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+ mapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
+ JsonNode capabilitiesNode = mapper.readValue(capabilitiesData, JsonNode.class);
+ log.info("capabilitiesNode:" + capabilitiesNode.toString());
+
+ JsonNode vnfs = capabilitiesNode.findValue(VNF);
+ List<String> vnfsList = new ArrayList<>();
+ if (vnfs != null) {
+ for (int i = 0; i < vnfs.size(); i++) {
+ String vnf = vnfs.get(i).asText();
+ vnfsList.add(vnf);
}
- 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);
- }
+ }
+
+ JsonNode vfModules = capabilitiesNode.findValue(VF_MODULE);
+ List<String> vfModulesList = new ArrayList<>();
+ if (vfModules != null) {
+ for (int i = 0; i < vfModules.size(); i++) {
+ String vfModule = vfModules.get(i).asText();
+ vfModulesList.add(vfModule);
+ }
+ }
+
+ JsonNode vnfcs = capabilitiesNode.findValue(VNFC);
+ List<String> vnfcsList = new ArrayList<>();
+ if (vnfcs != null) {
+ for (int i = 0; i < vnfcs.size(); i++) {
+ String vnfc1 = vnfcs.get(i).asText();
+ vnfcsList.add(vnfc1);
+ }
+ }
+
+ JsonNode vms = capabilitiesNode.findValue(VM);
+ List<String> vmList = new ArrayList<>();
+ if (vms != null) {
+ for (int i = 0; i < vms.size(); i++) {
+ String vm1 = vms.get(i).asText();
+ vmList.add(vm1);
}
- InventoryInfo inventoryInfo = new InventoryInfo();
- inventoryInfo.setVnfInfo(vnfInfo);
- log.info(fn + "Inventory Output:" + inventoryInfo.toString());
+ }
- return inventoryInfo;
- }
+ capabilities.getVnfc().addAll(vnfcsList);
+ capabilities.getVnf().addAll(vnfsList);
+ capabilities.getVfModule().addAll(vfModulesList);
+ capabilities.getVm().addAll(vmList);
- private static Properties loadProperties() throws Exception {
- Properties props = new Properties();
- String propDir = System.getenv(SDNC_CONFIG_DIR_VAR);
- if (propDir == null) {
- throw new Exception("Cannot find Property file -" + SDNC_CONFIG_DIR_VAR);
+ log.info("Capabilities Output:" + capabilities.toString());
+ }
+ 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);
}
- String propFile = propDir + FlowControllerConstants.APPC_FLOW_CONTROLLER;
- try (InputStream propStream = new FileInputStream(propFile)) {
+ 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) {
+ 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);
+ props.load(propStream);
- } catch (Exception e) {
- throw new Exception("Could not load properties file " + propFile, e);
- }
- return props;
+ } catch (Exception e) {
+ throw new Exception("Could not load properties file " + propFile, e);
}
+ return props;
+ }
}
diff --git a/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/JsonParsingNode.java b/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/JsonParsingNode.java
index 42f38ba46..1fb6b0cd5 100644
--- a/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/JsonParsingNode.java
+++ b/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/JsonParsingNode.java
@@ -22,9 +22,14 @@
package org.onap.appc.flow.controller.node;
+import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_PARAM_RESPONSE_PREFIX;
+import static org.onap.appc.flow.controller.utils.FlowControllerConstants.OUTPUT_PARAM_ERROR_MESSAGE;
+import static org.onap.appc.flow.controller.utils.FlowControllerConstants.OUTPUT_PARAM_STATUS;
+import static org.onap.appc.flow.controller.utils.FlowControllerConstants.OUTPUT_STATUS_FAILURE;
+import static org.onap.appc.flow.controller.utils.FlowControllerConstants.OUTPUT_STATUS_SUCCESS;
+
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
-import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -32,56 +37,43 @@ import java.io.IOException;
import java.util.Map;
import java.util.Map.Entry;
import org.apache.commons.lang3.StringUtils;
-import org.onap.appc.flow.controller.utils.FlowControllerConstants;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
public class JsonParsingNode implements SvcLogicJavaPlugin {
- private static final EELFLogger log = EELFManager.getInstance().getLogger(JsonParsingNode.class);
+ private static final EELFLogger log = EELFManager.getInstance().getLogger(JsonParsingNode.class);
- public void parse(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
- String fn = "RestServiceNode.sendRequest";
- log.info("Received processParamKeys call with params : " + inParams);
- String responsePrefix = inParams.get(FlowControllerConstants.INPUT_PARAM_RESPONSE_PREFIX);
- responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
- try {
- //Remove below for Block
- JsonNode jnode = isValidJson(inParams.get("data"));
- if (jnode != null) {
- Map<String, Object> map
- = new ObjectMapper().readValue(jnode.toString(), new TypeReference<Map<String, String>>(){});
- for (Entry<String, Object> entry : map.entrySet()) {
- ctx.setAttribute(responsePrefix + entry.getKey(),(String) entry.getValue());
- }
- }
- ctx.setAttribute(responsePrefix + FlowControllerConstants.OUTPUT_PARAM_STATUS,
- FlowControllerConstants.OUTPUT_STATUS_SUCCESS);
-
- } catch (Exception e) {
- ctx.setAttribute(responsePrefix + FlowControllerConstants.OUTPUT_PARAM_STATUS,
- FlowControllerConstants.OUTPUT_STATUS_FAILURE);
- ctx.setAttribute(responsePrefix + FlowControllerConstants.OUTPUT_PARAM_ERROR_MESSAGE,
- e.getMessage());
- log.error(fn + " Error Message : " + e.getMessage(), e);
- throw new SvcLogicException(e.getMessage());
- }
- }
+ public void parse(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
+ String fn = "RestServiceNode.sendRequest";
+ log.info("Received processParamKeys call with params : " + inParams);
+ String responsePrefix = inParams.get(INPUT_PARAM_RESPONSE_PREFIX);
+ responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
+ try {
+ String json = inParams.get("data");
+ log.info("Received response from Interface " + json);
+ JsonNode node = JsonValidator.validate(json);
- private JsonNode isValidJson(String json) throws IOException {
- JsonNode output;
- log.info("Received response from Interface " + json);
- if (json == null || json.isEmpty()) {
- return null;
- }
- try {
- ObjectMapper objectMapper = new ObjectMapper();
- output = objectMapper.readTree(json);
- } catch (JsonProcessingException e) {
- log.warn("Response received from interface is not a valid JSON block" + json, e);
- return null;
+ if (node != null) {
+ Map<String, String> map = convertToMap(node);
+ for (Entry<String, String> entry : map.entrySet()) {
+ ctx.setAttribute(responsePrefix + entry.getKey(), entry.getValue());
}
- return output;
+ }
+ ctx.setAttribute(responsePrefix + OUTPUT_PARAM_STATUS, OUTPUT_STATUS_SUCCESS);
+
+ } catch (Exception e) {
+ ctx.setAttribute(responsePrefix + OUTPUT_PARAM_STATUS, OUTPUT_STATUS_FAILURE);
+ ctx.setAttribute(responsePrefix + OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
+ log.error(fn + " Error Message : " + e.getMessage(), e);
+ throw new SvcLogicException(e.getMessage());
}
+ }
+
+ private Map<String, String> convertToMap(JsonNode node) throws IOException {
+ return new ObjectMapper().readValue(node.toString(), new TypeReference<Map<String, String>>() {
+ });
+ }
+
}
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 c94816937..32525c587 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
@@ -126,7 +126,7 @@ public class FlowControlNodeTest {
{
Map<Integer, Transaction> transactionMap = new HashMap<Integer,Transaction>();
SvcLogicContext ctx = new SvcLogicContext();
- Whitebox.invokeMethod(f, "exeuteAllTransaction",transactionMap, ctx);
+ Whitebox.invokeMethod(f, "executeAllTransaction",transactionMap, ctx);
}
@Test