aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services')
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ConfigConstants.java49
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/DataModelUtil.java871
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaAnalyzerService.java17
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaConstants.java16
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaNativeTypesServiceTemplate.java309
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaUtil.java106
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImpl.java529
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaFileOutputServiceCsarImpl.java37
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/yamlutil/ToscaExtensionYamlUtil.java17
9 files changed, 1346 insertions, 605 deletions
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
new file mode 100644
index 0000000000..df6eb195d8
--- /dev/null
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ConfigConstants.java
@@ -0,0 +1,49 @@
+/*-
+ * ============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;
+
+public class ConfigConstants {
+ //namespaces
+ 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";
+
+
+ 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 d0d7ccf621..28b9c67591 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
@@ -20,15 +20,29 @@
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;
+import org.openecomp.sdc.logging.context.impl.MdcDataErrorMessage;
+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.ToscaFunctions;
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.Constraint;
import org.openecomp.sdc.tosca.datatypes.model.EntrySchema;
import org.openecomp.sdc.tosca.datatypes.model.GroupDefinition;
-import org.openecomp.sdc.tosca.datatypes.model.Metadata;
+import org.openecomp.sdc.tosca.datatypes.model.Import;
import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate;
import org.openecomp.sdc.tosca.datatypes.model.NodeType;
+import org.openecomp.sdc.tosca.datatypes.model.ParameterDefinition;
import org.openecomp.sdc.tosca.datatypes.model.PolicyDefinition;
import org.openecomp.sdc.tosca.datatypes.model.PropertyDefinition;
import org.openecomp.sdc.tosca.datatypes.model.RelationshipTemplate;
@@ -41,15 +55,18 @@ import org.openecomp.sdc.tosca.datatypes.model.TopologyTemplate;
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.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
+import java.util.ListIterator;
import java.util.Map;
import java.util.Objects;
-import java.util.stream.Collectors;
+import java.util.Optional;
/**
* The type Data model util.
@@ -58,13 +75,24 @@ public class DataModelUtil {
/**
* Add substitution mapping.
+ */
+
+ private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
+
+ /**
+ * Add substitution mapping.
*
* @param serviceTemplate the service template
* @param substitutionMapping the substitution mapping
*/
public static void addSubstitutionMapping(ServiceTemplate serviceTemplate,
SubstitutionMapping substitutionMapping) {
+ mdcDataDebugMessage.debugEntryMessage(null, null);
+
if (serviceTemplate == null) {
+ MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
+ LoggerTragetServiceName.ADD_ENTITIES_TO_TOSCA, ErrorLevel.ERROR.name(),
+ LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_ADD_ACTION);
throw new CoreException(
new InvalidAddActionNullEntityErrorBuilder("Substitution Mapping", "Service Template")
.build());
@@ -74,6 +102,8 @@ public class DataModelUtil {
serviceTemplate.setTopology_template(new TopologyTemplate());
}
serviceTemplate.getTopology_template().setSubstitution_mappings(substitutionMapping);
+
+ mdcDataDebugMessage.debugExitMessage(null, null);
}
/**
@@ -86,7 +116,14 @@ public class DataModelUtil {
public static void addSubstitutionMappingReq(ServiceTemplate serviceTemplate,
String substitutionMappingRequirementId,
List<String> substitutionMappingRequirementList) {
+
+
+ mdcDataDebugMessage.debugEntryMessage(null, null);
+
if (serviceTemplate == null) {
+ MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
+ LoggerTragetServiceName.ADD_ENTITIES_TO_TOSCA, ErrorLevel.ERROR.name(),
+ LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_ADD_ACTION);
throw new CoreException(
new InvalidAddActionNullEntityErrorBuilder("Substitution Mapping Requirements",
"Service Template").build());
@@ -106,6 +143,8 @@ public class DataModelUtil {
serviceTemplate.getTopology_template().getSubstitution_mappings().getRequirements()
.put(substitutionMappingRequirementId, substitutionMappingRequirementList);
+
+ mdcDataDebugMessage.debugExitMessage(null, null);
}
/**
@@ -117,7 +156,14 @@ public class DataModelUtil {
*/
public static void addNodeTemplate(ServiceTemplate serviceTemplate, String nodeTemplateId,
NodeTemplate nodeTemplate) {
+
+
+ mdcDataDebugMessage.debugEntryMessage(null, null);
+
if (serviceTemplate == null) {
+ MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
+ LoggerTragetServiceName.ADD_ENTITIES_TO_TOSCA, ErrorLevel.ERROR.name(),
+ LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_ADD_ACTION);
throw new CoreException(
new InvalidAddActionNullEntityErrorBuilder("Node Template", "Service Template").build());
}
@@ -130,6 +176,66 @@ public class DataModelUtil {
topologyTemplate.setNode_templates(new HashMap<>());
}
topologyTemplate.getNode_templates().put(nodeTemplateId, nodeTemplate);
+
+ mdcDataDebugMessage.debugExitMessage(null, null);
+
+ }
+
+ /**
+ * Add capability def.
+ *
+ * @param nodeType the node type
+ * @param capabilityId the capability id
+ * @param capabilityDefinition the capability definition
+ */
+ public static void addCapabilityDef(NodeType nodeType, String capabilityId,
+ CapabilityDefinition capabilityDefinition) {
+
+
+ mdcDataDebugMessage.debugEntryMessage(null, null);
+
+ if (nodeType == null) {
+ throw new CoreException(
+ new InvalidAddActionNullEntityErrorBuilder("Capability Definition", "Node Type").build());
+ }
+ if (Objects.isNull(nodeType.getCapabilities())) {
+ nodeType.setCapabilities(new HashMap<>());
+ }
+ nodeType.getCapabilities().put(capabilityId, capabilityDefinition);
+
+ mdcDataDebugMessage.debugExitMessage(null, null);
+ }
+
+ /**
+ * Add capabilities def to node type.
+ *
+ * @param nodeType the node type
+ * @param capabilities the capability definitions
+ */
+ public static void addNodeTypeCapabilitiesDef(NodeType nodeType,
+ Map<String, CapabilityDefinition> capabilities) {
+ mdcDataDebugMessage.debugEntryMessage(null, null);
+
+ if (capabilities == null || capabilities.entrySet().size() == 0) {
+ return;
+ }
+
+ if (nodeType == null) {
+ throw new CoreException(
+ new InvalidAddActionNullEntityErrorBuilder("Capability Definition", "Node Type").build());
+ }
+
+ if (MapUtils.isEmpty(nodeType.getCapabilities())) {
+ nodeType.setCapabilities(new HashMap<>());
+ }
+ if (capabilities.size() > 0) {
+ nodeType.setCapabilities(new HashMap<>());
+ }
+ for (Map.Entry<String, CapabilityDefinition> entry : capabilities.entrySet()) {
+ nodeType.getCapabilities().put(entry.getKey(), entry.getValue());
+ }
+
+ mdcDataDebugMessage.debugExitMessage(null, null);
}
/**
@@ -141,7 +247,14 @@ public class DataModelUtil {
*/
public static void addPolicyDefinition(ServiceTemplate serviceTemplate, String policyId,
PolicyDefinition policyDefinition) {
+
+
+ mdcDataDebugMessage.debugEntryMessage(null, null);
+
if (serviceTemplate == null) {
+ MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
+ LoggerTragetServiceName.ADD_ENTITIES_TO_TOSCA, ErrorLevel.ERROR.name(),
+ LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_ADD_ACTION);
throw new CoreException(
new InvalidAddActionNullEntityErrorBuilder("Policy Definition", "Service Template")
.build());
@@ -155,6 +268,8 @@ public class DataModelUtil {
topologyTemplate.setPolicies(new HashMap<>());
}
topologyTemplate.getPolicies().put(policyId, policyDefinition);
+
+ mdcDataDebugMessage.debugExitMessage(null, null);
}
/**
@@ -166,7 +281,14 @@ public class DataModelUtil {
*/
public static void addNodeType(ServiceTemplate serviceTemplate, String nodeTypeId,
NodeType nodeType) {
+
+
+ mdcDataDebugMessage.debugEntryMessage(null, null);
+
if (serviceTemplate == null) {
+ MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
+ LoggerTragetServiceName.ADD_ENTITIES_TO_TOSCA, ErrorLevel.ERROR.name(),
+ LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_ADD_ACTION);
throw new CoreException(
new InvalidAddActionNullEntityErrorBuilder("Node Type", "Service Template").build());
}
@@ -174,6 +296,8 @@ public class DataModelUtil {
serviceTemplate.setNode_types(new HashMap<>());
}
serviceTemplate.getNode_types().put(nodeTypeId, nodeType);
+
+ mdcDataDebugMessage.debugExitMessage(null, null);
}
/**
@@ -186,7 +310,14 @@ public class DataModelUtil {
public static void addRelationshipTemplate(ServiceTemplate serviceTemplate,
String relationshipTemplateId,
RelationshipTemplate relationshipTemplate) {
+
+
+ mdcDataDebugMessage.debugEntryMessage(null, null);
+
if (serviceTemplate == null) {
+ MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
+ LoggerTragetServiceName.ADD_ENTITIES_TO_TOSCA, ErrorLevel.ERROR.name(),
+ LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_ADD_ACTION);
throw new CoreException(
new InvalidAddActionNullEntityErrorBuilder("Relationship Template", "Service Template")
.build());
@@ -199,6 +330,8 @@ public class DataModelUtil {
}
serviceTemplate.getTopology_template().getRelationship_templates()
.put(relationshipTemplateId, relationshipTemplate);
+
+ mdcDataDebugMessage.debugExitMessage(null, null);
}
/**
@@ -210,12 +343,22 @@ public class DataModelUtil {
*/
public static void addRequirementAssignment(NodeTemplate nodeTemplate, String requirementId,
RequirementAssignment requirementAssignment) {
+
+
+ mdcDataDebugMessage.debugEntryMessage(null, null);
+
if (nodeTemplate == null) {
+ MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
+ LoggerTragetServiceName.ADD_ENTITIES_TO_TOSCA, ErrorLevel.ERROR.name(),
+ LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_ADD_ACTION);
throw new CoreException(
new InvalidAddActionNullEntityErrorBuilder("Requirement Assignment", "Node Template")
.build());
}
if (requirementAssignment.getNode() == null) {
+ MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
+ LoggerTragetServiceName.ADD_ENTITIES_TO_TOSCA, ErrorLevel.ERROR.name(),
+ LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_ADD_ACTION);
throw new CoreException(new InvalidRequirementAssignmentErrorBuilder(requirementId).build());
}
@@ -225,6 +368,8 @@ public class DataModelUtil {
Map<String, RequirementAssignment> requirement = new HashMap<>();
requirement.put(requirementId, requirementAssignment);
nodeTemplate.getRequirements().add(requirement);
+
+ mdcDataDebugMessage.debugExitMessage(null, null);
}
/**
@@ -236,11 +381,16 @@ public class DataModelUtil {
*/
public static NodeTemplate getNodeTemplate(ServiceTemplate serviceTemplate,
String nodeTemplateId) {
+
+ mdcDataDebugMessage.debugEntryMessage(null, null);
+
if (serviceTemplate == null
|| serviceTemplate.getTopology_template() == null
|| serviceTemplate.getTopology_template().getNode_templates() == null) {
return null;
}
+
+ mdcDataDebugMessage.debugExitMessage(null, null);
return serviceTemplate.getTopology_template().getNode_templates().get(nodeTemplateId);
}
@@ -252,13 +402,92 @@ public class DataModelUtil {
* @return the node type
*/
public static NodeType getNodeType(ServiceTemplate serviceTemplate, String nodeTypeId) {
+
+
+ mdcDataDebugMessage.debugEntryMessage(null, null);
if (serviceTemplate == null || serviceTemplate.getNode_types() == null) {
return null;
}
+
+ mdcDataDebugMessage.debugExitMessage(null, null);
return serviceTemplate.getNode_types().get(nodeTypeId);
}
/**
+ * Gets requirement definition.
+ *
+ * @param nodeType the node type
+ * @param requirementDefinitionId the requirement definition id
+ * @return the requirement definition
+ */
+ public static Optional<RequirementDefinition> getRequirementDefinition(
+ NodeType nodeType,
+ String requirementDefinitionId) {
+
+
+ mdcDataDebugMessage.debugEntryMessage(null, null);
+
+ if (nodeType == null || nodeType.getRequirements() == null || requirementDefinitionId == null) {
+ return Optional.empty();
+ }
+ for (Map<String, RequirementDefinition> reqMap : nodeType.getRequirements()) {
+ if (reqMap.containsKey(requirementDefinitionId)) {
+ return Optional.of(reqMap.get(requirementDefinitionId));
+ }
+ }
+
+ mdcDataDebugMessage.debugExitMessage(null, null);
+ return Optional.empty();
+ }
+
+ /**
+ * get requirement defenition from requirement defenition list by req key.
+ *
+ * @param requirementsDefinitionList requirement defenition list
+ * @param requirementKey requirement key
+ */
+ public static Optional<RequirementDefinition> getRequirementDefinition(
+ List<Map<String, RequirementDefinition>> requirementsDefinitionList,
+ String requirementKey) {
+ mdcDataDebugMessage.debugEntryMessage(null, null);
+ if (CollectionUtils.isEmpty(requirementsDefinitionList)) {
+ return Optional.empty();
+ }
+
+ for (Map<String, RequirementDefinition> requirementMap : requirementsDefinitionList) {
+ if (requirementMap.containsKey(requirementKey)) {
+ mdcDataDebugMessage.debugExitMessage(null, null);
+ return Optional.of(requirementMap.get(requirementKey));
+ }
+ }
+
+ mdcDataDebugMessage.debugExitMessage(null, null);
+ return Optional.empty();
+ }
+
+ /**
+ * Gets capability definition.
+ *
+ * @param nodeType the node type
+ * @param capabilityDefinitionId the capability definition id
+ * @return the capability definition
+ */
+ public static Optional<CapabilityDefinition> getCapabilityDefinition(
+ NodeType nodeType,
+ String capabilityDefinitionId) {
+
+
+ mdcDataDebugMessage.debugEntryMessage(null, null);
+
+ if (nodeType == null || nodeType.getCapabilities() == null || capabilityDefinitionId == null) {
+ return Optional.empty();
+ }
+
+ mdcDataDebugMessage.debugExitMessage(null, null);
+ return Optional.ofNullable(nodeType.getCapabilities().get(capabilityDefinitionId));
+ }
+
+ /**
* Add group definition to topology template.
*
* @param serviceTemplate the service template
@@ -267,7 +496,14 @@ public class DataModelUtil {
*/
public static void addGroupDefinitionToTopologyTemplate(ServiceTemplate serviceTemplate,
String groupName, GroupDefinition group) {
+
+
+ mdcDataDebugMessage.debugEntryMessage(null, null);
+
if (serviceTemplate == null) {
+ MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
+ LoggerTragetServiceName.ADD_ENTITIES_TO_TOSCA, ErrorLevel.ERROR.name(),
+ LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_ADD_ACTION);
throw new CoreException(
new InvalidAddActionNullEntityErrorBuilder("Group Definition", "Service Template")
.build());
@@ -285,7 +521,9 @@ public class DataModelUtil {
Map<String, GroupDefinition> groups = new HashMap<>();
serviceTemplate.getTopology_template().setGroups(groups);
}
+
serviceTemplate.getTopology_template().getGroups().put(groupName, group);
+ mdcDataDebugMessage.debugExitMessage(null, null);
}
/**
@@ -306,6 +544,10 @@ public class DataModelUtil {
Status status,
EntrySchema entrySchema,
Object defaultVal) {
+
+
+ mdcDataDebugMessage.debugEntryMessage(null, null);
+
PropertyDefinition propDef = new PropertyDefinition();
propDef.setType(type);
propDef.setDescription(description);
@@ -317,10 +559,50 @@ public class DataModelUtil {
propDef.setEntry_schema(entrySchema);
propDef.set_default(defaultVal);
+ mdcDataDebugMessage.debugExitMessage(null, null);
return propDef;
}
/**
+ * Create parameter definition property definition.
+ *
+ * @param type the type
+ * @param description the description
+ * @param value the value
+ * @param required the required
+ * @param constraints the constraints
+ * @param status the status
+ * @param entrySchema the entry schema
+ * @param defaultVal the default val
+ * @return the property definition
+ */
+ public static ParameterDefinition createParameterDefinition(String type, String description,
+ Object value, boolean required,
+ List<Constraint> constraints,
+ Status status,
+ EntrySchema entrySchema,
+ Object defaultVal) {
+
+
+ mdcDataDebugMessage.debugEntryMessage(null, null);
+
+ ParameterDefinition paramDef = new ParameterDefinition();
+ paramDef.setType(type);
+ paramDef.setDescription(description);
+ paramDef.setValue(value);
+ paramDef.setRequired(required);
+ paramDef.setConstraints(constraints);
+ if (status != null) {
+ paramDef.setStatus(status);
+ }
+ paramDef.setEntry_schema(entrySchema == null ? null : entrySchema.clone());
+ paramDef.set_default(defaultVal);
+
+ mdcDataDebugMessage.debugExitMessage(null, null);
+ return paramDef;
+ }
+
+ /**
* Create requirement requirement definition.
*
* @param capability the capability
@@ -331,6 +613,10 @@ public class DataModelUtil {
*/
public static RequirementDefinition createRequirement(String capability, String node,
String relationship, Object[] occurrences) {
+
+
+ mdcDataDebugMessage.debugEntryMessage(null, null);
+
RequirementDefinition requirementDefinition = new RequirementDefinition();
requirementDefinition.setCapability(capability);
requirementDefinition.setNode(node);
@@ -338,6 +624,8 @@ public class DataModelUtil {
if (occurrences != null) {
requirementDefinition.setOccurrences(occurrences);
}
+
+ mdcDataDebugMessage.debugExitMessage(null, null);
return requirementDefinition;
}
@@ -355,6 +643,10 @@ public class DataModelUtil {
Status status,
EntrySchema entrySchema,
Object defaultVal) {
+
+
+ mdcDataDebugMessage.debugEntryMessage(null, null);
+
AttributeDefinition attributeDef = new AttributeDefinition();
attributeDef.setType(type);
@@ -367,6 +659,7 @@ public class DataModelUtil {
attributeDef.setEntry_schema(entrySchema);
attributeDef.set_default(defaultVal);
+ mdcDataDebugMessage.debugExitMessage(null, null);
return attributeDef;
}
@@ -377,10 +670,16 @@ public class DataModelUtil {
* @return the constraint
*/
public static Constraint createValidValuesConstraint(Object... values) {
+
+
+ mdcDataDebugMessage.debugEntryMessage(null, null);
+
Constraint validValues = new Constraint();
for (Object value : values) {
validValues.addValidValue(value);
}
+
+ mdcDataDebugMessage.debugExitMessage(null, null);
return validValues;
}
@@ -392,13 +691,17 @@ public class DataModelUtil {
* @param templateAuthor the template author
* @return the metadata
*/
- public static Metadata createMetadata(String templateName, String templateVersion,
+ public static Map<String, String> createMetadata(String templateName, String templateVersion,
String templateAuthor) {
- Metadata metadata = new Metadata();
- metadata.setTemplate_name(templateName);
- metadata.setTemplate_version(templateVersion);
- metadata.setTemplate_author(templateAuthor);
+
+ mdcDataDebugMessage.debugEntryMessage(null, null);
+ Map<String, String> metadata = new HashMap<>();
+ metadata.put(ToscaConstants.ST_METADATA_TEMPLATE_NAME, templateName);
+ metadata.put("template_version", templateVersion);
+ metadata.put("template_author", templateAuthor);
+
+ mdcDataDebugMessage.debugExitMessage(null, null);
return metadata;
}
@@ -412,10 +715,16 @@ public class DataModelUtil {
*/
public static EntrySchema createEntrySchema(String type, String description,
List<Constraint> constraints) {
+
+
+ mdcDataDebugMessage.debugEntryMessage(null, null);
+
EntrySchema entrySchema = new EntrySchema();
entrySchema.setType(type);
entrySchema.setDescription(description);
entrySchema.setConstraints(constraints);
+
+ mdcDataDebugMessage.debugExitMessage(null, null);
return entrySchema;
}
@@ -426,11 +735,17 @@ public class DataModelUtil {
* @return the list
*/
public static List<Constraint> createValidValuesConstraintsList(String... values) {
+
+
+ mdcDataDebugMessage.debugEntryMessage(null, null);
+
List<Constraint> constraints;
Constraint validValues;
constraints = new ArrayList<>();
validValues = DataModelUtil.createValidValuesConstraint(values);
constraints.add(validValues);
+
+ mdcDataDebugMessage.debugExitMessage(null, null);
return constraints;
}
@@ -441,9 +756,12 @@ public class DataModelUtil {
* @return the constraint
*/
public static Constraint createGreaterOrEqualConstrain(Object value) {
+ mdcDataDebugMessage.debugEntryMessage(null, null);
Constraint constraint = new Constraint();
constraint.setGreater_or_equal(value);
+
+ mdcDataDebugMessage.debugExitMessage(null, null);
return constraint;
}
@@ -469,6 +787,10 @@ public class DataModelUtil {
public static Map createGetInputPropertyValueFromListParameter(String inputPropertyListName,
int indexInTheList,
String... nestedPropertyName) {
+
+
+ mdcDataDebugMessage.debugEntryMessage(null, null);
+
List propertyList = new ArrayList<>();
propertyList.add(inputPropertyListName);
propertyList.add(indexInTheList);
@@ -477,6 +799,8 @@ public class DataModelUtil {
}
Map getInputProperty = new HashMap<>();
getInputProperty.put(ToscaFunctions.GET_INPUT.getDisplayName(), propertyList);
+
+ mdcDataDebugMessage.debugExitMessage(null, null);
return getInputProperty;
}
@@ -488,6 +812,10 @@ public class DataModelUtil {
*/
public static ParameterDefinitionExt convertPropertyDefToParameterDef(
PropertyDefinition propertyDefinition) {
+
+
+ mdcDataDebugMessage.debugEntryMessage(null, null);
+
if (propertyDefinition == null) {
return null;
}
@@ -499,10 +827,12 @@ public class DataModelUtil {
parameterDefinition.set_default(propertyDefinition.get_default());
parameterDefinition.setStatus(propertyDefinition.getStatus());
parameterDefinition.setConstraints(propertyDefinition.getConstraints());
- parameterDefinition.setEntry_schema(propertyDefinition.getEntry_schema());
+ parameterDefinition.setEntry_schema(Objects.isNull(propertyDefinition.getEntry_schema()) ? null
+ : propertyDefinition.getEntry_schema().clone());
parameterDefinition.setHidden(false);
parameterDefinition.setImmutable(false);
+ mdcDataDebugMessage.debugExitMessage(null, null);
return parameterDefinition;
}
@@ -515,74 +845,535 @@ public class DataModelUtil {
*/
public static ParameterDefinitionExt convertAttributeDefToParameterDef(
AttributeDefinition attributeDefinition, Map<String, List> outputValue) {
+
+
+ mdcDataDebugMessage.debugEntryMessage(null, null);
+
if (attributeDefinition == null) {
return null;
}
ParameterDefinitionExt parameterDefinition = new ParameterDefinitionExt();
parameterDefinition.setDescription(attributeDefinition.getDescription());
parameterDefinition.setValue(outputValue);
+
+ mdcDataDebugMessage.debugExitMessage(null, null);
return parameterDefinition;
}
/**
- * Clone constraints list.
+ * Convert capability type to capability definition capability definition.
*
- * @param constraints the constraints
- * @return the list
+ * @param capabilityTypeId the capability type id
+ * @param capabilityType the capability type
+ * @param properties the properties
+ * @return the capability definition
*/
- public static List<Constraint> cloneConstraints(List<Constraint> constraints) {
- if (constraints == null) {
+ public static CapabilityDefinition convertCapabilityTypeToCapabilityDefinition(
+ String capabilityTypeId, CapabilityType capabilityType, Map<String, Object> properties) {
+
+
+ mdcDataDebugMessage.debugEntryMessage(null, null);
+
+ CapabilityDefinition capabilityDefinition = new CapabilityDefinition();
+ capabilityDefinition.setAttributes(cloneAttributeDefinitionMap(capabilityType.getAttributes()));
+ capabilityDefinition.setProperties(clonePropertyDefinitionMap(capabilityType.getProperties()));
+ capabilityDefinition.setDescription(capabilityType.getDescription());
+ capabilityDefinition.setType(capabilityTypeId);
+
+ capabilityDefinition.getProperties()
+ .entrySet()
+ .stream()
+ .filter(entry -> properties.containsKey(entry.getKey()))
+ .forEach(entry -> entry.getValue()
+ .set_default(properties.get(entry.getKey())));
+
+ mdcDataDebugMessage.debugExitMessage(null, null);
+ return capabilityDefinition;
+ }
+
+ /**
+ * Clone property definition map map.
+ *
+ * @param propertyDefinitionMap the property definition map
+ * @return the map
+ */
+ public static Map clonePropertyDefinitionMap(
+ Map<String, PropertyDefinition> propertyDefinitionMap) {
+
+
+ mdcDataDebugMessage.debugEntryMessage(null, null);
+
+ Map outMap = new HashMap<>();
+ for (String propertyDefKey : propertyDefinitionMap.keySet()) {
+ PropertyDefinition propertyDefValue = propertyDefinitionMap.get(propertyDefKey);
+ outMap.put(new String(propertyDefKey), propertyDefValue.clone());
+ }
+
+ mdcDataDebugMessage.debugExitMessage(null, null);
+ return outMap;
+ }
+
+ /**
+ * Clone attribute definition map map.
+ *
+ * @param attributeDefinitionMap the attribute definition map
+ * @return the map
+ */
+ public static Map cloneAttributeDefinitionMap(
+ Map<String, AttributeDefinition> attributeDefinitionMap) {
+
+
+ mdcDataDebugMessage.debugEntryMessage(null, null);
+
+ Map outMap = new HashMap<>();
+ for (String attributeDefKey : attributeDefinitionMap.keySet()) {
+ AttributeDefinition attributeDefinition = attributeDefinitionMap.get(attributeDefKey);
+ outMap.put(new String(attributeDefKey), attributeDefinition.clone());
+ }
+
+ mdcDataDebugMessage.debugExitMessage(null, null);
+ return outMap;
+ }
+
+ public static boolean isNodeTemplate(String entryId, ServiceTemplate serviceTemplate) {
+ return serviceTemplate.getTopology_template().getNode_templates() != null
+ && serviceTemplate.getTopology_template().getNode_templates().get(entryId) != null;
+ }
+
+ /**
+ * Add Input parameter.
+ *
+ * @param serviceTemplate the service template
+ * @param parameterDefinitionId the parameter definition id
+ * @param parameterDefinition the parameter definition
+ */
+ public static void addInputParameterToTopologyTemplate(ServiceTemplate serviceTemplate,
+ String parameterDefinitionId,
+ ParameterDefinition parameterDefinition) {
+
+
+ mdcDataDebugMessage.debugEntryMessage(null, null);
+
+ if (Objects.isNull(serviceTemplate)) {
+ MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
+ LoggerTragetServiceName.ADD_ENTITIES_TO_TOSCA, ErrorLevel.ERROR.name(),
+ LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_ADD_ACTION);
+ throw new CoreException(
+ new InvalidAddActionNullEntityErrorBuilder("Topology Template Input Parameter",
+ "Service Template").build());
+ }
+ TopologyTemplate topologyTemplate = serviceTemplate.getTopology_template();
+ if (Objects.isNull(topologyTemplate)) {
+ topologyTemplate = new TopologyTemplate();
+ serviceTemplate.setTopology_template(topologyTemplate);
+ }
+ if (topologyTemplate.getInputs() == null) {
+ topologyTemplate.setInputs(new HashMap<>());
+ }
+ topologyTemplate.getInputs().put(parameterDefinitionId, parameterDefinition);
+
+ mdcDataDebugMessage.debugExitMessage(null, null);
+
+ }
+
+ /**
+ * Add Output parameter.
+ *
+ * @param serviceTemplate the service template
+ * @param parameterDefinitionId the parameter definition id
+ * @param parameterDefinition the parameter definition
+ */
+ public static void addOutputParameterToTopologyTemplate(ServiceTemplate serviceTemplate,
+ String parameterDefinitionId,
+ ParameterDefinition parameterDefinition) {
+
+
+ mdcDataDebugMessage.debugEntryMessage(null, null);
+
+ if (Objects.isNull(serviceTemplate)) {
+ MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
+ LoggerTragetServiceName.ADD_ENTITIES_TO_TOSCA, ErrorLevel.ERROR.name(),
+ LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_ADD_ACTION);
+ throw new CoreException(
+ new InvalidAddActionNullEntityErrorBuilder("Topology Template Ouput Parameter",
+ "Service Template").build());
+ }
+ TopologyTemplate topologyTemplate = serviceTemplate.getTopology_template();
+ if (Objects.isNull(topologyTemplate)) {
+ topologyTemplate = new TopologyTemplate();
+ serviceTemplate.setTopology_template(topologyTemplate);
+ }
+ if (topologyTemplate.getOutputs() == null) {
+ topologyTemplate.setOutputs(new HashMap<>());
+ }
+ topologyTemplate.getOutputs().put(parameterDefinitionId, parameterDefinition);
+
+ mdcDataDebugMessage.debugExitMessage(null, null);
+
+ }
+
+ /**
+ * Add requirement def to requirement def list.
+ *
+ * @param requirementList requirement list
+ * @param requirementDef added requirement def
+ */
+ public static void addRequirementToList(List<Map<String, RequirementDefinition>> requirementList,
+ Map<String, RequirementDefinition> requirementDef) {
+ if (requirementDef == null) {
+ return;
+ }
+ if (requirementList == null) {
+ requirementList = new ArrayList<Map<String, RequirementDefinition>>();
+ }
+
+ for (Map.Entry<String, RequirementDefinition> entry : requirementDef.entrySet()) {
+ CommonMethods.mergeEntryInList(entry.getKey(), entry.getValue(), requirementList);
+ }
+ }
+
+ /**
+ * get node template requirement.
+ *
+ * @param nodeTemplate node template
+ */
+ public static Map<String, RequirementAssignment> getNodeTemplateRequirements(
+ NodeTemplate nodeTemplate) {
+ mdcDataDebugMessage.debugEntryMessage(null, null);
+
+ if (Objects.isNull(nodeTemplate)) {
return null;
}
- return constraints.stream().map(Constraint::clone).collect(Collectors.toList());
+ List<Map<String, RequirementAssignment>> templateRequirements = nodeTemplate.getRequirements();
+
+ Map<String, RequirementAssignment> nodeTemplateRequirementsAssignment = new HashMap<>();
+ if (CollectionUtils.isEmpty(templateRequirements)) {
+ return nodeTemplateRequirementsAssignment;
+ }
+ YamlUtil yamlUtil = new YamlUtil();
+ for (Map<String, RequirementAssignment> requirementAssignmentMap : templateRequirements) {
+ for (Map.Entry<String, RequirementAssignment> requirementEntry : requirementAssignmentMap
+ .entrySet()) {
+ RequirementAssignment requirementAssignment = (yamlUtil
+ .yamlToObject(yamlUtil.objectToYaml(requirementEntry.getValue()),
+ RequirementAssignment.class));
+ nodeTemplateRequirementsAssignment
+ .put(requirementEntry.getKey(), requirementAssignment);
+ }
+ }
+
+ mdcDataDebugMessage.debugExitMessage(null, null);
+ return nodeTemplateRequirementsAssignment;
}
/**
- * Clone valid source types list.
+ * Gets the list of requirements for the node template.
*
- * @param validSourceTypes the valid source types
- * @return the list
+ * @param nodeTemplate the node template
+ * @return the node template requirement list and null if the node has no requirements
*/
- public static List<String> cloneValidSourceTypes(List<String> validSourceTypes) {
- if (validSourceTypes == null) {
+ public static List<Map<String, RequirementAssignment>> getNodeTemplateRequirementList(
+ NodeTemplate nodeTemplate) {
+ mdcDataDebugMessage.debugEntryMessage(null, null);
+ ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
+ //Creating concrete objects
+ List<Map<String, RequirementAssignment>> requirements = nodeTemplate.getRequirements();
+ List<Map<String, RequirementAssignment>> concreteRequirementList = null;
+ if (requirements != null) {
+ concreteRequirementList = new ArrayList<>();
+ ListIterator<Map<String, RequirementAssignment>> reqListIterator = requirements
+ .listIterator();
+ while (reqListIterator.hasNext()) {
+ Map<String, RequirementAssignment> requirement = reqListIterator.next();
+ Map<String, RequirementAssignment> concreteRequirement = new HashMap<>();
+ for (Map.Entry<String, RequirementAssignment> reqEntry : requirement.entrySet()) {
+ RequirementAssignment requirementAssignment = (toscaExtensionYamlUtil
+ .yamlToObject(toscaExtensionYamlUtil.objectToYaml(reqEntry.getValue()),
+ RequirementAssignment.class));
+ concreteRequirement.put(reqEntry.getKey(), requirementAssignment);
+ concreteRequirementList.add(concreteRequirement);
+ reqListIterator.remove();
+ }
+ }
+ requirements.clear();
+ requirements.addAll(concreteRequirementList);
+ nodeTemplate.setRequirements(requirements);
+ }
+ mdcDataDebugMessage.debugExitMessage(null, null);
+ return concreteRequirementList;
+ }
+
+ /**
+ * get requirement assignment from requirement assignment list by req key.
+ *
+ * @param requirementsAssignmentList requirement defenition list
+ * @param requirementKey requirement key
+ */
+ public static Optional<List<RequirementAssignment>> getRequirementAssignment(
+ List<Map<String, RequirementAssignment>> requirementsAssignmentList,
+ String requirementKey) {
+
+ mdcDataDebugMessage.debugEntryMessage(null, null);
+ if (CollectionUtils.isEmpty(requirementsAssignmentList)) {
+ return Optional.empty();
+ }
+
+ List<RequirementAssignment> matchRequirementAssignmentList = new ArrayList<>();
+ for (Map<String, RequirementAssignment> requirementMap : requirementsAssignmentList) {
+ if (requirementMap.containsKey(requirementKey)) {
+ YamlUtil yamlUtil = new YamlUtil();
+ RequirementAssignment requirementAssignment = (yamlUtil
+ .yamlToObject(yamlUtil.objectToYaml(requirementMap.get(requirementKey)),
+ RequirementAssignment.class));
+ matchRequirementAssignmentList.add(requirementAssignment);
+ }
+ }
+
+ mdcDataDebugMessage.debugExitMessage(null, null);
+ return Optional.ofNullable(matchRequirementAssignmentList);
+ }
+
+ /**
+ * remove requirement defenition from requirement defenition list by req key.
+ *
+ * @param requirementsDefinitionList requirement defenition list
+ * @param requirementKey requirement key
+ */
+ public static void removeRequirementsDefinition(
+ List<Map<String, RequirementDefinition>> requirementsDefinitionList,
+ String requirementKey) {
+ mdcDataDebugMessage.debugEntryMessage(null, null);
+ if (requirementsDefinitionList == null) {
+ return;
+ }
+
+ List<Map<String, RequirementDefinition>> mapToBeRemoved = new ArrayList<>();
+ for (Map<String, RequirementDefinition> reqMap : requirementsDefinitionList) {
+ reqMap.remove(requirementKey);
+ if (reqMap.isEmpty()) {
+ mapToBeRemoved.add(reqMap);
+ }
+ }
+ for (Map<String, RequirementDefinition> removeMap : mapToBeRemoved) {
+ requirementsDefinitionList.remove(removeMap);
+ }
+
+ mdcDataDebugMessage.debugExitMessage(null, null);
+ }
+
+ /**
+ * remove requirement assignment from requirement defenition list by req key.
+ *
+ * @param requirementsAssignmentList requirement Assignment list
+ * @param requirementKey requirement key
+ */
+ public static void removeRequirementsAssignment(
+ List<Map<String, RequirementAssignment>> requirementsAssignmentList,
+ String requirementKey) {
+ mdcDataDebugMessage.debugEntryMessage(null, null);
+ if (requirementsAssignmentList == null) {
+ return;
+ }
+
+ List<Map<String, RequirementAssignment>> mapToBeRemoved = new ArrayList<>();
+ for (Map<String, RequirementAssignment> reqMap : requirementsAssignmentList) {
+ reqMap.remove(requirementKey);
+ if (reqMap.isEmpty()) {
+ mapToBeRemoved.add(reqMap);
+ }
+ }
+ for (Map<String, RequirementAssignment> removeMap : mapToBeRemoved) {
+ requirementsAssignmentList.remove(removeMap);
+ }
+
+ mdcDataDebugMessage.debugExitMessage(null, null);
+ }
+
+
+ /**
+ * Remove requirement assignment.
+ *
+ * @param nodeTemplate the node template
+ * @param requirementKey the requirement key
+ * @param requirementAssignmentToBeDeleted the requirement assignment to be deleted
+ */
+ public static void removeRequirementAssignment(
+ NodeTemplate nodeTemplate,
+ String requirementKey,
+ RequirementAssignment requirementAssignmentToBeDeleted) {
+ mdcDataDebugMessage.debugEntryMessage(null, null);
+ ToscaAnalyzerService toscaAnalyzerService = new ToscaAnalyzerServiceImpl();
+ List<Map<String, RequirementAssignment>> nodeTemplateRequirements = nodeTemplate
+ .getRequirements();
+ if (nodeTemplateRequirements == null) {
+ return;
+ }
+
+ Map<String, RequirementAssignment> mapToBeRemoved = new HashMap<>();
+ ListIterator<Map<String, RequirementAssignment>> iter = nodeTemplateRequirements.listIterator();
+ while (iter.hasNext()) {
+ Map<String, RequirementAssignment> reqMap = iter.next();
+ RequirementAssignment requirementAssignment = reqMap.get(requirementKey);
+ if (requirementAssignment != null) {
+ boolean isDesiredRequirementAssignment = toscaAnalyzerService
+ .isDesiredRequirementAssignment(requirementAssignment,
+ requirementAssignmentToBeDeleted.getCapability(),
+ requirementAssignmentToBeDeleted.getNode(),
+ requirementAssignmentToBeDeleted.getRelationship());
+ if (isDesiredRequirementAssignment) {
+ iter.remove();
+ }
+ }
+ }
+
+ mdcDataDebugMessage.debugExitMessage(null, null);
+ }
+
+ /**
+ * Return the suffix of the input namespace
+ * For an exmpale - for abc.sdf.vsrx, retrun vsrx
+ *
+ * @param namespace namespace
+ * @return String namespace suffix
+ */
+ public static String getNamespaceSuffix(String namespace) {
+ if (namespace == null) {
return null;
}
- return validSourceTypes.stream().collect(Collectors.toList());
+ String delimiterChar = ".";
+ if (namespace.contains(delimiterChar)) {
+ return namespace.substring(namespace.lastIndexOf(delimiterChar) + 1);
+ }
+ return namespace;
}
/**
- * Clone property definitions map.
+ * Return true if the input import exist in the input imports list.
*
- * @param propertyDefinitions the property definitions
- * @return the map
+ * @param imports namespace
+ * @param importId namespace
+ * @return true if exist, flase if not exist
+ */
+ public static boolean isImportAddedToServiceTemplate(List<Map<String, Import>> imports,
+ String importId) {
+ for (Map<String, Import> anImport : imports) {
+ if (anImport.containsKey(importId)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Get output parameter according to the input outputParameterId.
+ *
+ * @param serviceTemplate service template
+ * @param outputParameterId output parameter id
+ * @return ParameterDefinition - output parameter
*/
- public static Map<String, PropertyDefinition> clonePropertyDefinitions(
- Map<String, PropertyDefinition> propertyDefinitions) {
- if (propertyDefinitions == null) {
+ public static ParameterDefinition getOuputParameter(ServiceTemplate serviceTemplate,
+ String outputParameterId) {
+ mdcDataDebugMessage.debugEntryMessage(null, null);
+
+ if (serviceTemplate == null
+ || serviceTemplate.getTopology_template() == null
+ || serviceTemplate.getTopology_template().getOutputs() == null) {
return null;
}
- Map<String, PropertyDefinition> clonedProperties = new HashMap<>();
- for (String propertyKey : propertyDefinitions.keySet()) {
- clonedProperties.put(propertyKey, propertyDefinitions.get(propertyKey).clone());
+
+ mdcDataDebugMessage.debugExitMessage(null, null);
+ return serviceTemplate.getTopology_template().getOutputs().get(outputParameterId);
+ }
+
+ /**
+ * Gets input parameters in a service template.
+ *
+ * @param serviceTemplate the service template
+ * @return the input parameters
+ */
+ public static Map<String, ParameterDefinition> getInputParameters(ServiceTemplate
+ serviceTemplate) {
+ if (serviceTemplate == null
+ || serviceTemplate.getTopology_template() == null
+ || serviceTemplate.getTopology_template().getInputs() == null) {
+ return null;
}
- return clonedProperties;
+ return serviceTemplate.getTopology_template().getInputs();
}
/**
- * Clone attribute definitions map.
+ * Gets relationship templates in a service template.
*
- * @param attributeDefinitions the attribute definitions
- * @return the map
+ * @param serviceTemplate the service template
+ * @return the relationship template
+ */
+ public static Map<String, RelationshipTemplate> getRelationshipTemplates(ServiceTemplate
+ serviceTemplate) {
+ if (serviceTemplate == null
+ || serviceTemplate.getTopology_template() == null
+ || serviceTemplate.getTopology_template().getRelationship_templates() == null) {
+ return null;
+ }
+ return serviceTemplate.getTopology_template().getRelationship_templates();
+ }
+
+ /**
+ * Get property value according to the input propertyId.
+ *
+ * @param nodeTemplate node template
+ * @param propertyId property id
+ * @return Object property Value
*/
- public static Map<String, AttributeDefinition> cloneAttributeDefinitions(
- Map<String, AttributeDefinition> attributeDefinitions) {
- if (attributeDefinitions == null) {
+ public static Object getPropertyValue(NodeTemplate nodeTemplate,
+ String propertyId) {
+ mdcDataDebugMessage.debugEntryMessage(null, null);
+
+ if (nodeTemplate == null
+ || nodeTemplate.getProperties() == null) {
return null;
}
- Map<String, AttributeDefinition> clonedAttributeDefinitions = new HashMap<>();
- for (String attributeKey : attributeDefinitions.keySet()) {
- clonedAttributeDefinitions.put(attributeKey, attributeDefinitions.get(attributeKey).clone());
+
+ mdcDataDebugMessage.debugExitMessage(null, null);
+ return nodeTemplate.getProperties().get(propertyId);
+ }
+
+ /**
+ * Get node template properties according to the input node template id.
+ *
+ * @param serviceTemplate service template
+ * @param nodeTemplateId node template id
+ * @return node template properties
+ */
+ public static Map<String, Object> getNodeTemplateProperties(ServiceTemplate serviceTemplate,
+ String nodeTemplateId) {
+ mdcDataDebugMessage.debugEntryMessage(null, null);
+
+ if (serviceTemplate == null
+ || serviceTemplate.getTopology_template() == null
+ || serviceTemplate.getTopology_template().getNode_templates() == null
+ || serviceTemplate.getTopology_template().getNode_templates().get(nodeTemplateId) == null) {
+ return null;
+ }
+
+ mdcDataDebugMessage.debugExitMessage(null, null);
+ return serviceTemplate.getTopology_template().getNode_templates().get(nodeTemplateId)
+ .getProperties();
+ }
+
+ /**
+ * Compare two requirement assignment objects for equality.
+ *
+ * @param first the first requirement assignement object
+ * @param second the second requirement assignement object
+ * @return true if objects are equal and false otherwise
+ */
+ public static boolean compareRequirementAssignment(RequirementAssignment first,
+ RequirementAssignment second) {
+ if (first.getCapability().equals(second.getCapability())
+ && first.getNode().equals(second.getNode())
+ && first.getRelationship().equals(second.getRelationship())) {
+ return true;
}
- return clonedAttributeDefinitions;
+ return false;
}
}
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 271c471922..ac7cab6c51 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
@@ -23,9 +23,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.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.ServiceTemplate;
+import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@@ -38,6 +41,8 @@ public interface ToscaAnalyzerService {
Map<String, NodeTemplate> getNodeTemplatesByType(ServiceTemplate serviceTemplate, String nodeType,
ToscaServiceModel toscaServiceModel);
+ Optional<NodeType> fetchNodeType(String nodeTypeKey, Collection<ServiceTemplate> serviceTemplates);
+
boolean isTypeOf(NodeTemplate nodeTemplate, String nodeType, ServiceTemplate serviceTemplate,
ToscaServiceModel toscaServiceModel);
@@ -63,4 +68,16 @@ public interface ToscaAnalyzerService {
Object getFlatEntity(ToscaElementTypes elementType, String type, ServiceTemplate serviceTemplate,
ToscaServiceModel toscaModel);
+
+ boolean isSubstitutableNodeTemplate(NodeTemplate nodeTemplate);
+
+ NodeType createInitSubstitutionNodeType(ServiceTemplate substitutionServiceTemplate,
+ String nodeTypeDerivedFromValue);
+
+ boolean isRequirementExistInNodeTemplate(NodeTemplate nodeTemplate,
+ String requirementId,
+ RequirementAssignment requirementAssignment);
+
+ public Map<String, PropertyDefinition> manageSubstitutionNodeTypeProperties(
+ ServiceTemplate substitutionServiceTemplate);
}
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaConstants.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaConstants.java
index 27cf07e166..cf0c763846 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaConstants.java
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaConstants.java
@@ -23,11 +23,6 @@ package org.openecomp.sdc.tosca.services;
public class ToscaConstants {
- //TOSCA Node Types prefix
- public static final String NODES_PREFIX = "org.openecomp.resource.vfc.nodes.heat.";
- public static final String NODES_SUBSTITUTION_PREFIX
- = "org.openecomp.resource.abstract.nodes.heat.";
-
//TOSCA Requirement Ids
public static final String DEPENDS_ON_REQUIREMENT_ID = "dependency";
public static final String BINDING_REQUIREMENT_ID = "binding";
@@ -43,6 +38,8 @@ public class ToscaConstants {
public static final String ENDPOINT_CAPABILITY_ID = "endpoint";
public static final String OS_CAPABILITY_ID = "os";
public static final String SCALABLE_CAPABILITY_ID = "scalable";
+ public static final String ATTACHMENT_CAPABILITY_ID = "attachment";
+ public static final String FEATURE_CAPABILITY_ID = "feature";
//General
public static final String TOSCA_DEFINITIONS_VERSION = "tosca_simple_yaml_1_0_0";
@@ -50,6 +47,8 @@ public class ToscaConstants {
public static final String NODE_TEMPLATE_DIRECTIVE_SUBSTITUTABLE = "substitutable";
public static final String NATIVE_TYPES_SERVICE_TEMPLATE_NAME = "NativeTypesServiceTemplate";
public static final String UNBOUNDED = "UNBOUNDED";
+ public static final String ST_METADATA_FILE_NAME = "filename";
+ public static final String ST_METADATA_TEMPLATE_NAME = "template_name";
//properties
public static final String SERVICE_TEMPLATE_FILTER_PROPERTY_NAME = "service_template_filter";
@@ -61,5 +60,12 @@ public class ToscaConstants {
public static final String DHCP_ENABLED_PROPERTY_NAME = "dhcp_enabled";
+ public static final String PORT_FIXED_IPS = "fixed_ips";
+ public static final String PORT_ALLOWED_ADDRESS_PAIRS = "allowed_address_pairs";
+ public static final String MAC_ADDRESS = "mac_address";
+
+ public static final String COMPUTE_IMAGE = "image";
+ public static final String COMPUTE_FLAVOR = "flavor";
+
}
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaNativeTypesServiceTemplate.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaNativeTypesServiceTemplate.java
deleted file mode 100644
index 013d761168..0000000000
--- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaNativeTypesServiceTemplate.java
+++ /dev/null
@@ -1,309 +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;
-
-import org.openecomp.sdc.tosca.datatypes.ToscaCapabilityType;
-import org.openecomp.sdc.tosca.datatypes.ToscaDataType;
-import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
-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.InterfaceDefinition;
-import org.openecomp.sdc.tosca.datatypes.model.NodeType;
-import org.openecomp.sdc.tosca.datatypes.model.PropertyDefinition;
-import org.openecomp.sdc.tosca.datatypes.model.PropertyType;
-import org.openecomp.sdc.tosca.datatypes.model.RequirementDefinition;
-import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * The type Tosca native types service template.
- */
-public class ToscaNativeTypesServiceTemplate {
- /**
- * Create service template service template.
- *
- * @return the service template
- */
- public static ServiceTemplate createServiceTemplate() {
- ServiceTemplate nativeNodeTypesServiceTemplate = new ServiceTemplate();
- nativeNodeTypesServiceTemplate
- .setTosca_definitions_version(ToscaConstants.TOSCA_DEFINITIONS_VERSION);
- nativeNodeTypesServiceTemplate.setMetadata(DataModelUtil
- .createMetadata(ToscaConstants.NATIVE_TYPES_SERVICE_TEMPLATE_NAME, "1.0.0", null));
- nativeNodeTypesServiceTemplate.setDescription("TOSCA Native Node Types");
- nativeNodeTypesServiceTemplate.setNode_types(createNativeNodeTypes());
- return nativeNodeTypesServiceTemplate;
- }
-
- private static Map<String, NodeType> createNativeNodeTypes() {
- Map<String, NodeType> nativeNodeTypes = new HashMap<>();
- nativeNodeTypes.put(ToscaNodeType.COMPUTE.getDisplayName(), createToscaNodesComputeNodeType());
- nativeNodeTypes.put(ToscaNodeType.ROOT.getDisplayName(), createToscaNodesRootNodeType());
- nativeNodeTypes
- .put(ToscaNodeType.NETWORK_PORT.getDisplayName(), createToscaNodesPortsNodeType());
- nativeNodeTypes
- .put(ToscaNodeType.BLOCK_STORAGE.getDisplayName(), createToscaNodesBlockStorageNodeType());
- nativeNodeTypes.put(ToscaNodeType.NETWORK.getDisplayName(), createToscaNodesNetworkNodeType());
- return nativeNodeTypes;
- }
-
- private static NodeType createToscaNodesComputeNodeType() {
- NodeType computeNodeType = new NodeType();
- computeNodeType.setDerived_from(ToscaNodeType.ROOT.getDisplayName());
- computeNodeType.setAttributes(createComputeAttributes());
- computeNodeType.setRequirements(createComputeRequirements());
- computeNodeType.setCapabilities(createComputeCapabilities());
- return computeNodeType;
- }
-
- private static NodeType createToscaNodesRootNodeType() {
- NodeType computeNodeType = new NodeType();
- computeNodeType.setAttributes(createRootAttributes());
- computeNodeType.setInterfaces(createRootInterfaces());
- return computeNodeType;
- }
-
- private static NodeType createToscaNodesPortsNodeType() {
- NodeType computeNodeType = new NodeType();
- computeNodeType.setDerived_from(ToscaNodeType.ROOT.getDisplayName());
- computeNodeType.setProperties(createToscaNodesPortProperties());
- computeNodeType.setRequirements(createToscaNodesPortRequirements());
- return computeNodeType;
- }
-
- private static NodeType createToscaNodesBlockStorageNodeType() {
- NodeType computeNodeType = new NodeType();
- computeNodeType.setDerived_from(ToscaNodeType.ROOT.getDisplayName());
- computeNodeType.setProperties(createToscaNodesBlockStorageProperties());
- computeNodeType.setCapabilities(createToscaNodesBlockStorageCapabilities());
- return computeNodeType;
- }
-
- private static NodeType createToscaNodesNetworkNodeType() {
- NodeType computeNodeType = new NodeType();
- computeNodeType.setDerived_from(ToscaNodeType.ROOT.getDisplayName());
- computeNodeType.setProperties(createToscaNodesNetworkProperties());
- computeNodeType.setCapabilities(createToscaNodesNetworkCapabilities());
- return computeNodeType;
- }
-
- private static Map<String, PropertyDefinition> createToscaNodesPortProperties() {
- Map<String, PropertyDefinition> propertyDefinitionMap = new HashMap<>();
- propertyDefinitionMap.put("ip_address", DataModelUtil
- .createPropertyDefinition(PropertyType.STRING.getDisplayName(), null, false, null, null,
- null, null));
- propertyDefinitionMap.put("order", DataModelUtil
- .createPropertyDefinition(PropertyType.INTEGER.getDisplayName(), null, true,
- DataModelUtil.getConstrainList(DataModelUtil.createGreaterOrEqualConstrain(0)), null,
- null, 0));
- propertyDefinitionMap.put("is_default", DataModelUtil
- .createPropertyDefinition(PropertyType.BOOLEAN.getDisplayName(), null, false, null, null,
- null, false));
- propertyDefinitionMap.put("ip_range_start", DataModelUtil
- .createPropertyDefinition(PropertyType.STRING.getDisplayName(), null, false, null, null,
- null, null));
- propertyDefinitionMap.put("ip_range_end", DataModelUtil
- .createPropertyDefinition(PropertyType.STRING.getDisplayName(), null, false, null, null,
- null, null));
- return propertyDefinitionMap;
- }
-
- private static Map<String, PropertyDefinition> createToscaNodesBlockStorageProperties() {
- Map<String, PropertyDefinition> propertyDefinitionMap = new HashMap<>();
- propertyDefinitionMap.put("size", DataModelUtil
- .createPropertyDefinition(PropertyType.SCALAR_UNIT_SIZE.getDisplayName(), null, false,
- DataModelUtil.getConstrainList(DataModelUtil.createGreaterOrEqualConstrain("1 MB")),
- null, null, null));
- propertyDefinitionMap.put("volume_id", DataModelUtil
- .createPropertyDefinition(PropertyType.STRING.getDisplayName(), null, false, null, null,
- null, null));
- propertyDefinitionMap.put("snapshot_id", DataModelUtil
- .createPropertyDefinition(PropertyType.STRING.getDisplayName(), null, false, null, null,
- null, null));
- return propertyDefinitionMap;
- }
-
- private static Map<String, PropertyDefinition> createToscaNodesNetworkProperties() {
- Map<String, PropertyDefinition> propertyDefinitionMap = new HashMap<>();
- propertyDefinitionMap.put("ip_version", DataModelUtil
- .createPropertyDefinition(PropertyType.INTEGER.getDisplayName(), null, false,
- DataModelUtil.getConstrainList(DataModelUtil.createValidValuesConstraint(4, 6)), null,
- null, 4));
- propertyDefinitionMap.put("cidr", DataModelUtil
- .createPropertyDefinition(PropertyType.STRING.getDisplayName(), null, false, null, null,
- null, null));
- propertyDefinitionMap.put("start_ip", DataModelUtil
- .createPropertyDefinition(PropertyType.STRING.getDisplayName(), null, false, null, null,
- null, null));
- propertyDefinitionMap.put("end_ip", DataModelUtil
- .createPropertyDefinition(PropertyType.STRING.getDisplayName(), null, false, null, null,
- null, null));
- propertyDefinitionMap.put("gateway_ip", DataModelUtil
- .createPropertyDefinition(PropertyType.STRING.getDisplayName(), null, false, null, null,
- null, null));
- propertyDefinitionMap.put("network_name", DataModelUtil
- .createPropertyDefinition(PropertyType.STRING.getDisplayName(), null, false, null, null,
- null, null));
- propertyDefinitionMap.put("network_id", DataModelUtil
- .createPropertyDefinition(PropertyType.STRING.getDisplayName(), null, false, null, null,
- null, null));
- propertyDefinitionMap.put("segmentation_id", DataModelUtil
- .createPropertyDefinition(PropertyType.STRING.getDisplayName(), null, false, null, null,
- null, null));
- propertyDefinitionMap.put("network_type", DataModelUtil
- .createPropertyDefinition(PropertyType.STRING.getDisplayName(), null, false, null, null,
- null, null));
- propertyDefinitionMap.put("physical_network", DataModelUtil
- .createPropertyDefinition(PropertyType.STRING.getDisplayName(), null, false, null, null,
- null, null));
- propertyDefinitionMap.put("dhcp_enabled", DataModelUtil
- .createPropertyDefinition(PropertyType.BOOLEAN.getDisplayName(), null, false, null, null,
- null, true));
-
- return propertyDefinitionMap;
- }
-
- private static Map<String, InterfaceDefinition> createRootInterfaces() {
- return new HashMap<>();
- }
-
- private static Map<String, CapabilityDefinition> createComputeCapabilities() {
- Map<String, CapabilityDefinition> computeCapabilities = new HashMap<>();
- computeCapabilities.put(ToscaConstants.HOST_CAPABILITY_ID,
- createCapabilityDefinition(ToscaCapabilityType.CONTAINER.getDisplayName(),
- createValidSourceTypes("tosca.nodes.SoftwareComponent")));
- computeCapabilities.put(ToscaConstants.ENDPOINT_CAPABILITY_ID,
- createCapabilityDefinition(ToscaCapabilityType.ENDPOINT_ADMIN.getDisplayName(), null));
- computeCapabilities.put(ToscaConstants.OS_CAPABILITY_ID,
- createCapabilityDefinition(ToscaCapabilityType.OPERATING_SYSTEM.getDisplayName(), null));
- computeCapabilities.put(ToscaConstants.SCALABLE_CAPABILITY_ID,
- createCapabilityDefinition(ToscaCapabilityType.SCALABLE.getDisplayName(), null));
- computeCapabilities.put(ToscaConstants.BINDING_CAPABILITY_ID,
- createCapabilityDefinition(ToscaCapabilityType.NETWORK_BINDABLE.getDisplayName(), null));
- return computeCapabilities;
- }
-
- private static Map<String, CapabilityDefinition> createToscaNodesBlockStorageCapabilities() {
- Map<String, CapabilityDefinition> computeCapabilities = new HashMap<>();
- computeCapabilities.put("attachment",
- createCapabilityDefinition(ToscaCapabilityType.ATTACHMENT.getDisplayName(), null));
- return computeCapabilities;
- }
-
- private static Map<String, CapabilityDefinition> createToscaNodesNetworkCapabilities() {
- Map<String, CapabilityDefinition> computeCapabilities = new HashMap<>();
- computeCapabilities.put(ToscaConstants.LINK_CAPABILITY_ID,
- createCapabilityDefinition(ToscaCapabilityType.NETWORK_LINKABLE.getDisplayName(), null));
- return computeCapabilities;
- }
-
- private static List<String> createValidSourceTypes(String... validSourceTypes) {
- return Arrays.asList(validSourceTypes);
- }
-
- private static CapabilityDefinition createCapabilityDefinition(String type,
- List<String> validSourceTypes) {
- CapabilityDefinition capabilityDefinition = new CapabilityDefinition();
- capabilityDefinition.setType(type);
- capabilityDefinition.setValid_source_types(validSourceTypes);
- return capabilityDefinition;
- }
-
- private static List<Map<String, RequirementDefinition>> createComputeRequirements() {
- List<Map<String, RequirementDefinition>> computeRequirementList = new ArrayList<>();
- Map<String, RequirementDefinition> localStorageRequirement = new HashMap<>();
- localStorageRequirement.put("local_storage", DataModelUtil
- .createRequirement(ToscaCapabilityType.ATTACHMENT.getDisplayName(),
- ToscaNodeType.BLOCK_STORAGE.getDisplayName(),
- ToscaRelationshipType.NATIVE_ATTACHES_TO.getDisplayName(),
- createOccurrences(0, ToscaConstants.UNBOUNDED)));
- computeRequirementList.add(localStorageRequirement);
- return computeRequirementList;
- }
-
- private static List<Map<String, RequirementDefinition>> createToscaNodesPortRequirements() {
- List<Map<String, RequirementDefinition>> requirements = new ArrayList<>();
-
- Map<String, RequirementDefinition> linkRequirement = new HashMap<>();
- linkRequirement.put(ToscaConstants.LINK_REQUIREMENT_ID, DataModelUtil
- .createRequirement(ToscaCapabilityType.NETWORK_LINKABLE.getDisplayName(),
- ToscaNodeType.ROOT.getDisplayName(),
- ToscaRelationshipType.NETWORK_LINK_TO.getDisplayName(), null));
- requirements.add(linkRequirement);
-
- Map<String, RequirementDefinition> bindingRequirement = new HashMap<>();
- bindingRequirement.put(ToscaConstants.BINDING_REQUIREMENT_ID, DataModelUtil
- .createRequirement(ToscaCapabilityType.NETWORK_BINDABLE.getDisplayName(),
- ToscaNodeType.ROOT.getDisplayName(),
- ToscaRelationshipType.NETWORK_BINDS_TO.getDisplayName(), null));
- requirements.add(bindingRequirement);
-
- return requirements;
- }
-
-
- private static Object[] createOccurrences(Object min, Object max) {
- return new Object[]{min, max};
-
- }
-
- private static Map<String, AttributeDefinition> createComputeAttributes() {
- Map<String, AttributeDefinition> computeAttributesDefMap = new HashMap<>();
- computeAttributesDefMap.put("private_address", DataModelUtil
- .createAttributeDefinition(PropertyType.STRING.getDisplayName(), "private address", null,
- null, null));
- computeAttributesDefMap.put("public_address", DataModelUtil
- .createAttributeDefinition(PropertyType.STRING.getDisplayName(), "public_address", null,
- null, null));
- computeAttributesDefMap.put("networks", DataModelUtil
- .createAttributeDefinition(PropertyType.MAP.getDisplayName(), "networks", null,
- DataModelUtil
- .createEntrySchema(ToscaDataType.NETWORK_NETWORK_INFO.getDisplayName(), null, null),
- null));
- computeAttributesDefMap.put("ports", DataModelUtil
- .createAttributeDefinition(PropertyType.MAP.getDisplayName(), "ports", null, DataModelUtil
- .createEntrySchema(ToscaDataType.NETWORK_PORT_INFO.getDisplayName(), null, null),
- null));
- return computeAttributesDefMap;
- }
-
- private static Map<String, AttributeDefinition> createRootAttributes() {
- Map<String, AttributeDefinition> attributesDefMap = new HashMap<>();
- attributesDefMap.put("tosca_id", DataModelUtil
- .createAttributeDefinition(PropertyType.STRING.getDisplayName(), "tosca id", null, null,
- null));
- attributesDefMap.put("tosca_name", DataModelUtil
- .createAttributeDefinition(PropertyType.STRING.getDisplayName(), "tosca name", null, null,
- null));
- attributesDefMap.put("state", DataModelUtil
- .createAttributeDefinition(PropertyType.STRING.getDisplayName(), "state", null, null,
- null));
- return attributesDefMap;
- }
-
-}
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaUtil.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaUtil.java
index 4f9c70267d..f3bf3280dc 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaUtil.java
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaUtil.java
@@ -20,18 +20,10 @@
package org.openecomp.sdc.tosca.services;
-import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
-import org.openecomp.sdc.tosca.datatypes.model.CapabilityDefinition;
-import org.openecomp.sdc.tosca.datatypes.model.CapabilityType;
-import org.openecomp.sdc.tosca.datatypes.model.NodeType;
import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate;
-import java.util.ArrayList;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
-import java.util.Objects;
-import java.util.Set;
import java.util.UUID;
/**
@@ -52,100 +44,40 @@ public class ToscaUtil {
if (serviceTemplate.getMetadata() == null) {
return UUID.randomUUID().toString() + "ServiceTemplate.yaml";
}
- return getServiceTemplateFileName(serviceTemplate.getMetadata().getTemplate_name());
+ return getServiceTemplateFileName(serviceTemplate.getMetadata());
}
/**
* Gets service template file name.
*
- * @param templateName the template name
+ * @param metaData the file name
* @return the service template file name
*/
- public static String getServiceTemplateFileName(String templateName) {
- return (Objects.isNull(templateName) ? UUID.randomUUID().toString() : templateName)
- + "ServiceTemplate.yaml";
- }
-
- /**
- * Add service template to map with key file name.
- *
- * @param serviceTemplates the service templates
- * @param commonServiceTemplate the common service template
- */
- public static void addServiceTemplateToMapWithKeyFileName(
- Map<String, ServiceTemplate> serviceTemplates, ServiceTemplate commonServiceTemplate) {
- serviceTemplates
- .put(ToscaUtil.getServiceTemplateFileName(commonServiceTemplate), commonServiceTemplate);
- }
-
- /**
- * Convert type to definition capability definition.
- *
- * @param type the type
- * @param capabilityType the capability type
- * @param properties the properties
- * @param description the description
- * @return the capability definition
- */
- public static CapabilityDefinition convertTypeToDefinition(String type,
- CapabilityType capabilityType,
- Map<String, Object> properties,
- String description) {
- CapabilityDefinition capabilityDefinition = new CapabilityDefinition();
- capabilityDefinition.setAttributes(capabilityType.getAttributes());
- capabilityDefinition.setProperties(capabilityType.getProperties());
- if (description == null) {
- capabilityDefinition.setDescription(capabilityType.getDescription());
- } else {
- capabilityDefinition.setDescription(description);
+ public static String getServiceTemplateFileName(Map<String, String> metadata) {
+ if (metadata.get(ToscaConstants.ST_METADATA_FILE_NAME) != null) {
+ return metadata.get(ToscaConstants.ST_METADATA_FILE_NAME);
+ } else if (metadata.get(ToscaConstants.ST_METADATA_TEMPLATE_NAME) != null) {
+ return metadata.get(ToscaConstants.ST_METADATA_TEMPLATE_NAME) + "ServiceTemplate.yaml";
}
- capabilityDefinition.setType(type);
-
- capabilityDefinition.getProperties()
- .entrySet()
- .stream()
- .filter(entry -> properties.containsKey(entry.getKey()))
- .forEach(entry -> entry.getValue()
- .set_default(properties.get(entry.getKey())));
-
-
- return capabilityDefinition;
+ return UUID.randomUUID().toString() + "ServiceTemplate.yaml";
}
+
/**
- * Normalize component name node type map.
+ * Add service template to map with key file name.
*
- * @param toscaModel the tosca model
- * @param components the components
- * @return the map
+ * @param serviceTemplateMap the service template map
+ * @param serviceTemplate the service template
*/
- public static Map<String, List<NodeType>> normalizeComponentNameNodeType(
- ToscaServiceModel toscaModel, Set<String> components) {
-
- Map<String, List<NodeType>> normalizedData = new HashMap<>();
- toscaModel
- .getServiceTemplates()
- .entrySet().stream().filter(entry -> entry
- .getValue()
- .getNode_types() != null)
- .forEach(entry -> entry
- .getValue()
- .getNode_types()
- .entrySet().stream()
- .filter(nodeTypeEntry -> components
- .contains(nodeTypeEntry
- .getKey()))
- .forEach(nodeTypeEntry -> addNodeType(nodeTypeEntry.getKey(), nodeTypeEntry.getValue(),
- normalizedData)));
- return normalizedData;
+ public static void addServiceTemplateToMapWithKeyFileName(
+ Map<String, ServiceTemplate> serviceTemplateMap, ServiceTemplate serviceTemplate) {
+ serviceTemplateMap.put(ToscaUtil.getServiceTemplateFileName(serviceTemplate), serviceTemplate);
}
- private static void addNodeType(String key, NodeType value,
- Map<String, List<NodeType>> normalizedData) {
- if (!normalizedData.containsKey(key)) {
- normalizedData.put(key, new ArrayList<>());
- }
- normalizedData.get(key).add(value);
+ public static String getServiceTemplateFileName(String templateName) {
+ Map<String, String> metadata = new HashMap<>();
+ metadata.put(ToscaConstants.ST_METADATA_TEMPLATE_NAME, templateName);
+ return getServiceTemplateFileName(metadata);
}
}
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 a11bff4b6a..eaf3fb492f 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
@@ -24,25 +24,37 @@ import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.openecomp.core.utilities.CommonMethods;
import org.openecomp.sdc.common.errors.CoreException;
-import org.openecomp.sdc.tosca.datatypes.ToscaCapabilityType;
+import org.openecomp.sdc.datatypes.error.ErrorLevel;
+import org.openecomp.sdc.logging.context.impl.MdcDataErrorMessage;
+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.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.CapabilityType;
import org.openecomp.sdc.tosca.datatypes.model.Import;
import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate;
import org.openecomp.sdc.tosca.datatypes.model.NodeType;
+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.ServiceTemplate;
import org.openecomp.sdc.tosca.errors.ToscaInvalidEntryNotFoundErrorBuilder;
import org.openecomp.sdc.tosca.errors.ToscaInvalidSubstituteNodeTemplatePropertiesErrorBuilder;
import org.openecomp.sdc.tosca.errors.ToscaInvalidSubstitutionServiceTemplateErrorBuilder;
import org.openecomp.sdc.tosca.errors.ToscaNodeTypeNotFoundErrorBuilder;
+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 java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -53,7 +65,7 @@ import java.util.Set;
public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
/*
- 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,
@@ -75,6 +87,19 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
}
@Override
+ public Optional<NodeType> fetchNodeType(String nodeTypeKey, Collection<ServiceTemplate>
+ serviceTemplates) {
+ Optional<Map<String, NodeType>> nodeTypeMap = serviceTemplates.stream()
+ .map(st -> st.getNode_types())
+ .filter(nodeTypes -> Objects.nonNull(nodeTypes) && nodeTypes.containsKey(nodeTypeKey))
+ .findFirst();
+ if (nodeTypeMap.isPresent()) {
+ return Optional.ofNullable(nodeTypeMap.get().get(nodeTypeKey));
+ }
+ return Optional.empty();
+ }
+
+ @Override
public boolean isTypeOf(NodeTemplate nodeTemplate, String nodeType,
ServiceTemplate serviceTemplate, ToscaServiceModel toscaServiceModel) {
if (nodeTemplate == null) {
@@ -92,88 +117,6 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
new ToscaNodeTypeNotFoundErrorBuilder(nodeTemplate.getType()).build()));
}
-
- private Optional<Boolean> isNodeTypeExistInServiceTemplateHierarchy(String nodeTypeToMatch,
- String nodeTypeToSearch,
- ServiceTemplate serviceTemplate,
- ToscaServiceModel toscaServiceModel,
- Set<String> analyzedImportFiles) {
- Map<String, NodeType> searchableNodeTypes = serviceTemplate.getNode_types();
- if (!MapUtils.isEmpty(searchableNodeTypes)) {
- NodeType nodeType = searchableNodeTypes.get(nodeTypeToSearch);
- if (Objects.nonNull(nodeType)) {
- if (Objects.equals(nodeType.getDerived_from(), nodeTypeToMatch)) {
- return Optional.of(true);
- } else if (isNodeTypeIsToscaRoot(nodeType)) {
- return Optional.of(false);
- } else {
- return isNodeTypeExistInServiceTemplateHierarchy(nodeTypeToMatch,
- nodeType.getDerived_from(), serviceTemplate, toscaServiceModel, null);
- }
- } else {
- return isNodeTypeExistInImports(nodeTypeToMatch, nodeTypeToSearch, serviceTemplate,
- toscaServiceModel, analyzedImportFiles);
- }
- }
- return isNodeTypeExistInImports(nodeTypeToMatch, nodeTypeToSearch, serviceTemplate,
- toscaServiceModel, analyzedImportFiles);
-
- }
-
- private Optional<Boolean> isNodeTypeExistInImports(String nodeTypeToMatch,
- String nodeTypeToSearch,
- ServiceTemplate serviceTemplate,
- ToscaServiceModel toscaServiceModel,
- Set<String> analyzedImportFiles) {
- Map<String, Import> imports = serviceTemplate.getImports();
- if (imports == null) {
- return Optional.empty();
- }
-
- analyzedImportFiles = createAnalyzedImportFilesSet(analyzedImportFiles);
- for (Import anImport : imports.values()) {
- if (Objects.isNull(anImport) || Objects.isNull(anImport.getFile())) {
- throw new RuntimeException("import without file entry");
- }
- String importFile = anImport.getFile();
- if (analyzedImportFiles.contains(importFile)) {
- continue;
- }
- addImportFileToAnalyzedImportFilesSet(analyzedImportFiles, importFile);
- ServiceTemplate template = toscaServiceModel.getServiceTemplates().get(importFile);
- Optional<Boolean> nodeTypeExistInServiceTemplateHierarchy =
- isNodeTypeExistInServiceTemplateHierarchy(nodeTypeToMatch, nodeTypeToSearch, template,
- toscaServiceModel, analyzedImportFiles);
- if (nodeTypeExistInServiceTemplateHierarchy.isPresent()) {
- if (nodeTypeExistInServiceTemplateHierarchy.get()) {
- return Optional.of(true);
- }
- }
- }
- return Optional.of(false);
- }
-
- private Set<String> addImportFileToAnalyzedImportFilesSet(Set<String> analyzedImportFiles,
- String importFile) {
- analyzedImportFiles.add(importFile);
- return analyzedImportFiles;
- }
-
- private Set<String> createAnalyzedImportFilesSet(Set<String> analyzedImportFiles) {
- if (Objects.isNull(analyzedImportFiles)) {
- analyzedImportFiles = new HashSet<>();
- }
- return analyzedImportFiles;
- }
-
- private boolean isNodeTypeIsToscaRoot(NodeType stNodeType) {
- return Objects.equals(stNodeType.getDerived_from(), ToscaNodeType.ROOT.getDisplayName());
- }
-
- private boolean isNodeTemplateOfTypeNodeType(NodeTemplate nodeTemplate, String nodeType) {
- return Objects.equals(nodeTemplate.getType(), nodeType);
- }
-
@Override
public List<RequirementAssignment> getRequirements(NodeTemplate nodeTemplate,
String requirementId) {
@@ -197,8 +140,8 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
String nodeTemplateId) {
if ((serviceTemplate.getTopology_template() != null)
&& (serviceTemplate.getTopology_template().getNode_templates() != null)
- && (serviceTemplate.getTopology_template().getNode_templates()
- .get(nodeTemplateId) != null)) {
+ && (serviceTemplate.getTopology_template().getNode_templates().get(nodeTemplateId)
+ != null)) {
return Optional
.of(serviceTemplate.getTopology_template().getNode_templates().get(nodeTemplateId));
}
@@ -214,13 +157,16 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
if (substitutableNodeTemplate.getProperties() != null
&& substitutableNodeTemplate.getProperties()
- .get(ToscaConstants.SERVICE_TEMPLATE_FILTER_PROPERTY_NAME) != null) {
+ .get(ToscaConstants.SERVICE_TEMPLATE_FILTER_PROPERTY_NAME) != null) {
Object serviceTemplateFilter = substitutableNodeTemplate.getProperties()
.get(ToscaConstants.SERVICE_TEMPLATE_FILTER_PROPERTY_NAME);
if (serviceTemplateFilter != null && serviceTemplateFilter instanceof Map) {
Object substituteServiceTemplate = ((Map) serviceTemplateFilter)
.get(ToscaConstants.SUBSTITUTE_SERVICE_TEMPLATE_PROPERTY_NAME);
if (substituteServiceTemplate == null) {
+ MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
+ LoggerTragetServiceName.ADD_ENTITIES_TO_TOSCA, ErrorLevel.ERROR.name(),
+ LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_PROPERTY);
throw new CoreException(
new ToscaInvalidSubstituteNodeTemplatePropertiesErrorBuilder(substituteNodeTemplateId)
.build());
@@ -228,6 +174,9 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
return Optional.of(substituteServiceTemplate.toString());
}
}
+ MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
+ LoggerTragetServiceName.ADD_ENTITIES_TO_TOSCA, ErrorLevel.ERROR.name(),
+ LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_PROPERTY);
throw new CoreException(
new ToscaInvalidSubstituteNodeTemplatePropertiesErrorBuilder(substituteNodeTemplateId)
.build());
@@ -255,28 +204,6 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
return substitutableNodeTemplates;
}
- private boolean isSubstitutableNodeTemplate(NodeTemplate nodeTemplate) {
- return nodeTemplate.getDirectives() != null
- && nodeTemplate.getDirectives().contains(ToscaConstants
- .NODE_TEMPLATE_DIRECTIVE_SUBSTITUTABLE);
- }
-
- private boolean isSubstitutionServiceTemplate(String substituteServiceTemplateFileName,
- ServiceTemplate substituteServiceTemplate) {
- if (substituteServiceTemplate != null
- && substituteServiceTemplate.getTopology_template() != null
- && substituteServiceTemplate.getTopology_template().getSubstitution_mappings() != null) {
- if (substituteServiceTemplate.getTopology_template().getSubstitution_mappings()
- .getNode_type() == null) {
- throw new CoreException(new ToscaInvalidSubstitutionServiceTemplateErrorBuilder(
- substituteServiceTemplateFileName).build());
- }
- return true;
- }
- return false;
-
- }
-
@Override
public Optional<Map.Entry<String, NodeTemplate>> getSubstitutionMappedNodeTemplateByExposedReq(
String substituteServiceTemplateFileName, ServiceTemplate substituteServiceTemplate,
@@ -319,7 +246,6 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
return Optional.empty();
}
-
/*
match only for the input which is not null
*/
@@ -361,62 +287,245 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
case CAPABILITY_TYPE:
returnEntity = new CapabilityType();
break;
+ case NODE_TYPE:
+ returnEntity = new NodeType();
+ break;
default:
+ MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
+ LoggerTragetServiceName.ADD_ENTITIES_TO_TOSCA, ErrorLevel.ERROR.name(),
+ LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.UNSUPPORTED_ENTITY);
throw new RuntimeException(
"Entity[" + elementType + "] id[" + typeId + "] flat not supported");
}
- scanAnFlatEntity(elementType, typeId, returnEntity, serviceTemplate, toscaModel);
+ scanAnFlatEntity(elementType, typeId, returnEntity, serviceTemplate, toscaModel,
+ new ArrayList<String>(), 0);
return returnEntity;
}
- private void scanAnFlatEntity(ToscaElementTypes elementType, String typeId, Object entity,
- ServiceTemplate serviceTemplate, ToscaServiceModel toscaModel) {
+ @Override
+ public boolean isSubstitutableNodeTemplate(NodeTemplate nodeTemplate) {
+ return nodeTemplate.getDirectives() != null
+ && nodeTemplate.getDirectives().contains(ToscaConstants
+ .NODE_TEMPLATE_DIRECTIVE_SUBSTITUTABLE);
+ }
+
+ private Optional<Boolean> isNodeTypeExistInServiceTemplateHierarchy(
+ String nodeTypeToMatch,
+ String nodeTypeToSearch,
+ ServiceTemplate serviceTemplate,
+ ToscaServiceModel toscaServiceModel,
+ Set<String> analyzedImportFiles) {
+ Map<String, NodeType> searchableNodeTypes = serviceTemplate.getNode_types();
+ if (!MapUtils.isEmpty(searchableNodeTypes)) {
+ NodeType nodeType = searchableNodeTypes.get(nodeTypeToSearch);
+ if (Objects.nonNull(nodeType)) {
+ if (Objects.equals(nodeType.getDerived_from(), nodeTypeToMatch)) {
+ return Optional.of(true);
+ } else if (isNodeTypeIsToscaRoot(nodeType)) {
+ return Optional.of(false);
+ } else {
+ return isNodeTypeExistInServiceTemplateHierarchy(nodeTypeToMatch,
+ nodeType.getDerived_from(), serviceTemplate, toscaServiceModel, null);
+ }
+ } else {
+ return isNodeTypeExistInImports(nodeTypeToMatch, nodeTypeToSearch, serviceTemplate,
+ toscaServiceModel, analyzedImportFiles);
+ }
+ }
+ return isNodeTypeExistInImports(nodeTypeToMatch, nodeTypeToSearch, serviceTemplate,
+ toscaServiceModel, analyzedImportFiles);
+
+ }
+
+ private Optional<Boolean> isNodeTypeExistInImports(String nodeTypeToMatch,
+ String nodeTypeToSearch,
+ ServiceTemplate serviceTemplate,
+ ToscaServiceModel toscaServiceModel,
+ Set<String> filesScanned) {
+ List<Map<String, Import>> imports = serviceTemplate.getImports();
+ if (CollectionUtils.isEmpty(imports)) {
+ return Optional.empty();
+ }
+
+ filesScanned = createFilesScannedSet(filesScanned);
+
+ for (Map<String, Import> map : imports) {
+ ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
+ Import anImport = toscaExtensionYamlUtil
+ .yamlToObject(toscaExtensionYamlUtil.objectToYaml(map.values().iterator().next()),
+ Import.class);
+ if (Objects.isNull(anImport) || Objects.isNull(anImport.getFile())) {
+ throw new RuntimeException("import without file entry");
+ }
+ String importFile = anImport.getFile();
+ ServiceTemplate template =
+ toscaServiceModel.getServiceTemplates().get(fetchFileNameForImport(importFile,
+ serviceTemplate.getMetadata() == null ? null
+ : serviceTemplate.getMetadata().get("filename")));
+ if (filesScanned.contains(ToscaUtil.getServiceTemplateFileName(template))) {
+ continue;
+ } else {
+ filesScanned.add(ToscaUtil.getServiceTemplateFileName(template));
+ }
+ Optional<Boolean> nodeTypeExistInServiceTemplateHierarchy =
+ isNodeTypeExistInServiceTemplateHierarchy(nodeTypeToMatch, nodeTypeToSearch, template,
+ toscaServiceModel, filesScanned);
+ if (nodeTypeExistInServiceTemplateHierarchy.isPresent()) {
+ if (nodeTypeExistInServiceTemplateHierarchy.get()) {
+ filesScanned.clear();
+ return Optional.of(true);
+ }
+ }
+
+ }
+ return Optional.of(false);
+ }
+
+ private Set<String> addImportFileToAnalyzedImportFilesSet(Set<String> analyzedImportFiles,
+ String importFile) {
+ analyzedImportFiles.add(importFile);
+ return analyzedImportFiles;
+ }
+
+ private Set<String> createFilesScannedSet(Set<String> filesScanned) {
+ if (Objects.isNull(filesScanned)) {
+ filesScanned = new HashSet<>();
+ }
+ return filesScanned;
+ }
+
+ private boolean isNodeTypeIsToscaRoot(NodeType stNodeType) {
+ return Objects.equals(stNodeType.getDerived_from(), ToscaNodeType.NATIVE_ROOT);
+ }
+
+ private boolean isNodeTemplateOfTypeNodeType(NodeTemplate nodeTemplate, String nodeType) {
+ return Objects.equals(nodeTemplate.getType(), nodeType);
+ }
+
+ private boolean isSubstitutionServiceTemplate(String substituteServiceTemplateFileName,
+ ServiceTemplate substituteServiceTemplate) {
+ if (substituteServiceTemplate != null
+ && substituteServiceTemplate.getTopology_template() != null
+ && substituteServiceTemplate.getTopology_template().getSubstitution_mappings() != null) {
+ if (substituteServiceTemplate.getTopology_template().getSubstitution_mappings()
+ .getNode_type() == null) {
+ throw new CoreException(new ToscaInvalidSubstitutionServiceTemplateErrorBuilder(
+ substituteServiceTemplateFileName).build());
+ }
+ return true;
+ }
+ return false;
+
+ }
+
+ private boolean scanAnFlatEntity(ToscaElementTypes elementType, String typeId, Object entity,
+ ServiceTemplate serviceTemplate, ToscaServiceModel toscaModel,
+ List<String> filesScanned, int rootScanStartInx) {
boolean entityFound =
enrichEntityFromCurrentServiceTemplate(elementType, typeId, entity, serviceTemplate,
- toscaModel);
+ toscaModel, filesScanned, rootScanStartInx);
if (!entityFound) {
- Map<String, Import> imports = serviceTemplate.getImports();
- if (MapUtils.isEmpty(imports)) {
- return;
+ List<Map<String, Import>> imports = serviceTemplate.getImports();
+ if (CollectionUtils.isEmpty(imports)) {
+ return false;
}
- for (Import importServiceTemplate : imports.values()) {
- ServiceTemplate template =
- toscaModel.getServiceTemplates().get(importServiceTemplate.getFile());
- scanAnFlatEntity(elementType, typeId, entity, template, toscaModel);
+ ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
+ boolean found = false;
+ for (Map<String, Import> importMap : imports) {
+ if (found) {
+ return true;
+ }
+ String filename = "";
+ for (Object importObject : importMap.values()) {
+ Import importServiceTemplate = toscaExtensionYamlUtil
+ .yamlToObject(toscaExtensionYamlUtil.objectToYaml(importObject), Import.class);
+ filename = fetchFileNameForImport(importServiceTemplate.getFile(),
+ serviceTemplate.getMetadata() == null ? null : serviceTemplate.getMetadata().get
+ ("filename"));
+ if (filesScanned.contains(filename)) {
+ return false;
+ } else {
+ filesScanned.add(filename);
+ }
+ ServiceTemplate template =
+ toscaModel.getServiceTemplates()
+ .get(filename);
+ found =
+ scanAnFlatEntity(elementType, typeId, entity, template, toscaModel, filesScanned,
+ filesScanned.size());
+ }
}
+ return found;
}
+ return true;
+ }
+ private String fetchFileNameForImport(String importServiceTemplateFile,
+ String currentMetadatafileName) {
+ if (importServiceTemplateFile.contains("../")) {
+ return importServiceTemplateFile.replace("../", "");
+ } else if (importServiceTemplateFile.contains("/")) {
+ return importServiceTemplateFile;
+ } else if (currentMetadatafileName != null) {
+ return currentMetadatafileName.substring(0, currentMetadatafileName.indexOf("/")) + "/" +
+ importServiceTemplateFile;
+ } else {
+ return importServiceTemplateFile;
+ }
}
private boolean enrichEntityFromCurrentServiceTemplate(ToscaElementTypes elementType,
String typeId, Object entity,
ServiceTemplate serviceTemplate,
- ToscaServiceModel toscaModel) {
+ ToscaServiceModel toscaModel,
+ List<String> filesScanned,
+ int rootScanStartInx) {
String derivedFrom;
switch (elementType) {
case CAPABILITY_TYPE:
if (serviceTemplate.getCapability_types() != null
&& serviceTemplate.getCapability_types().containsKey(typeId)) {
+ filesScanned.clear();
CapabilityType targetCapabilityType = ((CapabilityType) entity);
CapabilityType sourceCapabilityType = serviceTemplate.getCapability_types().get(typeId);
derivedFrom = sourceCapabilityType.getDerived_from();
- if (derivedFrom != null
- && !ToscaCapabilityType.NFV_METRIC.getDisplayName().equals(derivedFrom)) {
- scanAnFlatEntity(elementType, derivedFrom, entity, serviceTemplate, toscaModel);
+ if (derivedFrom != null) {
+ scanAnFlatEntity(elementType, derivedFrom, entity, serviceTemplate, toscaModel,
+ filesScanned, rootScanStartInx);
}
combineCapabilityTypeInfo(sourceCapabilityType, targetCapabilityType);
} else {
return false;
}
break;
+ case NODE_TYPE:
+ if (serviceTemplate.getNode_types() != null
+ && serviceTemplate.getNode_types().containsKey(typeId)) {
+
+ filesScanned.clear();
+ NodeType targetNodeType = ((NodeType) entity);
+ NodeType sourceNodeType = serviceTemplate.getNode_types().get(typeId);
+ derivedFrom = sourceNodeType.getDerived_from();
+ if (derivedFrom != null) {
+ scanAnFlatEntity(elementType, derivedFrom, entity, serviceTemplate, toscaModel,
+ filesScanned, rootScanStartInx);
+ }
+ combineNodeTypeInfo(sourceNodeType, targetNodeType);
+ } else {
+ return false;
+ }
+ break;
default:
+ MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
+ LoggerTragetServiceName.ADD_ENTITIES_TO_TOSCA, ErrorLevel.ERROR.name(),
+ LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.UNSUPPORTED_ENTITY);
throw new RuntimeException(
"Entity[" + elementType + "] id[" + typeId + "] flat not supported");
}
@@ -426,37 +535,44 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
}
+ private void combineNodeTypeInfo(NodeType sourceNodeType, NodeType targetNodeType) {
+ targetNodeType.setDerived_from(sourceNodeType.getDerived_from());
+ targetNodeType.setDescription(sourceNodeType.getDescription());
+ targetNodeType.setVersion(sourceNodeType.getVersion());
+ targetNodeType.setProperties(
+ CommonMethods.mergeMaps(targetNodeType.getProperties(), sourceNodeType.getProperties()));
+ targetNodeType.setInterfaces(
+ CommonMethods.mergeMaps(targetNodeType.getInterfaces(), sourceNodeType.getInterfaces()));
+ targetNodeType.setArtifacts(
+ CommonMethods.mergeMaps(targetNodeType.getArtifacts(), sourceNodeType.getArtifacts()));
+ targetNodeType.setAttributes(
+ CommonMethods.mergeMaps(targetNodeType.getAttributes(), sourceNodeType.getAttributes()));
+ targetNodeType.setCapabilities(CommonMethods
+ .mergeMaps(targetNodeType.getCapabilities(), sourceNodeType.getCapabilities()));
+ targetNodeType.setRequirements(CommonMethods
+ .mergeListsOfMap(targetNodeType.getRequirements(), sourceNodeType.getRequirements()));
+
+ }
+
+
private void combineCapabilityTypeInfo(CapabilityType sourceCapabilityType,
CapabilityType targetCapabilityType) {
- if (MapUtils.isNotEmpty(sourceCapabilityType.getAttributes())) {
- if (targetCapabilityType.getAttributes() == null) {
- targetCapabilityType.setAttributes(new HashMap<>());
- }
- targetCapabilityType.getAttributes().putAll(sourceCapabilityType.getAttributes());
- }
- if (MapUtils.isNotEmpty(sourceCapabilityType.getProperties())) {
- if (targetCapabilityType.getProperties() == null) {
- targetCapabilityType.setProperties(new HashMap<>());
- }
- targetCapabilityType.getProperties().putAll(sourceCapabilityType.getProperties());
- }
+ targetCapabilityType.setAttributes(CommonMethods
+ .mergeMaps(targetCapabilityType.getAttributes(), sourceCapabilityType.getAttributes()));
+ targetCapabilityType.setProperties(CommonMethods
+ .mergeMaps(targetCapabilityType.getProperties(), sourceCapabilityType.getProperties()));
+ targetCapabilityType.setValid_source_types(CommonMethods
+ .mergeLists(targetCapabilityType.getValid_source_types(),
+ sourceCapabilityType.getValid_source_types()));
- if (CollectionUtils.isNotEmpty(sourceCapabilityType.getValid_source_types())) {
- if (targetCapabilityType.getValid_source_types() == null) {
- targetCapabilityType.setValid_source_types(new ArrayList<>());
- }
- targetCapabilityType.getValid_source_types()
- .addAll(sourceCapabilityType.getValid_source_types());
- }
-
- if (CommonMethods.isEmpty(sourceCapabilityType.getDerived_from())) {
+ if (!CommonMethods.isEmpty(sourceCapabilityType.getDerived_from())) {
targetCapabilityType.setDerived_from(sourceCapabilityType.getDerived_from());
}
- if (CommonMethods.isEmpty(sourceCapabilityType.getDescription())) {
+ if (!CommonMethods.isEmpty(sourceCapabilityType.getDescription())) {
targetCapabilityType.setDescription(sourceCapabilityType.getDescription());
}
- if (CommonMethods.isEmpty(sourceCapabilityType.getVersion())) {
+ if (!CommonMethods.isEmpty(sourceCapabilityType.getVersion())) {
targetCapabilityType.setVersion(sourceCapabilityType.getVersion());
}
@@ -464,4 +580,121 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
}
+ /*
+ * Create node type according to the input substitution service template, while the substitution
+ * service template can be mappted to this node type, for substitution mapping.
+ *
+ * @param substitutionServiceTemplate substitution serivce template
+ * @param nodeTypeDerivedFromValue derived from value for the created node type
+ * @return the node type
+ */
+ @Override
+ public NodeType createInitSubstitutionNodeType(ServiceTemplate substitutionServiceTemplate,
+ String nodeTypeDerivedFromValue) {
+ NodeType substitutionNodeType = new NodeType();
+ substitutionNodeType.setDerived_from(nodeTypeDerivedFromValue);
+ substitutionNodeType.setDescription(substitutionServiceTemplate.getDescription());
+ substitutionNodeType
+ .setProperties(manageSubstitutionNodeTypeProperties(substitutionServiceTemplate));
+ substitutionNodeType
+ .setAttributes(manageSubstitutionNodeTypeAttributes(substitutionServiceTemplate));
+ return substitutionNodeType;
+ }
+
+ public Map<String, PropertyDefinition> manageSubstitutionNodeTypeProperties(
+ ServiceTemplate substitutionServiceTemplate) {
+ Map<String, PropertyDefinition> substitutionNodeTypeProperties = new HashMap<>();
+ Map<String, ParameterDefinition> properties =
+ substitutionServiceTemplate.getTopology_template().getInputs();
+ if (properties == null) {
+ return null;
+ }
+
+ PropertyDefinition propertyDefinition;
+ String toscaPropertyName;
+ for (Map.Entry<String, ParameterDefinition> entry : properties.entrySet()) {
+ toscaPropertyName = entry.getKey();
+ propertyDefinition = new PropertyDefinition();
+ ParameterDefinition parameterDefinition =
+ substitutionServiceTemplate.getTopology_template().getInputs().get(toscaPropertyName);
+ propertyDefinition.setType(parameterDefinition.getType());
+ propertyDefinition.setDescription(parameterDefinition.getDescription());
+ propertyDefinition.set_default(parameterDefinition.get_default());
+ if (parameterDefinition.getRequired() != null) {
+ propertyDefinition.setRequired(parameterDefinition.getRequired());
+ }
+ if (propertyDefinition.get_default() != null) {
+ propertyDefinition.setRequired(false);
+ }
+ if (!CollectionUtils.isEmpty(parameterDefinition.getConstraints())) {
+ propertyDefinition.setConstraints(parameterDefinition.getConstraints());
+ }
+ propertyDefinition.setEntry_schema(parameterDefinition.getEntry_schema());
+ if (parameterDefinition.getStatus() != null) {
+ propertyDefinition.setStatus(parameterDefinition.getStatus());
+ }
+ substitutionNodeTypeProperties.put(toscaPropertyName, propertyDefinition);
+ }
+ return substitutionNodeTypeProperties;
+ }
+
+ private Map<String, AttributeDefinition> manageSubstitutionNodeTypeAttributes(
+ ServiceTemplate substitutionServiceTemplate) {
+ Map<String, AttributeDefinition> substitutionNodeTypeAttributes = new HashMap<>();
+ Map<String, ParameterDefinition> attributes =
+ substitutionServiceTemplate.getTopology_template().getOutputs();
+ if (attributes == null) {
+ return null;
+ }
+ AttributeDefinition attributeDefinition;
+ String toscaAttributeName;
+
+ for (Map.Entry<String, ParameterDefinition> entry : attributes.entrySet()) {
+ attributeDefinition = new AttributeDefinition();
+ toscaAttributeName = entry.getKey();
+ ParameterDefinition parameterDefinition =
+ substitutionServiceTemplate.getTopology_template().getOutputs().get(toscaAttributeName);
+ if (parameterDefinition.getType() != null && !parameterDefinition.getType().isEmpty()) {
+ attributeDefinition.setType(parameterDefinition.getType());
+ } else {
+ attributeDefinition.setType(PropertyType.STRING.getDisplayName());
+ }
+ attributeDefinition.setDescription(parameterDefinition.getDescription());
+ attributeDefinition.set_default(parameterDefinition.get_default());
+ attributeDefinition.setEntry_schema(parameterDefinition.getEntry_schema());
+ if (Objects.nonNull(parameterDefinition.getStatus())) {
+ attributeDefinition.setStatus(parameterDefinition.getStatus());
+ }
+ substitutionNodeTypeAttributes.put(toscaAttributeName, attributeDefinition);
+ }
+ return substitutionNodeTypeAttributes;
+ }
+
+ /**
+ * Checks if the requirement exists in the node template.
+ *
+ * @param nodeTemplate the node template
+ * @param requirementId the requirement id
+ * @param requirementAssignment the requirement assignment
+ * @return true if the requirement already exists and false otherwise
+ */
+ public boolean isRequirementExistInNodeTemplate(NodeTemplate nodeTemplate,
+ String requirementId,
+ RequirementAssignment requirementAssignment) {
+ boolean result = false;
+ List<Map<String, RequirementAssignment>> nodeTemplateRequirements = nodeTemplate
+ .getRequirements();
+ if (nodeTemplateRequirements != null) {
+ for (Map<String, RequirementAssignment> requirement : nodeTemplateRequirements) {
+ if (requirement.containsKey(requirementId)) {
+ result = DataModelUtil.compareRequirementAssignment(requirementAssignment,
+ requirement.get(requirementId));
+ if (result) {
+ break;
+ }
+ }
+ }
+ }
+ return result;
+ }
}
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaFileOutputServiceCsarImpl.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaFileOutputServiceCsarImpl.java
index d4c22f105f..b518057e35 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaFileOutputServiceCsarImpl.java
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaFileOutputServiceCsarImpl.java
@@ -23,6 +23,12 @@ package org.openecomp.sdc.tosca.services.impl;
import org.openecomp.core.utilities.file.FileContentHandler;
import org.openecomp.core.utilities.file.FileUtils;
import org.openecomp.sdc.common.errors.CoreException;
+import org.openecomp.sdc.datatypes.error.ErrorLevel;
+import org.openecomp.sdc.logging.context.impl.MdcDataErrorMessage;
+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.ToscaServiceModel;
import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate;
import org.openecomp.sdc.tosca.exceptions.CsarCreationErrorBuilder;
@@ -39,6 +45,7 @@ import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
+
public class ToscaFileOutputServiceCsarImpl implements ToscaFileOutputService {
static final String EXTERNAL_ARTIFACTS_FOLDER_NAME = "Artifacts";
private static final String DEFINITIONS_FOLDER_NAME = "Definitions";
@@ -57,6 +64,7 @@ public class ToscaFileOutputServiceCsarImpl implements ToscaFileOutputService {
private static final String SPACE = " ";
private static final String FILE_SEPARATOR = File.separator;
+
@Override
public byte[] createOutputFile(ToscaServiceModel toscaServiceModel,
FileContentHandler externalArtifacts) {
@@ -68,18 +76,25 @@ public class ToscaFileOutputServiceCsarImpl implements ToscaFileOutputService {
packArtifacts(zos, artifactFiles);
}
if (toscaServiceModel.getEntryDefinitionServiceTemplate() == null) {
+ MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
+ LoggerTragetServiceName.CREATE_CSAR, ErrorLevel.ERROR.name(),
+ LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.CREATE_CSAR);
throw new CoreException(new CsarMissingEntryPointErrorBuilder().build());
}
createAndPackToscaMetaFile(zos, toscaServiceModel.getEntryDefinitionServiceTemplate());
if (externalArtifacts != null) {
packExternalArtifacts(zos, externalArtifacts);
}
- } catch (IOException exc) {
- throw new CoreException(new CsarCreationErrorBuilder().build(), exc);
+ } catch (IOException ex) {
+ MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
+ LoggerTragetServiceName.CREATE_CSAR, ErrorLevel.ERROR.name(),
+ LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.CREATE_CSAR);
+ throw new CoreException(new CsarCreationErrorBuilder().build(), ex);
}
return baos.toByteArray();
}
+
@Override
public String createMetaFile(String entryDefinitionsFileName) {
return TOSCA_META_FILE_VERSION + META_FILE_DELIMITER + SPACE + TOSCA_META_FILE_VERSION_VALUE
@@ -87,7 +102,8 @@ public class ToscaFileOutputServiceCsarImpl implements ToscaFileOutputService {
+ CSAR_VERSION + META_FILE_DELIMITER + SPACE + CSAR_VERSION_VALUE + System.lineSeparator()
+ CREATED_BY + META_FILE_DELIMITER + SPACE + CREATED_BY_VALUE + System.lineSeparator()
+ ENTRY_DEFINITIONS + META_FILE_DELIMITER + SPACE + DEFINITIONS_FOLDER_NAME
- + FILE_SEPARATOR + entryDefinitionsFileName;
+ + FILE_SEPARATOR
+ + entryDefinitionsFileName;
}
@Override
@@ -120,8 +136,11 @@ public class ToscaFileOutputServiceCsarImpl implements ToscaFileOutputService {
zos.putNextEntry(new ZipEntry(filenameIncludingPath));
writeBytesToZip(zos, externalArtifacts.getFileContent(filenameIncludingPath));
- } catch (IOException exc) {
- throw new RuntimeException(exc);
+ } catch (IOException ex) {
+ MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
+ LoggerTragetServiceName.PACK_ARTIFACTS, ErrorLevel.ERROR.name(),
+ LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.PACK_ARTIFACTS);
+ throw new RuntimeException(ex);
} finally {
try {
zos.closeEntry();
@@ -140,8 +159,11 @@ public class ToscaFileOutputServiceCsarImpl implements ToscaFileOutputService {
zos.putNextEntry(new ZipEntry((ARTIFACTS_FOLDER_NAME + FILE_SEPARATOR + fileName)));
writeBytesToZip(zos, artifacts.getFileContent(fileName));
- } catch (IOException exc) {
- throw new RuntimeException(exc);
+ } catch (IOException ex) {
+ MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
+ LoggerTragetServiceName.PACK_ARTIFACTS, ErrorLevel.ERROR.name(),
+ LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.PACK_ARTIFACTS);
+ throw new RuntimeException(ex);
} finally {
try {
zos.closeEntry();
@@ -150,6 +172,7 @@ public class ToscaFileOutputServiceCsarImpl implements ToscaFileOutputService {
}
}
}
+
}
private void writeBytesToZip(ZipOutputStream zos, InputStream is) throws IOException {
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
index a1c11c2483..2b806fbea0 100644
--- 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
@@ -46,13 +46,13 @@ public class ToscaExtensionYamlUtil extends YamlUtil {
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");
+ 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 exception) {
- throw new RuntimeException(exception);
+ } catch (ClassNotFoundException ex) {
+ throw new RuntimeException(ex);
}
return super.getProperty(type, name);
}
@@ -80,9 +80,8 @@ public class ToscaExtensionYamlUtil extends YamlUtil {
// create JavaBean
return super.constructJavaBean2ndStep(node, object);
}
- } catch (ClassNotFoundException | InstantiationException
- | IllegalAccessException exception) {
- throw new RuntimeException(exception);
+ } catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) {
+ throw new RuntimeException(ex);
}
}
}