diff options
Diffstat (limited to 'appc-sequence-generator/appc-sequence-generator-bundle/src/main/java')
18 files changed, 2074 insertions, 0 deletions
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 new file mode 100644 index 000000000..7fa1dcb4e --- /dev/null +++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/opendaylight/yang/gen/v1/org/openecomp/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.openecomp.appc.sequencegenerator.impl.rev170706; + +import org.openecomp.appc.seqgen.provider.SequenceGeneratorProvider; + +public class SequenceGeneratorModule extends org.opendaylight.yang.gen.v1.org.openecomp.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.openecomp.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 new file mode 100644 index 000000000..3ebba2076 --- /dev/null +++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/opendaylight/yang/gen/v1/org/openecomp/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.openecomp.appc.sequencegenerator.impl.rev170706; +public class SequenceGeneratorModuleFactory extends org.opendaylight.yang.gen.v1.org.openecomp.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 new file mode 100644 index 000000000..0eba668ef --- /dev/null +++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/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.openecomp.appc.seqgen; + + +import org.openecomp.appc.dg.objects.VnfcFlowModel; +import org.openecomp.appc.exceptions.APPCException; +import org.openecomp.appc.seqgen.objects.SequenceGeneratorInput; +import org.openecomp.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<Transaction> 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 new file mode 100644 index 000000000..2264751cf --- /dev/null +++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/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.openecomp.appc.seqgen.dgplugin; + +import org.openecomp.sdnc.sli.SvcLogicContext; +import org.openecomp.sdnc.sli.SvcLogicJavaPlugin; + +import java.util.Map; + +public interface SequenceGeneratorPlugin extends SvcLogicJavaPlugin{ + + void generateSequence(Map<String,String> 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 new file mode 100644 index 000000000..6671203e7 --- /dev/null +++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/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.openecomp.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.openecomp.appc.dg.objects.*; +import org.openecomp.appc.domainmodel.Vnf; +import org.openecomp.appc.domainmodel.Vnfc; +import org.openecomp.appc.domainmodel.Vserver; +import org.openecomp.appc.domainmodel.lcm.VNFOperation; +import org.openecomp.appc.exceptions.APPCException; +import org.openecomp.appc.seqgen.SequenceGenerator; +import org.openecomp.appc.seqgen.dgplugin.SequenceGeneratorPlugin; +import org.openecomp.appc.seqgen.impl.SequenceGeneratorFactory; +import org.openecomp.appc.seqgen.objects.Constants; +import org.openecomp.appc.seqgen.objects.SequenceGeneratorInput; +import org.openecomp.appc.seqgen.objects.Transaction; +import org.openecomp.sdnc.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<String, String> 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<Transaction> 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<Transaction> 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<Node<Vnfc>> 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<Vnfc> 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<Vnfc> 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<Vnfc> getNode(Set<Node<Vnfc>> dependency, String vnfcType) { + for (Node<Vnfc> 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<Vnfc, List<Vserver>> 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<Vserver> vServers = vfcs.get(vfc); + if (vServers == null) { + vServers = new LinkedList<>(); + vfcs.put(vfc, vServers); + } + vServers.add(vserver); + } + + for (Map.Entry<Vnfc, List<Vserver>> entry : vfcs.entrySet()) { + Vnfc vnfc = entry.getKey(); + List<Vserver> 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 new file mode 100644 index 000000000..5d41fffe1 --- /dev/null +++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/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.openecomp.appc.seqgen.impl; + +import org.openecomp.appc.domainmodel.lcm.VNFOperation; +import org.openecomp.appc.exceptions.APPCException; +import org.openecomp.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 new file mode 100644 index 000000000..acdeddd30 --- /dev/null +++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/impl/StartSequenceGenerator.java @@ -0,0 +1,291 @@ +/*- + * ============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.openecomp.appc.seqgen.impl; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.apache.commons.lang3.StringUtils; +import org.openecomp.appc.dg.flowbuilder.FlowBuilder; +import org.openecomp.appc.dg.flowbuilder.impl.FlowBuilderFactory; +import org.openecomp.appc.dg.objects.FlowStrategies; +import org.openecomp.appc.dg.objects.InventoryModel; +import org.openecomp.appc.dg.objects.VnfcDependencyModel; +import org.openecomp.appc.dg.objects.VnfcFlowModel; +import org.openecomp.appc.domainmodel.Vnfc; +import org.openecomp.appc.domainmodel.Vserver; +import org.openecomp.appc.exceptions.APPCException; +import org.openecomp.appc.seqgen.SequenceGenerator; +import org.openecomp.appc.seqgen.objects.*; + +import java.util.*; + +import static org.openecomp.appc.seqgen.objects.Constants.*; + +public class StartSequenceGenerator implements SequenceGenerator { + + private static final EELFLogger logger = EELFManager.getInstance().getLogger(StartSequenceGenerator.class); + + private List<Transaction> generateSequenceWithOutDependency(SequenceGeneratorInput input) throws APPCException { + + List<Transaction> transactionList = new LinkedList<>(); + Integer transactionId = 1; + List<Vnfc> invVnfcList = input.getInventoryModel().getVnf().getVnfcs(); + boolean singleTransaction=checkSingleTransaction(invVnfcList); + for (Vnfc vnfc : invVnfcList) { + List<Vserver> vms = vnfc.getVserverList(); + List<Integer> 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<Vnfc> invVnfcList) { + int vServerCount=0; + for(Vnfc vnfc : invVnfcList) { + List<Vserver> 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<String, String> ignoreAction = new HashMap<>(); + ignoreAction.put(ResponseAction.IGNORE.getAction(), Boolean.TRUE.toString()); + ignoreResponse.setResponseAction(ignoreAction); + transaction.addResponse(ignoreResponse); + } + + private List<Transaction> generateSequenceWithDependencyModel(VnfcFlowModel flowModel, SequenceGeneratorInput input) throws APPCException { + Integer waitTime = readWaitTime(input); + Integer retryCount = readRetryCount(input); + List<Transaction> transactionList = new LinkedList<>(); + Integer transactionId = 1; + Iterator<List<Vnfc>> itr = flowModel.getModelIterator(); + while (itr.hasNext()) { + List<Vnfc> vnfcs = itr.next(); + for (Vnfc vnfc : vnfcs) { + List<Vserver> vms = vnfc.getVserverList(); + List<Integer> transactionIds = new LinkedList<>(); + transactionId = updateTransactions(input, transactionList, transactionId, vms, transactionIds); + + boolean startApplicationSupported = readApplicationStartCapability(input); + transactionId = checkAndUpdateStartApplication(input, transactionList, transactionId, vnfc, transactionIds, startApplicationSupported); + + boolean healthCheckSupported = readHealthCheckCapabilites(input.getCapability()); + transactionId = checkAndUpdateHealthCheck(input, waitTime, retryCount, transactionList, transactionId, vnfc, healthCheckSupported); + } + } + return transactionList; + } + + private Integer checkAndUpdateHealthCheck(SequenceGeneratorInput input, Integer waitTime, Integer retryCount, List<Transaction> transactionList, Integer transactionId, Vnfc vnfc, boolean healthCheckSupported) { + 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<String, String> 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<String, String> 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<String, String> failureResonseAction = new HashMap<>(); + failureResonseAction.put(ResponseAction.STOP.getAction(), Boolean.TRUE.toString()); + failureResponse.setResponseAction(failureResonseAction); + healthCheckTransaction.addResponse(failureResponse); + transactionList.add(healthCheckTransaction); + } + return transactionId; + } + + private Integer checkAndUpdateStartApplication(SequenceGeneratorInput input, List<Transaction> transactionList, Integer transactionId, Vnfc vnfc, List<Integer> transactionIds, boolean startApplicationSupported) { + 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<PreCheckOption> preCheckOptions = new LinkedList<>(); + for (Integer vmTransactionId : transactionIds) { + setPreCheckOptions(preCheckOptions, vmTransactionId); + } + startAppTransaction.setPreCheckOperator(PreCheckOperator.ANY.getOperator()); + startAppTransaction.setPrecheckOptions(preCheckOptions); + transactionList.add(startAppTransaction); + } + return transactionId; + } + + private Integer updateTransactions(SequenceGeneratorInput input, List<Transaction> transactionList, Integer transactionId, List<Vserver> vms, List<Integer> transactionIds) { + 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); + } + return transactionId; + } + + private void setPreCheckOptions(List<PreCheckOption> preCheckOptions, Integer vmTransactionId) { + PreCheckOption option = new PreCheckOption(); + option.setPreTransactionId(vmTransactionId); + option.setParamName("status"); + option.setParamValue("success"); + preCheckOptions.add(option); + } + + @Override + public List<Transaction> 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<String, String> 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<String, List<String>> capabilities) { + if (capabilities != null) { + List<String> 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<String, List<String>> capability = input.getCapability(); + if (capability != null) { + List<String> 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 new file mode 100644 index 000000000..6dec0e61f --- /dev/null +++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/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.openecomp.appc.seqgen.impl; + +import org.apache.commons.lang3.StringUtils; +import org.openecomp.appc.dg.flowbuilder.FlowBuilder; +import org.openecomp.appc.dg.flowbuilder.impl.FlowBuilderFactory; +import org.openecomp.appc.dg.objects.FlowStrategies; +import org.openecomp.appc.dg.objects.InventoryModel; +import org.openecomp.appc.dg.objects.VnfcDependencyModel; +import org.openecomp.appc.dg.objects.VnfcFlowModel; +import org.openecomp.appc.domainmodel.Vnfc; +import org.openecomp.appc.domainmodel.Vserver; +import org.openecomp.appc.exceptions.APPCException; +import org.openecomp.appc.seqgen.SequenceGenerator; +import org.openecomp.appc.seqgen.objects.*; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +import java.util.*; + +import static org.openecomp.appc.seqgen.objects.Constants.*; + +public class StopSequenceGenerator implements SequenceGenerator { + + private static final EELFLogger logger = EELFManager.getInstance().getLogger(StartSequenceGenerator.class); + + @Override + public List<Transaction> 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<Transaction> generateSequenceWithOutDependency(SequenceGeneratorInput input){ + List<Transaction> transactionList = new LinkedList<>(); + Integer transactionId = 1; + List<Integer> transactionIds = new LinkedList<>(); + List<Vnfc> invVnfcList = input.getInventoryModel().getVnf().getVnfcs(); + boolean singleTransaction=checkSingleTransaction(invVnfcList); + for (Vnfc vnfc : invVnfcList) { + List<Vserver> 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<String,String> failureAction = new HashMap<>(); + failureAction.put(ResponseAction.IGNORE.getAction(),Boolean.TRUE.toString()); + failureResponse.setResponseAction(failureAction); + transaction.addResponse(failureResponse); + } + private boolean checkSingleTransaction(List<Vnfc> invVnfcList) { + int vServerCount=0; + for(Vnfc vnfc : invVnfcList) { + List<Vserver> vms = vnfc.getVserverList(); + vServerCount=vServerCount+vms.size(); + } + return vServerCount <= 1; + } + + private List<Transaction> generateSequenceWithDependencyModel(VnfcFlowModel flowModel,SequenceGeneratorInput input){ + List<Transaction> transactionList = new LinkedList<>(); + Integer transactionId = 1; + List<Integer> transactionIds = new LinkedList<>(); + Iterator<List<Vnfc>> itr = flowModel.getModelIterator(); + while (itr.hasNext()){ + List<Vnfc> vnfcs = itr.next(); + for(Vnfc vnfc:vnfcs){ + boolean stopApplicationSupported = readApplicationStopCapability(input); + if(stopApplicationSupported){ + 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<Vserver> 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<String, String> 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<String,List<String>> capability = input.getCapability(); + if(capability!= null){ + List<String> 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 new file mode 100644 index 000000000..ae3ed942d --- /dev/null +++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/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.openecomp.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 new file mode 100644 index 000000000..354145f02 --- /dev/null +++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/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.openecomp.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 new file mode 100644 index 000000000..860fac7e2 --- /dev/null +++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/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.openecomp.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 new file mode 100644 index 000000000..697e13e3b --- /dev/null +++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/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.openecomp.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 new file mode 100644 index 000000000..70d4e9a0c --- /dev/null +++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/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.openecomp.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 new file mode 100644 index 000000000..9247e6e7f --- /dev/null +++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/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.openecomp.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<String,String> 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<String, String> getResponseAction() { + return responseAction; + } + + public void setResponseAction(Map<String, String> 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 new file mode 100644 index 000000000..851a07582 --- /dev/null +++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/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.openecomp.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.openecomp.appc.dg.objects.InventoryModel; +import org.openecomp.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<String,String> tunableParams; + + @JsonProperty("capabilities") + private Map<String,List<String>> 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<String, String> getTunableParams() { + return tunableParams; + } + + public void setTunableParams(Map<String, String> tunableParams) { + this.tunableParams = tunableParams; + } + + public Map<String, List<String>> getCapability() { + return capability; + } + + public void setCapability(Map<String, List<String>> 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 new file mode 100644 index 000000000..b72e46e7e --- /dev/null +++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/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.openecomp.appc.seqgen.objects; + +import org.openecomp.appc.dg.objects.InventoryModel; +import org.openecomp.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<String,String> tunableParams; + + private Map<String,List<String>> capability; + + public SequenceGeneratorInputBuilder requestInfo(RequestInfo requestInfo){ + this.requestInfo = requestInfo; + return this; + } + + public SequenceGeneratorInputBuilder capability(String level,List<String> 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 new file mode 100644 index 000000000..b49d1323a --- /dev/null +++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/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.openecomp.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<String,String> parameters; + + @JsonProperty("precheck-operator") + private String preCheckOperator; + + + @JsonProperty("precheck-options") + private List<PreCheckOption> precheckOptions; + + @JsonProperty("responses") + private List<Response> 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<String, String> getParameters() { + return parameters; + } + + public void setParameters(Map<String, String> parameters) { + this.parameters = parameters; + } + + public List<Response> getResponses() { + return responses; + } + + public void setResponses(List<Response> 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<PreCheckOption> getPrecheckOptions() { + return precheckOptions; + } + + public void setPrecheckOptions(List<PreCheckOption> 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 new file mode 100644 index 000000000..b3aab54e1 --- /dev/null +++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/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.openecomp.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.openecomp.appc.sequencegenerator.rev170706.GenerateSequenceInput; +import org.opendaylight.yang.gen.v1.org.openecomp.appc.sequencegenerator.rev170706.GenerateSequenceOutput; +import org.opendaylight.yang.gen.v1.org.openecomp.appc.sequencegenerator.rev170706.GenerateSequenceOutputBuilder; +import org.opendaylight.yang.gen.v1.org.openecomp.appc.sequencegenerator.rev170706.SequenceGeneratorService; +import org.opendaylight.yang.gen.v1.org.openecomp.appc.sequencegenerator.rev170706.dependency.info.dependency.info.Vnfcs; +import org.opendaylight.yang.gen.v1.org.openecomp.appc.sequencegenerator.rev170706.inventory.info.inventory.info.vnf.info.Vm; +import org.opendaylight.yang.gen.v1.org.openecomp.appc.sequencegenerator.rev170706.response.StatusBuilder; +import org.opendaylight.yang.gen.v1.org.openecomp.appc.sequencegenerator.rev170706.response.Transactions; +import org.opendaylight.yang.gen.v1.org.openecomp.appc.sequencegenerator.rev170706.response.TransactionsBuilder; +import org.opendaylight.yang.gen.v1.org.openecomp.appc.sequencegenerator.rev170706.response.transactions.ActionIdentifier; +import org.opendaylight.yang.gen.v1.org.openecomp.appc.sequencegenerator.rev170706.response.transactions.*; +import org.opendaylight.yang.gen.v1.org.openecomp.appc.sequencegenerator.rev170706.response.transactions.responses.ResponseActionBuilder; +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.opendaylight.yangtools.yang.common.RpcResultBuilder; +import org.openecomp.appc.dg.objects.InventoryModel; +import org.openecomp.appc.dg.objects.Node; +import org.openecomp.appc.dg.objects.VnfcDependencyModel; +import org.openecomp.appc.domainmodel.Vnf; +import org.openecomp.appc.domainmodel.Vserver; +import org.openecomp.appc.domainmodel.lcm.VNFOperation; +import org.openecomp.appc.exceptions.APPCException; +import org.openecomp.appc.seqgen.SequenceGenerator; +import org.openecomp.appc.seqgen.impl.SequenceGeneratorFactory; +import org.openecomp.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<SequenceGeneratorService> 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<RpcResult<GenerateSequenceOutput>> generateSequence(GenerateSequenceInput input) { + RpcResult<GenerateSequenceOutput> rpcResult=null; + log.debug("Received input = " + input ); + try { + SequenceGenerator seqGenerator = SequenceGeneratorFactory.getInstance() + .createSequenceGenerator(VNFOperation.findByString(input.getRequestInfo().getAction().name())); + SequenceGeneratorInput seqGenInput = buildSeqGenInput(input); + List<Transaction> 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<GenerateSequenceOutput> buildSuccessResponse(List<Transaction> transactions) { + + List<Transactions> 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> 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<Responses> 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 + .<GenerateSequenceOutput> status(true) + .withResult(builder.build()).build(); + } + + private List<Responses> getResponses(Transaction transaction) { + List<Responses> responseList = new LinkedList<>(); + for(Response resp : transaction.getResponses()){ + Map<String,String> 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> vnfcs = input.getDependencyInfo().getVnfcs(); + Set<Node<org.openecomp.appc.domainmodel.Vnfc>> dependencies = new HashSet<>(); + for(Vnfcs vnfcObj:vnfcs){ + org.openecomp.appc.domainmodel.Vnfc vnfc; + Node<org.openecomp.appc.domainmodel.Vnfc> currentNode = readNode(vnfcObj.getVnfcType(),dependencies); + if(currentNode == null){ + vnfc = new org.openecomp.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<org.openecomp.appc.domainmodel.Vnfc> parentNode = readNode(parentVnfcType,dependencies); + if(parentNode == null){ + org.openecomp.appc.domainmodel.Vnfc parentVnfc = new org.openecomp.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<org.openecomp.appc.domainmodel.Vnfc> readNode(String vnfcType, Set<Node<org.openecomp.appc.domainmodel.Vnfc>> dependencies) { + for(Node<org.openecomp.appc.domainmodel.Vnfc> 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<org.openecomp.appc.domainmodel.Vnfc,List<Vserver>> 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.openecomp.appc.domainmodel.Vnfc vnfc = new org.openecomp.appc.domainmodel.Vnfc(vm.getVnfc().getVnfcType(),null,vm.getVnfc().getVnfcName()); + List<Vserver> 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<org.openecomp.appc.domainmodel.Vnfc,List<Vserver>> entry:map.entrySet()){ + org.openecomp.appc.domainmodel.Vnfc vnfc = entry.getKey(); + List<Vserver> vmList = entry.getValue(); + vnfc.addVms(vmList); + vnf.addVnfc(vnfc); + } + return new InventoryModel(vnf); + } + + private RpcResult<GenerateSequenceOutput> buildFailureResponse(String errorMessage){ + GenerateSequenceOutputBuilder sequenceGeneratorOutputBuilder=new GenerateSequenceOutputBuilder(); + StatusBuilder statusBuilder =new StatusBuilder(); + statusBuilder.setCode(401); + statusBuilder.setMessage(errorMessage); + sequenceGeneratorOutputBuilder.setStatus(statusBuilder.build()); + return RpcResultBuilder + .<GenerateSequenceOutput> status(true) + .withResult(sequenceGeneratorOutputBuilder.build()) + .build(); + } +} |