From 781b1a6df324419c846c84ea983c18fc8362bfd3 Mon Sep 17 00:00:00 2001 From: Patrick Brady Date: Wed, 13 Dec 2017 11:19:06 -0800 Subject: Third part of onap rename This part of the commit changes the folder structure on all other folders of appc. Change-Id: I8acfa11cdfcdcd36be0e137245d1dd7324f1abd3 Signed-off-by: Patrick Brady Issue-ID: APPC-13 --- .../org/onap/appc/seqgen/SequenceGenerator.java | 43 +++ .../seqgen/dgplugin/SequenceGeneratorPlugin.java | 31 ++ .../dgplugin/impl/SequenceGeneratorPluginImpl.java | 243 ++++++++++++++ .../appc/seqgen/impl/SequenceGeneratorFactory.java | 54 ++++ .../appc/seqgen/impl/StartSequenceGenerator.java | 275 ++++++++++++++++ .../appc/seqgen/impl/StopSequenceGenerator.java | 183 +++++++++++ .../onap/appc/seqgen/objects/ActionIdentifier.java | 63 ++++ .../org/onap/appc/seqgen/objects/Constants.java | 123 +++++++ .../onap/appc/seqgen/objects/PreCheckOption.java | 74 +++++ .../org/onap/appc/seqgen/objects/RequestInfo.java | 72 +++++ .../appc/seqgen/objects/RequestInfoBuilder.java | 76 +++++ .../org/onap/appc/seqgen/objects/Response.java | 65 ++++ .../seqgen/objects/SequenceGeneratorInput.java | 93 ++++++ .../objects/SequenceGeneratorInputBuilder.java | 85 +++++ .../org/onap/appc/seqgen/objects/Transaction.java | 142 +++++++++ .../seqgen/provider/SequenceGeneratorProvider.java | 352 +++++++++++++++++++++ .../impl/rev170706/SequenceGeneratorModule.java | 51 +++ .../rev170706/SequenceGeneratorModuleFactory.java | 33 ++ .../impl/rev170706/SequenceGeneratorModule.java | 51 --- .../rev170706/SequenceGeneratorModuleFactory.java | 33 -- .../openecomp/appc/seqgen/SequenceGenerator.java | 43 --- .../seqgen/dgplugin/SequenceGeneratorPlugin.java | 31 -- .../dgplugin/impl/SequenceGeneratorPluginImpl.java | 243 -------------- .../appc/seqgen/impl/SequenceGeneratorFactory.java | 54 ---- .../appc/seqgen/impl/StartSequenceGenerator.java | 275 ---------------- .../appc/seqgen/impl/StopSequenceGenerator.java | 183 ----------- .../appc/seqgen/objects/ActionIdentifier.java | 63 ---- .../openecomp/appc/seqgen/objects/Constants.java | 123 ------- .../appc/seqgen/objects/PreCheckOption.java | 74 ----- .../openecomp/appc/seqgen/objects/RequestInfo.java | 72 ----- .../appc/seqgen/objects/RequestInfoBuilder.java | 76 ----- .../openecomp/appc/seqgen/objects/Response.java | 65 ---- .../seqgen/objects/SequenceGeneratorInput.java | 93 ------ .../objects/SequenceGeneratorInputBuilder.java | 85 ----- .../openecomp/appc/seqgen/objects/Transaction.java | 142 --------- .../seqgen/provider/SequenceGeneratorProvider.java | 352 --------------------- .../appc/seqgen/TestSequenceGeneratorPlugin.java | 272 ++++++++++++++++ .../appc/seqgen/TestSequenceGeneratorPlugin.java | 272 ---------------- 38 files changed, 2330 insertions(+), 2330 deletions(-) create mode 100644 appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/SequenceGenerator.java create mode 100644 appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/dgplugin/SequenceGeneratorPlugin.java create mode 100644 appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/dgplugin/impl/SequenceGeneratorPluginImpl.java create mode 100644 appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/impl/SequenceGeneratorFactory.java create mode 100644 appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/impl/StartSequenceGenerator.java create mode 100644 appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/impl/StopSequenceGenerator.java create mode 100644 appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/objects/ActionIdentifier.java create mode 100644 appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/objects/Constants.java create mode 100644 appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/objects/PreCheckOption.java create mode 100644 appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/objects/RequestInfo.java create mode 100644 appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/objects/RequestInfoBuilder.java create mode 100644 appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/objects/Response.java create mode 100644 appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/objects/SequenceGeneratorInput.java create mode 100644 appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/objects/SequenceGeneratorInputBuilder.java create mode 100644 appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/objects/Transaction.java create mode 100644 appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/provider/SequenceGeneratorProvider.java create mode 100644 appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/opendaylight/yang/gen/v1/org/onap/appc/sequencegenerator/impl/rev170706/SequenceGeneratorModule.java create mode 100644 appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/opendaylight/yang/gen/v1/org/onap/appc/sequencegenerator/impl/rev170706/SequenceGeneratorModuleFactory.java delete mode 100644 appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/opendaylight/yang/gen/v1/org/openecomp/appc/sequencegenerator/impl/rev170706/SequenceGeneratorModule.java delete mode 100644 appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/opendaylight/yang/gen/v1/org/openecomp/appc/sequencegenerator/impl/rev170706/SequenceGeneratorModuleFactory.java delete mode 100644 appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/SequenceGenerator.java delete mode 100644 appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/dgplugin/SequenceGeneratorPlugin.java delete mode 100644 appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/dgplugin/impl/SequenceGeneratorPluginImpl.java delete mode 100644 appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/impl/SequenceGeneratorFactory.java delete mode 100644 appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/impl/StartSequenceGenerator.java delete mode 100644 appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/impl/StopSequenceGenerator.java delete mode 100644 appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/objects/ActionIdentifier.java delete mode 100644 appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/objects/Constants.java delete mode 100644 appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/objects/PreCheckOption.java delete mode 100644 appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/objects/RequestInfo.java delete mode 100644 appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/objects/RequestInfoBuilder.java delete mode 100644 appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/objects/Response.java delete mode 100644 appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/objects/SequenceGeneratorInput.java delete mode 100644 appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/objects/SequenceGeneratorInputBuilder.java delete mode 100644 appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/objects/Transaction.java delete mode 100644 appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/provider/SequenceGeneratorProvider.java create mode 100644 appc-sequence-generator/appc-sequence-generator-bundle/src/test/java/org/onap/appc/seqgen/TestSequenceGeneratorPlugin.java delete mode 100644 appc-sequence-generator/appc-sequence-generator-bundle/src/test/java/org/openecomp/appc/seqgen/TestSequenceGeneratorPlugin.java (limited to 'appc-sequence-generator/appc-sequence-generator-bundle') diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/SequenceGenerator.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/SequenceGenerator.java new file mode 100644 index 000000000..709e4e31b --- /dev/null +++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/SequenceGenerator.java @@ -0,0 +1,43 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APP-C + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.seqgen; + + +import org.onap.appc.dg.objects.VnfcFlowModel; +import org.onap.appc.exceptions.APPCException; +import org.onap.appc.seqgen.objects.SequenceGeneratorInput; +import org.onap.appc.seqgen.objects.Transaction; + +import java.util.List; +import java.util.Map; + +/** + * Sequence Generator API generates runtime sequence for LCM operations execution + */ +public interface SequenceGenerator { + /** + * + * @param input Sequence Generator Input containing request info, vnf capabilites and tunable parameters + * @return returns runtime sequence for LCM operation execution + * @throws APPCException + */ + List generateSequence(SequenceGeneratorInput input) throws APPCException; +} diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/dgplugin/SequenceGeneratorPlugin.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/dgplugin/SequenceGeneratorPlugin.java new file mode 100644 index 000000000..26260d22f --- /dev/null +++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/dgplugin/SequenceGeneratorPlugin.java @@ -0,0 +1,31 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APP-C + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.seqgen.dgplugin; + +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; + +import java.util.Map; + +public interface SequenceGeneratorPlugin extends SvcLogicJavaPlugin{ + + void generateSequence(Map params, SvcLogicContext context); +} diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/dgplugin/impl/SequenceGeneratorPluginImpl.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/dgplugin/impl/SequenceGeneratorPluginImpl.java new file mode 100644 index 000000000..c0ea4134c --- /dev/null +++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/dgplugin/impl/SequenceGeneratorPluginImpl.java @@ -0,0 +1,243 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APP-C + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.seqgen.dgplugin.impl; + + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.apache.commons.lang3.StringUtils; +import org.onap.appc.dg.objects.*; +import org.onap.appc.domainmodel.Vnf; +import org.onap.appc.domainmodel.Vnfc; +import org.onap.appc.domainmodel.Vserver; +import org.onap.appc.domainmodel.lcm.VNFOperation; +import org.onap.appc.exceptions.APPCException; +import org.onap.appc.seqgen.SequenceGenerator; +import org.onap.appc.seqgen.dgplugin.SequenceGeneratorPlugin; +import org.onap.appc.seqgen.impl.SequenceGeneratorFactory; +import org.onap.appc.seqgen.objects.Constants; +import org.onap.appc.seqgen.objects.SequenceGeneratorInput; +import org.onap.appc.seqgen.objects.Transaction; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; + +import java.io.IOException; +import java.util.*; + +public class SequenceGeneratorPluginImpl implements SequenceGeneratorPlugin { + + private static final EELFLogger logger = EELFManager.getInstance().getLogger(SequenceGeneratorPluginImpl.class); + + @Override + public void generateSequence(Map params, SvcLogicContext context) { + ObjectMapper objectMapper = new ObjectMapper(); + String inputJSON = context.getAttribute("inputJSON"); + logger.debug("Input to Sequence Generator " + inputJSON); + try { + SequenceGeneratorInput sequenceGeneratorInput = buildSequenceGeneratorInput(inputJSON); + List sequence = generateSequence(sequenceGeneratorInput); + String output = objectMapper.writeValueAsString(sequence); + logger.debug("Sequence Generator Output " + output); + + context.setAttribute("output", output); + } catch (Exception e) { + logger.error("Error generating sequence", e); + context.setAttribute("error-code", "401"); + context.setAttribute("error-message", "Error generating sequence " + e.getMessage()); + } + } + + private SequenceGeneratorInput buildSequenceGeneratorInput(String inputJson) throws IOException, APPCException { + ObjectMapper objectMapper = new ObjectMapper(); + SequenceGeneratorInput sequenceGeneratorInput ; + objectMapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true); + objectMapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true); + sequenceGeneratorInput = objectMapper.readValue(inputJson, SequenceGeneratorInput.class); + + InventoryModel inventoryModel = buildInventoryModel(inputJson); + sequenceGeneratorInput.setInventoryModel(inventoryModel); + + VnfcDependencyModel dependencyModel = buildDependencyModel(inputJson); + sequenceGeneratorInput.setDependencyModel(dependencyModel); + + return sequenceGeneratorInput; + } + private List generateSequence(SequenceGeneratorInput sequenceGeneratorInput) throws APPCException { + if (sequenceGeneratorInput.getRequestInfo() == null) { + throw new APPCException("Request info is not provided in the input"); + } + String action = sequenceGeneratorInput.getRequestInfo().getAction(); + VNFOperation operation = VNFOperation.findByString(action); + if (operation == null) { + throw new APPCException("Invalid Action " + action); + } + SequenceGenerator sequenceGenerator = SequenceGeneratorFactory.getInstance().createSequenceGenerator(operation); + return sequenceGenerator.generateSequence(sequenceGeneratorInput); + } + + // Dependency model is an optional attribute and may contain null values + private VnfcDependencyModel buildDependencyModel(String inputJson) throws IOException, APPCException { + Set> dependency = new HashSet<>(); + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true); + JsonNode rootNode = objectMapper.readTree(inputJson); + JsonNode vnfcs = getVnfcsNode(rootNode); + if (vnfcs != null) { + for (JsonNode vnfcNode : vnfcs) { + String vnfcType = readVnfcType(vnfcNode); + String mandatory = readMandatory(vnfcNode); + String resilience = readResilience(vnfcNode); + Vnfc vnfc = new Vnfc(vnfcType, resilience, null, Boolean.parseBoolean(mandatory)); + Node currentNode = getNode(dependency, vnfcType); + if (currentNode == null) { + currentNode = new Node<>(vnfc); + dependency.add(currentNode); + } else { + currentNode.getChild().setMandatory(Boolean.valueOf(mandatory)); + currentNode.getChild().setResilienceType(resilience); + } + JsonNode parents = vnfcNode.get("parents"); + for (JsonNode parent : parents) { + String parentVnfcType = parent.asText(); + Node parentNode = getNode(dependency, parentVnfcType); + if (parentNode != null) { + currentNode.addParent(parentNode.getChild()); + } else { + Vnfc parentVnfc = new Vnfc(parentVnfcType, null, null, false); + parentNode = new Node<>(parentVnfc); + currentNode.addParent(parentVnfc); + dependency.add(parentNode); + } + } + + } + return new VnfcDependencyModel(dependency); + } + return null; + } + + private String readResilience(JsonNode vnfcNode) { + String resilience = null; + if (vnfcNode.get("resilience") != null) { + resilience = vnfcNode.get("resilience").asText(); + } + return resilience; + } + + private String readMandatory(JsonNode vnfcNode) { + String mandatory ; + JsonNode mandatoryNode = vnfcNode.get("mandatory"); + if (mandatoryNode == null) { + mandatory = "false"; + } else { + mandatory = mandatoryNode.asText(); + } + return mandatory; + } + + private String readVnfcType(JsonNode vnfcNode) throws APPCException { + JsonNode vnfcTypeNode = vnfcNode.get(Constants.VNFC_TYPE); + if (vnfcTypeNode == null) { + throw new APPCException("vnfc-type is not available in dependency info"); + } + return vnfcTypeNode.asText(); + } + + private JsonNode getVnfcsNode(JsonNode rootNode) { + JsonNode dependencyInfo = rootNode.get("dependency-info"); + JsonNode vnfcs = null; + if (dependencyInfo != null) { + vnfcs = dependencyInfo.get("vnfcs"); + } + return vnfcs; + } + + private Node getNode(Set> dependency, String vnfcType) { + for (Node node : dependency) { + if (node.getChild().getVnfcType().equals(vnfcType)) { + return node; + } + } + return null; + } + + private InventoryModel buildInventoryModel(String inputJson) throws IOException, APPCException { + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true); + JsonNode jsonNode = objectMapper.readTree(inputJson); + JsonNode inventoryInfo = jsonNode.get("inventory-info"); + if (inventoryInfo == null) { + throw new APPCException("inventory-info is not provided in the input"); + } + JsonNode vnfInfo = inventoryInfo.get("vnf-info"); + if (vnfInfo == null) { + throw new APPCException("vnf-info is not provided in the input"); + } + + String vnfId = vnfInfo.get("vnf-id").asText(); + String vnfType = vnfInfo.get("vnf-type").asText(); + String vnfVersion = vnfInfo.get("vnf-version").asText(); + + Vnf vnf = new Vnf(vnfId, vnfType, vnfVersion); + + JsonNode vms = vnfInfo.get("vm"); + + Map> vfcs = new HashMap<>(); + for (JsonNode vm : vms) { + if(vm.get("vserver-id")== null){ + throw new APPCException("vserver-id not found "); + } + String vserverId = vm.get("vserver-id").asText(); + Vserver vserver = new Vserver(null, null, vserverId, null, null); + JsonNode vnfc = vm.get("vnfc"); + if (vnfc.get("vnfc-name") == null) { + throw new APPCException("vnfc-name not found for vserver " + vserverId); + } + String vnfcName = vnfc.get("vnfc-name").asText(); + if (vnfc.get("vnfc-type") == null) { + throw new APPCException("vnfc-type not found for vserver " + vserverId); + } + String vnfcType = vnfc.get("vnfc-type").asText(); + if (StringUtils.isEmpty(vnfcType)) { + throw new APPCException("vserver " + vserverId + " is not associated with any vnfc"); + } + Vnfc vfc = new Vnfc(vnfcType, null, vnfcName); + List vServers = vfcs.get(vfc); + if (vServers == null) { + vServers = new LinkedList<>(); + vfcs.put(vfc, vServers); + } + vServers.add(vserver); + } + + for (Map.Entry> entry : vfcs.entrySet()) { + Vnfc vnfc = entry.getKey(); + List vServers = vfcs.get(vnfc); + vnfc.addVms(vServers); + vnf.addVnfc(vnfc); + } + + return new InventoryModel(vnf); + } +} diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/impl/SequenceGeneratorFactory.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/impl/SequenceGeneratorFactory.java new file mode 100644 index 000000000..3c6a11962 --- /dev/null +++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/impl/SequenceGeneratorFactory.java @@ -0,0 +1,54 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APP-C + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.seqgen.impl; + +import org.onap.appc.domainmodel.lcm.VNFOperation; +import org.onap.appc.exceptions.APPCException; +import org.onap.appc.seqgen.SequenceGenerator; + +public class SequenceGeneratorFactory { + + private static class ReferenceHolder { + private static SequenceGeneratorFactory instance = new SequenceGeneratorFactory(); + private ReferenceHolder(){ + + } + } + + private SequenceGeneratorFactory(){ + + } + + public static SequenceGeneratorFactory getInstance(){ + return ReferenceHolder.instance; + } + + public SequenceGenerator createSequenceGenerator(VNFOperation operation) throws APPCException { + switch (operation){ + case Start: + return new StartSequenceGenerator(); + case Stop: + return new StopSequenceGenerator(); + default: + throw new APPCException("Sequence Generator does not support operation " + operation.name()); + } + } +} diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/impl/StartSequenceGenerator.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/impl/StartSequenceGenerator.java new file mode 100644 index 000000000..dcffaafd8 --- /dev/null +++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/impl/StartSequenceGenerator.java @@ -0,0 +1,275 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APP-C + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.seqgen.impl; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.apache.commons.lang3.StringUtils; +import org.onap.appc.dg.flowbuilder.FlowBuilder; +import org.onap.appc.dg.flowbuilder.impl.FlowBuilderFactory; +import org.onap.appc.dg.objects.FlowStrategies; +import org.onap.appc.dg.objects.InventoryModel; +import org.onap.appc.dg.objects.VnfcDependencyModel; +import org.onap.appc.dg.objects.VnfcFlowModel; +import org.onap.appc.domainmodel.Vnfc; +import org.onap.appc.domainmodel.Vserver; +import org.onap.appc.exceptions.APPCException; +import org.onap.appc.seqgen.SequenceGenerator; +import org.onap.appc.seqgen.objects.*; + +import java.util.*; + +import static org.onap.appc.seqgen.objects.Constants.*; + +public class StartSequenceGenerator implements SequenceGenerator { + + private static final EELFLogger logger = EELFManager.getInstance().getLogger(StartSequenceGenerator.class); + + private List generateSequenceWithOutDependency(SequenceGeneratorInput input) throws APPCException { + + List transactionList = new LinkedList<>(); + Integer transactionId = 1; + List invVnfcList = input.getInventoryModel().getVnf().getVnfcs(); + boolean singleTransaction=checkSingleTransaction(invVnfcList); + for (Vnfc vnfc : invVnfcList) { + List vms = vnfc.getVserverList(); + List transactionIds = new LinkedList<>(); + for (Vserver vm : vms) { + Transaction transaction = new Transaction(); + transaction.setTransactionId(transactionId); + transactionIds.add(transactionId++); + transaction.setAction(Action.START.getActionType()); + transaction.setActionLevel(ActionLevel.VM.getAction()); + ActionIdentifier actionIdentifier = new ActionIdentifier(); + actionIdentifier.setvServerId(vm.getId()); + transaction.setActionIdentifier(actionIdentifier); + transaction.setPayload(input.getRequestInfo().getPayload()); + if(!singleTransaction){ + updateResponse(transaction); + } + + transactionList.add(transaction); + } + } + return transactionList; + } + + private boolean checkSingleTransaction(List invVnfcList) { + int vServerCount=0; + for(Vnfc vnfc : invVnfcList) { + List vms = vnfc.getVserverList(); + vServerCount=vServerCount+vms.size(); + } + return vServerCount <= 1; + } + + private void updateResponse(Transaction transaction) { + Response ignoreResponse = new Response(); + ignoreResponse.setResponseMessage(ResponseMessage.FAILURE.getResponse()); + Map ignoreAction = new HashMap<>(); + ignoreAction.put(ResponseAction.IGNORE.getAction(), Boolean.TRUE.toString()); + ignoreResponse.setResponseAction(ignoreAction); + transaction.addResponse(ignoreResponse); + } + + private List generateSequenceWithDependencyModel(VnfcFlowModel flowModel, SequenceGeneratorInput input) throws APPCException { + Integer waitTime = readWaitTime(input); + Integer retryCount = readRetryCount(input); + List transactionList = new LinkedList<>(); + Integer transactionId = 1; + Iterator> itr = flowModel.getModelIterator(); + while (itr.hasNext()) { + List vnfcs = itr.next(); + for (Vnfc vnfc : vnfcs) { + List vms = vnfc.getVserverList(); + List transactionIds = new LinkedList<>(); + if(!vms.isEmpty()) { + for (Vserver vm : vms) { + Transaction transaction = new Transaction(); + transaction.setTransactionId(transactionId); + transactionIds.add(transactionId++); + transaction.setAction(Action.START.getActionType()); + transaction.setActionLevel(ActionLevel.VM.getAction()); + ActionIdentifier actionIdentifier = new ActionIdentifier(); + actionIdentifier.setvServerId(vm.getId()); + transaction.setActionIdentifier(actionIdentifier); + transaction.setPayload(input.getRequestInfo().getPayload()); + updateResponse(transaction); + transactionList.add(transaction); + } + boolean startApplicationSupported = readApplicationStartCapability(input); + if (startApplicationSupported) { + Transaction startAppTransaction = new Transaction(); + startAppTransaction.setTransactionId(transactionId++); + startAppTransaction.setAction(Action.START_APPLICATION.getActionType()); + startAppTransaction.setActionLevel(ActionLevel.VNFC.getAction()); + ActionIdentifier startActionIdentifier = new ActionIdentifier(); + startActionIdentifier.setVnfcName(vnfc.getVnfcName()); + startAppTransaction.setActionIdentifier(startActionIdentifier); + startAppTransaction.setPayload(input.getRequestInfo().getPayload()); + + List preCheckOptions = new LinkedList<>(); + for (Integer vmTransactionId : transactionIds) { + setPreCheckOptions(preCheckOptions, vmTransactionId); + } + startAppTransaction.setPreCheckOperator(PreCheckOperator.ANY.getOperator()); + startAppTransaction.setPrecheckOptions(preCheckOptions); + transactionList.add(startAppTransaction); + } + boolean healthCheckSupported = readHealthCheckCapabilites(input.getCapability()); + if (healthCheckSupported) { + Transaction healthCheckTransaction = new Transaction(); + healthCheckTransaction.setTransactionId(transactionId++); + healthCheckTransaction.setAction(Action.HEALTH_CHECK.getActionType()); + healthCheckTransaction.setActionLevel(ActionLevel.VNFC.getAction()); + ActionIdentifier healthCheckActionIdentifier = new ActionIdentifier(); + healthCheckActionIdentifier.setVnfcName(vnfc.getVnfcName()); + healthCheckTransaction.setActionIdentifier(healthCheckActionIdentifier); + healthCheckTransaction.setPayload(input.getRequestInfo().getPayload()); + + Response retryResponse = new Response(); + retryResponse.setResponseMessage(ResponseMessage.UNHEALTHY.getResponse()); + Map retryAction = new HashMap<>(); + retryAction.put(ResponseAction.RETRY.getAction(), retryCount.toString()); + retryAction.put(ResponseAction.WAIT.getAction(), waitTime.toString()); + retryResponse.setResponseAction(retryAction); + healthCheckTransaction.addResponse(retryResponse); + + Response healthyResponse = new Response(); + healthyResponse.setResponseMessage(ResponseMessage.HEALTHY.getResponse()); + Map healthyAction = new HashMap<>(); + healthyAction.put(ResponseAction.CONTINUE.getAction().toLowerCase(), Boolean.TRUE.toString()); + healthyResponse.setResponseAction(healthyAction); + healthCheckTransaction.addResponse(healthyResponse); + + Response failureResponse = new Response(); + failureResponse.setResponseMessage(ResponseMessage.FAILURE.getResponse()); + Map failureResonseAction = new HashMap<>(); + failureResonseAction.put(ResponseAction.STOP.getAction(), Boolean.TRUE.toString()); + failureResponse.setResponseAction(failureResonseAction); + healthCheckTransaction.addResponse(failureResponse); + transactionList.add(healthCheckTransaction); + } + } + } + } + return transactionList; + } + + private void setPreCheckOptions(List preCheckOptions, Integer vmTransactionId) { + PreCheckOption option = new PreCheckOption(); + option.setPreTransactionId(vmTransactionId); + option.setParamName("status"); + option.setParamValue("success"); + preCheckOptions.add(option); + } + + @Override + public List generateSequence(SequenceGeneratorInput input) throws APPCException { + if(input.getRequestInfo().getActionLevel().equals(ActionLevel.VM.getAction())||input.getRequestInfo().getActionLevel().equals(ActionLevel.VNFC.getAction())|| + input.getRequestInfo().getActionLevel().equals(ActionLevel.VNF.getAction())||input.getRequestInfo().getActionLevel().equals(ActionLevel.VF_MODULE.getAction())) { + if (input.getRequestInfo().getActionLevel().equals(ActionLevel.VNF.getAction()) && input.getDependencyModel() != null) { + FlowStrategies flowStrategy = readStartFlowStrategy(input); + VnfcFlowModel flowModel = buildFlowModel(input.getInventoryModel() + , input.getDependencyModel(), flowStrategy); + logger.debug("Flow Model " + flowModel); + return generateSequenceWithDependencyModel(flowModel, input); + } else { + logger.info("Generating sequence without dependency model"); + return generateSequenceWithOutDependency(input); + } + }throw new APPCException("Invalid action level "+input.getRequestInfo().getActionLevel()); + } + + private VnfcFlowModel buildFlowModel(InventoryModel inventoryModel, VnfcDependencyModel dependencyModel, FlowStrategies flowStrategy) throws APPCException { + FlowBuilder flowBuilder = FlowBuilderFactory.getInstance().getFlowBuilder(flowStrategy); + if (flowBuilder == null) { + throw new APPCException("Flow Strategy not supported " + flowStrategy); + } + return flowBuilder.buildFlowModel(dependencyModel, inventoryModel); + } + + private FlowStrategies readStartFlowStrategy(SequenceGeneratorInput sequenceGeneratorInput) throws APPCException { + Map tunableParams = sequenceGeneratorInput.getTunableParams(); + FlowStrategies strategy; + String strategyStr = null; + if (tunableParams != null) { + strategyStr = tunableParams.get(Constants.STRATEGY); + if (StringUtils.isBlank(strategyStr)) { + return FlowStrategies.FORWARD; + } + + strategy = FlowStrategies.findByString(strategyStr); + if (strategy != null) { + return strategy; + } + } + throw new APPCException("Invalid Strategy " + strategyStr); + } + + private boolean readHealthCheckCapabilites(Map> capabilities) { + if (capabilities != null) { + List vnfcCapabilities = capabilities.get(CapabilityLevel.VNFC.getLevel()); + if (vnfcCapabilities != null) + return vnfcCapabilities.stream() + .anyMatch(p -> Capabilties.HEALTH_CHECK.getCapability().equalsIgnoreCase(p)); + } + return false; + } + + private boolean readApplicationStartCapability(SequenceGeneratorInput input) { + Map> capability = input.getCapability(); + if (capability != null) { + List vnfcCapabilities = capability.get(CapabilityLevel.VNFC.getLevel()); + if (vnfcCapabilities != null) + return vnfcCapabilities.stream().anyMatch(p -> Capabilties.START_APPLICATION.getCapability().equalsIgnoreCase(p)); + } + return false; + } + + private Integer readRetryCount(SequenceGeneratorInput input) throws APPCException { + String paramValStr = input.getTunableParams().get(RETRY_COUNT); + if (StringUtils.isEmpty(paramValStr)) { + return RETRY_COUNT_VALUE; + } + try { + return Integer.parseInt(paramValStr); + } catch (NumberFormatException e) { + String message = "Invalid Number for Retry Count " + paramValStr; + logger.error(message, e); + throw new APPCException(message); + } + } + + private Integer readWaitTime(SequenceGeneratorInput input) throws APPCException { + String paramValStr = input.getTunableParams().get(WAIT_TIME); + if (StringUtils.isEmpty(paramValStr)) { + return WAIT_TIME_VALUE; + } + try { + return Integer.parseInt(paramValStr); + } catch (NumberFormatException e) { + String message = "Invalid Number for Wait Time " + paramValStr; + logger.error(message, e); + throw new APPCException(message); + } + } +} diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/impl/StopSequenceGenerator.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/impl/StopSequenceGenerator.java new file mode 100644 index 000000000..77bee6b83 --- /dev/null +++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/impl/StopSequenceGenerator.java @@ -0,0 +1,183 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APP-C + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.seqgen.impl; + +import org.apache.commons.lang3.StringUtils; +import org.onap.appc.dg.flowbuilder.FlowBuilder; +import org.onap.appc.dg.flowbuilder.impl.FlowBuilderFactory; +import org.onap.appc.dg.objects.FlowStrategies; +import org.onap.appc.dg.objects.InventoryModel; +import org.onap.appc.dg.objects.VnfcDependencyModel; +import org.onap.appc.dg.objects.VnfcFlowModel; +import org.onap.appc.domainmodel.Vnfc; +import org.onap.appc.domainmodel.Vserver; +import org.onap.appc.exceptions.APPCException; +import org.onap.appc.seqgen.SequenceGenerator; +import org.onap.appc.seqgen.objects.*; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +import java.util.*; + +import static org.onap.appc.seqgen.objects.Constants.*; + +public class StopSequenceGenerator implements SequenceGenerator { + + private static final EELFLogger logger = EELFManager.getInstance().getLogger(StartSequenceGenerator.class); + + @Override + public List generateSequence(SequenceGeneratorInput input) throws APPCException { + if(input.getRequestInfo().getActionLevel().equals(ActionLevel.VM.getAction())||input.getRequestInfo().getActionLevel().equals(ActionLevel.VNFC.getAction())|| + input.getRequestInfo().getActionLevel().equals(ActionLevel.VNF.getAction())||input.getRequestInfo().getActionLevel().equals(ActionLevel.VF_MODULE.getAction())) { + if (input.getRequestInfo().getActionLevel().equals(ActionLevel.VNF.getAction()) && input.getDependencyModel() != null) { + FlowStrategies flowStrategy = readStopFlowStrategy(input); + VnfcFlowModel flowModel = buildFlowModel(input.getInventoryModel() + , input.getDependencyModel(), flowStrategy); + logger.debug("Flow Model " + flowModel); + return generateSequenceWithDependencyModel(flowModel, input); + } else { + logger.info("Generating sequence without dependency model"); + return generateSequenceWithOutDependency(input); + } + }throw new APPCException("Invalid action level "+input.getRequestInfo().getActionLevel()); + + } + private List generateSequenceWithOutDependency(SequenceGeneratorInput input){ + List transactionList = new LinkedList<>(); + Integer transactionId = 1; + List transactionIds = new LinkedList<>(); + List invVnfcList = input.getInventoryModel().getVnf().getVnfcs(); + boolean singleTransaction=checkSingleTransaction(invVnfcList); + for (Vnfc vnfc : invVnfcList) { + List vms = vnfc.getVserverList(); + for(Vserver vm:vms){ + Transaction transaction = new Transaction(); + transaction.setTransactionId(transactionId); + transactionIds.add(transactionId++); + transaction.setAction(Action.STOP.getActionType()); + transaction.setActionLevel(ActionLevel.VM.getAction()); + ActionIdentifier actionIdentifier = new ActionIdentifier(); + actionIdentifier.setvServerId(vm.getId()); + transaction.setActionIdentifier(actionIdentifier); + transaction.setPayload(input.getRequestInfo().getPayload()); + if(!singleTransaction){ + updateStopResponse(transaction); + } + transactionList.add(transaction); + } + } + return transactionList; + } + + private void updateStopResponse(Transaction transaction) { + Response failureResponse = new Response(); + failureResponse.setResponseMessage(ResponseMessage.FAILURE.getResponse()); + Map failureAction = new HashMap<>(); + failureAction.put(ResponseAction.IGNORE.getAction(),Boolean.TRUE.toString()); + failureResponse.setResponseAction(failureAction); + transaction.addResponse(failureResponse); + } + private boolean checkSingleTransaction(List invVnfcList) { + int vServerCount=0; + for(Vnfc vnfc : invVnfcList) { + List vms = vnfc.getVserverList(); + vServerCount=vServerCount+vms.size(); + } + return vServerCount <= 1; + } + + private List generateSequenceWithDependencyModel(VnfcFlowModel flowModel,SequenceGeneratorInput input){ + List transactionList = new LinkedList<>(); + Integer transactionId = 1; + List transactionIds = new LinkedList<>(); + Iterator> itr = flowModel.getModelIterator(); + while (itr.hasNext()){ + List vnfcs = itr.next(); + for(Vnfc vnfc:vnfcs){ + boolean stopApplicationSupported = readApplicationStopCapability(input); + if(stopApplicationSupported && !vnfc.getVserverList().isEmpty()){ + Transaction stopAppTransaction = new Transaction(); + stopAppTransaction.setTransactionId(transactionId++); + stopAppTransaction.setAction(Action.STOP_APPLICATION.getActionType()); + stopAppTransaction.setActionLevel(ActionLevel.VNFC.getAction()); + ActionIdentifier stopActionIdentifier = new ActionIdentifier(); + stopActionIdentifier .setVnfcName(vnfc.getVnfcName()); + stopAppTransaction.setActionIdentifier(stopActionIdentifier ); + stopAppTransaction.setPayload(input.getRequestInfo().getPayload()); + updateStopResponse(stopAppTransaction); + transactionList.add(stopAppTransaction); + } + List vms = vnfc.getVserverList(); + for(Vserver vm:vms){ + Transaction transaction = new Transaction(); + transaction.setTransactionId(transactionId); + transactionIds.add(transactionId++); + transaction.setAction(Action.STOP.getActionType()); + transaction.setActionLevel(ActionLevel.VM.getAction()); + ActionIdentifier actionIdentifier = new ActionIdentifier(); + actionIdentifier.setvServerId(vm.getId()); + transaction.setActionIdentifier(actionIdentifier); + transaction.setPayload(input.getRequestInfo().getPayload()); + + updateStopResponse(transaction); + transactionList.add(transaction); + } + } + } + return transactionList; + } + + private VnfcFlowModel buildFlowModel(InventoryModel inventoryModel, VnfcDependencyModel dependencyModel, FlowStrategies flowStrategy) throws APPCException { + FlowBuilder flowBuilder = FlowBuilderFactory.getInstance().getFlowBuilder(flowStrategy); + if (flowBuilder == null) { + throw new APPCException("Flow Strategy not supported " + flowStrategy); + } + return flowBuilder.buildFlowModel(dependencyModel, inventoryModel); + } + + private FlowStrategies readStopFlowStrategy(SequenceGeneratorInput sequenceGeneratorInput) throws APPCException { + Map tunableParams = sequenceGeneratorInput.getTunableParams(); + FlowStrategies strategy; + String strategyStr = null; + if (tunableParams != null) { + strategyStr = tunableParams.get(Constants.STRATEGY); + if (StringUtils.isBlank(strategyStr)) { + return FlowStrategies.REVERSE; + } + strategy = FlowStrategies.findByString(strategyStr); + if (strategy != null) { + return strategy; + } + } + throw new APPCException("Invalid Strategy " + strategyStr); + } + private boolean readApplicationStopCapability(SequenceGeneratorInput input) { + Map> capability = input.getCapability(); + if(capability!= null){ + List vnfcCapabilities = capability.get(Constants.CapabilityLevel.VNFC.getLevel()); + if(vnfcCapabilities!=null) + return vnfcCapabilities.stream().anyMatch(p -> Capabilties.STOP_APPLICATION.getCapability().equalsIgnoreCase(p)); + } + return false; + } + + +} diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/objects/ActionIdentifier.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/objects/ActionIdentifier.java new file mode 100644 index 000000000..0703edf42 --- /dev/null +++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/objects/ActionIdentifier.java @@ -0,0 +1,63 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APP-C + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.seqgen.objects; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; + +@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public class ActionIdentifier { + + @JsonProperty("vnf-id") + private String vnfId; + + @JsonProperty("vnfc-name") + private String vnfcName; + + @JsonProperty("vserver-id") + private String vServerId; + + public String getVnfId() { + return vnfId; + } + + public void setVnfId(String vnfId) { + this.vnfId = vnfId; + } + + public String getVnfcName() { + return vnfcName; + } + + public void setVnfcName(String vnfcName) { + this.vnfcName = vnfcName; + } + + public String getvServerId() { + return vServerId; + } + + public void setvServerId(String vServerId) { + this.vServerId = vServerId; + } +} diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/objects/Constants.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/objects/Constants.java new file mode 100644 index 000000000..476c5b718 --- /dev/null +++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/objects/Constants.java @@ -0,0 +1,123 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APP-C + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.seqgen.objects; + +public class Constants { + public static final String RETRY_COUNT = "retry-count"; + public static final String WAIT_TIME = "wait-time"; + public static final Integer WAIT_TIME_VALUE = 60; + public static final Integer RETRY_COUNT_VALUE = 4; + public static final String STRATEGY = "strategy"; + public static final String VNFC_TYPE = "vnfc-type"; + + public enum CapabilityLevel{ + VNF("vnf"),VNFC("vnfc"),VM("vm"); + private String level; + CapabilityLevel(String level) { + this.level=level; + } + + public String getLevel() { + return level; + } + } + + public enum Capabilties{ + START_APPLICATION("StartApplication"),HEALTH_CHECK("HealthCheck"),STOP_APPLICATION("StopApplication"); + private String capability; + + Capabilties(String capability) { + this.capability=capability; + } + public String getCapability(){ + return capability; + } + } + + public enum ResponseMessage{ + HEALTHY("healthy"),UNHEALTHY("unhealthy"),SUCCESS("success"),FAILURE("failure"); + + public String getResponse() { + return response; + } + + private String response; + ResponseMessage(String response){ + this.response=response; + } + + } + + public enum ResponseAction{ + STOP("stop"),RETRY("retry"),IGNORE("ignore"),WAIT("wait"),CONTINUE("Continue"); + + ResponseAction(String action) { + this.action=action; + } + + private String action; + + public String getAction() { + return action; + } + + } + + public enum Action{ + START("Start"),START_APPLICATION("StartApplication"),HEALTH_CHECK("HealthCheck"),STOP_APPLICATION("StopApplication"),STOP("Stop"); + + Action(String actionType) { + this.actionType=actionType; + } + + public String getActionType() { + return actionType; + } + + private String actionType; + + } + public enum ActionLevel{ + VM("vm"),VNFC("vnfc"),VNF("vnf"),VF_MODULE("vf-module"); + private String action; + ActionLevel(String action){ + this.action=action; + } + public String getAction() { + return action; + } + } + + public enum PreCheckOperator{ + ANY("any"),ALL("all"); + + PreCheckOperator(String operator){ + this.operator=operator; + } + + public String getOperator() { + return operator; + } + + private String operator; + + } +} diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/objects/PreCheckOption.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/objects/PreCheckOption.java new file mode 100644 index 000000000..00d079b00 --- /dev/null +++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/objects/PreCheckOption.java @@ -0,0 +1,74 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APP-C + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.seqgen.objects; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; + +@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public class PreCheckOption { + + @JsonProperty("pre-transactionID") + private Integer preTransactionId; + + @JsonProperty("param-name") + private String paramName; + + @JsonProperty("param-value") + private String paramValue; + + private String rule; + + + public Integer getPreTransactionId() { + return preTransactionId; + } + + public void setPreTransactionId(Integer preTransactionId) { + this.preTransactionId = preTransactionId; + } + + public String getParamName() { + return paramName; + } + + public void setParamName(String paramName) { + this.paramName = paramName; + } + + public String getParamValue() { + return paramValue; + } + + public void setParamValue(String paramValue) { + this.paramValue = paramValue; + } + + public String getRule() { + return rule; + } + + public void setRule(String rule) { + this.rule = rule; + } +} diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/objects/RequestInfo.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/objects/RequestInfo.java new file mode 100644 index 000000000..1704d274f --- /dev/null +++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/objects/RequestInfo.java @@ -0,0 +1,72 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APP-C + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.seqgen.objects; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; + +@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public class RequestInfo { + + private String action; + + @JsonProperty("action-level") + private String actionLevel; + + @JsonProperty("action-identifier") + private ActionIdentifier actionIdentifier; + + private String payload; + + public String getAction() { + return action; + } + + public void setAction(String action) { + this.action = action; + } + + public String getActionLevel() { + return actionLevel; + } + + public void setActionLevel(String actionLevel) { + this.actionLevel = actionLevel; + } + + public ActionIdentifier getActionIdentifier() { + return actionIdentifier; + } + + public void setActionIdentifier(ActionIdentifier actionIdentifier) { + this.actionIdentifier = actionIdentifier; + } + + public String getPayload() { + return payload; + } + + public void setPayload(String payload) { + this.payload = payload; + } +} diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/objects/RequestInfoBuilder.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/objects/RequestInfoBuilder.java new file mode 100644 index 000000000..4fad00013 --- /dev/null +++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/objects/RequestInfoBuilder.java @@ -0,0 +1,76 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APP-C + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.seqgen.objects; + +public class RequestInfoBuilder { + + private String action; + + private String actionLevel; + + private ActionIdentifier actionIdentifier; + + private String payload; + + public RequestInfoBuilder actionIdentifier(){ + this.actionIdentifier = new ActionIdentifier(); + return this; + } + + public RequestInfoBuilder vnfId(String vnfId){ + this.actionIdentifier.setVnfId(vnfId); + return this; + } + + public RequestInfoBuilder vnfcName(String vnfcName){ + this.actionIdentifier.setVnfcName(vnfcName); + return this; + } + + public RequestInfoBuilder vServerId(String vServerId){ + this.actionIdentifier.setvServerId(vServerId); + return this; + } + + public RequestInfoBuilder action(String action){ + this.action = action; + return this; + } + + public RequestInfoBuilder actionLevel(String actionLevel){ + this.actionLevel = actionLevel; + return this; + } + + public RequestInfoBuilder payload(String payload){ + this.payload = payload; + return this; + } + + public RequestInfo build(){ + RequestInfo requestInfo = new RequestInfo(); + requestInfo.setAction(this.action); + requestInfo.setActionIdentifier(this.actionIdentifier); + requestInfo.setActionLevel(this.actionLevel); + requestInfo.setPayload(this.payload); + return requestInfo; + } +} diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/objects/Response.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/objects/Response.java new file mode 100644 index 000000000..ba3ccd400 --- /dev/null +++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/objects/Response.java @@ -0,0 +1,65 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APP-C + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.seqgen.objects; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; + +import java.util.Map; + +@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public class Response { + + @JsonProperty("response-code") + private String responseCode; + + @JsonProperty("response-message") + private String responseMessage; + + @JsonProperty("response-action") + private Map responseAction; + + public String getResponseCode() { + return responseCode; + } + + public void setResponseCode(String responseCode) { + this.responseCode = responseCode; + } + + public String getResponseMessage() { + return responseMessage; + } + + public void setResponseMessage(String responseMessage) { + this.responseMessage = responseMessage; + } + + public Map getResponseAction() { + return responseAction; + } + + public void setResponseAction(Map responseAction) { + this.responseAction = responseAction; + } +} diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/objects/SequenceGeneratorInput.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/objects/SequenceGeneratorInput.java new file mode 100644 index 000000000..d3f6a6d14 --- /dev/null +++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/objects/SequenceGeneratorInput.java @@ -0,0 +1,93 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APP-C + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.seqgen.objects; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import org.onap.appc.dg.objects.InventoryModel; +import org.onap.appc.dg.objects.VnfcDependencyModel; + +import javax.validation.constraints.NotNull; +import java.util.List; +import java.util.Map; + +@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public class SequenceGeneratorInput { + + @NotNull + @JsonProperty("request-info") + private RequestInfo requestInfo; + + @JsonIgnore + private InventoryModel inventoryModel; + + @JsonIgnore + private VnfcDependencyModel dependencyModel; + + @JsonProperty("tunable-parameters") + private Map tunableParams; + + @JsonProperty("capabilities") + private Map> capability; + + public RequestInfo getRequestInfo() { + return requestInfo; + } + + public void setRequestInfo(RequestInfo requestInfo) { + this.requestInfo = requestInfo; + } + + public InventoryModel getInventoryModel() { + return inventoryModel; + } + + public void setInventoryModel(InventoryModel inventoryModel) { + this.inventoryModel = inventoryModel; + } + + public VnfcDependencyModel getDependencyModel() { + return dependencyModel; + } + + public void setDependencyModel(VnfcDependencyModel dependencyModel) { + this.dependencyModel = dependencyModel; + } + + public Map getTunableParams() { + return tunableParams; + } + + public void setTunableParams(Map tunableParams) { + this.tunableParams = tunableParams; + } + + public Map> getCapability() { + return capability; + } + + public void setCapability(Map> capability) { + this.capability = capability; + } +} diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/objects/SequenceGeneratorInputBuilder.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/objects/SequenceGeneratorInputBuilder.java new file mode 100644 index 000000000..66cb111b5 --- /dev/null +++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/objects/SequenceGeneratorInputBuilder.java @@ -0,0 +1,85 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APP-C + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.seqgen.objects; + +import org.onap.appc.dg.objects.InventoryModel; +import org.onap.appc.dg.objects.VnfcDependencyModel; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class SequenceGeneratorInputBuilder { + + private RequestInfo requestInfo; + + private InventoryModel inventoryModel; + + private VnfcDependencyModel dependencyModel; + + private Map tunableParams; + + private Map> capability; + + public SequenceGeneratorInputBuilder requestInfo(RequestInfo requestInfo){ + this.requestInfo = requestInfo; + return this; + } + + public SequenceGeneratorInputBuilder capability(String level,List capabilities){ + if(this.capability ==null){ + this.capability = new HashMap<>(); + } + this.capability.put(level,capabilities); + return this; + } + + public SequenceGeneratorInputBuilder tunableParameter(String key,String value){ + if(this.tunableParams ==null){ + this.tunableParams = new HashMap<>(); + } + this.tunableParams.put(key,value); + return this; + } + + public SequenceGeneratorInputBuilder inventoryModel(InventoryModel model){ + this.inventoryModel = model; + return this; + } + + public SequenceGeneratorInputBuilder dependendcyModel(VnfcDependencyModel model){ + this.dependencyModel = model; + return this; + } + + public SequenceGeneratorInput build(){ + SequenceGeneratorInput input = new SequenceGeneratorInput(); + input.setRequestInfo(this.requestInfo); + input.setCapability(this.capability); + input.setInventoryModel(this.inventoryModel); + input.setDependencyModel(this.dependencyModel); + input.setTunableParams(this.tunableParams); + return input; + } + + + +} diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/objects/Transaction.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/objects/Transaction.java new file mode 100644 index 000000000..ce45ec9e5 --- /dev/null +++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/objects/Transaction.java @@ -0,0 +1,142 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APP-C + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.seqgen.objects; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; + +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public class Transaction { + + @JsonProperty("transactionId") + private Integer transactionId; + + @JsonProperty("action") + private String action; + + @JsonProperty("action-level") + private String actionLevel; + + @JsonProperty("action-identifier") + private ActionIdentifier actionIdentifier; + + @JsonProperty("payload") + private String payload; + + @JsonProperty("parameters") + private Map parameters; + + @JsonProperty("precheck-operator") + private String preCheckOperator; + + + @JsonProperty("precheck-options") + private List precheckOptions; + + @JsonProperty("responses") + private List responses; + + public Transaction(){ + responses = new LinkedList<>(); + } + + public Integer getTransactionId() { + return transactionId; + } + + public void setTransactionId(Integer transactionId) { + this.transactionId = transactionId; + } + + public String getAction() { + return action; + } + + public void setAction(String action) { + this.action = action; + } + + public String getActionLevel() { + return actionLevel; + } + + public void setActionLevel(String actionLevel) { + this.actionLevel = actionLevel; + } + + public ActionIdentifier getActionIdentifier() { + return actionIdentifier; + } + + public void setActionIdentifier(ActionIdentifier actionIdentifier) { + this.actionIdentifier = actionIdentifier; + } + + public String getPayload() { + return payload; + } + + public void setPayload(String payload) { + this.payload = payload; + } + + public Map getParameters() { + return parameters; + } + + public void setParameters(Map parameters) { + this.parameters = parameters; + } + + public List getResponses() { + return responses; + } + + public void setResponses(List responses) { + this.responses = responses; + } + + public void addResponse(Response response){ + this.responses.add(response); + } + + public String getPreCheckOperator() { + return preCheckOperator; + } + + public void setPreCheckOperator(String preCheckOperator) { + this.preCheckOperator = preCheckOperator; + } + + public List getPrecheckOptions() { + return precheckOptions; + } + + public void setPrecheckOptions(List precheckOptions) { + this.precheckOptions = precheckOptions; + } +} diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/provider/SequenceGeneratorProvider.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/provider/SequenceGeneratorProvider.java new file mode 100644 index 000000000..ad9a68705 --- /dev/null +++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/provider/SequenceGeneratorProvider.java @@ -0,0 +1,352 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APP-C + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.seqgen.provider; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.google.common.util.concurrent.Futures; +import org.apache.commons.lang.StringUtils; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.sal.binding.api.BindingAwareBroker; +import org.opendaylight.controller.sal.binding.api.NotificationProviderService; +import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry; +import org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.rev170706.GenerateSequenceInput; +import org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.rev170706.GenerateSequenceOutput; +import org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.rev170706.GenerateSequenceOutputBuilder; +import org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.rev170706.SequenceGeneratorService; +import org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.rev170706.dependency.info.dependency.info.Vnfcs; +import org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.rev170706.inventory.info.inventory.info.vnf.info.Vm; +import org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.rev170706.response.StatusBuilder; +import org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.rev170706.response.Transactions; +import org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.rev170706.response.TransactionsBuilder; +import org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.rev170706.response.transactions.ActionIdentifier; +import org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.rev170706.response.transactions.*; +import org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.rev170706.response.transactions.responses.ResponseActionBuilder; +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.opendaylight.yangtools.yang.common.RpcResultBuilder; +import org.onap.appc.dg.objects.InventoryModel; +import org.onap.appc.dg.objects.Node; +import org.onap.appc.dg.objects.VnfcDependencyModel; +import org.onap.appc.domainmodel.Vnf; +import org.onap.appc.domainmodel.Vserver; +import org.onap.appc.domainmodel.lcm.VNFOperation; +import org.onap.appc.exceptions.APPCException; +import org.onap.appc.seqgen.SequenceGenerator; +import org.onap.appc.seqgen.impl.SequenceGeneratorFactory; +import org.onap.appc.seqgen.objects.*; + +import java.util.*; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; + + +public class SequenceGeneratorProvider implements AutoCloseable,SequenceGeneratorService{ + protected DataBroker dataBroker; + protected RpcProviderRegistry rpcRegistry; + protected NotificationProviderService notificationService; + protected BindingAwareBroker.RpcRegistration rpcRegistration; + private final EELFLogger log = EELFManager.getInstance().getLogger(SequenceGeneratorProvider.class); + private final ExecutorService executor; + private final static String APP_NAME = "SequenceGeneratorProvider"; + + public SequenceGeneratorProvider(DataBroker dataBroker2, NotificationProviderService notificationProviderService + , RpcProviderRegistry rpcRegistry2) { + log.info("Creating provider for " + APP_NAME); + executor = Executors.newFixedThreadPool(1); + this.dataBroker = dataBroker2; + this.notificationService = notificationProviderService; + + this.rpcRegistry = rpcRegistry2; + + if (this.rpcRegistry != null) { + rpcRegistration = rpcRegistry.addRpcImplementation(SequenceGeneratorService.class, this); + } + log.info("Initialization complete for " + APP_NAME); + } + + @Override + public void close() throws Exception { + log.info("Closing provider for " + APP_NAME); + if(this.executor != null){ + executor.shutdown(); + } + if(this.rpcRegistration != null){ + rpcRegistration.close(); + } + log.info("Successfully closed provider for " + APP_NAME); + } + + @Override + public Future> generateSequence(GenerateSequenceInput input) { + RpcResult rpcResult=null; + log.debug("Received input = " + input ); + try { + SequenceGenerator seqGenerator = SequenceGeneratorFactory.getInstance() + .createSequenceGenerator(VNFOperation.findByString(input.getRequestInfo().getAction().name())); + SequenceGeneratorInput seqGenInput = buildSeqGenInput(input); + List transactions = seqGenerator.generateSequence(seqGenInput); + rpcResult = buildSuccessResponse(transactions); + } catch (APPCException e) { + log.error("Error Generating Sequence",e); + rpcResult = buildFailureResponse(e.getMessage()); + } + return Futures.immediateFuture(rpcResult); + } + + private RpcResult buildSuccessResponse(List transactions) { + + List transactionList = new LinkedList<>(); + for(Transaction transaction:transactions){ + ActionIdentifier actionIdentifier = null; + if(transaction.getActionIdentifier() != null){ + actionIdentifier = new ActionIdentifierBuilder() + .setVnfId(transaction.getActionIdentifier().getVnfId()) + .setVnfcName(transaction.getActionIdentifier().getVnfcName()) + .setVserverId(transaction.getActionIdentifier().getvServerId()) + .build(); + } + + List precheckOptions = new LinkedList<>(); + if(transaction.getPrecheckOptions()!=null){ + for(PreCheckOption option:transaction.getPrecheckOptions()){ + PrecheckOptions precheckOption = new PrecheckOptionsBuilder() + .setParamName(option.getParamName()) + .setParamValue(option.getParamValue()) + .setPreTransactionId(option.getPreTransactionId()) + .setRule(option.getRule()) + .build(); + precheckOptions.add(precheckOption); + } + } + + List responseList = getResponses(transaction); + + Transactions transactionObj + = new TransactionsBuilder() + .setActionIdentifier(actionIdentifier) + .setAction(transaction.getAction()) + .setActionLevel(transaction.getActionLevel()) + .setPrecheckOperator(transaction.getPreCheckOperator()) + .setPayload(transaction.getPayload()) + .setTransactionId(transaction.getTransactionId()) + .setPrecheckOptions(precheckOptions) + .setResponses(responseList) + .build(); + transactionList.add(transactionObj); + } + + GenerateSequenceOutputBuilder builder = new GenerateSequenceOutputBuilder() + .setTransactions(transactionList); + + return RpcResultBuilder + . status(true) + .withResult(builder.build()).build(); + } + + private List getResponses(Transaction transaction) { + List responseList = new LinkedList<>(); + for(Response resp : transaction.getResponses()){ + Map responseActions = resp.getResponseAction(); + ResponseActionBuilder responseActionBuilder = new ResponseActionBuilder(); + if(responseActions.get(Constants.ResponseAction.WAIT.getAction())!=null){ + responseActionBuilder = responseActionBuilder.setWait(Integer.parseInt(responseActions.get(Constants.ResponseAction.WAIT.getAction()))); + } + if(responseActions.get(Constants.ResponseAction.RETRY.getAction())!=null){ + responseActionBuilder = responseActionBuilder.setRetry(Integer.parseInt(responseActions.get(Constants.ResponseAction.RETRY.getAction()))); + } + if(responseActions.get(Constants.ResponseAction.CONTINUE.getAction().toLowerCase())!=null){ + responseActionBuilder = responseActionBuilder + .setContinue(Boolean.parseBoolean(responseActions.get(Constants.ResponseAction.CONTINUE.getAction().toLowerCase()))); + } + if(responseActions.get(Constants.ResponseAction.IGNORE.getAction()) !=null){ + responseActionBuilder = responseActionBuilder.setIgnore(Boolean.parseBoolean(responseActions.get(Constants.ResponseAction.IGNORE.getAction()))); + } + if(responseActions.get(Constants.ResponseAction.STOP.getAction()) !=null){ + responseActionBuilder = responseActionBuilder.setStop(Boolean.parseBoolean(responseActions.get(Constants.ResponseAction.STOP.getAction()))); + } + Responses response = new ResponsesBuilder() + .setResponseMessage(resp.getResponseMessage()) + .setResponseAction(responseActionBuilder.build()) + .build(); + responseList.add(response); + } + return responseList; + } + + private SequenceGeneratorInput buildSeqGenInput(GenerateSequenceInput input) throws APPCException { + + validateMandatory(input); + + RequestInfoBuilder requestInfobuilder = new RequestInfoBuilder() + .action(input.getRequestInfo().getAction().name()) + .actionLevel(input.getRequestInfo().getActionLevel().getName().toLowerCase()) + .payload(input.getRequestInfo().getPayload()); + + if(input.getRequestInfo().getActionIdentifier() !=null){ + requestInfobuilder = requestInfobuilder + .actionIdentifier() + .vnfId(input.getRequestInfo().getActionIdentifier().getVnfId()) + .vnfcName(input.getRequestInfo().getActionIdentifier().getVnfcName()) + .vServerId(input.getRequestInfo().getActionIdentifier().getVserverId()); + } + + RequestInfo requestInfo = requestInfobuilder.build(); + + InventoryModel inventoryModel = readInventoryModel(input); + + VnfcDependencyModel dependencyModel = readDependencyModel(input); + + SequenceGeneratorInputBuilder builder = new SequenceGeneratorInputBuilder() + .requestInfo(requestInfo) + .inventoryModel(inventoryModel) + .dependendcyModel(dependencyModel); + + if(input.getCapabilities() !=null){ + if(input.getCapabilities().getVnf()!=null){ + builder = builder.capability("vnf",input.getCapabilities().getVnf()); + } + if(input.getCapabilities().getVnfc()!=null){ + builder = builder.capability("vnfc",input.getCapabilities().getVnfc()); + } + if(input.getCapabilities().getVm()!=null){ + builder = builder.capability("vm",input.getCapabilities().getVm()); + } + if(input.getCapabilities().getVfModule()!=null){ + builder = builder.capability("vf-module",input.getCapabilities().getVfModule()); + } + } + + if(input.getTunableParameters() != null){ + builder = builder.tunableParameter(Constants.RETRY_COUNT,String.valueOf(input.getTunableParameters().getRetryCount())) + .tunableParameter(Constants.WAIT_TIME,String.valueOf(input.getTunableParameters().getWaitTime())); + if(input.getTunableParameters().getStrategy() !=null){ + builder = builder.tunableParameter(Constants.STRATEGY,input.getTunableParameters().getStrategy().name()); + } + } + return builder.build(); + } + + + private void validateMandatory(GenerateSequenceInput input) throws APPCException { + if(input.getRequestInfo() ==null){ + throw new APPCException("Request Info is not present in the request"); + } + if(input.getRequestInfo().getAction() ==null){ + throw new APPCException("Action is not present in the request"); + } + if(input.getInventoryInfo() ==null){ + throw new APPCException("inventoryInfo is not provided in the input"); + } + } + + private VnfcDependencyModel readDependencyModel(GenerateSequenceInput input) { + if(input.getDependencyInfo() == null || input.getDependencyInfo().getVnfcs() ==null || input.getDependencyInfo().getVnfcs().isEmpty()){ + return null; + } + List vnfcs = input.getDependencyInfo().getVnfcs(); + Set> dependencies = new HashSet<>(); + for(Vnfcs vnfcObj:vnfcs){ + org.onap.appc.domainmodel.Vnfc vnfc; + Node currentNode = readNode(vnfcObj.getVnfcType(),dependencies); + if(currentNode == null){ + vnfc = new org.onap.appc.domainmodel.Vnfc(vnfcObj.getVnfcType(),vnfcObj.getResilience()); + currentNode = new Node<>(vnfc); + dependencies.add(currentNode); + } + else{ + currentNode.getChild().setResilienceType(vnfcObj.getResilience()); + currentNode.getChild().setMandatory(vnfcObj.isMandatory()); + } + for(String parentVnfcType:vnfcObj.getParents()){ + Node parentNode = readNode(parentVnfcType,dependencies); + if(parentNode == null){ + org.onap.appc.domainmodel.Vnfc parentVnfc = new org.onap.appc.domainmodel.Vnfc(parentVnfcType,null); + parentNode = new Node<>(parentVnfc); + currentNode.addParent(parentVnfc); + dependencies.add(parentNode); + } + else{ + currentNode.addParent(parentNode.getChild()); + } + } + } + return new VnfcDependencyModel(dependencies); + } + + private Node readNode(String vnfcType, Set> dependencies) { + for(Node node : dependencies){ + if(node.getChild().getVnfcType().equalsIgnoreCase(vnfcType)){ + return node; + } + } + return null; + } + + private InventoryModel readInventoryModel(GenerateSequenceInput input) throws APPCException { + if (input.getInventoryInfo().getVnfInfo()== null) { + throw new APPCException("vnfInfo is not provided in the input"); + } + + Vnf vnf = new Vnf(input.getInventoryInfo().getVnfInfo().getVnfId(), + input.getInventoryInfo().getVnfInfo().getVnfType(),null); + + Map> map = new HashMap<>(); + for(Vm vm:input.getInventoryInfo().getVnfInfo().getVm()){ + if(StringUtils.isBlank(vm.getVserverId())){ + throw new APPCException("vserver-id not found "); + } + if(StringUtils.isBlank(vm.getVnfc().getVnfcType())){ + throw new APPCException("vnfc-type not found for vserver " + vm.getVserverId()); + } + if(StringUtils.isBlank(vm.getVnfc().getVnfcName())){ + throw new APPCException("vnfc-name not found for vserver " + vm.getVserverId()); + } + + org.onap.appc.domainmodel.Vnfc vnfc = new org.onap.appc.domainmodel.Vnfc(vm.getVnfc().getVnfcType(),null,vm.getVnfc().getVnfcName()); + List vms = map.get(vnfc); + if(vms ==null){ + vms = new LinkedList<>(); + map.put(vnfc,vms); + } + vms.add(new Vserver(null,null,vm.getVserverId(),null,null)); + } + for(Map.Entry> entry:map.entrySet()){ + org.onap.appc.domainmodel.Vnfc vnfc = entry.getKey(); + List vmList = entry.getValue(); + vnfc.addVms(vmList); + vnf.addVnfc(vnfc); + } + return new InventoryModel(vnf); + } + + private RpcResult buildFailureResponse(String errorMessage){ + GenerateSequenceOutputBuilder sequenceGeneratorOutputBuilder=new GenerateSequenceOutputBuilder(); + StatusBuilder statusBuilder =new StatusBuilder(); + statusBuilder.setCode(401); + statusBuilder.setMessage(errorMessage); + sequenceGeneratorOutputBuilder.setStatus(statusBuilder.build()); + return RpcResultBuilder + . status(true) + .withResult(sequenceGeneratorOutputBuilder.build()) + .build(); + } +} diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/opendaylight/yang/gen/v1/org/onap/appc/sequencegenerator/impl/rev170706/SequenceGeneratorModule.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/opendaylight/yang/gen/v1/org/onap/appc/sequencegenerator/impl/rev170706/SequenceGeneratorModule.java new file mode 100644 index 000000000..9de0289ea --- /dev/null +++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/opendaylight/yang/gen/v1/org/onap/appc/sequencegenerator/impl/rev170706/SequenceGeneratorModule.java @@ -0,0 +1,51 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APP-C + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.impl.rev170706; + +import org.onap.appc.seqgen.provider.SequenceGeneratorProvider; + +public class SequenceGeneratorModule extends org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.impl.rev170706.AbstractSequenceGeneratorModule { + public SequenceGeneratorModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { + super(identifier, dependencyResolver); + } + + public SequenceGeneratorModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.impl.rev170706.SequenceGeneratorModule oldModule, java.lang.AutoCloseable oldInstance) { + super(identifier, dependencyResolver, oldModule, oldInstance); + } + + @Override + public void customValidation() { + // add custom validation form module attributes here. + } + + @Override + public java.lang.AutoCloseable createInstance() { + final SequenceGeneratorProvider provider = new SequenceGeneratorProvider(getDataBrokerDependency(), getNotificationServiceDependency(), getRpcRegistryDependency()); + return new AutoCloseable() { + + @Override + public void close() throws Exception { + provider.close(); + } + }; + } + +} diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/opendaylight/yang/gen/v1/org/onap/appc/sequencegenerator/impl/rev170706/SequenceGeneratorModuleFactory.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/opendaylight/yang/gen/v1/org/onap/appc/sequencegenerator/impl/rev170706/SequenceGeneratorModuleFactory.java new file mode 100644 index 000000000..3ebd11b05 --- /dev/null +++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/opendaylight/yang/gen/v1/org/onap/appc/sequencegenerator/impl/rev170706/SequenceGeneratorModuleFactory.java @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APP-C + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/* +* Generated file +* +* Generated from: yang module name: sequence-generator-impl yang module local name: sequence-generator-impl +* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator +* Generated at: Thu Aug 10 15:48:17 IST 2017 +* +* Do not modify this file unless it is present under src/main directory +*/ +package org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.impl.rev170706; +public class SequenceGeneratorModuleFactory extends org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.impl.rev170706.AbstractSequenceGeneratorModuleFactory { + +} diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/opendaylight/yang/gen/v1/org/openecomp/appc/sequencegenerator/impl/rev170706/SequenceGeneratorModule.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/opendaylight/yang/gen/v1/org/openecomp/appc/sequencegenerator/impl/rev170706/SequenceGeneratorModule.java deleted file mode 100644 index 9de0289ea..000000000 --- a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/opendaylight/yang/gen/v1/org/openecomp/appc/sequencegenerator/impl/rev170706/SequenceGeneratorModule.java +++ /dev/null @@ -1,51 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APP-C - * ================================================================================ - * Copyright (C) 2017 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.impl.rev170706; - -import org.onap.appc.seqgen.provider.SequenceGeneratorProvider; - -public class SequenceGeneratorModule extends org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.impl.rev170706.AbstractSequenceGeneratorModule { - public SequenceGeneratorModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { - super(identifier, dependencyResolver); - } - - public SequenceGeneratorModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.impl.rev170706.SequenceGeneratorModule oldModule, java.lang.AutoCloseable oldInstance) { - super(identifier, dependencyResolver, oldModule, oldInstance); - } - - @Override - public void customValidation() { - // add custom validation form module attributes here. - } - - @Override - public java.lang.AutoCloseable createInstance() { - final SequenceGeneratorProvider provider = new SequenceGeneratorProvider(getDataBrokerDependency(), getNotificationServiceDependency(), getRpcRegistryDependency()); - return new AutoCloseable() { - - @Override - public void close() throws Exception { - provider.close(); - } - }; - } - -} diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/opendaylight/yang/gen/v1/org/openecomp/appc/sequencegenerator/impl/rev170706/SequenceGeneratorModuleFactory.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/opendaylight/yang/gen/v1/org/openecomp/appc/sequencegenerator/impl/rev170706/SequenceGeneratorModuleFactory.java deleted file mode 100644 index 3ebd11b05..000000000 --- a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/opendaylight/yang/gen/v1/org/openecomp/appc/sequencegenerator/impl/rev170706/SequenceGeneratorModuleFactory.java +++ /dev/null @@ -1,33 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APP-C - * ================================================================================ - * Copyright (C) 2017 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -/* -* Generated file -* -* Generated from: yang module name: sequence-generator-impl yang module local name: sequence-generator-impl -* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator -* Generated at: Thu Aug 10 15:48:17 IST 2017 -* -* Do not modify this file unless it is present under src/main directory -*/ -package org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.impl.rev170706; -public class SequenceGeneratorModuleFactory extends org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.impl.rev170706.AbstractSequenceGeneratorModuleFactory { - -} diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/SequenceGenerator.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/SequenceGenerator.java deleted file mode 100644 index 709e4e31b..000000000 --- a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/SequenceGenerator.java +++ /dev/null @@ -1,43 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APP-C - * ================================================================================ - * Copyright (C) 2017 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.seqgen; - - -import org.onap.appc.dg.objects.VnfcFlowModel; -import org.onap.appc.exceptions.APPCException; -import org.onap.appc.seqgen.objects.SequenceGeneratorInput; -import org.onap.appc.seqgen.objects.Transaction; - -import java.util.List; -import java.util.Map; - -/** - * Sequence Generator API generates runtime sequence for LCM operations execution - */ -public interface SequenceGenerator { - /** - * - * @param input Sequence Generator Input containing request info, vnf capabilites and tunable parameters - * @return returns runtime sequence for LCM operation execution - * @throws APPCException - */ - List generateSequence(SequenceGeneratorInput input) throws APPCException; -} diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/dgplugin/SequenceGeneratorPlugin.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/dgplugin/SequenceGeneratorPlugin.java deleted file mode 100644 index 26260d22f..000000000 --- a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/dgplugin/SequenceGeneratorPlugin.java +++ /dev/null @@ -1,31 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APP-C - * ================================================================================ - * Copyright (C) 2017 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.seqgen.dgplugin; - -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; - -import java.util.Map; - -public interface SequenceGeneratorPlugin extends SvcLogicJavaPlugin{ - - void generateSequence(Map params, SvcLogicContext context); -} diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/dgplugin/impl/SequenceGeneratorPluginImpl.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/dgplugin/impl/SequenceGeneratorPluginImpl.java deleted file mode 100644 index c0ea4134c..000000000 --- a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/dgplugin/impl/SequenceGeneratorPluginImpl.java +++ /dev/null @@ -1,243 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APP-C - * ================================================================================ - * Copyright (C) 2017 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.seqgen.dgplugin.impl; - - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.apache.commons.lang3.StringUtils; -import org.onap.appc.dg.objects.*; -import org.onap.appc.domainmodel.Vnf; -import org.onap.appc.domainmodel.Vnfc; -import org.onap.appc.domainmodel.Vserver; -import org.onap.appc.domainmodel.lcm.VNFOperation; -import org.onap.appc.exceptions.APPCException; -import org.onap.appc.seqgen.SequenceGenerator; -import org.onap.appc.seqgen.dgplugin.SequenceGeneratorPlugin; -import org.onap.appc.seqgen.impl.SequenceGeneratorFactory; -import org.onap.appc.seqgen.objects.Constants; -import org.onap.appc.seqgen.objects.SequenceGeneratorInput; -import org.onap.appc.seqgen.objects.Transaction; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; - -import java.io.IOException; -import java.util.*; - -public class SequenceGeneratorPluginImpl implements SequenceGeneratorPlugin { - - private static final EELFLogger logger = EELFManager.getInstance().getLogger(SequenceGeneratorPluginImpl.class); - - @Override - public void generateSequence(Map params, SvcLogicContext context) { - ObjectMapper objectMapper = new ObjectMapper(); - String inputJSON = context.getAttribute("inputJSON"); - logger.debug("Input to Sequence Generator " + inputJSON); - try { - SequenceGeneratorInput sequenceGeneratorInput = buildSequenceGeneratorInput(inputJSON); - List sequence = generateSequence(sequenceGeneratorInput); - String output = objectMapper.writeValueAsString(sequence); - logger.debug("Sequence Generator Output " + output); - - context.setAttribute("output", output); - } catch (Exception e) { - logger.error("Error generating sequence", e); - context.setAttribute("error-code", "401"); - context.setAttribute("error-message", "Error generating sequence " + e.getMessage()); - } - } - - private SequenceGeneratorInput buildSequenceGeneratorInput(String inputJson) throws IOException, APPCException { - ObjectMapper objectMapper = new ObjectMapper(); - SequenceGeneratorInput sequenceGeneratorInput ; - objectMapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true); - objectMapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true); - sequenceGeneratorInput = objectMapper.readValue(inputJson, SequenceGeneratorInput.class); - - InventoryModel inventoryModel = buildInventoryModel(inputJson); - sequenceGeneratorInput.setInventoryModel(inventoryModel); - - VnfcDependencyModel dependencyModel = buildDependencyModel(inputJson); - sequenceGeneratorInput.setDependencyModel(dependencyModel); - - return sequenceGeneratorInput; - } - private List generateSequence(SequenceGeneratorInput sequenceGeneratorInput) throws APPCException { - if (sequenceGeneratorInput.getRequestInfo() == null) { - throw new APPCException("Request info is not provided in the input"); - } - String action = sequenceGeneratorInput.getRequestInfo().getAction(); - VNFOperation operation = VNFOperation.findByString(action); - if (operation == null) { - throw new APPCException("Invalid Action " + action); - } - SequenceGenerator sequenceGenerator = SequenceGeneratorFactory.getInstance().createSequenceGenerator(operation); - return sequenceGenerator.generateSequence(sequenceGeneratorInput); - } - - // Dependency model is an optional attribute and may contain null values - private VnfcDependencyModel buildDependencyModel(String inputJson) throws IOException, APPCException { - Set> dependency = new HashSet<>(); - ObjectMapper objectMapper = new ObjectMapper(); - objectMapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true); - JsonNode rootNode = objectMapper.readTree(inputJson); - JsonNode vnfcs = getVnfcsNode(rootNode); - if (vnfcs != null) { - for (JsonNode vnfcNode : vnfcs) { - String vnfcType = readVnfcType(vnfcNode); - String mandatory = readMandatory(vnfcNode); - String resilience = readResilience(vnfcNode); - Vnfc vnfc = new Vnfc(vnfcType, resilience, null, Boolean.parseBoolean(mandatory)); - Node currentNode = getNode(dependency, vnfcType); - if (currentNode == null) { - currentNode = new Node<>(vnfc); - dependency.add(currentNode); - } else { - currentNode.getChild().setMandatory(Boolean.valueOf(mandatory)); - currentNode.getChild().setResilienceType(resilience); - } - JsonNode parents = vnfcNode.get("parents"); - for (JsonNode parent : parents) { - String parentVnfcType = parent.asText(); - Node parentNode = getNode(dependency, parentVnfcType); - if (parentNode != null) { - currentNode.addParent(parentNode.getChild()); - } else { - Vnfc parentVnfc = new Vnfc(parentVnfcType, null, null, false); - parentNode = new Node<>(parentVnfc); - currentNode.addParent(parentVnfc); - dependency.add(parentNode); - } - } - - } - return new VnfcDependencyModel(dependency); - } - return null; - } - - private String readResilience(JsonNode vnfcNode) { - String resilience = null; - if (vnfcNode.get("resilience") != null) { - resilience = vnfcNode.get("resilience").asText(); - } - return resilience; - } - - private String readMandatory(JsonNode vnfcNode) { - String mandatory ; - JsonNode mandatoryNode = vnfcNode.get("mandatory"); - if (mandatoryNode == null) { - mandatory = "false"; - } else { - mandatory = mandatoryNode.asText(); - } - return mandatory; - } - - private String readVnfcType(JsonNode vnfcNode) throws APPCException { - JsonNode vnfcTypeNode = vnfcNode.get(Constants.VNFC_TYPE); - if (vnfcTypeNode == null) { - throw new APPCException("vnfc-type is not available in dependency info"); - } - return vnfcTypeNode.asText(); - } - - private JsonNode getVnfcsNode(JsonNode rootNode) { - JsonNode dependencyInfo = rootNode.get("dependency-info"); - JsonNode vnfcs = null; - if (dependencyInfo != null) { - vnfcs = dependencyInfo.get("vnfcs"); - } - return vnfcs; - } - - private Node getNode(Set> dependency, String vnfcType) { - for (Node node : dependency) { - if (node.getChild().getVnfcType().equals(vnfcType)) { - return node; - } - } - return null; - } - - private InventoryModel buildInventoryModel(String inputJson) throws IOException, APPCException { - ObjectMapper objectMapper = new ObjectMapper(); - objectMapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true); - JsonNode jsonNode = objectMapper.readTree(inputJson); - JsonNode inventoryInfo = jsonNode.get("inventory-info"); - if (inventoryInfo == null) { - throw new APPCException("inventory-info is not provided in the input"); - } - JsonNode vnfInfo = inventoryInfo.get("vnf-info"); - if (vnfInfo == null) { - throw new APPCException("vnf-info is not provided in the input"); - } - - String vnfId = vnfInfo.get("vnf-id").asText(); - String vnfType = vnfInfo.get("vnf-type").asText(); - String vnfVersion = vnfInfo.get("vnf-version").asText(); - - Vnf vnf = new Vnf(vnfId, vnfType, vnfVersion); - - JsonNode vms = vnfInfo.get("vm"); - - Map> vfcs = new HashMap<>(); - for (JsonNode vm : vms) { - if(vm.get("vserver-id")== null){ - throw new APPCException("vserver-id not found "); - } - String vserverId = vm.get("vserver-id").asText(); - Vserver vserver = new Vserver(null, null, vserverId, null, null); - JsonNode vnfc = vm.get("vnfc"); - if (vnfc.get("vnfc-name") == null) { - throw new APPCException("vnfc-name not found for vserver " + vserverId); - } - String vnfcName = vnfc.get("vnfc-name").asText(); - if (vnfc.get("vnfc-type") == null) { - throw new APPCException("vnfc-type not found for vserver " + vserverId); - } - String vnfcType = vnfc.get("vnfc-type").asText(); - if (StringUtils.isEmpty(vnfcType)) { - throw new APPCException("vserver " + vserverId + " is not associated with any vnfc"); - } - Vnfc vfc = new Vnfc(vnfcType, null, vnfcName); - List vServers = vfcs.get(vfc); - if (vServers == null) { - vServers = new LinkedList<>(); - vfcs.put(vfc, vServers); - } - vServers.add(vserver); - } - - for (Map.Entry> entry : vfcs.entrySet()) { - Vnfc vnfc = entry.getKey(); - List vServers = vfcs.get(vnfc); - vnfc.addVms(vServers); - vnf.addVnfc(vnfc); - } - - return new InventoryModel(vnf); - } -} diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/impl/SequenceGeneratorFactory.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/impl/SequenceGeneratorFactory.java deleted file mode 100644 index 3c6a11962..000000000 --- a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/impl/SequenceGeneratorFactory.java +++ /dev/null @@ -1,54 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APP-C - * ================================================================================ - * Copyright (C) 2017 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.seqgen.impl; - -import org.onap.appc.domainmodel.lcm.VNFOperation; -import org.onap.appc.exceptions.APPCException; -import org.onap.appc.seqgen.SequenceGenerator; - -public class SequenceGeneratorFactory { - - private static class ReferenceHolder { - private static SequenceGeneratorFactory instance = new SequenceGeneratorFactory(); - private ReferenceHolder(){ - - } - } - - private SequenceGeneratorFactory(){ - - } - - public static SequenceGeneratorFactory getInstance(){ - return ReferenceHolder.instance; - } - - public SequenceGenerator createSequenceGenerator(VNFOperation operation) throws APPCException { - switch (operation){ - case Start: - return new StartSequenceGenerator(); - case Stop: - return new StopSequenceGenerator(); - default: - throw new APPCException("Sequence Generator does not support operation " + operation.name()); - } - } -} diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/impl/StartSequenceGenerator.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/impl/StartSequenceGenerator.java deleted file mode 100644 index dcffaafd8..000000000 --- a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/impl/StartSequenceGenerator.java +++ /dev/null @@ -1,275 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APP-C - * ================================================================================ - * Copyright (C) 2017 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.seqgen.impl; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import org.apache.commons.lang3.StringUtils; -import org.onap.appc.dg.flowbuilder.FlowBuilder; -import org.onap.appc.dg.flowbuilder.impl.FlowBuilderFactory; -import org.onap.appc.dg.objects.FlowStrategies; -import org.onap.appc.dg.objects.InventoryModel; -import org.onap.appc.dg.objects.VnfcDependencyModel; -import org.onap.appc.dg.objects.VnfcFlowModel; -import org.onap.appc.domainmodel.Vnfc; -import org.onap.appc.domainmodel.Vserver; -import org.onap.appc.exceptions.APPCException; -import org.onap.appc.seqgen.SequenceGenerator; -import org.onap.appc.seqgen.objects.*; - -import java.util.*; - -import static org.onap.appc.seqgen.objects.Constants.*; - -public class StartSequenceGenerator implements SequenceGenerator { - - private static final EELFLogger logger = EELFManager.getInstance().getLogger(StartSequenceGenerator.class); - - private List generateSequenceWithOutDependency(SequenceGeneratorInput input) throws APPCException { - - List transactionList = new LinkedList<>(); - Integer transactionId = 1; - List invVnfcList = input.getInventoryModel().getVnf().getVnfcs(); - boolean singleTransaction=checkSingleTransaction(invVnfcList); - for (Vnfc vnfc : invVnfcList) { - List vms = vnfc.getVserverList(); - List transactionIds = new LinkedList<>(); - for (Vserver vm : vms) { - Transaction transaction = new Transaction(); - transaction.setTransactionId(transactionId); - transactionIds.add(transactionId++); - transaction.setAction(Action.START.getActionType()); - transaction.setActionLevel(ActionLevel.VM.getAction()); - ActionIdentifier actionIdentifier = new ActionIdentifier(); - actionIdentifier.setvServerId(vm.getId()); - transaction.setActionIdentifier(actionIdentifier); - transaction.setPayload(input.getRequestInfo().getPayload()); - if(!singleTransaction){ - updateResponse(transaction); - } - - transactionList.add(transaction); - } - } - return transactionList; - } - - private boolean checkSingleTransaction(List invVnfcList) { - int vServerCount=0; - for(Vnfc vnfc : invVnfcList) { - List vms = vnfc.getVserverList(); - vServerCount=vServerCount+vms.size(); - } - return vServerCount <= 1; - } - - private void updateResponse(Transaction transaction) { - Response ignoreResponse = new Response(); - ignoreResponse.setResponseMessage(ResponseMessage.FAILURE.getResponse()); - Map ignoreAction = new HashMap<>(); - ignoreAction.put(ResponseAction.IGNORE.getAction(), Boolean.TRUE.toString()); - ignoreResponse.setResponseAction(ignoreAction); - transaction.addResponse(ignoreResponse); - } - - private List generateSequenceWithDependencyModel(VnfcFlowModel flowModel, SequenceGeneratorInput input) throws APPCException { - Integer waitTime = readWaitTime(input); - Integer retryCount = readRetryCount(input); - List transactionList = new LinkedList<>(); - Integer transactionId = 1; - Iterator> itr = flowModel.getModelIterator(); - while (itr.hasNext()) { - List vnfcs = itr.next(); - for (Vnfc vnfc : vnfcs) { - List vms = vnfc.getVserverList(); - List transactionIds = new LinkedList<>(); - if(!vms.isEmpty()) { - for (Vserver vm : vms) { - Transaction transaction = new Transaction(); - transaction.setTransactionId(transactionId); - transactionIds.add(transactionId++); - transaction.setAction(Action.START.getActionType()); - transaction.setActionLevel(ActionLevel.VM.getAction()); - ActionIdentifier actionIdentifier = new ActionIdentifier(); - actionIdentifier.setvServerId(vm.getId()); - transaction.setActionIdentifier(actionIdentifier); - transaction.setPayload(input.getRequestInfo().getPayload()); - updateResponse(transaction); - transactionList.add(transaction); - } - boolean startApplicationSupported = readApplicationStartCapability(input); - if (startApplicationSupported) { - Transaction startAppTransaction = new Transaction(); - startAppTransaction.setTransactionId(transactionId++); - startAppTransaction.setAction(Action.START_APPLICATION.getActionType()); - startAppTransaction.setActionLevel(ActionLevel.VNFC.getAction()); - ActionIdentifier startActionIdentifier = new ActionIdentifier(); - startActionIdentifier.setVnfcName(vnfc.getVnfcName()); - startAppTransaction.setActionIdentifier(startActionIdentifier); - startAppTransaction.setPayload(input.getRequestInfo().getPayload()); - - List preCheckOptions = new LinkedList<>(); - for (Integer vmTransactionId : transactionIds) { - setPreCheckOptions(preCheckOptions, vmTransactionId); - } - startAppTransaction.setPreCheckOperator(PreCheckOperator.ANY.getOperator()); - startAppTransaction.setPrecheckOptions(preCheckOptions); - transactionList.add(startAppTransaction); - } - boolean healthCheckSupported = readHealthCheckCapabilites(input.getCapability()); - if (healthCheckSupported) { - Transaction healthCheckTransaction = new Transaction(); - healthCheckTransaction.setTransactionId(transactionId++); - healthCheckTransaction.setAction(Action.HEALTH_CHECK.getActionType()); - healthCheckTransaction.setActionLevel(ActionLevel.VNFC.getAction()); - ActionIdentifier healthCheckActionIdentifier = new ActionIdentifier(); - healthCheckActionIdentifier.setVnfcName(vnfc.getVnfcName()); - healthCheckTransaction.setActionIdentifier(healthCheckActionIdentifier); - healthCheckTransaction.setPayload(input.getRequestInfo().getPayload()); - - Response retryResponse = new Response(); - retryResponse.setResponseMessage(ResponseMessage.UNHEALTHY.getResponse()); - Map retryAction = new HashMap<>(); - retryAction.put(ResponseAction.RETRY.getAction(), retryCount.toString()); - retryAction.put(ResponseAction.WAIT.getAction(), waitTime.toString()); - retryResponse.setResponseAction(retryAction); - healthCheckTransaction.addResponse(retryResponse); - - Response healthyResponse = new Response(); - healthyResponse.setResponseMessage(ResponseMessage.HEALTHY.getResponse()); - Map healthyAction = new HashMap<>(); - healthyAction.put(ResponseAction.CONTINUE.getAction().toLowerCase(), Boolean.TRUE.toString()); - healthyResponse.setResponseAction(healthyAction); - healthCheckTransaction.addResponse(healthyResponse); - - Response failureResponse = new Response(); - failureResponse.setResponseMessage(ResponseMessage.FAILURE.getResponse()); - Map failureResonseAction = new HashMap<>(); - failureResonseAction.put(ResponseAction.STOP.getAction(), Boolean.TRUE.toString()); - failureResponse.setResponseAction(failureResonseAction); - healthCheckTransaction.addResponse(failureResponse); - transactionList.add(healthCheckTransaction); - } - } - } - } - return transactionList; - } - - private void setPreCheckOptions(List preCheckOptions, Integer vmTransactionId) { - PreCheckOption option = new PreCheckOption(); - option.setPreTransactionId(vmTransactionId); - option.setParamName("status"); - option.setParamValue("success"); - preCheckOptions.add(option); - } - - @Override - public List generateSequence(SequenceGeneratorInput input) throws APPCException { - if(input.getRequestInfo().getActionLevel().equals(ActionLevel.VM.getAction())||input.getRequestInfo().getActionLevel().equals(ActionLevel.VNFC.getAction())|| - input.getRequestInfo().getActionLevel().equals(ActionLevel.VNF.getAction())||input.getRequestInfo().getActionLevel().equals(ActionLevel.VF_MODULE.getAction())) { - if (input.getRequestInfo().getActionLevel().equals(ActionLevel.VNF.getAction()) && input.getDependencyModel() != null) { - FlowStrategies flowStrategy = readStartFlowStrategy(input); - VnfcFlowModel flowModel = buildFlowModel(input.getInventoryModel() - , input.getDependencyModel(), flowStrategy); - logger.debug("Flow Model " + flowModel); - return generateSequenceWithDependencyModel(flowModel, input); - } else { - logger.info("Generating sequence without dependency model"); - return generateSequenceWithOutDependency(input); - } - }throw new APPCException("Invalid action level "+input.getRequestInfo().getActionLevel()); - } - - private VnfcFlowModel buildFlowModel(InventoryModel inventoryModel, VnfcDependencyModel dependencyModel, FlowStrategies flowStrategy) throws APPCException { - FlowBuilder flowBuilder = FlowBuilderFactory.getInstance().getFlowBuilder(flowStrategy); - if (flowBuilder == null) { - throw new APPCException("Flow Strategy not supported " + flowStrategy); - } - return flowBuilder.buildFlowModel(dependencyModel, inventoryModel); - } - - private FlowStrategies readStartFlowStrategy(SequenceGeneratorInput sequenceGeneratorInput) throws APPCException { - Map tunableParams = sequenceGeneratorInput.getTunableParams(); - FlowStrategies strategy; - String strategyStr = null; - if (tunableParams != null) { - strategyStr = tunableParams.get(Constants.STRATEGY); - if (StringUtils.isBlank(strategyStr)) { - return FlowStrategies.FORWARD; - } - - strategy = FlowStrategies.findByString(strategyStr); - if (strategy != null) { - return strategy; - } - } - throw new APPCException("Invalid Strategy " + strategyStr); - } - - private boolean readHealthCheckCapabilites(Map> capabilities) { - if (capabilities != null) { - List vnfcCapabilities = capabilities.get(CapabilityLevel.VNFC.getLevel()); - if (vnfcCapabilities != null) - return vnfcCapabilities.stream() - .anyMatch(p -> Capabilties.HEALTH_CHECK.getCapability().equalsIgnoreCase(p)); - } - return false; - } - - private boolean readApplicationStartCapability(SequenceGeneratorInput input) { - Map> capability = input.getCapability(); - if (capability != null) { - List vnfcCapabilities = capability.get(CapabilityLevel.VNFC.getLevel()); - if (vnfcCapabilities != null) - return vnfcCapabilities.stream().anyMatch(p -> Capabilties.START_APPLICATION.getCapability().equalsIgnoreCase(p)); - } - return false; - } - - private Integer readRetryCount(SequenceGeneratorInput input) throws APPCException { - String paramValStr = input.getTunableParams().get(RETRY_COUNT); - if (StringUtils.isEmpty(paramValStr)) { - return RETRY_COUNT_VALUE; - } - try { - return Integer.parseInt(paramValStr); - } catch (NumberFormatException e) { - String message = "Invalid Number for Retry Count " + paramValStr; - logger.error(message, e); - throw new APPCException(message); - } - } - - private Integer readWaitTime(SequenceGeneratorInput input) throws APPCException { - String paramValStr = input.getTunableParams().get(WAIT_TIME); - if (StringUtils.isEmpty(paramValStr)) { - return WAIT_TIME_VALUE; - } - try { - return Integer.parseInt(paramValStr); - } catch (NumberFormatException e) { - String message = "Invalid Number for Wait Time " + paramValStr; - logger.error(message, e); - throw new APPCException(message); - } - } -} diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/impl/StopSequenceGenerator.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/impl/StopSequenceGenerator.java deleted file mode 100644 index 77bee6b83..000000000 --- a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/impl/StopSequenceGenerator.java +++ /dev/null @@ -1,183 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APP-C - * ================================================================================ - * Copyright (C) 2017 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.seqgen.impl; - -import org.apache.commons.lang3.StringUtils; -import org.onap.appc.dg.flowbuilder.FlowBuilder; -import org.onap.appc.dg.flowbuilder.impl.FlowBuilderFactory; -import org.onap.appc.dg.objects.FlowStrategies; -import org.onap.appc.dg.objects.InventoryModel; -import org.onap.appc.dg.objects.VnfcDependencyModel; -import org.onap.appc.dg.objects.VnfcFlowModel; -import org.onap.appc.domainmodel.Vnfc; -import org.onap.appc.domainmodel.Vserver; -import org.onap.appc.exceptions.APPCException; -import org.onap.appc.seqgen.SequenceGenerator; -import org.onap.appc.seqgen.objects.*; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -import java.util.*; - -import static org.onap.appc.seqgen.objects.Constants.*; - -public class StopSequenceGenerator implements SequenceGenerator { - - private static final EELFLogger logger = EELFManager.getInstance().getLogger(StartSequenceGenerator.class); - - @Override - public List generateSequence(SequenceGeneratorInput input) throws APPCException { - if(input.getRequestInfo().getActionLevel().equals(ActionLevel.VM.getAction())||input.getRequestInfo().getActionLevel().equals(ActionLevel.VNFC.getAction())|| - input.getRequestInfo().getActionLevel().equals(ActionLevel.VNF.getAction())||input.getRequestInfo().getActionLevel().equals(ActionLevel.VF_MODULE.getAction())) { - if (input.getRequestInfo().getActionLevel().equals(ActionLevel.VNF.getAction()) && input.getDependencyModel() != null) { - FlowStrategies flowStrategy = readStopFlowStrategy(input); - VnfcFlowModel flowModel = buildFlowModel(input.getInventoryModel() - , input.getDependencyModel(), flowStrategy); - logger.debug("Flow Model " + flowModel); - return generateSequenceWithDependencyModel(flowModel, input); - } else { - logger.info("Generating sequence without dependency model"); - return generateSequenceWithOutDependency(input); - } - }throw new APPCException("Invalid action level "+input.getRequestInfo().getActionLevel()); - - } - private List generateSequenceWithOutDependency(SequenceGeneratorInput input){ - List transactionList = new LinkedList<>(); - Integer transactionId = 1; - List transactionIds = new LinkedList<>(); - List invVnfcList = input.getInventoryModel().getVnf().getVnfcs(); - boolean singleTransaction=checkSingleTransaction(invVnfcList); - for (Vnfc vnfc : invVnfcList) { - List vms = vnfc.getVserverList(); - for(Vserver vm:vms){ - Transaction transaction = new Transaction(); - transaction.setTransactionId(transactionId); - transactionIds.add(transactionId++); - transaction.setAction(Action.STOP.getActionType()); - transaction.setActionLevel(ActionLevel.VM.getAction()); - ActionIdentifier actionIdentifier = new ActionIdentifier(); - actionIdentifier.setvServerId(vm.getId()); - transaction.setActionIdentifier(actionIdentifier); - transaction.setPayload(input.getRequestInfo().getPayload()); - if(!singleTransaction){ - updateStopResponse(transaction); - } - transactionList.add(transaction); - } - } - return transactionList; - } - - private void updateStopResponse(Transaction transaction) { - Response failureResponse = new Response(); - failureResponse.setResponseMessage(ResponseMessage.FAILURE.getResponse()); - Map failureAction = new HashMap<>(); - failureAction.put(ResponseAction.IGNORE.getAction(),Boolean.TRUE.toString()); - failureResponse.setResponseAction(failureAction); - transaction.addResponse(failureResponse); - } - private boolean checkSingleTransaction(List invVnfcList) { - int vServerCount=0; - for(Vnfc vnfc : invVnfcList) { - List vms = vnfc.getVserverList(); - vServerCount=vServerCount+vms.size(); - } - return vServerCount <= 1; - } - - private List generateSequenceWithDependencyModel(VnfcFlowModel flowModel,SequenceGeneratorInput input){ - List transactionList = new LinkedList<>(); - Integer transactionId = 1; - List transactionIds = new LinkedList<>(); - Iterator> itr = flowModel.getModelIterator(); - while (itr.hasNext()){ - List vnfcs = itr.next(); - for(Vnfc vnfc:vnfcs){ - boolean stopApplicationSupported = readApplicationStopCapability(input); - if(stopApplicationSupported && !vnfc.getVserverList().isEmpty()){ - Transaction stopAppTransaction = new Transaction(); - stopAppTransaction.setTransactionId(transactionId++); - stopAppTransaction.setAction(Action.STOP_APPLICATION.getActionType()); - stopAppTransaction.setActionLevel(ActionLevel.VNFC.getAction()); - ActionIdentifier stopActionIdentifier = new ActionIdentifier(); - stopActionIdentifier .setVnfcName(vnfc.getVnfcName()); - stopAppTransaction.setActionIdentifier(stopActionIdentifier ); - stopAppTransaction.setPayload(input.getRequestInfo().getPayload()); - updateStopResponse(stopAppTransaction); - transactionList.add(stopAppTransaction); - } - List vms = vnfc.getVserverList(); - for(Vserver vm:vms){ - Transaction transaction = new Transaction(); - transaction.setTransactionId(transactionId); - transactionIds.add(transactionId++); - transaction.setAction(Action.STOP.getActionType()); - transaction.setActionLevel(ActionLevel.VM.getAction()); - ActionIdentifier actionIdentifier = new ActionIdentifier(); - actionIdentifier.setvServerId(vm.getId()); - transaction.setActionIdentifier(actionIdentifier); - transaction.setPayload(input.getRequestInfo().getPayload()); - - updateStopResponse(transaction); - transactionList.add(transaction); - } - } - } - return transactionList; - } - - private VnfcFlowModel buildFlowModel(InventoryModel inventoryModel, VnfcDependencyModel dependencyModel, FlowStrategies flowStrategy) throws APPCException { - FlowBuilder flowBuilder = FlowBuilderFactory.getInstance().getFlowBuilder(flowStrategy); - if (flowBuilder == null) { - throw new APPCException("Flow Strategy not supported " + flowStrategy); - } - return flowBuilder.buildFlowModel(dependencyModel, inventoryModel); - } - - private FlowStrategies readStopFlowStrategy(SequenceGeneratorInput sequenceGeneratorInput) throws APPCException { - Map tunableParams = sequenceGeneratorInput.getTunableParams(); - FlowStrategies strategy; - String strategyStr = null; - if (tunableParams != null) { - strategyStr = tunableParams.get(Constants.STRATEGY); - if (StringUtils.isBlank(strategyStr)) { - return FlowStrategies.REVERSE; - } - strategy = FlowStrategies.findByString(strategyStr); - if (strategy != null) { - return strategy; - } - } - throw new APPCException("Invalid Strategy " + strategyStr); - } - private boolean readApplicationStopCapability(SequenceGeneratorInput input) { - Map> capability = input.getCapability(); - if(capability!= null){ - List vnfcCapabilities = capability.get(Constants.CapabilityLevel.VNFC.getLevel()); - if(vnfcCapabilities!=null) - return vnfcCapabilities.stream().anyMatch(p -> Capabilties.STOP_APPLICATION.getCapability().equalsIgnoreCase(p)); - } - return false; - } - - -} diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/objects/ActionIdentifier.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/objects/ActionIdentifier.java deleted file mode 100644 index 0703edf42..000000000 --- a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/objects/ActionIdentifier.java +++ /dev/null @@ -1,63 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APP-C - * ================================================================================ - * Copyright (C) 2017 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.seqgen.objects; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; - -@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) -@JsonIgnoreProperties(ignoreUnknown = true) -public class ActionIdentifier { - - @JsonProperty("vnf-id") - private String vnfId; - - @JsonProperty("vnfc-name") - private String vnfcName; - - @JsonProperty("vserver-id") - private String vServerId; - - public String getVnfId() { - return vnfId; - } - - public void setVnfId(String vnfId) { - this.vnfId = vnfId; - } - - public String getVnfcName() { - return vnfcName; - } - - public void setVnfcName(String vnfcName) { - this.vnfcName = vnfcName; - } - - public String getvServerId() { - return vServerId; - } - - public void setvServerId(String vServerId) { - this.vServerId = vServerId; - } -} diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/objects/Constants.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/objects/Constants.java deleted file mode 100644 index 476c5b718..000000000 --- a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/objects/Constants.java +++ /dev/null @@ -1,123 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APP-C - * ================================================================================ - * Copyright (C) 2017 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.seqgen.objects; - -public class Constants { - public static final String RETRY_COUNT = "retry-count"; - public static final String WAIT_TIME = "wait-time"; - public static final Integer WAIT_TIME_VALUE = 60; - public static final Integer RETRY_COUNT_VALUE = 4; - public static final String STRATEGY = "strategy"; - public static final String VNFC_TYPE = "vnfc-type"; - - public enum CapabilityLevel{ - VNF("vnf"),VNFC("vnfc"),VM("vm"); - private String level; - CapabilityLevel(String level) { - this.level=level; - } - - public String getLevel() { - return level; - } - } - - public enum Capabilties{ - START_APPLICATION("StartApplication"),HEALTH_CHECK("HealthCheck"),STOP_APPLICATION("StopApplication"); - private String capability; - - Capabilties(String capability) { - this.capability=capability; - } - public String getCapability(){ - return capability; - } - } - - public enum ResponseMessage{ - HEALTHY("healthy"),UNHEALTHY("unhealthy"),SUCCESS("success"),FAILURE("failure"); - - public String getResponse() { - return response; - } - - private String response; - ResponseMessage(String response){ - this.response=response; - } - - } - - public enum ResponseAction{ - STOP("stop"),RETRY("retry"),IGNORE("ignore"),WAIT("wait"),CONTINUE("Continue"); - - ResponseAction(String action) { - this.action=action; - } - - private String action; - - public String getAction() { - return action; - } - - } - - public enum Action{ - START("Start"),START_APPLICATION("StartApplication"),HEALTH_CHECK("HealthCheck"),STOP_APPLICATION("StopApplication"),STOP("Stop"); - - Action(String actionType) { - this.actionType=actionType; - } - - public String getActionType() { - return actionType; - } - - private String actionType; - - } - public enum ActionLevel{ - VM("vm"),VNFC("vnfc"),VNF("vnf"),VF_MODULE("vf-module"); - private String action; - ActionLevel(String action){ - this.action=action; - } - public String getAction() { - return action; - } - } - - public enum PreCheckOperator{ - ANY("any"),ALL("all"); - - PreCheckOperator(String operator){ - this.operator=operator; - } - - public String getOperator() { - return operator; - } - - private String operator; - - } -} diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/objects/PreCheckOption.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/objects/PreCheckOption.java deleted file mode 100644 index 00d079b00..000000000 --- a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/objects/PreCheckOption.java +++ /dev/null @@ -1,74 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APP-C - * ================================================================================ - * Copyright (C) 2017 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.seqgen.objects; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; - -@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) -@JsonIgnoreProperties(ignoreUnknown = true) -public class PreCheckOption { - - @JsonProperty("pre-transactionID") - private Integer preTransactionId; - - @JsonProperty("param-name") - private String paramName; - - @JsonProperty("param-value") - private String paramValue; - - private String rule; - - - public Integer getPreTransactionId() { - return preTransactionId; - } - - public void setPreTransactionId(Integer preTransactionId) { - this.preTransactionId = preTransactionId; - } - - public String getParamName() { - return paramName; - } - - public void setParamName(String paramName) { - this.paramName = paramName; - } - - public String getParamValue() { - return paramValue; - } - - public void setParamValue(String paramValue) { - this.paramValue = paramValue; - } - - public String getRule() { - return rule; - } - - public void setRule(String rule) { - this.rule = rule; - } -} diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/objects/RequestInfo.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/objects/RequestInfo.java deleted file mode 100644 index 1704d274f..000000000 --- a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/objects/RequestInfo.java +++ /dev/null @@ -1,72 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APP-C - * ================================================================================ - * Copyright (C) 2017 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.seqgen.objects; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; - -@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) -@JsonIgnoreProperties(ignoreUnknown = true) -public class RequestInfo { - - private String action; - - @JsonProperty("action-level") - private String actionLevel; - - @JsonProperty("action-identifier") - private ActionIdentifier actionIdentifier; - - private String payload; - - public String getAction() { - return action; - } - - public void setAction(String action) { - this.action = action; - } - - public String getActionLevel() { - return actionLevel; - } - - public void setActionLevel(String actionLevel) { - this.actionLevel = actionLevel; - } - - public ActionIdentifier getActionIdentifier() { - return actionIdentifier; - } - - public void setActionIdentifier(ActionIdentifier actionIdentifier) { - this.actionIdentifier = actionIdentifier; - } - - public String getPayload() { - return payload; - } - - public void setPayload(String payload) { - this.payload = payload; - } -} diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/objects/RequestInfoBuilder.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/objects/RequestInfoBuilder.java deleted file mode 100644 index 4fad00013..000000000 --- a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/objects/RequestInfoBuilder.java +++ /dev/null @@ -1,76 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APP-C - * ================================================================================ - * Copyright (C) 2017 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.seqgen.objects; - -public class RequestInfoBuilder { - - private String action; - - private String actionLevel; - - private ActionIdentifier actionIdentifier; - - private String payload; - - public RequestInfoBuilder actionIdentifier(){ - this.actionIdentifier = new ActionIdentifier(); - return this; - } - - public RequestInfoBuilder vnfId(String vnfId){ - this.actionIdentifier.setVnfId(vnfId); - return this; - } - - public RequestInfoBuilder vnfcName(String vnfcName){ - this.actionIdentifier.setVnfcName(vnfcName); - return this; - } - - public RequestInfoBuilder vServerId(String vServerId){ - this.actionIdentifier.setvServerId(vServerId); - return this; - } - - public RequestInfoBuilder action(String action){ - this.action = action; - return this; - } - - public RequestInfoBuilder actionLevel(String actionLevel){ - this.actionLevel = actionLevel; - return this; - } - - public RequestInfoBuilder payload(String payload){ - this.payload = payload; - return this; - } - - public RequestInfo build(){ - RequestInfo requestInfo = new RequestInfo(); - requestInfo.setAction(this.action); - requestInfo.setActionIdentifier(this.actionIdentifier); - requestInfo.setActionLevel(this.actionLevel); - requestInfo.setPayload(this.payload); - return requestInfo; - } -} diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/objects/Response.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/objects/Response.java deleted file mode 100644 index ba3ccd400..000000000 --- a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/objects/Response.java +++ /dev/null @@ -1,65 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APP-C - * ================================================================================ - * Copyright (C) 2017 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.seqgen.objects; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; - -import java.util.Map; - -@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) -@JsonIgnoreProperties(ignoreUnknown = true) -public class Response { - - @JsonProperty("response-code") - private String responseCode; - - @JsonProperty("response-message") - private String responseMessage; - - @JsonProperty("response-action") - private Map responseAction; - - public String getResponseCode() { - return responseCode; - } - - public void setResponseCode(String responseCode) { - this.responseCode = responseCode; - } - - public String getResponseMessage() { - return responseMessage; - } - - public void setResponseMessage(String responseMessage) { - this.responseMessage = responseMessage; - } - - public Map getResponseAction() { - return responseAction; - } - - public void setResponseAction(Map responseAction) { - this.responseAction = responseAction; - } -} diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/objects/SequenceGeneratorInput.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/objects/SequenceGeneratorInput.java deleted file mode 100644 index d3f6a6d14..000000000 --- a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/objects/SequenceGeneratorInput.java +++ /dev/null @@ -1,93 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APP-C - * ================================================================================ - * Copyright (C) 2017 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.seqgen.objects; - -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import org.onap.appc.dg.objects.InventoryModel; -import org.onap.appc.dg.objects.VnfcDependencyModel; - -import javax.validation.constraints.NotNull; -import java.util.List; -import java.util.Map; - -@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) -@JsonIgnoreProperties(ignoreUnknown = true) -public class SequenceGeneratorInput { - - @NotNull - @JsonProperty("request-info") - private RequestInfo requestInfo; - - @JsonIgnore - private InventoryModel inventoryModel; - - @JsonIgnore - private VnfcDependencyModel dependencyModel; - - @JsonProperty("tunable-parameters") - private Map tunableParams; - - @JsonProperty("capabilities") - private Map> capability; - - public RequestInfo getRequestInfo() { - return requestInfo; - } - - public void setRequestInfo(RequestInfo requestInfo) { - this.requestInfo = requestInfo; - } - - public InventoryModel getInventoryModel() { - return inventoryModel; - } - - public void setInventoryModel(InventoryModel inventoryModel) { - this.inventoryModel = inventoryModel; - } - - public VnfcDependencyModel getDependencyModel() { - return dependencyModel; - } - - public void setDependencyModel(VnfcDependencyModel dependencyModel) { - this.dependencyModel = dependencyModel; - } - - public Map getTunableParams() { - return tunableParams; - } - - public void setTunableParams(Map tunableParams) { - this.tunableParams = tunableParams; - } - - public Map> getCapability() { - return capability; - } - - public void setCapability(Map> capability) { - this.capability = capability; - } -} diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/objects/SequenceGeneratorInputBuilder.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/objects/SequenceGeneratorInputBuilder.java deleted file mode 100644 index 66cb111b5..000000000 --- a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/objects/SequenceGeneratorInputBuilder.java +++ /dev/null @@ -1,85 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APP-C - * ================================================================================ - * Copyright (C) 2017 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.seqgen.objects; - -import org.onap.appc.dg.objects.InventoryModel; -import org.onap.appc.dg.objects.VnfcDependencyModel; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class SequenceGeneratorInputBuilder { - - private RequestInfo requestInfo; - - private InventoryModel inventoryModel; - - private VnfcDependencyModel dependencyModel; - - private Map tunableParams; - - private Map> capability; - - public SequenceGeneratorInputBuilder requestInfo(RequestInfo requestInfo){ - this.requestInfo = requestInfo; - return this; - } - - public SequenceGeneratorInputBuilder capability(String level,List capabilities){ - if(this.capability ==null){ - this.capability = new HashMap<>(); - } - this.capability.put(level,capabilities); - return this; - } - - public SequenceGeneratorInputBuilder tunableParameter(String key,String value){ - if(this.tunableParams ==null){ - this.tunableParams = new HashMap<>(); - } - this.tunableParams.put(key,value); - return this; - } - - public SequenceGeneratorInputBuilder inventoryModel(InventoryModel model){ - this.inventoryModel = model; - return this; - } - - public SequenceGeneratorInputBuilder dependendcyModel(VnfcDependencyModel model){ - this.dependencyModel = model; - return this; - } - - public SequenceGeneratorInput build(){ - SequenceGeneratorInput input = new SequenceGeneratorInput(); - input.setRequestInfo(this.requestInfo); - input.setCapability(this.capability); - input.setInventoryModel(this.inventoryModel); - input.setDependencyModel(this.dependencyModel); - input.setTunableParams(this.tunableParams); - return input; - } - - - -} diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/objects/Transaction.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/objects/Transaction.java deleted file mode 100644 index ce45ec9e5..000000000 --- a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/objects/Transaction.java +++ /dev/null @@ -1,142 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APP-C - * ================================================================================ - * Copyright (C) 2017 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.seqgen.objects; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; - -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - -@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) -@JsonIgnoreProperties(ignoreUnknown = true) -public class Transaction { - - @JsonProperty("transactionId") - private Integer transactionId; - - @JsonProperty("action") - private String action; - - @JsonProperty("action-level") - private String actionLevel; - - @JsonProperty("action-identifier") - private ActionIdentifier actionIdentifier; - - @JsonProperty("payload") - private String payload; - - @JsonProperty("parameters") - private Map parameters; - - @JsonProperty("precheck-operator") - private String preCheckOperator; - - - @JsonProperty("precheck-options") - private List precheckOptions; - - @JsonProperty("responses") - private List responses; - - public Transaction(){ - responses = new LinkedList<>(); - } - - public Integer getTransactionId() { - return transactionId; - } - - public void setTransactionId(Integer transactionId) { - this.transactionId = transactionId; - } - - public String getAction() { - return action; - } - - public void setAction(String action) { - this.action = action; - } - - public String getActionLevel() { - return actionLevel; - } - - public void setActionLevel(String actionLevel) { - this.actionLevel = actionLevel; - } - - public ActionIdentifier getActionIdentifier() { - return actionIdentifier; - } - - public void setActionIdentifier(ActionIdentifier actionIdentifier) { - this.actionIdentifier = actionIdentifier; - } - - public String getPayload() { - return payload; - } - - public void setPayload(String payload) { - this.payload = payload; - } - - public Map getParameters() { - return parameters; - } - - public void setParameters(Map parameters) { - this.parameters = parameters; - } - - public List getResponses() { - return responses; - } - - public void setResponses(List responses) { - this.responses = responses; - } - - public void addResponse(Response response){ - this.responses.add(response); - } - - public String getPreCheckOperator() { - return preCheckOperator; - } - - public void setPreCheckOperator(String preCheckOperator) { - this.preCheckOperator = preCheckOperator; - } - - public List getPrecheckOptions() { - return precheckOptions; - } - - public void setPrecheckOptions(List precheckOptions) { - this.precheckOptions = precheckOptions; - } -} diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/provider/SequenceGeneratorProvider.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/provider/SequenceGeneratorProvider.java deleted file mode 100644 index ad9a68705..000000000 --- a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/provider/SequenceGeneratorProvider.java +++ /dev/null @@ -1,352 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APP-C - * ================================================================================ - * Copyright (C) 2017 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.seqgen.provider; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import com.google.common.util.concurrent.Futures; -import org.apache.commons.lang.StringUtils; -import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.controller.sal.binding.api.BindingAwareBroker; -import org.opendaylight.controller.sal.binding.api.NotificationProviderService; -import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry; -import org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.rev170706.GenerateSequenceInput; -import org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.rev170706.GenerateSequenceOutput; -import org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.rev170706.GenerateSequenceOutputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.rev170706.SequenceGeneratorService; -import org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.rev170706.dependency.info.dependency.info.Vnfcs; -import org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.rev170706.inventory.info.inventory.info.vnf.info.Vm; -import org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.rev170706.response.StatusBuilder; -import org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.rev170706.response.Transactions; -import org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.rev170706.response.TransactionsBuilder; -import org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.rev170706.response.transactions.ActionIdentifier; -import org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.rev170706.response.transactions.*; -import org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.rev170706.response.transactions.responses.ResponseActionBuilder; -import org.opendaylight.yangtools.yang.common.RpcResult; -import org.opendaylight.yangtools.yang.common.RpcResultBuilder; -import org.onap.appc.dg.objects.InventoryModel; -import org.onap.appc.dg.objects.Node; -import org.onap.appc.dg.objects.VnfcDependencyModel; -import org.onap.appc.domainmodel.Vnf; -import org.onap.appc.domainmodel.Vserver; -import org.onap.appc.domainmodel.lcm.VNFOperation; -import org.onap.appc.exceptions.APPCException; -import org.onap.appc.seqgen.SequenceGenerator; -import org.onap.appc.seqgen.impl.SequenceGeneratorFactory; -import org.onap.appc.seqgen.objects.*; - -import java.util.*; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; - - -public class SequenceGeneratorProvider implements AutoCloseable,SequenceGeneratorService{ - protected DataBroker dataBroker; - protected RpcProviderRegistry rpcRegistry; - protected NotificationProviderService notificationService; - protected BindingAwareBroker.RpcRegistration rpcRegistration; - private final EELFLogger log = EELFManager.getInstance().getLogger(SequenceGeneratorProvider.class); - private final ExecutorService executor; - private final static String APP_NAME = "SequenceGeneratorProvider"; - - public SequenceGeneratorProvider(DataBroker dataBroker2, NotificationProviderService notificationProviderService - , RpcProviderRegistry rpcRegistry2) { - log.info("Creating provider for " + APP_NAME); - executor = Executors.newFixedThreadPool(1); - this.dataBroker = dataBroker2; - this.notificationService = notificationProviderService; - - this.rpcRegistry = rpcRegistry2; - - if (this.rpcRegistry != null) { - rpcRegistration = rpcRegistry.addRpcImplementation(SequenceGeneratorService.class, this); - } - log.info("Initialization complete for " + APP_NAME); - } - - @Override - public void close() throws Exception { - log.info("Closing provider for " + APP_NAME); - if(this.executor != null){ - executor.shutdown(); - } - if(this.rpcRegistration != null){ - rpcRegistration.close(); - } - log.info("Successfully closed provider for " + APP_NAME); - } - - @Override - public Future> generateSequence(GenerateSequenceInput input) { - RpcResult rpcResult=null; - log.debug("Received input = " + input ); - try { - SequenceGenerator seqGenerator = SequenceGeneratorFactory.getInstance() - .createSequenceGenerator(VNFOperation.findByString(input.getRequestInfo().getAction().name())); - SequenceGeneratorInput seqGenInput = buildSeqGenInput(input); - List transactions = seqGenerator.generateSequence(seqGenInput); - rpcResult = buildSuccessResponse(transactions); - } catch (APPCException e) { - log.error("Error Generating Sequence",e); - rpcResult = buildFailureResponse(e.getMessage()); - } - return Futures.immediateFuture(rpcResult); - } - - private RpcResult buildSuccessResponse(List transactions) { - - List transactionList = new LinkedList<>(); - for(Transaction transaction:transactions){ - ActionIdentifier actionIdentifier = null; - if(transaction.getActionIdentifier() != null){ - actionIdentifier = new ActionIdentifierBuilder() - .setVnfId(transaction.getActionIdentifier().getVnfId()) - .setVnfcName(transaction.getActionIdentifier().getVnfcName()) - .setVserverId(transaction.getActionIdentifier().getvServerId()) - .build(); - } - - List precheckOptions = new LinkedList<>(); - if(transaction.getPrecheckOptions()!=null){ - for(PreCheckOption option:transaction.getPrecheckOptions()){ - PrecheckOptions precheckOption = new PrecheckOptionsBuilder() - .setParamName(option.getParamName()) - .setParamValue(option.getParamValue()) - .setPreTransactionId(option.getPreTransactionId()) - .setRule(option.getRule()) - .build(); - precheckOptions.add(precheckOption); - } - } - - List responseList = getResponses(transaction); - - Transactions transactionObj - = new TransactionsBuilder() - .setActionIdentifier(actionIdentifier) - .setAction(transaction.getAction()) - .setActionLevel(transaction.getActionLevel()) - .setPrecheckOperator(transaction.getPreCheckOperator()) - .setPayload(transaction.getPayload()) - .setTransactionId(transaction.getTransactionId()) - .setPrecheckOptions(precheckOptions) - .setResponses(responseList) - .build(); - transactionList.add(transactionObj); - } - - GenerateSequenceOutputBuilder builder = new GenerateSequenceOutputBuilder() - .setTransactions(transactionList); - - return RpcResultBuilder - . status(true) - .withResult(builder.build()).build(); - } - - private List getResponses(Transaction transaction) { - List responseList = new LinkedList<>(); - for(Response resp : transaction.getResponses()){ - Map responseActions = resp.getResponseAction(); - ResponseActionBuilder responseActionBuilder = new ResponseActionBuilder(); - if(responseActions.get(Constants.ResponseAction.WAIT.getAction())!=null){ - responseActionBuilder = responseActionBuilder.setWait(Integer.parseInt(responseActions.get(Constants.ResponseAction.WAIT.getAction()))); - } - if(responseActions.get(Constants.ResponseAction.RETRY.getAction())!=null){ - responseActionBuilder = responseActionBuilder.setRetry(Integer.parseInt(responseActions.get(Constants.ResponseAction.RETRY.getAction()))); - } - if(responseActions.get(Constants.ResponseAction.CONTINUE.getAction().toLowerCase())!=null){ - responseActionBuilder = responseActionBuilder - .setContinue(Boolean.parseBoolean(responseActions.get(Constants.ResponseAction.CONTINUE.getAction().toLowerCase()))); - } - if(responseActions.get(Constants.ResponseAction.IGNORE.getAction()) !=null){ - responseActionBuilder = responseActionBuilder.setIgnore(Boolean.parseBoolean(responseActions.get(Constants.ResponseAction.IGNORE.getAction()))); - } - if(responseActions.get(Constants.ResponseAction.STOP.getAction()) !=null){ - responseActionBuilder = responseActionBuilder.setStop(Boolean.parseBoolean(responseActions.get(Constants.ResponseAction.STOP.getAction()))); - } - Responses response = new ResponsesBuilder() - .setResponseMessage(resp.getResponseMessage()) - .setResponseAction(responseActionBuilder.build()) - .build(); - responseList.add(response); - } - return responseList; - } - - private SequenceGeneratorInput buildSeqGenInput(GenerateSequenceInput input) throws APPCException { - - validateMandatory(input); - - RequestInfoBuilder requestInfobuilder = new RequestInfoBuilder() - .action(input.getRequestInfo().getAction().name()) - .actionLevel(input.getRequestInfo().getActionLevel().getName().toLowerCase()) - .payload(input.getRequestInfo().getPayload()); - - if(input.getRequestInfo().getActionIdentifier() !=null){ - requestInfobuilder = requestInfobuilder - .actionIdentifier() - .vnfId(input.getRequestInfo().getActionIdentifier().getVnfId()) - .vnfcName(input.getRequestInfo().getActionIdentifier().getVnfcName()) - .vServerId(input.getRequestInfo().getActionIdentifier().getVserverId()); - } - - RequestInfo requestInfo = requestInfobuilder.build(); - - InventoryModel inventoryModel = readInventoryModel(input); - - VnfcDependencyModel dependencyModel = readDependencyModel(input); - - SequenceGeneratorInputBuilder builder = new SequenceGeneratorInputBuilder() - .requestInfo(requestInfo) - .inventoryModel(inventoryModel) - .dependendcyModel(dependencyModel); - - if(input.getCapabilities() !=null){ - if(input.getCapabilities().getVnf()!=null){ - builder = builder.capability("vnf",input.getCapabilities().getVnf()); - } - if(input.getCapabilities().getVnfc()!=null){ - builder = builder.capability("vnfc",input.getCapabilities().getVnfc()); - } - if(input.getCapabilities().getVm()!=null){ - builder = builder.capability("vm",input.getCapabilities().getVm()); - } - if(input.getCapabilities().getVfModule()!=null){ - builder = builder.capability("vf-module",input.getCapabilities().getVfModule()); - } - } - - if(input.getTunableParameters() != null){ - builder = builder.tunableParameter(Constants.RETRY_COUNT,String.valueOf(input.getTunableParameters().getRetryCount())) - .tunableParameter(Constants.WAIT_TIME,String.valueOf(input.getTunableParameters().getWaitTime())); - if(input.getTunableParameters().getStrategy() !=null){ - builder = builder.tunableParameter(Constants.STRATEGY,input.getTunableParameters().getStrategy().name()); - } - } - return builder.build(); - } - - - private void validateMandatory(GenerateSequenceInput input) throws APPCException { - if(input.getRequestInfo() ==null){ - throw new APPCException("Request Info is not present in the request"); - } - if(input.getRequestInfo().getAction() ==null){ - throw new APPCException("Action is not present in the request"); - } - if(input.getInventoryInfo() ==null){ - throw new APPCException("inventoryInfo is not provided in the input"); - } - } - - private VnfcDependencyModel readDependencyModel(GenerateSequenceInput input) { - if(input.getDependencyInfo() == null || input.getDependencyInfo().getVnfcs() ==null || input.getDependencyInfo().getVnfcs().isEmpty()){ - return null; - } - List vnfcs = input.getDependencyInfo().getVnfcs(); - Set> dependencies = new HashSet<>(); - for(Vnfcs vnfcObj:vnfcs){ - org.onap.appc.domainmodel.Vnfc vnfc; - Node currentNode = readNode(vnfcObj.getVnfcType(),dependencies); - if(currentNode == null){ - vnfc = new org.onap.appc.domainmodel.Vnfc(vnfcObj.getVnfcType(),vnfcObj.getResilience()); - currentNode = new Node<>(vnfc); - dependencies.add(currentNode); - } - else{ - currentNode.getChild().setResilienceType(vnfcObj.getResilience()); - currentNode.getChild().setMandatory(vnfcObj.isMandatory()); - } - for(String parentVnfcType:vnfcObj.getParents()){ - Node parentNode = readNode(parentVnfcType,dependencies); - if(parentNode == null){ - org.onap.appc.domainmodel.Vnfc parentVnfc = new org.onap.appc.domainmodel.Vnfc(parentVnfcType,null); - parentNode = new Node<>(parentVnfc); - currentNode.addParent(parentVnfc); - dependencies.add(parentNode); - } - else{ - currentNode.addParent(parentNode.getChild()); - } - } - } - return new VnfcDependencyModel(dependencies); - } - - private Node readNode(String vnfcType, Set> dependencies) { - for(Node node : dependencies){ - if(node.getChild().getVnfcType().equalsIgnoreCase(vnfcType)){ - return node; - } - } - return null; - } - - private InventoryModel readInventoryModel(GenerateSequenceInput input) throws APPCException { - if (input.getInventoryInfo().getVnfInfo()== null) { - throw new APPCException("vnfInfo is not provided in the input"); - } - - Vnf vnf = new Vnf(input.getInventoryInfo().getVnfInfo().getVnfId(), - input.getInventoryInfo().getVnfInfo().getVnfType(),null); - - Map> map = new HashMap<>(); - for(Vm vm:input.getInventoryInfo().getVnfInfo().getVm()){ - if(StringUtils.isBlank(vm.getVserverId())){ - throw new APPCException("vserver-id not found "); - } - if(StringUtils.isBlank(vm.getVnfc().getVnfcType())){ - throw new APPCException("vnfc-type not found for vserver " + vm.getVserverId()); - } - if(StringUtils.isBlank(vm.getVnfc().getVnfcName())){ - throw new APPCException("vnfc-name not found for vserver " + vm.getVserverId()); - } - - org.onap.appc.domainmodel.Vnfc vnfc = new org.onap.appc.domainmodel.Vnfc(vm.getVnfc().getVnfcType(),null,vm.getVnfc().getVnfcName()); - List vms = map.get(vnfc); - if(vms ==null){ - vms = new LinkedList<>(); - map.put(vnfc,vms); - } - vms.add(new Vserver(null,null,vm.getVserverId(),null,null)); - } - for(Map.Entry> entry:map.entrySet()){ - org.onap.appc.domainmodel.Vnfc vnfc = entry.getKey(); - List vmList = entry.getValue(); - vnfc.addVms(vmList); - vnf.addVnfc(vnfc); - } - return new InventoryModel(vnf); - } - - private RpcResult buildFailureResponse(String errorMessage){ - GenerateSequenceOutputBuilder sequenceGeneratorOutputBuilder=new GenerateSequenceOutputBuilder(); - StatusBuilder statusBuilder =new StatusBuilder(); - statusBuilder.setCode(401); - statusBuilder.setMessage(errorMessage); - sequenceGeneratorOutputBuilder.setStatus(statusBuilder.build()); - return RpcResultBuilder - . status(true) - .withResult(sequenceGeneratorOutputBuilder.build()) - .build(); - } -} diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/test/java/org/onap/appc/seqgen/TestSequenceGeneratorPlugin.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/test/java/org/onap/appc/seqgen/TestSequenceGeneratorPlugin.java new file mode 100644 index 000000000..748773a21 --- /dev/null +++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/test/java/org/onap/appc/seqgen/TestSequenceGeneratorPlugin.java @@ -0,0 +1,272 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APP-C + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.seqgen; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.junit.Assert; +import org.junit.Test; +import org.onap.appc.seqgen.dgplugin.SequenceGeneratorPlugin; +import org.onap.appc.seqgen.dgplugin.impl.SequenceGeneratorPluginImpl; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.net.URISyntaxException; +import java.util.HashMap; +import java.util.Map; + +public class TestSequenceGeneratorPlugin { + + private static final EELFLogger logger = EELFManager.getInstance().getLogger(TestSequenceGeneratorPlugin.class); + + @Test + public void testGenerateSequenceStart() throws URISyntaxException, IOException { + String inputJSON = readInput("/input/start.json"); + + Map params = new HashMap<>(); + SvcLogicContext context = new SvcLogicContext(); + context.setAttribute("inputJSON",inputJSON); + + SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl(); + plugin.generateSequence(params,context); + + String outputJSON = context.getAttribute("output"); + String actualOutput = readOutput("/output/start.json"); + Assert.assertEquals(outputJSON.trim(),actualOutput.trim()); + } + + + + @Test + public void testGenerateSequenceSingleVM()throws URISyntaxException, IOException { + String inputJSON = readInput("/input/start-single-vm.json"); + + Map params = new HashMap<>(); + SvcLogicContext context = new SvcLogicContext(); + context.setAttribute("inputJSON",inputJSON); + + SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl(); + plugin.generateSequence(params,context); + + String outputJSON = context.getAttribute("output"); + String actualOutput = readOutput("/output/start-single-vm.json"); + Assert.assertEquals(outputJSON.trim(),actualOutput.trim()); + } + + @Test + public void testGenerateSequenceNoStrategy() throws URISyntaxException, IOException { + String inputJSON = readInput("/input/no-strategy.json"); + + Map params = new HashMap<>(); + SvcLogicContext context = new SvcLogicContext(); + context.setAttribute("inputJSON",inputJSON); + + SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl(); + plugin.generateSequence(params,context); + + String outputJSON = context.getAttribute("output"); + String actualOutput = readOutput("/output/start.json"); + + Assert.assertEquals(outputJSON.trim(),actualOutput.trim()); + } + + @Test + public void testGenerateSequenceStop() throws URISyntaxException, IOException { + String inputJSON = readInput("/input/stop.json"); + + Map params = new HashMap<>(); + SvcLogicContext context = new SvcLogicContext(); + context.setAttribute("inputJSON",inputJSON); + + SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl(); + plugin.generateSequence(params,context); + + String outputJSON = context.getAttribute("output"); + String actualOutput = readOutput("/output/stop.json"); + + Assert.assertEquals(outputJSON.trim(),actualOutput.trim()); + } + + @Test + public void testGenerateSequenceWrongNumber() throws URISyntaxException, IOException { + String inputJSON = readInput("/input/wrongnumber.json"); + + Map params = new HashMap<>(); + SvcLogicContext context = new SvcLogicContext(); + context.setAttribute("inputJSON",inputJSON); + + SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl(); + plugin.generateSequence(params,context); + + String errorCode = context.getAttribute("error-code"); + String errorMessage = context.getAttribute("error-message"); + logger.debug("errorCode = " + errorCode); + Assert.assertEquals(errorCode,"401"); + Assert.assertEquals(errorMessage,"Error generating sequence Invalid Number for Wait Time 6a"); + } + + + @Test + public void testGenerateSequenceCyclic() throws URISyntaxException, IOException { + String inputJSON = readInput("/input/cyclic.json"); + + Map params = new HashMap<>(); + SvcLogicContext context = new SvcLogicContext(); + context.setAttribute("inputJSON",inputJSON); + + SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl(); + plugin.generateSequence(params,context); + + String errorCode = context.getAttribute("error-code"); + String errorMessage = context.getAttribute("error-message"); + logger.debug("errorCode = " + errorCode); + Assert.assertEquals(errorCode,"401"); + Assert.assertEquals(errorMessage,"Error generating sequence There seems to be no Root/Independent node for Vnfc dependencies"); + } + + + @Test + public void testGenerateSequenceWrongAction() throws URISyntaxException, IOException { + String inputJSON = readInput("/input/wrongaction.json"); + + Map params = new HashMap<>(); + SvcLogicContext context = new SvcLogicContext(); + context.setAttribute("inputJSON",inputJSON); + + SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl(); + plugin.generateSequence(params,context); + + String errorCode = context.getAttribute("error-code"); + String errorMessage = context.getAttribute("error-message"); + logger.debug("errorCode = " + errorCode); + Assert.assertEquals(errorCode,"401"); + Assert.assertEquals(errorMessage,"Error generating sequence Invalid Action start"); + } + + + @Test + public void testGenerateSequenceMissingRequestInfo() throws URISyntaxException, IOException { + String inputJSON = readInput("/input/missingrequestinfo.json"); + + Map params = new HashMap<>(); + SvcLogicContext context = new SvcLogicContext(); + context.setAttribute("inputJSON",inputJSON); + + SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl(); + plugin.generateSequence(params,context); + + String errorCode = context.getAttribute("error-code"); + String errorMessage = context.getAttribute("error-message"); + logger.debug("errorCode = " + errorCode); + Assert.assertEquals(errorCode,"401"); + Assert.assertEquals(errorMessage,"Error generating sequence Request info is not provided in the input"); + } + + @Test + public void testGenerateSequenceStopSingleVM() throws URISyntaxException, IOException{ + String inputJSON = readInput("/input/stop-single-vm.json"); + + Map params = new HashMap<>(); + SvcLogicContext context = new SvcLogicContext(); + context.setAttribute("inputJSON",inputJSON); + + SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl(); + plugin.generateSequence(params,context); + + String outputJSON = context.getAttribute("output"); + String actualOutput = readOutput("/output/stop-single-vm.json"); + Assert.assertEquals(outputJSON.trim(),actualOutput.trim()); + } + + @Test + public void testGenerateSequenceStopSingleVmPerVnfc() throws URISyntaxException, IOException{ + String inputJSON = readInput("/input/stop-single-vm-per-vnfc.json"); + + Map params = new HashMap<>(); + SvcLogicContext context = new SvcLogicContext(); + context.setAttribute("inputJSON",inputJSON); + + SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl(); + plugin.generateSequence(params,context); + + String outputJSON = context.getAttribute("output"); + String actualOutput = readOutput("/output/stop-single-vm-per-vnfc.json"); + Assert.assertEquals(outputJSON.trim(),actualOutput.trim()); + } + + @Test + public void testGenerateSequenceStartSingleVmPerVnfc() throws URISyntaxException, IOException{ + String inputJSON = readInput("/input/start-single-vm-per-vnfc.json"); + + Map params = new HashMap<>(); + SvcLogicContext context = new SvcLogicContext(); + context.setAttribute("inputJSON",inputJSON); + + SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl(); + plugin.generateSequence(params,context); + + String outputJSON = context.getAttribute("output"); + String actualOutput = readOutput("/output/start-single-vm-per-vnfc.json"); + Assert.assertEquals(outputJSON.trim(),actualOutput.trim()); + } + + @Test + public void testGenerateSequenceVnfcNotPresentInInventory() throws URISyntaxException, IOException { + String inputJSON = readInput("/input/CheckVNfcInInventory.json"); + + Map params = new HashMap<>(); + SvcLogicContext context = new SvcLogicContext(); + context.setAttribute("inputJSON",inputJSON); + SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl(); + plugin.generateSequence(params,context); + + String outputJSON = context.getAttribute("output"); + String actualOutput = readOutput("/output/CheckVnfcInInventory.json"); + + Assert.assertEquals(outputJSON.trim(),actualOutput.trim()); + } + + private String readInput(String inputFile) throws URISyntaxException, IOException { + File file = new File(this.getClass().getResource(inputFile).toURI()); + + byte[] bFile = new byte[(int) file.length()]; + FileInputStream fileInputStream = new FileInputStream(file); + fileInputStream.read(bFile); + fileInputStream.close(); + return new String(bFile); + } + private String readOutput(String outputFile) throws IOException,URISyntaxException { + File file = new File(this.getClass().getResource(outputFile).toURI()); + + byte[] bFile = new byte[(int) file.length()]; + FileInputStream fileInputStream = new FileInputStream(file); + fileInputStream.read(bFile); + fileInputStream.close(); + + String output=new String(bFile); + int start=output.indexOf("["); + int last=output.length(); + return output.substring(start,last); + + } +} diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/test/java/org/openecomp/appc/seqgen/TestSequenceGeneratorPlugin.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/test/java/org/openecomp/appc/seqgen/TestSequenceGeneratorPlugin.java deleted file mode 100644 index 748773a21..000000000 --- a/appc-sequence-generator/appc-sequence-generator-bundle/src/test/java/org/openecomp/appc/seqgen/TestSequenceGeneratorPlugin.java +++ /dev/null @@ -1,272 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APP-C - * ================================================================================ - * Copyright (C) 2017 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.seqgen; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import org.junit.Assert; -import org.junit.Test; -import org.onap.appc.seqgen.dgplugin.SequenceGeneratorPlugin; -import org.onap.appc.seqgen.dgplugin.impl.SequenceGeneratorPluginImpl; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.net.URISyntaxException; -import java.util.HashMap; -import java.util.Map; - -public class TestSequenceGeneratorPlugin { - - private static final EELFLogger logger = EELFManager.getInstance().getLogger(TestSequenceGeneratorPlugin.class); - - @Test - public void testGenerateSequenceStart() throws URISyntaxException, IOException { - String inputJSON = readInput("/input/start.json"); - - Map params = new HashMap<>(); - SvcLogicContext context = new SvcLogicContext(); - context.setAttribute("inputJSON",inputJSON); - - SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl(); - plugin.generateSequence(params,context); - - String outputJSON = context.getAttribute("output"); - String actualOutput = readOutput("/output/start.json"); - Assert.assertEquals(outputJSON.trim(),actualOutput.trim()); - } - - - - @Test - public void testGenerateSequenceSingleVM()throws URISyntaxException, IOException { - String inputJSON = readInput("/input/start-single-vm.json"); - - Map params = new HashMap<>(); - SvcLogicContext context = new SvcLogicContext(); - context.setAttribute("inputJSON",inputJSON); - - SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl(); - plugin.generateSequence(params,context); - - String outputJSON = context.getAttribute("output"); - String actualOutput = readOutput("/output/start-single-vm.json"); - Assert.assertEquals(outputJSON.trim(),actualOutput.trim()); - } - - @Test - public void testGenerateSequenceNoStrategy() throws URISyntaxException, IOException { - String inputJSON = readInput("/input/no-strategy.json"); - - Map params = new HashMap<>(); - SvcLogicContext context = new SvcLogicContext(); - context.setAttribute("inputJSON",inputJSON); - - SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl(); - plugin.generateSequence(params,context); - - String outputJSON = context.getAttribute("output"); - String actualOutput = readOutput("/output/start.json"); - - Assert.assertEquals(outputJSON.trim(),actualOutput.trim()); - } - - @Test - public void testGenerateSequenceStop() throws URISyntaxException, IOException { - String inputJSON = readInput("/input/stop.json"); - - Map params = new HashMap<>(); - SvcLogicContext context = new SvcLogicContext(); - context.setAttribute("inputJSON",inputJSON); - - SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl(); - plugin.generateSequence(params,context); - - String outputJSON = context.getAttribute("output"); - String actualOutput = readOutput("/output/stop.json"); - - Assert.assertEquals(outputJSON.trim(),actualOutput.trim()); - } - - @Test - public void testGenerateSequenceWrongNumber() throws URISyntaxException, IOException { - String inputJSON = readInput("/input/wrongnumber.json"); - - Map params = new HashMap<>(); - SvcLogicContext context = new SvcLogicContext(); - context.setAttribute("inputJSON",inputJSON); - - SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl(); - plugin.generateSequence(params,context); - - String errorCode = context.getAttribute("error-code"); - String errorMessage = context.getAttribute("error-message"); - logger.debug("errorCode = " + errorCode); - Assert.assertEquals(errorCode,"401"); - Assert.assertEquals(errorMessage,"Error generating sequence Invalid Number for Wait Time 6a"); - } - - - @Test - public void testGenerateSequenceCyclic() throws URISyntaxException, IOException { - String inputJSON = readInput("/input/cyclic.json"); - - Map params = new HashMap<>(); - SvcLogicContext context = new SvcLogicContext(); - context.setAttribute("inputJSON",inputJSON); - - SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl(); - plugin.generateSequence(params,context); - - String errorCode = context.getAttribute("error-code"); - String errorMessage = context.getAttribute("error-message"); - logger.debug("errorCode = " + errorCode); - Assert.assertEquals(errorCode,"401"); - Assert.assertEquals(errorMessage,"Error generating sequence There seems to be no Root/Independent node for Vnfc dependencies"); - } - - - @Test - public void testGenerateSequenceWrongAction() throws URISyntaxException, IOException { - String inputJSON = readInput("/input/wrongaction.json"); - - Map params = new HashMap<>(); - SvcLogicContext context = new SvcLogicContext(); - context.setAttribute("inputJSON",inputJSON); - - SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl(); - plugin.generateSequence(params,context); - - String errorCode = context.getAttribute("error-code"); - String errorMessage = context.getAttribute("error-message"); - logger.debug("errorCode = " + errorCode); - Assert.assertEquals(errorCode,"401"); - Assert.assertEquals(errorMessage,"Error generating sequence Invalid Action start"); - } - - - @Test - public void testGenerateSequenceMissingRequestInfo() throws URISyntaxException, IOException { - String inputJSON = readInput("/input/missingrequestinfo.json"); - - Map params = new HashMap<>(); - SvcLogicContext context = new SvcLogicContext(); - context.setAttribute("inputJSON",inputJSON); - - SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl(); - plugin.generateSequence(params,context); - - String errorCode = context.getAttribute("error-code"); - String errorMessage = context.getAttribute("error-message"); - logger.debug("errorCode = " + errorCode); - Assert.assertEquals(errorCode,"401"); - Assert.assertEquals(errorMessage,"Error generating sequence Request info is not provided in the input"); - } - - @Test - public void testGenerateSequenceStopSingleVM() throws URISyntaxException, IOException{ - String inputJSON = readInput("/input/stop-single-vm.json"); - - Map params = new HashMap<>(); - SvcLogicContext context = new SvcLogicContext(); - context.setAttribute("inputJSON",inputJSON); - - SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl(); - plugin.generateSequence(params,context); - - String outputJSON = context.getAttribute("output"); - String actualOutput = readOutput("/output/stop-single-vm.json"); - Assert.assertEquals(outputJSON.trim(),actualOutput.trim()); - } - - @Test - public void testGenerateSequenceStopSingleVmPerVnfc() throws URISyntaxException, IOException{ - String inputJSON = readInput("/input/stop-single-vm-per-vnfc.json"); - - Map params = new HashMap<>(); - SvcLogicContext context = new SvcLogicContext(); - context.setAttribute("inputJSON",inputJSON); - - SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl(); - plugin.generateSequence(params,context); - - String outputJSON = context.getAttribute("output"); - String actualOutput = readOutput("/output/stop-single-vm-per-vnfc.json"); - Assert.assertEquals(outputJSON.trim(),actualOutput.trim()); - } - - @Test - public void testGenerateSequenceStartSingleVmPerVnfc() throws URISyntaxException, IOException{ - String inputJSON = readInput("/input/start-single-vm-per-vnfc.json"); - - Map params = new HashMap<>(); - SvcLogicContext context = new SvcLogicContext(); - context.setAttribute("inputJSON",inputJSON); - - SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl(); - plugin.generateSequence(params,context); - - String outputJSON = context.getAttribute("output"); - String actualOutput = readOutput("/output/start-single-vm-per-vnfc.json"); - Assert.assertEquals(outputJSON.trim(),actualOutput.trim()); - } - - @Test - public void testGenerateSequenceVnfcNotPresentInInventory() throws URISyntaxException, IOException { - String inputJSON = readInput("/input/CheckVNfcInInventory.json"); - - Map params = new HashMap<>(); - SvcLogicContext context = new SvcLogicContext(); - context.setAttribute("inputJSON",inputJSON); - SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl(); - plugin.generateSequence(params,context); - - String outputJSON = context.getAttribute("output"); - String actualOutput = readOutput("/output/CheckVnfcInInventory.json"); - - Assert.assertEquals(outputJSON.trim(),actualOutput.trim()); - } - - private String readInput(String inputFile) throws URISyntaxException, IOException { - File file = new File(this.getClass().getResource(inputFile).toURI()); - - byte[] bFile = new byte[(int) file.length()]; - FileInputStream fileInputStream = new FileInputStream(file); - fileInputStream.read(bFile); - fileInputStream.close(); - return new String(bFile); - } - private String readOutput(String outputFile) throws IOException,URISyntaxException { - File file = new File(this.getClass().getResource(outputFile).toURI()); - - byte[] bFile = new byte[(int) file.length()]; - FileInputStream fileInputStream = new FileInputStream(file); - fileInputStream.read(bFile); - fileInputStream.close(); - - String output=new String(bFile); - int start=output.indexOf("["); - int last=output.length(); - return output.substring(start,last); - - } -} -- cgit 1.2.3-korg