diff options
author | George, Lina (lg941u) <lg941u@att.com> | 2019-02-07 11:33:37 -0500 |
---|---|---|
committer | Patrick Brady <patrick.brady@att.com> | 2019-02-08 16:58:52 +0000 |
commit | 899c2f1520b1ec529bf6b4faef6623ea566634dd (patch) | |
tree | 85e92286f1a52bb22a22651d71c142746cbcacee /appc-config/appc-flow-controller | |
parent | 3188cd1b2770159eca5de4fbb64a5d1c90aa803e (diff) |
Changes to config bundle for vnf level enhancement
Issue-ID: APPC-1380
Change-Id: Icfdc202a4763b7e708007573505e5b3be9d1454e
Signed-off-by: George, Lina (lg941u) <lg941u@att.com>
Diffstat (limited to 'appc-config/appc-flow-controller')
12 files changed, 731 insertions, 636 deletions
diff --git a/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/ResponseHandlerImpl/DefaultResponseHandler.java b/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/ResponseHandlerImpl/DefaultResponseHandler.java index 4c37a7afa..95740e9cc 100644 --- a/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/ResponseHandlerImpl/DefaultResponseHandler.java +++ b/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/ResponseHandlerImpl/DefaultResponseHandler.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP : APPC * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,28 +21,33 @@ package org.onap.appc.flow.controller.ResponseHandlerImpl; +import org.apache.commons.lang3.StringUtils; import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; import org.onap.appc.flow.controller.data.Response; import org.onap.appc.flow.controller.data.ResponseAction; import org.onap.appc.flow.controller.data.Transaction; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; public class DefaultResponseHandler { private static final EELFLogger log = EELFManager.getInstance().getLogger(DefaultResponseHandler.class); - public ResponseAction handlerResponse(Transaction transaction) { + public ResponseAction handlerResponse(Transaction transaction, SvcLogicContext ctx) { log.info("Transaction Input params " + transaction.toString()); ResponseAction responseAction = new ResponseAction(); if (transaction.getResponses() != null && !transaction.getResponses().isEmpty()) { for (Response response : transaction.getResponses()) { - if (response.getResponseCode() != null - && response.getResponseCode().equals(transaction.getStatusCode())) { + if ((StringUtils.isNotBlank(ctx.getAttribute("error-code")) + && !StringUtils.equals(ctx.getAttribute("error-code"), "400")) + || ((StringUtils.isNotBlank(transaction.getStatusCode())) + && !StringUtils.equals(transaction.getStatusCode(), "400"))) { + responseAction = response.getResponseAction(); break; } } } - return responseAction ; + return responseAction; } } diff --git a/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/interfaceData/Capabilities.java b/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/interfaceData/Capabilities.java index 3ee2ceb49..200fbde2a 100644 --- a/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/interfaceData/Capabilities.java +++ b/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/interfaceData/Capabilities.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP : APPC * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,11 +25,12 @@ // Generated on: 2017.07.31 at 10:30:39 AM EDT // - package org.onap.appc.flow.controller.interfaceData; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; @@ -40,14 +41,8 @@ import javax.xml.bind.annotation.XmlType; import com.fasterxml.jackson.annotation.JsonProperty; - @XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "", propOrder = { - "vnf", - "vfModule", - "vm", - "vnfc" -}) +@XmlType(name = "", propOrder = { "vnf", "vfModule", "vm", "vnfc" }) @XmlRootElement(name = "capabilities") public class Capabilities { @@ -60,7 +55,7 @@ public class Capabilities { protected List<String> vfModule; @XmlList @XmlElement(required = true) - protected List<String> vm; + protected Map<String, List<String>> vm; @XmlList @XmlElement(required = true) protected List<String> vnfc; @@ -69,21 +64,21 @@ public class Capabilities { * Gets the value of the vnf property. * * <p> - * This accessor method returns a reference to the live list, - * not a snapshot. Therefore any modification you make to the - * returned list will be present inside the JAXB object. - * This is why there is not a <CODE>set</CODE> method for the vnf property. + * This accessor method returns a reference to the live list, not a snapshot. + * Therefore any modification you make to the returned list will be present + * inside the JAXB object. This is why there is not a <CODE>set</CODE> method + * for the vnf property. * * <p> * For example, to add a new item, do as follows: + * * <pre> - * getVnf().add(newItem); + * getVnf().add(newItem); * </pre> * * * <p> - * Objects of the following type(s) are allowed in the list - * {@link String } + * Objects of the following type(s) are allowed in the list {@link String } * * */ @@ -98,21 +93,21 @@ public class Capabilities { * Gets the value of the vfModule property. * * <p> - * This accessor method returns a reference to the live list, - * not a snapshot. Therefore any modification you make to the - * returned list will be present inside the JAXB object. - * This is why there is not a <CODE>set</CODE> method for the vfModule property. + * This accessor method returns a reference to the live list, not a snapshot. + * Therefore any modification you make to the returned list will be present + * inside the JAXB object. This is why there is not a <CODE>set</CODE> method + * for the vfModule property. * * <p> * For example, to add a new item, do as follows: + * * <pre> - * getVfModule().add(newItem); + * getVfModule().add(newItem); * </pre> * * * <p> - * Objects of the following type(s) are allowed in the list - * {@link String } + * Objects of the following type(s) are allowed in the list {@link String } * * */ @@ -127,27 +122,27 @@ public class Capabilities { * Gets the value of the vm property. * * <p> - * This accessor method returns a reference to the live list, - * not a snapshot. Therefore any modification you make to the - * returned list will be present inside the JAXB object. - * This is why there is not a <CODE>set</CODE> method for the vm property. + * This accessor method returns a reference to the live list, not a snapshot. + * Therefore any modification you make to the returned list will be present + * inside the JAXB object. This is why there is not a <CODE>set</CODE> method + * for the vm property. * * <p> * For example, to add a new item, do as follows: + * * <pre> - * getVm().add(newItem); + * getVm().add(newItem); * </pre> * * * <p> - * Objects of the following type(s) are allowed in the list - * {@link String } + * Objects of the following type(s) are allowed in the list {@link Map} * * */ - public List<String> getVm() { + public Map<String, List<String>> getVm() { if (vm == null) { - vm = new ArrayList<String>(); + vm = new HashMap<String, List<String>>(); } return this.vm; } @@ -156,21 +151,21 @@ public class Capabilities { * Gets the value of the vnfc property. * * <p> - * This accessor method returns a reference to the live list, - * not a snapshot. Therefore any modification you make to the - * returned list will be present inside the JAXB object. - * This is why there is not a <CODE>set</CODE> method for the vnfc property. + * This accessor method returns a reference to the live list, not a snapshot. + * Therefore any modification you make to the returned list will be present + * inside the JAXB object. This is why there is not a <CODE>set</CODE> method + * for the vnfc property. * * <p> * For example, to add a new item, do as follows: + * * <pre> - * getVnfc().add(newItem); + * getVnfc().add(newItem); * </pre> * * * <p> - * Objects of the following type(s) are allowed in the list - * {@link String } + * Objects of the following type(s) are allowed in the list {@link String } * * */ @@ -183,8 +178,7 @@ public class Capabilities { @Override public String toString() { - return "Capabilities [vnf=" + vnf + ", vfModule=" + vfModule + ", vm=" - + vm + ", vnfc=" + vnfc + "]"; + return "Capabilities [vnf=" + vnf + ", vfModule=" + vfModule + ", vm=" + vm + ", vnfc=" + vnfc + "]"; } } diff --git a/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/interfaceData/Vnfcslist.java b/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/interfaceData/Vnfcslist.java index 110c89201..4c83ce6fe 100644 --- a/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/interfaceData/Vnfcslist.java +++ b/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/interfaceData/Vnfcslist.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP : APPC * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,7 +25,6 @@ // Generated on: 2017.07.31 at 10:30:39 AM EDT // - package org.onap.appc.flow.controller.interfaceData; import javax.xml.bind.annotation.XmlAccessType; @@ -35,11 +34,13 @@ import javax.xml.bind.annotation.XmlType; import com.fasterxml.jackson.annotation.JsonProperty; - /** - * <p>Java class for vnfcslist complex type. + * <p> + * Java class for vnfcslist complex type. * - * <p>The following schema fragment specifies the expected content contained within this class. + * <p> + * The following schema fragment specifies the expected content contained within + * this class. * * <pre> * <complexType name="vnfcslist"> @@ -57,10 +58,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; * */ @XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "vnfcslist", propOrder = { - "vnfcType", - "vnfcName" -}) +@XmlType(name = "vnfcslist", propOrder = { "vnfcType", "vnfcName" }) public class Vnfcslist { @XmlElement(name = "vnfc-type", required = true) @@ -69,13 +67,14 @@ public class Vnfcslist { @XmlElement(name = "vnfc-name", required = true) @JsonProperty("vnfc-name") protected String vnfcName; + @XmlElement(name = "vnfc-function-code", required = true) + @JsonProperty("vnfc-function-code") + protected String vnfcFunctionCode; /** * Gets the value of the vnfcType property. * - * @return - * possible object is - * {@link String } + * @return possible object is {@link String } * */ public String getVnfcType() { @@ -86,8 +85,7 @@ public class Vnfcslist { * Sets the value of the vnfcType property. * * @param value - * allowed object is - * {@link String } + * allowed object is {@link String } * */ public void setVnfcType(String value) { @@ -97,9 +95,7 @@ public class Vnfcslist { /** * Gets the value of the vnfcName property. * - * @return - * possible object is - * {@link String } + * @return possible object is {@link String } * */ public String getVnfcName() { @@ -110,17 +106,37 @@ public class Vnfcslist { * Sets the value of the vnfcName property. * * @param value - * allowed object is - * {@link String } + * allowed object is {@link String } * */ public void setVnfcName(String value) { this.vnfcName = value; } + /** + * Gets the value of the vnfcFunctionCode property. + * + * @return possible object is {@link String } + * + */ + public String getVnfcFunctionCode() { + return vnfcFunctionCode; + } + + /** + * Sets the value of the vnfcName property. + * + * @param value + * allowed object is {@link String } + * + */ + public void setVnfcFunctionCode(String value) { + this.vnfcFunctionCode = value; + } + @Override public String toString() { - return "Vnfcslist [vnfcType=" + vnfcType + ", vnfcName=" + vnfcName + return "Vnfcslist [vnfcType=" + vnfcType + ", vnfcName=" + vnfcName + ", vnfcFunctionCode=" + vnfcFunctionCode + "]"; } 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 index b740e4feb..a98d3268e 100644 --- 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 @@ -3,6 +3,7 @@ * ONAP : APPC * ================================================================================ * Copyright (C) 2018 Nokia. All rights reserved. + * Copyright (C) 2019 AT&T intellectual property. All rights reserved. * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,7 +33,13 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.apache.commons.lang3.StringUtils; import org.onap.appc.flow.controller.dbervices.FlowControlDBService; import org.onap.appc.flow.controller.interfaceData.Capabilities; import org.onap.ccsdk.sli.core.sli.SvcLogicContext; @@ -40,56 +47,80 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicException; public class CapabilitiesDataExtractor { - private static final EELFLogger log = EELFManager.getInstance().getLogger(CapabilitiesDataExtractor.class); + private static final EELFLogger log = EELFManager.getInstance().getLogger(CapabilitiesDataExtractor.class); - private final FlowControlDBService dbService; - private final ObjectMapper mapper; + private final FlowControlDBService dbService; + private final ObjectMapper mapper; - public CapabilitiesDataExtractor() { - this(FlowControlDBService.initialise()); - } + public CapabilitiesDataExtractor() { + this(FlowControlDBService.initialise()); + } - /** - * Ctor for tests, prefer to use default one - */ - public CapabilitiesDataExtractor(FlowControlDBService dbService) { - this.dbService = dbService; + /** + * 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); - } + 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 { + Capabilities getCapabilitiesData(SvcLogicContext ctx) throws SvcLogicException, IOException { - String fn = "FlowExecutorNode.getCapabilitiesData"; - String capabilitiesData = dbService.getCapabilitiesData(ctx); - log.info(fn + "capabilitiesDataInput:" + capabilitiesData); + String fn = "FlowExecutorNode.getCapabilitiesData"; + String capabilitiesData = dbService.getCapabilitiesData(ctx); + log.info(fn + ":capabilitiesDataInput:" + capabilitiesData); - Capabilities capabilities = new Capabilities(); - if (capabilitiesData == null) { - return capabilities; - } + Capabilities capabilities = new Capabilities(); + if (StringUtils.isBlank(capabilitiesData)) { + return capabilities; + } - JsonNode capabilitiesNode = mapper.readTree(capabilitiesData); - log.info("capabilitiesNode:" + capabilitiesNode.toString()); + JsonNode capabilitiesNode = mapper.readTree(capabilitiesData); + JsonNode capNode = capabilitiesNode.get("capabilities"); + 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)); + capabilities.getVfModule().addAll(extractParameterList(capNode, VF_MODULE)); + capabilities.getVnfc().addAll(extractParameterList(capNode, VNFC)); + capabilities.getVnf().addAll(extractParameterList(capNode, VNF)); + capabilities.getVm().putAll(extractParameterMap(capNode, VM)); - log.info("Capabilities Output:" + capabilities.toString()); + log.info("Capabilities Output:" + capabilities.toString()); - return capabilities; - } + return capabilities; + } - private <T> List<T> extractParameterList(JsonNode root, String parameter) throws IOException { - JsonNode parameterNode = root.get(parameter); - if (parameterNode == null) { - return new ArrayList<>(); + private List<String> 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<String>>() { + }); } - return mapper.readValue(parameterNode.toString(), new TypeReference<List<T>>() {}); - } -}
\ No newline at end of file + private HashMap<String, List<String>> extractParameterMap(JsonNode root, String parameter) throws IOException { + JsonNode parameterNode = root.get(parameter); + HashMap<String, List<String>> hm = new HashMap<>(); + if (parameterNode == null || !parameterNode.isArray()) { + return hm; + } + for (JsonNode n : parameterNode) { + Iterator<Map.Entry<String, JsonNode>> fldIter = n.fields(); + while (fldIter.hasNext()) { + Map.Entry<String, JsonNode> currentEntry = fldIter.next(); + if (currentEntry.getValue().isArray()) { + Iterator<JsonNode> nodeIter = currentEntry.getValue().elements(); + List<String> listOfT = new ArrayList<>(); + while (nodeIter.hasNext()) { + listOfT.add((nodeIter.next().asText())); + } + hm.put(currentEntry.getKey(), listOfT); + } + } + } + return hm; + } +} 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 1bbf8d0d1..34d40dd55 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 @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP : APPC * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -95,212 +95,205 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; public class FlowControlNode implements SvcLogicJavaPlugin { - private static final EELFLogger log = EELFManager.getInstance().getLogger(FlowControlNode.class); - - private final FlowControlDBService dbService; - private final FlowSequenceGenerator flowSequenceGenerator; - - public FlowControlNode() { - this.dbService = FlowControlDBService.initialise(); - this.flowSequenceGenerator = new FlowSequenceGenerator(); - } - - FlowControlNode(FlowControlDBService dbService, FlowSequenceGenerator flowSequenceGenerator) { - this.dbService = dbService; - this.flowSequenceGenerator = flowSequenceGenerator; - } - - 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); - - 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 static final EELFLogger log = EELFManager.getInstance().getLogger(FlowControlNode.class); + + private final FlowControlDBService dbService; + private final FlowSequenceGenerator flowSequenceGenerator; + + public FlowControlNode() { + this.dbService = FlowControlDBService.initialise(); + this.flowSequenceGenerator = new FlowSequenceGenerator(); } - } - - 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()); - - localContext - .getAttributeKeySet() - .forEach(key -> log.debug(key + "=" + ctx.getAttribute(key))); - - String flowSequence = flowSequenceGenerator.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"); - } - - 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); - 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; + FlowControlNode(FlowControlDBService dbService, FlowSequenceGenerator flowSequenceGenerator) { + this.dbService = dbService; + this.flowSequenceGenerator = flowSequenceGenerator; + } + + 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); + + 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()); } - if (responseAction.getJump() != null && Integer.parseInt(responseAction.getJump()) > 0) { - key = Integer.parseInt(responseAction.getJump()); - key--; + } + + 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()); + + localContext.getAttributeKeySet().forEach(key -> log.debug(key + "=" + ctx.getAttribute(key))); + + String flowSequence = flowSequenceGenerator.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"); + } + + 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, ctx); + + 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()); + } } - log.debug(fn + "key =" + key + "retry =" + retry); + } - } else { - throw new Exception("Don't know how to execute transaction ID " + transaction.getTransactionId()); - } + private void sendIntermediateMessage() { + // TODO Auto-generated method stub } - } - - 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; - } + + private ResponseAction handleResponse(Transaction transaction, SvcLogicContext ctx) { + log.info("Handling Response for transaction Id " + transaction.getTransactionId()); + DefaultResponseHandler defaultHandler = new DefaultResponseHandler(); + return defaultHandler.handlerResponse(transaction, ctx); + } + + 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; + } + } + } 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; } - } 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; } - 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); + + 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; } - return transMap; - } - private void compileFlowDependencies(Transaction transaction, SvcLogicContext localContext) - throws Exception { + private void compileFlowDependencies(Transaction transaction, SvcLogicContext localContext) throws Exception { - dbService.populateModuleAndRPC(transaction, localContext.getAttribute(VNF_TYPE)); - ObjectMapper mapper = new ObjectMapper(); - log.debug("Individual Transaction Details :" + transaction.toString()); + dbService.populateModuleAndRPC(transaction, localContext.getAttribute(VNF_TYPE)); + ObjectMapper mapper = new ObjectMapper(); + log.debug("Individual Transaction Details :" + transaction.toString()); - if ((localContext.getAttribute(SEQUENCE_TYPE) == null) - || (localContext.getAttribute(SEQUENCE_TYPE) != null - && !localContext.getAttribute(SEQUENCE_TYPE) - .equalsIgnoreCase(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); + 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 transactions } - //get a field in transction class as transactionhandle interface and register the Handler here for each trnactions - } } diff --git a/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/InventoryInfoExtractor.java b/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/InventoryInfoExtractor.java index 4e2706514..b45d6366a 100644 --- a/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/InventoryInfoExtractor.java +++ b/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/InventoryInfoExtractor.java @@ -3,7 +3,7 @@ * ONAP : APPC * ================================================================================ * Copyright (C) 2018 Nokia. All rights reserved. - * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved. * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,66 +34,65 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicContext; */ class InventoryInfoExtractor { - private static final EELFLogger log = EELFManager.getInstance().getLogger(InventoryInfoExtractor.class); + private static final EELFLogger log = EELFManager.getInstance().getLogger(InventoryInfoExtractor.class); - InventoryInfo getInventoryInfo(SvcLogicContext ctx, String vnfId) { - String fn = "InventoryInfoExtractor.getInventoryInfo"; + InventoryInfo getInventoryInfo(SvcLogicContext ctx, String vnfId) { + String fn = "InventoryInfoExtractor.getInventoryInfo"; - VnfInfo vnfInfo = new VnfInfo(); - vnfInfo.setVnfId(vnfId); - vnfInfo.setVnfName(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-name")); - vnfInfo.setVnfType(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-type")); - vnfInfo.setIdentityUrl(getIdentityUrl(ctx,vnfInfo,vnfId)); + 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")); + vnfInfo.setIdentityUrl(getIdentityUrl(ctx, vnfInfo, vnfId)); - String vmcount = ctx.getAttribute("tmp.vnfInfo.vm-count"); - log.info(fn + "vmcount:" + vmcount); + String vmcount = ctx.getAttribute("tmp.vnfInfo.vm-count"); + log.info(fn + "vmcount:" + vmcount); - int vmCount = (StringUtils.isNotBlank(vmcount)) ? Integer.parseInt(vmcount) : 0; + int vmCount = (StringUtils.isNotBlank(vmcount)) ? Integer.parseInt(vmcount) : 0; - for (int i = 0; i < vmCount; i++) { - processVm(ctx, vnfInfo, i); - } - - InventoryInfo inventoryInfo = new InventoryInfo(); - inventoryInfo.setVnfInfo(vnfInfo); - log.info(fn + "Inventory Output:" + inventoryInfo.toString()); + for (int i = 0; i < vmCount; i++) { + processVm(ctx, vnfInfo, i); + } - return inventoryInfo; - } + InventoryInfo inventoryInfo = new InventoryInfo(); + inventoryInfo.setVnfInfo(vnfInfo); + log.info(fn + "Inventory Output:" + inventoryInfo.toString()); - private void processVm(SvcLogicContext ctx, VnfInfo vnfInfo, int index) { - Vm vm = new Vm(); - vm.setVserverId(ctx.getAttribute("tmp.vnfInfo.vm[" + index + "].vserver-id")); - vm.setVmId(ctx.getAttribute("tmp.vnfInfo.vm[" + index + "].vserver-selflink")); - int vnfcCount = Integer.parseInt(ctx.getAttribute("tmp.vnfInfo.vm[" + index + "].vnfc-count")); - if (vnfcCount > 0) { - Vnfcslist vnfc = new Vnfcslist(); - vnfc.setVnfcName(ctx.getAttribute("tmp.vnfInfo.vm[" + index + "].vnfc-name")); - vnfc.setVnfcType(ctx.getAttribute("tmp.vnfInfo.vm[" + index + "].vnfc-type")); - vm.setVnfc(vnfc); + return inventoryInfo; } - vnfInfo.getVm().add(vm); - } + private void processVm(SvcLogicContext ctx, VnfInfo vnfInfo, int index) { + Vm vm = new Vm(); + vm.setVserverId(ctx.getAttribute("tmp.vnfInfo.vm[" + index + "].vserver-id")); + vm.setVmId(ctx.getAttribute("tmp.vnfInfo.vm[" + index + "].vserver-selflink")); + int vnfcCount = Integer.parseInt(ctx.getAttribute("tmp.vnfInfo.vm[" + index + "].vnfc-count")); + if (vnfcCount > 0) { + Vnfcslist vnfc = new Vnfcslist(); + vnfc.setVnfcName(ctx.getAttribute("tmp.vnfInfo.vm[" + index + "].vnfc-name")); + vnfc.setVnfcType(ctx.getAttribute("tmp.vnfInfo.vm[" + index + "].vnfc-type")); + vnfc.setVnfcFunctionCode(ctx.getAttribute("tmp.vnfInfo.vm[" + index + "].vnfc-function-code")); + vm.setVnfc(vnfc); + } + vnfInfo.getVm().add(vm); + } - public String getIdentityUrl(SvcLogicContext ctx, VnfInfo vnfInfo, String vnfId) { - String identityUrl = ""; - for (String key : ctx.getAttributeKeySet()) { + public String getIdentityUrl(SvcLogicContext ctx, VnfInfo vnfInfo, String vnfId) { + String identityUrl = ""; + for (String key : ctx.getAttributeKeySet()) { log.debug("InventoryData " + key + "=" + ctx.getAttribute(key)); - } - String urlFromPayload= ctx.getAttribute("identity-url"); - log.info("Url from payload:" + urlFromPayload); - String urlFromAAI=ctx.getAttribute("tmp.vnfInfo.cloud-region.identity-url"); - log.info("Url from AAI:" + urlFromAAI); + } + String urlFromPayload = ctx.getAttribute("identity-url"); + log.info("Url from payload:" + urlFromPayload); + String urlFromAAI = ctx.getAttribute("tmp.vnfInfo.cloud-region.identity-url"); + log.info("Url from AAI:" + urlFromAAI); + + if (StringUtils.isNotBlank(urlFromPayload)) { + identityUrl = urlFromPayload; + } else if (StringUtils.isNotBlank(urlFromAAI)) { + identityUrl = urlFromAAI; + } + return identityUrl; - if(StringUtils.isNotBlank(urlFromPayload)){ - identityUrl=urlFromPayload; - }else if(StringUtils.isNotBlank(urlFromAAI)){ - identityUrl=urlFromAAI; - } - return identityUrl; - - - } + } } 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 bd5144004..051d22fc6 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 @@ -4,7 +4,7 @@ * ================================================================================ * Copyright (C) 2018 Nokia. All rights reserved. * ================================================================================ - * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved. * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,6 +24,7 @@ package org.onap.appc.flow.controller.node; import static org.onap.appc.flow.controller.utils.FlowControllerConstants.HTTP; import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_CONTEXT; import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_HOST_IP_ADDRESS; +import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_HOST_IP_ADDRESS_ALT; import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_REQUEST_ACTION; import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_URL; import static org.onap.appc.flow.controller.utils.FlowControllerConstants.REST_PORT; @@ -57,6 +58,8 @@ class ResourceUriExtractor { private String getAddress(SvcLogicContext ctx) { String address = ctx.getAttribute(INPUT_HOST_IP_ADDRESS); + if (address == null || address.length() == 0) + address = ctx.getAttribute(INPUT_HOST_IP_ADDRESS_ALT); String port = ctx.getAttribute(REST_PORT); return HTTP + address + ":" + port; } diff --git a/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/utils/FlowControllerConstants.java b/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/utils/FlowControllerConstants.java index fee6b677a..c4000dfe1 100644 --- a/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/utils/FlowControllerConstants.java +++ b/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/utils/FlowControllerConstants.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP : APPC * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -61,9 +61,13 @@ public class FlowControllerConstants { public static final String ACTION_LEVEL = "action-level"; public static final String ARTIFACT_NAME = "artifact-name"; - public enum EndPointType { DG, REST, NODE } + public enum EndPointType { + DG, REST, NODE + } - public enum FlowStatus { PENDING, IN_PROCESS, COMPLETED } + public enum FlowStatus { + PENDING, IN_PROCESS, COMPLETED + } public static final String GENERATION_NODE = "GENERATION-NODE"; public static final String SEQUENCE_TYPE = "SEQUENCE-TYPE"; @@ -98,6 +102,7 @@ public class FlowControllerConstants { public static final String HEALTHY = "healthy"; public static final String INPUT_URL = "input.url"; public static final String INPUT_HOST_IP_ADDRESS = "request-parameters.host-ip-address"; + public static final String INPUT_HOST_IP_ADDRESS_ALT = "host-ip-address"; public static final String INPUT_PORT_NUMBER = "port-number"; public static final String INPUT_CONTEXT = "context"; public static final String INPUT_SUB_CONTEXT = "sub-context"; @@ -116,9 +121,9 @@ public class FlowControllerConstants { public static final String VNFC_NAME = "vnfc-name"; public static final String AAI_VNF_TYPE = "aai-vnf-type"; public static final String REST_PROTOCOL = "REST"; - public static final String HEALTHCHECK ="HealthCheck"; - public static final String REST_USER="user"; - public static final String REST_PWD="pwd"; - public static final String REST_PORT="port"; - public static final String REST_CONTEXT_URL="url"; + public static final String HEALTHCHECK = "HealthCheck"; + public static final String REST_USER = "user"; + public static final String REST_PWD = "pwd"; + public static final String REST_PORT = "port"; + public static final String REST_CONTEXT_URL = "url"; } diff --git a/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/ResponseHandlerImpl/DefaultResponseHandlerTest.java b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/ResponseHandlerImpl/DefaultResponseHandlerTest.java index dc5e2553c..14c513dfc 100644 --- a/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/ResponseHandlerImpl/DefaultResponseHandlerTest.java +++ b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/ResponseHandlerImpl/DefaultResponseHandlerTest.java @@ -3,6 +3,7 @@ * ONAP : APPC * ================================================================================ * Copyright (C) 2018 Nokia. + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,20 +28,23 @@ import org.junit.Test; import org.onap.appc.flow.controller.data.Response; import org.onap.appc.flow.controller.data.ResponseAction; import org.onap.appc.flow.controller.data.Transaction; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; public class DefaultResponseHandlerTest { @Test public void handlerResponse_shouldReturnEmptyResponseAction_whenTransactionResponsesAreNull() { Transaction transaction = new Transaction(); - assertExpectedResponseAction(transaction, new ResponseAction()); + SvcLogicContext ctx = new SvcLogicContext(); + assertExpectedResponseAction(transaction, new ResponseAction(), ctx); } @Test public void handlerResponse_shouldReturnEmptyResponseAction_whenTransactionResponsesAreEmpty() { Transaction transaction = new Transaction(); transaction.setResponses(Collections.emptyList()); - assertExpectedResponseAction(transaction, new ResponseAction()); + SvcLogicContext ctx = new SvcLogicContext(); + assertExpectedResponseAction(transaction, new ResponseAction(), ctx); } @Test @@ -49,14 +53,12 @@ public class DefaultResponseHandlerTest { ResponseAction expectedResponseAction = createExpectedResponseAction(); String responseCode = "404"; + SvcLogicContext ctx = new SvcLogicContext(); Transaction transaction = new Transaction(); transaction.setStatusCode(responseCode); - transaction.setResponses(Lists.newArrayList( - createResponse(null, null), - createResponse(null, "500"), - createResponse(expectedResponseAction, responseCode))); + transaction.setResponses(Lists.newArrayList(createResponse(expectedResponseAction, responseCode))); - assertExpectedResponseAction(transaction, expectedResponseAction); + assertExpectedResponseAction(transaction, expectedResponseAction, ctx); } private ResponseAction createExpectedResponseAction() { @@ -72,14 +74,16 @@ public class DefaultResponseHandlerTest { private Response createResponse(ResponseAction expectedResponseAction, String responseCode) { Response response = new Response(); + response.setResponseMessage("failure"); response.setResponseCode(responseCode); response.setResponseAction(expectedResponseAction); return response; } - private void assertExpectedResponseAction(Transaction transaction, ResponseAction expectedResponseAction) { + private void assertExpectedResponseAction(Transaction transaction, ResponseAction expectedResponseAction, + SvcLogicContext ctx) { // WHEN - ResponseAction responseAction = new DefaultResponseHandler().handlerResponse(transaction); + ResponseAction responseAction = new DefaultResponseHandler().handlerResponse(transaction, ctx); // THEN assertEquals(expectedResponseAction.isIntermediateMessage(), responseAction.isIntermediateMessage()); diff --git a/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/CapabilitiesDataExtractorTest.java b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/CapabilitiesDataExtractorTest.java index c373840ab..1c0fe87a4 100644 --- a/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/CapabilitiesDataExtractorTest.java +++ b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/CapabilitiesDataExtractorTest.java @@ -3,6 +3,7 @@ * ONAP : APPC * ================================================================================ * Copyright (C) 2018 Nokia. All rights reserved. + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,38 +32,52 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicContext; public class CapabilitiesDataExtractorTest { - private CapabilitiesDataExtractor capabilitiesDataExtractor; - private FlowControlDBService dbService; - private SvcLogicContext ctx; + private CapabilitiesDataExtractor capabilitiesDataExtractor; + private FlowControlDBService dbService; + private SvcLogicContext ctx; - @Before - public void setUp() { - dbService = mock(FlowControlDBService.class); - ctx = mock(SvcLogicContext.class); - capabilitiesDataExtractor = new CapabilitiesDataExtractor(dbService); - } + @Before + public void setUp() { + dbService = mock(FlowControlDBService.class); + ctx = mock(SvcLogicContext.class); + capabilitiesDataExtractor = new CapabilitiesDataExtractor(dbService); + } - @Test - public void should_handle_capabilities_full_config() throws Exception { + @Test + public void should_handle_capabilities_full_config() throws Exception { - String jsonPayload = "{'vnf':['vnf-1', 'vnf-2'],'vf-module':['vf-module-1', 'vf-module-2'],'vnfc':['vnfc-1', 'vnfc-2'],'vm':['vm-1', 'vm-2']}"; - when(dbService.getCapabilitiesData(ctx)).thenReturn(jsonPayload.replaceAll("'","\"")); + String jsonPayload = "{'capabilities':{'vnfc':[],'vm':[{'AttachVolume':[]},{'DetachVolume':[]},{'Evacuate':['pld','ssc']},{'Migrate':['pld','ssc']},{'Reboot':['pld','ssc']},{'Rebuild':['pld','ssc']},{'Restart':['pld','ssc']},{'Snapshot':['pld','ssc']},{'Start':['pld','ssc']},{'Stop':['pld','ssc']}],'vf-module':[],'vnf':['Configure','AllAction','ConfigModify','OpenStack Actions']}}"; + when(dbService.getCapabilitiesData(ctx)).thenReturn(jsonPayload.replaceAll("'", "\"")); - Capabilities capabilitiesData = capabilitiesDataExtractor.getCapabilitiesData(ctx); + Capabilities capabilitiesData = capabilitiesDataExtractor.getCapabilitiesData(ctx); + Assert.assertEquals( + "Capabilities [vnf=[Configure, AllAction, ConfigModify, OpenStack Actions], vfModule=[], vm={Evacuate=[pld, ssc], DetachVolume=[], Snapshot=[pld, ssc], AttachVolume=[], Start=[pld, ssc], Stop=[pld, ssc], Migrate=[pld, ssc], Restart=[pld, ssc], Reboot=[pld, ssc], Rebuild=[pld, ssc]}, vnfc=[]]", + capabilitiesData.toString()); + } - Assert.assertEquals("Capabilities [vnf=[vnf-1, vnf-2], vfModule=[vf-module-1, vf-module-2], vm=[vm-1, vm-2], vnfc=[vnfc-1, vnfc-2]]", capabilitiesData.toString()); - } + @Test + public void should_handle_capabilities_config_with_missing_params1() throws Exception { - @Test - public void should_handle_capabilities_config_with_missing_params() throws Exception { + // CASE: vm is empty, vnfc is absent + String jsonPayload = "{'capabilities':{'vnf':['vnf-1', 'vnf-2'],'vf-module':['vf-module-1'],'vm':[]}}"; + when(dbService.getCapabilitiesData(ctx)).thenReturn(jsonPayload.replaceAll("'", "\"")); - // CASE: vm is empty, vnfc is absent - String jsonPayload = "{'vnf':['vnf-1', 'vnf-2'],'vf-module':['vf-module-1'],'vm':[]}"; - when(dbService.getCapabilitiesData(ctx)).thenReturn(jsonPayload.replaceAll("'","\"")); + Capabilities capabilitiesData = capabilitiesDataExtractor.getCapabilitiesData(ctx); - Capabilities capabilitiesData = capabilitiesDataExtractor.getCapabilitiesData(ctx); + Assert.assertEquals("Capabilities [vnf=[vnf-1, vnf-2], vfModule=[vf-module-1], vm={}, vnfc=[]]", + capabilitiesData.toString()); + } - Assert.assertEquals("Capabilities [vnf=[vnf-1, vnf-2], vfModule=[vf-module-1], vm=[], vnfc=[]]", capabilitiesData.toString()); - } + @Test + public void should_handle_capabilities_config_with_missing_params2() throws Exception { -}
\ No newline at end of file + // CASE: vm has action+vnfc format, vf-module is empty, vnfc is absent + String jsonPayload = "{'capabilities':{'vnf':['vnf-1', 'vnf-2'],'vf-module':[],'vm':[{'AttachVolume':['vnfc-1']}]}}"; + when(dbService.getCapabilitiesData(ctx)).thenReturn(jsonPayload.replaceAll("'", "\"")); + + Capabilities capabilitiesData = capabilitiesDataExtractor.getCapabilitiesData(ctx); + + Assert.assertEquals("Capabilities [vnf=[vnf-1, vnf-2], vfModule=[], vm={AttachVolume=[vnfc-1]}, vnfc=[]]", + capabilitiesData.toString()); + } +} diff --git a/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/InputParamsCollectorTest.java b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/InputParamsCollectorTest.java index 951c38dc5..6d1141459 100644 --- a/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/InputParamsCollectorTest.java +++ b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/InputParamsCollectorTest.java @@ -3,7 +3,7 @@ * ONAP : APPC * ================================================================================ * Copyright (C) 2018 Nokia. All rights reserved. - * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved. * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -47,84 +47,112 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicContext; public class InputParamsCollectorTest { - private SvcLogicContext ctx; - private FlowControlDBService dbService; - private EnvVariables envVariables; - private InputParamsCollector inputParamsCollector; - - @Before - public void setUp() { - - ctx = mock(SvcLogicContext.class); - dbService = mock(FlowControlDBService.class); - envVariables = mock(EnvVariables.class); - - when(envVariables.getenv(SDNC_CONFIG_DIR_VAR)).thenReturn("./src/test/resources"); - - inputParamsCollector = new InputParamsCollector(envVariables, dbService); - } - - @Test - public void should_collect_input_params() throws Exception { - - when(ctx.getAttribute(VNF_ID)).thenReturn("some-vnf-id"); - when(ctx.getAttribute(REQUEST_ACTION)).thenReturn("some-request-action"); - when(ctx.getAttribute(ACTION_LEVEL)).thenReturn("some-action-level"); - when(ctx.getAttribute(PAYLOAD)).thenReturn("some-payload"); - when(ctx.getAttribute(VSERVER_ID)).thenReturn("some-vserver-id"); - when(ctx.getAttribute(VNFC_NAME)).thenReturn("some-vnfc-name"); - - when(dbService.getCapabilitiesData(ctx)).thenReturn( - "{'vnf':['vnf-1', 'vnf-2'],'vf-module':['vf-module-1', 'vf-module-2'],'vnfc':['vnfc-1', 'vnfc-2'],'vm':['vm-1', 'vm-2']}" - .replaceAll("'", "\"")); - when(dbService.getDependencyInfo(ctx)).thenReturn(dependencyInfoPayload()); - - Transaction transaction = inputParamsCollector.collectInputParams(ctx); - - Assert.assertEquals("{\"input\":{\"request-info\":{\"action\":\"some-request-action\",\"payload\":\"some-payload\",\"action-level\":\"some-action-level\",\"action-identifier\":{\"vnf-id\":\"some-vnf-id\",\"vserver-id\":\"some-vserver-id\",\"vnfc-name\":\"some-vnfc-name\"}},\"inventory-info\":{\"vnf-info\":{\"vnf-id\":\"some-vnf-id\",\"identity-url\":\"\",\"vm\":[]}},\"capabilities\":{\"vnf\":[\"vnf-1\",\"vnf-2\"],\"vm\":[\"vm-1\",\"vm-2\"],\"vnfc\":[\"vnfc-1\",\"vnfc-2\"],\"vf-module\":[\"vf-module-1\",\"vf-module-2\"]}}}", - transaction.getPayload()); - Assert.assertEquals("POST", transaction.getExecutionRPC()); - Assert.assertEquals("seq-generator-uid", transaction.getuId()); - Assert.assertEquals("some-pswd", transaction.getPswd()); - Assert.assertEquals("exec-endpoint", transaction.getExecutionEndPoint()); - } - - @Test - public void should_handle_dependency_config() throws Exception { - - Vnfcs vnfcs = new Vnfcs(); - vnfcs.setVnfcType("some-type"); - vnfcs.setResilience("some-resilience"); - 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); - - DependencyInfo dependencyInfo = inputParamsCollector.getDependencyInfo(ctx); - - Assert.assertEquals( - "DependencyInfo [vnfcs=[Vnfcs [vnfcType=some-type, mandatory=some-mandatory, resilience=some-resilience, parents=[]], Vnfcs [vnfcType=some-type, mandatory=some-mandatory, resilience=some-resilience, parents=[]]]]", - dependencyInfo.toString()); - } - - private String dependencyInfoPayload() throws JsonProcessingException { - Vnfcs vnfcs = new Vnfcs(); - vnfcs.setVnfcType("some-type"); - vnfcs.setResilience("some-resilience"); - 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); - - return new ObjectMapper().writeValueAsString(input); - } + private SvcLogicContext ctx; + private FlowControlDBService dbService; + private EnvVariables envVariables; + private InputParamsCollector inputParamsCollector; + + @Before + public void setUp() { + + ctx = mock(SvcLogicContext.class); + dbService = mock(FlowControlDBService.class); + envVariables = mock(EnvVariables.class); + + when(envVariables.getenv(SDNC_CONFIG_DIR_VAR)).thenReturn("./src/test/resources"); + + inputParamsCollector = new InputParamsCollector(envVariables, dbService); + } + + @Test + public void should_collect_input_params() throws Exception { + + when(ctx.getAttribute(VNF_ID)).thenReturn("some-vnf-id"); + when(ctx.getAttribute(REQUEST_ACTION)).thenReturn("some-request-action"); + when(ctx.getAttribute(ACTION_LEVEL)).thenReturn("some-action-level"); + when(ctx.getAttribute(PAYLOAD)).thenReturn("some-payload"); + when(ctx.getAttribute(VSERVER_ID)).thenReturn("some-vserver-id"); + when(ctx.getAttribute(VNFC_NAME)).thenReturn("some-vnfc-name"); + when(ctx.getAttribute("identity-url")).thenReturn("test_url"); + + when(dbService.getCapabilitiesData(ctx)).thenReturn( + "{'capabilities': { 'vnf':['vnf-1', 'vnf-2'],'vf-module':['vf-module-1', 'vf-module-2'],'vnfc':['vnfc-1', 'vnfc-2'],'vm':[{'Start':['vnfc-1','vnfc-2']},{'Stop':[]}]}}" + .replaceAll("'", "\"")); + when(dbService.getDependencyInfo(ctx)).thenReturn(dependencyInfoPayload()); + + Transaction transaction = inputParamsCollector.collectInputParams(ctx); + + Assert.assertEquals( + "{\"input\":{\"request-info\":{\"action\":\"some-request-action\",\"payload\":\"some-payload\",\"action-level\":\"some-action-level\",\"action-identifier\":{\"vnf-id\":\"some-vnf-id\",\"vserver-id\":\"some-vserver-id\",\"vnfc-name\":\"some-vnfc-name\"}},\"inventory-info\":{\"vnf-info\":{\"vnf-id\":\"some-vnf-id\",\"identity-url\":\"test_url\",\"vm\":[]}},\"capabilities\":{\"vnf\":[\"vnf-1\",\"vnf-2\"],\"vm\":{\"Start\":[\"vnfc-1\",\"vnfc-2\"],\"Stop\":[]},\"vnfc\":[\"vnfc-1\",\"vnfc-2\"],\"vf-module\":[\"vf-module-1\",\"vf-module-2\"]}}}", + transaction.getPayload()); + Assert.assertEquals("POST", transaction.getExecutionRPC()); + Assert.assertEquals("seq-generator-uid", transaction.getuId()); + Assert.assertEquals("some-pswd", transaction.getPswd()); + Assert.assertEquals("exec-endpoint", transaction.getExecutionEndPoint()); + } + + @Test + public void should_handle_dependency_config() throws Exception { + + Vnfcs vnfcs = new Vnfcs(); + vnfcs.setVnfcType("some-type"); + vnfcs.setResilience("some-resilience"); + 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); + + DependencyInfo dependencyInfo = inputParamsCollector.getDependencyInfo(ctx); + + Assert.assertEquals( + "DependencyInfo [vnfcs=[Vnfcs [vnfcType=some-type, mandatory=some-mandatory, resilience=some-resilience, parents=[]], Vnfcs [vnfcType=some-type, mandatory=some-mandatory, resilience=some-resilience, parents=[]]]]", + dependencyInfo.toString()); + } + + @Test + public void should_collect_input_params_null_caps() throws Exception { + + when(ctx.getAttribute(VNF_ID)).thenReturn("some-vnf-id"); + when(ctx.getAttribute(REQUEST_ACTION)).thenReturn("some-request-action"); + when(ctx.getAttribute(ACTION_LEVEL)).thenReturn("some-action-level"); + when(ctx.getAttribute(PAYLOAD)).thenReturn("some-payload"); + when(ctx.getAttribute(VSERVER_ID)).thenReturn("some-vserver-id"); + when(ctx.getAttribute(VNFC_NAME)).thenReturn("some-vnfc-name"); + when(ctx.getAttribute("identity-url")).thenReturn("test_url"); + + when(dbService.getCapabilitiesData(ctx)).thenReturn(null); + + when(dbService.getDependencyInfo(ctx)).thenReturn(dependencyInfoPayload()); + + Transaction transaction = inputParamsCollector.collectInputParams(ctx); + + Assert.assertEquals( + "{\"input\":{\"request-info\":{\"action\":\"some-request-action\",\"payload\":\"some-payload\",\"action-level\":\"some-action-level\",\"action-identifier\":{\"vnf-id\":\"some-vnf-id\",\"vserver-id\":\"some-vserver-id\",\"vnfc-name\":\"some-vnfc-name\"}},\"inventory-info\":{\"vnf-info\":{\"vnf-id\":\"some-vnf-id\",\"identity-url\":\"test_url\",\"vm\":[]}},\"capabilities\":{\"vnf\":[],\"vm\":{},\"vnfc\":[],\"vf-module\":[]}}}", + transaction.getPayload()); + Assert.assertEquals("POST", transaction.getExecutionRPC()); + Assert.assertEquals("seq-generator-uid", transaction.getuId()); + Assert.assertEquals("some-pswd", transaction.getPswd()); + Assert.assertEquals("exec-endpoint", transaction.getExecutionEndPoint()); + } + + private String dependencyInfoPayload() throws JsonProcessingException { + Vnfcs vnfcs = new Vnfcs(); + vnfcs.setVnfcType("some-type"); + vnfcs.setResilience("some-resilience"); + 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); + + return new ObjectMapper().writeValueAsString(input); + } } diff --git a/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/InventoryInfoExtractorTest.java b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/InventoryInfoExtractorTest.java index 022f31742..aad6dcec0 100644 --- a/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/InventoryInfoExtractorTest.java +++ b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/InventoryInfoExtractorTest.java @@ -3,7 +3,7 @@ * ONAP : APPC * ================================================================================ * Copyright (C) 2018 Nokia. All rights reserved. - * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved. * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,167 +32,169 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicContext; public class InventoryInfoExtractorTest { - private SvcLogicContext ctx; - private InventoryInfoExtractor inventoryInfoExtractor; - - @Before - public void setUp() { - inventoryInfoExtractor = new InventoryInfoExtractor(); - ctx = mock(SvcLogicContext.class); - } - - @Test - public void full_config() throws Exception { - when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-name")).thenReturn("some-vnf-name"); - when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-type")).thenReturn("some-vnf-type"); - when(ctx.getAttribute("tmp.vnfInfo.vm-count")).thenReturn("2"); - - when(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-id")).thenReturn("some-id-0"); - when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-count")).thenReturn("2"); - when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-name")).thenReturn("some-vnfc-name-0"); - when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-type")).thenReturn("some-vnfc-type-0"); - - when(ctx.getAttribute("tmp.vnfInfo.vm[1].vserver-id")).thenReturn("some-id-1"); - when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-count")).thenReturn("1"); - when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-name")).thenReturn("some-vnfc-name-1"); - when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-type")).thenReturn("some-vnfc-type-1"); - - when(ctx.getAttribute("tmp.vnfInfo.cloud-region.identity-url")).thenReturn("some-url"); - - String vnfId = "some-vnf-id"; - InventoryInfo inventoryInfo = inventoryInfoExtractor.getInventoryInfo(ctx, vnfId); - - Assert.assertEquals( - "InventoryInfo [vnfInfo=VnfInfo [vnfId=some-vnf-id, vnfName=some-vnf-name, vnfType=some-vnf-type, " + - "identityUrl=some-url, vm=[Vm [vserverId=some-id-0, vmId=null, " + - "vnfc=Vnfcslist [vnfcType=some-vnfc-type-0, vnfcName=some-vnfc-name-0]], Vm [vserverId=some-id-1, vmId=null, vnfc=Vnfcslist [vnfcType=some-vnfc-type-1, vnfcName=some-vnfc-name-1]]]]]", - inventoryInfo.toString()); - } - - @Test - public void full_config__with_zero__vnfc_count() throws Exception { - when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-name")).thenReturn("some-vnf-name"); - when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-type")).thenReturn("some-vnf-type"); - when(ctx.getAttribute("tmp.vnfInfo.vm-count")).thenReturn("2"); - when(ctx.getAttribute("tmp.vnfInfo.cloud-region.identity-url")).thenReturn("some-url"); - - when(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-id")).thenReturn("some-id-0"); - when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-count")).thenReturn("2"); - when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-name")).thenReturn("some-vnfc-name-0"); - when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-type")).thenReturn("some-vnfc-type-0"); - - when(ctx.getAttribute("tmp.vnfInfo.vm[1].vserver-id")).thenReturn("some-id-1"); - when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-count")).thenReturn("0"); - when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-name")).thenReturn("some-vnfc-name-1"); - when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-type")).thenReturn("some-vnfc-type-1"); - - String vnfId = "some-vnf-id"; - InventoryInfo inventoryInfo = inventoryInfoExtractor.getInventoryInfo(ctx, vnfId); - - Assert.assertEquals( - "InventoryInfo [vnfInfo=VnfInfo [vnfId=some-vnf-id, vnfName=some-vnf-name, " - + "vnfType=some-vnf-type, identityUrl=some-url, vm=[Vm [vserverId=some-id-0, " - + "vmId=null, vnfc=Vnfcslist [vnfcType=some-vnfc-type-0, vnfcName=some-vnfc-name-0]], " - + "Vm [vserverId=some-id-1, vmId=null, vnfc=null]]]]", - inventoryInfo.toString()); - } - - @Test - public void full_config__with_zero__vm_count() throws Exception { - when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-name")).thenReturn("some-vnf-name"); - when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-type")).thenReturn("some-vnf-type"); - when(ctx.getAttribute("tmp.vnfInfo.vm-count")).thenReturn("0"); - when(ctx.getAttribute("tmp.vnfInfo.cloud-region.identity-url")).thenReturn("some-url"); - - - when(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-id")).thenReturn("some-id-0"); - when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-count")).thenReturn("2"); - when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-name")).thenReturn("some-vnfc-name-0"); - when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-type")).thenReturn("some-vnfc-type-0"); - - when(ctx.getAttribute("tmp.vnfInfo.vm[1].vserver-id")).thenReturn("some-id-1"); - when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-count")).thenReturn("0"); - when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-name")).thenReturn("some-vnfc-name-1"); - when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-type")).thenReturn("some-vnfc-type-1"); - - String vnfId = "some-vnf-id"; - InventoryInfo inventoryInfo = inventoryInfoExtractor.getInventoryInfo(ctx, vnfId); - - Assert.assertEquals("InventoryInfo [vnfInfo=VnfInfo [vnfId=some-vnf-id, vnfName=some-vnf-name, " - + "vnfType=some-vnf-type, identityUrl=some-url, vm=null]]", - inventoryInfo.toString()); - } - - @Test - public void full_config__with_empty__vm_count() throws Exception { - when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-name")).thenReturn("some-vnf-name"); - when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-type")).thenReturn("some-vnf-type"); - when(ctx.getAttribute("tmp.vnfInfo.vm-count")).thenReturn(""); - when(ctx.getAttribute("tmp.vnfInfo.cloud-region.identity-url")).thenReturn("some-url"); - - when(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-id")).thenReturn("some-id-0"); - when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-count")).thenReturn("2"); - when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-name")).thenReturn("some-vnfc-name-0"); - when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-type")).thenReturn("some-vnfc-type-0"); - - when(ctx.getAttribute("tmp.vnfInfo.vm[1].vserver-id")).thenReturn("some-id-1"); - when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-count")).thenReturn("0"); - when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-name")).thenReturn("some-vnfc-name-1"); - when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-type")).thenReturn("some-vnfc-type-1"); - - String vnfId = "some-vnf-id"; - InventoryInfo inventoryInfo = inventoryInfoExtractor.getInventoryInfo(ctx, vnfId); - - Assert.assertEquals( - "InventoryInfo [vnfInfo=VnfInfo [vnfId=some-vnf-id, vnfName=some-vnf-name, " - + "vnfType=some-vnf-type, identityUrl=some-url, vm=null]]", - inventoryInfo.toString()); - } - - @Test - public void full_config__with_null__vm_count() throws Exception { - when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-name")).thenReturn("some-vnf-name"); - when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-type")).thenReturn("some-vnf-type"); - when(ctx.getAttribute("tmp.vnfInfo.vm-count")).thenReturn(null); - when(ctx.getAttribute("tmp.vnfInfo.cloud-region.identity-url")).thenReturn("some-url"); - - when(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-id")).thenReturn("some-id-0"); - when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-count")).thenReturn("2"); - when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-name")).thenReturn("some-vnfc-name-0"); - when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-type")).thenReturn("some-vnfc-type-0"); - - when(ctx.getAttribute("tmp.vnfInfo.vm[1].vserver-id")).thenReturn("some-id-1"); - when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-count")).thenReturn("0"); - when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-name")).thenReturn("some-vnfc-name-1"); - when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-type")).thenReturn("some-vnfc-type-1"); - - String vnfId = "some-vnf-id"; - InventoryInfo inventoryInfo = inventoryInfoExtractor.getInventoryInfo(ctx, vnfId); - - Assert.assertEquals( - "InventoryInfo [vnfInfo=VnfInfo [vnfId=some-vnf-id, vnfName=some-vnf-name, " - + "vnfType=some-vnf-type, identityUrl=some-url, vm=null]]", - inventoryInfo.toString()); - } - - @Test - public void testGetIdentityUrl_from_payload() throws Exception{ - InventoryInfoExtractor info = new InventoryInfoExtractor(); - when(ctx.getAttribute("identity-url")).thenReturn("some_url"); - VnfInfo vnfInfo = new VnfInfo(); - String url=info.getIdentityUrl(ctx, vnfInfo, "123"); - System.out.println(info.toString()); - Assert.assertEquals(url, "some_url"); - } - - @Test - public void testGetIdentityUrl_from_Inventory() throws Exception{ - InventoryInfoExtractor info = new InventoryInfoExtractor(); - when(ctx.getAttribute("tmp.vnfInfo.cloud-region.identity-url")).thenReturn("some_url_from_inventory"); - VnfInfo vnfInfo = new VnfInfo(); - String url=info.getIdentityUrl(ctx, vnfInfo, "123"); - System.out.println(info.toString()); - Assert.assertEquals(url, "some_url_from_inventory"); - } + private SvcLogicContext ctx; + private InventoryInfoExtractor inventoryInfoExtractor; + + @Before + public void setUp() { + inventoryInfoExtractor = new InventoryInfoExtractor(); + ctx = mock(SvcLogicContext.class); + } + + @Test + public void full_config() throws Exception { + when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-name")).thenReturn("some-vnf-name"); + when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-type")).thenReturn("some-vnf-type"); + when(ctx.getAttribute("tmp.vnfInfo.vm-count")).thenReturn("2"); + when(ctx.getAttribute("tmp.vnfInfo.cloud-region.identity-url")).thenReturn("some-url"); + + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-id")).thenReturn("some-id-0"); + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-count")).thenReturn("2"); + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-name")).thenReturn("some-vnfc-name-0"); + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-type")).thenReturn("some-vnfc-type-0"); + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-function-code")).thenReturn("some-vnfc-function-code-0"); + + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vserver-id")).thenReturn("some-id-1"); + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-count")).thenReturn("1"); + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-name")).thenReturn("some-vnfc-name-1"); + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-type")).thenReturn("some-vnfc-type-1"); + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-function-code")).thenReturn("some-vnfc-function-code-1"); + + String vnfId = "some-vnf-id"; + InventoryInfo inventoryInfo = inventoryInfoExtractor.getInventoryInfo(ctx, vnfId); + + Assert.assertEquals( + "InventoryInfo [vnfInfo=VnfInfo [vnfId=some-vnf-id, vnfName=some-vnf-name, vnfType=some-vnf-type, identityUrl=some-url, vm=[Vm [vserverId=some-id-0, vmId=null, vnfc=Vnfcslist [vnfcType=some-vnfc-type-0, vnfcName=some-vnfc-name-0, vnfcFunctionCode=some-vnfc-function-code-0]], Vm [vserverId=some-id-1, vmId=null, vnfc=Vnfcslist [vnfcType=some-vnfc-type-1, vnfcName=some-vnfc-name-1, vnfcFunctionCode=some-vnfc-function-code-1]]]]]", + inventoryInfo.toString()); + // System.out.println("New inventory info"+inventoryInfo.toString()); + } + + @Test + public void full_config__with_zero__vnfc_count() throws Exception { + when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-name")).thenReturn("some-vnf-name"); + when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-type")).thenReturn("some-vnf-type"); + when(ctx.getAttribute("tmp.vnfInfo.vm-count")).thenReturn("2"); + when(ctx.getAttribute("tmp.vnfInfo.cloud-region.identity-url")).thenReturn("some-url"); + + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-id")).thenReturn("some-id-0"); + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-count")).thenReturn("2"); + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-name")).thenReturn("some-vnfc-name-0"); + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-type")).thenReturn("some-vnfc-type-0"); + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-function-code")).thenReturn("some-vnfc-function-code-0"); + + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vserver-id")).thenReturn("some-id-1"); + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-count")).thenReturn("0"); + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-name")).thenReturn("some-vnfc-name-1"); + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-type")).thenReturn("some-vnfc-type-1"); + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-function-code")).thenReturn("some-vnfc-function-code-1"); + + String vnfId = "some-vnf-id"; + InventoryInfo inventoryInfo = inventoryInfoExtractor.getInventoryInfo(ctx, vnfId); + + Assert.assertEquals( + "InventoryInfo [vnfInfo=VnfInfo [vnfId=some-vnf-id, vnfName=some-vnf-name, vnfType=some-vnf-type, identityUrl=some-url, vm=[Vm [vserverId=some-id-0, vmId=null, vnfc=Vnfcslist [vnfcType=some-vnfc-type-0, vnfcName=some-vnfc-name-0, vnfcFunctionCode=some-vnfc-function-code-0]], Vm [vserverId=some-id-1, vmId=null, vnfc=null]]]]", + inventoryInfo.toString()); + } + + @Test + public void full_config__with_zero__vm_count() throws Exception { + when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-name")).thenReturn("some-vnf-name"); + when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-type")).thenReturn("some-vnf-type"); + when(ctx.getAttribute("tmp.vnfInfo.vm-count")).thenReturn("0"); + when(ctx.getAttribute("tmp.vnfInfo.cloud-region.identity-url")).thenReturn("some-url"); + + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-id")).thenReturn("some-id-0"); + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-count")).thenReturn("2"); + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-name")).thenReturn("some-vnfc-name-0"); + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-type")).thenReturn("some-vnfc-type-0"); + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-function-code")).thenReturn("some-vnfc-function-code-0"); + + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vserver-id")).thenReturn("some-id-1"); + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-count")).thenReturn("0"); + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-name")).thenReturn("some-vnfc-name-1"); + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-type")).thenReturn("some-vnfc-type-1"); + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-function-code")).thenReturn("some-vnfc-function-code-1"); + + String vnfId = "some-vnf-id"; + InventoryInfo inventoryInfo = inventoryInfoExtractor.getInventoryInfo(ctx, vnfId); + + Assert.assertEquals( + "InventoryInfo [vnfInfo=VnfInfo [vnfId=some-vnf-id, vnfName=some-vnf-name, vnfType=some-vnf-type, identityUrl=some-url, vm=null]]", + inventoryInfo.toString()); + } + + @Test + public void full_config__with_empty__vm_count() throws Exception { + when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-name")).thenReturn("some-vnf-name"); + when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-type")).thenReturn("some-vnf-type"); + when(ctx.getAttribute("tmp.vnfInfo.vm-count")).thenReturn(""); + when(ctx.getAttribute("tmp.vnfInfo.cloud-region.identity-url")).thenReturn("some-url"); + + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-id")).thenReturn("some-id-0"); + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-count")).thenReturn("2"); + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-name")).thenReturn("some-vnfc-name-0"); + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-type")).thenReturn("some-vnfc-type-0"); + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-function-code")).thenReturn("some-vnfc-function-code-0"); + + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vserver-id")).thenReturn("some-id-1"); + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-count")).thenReturn("0"); + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-name")).thenReturn("some-vnfc-name-1"); + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-type")).thenReturn("some-vnfc-type-1"); + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-function-code")).thenReturn("some-vnfc-function-code-1"); + + String vnfId = "some-vnf-id"; + InventoryInfo inventoryInfo = inventoryInfoExtractor.getInventoryInfo(ctx, vnfId); + + Assert.assertEquals( + "InventoryInfo [vnfInfo=VnfInfo [vnfId=some-vnf-id, vnfName=some-vnf-name, vnfType=some-vnf-type, identityUrl=some-url, vm=null]]", + inventoryInfo.toString()); + } + + @Test + public void full_config__with_null__vm_count() throws Exception { + when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-name")).thenReturn("some-vnf-name"); + when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-type")).thenReturn("some-vnf-type"); + when(ctx.getAttribute("tmp.vnfInfo.vm-count")).thenReturn(null); + when(ctx.getAttribute("tmp.vnfInfo.cloud-region.identity-url")).thenReturn("some-url"); + + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-id")).thenReturn("some-id-0"); + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-count")).thenReturn("2"); + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-name")).thenReturn("some-vnfc-name-0"); + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-type")).thenReturn("some-vnfc-type-0"); + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-function-code")).thenReturn("some-vnfc-function-code-0"); + + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vserver-id")).thenReturn("some-id-1"); + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-count")).thenReturn("0"); + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-name")).thenReturn("some-vnfc-name-1"); + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-type")).thenReturn("some-vnfc-type-1"); + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-function-code")).thenReturn("some-vnfc-function-code-1"); + + String vnfId = "some-vnf-id"; + InventoryInfo inventoryInfo = inventoryInfoExtractor.getInventoryInfo(ctx, vnfId); + + Assert.assertEquals( + "InventoryInfo [vnfInfo=VnfInfo [vnfId=some-vnf-id, vnfName=some-vnf-name, vnfType=some-vnf-type, identityUrl=some-url, vm=null]]", + inventoryInfo.toString()); + } + + @Test + public void testGetIdentityUrl_from_payload() throws Exception { + InventoryInfoExtractor info = new InventoryInfoExtractor(); + when(ctx.getAttribute("identity-url")).thenReturn("some_url"); + VnfInfo vnfInfo = new VnfInfo(); + String url = info.getIdentityUrl(ctx, vnfInfo, "123"); + System.out.println(info.toString()); + Assert.assertEquals(url, "some_url"); + } + + @Test + public void testGetIdentityUrl_from_Inventory() throws Exception { + InventoryInfoExtractor info = new InventoryInfoExtractor(); + when(ctx.getAttribute("tmp.vnfInfo.cloud-region.identity-url")).thenReturn("some_url_from_inventory"); + VnfInfo vnfInfo = new VnfInfo(); + String url = info.getIdentityUrl(ctx, vnfInfo, "123"); + System.out.println(info.toString()); + Assert.assertEquals(url, "some_url_from_inventory"); + } } |