summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-sdc-translator-lib
diff options
context:
space:
mode:
authorojasdubey <ojas.dubey@amdocs.com>2018-05-21 17:07:59 +0530
committerAvi Gaffa <avi.gaffa@amdocs.com>2018-05-23 10:08:42 +0000
commit1742d73bf62fd80c6e88059c7226eb91c011a99d (patch)
tree19c88408b92e17a1c096969f90e703fb26c24c9c /openecomp-be/lib/openecomp-sdc-translator-lib
parent66b0d09b07a0d16daacbb4c08da8cfe7e55bc28b (diff)
Refactor Onboarding Translator code
1. Fixed sonar violations 2. Fixed static analysis issues 3. Refactored methods for code smells 4. Moved log messages to a common place as per review comments Note: UnifiedCompositionService has been included to ensure successful compilation. The violations of this class will be handled in a separate commit Change-Id: I2a37176e1d5cebc5c32883df2d19f1c602c9d958 Issue-ID: SDC-1331 Signed-off-by: ojasdubey <ojas.dubey@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-translator-lib')
-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
13 files changed, 1590 insertions, 1569 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());
+ }
}