From b8e2faf476202b6ffe61bc3a9a37df1304881d40 Mon Sep 17 00:00:00 2001 From: Avi Ziv Date: Tue, 18 Jul 2017 19:45:38 +0300 Subject: [SDC] Onboarding 1710 rebase. Change-Id: If3b6b81d221fde13908f1e8160db6f7d9433c535 Signed-off-by: Avi Ziv --- .../sdc/tosca/datatypes/ToscaNodeType.java | 9 +- .../sdc/tosca/datatypes/ToscaServiceModel.java | 17 ++ .../sdc/tosca/services/ConfigConstants.java | 29 ++- .../sdc/tosca/services/DataModelUtil.java | 199 ++++++++++++++++++++- .../sdc/tosca/services/ToscaAnalyzerService.java | 10 ++ .../services/impl/ToscaAnalyzerServiceImpl.java | 133 +++++++++++++- .../services/yamlutil/ToscaExtensionYamlUtil.java | 92 ---------- 7 files changed, 374 insertions(+), 115 deletions(-) delete mode 100644 openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/yamlutil/ToscaExtensionYamlUtil.java (limited to 'openecomp-be/lib/openecomp-tosca-lib/src/main/java') diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaNodeType.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaNodeType.java index 22658c8b1c..b5b3e172fe 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaNodeType.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaNodeType.java @@ -39,6 +39,8 @@ public class ToscaNodeType { config.getAsString(ConfigConstants.NAMESPACE, ConfigConstants.PREFIX_NODE_TYPE_ABSTARCT); public static String RULE_NODE_TYPE_PREFIX = config.getAsString(ConfigConstants.NAMESPACE, ConfigConstants.PREFIX_NODE_TYPE_RULE); + public static String NODE_TYPE_PREFIX = + config.getAsString(ConfigConstants.NAMESPACE, ConfigConstants.PREFIX); //TOSCA native types public static String NATIVE_COMPUTE = "tosca.nodes.Compute"; @@ -80,6 +82,11 @@ public class ToscaNodeType { public static String VFC_ABSTRACT_SUBSTITUTE = ABSTRACT_NODE_TYPE_PREFIX + "VFC"; public static String CONTRAIL_ABSTRACT_SUBSTITUTE = ABSTRACT_NODE_TYPE_PREFIX + "contrail.AbstractSubstitute"; - + public static String COMPLEX_VFC_NODE_TYPE = ABSTRACT_NODE_TYPE_PREFIX + "ComplexVFC"; + //Questionnaire to Tosca Types + public static String VNF_CONFIG_NODE_TYPE = ABSTRACT_NODE_TYPE_PREFIX + "VnfConfiguration"; + public static String MULTIFLAVOR_VFC_NODE_TYPE = ABSTRACT_NODE_TYPE_PREFIX + "MultiFlavorVFC"; + public static String MULTIDEPLOYMENTFLAVOR_NODE_TYPE = ABSTRACT_NODE_TYPE_PREFIX + + "MultiDeploymentFlavor"; } diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaServiceModel.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaServiceModel.java index 573ce395d5..0fcaafa1c2 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaServiceModel.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaServiceModel.java @@ -23,6 +23,7 @@ package org.openecomp.sdc.tosca.datatypes; import org.openecomp.core.utilities.file.FileContentHandler; import org.openecomp.sdc.datatypes.model.AsdcModel; import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate; +import org.openecomp.sdc.tosca.services.DataModelUtil; import java.util.Collections; import java.util.Map; @@ -35,6 +36,9 @@ public class ToscaServiceModel implements AsdcModel { private Map serviceTemplates; private String entryDefinitionServiceTemplate; + public ToscaServiceModel() { + } + /** * Instantiates a new Tosca service model. * @@ -60,6 +64,9 @@ public class ToscaServiceModel implements AsdcModel { return artifactFiles; } + public void setArtifactFiles(FileContentHandler artifactFiles) { + this.artifactFiles = artifactFiles; + } /** * Gets service templates. @@ -96,4 +103,14 @@ public class ToscaServiceModel implements AsdcModel { public void setEntryDefinitionServiceTemplate(String entryDefinitionServiceTemplate) { this.entryDefinitionServiceTemplate = entryDefinitionServiceTemplate; } + + /** + * Gets cloned service model. + * + * @param toscaServiceModel the tosca service model + * @return the cloned service model + */ + public static ToscaServiceModel getClonedServiceModel(ToscaServiceModel toscaServiceModel) { + return ToscaServiceModel.class.cast(DataModelUtil.getClonedObject(toscaServiceModel)); + } } diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ConfigConstants.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ConfigConstants.java index df6eb195d8..0e4bc22c37 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ConfigConstants.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ConfigConstants.java @@ -25,24 +25,19 @@ public class ConfigConstants { public static final String NAMESPACE = "ToscaModel"; //keys - public static final String PREFIX_CAPABILITY_TYPE = - "tosca.entity.namespace.prefix.capabilityType"; - public static final String PREFIX_DATA_TYPE = "tosca.entity.namespace.prefix.dataType"; - public static final String PREFIX_GROUP_TYPE = "tosca.entity.namespace.prefix.groupType"; - public static final String PREFIX_POLICY_TYPE = "tosca.entity.namespace.prefix.policyType"; - public static final String PREFIX_ARTIFACT_TYPE = "tosca.entity.namespace.prefix.artifactType"; - public static final String PREFIX_RELATIONSHIP_TYPE = - "tosca.entity.namespace.prefix.relationshipType"; - - public static final String PREFIX_NODE_TYPE_VFC = "tosca.entity.namespace.prefix.nodeType.vfc"; - public static final String PREFIX_NODE_TYPE_NETWORK = - "tosca.entity.namespace.prefix.nodeType.network"; - public static final String PREFIX_NODE_TYPE_CP = - "tosca.entity.namespace.prefix.nodeType.connectionPoint"; - public static final String PREFIX_NODE_TYPE_ABSTARCT = - "tosca.entity.namespace.prefix.nodeType.abstract"; - public static final String PREFIX_NODE_TYPE_RULE = "tosca.entity.namespace.prefix.nodeType.rule"; + public static final String PREFIX = "tosca.entity.namespace.prefix"; + public static final String PREFIX_CAPABILITY_TYPE = PREFIX + ".capabilityType"; + public static final String PREFIX_DATA_TYPE = PREFIX + ".dataType"; + public static final String PREFIX_GROUP_TYPE = PREFIX + ".groupType"; + public static final String PREFIX_POLICY_TYPE = PREFIX + ".policyType"; + public static final String PREFIX_ARTIFACT_TYPE = PREFIX + ".artifactType"; + public static final String PREFIX_RELATIONSHIP_TYPE = PREFIX + ".relationshipType"; + public static final String PREFIX_NODE_TYPE_VFC = PREFIX + ".nodeType.vfc"; + public static final String PREFIX_NODE_TYPE_NETWORK = PREFIX + ".nodeType.network"; + public static final String PREFIX_NODE_TYPE_CP = PREFIX + ".nodeType.connectionPoint"; + public static final String PREFIX_NODE_TYPE_ABSTARCT = PREFIX + ".nodeType.abstract"; + public static final String PREFIX_NODE_TYPE_RULE = PREFIX + ".nodeType.rule"; private ConfigConstants() { } diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/DataModelUtil.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/DataModelUtil.java index 49ea45e8c8..d908b2cf74 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/DataModelUtil.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/DataModelUtil.java @@ -23,7 +23,6 @@ package org.openecomp.sdc.tosca.services; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; import org.openecomp.core.utilities.CommonMethods; -import org.openecomp.core.utilities.yaml.YamlUtil; import org.openecomp.sdc.common.errors.CoreException; import org.openecomp.sdc.datatypes.error.ErrorLevel; import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage; @@ -32,7 +31,9 @@ import org.openecomp.sdc.logging.types.LoggerConstants; import org.openecomp.sdc.logging.types.LoggerErrorCode; import org.openecomp.sdc.logging.types.LoggerErrorDescription; import org.openecomp.sdc.logging.types.LoggerTragetServiceName; +import org.openecomp.sdc.tosca.datatypes.ToscaCapabilityType; import org.openecomp.sdc.tosca.datatypes.ToscaFunctions; +import org.openecomp.sdc.tosca.datatypes.ToscaRelationshipType; import org.openecomp.sdc.tosca.datatypes.model.AttributeDefinition; import org.openecomp.sdc.tosca.datatypes.model.CapabilityDefinition; import org.openecomp.sdc.tosca.datatypes.model.CapabilityType; @@ -56,8 +57,13 @@ import org.openecomp.sdc.tosca.datatypes.model.heatextend.ParameterDefinitionExt import org.openecomp.sdc.tosca.errors.InvalidAddActionNullEntityErrorBuilder; import org.openecomp.sdc.tosca.errors.InvalidRequirementAssignmentErrorBuilder; import org.openecomp.sdc.tosca.services.impl.ToscaAnalyzerServiceImpl; -import org.openecomp.sdc.tosca.services.yamlutil.ToscaExtensionYamlUtil; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.NotSerializableException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -1364,6 +1370,26 @@ public class DataModelUtil { .getProperties(); } + /** + * Gets substitution mappings in a service template. + * + * @param serviceTemplate the service template + * @return the substitution mappings + */ + public static SubstitutionMapping getSubstitutionMappings(ServiceTemplate serviceTemplate) { + mdcDataDebugMessage.debugEntryMessage(null, null); + + if (serviceTemplate == null + || serviceTemplate.getTopology_template() == null + || serviceTemplate.getTopology_template().getSubstitution_mappings() == null) { + return null; + } + + mdcDataDebugMessage.debugExitMessage(null, null); + return serviceTemplate.getTopology_template().getSubstitution_mappings(); + } + + /** * Compare two requirement assignment objects for equality. * @@ -1380,4 +1406,173 @@ public class DataModelUtil { } return false; } + + /** + * Gets a deep copy clone of the input object. + * + * @param the type parameter + * @param objectValue the object value + * @param clazz the clazz + * @return the cloned object + */ + public static Object getClonedObject(Object objectValue, Class clazz) { + YamlUtil yamlUtil = new ToscaExtensionYamlUtil(); + Object clonedObjectValue; + String objectToYaml = yamlUtil.objectToYaml(objectValue); + clonedObjectValue = yamlUtil.yamlToObject(objectToYaml, clazz); + return clonedObjectValue; + } + + /** + * Gets a deep copy clone of the input object. + * + * @param obj the object to be cloned + * @return the cloned object + */ + public static Object getClonedObject(Object obj) { + Object clonedObjectValue; + try { + //Serialize object + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream); + objectOutputStream.writeObject(obj); + //Deserialize object + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream + .toByteArray()); + ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream); + clonedObjectValue = objectInputStream.readObject(); + } catch (NotSerializableException ex) { + return getClonedObject(obj, obj.getClass()); + } catch (IOException | ClassNotFoundException ex) { + return null; + } + return clonedObjectValue; + } + + /** + * Add substitution filtering property. + * + * @param templateName the substitution service template name + * @param nodeTemplate the node template + * @param count the count + */ + public static void addSubstitutionFilteringProperty(String templateName, + NodeTemplate nodeTemplate, int count) { + Map serviceTemplateFilterPropertyValue = new HashMap<>(); + Map properties = nodeTemplate.getProperties(); + serviceTemplateFilterPropertyValue.put(ToscaConstants + .SUBSTITUTE_SERVICE_TEMPLATE_PROPERTY_NAME, templateName); + serviceTemplateFilterPropertyValue.put(ToscaConstants.COUNT_PROPERTY_NAME, count); + properties.put(ToscaConstants.SERVICE_TEMPLATE_FILTER_PROPERTY_NAME, + serviceTemplateFilterPropertyValue); + nodeTemplate.setProperties(properties); + } + + /** + * Adding binding requirement from port node template to compute node template. + * + * @param computeNodeTemplateId compute node template id + * @param portNodeTemplate port node template + */ + public static void addBindingReqFromPortToCompute(String computeNodeTemplateId, + NodeTemplate portNodeTemplate) { + + + mdcDataDebugMessage.debugEntryMessage(null, null); + RequirementAssignment requirementAssignment = new RequirementAssignment(); + requirementAssignment.setCapability(ToscaCapabilityType.NATIVE_NETWORK_BINDABLE); + requirementAssignment.setRelationship(ToscaRelationshipType.NATIVE_NETWORK_BINDS_TO); + requirementAssignment.setNode(computeNodeTemplateId); + addRequirementAssignment(portNodeTemplate, ToscaConstants.BINDING_REQUIREMENT_ID, + requirementAssignment); + mdcDataDebugMessage.debugExitMessage(null, null); + } + + public static SubstitutionMapping createSubstitutionTemplateSubMapping( + String nodeTypeKey, + NodeType substitutionNodeType, + Map>> mapping) { + mdcDataDebugMessage.debugEntryMessage(null, null); + SubstitutionMapping substitutionMapping = new SubstitutionMapping(); + substitutionMapping.setNode_type(nodeTypeKey); + substitutionMapping.setCapabilities( + manageCapabilityMapping(substitutionNodeType.getCapabilities(), mapping.get("capability"))); + substitutionMapping.setRequirements( + manageRequirementMapping(substitutionNodeType.getRequirements(), + mapping.get("requirement"))); + + mdcDataDebugMessage.debugExitMessage(null, null); + return substitutionMapping; + } + + private static Map> manageRequirementMapping( + List> requirementList, + Map> requirementSubstitutionMapping) { + mdcDataDebugMessage.debugEntryMessage(null, null); + + if (requirementList == null) { + return null; + } + Map> requirementMapping = new HashMap<>(); + String requirementKey; + List requirementMap; + for (Map requirementDefMap : requirementList) { + for (Map.Entry entry : requirementDefMap.entrySet()) { + requirementKey = entry.getKey(); + requirementMap = requirementSubstitutionMapping.get(requirementKey); + requirementMapping.put(requirementKey, requirementMap); + } + } + + mdcDataDebugMessage.debugExitMessage(null, null); + return requirementMapping; + } + + private static Map> manageCapabilityMapping( + Map capabilities, + Map> capabilitySubstitutionMapping) { + mdcDataDebugMessage.debugEntryMessage(null, null); + + if (capabilities == null) { + mdcDataDebugMessage.debugExitMessage(null, null); + return null; + } + + Map> capabilityMapping = new HashMap<>(); + String capabilityKey; + List capabilityMap; + for (Map.Entry entry : capabilities.entrySet()) { + capabilityKey = entry.getKey(); + capabilityMap = capabilitySubstitutionMapping.get(capabilityKey); + capabilityMapping.put(capabilityKey, capabilityMap); + } + + mdcDataDebugMessage.debugExitMessage(null, null); + return capabilityMapping; + } + + public static void addSubstitutionNodeTypeRequirements(NodeType substitutionNodeType, + List> + requirementsList, + String templateName) { + mdcDataDebugMessage.debugEntryMessage(null, null); + + if (requirementsList == null || requirementsList.size() == 0) { + return; + } + + if (substitutionNodeType.getRequirements() == null) { + substitutionNodeType.setRequirements(new ArrayList<>()); + } + + for (Map requirementDef : requirementsList) { + for (Map.Entry entry : requirementDef.entrySet()) { + Map requirementMap = new HashMap<>(); + requirementMap.put(entry.getKey() + "_" + templateName, entry.getValue().clone()); + substitutionNodeType.getRequirements().add(requirementMap); + } + } + + mdcDataDebugMessage.debugExitMessage(null, null); + } } diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaAnalyzerService.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaAnalyzerService.java index ac7cab6c51..c4c154efb4 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaAnalyzerService.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaAnalyzerService.java @@ -22,10 +22,12 @@ package org.openecomp.sdc.tosca.services; import org.openecomp.sdc.tosca.datatypes.ToscaElementTypes; import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; +import org.openecomp.sdc.tosca.datatypes.model.CapabilityDefinition; import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate; import org.openecomp.sdc.tosca.datatypes.model.NodeType; import org.openecomp.sdc.tosca.datatypes.model.PropertyDefinition; import org.openecomp.sdc.tosca.datatypes.model.RequirementAssignment; +import org.openecomp.sdc.tosca.datatypes.model.RequirementDefinition; import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate; import java.util.Collection; @@ -80,4 +82,12 @@ public interface ToscaAnalyzerService { public Map manageSubstitutionNodeTypeProperties( ServiceTemplate substitutionServiceTemplate); + + public Map calculateExposedCapabilities( + Map nodeTypeCapabilitiesDefinition, + Map> fullFilledRequirementsDefinitionMap); + + public List> calculateExposedRequirements( + List> nodeTypeRequirementsDefinitionList, + Map nodeTemplateRequirementsAssignment); } diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImpl.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImpl.java index eaf3fb492f..dc2ed6c76b 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImpl.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImpl.java @@ -25,6 +25,7 @@ import org.apache.commons.collections4.MapUtils; import org.openecomp.core.utilities.CommonMethods; import org.openecomp.sdc.common.errors.CoreException; import org.openecomp.sdc.datatypes.error.ErrorLevel; +import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage; import org.openecomp.sdc.logging.context.impl.MdcDataErrorMessage; import org.openecomp.sdc.logging.types.LoggerConstants; import org.openecomp.sdc.logging.types.LoggerErrorCode; @@ -34,6 +35,7 @@ import org.openecomp.sdc.tosca.datatypes.ToscaElementTypes; import org.openecomp.sdc.tosca.datatypes.ToscaNodeType; import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; import org.openecomp.sdc.tosca.datatypes.model.AttributeDefinition; +import org.openecomp.sdc.tosca.datatypes.model.CapabilityDefinition; import org.openecomp.sdc.tosca.datatypes.model.CapabilityType; import org.openecomp.sdc.tosca.datatypes.model.Import; import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate; @@ -42,6 +44,7 @@ import org.openecomp.sdc.tosca.datatypes.model.ParameterDefinition; import org.openecomp.sdc.tosca.datatypes.model.PropertyDefinition; import org.openecomp.sdc.tosca.datatypes.model.PropertyType; import org.openecomp.sdc.tosca.datatypes.model.RequirementAssignment; +import org.openecomp.sdc.tosca.datatypes.model.RequirementDefinition; import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate; import org.openecomp.sdc.tosca.errors.ToscaInvalidEntryNotFoundErrorBuilder; import org.openecomp.sdc.tosca.errors.ToscaInvalidSubstituteNodeTemplatePropertiesErrorBuilder; @@ -51,7 +54,7 @@ import org.openecomp.sdc.tosca.services.DataModelUtil; import org.openecomp.sdc.tosca.services.ToscaAnalyzerService; import org.openecomp.sdc.tosca.services.ToscaConstants; import org.openecomp.sdc.tosca.services.ToscaUtil; -import org.openecomp.sdc.tosca.services.yamlutil.ToscaExtensionYamlUtil; +import org.openecomp.sdc.tosca.services.ToscaExtensionYamlUtil; import java.util.ArrayList; import java.util.Collection; @@ -64,9 +67,133 @@ import java.util.Optional; import java.util.Set; public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService { + + protected static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage(); + + public List> calculateExposedRequirements( + List> nodeTypeRequirementsDefinitionList, + Map nodeTemplateRequirementsAssignment) { + mdcDataDebugMessage.debugEntryMessage(null, null); + + if (nodeTypeRequirementsDefinitionList == null) { + return null; + } + for (Map.Entry entry : nodeTemplateRequirementsAssignment + .entrySet()) { + if (entry.getValue().getNode() != null) { + Optional requirementDefinition = + DataModelUtil.getRequirementDefinition(nodeTypeRequirementsDefinitionList, entry + .getKey()); + RequirementDefinition cloneRequirementDefinition; + if (requirementDefinition.isPresent()) { + cloneRequirementDefinition = requirementDefinition.get().clone(); + if (!evaluateRequirementFulfillment(cloneRequirementDefinition)) { + CommonMethods.mergeEntryInList(entry.getKey(), cloneRequirementDefinition, + nodeTypeRequirementsDefinitionList); + } else { + DataModelUtil.removeRequirementsDefinition(nodeTypeRequirementsDefinitionList, entry + .getKey()); + } + } + } else { + for (Map nodeTypeRequirementsMap : + nodeTypeRequirementsDefinitionList) { + Object max = nodeTypeRequirementsMap.get(entry.getKey()).getOccurrences() != null + && nodeTypeRequirementsMap.get(entry.getKey()).getOccurrences().length > 0 + ? nodeTypeRequirementsMap.get(entry.getKey()).getOccurrences()[1] : 1; + Object min = nodeTypeRequirementsMap.get(entry.getKey()).getOccurrences() != null + && nodeTypeRequirementsMap.get(entry.getKey()).getOccurrences().length > 0 + ? nodeTypeRequirementsMap.get(entry.getKey()).getOccurrences()[0] : 1; + nodeTypeRequirementsMap.get(entry.getKey()).setOccurrences(new Object[]{min, max}); + } + } + } + + mdcDataDebugMessage.debugExitMessage(null, null); + return nodeTypeRequirementsDefinitionList; + } + + private static boolean evaluateRequirementFulfillment(RequirementDefinition + requirementDefinition) { + Object[] occurrences = requirementDefinition.getOccurrences(); + if (occurrences == null) { + requirementDefinition.setOccurrences(new Object[]{1, 1}); + return false; + } + if (occurrences[1].equals(ToscaConstants.UNBOUNDED)) { + return false; + } + + if (occurrences[1].equals(1)) { + return true; + } + occurrences[1] = (Integer) occurrences[1] - 1; + return false; + } + + public Map calculateExposedCapabilities( + Map nodeTypeCapabilitiesDefinition, + Map> fullFilledRequirementsDefinitionMap) { + + + mdcDataDebugMessage.debugEntryMessage(null, null); + + String capabilityKey; + String capability; + String node; + for (Map.Entry> entry : + fullFilledRequirementsDefinitionMap.entrySet()) { + for (Map.Entry fullFilledEntry : entry.getValue().entrySet()) { + + capability = fullFilledEntry.getValue().getCapability(); + fullFilledEntry.getValue().getOccurrences(); + node = fullFilledEntry.getValue().getNode(); + capabilityKey = capability + "_" + node; + CapabilityDefinition capabilityDefinition = nodeTypeCapabilitiesDefinition.get( + capabilityKey); + if (capabilityDefinition != null) { + CapabilityDefinition clonedCapabilityDefinition = capabilityDefinition.clone(); + nodeTypeCapabilitiesDefinition.put(capabilityKey, capabilityDefinition.clone()); + if (evaluateCapabilityFulfillment(clonedCapabilityDefinition)) { + nodeTypeCapabilitiesDefinition.remove(capabilityKey); + } else { + nodeTypeCapabilitiesDefinition.put(capabilityKey, clonedCapabilityDefinition); + } + } + } + } + + Map exposedCapabilitiesDefinition = new HashMap<>(); + for (Map.Entry entry : nodeTypeCapabilitiesDefinition + .entrySet()) { + exposedCapabilitiesDefinition.put(entry.getKey(), entry.getValue()); + } + + mdcDataDebugMessage.debugExitMessage(null, null); + return exposedCapabilitiesDefinition; + } + + private static boolean evaluateCapabilityFulfillment(CapabilityDefinition capabilityDefinition) { + + Object[] occurrences = capabilityDefinition.getOccurrences(); + if (occurrences == null) { + capabilityDefinition.setOccurrences(new Object[]{1, ToscaConstants.UNBOUNDED}); + return false; + } + if (occurrences[1].equals(ToscaConstants.UNBOUNDED)) { + return false; + } + + if (occurrences[1].equals(1)) { + return true; + } + occurrences[1] = (Integer) occurrences[1] - 1; + return false; + } + /* - node template with type equal to node type or derived from node type - */ + node template with type equal to node type or derived from node type + */ @Override public Map getNodeTemplatesByType(ServiceTemplate serviceTemplate, String nodeType, diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/yamlutil/ToscaExtensionYamlUtil.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/yamlutil/ToscaExtensionYamlUtil.java deleted file mode 100644 index 2b806fbea0..0000000000 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/yamlutil/ToscaExtensionYamlUtil.java +++ /dev/null @@ -1,92 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * 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.sdc.tosca.services.yamlutil; - -import org.openecomp.core.utilities.yaml.YamlUtil; -import org.yaml.snakeyaml.constructor.Constructor; -import org.yaml.snakeyaml.introspector.Property; -import org.yaml.snakeyaml.introspector.PropertyUtils; -import org.yaml.snakeyaml.nodes.MappingNode; -import org.yaml.snakeyaml.nodes.NodeId; - -import java.beans.IntrospectionException; - -public class ToscaExtensionYamlUtil extends YamlUtil { - - @Override - public Constructor getConstructor(Class typClass) { - return new ToscaWithHeatExtensionConstructor(typClass); - } - - @Override - protected PropertyUtils getPropertyUtils() { - return new ToscaPropertyUtilsWithHeatExtension(); - } - - public class ToscaPropertyUtilsWithHeatExtension extends MyPropertyUtils { - @Override - public Property getProperty(Class type, String name) - throws IntrospectionException { - try { - if (type - .equals(Class.forName("org.openecomp.sdc.tosca.datatypes.model.ParameterDefinition"))) { - type = Class - .forName("org.openecomp.sdc.tosca.datatypes.model.heatextend.ParameterDefinitionExt"); - } - } catch (ClassNotFoundException ex) { - throw new RuntimeException(ex); - } - return super.getProperty(type, name); - } - } - - protected class ToscaWithHeatExtensionConstructor extends StrictMapAppenderConstructor { - public ToscaWithHeatExtensionConstructor(Class theRoot) { - super(theRoot); - yamlClassConstructors.put(NodeId.mapping, new MyPersistentObjectConstruct()); - } - - class MyPersistentObjectConstruct extends ConstructMapping { - @Override - protected Object constructJavaBean2ndStep(MappingNode node, Object object) { - Class type = node.getType(); - try { - if (type.equals( - Class.forName("org.openecomp.sdc.tosca.datatypes.model.ParameterDefinition"))) { - Class extendHeatClass = Class.forName( - "org.openecomp.sdc.tosca.datatypes.model.heatextend.ParameterDefinitionExt"); - Object extendHeatObject = extendHeatClass.newInstance(); - // create JavaBean - return super.constructJavaBean2ndStep(node, extendHeatObject); - } else { - // create JavaBean - return super.constructJavaBean2ndStep(node, object); - } - } catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) { - throw new RuntimeException(ex); - } - } - } - } -} - - - -- cgit 1.2.3-korg