aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org
diff options
context:
space:
mode:
authorAvi Ziv <avi.ziv@amdocs.com>2017-07-18 19:45:38 +0300
committerAvi Ziv <avi.ziv@amdocs.com>2017-07-18 19:45:38 +0300
commitb8e2faf476202b6ffe61bc3a9a37df1304881d40 (patch)
treef78b8c0517d8e16c5ae610bf8b49f68ea8a312a1 /openecomp-be/lib/openecomp-tosca-lib/src/main/java/org
parent75aacbbe1acf78fa53378f07f0a8c7769449a17e (diff)
[SDC] Onboarding 1710 rebase.
Change-Id: If3b6b81d221fde13908f1e8160db6f7d9433c535 Signed-off-by: Avi Ziv <avi.ziv@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-tosca-lib/src/main/java/org')
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaNodeType.java9
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaServiceModel.java17
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ConfigConstants.java29
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/DataModelUtil.java199
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaAnalyzerService.java10
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImpl.java133
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/yamlutil/ToscaExtensionYamlUtil.java92
7 files changed, 374 insertions, 115 deletions
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<String, ServiceTemplate> 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;
@@ -1365,6 +1371,26 @@ public class DataModelUtil {
}
/**
+ * 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.
*
* @param first the first requirement assignement object
@@ -1380,4 +1406,173 @@ public class DataModelUtil {
}
return false;
}
+
+ /**
+ * Gets a deep copy clone of the input object.
+ *
+ * @param <T> the type parameter
+ * @param objectValue the object value
+ * @param clazz the clazz
+ * @return the cloned object
+ */
+ public static <T> Object getClonedObject(Object objectValue, Class<T> 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<String, Object> serviceTemplateFilterPropertyValue = new HashMap<>();
+ Map<String, Object> 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<String, Map<String, List<String>>> 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<String, List<String>> manageRequirementMapping(
+ List<Map<String, RequirementDefinition>> requirementList,
+ Map<String, List<String>> requirementSubstitutionMapping) {
+ mdcDataDebugMessage.debugEntryMessage(null, null);
+
+ if (requirementList == null) {
+ return null;
+ }
+ Map<String, List<String>> requirementMapping = new HashMap<>();
+ String requirementKey;
+ List<String> requirementMap;
+ for (Map<String, RequirementDefinition> requirementDefMap : requirementList) {
+ for (Map.Entry<String, RequirementDefinition> entry : requirementDefMap.entrySet()) {
+ requirementKey = entry.getKey();
+ requirementMap = requirementSubstitutionMapping.get(requirementKey);
+ requirementMapping.put(requirementKey, requirementMap);
+ }
+ }
+
+ mdcDataDebugMessage.debugExitMessage(null, null);
+ return requirementMapping;
+ }
+
+ private static Map<String, List<String>> manageCapabilityMapping(
+ Map<String, CapabilityDefinition> capabilities,
+ Map<String, List<String>> capabilitySubstitutionMapping) {
+ mdcDataDebugMessage.debugEntryMessage(null, null);
+
+ if (capabilities == null) {
+ mdcDataDebugMessage.debugExitMessage(null, null);
+ return null;
+ }
+
+ Map<String, List<String>> capabilityMapping = new HashMap<>();
+ String capabilityKey;
+ List<String> capabilityMap;
+ for (Map.Entry<String, CapabilityDefinition> 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<Map<String, RequirementDefinition>>
+ requirementsList,
+ String templateName) {
+ mdcDataDebugMessage.debugEntryMessage(null, null);
+
+ if (requirementsList == null || requirementsList.size() == 0) {
+ return;
+ }
+
+ if (substitutionNodeType.getRequirements() == null) {
+ substitutionNodeType.setRequirements(new ArrayList<>());
+ }
+
+ for (Map<String, RequirementDefinition> requirementDef : requirementsList) {
+ for (Map.Entry<String, RequirementDefinition> entry : requirementDef.entrySet()) {
+ Map<String, RequirementDefinition> 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<String, PropertyDefinition> manageSubstitutionNodeTypeProperties(
ServiceTemplate substitutionServiceTemplate);
+
+ public Map<String, CapabilityDefinition> calculateExposedCapabilities(
+ Map<String, CapabilityDefinition> nodeTypeCapabilitiesDefinition,
+ Map<String, Map<String, RequirementAssignment>> fullFilledRequirementsDefinitionMap);
+
+ public List<Map<String, RequirementDefinition>> calculateExposedRequirements(
+ List<Map<String, RequirementDefinition>> nodeTypeRequirementsDefinitionList,
+ Map<String, RequirementAssignment> 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<Map<String, RequirementDefinition>> calculateExposedRequirements(
+ List<Map<String, RequirementDefinition>> nodeTypeRequirementsDefinitionList,
+ Map<String, RequirementAssignment> nodeTemplateRequirementsAssignment) {
+ mdcDataDebugMessage.debugEntryMessage(null, null);
+
+ if (nodeTypeRequirementsDefinitionList == null) {
+ return null;
+ }
+ for (Map.Entry<String, RequirementAssignment> entry : nodeTemplateRequirementsAssignment
+ .entrySet()) {
+ if (entry.getValue().getNode() != null) {
+ Optional<RequirementDefinition> 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<String, RequirementDefinition> 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<String, CapabilityDefinition> calculateExposedCapabilities(
+ Map<String, CapabilityDefinition> nodeTypeCapabilitiesDefinition,
+ Map<String, Map<String, RequirementAssignment>> fullFilledRequirementsDefinitionMap) {
+
+
+ mdcDataDebugMessage.debugEntryMessage(null, null);
+
+ String capabilityKey;
+ String capability;
+ String node;
+ for (Map.Entry<String, Map<String, RequirementAssignment>> entry :
+ fullFilledRequirementsDefinitionMap.entrySet()) {
+ for (Map.Entry<String, RequirementAssignment> 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<String, CapabilityDefinition> exposedCapabilitiesDefinition = new HashMap<>();
+ for (Map.Entry<String, CapabilityDefinition> 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<String, NodeTemplate> 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 <T> Constructor getConstructor(Class<T> typClass) {
- return new ToscaWithHeatExtensionConstructor(typClass);
- }
-
- @Override
- protected PropertyUtils getPropertyUtils() {
- return new ToscaPropertyUtilsWithHeatExtension();
- }
-
- public class ToscaPropertyUtilsWithHeatExtension extends MyPropertyUtils {
- @Override
- public Property getProperty(Class<? extends Object> 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);
- }
- }
- }
- }
-}
-
-
-