diff options
author | Patrick Brady <pb071s@att.com> | 2017-06-01 10:45:37 -0700 |
---|---|---|
committer | Patrick Brady <pb071s@att.com> | 2017-06-02 13:05:15 -0700 |
commit | c7d0075d223eab9f89fd28853c4b138792059be9 (patch) | |
tree | 40aa3e41e598ea7a59bcf6899a2004c1abab11c2 /appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org | |
parent | 8aac2df744820304ee29354333661699e9695939 (diff) |
Merge of new rebased code
Change-Id: I9b8d1f69eb3e0af1935ed8304fea4bf54c1aac47
Signed-off-by: Patrick Brady <pb071s@att.com>
Diffstat (limited to 'appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org')
22 files changed, 1409 insertions, 0 deletions
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/DependencyManager.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/DependencyManager.java new file mode 100644 index 000000000..5b5b3451b --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/DependencyManager.java @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : 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.dg.dependencymanager; + +import org.openecomp.appc.dg.dependencymanager.exception.DependencyModelNotFound; +import org.openecomp.appc.dg.flowbuilder.exception.InvalidDependencyModel; +import org.openecomp.appc.dg.objects.DependencyTypes; +import org.openecomp.appc.dg.objects.VnfcDependencyModel; + +import org.openecomp.appc.metadata.objects.DependencyModelIdentifier; + +public interface DependencyManager { + VnfcDependencyModel getVnfcDependencyModel(DependencyModelIdentifier modelIdentifier, DependencyTypes dependencyType) throws InvalidDependencyModel, DependencyModelNotFound; +} diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/DependencyType.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/DependencyType.java new file mode 100644 index 000000000..06a29cd1d --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/DependencyType.java @@ -0,0 +1,32 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : 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.dg.dependencymanager; + +import org.openecomp.appc.dg.dependencymanager.exception.DependencyModelNotFound; +import org.openecomp.appc.dg.flowbuilder.exception.InvalidDependencyModel; +import org.openecomp.appc.dg.objects.VnfcDependencyModel; + +import org.openecomp.appc.metadata.objects.DependencyModelIdentifier; + +public interface DependencyType { + VnfcDependencyModel getVnfcDependencyModel(DependencyModelIdentifier modelIdentifier) throws InvalidDependencyModel, DependencyModelNotFound; +} diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/exception/DependencyModelNotFound.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/exception/DependencyModelNotFound.java new file mode 100644 index 000000000..521e0edb3 --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/exception/DependencyModelNotFound.java @@ -0,0 +1,29 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : 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.dg.dependencymanager.exception; + + +public class DependencyModelNotFound extends Exception { + public DependencyModelNotFound(String message){ + super(message); + } +} diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/helper/DependencyModelParser.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/helper/DependencyModelParser.java new file mode 100644 index 000000000..397042ecd --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/helper/DependencyModelParser.java @@ -0,0 +1,183 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : 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.dg.dependencymanager.helper; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; +import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; +import org.apache.commons.lang3.StringUtils; +import org.openecomp.appc.dg.flowbuilder.exception.InvalidDependencyModel; +import org.openecomp.appc.dg.objects.Node; +import org.openecomp.appc.dg.objects.VnfcDependencyModel; +import org.openecomp.appc.domainmodel.Vnfc; + +import java.io.IOException; +import java.util.*; + + +public class DependencyModelParser { + + private static final EELFLogger logger = EELFManager.getInstance().getLogger(DependencyModelParser.class); + private static Map<String, String> dependencyMap; + private static final String PROPERTIES = "properties"; + private static final String ACTIVE_ACTIVE = "Active-Active"; + private static final String ACTIVE_PASSIVE = "Active-Passive"; + private static final String HIGH_AVAILABLITY = "high_availablity"; + private static final String MANDATORY = "mandatory"; + private static final String TOPOLOGY_TEMPLATE = "topology_template"; + + static { + Map<String, String> dependencyTypeMappingMap =new HashMap<>(); + dependencyTypeMappingMap.put("geo-activeactive", ACTIVE_ACTIVE); + dependencyTypeMappingMap.put("geo-activestandby", ACTIVE_PASSIVE); + dependencyTypeMappingMap.put("local-activeactive", ACTIVE_ACTIVE); + dependencyTypeMappingMap.put("local-activestandby", ACTIVE_PASSIVE); + dependencyMap = Collections.unmodifiableMap(dependencyTypeMappingMap); + } + + public VnfcDependencyModel generateDependencyModel(String vnfModel,String vnfType) { + Set<Node<Vnfc>> dependencies = new HashSet<>(); + ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); + boolean mandatory; + String resilienceType; + String prefix = "org.openecomp.resource.vfc."+vnfType+".abstract.nodes."; + try { + ObjectNode root = (ObjectNode) mapper.readTree(vnfModel); + logger.debug("VNF Model after parsing: " + root); + + if(root.get(TOPOLOGY_TEMPLATE) == null || root.get(TOPOLOGY_TEMPLATE).get("node_templates") == null) { + throw new InvalidDependencyModel("Dependency model is missing 'topology_template' or 'node_templates' elements"); + } + + JsonNode topologyTemplateNode = root.get(TOPOLOGY_TEMPLATE); + JsonNode nodeTemplateNode = topologyTemplateNode.get("node_templates"); + Iterator<Map.Entry<String, JsonNode>> itretor = nodeTemplateNode.fields(); + for (JsonNode yamlNode : nodeTemplateNode) { + logger.debug("Processing node: " + yamlNode); + String vnfcType = itretor.next().getKey(); + String type = yamlNode.get("type").textValue(); + type = type.substring(0,type.lastIndexOf(".")+1); + if(type.concat(vnfcType).toLowerCase().startsWith(prefix.concat(vnfcType).toLowerCase())) { + + if(yamlNode.get(PROPERTIES).findValue(HIGH_AVAILABLITY) == null || yamlNode.get(PROPERTIES).findValue(HIGH_AVAILABLITY).asText().isEmpty()) { + resilienceType = ACTIVE_ACTIVE; + }else { + resilienceType = dependencyMap.get(yamlNode.get(PROPERTIES).findValue(HIGH_AVAILABLITY).textValue()); + } + + if(yamlNode.get(PROPERTIES).findValue(MANDATORY) == null || yamlNode.get(PROPERTIES).findValue(MANDATORY).asText().isEmpty()) { + mandatory = false; + }else { + mandatory = yamlNode.get(PROPERTIES).findValue(MANDATORY).booleanValue(); + } + String[] parentList = getDependencyArray(yamlNode); + Node<Vnfc> vnfcNode = getNode(dependencies, vnfcType); + if (vnfcNode != null) { + logger.debug("Dependency node already exists for vnfc Type: " + vnfcType); + if (StringUtils.isEmpty(vnfcNode.getChild().getResilienceType())) { + logger.debug("Updating resilience type, dependencies and mandatory attribute for VNFC type: " + vnfcType); + vnfcNode.getChild().setResilienceType(resilienceType); + if (parentList != null && parentList.length > 0) { + addDependencies(dependencies, vnfcNode, parentList); + } + vnfcNode.getChild().setMandatory(mandatory); + } + + } else { + logger.debug("Creating dependency node for : " + vnfcType); + vnfcNode = new Node<>(new Vnfc(vnfcType, resilienceType, null, mandatory)); + if (parentList != null && parentList.length > 0) + addDependencies(dependencies, vnfcNode, parentList); + logger.debug("Adding VNFC to dependency model : " + vnfcNode); + dependencies.add(vnfcNode); + } + } + } + } catch (IOException e) { + logger.error("Error parsing dependency model : " + vnfModel); + logger.error("Error message : " + e); + throw new InvalidDependencyModel("Error parsing dependency model. " + e.getMessage()); + } + return new VnfcDependencyModel(dependencies); + } + + private void addDependencies(Set<Node<Vnfc>> nodes, Node node, String[] parentList) { + for (String type : parentList) { + String parentType = getVnfcType(type); + Node<Vnfc> parentNode = getNode(nodes, parentType); + if (parentNode != null) { + logger.debug("VNFC already exists for VNFC type: " + parentType + ". Adding it to parent list "); + node.addParent(parentNode.getChild()); + } else { + logger.debug("VNFC does not exist for VNFC type: " + parentType + ". Creating new VNFC "); + parentNode = new Node<>(new Vnfc(parentType, null)); + node.addParent(parentNode.getChild()); + logger.debug("Adding VNFC to dependency model : " + parentNode); + nodes.add(parentNode); + } + } + } + + private String[] getDependencyArray(JsonNode node) { + JsonNode requirementsNode = node.get("requirements"); + List<String> dependencyList = new ArrayList(); + if(requirementsNode!=null) { + for (JsonNode internalNode : requirementsNode) { + if (nodeNullCheck(internalNode) &&"tosca.capabilities.Node".equalsIgnoreCase(internalNode.get("capability").asText()) + && "tosca.relationships.DependsOn".equalsIgnoreCase(internalNode.get("relationship").asText())) { + if(internalNode.get("node") != null) { + dependencyList.add(internalNode.get("node").asText()); + }else{ + throw new InvalidDependencyModel("Error parsing dependency model. " + "Dependent Node not found for "+ node.get("type")); + } + } + } + return dependencyList.toArray(new String[0]); + }else{ + return new String[0]; + } + } + + private boolean nodeNullCheck(JsonNode internalNode) { + return internalNode.get("dependency") != null && internalNode.get("capability") != null && internalNode.get("relationship") != null; + } + + private Node<Vnfc> getNode(Set<Node<Vnfc>> nodes, String vnfcType) { + Iterator itr = nodes.iterator(); + Node<Vnfc> node; + while (itr.hasNext()) { + node = (Node<Vnfc>) itr.next(); + if (node.getChild().getVnfcType().equalsIgnoreCase(vnfcType)) { + return node; + } + } + return null; + } + + private String getVnfcType(String type) { + return type.substring(type.lastIndexOf('.') + 1, type.length()); + } + +} diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/impl/DependencyManagerImpl.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/impl/DependencyManagerImpl.java new file mode 100644 index 000000000..758d5ee7e --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/impl/DependencyManagerImpl.java @@ -0,0 +1,71 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : 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.dg.dependencymanager.impl; + +import org.openecomp.appc.dg.dependencymanager.DependencyManager; +import org.openecomp.appc.dg.dependencymanager.DependencyType; +import org.openecomp.appc.dg.dependencymanager.exception.DependencyModelNotFound; +import org.openecomp.appc.dg.flowbuilder.exception.InvalidDependencyModel; +import org.openecomp.appc.dg.objects.DependencyTypes; +import org.openecomp.appc.dg.objects.VnfcDependencyModel; + +import org.openecomp.appc.cache.MetadataCache; +import org.openecomp.appc.cache.impl.MetadataCacheFactory; +import org.openecomp.appc.metadata.objects.DependencyModelIdentifier; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +public class DependencyManagerImpl implements DependencyManager { + + private static final EELFLogger logger = EELFManager.getInstance().getLogger(DependencyManagerImpl.class); + + MetadataCache<DependencyModelIdentifier,VnfcDependencyModel> cache; + + DependencyManagerImpl(){ + cache = MetadataCacheFactory.getInstance().getMetadataCache(); + } + + public VnfcDependencyModel getVnfcDependencyModel(DependencyModelIdentifier modelIdentifier,DependencyTypes dependencyType) throws InvalidDependencyModel, DependencyModelNotFound { + if (logger.isTraceEnabled()) { + logger.trace("Entering to getVnfcDependencyModel with DependencyModelIdentifier = "+ modelIdentifier + + " , DependencyTypes = " + dependencyType); + } + VnfcDependencyModel dependencyModel = cache.getObject(modelIdentifier); + if(dependencyModel == null){ + logger.debug("Dependency model not found in cache, creating strategy for reading it"); + DependencyType strategy = getStrategy(dependencyType); + dependencyModel = strategy.getVnfcDependencyModel(modelIdentifier); + } + if (logger.isTraceEnabled()) { + logger.trace("Returning getVnfcDependencyModel with dependency model = "+ dependencyModel); + } + return dependencyModel; + } + + private DependencyType getStrategy(DependencyTypes dependencyType) { + switch (dependencyType){ + case RESOURCE: + return new ResourceDependency(); + } + return null; + } +} diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/impl/DependencyModelFactory.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/impl/DependencyModelFactory.java new file mode 100644 index 000000000..87bdd32fa --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/impl/DependencyModelFactory.java @@ -0,0 +1,37 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : 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.dg.dependencymanager.impl; + +import org.openecomp.appc.dg.dependencymanager.DependencyManager; + + +public class DependencyModelFactory { + + private static class ReferenceHolder{ + private static final DependencyManagerImpl INSTANCE = new DependencyManagerImpl(); + } + + public static DependencyManager createDependencyManager(){ + return ReferenceHolder.INSTANCE; + } + +} diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/impl/ResourceDependency.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/impl/ResourceDependency.java new file mode 100644 index 000000000..0cb9eebb4 --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/impl/ResourceDependency.java @@ -0,0 +1,83 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : 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.dg.dependencymanager.impl; + +import org.openecomp.appc.metadata.MetadataService; +import org.openecomp.appc.metadata.objects.DependencyModelIdentifier; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +import org.openecomp.appc.dg.dependencymanager.DependencyType; +import org.openecomp.appc.dg.dependencymanager.exception.DependencyModelNotFound; +import org.openecomp.appc.dg.dependencymanager.helper.DependencyModelParser; +import org.openecomp.appc.dg.flowbuilder.exception.InvalidDependencyModel; +import org.openecomp.appc.dg.objects.VnfcDependencyModel; +import org.osgi.framework.BundleContext; +import org.osgi.framework.FrameworkUtil; +import org.osgi.framework.ServiceReference; + + +public class ResourceDependency implements DependencyType{ + + private static final EELFLogger logger = EELFManager.getInstance().getLogger(ResourceDependency.class); + + + private MetadataService metadataService; + + public ResourceDependency(){ + getMetadataServiceRef(); + } + + private void getMetadataServiceRef() { + BundleContext bctx = FrameworkUtil.getBundle(MetadataService.class).getBundleContext(); + // Get MetadataService reference + ServiceReference sref = bctx.getServiceReference(MetadataService.class.getName()); + if (sref != null) { + logger.info("MetadataService from bundlecontext"); + metadataService = (MetadataService) bctx.getService(sref); + + } else { + logger.info("MetadataService error from bundlecontext"); + logger.warn("Cannot find service reference for org.openecomp.appc.metadata.MetadataService"); + } + } + + public void setMetadataService(MetadataService metadataService) { + this.metadataService = metadataService; + } + + public VnfcDependencyModel getVnfcDependencyModel(DependencyModelIdentifier modelIdentifier) throws InvalidDependencyModel, DependencyModelNotFound { + if (logger.isTraceEnabled()) { + logger.trace("Entering to getVnfcDependencyModel with DependencyModelIdentifier = "+ modelIdentifier); + } + String vnfModel = metadataService.getVnfModel(modelIdentifier); + if(vnfModel ==null){ + logger.debug("Vnf model not found from metadata service"); + throw new DependencyModelNotFound("Invalid or Empty VNF Model"); + } + if (logger.isTraceEnabled()) { + logger.trace("Building dependency model for Vnf Model : " + vnfModel); + } + DependencyModelParser modelParser = new DependencyModelParser(); + return modelParser.generateDependencyModel(vnfModel,modelIdentifier.getVnfType()); + } +} diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/FlowBuilder.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/FlowBuilder.java new file mode 100644 index 000000000..6b87e6621 --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/FlowBuilder.java @@ -0,0 +1,31 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : 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.dg.flowbuilder; + +import org.openecomp.appc.dg.objects.InventoryModel; +import org.openecomp.appc.dg.objects.VnfcDependencyModel; +import org.openecomp.appc.dg.objects.VnfcFlowModel; + + +public interface FlowBuilder { + VnfcFlowModel buildFlowModel(VnfcDependencyModel dependencyModel,InventoryModel inventoryModel); +} diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/FlowStrategy.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/FlowStrategy.java new file mode 100644 index 000000000..3c3488f70 --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/FlowStrategy.java @@ -0,0 +1,32 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : 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.dg.flowbuilder; + +import org.openecomp.appc.dg.objects.InventoryModel; +import org.openecomp.appc.dg.objects.VnfcDependencyModel; +import org.openecomp.appc.dg.objects.VnfcFlowModel; + + +public interface FlowStrategy { + + VnfcFlowModel buildFlowModel(VnfcDependencyModel dependencyModel, InventoryModel inventoryModel); +} diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/exception/InvalidDependencyModel.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/exception/InvalidDependencyModel.java new file mode 100644 index 000000000..8bec80a47 --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/exception/InvalidDependencyModel.java @@ -0,0 +1,29 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : 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.dg.flowbuilder.exception; + + +public class InvalidDependencyModel extends RuntimeException { + public InvalidDependencyModel(String message){ + super(message); + } +} diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/helper/Graph.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/helper/Graph.java new file mode 100644 index 000000000..b9115187c --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/helper/Graph.java @@ -0,0 +1,64 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : 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.dg.flowbuilder.helper; + +import java.util.*; + +import org.openecomp.appc.dg.flowbuilder.exception.InvalidDependencyModel; + + +public class Graph<T> { + private int size; + private List<T> vertexList; + + private int[][] dependencyMatrix; + + public Graph(int size){ + this.size =size; + vertexList = new ArrayList<>(); + dependencyMatrix = new int[size][size]; + } + + public void addVertex(T vertex){ + vertexList.add(vertex); + } + + public int getIndex(T vertex){ + return vertexList.indexOf(vertex); + } + + public void addEdge(T vertex1,T vertex2){ + dependencyMatrix[vertexList.indexOf(vertex1)][vertexList.indexOf(vertex2)] = 1; + } + + public int[][] getDependencyMatrix() { + return dependencyMatrix; + } + + public int getSize() { + return size; + } + + public List<T> getVertexList() { + return vertexList; + } +} diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/impl/AbstractFlowStrategy.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/impl/AbstractFlowStrategy.java new file mode 100644 index 000000000..15ff20083 --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/impl/AbstractFlowStrategy.java @@ -0,0 +1,133 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : 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.dg.flowbuilder.impl; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +import org.openecomp.appc.dg.flowbuilder.FlowStrategy; +import org.openecomp.appc.dg.flowbuilder.exception.InvalidDependencyModel; +import org.openecomp.appc.dg.flowbuilder.helper.Graph; +import org.openecomp.appc.dg.objects.*; +import org.openecomp.appc.domainmodel.Vnfc; + + +public abstract class AbstractFlowStrategy implements FlowStrategy { + + protected Graph<Vnfc> graph; + + private static final EELFLogger logger = EELFManager.getInstance().getLogger(AbstractFlowStrategy.class); + + public VnfcFlowModel buildFlowModel(VnfcDependencyModel dependencyModel, InventoryModel inventoryModel) { + if(logger.isTraceEnabled()){ + logger.trace("Entering into buildFlowModel with dependency model = " + dependencyModel + + "inventory model = " +inventoryModel); + } + + if(dependencyModel == null + || dependencyModel.getDependencies() ==null + || dependencyModel.getDependencies().size() ==0){ + logger.debug("Dependency model not available, building flow model with sequence"); + throw new InvalidDependencyModel("Dependency model either null or does not contain any dependency"); + } + + VnfcFlowModel flowModel = buildFlowModel(dependencyModel); + if(logger.isDebugEnabled()){ + logger.debug("Flow Model without instance data: \n" + flowModel); + } + + logger.info("Populating flow model with A&AI data"); + populateFlowModel(flowModel,inventoryModel); + if(logger.isDebugEnabled()){ + logger.debug("Flow Model with instance data: \n" + flowModel); + } + + return flowModel; + } + + private void populateFlowModel(VnfcFlowModel flowModel, InventoryModel inventoryModel) { + Iterator<List<Vnfc>> flowIterator = null; + + for(Vnfc vnfcFromInventory:inventoryModel.getVnf().getVnfcs()){ + flowIterator = flowModel.getModelIterator(); + String vnfcType = vnfcFromInventory.getVnfcType(); + while (flowIterator.hasNext()){ + for(Vnfc vnfcFromFlowModel:flowIterator.next() ){ + if(vnfcType.equalsIgnoreCase(vnfcFromFlowModel.getVnfcType())){ + vnfcFromFlowModel.setVnfcName(vnfcFromInventory.getVnfcName()); + vnfcFromFlowModel.addVms(vnfcFromInventory.getVserverList()); + } + } + } + + } + + } + + private VnfcFlowModel buildFlowModel(VnfcDependencyModel dependencyModel) throws InvalidDependencyModel { + Set<Node<Vnfc>> dependencies = dependencyModel.getDependencies(); + graph = new Graph(dependencies.size()); + + for(Node<Vnfc> node:dependencies){ + graph.addVertex(node.getChild()); + } + + for(Node node:dependencies){ + Vnfc child = (Vnfc)node.getChild(); + List<Vnfc> parents = node.getParents(); + for(Vnfc parent:parents){ + graph.addEdge(child,parent); + } + } + List<List<Vnfc>> dependencyList = orderDependencies(); + + VnfcFlowModel.VnfcFlowModelBuilder builder = new VnfcFlowModel.VnfcFlowModelBuilder(); + int count=0; + int flowModelSize = 0; + for(List<Vnfc> vnfcList:dependencyList){ + builder.addMetadata(count,vnfcList); + flowModelSize += vnfcList.size(); + count++; + } + if(flowModelSize != dependencies.size()){ + throw new InvalidDependencyModel("Cycle detected in the VNFC dependencies"); + } + + return builder.build(); + } + + protected abstract List<List<Vnfc>> orderDependencies(); + + /*private VnfcFlowModel buildFlowModelWithoutSequence(InventoryModel inventoryModel) { + VnfcFlowModel.VnfcFlowModelBuilder builder = new VnfcFlowModel.VnfcFlowModelBuilder(); + + for(Vnfc vnfc:inventoryModel.getVnf().getVnfcs()){ + builder = builder.addMetadata(0,vnfc); + } + + return builder.build(); + }*/ +} diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/impl/FlowBuilderFactory.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/impl/FlowBuilderFactory.java new file mode 100644 index 000000000..7b9759852 --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/impl/FlowBuilderFactory.java @@ -0,0 +1,48 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : 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.dg.flowbuilder.impl; + +import org.openecomp.appc.dg.flowbuilder.FlowBuilder; +import org.openecomp.appc.dg.objects.FlowStrategies; + + +public class FlowBuilderFactory { + private static class ReferenceHolder{ + private static final FlowBuilderFactory FACTORY = new FlowBuilderFactory(); + } + + public static FlowBuilderFactory getInstance(){ + return ReferenceHolder.FACTORY; + } + + public FlowBuilder getFlowBuilder(FlowStrategies flowStrategy){ + + switch (flowStrategy){ + case FORWARD: + return new FlowBuilderImpl(new ForwardFlowStrategy()); + case REVERSE: + return new FlowBuilderImpl(new ReverseFlowStrategy()); + } + return null; + + } +} diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/impl/FlowBuilderImpl.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/impl/FlowBuilderImpl.java new file mode 100644 index 000000000..80bd3eec2 --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/impl/FlowBuilderImpl.java @@ -0,0 +1,49 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : 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.dg.flowbuilder.impl; + +import org.openecomp.appc.dg.flowbuilder.FlowBuilder; +import org.openecomp.appc.dg.flowbuilder.FlowStrategy; +import org.openecomp.appc.dg.objects.InventoryModel; +import org.openecomp.appc.dg.objects.VnfcDependencyModel; +import org.openecomp.appc.dg.objects.VnfcFlowModel; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + + +public class FlowBuilderImpl implements FlowBuilder { + + + + private FlowStrategy strategy; + + FlowBuilderImpl(FlowStrategy strategy){ + this.strategy = strategy; + } + + public VnfcFlowModel buildFlowModel(VnfcDependencyModel dependencyModel, InventoryModel inventoryModel) { + return strategy.buildFlowModel(dependencyModel, inventoryModel); + } + + +} diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/impl/ForwardFlowStrategy.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/impl/ForwardFlowStrategy.java new file mode 100644 index 000000000..486e942a7 --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/impl/ForwardFlowStrategy.java @@ -0,0 +1,114 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : 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.dg.flowbuilder.impl; + +import java.util.*; + +import org.openecomp.appc.dg.flowbuilder.exception.InvalidDependencyModel; +import org.openecomp.appc.domainmodel.Vnfc; + + +public class ForwardFlowStrategy extends AbstractFlowStrategy { + @Override + protected List<List<Vnfc>> orderDependencies() { + ArrayList<List<Vnfc>> arrayList = new ArrayList<>(); + + Queue<Vnfc> queue1 = new LinkedList(); + Set<Vnfc> queue2 = new LinkedHashSet<>(); + + Set<Vnfc> uniqueElementSet = new HashSet<>(); + Set<Vnfc> duplicateElementSet = new HashSet<>(); + + // identifying independent nodes in queue1 + for(int rowIndex=0;rowIndex<graph.getSize();rowIndex++){ + Integer sum = 0; + for(int colIndex=0;colIndex<graph.getSize();colIndex++){ + sum+= graph.getDependencyMatrix()[rowIndex][colIndex]; + } + if(sum==0){ + Vnfc vnfc = graph.getVertexList().get(rowIndex); + queue1.add(vnfc); + } + } + if(queue1.isEmpty()){ + throw new InvalidDependencyModel("There seems to be no Root/Independent node for Vnfc dependencies"); + } + arrayList.add((List<Vnfc>)queue1); + queue1 = new LinkedList<>(queue1); + + boolean flag = true; + + while(flag){ + // iterating over queue1 and for each node in it finding all dependent nodes and putting them on queue2 + while(!queue1.isEmpty()){ + Vnfc listItem = queue1.remove(); + Integer colIndex = graph.getIndex(listItem); + for(Integer index =0;index<graph.getSize();index++){ + Integer value = graph.getDependencyMatrix()[index][colIndex]; + if(value ==1){ + Vnfc vnfc = graph.getVertexList().get(index); + queue2.add(vnfc); + } + } + } + for(Vnfc vnfc:queue2){ + if(!uniqueElementSet.add(vnfc)){ + duplicateElementSet.add(vnfc); + } + } + if(queue2.isEmpty()){ + flag= false; // empty queue2 indicates that all leaf nodes have been identified, i.e. stop the iteration + } + else{ + arrayList.add(new ArrayList<Vnfc>(queue2)); + if(arrayList.size()>graph.getSize()){ + // dependency list cannot be larger than total number of nodes + // if it happens indicates cycle in the dependency + throw new InvalidDependencyModel("Cycle detected in the VNFC dependencies"); + } + queue1.addAll(queue2); + queue2 = new LinkedHashSet<>(); + } + } + // If any node depends on multiple nodes present in different execution sequence, + // its execution should happen on the higher order, removing its presence on lower execution sequence + if(!duplicateElementSet.isEmpty()){ + for(Vnfc vnfc:duplicateElementSet){ + boolean firstOccurrence= true; + for(int i=arrayList.size()-1;i>=0;i--){ + List<Vnfc> list = arrayList.get(i); + if(list.contains(vnfc)){ + if(firstOccurrence){ + firstOccurrence =false; + continue; + } + else{ + list.remove(vnfc); + } + } + + } + } + } + return arrayList; + } +} diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/impl/ReverseFlowStrategy.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/impl/ReverseFlowStrategy.java new file mode 100644 index 000000000..2ef051da1 --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/impl/ReverseFlowStrategy.java @@ -0,0 +1,115 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : 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.dg.flowbuilder.impl; + +import java.util.*; + +import org.openecomp.appc.dg.flowbuilder.exception.InvalidDependencyModel; +import org.openecomp.appc.domainmodel.Vnfc; + + +public class ReverseFlowStrategy extends AbstractFlowStrategy { + + @Override + protected List<List<Vnfc>> orderDependencies() { + ArrayList<List<Vnfc>> arrayList = new ArrayList<>(); + + Queue<Vnfc> queue1 = new LinkedList(); + Set<Vnfc> queue2 = new LinkedHashSet<>(); + + Set<Vnfc> uniqueElementSet = new HashSet<>(); + Set<Vnfc> duplicateElementSet = new HashSet<>(); + + // identifying independent nodes in queue1 + for(int colIndex=0;colIndex<graph.getSize();colIndex++){ + Integer sum = 0; + for(int rowIndex=0;rowIndex<graph.getSize();rowIndex++){ + sum+= graph.getDependencyMatrix()[rowIndex][colIndex]; + } + if(sum==0){ + Vnfc vnfc = graph.getVertexList().get(colIndex); + queue1.add(vnfc); + } + } + if(queue1.isEmpty()){ + throw new InvalidDependencyModel("There seems to be no leaf node for Vnfc dependencies"); + } + arrayList.add((List<Vnfc>)queue1); + queue1 = new LinkedList<>(queue1); + + boolean flag = true; + + while(flag){ + // iterating over queue1 and for each node in it finding all dependent nodes and putting them on queue2 + while(!queue1.isEmpty()){ + Vnfc listItem = queue1.remove(); + Integer rowIndex = graph.getIndex(listItem); + for(Integer index =0;index<graph.getSize();index++){ + Integer value = graph.getDependencyMatrix()[rowIndex][index]; + if(value ==1){ + Vnfc vnfc = graph.getVertexList().get(index); + queue2.add(vnfc); + } + } + } + for(Vnfc vnfc:queue2){ + if(!uniqueElementSet.add(vnfc)){ + duplicateElementSet.add(vnfc); + } + } + if(queue2.isEmpty()){ + flag= false; // empty queue2 indicates that all leaf nodes have been identified, i.e. stop the iteration + } + else{ + arrayList.add(new ArrayList<Vnfc>(queue2)); + if(arrayList.size()>graph.getSize()){ + // dependency list cannot be larger than total number of nodes + // if it happens indicates cycle in the dependency + throw new InvalidDependencyModel("Cycle detected in the VNFC dependencies"); + } + queue1.addAll(queue2); + queue2 = new LinkedHashSet<>(); + } + } + // If any node depends on multiple nodes present in different execution sequence, + // its execution should happen on the higher order, removing its presence on lower execution sequence + if(!duplicateElementSet.isEmpty()){ + for(Vnfc vnfc:duplicateElementSet){ + boolean firstOccurrence= true; + for(int i=0;i<arrayList.size();i++){ + List<Vnfc> list = arrayList.get(i); + if(list.contains(vnfc)){ + if(firstOccurrence){ + firstOccurrence =false; + list.remove(vnfc); + } + else{ + continue; + } + } + + } + } + } + return arrayList; + } +} diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/DependencyTypes.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/DependencyTypes.java new file mode 100644 index 000000000..e8b8c2591 --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/DependencyTypes.java @@ -0,0 +1,36 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : 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.dg.objects; + + +public enum DependencyTypes { + RESOURCE; + + public static DependencyTypes findByString(String dependencyTypeStr){ + for(DependencyTypes dependencyType : DependencyTypes.values()){ + if(dependencyType.name().equalsIgnoreCase(dependencyTypeStr)){ + return dependencyType; + } + } + return null; + } +} diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/FlowStrategies.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/FlowStrategies.java new file mode 100644 index 000000000..8c3126bb5 --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/FlowStrategies.java @@ -0,0 +1,36 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : 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.dg.objects; + + +public enum FlowStrategies { + FORWARD,REVERSE; + + public static FlowStrategies findByString(String flowStrategyStr){ + for(FlowStrategies flowStrategy:FlowStrategies.values()){ + if(flowStrategy.name().equalsIgnoreCase(flowStrategyStr)){ + return flowStrategy; + } + } + return null; + } +} diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/InventoryModel.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/InventoryModel.java new file mode 100644 index 000000000..ffd3a35ba --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/InventoryModel.java @@ -0,0 +1,43 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : 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.dg.objects; + +import org.openecomp.appc.domainmodel.Vnf; + + +public class InventoryModel { + + private Vnf vnf; + + public InventoryModel(Vnf vnf){ + this.vnf= vnf; + } + + public Vnf getVnf() { + return vnf; + } + + @Override + public String toString() { + return "InventoryModel = " + vnf.toString(); + } +} diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/Node.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/Node.java new file mode 100644 index 000000000..a751504b8 --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/Node.java @@ -0,0 +1,74 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : 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.dg.objects; + +import java.util.LinkedList; +import java.util.List; + + +public class Node<T> { + T child; + List<T> parents; + + @Override + public int hashCode(){ + return child.hashCode(); + } + + @Override + public boolean equals(Object object){ + if(object == null){ + return false; + } + if(!(object instanceof Node)){ + return false; + } + Node node = (Node)object; + return this.child.equals(node.getChild()); + } + + public Node(T child){ + this.child = child; + this.parents = new LinkedList<>(); + } + + public T getChild() { + return child; + } + + public List<T> getParents() { + return parents; + } + + public void addParent(T parent){ + this.parents.add(parent); + } + + @Override + public String toString() { + StringBuilder stringBuilder = new StringBuilder("Node : child = " + child + " , parents = "); + for(T parent:parents){ + stringBuilder.append(parent).append(","); + } + return stringBuilder.toString(); + } +} diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/VnfcDependencyModel.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/VnfcDependencyModel.java new file mode 100644 index 000000000..12b5c15a5 --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/VnfcDependencyModel.java @@ -0,0 +1,48 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : 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.dg.objects; + +import java.util.Set; + +import org.openecomp.appc.domainmodel.Vnfc; + + +public class VnfcDependencyModel { + private Set<Node<Vnfc>> dependencies; + + public VnfcDependencyModel(Set<Node<Vnfc>> dependencies){ + this.dependencies = dependencies; + } + + public Set<Node<Vnfc>> getDependencies() { + return dependencies; + } + + @Override + public String toString() { + StringBuilder stringBuilder = new StringBuilder("dependencies = "); + for(Node node:dependencies){ + stringBuilder.append(node.toString()).append(", "); + } + return super.toString(); + } +} diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/VnfcFlowModel.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/VnfcFlowModel.java new file mode 100644 index 000000000..ef3934162 --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/VnfcFlowModel.java @@ -0,0 +1,89 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : 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.dg.objects; + +import java.util.*; + +import org.openecomp.appc.domainmodel.Vnfc; + + +public class VnfcFlowModel { + private Map<Integer,List<Vnfc>> flowModelMap; + + private VnfcFlowModel(VnfcFlowModelBuilder builder){ + this.flowModelMap = builder.map; + + } + + @Override + public String toString() { + StringBuilder stringBuilder = new StringBuilder("Flow Model : "); + Iterator<List<Vnfc>> iterator = getModelIterator(); + while(iterator.hasNext()){ + for(Vnfc vnfc:iterator.next()){ + stringBuilder.append(vnfc.toString()).append(", \n"); + } + } + + return stringBuilder.toString(); + } + + public Iterator<List<Vnfc>> getModelIterator(){ + return flowModelMap.values().iterator(); + } + + public static class VnfcFlowModelBuilder{ + + Map<Integer,List<Vnfc>> map; + + public VnfcFlowModelBuilder(){ + map = new HashMap<>(); + } + + public VnfcFlowModelBuilder addMetadata(Integer index,Vnfc vnfc){ + List<Vnfc> vnfcList = this.map.get(index); + if(vnfcList == null){ + vnfcList = new LinkedList<>(); + map.put(index,vnfcList); + } + vnfcList.add(vnfc); + return this; + } + + public VnfcFlowModelBuilder addMetadata(Integer index,List<Vnfc> vnfcs){ + List<Vnfc> vnfcList = this.map.get(index); + if(vnfcList == null){ + vnfcList = new LinkedList<>(); + map.put(index,vnfcList); + } + vnfcList.addAll(vnfcs); + return this; + } + + public VnfcFlowModel build(){ + return new VnfcFlowModel(this); + } + + } + + +} |