aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/to/ContrailServiceInstanceTo.java58
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/HeatToToscaLogConstants.java85
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/UnifiedCompositionService.java10
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationContrailAttachPolicyImpl.java195
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationContrailNetworkPolicyImpl.java47
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationContrailServiceInstanceImpl.java1191
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationContrailServiceTemplateImpl.java141
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationContrailV2NetworkPolicyImpl.java44
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationContrailV2VirtualNetworkImpl.java313
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationContrailV2VlanSubInterfaceImpl.java155
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationContrailV2VmInterfaceImpl.java144
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationNestedImpl.java384
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationNeutronPortImpl.java392
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/DataModelUtil.java2759
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaConstants.java1
15 files changed, 2985 insertions, 2934 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/to/ContrailServiceInstanceTo.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/to/ContrailServiceInstanceTo.java
new file mode 100644
index 0000000000..99b3f502b4
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/to/ContrailServiceInstanceTo.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
+ * 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.
+ */
+
+package org.openecomp.sdc.translator.datatypes.heattotosca.to;
+
+import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
+import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
+
+public class ContrailServiceInstanceTo {
+ private final ServiceTemplate nestedSubstitutionServiceTemplate;
+ private final NodeTemplate substitutedNodeTemplate;
+ private final String heatStackGroupKey;
+ private final boolean orderedInterfaces;
+ private final String computeNodeTemplateId;
+
+ public ContrailServiceInstanceTo(ServiceTemplate nestedSubstitutionServiceTemplate,
+ NodeTemplate substitutedNodeTemplate, String heatStackGroupKey,
+ boolean orderedInterfaces, String computeNodeTemplateId) {
+ this.nestedSubstitutionServiceTemplate = nestedSubstitutionServiceTemplate;
+ this.substitutedNodeTemplate = substitutedNodeTemplate;
+ this.heatStackGroupKey = heatStackGroupKey;
+ this.orderedInterfaces = orderedInterfaces;
+ this.computeNodeTemplateId = computeNodeTemplateId;
+ }
+
+ public ServiceTemplate getNestedSubstitutionServiceTemplate() {
+ return nestedSubstitutionServiceTemplate;
+ }
+
+ public NodeTemplate getSubstitutedNodeTemplate() {
+ return substitutedNodeTemplate;
+ }
+
+ public String getHeatStackGroupKey() {
+ return heatStackGroupKey;
+ }
+
+ public boolean isOrderedInterfaces() {
+ return orderedInterfaces;
+ }
+
+ public String getComputeNodeTemplateId() {
+ return computeNodeTemplateId;
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/HeatToToscaLogConstants.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/HeatToToscaLogConstants.java
new file mode 100644
index 0000000000..15c9ccd401
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/HeatToToscaLogConstants.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
+ * 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.
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca;
+
+public class HeatToToscaLogConstants {
+ private static final String LOG_HEAT_RESOURCE_TYPE_PREFIX = "Heat resource: '{}' with type: '{}' ";
+ private static final String LOG_UNSUPPORTED_HEAT_RESOURCE_SUFFIX =
+ "therefore this resource will be ignored in TOSCA translation.";
+ private static final String LOG_UNSUPPORTED_RESOURCE_CONNECTION_SUFFIX =
+ "therefore this connection will be ignored in TOSCA translation.";
+ private static final String LOG_UNSUPPORTED_PROPERTY_SUFFIX =
+ "therefore this property will be ignored in TOSCA translation.";
+
+ //Contrail Attach Policy messages
+ public static final String LOG_UNSUPPORTED_POLICY_PROPERTY_GET_ATTR = LOG_HEAT_RESOURCE_TYPE_PREFIX
+ + "include 'policy' property without 'get_attr' of 'fq_name'/'get_resource' function, "
+ + LOG_UNSUPPORTED_HEAT_RESOURCE_SUFFIX;
+ public static final String LOG_UNSUPPORTED_POLICY_RESOURCE = LOG_HEAT_RESOURCE_TYPE_PREFIX
+ + "include unsupported policy resource, " + LOG_UNSUPPORTED_HEAT_RESOURCE_SUFFIX;
+ public static final String LOG_UNSUPPORTED_POLICY_NETWORK_PROPERTY = LOG_HEAT_RESOURCE_TYPE_PREFIX
+ + "include 'network' property without 'get_resource' function, " + LOG_UNSUPPORTED_HEAT_RESOURCE_SUFFIX;
+
+ //Service Instance messages
+ public static final String LOG_SERVICE_TEMPLATE_PROPERTY_GET_RESOURCE = LOG_HEAT_RESOURCE_TYPE_PREFIX
+ + "include 'service_template' property without 'get_resource' function, currently not supported, "
+ + LOG_UNSUPPORTED_HEAT_RESOURCE_SUFFIX;
+ public static final String LOG_SERVICE_TEMPLATE_PROPERTY_INVALID_TYPE =
+ "Resource id '{}' with type '{} has reference to resource '{}' with type '{}' in property service_template"
+ + ". Invalid type, resource type should be type of '{}', " + LOG_UNSUPPORTED_HEAT_RESOURCE_SUFFIX;
+ public static final String LOG_SERVICE_TEMPLATE_PROPERTY_UNSUPPORTED_RESOURCE =
+ "Resource id '{}' with type '{}' has reference to unsupported resource '{}' with type '{}' in"
+ + " property 'service_template', " + LOG_UNSUPPORTED_HEAT_RESOURCE_SUFFIX;
+ public static final String LOG_MULTIPLE_SERVICE_INSTANCE_DIFF_INTERFACES =
+ "More than one ServiceInstance pointing to the same ServiceTemplate '{} ' with different number of "
+ + "interfaces., " + LOG_UNSUPPORTED_HEAT_RESOURCE_SUFFIX;
+ public static final String LOG_MISSING_VIRTUAL_NETWORK_INTERFACE_LIST = LOG_HEAT_RESOURCE_TYPE_PREFIX
+ + "missing 'virtual_network' property in 'interface_list' entry, therefore, no network connection is "
+ + "define for this entry.";
+ public static final String LOG_UNSUPPORTED_NETWORK_RESOURCE_CONNECTION = LOG_HEAT_RESOURCE_TYPE_PREFIX
+ + "has connection to invalid/not supported network resource, " + LOG_UNSUPPORTED_RESOURCE_CONNECTION_SUFFIX;
+ public static final String LOG_INVALID_NETWORK_CONNECTION = LOG_HEAT_RESOURCE_TYPE_PREFIX
+ + "include 'virtual_network' property with value '{}', the connection to this network wasn't found/not "
+ + "supported " + LOG_UNSUPPORTED_RESOURCE_CONNECTION_SUFFIX + " for this property.";
+
+ //Contrail v2 virtual network
+ public static final String LOG_INVALID_NETWORK_POLICY_REFS_RESOURCE = LOG_HEAT_RESOURCE_TYPE_PREFIX
+ + "property network_policy_refs is referenced to an unsupported resource "
+ + LOG_UNSUPPORTED_RESOURCE_CONNECTION_SUFFIX;
+
+ public static final String LOG_INVALID_PROPERTY_VALUE_FORMAT = LOG_HEAT_RESOURCE_TYPE_PREFIX
+ + "invalid format of property value, " + LOG_UNSUPPORTED_HEAT_RESOURCE_SUFFIX;
+
+ public static final String LOG_INVALID_PROPERTY_FORMAT_GET_ATTR_FQ_NAME = LOG_HEAT_RESOURCE_TYPE_PREFIX
+ + "has property with invalid format of 'get_attr' function with 'fq_name' value, "
+ + LOG_UNSUPPORTED_PROPERTY_SUFFIX;
+ public static final String LOG_INVALID_PROPERTY_FORMAT_GET_RESOURCE = LOG_HEAT_RESOURCE_TYPE_PREFIX
+ + "has property with invalid format of 'get_resource' function, "
+ + LOG_UNSUPPORTED_PROPERTY_SUFFIX;
+
+ //Contrail v2 vlan subinterface
+ public static final String LOG_MULTIPLE_INTERFACE_VALUES = LOG_HEAT_RESOURCE_TYPE_PREFIX
+ + "include '{}' property with more than one interface values, only the first interface will be connected, "
+ + "all rest will be ignored in TOSCA translation";
+ public static final String LOG_UNSUPPORTED_VLAN_RESOURCE_CONNECTION = LOG_HEAT_RESOURCE_TYPE_PREFIX
+ + "include '{}' property which is connect to unsupported/incorrect {} resource '{}' with type '{}', "
+ + LOG_UNSUPPORTED_RESOURCE_CONNECTION_SUFFIX;
+
+ private HeatToToscaLogConstants() {
+ //Hiding implicit constructor
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/UnifiedCompositionService.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/UnifiedCompositionService.java
index 358fe26998..217b5775a9 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/UnifiedCompositionService.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/UnifiedCompositionService.java
@@ -2521,10 +2521,8 @@ public class UnifiedCompositionService {
EntrySchema entrySchema,
ServiceTemplate serviceTemplate) {
- ParameterDefinition parameterDefinition = DataModelUtil.createParameterDefinition
- (parameterType, null, null,
- true, null, null,
- entrySchema, null);
+ ParameterDefinition parameterDefinition = DataModelUtil.createParameterDefinition(parameterType, null, true,
+ null, entrySchema, null);
DataModelUtil
@@ -2775,8 +2773,8 @@ public class UnifiedCompositionService {
private void createIndexInputParameter(ServiceTemplate substitutionServiceTemplate) {
ParameterDefinition indexParameterDefinition =
DataModelUtil.createParameterDefinition(PropertyType.INTEGER.getDisplayName(),
- "Index value of this substitution service template runtime instance", null,
- false, createIndexValueConstraint(), null, null, 0);
+ "Index value of this substitution service template runtime instance",
+ false, createIndexValueConstraint(), null, 0);
DataModelUtil.addInputParameterToTopologyTemplate(substitutionServiceTemplate,
ToscaConstants.INDEX_VALUE_PROPERTY_NAME, indexParameterDefinition);
}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationContrailAttachPolicyImpl.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationContrailAttachPolicyImpl.java
index 2bee60dbda..3792f0eb54 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationContrailAttachPolicyImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationContrailAttachPolicyImpl.java
@@ -1,34 +1,35 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
* 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.translator.services.heattotosca.impl.resourcetranslation;
+import static org.openecomp.sdc.heat.services.HeatConstants.NETWORK_PROPERTY_NAME;
+import static org.openecomp.sdc.tosca.services.DataModelUtil.createAttachmentRequirementAssignment;
+import static org.openecomp.sdc.translator.services.heattotosca.HeatToToscaLogConstants.LOG_UNSUPPORTED_POLICY_NETWORK_PROPERTY;
+import static org.openecomp.sdc.translator.services.heattotosca.HeatToToscaLogConstants.LOG_UNSUPPORTED_POLICY_PROPERTY_GET_ATTR;
+import static org.openecomp.sdc.translator.services.heattotosca.HeatToToscaLogConstants.LOG_UNSUPPORTED_POLICY_RESOURCE;
+
+import java.util.Optional;
+
+import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
import org.openecomp.sdc.common.errors.CoreException;
import org.openecomp.sdc.heat.datatypes.model.Resource;
import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
-import org.openecomp.sdc.tosca.datatypes.ToscaCapabilityType;
-import org.openecomp.sdc.tosca.datatypes.ToscaRelationshipType;
import org.openecomp.sdc.tosca.datatypes.ToscaTopologyTemplateElements;
-import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
-import org.onap.sdc.tosca.datatypes.model.RequirementAssignment;
import org.openecomp.sdc.tosca.services.DataModelUtil;
import org.openecomp.sdc.tosca.services.ToscaConstants;
import org.openecomp.sdc.translator.datatypes.heattotosca.AttachedResourceId;
@@ -37,107 +38,89 @@ import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil;
import org.openecomp.sdc.translator.services.heattotosca.ResourceTranslationFactory;
import org.openecomp.sdc.translator.services.heattotosca.errors.MissingMandatoryPropertyErrorBuilder;
-import java.util.Optional;
-
public class ResourceTranslationContrailAttachPolicyImpl extends ResourceTranslationBase {
- protected static Logger logger = LoggerFactory.getLogger(ResourceTranslationContrailAttachPolicyImpl.class);
+ protected static Logger logger = LoggerFactory.getLogger(ResourceTranslationContrailAttachPolicyImpl.class);
+
+ @Override
+ protected void translate(TranslateTo translateTo) {
+ String heatFileName = translateTo.getHeatFileName();
+ String translatedNetworkResourceId = getTranslatedNetworkResourceId(translateTo);
+ if (translatedNetworkResourceId == null) {
+ return;
+ }
+
+ NodeTemplate policyNodeTemplate = getTranslatedPolicyNodeTemplate(translateTo, heatFileName);
+ if (policyNodeTemplate != null) {
+ DataModelUtil.addRequirementAssignment(policyNodeTemplate, ToscaConstants.NETWORK_REQUIREMENT_ID,
+ createAttachmentRequirementAssignment(translatedNetworkResourceId));
+ }
+ }
- @Override
- protected void translate(TranslateTo translateTo) {
- String heatFileName = translateTo.getHeatFileName();
- String translatedNetworkResourceId = getTranslatedNetworkResourceId(translateTo);
- if (translatedNetworkResourceId == null) {
- return;
+ @Override
+ protected String generateTranslatedId(TranslateTo translateTo) {
+ return extractAttachedResourceIdHandleMissing(translateTo, NETWORK_PROPERTY_NAME).getEntityId().toString();
}
- NodeTemplate policyNodeTemplate = getTranslatedPolicyNodeTemplate(translateTo, heatFileName);
- if (policyNodeTemplate != null) {
- DataModelUtil
- .addRequirementAssignment(policyNodeTemplate, ToscaConstants.NETWORK_REQUIREMENT_ID,
- createRequirementAssignment(translatedNetworkResourceId));
+ @Override
+ protected Optional<ToscaTopologyTemplateElements> getTranslatedToscaTopologyElement(
+ TranslateTo translateTo) {
+ return Optional.empty();
}
- }
-
- @Override
- protected String generateTranslatedId(TranslateTo translateTo) {
- return extractAttachedResourceIdHandleMissing(translateTo, "network").getEntityId()
- .toString();
- }
-
- @Override
- protected Optional<ToscaTopologyTemplateElements> getTranslatedToscaTopologyElement(
- TranslateTo translateTo) {
- return Optional.empty();
- }
-
- private NodeTemplate getTranslatedPolicyNodeTemplate(TranslateTo translateTo,
- String heatFileName) {
- AttachedResourceId attachedPolicyResourceId =
- extractAttachedResourceIdHandleMissing(translateTo, "policy");
- NodeTemplate policyNodeTemplate = new NodeTemplate();
- Optional<String> policyResourceId =
- HeatToToscaUtil.getContrailAttachedHeatResourceId(attachedPolicyResourceId);
- if (policyResourceId.isPresent()) {
- policyNodeTemplate = getPolicyNodeTemplate(translateTo, heatFileName, policyResourceId.get());
- } else {
- logger.warn("Heat resource: '{}' with type: '{}' include 'policy' property without 'get_attr' of " +
- "'fq_name'/'get_resource' function, therefore this resource will be ignored in TOSCA translation.",
- translateTo.getResourceId(), translateTo.getResource().getType());
+
+ private NodeTemplate getTranslatedPolicyNodeTemplate(TranslateTo translateTo,
+ String heatFileName) {
+ AttachedResourceId attachedPolicyResourceId = extractAttachedResourceIdHandleMissing(translateTo, "policy");
+ NodeTemplate policyNodeTemplate = new NodeTemplate();
+ Optional<String> policyResourceId =
+ HeatToToscaUtil.getContrailAttachedHeatResourceId(attachedPolicyResourceId);
+ if (policyResourceId.isPresent()) {
+ policyNodeTemplate = getPolicyNodeTemplate(translateTo, heatFileName, policyResourceId.get());
+ } else {
+ logger.warn(LOG_UNSUPPORTED_POLICY_PROPERTY_GET_ATTR, translateTo.getResourceId(),
+ translateTo.getResource().getType());
+ }
+ return policyNodeTemplate;
}
- return policyNodeTemplate;
- }
-
- private NodeTemplate getPolicyNodeTemplate(TranslateTo translateTo, String heatFileName,
- String policyResourceId) {
- Resource policyResource = HeatToToscaUtil
- .getResource(translateTo.getHeatOrchestrationTemplate(), policyResourceId, heatFileName);
- Optional<String> translatedPolicyResourceId =
- ResourceTranslationFactory.getInstance(policyResource)
- .translateResource(heatFileName, translateTo.getServiceTemplate(),
- translateTo.getHeatOrchestrationTemplate(), policyResource, policyResourceId,
- translateTo.getContext());
- if (!translatedPolicyResourceId.isPresent()) {
- logger.warn("Heat resource: '{}' with type: '{}' include unsupported policy resource, " +
- "therefore this resource will be ignored in TOSCA translation.",
- translateTo.getResourceId(), translateTo.getResource().getType());
- return null;
+
+ private NodeTemplate getPolicyNodeTemplate(TranslateTo translateTo, String heatFileName,
+ String policyResourceId) {
+ Resource policyResource = HeatToToscaUtil
+ .getResource(translateTo.getHeatOrchestrationTemplate(), policyResourceId, heatFileName);
+ Optional<String> translatedPolicyResourceId =
+ ResourceTranslationFactory.getInstance(policyResource)
+ .translateResource(heatFileName, translateTo.getServiceTemplate(),
+ translateTo.getHeatOrchestrationTemplate(), policyResource, policyResourceId,
+ translateTo.getContext());
+ if (!translatedPolicyResourceId.isPresent()) {
+ logger.warn(LOG_UNSUPPORTED_POLICY_RESOURCE, translateTo.getResourceId(), translateTo.getResource().getType());
+ return null;
+ }
+ return DataModelUtil.getNodeTemplate(translateTo.getServiceTemplate(), translatedPolicyResourceId.get());
}
- return DataModelUtil
- .getNodeTemplate(translateTo.getServiceTemplate(), translatedPolicyResourceId.get());
- }
-
- private String getTranslatedNetworkResourceId(TranslateTo translateTo) {
- AttachedResourceId attachedNetworkResourceId =
- extractAttachedResourceIdHandleMissing(translateTo, "network");
-
- String translatedNetworkResourceId = null;
- if (attachedNetworkResourceId.isGetResource()) {
- translatedNetworkResourceId = (String) attachedNetworkResourceId.getTranslatedId();
- } else {
- logger.warn("Heat resource: '{}' with type: '{}' include 'network' property without 'get_resource' " +
- "function, therefore this resource will be ignored in TOSCA translation.",
- translateTo.getResourceId(), translateTo.getResource().getType());
+
+ private String getTranslatedNetworkResourceId(TranslateTo translateTo) {
+ AttachedResourceId attachedNetworkResourceId = extractAttachedResourceIdHandleMissing(translateTo,
+ NETWORK_PROPERTY_NAME);
+
+ String translatedNetworkResourceId = null;
+ if (attachedNetworkResourceId.isGetResource()) {
+ translatedNetworkResourceId = (String) attachedNetworkResourceId.getTranslatedId();
+ } else {
+ logger.warn(LOG_UNSUPPORTED_POLICY_NETWORK_PROPERTY, translateTo.getResourceId(),
+ translateTo.getResource().getType());
+ }
+ return translatedNetworkResourceId;
}
- return translatedNetworkResourceId;
- }
-
- private RequirementAssignment createRequirementAssignment(String translatedNetworkResourceId) {
- RequirementAssignment requirement = new RequirementAssignment();
- requirement.setCapability(ToscaCapabilityType.NATIVE_ATTACHMENT);
- requirement.setNode(translatedNetworkResourceId);
- requirement.setRelationship(ToscaRelationshipType.ATTACHES_TO);
- return requirement;
- }
-
- private AttachedResourceId extractAttachedResourceIdHandleMissing(
- TranslateTo translateTo, String propertyName) {
- Optional<AttachedResourceId> attachedResourceId =
- HeatToToscaUtil.extractAttachedResourceId(translateTo, propertyName);
-
- if (!attachedResourceId.isPresent()) {
- throw new CoreException(new MissingMandatoryPropertyErrorBuilder(propertyName).build());
+
+ private AttachedResourceId extractAttachedResourceIdHandleMissing(
+ TranslateTo translateTo, String propertyName) {
+ Optional<AttachedResourceId> attachedResourceId =
+ HeatToToscaUtil.extractAttachedResourceId(translateTo, propertyName);
+
+ if (!attachedResourceId.isPresent()) {
+ throw new CoreException(new MissingMandatoryPropertyErrorBuilder(propertyName).build());
+ }
+ return attachedResourceId.get();
}
- return attachedResourceId.get();
- }
}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationContrailNetworkPolicyImpl.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationContrailNetworkPolicyImpl.java
index 3bab225b54..b631573e24 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationContrailNetworkPolicyImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationContrailNetworkPolicyImpl.java
@@ -1,51 +1,44 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
* 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.translator.services.heattotosca.impl.resourcetranslation;
+import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
-import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
import org.openecomp.sdc.tosca.services.DataModelUtil;
import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo;
import org.openecomp.sdc.translator.services.heattotosca.mapping.TranslatorHeatToToscaPropertyConverter;
public class ResourceTranslationContrailNetworkPolicyImpl extends ResourceTranslationBase {
- protected static Logger logger =
- (Logger) LoggerFactory.getLogger(ResourceTranslationContrailNetworkPolicyImpl.class);
-
- @Override
- protected void translate(TranslateTo translateTo) {
- NodeTemplate nodeTemplate = new NodeTemplate();
- nodeTemplate.setType(ToscaNodeType.CONTRAIL_NETWORK_RULE);
-
- nodeTemplate.setProperties(TranslatorHeatToToscaPropertyConverter
- .getToscaPropertiesSimpleConversion(translateTo.getServiceTemplate(),translateTo.
- getResourceId(),translateTo.getResource().getProperties(),
- nodeTemplate.getProperties(), translateTo.getHeatFileName(),
- translateTo.getHeatOrchestrationTemplate(), translateTo.getResource().getType(),
- nodeTemplate, translateTo.getContext()));
+ protected static Logger logger =
+ (Logger) LoggerFactory.getLogger(ResourceTranslationContrailNetworkPolicyImpl.class);
- DataModelUtil.addNodeTemplate(translateTo.getServiceTemplate(), translateTo.getTranslatedId(),
- nodeTemplate);
- }
+ @Override
+ protected void translate(TranslateTo translateTo) {
+ NodeTemplate nodeTemplate = new NodeTemplate();
+ nodeTemplate.setType(ToscaNodeType.CONTRAIL_NETWORK_RULE);
+ nodeTemplate.setProperties(TranslatorHeatToToscaPropertyConverter
+ .getToscaPropertiesSimpleConversion(translateTo.getServiceTemplate(),
+ translateTo.getResourceId(), translateTo.getResource().getProperties(),
+ nodeTemplate.getProperties(), translateTo.getHeatFileName(),
+ translateTo.getHeatOrchestrationTemplate(), translateTo.getResource().getType(),
+ nodeTemplate, translateTo.getContext()));
+ DataModelUtil.addNodeTemplate(translateTo.getServiceTemplate(), translateTo.getTranslatedId(), nodeTemplate);
+ }
}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationContrailServiceInstanceImpl.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationContrailServiceInstanceImpl.java
index c9c6b5ab03..6f223e6937 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationContrailServiceInstanceImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationContrailServiceInstanceImpl.java
@@ -1,37 +1,38 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
* 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.translator.services.heattotosca.impl.resourcetranslation;
-import org.openecomp.sdc.common.errors.CoreException;
-import org.openecomp.sdc.heat.datatypes.HeatBoolean;
-import org.openecomp.sdc.heat.datatypes.model.HeatResourcesTypes;
-import org.openecomp.sdc.heat.datatypes.model.Resource;
-import org.openecomp.sdc.heat.services.HeatConstants;
-import org.openecomp.sdc.logging.api.Logger;
-import org.openecomp.sdc.logging.api.LoggerFactory;
-import org.openecomp.sdc.tosca.datatypes.ToscaCapabilityType;
-import org.openecomp.sdc.tosca.datatypes.ToscaFunctions;
-import org.openecomp.sdc.tosca.datatypes.ToscaGroupType;
-import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
-import org.openecomp.sdc.tosca.datatypes.ToscaRelationshipType;
+import static org.openecomp.sdc.tosca.services.ToscaConstants.MANDATORY_PROPERTY_NAME;
+import static org.openecomp.sdc.translator.services.heattotosca.HeatToToscaLogConstants.LOG_INVALID_NETWORK_CONNECTION;
+import static org.openecomp.sdc.translator.services.heattotosca.HeatToToscaLogConstants.LOG_MISSING_VIRTUAL_NETWORK_INTERFACE_LIST;
+import static org.openecomp.sdc.translator.services.heattotosca.HeatToToscaLogConstants.LOG_MULTIPLE_SERVICE_INSTANCE_DIFF_INTERFACES;
+import static org.openecomp.sdc.translator.services.heattotosca.HeatToToscaLogConstants.LOG_SERVICE_TEMPLATE_PROPERTY_GET_RESOURCE;
+import static org.openecomp.sdc.translator.services.heattotosca.HeatToToscaLogConstants.LOG_SERVICE_TEMPLATE_PROPERTY_INVALID_TYPE;
+import static org.openecomp.sdc.translator.services.heattotosca.HeatToToscaLogConstants.LOG_SERVICE_TEMPLATE_PROPERTY_UNSUPPORTED_RESOURCE;
+import static org.openecomp.sdc.translator.services.heattotosca.HeatToToscaLogConstants.LOG_UNSUPPORTED_NETWORK_RESOURCE_CONNECTION;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+
import org.onap.sdc.tosca.datatypes.model.AttributeDefinition;
import org.onap.sdc.tosca.datatypes.model.GroupDefinition;
import org.onap.sdc.tosca.datatypes.model.Import;
@@ -44,6 +45,18 @@ import org.onap.sdc.tosca.datatypes.model.RequirementDefinition;
import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
import org.onap.sdc.tosca.datatypes.model.SubstitutionMapping;
import org.onap.sdc.tosca.datatypes.model.TopologyTemplate;
+import org.openecomp.sdc.common.errors.CoreException;
+import org.openecomp.sdc.heat.datatypes.HeatBoolean;
+import org.openecomp.sdc.heat.datatypes.model.HeatResourcesTypes;
+import org.openecomp.sdc.heat.datatypes.model.Resource;
+import org.openecomp.sdc.heat.services.HeatConstants;
+import org.openecomp.sdc.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
+import org.openecomp.sdc.tosca.datatypes.ToscaCapabilityType;
+import org.openecomp.sdc.tosca.datatypes.ToscaFunctions;
+import org.openecomp.sdc.tosca.datatypes.ToscaGroupType;
+import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
+import org.openecomp.sdc.tosca.datatypes.ToscaRelationshipType;
import org.openecomp.sdc.tosca.services.DataModelUtil;
import org.openecomp.sdc.tosca.services.ToscaAnalyzerService;
import org.openecomp.sdc.tosca.services.ToscaConstants;
@@ -51,6 +64,7 @@ import org.openecomp.sdc.tosca.services.ToscaUtil;
import org.openecomp.sdc.tosca.services.impl.ToscaAnalyzerServiceImpl;
import org.openecomp.sdc.tosca.services.impl.ToscaFileOutputServiceCsarImpl;
import org.openecomp.sdc.translator.datatypes.heattotosca.AttachedResourceId;
+import org.openecomp.sdc.translator.datatypes.heattotosca.to.ContrailServiceInstanceTo;
import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo;
import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslatedHeatResource;
import org.openecomp.sdc.translator.services.heattotosca.Constants;
@@ -61,647 +75,586 @@ import org.openecomp.sdc.translator.services.heattotosca.globaltypes.GlobalTypes
import org.openecomp.sdc.translator.services.heattotosca.helper.ContrailTranslationHelper;
import org.openecomp.sdc.translator.services.heattotosca.mapping.TranslatorHeatToToscaPropertyConverter;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-
public class ResourceTranslationContrailServiceInstanceImpl extends ResourceTranslationBase {
- protected static Logger logger = LoggerFactory.getLogger(ResourceTranslationContrailServiceInstanceImpl.class);
-
- @Override
- public void translate(TranslateTo translateTo) {
- Resource serviceInstanceResource = translateTo.getResource();
- AttachedResourceId contrailServiceTemplateAttached =
- getServiceTemplateAttachedId(translateTo, serviceInstanceResource);
- if (contrailServiceTemplateAttached.isGetResource()) {
- String contrailServiceTemplateResourceId =
- (String) contrailServiceTemplateAttached.getEntityId();
- Resource contrailServiceTemplateResource = HeatToToscaUtil
- .getResource(translateTo.getHeatOrchestrationTemplate(),
- contrailServiceTemplateResourceId, translateTo.getHeatFileName());
- if (!contrailServiceTemplateResource.getType()
- .equals(HeatResourcesTypes.CONTRAIL_SERVICE_TEMPLATE.getHeatResource())) {
- logger.warn("resource id '" + translateTo.getResourceId() + "' with type '"
- + translateTo.getResource().getType()
- + "+ has reference to resource '" + contrailServiceTemplateResourceId + "' with type '"
- + contrailServiceTemplateResource.getType()
- + "' in property service_template. Invalid type, resource type should be type of '"
- + HeatResourcesTypes.CONTRAIL_SERVICE_TEMPLATE.getHeatResource()
- + "', therefore this resource will be ignored in TOSCA translation.");
- return;
- }
- Optional<String> contrailServiceTemplateTranslatedId =
- ResourceTranslationFactory.getInstance(contrailServiceTemplateResource)
- .translateResource(translateTo.getHeatFileName(), translateTo.getServiceTemplate(),
- translateTo.getHeatOrchestrationTemplate(), contrailServiceTemplateResource,
- contrailServiceTemplateResourceId, translateTo.getContext());
- if (!contrailServiceTemplateTranslatedId.isPresent()) {
- logger.warn("Resource id '" + translateTo.getResourceId() + "' with type '"
- + translateTo.getResource().getType()
- + "' has reference to unsupported resource '" + contrailServiceTemplateResourceId
- + "' with type '" + contrailServiceTemplateResource.getType()
- + "' in property 'service_template'"
- + ", therefore this resource will be ignored in TOSCA translation.");
- return;
- }
-
- ServiceTemplate globalSubstitutionServiceTemplate =
- translateTo.getContext().getTranslatedServiceTemplates().get(
- Constants.GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME);
- String contrailStId = ResourceTranslationContrailServiceTemplateImpl
- .getContrailSubstitutedNodeTypeId(contrailServiceTemplateTranslatedId.get());
- NodeType substitutedNodeType =
- DataModelUtil.getNodeType(globalSubstitutionServiceTemplate, contrailStId);
-
- int numberOfPorts = getServiceInstanceNumberOfPorts(serviceInstanceResource);
- if (substitutedNodeType.getRequirements() != null
- && substitutedNodeType.getRequirements().size() != numberOfPorts) {
- logger.warn("More than one ServiceInstance pointing to the same ServiceTemplate '"
- + contrailServiceTemplateResourceId + " ' with different number of interfaces."
- + ", therefore this resource will be ignored in TOSCA translation.");
- return;
- }
-
- addNetworkLinkRequirements(substitutedNodeType, numberOfPorts);
- NodeTemplate substitutedNodeTemplate =
- createSubstitutedNodeTemplate(translateTo, contrailServiceTemplateResource, contrailStId,
- numberOfPorts);
-
- String computeNodeTypeId = new ContrailTranslationHelper()
- .getComputeNodeTypeId(contrailServiceTemplateResource, contrailServiceTemplateResourceId,
- contrailServiceTemplateTranslatedId.get(), translateTo.getContext());
- boolean orderedInterfaces = getOrderedInterfaces(contrailServiceTemplateResource);
- ServiceTemplate nestedServiceTemplate =
- createNestedServiceTemplate(translateTo, computeNodeTypeId, contrailStId,
- substitutedNodeTemplate, orderedInterfaces);
- addAbstractSubstitutionProperty(translateTo, substitutedNodeTemplate.getProperties(),
- nestedServiceTemplate, contrailServiceTemplateResource);
- translateTo.getContext().getTranslatedServiceTemplates().put(new ContrailTranslationHelper()
- .getSubstitutionContrailServiceTemplateMetadata(translateTo.getHeatFileName(),
- translateTo.getTranslatedId()), nestedServiceTemplate);
-
- } else {
- logger.warn("Heat resource: '" + translateTo.getResourceId() + "' with type: '"
- + translateTo.getResource().getType()
- + "' include 'service_template' property without 'get_resource' function, currently not"
- + " supported, therefore this resource will be ignored in TOSCA translation.");
- }
- }
-
- private void addAbstractSubstitutionProperty(TranslateTo translateTo,
- Map<String, Object> substitutionProperties,
- ServiceTemplate nestedServiceTemplate,
- Resource contrailServiceTemplateResource) {
- Map<String, Object> innerProps = new HashMap<>();
- innerProps.put(ToscaConstants.SUBSTITUTE_SERVICE_TEMPLATE_PROPERTY_NAME,
- ToscaUtil.getServiceTemplateFileName(nestedServiceTemplate));
-
- Object countValue = handleScaleOutProperty(translateTo, innerProps);
- handleServiceScalingProperty(translateTo, innerProps, contrailServiceTemplateResource);
-
- boolean mandatory = false;
- if (countValue instanceof Integer && (Integer) countValue > 0) {
- mandatory = true;
+ private static final String INTERFACE_LIST = "interface_list";
+ protected static Logger logger = LoggerFactory.getLogger(ResourceTranslationContrailServiceInstanceImpl.class);
+
+ @Override
+ public void translate(TranslateTo translateTo) {
+ Resource serviceInstanceResource = translateTo.getResource();
+ AttachedResourceId contrailServiceTemplateAttached = getServiceTemplateAttachedId(translateTo,
+ serviceInstanceResource);
+ if (contrailServiceTemplateAttached.isGetResource()) {
+ translateContrailServiceInstance(translateTo, serviceInstanceResource, contrailServiceTemplateAttached);
+ } else {
+ logger.warn(LOG_SERVICE_TEMPLATE_PROPERTY_GET_RESOURCE, translateTo.getResourceId(),
+ translateTo.getResource().getType());
+ }
}
- if (countValue == null) {
- mandatory = true;
+
+ private void translateContrailServiceInstance(TranslateTo translateTo, Resource serviceInstanceResource,
+ AttachedResourceId contrailServiceTemplateAttached) {
+ String contrailServiceTemplateResourceId = (String) contrailServiceTemplateAttached.getEntityId();
+ Resource contrailServiceTemplateResource = HeatToToscaUtil
+ .getResource(translateTo.getHeatOrchestrationTemplate(),
+ contrailServiceTemplateResourceId, translateTo.getHeatFileName());
+ if (!contrailServiceTemplateResource.getType()
+ .equals(HeatResourcesTypes.CONTRAIL_SERVICE_TEMPLATE.getHeatResource())) {
+ logger.warn(LOG_SERVICE_TEMPLATE_PROPERTY_INVALID_TYPE, translateTo.getResourceId(),
+ translateTo.getResource().getType(), contrailServiceTemplateResourceId,
+ contrailServiceTemplateResource.getType(),
+ HeatResourcesTypes.CONTRAIL_SERVICE_TEMPLATE.getHeatResource());
+ return;
+ }
+ Optional<String> contrailServiceTemplateTranslatedId =
+ ResourceTranslationFactory.getInstance(contrailServiceTemplateResource)
+ .translateResource(translateTo.getHeatFileName(), translateTo.getServiceTemplate(),
+ translateTo.getHeatOrchestrationTemplate(), contrailServiceTemplateResource,
+ contrailServiceTemplateResourceId, translateTo.getContext());
+ if (!contrailServiceTemplateTranslatedId.isPresent()) {
+ logger.warn(LOG_SERVICE_TEMPLATE_PROPERTY_UNSUPPORTED_RESOURCE, translateTo.getResourceId(),
+ translateTo.getResource().getType(), contrailServiceTemplateResourceId,
+ contrailServiceTemplateResource.getType());
+ return;
+ }
+
+ ServiceTemplate globalSubstitutionServiceTemplate = translateTo.getContext().getTranslatedServiceTemplates()
+ .get(Constants.GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME);
+ String contrailStId = ResourceTranslationContrailServiceTemplateImpl
+ .getContrailSubstitutedNodeTypeId(contrailServiceTemplateTranslatedId.get());
+ NodeType substitutedNodeType = DataModelUtil.getNodeType(globalSubstitutionServiceTemplate, contrailStId);
+ int numberOfPorts = getServiceInstanceNumberOfPorts(serviceInstanceResource);
+ if (substitutedNodeType.getRequirements() != null
+ && substitutedNodeType.getRequirements().size() != numberOfPorts) {
+ logger.warn(LOG_MULTIPLE_SERVICE_INSTANCE_DIFF_INTERFACES, contrailServiceTemplateResourceId);
+ return;
+ }
+ addNetworkLinkRequirements(substitutedNodeType, numberOfPorts);
+ NodeTemplate substitutedNodeTemplate = createSubstitutedNodeTemplate(translateTo,
+ contrailServiceTemplateResource, contrailStId, numberOfPorts);
+ String computeNodeTypeId = new ContrailTranslationHelper()
+ .getComputeNodeTypeId(contrailServiceTemplateResource, contrailServiceTemplateResourceId,
+ contrailServiceTemplateTranslatedId.get(), translateTo.getContext());
+ boolean orderedInterfaces = getOrderedInterfaces(contrailServiceTemplateResource);
+ ServiceTemplate nestedServiceTemplate = createNestedServiceTemplate(translateTo, computeNodeTypeId,
+ contrailStId, substitutedNodeTemplate, orderedInterfaces);
+ addAbstractSubstitutionProperty(translateTo, substitutedNodeTemplate.getProperties(),
+ nestedServiceTemplate, contrailServiceTemplateResource);
+ translateTo.getContext().getTranslatedServiceTemplates().put(new ContrailTranslationHelper()
+ .getSubstitutionContrailServiceTemplateMetadata(translateTo.getHeatFileName(),
+ translateTo.getTranslatedId()), nestedServiceTemplate);
}
- innerProps.put("mandatory", mandatory);
- substitutionProperties.put(ToscaConstants.SERVICE_TEMPLATE_FILTER_PROPERTY_NAME, innerProps);
- }
-
- private Object handleScaleOutProperty(TranslateTo translateTo, Map<String, Object> innerProps) {
- Object scaleOutPropertyValue =
- translateTo.getResource().getProperties().get(HeatConstants.SCALE_OUT_PROPERTY_NAME);
- Object countValue = null;
- if (scaleOutPropertyValue != null && scaleOutPropertyValue instanceof Map) {
- countValue = TranslatorHeatToToscaPropertyConverter
- .getToscaPropertyValue(translateTo.getServiceTemplate(), translateTo.getTranslatedId(),
- Constants.MAX_INSTANCES_PROPERTY_NAME,
- ((Map) scaleOutPropertyValue).get(Constants.MAX_INSTANCES_PROPERTY_NAME), null,
- translateTo.getHeatFileName(), translateTo.getHeatOrchestrationTemplate(), null,
- translateTo.getContext());
- if (countValue != null) {
- innerProps.put(ToscaConstants.COUNT_PROPERTY_NAME, countValue);
- } else {
- innerProps.put(ToscaConstants.COUNT_PROPERTY_NAME, 1);
- }
- } else {
- innerProps.put(ToscaConstants.COUNT_PROPERTY_NAME, 1);
+
+ private void addAbstractSubstitutionProperty(TranslateTo translateTo,
+ Map<String, Object> substitutionProperties,
+ ServiceTemplate nestedServiceTemplate,
+ Resource contrailServiceTemplateResource) {
+ Map<String, Object> innerProps = new HashMap<>();
+ innerProps.put(ToscaConstants.SUBSTITUTE_SERVICE_TEMPLATE_PROPERTY_NAME,
+ ToscaUtil.getServiceTemplateFileName(nestedServiceTemplate));
+ Object countValue = handleScaleOutProperty(translateTo, innerProps);
+ handleServiceScalingProperty(translateTo, innerProps, contrailServiceTemplateResource);
+ boolean mandatory = false;
+ if (countValue instanceof Integer && (Integer) countValue > 0) {
+ mandatory = true;
+ }
+ if (countValue == null) {
+ mandatory = true;
+ }
+ innerProps.put(MANDATORY_PROPERTY_NAME, mandatory);
+ substitutionProperties.put(ToscaConstants.SERVICE_TEMPLATE_FILTER_PROPERTY_NAME, innerProps);
}
- return countValue;
- }
-
- private void handleServiceScalingProperty(TranslateTo translateTo, Map<String, Object> innerProps,
- Resource contrailServiceTemplateResource) {
- Object serviceScalingPropertyValue = contrailServiceTemplateResource.getProperties()
- .get(HeatConstants.SERVICE_SCALING_PROPERTY_NAME);
- Object serviceScalingValue;
- if (serviceScalingPropertyValue != null) {
- serviceScalingValue = TranslatorHeatToToscaPropertyConverter
- .getToscaPropertyValue(translateTo.getServiceTemplate(), translateTo.getTranslatedId(),
- HeatConstants.SERVICE_SCALING_PROPERTY_NAME, serviceScalingPropertyValue, null,
- translateTo.getHeatFileName(), translateTo.getHeatOrchestrationTemplate(), null,
- translateTo.getContext());
- if (serviceScalingValue != null) {
- innerProps.put(ToscaConstants.SCALING_ENABLED_PROPERTY_NAME,
- (HeatBoolean.isValueBoolean(serviceScalingValue)) ? HeatBoolean
- .eval(serviceScalingValue) : serviceScalingValue);
- }
+
+ private Object handleScaleOutProperty(TranslateTo translateTo, Map<String, Object> innerProps) {
+ Object scaleOutPropertyValue =
+ translateTo.getResource().getProperties().get(HeatConstants.SCALE_OUT_PROPERTY_NAME);
+ Object countValue = null;
+ if (scaleOutPropertyValue instanceof Map) {
+ countValue = TranslatorHeatToToscaPropertyConverter
+ .getToscaPropertyValue(translateTo.getServiceTemplate(), translateTo.getTranslatedId(),
+ Constants.MAX_INSTANCES_PROPERTY_NAME,
+ ((Map) scaleOutPropertyValue).get(Constants.MAX_INSTANCES_PROPERTY_NAME), null,
+ translateTo.getHeatFileName(), translateTo.getHeatOrchestrationTemplate(), null,
+ translateTo.getContext());
+ if (countValue != null) {
+ innerProps.put(ToscaConstants.COUNT_PROPERTY_NAME, countValue);
+ } else {
+ innerProps.put(ToscaConstants.COUNT_PROPERTY_NAME, 1);
+ }
+ } else {
+ innerProps.put(ToscaConstants.COUNT_PROPERTY_NAME, 1);
+ }
+ return countValue;
}
- }
- private boolean getOrderedInterfaces(Resource contrailServiceTemplate) {
- Object orderedInterfaces = contrailServiceTemplate.getProperties().get("ordered_interfaces");
- if (orderedInterfaces == null) {
- return false;
+ private void handleServiceScalingProperty(TranslateTo translateTo, Map<String, Object> innerProps,
+ Resource contrailServiceTemplateResource) {
+ Object serviceScalingPropertyValue = contrailServiceTemplateResource.getProperties()
+ .get(HeatConstants.SERVICE_SCALING_PROPERTY_NAME);
+ Object serviceScalingValue;
+ if (serviceScalingPropertyValue != null) {
+ serviceScalingValue = TranslatorHeatToToscaPropertyConverter
+ .getToscaPropertyValue(translateTo.getServiceTemplate(), translateTo.getTranslatedId(),
+ HeatConstants.SERVICE_SCALING_PROPERTY_NAME, serviceScalingPropertyValue, null,
+ translateTo.getHeatFileName(), translateTo.getHeatOrchestrationTemplate(), null,
+ translateTo.getContext());
+ if (serviceScalingValue != null) {
+ innerProps.put(ToscaConstants.SCALING_ENABLED_PROPERTY_NAME,
+ (HeatBoolean.isValueBoolean(serviceScalingValue)) ? HeatBoolean.eval(serviceScalingValue) :
+ serviceScalingValue);
+ }
+ }
}
- if (orderedInterfaces instanceof String) {
- return HeatBoolean.eval(orderedInterfaces);
+
+ private boolean getOrderedInterfaces(Resource contrailServiceTemplate) {
+ Object orderedInterfaces = contrailServiceTemplate.getProperties().get("ordered_interfaces");
+ if (orderedInterfaces == null) {
+ return false;
+ }
+ if (orderedInterfaces instanceof String) {
+ return HeatBoolean.eval(orderedInterfaces);
+ }
+ //if get_param, set default value to true
+ return true;
}
- //if get_param, set default value to true
- return true;
- }
-
- private ServiceTemplate createNestedServiceTemplate(TranslateTo translateTo,
- String computeNodeTypeId,
- String substitutedNodeTypeId,
- NodeTemplate substitutedNodeTemplate,
- boolean orderedInterfaces) {
- ServiceTemplate nestedSubstitutionServiceTemplate = new ServiceTemplate();
- setNestedServiceTemplateGeneralDetails(translateTo, nestedSubstitutionServiceTemplate);
- String heatStackGroupKey = addHeatStackGroup(translateTo, nestedSubstitutionServiceTemplate);
- addSubstitutionMappingEntry(nestedSubstitutionServiceTemplate, substitutedNodeTypeId);
-
- handleInputParameters(nestedSubstitutionServiceTemplate, translateTo);
- String computeNodeTemplateId =
- handleComputeNodeTemplate(translateTo, computeNodeTypeId, nestedSubstitutionServiceTemplate,
- heatStackGroupKey);
- handleOutputParameters(nestedSubstitutionServiceTemplate, computeNodeTemplateId, translateTo);
- handleServiceInstanceInterfaces(translateTo, nestedSubstitutionServiceTemplate,
- substitutedNodeTemplate, heatStackGroupKey, orderedInterfaces, computeNodeTemplateId);
- return nestedSubstitutionServiceTemplate;
- }
-
- private void handleOutputParameters(ServiceTemplate nestedSubstitutionServiceTemplate,
- String nodeTemplateId, TranslateTo translateTo) {
- if (nodeTemplateId == null) {
- return;
+
+ private ServiceTemplate createNestedServiceTemplate(TranslateTo translateTo,
+ String computeNodeTypeId,
+ String substitutedNodeTypeId,
+ NodeTemplate substitutedNodeTemplate,
+ boolean orderedInterfaces) {
+ ServiceTemplate nestedSubstitutionServiceTemplate = new ServiceTemplate();
+ setNestedServiceTemplateGeneralDetails(translateTo, nestedSubstitutionServiceTemplate);
+ String heatStackGroupKey = addHeatStackGroup(translateTo, nestedSubstitutionServiceTemplate);
+ addSubstitutionMappingEntry(nestedSubstitutionServiceTemplate, substitutedNodeTypeId);
+ handleInputParameters(nestedSubstitutionServiceTemplate, translateTo);
+ String computeNodeTemplateId = handleComputeNodeTemplate(translateTo, computeNodeTypeId,
+ nestedSubstitutionServiceTemplate, heatStackGroupKey);
+ handleOutputParameters(nestedSubstitutionServiceTemplate, computeNodeTemplateId, translateTo);
+ handleServiceInstanceInterfaces(translateTo,
+ new ContrailServiceInstanceTo(nestedSubstitutionServiceTemplate, substitutedNodeTemplate,
+ heatStackGroupKey, orderedInterfaces, computeNodeTemplateId));
+ return nestedSubstitutionServiceTemplate;
}
- ToscaAnalyzerService toscaAnalyzerService = new ToscaAnalyzerServiceImpl();
- Optional<NodeType> contrailAbstractNodeType =
- toscaAnalyzerService.fetchNodeType(ToscaNodeType.CONTRAIL_ABSTRACT_SUBSTITUTE, translateTo
- .getContext().getGlobalServiceTemplates().values());
+ private void handleOutputParameters(ServiceTemplate nestedSubstitutionServiceTemplate,
+ String nodeTemplateId, TranslateTo translateTo) {
+ if (nodeTemplateId == null) {
+ return;
+ }
+ ToscaAnalyzerService toscaAnalyzerService = new ToscaAnalyzerServiceImpl();
- if (!contrailAbstractNodeType.isPresent()) {
- return;
- }
- Map<String, AttributeDefinition> contrailAbstractAttributes =
- contrailAbstractNodeType.get().getAttributes();
- Map<String, ParameterDefinition> nestedSubstitutionServiceTemplateOutputs = new HashMap<>();
+ Optional<NodeType> contrailAbstractNodeType =
+ toscaAnalyzerService.fetchNodeType(ToscaNodeType.CONTRAIL_ABSTRACT_SUBSTITUTE, translateTo
+ .getContext().getGlobalServiceTemplates().values());
- if (contrailAbstractAttributes == null) {
- return;
- }
+ if (!contrailAbstractNodeType.isPresent()) {
+ return;
+ }
+ Map<String, AttributeDefinition> contrailAbstractAttributes =
+ contrailAbstractNodeType.get().getAttributes();
+ Map<String, ParameterDefinition> nestedSubstitutionServiceTemplateOutputs = new HashMap<>();
- for (String attributeKey : contrailAbstractAttributes.keySet()) {
- AttributeDefinition abstractAttributeDef = contrailAbstractAttributes.get(attributeKey);
- if (abstractAttributeDef != null) {
- Map<String, List> outputValue = new HashMap<>();
- List outputGetAttributeList = new ArrayList<>();
- outputGetAttributeList.add(nodeTemplateId);
- outputGetAttributeList.add(attributeKey);
- outputValue.put(ToscaFunctions.GET_ATTRIBUTE.getDisplayName(), outputGetAttributeList);
- nestedSubstitutionServiceTemplateOutputs.put(attributeKey,
- DataModelUtil.convertAttributeDefToParameterDef(abstractAttributeDef, outputValue));
- }
- }
- if (!nestedSubstitutionServiceTemplateOutputs.isEmpty()) {
- nestedSubstitutionServiceTemplate.getTopology_template()
- .setOutputs(nestedSubstitutionServiceTemplateOutputs);
- }
- }
-
- private void handleServiceInstanceInterfaces(TranslateTo translateTo,
- ServiceTemplate nestedSubstitutionServiceTemplate,
- NodeTemplate substitutedNodeTemplate,
- String heatStackGroupKey, boolean orderedInterfaces,
- String computeNodeTemplateId) {
- Resource serviceInstanceResource = translateTo.getResource();
- Object interfaceListProperty =
- serviceInstanceResource.getProperties().get(HeatConstants.INTERFACE_LIST_PROPERTY_NAME);
- if (interfaceListProperty == null) {
- return;
+ if (contrailAbstractAttributes == null) {
+ return;
+ }
+
+ for (Map.Entry<String, AttributeDefinition> attributeDefinitionEntry : contrailAbstractAttributes.entrySet()) {
+ AttributeDefinition abstractAttributeDef = attributeDefinitionEntry.getValue();
+ if (abstractAttributeDef != null) {
+ Map<String, List> outputValue = new HashMap<>();
+ List<String> outputGetAttributeList = new ArrayList<>();
+ outputGetAttributeList.add(nodeTemplateId);
+ outputGetAttributeList.add(attributeDefinitionEntry.getKey());
+ outputValue.put(ToscaFunctions.GET_ATTRIBUTE.getDisplayName(), outputGetAttributeList);
+ nestedSubstitutionServiceTemplateOutputs.put(attributeDefinitionEntry.getKey(),
+ DataModelUtil.convertAttributeDefToParameterDef(abstractAttributeDef, outputValue));
+ }
+ }
+
+ if (!nestedSubstitutionServiceTemplateOutputs.isEmpty()) {
+ nestedSubstitutionServiceTemplate.getTopology_template()
+ .setOutputs(nestedSubstitutionServiceTemplateOutputs);
+ }
}
- if (interfaceListProperty instanceof List) {
- for (int index = 0; index < ((List) interfaceListProperty).size(); index++) {
- Object interfaceEntry = ((List) interfaceListProperty).get(index);
- handleInterface(translateTo, interfaceEntry, index, nestedSubstitutionServiceTemplate,
- heatStackGroupKey, substitutedNodeTemplate, orderedInterfaces, computeNodeTemplateId);
- }
- } else if (interfaceListProperty instanceof Map) {
- handleInterface(translateTo, interfaceListProperty, null, nestedSubstitutionServiceTemplate,
- heatStackGroupKey, substitutedNodeTemplate, orderedInterfaces, computeNodeTemplateId);
+
+ private void handleServiceInstanceInterfaces(TranslateTo translateTo,
+ ContrailServiceInstanceTo contrailServiceInstanceTo) {
+ Resource serviceInstanceResource = translateTo.getResource();
+ Object interfaceListProperty =
+ serviceInstanceResource.getProperties().get(HeatConstants.INTERFACE_LIST_PROPERTY_NAME);
+ if (interfaceListProperty == null) {
+ return;
+ }
+ if (interfaceListProperty instanceof List) {
+ for (int index = 0; index < ((List) interfaceListProperty).size(); index++) {
+ Object interfaceEntry = ((List) interfaceListProperty).get(index);
+ handleInterface(translateTo, interfaceEntry, index, contrailServiceInstanceTo);
+ }
+ } else if (interfaceListProperty instanceof Map) {
+ handleInterface(translateTo, interfaceListProperty, null, contrailServiceInstanceTo);
+ }
}
- }
-
- private void handleInterface(TranslateTo translateTo, Object interfacePropertyValue,
- Integer index,
- ServiceTemplate nestedSubstitutionServiceTemplate,
- String heatStackGroupKey, NodeTemplate substitutedNodeTemplate,
- boolean orderedInterfaces, String computeNodeTemplateId) {
- if (index == null) {
- index = 0;
+
+ private void handleInterface(TranslateTo translateTo, Object interfacePropertyValue,
+ Integer index, ContrailServiceInstanceTo contrailServiceInstanceTo) {
+ if (index == null) {
+ index = 0;
+ }
+ NodeTemplate portNodeTemplate = createPortNodeTemplate(index, contrailServiceInstanceTo.isOrderedInterfaces(),
+ contrailServiceInstanceTo.getComputeNodeTemplateId());
+ String portNodeTemplateId = Constants.SERVICE_INSTANCE_PORT_PREFIX + index;
+ String portReqMappingKey = Constants.SERVICE_INSTANCE_LINK_PREFIX + portNodeTemplateId;
+
+ DataModelUtil.addNodeTemplate(contrailServiceInstanceTo.getNestedSubstitutionServiceTemplate(),
+ portNodeTemplateId, portNodeTemplate);
+ updateSubstitutionMappingRequirement(contrailServiceInstanceTo.getNestedSubstitutionServiceTemplate(),
+ portReqMappingKey, portNodeTemplateId);
+ updateHeatStackGroup(contrailServiceInstanceTo.getNestedSubstitutionServiceTemplate(),
+ contrailServiceInstanceTo.getHeatStackGroupKey(), portNodeTemplateId);
+ connectPortToNetwork(translateTo, interfacePropertyValue, contrailServiceInstanceTo
+ .getSubstitutedNodeTemplate(), portReqMappingKey);
}
- NodeTemplate portNodeTemplate =
- createPortNodeTemplate(index, orderedInterfaces, computeNodeTemplateId);
- String portNodeTemplateId = Constants.SERVICE_INSTANCE_PORT_PREFIX + index;
- String portReqMappingKey = Constants.SERVICE_INSTANCE_LINK_PREFIX + portNodeTemplateId;
-
- DataModelUtil
- .addNodeTemplate(nestedSubstitutionServiceTemplate, portNodeTemplateId, portNodeTemplate);
- updateSubstitutionMappingRequirement(nestedSubstitutionServiceTemplate, portReqMappingKey,
- portNodeTemplateId);
- updateHeatStackGroup(nestedSubstitutionServiceTemplate, heatStackGroupKey, portNodeTemplateId);
- connectPortToNetwork(translateTo, interfacePropertyValue, substitutedNodeTemplate,
- portReqMappingKey);
- }
-
- private void connectPortToNetwork(TranslateTo translateTo, Object interfacePropertyValue,
- NodeTemplate substitutedNodeTemplate,
- String portReqMappingKey) {
- List<String> validNetworksForConnections = Arrays
- .asList(HeatResourcesTypes.NEUTRON_NET_RESOURCE_TYPE.getHeatResource(),
- HeatResourcesTypes.CONTRAIL_VIRTUAL_NETWORK_RESOURCE_TYPE.getHeatResource());
-
- if (interfacePropertyValue instanceof Map) {
- Object virtualNetworkValue =
- ((Map) interfacePropertyValue).get(HeatConstants.VIRTUAL_NETWORK_PROPERTY_NAME);
- if (virtualNetworkValue != null) {
+
+ private void connectPortToNetwork(TranslateTo translateTo, Object interfacePropertyValue,
+ NodeTemplate substitutedNodeTemplate,
+ String portReqMappingKey) {
+ List<String> validNetworksForConnections = Arrays
+ .asList(HeatResourcesTypes.NEUTRON_NET_RESOURCE_TYPE.getHeatResource(),
+ HeatResourcesTypes.CONTRAIL_VIRTUAL_NETWORK_RESOURCE_TYPE.getHeatResource());
+ if (!(interfacePropertyValue instanceof Map)) {
+ return;
+ }
+ Object virtualNetworkValue = ((Map) interfacePropertyValue).get(HeatConstants.VIRTUAL_NETWORK_PROPERTY_NAME);
+ if (virtualNetworkValue == null) {
+ logger.warn(LOG_MISSING_VIRTUAL_NETWORK_INTERFACE_LIST, translateTo.getResourceId(),
+ translateTo.getResource().getType());
+ return;
+ }
Optional<AttachedResourceId> networkAttachedResourceId = HeatToToscaUtil
- .extractAttachedResourceId(translateTo.getHeatFileName(),
- translateTo.getHeatOrchestrationTemplate(), translateTo.getContext(),
- virtualNetworkValue);
- if (networkAttachedResourceId.isPresent()) {
- Optional<String> networkResourceId =
- HeatToToscaUtil.getContrailAttachedHeatResourceId(networkAttachedResourceId.get());
- if (networkResourceId.isPresent()) {
- Resource networkResource = HeatToToscaUtil
- .getResource(translateTo.getHeatOrchestrationTemplate(), networkResourceId.get(),
- translateTo.getHeatFileName());
+ .extractAttachedResourceId(translateTo.getHeatFileName(), translateTo.getHeatOrchestrationTemplate(),
+ translateTo.getContext(), virtualNetworkValue);
+ if (!networkAttachedResourceId.isPresent()) {
+ return;
+ }
+ Optional<String> networkResourceId =
+ HeatToToscaUtil.getContrailAttachedHeatResourceId(networkAttachedResourceId.get());
+ if (networkResourceId.isPresent()) {
+ Resource networkResource = HeatToToscaUtil.getResource(translateTo.getHeatOrchestrationTemplate(),
+ networkResourceId.get(), translateTo.getHeatFileName());
if (validNetworksForConnections.contains(networkResource.getType())) {
- Optional<String> networkTranslatedId =
- getResourceTranslatedId(translateTo.getHeatFileName(),
- translateTo.getHeatOrchestrationTemplate(), networkResourceId.get(),
- translateTo.getContext());
- networkTranslatedId
- .ifPresent(
- translatedId -> addLinkToNetworkRequirementAssignment(substitutedNodeTemplate,
- translatedId, portReqMappingKey));
+ Optional<String> networkTranslatedId =
+ getResourceTranslatedId(translateTo.getHeatFileName(),
+ translateTo.getHeatOrchestrationTemplate(), networkResourceId.get(),
+ translateTo.getContext());
+ networkTranslatedId.ifPresent(translatedId -> addLinkToNetworkRequirementAssignment(
+ substitutedNodeTemplate, translatedId, portReqMappingKey));
} else {
- logger.warn("Heat resource " + translateTo.getResourceId() + " with type "
- + translateTo.getResource().getType()
- + " has connection to invalid/not supported network resource, therefore, this "
- + "connection will be ignored in the translation.");
+ logger.warn(LOG_UNSUPPORTED_NETWORK_RESOURCE_CONNECTION, translateTo.getResourceId(),
+ translateTo.getResource().getType());
}
- } else if (networkAttachedResourceId.get().isGetParam()
- && networkAttachedResourceId.get().getEntityId() instanceof String) {
- TranslatedHeatResource
- translatedSharedResourceId =
- translateTo.getContext().getHeatSharedResourcesByParam()
- .get(networkAttachedResourceId.get().getEntityId());
+ } else if (networkAttachedResourceId.get().isGetParam()
+ && networkAttachedResourceId.get().getEntityId() instanceof String) {
+ TranslatedHeatResource translatedSharedResourceId = translateTo.getContext().getHeatSharedResourcesByParam()
+ .get(networkAttachedResourceId.get().getEntityId());
if (Objects.nonNull(translatedSharedResourceId)
- && !HeatToToscaUtil.isHeatFileNested(translateTo, translateTo.getHeatFileName())) {
- addLinkToNetworkRequirementAssignment(substitutedNodeTemplate,
- translatedSharedResourceId.getTranslatedId(), portReqMappingKey);
+ && !HeatToToscaUtil.isHeatFileNested(translateTo, translateTo.getHeatFileName())) {
+ addLinkToNetworkRequirementAssignment(substitutedNodeTemplate,
+ translatedSharedResourceId.getTranslatedId(), portReqMappingKey);
}
- } else {
- logger.warn("Heat resource: '" + translateTo.getResourceId() + "' with type: '"
- + translateTo.getResource().getType()
- + "' include 'virtual_network' property with value '"
- + virtualNetworkValue.toString()
- + "', the connection to this network wasn't found/not supported therefore this "
- + "connection will be ignored in TOSCA translation for this property.");
- }
- }
- } else {
- logger.warn("Heat resource: '" + translateTo.getResourceId() + "' with type: '"
- + translateTo.getResource().getType()
- + "' missing 'virtual_network' property in 'interface_list' entry, therefore, no "
- + "network connection is define for this entry.");
- }
+ } else {
+ logger.warn(LOG_INVALID_NETWORK_CONNECTION, translateTo.getResourceId(),
+ translateTo.getResource().getType(), virtualNetworkValue.toString());
+ }
}
- }
-
- private NodeTemplate createPortNodeTemplate(Integer index, boolean orderedInterfaces,
- String computeNodeTemplateId) {
- NodeTemplate portNodeTemplate = new NodeTemplate();
- portNodeTemplate.setType(ToscaNodeType.CONTRAIL_PORT);
- Map<String, Object> portProperties = new HashMap<>();
- portProperties.put("static_routes", DataModelUtil
- .createGetInputPropertyValueFromListParameter("interface_list", index, "static_routes"));
- portProperties.put("virtual_network", DataModelUtil
- .createGetInputPropertyValueFromListParameter("interface_list", index, "virtual_network"));
- portProperties.put("allowed_address_pairs", DataModelUtil
- .createGetInputPropertyValueFromListParameter("interface_list", index,
- "allowed_address_pairs"));
- portProperties.put("ip_address", DataModelUtil
- .createGetInputPropertyValueFromListParameter("interface_list", index, "ip_address"));
- portProperties.put("static_route",
- DataModelUtil.createGetInputPropertyValueFromListParameter("static_routes_list", index));
- portProperties.put("shared_ip",
- DataModelUtil.createGetInputPropertyValueFromListParameter("shared_ip_list", index));
- portProperties.put("interface_type", DataModelUtil
- .createGetInputPropertyValueFromListParameter("service_interface_type_list", index));
- if (orderedInterfaces) {
- portProperties.put("order", index);
+
+ private NodeTemplate createPortNodeTemplate(Integer index, boolean orderedInterfaces,
+ String computeNodeTemplateId) {
+ NodeTemplate portNodeTemplate = new NodeTemplate();
+ portNodeTemplate.setType(ToscaNodeType.CONTRAIL_PORT);
+ Map<String, Object> portProperties = new HashMap<>();
+ portProperties.put("static_routes", DataModelUtil
+ .createGetInputPropertyValueFromListParameter(INTERFACE_LIST, index, "static_routes"));
+ portProperties.put("virtual_network", DataModelUtil
+ .createGetInputPropertyValueFromListParameter(INTERFACE_LIST, index, "virtual_network"));
+ portProperties.put("allowed_address_pairs", DataModelUtil
+ .createGetInputPropertyValueFromListParameter(INTERFACE_LIST, index,
+ "allowed_address_pairs"));
+ portProperties.put("ip_address", DataModelUtil
+ .createGetInputPropertyValueFromListParameter(INTERFACE_LIST, index, "ip_address"));
+ portProperties.put("static_route",
+ DataModelUtil.createGetInputPropertyValueFromListParameter("static_routes_list", index));
+ portProperties.put("shared_ip",
+ DataModelUtil.createGetInputPropertyValueFromListParameter("shared_ip_list", index));
+ portProperties.put("interface_type", DataModelUtil
+ .createGetInputPropertyValueFromListParameter("service_interface_type_list", index));
+ if (orderedInterfaces) {
+ portProperties.put("order", index);
+ }
+ portNodeTemplate.setProperties(portProperties);
+ DataModelUtil.addBindingReqFromPortToCompute(computeNodeTemplateId, portNodeTemplate);
+ return portNodeTemplate;
}
- portNodeTemplate.setProperties(portProperties);
- DataModelUtil.addBindingReqFromPortToCompute(computeNodeTemplateId, portNodeTemplate);
- return portNodeTemplate;
- }
- private void addLinkToNetworkRequirementAssignment(NodeTemplate nodeTemplate,
- String connectedNodeTranslatedId,
- String requirementId) {
- if (nodeTemplate == null || connectedNodeTranslatedId == null) {
- return;
+ private void addLinkToNetworkRequirementAssignment(NodeTemplate nodeTemplate,
+ String connectedNodeTranslatedId,
+ String requirementId) {
+ if (nodeTemplate == null || connectedNodeTranslatedId == null) {
+ return;
+ }
+ RequirementAssignment requirement = new RequirementAssignment();
+ requirement.setCapability(ToscaCapabilityType.NATIVE_NETWORK_LINKABLE);
+ requirement.setRelationship(ToscaRelationshipType.NATIVE_NETWORK_LINK_TO);
+ requirement.setNode(connectedNodeTranslatedId);
+ DataModelUtil.addRequirementAssignment(nodeTemplate, requirementId, requirement);
}
- RequirementAssignment requirement = new RequirementAssignment();
- requirement.setCapability(ToscaCapabilityType.NATIVE_NETWORK_LINKABLE);
- requirement.setRelationship(ToscaRelationshipType.NATIVE_NETWORK_LINK_TO);
- requirement.setNode(connectedNodeTranslatedId);
- DataModelUtil.addRequirementAssignment(nodeTemplate, requirementId, requirement);
- }
-
- private void updateHeatStackGroup(ServiceTemplate serviceTemplate, String heatStackGroupKey,
- String memberId) {
- serviceTemplate.getTopology_template().getGroups().get(heatStackGroupKey).getMembers()
- .add(memberId);
- }
-
- private void updateSubstitutionMappingRequirement(ServiceTemplate serviceTemplate,
- String portReqMappingKey,
- String portNodeTemplateId) {
- List<String> portReqMappingValue = new ArrayList<>();
- portReqMappingValue.add(portNodeTemplateId);
- portReqMappingValue.add(ToscaConstants.LINK_REQUIREMENT_ID);
- DataModelUtil
- .addSubstitutionMappingReq(serviceTemplate, portReqMappingKey, portReqMappingValue);
- }
-
- private void addSubstitutionMappingEntry(ServiceTemplate nestedSubstitutionServiceTemplate,
- String substitutedNodeTypeId) {
- SubstitutionMapping substitutionMappings = new SubstitutionMapping();
- substitutionMappings.setNode_type(substitutedNodeTypeId);
- DataModelUtil.addSubstitutionMapping(nestedSubstitutionServiceTemplate, substitutionMappings);
- }
-
- private void handleInputParameters(ServiceTemplate nestedSubstitutionServiceTemplate,
- TranslateTo translateTo) {
- ToscaAnalyzerService toscaAnalyzerService = new ToscaAnalyzerServiceImpl();
-
- Optional<NodeType> contrailAbstractNodeType =
- toscaAnalyzerService.fetchNodeType(ToscaNodeType.CONTRAIL_ABSTRACT_SUBSTITUTE, translateTo
- .getContext().getGlobalServiceTemplates().values());
- Map<String, ParameterDefinition> nestedSubstitutionServiceTemplateInputs = new HashMap<>();
- if (contrailAbstractNodeType.isPresent()) {
- Map<String, PropertyDefinition> contrailAbstractProperties =
- contrailAbstractNodeType.get().getProperties();
-
- for (String propertyKey : contrailAbstractProperties.keySet()) {
- PropertyDefinition abstractPropertyDef = contrailAbstractProperties.get(propertyKey);
- if (abstractPropertyDef != null) {
- nestedSubstitutionServiceTemplateInputs
- .put(propertyKey,
- DataModelUtil.convertPropertyDefToParameterDef(abstractPropertyDef));
-
- }
- }
+ private void updateHeatStackGroup(ServiceTemplate serviceTemplate, String heatStackGroupKey,
+ String memberId) {
+ serviceTemplate.getTopology_template().getGroups().get(heatStackGroupKey).getMembers().add(memberId);
}
- if (!nestedSubstitutionServiceTemplateInputs.isEmpty()) {
- nestedSubstitutionServiceTemplate.getTopology_template()
- .setInputs(nestedSubstitutionServiceTemplateInputs);
+
+ private void updateSubstitutionMappingRequirement(ServiceTemplate serviceTemplate,
+ String portReqMappingKey,
+ String portNodeTemplateId) {
+ List<String> portReqMappingValue = new ArrayList<>();
+ portReqMappingValue.add(portNodeTemplateId);
+ portReqMappingValue.add(ToscaConstants.LINK_REQUIREMENT_ID);
+ DataModelUtil.addSubstitutionMappingReq(serviceTemplate, portReqMappingKey, portReqMappingValue);
}
- }
-
- private String handleComputeNodeTemplate(TranslateTo translateTo, String computeNodeTypeId,
- ServiceTemplate nestedSubstitutionServiceTemplate,
- String heatStackGroupKey) {
- ToscaAnalyzerService toscaAnalyzerService = new ToscaAnalyzerServiceImpl();
- Optional<NodeType> contrailComputeNodeType = toscaAnalyzerService
- .fetchNodeType(ToscaNodeType.CONTRAIL_COMPUTE,
- translateTo.getContext().getGlobalServiceTemplates().values());
-
- Map<String, Object> computeNodeTemplateProperties = null;
- if (contrailComputeNodeType.isPresent()) {
- Map<String, PropertyDefinition> contrailComputeProperties =
- contrailComputeNodeType.get().getProperties();
- computeNodeTemplateProperties = new HashMap<>();
-
- if (contrailComputeProperties != null) {
- for (String computePropertyKey : contrailComputeProperties.keySet()) {
- Map getInputProperty = new HashMap<>();
- getInputProperty.put(ToscaFunctions.GET_INPUT.getDisplayName(), computePropertyKey);
- computeNodeTemplateProperties.put(computePropertyKey, getInputProperty);
- }
- }
+
+ private void addSubstitutionMappingEntry(ServiceTemplate nestedSubstitutionServiceTemplate,
+ String substitutedNodeTypeId) {
+ SubstitutionMapping substitutionMappings = new SubstitutionMapping();
+ substitutionMappings.setNode_type(substitutedNodeTypeId);
+ DataModelUtil.addSubstitutionMapping(nestedSubstitutionServiceTemplate, substitutionMappings);
+ }
+
+ private void handleInputParameters(ServiceTemplate nestedSubstitutionServiceTemplate,
+ TranslateTo translateTo) {
+ ToscaAnalyzerService toscaAnalyzerService = new ToscaAnalyzerServiceImpl();
+ Optional<NodeType> contrailAbstractNodeType = toscaAnalyzerService.fetchNodeType(ToscaNodeType
+ .CONTRAIL_ABSTRACT_SUBSTITUTE, translateTo.getContext().getGlobalServiceTemplates().values());
+ Map<String, ParameterDefinition> nestedSubstitutionServiceTemplateInputs = new HashMap<>();
+ if (contrailAbstractNodeType.isPresent()) {
+ Map<String, PropertyDefinition> contrailAbstractProperties = contrailAbstractNodeType.get().getProperties();
+ for (Map.Entry<String, PropertyDefinition> propertyEntry : contrailAbstractProperties.entrySet()) {
+ PropertyDefinition abstractPropertyDef = contrailAbstractProperties.get(propertyEntry.getKey());
+ if (abstractPropertyDef != null) {
+ nestedSubstitutionServiceTemplateInputs.put(propertyEntry.getKey(),
+ DataModelUtil.convertPropertyDefToParameterDef(abstractPropertyDef));
+ }
+ }
+ }
+ if (!nestedSubstitutionServiceTemplateInputs.isEmpty()) {
+ nestedSubstitutionServiceTemplate.getTopology_template().setInputs(nestedSubstitutionServiceTemplateInputs);
+ }
}
- NodeTemplate computeNodeTemplate = new NodeTemplate();
- computeNodeTemplate.setType(computeNodeTypeId);
- if (computeNodeTemplateProperties != null && !computeNodeTemplateProperties.isEmpty()) {
- computeNodeTemplate.setProperties(computeNodeTemplateProperties);
+ private String handleComputeNodeTemplate(TranslateTo translateTo, String computeNodeTypeId,
+ ServiceTemplate nestedSubstitutionServiceTemplate,
+ String heatStackGroupKey) {
+ ToscaAnalyzerService toscaAnalyzerService = new ToscaAnalyzerServiceImpl();
+ Optional<NodeType> contrailComputeNodeType = toscaAnalyzerService.fetchNodeType(ToscaNodeType.CONTRAIL_COMPUTE,
+ translateTo.getContext().getGlobalServiceTemplates().values());
+ Map<String, Object> computeNodeTemplateProperties = null;
+ if (contrailComputeNodeType.isPresent()) {
+ Map<String, PropertyDefinition> contrailComputeProperties = contrailComputeNodeType.get().getProperties();
+ computeNodeTemplateProperties = new HashMap<>();
+ if (contrailComputeProperties != null) {
+ for (String computePropertyKey : contrailComputeProperties.keySet()) {
+ Map<String, Object> getInputProperty = new HashMap<>();
+ getInputProperty.put(ToscaFunctions.GET_INPUT.getDisplayName(), computePropertyKey);
+ computeNodeTemplateProperties.put(computePropertyKey, getInputProperty);
+ }
+ }
+ }
+
+ NodeTemplate computeNodeTemplate = new NodeTemplate();
+ computeNodeTemplate.setType(computeNodeTypeId);
+ if (computeNodeTemplateProperties != null && !computeNodeTemplateProperties.isEmpty()) {
+ computeNodeTemplate.setProperties(computeNodeTemplateProperties);
+ }
+ String computeNodeTemplateId = translateTo.getTranslatedId();
+ DataModelUtil.addNodeTemplate(nestedSubstitutionServiceTemplate, computeNodeTemplateId, computeNodeTemplate);
+ nestedSubstitutionServiceTemplate.getTopology_template().getGroups().get(heatStackGroupKey)
+ .getMembers().add(computeNodeTemplateId);
+ return computeNodeTemplateId;
}
- String computeNodeTemplateId = translateTo.getTranslatedId();
- DataModelUtil.addNodeTemplate(nestedSubstitutionServiceTemplate, computeNodeTemplateId,
- computeNodeTemplate);
- nestedSubstitutionServiceTemplate.getTopology_template().getGroups().get(heatStackGroupKey)
- .getMembers().add(computeNodeTemplateId);
- return computeNodeTemplateId;
- }
-
- private String addHeatStackGroup(TranslateTo translateTo, ServiceTemplate serviceTemplate) {
- GroupDefinition serviceInstanceGroupDefinition = new GroupDefinition();
- serviceInstanceGroupDefinition.setType(ToscaGroupType.HEAT_STACK);
- Map<String, Object> groupProperties = new HashMap<>();
- groupProperties.put("heat_file",
- "../" + (new ToscaFileOutputServiceCsarImpl()).getArtifactsFolderName() + "/"
- + translateTo.getHeatFileName());
- serviceInstanceGroupDefinition.setProperties(groupProperties);
- serviceInstanceGroupDefinition.setMembers(new ArrayList<>());
- String heatStackGroupKey = translateTo.getTranslatedId() + "_group";
- DataModelUtil.addGroupDefinitionToTopologyTemplate(serviceTemplate, heatStackGroupKey,
- serviceInstanceGroupDefinition);
- return heatStackGroupKey;
- }
-
-
- private void setNestedServiceTemplateGeneralDetails(TranslateTo translateTo,
- ServiceTemplate
- nestedSubstitutionServiceTemplate) {
- Map<String, String> nestedTemplateMetadata = new HashMap<>();
- String nestedTemplateName = new ContrailTranslationHelper()
- .getSubstitutionContrailServiceTemplateMetadata(translateTo.getHeatFileName(),
- translateTo.getResourceId());
- nestedTemplateMetadata.put(ToscaConstants.ST_METADATA_TEMPLATE_NAME, nestedTemplateName);
- nestedSubstitutionServiceTemplate.setMetadata(nestedTemplateMetadata);
- nestedSubstitutionServiceTemplate
- .setTosca_definitions_version(ToscaConstants.TOSCA_DEFINITIONS_VERSION);
- nestedSubstitutionServiceTemplate.setTopology_template(new TopologyTemplate());
- List<Map<String, Import>> globalTypesImportList =
- GlobalTypesGenerator.getGlobalTypesImportList();
- globalTypesImportList.addAll(
- HeatToToscaUtil.createImportList(Constants.GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME));
- nestedSubstitutionServiceTemplate.setImports(globalTypesImportList);
- }
-
- private NodeTemplate createSubstitutedNodeTemplate(TranslateTo translateTo,
- Resource contrailServiceTemplateResource,
- String contrailServiceTemplateTranslatedId,
- int numberOfPorts) {
- boolean isImportAddedToServiceTemplate =
- DataModelUtil
- .isImportAddedToServiceTemplate(translateTo.getServiceTemplate().getImports(), Constants
- .GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME);
- if (!isImportAddedToServiceTemplate) {
- translateTo.getServiceTemplate().getImports()
- .addAll(HeatToToscaUtil
- .createImportList(Constants.GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME));
+
+ private String addHeatStackGroup(TranslateTo translateTo, ServiceTemplate serviceTemplate) {
+ GroupDefinition serviceInstanceGroupDefinition = new GroupDefinition();
+ serviceInstanceGroupDefinition.setType(ToscaGroupType.HEAT_STACK);
+ Map<String, Object> groupProperties = new HashMap<>();
+ groupProperties.put("heat_file",
+ "../" + (new ToscaFileOutputServiceCsarImpl()).getArtifactsFolderName() + "/"
+ + translateTo.getHeatFileName());
+ serviceInstanceGroupDefinition.setProperties(groupProperties);
+ serviceInstanceGroupDefinition.setMembers(new ArrayList<>());
+ String heatStackGroupKey = translateTo.getTranslatedId() + "_group";
+ DataModelUtil.addGroupDefinitionToTopologyTemplate(serviceTemplate, heatStackGroupKey,
+ serviceInstanceGroupDefinition);
+ return heatStackGroupKey;
}
- NodeTemplate substitutesNodeTemplate = new NodeTemplate();
- substitutesNodeTemplate.setType(contrailServiceTemplateTranslatedId);
- List<String> directiveList = new ArrayList<>();
- directiveList.add(ToscaConstants.NODE_TEMPLATE_DIRECTIVE_SUBSTITUTABLE);
- substitutesNodeTemplate.setDirectives(directiveList);
- substitutesNodeTemplate.setProperties(TranslatorHeatToToscaPropertyConverter
- .getToscaPropertiesSimpleConversion(translateTo.getServiceTemplate(), translateTo.
- getResourceId(), translateTo.getResource().getProperties(),
- substitutesNodeTemplate.getProperties(), translateTo.getHeatFileName(),
- translateTo.getHeatOrchestrationTemplate(),
- HeatResourcesTypes.CONTRAIL_SERVICE_INSTANCE.getHeatResource(), substitutesNodeTemplate,
- translateTo.getContext()));
- substitutesNodeTemplate.setProperties(TranslatorHeatToToscaPropertyConverter
- .getToscaPropertiesSimpleConversion(translateTo.getServiceTemplate(), translateTo.
- getResourceId(), contrailServiceTemplateResource.getProperties(),
- substitutesNodeTemplate.getProperties(), translateTo.getHeatFileName(),
- translateTo.getHeatOrchestrationTemplate(),
- HeatResourcesTypes.CONTRAIL_SERVICE_TEMPLATE.getHeatResource(), substitutesNodeTemplate,
- translateTo.getContext()));
- HeatToToscaUtil.mapBoolean(substitutesNodeTemplate, HeatToToscaUtil
- .getToscaPropertyName(translateTo.getContext(), contrailServiceTemplateResource.getType(),
- HeatConstants.AVAILABILITY_ZONE_ENABLE_PROPERTY_NAME));
- HeatToToscaUtil.mapBoolean(substitutesNodeTemplate, HeatToToscaUtil
- .getToscaPropertyName(translateTo.getContext(), contrailServiceTemplateResource.getType(),
- HeatConstants.ORDERED_INTERFACES_PROPERTY_NAME));
-
- Object sharedIpListPropertyValue =
- contrailServiceTemplateResource.getProperties()
- .get(HeatConstants.SHARED_IP_LIST_PROPERTY_NAME);
- String toscaSharedIpListPropertyName = HeatToToscaUtil
- .getToscaPropertyName(translateTo.getContext(), contrailServiceTemplateResource.getType(),
- HeatConstants.SHARED_IP_LIST_PROPERTY_NAME);
- Optional<List<Map<String, List>>> sharedIpTranslatedSplitFun =
- new ContrailTranslationHelper()
- .translateFnSplitFunction(sharedIpListPropertyValue, numberOfPorts, true);
- if (sharedIpTranslatedSplitFun.isPresent()) {
- substitutesNodeTemplate.getProperties()
- .put(toscaSharedIpListPropertyName, sharedIpTranslatedSplitFun.get());
- } else {
- HeatToToscaUtil.mapBooleanList(substitutesNodeTemplate, toscaSharedIpListPropertyName);
+
+
+ private void setNestedServiceTemplateGeneralDetails(TranslateTo translateTo,
+ ServiceTemplate
+ nestedSubstitutionServiceTemplate) {
+ Map<String, String> nestedTemplateMetadata = new HashMap<>();
+ String nestedTemplateName = new ContrailTranslationHelper()
+ .getSubstitutionContrailServiceTemplateMetadata(translateTo.getHeatFileName(),
+ translateTo.getResourceId());
+ nestedTemplateMetadata.put(ToscaConstants.ST_METADATA_TEMPLATE_NAME, nestedTemplateName);
+ nestedSubstitutionServiceTemplate.setMetadata(nestedTemplateMetadata);
+ nestedSubstitutionServiceTemplate.setTosca_definitions_version(ToscaConstants.TOSCA_DEFINITIONS_VERSION);
+ nestedSubstitutionServiceTemplate.setTopology_template(new TopologyTemplate());
+ List<Map<String, Import>> globalTypesImportList = GlobalTypesGenerator.getGlobalTypesImportList();
+ globalTypesImportList.addAll(
+ HeatToToscaUtil.createImportList(Constants.GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME));
+ nestedSubstitutionServiceTemplate.setImports(globalTypesImportList);
}
- Object staticRouteListPropertyValue =
- contrailServiceTemplateResource.getProperties()
- .get(HeatConstants.STATIC_ROUTES_LIST_PROPERTY_NAME);
- String toscaStaticRoutesListPropertyName = HeatToToscaUtil
- .getToscaPropertyName(translateTo.getContext(), contrailServiceTemplateResource.getType(),
- HeatConstants.STATIC_ROUTES_LIST_PROPERTY_NAME);
- Optional<List<Map<String, List>>> staticRouteTranslatedSplitFun =
- new ContrailTranslationHelper()
- .translateFnSplitFunction(staticRouteListPropertyValue, numberOfPorts, true);
- if (staticRouteTranslatedSplitFun.isPresent()) {
- substitutesNodeTemplate.getProperties()
- .put(toscaStaticRoutesListPropertyName, staticRouteTranslatedSplitFun.get());
- } else {
- HeatToToscaUtil.mapBooleanList(substitutesNodeTemplate, toscaStaticRoutesListPropertyName);
+ private NodeTemplate createSubstitutedNodeTemplate(TranslateTo translateTo,
+ Resource contrailServiceTemplateResource,
+ String contrailServiceTemplateTranslatedId,
+ int numberOfPorts) {
+ boolean isImportAddedToServiceTemplate =
+ DataModelUtil
+ .isImportAddedToServiceTemplate(translateTo.getServiceTemplate().getImports(), Constants
+ .GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME);
+ if (!isImportAddedToServiceTemplate) {
+ translateTo.getServiceTemplate().getImports()
+ .addAll(HeatToToscaUtil
+ .createImportList(Constants.GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME));
+ }
+ NodeTemplate substitutesNodeTemplate = new NodeTemplate();
+ substitutesNodeTemplate.setType(contrailServiceTemplateTranslatedId);
+ List<String> directiveList = new ArrayList<>();
+ directiveList.add(ToscaConstants.NODE_TEMPLATE_DIRECTIVE_SUBSTITUTABLE);
+ substitutesNodeTemplate.setDirectives(directiveList);
+ substitutesNodeTemplate.setProperties(TranslatorHeatToToscaPropertyConverter
+ .getToscaPropertiesSimpleConversion(translateTo.getServiceTemplate(),
+ translateTo.getResourceId(), translateTo.getResource().getProperties(),
+ substitutesNodeTemplate.getProperties(), translateTo.getHeatFileName(),
+ translateTo.getHeatOrchestrationTemplate(),
+ HeatResourcesTypes.CONTRAIL_SERVICE_INSTANCE.getHeatResource(), substitutesNodeTemplate,
+ translateTo.getContext()));
+ substitutesNodeTemplate.setProperties(TranslatorHeatToToscaPropertyConverter
+ .getToscaPropertiesSimpleConversion(translateTo.getServiceTemplate(),
+ translateTo.getResourceId(), contrailServiceTemplateResource.getProperties(),
+ substitutesNodeTemplate.getProperties(), translateTo.getHeatFileName(),
+ translateTo.getHeatOrchestrationTemplate(),
+ HeatResourcesTypes.CONTRAIL_SERVICE_TEMPLATE.getHeatResource(), substitutesNodeTemplate,
+ translateTo.getContext()));
+ HeatToToscaUtil.mapBoolean(substitutesNodeTemplate, HeatToToscaUtil
+ .getToscaPropertyName(translateTo.getContext(), contrailServiceTemplateResource.getType(),
+ HeatConstants.AVAILABILITY_ZONE_ENABLE_PROPERTY_NAME));
+ HeatToToscaUtil.mapBoolean(substitutesNodeTemplate, HeatToToscaUtil
+ .getToscaPropertyName(translateTo.getContext(), contrailServiceTemplateResource.getType(),
+ HeatConstants.ORDERED_INTERFACES_PROPERTY_NAME));
+
+ Object sharedIpListPropertyValue =
+ contrailServiceTemplateResource.getProperties()
+ .get(HeatConstants.SHARED_IP_LIST_PROPERTY_NAME);
+ String toscaSharedIpListPropertyName = HeatToToscaUtil
+ .getToscaPropertyName(translateTo.getContext(), contrailServiceTemplateResource.getType(),
+ HeatConstants.SHARED_IP_LIST_PROPERTY_NAME);
+ Optional<List<Map<String, List>>> sharedIpTranslatedSplitFun =
+ new ContrailTranslationHelper()
+ .translateFnSplitFunction(sharedIpListPropertyValue, numberOfPorts, true);
+ if (sharedIpTranslatedSplitFun.isPresent()) {
+ substitutesNodeTemplate.getProperties()
+ .put(toscaSharedIpListPropertyName, sharedIpTranslatedSplitFun.get());
+ } else {
+ HeatToToscaUtil.mapBooleanList(substitutesNodeTemplate, toscaSharedIpListPropertyName);
+ }
+
+ Object staticRouteListPropertyValue =
+ contrailServiceTemplateResource.getProperties()
+ .get(HeatConstants.STATIC_ROUTES_LIST_PROPERTY_NAME);
+ String toscaStaticRoutesListPropertyName = HeatToToscaUtil
+ .getToscaPropertyName(translateTo.getContext(), contrailServiceTemplateResource.getType(),
+ HeatConstants.STATIC_ROUTES_LIST_PROPERTY_NAME);
+ Optional<List<Map<String, List>>> staticRouteTranslatedSplitFun =
+ new ContrailTranslationHelper()
+ .translateFnSplitFunction(staticRouteListPropertyValue, numberOfPorts, true);
+ if (staticRouteTranslatedSplitFun.isPresent()) {
+ substitutesNodeTemplate.getProperties()
+ .put(toscaStaticRoutesListPropertyName, staticRouteTranslatedSplitFun.get());
+ } else {
+ HeatToToscaUtil.mapBooleanList(substitutesNodeTemplate, toscaStaticRoutesListPropertyName);
+ }
+
+ Object serviceInterfaceTypeListPropertyValue =
+ contrailServiceTemplateResource.getProperties()
+ .get(HeatConstants.SERVICE_INTERFCAE_TYPE_LIST_PROPERTY_NAME);
+ String toscaServiceInterfaceTypeListPropertyName = HeatToToscaUtil
+ .getToscaPropertyName(translateTo.getContext(), contrailServiceTemplateResource.getType(),
+ HeatConstants.SERVICE_INTERFCAE_TYPE_LIST_PROPERTY_NAME);
+ Optional<List<Map<String, List>>> serviceInterfaceTypeTranslatedSplitFun =
+ new ContrailTranslationHelper()
+ .translateFnSplitFunction(serviceInterfaceTypeListPropertyValue, numberOfPorts, false);
+ serviceInterfaceTypeTranslatedSplitFun
+ .ifPresent(translatedSplitFun -> substitutesNodeTemplate.getProperties()
+ .put(toscaServiceInterfaceTypeListPropertyName, translatedSplitFun));
+
+ String substitutedNodeTemplateId = translateTo.getTranslatedId();
+ DataModelUtil.addNodeTemplate(translateTo.getServiceTemplate(), substitutedNodeTemplateId,
+ substitutesNodeTemplate);
+ return substitutesNodeTemplate;
}
- Object serviceInterfaceTypeListPropertyValue =
- contrailServiceTemplateResource.getProperties()
- .get(HeatConstants.SERVICE_INTERFCAE_TYPE_LIST_PROPERTY_NAME);
- String toscaServiceInterfaceTypeListPropertyName = HeatToToscaUtil
- .getToscaPropertyName(translateTo.getContext(), contrailServiceTemplateResource.getType(),
- HeatConstants.SERVICE_INTERFCAE_TYPE_LIST_PROPERTY_NAME);
- Optional<List<Map<String, List>>> serviceInterfaceTypeTranslatedSplitFun =
- new ContrailTranslationHelper()
- .translateFnSplitFunction(serviceInterfaceTypeListPropertyValue, numberOfPorts, false);
- serviceInterfaceTypeTranslatedSplitFun
- .ifPresent(translatedSplitFun -> substitutesNodeTemplate.getProperties()
- .put(toscaServiceInterfaceTypeListPropertyName, translatedSplitFun));
-
- String substitutedNodeTemplateId = translateTo.getTranslatedId();
- DataModelUtil.addNodeTemplate(translateTo.getServiceTemplate(), substitutedNodeTemplateId,
- substitutesNodeTemplate);
- return substitutesNodeTemplate;
- }
-
- private void addNetworkLinkRequirements(NodeType nodeType, int numberOfPorts) {
- if (nodeType.getRequirements() == null) {
- List<Map<String, RequirementDefinition>> requirementList = new ArrayList<>();
- for (int i = 0; i < numberOfPorts; i++) {
- Map<String, RequirementDefinition> requirementDefinitionMap = new HashMap<>();
- requirementDefinitionMap.put(ToscaConstants.LINK_REQUIREMENT_ID + "_port_" + i,
- DataModelUtil.createRequirement(ToscaCapabilityType.NATIVE_NETWORK_LINKABLE,
- ToscaNodeType.NATIVE_ROOT,
- ToscaRelationshipType.NATIVE_NETWORK_LINK_TO, null));
- requirementList.add(requirementDefinitionMap);
- }
- if (numberOfPorts > 0) {
- nodeType.setRequirements(requirementList);
- }
+ private void addNetworkLinkRequirements(NodeType nodeType, int numberOfPorts) {
+ if (nodeType.getRequirements() == null) {
+ List<Map<String, RequirementDefinition>> requirementList = new ArrayList<>();
+ for (int i = 0; i < numberOfPorts; i++) {
+ Map<String, RequirementDefinition> requirementDefinitionMap = new HashMap<>();
+ requirementDefinitionMap.put(ToscaConstants.LINK_REQUIREMENT_ID + "_port_" + i,
+ DataModelUtil.createRequirement(ToscaCapabilityType.NATIVE_NETWORK_LINKABLE,
+ ToscaNodeType.NATIVE_ROOT,
+ ToscaRelationshipType.NATIVE_NETWORK_LINK_TO, null));
+ requirementList.add(requirementDefinitionMap);
+ }
+ if (numberOfPorts > 0) {
+ nodeType.setRequirements(requirementList);
+ }
+ }
}
- }
-
- private int getServiceInstanceNumberOfPorts(Resource serviceInstanceResource) {
- int numberOfPorts;
- Object interfaceTypeProperty =
- serviceInstanceResource.getProperties().get(HeatConstants.INTERFACE_LIST_PROPERTY_NAME);
- if (interfaceTypeProperty == null) {
- numberOfPorts = 0;
- } else if (interfaceTypeProperty instanceof List) {
- numberOfPorts = ((List) interfaceTypeProperty).size();
- } else if (interfaceTypeProperty instanceof Map) {
- numberOfPorts = 1;
- } else {
- numberOfPorts = 0;
+
+ private int getServiceInstanceNumberOfPorts(Resource serviceInstanceResource) {
+ int numberOfPorts;
+ Object interfaceTypeProperty =
+ serviceInstanceResource.getProperties().get(HeatConstants.INTERFACE_LIST_PROPERTY_NAME);
+ if (interfaceTypeProperty == null) {
+ numberOfPorts = 0;
+ } else if (interfaceTypeProperty instanceof List) {
+ numberOfPorts = ((List) interfaceTypeProperty).size();
+ } else if (interfaceTypeProperty instanceof Map) {
+ numberOfPorts = 1;
+ } else {
+ numberOfPorts = 0;
+ }
+ return numberOfPorts;
}
- return numberOfPorts;
- }
-
- private AttachedResourceId getServiceTemplateAttachedId(TranslateTo translateTo,
- Resource serviceInstanceResource) {
- Object serviceTemplateProperty =
- serviceInstanceResource.getProperties().get("service_template");
- Optional<AttachedResourceId> serviceTemplateId = HeatToToscaUtil
- .extractAttachedResourceId(translateTo.getHeatFileName(),
- translateTo.getHeatOrchestrationTemplate(), translateTo.getContext(),
- serviceTemplateProperty);
- if (serviceTemplateId.isPresent()) {
- return serviceTemplateId.get();
- } else {
- throw new CoreException(new MissingMandatoryPropertyErrorBuilder("service_template").build());
+
+ private AttachedResourceId getServiceTemplateAttachedId(TranslateTo translateTo,
+ Resource serviceInstanceResource) {
+ Object serviceTemplateProperty =
+ serviceInstanceResource.getProperties().get("service_template");
+ Optional<AttachedResourceId> serviceTemplateId = HeatToToscaUtil
+ .extractAttachedResourceId(translateTo.getHeatFileName(),
+ translateTo.getHeatOrchestrationTemplate(), translateTo.getContext(),
+ serviceTemplateProperty);
+ if (serviceTemplateId.isPresent()) {
+ return serviceTemplateId.get();
+ } else {
+ throw new CoreException(new MissingMandatoryPropertyErrorBuilder("service_template").build());
+ }
}
- }
}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationContrailServiceTemplateImpl.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationContrailServiceTemplateImpl.java
index d9867c0626..211ffeddbf 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationContrailServiceTemplateImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationContrailServiceTemplateImpl.java
@@ -1,30 +1,31 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
* 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.translator.services.heattotosca.impl.resourcetranslation;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+
+import org.onap.sdc.tosca.datatypes.model.NodeType;
+import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
import org.openecomp.sdc.common.errors.CoreException;
import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
import org.openecomp.sdc.tosca.datatypes.ToscaTopologyTemplateElements;
-import org.onap.sdc.tosca.datatypes.model.NodeType;
-import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
import org.openecomp.sdc.tosca.services.DataModelUtil;
import org.openecomp.sdc.tosca.services.ToscaConstants;
import org.openecomp.sdc.translator.datatypes.heattotosca.TranslationContext;
@@ -34,78 +35,70 @@ import org.openecomp.sdc.translator.services.heattotosca.errors.MissingMandatory
import org.openecomp.sdc.translator.services.heattotosca.globaltypes.GlobalTypesGenerator;
import org.openecomp.sdc.translator.services.heattotosca.helper.ContrailTranslationHelper;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-
public class ResourceTranslationContrailServiceTemplateImpl extends ResourceTranslationBase {
- static String getContrailSubstitutedNodeTypeId(String serviceTemplateTranslatedId) {
- return ToscaNodeType.ABSTRACT_NODE_TYPE_PREFIX + "heat." + serviceTemplateTranslatedId;
- }
+ private static final String IMAGE_NAME = "image_name";
+
+ static String getContrailSubstitutedNodeTypeId(String serviceTemplateTranslatedId) {
+ return ToscaNodeType.ABSTRACT_NODE_TYPE_PREFIX + ToscaConstants.HEAT_NODE_TYPE_SUFFIX
+ + serviceTemplateTranslatedId;
+ }
- @Override
- public void translate(TranslateTo translateTo) {
- ServiceTemplate globalSubstitutionServiceTemplate =
- getGlobalSubstitutionTypesServiceTemplate(translateTo);
- addSubstitutedNodeType(translateTo, globalSubstitutionServiceTemplate);
- addComputeNodeType(translateTo, globalSubstitutionServiceTemplate, translateTo.getContext());
- }
+ @Override
+ public void translate(TranslateTo translateTo) {
+ ServiceTemplate globalSubstitutionServiceTemplate = getGlobalSubstitutionTypesServiceTemplate(translateTo);
+ addSubstitutedNodeType(translateTo, globalSubstitutionServiceTemplate);
+ addComputeNodeType(translateTo, globalSubstitutionServiceTemplate, translateTo.getContext());
+ }
- @Override
- protected boolean isEssentialRequirementsValid(TranslateTo translateTo) {
- Map<String, Object> properties = translateTo.getResource().getProperties();
- if (Objects.isNull(properties) || Objects.isNull(properties.get("image_name"))) {
- throw new CoreException(new MissingMandatoryPropertyErrorBuilder("image_name").build());
+ @Override
+ protected boolean isEssentialRequirementsValid(TranslateTo translateTo) {
+ Map<String, Object> properties = translateTo.getResource().getProperties();
+ if (Objects.isNull(properties) || Objects.isNull(properties.get(IMAGE_NAME))) {
+ throw new CoreException(new MissingMandatoryPropertyErrorBuilder(IMAGE_NAME).build());
+ }
+ return true;
}
- return true;
- }
- private void addComputeNodeType(TranslateTo translateTo,
- ServiceTemplate globalSubstitutionServiceTemplate,
- TranslationContext context) {
- NodeType computeNodeType = new NodeType();
- computeNodeType.setDerived_from(ToscaNodeType.CONTRAIL_COMPUTE);
- String computeNodeTypeId = new ContrailTranslationHelper()
- .getComputeNodeTypeId(translateTo.getResource(), translateTo.getResourceId(),
- translateTo.getTranslatedId(), context);
- DataModelUtil
- .addNodeType(globalSubstitutionServiceTemplate, computeNodeTypeId, computeNodeType);
- }
+ private void addComputeNodeType(TranslateTo translateTo,
+ ServiceTemplate globalSubstitutionServiceTemplate,
+ TranslationContext context) {
+ NodeType computeNodeType = new NodeType();
+ computeNodeType.setDerived_from(ToscaNodeType.CONTRAIL_COMPUTE);
+ String computeNodeTypeId = new ContrailTranslationHelper().getComputeNodeTypeId(translateTo.getResource(),
+ translateTo.getResourceId(), translateTo.getTranslatedId(), context);
+ DataModelUtil.addNodeType(globalSubstitutionServiceTemplate, computeNodeTypeId, computeNodeType);
+ }
- private void addSubstitutedNodeType(TranslateTo translateTo,
- ServiceTemplate globalSubstitutionServiceTemplate) {
- NodeType substitutedNodeType = new NodeType();
- substitutedNodeType
- .setDerived_from(ToscaNodeType.CONTRAIL_ABSTRACT_SUBSTITUTE);
- DataModelUtil.addNodeType(globalSubstitutionServiceTemplate,
- getContrailSubstitutedNodeTypeId(translateTo.getTranslatedId()), substitutedNodeType);
- }
+ private void addSubstitutedNodeType(TranslateTo translateTo,
+ ServiceTemplate globalSubstitutionServiceTemplate) {
+ NodeType substitutedNodeType = new NodeType();
+ substitutedNodeType.setDerived_from(ToscaNodeType.CONTRAIL_ABSTRACT_SUBSTITUTE);
+ DataModelUtil.addNodeType(globalSubstitutionServiceTemplate,
+ getContrailSubstitutedNodeTypeId(translateTo.getTranslatedId()), substitutedNodeType);
+ }
- @Override
- protected Optional<ToscaTopologyTemplateElements> getTranslatedToscaTopologyElement(
- TranslateTo translateTo) {
- return Optional.empty();
- }
+ @Override
+ protected Optional<ToscaTopologyTemplateElements> getTranslatedToscaTopologyElement(
+ TranslateTo translateTo) {
+ return Optional.empty();
+ }
- private ServiceTemplate getGlobalSubstitutionTypesServiceTemplate(TranslateTo translateTo) {
- ServiceTemplate globalSubstitutionServiceTemplate =
- translateTo.getContext().getTranslatedServiceTemplates().get(
- Constants.GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME);
- if (globalSubstitutionServiceTemplate == null) {
- globalSubstitutionServiceTemplate = new ServiceTemplate();
- Map<String, String> templateMetadata = new HashMap<>();
- templateMetadata.put(ToscaConstants.ST_METADATA_TEMPLATE_NAME, Constants.GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME);
- globalSubstitutionServiceTemplate.setMetadata(templateMetadata);
- globalSubstitutionServiceTemplate.setImports(GlobalTypesGenerator.getGlobalTypesImportList());
- globalSubstitutionServiceTemplate
- .setTosca_definitions_version(ToscaConstants.TOSCA_DEFINITIONS_VERSION);
- translateTo.getContext().getTranslatedServiceTemplates()
- .put(Constants.GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME,
- globalSubstitutionServiceTemplate);
+ private ServiceTemplate getGlobalSubstitutionTypesServiceTemplate(TranslateTo translateTo) {
+ ServiceTemplate globalSubstitutionServiceTemplate = translateTo.getContext().getTranslatedServiceTemplates()
+ .get(Constants.GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME);
+ if (globalSubstitutionServiceTemplate == null) {
+ globalSubstitutionServiceTemplate = new ServiceTemplate();
+ Map<String, String> templateMetadata = new HashMap<>();
+ templateMetadata.put(ToscaConstants.ST_METADATA_TEMPLATE_NAME, Constants
+ .GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME);
+ globalSubstitutionServiceTemplate.setMetadata(templateMetadata);
+ globalSubstitutionServiceTemplate.setImports(GlobalTypesGenerator.getGlobalTypesImportList());
+ globalSubstitutionServiceTemplate.setTosca_definitions_version(ToscaConstants.TOSCA_DEFINITIONS_VERSION);
+ translateTo.getContext().getTranslatedServiceTemplates().put(Constants
+ .GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME, globalSubstitutionServiceTemplate);
+ }
+ return globalSubstitutionServiceTemplate;
}
- return globalSubstitutionServiceTemplate;
- }
}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationContrailV2NetworkPolicyImpl.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationContrailV2NetworkPolicyImpl.java
index bb6fa9054c..32aaabc482 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationContrailV2NetworkPolicyImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationContrailV2NetworkPolicyImpl.java
@@ -1,49 +1,43 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
* 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.translator.services.heattotosca.impl.resourcetranslation;
+import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
-import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
import org.openecomp.sdc.tosca.services.DataModelUtil;
import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo;
import org.openecomp.sdc.translator.services.heattotosca.mapping.TranslatorHeatToToscaPropertyConverter;
public class ResourceTranslationContrailV2NetworkPolicyImpl extends ResourceTranslationBase {
- protected static Logger logger =
- (Logger) LoggerFactory.getLogger(ResourceTranslationContrailV2NetworkPolicyImpl.class);
+ protected static Logger logger = LoggerFactory.getLogger(ResourceTranslationContrailV2NetworkPolicyImpl.class);
- @Override
- protected void translate(TranslateTo translateTo) {
- NodeTemplate nodeTemplate = new NodeTemplate();
- nodeTemplate.setType(ToscaNodeType.CONTRAILV2_NETWORK_RULE);
- nodeTemplate.setProperties(TranslatorHeatToToscaPropertyConverter
- .getToscaPropertiesSimpleConversion(translateTo.getServiceTemplate(),translateTo.
- getResourceId(),translateTo.getResource().getProperties(),
- nodeTemplate.getProperties(), translateTo.getHeatFileName(),
- translateTo.getHeatOrchestrationTemplate(), translateTo.getResource().getType(),
- nodeTemplate, translateTo.getContext()));
- DataModelUtil.addNodeTemplate(translateTo.getServiceTemplate(), translateTo.getTranslatedId(),
- nodeTemplate);
- }
+ @Override
+ protected void translate(TranslateTo translateTo) {
+ NodeTemplate nodeTemplate = new NodeTemplate();
+ nodeTemplate.setType(ToscaNodeType.CONTRAILV2_NETWORK_RULE);
+ nodeTemplate.setProperties(TranslatorHeatToToscaPropertyConverter
+ .getToscaPropertiesSimpleConversion(translateTo.getServiceTemplate(),
+ translateTo.getResourceId(), translateTo.getResource().getProperties(),
+ nodeTemplate.getProperties(), translateTo.getHeatFileName(),
+ translateTo.getHeatOrchestrationTemplate(), translateTo.getResource().getType(),
+ nodeTemplate, translateTo.getContext()));
+ DataModelUtil.addNodeTemplate(translateTo.getServiceTemplate(), translateTo.getTranslatedId(), nodeTemplate);
+ }
}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationContrailV2VirtualNetworkImpl.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationContrailV2VirtualNetworkImpl.java
index 5bc36c242e..f2addd0ffe 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationContrailV2VirtualNetworkImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationContrailV2VirtualNetworkImpl.java
@@ -1,35 +1,42 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
* 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.translator.services.heattotosca.impl.resourcetranslation;
+import static org.openecomp.sdc.tosca.services.DataModelUtil.createAttachmentRequirementAssignment;
+import static org.openecomp.sdc.translator.services.heattotosca.HeatToToscaLogConstants.LOG_INVALID_NETWORK_POLICY_REFS_RESOURCE;
+import static org.openecomp.sdc.translator.services.heattotosca.HeatToToscaLogConstants.LOG_INVALID_PROPERTY_FORMAT_GET_ATTR_FQ_NAME;
+import static org.openecomp.sdc.translator.services.heattotosca.HeatToToscaLogConstants.LOG_INVALID_PROPERTY_FORMAT_GET_RESOURCE;
+import static org.openecomp.sdc.translator.services.heattotosca.HeatToToscaLogConstants.LOG_INVALID_PROPERTY_VALUE_FORMAT;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
import org.apache.commons.collections.CollectionUtils;
+import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
import org.openecomp.sdc.heat.datatypes.model.HeatResourcesTypes;
import org.openecomp.sdc.heat.datatypes.model.Resource;
+import org.openecomp.sdc.heat.datatypes.model.ResourceReferenceFunctions;
import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
-import org.openecomp.sdc.tosca.datatypes.ToscaCapabilityType;
import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
-import org.openecomp.sdc.tosca.datatypes.ToscaRelationshipType;
-import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
-import org.onap.sdc.tosca.datatypes.model.RequirementAssignment;
import org.openecomp.sdc.tosca.services.DataModelUtil;
import org.openecomp.sdc.tosca.services.ToscaConstants;
import org.openecomp.sdc.translator.datatypes.heattotosca.AttachedResourceId;
@@ -39,164 +46,160 @@ import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil;
import org.openecomp.sdc.translator.services.heattotosca.ResourceTranslationFactory;
import org.openecomp.sdc.translator.services.heattotosca.mapping.TranslatorHeatToToscaPropertyConverter;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-
public class ResourceTranslationContrailV2VirtualNetworkImpl extends ResourceTranslationBase {
- protected static Logger logger =
- (Logger) LoggerFactory.getLogger(ResourceTranslationContrailV2VirtualNetworkImpl.class);
-
- @Override
- public void translate(TranslateTo translateTo) {
- NodeTemplate nodeTemplate = new NodeTemplate();
- nodeTemplate.setType(ToscaNodeType.CONTRAILV2_VIRTUAL_NETWORK);
- nodeTemplate.setProperties(TranslatorHeatToToscaPropertyConverter
- .getToscaPropertiesSimpleConversion(translateTo.getServiceTemplate(),translateTo.
- getResourceId(),translateTo.getResource().getProperties(),
- nodeTemplate.getProperties(), translateTo.getHeatFileName(),
- translateTo.getHeatOrchestrationTemplate(), translateTo.getResource().getType(),
- nodeTemplate, translateTo.getContext()));
- DataModelUtil.addNodeTemplate(translateTo.getServiceTemplate(), translateTo.getTranslatedId(),
- nodeTemplate);
- linkToPolicyNodeTemplate(translateTo);
- }
-
- private void linkToPolicyNodeTemplate(TranslateTo translateTo) {
- List<AttachedResourceId> networkPolicyIdList = extractNetworkPolicyIdList(translateTo);
- if (CollectionUtils.isEmpty(networkPolicyIdList)) {
- return;
- }
- for (AttachedResourceId attachedResourceId : networkPolicyIdList) {
- NodeTemplate policyNodeTemplate = DataModelUtil
- .getNodeTemplate(translateTo.getServiceTemplate(),
- (String) attachedResourceId.getTranslatedId());
- DataModelUtil
- .addRequirementAssignment(policyNodeTemplate, ToscaConstants.NETWORK_REQUIREMENT_ID,
- createRequirementAssignment(translateTo.getTranslatedId()));
- }
- }
-
- private List<AttachedResourceId> extractNetworkPolicyIdList(TranslateTo translateTo) {
- Object propertyValue = translateTo.getResource().getProperties().get("network_policy_refs");
- if (propertyValue != null) {
- return extractNetworkPolicyId(propertyValue, translateTo);
- } else {
- return null;
+ private static final String FQ_NAME = "fq_name";
+ protected static Logger logger = LoggerFactory.getLogger(ResourceTranslationContrailV2VirtualNetworkImpl.class);
+
+ @Override
+ public void translate(TranslateTo translateTo) {
+ NodeTemplate nodeTemplate = new NodeTemplate();
+ nodeTemplate.setType(ToscaNodeType.CONTRAILV2_VIRTUAL_NETWORK);
+ nodeTemplate.setProperties(TranslatorHeatToToscaPropertyConverter
+ .getToscaPropertiesSimpleConversion(translateTo.getServiceTemplate(),
+ translateTo.getResourceId(), translateTo.getResource().getProperties(),
+ nodeTemplate.getProperties(), translateTo.getHeatFileName(),
+ translateTo.getHeatOrchestrationTemplate(), translateTo.getResource().getType(),
+ nodeTemplate, translateTo.getContext()));
+ DataModelUtil.addNodeTemplate(translateTo.getServiceTemplate(), translateTo.getTranslatedId(),
+ nodeTemplate);
+ linkToPolicyNodeTemplate(translateTo);
}
- }
-
- private List<AttachedResourceId> extractNetworkPolicyId(Object propertyValue,
- TranslateTo translateTo) {
- List<AttachedResourceId> attachedResourceIdList = new ArrayList<>();
-
- if (propertyValue instanceof List) {
- for (Object value : (List) propertyValue) {
- attachedResourceIdList.addAll(extractNetworkPolicyId(value, translateTo));
- }
- } else {
- AttachedResourceId resourceId = parsNetworkPolicyId(propertyValue, translateTo);
- if (resourceId != null) {
- attachedResourceIdList.add(resourceId);
- }
+
+ private void linkToPolicyNodeTemplate(TranslateTo translateTo) {
+ List<AttachedResourceId> networkPolicyIdList = extractNetworkPolicyIdList(translateTo);
+ if (CollectionUtils.isEmpty(networkPolicyIdList)) {
+ return;
+ }
+ for (AttachedResourceId attachedResourceId : networkPolicyIdList) {
+ NodeTemplate policyNodeTemplate = DataModelUtil.getNodeTemplate(translateTo.getServiceTemplate(),
+ (String) attachedResourceId.getTranslatedId());
+ DataModelUtil.addRequirementAssignment(policyNodeTemplate, ToscaConstants.NETWORK_REQUIREMENT_ID,
+ createAttachmentRequirementAssignment(translateTo.getTranslatedId()));
+ }
}
- return attachedResourceIdList;
- }
-
- private AttachedResourceId parsNetworkPolicyId(Object propertyValue, TranslateTo translateTo) {
- Optional<String> translatedPolicyResourceId;
- String policyResourceId = extractResourceId(propertyValue, translateTo);
- if (policyResourceId == null) {
- return null;
+
+ private List<AttachedResourceId> extractNetworkPolicyIdList(TranslateTo translateTo) {
+ Object propertyValue = translateTo.getResource().getProperties().get("network_policy_refs");
+ if (propertyValue != null) {
+ return extractNetworkPolicyId(propertyValue, translateTo);
+ }
+ return Collections.emptyList();
}
- Resource policyResource = HeatToToscaUtil
- .getResource(translateTo.getHeatOrchestrationTemplate(), policyResourceId,
- translateTo.getHeatFileName());
- if (!policyResource.getType()
- .equals(HeatResourcesTypes.CONTRAIL_V2_NETWORK_RULE_RESOURCE_TYPE.getHeatResource())) {
- return null;
+ private List<AttachedResourceId> extractNetworkPolicyId(Object propertyValue,
+ TranslateTo translateTo) {
+ List<AttachedResourceId> attachedResourceIdList = new ArrayList<>();
+ if (propertyValue instanceof List) {
+ for (Object value : (List) propertyValue) {
+ attachedResourceIdList.addAll(extractNetworkPolicyId(value, translateTo));
+ }
+ } else {
+ AttachedResourceId resourceId = parseNetworkPolicyId(propertyValue, translateTo);
+ if (resourceId != null) {
+ attachedResourceIdList.add(resourceId);
+ }
+ }
+ return attachedResourceIdList;
}
- translatedPolicyResourceId = ResourceTranslationFactory.getInstance(policyResource)
- .translateResource(translateTo.getHeatFileName(), translateTo.getServiceTemplate(),
- translateTo.getHeatOrchestrationTemplate(), policyResource, policyResourceId,
- translateTo.getContext());
- if (!translatedPolicyResourceId.isPresent()) {
- logger.warn("Heat resource: '" + translateTo.getResourceId() + "' with type: '"
- + translateTo.getResource().getType()
- + "' property network_policy_refs is referenced to an unsupported resource the "
- + "connection will be ignored in TOSCA translation.");
- return null;
+
+ private AttachedResourceId parseNetworkPolicyId(Object propertyValue, TranslateTo translateTo) {
+ Optional<String> translatedPolicyResourceId;
+ String policyResourceId = extractResourceId(propertyValue, translateTo);
+ if (policyResourceId == null) {
+ return null;
+ }
+
+ Resource policyResource = HeatToToscaUtil.getResource(translateTo.getHeatOrchestrationTemplate(),
+ policyResourceId, translateTo.getHeatFileName());
+ if (!policyResource.getType().equals(HeatResourcesTypes.CONTRAIL_V2_NETWORK_RULE_RESOURCE_TYPE
+ .getHeatResource())) {
+ return null;
+ }
+ translatedPolicyResourceId = ResourceTranslationFactory.getInstance(policyResource)
+ .translateResource(translateTo.getHeatFileName(), translateTo.getServiceTemplate(),
+ translateTo.getHeatOrchestrationTemplate(), policyResource, policyResourceId,
+ translateTo.getContext());
+ if (!translatedPolicyResourceId.isPresent()) {
+ logger.warn(LOG_INVALID_NETWORK_POLICY_REFS_RESOURCE,
+ translateTo.getResourceId(), translateTo.getResource().getType());
+ return null;
+ }
+ return new AttachedResourceId(translatedPolicyResourceId.get(), policyResourceId, ReferenceType.GET_ATTR);
}
- AttachedResourceId attachedResourceId =
- new AttachedResourceId(translatedPolicyResourceId.get(), policyResourceId,
- ReferenceType.GET_ATTR);
- return attachedResourceId;
- }
-
- private String extractResourceId(Object propertyValue, TranslateTo translateTo) {
-
- Object value;
- if (propertyValue instanceof Map) {
- if (((Map) propertyValue).containsKey("get_attr")) {
- value = ((Map) propertyValue).get("get_attr");
- if (value instanceof List) {
- if (((List) value).size() == 2 && ((List) value).get(1).equals("fq_name")) {
- if (((List) value).get(0) instanceof String) {
- return (String) ((List) value).get(0);
- } else {
- logger.warn("Heat resource: '" + translateTo.getResourceId() + "' with type: '"
- + translateTo.getResource().getType()
- + "' has property with invalid format of 'get_attr' function with 'fq_name' "
- + "value, therefore this property will be ignored in TOSCA translation.");
+
+ private String extractResourceId(Object propertyValue, TranslateTo translateTo) {
+ if (propertyValue instanceof Map) {
+ return extractResourceIdFromMapProperty((Map) propertyValue, translateTo);
+ } else if (propertyValue instanceof List) {
+ String resourceId = extractResourceIdFromListProperty((List) propertyValue, translateTo);
+ if (resourceId != null) {
+ return resourceId;
}
- }
}
- } else if (((Map) propertyValue).containsKey("get_resource")) {
- value = ((Map) propertyValue).get("get_resource");
- if (value instanceof String) {
- return (String) value;
+ logger.warn(LOG_INVALID_PROPERTY_VALUE_FORMAT, translateTo.getResourceId(),
+ translateTo.getResource().getType());
+ return null;
+ }
+
+ private String extractResourceIdFromMapProperty(Map propertyValue, TranslateTo translateTo) {
+ Object value;
+ String resourceId = null;
+ if (propertyValue.containsKey(ResourceReferenceFunctions.GET_ATTR.getFunction())) {
+ value = propertyValue.get(ResourceReferenceFunctions.GET_ATTR.getFunction());
+ if (value instanceof List && extractResourceIdFromGetAttrList(translateTo, (List) value)) {
+ resourceId = (String) ((List) value).get(0);
+ }
+ } else if (propertyValue.containsKey(ResourceReferenceFunctions.GET_RESOURCE.getFunction())) {
+ resourceId = extractResourceIdFromGetResource(propertyValue, translateTo);
} else {
- logger.warn("Heat resource: '" + translateTo.getResourceId() + "' with type: '"
- + translateTo.getResource().getType()
- + "' has property invalid format of 'get_resource' function, therefore this property"
- + " will be ignored in TOSCA translation.");
+ resourceId = extractResourceIdFromPropertyValues(propertyValue, translateTo);
}
- } else {
- Collection<Object> valCollection = ((Map) propertyValue).values();
- for (Object entryValue : valCollection) {
- String ret = extractResourceId(entryValue, translateTo);
- if (ret != null) {
- return ret;
- }
+ return resourceId;
+ }
+ private boolean extractResourceIdFromGetAttrList(TranslateTo translateTo, List<Object> value) {
+ if (value.size() == 2 && FQ_NAME.equals(value.get(1))) {
+ if (value.get(0) instanceof String) {
+ return true;
+ } else {
+ logger.warn(LOG_INVALID_PROPERTY_FORMAT_GET_ATTR_FQ_NAME, translateTo.getResourceId(),
+ translateTo.getResource().getType());
+ }
}
- }
- } else if (propertyValue instanceof List) {
- for (Object prop : (List) propertyValue) {
- String ret = extractResourceId(prop, translateTo);
- if (ret != null) {
- return ret;
+ return false;
+ }
+
+ private String extractResourceIdFromPropertyValues(Map propertyValue, TranslateTo translateTo) {
+ Collection<Object> valCollection = propertyValue.values();
+ for (Object entryValue : valCollection) {
+ String ret = extractResourceId(entryValue, translateTo);
+ if (ret != null) {
+ return ret;
+ }
}
- }
+ return null;
}
- logger.warn("Heat resource: '" + translateTo.getResourceId() + "' with type: '"
- + translateTo.getResource().getType()
- + "' invalid format of property value, therefore this resource will be ignored in TOSCA "
- + "translation.");
- return null;
- }
-
- private RequirementAssignment createRequirementAssignment(String translatedNetworkResourceId) {
- RequirementAssignment requirement = new RequirementAssignment();
- requirement.setCapability(ToscaCapabilityType.NATIVE_ATTACHMENT);
- requirement.setNode(translatedNetworkResourceId);
- requirement.setRelationship(ToscaRelationshipType.ATTACHES_TO);
- return requirement;
- }
+ private String extractResourceIdFromListProperty(List<Object> propertyValue, TranslateTo translateTo) {
+ for (Object prop : propertyValue) {
+ String resourceId = extractResourceId(prop, translateTo);
+ if (resourceId != null) {
+ return resourceId;
+ }
+ }
+ return null;
+ }
+ private String extractResourceIdFromGetResource(Map propertyValue, TranslateTo translateTo) {
+ Object value;
+ value = propertyValue.get(ResourceReferenceFunctions.GET_RESOURCE.getFunction());
+ if (value instanceof String) {
+ return (String) value;
+ } else {
+ logger.warn(LOG_INVALID_PROPERTY_FORMAT_GET_RESOURCE, translateTo.getResourceId(),
+ translateTo.getResource().getType());
+ }
+ return null;
+ }
}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationContrailV2VlanSubInterfaceImpl.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationContrailV2VlanSubInterfaceImpl.java
index a83bf3217c..8c69b1565b 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationContrailV2VlanSubInterfaceImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationContrailV2VlanSubInterfaceImpl.java
@@ -1,119 +1,104 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
* 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.translator.services.heattotosca.impl.resourcetranslation;
+import static org.openecomp.sdc.translator.services.heattotosca.HeatToToscaLogConstants.LOG_MULTIPLE_INTERFACE_VALUES;
+import static org.openecomp.sdc.translator.services.heattotosca.HeatToToscaLogConstants.LOG_UNSUPPORTED_VLAN_RESOURCE_CONNECTION;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
+
+import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
import org.openecomp.sdc.heat.datatypes.model.HeatResourcesTypes;
import org.openecomp.sdc.heat.datatypes.model.Resource;
import org.openecomp.sdc.heat.services.HeatConstants;
import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
-import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
import org.openecomp.sdc.tosca.services.DataModelUtil;
import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo;
import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil;
import org.openecomp.sdc.translator.services.heattotosca.helper.ContrailV2VirtualMachineInterfaceHelper;
import org.openecomp.sdc.translator.services.heattotosca.mapping.TranslatorHeatToToscaPropertyConverter;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Objects;
-import java.util.Optional;
-
public class ResourceTranslationContrailV2VlanSubInterfaceImpl extends ResourceTranslationBase {
- protected static Logger logger =
- (Logger) LoggerFactory.getLogger(ResourceTranslationContrailV2VlanSubInterfaceImpl.class);
-
- @Override
- protected void translate(TranslateTo translateTo) {
- NodeTemplate nodeTemplate = new NodeTemplate();
- nodeTemplate.setType(ToscaNodeType.CONTRAILV2_VLAN_SUB_INTERFACE);
+ protected static Logger logger = LoggerFactory.getLogger(ResourceTranslationContrailV2VlanSubInterfaceImpl.class);
- nodeTemplate.setProperties(TranslatorHeatToToscaPropertyConverter
- .getToscaPropertiesSimpleConversion(translateTo.getServiceTemplate(),translateTo.
- getResourceId(),translateTo.getResource().getProperties(),
- nodeTemplate.getProperties(), translateTo.getHeatFileName(),
- translateTo.getHeatOrchestrationTemplate(), translateTo.getResource().getType(),
- nodeTemplate, translateTo.getContext()));
-
- new ContrailV2VirtualMachineInterfaceHelper()
- .connectVmiToNetwork(this, translateTo, nodeTemplate);
- connectSubInterfaceToInterface(translateTo, nodeTemplate);
- DataModelUtil.addNodeTemplate(translateTo.getServiceTemplate(), translateTo.getTranslatedId(),
- nodeTemplate);
- }
-
- //connection to shared interface is not supported
- private void connectSubInterfaceToInterface(TranslateTo translateTo,
- NodeTemplate vlanSubInterfaceNodeTemplate) {
- Object interfaceRefs =
- translateTo.getResource().getProperties().get(HeatConstants.VMI_REFS_PROPERTY_NAME);
- if (Objects.isNull(interfaceRefs) || !(interfaceRefs instanceof List)
- || ((List) interfaceRefs).size() == 0) {
- return;
+ @Override
+ protected void translate(TranslateTo translateTo) {
+ NodeTemplate nodeTemplate = new NodeTemplate();
+ nodeTemplate.setType(ToscaNodeType.CONTRAILV2_VLAN_SUB_INTERFACE);
+ nodeTemplate.setProperties(TranslatorHeatToToscaPropertyConverter
+ .getToscaPropertiesSimpleConversion(translateTo.getServiceTemplate(),
+ translateTo.getResourceId(), translateTo.getResource().getProperties(),
+ nodeTemplate.getProperties(), translateTo.getHeatFileName(),
+ translateTo.getHeatOrchestrationTemplate(), translateTo.getResource().getType(),
+ nodeTemplate, translateTo.getContext()));
+ new ContrailV2VirtualMachineInterfaceHelper().connectVmiToNetwork(this, translateTo, nodeTemplate);
+ connectSubInterfaceToInterface(translateTo, nodeTemplate);
+ DataModelUtil.addNodeTemplate(translateTo.getServiceTemplate(), translateTo.getTranslatedId(),
+ nodeTemplate);
}
- List<String> acceptableResourceTypes = Arrays
- .asList(HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE
- .getHeatResource(),
- HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource());
- if (((List) interfaceRefs).size() > 1) {
- logger.warn("Heat resource: '" + translateTo.getResourceId() + "' with type: '"
- + translateTo.getResource().getType()
- + "' include '" + HeatConstants.VMI_REFS_PROPERTY_NAME
- + "' property with more than one interface values, only "
- + "the first interface will be connected, "
- + "all rest will be ignored in TOSCA translation.");
- }
- Object interfaceRef = ((List) interfaceRefs).get(0);
- Optional<String> interfaceResourceId =
- HeatToToscaUtil.extractContrailGetResourceAttachedHeatResourceId(interfaceRef);
- if (interfaceResourceId.isPresent()) { // get_resource
- Resource interfaceResource = HeatToToscaUtil
- .getResource(translateTo.getHeatOrchestrationTemplate(), interfaceResourceId.get(),
- translateTo.getHeatFileName());
+ //connection to shared interface is not supported
+ private void connectSubInterfaceToInterface(TranslateTo translateTo,
+ NodeTemplate vlanSubInterfaceNodeTemplate) {
+ Object interfaceRefs = translateTo.getResource().getProperties().get(HeatConstants.VMI_REFS_PROPERTY_NAME);
+ if (Objects.isNull(interfaceRefs) || !(interfaceRefs instanceof List)
+ || ((List) interfaceRefs).isEmpty()) {
+ return;
+ }
+ List<String> acceptableResourceTypes = Arrays
+ .asList(HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
+ HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource());
+ if (((List) interfaceRefs).size() > 1) {
+ logger.warn(LOG_MULTIPLE_INTERFACE_VALUES, translateTo.getResourceId(), translateTo.getResource().getType(),
+ HeatConstants.VMI_REFS_PROPERTY_NAME);
+ }
+ Object interfaceRef = ((List) interfaceRefs).get(0);
+ Optional<String> interfaceResourceId =
+ HeatToToscaUtil.extractContrailGetResourceAttachedHeatResourceId(interfaceRef);
+ if (interfaceResourceId.isPresent()) { // get_resource
+ Resource interfaceResource = HeatToToscaUtil.getResource(translateTo.getHeatOrchestrationTemplate(),
+ interfaceResourceId.get(), translateTo.getHeatFileName());
- if (acceptableResourceTypes.contains(interfaceResource.getType())
- && !(new ContrailV2VirtualMachineInterfaceHelper()
- .isVlanSubInterfaceResource(interfaceResource))) {
- Optional<String> interfaceResourceTranslatedId =
- getResourceTranslatedId(translateTo.getHeatFileName(),
- translateTo.getHeatOrchestrationTemplate(), interfaceResourceId.get(),
- translateTo.getContext());
- interfaceResourceTranslatedId.ifPresent(interfaceResourceTranslatedIdVal -> HeatToToscaUtil
- .addBindingReqFromSubInterfaceToInterface(vlanSubInterfaceNodeTemplate,
- interfaceResourceTranslatedIdVal));
- } else {
- logger.warn("Heat resource: '" + translateTo.getResourceId() + "' with type: '"
- + translateTo.getResource().getType()
- + "' include '" + HeatConstants.VMI_REFS_PROPERTY_NAME
- + "' property which is connect to unsupported/incorrect "
- + (true == (new ContrailV2VirtualMachineInterfaceHelper()
- .isVlanSubInterfaceResource(interfaceResource)) ? "Vlan Sub interface " : "")
- + "resource '" + interfaceResourceId.get() + "' with type '"
- + interfaceResource.getType()
- + "', therefore, this connection will be ignored in TOSCA translation.");
- }
+ if (acceptableResourceTypes.contains(interfaceResource.getType())
+ && !(new ContrailV2VirtualMachineInterfaceHelper()
+ .isVlanSubInterfaceResource(interfaceResource))) {
+ Optional<String> interfaceResourceTranslatedId =
+ getResourceTranslatedId(translateTo.getHeatFileName(),
+ translateTo.getHeatOrchestrationTemplate(), interfaceResourceId.get(),
+ translateTo.getContext());
+ interfaceResourceTranslatedId.ifPresent(interfaceResourceTranslatedIdVal -> HeatToToscaUtil
+ .addBindingReqFromSubInterfaceToInterface(vlanSubInterfaceNodeTemplate,
+ interfaceResourceTranslatedIdVal));
+ } else {
+ logger.warn(LOG_UNSUPPORTED_VLAN_RESOURCE_CONNECTION, translateTo.getResourceId(), translateTo
+ .getResource().getType(), HeatConstants.VMI_REFS_PROPERTY_NAME,
+ getLogMessage(interfaceResource), interfaceResourceId.get(), interfaceResource.getType());
+ }
+ }
}
- }
+ private String getLogMessage(Resource interfaceResource) {
+ return (new ContrailV2VirtualMachineInterfaceHelper().isVlanSubInterfaceResource(interfaceResource))
+ ? "Vlan Sub interface " : "";
+ }
}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationContrailV2VmInterfaceImpl.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationContrailV2VmInterfaceImpl.java
index 1bb1df4899..30a6c051af 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationContrailV2VmInterfaceImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationContrailV2VmInterfaceImpl.java
@@ -16,105 +16,93 @@
package org.openecomp.sdc.translator.services.heattotosca.impl.resourcetranslation;
+import java.util.List;
+import java.util.Map;
+
+import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
import org.openecomp.sdc.common.togglz.ToggleableFeature;
import org.openecomp.sdc.heat.services.HeatConstants;
-import org.openecomp.sdc.logging.api.Logger;
-import org.openecomp.sdc.logging.api.LoggerFactory;
import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
-import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
import org.openecomp.sdc.tosca.services.DataModelUtil;
import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo;
import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil;
import org.openecomp.sdc.translator.services.heattotosca.helper.ContrailV2VirtualMachineInterfaceHelper;
import org.openecomp.sdc.translator.services.heattotosca.mapping.TranslatorHeatToToscaPropertyConverter;
-import java.util.List;
-import java.util.Map;
-
public class ResourceTranslationContrailV2VmInterfaceImpl extends ResourceTranslationBase {
- protected static final Logger LOGGER = LoggerFactory.getLogger(ResourceTranslationContrailV2VmInterfaceImpl.class);
- final ContrailV2VirtualMachineInterfaceHelper contrailV2VirtualMachineInterfaceHelper =
- new ContrailV2VirtualMachineInterfaceHelper();
-
- @Override
- protected boolean isEssentialRequirementsValid(TranslateTo translateTo) {
- if(contrailV2VirtualMachineInterfaceHelper
- .isVlanSubInterfaceResource(translateTo.getResource())) {
- return ToggleableFeature.VLAN_TAGGING.isActive() && contrailV2VirtualMachineInterfaceHelper
- .isVlanSubInterfaceConnectedToPortIndirectly(translateTo);
+ private final ContrailV2VirtualMachineInterfaceHelper contrailV2VirtualMachineInterfaceHelper =
+ new ContrailV2VirtualMachineInterfaceHelper();
+
+ @Override
+ protected boolean isEssentialRequirementsValid(TranslateTo translateTo) {
+ if (contrailV2VirtualMachineInterfaceHelper
+ .isVlanSubInterfaceResource(translateTo.getResource())) {
+ return ToggleableFeature.VLAN_TAGGING.isActive() && contrailV2VirtualMachineInterfaceHelper
+ .isVlanSubInterfaceConnectedToPortIndirectly(translateTo);
+ }
+ return true;
}
- return true;
- }
- @Override
- protected void translate(TranslateTo translateTo) {
- if (contrailV2VirtualMachineInterfaceHelper
- .isVlanSubInterfaceResource(translateTo.getResource())) {
- translateVlanSubInterfaceResource(translateTo);
- } else {
- translateVirtualMachineInterfaceResource(translateTo);
+ @Override
+ protected void translate(TranslateTo translateTo) {
+ if (contrailV2VirtualMachineInterfaceHelper
+ .isVlanSubInterfaceResource(translateTo.getResource())) {
+ translateVlanSubInterfaceResource(translateTo);
+ } else {
+ translateVirtualMachineInterfaceResource(translateTo);
+ }
}
- }
- private void translateVirtualMachineInterfaceResource(TranslateTo translateTo) {
- NodeTemplate nodeTemplate = new NodeTemplate();
- nodeTemplate.setType(ToscaNodeType.CONTRAILV2_VIRTUAL_MACHINE_INTERFACE);
- nodeTemplate.setProperties(TranslatorHeatToToscaPropertyConverter
- .getToscaPropertiesSimpleConversion(translateTo.getServiceTemplate(), translateTo.
- getResourceId(), translateTo.getResource().getProperties(),
- nodeTemplate.getProperties(), translateTo.getHeatFileName(),
- translateTo.getHeatOrchestrationTemplate(), translateTo.getResource().getType(),
- nodeTemplate, translateTo.getContext()));
- String toscaVmiRefsPropertyName =
- HeatToToscaUtil.getToscaPropertyName(translateTo, HeatConstants.VMI_REFS_PROPERTY_NAME);
- if (nodeTemplate.getProperties().containsKey(toscaVmiRefsPropertyName)) {
- nodeTemplate.getProperties().remove(toscaVmiRefsPropertyName);
+ private void translateVirtualMachineInterfaceResource(TranslateTo translateTo) {
+ NodeTemplate nodeTemplate = new NodeTemplate();
+ nodeTemplate.setType(ToscaNodeType.CONTRAILV2_VIRTUAL_MACHINE_INTERFACE);
+ nodeTemplate.setProperties(TranslatorHeatToToscaPropertyConverter
+ .getToscaPropertiesSimpleConversion(translateTo.getServiceTemplate(),
+ translateTo.getResourceId(), translateTo.getResource().getProperties(),
+ nodeTemplate.getProperties(), translateTo.getHeatFileName(),
+ translateTo.getHeatOrchestrationTemplate(), translateTo.getResource().getType(),
+ nodeTemplate, translateTo.getContext()));
+ String toscaVmiRefsPropertyName =
+ HeatToToscaUtil.getToscaPropertyName(translateTo, HeatConstants.VMI_REFS_PROPERTY_NAME);
+ nodeTemplate.getProperties().remove(toscaVmiRefsPropertyName);
+ handleVmiMacAddressesInProperties(translateTo, nodeTemplate);
+ contrailV2VirtualMachineInterfaceHelper.connectVmiToNetwork(this, translateTo, nodeTemplate);
+ DataModelUtil.addNodeTemplate(translateTo.getServiceTemplate(), translateTo.getTranslatedId(), nodeTemplate);
}
- handleVmiMacAddressesInProperties(translateTo, nodeTemplate);
-
- contrailV2VirtualMachineInterfaceHelper
- .connectVmiToNetwork(this, translateTo, nodeTemplate);
- DataModelUtil.addNodeTemplate(translateTo.getServiceTemplate(), translateTo.getTranslatedId(),
- nodeTemplate);
- }
-
- private void handleVmiMacAddressesInProperties(TranslateTo translateTo,
- NodeTemplate nodeTemplate) {
- String toscaVmiMacAddressesName =
- HeatToToscaUtil.getToscaPropertyName(translateTo, HeatConstants.VMI_MAC_ADDRESSES);
- String toscaVmiMacAddressesMacAddressesName =
- HeatToToscaUtil
- .getToscaPropertyName(translateTo, HeatConstants.VMI_MAC_ADDRESSES_MAC_ADDRESSES);
-
- if (nodeTemplate.getProperties().containsKey(toscaVmiMacAddressesName)) {
- Object macAddressesValue = nodeTemplate.getProperties().get(toscaVmiMacAddressesName);
- if (macAddressesValue instanceof Map && ((Map<String, Object>) macAddressesValue).containsKey
- (toscaVmiMacAddressesMacAddressesName)) {
- updateMacAddressesMacAddressesInProperties(nodeTemplate, toscaVmiMacAddressesName,
- toscaVmiMacAddressesMacAddressesName,
- (Map<String, Object>) macAddressesValue);
- }
+ private void handleVmiMacAddressesInProperties(TranslateTo translateTo,
+ NodeTemplate nodeTemplate) {
+ String toscaVmiMacAddressesName =
+ HeatToToscaUtil.getToscaPropertyName(translateTo, HeatConstants.VMI_MAC_ADDRESSES);
+ String toscaVmiMacAddressesMacAddressesName = HeatToToscaUtil
+ .getToscaPropertyName(translateTo, HeatConstants.VMI_MAC_ADDRESSES_MAC_ADDRESSES);
+ if (nodeTemplate.getProperties().containsKey(toscaVmiMacAddressesName)) {
+ Object macAddressesValue = nodeTemplate.getProperties().get(toscaVmiMacAddressesName);
+ if (macAddressesValue instanceof Map && ((Map<String, Object>) macAddressesValue).containsKey(
+ toscaVmiMacAddressesMacAddressesName)) {
+ updateMacAddressesMacAddressesInProperties(nodeTemplate, toscaVmiMacAddressesName,
+ toscaVmiMacAddressesMacAddressesName, (Map<String, Object>) macAddressesValue);
+ }
+ }
}
- }
- private void updateMacAddressesMacAddressesInProperties(NodeTemplate nodeTemplate,
- String toscaVmiMacAddressesName,
- String toscaVmiMacAddressesMacAddressesName,
- Map<String, Object> macAddressesValue) {
- Object macAddressesMacAddressesValue =
- macAddressesValue.get(toscaVmiMacAddressesMacAddressesName);
- if (macAddressesMacAddressesValue instanceof List) {
- nodeTemplate.getProperties().put(toscaVmiMacAddressesName, macAddressesMacAddressesValue);
- } else {
- nodeTemplate.getProperties().remove(toscaVmiMacAddressesName);
+ private void updateMacAddressesMacAddressesInProperties(NodeTemplate nodeTemplate,
+ String toscaVmiMacAddressesName,
+ String toscaVmiMacAddressesMacAddressesName,
+ Map<String, Object> macAddressesValue) {
+ Object macAddressesMacAddressesValue =
+ macAddressesValue.get(toscaVmiMacAddressesMacAddressesName);
+ if (macAddressesMacAddressesValue instanceof List) {
+ nodeTemplate.getProperties().put(toscaVmiMacAddressesName, macAddressesMacAddressesValue);
+ } else {
+ nodeTemplate.getProperties().remove(toscaVmiMacAddressesName);
+ }
}
- }
- private void translateVlanSubInterfaceResource(TranslateTo translateTo) {
- new ResourceTranslationContrailV2VlanSubInterfaceImpl().translate(translateTo);
- }
+ private void translateVlanSubInterfaceResource(TranslateTo translateTo) {
+ new ResourceTranslationContrailV2VlanSubInterfaceImpl().translate(translateTo);
+ }
}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationNestedImpl.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationNestedImpl.java
index e3e585a02f..a42e4c3366 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationNestedImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationNestedImpl.java
@@ -16,8 +16,16 @@
package org.openecomp.sdc.translator.services.heattotosca.impl.resourcetranslation;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
+import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
+import org.onap.sdc.tosca.datatypes.model.NodeType;
+import org.onap.sdc.tosca.datatypes.model.RequirementAssignment;
+import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
import org.openecomp.core.utilities.file.FileUtils;
import org.openecomp.sdc.heat.datatypes.manifest.FileData;
import org.openecomp.sdc.heat.datatypes.model.HeatResourcesTypes;
@@ -27,10 +35,6 @@ import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
import org.openecomp.sdc.tosca.datatypes.ToscaCapabilityType;
import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
-import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
-import org.onap.sdc.tosca.datatypes.model.NodeType;
-import org.onap.sdc.tosca.datatypes.model.RequirementAssignment;
-import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
import org.openecomp.sdc.tosca.services.DataModelUtil;
import org.openecomp.sdc.tosca.services.ToscaUtil;
import org.openecomp.sdc.tosca.services.impl.ToscaAnalyzerServiceImpl;
@@ -42,226 +46,212 @@ import org.openecomp.sdc.translator.services.heattotosca.Constants;
import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil;
import org.openecomp.sdc.translator.services.heattotosca.TranslationService;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-
public class ResourceTranslationNestedImpl extends ResourceTranslationBase {
- private static final String SUB_INTERFACE_COUNT = "count";
- protected static Logger log = LoggerFactory.getLogger(ResourceTranslationNestedImpl.class);
+ private static final String SUB_INTERFACE_COUNT = "count";
+ protected static Logger log = LoggerFactory.getLogger(ResourceTranslationNestedImpl.class);
- @Override
- public void translate(TranslateTo translateTo) {
- TranslationContext context = translateTo.getContext();
- FileData nestedFileData =
- HeatToToscaUtil.getFileData(translateTo.getResource().getType(), context);
- if (nestedFileData == null) {
- log.warn("Nested File '" + translateTo.getResource().getType()
- + "' is not exist, therefore, the nested resource with the ID '"
- + translateTo.getResourceId() + "' will be ignored in TOSCA translation");
- return;
+ @Override
+ public void translate(TranslateTo translateTo) {
+ TranslationContext context = translateTo.getContext();
+ FileData nestedFileData = HeatToToscaUtil.getFileData(translateTo.getResource().getType(), context);
+ if (nestedFileData == null) {
+ log.warn("Nested File '{}' is not exist, therefore, the nested resource with the ID '{}' will be ignored "
+ + "in TOSCA translation", translateTo.getResource().getType(), translateTo.getResourceId());
+ return;
+ }
+ String templateName = FileUtils.getFileWithoutExtention(translateTo.getResource().getType());
+ String substitutionNodeTypeKey = HeatToToscaUtil.getNestedResourceTypePrefix(translateTo) + templateName;
+ if (!context.getTranslatedServiceTemplates().containsKey(translateTo.getResource().getType())) {
+ translateNestedHeat(translateTo, nestedFileData, templateName, substitutionNodeTypeKey);
+ }
+ ServiceTemplate substitutionServiceTemplate = context.getTranslatedServiceTemplates()
+ .get(translateTo.getResource().getType());
+ if (DataModelUtil.isNodeTemplateSectionMissingFromServiceTemplate(substitutionServiceTemplate)) {
+ handleSubstitutionServiceTemplateWithoutNodeTemplates(templateName, translateTo);
+ return;
+ }
+ NodeTemplate substitutionNodeTemplate = HeatToToscaUtil.createAbstractSubstitutionNodeTemplate(translateTo,
+ templateName, substitutionNodeTypeKey);
+ manageSubstitutionNodeTemplateConnectionPoint(translateTo, nestedFileData, substitutionNodeTemplate,
+ substitutionNodeTypeKey);
+ DataModelUtil.addNodeTemplate(translateTo.getServiceTemplate(), translateTo.getTranslatedId(),
+ substitutionNodeTemplate);
+ //Add nested node template id to consolidation data
+ ConsolidationDataUtil.updateNestedNodeTemplateId(translateTo);
+ //Gather consolidation data if the resource group represents a sub interface
+ if (isResourceGroupSubInterface(substitutionNodeTypeKey)) {
+ populateSubInterfaceTemplateConsolidationData(translateTo, substitutionNodeTemplate);
+ }
}
- String templateName = FileUtils.getFileWithoutExtention(translateTo.getResource().getType());
- String substitutionNodeTypeKey = HeatToToscaUtil.getNestedResourceTypePrefix(translateTo)
- + templateName;
-
- if (!context.getTranslatedServiceTemplates()
- .containsKey(translateTo.getResource().getType())) {
-
- //substitution service template
- ServiceTemplate nestedSubstitutionServiceTemplate =
- createSubstitutionServiceTemplate(translateTo, nestedFileData, templateName);
-
- //global substitution service template
- ServiceTemplate globalSubstitutionServiceTemplate = HeatToToscaUtil
- .fetchGlobalSubstitutionServiceTemplate(translateTo.getServiceTemplate(),
- context);
- //substitution node type
- NodeType substitutionNodeType = new ToscaAnalyzerServiceImpl()
- .createInitSubstitutionNodeType(nestedSubstitutionServiceTemplate,
- ToscaNodeType.ABSTRACT_SUBSTITUTE);
- DataModelUtil.addNodeType(globalSubstitutionServiceTemplate, substitutionNodeTypeKey,
- substitutionNodeType);
- //substitution mapping
- HeatToToscaUtil
- .handleSubstitutionMapping(context, substitutionNodeTypeKey,
- nestedSubstitutionServiceTemplate, substitutionNodeType);
-
- //add new nested service template
- context.getTranslatedServiceTemplates()
- .put(translateTo.getResource().getType(), nestedSubstitutionServiceTemplate);
+ private boolean isResourceGroupSubInterface(String substitutionNodeTypeKey) {
+ return StringUtils.isNotBlank(substitutionNodeTypeKey)
+ && substitutionNodeTypeKey.contains(ToscaNodeType.VLAN_SUB_INTERFACE_RESOURCE_TYPE_PREFIX);
}
- ServiceTemplate substitutionServiceTemplate = context.getTranslatedServiceTemplates()
- .get(translateTo.getResource().getType());
-
- if (DataModelUtil.isNodeTemplateSectionMissingFromServiceTemplate(substitutionServiceTemplate)) {
- handleSubstitutionServiceTemplateWithoutNodeTemplates(
- templateName, translateTo);
- return;
+ private void translateNestedHeat(TranslateTo translateTo, FileData nestedFileData, String templateName,
+ String substitutionNodeTypeKey) {
+ TranslationContext context = translateTo.getContext();
+ //substitution service template
+ ServiceTemplate nestedSubstitutionServiceTemplate =
+ createSubstitutionServiceTemplate(translateTo, nestedFileData, templateName);
+ //global substitution service template
+ ServiceTemplate globalSubstitutionServiceTemplate = HeatToToscaUtil
+ .fetchGlobalSubstitutionServiceTemplate(translateTo.getServiceTemplate(), context);
+ //substitution node type
+ NodeType substitutionNodeType = new ToscaAnalyzerServiceImpl()
+ .createInitSubstitutionNodeType(nestedSubstitutionServiceTemplate, ToscaNodeType.ABSTRACT_SUBSTITUTE);
+ DataModelUtil.addNodeType(globalSubstitutionServiceTemplate, substitutionNodeTypeKey,
+ substitutionNodeType);
+ //substitution mapping
+ HeatToToscaUtil.handleSubstitutionMapping(context, substitutionNodeTypeKey,
+ nestedSubstitutionServiceTemplate, substitutionNodeType);
+ //add new nested service template
+ context.getTranslatedServiceTemplates().put(translateTo.getResource().getType(),
+ nestedSubstitutionServiceTemplate);
}
- NodeTemplate substitutionNodeTemplate =
- HeatToToscaUtil.createAbstractSubstitutionNodeTemplate(translateTo, templateName,
- substitutionNodeTypeKey);
- manageSubstitutionNodeTemplateConnectionPoint(translateTo, nestedFileData,
- substitutionNodeTemplate, substitutionNodeTypeKey);
- DataModelUtil.addNodeTemplate(translateTo.getServiceTemplate(), translateTo.getTranslatedId(),
- substitutionNodeTemplate);
- //Add nested node template id to consolidation data
- ConsolidationDataUtil.updateNestedNodeTemplateId(translateTo);
+ private void populateSubInterfaceTemplateConsolidationData(TranslateTo translateTo,
+ NodeTemplate nodeTemplate) {
- //Gather consolidation data if the resource group represents a sub interface
- if (StringUtils.isNotBlank(substitutionNodeTypeKey)
- && substitutionNodeTypeKey.contains(ToscaNodeType
- .VLAN_SUB_INTERFACE_RESOURCE_TYPE_PREFIX)) {
- populateSubInterfaceTemplateConsolidationData(translateTo, substitutionNodeTemplate);
+ Optional<SubInterfaceTemplateConsolidationData> subInterfaceTemplateConsolidationData =
+ ConsolidationDataUtil.getSubInterfaceTemplateConsolidationData(translateTo, translateTo
+ .getTranslatedId());
+ if (!subInterfaceTemplateConsolidationData.isPresent()) {
+ return;
+ }
+ Optional<String> subInterfaceNetworkRole =
+ HeatToToscaUtil.getNetworkRoleFromSubInterfaceId(translateTo.getResource(), translateTo.getContext());
+ subInterfaceNetworkRole.ifPresent(subInterfaceTemplateConsolidationData.get()::setNetworkRole);
+ subInterfaceTemplateConsolidationData.get()
+ .setResourceGroupCount(getSubInterfaceCountFromResourceProperties(translateTo));
+ if (CollectionUtils.isEmpty(nodeTemplate.getRequirements())) {
+ return;
+ }
+ //Add connectivity to network in consolidation data based on resource group link requirements
+ nodeTemplate.getRequirements().forEach((Map<String, RequirementAssignment> requirementMap) ->
+ requirementMap.entrySet().stream()
+ .filter(requirementAssignmentEntry -> ToscaCapabilityType.NATIVE_NETWORK_LINKABLE
+ .equals(requirementAssignmentEntry.getValue().getCapability()))
+ .forEach(requirementAssignmentEntry -> subInterfaceTemplateConsolidationData.get()
+ .addNodesConnectedOut(requirementAssignmentEntry.getValue().getNode(),
+ requirementAssignmentEntry.getKey(),
+ requirementAssignmentEntry.getValue())
+ )
+ );
}
- }
-
- private void populateSubInterfaceTemplateConsolidationData(TranslateTo translateTo,
- NodeTemplate nodeTemplate) {
- Optional<SubInterfaceTemplateConsolidationData> subInterfaceTemplateConsolidationData =
- ConsolidationDataUtil.getSubInterfaceTemplateConsolidationData(translateTo, translateTo
- .getTranslatedId());
- if (!subInterfaceTemplateConsolidationData.isPresent()) {
- return;
+ private Object getSubInterfaceCountFromResourceProperties(TranslateTo translateTo) {
+ if (Objects.nonNull(translateTo.getHeatOrchestrationTemplate().getResources().get(translateTo
+ .getResourceId()))) {
+ Resource resource = translateTo.getHeatOrchestrationTemplate().getResources().get(translateTo
+ .getResourceId());
+ if (HeatResourcesTypes.RESOURCE_GROUP_RESOURCE_TYPE.getHeatResource().equals(resource.getType())) {
+ return resource.getProperties().get(SUB_INTERFACE_COUNT);
+ } else if (HeatToToscaUtil.isYamlFile(resource.getType())) {
+ return HeatConstants.DEFAULT_NESTED_HEAT_RESOURCE_COUNT;
+ }
+ }
+ return null;
}
- Optional<String> subInterfaceNetworkRole =
- HeatToToscaUtil.getNetworkRoleFromSubInterfaceId(translateTo.getResource(), translateTo.getContext());
- subInterfaceNetworkRole.ifPresent(subInterfaceTemplateConsolidationData.get()::setNetworkRole);
- Object count = getSubInterfaceCountFromResourceProperties(translateTo);
- subInterfaceTemplateConsolidationData.get().setResourceGroupCount(count);
- if (CollectionUtils.isNotEmpty(nodeTemplate.getRequirements())) {
- //Add connectivity to network in consolidation data based on resource group link requirements
- nodeTemplate.getRequirements().forEach((Map<String, RequirementAssignment> requirementMap) ->
- requirementMap.entrySet().stream()
- .filter(requirementAssignmentEntry -> ToscaCapabilityType.NATIVE_NETWORK_LINKABLE
- .equals(requirementAssignmentEntry.getValue().getCapability()))
- .forEach(requirementAssignmentEntry -> subInterfaceTemplateConsolidationData.get()
- .addNodesConnectedOut(requirementAssignmentEntry.getValue().getNode(),
- requirementAssignmentEntry.getKey(),
- requirementAssignmentEntry.getValue())
- )
- );
+ private void handleSubstitutionServiceTemplateWithoutNodeTemplates(String templateName,
+ TranslateTo translateTo) {
+ translateTo.getContext().addServiceTemplateWithoutNodeTemplates(templateName);
+ translateTo.getContext()
+ .addNestedNodeTemplateIdPointsToStWithoutNodeTemplates(translateTo.getTranslatedId());
+ translateTo.getContext().getTranslatedServiceTemplates().remove(translateTo.getResource().getType());
}
- }
- private Object getSubInterfaceCountFromResourceProperties(TranslateTo translateTo) {
- if (Objects.nonNull(translateTo.getHeatOrchestrationTemplate().getResources().get(translateTo
- .getResourceId()))) {
- Resource resource = translateTo.getHeatOrchestrationTemplate().getResources().get(translateTo
- .getResourceId());
- if(HeatResourcesTypes.RESOURCE_GROUP_RESOURCE_TYPE.getHeatResource().equals(resource.getType())) {
- return resource.getProperties().get(SUB_INTERFACE_COUNT);
- } else if (HeatToToscaUtil.isYamlFile(resource.getType())) {
- return HeatConstants.DEFAULT_NESTED_HEAT_RESOURCE_COUNT;
- }
+ private ServiceTemplate createSubstitutionServiceTemplate(TranslateTo translateTo,
+ FileData nestedFileData,
+ String templateName) {
+ ServiceTemplate nestedSubstitutionServiceTemplate =
+ HeatToToscaUtil.createInitSubstitutionServiceTemplate(templateName);
+ translateTo.getContext().addNestedHeatFileName(ToscaUtil.getServiceTemplateFileName(templateName),
+ translateTo.getResource().getType());
+ new TranslationService().translateHeatFile(nestedSubstitutionServiceTemplate, nestedFileData, translateTo
+ .getContext());
+ return nestedSubstitutionServiceTemplate;
}
- return null;
- }
- private void handleSubstitutionServiceTemplateWithoutNodeTemplates(String templateName,
- TranslateTo translateTo) {
- translateTo.getContext().addServiceTemplateWithoutNodeTemplates(templateName);
- translateTo.getContext()
- .addNestedNodeTemplateIdPointsToStWithoutNodeTemplates(translateTo.getTranslatedId());
- translateTo.getContext().getTranslatedServiceTemplates().remove(translateTo.getResource().getType());
- }
- private ServiceTemplate createSubstitutionServiceTemplate(TranslateTo translateTo,
- FileData nestedFileData,
- String templateName) {
- ServiceTemplate nestedSubstitutionServiceTemplate =
- HeatToToscaUtil.createInitSubstitutionServiceTemplate(templateName);
- translateTo.getContext()
- .addNestedHeatFileName(ToscaUtil.getServiceTemplateFileName(templateName),
- translateTo.getResource().getType());
- new TranslationService().translateHeatFile(nestedSubstitutionServiceTemplate,
- nestedFileData, translateTo.getContext());
- return nestedSubstitutionServiceTemplate;
- }
+ private void manageSubstitutionNodeTemplateConnectionPoint(TranslateTo translateTo,
+ FileData nestedFileData,
+ NodeTemplate substitutionNodeTemplate,
+ String substitutionNodeTypeId) {
+ ServiceTemplate globalSubstitutionTemplate =
+ translateTo.getContext().getTranslatedServiceTemplates()
+ .get(Constants.GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME);
+ NodeType nodeType = globalSubstitutionTemplate.getNode_types().get(substitutionNodeTypeId);
+ handlePortToNetConnections(translateTo, nestedFileData, substitutionNodeTemplate, nodeType);
+ handleSecurityRulesToPortConnections(translateTo, nestedFileData, substitutionNodeTemplate,
+ nodeType);
+ handleNovaToVolConnection(translateTo, nestedFileData, substitutionNodeTemplate, nodeType);
+ handleContrailV2VmInterfaceToNetworkConnection(translateTo, nestedFileData,
+ substitutionNodeTemplate, nodeType);
+ handleContrailPortToNetConnections(translateTo, nestedFileData, substitutionNodeTemplate,
+ nodeType);
+ handleVlanSubInterfaceToInterfaceConnections(translateTo, nestedFileData,
+ substitutionNodeTemplate, nodeType);
+ }
+ private void handleVlanSubInterfaceToInterfaceConnections(TranslateTo translateTo,
+ FileData nestedFileData,
+ NodeTemplate substitutionNodeTemplate,
+ NodeType nodeType) {
+ ContrailV2VlanToInterfaceResourceConnection linker =
+ new ContrailV2VlanToInterfaceResourceConnection(this, translateTo, nestedFileData,
+ substitutionNodeTemplate, nodeType);
+ linker.connect();
+ }
- private void manageSubstitutionNodeTemplateConnectionPoint(TranslateTo translateTo,
- FileData nestedFileData,
- NodeTemplate substitutionNodeTemplate,
- String substitutionNodeTypeId) {
- ServiceTemplate globalSubstitutionTemplate =
- translateTo.getContext().getTranslatedServiceTemplates()
- .get(Constants.GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME);
- NodeType nodeType = globalSubstitutionTemplate.getNode_types().get(substitutionNodeTypeId);
- handlePortToNetConnections(translateTo, nestedFileData, substitutionNodeTemplate, nodeType);
- handleSecurityRulesToPortConnections(translateTo, nestedFileData, substitutionNodeTemplate,
- nodeType);
- handleNovaToVolConnection(translateTo, nestedFileData, substitutionNodeTemplate, nodeType);
- handleContrailV2VmInterfaceToNetworkConnection(translateTo, nestedFileData,
- substitutionNodeTemplate, nodeType);
- handleContrailPortToNetConnections(translateTo, nestedFileData, substitutionNodeTemplate,
- nodeType);
- handleVlanSubInterfaceToInterfaceConnections(translateTo, nestedFileData,
- substitutionNodeTemplate, nodeType);
- }
- private void handleVlanSubInterfaceToInterfaceConnections(TranslateTo translateTo,
- FileData nestedFileData,
- NodeTemplate substitutionNodeTemplate,
- NodeType nodeType) {
- ContrailV2VlanToInterfaceResourceConnection linker =
- new ContrailV2VlanToInterfaceResourceConnection(this, translateTo, nestedFileData,
- substitutionNodeTemplate, nodeType);
- linker.connect();
- }
+ private void handleContrailV2VmInterfaceToNetworkConnection(TranslateTo translateTo,
+ FileData nestedFileData,
+ NodeTemplate substitutionNodeTemplate,
+ NodeType nodeType) {
+ ContrailV2VmInterfaceToNetResourceConnection linker =
+ new ContrailV2VmInterfaceToNetResourceConnection(this, translateTo, nestedFileData,
+ substitutionNodeTemplate, nodeType);
+ linker.connect();
+ }
+ private void handleNovaToVolConnection(TranslateTo translateTo, FileData nestedFileData,
+ NodeTemplate substitutionNodeTemplate, NodeType nodeType) {
+ NovaToVolResourceConnection linker =
+ new NovaToVolResourceConnection(this, translateTo, nestedFileData, substitutionNodeTemplate,
+ nodeType);
+ linker.connect();
+ }
- private void handleContrailV2VmInterfaceToNetworkConnection(TranslateTo translateTo,
- FileData nestedFileData,
- NodeTemplate substitutionNodeTemplate,
- NodeType nodeType) {
- ContrailV2VmInterfaceToNetResourceConnection linker =
- new ContrailV2VmInterfaceToNetResourceConnection(this, translateTo, nestedFileData,
- substitutionNodeTemplate, nodeType);
- linker.connect();
- }
+ private void handleSecurityRulesToPortConnections(TranslateTo translateTo,
+ FileData nestedFileData,
+ NodeTemplate substitutionNodeTemplate,
+ NodeType nodeType) {
+ SecurityRulesToPortResourceConnection linker =
+ new SecurityRulesToPortResourceConnection(this, translateTo, nestedFileData,
+ substitutionNodeTemplate, nodeType);
+ linker.connect();
+ }
- private void handleNovaToVolConnection(TranslateTo translateTo, FileData nestedFileData,
- NodeTemplate substitutionNodeTemplate, NodeType nodeType) {
- NovaToVolResourceConnection linker =
- new NovaToVolResourceConnection(this, translateTo, nestedFileData, substitutionNodeTemplate,
- nodeType);
- linker.connect();
- }
+ private void handlePortToNetConnections(TranslateTo translateTo, FileData nestedFileData,
+ NodeTemplate substitutionNodeTemplate,
+ NodeType nodeType) {
+ PortToNetResourceConnection linker =
+ new PortToNetResourceConnection(this, translateTo, nestedFileData, substitutionNodeTemplate,
+ nodeType);
+ linker.connect();
+ }
- private void handleSecurityRulesToPortConnections(TranslateTo translateTo,
- FileData nestedFileData,
+ private void handleContrailPortToNetConnections(TranslateTo translateTo, FileData nestedFileData,
NodeTemplate substitutionNodeTemplate,
NodeType nodeType) {
- SecurityRulesToPortResourceConnection linker =
- new SecurityRulesToPortResourceConnection(this, translateTo, nestedFileData,
- substitutionNodeTemplate, nodeType);
- linker.connect();
- }
-
- private void handlePortToNetConnections(TranslateTo translateTo, FileData nestedFileData,
- NodeTemplate substitutionNodeTemplate,
- NodeType nodeType) {
- PortToNetResourceConnection linker =
- new PortToNetResourceConnection(this, translateTo, nestedFileData, substitutionNodeTemplate,
- nodeType);
- linker.connect();
- }
-
- private void handleContrailPortToNetConnections(TranslateTo translateTo, FileData nestedFileData,
- NodeTemplate substitutionNodeTemplate,
- NodeType nodeType) {
- ContrailPortToNetResourceConnection linker =
- new ContrailPortToNetResourceConnection(this, translateTo, nestedFileData,
- substitutionNodeTemplate, nodeType);
- linker.connect();
- }
+ ContrailPortToNetResourceConnection linker =
+ new ContrailPortToNetResourceConnection(this, translateTo, nestedFileData,
+ substitutionNodeTemplate, nodeType);
+ linker.connect();
+ }
}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationNeutronPortImpl.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationNeutronPortImpl.java
index bce0ada230..3e3983ff88 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationNeutronPortImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationNeutronPortImpl.java
@@ -1,32 +1,39 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
* 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.translator.services.heattotosca.impl.resourcetranslation;
+import static org.openecomp.sdc.translator.services.heattotosca.Constants.SECURITY_GROUPS_PROPERTY_NAME;
+
+import com.google.common.collect.ImmutableList;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+
+import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
+import org.onap.sdc.tosca.datatypes.model.RequirementAssignment;
import org.openecomp.sdc.heat.datatypes.model.HeatResourcesTypes;
import org.openecomp.sdc.heat.datatypes.model.Resource;
+import org.openecomp.sdc.heat.services.HeatConstants;
import org.openecomp.sdc.tosca.datatypes.ToscaCapabilityType;
import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
import org.openecomp.sdc.tosca.datatypes.ToscaRelationshipType;
-import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
-import org.onap.sdc.tosca.datatypes.model.RequirementAssignment;
import org.openecomp.sdc.tosca.services.DataModelUtil;
import org.openecomp.sdc.tosca.services.ToscaConstants;
import org.openecomp.sdc.translator.datatypes.heattotosca.AttachedResourceId;
@@ -34,212 +41,203 @@ import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo;
import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslatedHeatResource;
import org.openecomp.sdc.translator.services.heattotosca.ConsolidationDataUtil;
import org.openecomp.sdc.translator.services.heattotosca.ConsolidationEntityType;
-import org.openecomp.sdc.translator.services.heattotosca.Constants;
import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil;
import org.openecomp.sdc.translator.services.heattotosca.ResourceTranslationFactory;
import org.openecomp.sdc.translator.services.heattotosca.helper.ResourceTranslationNeutronPortHelper;
import org.openecomp.sdc.translator.services.heattotosca.mapping.TranslatorHeatToToscaPropertyConverter;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-
public class ResourceTranslationNeutronPortImpl extends ResourceTranslationBase {
- @Override
- public void translate(TranslateTo translateTo) {
- NodeTemplate nodeTemplate = new NodeTemplate();
- nodeTemplate.setType(ToscaNodeType.NEUTRON_PORT);
- nodeTemplate.setProperties(TranslatorHeatToToscaPropertyConverter
- .getToscaPropertiesSimpleConversion(translateTo.getServiceTemplate(), translateTo.
- getResourceId(), translateTo.getResource().getProperties(),
- nodeTemplate.getProperties(), translateTo.getHeatFileName(),
- translateTo.getHeatOrchestrationTemplate(), translateTo.getResource().getType(),
- nodeTemplate, translateTo.getContext()));
- new ResourceTranslationNeutronPortHelper().setAdditionalProperties(nodeTemplate
- .getProperties());
- handleNetworkRequirement(translateTo, nodeTemplate);
- String resourceTranslatedId = handleSecurityRulesRequirement(translateTo);
- DataModelUtil
- .addNodeTemplate(translateTo.getServiceTemplate(), resourceTranslatedId, nodeTemplate);
- }
-
- private String handleSecurityRulesRequirement(TranslateTo translateTo) {
- String resourceTranslatedId = translateTo.getTranslatedId();
- Map<String, Object> properties = translateTo.getResource().getProperties();
- Optional<Object> securityGroups =
- Optional.ofNullable(properties.get(Constants.SECURITY_GROUPS_PROPERTY_NAME));
- if (securityGroups.isPresent() && securityGroups.get() instanceof List) {
- List securityGroupsList = (List) securityGroups.get();
- securityGroupsList.forEach(resourceValue -> {
- Optional<AttachedResourceId> securityGroupResourceId = HeatToToscaUtil
- .extractAttachedResourceId(translateTo.getHeatFileName(),
- translateTo.getHeatOrchestrationTemplate(), translateTo.getContext(),
- resourceValue);
- securityGroupResourceId.ifPresent(
- attachedResourceId -> handleSecurityGroupResourceId(translateTo, resourceTranslatedId,
- attachedResourceId));
- });
+ @Override
+ public void translate(TranslateTo translateTo) {
+ NodeTemplate nodeTemplate = new NodeTemplate();
+ nodeTemplate.setType(ToscaNodeType.NEUTRON_PORT);
+ nodeTemplate.setProperties(TranslatorHeatToToscaPropertyConverter
+ .getToscaPropertiesSimpleConversion(translateTo.getServiceTemplate(),
+ translateTo.getResourceId(), translateTo.getResource().getProperties(),
+ nodeTemplate.getProperties(), translateTo.getHeatFileName(),
+ translateTo.getHeatOrchestrationTemplate(), translateTo.getResource().getType(),
+ nodeTemplate, translateTo.getContext()));
+ new ResourceTranslationNeutronPortHelper().setAdditionalProperties(nodeTemplate
+ .getProperties());
+ handleNetworkRequirement(translateTo, nodeTemplate);
+ String resourceTranslatedId = handleSecurityRulesRequirement(translateTo);
+ DataModelUtil
+ .addNodeTemplate(translateTo.getServiceTemplate(), resourceTranslatedId, nodeTemplate);
+ }
+
+ private String handleSecurityRulesRequirement(TranslateTo translateTo) {
+ String resourceTranslatedId = translateTo.getTranslatedId();
+ Map<String, Object> properties = translateTo.getResource().getProperties();
+ Optional<Object> securityGroups = Optional.ofNullable(properties.get(SECURITY_GROUPS_PROPERTY_NAME));
+ if (securityGroups.isPresent() && securityGroups.get() instanceof List) {
+ List securityGroupsList = (List) securityGroups.get();
+ securityGroupsList.forEach(resourceValue -> {
+ Optional<AttachedResourceId> securityGroupResourceId = HeatToToscaUtil
+ .extractAttachedResourceId(translateTo.getHeatFileName(),
+ translateTo.getHeatOrchestrationTemplate(), translateTo.getContext(), resourceValue);
+ securityGroupResourceId.ifPresent(attachedResourceId -> handleSecurityGroupResourceId(translateTo,
+ resourceTranslatedId, attachedResourceId));
+ });
+ }
+ return resourceTranslatedId;
}
- return resourceTranslatedId;
- }
-
- private void handleSecurityGroupResourceId(TranslateTo translateTo, String resourceTranslatedId,
- AttachedResourceId securityGroupResourceId) {
- List<String> supportedSecurityGroupsTypes = Collections
- .singletonList(HeatResourcesTypes.NEUTRON_SECURITY_GROUP_RESOURCE_TYPE.getHeatResource());
- if (securityGroupResourceId.isGetResource()) {
- handleGetResource(translateTo, resourceTranslatedId, securityGroupResourceId,
- supportedSecurityGroupsTypes);
- } else if (securityGroupResourceId.isGetParam()) {
- handleGetParam(translateTo, resourceTranslatedId, securityGroupResourceId,
- supportedSecurityGroupsTypes);
+
+ private void handleSecurityGroupResourceId(TranslateTo translateTo, String resourceTranslatedId,
+ AttachedResourceId securityGroupResourceId) {
+ List<String> supportedSecurityGroupsTypes = Collections
+ .singletonList(HeatResourcesTypes.NEUTRON_SECURITY_GROUP_RESOURCE_TYPE.getHeatResource());
+ if (securityGroupResourceId.isGetResource()) {
+ handleGetResource(translateTo, resourceTranslatedId, securityGroupResourceId, supportedSecurityGroupsTypes);
+ } else if (securityGroupResourceId.isGetParam()) {
+ handleGetParam(translateTo, resourceTranslatedId, securityGroupResourceId, supportedSecurityGroupsTypes);
+ }
+ }
+
+ private void handleGetParam(TranslateTo translateTo, String resourceTranslatedId,
+ AttachedResourceId securityGroupResourceId,
+ List<String> supportedSecurityGroupsTypes) {
+ if (!(securityGroupResourceId.getEntityId() instanceof String)) {
+ return;
+ }
+ TranslatedHeatResource translatedSharedResourceId =
+ translateTo.getContext().getHeatSharedResourcesByParam().get(securityGroupResourceId.getEntityId());
+ if (Objects.nonNull(translatedSharedResourceId)
+ && !HeatToToscaUtil.isHeatFileNested(translateTo, translateTo.getHeatFileName())) {
+ if (validateResourceTypeSupportedForReqCreation(translateTo, supportedSecurityGroupsTypes,
+ translatedSharedResourceId.getHeatResource(), SECURITY_GROUPS_PROPERTY_NAME)) {
+ return;
+ }
+ final NodeTemplate securityGroupNodeTemplate = DataModelUtil
+ .getNodeTemplate(translateTo.getServiceTemplate(),
+ translatedSharedResourceId.getTranslatedId());
+ RequirementAssignment requirement = new RequirementAssignment();
+ requirement.setCapability(ToscaCapabilityType.NATIVE_ATTACHMENT);
+ requirement.setNode(resourceTranslatedId);
+ requirement.setRelationship(ToscaRelationshipType.ATTACHES_TO);
+ DataModelUtil.addRequirementAssignment(securityGroupNodeTemplate, ToscaConstants.PORT_REQUIREMENT_ID,
+ requirement);
+
+ ConsolidationDataUtil.updateNodesConnectedIn(translateTo, translatedSharedResourceId.getTranslatedId(),
+ ConsolidationEntityType.PORT, translateTo.getResourceId(),
+ ToscaConstants.PORT_REQUIREMENT_ID, requirement);
+ }
}
- }
- private void handleGetParam(TranslateTo translateTo, String resourceTranslatedId,
- AttachedResourceId securityGroupResourceId,
- List<String> supportedSecurityGroupsTypes) {
- if (!(securityGroupResourceId.getEntityId() instanceof String)) {
- return;
+ private void handleGetResource(TranslateTo translateTo, String resourceTranslatedId,
+ AttachedResourceId securityGroupResourceId,
+ List<String> supportedSecurityGroupsTypes) {
+ String resourceId = (String) securityGroupResourceId.getEntityId();
+ Resource securityGroupResource = HeatToToscaUtil.getResource(translateTo.getHeatOrchestrationTemplate(),
+ resourceId, translateTo.getHeatFileName());
+ Optional<String> securityGroupTranslatedId = ResourceTranslationFactory.getInstance(securityGroupResource)
+ .translateResource(translateTo.getHeatFileName(), translateTo.getServiceTemplate(),
+ translateTo.getHeatOrchestrationTemplate(), securityGroupResource, resourceId,
+ translateTo.getContext());
+ if (!securityGroupTranslatedId.isPresent()) {
+ return;
+ }
+ if (validateResourceTypeSupportedForReqCreation(translateTo, supportedSecurityGroupsTypes,
+ securityGroupResource, SECURITY_GROUPS_PROPERTY_NAME)) {
+ return;
+ }
+ final NodeTemplate securityGroupNodeTemplate = DataModelUtil
+ .getNodeTemplate(translateTo.getServiceTemplate(), securityGroupTranslatedId.get());
+ RequirementAssignment requirement = new RequirementAssignment();
+ requirement.setCapability(ToscaCapabilityType.NATIVE_ATTACHMENT);
+ requirement.setNode(resourceTranslatedId);
+ requirement.setRelationship(ToscaRelationshipType.ATTACHES_TO);
+ DataModelUtil
+ .addRequirementAssignment(securityGroupNodeTemplate, ToscaConstants.PORT_REQUIREMENT_ID,
+ requirement);
+
+ ConsolidationDataUtil.updateNodesConnectedIn(translateTo, securityGroupTranslatedId.get(),
+ ConsolidationEntityType.PORT, translateTo.getResourceId(),
+ ToscaConstants.PORT_REQUIREMENT_ID, requirement);
}
- TranslatedHeatResource translatedSharedResourceId =
- translateTo.getContext().getHeatSharedResourcesByParam()
- .get(securityGroupResourceId.getEntityId());
- if (Objects.nonNull(translatedSharedResourceId)
- && !HeatToToscaUtil.isHeatFileNested(translateTo, translateTo.getHeatFileName())) {
- if (validateResourceTypeSupportedForReqCreation(translateTo, supportedSecurityGroupsTypes,
- translatedSharedResourceId.getHeatResource(), "security_groups")) {
- return;
- }
- final NodeTemplate securityGroupNodeTemplate = DataModelUtil
- .getNodeTemplate(translateTo.getServiceTemplate(),
- translatedSharedResourceId.getTranslatedId());
- RequirementAssignment requirement = new RequirementAssignment();
- requirement.setCapability(ToscaCapabilityType.NATIVE_ATTACHMENT);
- requirement.setNode(resourceTranslatedId);
- requirement.setRelationship(ToscaRelationshipType.ATTACHES_TO);
- DataModelUtil
- .addRequirementAssignment(securityGroupNodeTemplate, ToscaConstants.PORT_REQUIREMENT_ID,
- requirement);
-
- ConsolidationDataUtil
- .updateNodesConnectedIn(translateTo, translatedSharedResourceId.getTranslatedId(),
- ConsolidationEntityType.PORT, translateTo.getResourceId(),
- ToscaConstants.PORT_REQUIREMENT_ID, requirement);
+
+ private void handleNetworkRequirement(TranslateTo translateTo, NodeTemplate nodeTemplate) {
+ Optional<AttachedResourceId> networkResourceId =
+ HeatToToscaUtil.extractAttachedResourceId(translateTo, HeatConstants.NETWORK_PROPERTY_NAME);
+ if (networkResourceId.isPresent()) {
+ AttachedResourceId attachedResourceId = networkResourceId.get();
+ addRequirementAssignmentForNetworkResource(translateTo, nodeTemplate, attachedResourceId);
+ } else {
+ networkResourceId = HeatToToscaUtil.extractAttachedResourceId(translateTo, HeatConstants
+ .NETWORK_ID_PROPERTY_NAME);
+ if (networkResourceId.isPresent()) {
+ AttachedResourceId attachedResourceId = networkResourceId.get();
+ addRequirementAssignmentForNetworkResource(translateTo, nodeTemplate, attachedResourceId);
+ }
+ }
}
- }
-
- private void handleGetResource(TranslateTo translateTo, String resourceTranslatedId,
- AttachedResourceId securityGroupResourceId,
- List<String> supportedSecurityGroupsTypes) {
- String resourceId = (String) securityGroupResourceId.getEntityId();
- Resource securityGroupResource = HeatToToscaUtil
- .getResource(translateTo.getHeatOrchestrationTemplate(), resourceId,
- translateTo.getHeatFileName());
- Optional<String> securityGroupTranslatedId =
- ResourceTranslationFactory.getInstance(securityGroupResource)
- .translateResource(translateTo.getHeatFileName(), translateTo.getServiceTemplate(),
- translateTo.getHeatOrchestrationTemplate(), securityGroupResource, resourceId,
- translateTo.getContext());
- if (securityGroupTranslatedId.isPresent()) {
- if (validateResourceTypeSupportedForReqCreation(translateTo, supportedSecurityGroupsTypes,
- securityGroupResource, "security_groups")) {
- return;
- }
- final NodeTemplate securityGroupNodeTemplate = DataModelUtil
- .getNodeTemplate(translateTo.getServiceTemplate(), securityGroupTranslatedId.get());
- RequirementAssignment requirement = new RequirementAssignment();
- requirement.setCapability(ToscaCapabilityType.NATIVE_ATTACHMENT);
- requirement.setNode(resourceTranslatedId);
- requirement.setRelationship(ToscaRelationshipType.ATTACHES_TO);
- DataModelUtil
- .addRequirementAssignment(securityGroupNodeTemplate, ToscaConstants.PORT_REQUIREMENT_ID,
- requirement);
-
- ConsolidationDataUtil.updateNodesConnectedIn(translateTo, securityGroupTranslatedId.get(),
- ConsolidationEntityType.PORT, translateTo.getResourceId(),
- ToscaConstants.PORT_REQUIREMENT_ID, requirement);
+
+ private void addRequirementAssignmentForNetworkResource(TranslateTo translateTo,
+ NodeTemplate nodeTemplate,
+ AttachedResourceId attachedResourceId) {
+ if (attachedResourceId.isGetResource()) {
+ addLinkRequirementForGetResource(translateTo, nodeTemplate, attachedResourceId);
+ } else if (attachedResourceId.isGetParam() && attachedResourceId.getEntityId() instanceof String) {
+ addLinkRequirementForGetParam(translateTo, nodeTemplate, attachedResourceId);
+ }
}
- }
-
- private void handleNetworkRequirement(TranslateTo translateTo, NodeTemplate nodeTemplate) {
- Optional<AttachedResourceId> networkResourceId =
- HeatToToscaUtil.extractAttachedResourceId(translateTo, "network");
- if (networkResourceId.isPresent()) {
- AttachedResourceId attachedResourceId = networkResourceId.get();
- addRequirementAssignmentForNetworkResource(translateTo, nodeTemplate, attachedResourceId);
- } else {
- networkResourceId = HeatToToscaUtil.extractAttachedResourceId(translateTo, "network_id");
- if (networkResourceId.isPresent()) {
- AttachedResourceId attachedResourceId = networkResourceId.get();
- addRequirementAssignmentForNetworkResource(translateTo, nodeTemplate, attachedResourceId);
- }
+
+ private void addLinkRequirementForGetParam(TranslateTo translateTo, NodeTemplate nodeTemplate,
+ AttachedResourceId attachedResourceId) {
+ TranslatedHeatResource translatedSharedResourceId =
+ translateTo.getContext().getHeatSharedResourcesByParam().get(attachedResourceId.getEntityId());
+ if (Objects.nonNull(translatedSharedResourceId)
+ && !HeatToToscaUtil.isHeatFileNested(translateTo, translateTo.getHeatFileName())) {
+ if (validateResourceTypeSupportedForReqCreation(translateTo, getSupportedNetworkResourceTypes(),
+ translatedSharedResourceId.getHeatResource(), "network'\\'network_id")) {
+ return;
+ }
+ RequirementAssignment requirementAssignment = HeatToToscaUtil.addLinkReqFromPortToNetwork(
+ nodeTemplate, translatedSharedResourceId.getTranslatedId());
+
+ ConsolidationDataUtil.updateNodesConnectedOut(translateTo,
+ translatedSharedResourceId.getTranslatedId(), ConsolidationEntityType.PORT,
+ ToscaConstants.LINK_REQUIREMENT_ID, requirementAssignment);
+ }
}
- }
-
- private void addRequirementAssignmentForNetworkResource(TranslateTo translateTo,
- NodeTemplate nodeTemplate,
- AttachedResourceId attachedResourceId) {
- String networkTranslatedId;
- List<String> supportedNetworkTypes =
- Arrays.asList(HeatResourcesTypes.NEUTRON_NET_RESOURCE_TYPE.getHeatResource(),
- HeatResourcesTypes.CONTRAIL_VIRTUAL_NETWORK_RESOURCE_TYPE.getHeatResource(),
- HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_NETWORK_RESOURCE_TYPE.getHeatResource());
- if (attachedResourceId.isGetResource()) {
- Resource networkHeatResource = translateTo.getHeatOrchestrationTemplate().getResources()
- .get(attachedResourceId.getEntityId());
- if (validateResourceTypeSupportedForReqCreation(translateTo, supportedNetworkTypes,
- networkHeatResource, "network'\\'network_id")) {
- return;
- }
- networkTranslatedId = (String) attachedResourceId.getTranslatedId();
- RequirementAssignment requirementAssignment = HeatToToscaUtil.addLinkReqFromPortToNetwork(
- nodeTemplate, networkTranslatedId);
-
- ConsolidationDataUtil.updateNodesConnectedOut(translateTo, networkTranslatedId,
- ConsolidationEntityType.PORT, ToscaConstants.LINK_REQUIREMENT_ID, requirementAssignment);
-
- } else if (attachedResourceId.isGetParam()
- && attachedResourceId.getEntityId() instanceof String) {
- TranslatedHeatResource translatedSharedResourceId =
- translateTo.getContext().getHeatSharedResourcesByParam()
- .get(attachedResourceId.getEntityId());
- if (Objects.nonNull(translatedSharedResourceId)
- && !HeatToToscaUtil.isHeatFileNested(translateTo, translateTo.getHeatFileName())) {
- if (validateResourceTypeSupportedForReqCreation(translateTo, supportedNetworkTypes,
- translatedSharedResourceId.getHeatResource(), "network'\\'network_id")) {
- return;
+
+ private void addLinkRequirementForGetResource(TranslateTo translateTo, NodeTemplate nodeTemplate,
+ AttachedResourceId attachedResourceId) {
+ String networkTranslatedId;
+ Resource networkHeatResource = translateTo.getHeatOrchestrationTemplate()
+ .getResources().get(attachedResourceId.getEntityId());
+ if (validateResourceTypeSupportedForReqCreation(translateTo, getSupportedNetworkResourceTypes(),
+ networkHeatResource, "network'\\'network_id")) {
+ return;
}
+ networkTranslatedId = (String) attachedResourceId.getTranslatedId();
RequirementAssignment requirementAssignment = HeatToToscaUtil.addLinkReqFromPortToNetwork(
- nodeTemplate, translatedSharedResourceId.getTranslatedId());
+ nodeTemplate, networkTranslatedId);
- ConsolidationDataUtil.updateNodesConnectedOut(translateTo,
- translatedSharedResourceId.getTranslatedId(), ConsolidationEntityType.PORT,
- ToscaConstants.LINK_REQUIREMENT_ID, requirementAssignment);
- }
+ ConsolidationDataUtil.updateNodesConnectedOut(translateTo, networkTranslatedId,
+ ConsolidationEntityType.PORT, ToscaConstants.LINK_REQUIREMENT_ID, requirementAssignment);
}
- }
-
-
- private boolean validateResourceTypeSupportedForReqCreation(TranslateTo translateTo,
- List<String> supportedTypes,
- Resource heatResource,
- final String propertyName) {
- if (!isResourceTypeSupported(heatResource, supportedTypes)) {
- logger.warn(
- "'" + propertyName + "' property of port resource('" + translateTo.getResourceId()
- + "') is pointing to a resource of type '" + heatResource.getType() + "' "
- + "which is not supported for this requirement. "
- + "Supported types are: " + supportedTypes.toString());
- return true;
+
+
+ private boolean validateResourceTypeSupportedForReqCreation(TranslateTo translateTo,
+ List<String> supportedTypes,
+ Resource heatResource,
+ final String propertyName) {
+ if (!isResourceTypeSupported(heatResource, supportedTypes)) {
+ String supportedResourceTypes = supportedTypes.toString();
+ logger.warn("'{}' property of port resource('{}') is pointing to a resource of type '{}' which is not "
+ + "supported for this requirement. Supported types are: {}", propertyName, translateTo
+ .getResourceId(), heatResource.getType(), supportedResourceTypes);
+ return true;
+ }
+ return false;
}
- return false;
- }
+ private List<String> getSupportedNetworkResourceTypes() {
+ return ImmutableList.of(HeatResourcesTypes.NEUTRON_NET_RESOURCE_TYPE.getHeatResource(),
+ HeatResourcesTypes.CONTRAIL_VIRTUAL_NETWORK_RESOURCE_TYPE.getHeatResource(),
+ HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_NETWORK_RESOURCE_TYPE.getHeatResource());
+ }
}
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 d18a2f214e..69231d5c51 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
@@ -1,39 +1,42 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
* 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 com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.NotSerializableException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
-import org.onap.sdc.tosca.services.ToscaExtensionYamlUtil;
-import org.onap.sdc.tosca.services.YamlUtil;
-import org.openecomp.core.utilities.CommonMethods;
-import org.openecomp.sdc.common.errors.CoreException;
-import org.openecomp.sdc.common.utils.CommonUtil;
-import org.openecomp.sdc.logging.api.Logger;
-import org.openecomp.sdc.logging.api.LoggerFactory;
-import org.openecomp.sdc.tosca.datatypes.ToscaCapabilityType;
-import org.openecomp.sdc.tosca.datatypes.ToscaFunctions;
-import org.openecomp.sdc.tosca.datatypes.ToscaRelationshipType;
import org.onap.sdc.tosca.datatypes.model.AttributeDefinition;
import org.onap.sdc.tosca.datatypes.model.CapabilityAssignment;
import org.onap.sdc.tosca.datatypes.model.CapabilityDefinition;
@@ -57,10 +60,19 @@ import org.onap.sdc.tosca.datatypes.model.RelationshipTemplate;
import org.onap.sdc.tosca.datatypes.model.RequirementAssignment;
import org.onap.sdc.tosca.datatypes.model.RequirementDefinition;
import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
-import org.onap.sdc.tosca.datatypes.model.Status;
import org.onap.sdc.tosca.datatypes.model.SubstitutionMapping;
import org.onap.sdc.tosca.datatypes.model.TopologyTemplate;
import org.onap.sdc.tosca.datatypes.model.heatextend.ParameterDefinitionExt;
+import org.onap.sdc.tosca.services.ToscaExtensionYamlUtil;
+import org.onap.sdc.tosca.services.YamlUtil;
+import org.openecomp.core.utilities.CommonMethods;
+import org.openecomp.sdc.common.errors.CoreException;
+import org.openecomp.sdc.common.utils.CommonUtil;
+import org.openecomp.sdc.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
+import org.openecomp.sdc.tosca.datatypes.ToscaCapabilityType;
+import org.openecomp.sdc.tosca.datatypes.ToscaFunctions;
+import org.openecomp.sdc.tosca.datatypes.ToscaRelationshipType;
import org.openecomp.sdc.tosca.errors.CreateInterfaceObjectErrorBuilder;
import org.openecomp.sdc.tosca.errors.CreateInterfaceOperationObjectErrorBuilder;
import org.openecomp.sdc.tosca.errors.InvalidAddActionNullEntityErrorBuilder;
@@ -68,1359 +80,1376 @@ import org.openecomp.sdc.tosca.errors.InvalidRequirementAssignmentErrorBuilder;
import org.openecomp.sdc.tosca.errors.ToscaInvalidInterfaceValueErrorBuilder;
import org.openecomp.sdc.tosca.services.impl.ToscaAnalyzerServiceImpl;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.NotSerializableException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.ListIterator;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.Set;
-
/**
* The type Data model util.
*/
public class DataModelUtil {
- private DataModelUtil() {
- // prevent instantiation
- }
-
- /**
- * Add substitution mapping.
- */
- private static final Logger logger = LoggerFactory.getLogger(DataModelUtil.class);
- private static final String SERVICE_TEMPLATE = "Service Template";
- private static final String NODE_TYPE = "Node Type";
- private static final String OPERATIONS = "operations";
-
- /**
- * Add substitution mapping.
- *
- * @param serviceTemplate the service template
- * @param substitutionMapping the substitution mapping
- */
- public static void addSubstitutionMapping(ServiceTemplate serviceTemplate,
- SubstitutionMapping substitutionMapping) {
- if (serviceTemplate == null) {
- throw new CoreException(
- new InvalidAddActionNullEntityErrorBuilder("Substitution Mapping", SERVICE_TEMPLATE)
- .build());
- }
-
- if (serviceTemplate.getTopology_template() == null) {
- serviceTemplate.setTopology_template(new TopologyTemplate());
- }
- serviceTemplate.getTopology_template().setSubstitution_mappings(substitutionMapping);
- }
-
- public static List<String> getDirectives(NodeTemplate nodeTemplate) {
- if (Objects.isNull(nodeTemplate)
- || Objects.isNull(nodeTemplate.getDirectives())) {
- return Collections.emptyList();
- }
-
- return nodeTemplate.getDirectives();
- }
-
- /**
- * Add substitution mapping req.
- *
- * @param serviceTemplate the service template
- * @param substitutionMappingRequirementId the substitution mapping requirement id
- * @param substitutionMappingRequirementList the substitution mapping requirement list
- */
- public static void addSubstitutionMappingReq(ServiceTemplate serviceTemplate,
- String substitutionMappingRequirementId,
- List<String> substitutionMappingRequirementList) {
- if (serviceTemplate == null) {
- throw new CoreException(
- new InvalidAddActionNullEntityErrorBuilder("Substitution Mapping Requirements",
- SERVICE_TEMPLATE).build());
- }
-
- if (serviceTemplate.getTopology_template() == null) {
- serviceTemplate.setTopology_template(new TopologyTemplate());
- }
- if (serviceTemplate.getTopology_template().getSubstitution_mappings() == null) {
- serviceTemplate.getTopology_template().setSubstitution_mappings(new SubstitutionMapping());
- }
- if (serviceTemplate.getTopology_template().getSubstitution_mappings().getRequirements()
- == null) {
- serviceTemplate.getTopology_template().getSubstitution_mappings()
- .setRequirements(new HashMap<>());
- }
-
- serviceTemplate.getTopology_template().getSubstitution_mappings().getRequirements()
- .put(substitutionMappingRequirementId, substitutionMappingRequirementList);
- }
-
- /**
- * Add substitution mapping capability.
- *
- * @param serviceTemplate the service template
- * @param substitutionMappingCapabilityId the substitution mapping capability id
- * @param substitutionMappingCapabilityList the substitution mapping capability list
- */
- public static void addSubstitutionMappingCapability(ServiceTemplate serviceTemplate,
- String substitutionMappingCapabilityId,
- List<String> substitutionMappingCapabilityList) {
- if (serviceTemplate == null) {
- throw new CoreException(
- new InvalidAddActionNullEntityErrorBuilder("Substitution Mapping Capabilities",
- SERVICE_TEMPLATE).build());
- }
-
- if (serviceTemplate.getTopology_template() == null) {
- serviceTemplate.setTopology_template(new TopologyTemplate());
- }
- if (serviceTemplate.getTopology_template().getSubstitution_mappings() == null) {
- serviceTemplate.getTopology_template().setSubstitution_mappings(new SubstitutionMapping());
- }
- if (serviceTemplate.getTopology_template().getSubstitution_mappings().getCapabilities()
- == null) {
- serviceTemplate.getTopology_template().getSubstitution_mappings()
- .setCapabilities(new HashMap<>());
- }
-
- serviceTemplate.getTopology_template().getSubstitution_mappings().getCapabilities()
- .putIfAbsent(substitutionMappingCapabilityId, substitutionMappingCapabilityList);
- }
-
- public static Map<String, NodeTemplate> getNodeTemplates(ServiceTemplate serviceTemplate) {
- if (Objects.isNull(serviceTemplate)
- || Objects.isNull(serviceTemplate.getTopology_template())
- || MapUtils.isEmpty(serviceTemplate.getTopology_template().getNode_templates())) {
- return new HashMap<>();
- }
-
- return serviceTemplate.getTopology_template().getNode_templates();
- }
-
- public static Map<String, GroupDefinition> getGroups(ServiceTemplate serviceTemplate) {
- if (Objects.isNull(serviceTemplate)
- || Objects.isNull(serviceTemplate.getTopology_template())
- || MapUtils.isEmpty(serviceTemplate.getTopology_template().getGroups())) {
- return new HashMap<>();
- }
-
- return serviceTemplate.getTopology_template().getGroups();
- }
-
- /**
- * Add node template.
- *
- * @param serviceTemplate the service template
- * @param nodeTemplateId the node template id
- * @param nodeTemplate the node template
- */
- public static void addNodeTemplate(ServiceTemplate serviceTemplate, String nodeTemplateId,
- NodeTemplate nodeTemplate) {
- if (serviceTemplate == null) {
- throw new CoreException(
- new InvalidAddActionNullEntityErrorBuilder("Node Template", SERVICE_TEMPLATE).build());
- }
- TopologyTemplate topologyTemplate = serviceTemplate.getTopology_template();
- if (Objects.isNull(topologyTemplate)) {
- topologyTemplate = new TopologyTemplate();
- serviceTemplate.setTopology_template(topologyTemplate);
- }
- if (topologyTemplate.getNode_templates() == null) {
- topologyTemplate.setNode_templates(new HashMap<>());
- }
- topologyTemplate.getNode_templates().put(nodeTemplateId, nodeTemplate);
- }
-
- /**
- * 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) {
- if (MapUtils.isEmpty(capabilities) || capabilities.entrySet().isEmpty()) {
- 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());
- }
- }
-
- /**
- * Add policy definition.
- *
- * @param serviceTemplate the service template
- * @param policyId the policy id
- * @param policyDefinition the policy definition
- */
- public static void addPolicyDefinition(ServiceTemplate serviceTemplate, String policyId,
- PolicyDefinition policyDefinition) {
- if (serviceTemplate == null) {
- throw new CoreException(
- new InvalidAddActionNullEntityErrorBuilder("Policy Definition", SERVICE_TEMPLATE)
- .build());
- }
- TopologyTemplate topologyTemplate = serviceTemplate.getTopology_template();
- if (Objects.isNull(topologyTemplate)) {
- topologyTemplate = new TopologyTemplate();
- serviceTemplate.setTopology_template(topologyTemplate);
- }
- if (topologyTemplate.getPolicies() == null) {
- topologyTemplate.setPolicies(new HashMap<>());
- }
- topologyTemplate.getPolicies().put(policyId, policyDefinition);
- }
-
- /**
- * Add node type.
- *
- * @param serviceTemplate the service template
- * @param nodeTypeId the node type id
- * @param nodeType the node type
- */
- public static void addNodeType(ServiceTemplate serviceTemplate, String nodeTypeId,
- NodeType nodeType) {
- if (serviceTemplate == null) {
- throw new CoreException(
- new InvalidAddActionNullEntityErrorBuilder(NODE_TYPE, SERVICE_TEMPLATE).build());
- }
- if (serviceTemplate.getNode_types() == null) {
- serviceTemplate.setNode_types(new HashMap<>());
- }
- serviceTemplate.getNode_types().put(nodeTypeId, nodeType);
- }
-
- public static void removeNodeType(ServiceTemplate serviceTemplate,
- String nodeTypeId) {
- if (serviceTemplate == null) {
- throw new CoreException(
- new InvalidAddActionNullEntityErrorBuilder(NODE_TYPE, SERVICE_TEMPLATE).build());
- }
- if (serviceTemplate.getNode_types() == null) {
- serviceTemplate.setNode_types(new HashMap<>());
- }
- serviceTemplate.getNode_types().remove(nodeTypeId);
- }
-
- /**
- * Add relationship template.
- *
- * @param serviceTemplate the service template
- * @param relationshipTemplateId the relationship template id
- * @param relationshipTemplate the relationship template
- */
- public static void addRelationshipTemplate(ServiceTemplate serviceTemplate,
- String relationshipTemplateId,
- RelationshipTemplate relationshipTemplate) {
- if (serviceTemplate == null) {
- throw new CoreException(
- new InvalidAddActionNullEntityErrorBuilder("Relationship Template", SERVICE_TEMPLATE)
- .build());
- }
- if (serviceTemplate.getTopology_template() == null) {
- serviceTemplate.setTopology_template(new TopologyTemplate());
- }
- if (serviceTemplate.getTopology_template().getRelationship_templates() == null) {
- serviceTemplate.getTopology_template().setRelationship_templates(new HashMap<>());
- }
- serviceTemplate.getTopology_template().getRelationship_templates()
- .put(relationshipTemplateId, relationshipTemplate);
- }
-
- /**
- * Add requirement assignment.
- *
- * @param nodeTemplate the node template
- * @param requirementId the requirement id
- * @param requirementAssignment the requirement assignment
- */
- public static void addRequirementAssignment(NodeTemplate nodeTemplate, String requirementId,
- RequirementAssignment requirementAssignment) {
- if (nodeTemplate == null) {
- throw new CoreException(
- new InvalidAddActionNullEntityErrorBuilder("Requirement Assignment", "Node Template")
- .build());
- }
- if (requirementAssignment.getNode() == null) {
- throw new CoreException(new InvalidRequirementAssignmentErrorBuilder(requirementId).build());
- }
-
- if (nodeTemplate.getRequirements() == null) {
- nodeTemplate.setRequirements(new ArrayList<>());
- }
- Map<String, RequirementAssignment> requirement = new HashMap<>();
- requirement.put(requirementId, requirementAssignment);
- nodeTemplate.getRequirements().add(requirement);
- }
-
- /**
- * Gets node template.
- *
- * @param serviceTemplate the service template
- * @param nodeTemplateId the node template id
- * @return the node template
- */
- public static NodeTemplate getNodeTemplate(ServiceTemplate serviceTemplate,
- String nodeTemplateId) {
- if (serviceTemplate == null
- || serviceTemplate.getTopology_template() == null
- || serviceTemplate.getTopology_template().getNode_templates() == null) {
- return null;
- }
- return serviceTemplate.getTopology_template().getNode_templates().get(nodeTemplateId);
- }
-
- /**
- * Gets node type.
- *
- * @param serviceTemplate the service template
- * @param nodeTypeId the node type id
- * @return the node type
- */
- public static NodeType getNodeType(ServiceTemplate serviceTemplate, String nodeTypeId) {
- if (serviceTemplate == null || serviceTemplate.getNode_types() == null) {
- return 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) {
- 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));
- }
- }
- return Optional.empty();
- }
-
- /**
- * get requirement definition from requirement definition list by req key.
- *
- * @param requirementsDefinitionList requirement definition list
- * @param requirementKey requirement key
- */
- public static Optional<RequirementDefinition> getRequirementDefinition(
- List<Map<String, RequirementDefinition>> requirementsDefinitionList,
- String requirementKey) {
- if (CollectionUtils.isEmpty(requirementsDefinitionList)) {
- return Optional.empty();
- }
-
- for (Map<String, RequirementDefinition> requirementMap : requirementsDefinitionList) {
- if (requirementMap.containsKey(requirementKey)) {
- return Optional.of(requirementMap.get(requirementKey));
- }
- }
- 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) {
- if (nodeType == null || nodeType.getCapabilities() == null || capabilityDefinitionId == null) {
- return Optional.empty();
- }
- return Optional.ofNullable(nodeType.getCapabilities().get(capabilityDefinitionId));
- }
-
- /**
- * Add group definition to topology template.
- *
- * @param serviceTemplate the service template
- * @param groupName the group name
- * @param group the group
- */
- public static void addGroupDefinitionToTopologyTemplate(ServiceTemplate serviceTemplate,
- String groupName, GroupDefinition group) {
- if (serviceTemplate == null) {
- throw new CoreException(
- new InvalidAddActionNullEntityErrorBuilder("Group Definition", SERVICE_TEMPLATE)
- .build());
- }
-
- TopologyTemplate topologyTemplate = serviceTemplate.getTopology_template();
- if (Objects.isNull(topologyTemplate)) {
- topologyTemplate = new TopologyTemplate();
- serviceTemplate.setTopology_template(topologyTemplate);
- }
- if (topologyTemplate.getGroups() == null) {
- topologyTemplate.setGroups(new HashMap<>());
- }
- if (serviceTemplate.getTopology_template().getGroups() == null) {
- Map<String, GroupDefinition> groups = new HashMap<>();
- serviceTemplate.getTopology_template().setGroups(groups);
- }
-
- serviceTemplate.getTopology_template().getGroups().put(groupName, group);
- }
-
- public static void addGroupMember(ServiceTemplate serviceTemplate,
- String groupName,
- String groupMemberId) {
- TopologyTemplate topologyTemplate = serviceTemplate.getTopology_template();
- if (Objects.isNull(topologyTemplate)
- || topologyTemplate.getGroups() == null
- || topologyTemplate.getGroups().get(groupName) == null) {
- return;
- }
-
- GroupDefinition groupDefinition = topologyTemplate.getGroups().get(groupName);
- if (CollectionUtils.isEmpty(groupDefinition.getMembers())) {
- groupDefinition.setMembers(new ArrayList<>());
- }
-
- if(!groupDefinition.getMembers().contains(groupMemberId)) {
- groupDefinition.getMembers().add(groupMemberId);
- }
- }
-
- /**
- * 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) {
- 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);
- return paramDef;
- }
-
- /**
- * Create requirement requirement definition.
- *
- * @param capability the capability
- * @param node the node
- * @param relationship the relationship
- * @param occurrences the occurrences
- * @return the requirement definition
- */
- public static RequirementDefinition createRequirement(String capability, String node,
- String relationship, Object[] occurrences) {
- RequirementDefinition requirementDefinition = new RequirementDefinition();
- requirementDefinition.setCapability(capability);
- requirementDefinition.setNode(node);
- requirementDefinition.setRelationship(relationship);
- if (occurrences != null) {
- requirementDefinition.setOccurrences(occurrences);
- }
- return requirementDefinition;
- }
-
- /**
- * Create entry schema entry schema.
- *
- * @param type the type
- * @param description the description
- * @param constraints the constraints
- * @return the entry schema
- */
- public static EntrySchema createEntrySchema(String type, String description,
- List<Constraint> constraints) {
- if (Objects.isNull(type) && Objects.isNull(description) &&
- CollectionUtils.isEmpty(constraints)) {
- return null;
- }
-
- EntrySchema entrySchema = new EntrySchema();
- entrySchema.setType(type);
- entrySchema.setDescription(description);
- entrySchema.setConstraints(constraints);
- return entrySchema;
- }
-
- /**
- * Create get input property value from list parameter map.
- *
- * @param inputPropertyListName the input property list name
- * @param indexInTheList the index in the list
- * @param nestedPropertyName the nested property name
- * @return the map
- */
- public static Map createGetInputPropertyValueFromListParameter(String inputPropertyListName,
- int indexInTheList,
- String... nestedPropertyName) {
- List propertyList = new ArrayList<>();
- propertyList.add(inputPropertyListName);
- propertyList.add(indexInTheList);
- if (nestedPropertyName != null) {
- Collections.addAll(propertyList, nestedPropertyName);
- }
- Map getInputProperty = new HashMap<>();
- getInputProperty.put(ToscaFunctions.GET_INPUT.getDisplayName(), propertyList);
- return getInputProperty;
- }
-
- /**
- * Convert property def to parameter def parameter definition ext.
- *
- * @param propertyDefinition the property definition
- * @return the parameter definition ext
- */
- public static ParameterDefinitionExt convertPropertyDefToParameterDef(
- PropertyDefinition propertyDefinition) {
- if (propertyDefinition == null) {
- return null;
- }
-
- ParameterDefinitionExt parameterDefinition = new ParameterDefinitionExt();
- parameterDefinition.setType(propertyDefinition.getType());
- parameterDefinition.setDescription(propertyDefinition.getDescription());
- parameterDefinition.setRequired(propertyDefinition.getRequired());
- parameterDefinition.set_default(propertyDefinition.get_default());
- parameterDefinition.setStatus(propertyDefinition.getStatus());
- parameterDefinition.setConstraints(propertyDefinition.getConstraints());
- parameterDefinition.setEntry_schema(Objects.isNull(propertyDefinition.getEntry_schema()) ? null
- : propertyDefinition.getEntry_schema().clone());
- parameterDefinition.setHidden(false);
- parameterDefinition.setImmutable(false);
- return parameterDefinition;
- }
-
- /**
- * Convert attribute def to parameter def parameter definition ext.
- *
- * @param attributeDefinition the attribute definition
- * @param outputValue the output value
- * @return the parameter definition ext
- */
- public static ParameterDefinitionExt convertAttributeDefToParameterDef(
- AttributeDefinition attributeDefinition, Map<String, List> outputValue) {
- if (attributeDefinition == null) {
- return null;
- }
- ParameterDefinitionExt parameterDefinition = new ParameterDefinitionExt();
- parameterDefinition.setDescription(attributeDefinition.getDescription());
- parameterDefinition.setValue(outputValue);
- return parameterDefinition;
- }
-
- 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) {
- if (Objects.isNull(serviceTemplate)) {
- 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);
- }
-
- /**
- * 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) {
- if (Objects.isNull(serviceTemplate)) {
- throw new CoreException(
- new InvalidAddActionNullEntityErrorBuilder("Topology Template Output 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);
- }
-
- /**
- * 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<>();
- }
-
- 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) {
- if (Objects.isNull(nodeTemplate)) {
- return null;
- }
- 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);
- }
- }
- return nodeTemplateRequirementsAssignment;
- }
-
- /**
- * Gets the list of requirements for the node template.
- *
- * @param nodeTemplate the node template
- * @return the node template requirement list and null if the node has no requirements
- */
- public static List<Map<String, RequirementAssignment>> getNodeTemplateRequirementList(
- NodeTemplate nodeTemplate) {
- 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);
- }
- return concreteRequirementList;
- }
-
- /**
- * get requirement assignment from requirement assignment list by req key.
- *
- * @param requirementsAssignmentList requirement definition list
- * @param requirementKey requirement key
- */
- public static Optional<List<RequirementAssignment>> getRequirementAssignment(
- List<Map<String, RequirementAssignment>> requirementsAssignmentList,
- String requirementKey) {
- if (CollectionUtils.isEmpty(requirementsAssignmentList)) {
- return Optional.empty();
- }
-
- List<RequirementAssignment> matchRequirementAssignmentList = new ArrayList<>();
- for (Map<String, RequirementAssignment> requirementMap : requirementsAssignmentList) {
- if (requirementMap.containsKey(requirementKey)) {
+ private static final Logger LOGGER = LoggerFactory.getLogger(DataModelUtil.class);
+ private static final String SERVICE_TEMPLATE = "Service Template";
+ private static final String NODE_TYPE = "Node Type";
+ private static final String OPERATIONS = "operations";
+
+ private DataModelUtil() {
+ // prevent instantiation
+ }
+
+ /**
+ * Add substitution mapping.
+ *
+ * @param serviceTemplate the service template
+ * @param substitutionMapping the substitution mapping
+ */
+ public static void addSubstitutionMapping(ServiceTemplate serviceTemplate,
+ SubstitutionMapping substitutionMapping) {
+ if (serviceTemplate == null) {
+ throw new CoreException(
+ new InvalidAddActionNullEntityErrorBuilder("Substitution Mapping", SERVICE_TEMPLATE)
+ .build());
+ }
+
+ if (serviceTemplate.getTopology_template() == null) {
+ serviceTemplate.setTopology_template(new TopologyTemplate());
+ }
+ serviceTemplate.getTopology_template().setSubstitution_mappings(substitutionMapping);
+ }
+
+ /**
+ * Gets node template directives.
+ *
+ * @param nodeTemplate the node template
+ * @return the directives
+ */
+ public static List<String> getDirectives(NodeTemplate nodeTemplate) {
+ if (Objects.isNull(nodeTemplate) || Objects.isNull(nodeTemplate.getDirectives())) {
+ return Collections.emptyList();
+ }
+ return nodeTemplate.getDirectives();
+ }
+
+ /**
+ * Add substitution mapping req.
+ *
+ * @param serviceTemplate the service template
+ * @param substitutionMappingRequirementId the substitution mapping requirement id
+ * @param substitutionMappingRequirementList the substitution mapping requirement list
+ */
+ public static void addSubstitutionMappingReq(ServiceTemplate serviceTemplate,
+ String substitutionMappingRequirementId,
+ List<String> substitutionMappingRequirementList) {
+ if (serviceTemplate == null) {
+ throw new CoreException(
+ new InvalidAddActionNullEntityErrorBuilder("Substitution Mapping Requirements",
+ SERVICE_TEMPLATE).build());
+ }
+
+ if (serviceTemplate.getTopology_template() == null) {
+ serviceTemplate.setTopology_template(new TopologyTemplate());
+ }
+ if (serviceTemplate.getTopology_template().getSubstitution_mappings() == null) {
+ serviceTemplate.getTopology_template().setSubstitution_mappings(new SubstitutionMapping());
+ }
+ if (serviceTemplate.getTopology_template().getSubstitution_mappings().getRequirements()
+ == null) {
+ serviceTemplate.getTopology_template().getSubstitution_mappings()
+ .setRequirements(new HashMap<>());
+ }
+
+ serviceTemplate.getTopology_template().getSubstitution_mappings().getRequirements()
+ .put(substitutionMappingRequirementId, substitutionMappingRequirementList);
+ }
+
+ /**
+ * Add substitution mapping capability.
+ *
+ * @param serviceTemplate the service template
+ * @param substitutionMappingCapabilityId the substitution mapping capability id
+ * @param substitutionMappingCapabilityList the substitution mapping capability list
+ */
+ public static void addSubstitutionMappingCapability(ServiceTemplate serviceTemplate,
+ String substitutionMappingCapabilityId,
+ List<String> substitutionMappingCapabilityList) {
+ if (serviceTemplate == null) {
+ throw new CoreException(
+ new InvalidAddActionNullEntityErrorBuilder("Substitution Mapping Capabilities",
+ SERVICE_TEMPLATE).build());
+ }
+
+ if (serviceTemplate.getTopology_template() == null) {
+ serviceTemplate.setTopology_template(new TopologyTemplate());
+ }
+ if (serviceTemplate.getTopology_template().getSubstitution_mappings() == null) {
+ serviceTemplate.getTopology_template().setSubstitution_mappings(new SubstitutionMapping());
+ }
+ if (serviceTemplate.getTopology_template().getSubstitution_mappings().getCapabilities()
+ == null) {
+ serviceTemplate.getTopology_template().getSubstitution_mappings()
+ .setCapabilities(new HashMap<>());
+ }
+
+ serviceTemplate.getTopology_template().getSubstitution_mappings().getCapabilities()
+ .putIfAbsent(substitutionMappingCapabilityId, substitutionMappingCapabilityList);
+ }
+
+ /**
+ * Gets node templates from the service template.
+ *
+ * @param serviceTemplate the service template
+ * @return the service template node templates and empty map if not present
+ */
+ public static Map<String, NodeTemplate> getNodeTemplates(ServiceTemplate serviceTemplate) {
+ if (Objects.isNull(serviceTemplate)
+ || Objects.isNull(serviceTemplate.getTopology_template())
+ || MapUtils.isEmpty(serviceTemplate.getTopology_template().getNode_templates())) {
+ return new HashMap<>();
+ }
+
+ return serviceTemplate.getTopology_template().getNode_templates();
+ }
+
+ /**
+ * Gets groups from the service template.
+ *
+ * @param serviceTemplate the service template
+ * @return the service template groups and empty map if not present
+ */
+ public static Map<String, GroupDefinition> getGroups(ServiceTemplate serviceTemplate) {
+ if (Objects.isNull(serviceTemplate)
+ || Objects.isNull(serviceTemplate.getTopology_template())
+ || MapUtils.isEmpty(serviceTemplate.getTopology_template().getGroups())) {
+ return new HashMap<>();
+ }
+
+ return serviceTemplate.getTopology_template().getGroups();
+ }
+
+ /**
+ * Add node template.
+ *
+ * @param serviceTemplate the service template
+ * @param nodeTemplateId the node template id
+ * @param nodeTemplate the node template
+ */
+ public static void addNodeTemplate(ServiceTemplate serviceTemplate, String nodeTemplateId,
+ NodeTemplate nodeTemplate) {
+ if (serviceTemplate == null) {
+ throw new CoreException(
+ new InvalidAddActionNullEntityErrorBuilder("Node Template", SERVICE_TEMPLATE).build());
+ }
+ TopologyTemplate topologyTemplate = serviceTemplate.getTopology_template();
+ if (Objects.isNull(topologyTemplate)) {
+ topologyTemplate = new TopologyTemplate();
+ serviceTemplate.setTopology_template(topologyTemplate);
+ }
+ if (topologyTemplate.getNode_templates() == null) {
+ topologyTemplate.setNode_templates(new HashMap<>());
+ }
+ topologyTemplate.getNode_templates().put(nodeTemplateId, nodeTemplate);
+ }
+
+ /**
+ * 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) {
+ if (MapUtils.isEmpty(capabilities) || capabilities.entrySet().isEmpty()) {
+ 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());
+ }
+ }
+
+ /**
+ * Add policy definition.
+ *
+ * @param serviceTemplate the service template
+ * @param policyId the policy id
+ * @param policyDefinition the policy definition
+ */
+ public static void addPolicyDefinition(ServiceTemplate serviceTemplate, String policyId,
+ PolicyDefinition policyDefinition) {
+ if (serviceTemplate == null) {
+ throw new CoreException(
+ new InvalidAddActionNullEntityErrorBuilder("Policy Definition", SERVICE_TEMPLATE)
+ .build());
+ }
+ TopologyTemplate topologyTemplate = serviceTemplate.getTopology_template();
+ if (Objects.isNull(topologyTemplate)) {
+ topologyTemplate = new TopologyTemplate();
+ serviceTemplate.setTopology_template(topologyTemplate);
+ }
+ if (topologyTemplate.getPolicies() == null) {
+ topologyTemplate.setPolicies(new HashMap<>());
+ }
+ topologyTemplate.getPolicies().put(policyId, policyDefinition);
+ }
+
+ /**
+ * Add node type.
+ *
+ * @param serviceTemplate the service template
+ * @param nodeTypeId the node type id
+ * @param nodeType the node type
+ */
+ public static void addNodeType(ServiceTemplate serviceTemplate, String nodeTypeId,
+ NodeType nodeType) {
+ if (serviceTemplate == null) {
+ throw new CoreException(
+ new InvalidAddActionNullEntityErrorBuilder(NODE_TYPE, SERVICE_TEMPLATE).build());
+ }
+ if (serviceTemplate.getNode_types() == null) {
+ serviceTemplate.setNode_types(new HashMap<>());
+ }
+ serviceTemplate.getNode_types().put(nodeTypeId, nodeType);
+ }
+
+ /**
+ * Add relationship template.
+ *
+ * @param serviceTemplate the service template
+ * @param relationshipTemplateId the relationship template id
+ * @param relationshipTemplate the relationship template
+ */
+ public static void addRelationshipTemplate(ServiceTemplate serviceTemplate,
+ String relationshipTemplateId,
+ RelationshipTemplate relationshipTemplate) {
+ if (serviceTemplate == null) {
+ throw new CoreException(
+ new InvalidAddActionNullEntityErrorBuilder("Relationship Template", SERVICE_TEMPLATE)
+ .build());
+ }
+ if (serviceTemplate.getTopology_template() == null) {
+ serviceTemplate.setTopology_template(new TopologyTemplate());
+ }
+ if (serviceTemplate.getTopology_template().getRelationship_templates() == null) {
+ serviceTemplate.getTopology_template().setRelationship_templates(new HashMap<>());
+ }
+ serviceTemplate.getTopology_template().getRelationship_templates()
+ .put(relationshipTemplateId, relationshipTemplate);
+ }
+
+ /**
+ * Add requirement assignment.
+ *
+ * @param nodeTemplate the node template
+ * @param requirementId the requirement id
+ * @param requirementAssignment the requirement assignment
+ */
+ public static void addRequirementAssignment(NodeTemplate nodeTemplate, String requirementId,
+ RequirementAssignment requirementAssignment) {
+ if (nodeTemplate == null) {
+ throw new CoreException(
+ new InvalidAddActionNullEntityErrorBuilder("Requirement Assignment", "Node Template")
+ .build());
+ }
+ if (requirementAssignment.getNode() == null) {
+ throw new CoreException(new InvalidRequirementAssignmentErrorBuilder(requirementId).build());
+ }
+
+ if (nodeTemplate.getRequirements() == null) {
+ nodeTemplate.setRequirements(new ArrayList<>());
+ }
+ Map<String, RequirementAssignment> requirement = new HashMap<>();
+ requirement.put(requirementId, requirementAssignment);
+ nodeTemplate.getRequirements().add(requirement);
+ }
+
+ /**
+ * Creates a new requirement assignment object for attachment requirement.
+ *
+ * @param node the node
+ * @return the attachment requirement assignment object
+ */
+ public static RequirementAssignment createAttachmentRequirementAssignment(String node) {
+ RequirementAssignment requirement = new RequirementAssignment();
+ requirement.setCapability(ToscaCapabilityType.NATIVE_ATTACHMENT);
+ requirement.setNode(node);
+ requirement.setRelationship(ToscaRelationshipType.ATTACHES_TO);
+ return requirement;
+ }
+
+ /**
+ * Gets node template.
+ *
+ * @param serviceTemplate the service template
+ * @param nodeTemplateId the node template id
+ * @return the node template
+ */
+ public static NodeTemplate getNodeTemplate(ServiceTemplate serviceTemplate,
+ String nodeTemplateId) {
+ if (serviceTemplate == null
+ || serviceTemplate.getTopology_template() == null
+ || serviceTemplate.getTopology_template().getNode_templates() == null) {
+ return null;
+ }
+ return serviceTemplate.getTopology_template().getNode_templates().get(nodeTemplateId);
+ }
+
+ /**
+ * Gets node type.
+ *
+ * @param serviceTemplate the service template
+ * @param nodeTypeId the node type id
+ * @return the node type
+ */
+ public static NodeType getNodeType(ServiceTemplate serviceTemplate, String nodeTypeId) {
+ if (serviceTemplate == null || serviceTemplate.getNode_types() == null) {
+ return 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) {
+ 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));
+ }
+ }
+ return Optional.empty();
+ }
+
+ /**
+ * get requirement definition from requirement definition list by req key.
+ *
+ * @param requirementsDefinitionList requirement definition list
+ * @param requirementKey requirement key
+ */
+ public static Optional<RequirementDefinition> getRequirementDefinition(
+ List<Map<String, RequirementDefinition>> requirementsDefinitionList,
+ String requirementKey) {
+ if (CollectionUtils.isEmpty(requirementsDefinitionList)) {
+ return Optional.empty();
+ }
+
+ for (Map<String, RequirementDefinition> requirementMap : requirementsDefinitionList) {
+ if (requirementMap.containsKey(requirementKey)) {
+ return Optional.of(requirementMap.get(requirementKey));
+ }
+ }
+ 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) {
+ if (nodeType == null || nodeType.getCapabilities() == null || capabilityDefinitionId == null) {
+ return Optional.empty();
+ }
+ return Optional.ofNullable(nodeType.getCapabilities().get(capabilityDefinitionId));
+ }
+
+ /**
+ * Add group definition to topology template.
+ *
+ * @param serviceTemplate the service template
+ * @param groupName the group name
+ * @param group the group
+ */
+ public static void addGroupDefinitionToTopologyTemplate(ServiceTemplate serviceTemplate,
+ String groupName, GroupDefinition group) {
+ if (serviceTemplate == null) {
+ throw new CoreException(
+ new InvalidAddActionNullEntityErrorBuilder("Group Definition", SERVICE_TEMPLATE)
+ .build());
+ }
+
+ TopologyTemplate topologyTemplate = serviceTemplate.getTopology_template();
+ if (Objects.isNull(topologyTemplate)) {
+ topologyTemplate = new TopologyTemplate();
+ serviceTemplate.setTopology_template(topologyTemplate);
+ }
+ if (topologyTemplate.getGroups() == null) {
+ topologyTemplate.setGroups(new HashMap<>());
+ }
+ if (serviceTemplate.getTopology_template().getGroups() == null) {
+ Map<String, GroupDefinition> groups = new HashMap<>();
+ serviceTemplate.getTopology_template().setGroups(groups);
+ }
+
+ serviceTemplate.getTopology_template().getGroups().put(groupName, group);
+ }
+
+ /**
+ * Adds a group member to an existing group in the service template.
+ *
+ * @param serviceTemplate the service template
+ * @param groupName the group name
+ * @param groupMemberId the group member id
+ */
+ public static void addGroupMember(ServiceTemplate serviceTemplate,
+ String groupName,
+ String groupMemberId) {
+ TopologyTemplate topologyTemplate = serviceTemplate.getTopology_template();
+ if (Objects.isNull(topologyTemplate)
+ || topologyTemplate.getGroups() == null
+ || topologyTemplate.getGroups().get(groupName) == null) {
+ return;
+ }
+
+ GroupDefinition groupDefinition = topologyTemplate.getGroups().get(groupName);
+ if (CollectionUtils.isEmpty(groupDefinition.getMembers())) {
+ groupDefinition.setMembers(new ArrayList<>());
+ }
+
+ if (!groupDefinition.getMembers().contains(groupMemberId)) {
+ groupDefinition.getMembers().add(groupMemberId);
+ }
+ }
+
+ /**
+ * Create parameter definition property definition.
+ *
+ * @param type the type
+ * @param description the description
+ * @param required the required
+ * @param constraints the constraints
+ * @param entrySchema the entry schema
+ * @param defaultVal the default val
+ * @return the property definition
+ */
+ public static ParameterDefinition createParameterDefinition(String type, String description,
+ boolean required,
+ List<Constraint> constraints,
+ EntrySchema entrySchema,
+ Object defaultVal) {
+ ParameterDefinition paramDef = new ParameterDefinition();
+ paramDef.setType(type);
+ paramDef.setDescription(description);
+ paramDef.setRequired(required);
+ paramDef.setConstraints(constraints);
+ paramDef.setEntry_schema(entrySchema == null ? null : entrySchema.clone());
+ paramDef.set_default(defaultVal);
+ return paramDef;
+ }
+
+ /**
+ * Create requirement requirement definition.
+ *
+ * @param capability the capability
+ * @param node the node
+ * @param relationship the relationship
+ * @param occurrences the occurrences
+ * @return the requirement definition
+ */
+ public static RequirementDefinition createRequirement(String capability, String node,
+ String relationship, Object[] occurrences) {
+ RequirementDefinition requirementDefinition = new RequirementDefinition();
+ requirementDefinition.setCapability(capability);
+ requirementDefinition.setNode(node);
+ requirementDefinition.setRelationship(relationship);
+ if (occurrences != null) {
+ requirementDefinition.setOccurrences(occurrences);
+ }
+ return requirementDefinition;
+ }
+
+ /**
+ * Create entry schema entry schema.
+ *
+ * @param type the type
+ * @param description the description
+ * @param constraints the constraints
+ * @return the entry schema
+ */
+ public static EntrySchema createEntrySchema(String type, String description,
+ List<Constraint> constraints) {
+ if (Objects.isNull(type) && Objects.isNull(description)
+ && CollectionUtils.isEmpty(constraints)) {
+ return null;
+ }
+
+ EntrySchema entrySchema = new EntrySchema();
+ entrySchema.setType(type);
+ entrySchema.setDescription(description);
+ entrySchema.setConstraints(constraints);
+ return entrySchema;
+ }
+
+ /**
+ * Create get input property value from list parameter map.
+ *
+ * @param inputPropertyListName the input property list name
+ * @param indexInTheList the index in the list
+ * @param nestedPropertyName the nested property name
+ * @return the map
+ */
+ public static Map createGetInputPropertyValueFromListParameter(String inputPropertyListName,
+ int indexInTheList,
+ String... nestedPropertyName) {
+ List<Object> propertyList = new ArrayList<>();
+ propertyList.add(inputPropertyListName);
+ propertyList.add(indexInTheList);
+ if (nestedPropertyName != null) {
+ Collections.addAll(propertyList, nestedPropertyName);
+ }
+ Map<String, Object> getInputProperty = new HashMap<>();
+ getInputProperty.put(ToscaFunctions.GET_INPUT.getDisplayName(), propertyList);
+ return getInputProperty;
+ }
+
+ /**
+ * Convert property def to parameter def parameter definition ext.
+ *
+ * @param propertyDefinition the property definition
+ * @return the parameter definition ext
+ */
+ public static ParameterDefinitionExt convertPropertyDefToParameterDef(
+ PropertyDefinition propertyDefinition) {
+ if (propertyDefinition == null) {
+ return null;
+ }
+
+ ParameterDefinitionExt parameterDefinition = new ParameterDefinitionExt();
+ parameterDefinition.setType(propertyDefinition.getType());
+ parameterDefinition.setDescription(propertyDefinition.getDescription());
+ parameterDefinition.setRequired(propertyDefinition.getRequired());
+ parameterDefinition.set_default(propertyDefinition.get_default());
+ parameterDefinition.setStatus(propertyDefinition.getStatus());
+ parameterDefinition.setConstraints(propertyDefinition.getConstraints());
+ parameterDefinition.setEntry_schema(Objects.isNull(propertyDefinition.getEntry_schema()) ? null
+ : propertyDefinition.getEntry_schema().clone());
+ parameterDefinition.setHidden(false);
+ parameterDefinition.setImmutable(false);
+ return parameterDefinition;
+ }
+
+ /**
+ * Convert attribute def to parameter def parameter definition ext.
+ *
+ * @param attributeDefinition the attribute definition
+ * @param outputValue the output value
+ * @return the parameter definition ext
+ */
+ public static ParameterDefinitionExt convertAttributeDefToParameterDef(
+ AttributeDefinition attributeDefinition, Map<String, List> outputValue) {
+ if (attributeDefinition == null) {
+ return null;
+ }
+ ParameterDefinitionExt parameterDefinition = new ParameterDefinitionExt();
+ parameterDefinition.setDescription(attributeDefinition.getDescription());
+ parameterDefinition.setValue(outputValue);
+ return parameterDefinition;
+ }
+
+ 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) {
+ if (Objects.isNull(serviceTemplate)) {
+ 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);
+ }
+
+ /**
+ * 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) {
+ if (Objects.isNull(serviceTemplate)) {
+ throw new CoreException(
+ new InvalidAddActionNullEntityErrorBuilder("Topology Template Output 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);
+ }
+
+ /**
+ * 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<>();
+ }
+
+ 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) {
+ if (Objects.isNull(nodeTemplate)) {
+ return null;
+ }
+ List<Map<String, RequirementAssignment>> templateRequirements = nodeTemplate.getRequirements();
+
+ Map<String, RequirementAssignment> nodeTemplateRequirementsAssignment = new HashMap<>();
+ if (CollectionUtils.isEmpty(templateRequirements)) {
+ return nodeTemplateRequirementsAssignment;
+ }
YamlUtil yamlUtil = new YamlUtil();
- RequirementAssignment requirementAssignment = (yamlUtil
- .yamlToObject(yamlUtil.objectToYaml(requirementMap.get(requirementKey)),
- RequirementAssignment.class));
- matchRequirementAssignmentList.add(requirementAssignment);
- }
- }
- if(CollectionUtils.isEmpty(matchRequirementAssignmentList)){
- return Optional.empty();
- }
- return Optional.of(matchRequirementAssignmentList);
- }
-
- /**
- * remove requirement definition from requirement definition list by req key.
- *
- * @param requirementsDefinitionList requirement definition list
- * @param requirementKey requirement key
- */
- public static void removeRequirementsDefinition(
- List<Map<String, RequirementDefinition>> requirementsDefinitionList,
- String requirementKey) {
- 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);
- }
- }
-
- /**
- * remove requirement assignment from requirement definition list by req key.
- *
- * @param requirementsAssignmentList requirement Assignment list
- * @param requirementKey requirement key
- */
- public static void removeRequirementsAssignment(
- List<Map<String, RequirementAssignment>> requirementsAssignmentList,
- String requirementKey) {
- 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);
- }
- }
-
-
- /**
- * 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) {
- ToscaAnalyzerService toscaAnalyzerService = new ToscaAnalyzerServiceImpl();
- List<Map<String, RequirementAssignment>> nodeTemplateRequirements = nodeTemplate
- .getRequirements();
- if (nodeTemplateRequirements == null) {
- return;
- }
-
- 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();
- }
- }
- }
- }
-
- /**
- * Return the suffix of the input namespace For an exampale - for abc.sdf.vsrx, return vsrx
- *
- * @param namespace namespace
- * @return String namespace suffix
- */
- public static String getNamespaceSuffix(String namespace) {
- if (namespace == null) {
- return null;
- }
- String delimiterChar = ".";
- if (namespace.contains(delimiterChar)) {
- return namespace.substring(namespace.lastIndexOf(delimiterChar) + 1);
- }
- return namespace;
- }
-
- /**
- * Return true if the input import exist in the input imports list.
- *
- * @param imports namespace
- * @param importId namespace
- * @return true if exist, false 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 ParameterDefinition getOuputParameter(ServiceTemplate serviceTemplate,
- String outputParameterId) {
- if (serviceTemplate == null
- || serviceTemplate.getTopology_template() == null
- || serviceTemplate.getTopology_template().getOutputs() == null) {
- return 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 serviceTemplate.getTopology_template().getInputs();
- }
-
- /**
- * Gets relationship templates in a service template.
- *
- * @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 Object getPropertyValue(NodeTemplate nodeTemplate,
- String propertyId) {
- if (nodeTemplate == null
- || nodeTemplate.getProperties() == null) {
- return 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) {
- if (serviceTemplate == null
- || serviceTemplate.getTopology_template() == null
- || serviceTemplate.getTopology_template().getNode_templates() == null
- || serviceTemplate.getTopology_template().getNode_templates().get(nodeTemplateId) == null) {
- return null;
- }
- return serviceTemplate.getTopology_template().getNode_templates().get(nodeTemplateId)
- .getProperties();
- }
-
- public static void addNodeTemplateProperty(NodeTemplate nodeTemplate,
+ 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);
+ }
+ }
+ return nodeTemplateRequirementsAssignment;
+ }
+
+ /**
+ * Gets the list of requirements for the node template.
+ *
+ * @param nodeTemplate the node template
+ * @return the node template requirement list and null if the node has no requirements
+ */
+ public static List<Map<String, RequirementAssignment>> getNodeTemplateRequirementList(
+ NodeTemplate nodeTemplate) {
+ 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);
+ }
+ return concreteRequirementList;
+ }
+
+ /**
+ * get requirement assignment from requirement assignment list by req key.
+ *
+ * @param requirementsAssignmentList requirement definition list
+ * @param requirementKey requirement key
+ */
+ public static Optional<List<RequirementAssignment>> getRequirementAssignment(
+ List<Map<String, RequirementAssignment>> requirementsAssignmentList,
+ String requirementKey) {
+ 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);
+ }
+ }
+ if (CollectionUtils.isEmpty(matchRequirementAssignmentList)) {
+ return Optional.empty();
+ }
+ return Optional.of(matchRequirementAssignmentList);
+ }
+
+ /**
+ * remove requirement definition from requirement definition list by req key.
+ *
+ * @param requirementsDefinitionList requirement definition list
+ * @param requirementKey requirement key
+ */
+ public static void removeRequirementsDefinition(
+ List<Map<String, RequirementDefinition>> requirementsDefinitionList,
+ String requirementKey) {
+ 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);
+ }
+ }
+
+ /**
+ * remove requirement assignment from requirement definition list by req key.
+ *
+ * @param requirementsAssignmentList requirement Assignment list
+ * @param requirementKey requirement key
+ */
+ public static void removeRequirementsAssignment(
+ List<Map<String, RequirementAssignment>> requirementsAssignmentList,
+ String requirementKey) {
+ 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);
+ }
+ }
+
+
+ /**
+ * 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) {
+ ToscaAnalyzerService toscaAnalyzerService = new ToscaAnalyzerServiceImpl();
+ List<Map<String, RequirementAssignment>> nodeTemplateRequirements = nodeTemplate
+ .getRequirements();
+ if (nodeTemplateRequirements == null) {
+ return;
+ }
+
+ 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();
+ }
+ }
+ }
+ }
+
+ /**
+ * Return the suffix of the input namespace For an exampale - for abc.sdf.vsrx, return vsrx
+ *
+ * @param namespace namespace
+ * @return String namespace suffix
+ */
+ public static String getNamespaceSuffix(String namespace) {
+ if (namespace == null) {
+ return null;
+ }
+ String delimiterChar = ".";
+ if (namespace.contains(delimiterChar)) {
+ return namespace.substring(namespace.lastIndexOf(delimiterChar) + 1);
+ }
+ return namespace;
+ }
+
+ /**
+ * Return true if the input import exist in the input imports list.
+ *
+ * @param imports namespace
+ * @param importId namespace
+ * @return true if exist, false 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 ParameterDefinition getOuputParameter(ServiceTemplate serviceTemplate,
+ String outputParameterId) {
+ if (serviceTemplate == null
+ || serviceTemplate.getTopology_template() == null
+ || serviceTemplate.getTopology_template().getOutputs() == null) {
+ return 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 serviceTemplate.getTopology_template().getInputs();
+ }
+
+ /**
+ * Gets relationship templates in a service template.
+ *
+ * @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 Object getPropertyValue(NodeTemplate nodeTemplate,
+ String propertyId) {
+ if (nodeTemplate == null
+ || nodeTemplate.getProperties() == null) {
+ return 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) {
+ if (serviceTemplate == null
+ || serviceTemplate.getTopology_template() == null
+ || serviceTemplate.getTopology_template().getNode_templates() == null
+ || serviceTemplate.getTopology_template().getNode_templates().get(nodeTemplateId) == null) {
+ return null;
+ }
+ return serviceTemplate.getTopology_template().getNode_templates().get(nodeTemplateId)
+ .getProperties();
+ }
+
+ /**
+ * Adds a property to a node template.
+ *
+ * @param nodeTemplate the node template
+ * @param propertyKey the property key
+ * @param propertyValue the property value
+ */
+ public static void addNodeTemplateProperty(NodeTemplate nodeTemplate,
String propertyKey,
Object propertyValue) {
- if (Objects.isNull(nodeTemplate)) {
- return;
- }
-
- if(MapUtils.isEmpty(nodeTemplate.getProperties())) {
- nodeTemplate.setProperties(new HashMap<>());
- }
-
- nodeTemplate.getProperties().put(propertyKey, propertyValue);
- }
-
- /**
- * Gets substitution mappings in a service template.
- *
- * @param serviceTemplate the service template
- * @return the substitution mappings
- */
- public static SubstitutionMapping getSubstitutionMappings(ServiceTemplate serviceTemplate) {
- if (serviceTemplate == null
- || serviceTemplate.getTopology_template() == null
- || serviceTemplate.getTopology_template().getSubstitution_mappings() == null) {
- return null;
- }
- return serviceTemplate.getTopology_template().getSubstitution_mappings();
- }
-
-
- /**
- * Compare two requirement assignment objects for equality.
- *
- * @param first the first requirement assignment object
- * @param second the second requirement assignment object
- * @return true if objects are equal and false otherwise
- */
- public static boolean compareRequirementAssignment(RequirementAssignment first,
- RequirementAssignment second) {
- return (first.getCapability().equals(second.getCapability())
- && first.getNode().equals(second.getNode())
- && first.getRelationship().equals(second.getRelationship()));
- }
-
- /**
- * Gets a deep copy clone of the input object.
- *
- * @param <T> the type parameter
- * @param objectValue the object value
- * @param clazz the clazz
- * @return the cloned object
- */
- public static <T> Object getClonedObject(Object objectValue, Class<T> clazz) {
- YamlUtil yamlUtil = new ToscaExtensionYamlUtil();
- Object clonedObjectValue;
- String objectToYaml = yamlUtil.objectToYaml(objectValue);
- clonedObjectValue = yamlUtil.yamlToObject(objectToYaml, clazz);
- return clonedObjectValue;
- }
-
- /**
- * Gets a deep copy clone of the input object.
- *
- * @param obj the object to be cloned
- * @return the cloned object
- */
- public static Object getClonedObject(Object obj) {
- Object clonedObjectValue;
- try {
- //Serialize object
- ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
- ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
- objectOutputStream.writeObject(obj);
- //Deserialize object
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream
- .toByteArray());
- ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
- clonedObjectValue = objectInputStream.readObject();
- } catch (NotSerializableException ex) {
- logger.debug(ex.getMessage(), ex);
- return getClonedObject(obj, obj.getClass());
- } catch (IOException | ClassNotFoundException ex) {
- logger.debug(ex.getMessage(), ex);
- return null;
- }
- return clonedObjectValue;
- }
-
- /**
- * Add substitution filtering property.
- *
- * @param templateName the substitution service template name
- * @param nodeTemplate the node template
- * @param count the count
- */
- public static void addSubstitutionFilteringProperty(String templateName,
- NodeTemplate nodeTemplate, int count) {
- Map<String, Object> serviceTemplateFilterPropertyValue = new HashMap<>();
- Map<String, Object> properties = nodeTemplate.getProperties();
- serviceTemplateFilterPropertyValue.put(ToscaConstants
- .SUBSTITUTE_SERVICE_TEMPLATE_PROPERTY_NAME, templateName);
- serviceTemplateFilterPropertyValue.put(ToscaConstants.COUNT_PROPERTY_NAME, count);
- properties.put(ToscaConstants.SERVICE_TEMPLATE_FILTER_PROPERTY_NAME,
- serviceTemplateFilterPropertyValue);
- nodeTemplate.setProperties(properties);
- }
-
- /**
- * Adding binding requirement from port node template to compute node template.
- *
- * @param computeNodeTemplateId compute node template id
- * @param portNodeTemplate port node template
- */
- public static void addBindingReqFromPortToCompute(String computeNodeTemplateId,
- NodeTemplate portNodeTemplate) {
- RequirementAssignment requirementAssignment = new RequirementAssignment();
- requirementAssignment.setCapability(ToscaCapabilityType.NATIVE_NETWORK_BINDABLE);
- requirementAssignment.setRelationship(ToscaRelationshipType.NATIVE_NETWORK_BINDS_TO);
- requirementAssignment.setNode(computeNodeTemplateId);
- addRequirementAssignment(portNodeTemplate, ToscaConstants.BINDING_REQUIREMENT_ID,
- requirementAssignment);
- }
-
- public static SubstitutionMapping createSubstitutionTemplateSubMapping(
- String nodeTypeKey,
- NodeType substitutionNodeType,
- Map<String, Map<String, List<String>>> mapping) {
- SubstitutionMapping substitutionMapping = new SubstitutionMapping();
- substitutionMapping.setNode_type(nodeTypeKey);
- substitutionMapping.setCapabilities(
- manageCapabilityMapping(substitutionNodeType.getCapabilities(), mapping.get("capability")));
- substitutionMapping.setRequirements(
- manageRequirementMapping(substitutionNodeType.getRequirements(),
- mapping.get("requirement")));
- return substitutionMapping;
- }
-
- /**
- * Add node template capability.
- *
- * @param nodeTemplate the node template
- * @param capabilityId the capability id
- * @param capabilityProperties the capability properties
- * @param capabilityAttributes the capability attributes
- */
- public static void addNodeTemplateCapability(NodeTemplate nodeTemplate, String capabilityId,
- Map<String, Object> capabilityProperties,
- Map<String, Object> capabilityAttributes) {
- Map<String, CapabilityAssignment> capabilities = nodeTemplate.getCapabilities();
- if (Objects.isNull(capabilities)) {
- capabilities = new HashMap<>();
- }
- CapabilityAssignment capabilityAssignment = new CapabilityAssignment();
- capabilityAssignment.setProperties(capabilityProperties);
- capabilityAssignment.setAttributes(capabilityAttributes);
- capabilities.put(capabilityId, capabilityAssignment);
- nodeTemplate.setCapabilities(capabilities);
- }
-
- private static Map<String, List<String>> manageRequirementMapping(
- List<Map<String, RequirementDefinition>> requirementList,
- Map<String, List<String>> requirementSubstitutionMapping) {
- if (requirementList == null) {
- return null;
- }
- Map<String, List<String>> requirementMapping = new HashMap<>();
- String requirementKey;
- List<String> requirementMap;
- for (Map<String, RequirementDefinition> requirementDefMap : requirementList) {
- for (Map.Entry<String, RequirementDefinition> entry : requirementDefMap.entrySet()) {
- requirementKey = entry.getKey();
- requirementMap = requirementSubstitutionMapping.get(requirementKey);
- requirementMapping.put(requirementKey, requirementMap);
- }
- }
- return requirementMapping;
- }
-
- private static Map<String, List<String>> manageCapabilityMapping(
- Map<String, CapabilityDefinition> capabilities,
- Map<String, List<String>> capabilitySubstitutionMapping) {
- if (capabilities == null) {
- return null;
- }
-
- Map<String, List<String>> capabilityMapping = new HashMap<>();
- String capabilityKey;
- List<String> capabilityMap;
- for (Map.Entry<String, CapabilityDefinition> entry : capabilities.entrySet()) {
- capabilityKey = entry.getKey();
- capabilityMap = capabilitySubstitutionMapping.get(capabilityKey);
- capabilityMapping.put(capabilityKey, capabilityMap);
- }
- return capabilityMapping;
- }
-
-
- public static void addInterfaceOperation(ServiceTemplate serviceTemplate,
- String interfaceId,
- String operationId,
- OperationDefinition operationDefinition) {
- Map<String, Object> interfaceTypes = serviceTemplate.getInterface_types();
- if (MapUtils.isEmpty(interfaceTypes)
- || Objects.isNull(interfaceTypes.get(interfaceId))) {
- return;
- }
-
- Object interfaceObject = interfaceTypes.get(interfaceId);
- Map<String, Object> interfaceAsMap = CommonUtil.getObjectAsMap(interfaceObject);
- interfaceAsMap.put(operationId, operationDefinition);
- }
-
- public static Map<String, InterfaceType> getInterfaceTypes(ServiceTemplate serviceTemplate) {
- Map<String, Object> interfaceTypes = serviceTemplate.getInterface_types();
-
- if (MapUtils.isEmpty(interfaceTypes)) {
- return new HashMap<>();
- }
-
- Map<String, InterfaceType> convertedInterfaceTypes = new HashMap<>();
- for (Map.Entry<String, Object> interfaceEntry : interfaceTypes.entrySet()) {
- try {
- Optional<InterfaceType> interfaceType =
- convertObjToInterfaceType(interfaceEntry.getKey(), interfaceEntry.getValue());
- interfaceType.ifPresent(
- interfaceValue -> convertedInterfaceTypes.put(interfaceEntry.getKey(), interfaceValue));
- } catch (Exception e) {
- throw new CoreException(
- new ToscaInvalidInterfaceValueErrorBuilder(e.getMessage()).build());
- }
- }
-
- return convertedInterfaceTypes;
- }
-
- public static <T extends InterfaceDefinition> Optional<T>
- convertObjToInterfaceDefinition(
- String interfaceId, Object interfaceObj, Class<T> interfaceClass) {
-
- try {
- Optional<T> interfaceDefinition =
- CommonUtil.createObjectUsingSetters(interfaceObj, interfaceClass);
- interfaceDefinition.ifPresent(interfaceDefinitionType1 -> updateInterfaceDefinitionOperations(
- CommonUtil.getObjectAsMap(interfaceObj),
- interfaceDefinitionType1, getOperationClass(interfaceClass)));
- return interfaceDefinition;
- } catch (Exception ex) {
- throw new CoreException(
- new CreateInterfaceObjectErrorBuilder(InterfaceDefinitionType.class.getName(),
- interfaceId,
- ex.getMessage()).build());
- }
-
- }
-
- private static <T extends OperationDefinition, V extends InterfaceDefinition> Class<T> getOperationClass(
- Class<V> interfaceClass) {
- return interfaceClass.equals(InterfaceDefinitionType.class)
- ? (Class<T>) OperationDefinitionType.class
- :
- (Class<T>) OperationDefinitionTemplate.class;
- }
-
- public static Optional<Object> convertInterfaceDefinitionToObj(
- InterfaceDefinitionType interfaceDefinitionType) {
- return converInetrfaceToToscaInterfaceObj(interfaceDefinitionType);
- }
-
- public static Optional<InterfaceType> convertObjToInterfaceType(String interfaceId,
- Object interfaceObj) {
- try {
- Optional<InterfaceType> interfaceType =
- CommonUtil.createObjectUsingSetters(interfaceObj, InterfaceType.class);
- interfaceType.ifPresent(
- interfaceType1 -> updateInterfaceTypeOperations(CommonUtil.getObjectAsMap(interfaceObj),
- interfaceType1));
- return interfaceType;
- } catch (Exception ex) {
- throw new CoreException(
- new CreateInterfaceObjectErrorBuilder(InterfaceType.class.getName(), interfaceId,
- ex.getMessage()).build());
- }
- }
-
- public static Optional<Object> convertInterfaceTypeToObj(InterfaceType interfaceType) {
- return converInetrfaceToToscaInterfaceObj(interfaceType);
- }
-
- private static Optional<Object> converInetrfaceToToscaInterfaceObj(Object interfaceEntity) {
- if (Objects.isNull(interfaceEntity)) {
- return Optional.empty();
- }
-
- Map<String, Object> interfaceAsMap = CommonUtil.getObjectAsMap(interfaceEntity);
- Map<String, Object> operations = (Map<String, Object>) interfaceAsMap.get(OPERATIONS);
- if (MapUtils.isNotEmpty(operations)) {
- interfaceAsMap.remove(OPERATIONS);
- interfaceAsMap.putAll(operations);
- }
-
- ObjectMapper objectMapper = new ObjectMapper();
- objectMapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false);
- return Optional.of(objectMapper.convertValue(interfaceAsMap, Object.class));
- }
-
- private static void updateInterfaceTypeOperations(Map<String, Object> interfaceAsMap,
- InterfaceType interfaceType) {
-
- Set<String> fieldNames = CommonUtil.getClassFieldNames(InterfaceType.class);
-
- for (Map.Entry<String, Object> entry : interfaceAsMap.entrySet()) {
- Optional<? extends OperationDefinition> operationDefinition =
- createOperation(entry.getKey(), entry.getValue(), fieldNames,
- OperationDefinitionType.class);
- operationDefinition
- .ifPresent(operation -> interfaceType.addOperation(entry.getKey(), operation));
- }
- }
-
- private static Optional<? extends OperationDefinition> createOperation(String propertyName,
- Object operationCandidate,
- Set<String> fieldNames,
- Class<? extends OperationDefinition> operationClass) {
- if (!fieldNames.contains(propertyName)) {
- try {
- return CommonUtil.createObjectUsingSetters(operationCandidate, operationClass);
- } catch (Exception ex) {
- throw new CoreException(
- new CreateInterfaceOperationObjectErrorBuilder(propertyName, ex.getMessage()).build());
- }
- }
-
- return Optional.empty();
- }
-
- private static <T extends OperationDefinition> void updateInterfaceDefinitionOperations
- (Map<String, Object> interfaceAsMap, InterfaceDefinition interfaceDefinition,
- Class<T> operationClass) {
-
- Set<String> fieldNames = CommonUtil.getClassFieldNames(interfaceDefinition.getClass());
- Optional<? extends OperationDefinition> operationDefinition;
-
- for (Map.Entry<String, Object> entry : interfaceAsMap.entrySet()) {
- operationDefinition =
- createOperation(entry.getKey(), entry.getValue(), fieldNames, operationClass);
- operationDefinition.ifPresent(operation -> addOperationToInterface(interfaceDefinition,
- entry.getKey(), operation));
- }
- }
-
- private static void addOperationToInterface(InterfaceDefinition interfaceDefinition,
- String operationName,
- OperationDefinition operationDefinition) {
- if (interfaceDefinition instanceof InterfaceDefinitionType) {
- InterfaceDefinitionType interfaceDefinitionType =
- (InterfaceDefinitionType) interfaceDefinition;
- interfaceDefinitionType.addOperation(operationName, (OperationDefinitionType)
- operationDefinition);
- }
- if (interfaceDefinition instanceof InterfaceDefinitionTemplate) {
- InterfaceDefinitionTemplate interfaceDefinitionTemplate =
- (InterfaceDefinitionTemplate) interfaceDefinition;
- interfaceDefinitionTemplate.addOperation(operationName, (OperationDefinitionTemplate)
- operationDefinition);
- }
- }
-
- public static void addSubstitutionNodeTypeRequirements(NodeType substitutionNodeType,
- List<Map<String, RequirementDefinition>>
- requirementsList,
- String templateName) {
- if (CollectionUtils.isEmpty(requirementsList)) {
- return;
- }
-
- if (substitutionNodeType.getRequirements() == null) {
- substitutionNodeType.setRequirements(new ArrayList<>());
- }
+ if (Objects.isNull(nodeTemplate)) {
+ return;
+ }
- for (Map<String, RequirementDefinition> requirementDef : requirementsList) {
- for (Map.Entry<String, RequirementDefinition> entry : requirementDef.entrySet()) {
- Map<String, RequirementDefinition> requirementMap = new HashMap<>();
- requirementMap.put(entry.getKey() + "_" + templateName, entry.getValue().clone());
- substitutionNodeType.getRequirements().add(requirementMap);
- }
- }
- }
+ if (MapUtils.isEmpty(nodeTemplate.getProperties())) {
+ nodeTemplate.setProperties(new HashMap<>());
+ }
- public static boolean isNodeTemplateSectionMissingFromServiceTemplate(
- ServiceTemplate serviceTemplate) {
- return Objects.isNull(serviceTemplate.getTopology_template())
- || MapUtils.isEmpty(serviceTemplate.getTopology_template().getNode_templates());
- }
+ nodeTemplate.getProperties().put(propertyKey, propertyValue);
+ }
+
+ /**
+ * Gets substitution mappings in a service template.
+ *
+ * @param serviceTemplate the service template
+ * @return the substitution mappings
+ */
+ public static SubstitutionMapping getSubstitutionMappings(ServiceTemplate serviceTemplate) {
+ if (serviceTemplate == null
+ || serviceTemplate.getTopology_template() == null
+ || serviceTemplate.getTopology_template().getSubstitution_mappings() == null) {
+ return null;
+ }
+ return serviceTemplate.getTopology_template().getSubstitution_mappings();
+ }
+
+
+ /**
+ * Compare two requirement assignment objects for equality.
+ *
+ * @param first the first requirement assignment object
+ * @param second the second requirement assignment object
+ * @return true if objects are equal and false otherwise
+ */
+ public static boolean compareRequirementAssignment(RequirementAssignment first,
+ RequirementAssignment second) {
+ return (
+ first.getCapability().equals(second.getCapability())
+ && first.getNode().equals(second.getNode())
+ && first.getRelationship().equals(second.getRelationship()));
+ }
+
+ /**
+ * Gets a deep copy clone of the input object.
+ *
+ * @param <T> the type parameter
+ * @param objectValue the object value
+ * @param clazz the clazz
+ * @return the cloned object
+ */
+ public static <T> Object getClonedObject(Object objectValue, Class<T> clazz) {
+ YamlUtil yamlUtil = new ToscaExtensionYamlUtil();
+ Object clonedObjectValue;
+ String objectToYaml = yamlUtil.objectToYaml(objectValue);
+ clonedObjectValue = yamlUtil.yamlToObject(objectToYaml, clazz);
+ return clonedObjectValue;
+ }
+
+ /**
+ * Gets a deep copy clone of the input object.
+ *
+ * @param obj the object to be cloned
+ * @return the cloned object
+ */
+ public static Object getClonedObject(Object obj) {
+ Object clonedObjectValue;
+ try {
+ //Serialize object
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
+ objectOutputStream.writeObject(obj);
+ //Deserialize object
+ ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream
+ .toByteArray());
+ ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
+ clonedObjectValue = objectInputStream.readObject();
+ } catch (NotSerializableException ex) {
+ LOGGER.debug(ex.getMessage(), ex);
+ return getClonedObject(obj, obj.getClass());
+ } catch (IOException | ClassNotFoundException ex) {
+ LOGGER.debug(ex.getMessage(), ex);
+ return null;
+ }
+ return clonedObjectValue;
+ }
+
+ /**
+ * Add substitution filtering property.
+ *
+ * @param templateName the substitution service template name
+ * @param nodeTemplate the node template
+ * @param count the count
+ */
+ public static void addSubstitutionFilteringProperty(String templateName,
+ NodeTemplate nodeTemplate, int count) {
+ Map<String, Object> serviceTemplateFilterPropertyValue = new HashMap<>();
+ Map<String, Object> properties = nodeTemplate.getProperties();
+ serviceTemplateFilterPropertyValue.put(ToscaConstants
+ .SUBSTITUTE_SERVICE_TEMPLATE_PROPERTY_NAME, templateName);
+ serviceTemplateFilterPropertyValue.put(ToscaConstants.COUNT_PROPERTY_NAME, count);
+ properties.put(ToscaConstants.SERVICE_TEMPLATE_FILTER_PROPERTY_NAME,
+ serviceTemplateFilterPropertyValue);
+ nodeTemplate.setProperties(properties);
+ }
+
+ /**
+ * Adding binding requirement from port node template to compute node template.
+ *
+ * @param computeNodeTemplateId compute node template id
+ * @param portNodeTemplate port node template
+ */
+ public static void addBindingReqFromPortToCompute(String computeNodeTemplateId,
+ NodeTemplate portNodeTemplate) {
+ RequirementAssignment requirementAssignment = new RequirementAssignment();
+ requirementAssignment.setCapability(ToscaCapabilityType.NATIVE_NETWORK_BINDABLE);
+ requirementAssignment.setRelationship(ToscaRelationshipType.NATIVE_NETWORK_BINDS_TO);
+ requirementAssignment.setNode(computeNodeTemplateId);
+ addRequirementAssignment(portNodeTemplate, ToscaConstants.BINDING_REQUIREMENT_ID,
+ requirementAssignment);
+ }
+
+ /**
+ * Create substitution template substitution mapping.
+ *
+ * @param nodeTypeKey the node type key
+ * @param substitutionNodeType the substitution node type
+ * @param mapping the mapping
+ * @return the substitution mapping
+ */
+ public static SubstitutionMapping createSubstitutionTemplateSubMapping(
+ String nodeTypeKey,
+ NodeType substitutionNodeType,
+ Map<String, Map<String, List<String>>> mapping) {
+ SubstitutionMapping substitutionMapping = new SubstitutionMapping();
+ substitutionMapping.setNode_type(nodeTypeKey);
+ substitutionMapping.setCapabilities(
+ manageCapabilityMapping(substitutionNodeType.getCapabilities(), mapping.get("capability")));
+ substitutionMapping.setRequirements(
+ manageRequirementMapping(substitutionNodeType.getRequirements(),
+ mapping.get("requirement")));
+ return substitutionMapping;
+ }
+
+ /**
+ * Add node template capability.
+ *
+ * @param nodeTemplate the node template
+ * @param capabilityId the capability id
+ * @param capabilityProperties the capability properties
+ * @param capabilityAttributes the capability attributes
+ */
+ public static void addNodeTemplateCapability(NodeTemplate nodeTemplate, String capabilityId,
+ Map<String, Object> capabilityProperties,
+ Map<String, Object> capabilityAttributes) {
+ Map<String, CapabilityAssignment> capabilities = nodeTemplate.getCapabilities();
+ if (Objects.isNull(capabilities)) {
+ capabilities = new HashMap<>();
+ }
+ CapabilityAssignment capabilityAssignment = new CapabilityAssignment();
+ capabilityAssignment.setProperties(capabilityProperties);
+ capabilityAssignment.setAttributes(capabilityAttributes);
+ capabilities.put(capabilityId, capabilityAssignment);
+ nodeTemplate.setCapabilities(capabilities);
+ }
+
+ private static Map<String, List<String>> manageRequirementMapping(
+ List<Map<String, RequirementDefinition>> requirementList,
+ Map<String, List<String>> requirementSubstitutionMapping) {
+ if (requirementList == null) {
+ return null;
+ }
+ Map<String, List<String>> requirementMapping = new HashMap<>();
+ String requirementKey;
+ List<String> requirementMap;
+ for (Map<String, RequirementDefinition> requirementDefMap : requirementList) {
+ for (Map.Entry<String, RequirementDefinition> entry : requirementDefMap.entrySet()) {
+ requirementKey = entry.getKey();
+ requirementMap = requirementSubstitutionMapping.get(requirementKey);
+ requirementMapping.put(requirementKey, requirementMap);
+ }
+ }
+ return requirementMapping;
+ }
+
+ private static Map<String, List<String>> manageCapabilityMapping(
+ Map<String, CapabilityDefinition> capabilities,
+ Map<String, List<String>> capabilitySubstitutionMapping) {
+ if (capabilities == null) {
+ return null;
+ }
+
+ Map<String, List<String>> capabilityMapping = new HashMap<>();
+ String capabilityKey;
+ List<String> capabilityMap;
+ for (Map.Entry<String, CapabilityDefinition> entry : capabilities.entrySet()) {
+ capabilityKey = entry.getKey();
+ capabilityMap = capabilitySubstitutionMapping.get(capabilityKey);
+ capabilityMapping.put(capabilityKey, capabilityMap);
+ }
+ return capabilityMapping;
+ }
+
+
+ public static void addInterfaceOperation(ServiceTemplate serviceTemplate,
+ String interfaceId,
+ String operationId,
+ OperationDefinition operationDefinition) {
+ Map<String, Object> interfaceTypes = serviceTemplate.getInterface_types();
+ if (MapUtils.isEmpty(interfaceTypes)
+ || Objects.isNull(interfaceTypes.get(interfaceId))) {
+ return;
+ }
+
+ Object interfaceObject = interfaceTypes.get(interfaceId);
+ Map<String, Object> interfaceAsMap = CommonUtil.getObjectAsMap(interfaceObject);
+ interfaceAsMap.put(operationId, operationDefinition);
+ }
+
+ public static Map<String, InterfaceType> getInterfaceTypes(ServiceTemplate serviceTemplate) {
+ Map<String, Object> interfaceTypes = serviceTemplate.getInterface_types();
+
+ if (MapUtils.isEmpty(interfaceTypes)) {
+ return new HashMap<>();
+ }
+
+ Map<String, InterfaceType> convertedInterfaceTypes = new HashMap<>();
+ for (Map.Entry<String, Object> interfaceEntry : interfaceTypes.entrySet()) {
+ try {
+ Optional<InterfaceType> interfaceType =
+ convertObjToInterfaceType(interfaceEntry.getKey(), interfaceEntry.getValue());
+ interfaceType.ifPresent(
+ interfaceValue -> convertedInterfaceTypes.put(interfaceEntry.getKey(), interfaceValue));
+ } catch (Exception e) {
+ LOGGER.error("Cannot create interface object", e);
+ throw new CoreException(
+ new ToscaInvalidInterfaceValueErrorBuilder(e.getMessage()).build());
+ }
+ }
+
+ return convertedInterfaceTypes;
+ }
+
+ public static <T extends InterfaceDefinition> Optional<T> convertObjToInterfaceDefinition(String interfaceId,
+ Object interfaceObj,
+ Class<T> interfaceClass) {
+ try {
+ Optional<T> interfaceDefinition =
+ CommonUtil.createObjectUsingSetters(interfaceObj, interfaceClass);
+ interfaceDefinition.ifPresent(interfaceDefinitionType1 -> updateInterfaceDefinitionOperations(
+ CommonUtil.getObjectAsMap(interfaceObj),
+ interfaceDefinitionType1, getOperationClass(interfaceClass)));
+ return interfaceDefinition;
+ } catch (Exception ex) {
+ LOGGER.error("Could not create {} from {}", InterfaceDefinitionType.class.getName(),
+ interfaceId, ex);
+ throw new CoreException(
+ new CreateInterfaceObjectErrorBuilder(InterfaceDefinitionType.class.getName(),
+ interfaceId,
+ ex.getMessage()).build());
+ }
+
+ }
+
+ private static <T extends OperationDefinition, V extends InterfaceDefinition> Class<T> getOperationClass(
+ Class<V> interfaceClass) {
+ return interfaceClass.equals(InterfaceDefinitionType.class)
+ ? (Class<T>) OperationDefinitionType.class
+ : (Class<T>) OperationDefinitionTemplate.class;
+ }
+
+ public static Optional<InterfaceType> convertObjToInterfaceType(String interfaceId,
+ Object interfaceObj) {
+ try {
+ Optional<InterfaceType> interfaceType =
+ CommonUtil.createObjectUsingSetters(interfaceObj, InterfaceType.class);
+ interfaceType.ifPresent(
+ interfaceType1 -> updateInterfaceTypeOperations(CommonUtil.getObjectAsMap(interfaceObj),
+ interfaceType1));
+ return interfaceType;
+ } catch (Exception ex) {
+ LOGGER.error("Could not create {} from {}", InterfaceType.class.getName(), interfaceId, ex);
+ throw new CoreException(
+ new CreateInterfaceObjectErrorBuilder(InterfaceType.class.getName(), interfaceId,
+ ex.getMessage()).build());
+ }
+ }
+
+ public static Optional<Object> convertInterfaceTypeToObj(InterfaceType interfaceType) {
+ return converInterfaceToToscaInterfaceObj(interfaceType);
+ }
+
+ private static Optional<Object> converInterfaceToToscaInterfaceObj(Object interfaceEntity) {
+ if (Objects.isNull(interfaceEntity)) {
+ return Optional.empty();
+ }
+
+ Map<String, Object> interfaceAsMap = CommonUtil.getObjectAsMap(interfaceEntity);
+ Map<String, Object> operations = (Map<String, Object>) interfaceAsMap.get(OPERATIONS);
+ if (MapUtils.isNotEmpty(operations)) {
+ interfaceAsMap.remove(OPERATIONS);
+ interfaceAsMap.putAll(operations);
+ }
+
+ ObjectMapper objectMapper = new ObjectMapper();
+ objectMapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false);
+ return Optional.of(objectMapper.convertValue(interfaceAsMap, Object.class));
+ }
+
+ private static void updateInterfaceTypeOperations(Map<String, Object> interfaceAsMap,
+ InterfaceType interfaceType) {
+
+ Set<String> fieldNames = CommonUtil.getClassFieldNames(InterfaceType.class);
+
+ for (Map.Entry<String, Object> entry : interfaceAsMap.entrySet()) {
+ Optional<? extends OperationDefinition> operationDefinition =
+ createOperation(entry.getKey(), entry.getValue(), fieldNames,
+ OperationDefinitionType.class);
+ operationDefinition
+ .ifPresent(operation -> interfaceType.addOperation(entry.getKey(), operation));
+ }
+ }
+
+ private static Optional<? extends OperationDefinition> createOperation(String propertyName,
+ Object operationCandidate,
+ Set<String> fieldNames,
+ Class<? extends OperationDefinition>
+ operationClass) {
+ if (!fieldNames.contains(propertyName)) {
+ try {
+ return CommonUtil.createObjectUsingSetters(operationCandidate, operationClass);
+ } catch (Exception ex) {
+ LOGGER.error("Could not create Operation from {}", propertyName, ex);
+ throw new CoreException(
+ new CreateInterfaceOperationObjectErrorBuilder(propertyName, ex.getMessage()).build());
+ }
+ }
+
+ return Optional.empty();
+ }
+
+ private static <T extends OperationDefinition> void updateInterfaceDefinitionOperations(Map<String, Object>
+ interfaceAsMap,
+ InterfaceDefinition
+ interfaceDefinition,
+ Class<T> operationClass) {
+ Set<String> fieldNames = CommonUtil.getClassFieldNames(interfaceDefinition.getClass());
+ Optional<? extends OperationDefinition> operationDefinition;
+
+ for (Map.Entry<String, Object> entry : interfaceAsMap.entrySet()) {
+ operationDefinition =
+ createOperation(entry.getKey(), entry.getValue(), fieldNames, operationClass);
+ operationDefinition.ifPresent(operation -> addOperationToInterface(interfaceDefinition,
+ entry.getKey(), operation));
+ }
+ }
+
+ private static void addOperationToInterface(InterfaceDefinition interfaceDefinition,
+ String operationName,
+ OperationDefinition operationDefinition) {
+ if (interfaceDefinition instanceof InterfaceDefinitionType) {
+ InterfaceDefinitionType interfaceDefinitionType =
+ (InterfaceDefinitionType) interfaceDefinition;
+ interfaceDefinitionType.addOperation(operationName, (OperationDefinitionType)
+ operationDefinition);
+ }
+ if (interfaceDefinition instanceof InterfaceDefinitionTemplate) {
+ InterfaceDefinitionTemplate interfaceDefinitionTemplate =
+ (InterfaceDefinitionTemplate) interfaceDefinition;
+ interfaceDefinitionTemplate.addOperation(operationName, (OperationDefinitionTemplate)
+ operationDefinition);
+ }
+ }
+
+ public static void addSubstitutionNodeTypeRequirements(NodeType substitutionNodeType,
+ List<Map<String, RequirementDefinition>>
+ requirementsList,
+ String templateName) {
+ if (CollectionUtils.isEmpty(requirementsList)) {
+ return;
+ }
+ if (substitutionNodeType.getRequirements() == null) {
+ substitutionNodeType.setRequirements(new ArrayList<>());
+ }
+
+ for (Map<String, RequirementDefinition> requirementDef : requirementsList) {
+ for (Map.Entry<String, RequirementDefinition> entry : requirementDef.entrySet()) {
+ Map<String, RequirementDefinition> requirementMap = new HashMap<>();
+ requirementMap.put(entry.getKey() + "_" + templateName, entry.getValue().clone());
+ substitutionNodeType.getRequirements().add(requirementMap);
+ }
+ }
+ }
+
+ public static boolean isNodeTemplateSectionMissingFromServiceTemplate(
+ ServiceTemplate serviceTemplate) {
+ return Objects.isNull(serviceTemplate.getTopology_template())
+ || MapUtils.isEmpty(serviceTemplate.getTopology_template().getNode_templates());
+ }
}
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 f2d1d48d9b..47e2c9a2e1 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
@@ -64,6 +64,7 @@ public class ToscaConstants {
public static final String CONTRAIL_SERVICE_INSTANCE_IND = "contrail_service_instance_ind";
static final String ST_METADATA_FILE_NAME = "filename";
public static final String MANDATORY_PROPERTY_NAME = "mandatory";
+ public static final String HEAT_NODE_TYPE_SUFFIX = "heat.";
private ToscaConstants() {
//Hiding the implicit public constructor