aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-sdc-translator-lib
diff options
context:
space:
mode:
authorojasdubey <ojas.dubey@amdocs.com>2018-05-23 18:04:28 +0530
committerOren Kleks <orenkle@amdocs.com>2018-05-28 07:03:23 +0000
commitd981ef67e956f1e5a28ca77f2841f49e468c5b1b (patch)
tree58bed186fb242d0cfb5e6522613d8df1168ffe16 /openecomp-be/lib/openecomp-sdc-translator-lib
parentcb72310ab92091c47502f7e3c1bf2162884dca83 (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 Change-Id: I33725bc51040a2c7683b06b4294dea6f96c425e3 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/services/heattotosca/HeatToToscaLogConstants.java62
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/nameextractor/NameExtractorContrailComputeImpl.java46
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/nameextractor/NameExtractorNovaServerImpl.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/BaseResourceConnection.java462
-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/ContrailPortToNetResourceConnection.java262
-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/ContrailV2VlanToInterfaceResourceConnection.java215
-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/ContrailV2VmInterfaceToNetResourceConnection.java210
-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/NovaToVolResourceConnection.java353
-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/PortToNetResourceConnection.java208
-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/ResourceConnectionUsingCapabilityHelper.java297
-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/ResourceConnectionUsingRequirementHelper.java211
-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/ResourceTranslationBase.java543
-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/ResourceTranslationCinderVolumeAttachmentImpl.java332
-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/ResourceTranslationCinderVolumeImpl.java89
-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.java9
-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.java6
-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/SecurityRulesToPortResourceConnection.java8
17 files changed, 1690 insertions, 1667 deletions
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
index 15c9ccd401..02f4fd6226 100644
--- 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
@@ -79,6 +79,68 @@ public class HeatToToscaLogConstants {
+ "include '{}' property which is connect to unsupported/incorrect {} resource '{}' with type '{}', "
+ LOG_UNSUPPORTED_RESOURCE_CONNECTION_SUFFIX;
+ //Security rules to port
+ public static final String LOG_UNSUPPORTED_SECURITY_RULE_PORT_CAPABILITY_CONNECTION =
+ "Nested resource '{}' property '{}' is pointing to resource with type '{}' which is not supported for "
+ + "capability '{}' connection, (security rules to port connection). Supported types are: '{}', "
+ + "therefore, this TOSCA capability will not be connected.";
+
+ //Neutron Port
+ public static final String LOG_UNSUPPORTED_RESOURCE_REQUIREMENT_CONNECTION =
+ "'{}' property of port resource('{}') is pointing to a resource of type '{}' which is not supported for "
+ + "this requirement. Supported types are: {}";
+ //Volume Attachment
+ public static final String LOG_INVALID_INSTANCE_UUID = LOG_HEAT_RESOURCE_TYPE_PREFIX
+ + "include 'instance_uuid' property without 'get_resource' function, "
+ + LOG_UNSUPPORTED_HEAT_RESOURCE_SUFFIX;
+ public static final String LOG_UNSUPPORTED_VOLUME_ATTACHMENT_MSG =
+ "Volume attachment with id '{}' is pointing to unsupported resource type({}) through the property "
+ + "'volume_id'. The connection to the volume is ignored. Supported types are: {}";
+
+ //Capability/Requirement helpers
+ public static final String LOG_NESTED_RESOURCE_PROPERTY_NOT_DEFINED = "'{}' property is not define in nested "
+ + "resource '{}' for the nested heat file, therefore, '{}' TOSCA {} will not be connected.";
+ public static final String LOG_UNSUPPORTED_CAPABILITY_CONNECTION =
+ "'{}' connection to '{}' capability of type '{}' is not supported/invalid,"
+ + LOG_UNSUPPORTED_RESOURCE_CONNECTION_SUFFIX;
+
+ //Port to Net Resource Connection
+ public static final String LOG_UNSUPPORTED_PORT_NETWORK_REQUIREMENT_CONNECTION =
+ "Nested resource '{}' property '{}' is pointing to a resource with type '{}' which is not "
+ + "supported for requirement '{}' that connect port to network. Supported types are: '{}', "
+ + "therefore, this TOSCA requirement will not be connected.";
+
+ public static final String LOG_UNSUPPORTED_VOL_ATTACHMENT_VOLUME_REQUIREMENT_CONNECTION =
+ "Nested resource '{}' property '{}' is pointing to a resource with type '{}' which is not "
+ + "supported for requirement '{}' that connect VolumeAttachment to Volume. Supported "
+ + "types are: '{}', therefore, this TOSCA requirement will not be connected.";
+
+ //Contrail v2 vmi to net resource connection
+ public static final String LOG_MULTIPLE_VIRTUAL_NETWORK_REFS_VALUES =
+ "Heat resource: '{}' with nested heat file: '{}' has resource '{}' with "
+ + "type '{}' which include 'virtual_network_refs' property with more than one network values, "
+ + "only the first network will be translated, all rest will be ignored in TOSCA translation.";
+ public static final String LOG_UNSUPPORTED_VMI_NETWORK_REQUIREMENT_CONNECTION =
+ "Nested resource '{}' property '{}' is pointing to a resource with type '{}' which is not supported for "
+ + "requirement '{}' that connect virtual machine interface to network. Supported "
+ + "types are: '{}', therefore, this TOSCA requirement will not be connected.";
+
+ //Contrail v2 vlan to interface connection
+ public static final String LOG_UNSUPPORTED_VMI_VLAN_SUB_INTERFACE_REQUIREMENT_CONNECTION =
+ "Nested resource '{}' property '{}' is pointing to a {} resource with type '{}' which is not supported "
+ + "for requirement '{}' that connect vmi vlan sub interface to interface. Supported types are: "
+ + "'{}' (excluding Vlan), therefore, this TOSCA requirement will not be connected.";
+
+ public static final String LOG_MULTIPLE_INTERFACE_VALUES_NESTED =
+ "Heat resource: '{}' with nested heat file: '{}' has resource '{}' with type '{}' which 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_CONTRAIL_PORT_NETWORK_REQUIREMENT_CONNECTION =
+ "Nested resource '{}' property '{}' is pointing to a resource with type '{}' which is not supported"
+ + "for requirement '{}' that connect contrail port to network. Supported types "
+ + "are: '{}', therefore, this TOSCA requirement will not be connected.";
+
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/impl/nameextractor/NameExtractorContrailComputeImpl.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/nameextractor/NameExtractorContrailComputeImpl.java
index 637aff9406..f7297d402f 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/nameextractor/NameExtractorContrailComputeImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/nameextractor/NameExtractorContrailComputeImpl.java
@@ -1,25 +1,26 @@
-/*-
- * ============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.nameextractor;
+import static org.openecomp.sdc.tosca.services.ToscaConstants.HEAT_NODE_TYPE_SUFFIX;
+
+import java.util.List;
+import java.util.Optional;
+
import org.openecomp.sdc.heat.datatypes.model.Resource;
import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
import org.openecomp.sdc.translator.datatypes.heattotosca.PropertyRegexMatcher;
@@ -27,23 +28,18 @@ import org.openecomp.sdc.translator.services.heattotosca.NameExtractor;
import org.openecomp.sdc.translator.services.heattotosca.NameExtractorUtil;
import org.openecomp.sdc.translator.services.heattotosca.helper.ContrailTranslationHelper;
-import java.util.List;
-import java.util.Optional;
-
public class NameExtractorContrailComputeImpl implements NameExtractor {
- @Override
- public String extractNodeTypeName(Resource resource, String resourceId, String translatedId) {
- ContrailTranslationHelper contrailTranslationHelper = new ContrailTranslationHelper();
- List<PropertyRegexMatcher> propertyRegexMatchers =
- contrailTranslationHelper.getPropertyRegexMatchersForComputeNodeType();
- Optional<String> extractedNodeTypeName =
- NameExtractorUtil.extractNodeTypeNameByPropertiesPriority(resource.getProperties(),
- propertyRegexMatchers);
-
- return ToscaNodeType.VFC_NODE_TYPE_PREFIX + "heat."
- + (extractedNodeTypeName.isPresent() ? extractedNodeTypeName.get()
- : "compute_" + translatedId);
- }
+ @Override
+ public String extractNodeTypeName(Resource resource, String resourceId, String translatedId) {
+ ContrailTranslationHelper contrailTranslationHelper = new ContrailTranslationHelper();
+ List<PropertyRegexMatcher> propertyRegexMatchers =
+ contrailTranslationHelper.getPropertyRegexMatchersForComputeNodeType();
+ Optional<String> extractedNodeTypeName = NameExtractorUtil.extractNodeTypeNameByPropertiesPriority(resource
+ .getProperties(), propertyRegexMatchers);
+
+ return ToscaNodeType.VFC_NODE_TYPE_PREFIX + HEAT_NODE_TYPE_SUFFIX
+ + (extractedNodeTypeName.orElseGet(() -> "compute_" + translatedId));
+ }
}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/nameextractor/NameExtractorNovaServerImpl.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/nameextractor/NameExtractorNovaServerImpl.java
index 52ceafa454..9cfd2aeddc 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/nameextractor/NameExtractorNovaServerImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/nameextractor/NameExtractorNovaServerImpl.java
@@ -1,25 +1,26 @@
-/*-
- * ============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.nameextractor;
+import static org.openecomp.sdc.tosca.services.ToscaConstants.HEAT_NODE_TYPE_SUFFIX;
+
+import java.util.List;
+import java.util.Optional;
+
import org.openecomp.sdc.heat.datatypes.model.Resource;
import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
import org.openecomp.sdc.translator.datatypes.heattotosca.PropertyRegexMatcher;
@@ -27,24 +28,19 @@ import org.openecomp.sdc.translator.services.heattotosca.NameExtractor;
import org.openecomp.sdc.translator.services.heattotosca.NameExtractorUtil;
import org.openecomp.sdc.translator.services.heattotosca.impl.resourcetranslation.ResourceTranslationNovaServerImpl;
-import java.util.List;
-import java.util.Optional;
-
public class NameExtractorNovaServerImpl implements NameExtractor {
- @Override
- public String extractNodeTypeName(Resource resource, String resourceId, String translatedId) {
- ResourceTranslationNovaServerImpl novaServerTranslator =
- new ResourceTranslationNovaServerImpl();
- List<PropertyRegexMatcher> propertyRegexMatchers =
- novaServerTranslator.getPropertyRegexMatchersForNovaNodeType();
+ @Override
+ public String extractNodeTypeName(Resource resource, String resourceId, String translatedId) {
+ ResourceTranslationNovaServerImpl novaServerTranslator = new ResourceTranslationNovaServerImpl();
+ List<PropertyRegexMatcher> propertyRegexMatchers =
+ novaServerTranslator.getPropertyRegexMatchersForNovaNodeType();
- Optional<String> extractedNodeTypeName = NameExtractorUtil
- .extractNodeTypeNameByPropertiesPriority(resource.getProperties(), propertyRegexMatchers);
+ Optional<String> extractedNodeTypeName = NameExtractorUtil
+ .extractNodeTypeNameByPropertiesPriority(resource.getProperties(), propertyRegexMatchers);
- return ToscaNodeType.VFC_NODE_TYPE_PREFIX + "heat."
- + (extractedNodeTypeName.isPresent() ? extractedNodeTypeName.get()
- : translatedId.replace(".", "_"));
- }
+ return ToscaNodeType.VFC_NODE_TYPE_PREFIX + HEAT_NODE_TYPE_SUFFIX
+ + (extractedNodeTypeName.orElseGet(() -> translatedId.replace(".", "_")));
+ }
}
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/BaseResourceConnection.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/BaseResourceConnection.java
index 065092b00f..6b7f1cf5b9 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/BaseResourceConnection.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/BaseResourceConnection.java
@@ -1,26 +1,37 @@
-/*-
- * ============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.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.function.Predicate;
+
+import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
+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.RequirementDefinition;
+import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
+import org.onap.sdc.tosca.services.YamlUtil;
import org.openecomp.sdc.common.errors.CoreException;
import org.openecomp.sdc.common.errors.ErrorCategory;
import org.openecomp.sdc.common.errors.ErrorCode;
@@ -29,14 +40,9 @@ import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate;
import org.openecomp.sdc.heat.datatypes.model.Resource;
import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
-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.RequirementDefinition;
-import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
+import org.openecomp.sdc.tosca.datatypes.ToscaFunctions;
import org.openecomp.sdc.tosca.services.DataModelUtil;
import org.openecomp.sdc.tosca.services.ToscaAnalyzerService;
-import org.onap.sdc.tosca.services.YamlUtil;
import org.openecomp.sdc.tosca.services.impl.ToscaAnalyzerServiceImpl;
import org.openecomp.sdc.translator.datatypes.heattotosca.AttachedResourceId;
import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo;
@@ -44,267 +50,265 @@ import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslatedHeatResou
import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil;
import org.openecomp.sdc.translator.services.heattotosca.errors.TranslatorErrorCodes;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.function.Predicate;
-
abstract class BaseResourceConnection<T> {
- protected static Logger logger = LoggerFactory.getLogger(BaseResourceConnection.class);
- protected TranslateTo translateTo;
- FileData nestedFileData;
- NodeTemplate substitutionNodeTemplate;
- NodeType nodeType;
- ResourceTranslationBase resourceTranslationBase;
+ protected static Logger logger = LoggerFactory.getLogger(BaseResourceConnection.class);
+ protected TranslateTo translateTo;
+ FileData nestedFileData;
+ NodeTemplate substitutionNodeTemplate;
+ NodeType nodeType;
+ ResourceTranslationBase resourceTranslationBase;
- BaseResourceConnection(ResourceTranslationBase resourceTranslationBase, TranslateTo translateTo,
- FileData nestedFileData, NodeTemplate substitutionNodeTemplate,
- NodeType nodeType) {
- this.translateTo = translateTo;
- this.nestedFileData = nestedFileData;
- this.substitutionNodeTemplate = substitutionNodeTemplate;
- this.nodeType = nodeType;
- this.resourceTranslationBase = resourceTranslationBase;
- }
+ BaseResourceConnection(ResourceTranslationBase resourceTranslationBase, TranslateTo translateTo,
+ FileData nestedFileData, NodeTemplate substitutionNodeTemplate,
+ NodeType nodeType) {
+ this.translateTo = translateTo;
+ this.nestedFileData = nestedFileData;
+ this.substitutionNodeTemplate = substitutionNodeTemplate;
+ this.nodeType = nodeType;
+ this.resourceTranslationBase = resourceTranslationBase;
+ }
- abstract boolean isDesiredNodeTemplateType(NodeTemplate nodeTemplate);
+ abstract boolean isDesiredNodeTemplateType(NodeTemplate nodeTemplate);
- abstract List<Predicate<T>> getPredicatesListForConnectionPoints();
+ abstract List<Predicate<T>> getPredicatesListForConnectionPoints();
- abstract Optional<List<String>> getConnectorPropertyParamName(String heatResourceId,
- Resource heatResource,
- HeatOrchestrationTemplate
- nestedHeatOrchestrationTemplate,
- String nestedHeatFileName);
+ abstract Optional<List<String>> getConnectorPropertyParamName(String heatResourceId,
+ Resource heatResource,
+ HeatOrchestrationTemplate
+ nestedHeatOrchestrationTemplate,
+ String nestedHeatFileName);
- abstract String getDesiredResourceType();
+ abstract String getDesiredResourceType();
- abstract String getMappedNodeTranslatedResourceId(ServiceTemplate nestedServiceTemplate,
- Map.Entry<String, T> connectionPointEntry);
+ abstract String getMappedNodeTranslatedResourceId(ServiceTemplate nestedServiceTemplate,
+ Map.Entry<String, T> connectionPointEntry);
- abstract Map.Entry<String, T> getMappedConnectionPointEntry(ServiceTemplate nestedServiceTemplate,
- Map.Entry<String, T>
- connectionPointEntry);
+ abstract Map.Entry<String, T> getMappedConnectionPointEntry(ServiceTemplate nestedServiceTemplate,
+ Map.Entry<String, T>
+ connectionPointEntry);
- abstract void addRequirementToConnectResources(Map.Entry<String, T> connectionPointEntry,
- List<String> paramNames);
+ abstract void addRequirementToConnectResources(Map.Entry<String, T> connectionPointEntry,
+ List<String> paramNames);
- abstract List<Map<String, T>> getAllConnectionPoints();
+ abstract List<Map<String, T>> getAllConnectionPoints();
- abstract boolean validateResourceTypeSupportedForReqCreation(String nestedResourceId,
- final String nestedPropertyName,
- String connectionPointId,
- Resource connectedResource,
- List<String> supportedTypes);
+ abstract boolean validateResourceTypeSupportedForReqCreation(String nestedResourceId,
+ final String nestedPropertyName,
+ String connectionPointId,
+ Resource connectedResource,
+ List<String> supportedTypes);
- void connect() {
- ServiceTemplate nestedServiceTemplate = translateTo.getContext().getTranslatedServiceTemplates()
- .get(translateTo.getResource().getType());
- List<String> paramNames;
- HeatOrchestrationTemplate nestedHeatOrchestrationTemplate = new YamlUtil()
- .yamlToObject(translateTo.getContext().getFileContent(nestedFileData.getFile()),
- HeatOrchestrationTemplate.class);
- List<Map<String, T>> exposedConnectionPoints = getAllConnectionPoints();
- for (Map<String, T> connectionPointsMap : exposedConnectionPoints) {
- for (Map.Entry<String, T> connectionPointEntry : connectionPointsMap.entrySet()) {
- paramNames =
- getConnectionParameterName(nestedServiceTemplate, nestedHeatOrchestrationTemplate,
- nestedFileData.getFile(), connectionPointEntry);
- if (paramNames != null && !paramNames.isEmpty()) {
- addRequirementToConnectResources(connectionPointEntry, paramNames);
+ void connect() {
+ ServiceTemplate nestedServiceTemplate = translateTo.getContext().getTranslatedServiceTemplates()
+ .get(translateTo.getResource().getType());
+ List<String> paramNames;
+ HeatOrchestrationTemplate nestedHeatOrchestrationTemplate = new YamlUtil()
+ .yamlToObject(translateTo.getContext().getFileContent(nestedFileData.getFile()),
+ HeatOrchestrationTemplate.class);
+ List<Map<String, T>> exposedConnectionPoints = getAllConnectionPoints();
+ for (Map<String, T> connectionPointsMap : exposedConnectionPoints) {
+ for (Map.Entry<String, T> connectionPointEntry : connectionPointsMap.entrySet()) {
+ paramNames =
+ getConnectionParameterName(nestedServiceTemplate, nestedHeatOrchestrationTemplate,
+ nestedFileData.getFile(), connectionPointEntry);
+ if (CollectionUtils.isNotEmpty(paramNames)) {
+ addRequirementToConnectResources(connectionPointEntry, paramNames);
+ }
+ }
}
- }
}
- }
- private List<String> getConnectionParameterName(ServiceTemplate nestedServiceTemplate,
- HeatOrchestrationTemplate
- nestedHeatOrchestrationTemplate,
- String nestedHeatFileName,
- Map.Entry<String, T> connectionPointEntry) {
- List<String> connectionParameterNameList = new ArrayList<>();
- String mappedTranslatedResourceId =
- getMappedNodeTranslatedResourceId(nestedServiceTemplate, connectionPointEntry);
- NodeTemplate mappedNodeTemplate =
- nestedServiceTemplate.getTopology_template().getNode_templates()
- .get(mappedTranslatedResourceId);
- if (isDesiredNodeTemplateType(mappedNodeTemplate)) {
- return getResourcesConnectionParameterName(mappedTranslatedResourceId,
- nestedHeatOrchestrationTemplate, nestedHeatFileName);
- }
+ private List<String> getConnectionParameterName(ServiceTemplate nestedServiceTemplate,
+ HeatOrchestrationTemplate
+ nestedHeatOrchestrationTemplate,
+ String nestedHeatFileName,
+ Map.Entry<String, T> connectionPointEntry) {
+ List<String> connectionParameterNameList = new ArrayList<>();
+ String mappedTranslatedResourceId = getMappedNodeTranslatedResourceId(nestedServiceTemplate,
+ connectionPointEntry);
+ NodeTemplate mappedNodeTemplate = nestedServiceTemplate.getTopology_template().getNode_templates()
+ .get(mappedTranslatedResourceId);
+ if (isDesiredNodeTemplateType(mappedNodeTemplate)) {
+ return getResourcesConnectionParameterName(mappedTranslatedResourceId,
+ nestedHeatOrchestrationTemplate, nestedHeatFileName);
+ }
- ToscaAnalyzerService toscaAnalyzerService = new ToscaAnalyzerServiceImpl();
- if (toscaAnalyzerService.isSubstitutableNodeTemplate(mappedNodeTemplate)) {
- Optional<String> mappedSubstituteServiceTemplateName = toscaAnalyzerService
- .getSubstituteServiceTemplateName(mappedTranslatedResourceId, mappedNodeTemplate);
- if (mappedSubstituteServiceTemplateName.isPresent()) {
+ ToscaAnalyzerService toscaAnalyzerService = new ToscaAnalyzerServiceImpl();
+ if (!toscaAnalyzerService.isSubstitutableNodeTemplate(mappedNodeTemplate)) {
+ return Collections.emptyList();
+ }
+ Optional<String> mappedSubstituteServiceTemplateName = toscaAnalyzerService
+ .getSubstituteServiceTemplateName(mappedTranslatedResourceId, mappedNodeTemplate);
+ if (!mappedSubstituteServiceTemplateName.isPresent()) {
+ return Collections.emptyList();
+ }
String mappedNestedHeatFileName = translateTo.getContext().getNestedHeatFileName()
- .get(mappedSubstituteServiceTemplateName.get());
+ .get(mappedSubstituteServiceTemplateName.get());
if (Objects.isNull(mappedNestedHeatFileName)) {
- return null;
+ return Collections.emptyList();
}
HeatOrchestrationTemplate mappedNestedHeatOrchestrationTemplate = new YamlUtil()
- .yamlToObject(translateTo.getContext().getFileContent(mappedNestedHeatFileName),
- HeatOrchestrationTemplate.class);
+ .yamlToObject(translateTo.getContext().getFileContent(mappedNestedHeatFileName),
+ HeatOrchestrationTemplate.class);
ServiceTemplate mappedNestedServiceTemplate =
- translateTo.getContext().getTranslatedServiceTemplates().get(mappedNestedHeatFileName);
+ translateTo.getContext().getTranslatedServiceTemplates().get(mappedNestedHeatFileName);
List<String> nestedPropertyNames = getConnectionParameterName(mappedNestedServiceTemplate,
- mappedNestedHeatOrchestrationTemplate, mappedNestedHeatFileName,
- getMappedConnectionPointEntry(nestedServiceTemplate, connectionPointEntry));
+ mappedNestedHeatOrchestrationTemplate, mappedNestedHeatFileName,
+ getMappedConnectionPointEntry(nestedServiceTemplate, connectionPointEntry));
- if (nestedPropertyNames != null && !nestedPropertyNames.isEmpty()) {
- for (String propertyName : nestedPropertyNames) {
+ if (CollectionUtils.isEmpty(nestedPropertyNames)) {
+ return connectionParameterNameList;
+ }
+ for (String propertyName : nestedPropertyNames) {
Object propertyValue = mappedNodeTemplate.getProperties().get(propertyName);
- if (propertyValue instanceof Map && ((Map) propertyValue).containsKey("get_input")) {
- Object paramName = ((Map) propertyValue).get("get_input");
- if (paramName instanceof String) {
- connectionParameterNameList.add((String) paramName);
- }
+ if (propertyValue instanceof Map
+ && ((Map) propertyValue).containsKey(ToscaFunctions.GET_INPUT.getDisplayName())) {
+ Object paramName = ((Map) propertyValue).get(ToscaFunctions.GET_INPUT.getDisplayName());
+ if (paramName instanceof String) {
+ connectionParameterNameList.add((String) paramName);
+ }
}
- }
}
return connectionParameterNameList;
- }
}
- return null;
- }
- private List<String> getResourcesConnectionParameterName(String translatedResourceId,
- HeatOrchestrationTemplate
- nestedHeatOrchestrationTemplate,
- String nestedHeatFileName) {
- List<String> params = new ArrayList<>();
- Optional<List<Map.Entry<String, Resource>>> heatResources =
- getResourceByTranslatedResourceId(translatedResourceId, nestedHeatOrchestrationTemplate);
- if (heatResources.isPresent()) {
- for (Map.Entry<String, Resource> resourceEntry : heatResources.get()) {
- Resource heatResource = resourceEntry.getValue();
- if (!MapUtils.isEmpty(heatResource.getProperties())) {
- Optional<List<String>> connectorParamName =
- getConnectorPropertyParamName(resourceEntry.getKey(), heatResource,
- nestedHeatOrchestrationTemplate, nestedHeatFileName);
- connectorParamName.ifPresent(params::addAll);
+ private List<String> getResourcesConnectionParameterName(String translatedResourceId,
+ HeatOrchestrationTemplate
+ nestedHeatOrchestrationTemplate,
+ String nestedHeatFileName) {
+ List<String> params = new ArrayList<>();
+ Optional<List<Map.Entry<String, Resource>>> heatResources =
+ getResourceByTranslatedResourceId(translatedResourceId, nestedHeatOrchestrationTemplate);
+ if (!heatResources.isPresent()) {
+ return params;
}
- }
+ for (Map.Entry<String, Resource> resourceEntry : heatResources.get()) {
+ Resource heatResource = resourceEntry.getValue();
+ if (!MapUtils.isEmpty(heatResource.getProperties())) {
+ Optional<List<String>> connectorParamName =
+ getConnectorPropertyParamName(resourceEntry.getKey(), heatResource,
+ nestedHeatOrchestrationTemplate, nestedHeatFileName);
+ connectorParamName.ifPresent(params::addAll);
+ }
+ }
+ return params;
}
- return params;
- }
- protected Optional<List<Map.Entry<String, Resource>>> getResourceByTranslatedResourceId(
- String translatedResourceId, HeatOrchestrationTemplate nestedHeatOrchestrationTemplate) {
- Optional<List<Map.Entry<String, Resource>>> resourceByTranslatedResourceId =
- resourceTranslationBase.getResourceByTranslatedResourceId(nestedFileData.getFile(),
- nestedHeatOrchestrationTemplate, translatedResourceId, translateTo,
- getDesiredResourceType());
- if (!resourceByTranslatedResourceId.isPresent()) {
- throw new CoreException((new ErrorCode.ErrorCodeBuilder()).withMessage(
- "Failed to get original resource from heat for translate resource id '"
- + translatedResourceId + "'")
- .withId(TranslatorErrorCodes.HEAT_TO_TOSCA_MAPPING_COLLISION)
- .withCategory(ErrorCategory.APPLICATION).build());
+ protected Optional<List<Map.Entry<String, Resource>>> getResourceByTranslatedResourceId(
+ String translatedResourceId, HeatOrchestrationTemplate nestedHeatOrchestrationTemplate) {
+ Optional<List<Map.Entry<String, Resource>>> resourceByTranslatedResourceId =
+ resourceTranslationBase.getResourceByTranslatedResourceId(nestedFileData.getFile(),
+ nestedHeatOrchestrationTemplate, translatedResourceId, translateTo,
+ getDesiredResourceType());
+ if (!resourceByTranslatedResourceId.isPresent()) {
+ throw new CoreException((new ErrorCode.ErrorCodeBuilder()).withMessage(
+ "Failed to get original resource from heat for translate resource id '"
+ + translatedResourceId + "'")
+ .withId(TranslatorErrorCodes.HEAT_TO_TOSCA_MAPPING_COLLISION)
+ .withCategory(ErrorCategory.APPLICATION).build());
+ }
+ return resourceByTranslatedResourceId;
}
- return resourceByTranslatedResourceId;
- }
- RequirementAssignment createRequirementAssignment(Map.Entry<String, RequirementDefinition>
- requirementEntry, String node,
- NodeTemplate nodeTemplate) {
- RequirementAssignment requirementAssignment = null;
- if (Objects.nonNull(node)) {
- requirementAssignment = new RequirementAssignment();
- requirementAssignment.setRelationship(requirementEntry.getValue().getRelationship());
- requirementAssignment.setCapability(requirementEntry.getValue().getCapability());
- requirementAssignment.setNode(node);
- DataModelUtil
- .addRequirementAssignment(nodeTemplate, requirementEntry.getKey(), requirementAssignment);
+ RequirementAssignment createRequirementAssignment(Map.Entry<String, RequirementDefinition> requirementEntry,
+ String node,
+ NodeTemplate nodeTemplate) {
+ RequirementAssignment requirementAssignment = null;
+ if (Objects.nonNull(node)) {
+ requirementAssignment = new RequirementAssignment();
+ requirementAssignment.setRelationship(requirementEntry.getValue().getRelationship());
+ requirementAssignment.setCapability(requirementEntry.getValue().getCapability());
+ requirementAssignment.setNode(node);
+ DataModelUtil.addRequirementAssignment(nodeTemplate, requirementEntry.getKey(), requirementAssignment);
+ }
+ return requirementAssignment;
}
- return requirementAssignment;
- }
- Optional<String> getConnectionTranslatedNodeUsingGetParamFunc(
- Map.Entry<String, T> connectionPointEntry, String paramName,
- List<String> supportedNodeTypes) {
+ Optional<String> getConnectionTranslatedNodeUsingGetParamFunc(
+ Map.Entry<String, T> connectionPointEntry, String paramName,
+ List<String> supportedNodeTypes) {
- Optional<AttachedResourceId> attachedResourceId =
- HeatToToscaUtil.extractAttachedResourceId(translateTo, paramName);
- if (!attachedResourceId.isPresent()) {
- return Optional.empty();
- }
- AttachedResourceId resourceId = attachedResourceId.get();
- if (resourceId.isGetParam() && resourceId.getEntityId() instanceof String) {
- TranslatedHeatResource shareResource =
- translateTo.getContext().getHeatSharedResourcesByParam().get(resourceId.getEntityId());
- if (Objects.nonNull(shareResource)
- && !HeatToToscaUtil.isHeatFileNested(translateTo, translateTo.getHeatFileName())) {
- if (validateResourceTypeSupportedForReqCreation(translateTo.getResourceId(), paramName,
- connectionPointEntry.getKey(), shareResource.getHeatResource(), supportedNodeTypes)) {
- return Optional.of(shareResource.getTranslatedId());
+ Optional<AttachedResourceId> attachedResourceId =
+ HeatToToscaUtil.extractAttachedResourceId(translateTo, paramName);
+ if (!attachedResourceId.isPresent()) {
+ return Optional.empty();
}
- }
+ AttachedResourceId resourceId = attachedResourceId.get();
+ if (resourceId.isGetParam() && resourceId.getEntityId() instanceof String) {
+ TranslatedHeatResource shareResource =
+ translateTo.getContext().getHeatSharedResourcesByParam().get(resourceId.getEntityId());
+ if (isSupportedSharedResource(paramName, connectionPointEntry.getKey(), supportedNodeTypes,
+ shareResource)) {
+ return Optional.of(shareResource.getTranslatedId());
+ }
+ }
+ return Optional.empty();
}
- return Optional.empty();
- }
-
- Optional<TranslatedHeatResource> getConnectionTranslatedHeatResourceUsingGetParamFunc(
- Map.Entry<String, T> connectionPointEntry, String paramName,
- List<String> supportedNodeTypes) {
- Optional<AttachedResourceId> attachedResourceId =
- HeatToToscaUtil.extractAttachedResourceId(translateTo, paramName);
- if (!attachedResourceId.isPresent()) {
- return Optional.empty();
+ private boolean isSupportedSharedResource(String paramName, String connectionPointId,
+ List<String> supportedNodeTypes,
+ TranslatedHeatResource shareResource) {
+ return Objects.nonNull(shareResource)
+ && !HeatToToscaUtil.isHeatFileNested(translateTo, translateTo.getHeatFileName())
+ && validateResourceTypeSupportedForReqCreation(translateTo.getResourceId(), paramName,
+ connectionPointId, shareResource.getHeatResource(), supportedNodeTypes);
}
- AttachedResourceId resourceId = attachedResourceId.get();
- if (resourceId.isGetParam() && resourceId.getEntityId() instanceof String) {
- TranslatedHeatResource shareResource =
- translateTo.getContext().getHeatSharedResourcesByParam().get(resourceId.getEntityId());
- if (Objects.nonNull(shareResource)
- && !HeatToToscaUtil.isHeatFileNested(translateTo, translateTo.getHeatFileName())) {
- if (validateResourceTypeSupportedForReqCreation(translateTo.getResourceId(), paramName,
- connectionPointEntry.getKey(), shareResource.getHeatResource(), supportedNodeTypes)) {
- return Optional.of(shareResource);
+
+ Optional<TranslatedHeatResource> getConnectionTranslatedHeatResourceUsingGetParamFunc(
+ Map.Entry<String, T> connectionPointEntry, String paramName,
+ List<String> supportedNodeTypes) {
+
+ Optional<AttachedResourceId> attachedResourceId =
+ HeatToToscaUtil.extractAttachedResourceId(translateTo, paramName);
+ if (!attachedResourceId.isPresent()) {
+ return Optional.empty();
+ }
+ AttachedResourceId resourceId = attachedResourceId.get();
+ if (resourceId.isGetParam() && resourceId.getEntityId() instanceof String) {
+ TranslatedHeatResource shareResource =
+ translateTo.getContext().getHeatSharedResourcesByParam().get(resourceId.getEntityId());
+ if (isSupportedSharedResource(paramName, connectionPointEntry.getKey(), supportedNodeTypes,
+ shareResource)) {
+ return Optional.of(shareResource);
+ }
}
- }
+ return Optional.empty();
}
- return Optional.empty();
- }
- Optional<String> getConnectionTranslatedNodeUsingGetResourceFunc(
- Map.Entry<String, T> connectionPointEntry, String paramName, Object paramValue,
- List<String> supportedNodeTypes) {
- Optional<String> getResourceAttachedResourceId =
- HeatToToscaUtil.extractContrailGetResourceAttachedHeatResourceId(paramValue);
- if (getResourceAttachedResourceId.isPresent()) { // get resource
- Resource resource = translateTo.getHeatOrchestrationTemplate().getResources()
- .get(getResourceAttachedResourceId.get());
- if (validateResourceTypeSupportedForReqCreation(translateTo.getResourceId(), paramName,
- connectionPointEntry.getKey(), resource, supportedNodeTypes)) {
- return ResourceTranslationBase.getResourceTranslatedId(translateTo.getHeatFileName(),
- translateTo.getHeatOrchestrationTemplate(), getResourceAttachedResourceId.get(),
- translateTo.getContext());
- }
- }
+ Optional<String> getConnectionTranslatedNodeUsingGetResourceFunc(
+ Map.Entry<String, T> connectionPointEntry, String paramName, Object paramValue,
+ List<String> supportedNodeTypes) {
+ Optional<String> getResourceAttachedResourceId =
+ HeatToToscaUtil.extractContrailGetResourceAttachedHeatResourceId(paramValue);
+ if (getResourceAttachedResourceId.isPresent()) { // get resource
+ Resource resource = translateTo.getHeatOrchestrationTemplate().getResources()
+ .get(getResourceAttachedResourceId.get());
+ if (validateResourceTypeSupportedForReqCreation(translateTo.getResourceId(), paramName,
+ connectionPointEntry.getKey(), resource, supportedNodeTypes)) {
+ return ResourceTranslationBase.getResourceTranslatedId(translateTo.getHeatFileName(),
+ translateTo.getHeatOrchestrationTemplate(), getResourceAttachedResourceId.get(),
+ translateTo.getContext());
+ }
+ }
- return Optional.empty();
- }
+ return Optional.empty();
+ }
- Optional<String> getConnectionResourceUsingGetResourceFunc(
- Map.Entry<String, T> connectionPointEntry, String paramName, Object paramValue,
- List<String> supportedNodeTypes) {
- Optional<String> getResourceAttachedResourceId =
- HeatToToscaUtil.extractContrailGetResourceAttachedHeatResourceId(paramValue);
- if (getResourceAttachedResourceId.isPresent()) { // get resource
- Resource resource = translateTo.getHeatOrchestrationTemplate().getResources()
- .get(getResourceAttachedResourceId.get());
- if (validateResourceTypeSupportedForReqCreation(translateTo.getResourceId(), paramName,
- connectionPointEntry.getKey(), resource, supportedNodeTypes)) {
- return getResourceAttachedResourceId;
- }
+ Optional<String> getConnectionResourceUsingGetResourceFunc(
+ Map.Entry<String, T> connectionPointEntry, String paramName, Object paramValue,
+ List<String> supportedNodeTypes) {
+ Optional<String> getResourceAttachedResourceId =
+ HeatToToscaUtil.extractContrailGetResourceAttachedHeatResourceId(paramValue);
+ if (getResourceAttachedResourceId.isPresent()) { // get resource
+ Resource resource = translateTo.getHeatOrchestrationTemplate().getResources()
+ .get(getResourceAttachedResourceId.get());
+ if (validateResourceTypeSupportedForReqCreation(translateTo.getResourceId(), paramName,
+ connectionPointEntry.getKey(), resource, supportedNodeTypes)) {
+ return getResourceAttachedResourceId;
+ }
+ }
+ return Optional.empty();
}
- return Optional.empty();
- }
}
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/ContrailPortToNetResourceConnection.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ContrailPortToNetResourceConnection.java
index c3b55a9646..64912fce3b 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ContrailPortToNetResourceConnection.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ContrailPortToNetResourceConnection.java
@@ -1,26 +1,34 @@
-/*-
- * ============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_UNSUPPORTED_CONTRAIL_PORT_NETWORK_REQUIREMENT_CONNECTION;
+import com.google.common.collect.ImmutableList;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.function.Predicate;
+
+import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
+import org.onap.sdc.tosca.datatypes.model.NodeType;
+import org.onap.sdc.tosca.datatypes.model.RequirementDefinition;
import org.openecomp.sdc.heat.datatypes.manifest.FileData;
import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate;
import org.openecomp.sdc.heat.datatypes.model.HeatResourcesTypes;
@@ -30,137 +38,137 @@ import org.openecomp.sdc.tosca.datatypes.ToscaCapabilityType;
import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
import org.openecomp.sdc.tosca.datatypes.ToscaRelationshipType;
import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
-import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
-import org.onap.sdc.tosca.datatypes.model.NodeType;
-import org.onap.sdc.tosca.datatypes.model.RequirementDefinition;
import org.openecomp.sdc.tosca.services.ToscaAnalyzerService;
import org.openecomp.sdc.tosca.services.impl.ToscaAnalyzerServiceImpl;
import org.openecomp.sdc.translator.datatypes.heattotosca.AttachedResourceId;
import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo;
import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.function.Predicate;
-
public class ContrailPortToNetResourceConnection extends ResourceConnectionUsingRequirementHelper {
- public ContrailPortToNetResourceConnection(ResourceTranslationBase resourceTranslationBase,
- TranslateTo translateTo, FileData nestedFileData,
- NodeTemplate substitutionNodeTemplate,
- NodeType nodeType) {
- super(resourceTranslationBase, translateTo, nestedFileData, substitutionNodeTemplate, nodeType);
- }
-
- @Override
- protected boolean isDesiredNodeTemplateType(NodeTemplate nodeTemplate) {
- ToscaAnalyzerService toscaAnalyzerService = new ToscaAnalyzerServiceImpl();
- ToscaServiceModel toscaServiceModel =
- HeatToToscaUtil.getToscaServiceModel(translateTo.getContext());
- return toscaAnalyzerService
- .isTypeOf(nodeTemplate, ToscaNodeType.CONTRAIL_ABSTRACT_SUBSTITUTE,
- translateTo.getContext().getTranslatedServiceTemplates()
- .get(translateTo.getResource().getType()), toscaServiceModel);
- }
-
- @Override
- protected List<Predicate<RequirementDefinition>> getPredicatesListForConnectionPoints() {
- ArrayList<Predicate<RequirementDefinition>> predicates = new ArrayList<>();
- predicates.add(
- req -> req.getCapability().equals(ToscaCapabilityType.NATIVE_NETWORK_LINKABLE)
- && (req.getNode() == null || req.getNode().equals(ToscaNodeType.NATIVE_ROOT))
- && req.getRelationship()
- .equals(ToscaRelationshipType.NATIVE_NETWORK_LINK_TO));
- return predicates;
- }
-
- @Override
- protected Optional<List<String>> getConnectorPropertyParamName(String heatResourceId,
- Resource heatResource,
- HeatOrchestrationTemplate
- nestedHeatOrchestrationTemplate,
- String nestedHeatFileName) {
- Object interfaceListProperty =
- heatResource.getProperties().get(HeatConstants.INTERFACE_LIST_PROPERTY_NAME);
- if (interfaceListProperty == null) {
- return Optional.empty();
+ ContrailPortToNetResourceConnection(ResourceTranslationBase resourceTranslationBase,
+ TranslateTo translateTo, FileData nestedFileData,
+ NodeTemplate substitutionNodeTemplate,
+ NodeType nodeType) {
+ super(resourceTranslationBase, translateTo, nestedFileData, substitutionNodeTemplate, nodeType);
}
- List<String> paramsList = new ArrayList<>();
- if (interfaceListProperty instanceof List) {
- for (int index = 0; index < ((List) interfaceListProperty).size(); index++) {
- Object interfaceEntry = ((List) interfaceListProperty).get(index);
- if (interfaceEntry instanceof Map) {
- Optional<AttachedResourceId> attachedVirtualNetwork = HeatToToscaUtil
- .extractAttachedResourceId(nestedHeatFileName, nestedHeatOrchestrationTemplate,
- translateTo.getContext(),
- ((Map) interfaceEntry).get(HeatConstants.VIRTUAL_NETWORK_PROPERTY_NAME));
- if (attachedVirtualNetwork.isPresent() && attachedVirtualNetwork.get().isGetParam()
- && attachedVirtualNetwork.get().getEntityId() instanceof String) {
- paramsList.add((String) attachedVirtualNetwork.get().getEntityId());
- }
+
+ @Override
+ protected boolean isDesiredNodeTemplateType(NodeTemplate nodeTemplate) {
+ ToscaAnalyzerService toscaAnalyzerService = new ToscaAnalyzerServiceImpl();
+ ToscaServiceModel toscaServiceModel =
+ HeatToToscaUtil.getToscaServiceModel(translateTo.getContext());
+ return toscaAnalyzerService
+ .isTypeOf(nodeTemplate, ToscaNodeType.CONTRAIL_ABSTRACT_SUBSTITUTE,
+ translateTo.getContext().getTranslatedServiceTemplates()
+ .get(translateTo.getResource().getType()), toscaServiceModel);
+ }
+
+ @Override
+ protected List<Predicate<RequirementDefinition>> getPredicatesListForConnectionPoints() {
+ ArrayList<Predicate<RequirementDefinition>> predicates = new ArrayList<>();
+ predicates.add(
+ req -> req.getCapability().equals(ToscaCapabilityType.NATIVE_NETWORK_LINKABLE)
+ && (req.getNode() == null || req.getNode().equals(ToscaNodeType.NATIVE_ROOT))
+ && req.getRelationship()
+ .equals(ToscaRelationshipType.NATIVE_NETWORK_LINK_TO));
+ return predicates;
+ }
+
+ @Override
+ protected Optional<List<String>> getConnectorPropertyParamName(String heatResourceId,
+ Resource heatResource,
+ HeatOrchestrationTemplate
+ nestedHeatOrchestrationTemplate,
+ String nestedHeatFileName) {
+ Object interfaceListProperty = heatResource.getProperties().get(HeatConstants.INTERFACE_LIST_PROPERTY_NAME);
+ if (interfaceListProperty == null) {
+ return Optional.empty();
+ }
+ List<String> paramsList = new ArrayList<>();
+ if (interfaceListProperty instanceof List) {
+ return getConnectorPropertyParamNameFromList(nestedHeatOrchestrationTemplate, nestedHeatFileName,
+ (List) interfaceListProperty, paramsList);
+ } else if (interfaceListProperty instanceof Map) {
+ return getConnectorPropertyParamNameFromMap(nestedHeatOrchestrationTemplate, nestedHeatFileName,
+ (Map) interfaceListProperty, paramsList);
+ }
+ return Optional.empty();
+ }
+
+ private Optional<List<String>> getConnectorPropertyParamNameFromList(
+ HeatOrchestrationTemplate nestedHeatOrchestrationTemplate, String nestedHeatFileName,
+ List interfaceListProperty, List<String> paramsList) {
+ for (Object interfaceEntry : interfaceListProperty) {
+ if (interfaceEntry instanceof Map) {
+ Optional<AttachedResourceId> attachedVirtualNetwork = HeatToToscaUtil.extractAttachedResourceId(
+ nestedHeatFileName, nestedHeatOrchestrationTemplate, translateTo.getContext(),
+ ((Map) interfaceEntry).get(HeatConstants.VIRTUAL_NETWORK_PROPERTY_NAME));
+ if (attachedVirtualNetwork.isPresent() && attachedVirtualNetwork.get().isGetParam()
+ && attachedVirtualNetwork.get().getEntityId() instanceof String) {
+ paramsList.add((String) attachedVirtualNetwork.get().getEntityId());
+ }
+ }
}
- }
- return Optional.of(paramsList);
- } else if (interfaceListProperty instanceof Map) {
- Optional<AttachedResourceId> attachedVirtualNetwork = HeatToToscaUtil
- .extractAttachedResourceId(nestedHeatFileName, nestedHeatOrchestrationTemplate,
- translateTo.getContext(),
- ((Map) interfaceListProperty).get(HeatConstants.VIRTUAL_NETWORK_PROPERTY_NAME));
- if (attachedVirtualNetwork.isPresent() && attachedVirtualNetwork.get().isGetParam()
- && attachedVirtualNetwork.get().getEntityId() instanceof String) {
- paramsList.add((String) attachedVirtualNetwork.get().getEntityId());
return Optional.of(paramsList);
- }
}
- return Optional.empty();
- }
-
- @Override
- protected String getDesiredResourceType() {
- return HeatResourcesTypes.CONTRAIL_SERVICE_INSTANCE.getHeatResource();
- }
-
- @Override
- protected void addRequirementToConnectResources(
- Map.Entry<String, RequirementDefinition> requirementDefinitionEntry,
- List<String> paramNames) {
- if (paramNames == null || paramNames.isEmpty()) {
- return;
+
+ private Optional<List<String>> getConnectorPropertyParamNameFromMap(HeatOrchestrationTemplate
+ nestedHeatOrchestrationTemplate,
+ String nestedHeatFileName,
+ Map interfaceListProperty,
+ List<String> paramsList) {
+ Optional<AttachedResourceId> attachedVirtualNetwork = HeatToToscaUtil
+ .extractAttachedResourceId(nestedHeatFileName, nestedHeatOrchestrationTemplate,
+ translateTo.getContext(),
+ interfaceListProperty.get(HeatConstants.VIRTUAL_NETWORK_PROPERTY_NAME));
+ if (attachedVirtualNetwork.isPresent() && attachedVirtualNetwork.get().isGetParam()
+ && attachedVirtualNetwork.get().getEntityId() instanceof String) {
+ paramsList.add((String) attachedVirtualNetwork.get().getEntityId());
+ return Optional.of(paramsList);
+ }
+ return Optional.empty();
+ }
+
+ @Override
+ protected String getDesiredResourceType() {
+ return HeatResourcesTypes.CONTRAIL_SERVICE_INSTANCE.getHeatResource();
+ }
+
+ @Override
+ protected void addRequirementToConnectResources(
+ Map.Entry<String, RequirementDefinition> requirementDefinitionEntry,
+ List<String> paramNames) {
+ if (paramNames == null || paramNames.isEmpty()) {
+ return;
+ }
+ Integer index = Integer.valueOf(
+ requirementDefinitionEntry.getKey().substring("link_port_".length()).substring(0, 1));
+
+ String paramName = paramNames.get(
+ index); // port can connect to one network only and we are
+ // expecting to get only one param(unlike security rules to port)
+ Object paramValue = translateTo.getResource().getProperties().get(paramName);
+ List<String> supportedNetworkTypes =
+ ImmutableList.of(HeatResourcesTypes.NEUTRON_NET_RESOURCE_TYPE.getHeatResource(),
+ HeatResourcesTypes.CONTRAIL_VIRTUAL_NETWORK_RESOURCE_TYPE.getHeatResource());
+
+ addRequirementToConnectResource(requirementDefinitionEntry, paramName, paramValue,
+ supportedNetworkTypes);
}
- Integer index = Integer.valueOf(
- requirementDefinitionEntry.getKey().substring("link_port_".length()).substring(0, 1));
-
- String paramName = paramNames.get(
- index); // port can connect to one network only and we are
- // expecting to get only one param(unlike security rules to port)
- Object paramValue = translateTo.getResource().getProperties().get(paramName);
- List<String> supportedNetworkTypes =
- Arrays.asList(HeatResourcesTypes.NEUTRON_NET_RESOURCE_TYPE.getHeatResource(),
- HeatResourcesTypes.CONTRAIL_VIRTUAL_NETWORK_RESOURCE_TYPE.getHeatResource());
-
- addRequirementToConnectResource(requirementDefinitionEntry, paramName, paramValue,
- supportedNetworkTypes);
- }
-
- @Override
- boolean validateResourceTypeSupportedForReqCreation(String nestedResourceId,
- final String nestedPropertyName,
- String connectionPointId,
- Resource connectedResource,
- List<String> supportedTypes) {
- if (!resourceTranslationBase.isResourceTypeSupported(connectedResource, supportedTypes)) {
- logger.warn("Nested resource '" + nestedResourceId + "' property '" + nestedPropertyName
- + "' is pointing to a resource with type '" + connectedResource.getType()
- + "' which is not supported for requirement '" + connectionPointId
- + "' that connect contrail port to network. Supported types are: '"
- + supportedTypes.toString()
- + "', therefore, this TOSCA requirement will not be connected.");
- return false;
+
+ @Override
+ boolean validateResourceTypeSupportedForReqCreation(String nestedResourceId,
+ final String nestedPropertyName,
+ String connectionPointId,
+ Resource connectedResource,
+ List<String> supportedTypes) {
+ if (resourceTranslationBase.isUnsupportedResourceType(connectedResource, supportedTypes)) {
+ logger.warn(LOG_UNSUPPORTED_CONTRAIL_PORT_NETWORK_REQUIREMENT_CONNECTION, nestedResourceId,
+ nestedPropertyName, connectedResource.getType(), connectionPointId, supportedTypes.toString());
+ return false;
+ }
+ return true;
}
- return true;
- }
}
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/ContrailV2VlanToInterfaceResourceConnection.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ContrailV2VlanToInterfaceResourceConnection.java
index 7f80f47522..24ff55de60 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ContrailV2VlanToInterfaceResourceConnection.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ContrailV2VlanToInterfaceResourceConnection.java
@@ -1,25 +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.translator.services.heattotosca.HeatToToscaLogConstants.LOG_MULTIPLE_INTERFACE_VALUES_NESTED;
+import static org.openecomp.sdc.translator.services.heattotosca.HeatToToscaLogConstants.LOG_UNSUPPORTED_VMI_VLAN_SUB_INTERFACE_REQUIREMENT_CONNECTION;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.function.Predicate;
+
+import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
+import org.onap.sdc.tosca.datatypes.model.NodeType;
+import org.onap.sdc.tosca.datatypes.model.RequirementDefinition;
import org.openecomp.sdc.heat.datatypes.manifest.FileData;
import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate;
import org.openecomp.sdc.heat.datatypes.model.HeatResourcesTypes;
@@ -28,124 +38,109 @@ 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.NodeType;
-import org.onap.sdc.tosca.datatypes.model.RequirementDefinition;
import org.openecomp.sdc.translator.datatypes.heattotosca.AttachedResourceId;
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 java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.function.Predicate;
-
public class ContrailV2VlanToInterfaceResourceConnection
- extends ResourceConnectionUsingRequirementHelper {
+ extends ResourceConnectionUsingRequirementHelper {
- public ContrailV2VlanToInterfaceResourceConnection(
- ResourceTranslationBase resourceTranslationBase, TranslateTo translateTo,
- FileData nestedFileData, NodeTemplate substitutionNodeTemplate, NodeType nodeType) {
- super(resourceTranslationBase, translateTo, nestedFileData, substitutionNodeTemplate, nodeType);
- }
-
- @Override
- protected boolean isDesiredNodeTemplateType(NodeTemplate nodeTemplate) {
- return nodeTemplate.getType()
- .equals(ToscaNodeType.CONTRAILV2_VLAN_SUB_INTERFACE);
- }
+ ContrailV2VlanToInterfaceResourceConnection(ResourceTranslationBase resourceTranslationBase,
+ TranslateTo translateTo, FileData nestedFileData,
+ NodeTemplate substitutionNodeTemplate, NodeType nodeType) {
+ super(resourceTranslationBase, translateTo, nestedFileData, substitutionNodeTemplate, nodeType);
+ }
- @Override
- protected List<Predicate<RequirementDefinition>> getPredicatesListForConnectionPoints() {
- ArrayList<Predicate<RequirementDefinition>> predicates = new ArrayList<>();
- predicates.add(
- req -> req.getCapability().equals(ToscaCapabilityType.NATIVE_NETWORK_BINDABLE)
- && (req.getNode() == null || req.getNode().equals(ToscaNodeType.NETWORK_PORT))
- && req.getRelationship()
- .equals(ToscaRelationshipType.NATIVE_NETWORK_BINDS_TO));
- return predicates;
- }
+ @Override
+ protected boolean isDesiredNodeTemplateType(NodeTemplate nodeTemplate) {
+ return nodeTemplate.getType().equals(ToscaNodeType.CONTRAILV2_VLAN_SUB_INTERFACE);
+ }
- @Override
- protected Optional<List<String>> getConnectorPropertyParamName(String heatResourceId,
- Resource heatResource,
- HeatOrchestrationTemplate
- nestedHeatOrchestrationTemplate,
- String nestedHeatFileName) {
- List<String> interfaces = new ArrayList<>();
- Object interfaceRefs = heatResource.getProperties().get(HeatConstants.VMI_REFS_PROPERTY_NAME);
- if (Objects.isNull(interfaceRefs) || !(interfaceRefs instanceof List)
- || ((List) interfaceRefs).size() == 0) {
- return Optional.empty();
+ @Override
+ protected List<Predicate<RequirementDefinition>> getPredicatesListForConnectionPoints() {
+ ArrayList<Predicate<RequirementDefinition>> predicates = new ArrayList<>();
+ predicates.add(
+ req -> req.getCapability().equals(ToscaCapabilityType.NATIVE_NETWORK_BINDABLE)
+ && (req.getNode() == null || req.getNode().equals(ToscaNodeType.NETWORK_PORT))
+ && req.getRelationship()
+ .equals(ToscaRelationshipType.NATIVE_NETWORK_BINDS_TO));
+ return predicates;
}
- if (((List) interfaceRefs).size() > 1) {
- logger.warn("Heat resource: '" + translateTo.getResourceId() + "' with nested heat file: '"
- + translateTo.getResource().getType()
- + "' has resource '" + heatResourceId + "' with type '"
- + HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource()
- + "' which 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.");
+
+ @Override
+ protected Optional<List<String>> getConnectorPropertyParamName(String heatResourceId,
+ Resource heatResource,
+ HeatOrchestrationTemplate
+ nestedHeatOrchestrationTemplate,
+ String nestedHeatFileName) {
+ List<String> interfaces = new ArrayList<>();
+ Object interfaceRefs = heatResource.getProperties().get(HeatConstants.VMI_REFS_PROPERTY_NAME);
+ if (Objects.isNull(interfaceRefs) || !(interfaceRefs instanceof List)
+ || ((List) interfaceRefs).isEmpty()) {
+ return Optional.empty();
+ }
+ if (((List) interfaceRefs).size() > 1) {
+ logger.warn(LOG_MULTIPLE_INTERFACE_VALUES_NESTED,
+ translateTo.getResourceId(), translateTo.getResource().getType(), heatResourceId,
+ HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
+ HeatConstants.VMI_REFS_PROPERTY_NAME);
+ }
+ Object interfaceRef = ((List) interfaceRefs).get(0);
+ Optional<AttachedResourceId> attachedInterfaceResource = HeatToToscaUtil
+ .extractAttachedResourceId(nestedFileData.getFile(), nestedHeatOrchestrationTemplate,
+ translateTo.getContext(), interfaceRef);
+ if (attachedInterfaceResource.isPresent() && attachedInterfaceResource.get().isGetParam()
+ && attachedInterfaceResource.get().getEntityId() instanceof String) {
+ interfaces.add((String) attachedInterfaceResource.get().getEntityId());
+ }
+ return Optional.of(interfaces);
}
- Object interfaceRef = ((List) interfaceRefs).get(0);
- Optional<AttachedResourceId> attachedInterfaceResource = HeatToToscaUtil
- .extractAttachedResourceId(nestedFileData.getFile(), nestedHeatOrchestrationTemplate,
- translateTo.getContext(), interfaceRef);
- if (attachedInterfaceResource.isPresent() && attachedInterfaceResource.get().isGetParam()
- && attachedInterfaceResource.get().getEntityId() instanceof String) {
- interfaces.add((String) attachedInterfaceResource.get().getEntityId());
+
+ @Override
+ protected String getDesiredResourceType() {
+ return HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource();
}
- return Optional.of(interfaces);
- }
- @Override
- protected String getDesiredResourceType() {
- return HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource();
- }
+ @Override
+ protected void addRequirementToConnectResources(
+ Map.Entry<String, RequirementDefinition> requirementDefinitionEntry,
+ List<String> paramNames) {
+ if (paramNames == null || paramNames.isEmpty()) {
+ return;
+ }
+ for (String paramName : paramNames) {
+ Object paramValue = translateTo.getResource().getProperties().get(paramName);
+ List<String> supportedInterfaceTypes =
+ Arrays.asList(HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource(),
+ HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE
+ .getHeatResource());
- @Override
- protected void addRequirementToConnectResources(
- Map.Entry<String, RequirementDefinition> requirementDefinitionEntry,
- List<String> paramNames) {
- if (paramNames == null || paramNames.isEmpty()) {
- return;
+ addRequirementToConnectResource(requirementDefinitionEntry, paramName, paramValue,
+ supportedInterfaceTypes);
+ }
}
- for (String paramName : paramNames) {
- Object paramValue = translateTo.getResource().getProperties().get(paramName);
- List<String> supportedInterfaceTypes =
- Arrays.asList(HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource(),
- HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE
- .getHeatResource());
- addRequirementToConnectResource(requirementDefinitionEntry, paramName, paramValue,
- supportedInterfaceTypes);
+ @Override
+ boolean validateResourceTypeSupportedForReqCreation(String nestedResourceId,
+ final String nestedPropertyName,
+ String connectionPointId,
+ Resource connectedResource,
+ List<String> supportedTypes) {
+ if (resourceTranslationBase.isUnsupportedResourceType(connectedResource, supportedTypes)
+ || (new ContrailV2VirtualMachineInterfaceHelper()
+ .isVlanSubInterfaceResource(connectedResource))) {
+ logger.warn(LOG_UNSUPPORTED_VMI_VLAN_SUB_INTERFACE_REQUIREMENT_CONNECTION, nestedResourceId,
+ nestedPropertyName,
+ getLogMessageSuffixForConnectedResource(connectedResource), connectedResource.getType(),
+ connectionPointId, supportedTypes.toString());
+ return false;
+ }
+ return true;
}
- }
- @Override
- boolean validateResourceTypeSupportedForReqCreation(String nestedResourceId,
- final String nestedPropertyName,
- String connectionPointId,
- Resource connectedResource,
- List<String> supportedTypes) {
- if (!resourceTranslationBase.isResourceTypeSupported(connectedResource, supportedTypes)
- || (new ContrailV2VirtualMachineInterfaceHelper()
- .isVlanSubInterfaceResource(connectedResource))) {
- logger.warn("Nested resource '" + nestedResourceId + "' property '" + nestedPropertyName
- + "' is pointing to a " + (true == (new ContrailV2VirtualMachineInterfaceHelper()
- .isVlanSubInterfaceResource(connectedResource)) ? "Vlan Sub interface " : "")
- + "resource with type '" + connectedResource.getType() + "' which"
- + " is not supported for requirement '" + connectionPointId
- + "' that connect vmi vlan sub interface to interface. Supported types are: '"
- + supportedTypes.toString() + "' (excluding Vlan), therefore, this TOSCA requirement will"
- + " not be connected.");
- return false;
+ private String getLogMessageSuffixForConnectedResource(Resource connectedResource) {
+ return new ContrailV2VirtualMachineInterfaceHelper()
+ .isVlanSubInterfaceResource(connectedResource) ? "Vlan Sub interface " : "";
}
- return true;
- }
}
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/ContrailV2VmInterfaceToNetResourceConnection.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ContrailV2VmInterfaceToNetResourceConnection.java
index d5fb91a8a2..75938d69f9 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ContrailV2VmInterfaceToNetResourceConnection.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ContrailV2VmInterfaceToNetResourceConnection.java
@@ -1,145 +1,139 @@
-/*-
- * ============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_VIRTUAL_NETWORK_REFS_VALUES;
+import static org.openecomp.sdc.translator.services.heattotosca.HeatToToscaLogConstants.LOG_UNSUPPORTED_VMI_NETWORK_REQUIREMENT_CONNECTION;
+
+import com.google.common.collect.ImmutableList;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.function.Predicate;
+
+import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
+import org.onap.sdc.tosca.datatypes.model.NodeType;
+import org.onap.sdc.tosca.datatypes.model.RequirementDefinition;
import org.openecomp.sdc.heat.datatypes.manifest.FileData;
import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate;
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.NodeType;
-import org.onap.sdc.tosca.datatypes.model.RequirementDefinition;
import org.openecomp.sdc.translator.datatypes.heattotosca.AttachedResourceId;
import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo;
import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.function.Predicate;
-
public class ContrailV2VmInterfaceToNetResourceConnection
- extends ResourceConnectionUsingRequirementHelper {
+ extends ResourceConnectionUsingRequirementHelper {
- public ContrailV2VmInterfaceToNetResourceConnection(
- ResourceTranslationBase resourceTranslationBase, TranslateTo translateTo,
- FileData nestedFileData, NodeTemplate substitutionNodeTemplate, NodeType nodeType) {
- super(resourceTranslationBase, translateTo, nestedFileData, substitutionNodeTemplate, nodeType);
- }
-
- @Override
- protected boolean isDesiredNodeTemplateType(NodeTemplate nodeTemplate) {
- return (nodeTemplate.getType()
- .equals(ToscaNodeType.CONTRAILV2_VIRTUAL_MACHINE_INTERFACE)
- || nodeTemplate.getType()
- .equals(ToscaNodeType.CONTRAILV2_VLAN_SUB_INTERFACE));
- }
-
- @Override
- protected List<Predicate<RequirementDefinition>> getPredicatesListForConnectionPoints() {
- ArrayList<Predicate<RequirementDefinition>> predicates = new ArrayList<>();
- predicates.add(
- req -> req.getCapability().equals(ToscaCapabilityType.NATIVE_NETWORK_LINKABLE)
- && (req.getNode() == null || req.getNode().equals(ToscaNodeType.NATIVE_ROOT))
- && req.getRelationship()
- .equals(ToscaRelationshipType.NATIVE_NETWORK_LINK_TO));
- return predicates;
- }
-
- @Override
- protected Optional<List<String>> getConnectorPropertyParamName(String heatResourceId,
- Resource heatResource,
- HeatOrchestrationTemplate
- nestedHeatOrchestrationTemplate,
- String nestedHeatFileName) {
- List<String> networks = new ArrayList<>();
- Object virtualNetworkRefs = heatResource.getProperties().get("virtual_network_refs");
- if (Objects.isNull(virtualNetworkRefs) || !(virtualNetworkRefs instanceof List)
- || ((List) virtualNetworkRefs).size() == 0) {
- return Optional.empty();
+ ContrailV2VmInterfaceToNetResourceConnection(ResourceTranslationBase resourceTranslationBase,
+ TranslateTo translateTo, FileData nestedFileData,
+ NodeTemplate substitutionNodeTemplate, NodeType nodeType) {
+ super(resourceTranslationBase, translateTo, nestedFileData, substitutionNodeTemplate, nodeType);
}
- if (((List) virtualNetworkRefs).size() > 1) {
- logger.warn("Heat resource: '" + translateTo.getResourceId() + "' with nested heat file: '"
- + translateTo.getResource().getType()
- + "' has resource '" + heatResourceId + "' with type '"
- + HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource()
- + "' which include 'virtual_network_refs' property with more than one network values, "
- + "only the first network will be translated, all rest will be ignored in TOSCA "
- + "translation.");
+
+ @Override
+ protected boolean isDesiredNodeTemplateType(NodeTemplate nodeTemplate) {
+ return (nodeTemplate.getType()
+ .equals(ToscaNodeType.CONTRAILV2_VIRTUAL_MACHINE_INTERFACE)
+ || nodeTemplate.getType()
+ .equals(ToscaNodeType.CONTRAILV2_VLAN_SUB_INTERFACE));
}
- Object virtualNetworkRef = ((List) virtualNetworkRefs).get(0);
- Optional<AttachedResourceId> network = HeatToToscaUtil
- .extractAttachedResourceId(nestedFileData.getFile(), nestedHeatOrchestrationTemplate,
- translateTo.getContext(), virtualNetworkRef);
- if (network.isPresent() && network.get().isGetParam()
- && network.get().getEntityId() instanceof String) {
- networks.add((String) network.get().getEntityId());
+
+ @Override
+ protected List<Predicate<RequirementDefinition>> getPredicatesListForConnectionPoints() {
+ ArrayList<Predicate<RequirementDefinition>> predicates = new ArrayList<>();
+ predicates.add(
+ req -> req.getCapability().equals(ToscaCapabilityType.NATIVE_NETWORK_LINKABLE)
+ && (req.getNode() == null || req.getNode().equals(ToscaNodeType.NATIVE_ROOT))
+ && req.getRelationship()
+ .equals(ToscaRelationshipType.NATIVE_NETWORK_LINK_TO));
+ return predicates;
}
- return Optional.of(networks);
- }
- @Override
- protected String getDesiredResourceType() {
- return HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource();
- }
+ @Override
+ protected Optional<List<String>> getConnectorPropertyParamName(String heatResourceId,
+ Resource heatResource,
+ HeatOrchestrationTemplate
+ nestedHeatOrchestrationTemplate,
+ String nestedHeatFileName) {
+ List<String> networks = new ArrayList<>();
+ Object virtualNetworkRefs = heatResource.getProperties().get(HeatConstants.VIRTUAL_NETWORK_REFS_PROPERTY_NAME);
+ if (Objects.isNull(virtualNetworkRefs) || !(virtualNetworkRefs instanceof List)
+ || ((List) virtualNetworkRefs).isEmpty()) {
+ return Optional.empty();
+ }
+ if (((List) virtualNetworkRefs).size() > 1) {
+ logger.warn(LOG_MULTIPLE_VIRTUAL_NETWORK_REFS_VALUES, translateTo.getResourceId(),
+ translateTo.getResource().getType(), heatResourceId,
+ HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource());
+ }
+ Object virtualNetworkRef = ((List) virtualNetworkRefs).get(0);
+ Optional<AttachedResourceId> network = HeatToToscaUtil
+ .extractAttachedResourceId(nestedFileData.getFile(), nestedHeatOrchestrationTemplate,
+ translateTo.getContext(), virtualNetworkRef);
+ if (network.isPresent() && network.get().isGetParam()
+ && network.get().getEntityId() instanceof String) {
+ networks.add((String) network.get().getEntityId());
+ }
+ return Optional.of(networks);
+ }
- @Override
- protected void addRequirementToConnectResources(
- Map.Entry<String, RequirementDefinition> requirementDefinitionEntry,
- List<String> paramNames) {
- if (paramNames == null || paramNames.isEmpty()) {
- return;
+ @Override
+ protected String getDesiredResourceType() {
+ return HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource();
}
- for (String paramName : paramNames) {
- Object paramValue = translateTo.getResource().getProperties().get(paramName);
- List<String> supportedNetworkTypes =
- Arrays.asList(HeatResourcesTypes.NEUTRON_NET_RESOURCE_TYPE.getHeatResource(),
- HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_NETWORK_RESOURCE_TYPE.getHeatResource());
- addRequirementToConnectResource(requirementDefinitionEntry, paramName, paramValue,
- supportedNetworkTypes);
+ @Override
+ protected void addRequirementToConnectResources(
+ Map.Entry<String, RequirementDefinition> requirementDefinitionEntry,
+ List<String> paramNames) {
+ if (paramNames == null || paramNames.isEmpty()) {
+ return;
+ }
+ for (String paramName : paramNames) {
+ Object paramValue = translateTo.getResource().getProperties().get(paramName);
+ List<String> supportedNetworkTypes =
+ ImmutableList.of(HeatResourcesTypes.NEUTRON_NET_RESOURCE_TYPE.getHeatResource(),
+ HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_NETWORK_RESOURCE_TYPE.getHeatResource());
+
+ addRequirementToConnectResource(requirementDefinitionEntry, paramName, paramValue,
+ supportedNetworkTypes);
+ }
}
- }
- @Override
- boolean validateResourceTypeSupportedForReqCreation(String nestedResourceId,
- final String nestedPropertyName,
- String connectionPointId,
- Resource connectedResource,
- List<String> supportedTypes) {
- if (!resourceTranslationBase.isResourceTypeSupported(connectedResource, supportedTypes)) {
- logger.warn("Nested resource '" + nestedResourceId + "' property '" + nestedPropertyName
- + "' is pointing to a resource with type '" + connectedResource.getType()
- + "' which is not supported for requirement '" + connectionPointId
- + "' that connect virtual machine interface to network. Supported types are: '"
- + supportedTypes.toString()
- + "', therefore, this TOSCA requirement will not be connected.");
- return false;
+ @Override
+ boolean validateResourceTypeSupportedForReqCreation(String nestedResourceId,
+ final String nestedPropertyName,
+ String connectionPointId,
+ Resource connectedResource,
+ List<String> supportedTypes) {
+ if (resourceTranslationBase.isUnsupportedResourceType(connectedResource, supportedTypes)) {
+ logger.warn(LOG_UNSUPPORTED_VMI_NETWORK_REQUIREMENT_CONNECTION,
+ nestedResourceId, nestedPropertyName, connectedResource.getType(), connectionPointId,
+ supportedTypes.toString());
+ return false;
+ }
+ return true;
}
- return true;
- }
}
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/NovaToVolResourceConnection.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/NovaToVolResourceConnection.java
index ee65581ac5..cd8e3764e2 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/NovaToVolResourceConnection.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/NovaToVolResourceConnection.java
@@ -1,26 +1,36 @@
-/*-
- * ============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_UNSUPPORTED_VOL_ATTACHMENT_VOLUME_REQUIREMENT_CONNECTION;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+
import org.apache.commons.collections4.CollectionUtils;
+import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
+import org.onap.sdc.tosca.datatypes.model.NodeType;
+import org.onap.sdc.tosca.datatypes.model.RequirementDefinition;
import org.openecomp.sdc.common.errors.CoreException;
import org.openecomp.sdc.heat.datatypes.manifest.FileData;
import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate;
@@ -30,9 +40,6 @@ import org.openecomp.sdc.tosca.datatypes.ToscaCapabilityType;
import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
import org.openecomp.sdc.tosca.datatypes.ToscaRelationshipType;
import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
-import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
-import org.onap.sdc.tosca.datatypes.model.NodeType;
-import org.onap.sdc.tosca.datatypes.model.RequirementDefinition;
import org.openecomp.sdc.tosca.services.ToscaAnalyzerService;
import org.openecomp.sdc.tosca.services.impl.ToscaAnalyzerServiceImpl;
import org.openecomp.sdc.translator.datatypes.heattotosca.AttachedResourceId;
@@ -44,202 +51,180 @@ import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil;
import org.openecomp.sdc.translator.services.heattotosca.errors.MissingMandatoryPropertyErrorBuilder;
import org.openecomp.sdc.translator.services.heattotosca.helper.VolumeTranslationHelper;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.function.Predicate;
-import java.util.stream.Collectors;
-
class NovaToVolResourceConnection extends ResourceConnectionUsingRequirementHelper {
- public NovaToVolResourceConnection(ResourceTranslationBase resourceTranslationBase,
- TranslateTo translateTo, FileData nestedFileData,
- NodeTemplate substitutionNodeTemplate, NodeType nodeType) {
- super(resourceTranslationBase, translateTo, nestedFileData, substitutionNodeTemplate, nodeType);
- }
-
- @Override
- boolean isDesiredNodeTemplateType(NodeTemplate nodeTemplate) {
- ToscaAnalyzerService toscaAnalyzerService = new ToscaAnalyzerServiceImpl();
- ToscaServiceModel toscaServiceModel =
- HeatToToscaUtil.getToscaServiceModel(translateTo.getContext());
- return toscaAnalyzerService.isTypeOf(nodeTemplate, ToscaNodeType.NOVA_SERVER,
- translateTo.getContext().getTranslatedServiceTemplates()
- .get(translateTo.getResource().getType()), toscaServiceModel);
- }
-
- @Override
- List<Predicate<RequirementDefinition>> getPredicatesListForConnectionPoints() {
- ArrayList<Predicate<RequirementDefinition>> predicates = new ArrayList<>();
- predicates
- .add(req -> req.getCapability().equals(ToscaCapabilityType.NATIVE_ATTACHMENT)
- && req.getNode().equals(ToscaNodeType.NATIVE_BLOCK_STORAGE)
- && req.getRelationship()
- .equals(ToscaRelationshipType.NATIVE_ATTACHES_TO));
- return predicates;
- }
-
- @Override
- Optional<List<String>> getConnectorPropertyParamName(String heatResourceId, Resource heatResource,
- HeatOrchestrationTemplate
- nestedHeatOrchestrationTemplate,
- String nestedHeatFileName) {
-
-
-
- Optional<AttachedResourceId> volumeId = HeatToToscaUtil
- .extractAttachedResourceId(nestedFileData.getFile(), nestedHeatOrchestrationTemplate,
- translateTo.getContext(), heatResource.getProperties().get("volume_id"));
- if (volumeId.isPresent() && volumeId.get().isGetParam()
- && volumeId.get().getEntityId() instanceof String) {
- return Optional.of(Collections.singletonList((String) volumeId.get().getEntityId()));
- } else {
- return Optional.empty();
+ NovaToVolResourceConnection(ResourceTranslationBase resourceTranslationBase,
+ TranslateTo translateTo, FileData nestedFileData,
+ NodeTemplate substitutionNodeTemplate, NodeType nodeType) {
+ super(resourceTranslationBase, translateTo, nestedFileData, substitutionNodeTemplate, nodeType);
}
- }
-
- @Override
- String getDesiredResourceType() {
- return HeatResourcesTypes.CINDER_VOLUME_ATTACHMENT_RESOURCE_TYPE.getHeatResource();
- }
-
- @Override
- void addRequirementToConnectResources(
- Map.Entry<String, RequirementDefinition> requirementDefinitionEntry,
- List<String> paramNames) {
-
+ @Override
+ boolean isDesiredNodeTemplateType(NodeTemplate nodeTemplate) {
+ ToscaAnalyzerService toscaAnalyzerService = new ToscaAnalyzerServiceImpl();
+ ToscaServiceModel toscaServiceModel =
+ HeatToToscaUtil.getToscaServiceModel(translateTo.getContext());
+ return toscaAnalyzerService.isTypeOf(nodeTemplate, ToscaNodeType.NOVA_SERVER,
+ translateTo.getContext().getTranslatedServiceTemplates()
+ .get(translateTo.getResource().getType()), toscaServiceModel);
+ }
- if (paramNames == null || paramNames.isEmpty()) {
- return;
+ @Override
+ List<Predicate<RequirementDefinition>> getPredicatesListForConnectionPoints() {
+ ArrayList<Predicate<RequirementDefinition>> predicates = new ArrayList<>();
+ predicates
+ .add(req -> req.getCapability().equals(ToscaCapabilityType.NATIVE_ATTACHMENT)
+ && req.getNode().equals(ToscaNodeType.NATIVE_BLOCK_STORAGE)
+ && req.getRelationship()
+ .equals(ToscaRelationshipType.NATIVE_ATTACHES_TO));
+ return predicates;
}
- List<String> supportedVolumeTypes =
- Collections.singletonList(HeatResourcesTypes.CINDER_VOLUME_RESOURCE_TYPE.getHeatResource());
+ @Override
+ Optional<List<String>> getConnectorPropertyParamName(String heatResourceId, Resource heatResource,
+ HeatOrchestrationTemplate
+ nestedHeatOrchestrationTemplate,
+ String nestedHeatFileName) {
+
+
+ Optional<AttachedResourceId> volumeId = HeatToToscaUtil
+ .extractAttachedResourceId(nestedFileData.getFile(), nestedHeatOrchestrationTemplate,
+ translateTo.getContext(), heatResource.getProperties().get("volume_id"));
+ if (volumeId.isPresent() && volumeId.get().isGetParam()
+ && volumeId.get().getEntityId() instanceof String) {
+ return Optional.of(Collections.singletonList((String) volumeId.get().getEntityId()));
+ } else {
+ return Optional.empty();
+ }
+ }
- for (String paramName : paramNames) {
- Object paramValue = translateTo.getResource().getProperties().get(paramName);
- addRequirementToConnectResource(requirementDefinitionEntry, paramName, paramValue,
- supportedVolumeTypes);
+ @Override
+ String getDesiredResourceType() {
+ return HeatResourcesTypes.CINDER_VOLUME_ATTACHMENT_RESOURCE_TYPE.getHeatResource();
}
- }
+ @Override
+ void addRequirementToConnectResources(
+ Map.Entry<String, RequirementDefinition> requirementDefinitionEntry,
+ List<String> paramNames) {
- @Override
- boolean validateResourceTypeSupportedForReqCreation(String nestedResourceId,
- String nestedPropertyName,
- String connectionPointId,
- Resource connectedResource,
- List<String> supportedTypes) {
+ if (paramNames == null || paramNames.isEmpty()) {
+ return;
+ }
+ List<String> supportedVolumeTypes =
+ Collections.singletonList(HeatResourcesTypes.CINDER_VOLUME_RESOURCE_TYPE.getHeatResource());
- if (!resourceTranslationBase.isResourceTypeSupported(connectedResource, supportedTypes)) {
- logger.warn("Nested resource '" + nestedResourceId + "' property '" + nestedPropertyName
- + "' is pointing to a resource with type '" + connectedResource.getType()
- + "' which is not supported for requirement '" + connectionPointId
- + "' that connect VolumeAttachment to Volume. Supported types are: '"
- + supportedTypes.toString()
- + "', therefore, this TOSCA requirement will not be connected.");
+ for (String paramName : paramNames) {
+ Object paramValue = translateTo.getResource().getProperties().get(paramName);
+ addRequirementToConnectResource(requirementDefinitionEntry, paramName, paramValue,
+ supportedVolumeTypes);
+ }
- return false;
}
- return true;
- }
-
- @Override
- protected Optional<List<Map.Entry<String, Resource>>> getResourceByTranslatedResourceId(
- String translatedResourceId, HeatOrchestrationTemplate nestedHeatOrchestrationTemplate) {
-
-
-
- List<Predicate<Map.Entry<String, Resource>>> predicates =
- buildPredicates(nestedFileData.getFile(), nestedHeatOrchestrationTemplate,
- translatedResourceId);
- List<Map.Entry<String, Resource>> list =
- nestedHeatOrchestrationTemplate.getResources().entrySet()
- .stream()
- .filter(entry -> predicates
- .stream()
- .allMatch(p -> p.test(entry)))
- .collect(Collectors.toList());
- if (CollectionUtils.isEmpty(list)) {
- return Optional.empty();
- } else {
- return Optional.of(list);
+ @Override
+ boolean validateResourceTypeSupportedForReqCreation(String nestedResourceId,
+ String nestedPropertyName,
+ String connectionPointId,
+ Resource connectedResource,
+ List<String> supportedTypes) {
+
+
+ if (resourceTranslationBase.isUnsupportedResourceType(connectedResource, supportedTypes)) {
+ logger.warn(LOG_UNSUPPORTED_VOL_ATTACHMENT_VOLUME_REQUIREMENT_CONNECTION, nestedResourceId,
+ nestedPropertyName, connectedResource.getType(), connectionPointId, supportedTypes.toString());
+ return false;
+ }
+
+ return true;
}
- }
- @Override
- Optional<String> getConnectionTranslatedNodeUsingGetParamFunc(
- Map.Entry<String, RequirementDefinition> requirementDefinitionEntry, String paramName,
- List<String> supportedTargetNodeTypes) {
+ @Override
+ protected Optional<List<Map.Entry<String, Resource>>> getResourceByTranslatedResourceId(
+ String translatedResourceId, HeatOrchestrationTemplate nestedHeatOrchestrationTemplate) {
+
+
+ List<Predicate<Map.Entry<String, Resource>>> predicates =
+ buildPredicates(nestedFileData.getFile(), nestedHeatOrchestrationTemplate,
+ translatedResourceId);
+ List<Map.Entry<String, Resource>> list =
+ nestedHeatOrchestrationTemplate.getResources().entrySet()
+ .stream()
+ .filter(entry -> predicates
+ .stream()
+ .allMatch(p -> p.test(entry)))
+ .collect(Collectors.toList());
+ if (CollectionUtils.isEmpty(list)) {
+ return Optional.empty();
+ } else {
+ return Optional.of(list);
+ }
+ }
+ @Override
+ Optional<String> getConnectionTranslatedNodeUsingGetParamFunc(
+ Map.Entry<String, RequirementDefinition> requirementDefinitionEntry, String paramName,
+ List<String> supportedTargetNodeTypes) {
- Optional<String> targetTranslatedNodeId = super
- .getConnectionTranslatedNodeUsingGetParamFunc(requirementDefinitionEntry, paramName,
- supportedTargetNodeTypes);
- if (targetTranslatedNodeId.isPresent()) {
- return targetTranslatedNodeId;
- } else {
- Optional<AttachedResourceId> attachedResourceId =
- HeatToToscaUtil.extractAttachedResourceId(translateTo, paramName);
- if (!attachedResourceId.isPresent()) {
- return Optional.empty();
- }
- AttachedResourceId resourceId = attachedResourceId.get();
- if (resourceId.isGetParam() && resourceId.getEntityId() instanceof String) {
- TranslatedHeatResource shareResource =
- translateTo.getContext().getHeatSharedResourcesByParam().get(resourceId.getEntityId());
- if (Objects.isNull(shareResource)) {
- List<FileData> allFilesData =
- translateTo.getContext().getManifest().getContent().getData();
- Optional<FileData> fileData =
- HeatToToscaUtil.getFileData(translateTo.getHeatFileName(), allFilesData);
- if (fileData.isPresent()) {
- Optional<ResourceFileDataAndIDs> fileDataContainingResource =
- new VolumeTranslationHelper(logger)
- .getFileDataContainingVolume(fileData.get().getData(),
- (String) resourceId.getEntityId(), translateTo, FileData.Type.HEAT_VOL);
- if (fileDataContainingResource.isPresent()) {
- return Optional.of(fileDataContainingResource.get().getTranslatedResourceId());
+ Optional<String> targetTranslatedNodeId = super
+ .getConnectionTranslatedNodeUsingGetParamFunc(requirementDefinitionEntry, paramName,
+ supportedTargetNodeTypes);
+ if (targetTranslatedNodeId.isPresent()) {
+ return targetTranslatedNodeId;
+ }
+ Optional<AttachedResourceId> attachedResourceId =
+ HeatToToscaUtil.extractAttachedResourceId(translateTo, paramName);
+ if (!attachedResourceId.isPresent()) {
+ return Optional.empty();
+ }
+ AttachedResourceId resourceId = attachedResourceId.get();
+ if (resourceId.isGetParam() && resourceId.getEntityId() instanceof String) {
+ TranslatedHeatResource shareResource =
+ translateTo.getContext().getHeatSharedResourcesByParam().get(resourceId.getEntityId());
+ if (Objects.nonNull(shareResource)) {
+ return Optional.empty();
+ }
+ List<FileData> allFilesData = translateTo.getContext().getManifest().getContent().getData();
+ Optional<FileData> fileData = HeatToToscaUtil.getFileData(translateTo.getHeatFileName(), allFilesData);
+ if (fileData.isPresent()) {
+ Optional<ResourceFileDataAndIDs> fileDataContainingResource = new VolumeTranslationHelper(logger)
+ .getFileDataContainingVolume(fileData.get().getData(),
+ (String) resourceId.getEntityId(), translateTo, FileData.Type.HEAT_VOL);
+ if (fileDataContainingResource.isPresent()) {
+ return Optional.of(fileDataContainingResource.get().getTranslatedResourceId());
+ }
}
- }
}
- }
- return Optional.empty();
+ return Optional.empty();
+ }
+
+ private List<Predicate<Map.Entry<String, Resource>>> buildPredicates(
+ String fileName,
+ HeatOrchestrationTemplate heatOrchestrationTemplate,
+ String novaTranslatedResourceId) {
+ List<Predicate<Map.Entry<String, Resource>>> list = new ArrayList<>();
+ list.add(entry -> entry.getValue().getType().equals(getDesiredResourceType()));
+ list.add(entry -> {
+ Object instanceUuidProp = entry.getValue().getProperties().get("instance_uuid");
+ TranslationContext context = translateTo.getContext();
+ Optional<AttachedResourceId> instanceUuid = HeatToToscaUtil
+ .extractAttachedResourceId(fileName, heatOrchestrationTemplate, context,
+ instanceUuidProp);
+ if (instanceUuid.isPresent()) {
+ Optional<String> resourceTranslatedId =
+ ResourceTranslationBase.getResourceTranslatedId(fileName, heatOrchestrationTemplate,
+ (String) instanceUuid.get().getTranslatedId(), context);
+ return resourceTranslatedId.isPresent()
+ && resourceTranslatedId.get().equals(novaTranslatedResourceId);
+
+ } else {
+ throw new CoreException(new MissingMandatoryPropertyErrorBuilder("instance_uuid").build());
+ }
+ });
+ return list;
}
- }
-
- private List<Predicate<Map.Entry<String, Resource>>> buildPredicates(
- String fileName,
- HeatOrchestrationTemplate heatOrchestrationTemplate,
- String novaTranslatedResourceId) {
- List<Predicate<Map.Entry<String, Resource>>> list = new ArrayList<>();
- list.add(entry -> entry.getValue().getType().equals(getDesiredResourceType()));
- list.add(entry -> {
- Object instanceUuidProp = entry.getValue().getProperties().get("instance_uuid");
- TranslationContext context = translateTo.getContext();
- Optional<AttachedResourceId> instanceUuid = HeatToToscaUtil
- .extractAttachedResourceId(fileName, heatOrchestrationTemplate, context,
- instanceUuidProp);
- if (instanceUuid.isPresent()) {
- Optional<String> resourceTranslatedId =
- ResourceTranslationBase.getResourceTranslatedId(fileName, heatOrchestrationTemplate,
- (String) instanceUuid.get().getTranslatedId(), context);
- return resourceTranslatedId.isPresent()
- && resourceTranslatedId.get().equals(novaTranslatedResourceId);
-
- } else {
- throw new CoreException(new MissingMandatoryPropertyErrorBuilder("instance_uuid").build());
- }
- });
- return list;
- }
}
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/PortToNetResourceConnection.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/PortToNetResourceConnection.java
index 4a9cd92329..bcdc8aaf4d 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/PortToNetResourceConnection.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/PortToNetResourceConnection.java
@@ -1,138 +1,134 @@
-/*-
- * ============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_UNSUPPORTED_PORT_NETWORK_REQUIREMENT_CONNECTION;
+
+import com.google.common.collect.ImmutableList;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.function.Predicate;
+
+import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
+import org.onap.sdc.tosca.datatypes.model.NodeType;
+import org.onap.sdc.tosca.datatypes.model.RequirementDefinition;
import org.openecomp.sdc.heat.datatypes.manifest.FileData;
import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate;
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.NodeType;
-import org.onap.sdc.tosca.datatypes.model.RequirementDefinition;
import org.openecomp.sdc.translator.datatypes.heattotosca.AttachedResourceId;
import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo;
import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.function.Predicate;
-
public class PortToNetResourceConnection extends ResourceConnectionUsingRequirementHelper {
- public PortToNetResourceConnection(ResourceTranslationBase resourceTranslationBase,
- TranslateTo translateTo, FileData nestedFileData,
- NodeTemplate substitutionNodeTemplate, NodeType nodeType) {
- super(resourceTranslationBase, translateTo, nestedFileData, substitutionNodeTemplate, nodeType);
- }
-
- @Override
- protected boolean isDesiredNodeTemplateType(NodeTemplate nodeTemplate) {
- return nodeTemplate.getType().equals(ToscaNodeType.NEUTRON_PORT);
- }
-
- @Override
- protected List<Predicate<RequirementDefinition>> getPredicatesListForConnectionPoints() {
- ArrayList<Predicate<RequirementDefinition>> predicates = new ArrayList<>();
- predicates.add(
- req -> req.getCapability().equals(ToscaCapabilityType.NATIVE_NETWORK_LINKABLE)
- && (req.getNode() == null || req.getNode().equals(ToscaNodeType.NATIVE_ROOT))
- && req.getRelationship().equals(
- ToscaRelationshipType.NATIVE_NETWORK_LINK_TO));
- return predicates;
- }
-
- @Override
- protected Optional<List<String>> getConnectorPropertyParamName(String heatResourceId,
- Resource heatResource,
- HeatOrchestrationTemplate
- nestedHeatOrchestrationTemplate,
- String nestedHeatFileName) {
- Optional<AttachedResourceId> network = HeatToToscaUtil
- .extractAttachedResourceId(nestedHeatFileName, nestedHeatOrchestrationTemplate,
- translateTo.getContext(), heatResource.getProperties().get("network"));
- if (network.isPresent() && network.get().isGetParam()
- && network.get().getEntityId() instanceof String) {
- return Optional.of(Collections.singletonList((String) network.get().getEntityId()));
- } else {
- network = HeatToToscaUtil
- .extractAttachedResourceId(nestedHeatFileName, nestedHeatOrchestrationTemplate,
- translateTo.getContext(), heatResource.getProperties().get("network_id"));
- if (network.isPresent()
- && network.get().isGetParam()
- && network.get().getEntityId() instanceof String) {
- return Optional.of(Collections.singletonList((String) network.get().getEntityId()));
- } else {
- return Optional.empty();
- }
+ PortToNetResourceConnection(ResourceTranslationBase resourceTranslationBase,
+ TranslateTo translateTo, FileData nestedFileData,
+ NodeTemplate substitutionNodeTemplate, NodeType nodeType) {
+ super(resourceTranslationBase, translateTo, nestedFileData, substitutionNodeTemplate, nodeType);
+ }
+
+ @Override
+ protected boolean isDesiredNodeTemplateType(NodeTemplate nodeTemplate) {
+ return nodeTemplate.getType().equals(ToscaNodeType.NEUTRON_PORT);
+ }
+
+ @Override
+ protected List<Predicate<RequirementDefinition>> getPredicatesListForConnectionPoints() {
+ ArrayList<Predicate<RequirementDefinition>> predicates = new ArrayList<>();
+ predicates.add(
+ req -> req.getCapability().equals(ToscaCapabilityType.NATIVE_NETWORK_LINKABLE)
+ && (req.getNode() == null || req.getNode().equals(ToscaNodeType.NATIVE_ROOT))
+ && req.getRelationship().equals(
+ ToscaRelationshipType.NATIVE_NETWORK_LINK_TO));
+ return predicates;
+ }
+
+ @Override
+ protected Optional<List<String>> getConnectorPropertyParamName(String heatResourceId,
+ Resource heatResource,
+ HeatOrchestrationTemplate
+ nestedHeatOrchestrationTemplate,
+ String nestedHeatFileName) {
+ Optional<AttachedResourceId> network = HeatToToscaUtil
+ .extractAttachedResourceId(nestedHeatFileName, nestedHeatOrchestrationTemplate, translateTo
+ .getContext(), heatResource.getProperties().get(HeatConstants.NETWORK_PROPERTY_NAME));
+ if (network.isPresent() && network.get().isGetParam()
+ && network.get().getEntityId() instanceof String) {
+ return Optional.of(Collections.singletonList((String) network.get().getEntityId()));
+ } else {
+ network = HeatToToscaUtil
+ .extractAttachedResourceId(nestedHeatFileName, nestedHeatOrchestrationTemplate, translateTo
+ .getContext(), heatResource.getProperties().get(HeatConstants.NETWORK_ID_PROPERTY_NAME));
+ if (network.isPresent()
+ && network.get().isGetParam()
+ && network.get().getEntityId() instanceof String) {
+ return Optional.of(Collections.singletonList((String) network.get().getEntityId()));
+ } else {
+ return Optional.empty();
+ }
+ }
+ }
+
+ @Override
+ protected String getDesiredResourceType() {
+ return HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource();
}
- }
-
- @Override
- protected String getDesiredResourceType() {
- return HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource();
- }
-
- @Override
- protected void addRequirementToConnectResources(
- Map.Entry<String, RequirementDefinition> requirementDefinitionEntry,
- List<String> paramNames) {
- if (paramNames == null || paramNames.isEmpty()) {
- return;
+
+ @Override
+ protected void addRequirementToConnectResources(
+ Map.Entry<String, RequirementDefinition> requirementDefinitionEntry,
+ List<String> paramNames) {
+ if (paramNames == null || paramNames.isEmpty()) {
+ return;
+ }
+ String paramName = paramNames.get(0); // port can connect to one network only and we are
+ // expecting to have only one param(unlike security rules to port)
+ Object paramValue = translateTo.getResource().getProperties().get(paramName);
+ List<String> supportedNetworkTypes = ImmutableList.of(
+ HeatResourcesTypes.NEUTRON_NET_RESOURCE_TYPE.getHeatResource(),
+ HeatResourcesTypes.CONTRAIL_VIRTUAL_NETWORK_RESOURCE_TYPE.getHeatResource(),
+ HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_NETWORK_RESOURCE_TYPE.getHeatResource());
+
+ addRequirementToConnectResource(requirementDefinitionEntry, paramName, paramValue,
+ supportedNetworkTypes);
}
- String paramName = paramNames.get(
- 0); // port can connect to one network only and we are
- // expecting to have only one param(unlike security rules to port)
- Object paramValue = translateTo.getResource().getProperties().get(paramName);
- 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());
-
- addRequirementToConnectResource(requirementDefinitionEntry, paramName, paramValue,
- supportedNetworkTypes);
- }
-
- @Override
- boolean validateResourceTypeSupportedForReqCreation(String nestedResourceId,
- final String nestedPropertyName,
- String connectionPointId,
- Resource connectedResource,
- List<String> supportedTypes) {
- if (!resourceTranslationBase.isResourceTypeSupported(connectedResource, supportedTypes)) {
- logger.warn("Nested resource '" + nestedResourceId + "' property '" + nestedPropertyName
- + "' is pointing to a resource with type '" + connectedResource.getType()
- + "' which is not supported for requirement '" + connectionPointId
- + "' that connect port to network. Supported types are: '" + supportedTypes.toString()
- + "', therefore, this TOSCA requirement will not be connected.");
- return false;
+
+ @Override
+ boolean validateResourceTypeSupportedForReqCreation(String nestedResourceId,
+ final String nestedPropertyName,
+ String connectionPointId,
+ Resource connectedResource,
+ List<String> supportedTypes) {
+ if (resourceTranslationBase.isUnsupportedResourceType(connectedResource, supportedTypes)) {
+ logger.warn(LOG_UNSUPPORTED_PORT_NETWORK_REQUIREMENT_CONNECTION, nestedResourceId,
+ nestedPropertyName, connectedResource.getType(), connectionPointId, supportedTypes.toString());
+ return false;
+ }
+ return true;
}
- return true;
- }
}
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/ResourceConnectionUsingCapabilityHelper.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceConnectionUsingCapabilityHelper.java
index 15af3c0771..b5ef95e5d0 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceConnectionUsingCapabilityHelper.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceConnectionUsingCapabilityHelper.java
@@ -1,183 +1,180 @@
-/*-
- * ============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.heat.datatypes.manifest.FileData;
-import org.openecomp.sdc.heat.datatypes.model.Resource;
+import static org.openecomp.sdc.translator.services.heattotosca.HeatToToscaLogConstants.LOG_NESTED_RESOURCE_PROPERTY_NOT_DEFINED;
+import static org.openecomp.sdc.translator.services.heattotosca.HeatToToscaLogConstants.LOG_UNSUPPORTED_CAPABILITY_CONNECTION;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.function.Predicate;
+
import org.onap.sdc.tosca.datatypes.model.CapabilityDefinition;
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.RequirementDefinition;
import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
+import org.openecomp.sdc.heat.datatypes.manifest.FileData;
+import org.openecomp.sdc.heat.datatypes.model.Resource;
import org.openecomp.sdc.tosca.services.DataModelUtil;
+import org.openecomp.sdc.tosca.services.ToscaConstants;
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.HeatToToscaUtil;
import org.openecomp.sdc.translator.services.heattotosca.ResourceTranslationFactory;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.function.Predicate;
+public abstract class ResourceConnectionUsingCapabilityHelper extends BaseResourceConnection<CapabilityDefinition> {
+
+ ResourceConnectionUsingCapabilityHelper(ResourceTranslationBase resourceTranslationBase,
+ TranslateTo translateTo, FileData nestedFileData,
+ NodeTemplate substitutionNodeTemplate,
+ NodeType nodeType) {
+ super(resourceTranslationBase, translateTo, nestedFileData, substitutionNodeTemplate, nodeType);
+ }
+
+ abstract Map.Entry<String, RequirementDefinition> createRequirementDefinition(
+ String capabilityKey);
+
+ @Override
+ String getMappedNodeTranslatedResourceId(ServiceTemplate nestedServiceTemplate,
+ Map.Entry<String,
+ CapabilityDefinition> connectionPointEntry) {
+ List<String> substitutionMapping =
+ nestedServiceTemplate.getTopology_template().getSubstitution_mappings().getCapabilities()
+ .get(connectionPointEntry.getKey());
+ return substitutionMapping.get(0);
+ }
+
+ @Override
+ Map.Entry<String, CapabilityDefinition> getMappedConnectionPointEntry(
+ ServiceTemplate nestedServiceTemplate,
+ Map.Entry<String, CapabilityDefinition> connectionPointEntry) {
+ List<String> substitutionMapping =
+ nestedServiceTemplate.getTopology_template().getSubstitution_mappings().getCapabilities()
+ .get(connectionPointEntry.getKey());
+ String mappedNodeTranslatedId = substitutionMapping.get(0);
+ String mappedCapabilityId = substitutionMapping.get(1);
+ NodeTemplate mappedNodeTemplate =
+ nestedServiceTemplate.getTopology_template().getNode_templates()
+ .get(mappedNodeTranslatedId);
+ NodeType substituteNodeType =
+ translateTo.getContext().getGlobalSubstitutionServiceTemplate().getNode_types()
+ .get(mappedNodeTemplate.getType());
+ Optional<CapabilityDefinition> capabilityDefinition =
+ DataModelUtil.getCapabilityDefinition(substituteNodeType, mappedCapabilityId);
+ return new Map.Entry<String, CapabilityDefinition>() {
+ @Override
+ public String getKey() {
+ return mappedCapabilityId;
+ }
-public abstract class ResourceConnectionUsingCapabilityHelper
- extends BaseResourceConnection<CapabilityDefinition> {
- public ResourceConnectionUsingCapabilityHelper(ResourceTranslationBase resourceTranslationBase,
- TranslateTo translateTo, FileData nestedFileData,
- NodeTemplate substitutionNodeTemplate,
- NodeType nodeType) {
- super(resourceTranslationBase, translateTo, nestedFileData, substitutionNodeTemplate, nodeType);
- }
-
- abstract Map.Entry<String, RequirementDefinition> createRequirementDefinition(
- String capabilityKey);
-
- @Override
- String getMappedNodeTranslatedResourceId(ServiceTemplate nestedServiceTemplate,
- Map.Entry<String,
- CapabilityDefinition> connectionPointEntry) {
- List<String> substitutionMapping =
- nestedServiceTemplate.getTopology_template().getSubstitution_mappings().getCapabilities()
- .get(connectionPointEntry.getKey());
- return substitutionMapping.get(0);
- }
-
- @Override
- Map.Entry<String, CapabilityDefinition> getMappedConnectionPointEntry(
- ServiceTemplate nestedServiceTemplate,
- Map.Entry<String, CapabilityDefinition> connectionPointEntry) {
- List<String> substitutionMapping =
- nestedServiceTemplate.getTopology_template().getSubstitution_mappings().getCapabilities()
- .get(connectionPointEntry.getKey());
- String mappedNodeTranslatedId = substitutionMapping.get(0);
- String mappedCapabilityId = substitutionMapping.get(1);
- NodeTemplate mappedNodeTemplate =
- nestedServiceTemplate.getTopology_template().getNode_templates()
- .get(mappedNodeTranslatedId);
- NodeType substituteNodeType =
- translateTo.getContext().getGlobalSubstitutionServiceTemplate().getNode_types()
- .get(mappedNodeTemplate.getType());
- Optional<CapabilityDefinition> capabilityDefinition =
- DataModelUtil.getCapabilityDefinition(substituteNodeType, mappedCapabilityId);
- return new Map.Entry<String, CapabilityDefinition>() {
- @Override
- public String getKey() {
- return mappedCapabilityId;
- }
-
- @Override
- public CapabilityDefinition getValue() {
- return capabilityDefinition.get();
- }
-
- @Override
- public CapabilityDefinition setValue(CapabilityDefinition value) {
- return null;
- }
- };
- }
-
- @Override
- protected List<Map<String, CapabilityDefinition>> getAllConnectionPoints() {
- List<Map<String, CapabilityDefinition>> exposedRequirementsList = new ArrayList<>();
- List<Predicate<CapabilityDefinition>> predicates = getPredicatesListForConnectionPoints();
- Map<String, CapabilityDefinition> capabilities = this.nodeType.getCapabilities();
- if (capabilities == null) {
- return exposedRequirementsList;
+ @Override
+ public CapabilityDefinition getValue() {
+ return capabilityDefinition.orElse(null);
+ }
+
+ @Override
+ public CapabilityDefinition setValue(CapabilityDefinition value) {
+ return null;
+ }
+ };
}
- capabilities.entrySet()
- .stream()
- .filter(entry -> predicates
- .stream()
- .anyMatch(p -> p.test(entry.getValue())))
- .forEach(entry -> {
- Map<String, CapabilityDefinition> exposedRequirementsMap = new HashMap<>();
- exposedRequirementsMap.put(entry.getKey(), entry.getValue());
- exposedRequirementsList.add(exposedRequirementsMap);
- });
- return exposedRequirementsList;
- }
-
- void addRequirementToConnectResource(Map.Entry<String, CapabilityDefinition> connectionPointEntry,
- List<String> supportedSourceNodeTypes, String paramName) {
- Object paramValue = translateTo.getResource().getProperties().get(paramName);
- if (paramValue == null) {
- logger.warn("'" + paramName + "' property is not define in nested resource '"
- + translateTo.getResourceId() + "' for the nested heat file, therefore, '"
- + connectionPointEntry.getKey() + "' TOSCA capability will not be connected.");
- return;
+
+ @Override
+ protected List<Map<String, CapabilityDefinition>> getAllConnectionPoints() {
+ List<Map<String, CapabilityDefinition>> exposedRequirementsList = new ArrayList<>();
+ List<Predicate<CapabilityDefinition>> predicates = getPredicatesListForConnectionPoints();
+ Map<String, CapabilityDefinition> capabilities = this.nodeType.getCapabilities();
+ if (capabilities == null) {
+ return exposedRequirementsList;
+ }
+ capabilities.entrySet()
+ .stream()
+ .filter(entry -> predicates
+ .stream()
+ .anyMatch(p -> p.test(entry.getValue())))
+ .forEach(entry -> {
+ Map<String, CapabilityDefinition> exposedRequirementsMap = new HashMap<>();
+ exposedRequirementsMap.put(entry.getKey(), entry.getValue());
+ exposedRequirementsList.add(exposedRequirementsMap);
+ });
+ return exposedRequirementsList;
}
- Map.Entry<String, RequirementDefinition> requirementDefinition =
- createRequirementDefinition(connectionPointEntry.getKey());
-
- Optional<String> sourceResourceId =
- getConnectionResourceUsingGetResourceFunc(connectionPointEntry, paramName, paramValue,
- supportedSourceNodeTypes);
- if (sourceResourceId.isPresent()) {
- Resource sourceResource = HeatToToscaUtil
- .getResource(translateTo.getHeatOrchestrationTemplate(), sourceResourceId.get(),
- translateTo.getHeatFileName());
- Optional<String> translatedSourceNodeId =
- ResourceTranslationFactory.getInstance(sourceResource)
- .translateResource(translateTo.getHeatFileName(), translateTo.getServiceTemplate(),
- translateTo.getHeatOrchestrationTemplate(), sourceResource,
- sourceResourceId.get(), translateTo.getContext());
- if (translatedSourceNodeId.isPresent()) {
- NodeTemplate sourceNodeTemplate = DataModelUtil
- .getNodeTemplate(translateTo.getServiceTemplate(), translatedSourceNodeId.get());
- RequirementAssignment requirementAssignment = createRequirementAssignment(
- requirementDefinition, translateTo.getTranslatedId(), sourceNodeTemplate);
- ConsolidationDataUtil.updateNodesConnectedData(translateTo, translateTo.getResourceId(),
- translateTo.getResource(), sourceResource, translatedSourceNodeId.get(),
- requirementDefinition.getKey(), requirementAssignment);
- } else {
- logger.warn(
- "'" + sourceResource.getType() + "' connection to '" + connectionPointEntry.getKey()
- + "' capability of type '" + connectionPointEntry.getValue().getType()
- + "' is not supported/invalid, therefore this connection will be ignored in the "
- + "TOSCA translation");
- }
- } else {
- Optional<TranslatedHeatResource> sharedSourceTranslatedHeatResource =
- getConnectionTranslatedHeatResourceUsingGetParamFunc(connectionPointEntry, paramName,
- supportedSourceNodeTypes);
- if (sharedSourceTranslatedHeatResource.isPresent()) {
- NodeTemplate sharedSourceNodeTemplate = DataModelUtil
- .getNodeTemplate(translateTo.getServiceTemplate(),
- sharedSourceTranslatedHeatResource.get().getTranslatedId());
- RequirementAssignment requirementAssignment = createRequirementAssignment(
- requirementDefinition, translateTo.getTranslatedId(), sharedSourceNodeTemplate);
-
- ConsolidationDataUtil.updateNodesConnectedData(translateTo, translateTo.getResourceId(),
- translateTo.getResource(), sharedSourceTranslatedHeatResource.get().getHeatResource(),
- sharedSourceTranslatedHeatResource.get().getTranslatedId(),
- requirementDefinition.getKey(),
- requirementAssignment);
- }
+ void addRequirementToConnectResource(Map.Entry<String, CapabilityDefinition> connectionPointEntry,
+ List<String> supportedSourceNodeTypes, String paramName) {
+ Object paramValue = translateTo.getResource().getProperties().get(paramName);
+ if (paramValue == null) {
+ logger.warn(LOG_NESTED_RESOURCE_PROPERTY_NOT_DEFINED, paramName,
+ translateTo.getResourceId(), connectionPointEntry.getKey(), ToscaConstants.CAPABILITY);
+ return;
+ }
+
+ Map.Entry<String, RequirementDefinition> requirementDefinition =
+ createRequirementDefinition(connectionPointEntry.getKey());
+
+ Optional<String> sourceResourceId =
+ getConnectionResourceUsingGetResourceFunc(connectionPointEntry, paramName, paramValue,
+ supportedSourceNodeTypes);
+ if (sourceResourceId.isPresent()) {
+ Resource sourceResource = HeatToToscaUtil
+ .getResource(translateTo.getHeatOrchestrationTemplate(), sourceResourceId.get(),
+ translateTo.getHeatFileName());
+ Optional<String> translatedSourceNodeId =
+ ResourceTranslationFactory.getInstance(sourceResource)
+ .translateResource(translateTo.getHeatFileName(), translateTo.getServiceTemplate(),
+ translateTo.getHeatOrchestrationTemplate(), sourceResource,
+ sourceResourceId.get(), translateTo.getContext());
+ if (translatedSourceNodeId.isPresent()) {
+ NodeTemplate sourceNodeTemplate = DataModelUtil
+ .getNodeTemplate(translateTo.getServiceTemplate(), translatedSourceNodeId.get());
+ RequirementAssignment requirementAssignment = createRequirementAssignment(
+ requirementDefinition, translateTo.getTranslatedId(), sourceNodeTemplate);
+ ConsolidationDataUtil.updateNodesConnectedData(translateTo, translateTo.getResourceId(),
+ translateTo.getResource(), sourceResource, translatedSourceNodeId.get(),
+ requirementDefinition.getKey(), requirementAssignment);
+ } else {
+ logger.warn(LOG_UNSUPPORTED_CAPABILITY_CONNECTION, sourceResource.getType(),
+ connectionPointEntry.getKey(),
+ connectionPointEntry.getValue().getType());
+ }
+ } else {
+ Optional<TranslatedHeatResource> sharedSourceTranslatedHeatResource =
+ getConnectionTranslatedHeatResourceUsingGetParamFunc(connectionPointEntry, paramName,
+ supportedSourceNodeTypes);
+ if (sharedSourceTranslatedHeatResource.isPresent()) {
+ NodeTemplate sharedSourceNodeTemplate = DataModelUtil
+ .getNodeTemplate(translateTo.getServiceTemplate(),
+ sharedSourceTranslatedHeatResource.get().getTranslatedId());
+ RequirementAssignment requirementAssignment = createRequirementAssignment(
+ requirementDefinition, translateTo.getTranslatedId(), sharedSourceNodeTemplate);
+
+ ConsolidationDataUtil.updateNodesConnectedData(translateTo, translateTo.getResourceId(),
+ translateTo.getResource(), sharedSourceTranslatedHeatResource.get().getHeatResource(),
+ sharedSourceTranslatedHeatResource.get().getTranslatedId(),
+ requirementDefinition.getKey(),
+ requirementAssignment);
+ }
+ }
}
- }
}
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/ResourceConnectionUsingRequirementHelper.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceConnectionUsingRequirementHelper.java
index ff6521c4fe..729578ef60 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceConnectionUsingRequirementHelper.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceConnectionUsingRequirementHelper.java
@@ -1,32 +1,22 @@
-/*-
- * ============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.heat.datatypes.manifest.FileData;
-import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
-import org.onap.sdc.tosca.datatypes.model.NodeType;
-import org.onap.sdc.tosca.datatypes.model.RequirementDefinition;
-import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
-import org.openecomp.sdc.tosca.services.DataModelUtil;
-import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo;
+import static org.openecomp.sdc.translator.services.heattotosca.HeatToToscaLogConstants.LOG_NESTED_RESOURCE_PROPERTY_NOT_DEFINED;
import java.util.ArrayList;
import java.util.HashMap;
@@ -35,104 +25,111 @@ import java.util.Map;
import java.util.Optional;
import java.util.function.Predicate;
-public abstract class ResourceConnectionUsingRequirementHelper
- extends BaseResourceConnection<RequirementDefinition> {
- public ResourceConnectionUsingRequirementHelper(ResourceTranslationBase resourceTranslationBase,
- TranslateTo translateTo, FileData nestedFileData,
- NodeTemplate substitutionNodeTemplate,
- NodeType nodeType) {
- super(resourceTranslationBase, translateTo, nestedFileData, substitutionNodeTemplate, nodeType);
- }
+import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
+import org.onap.sdc.tosca.datatypes.model.NodeType;
+import org.onap.sdc.tosca.datatypes.model.RequirementDefinition;
+import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
+import org.openecomp.sdc.heat.datatypes.manifest.FileData;
+import org.openecomp.sdc.tosca.services.DataModelUtil;
+import org.openecomp.sdc.tosca.services.ToscaConstants;
+import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo;
- @Override
- String getMappedNodeTranslatedResourceId(ServiceTemplate nestedServiceTemplate,
- Map.Entry<String,
- RequirementDefinition> connectionPointEntry) {
- List<String> substitutionMapping =
- nestedServiceTemplate.getTopology_template().getSubstitution_mappings().getRequirements()
- .get(connectionPointEntry.getKey());
- return substitutionMapping.get(0);
- }
+abstract class ResourceConnectionUsingRequirementHelper extends BaseResourceConnection<RequirementDefinition> {
+ ResourceConnectionUsingRequirementHelper(ResourceTranslationBase resourceTranslationBase,
+ TranslateTo translateTo, FileData nestedFileData,
+ NodeTemplate substitutionNodeTemplate,
+ NodeType nodeType) {
+ super(resourceTranslationBase, translateTo, nestedFileData, substitutionNodeTemplate, nodeType);
+ }
- @Override
- Map.Entry<String, RequirementDefinition> getMappedConnectionPointEntry(
- ServiceTemplate nestedServiceTemplate,
- Map.Entry<String, RequirementDefinition> connectionPointEntry) {
- List<String> substitutionMapping =
- nestedServiceTemplate.getTopology_template().getSubstitution_mappings().getRequirements()
- .get(connectionPointEntry.getKey());
- String mappedNodeTranslatedId = substitutionMapping.get(0);
- String mappedReqId = substitutionMapping.get(1);
- NodeTemplate mappedNodeTemplate =
- nestedServiceTemplate.getTopology_template().getNode_templates()
- .get(mappedNodeTranslatedId);
- NodeType substituteNodeType =
- translateTo.getContext().getGlobalSubstitutionServiceTemplate().getNode_types()
- .get(mappedNodeTemplate.getType());
- Optional<RequirementDefinition> requirementDefinition =
- DataModelUtil.getRequirementDefinition(substituteNodeType, mappedReqId);
- return new Map.Entry<String, RequirementDefinition>() {
- @Override
- public String getKey() {
- return mappedReqId;
- }
+ @Override
+ String getMappedNodeTranslatedResourceId(ServiceTemplate nestedServiceTemplate,
+ Map.Entry<String,
+ RequirementDefinition> connectionPointEntry) {
+ List<String> substitutionMapping =
+ nestedServiceTemplate.getTopology_template().getSubstitution_mappings().getRequirements()
+ .get(connectionPointEntry.getKey());
+ return substitutionMapping.get(0);
+ }
- @Override
- public RequirementDefinition getValue() {
- return requirementDefinition.get();
- }
+ @Override
+ Map.Entry<String, RequirementDefinition> getMappedConnectionPointEntry(
+ ServiceTemplate nestedServiceTemplate,
+ Map.Entry<String, RequirementDefinition> connectionPointEntry) {
+ List<String> substitutionMapping =
+ nestedServiceTemplate.getTopology_template().getSubstitution_mappings().getRequirements()
+ .get(connectionPointEntry.getKey());
+ String mappedNodeTranslatedId = substitutionMapping.get(0);
+ String mappedReqId = substitutionMapping.get(1);
+ NodeTemplate mappedNodeTemplate =
+ nestedServiceTemplate.getTopology_template().getNode_templates()
+ .get(mappedNodeTranslatedId);
+ NodeType substituteNodeType =
+ translateTo.getContext().getGlobalSubstitutionServiceTemplate().getNode_types()
+ .get(mappedNodeTemplate.getType());
+ Optional<RequirementDefinition> requirementDefinition =
+ DataModelUtil.getRequirementDefinition(substituteNodeType, mappedReqId);
+ return new Map.Entry<String, RequirementDefinition>() {
+ @Override
+ public String getKey() {
+ return mappedReqId;
+ }
- @Override
- public RequirementDefinition setValue(RequirementDefinition value) {
- return null;
- }
- };
- }
+ @Override
+ public RequirementDefinition getValue() {
+ return requirementDefinition.orElse(null);
+ }
- @Override
- List<Map<String, RequirementDefinition>> getAllConnectionPoints() {
- List<Map<String, RequirementDefinition>> exposedRequirementsList = new ArrayList<>();
- List<Predicate<RequirementDefinition>> predicates = getPredicatesListForConnectionPoints();
- List<Map<String, RequirementDefinition>> requirements = this.nodeType.getRequirements();
- if (requirements == null) {
- return exposedRequirementsList;
+ @Override
+ public RequirementDefinition setValue(RequirementDefinition value) {
+ return null;
+ }
+ };
}
- requirements.stream()
- .map(Map::entrySet)
- .forEach(x -> x.stream()
- .filter(entry -> predicates
- .stream()
- .anyMatch(p -> p.test(entry.getValue())))
- .forEach(entry -> {
- Map<String, RequirementDefinition> exposedRequirementsMap = new HashMap<>();
- exposedRequirementsMap.put(entry.getKey(), entry.getValue());
- exposedRequirementsList.add(exposedRequirementsMap);
- }));
- return exposedRequirementsList;
- }
- void addRequirementToConnectResource(
- Map.Entry<String, RequirementDefinition> requirementDefinitionEntry, String paramName,
- Object paramValue, List<String> supportedNetworkTypes) {
- if (paramValue == null) {
- logger.warn("'" + paramName + "' property is not define in nested resource '"
- + translateTo.getResourceId() + "' for the nested heat file, therefore, '"
- + requirementDefinitionEntry.getKey() + "' TOSCA requirement will not be connected.");
- return;
+ @Override
+ List<Map<String, RequirementDefinition>> getAllConnectionPoints() {
+ List<Map<String, RequirementDefinition>> exposedRequirementsList = new ArrayList<>();
+ List<Predicate<RequirementDefinition>> predicates = getPredicatesListForConnectionPoints();
+ List<Map<String, RequirementDefinition>> requirements = this.nodeType.getRequirements();
+ if (requirements == null) {
+ return exposedRequirementsList;
+ }
+ requirements.stream()
+ .map(Map::entrySet)
+ .forEach(x -> x.stream()
+ .filter(entry -> predicates
+ .stream()
+ .anyMatch(p -> p.test(entry.getValue())))
+ .forEach(entry -> {
+ Map<String, RequirementDefinition> exposedRequirementsMap = new HashMap<>();
+ exposedRequirementsMap.put(entry.getKey(), entry.getValue());
+ exposedRequirementsList.add(exposedRequirementsMap);
+ }));
+ return exposedRequirementsList;
}
- Optional<String> targetTranslatedNodeId =
- getConnectionTranslatedNodeUsingGetResourceFunc(requirementDefinitionEntry, paramName,
- paramValue, supportedNetworkTypes);
- if (targetTranslatedNodeId.isPresent()) {
- createRequirementAssignment(requirementDefinitionEntry, targetTranslatedNodeId.get(),
- substitutionNodeTemplate);
- } else {
- targetTranslatedNodeId =
- getConnectionTranslatedNodeUsingGetParamFunc(requirementDefinitionEntry, paramName,
- supportedNetworkTypes);
- targetTranslatedNodeId
- .ifPresent(targetTranslatedId -> createRequirementAssignment(requirementDefinitionEntry,
- targetTranslatedId, substitutionNodeTemplate));
+
+ void addRequirementToConnectResource(
+ Map.Entry<String, RequirementDefinition> requirementDefinitionEntry, String paramName,
+ Object paramValue, List<String> supportedNetworkTypes) {
+ if (paramValue == null) {
+ logger.warn(LOG_NESTED_RESOURCE_PROPERTY_NOT_DEFINED, paramName, translateTo.getResourceId(),
+ requirementDefinitionEntry.getKey(), ToscaConstants.REQUIREMENT);
+ return;
+ }
+ Optional<String> targetTranslatedNodeId =
+ getConnectionTranslatedNodeUsingGetResourceFunc(requirementDefinitionEntry, paramName,
+ paramValue, supportedNetworkTypes);
+ if (targetTranslatedNodeId.isPresent()) {
+ createRequirementAssignment(requirementDefinitionEntry, targetTranslatedNodeId.get(),
+ substitutionNodeTemplate);
+ } else {
+ targetTranslatedNodeId =
+ getConnectionTranslatedNodeUsingGetParamFunc(requirementDefinitionEntry, paramName,
+ supportedNetworkTypes);
+ targetTranslatedNodeId
+ .ifPresent(targetTranslatedId -> createRequirementAssignment(requirementDefinitionEntry,
+ targetTranslatedId, substitutionNodeTemplate));
+ }
}
- }
}
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/ResourceTranslationBase.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationBase.java
index f93d3714ca..a19075f050 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationBase.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationBase.java
@@ -16,15 +16,26 @@
package org.openecomp.sdc.translator.services.heattotosca.impl.resourcetranslation;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+
import org.apache.commons.collections4.CollectionUtils;
+import org.onap.sdc.tosca.datatypes.model.RequirementAssignment;
+import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
import org.openecomp.sdc.common.errors.CoreException;
import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate;
import org.openecomp.sdc.heat.datatypes.model.Resource;
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.RequirementAssignment;
-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;
@@ -38,303 +49,285 @@ import org.openecomp.sdc.translator.services.heattotosca.errors.ResourceNotFound
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.Set;
-import java.util.function.Predicate;
-import java.util.stream.Collectors;
-
public abstract class ResourceTranslationBase {
- protected static Logger logger = LoggerFactory.getLogger(ResourceTranslationBase.class);
- protected abstract void translate(TranslateTo translateTo);
-
- /**
- * Translate resource.
- *
- * @param heatFileName the heat file name
- * @param serviceTemplate the service template
- * @param heatOrchestrationTemplate the heat orchestration template
- * @param resource the resource
- * @param resourceId the resource id
- * @param context the context
- * @return the translated id if this resource is supported, or empty value if not supported
- */
- public Optional<String> translateResource(String heatFileName, ServiceTemplate serviceTemplate,
- HeatOrchestrationTemplate heatOrchestrationTemplate,
- Resource resource, String resourceId,
- TranslationContext context) {
- Optional<String> translatedId =
- getResourceTranslatedId(heatFileName, heatOrchestrationTemplate, resourceId, context);
- context.getTranslatedResources().putIfAbsent(heatFileName, new HashSet<>());
-
- if (isResourceWithSameIdAppearsInOtherFiles(heatFileName, resourceId, context)) {
- throw new CoreException(
- new DuplicateResourceIdsInDifferentFilesErrorBuilder(resourceId).build());
- }
- if (context.getTranslatedResources().get(heatFileName).contains(resourceId)) {
- return translatedId;
+ protected static Logger logger = LoggerFactory.getLogger(ResourceTranslationBase.class);
+
+ /**
+ * Gets resource translated id.
+ *
+ * @param heatFileName the heat file name
+ * @param heatOrchestrationTemplate the heat orchestration template
+ * @param resourceId the resource id
+ * @param context the context
+ * @return the resource translated id
+ */
+ public static Optional<String> getResourceTranslatedId(String heatFileName,
+ HeatOrchestrationTemplate
+ heatOrchestrationTemplate,
+ String resourceId,
+ TranslationContext context) {
+ if (!context.getTranslatedIds().containsKey(heatFileName)) {
+ context.getTranslatedIds().put(heatFileName, new HashMap<>());
+ }
+
+ Map<String, String> translatedIdsPerFile = context.getTranslatedIds().get(heatFileName);
+ String translatedId = translatedIdsPerFile.get(resourceId);
+ if (translatedId != null) {
+ return Optional.of(translatedId);
+ }
+
+ Resource resource = heatOrchestrationTemplate.getResources().get(resourceId);
+ if (resource == null) {
+ throw new CoreException(
+ new ResourceNotFoundInHeatFileErrorBuilder(resourceId, heatFileName).build());
+ }
+ return getTranslatedResourceId(resourceId, heatFileName, resource, heatOrchestrationTemplate,
+ context
+ );
}
- if (!translatedId.isPresent()) {
- return Optional.empty();
+
+ private static Optional<String> getTranslatedResourceId(String resourceId,
+ String heatFileName,
+ Resource resource,
+ HeatOrchestrationTemplate heatOrchestrationTemplate,
+ TranslationContext context) {
+ TranslateTo translateTo =
+ generateTranslationTo(heatFileName, heatOrchestrationTemplate, resource, resourceId,
+ context);
+
+ String translatedId =
+ ResourceTranslationFactory.getInstance(resource).generateTranslatedId(translateTo);
+
+ if (ConsolidationDataUtil.isNodeTemplatePointsToServiceTemplateWithoutNodeTemplates(translatedId,
+ heatFileName, context)) {
+ return Optional.empty();
+ }
+
+ if (translatedId != null) {
+ context.getTranslatedIds().get(heatFileName).put(resourceId, translatedId);
+ }
+
+ return Optional.ofNullable(translatedId);
}
- logger.debug("Translate- file: {} resource Id: {} translated resource id: {}",
- heatFileName, resourceId, translatedId.get());
- TranslateTo translateTo = new TranslateTo(heatFileName, serviceTemplate,
- heatOrchestrationTemplate, resource, resourceId, translatedId.get(), context);
- translate(translateTo);
- context.getTranslatedResources().get(heatFileName).add(resourceId);
-
- if (DataModelUtil.isNodeTemplate(translatedId.get(), serviceTemplate)) {
- if (!context.getHeatStackGroupMembers().containsKey(heatFileName)) {
- context.getHeatStackGroupMembers().put(heatFileName, new HashSet<>());
- }
- context.getHeatStackGroupMembers().get(heatFileName).add(translatedId.get());
- updateResourceDependency(translateTo);
+
+ private static Optional<ToscaTopologyTemplateElements> getResourceTranslatedElementTemplate(String heatFileName,
+ HeatOrchestrationTemplate heatOrchestrationTemplate,
+ String resourceId, TranslationContext context) {
+ Resource resource = heatOrchestrationTemplate.getResources().get(resourceId);
+ if (resource == null) {
+ throw new CoreException(
+ new ResourceNotFoundInHeatFileErrorBuilder(resourceId, heatFileName).build());
+ }
+ TranslateTo translateTo =
+ generateTranslationTo(heatFileName, heatOrchestrationTemplate, resource, resourceId,
+ context);
+
+ return ResourceTranslationFactory.getInstance(resource)
+ .getTranslatedToscaTopologyElement(translateTo);
}
- return translatedId;
- }
-
- private boolean isResourceWithSameIdAppearsInOtherFiles(String heatFileName,
- String resourceId,
- TranslationContext context) {
- Set<String> translatedResourceIdsFromOtherFiles =
- context.getTranslatedResourceIdsFromOtherFiles(heatFileName);
-
- return CollectionUtils.isNotEmpty(translatedResourceIdsFromOtherFiles)
- && translatedResourceIdsFromOtherFiles.contains(resourceId);
- }
-
- /**
- * Gets resource translated id.
- *
- * @param heatFileName the heat file name
- * @param heatOrchestrationTemplate the heat orchestration template
- * @param resourceId the resource id
- * @param context the context
- * @return the resource translated id
- */
- public static Optional<String> getResourceTranslatedId(String heatFileName,
- HeatOrchestrationTemplate
+
+ private static TranslateTo generateTranslationTo(String heatFileName,
+ HeatOrchestrationTemplate
heatOrchestrationTemplate,
- String resourceId,
- TranslationContext context) {
- if (!context.getTranslatedIds().containsKey(heatFileName)) {
- context.getTranslatedIds().put(heatFileName, new HashMap<>());
+ Resource resource, String resourceId,
+ TranslationContext context) {
+ TranslateTo to = new TranslateTo();
+ to.setHeatFileName(heatFileName);
+ to.setServiceTemplate(null);
+ to.setHeatOrchestrationTemplate(heatOrchestrationTemplate);
+ to.setResource(resource);
+ to.setResourceId(resourceId);
+ to.setTranslatedId(null);
+ to.setContext(context);
+ return to;
}
- Map<String, String> translatedIdsPerFile = context.getTranslatedIds().get(heatFileName);
- String translatedId = translatedIdsPerFile.get(resourceId);
- if (translatedId != null) {
- return Optional.of(translatedId);
+ protected abstract void translate(TranslateTo translateTo);
+
+ /**
+ * Translate resource.
+ *
+ * @param heatFileName the heat file name
+ * @param serviceTemplate the service template
+ * @param heatOrchestrationTemplate the heat orchestration template
+ * @param resource the resource
+ * @param resourceId the resource id
+ * @param context the context
+ * @return the translated id if this resource is supported, or empty value if not supported
+ */
+ public Optional<String> translateResource(String heatFileName, ServiceTemplate serviceTemplate,
+ HeatOrchestrationTemplate heatOrchestrationTemplate,
+ Resource resource, String resourceId,
+ TranslationContext context) {
+ Optional<String> translatedId =
+ getResourceTranslatedId(heatFileName, heatOrchestrationTemplate, resourceId, context);
+ context.getTranslatedResources().putIfAbsent(heatFileName, new HashSet<>());
+
+ if (isResourceWithSameIdAppearsInOtherFiles(heatFileName, resourceId, context)) {
+ throw new CoreException(
+ new DuplicateResourceIdsInDifferentFilesErrorBuilder(resourceId).build());
+ }
+ if (context.getTranslatedResources().get(heatFileName).contains(resourceId)) {
+ return translatedId;
+ }
+ if (!translatedId.isPresent()) {
+ return Optional.empty();
+ }
+ logger.debug("Translate- file: {} resource Id: {} translated resource id: {}",
+ heatFileName, resourceId, translatedId.get());
+ TranslateTo translateTo = new TranslateTo(heatFileName, serviceTemplate,
+ heatOrchestrationTemplate, resource, resourceId, translatedId.get(), context);
+ translate(translateTo);
+ context.getTranslatedResources().get(heatFileName).add(resourceId);
+
+ if (DataModelUtil.isNodeTemplate(translatedId.get(), serviceTemplate)) {
+ if (!context.getHeatStackGroupMembers().containsKey(heatFileName)) {
+ context.getHeatStackGroupMembers().put(heatFileName, new HashSet<>());
+ }
+ context.getHeatStackGroupMembers().get(heatFileName).add(translatedId.get());
+ updateResourceDependency(translateTo);
+ }
+ return translatedId;
}
- Resource resource = heatOrchestrationTemplate.getResources().get(resourceId);
- if (resource == null) {
- throw new CoreException(
- new ResourceNotFoundInHeatFileErrorBuilder(resourceId, heatFileName).build());
- }
- return getTranslatedResourceId(resourceId, heatFileName, resource, heatOrchestrationTemplate,
- context
- );
- }
-
- private static Optional<String> getTranslatedResourceId(String resourceId,
- String heatFileName,
- Resource resource,
- HeatOrchestrationTemplate heatOrchestrationTemplate,
- TranslationContext context) {
- TranslateTo translateTo =
- generateTranslationTo(heatFileName, null, heatOrchestrationTemplate, resource, resourceId,
- null, context);
-
- String translatedId =
- ResourceTranslationFactory.getInstance(resource).generateTranslatedId(translateTo);
-
- if (ConsolidationDataUtil.isNodeTemplatePointsToServiceTemplateWithoutNodeTemplates
- (translatedId, heatFileName, context)) {
- return Optional.empty();
- }
+ private boolean isResourceWithSameIdAppearsInOtherFiles(String heatFileName,
+ String resourceId,
+ TranslationContext context) {
+ Set<String> translatedResourceIdsFromOtherFiles =
+ context.getTranslatedResourceIdsFromOtherFiles(heatFileName);
- if (translatedId != null) {
- context.getTranslatedIds().get(heatFileName).put(resourceId, translatedId);
+ return CollectionUtils.isNotEmpty(translatedResourceIdsFromOtherFiles)
+ && translatedResourceIdsFromOtherFiles.contains(resourceId);
}
- return Optional.ofNullable(translatedId);
- }
-
-
- /**
- * Gets resource translated element template.
- *
- * @param heatFileName the heat file name
- * @param heatOrchestrationTemplate the heat orchestration template
- * @param resourceId the resource id
- * @param context the context
- * @return the resource translated element template
- */
- public static Optional<ToscaTopologyTemplateElements> getResourceTranslatedElementTemplate(
- String heatFileName,
- HeatOrchestrationTemplate heatOrchestrationTemplate,
- String resourceId, TranslationContext context) {
- Resource resource = heatOrchestrationTemplate.getResources().get(resourceId);
- if (resource == null) {
- throw new CoreException(
- new ResourceNotFoundInHeatFileErrorBuilder(resourceId, heatFileName).build());
- }
- TranslateTo translateTo =
- generateTranslationTo(heatFileName, null, heatOrchestrationTemplate, resource, resourceId,
- null, context);
-
- return ResourceTranslationFactory.getInstance(resource)
- .getTranslatedToscaTopologyElement(translateTo);
- }
-
- protected String generateTranslatedId(TranslateTo translateTo) {
- if (isEssentialRequirementsValid(translateTo)) {
- return translateTo.getResourceId();
- } else {
- return null;
+ protected String generateTranslatedId(TranslateTo translateTo) {
+ if (isEssentialRequirementsValid(translateTo)) {
+ return translateTo.getResourceId();
+ } else {
+ return null;
+ }
+
}
- }
+ protected Optional<ToscaTopologyTemplateElements> getTranslatedToscaTopologyElement(
+ TranslateTo translateTo) {
+ if (isEssentialRequirementsValid(translateTo)) {
+ return Optional.of(ToscaTopologyTemplateElements.NODE_TEMPLATE);
+ } else {
+ return Optional.empty();
+ }
+ }
- protected Optional<ToscaTopologyTemplateElements> getTranslatedToscaTopologyElement(
- TranslateTo translateTo) {
- if (isEssentialRequirementsValid(translateTo)) {
- return Optional.of(ToscaTopologyTemplateElements.NODE_TEMPLATE);
- } else {
- return Optional.empty();
+ protected boolean isEssentialRequirementsValid(TranslateTo translateTo) {
+ return true;
}
- }
-
- protected boolean isEssentialRequirementsValid(TranslateTo translateTo) {
- return true;
- }
-
- private static TranslateTo generateTranslationTo(String heatFileName,
- ServiceTemplate serviceTemplate,
- HeatOrchestrationTemplate
- heatOrchestrationTemplate,
- Resource resource, String resourceId,
- String translatedId,
- TranslationContext context) {
- TranslateTo to = new TranslateTo();
- to.setHeatFileName(heatFileName);
- to.setServiceTemplate(serviceTemplate);
- to.setHeatOrchestrationTemplate(heatOrchestrationTemplate);
- to.setResource(resource);
- to.setResourceId(resourceId);
- to.setTranslatedId(translatedId);
- to.setContext(context);
- return to;
- }
-
- private void updateResourceDependency(TranslateTo translateTo) {
-
- Resource resource = translateTo.getResource();
- if (resource.getDepends_on() == null) {
- return;
+
+ private void updateResourceDependency(TranslateTo translateTo) {
+
+ Resource resource = translateTo.getResource();
+ if (resource.getDepends_on() == null) {
+ return;
+ }
+
+ if (resource.getDepends_on() instanceof List) {
+ List<String> dependsOnList = (List<String>) resource.getDepends_on();
+ for (String dependsOnResourceId : dependsOnList) {
+ addDependency(dependsOnResourceId, translateTo);
+ }
+ } else {
+ String dependsOnResourceId = (String) resource.getDepends_on();
+ addDependency(dependsOnResourceId, translateTo);
+ }
}
- if (resource.getDepends_on() instanceof List) {
- List<String> dependsOnList = (List<String>) resource.getDepends_on();
- for (String dependsOnResourceId : dependsOnList) {
- addDependOnRequirement(dependsOnResourceId, translateTo);
- }
- } else {
- String dependsOnResourceId = (String) resource.getDepends_on();
- addDependOnRequirement(dependsOnResourceId, translateTo);
+ private void addDependency(String dependsOnResourceId, TranslateTo translateTo) {
+ String heatFileName = translateTo.getHeatFileName();
+ HeatOrchestrationTemplate heatOrchestrationTemplate = translateTo
+ .getHeatOrchestrationTemplate();
+ TranslationContext context = translateTo.getContext();
+
+ Optional<String> resourceTranslatedId =
+ getResourceTranslatedId(heatFileName, heatOrchestrationTemplate, dependsOnResourceId,
+ context);
+
+ Optional<ToscaTopologyTemplateElements> resourceTranslatedElementTemplate =
+ getResourceTranslatedElementTemplate(heatFileName, heatOrchestrationTemplate,
+ dependsOnResourceId, context);
+
+ if (resourceTranslatedId.isPresent()
+ && (resourceTranslatedElementTemplate.isPresent()
+ && resourceTranslatedElementTemplate.get() == ToscaTopologyTemplateElements.NODE_TEMPLATE)) {
+ Resource sourceResource = translateTo.getResource();
+ Resource targetResource = HeatToToscaUtil.getResource(heatOrchestrationTemplate, dependsOnResourceId,
+ translateTo.getHeatFileName());
+ if (isValidDependency(sourceResource, targetResource, translateTo)) {
+ addDependsOnRequirement(dependsOnResourceId, translateTo, resourceTranslatedId.get(), sourceResource,
+ targetResource);
+ }
+ }
}
- }
-
- private void addDependOnRequirement(String dependsOnResourceId, TranslateTo translateTo) {
- String nodeTemplateId = translateTo.getTranslatedId();
- ServiceTemplate serviceTemplate = translateTo.getServiceTemplate();
- String heatFileName = translateTo.getHeatFileName();
- HeatOrchestrationTemplate heatOrchestrationTemplate = translateTo
- .getHeatOrchestrationTemplate();
- TranslationContext context = translateTo.getContext();
- RequirementAssignment requirementAssignment = new RequirementAssignment();
- Optional<String> resourceTranslatedId =
- getResourceTranslatedId(heatFileName, heatOrchestrationTemplate, dependsOnResourceId,
- context);
-
- Optional<ToscaTopologyTemplateElements> resourceTranslatedElementTemplate =
- getResourceTranslatedElementTemplate(heatFileName, heatOrchestrationTemplate,
- dependsOnResourceId, context);
-
- if (resourceTranslatedId.isPresent()
- && (resourceTranslatedElementTemplate.isPresent() && resourceTranslatedElementTemplate
- .get() == ToscaTopologyTemplateElements.NODE_TEMPLATE)) {
- Resource sourceResource = translateTo.getResource();
- Resource targetResource = HeatToToscaUtil
- .getResource(heatOrchestrationTemplate, dependsOnResourceId,
- translateTo.getHeatFileName());
- if (isValidDependency(sourceResource, targetResource, translateTo)) {
- requirementAssignment.setNode(resourceTranslatedId.get());
+
+ private void addDependsOnRequirement(String dependsOnResourceId, TranslateTo translateTo,
+ String resourceTranslatedId, Resource sourceResource,
+ Resource targetResource) {
+ RequirementAssignment requirementAssignment = new RequirementAssignment();
+ requirementAssignment.setNode(resourceTranslatedId);
requirementAssignment.setCapability(ToscaCapabilityType.NATIVE_NODE);
requirementAssignment.setRelationship(ToscaRelationshipType.NATIVE_DEPENDS_ON);
- DataModelUtil.addRequirementAssignment(
- serviceTemplate.getTopology_template().getNode_templates().get(nodeTemplateId),
- ToscaConstants.DEPENDS_ON_REQUIREMENT_ID, requirementAssignment);
+ DataModelUtil.addRequirementAssignment(translateTo.getServiceTemplate().getTopology_template()
+ .getNode_templates().get(translateTo.getTranslatedId()),
+ ToscaConstants.DEPENDS_ON_REQUIREMENT_ID, requirementAssignment);
ConsolidationDataUtil
- .updateNodesConnectedData(translateTo, dependsOnResourceId, targetResource,
- sourceResource, nodeTemplateId, ToscaConstants.DEPENDS_ON_REQUIREMENT_ID,
- requirementAssignment);
- }
+ .updateNodesConnectedData(translateTo, dependsOnResourceId, targetResource,
+ sourceResource, translateTo.getTranslatedId(), ToscaConstants.DEPENDS_ON_REQUIREMENT_ID,
+ requirementAssignment);
+ }
+
+ private boolean isValidDependency(Resource sourceResource, Resource targetResource, TranslateTo translateTo) {
+ return !(HeatToToscaUtil.isNestedResource(sourceResource) || HeatToToscaUtil.isNestedResource(targetResource))
+ && HeatToToscaUtil.isValidDependsOnCandidate(sourceResource, targetResource,
+ ConsolidationEntityType.OTHER, translateTo.getContext());
+ }
+
+ Optional<List<Map.Entry<String, Resource>>> getResourceByTranslatedResourceId(
+ String heatFileName,
+ HeatOrchestrationTemplate heatOrchestrationTemplate,
+ String translatedResourceId,
+ TranslateTo translateTo,
+ String heatResourceType) {
+ List<Map.Entry<String, Resource>> list = heatOrchestrationTemplate.getResources().entrySet()
+ .stream()
+ .filter(entry -> getPredicatesForTranslatedIdToResourceId(heatFileName,
+ heatOrchestrationTemplate, translatedResourceId, translateTo.getContext(),
+ heatResourceType)
+ .stream()
+ .allMatch(p -> p.test(entry)))
+ .collect(Collectors.toList());
+ if (CollectionUtils.isEmpty(list)) {
+ return Optional.empty();
+ } else {
+ return Optional.of(list);
+ }
}
- }
-
- private boolean isValidDependency(Resource sourceResource, Resource targetResource, TranslateTo translateTo) {
- return !(HeatToToscaUtil.isNestedResource(sourceResource) || HeatToToscaUtil.isNestedResource(targetResource))
- && HeatToToscaUtil.isValidDependsOnCandidate(sourceResource, targetResource,
- ConsolidationEntityType.OTHER, translateTo.getContext());
- }
-
- Optional<List<Map.Entry<String, Resource>>> getResourceByTranslatedResourceId(
- String heatFileName,
- HeatOrchestrationTemplate heatOrchestrationTemplate,
- String translatedResourceId,
- TranslateTo translateTo,
- String heatResourceType) {
- List<Map.Entry<String, Resource>> list = heatOrchestrationTemplate.getResources().entrySet()
- .stream()
- .filter(entry -> getPredicatesForTranslatedIdToResourceId(heatFileName,
- heatOrchestrationTemplate, translatedResourceId, translateTo.getContext(),
- heatResourceType)
- .stream()
- .allMatch(p -> p.test(entry)))
- .collect(Collectors.toList());
- if (CollectionUtils.isEmpty(list)) {
- return Optional.empty();
- } else {
- return Optional.of(list);
+
+ private List<Predicate<Map.Entry<String, Resource>>> getPredicatesForTranslatedIdToResourceId(
+ String heatFileName, HeatOrchestrationTemplate heatOrchestrationTemplate,
+ String translatedResourceId, TranslationContext context, String heatResourceType) {
+ List<Predicate<Map.Entry<String, Resource>>> list = new ArrayList<>();
+ list.add(entry ->
+ entry.getValue().getType().equals(heatResourceType));
+ list.add(entry -> {
+ Optional<String> resourceTranslatedId =
+ getResourceTranslatedId(heatFileName, heatOrchestrationTemplate, entry.getKey(), context);
+ return resourceTranslatedId.isPresent()
+ && resourceTranslatedId.get().equals(translatedResourceId);
+ });
+ return list;
+ }
+
+ boolean isUnsupportedResourceType(Resource resource, List<String> supportedTypes) {
+ return !Objects.nonNull(resource) || !supportedTypes.contains(resource.getType());
}
- }
-
- private List<Predicate<Map.Entry<String, Resource>>> getPredicatesForTranslatedIdToResourceId(
- String heatFileName, HeatOrchestrationTemplate heatOrchestrationTemplate,
- String translatedResourceId, TranslationContext context, String heatResourceType) {
- List<Predicate<Map.Entry<String, Resource>>> list = new ArrayList<>();
- list.add(entry ->
- entry.getValue().getType().equals(heatResourceType));
- list.add(entry -> {
- Optional<String> resourceTranslatedId =
- getResourceTranslatedId(heatFileName, heatOrchestrationTemplate, entry.getKey(), context);
- return resourceTranslatedId.isPresent()
- && resourceTranslatedId.get().equals(translatedResourceId);
- });
- return list;
- }
-
- boolean isResourceTypeSupported(Resource resource, List<String> supporteTypes) {
- return Objects.nonNull(resource) && supporteTypes.contains(resource.getType());
- }
}
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/ResourceTranslationCinderVolumeAttachmentImpl.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationCinderVolumeAttachmentImpl.java
index 73debf02a8..a2ed9e92f7 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationCinderVolumeAttachmentImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationCinderVolumeAttachmentImpl.java
@@ -1,26 +1,32 @@
-/*-
- * ============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_INVALID_INSTANCE_UUID;
+import static org.openecomp.sdc.translator.services.heattotosca.HeatToToscaLogConstants.LOG_UNSUPPORTED_VOLUME_ATTACHMENT_MSG;
+import static org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil.getResource;
+
+import java.util.List;
+import java.util.Optional;
+
import org.apache.commons.lang3.StringUtils;
+import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
+import org.onap.sdc.tosca.datatypes.model.RelationshipTemplate;
+import org.onap.sdc.tosca.datatypes.model.RequirementAssignment;
import org.openecomp.sdc.common.errors.CoreException;
import org.openecomp.sdc.heat.datatypes.manifest.FileData;
import org.openecomp.sdc.heat.datatypes.model.HeatResourcesTypes;
@@ -28,11 +34,9 @@ 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.ToscaRelationshipType;
import org.openecomp.sdc.tosca.datatypes.ToscaTopologyTemplateElements;
-import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
-import org.onap.sdc.tosca.datatypes.model.RelationshipTemplate;
-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;
@@ -45,170 +49,170 @@ import org.openecomp.sdc.translator.services.heattotosca.errors.MissingMandatory
import org.openecomp.sdc.translator.services.heattotosca.helper.VolumeTranslationHelper;
import org.openecomp.sdc.translator.services.heattotosca.mapping.TranslatorHeatToToscaPropertyConverter;
-import java.util.List;
-import java.util.Optional;
+public class ResourceTranslationCinderVolumeAttachmentImpl extends ResourceTranslationBase {
-import static org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil.getResource;
+ protected static Logger logger = LoggerFactory.getLogger(ResourceTranslationCinderVolumeAttachmentImpl.class);
+
+ @Override
+ protected void translate(TranslateTo translateTo) {
+ RelationshipTemplate relationTemplate = new RelationshipTemplate();
+ relationTemplate.setType(ToscaRelationshipType.CINDER_VOLUME_ATTACHES_TO);
+ String heatFileName = translateTo.getHeatFileName();
+ relationTemplate.setProperties(TranslatorHeatToToscaPropertyConverter
+ .getToscaPropertiesSimpleConversion(translateTo.getServiceTemplate(),
+ translateTo.getResourceId(), translateTo.getResource().getProperties(),
+ relationTemplate.getProperties(), heatFileName,
+ translateTo.getHeatOrchestrationTemplate(), translateTo.getResource().getType(),
+ relationTemplate, translateTo.getContext()));
+
+ String volumeIdPropertyName = HeatConstants.VOL_ID_PROPERTY_NAME;
+ AttachedResourceId attachedVolumeId = getAttachedResourceId(translateTo, volumeIdPropertyName);
+ String instanceUuid = HeatConstants.INSTANCE_UUID_PROPERTY_NAME;
+ AttachedResourceId attachedNovaServerId = getAttachedResourceId(translateTo, instanceUuid);
+ if (attachedNovaServerId.isGetResource()) {
+ handleNovaGetResource(translateTo, relationTemplate, attachedVolumeId,
+ (String) attachedNovaServerId.getEntityId());
+ } else {
+ logger.warn(LOG_INVALID_INSTANCE_UUID, translateTo.getResourceId(), translateTo.getResource().getType());
+ }
+ }
-public class ResourceTranslationCinderVolumeAttachmentImpl extends ResourceTranslationBase {
+ @Override
+ protected Optional<ToscaTopologyTemplateElements> getTranslatedToscaTopologyElement(TranslateTo translateTo) {
+ if (isEssentialRequirementsValid(translateTo)) {
+ return Optional.of(ToscaTopologyTemplateElements.RELATIONSHIP_TEMPLATE);
+ } else {
+ return Optional.empty();
+ }
+ }
- private static final String UNSUPPORTED_VOLUME_ATTACHMENT_MSG =
- "Volume attachment with id '{}' is pointing to unsupported resource type({}) through the property " +
- "'volume_id'. The connection to the volume is ignored. Supported types are: {}";
-
- protected static Logger logger = LoggerFactory.getLogger(ResourceTranslationCinderVolumeAttachmentImpl.class);
-
- @Override
- protected void translate(TranslateTo translateTo) {
- RelationshipTemplate relationTemplate = new RelationshipTemplate();
- relationTemplate.setType(ToscaRelationshipType.CINDER_VOLUME_ATTACHES_TO);
- String relationshipTemplateId = translateTo.getTranslatedId();
- String heatFileName = translateTo.getHeatFileName();
- relationTemplate.setProperties(TranslatorHeatToToscaPropertyConverter
- .getToscaPropertiesSimpleConversion(translateTo.getServiceTemplate(),translateTo
- .getResourceId(),translateTo.getResource().getProperties(),
- relationTemplate.getProperties(), heatFileName,
- translateTo.getHeatOrchestrationTemplate(), translateTo.getResource().getType(),
- relationTemplate, translateTo.getContext()));
-
- String volumeIdPropertyName = "volume_id";
- AttachedResourceId attachedVolumeId = getAttachedResourceId(translateTo, volumeIdPropertyName);
- String instanceUuid = HeatConstants.INSTANCE_UUID_PROPERTY_NAME;
- AttachedResourceId attachedNovaServerId = getAttachedResourceId(translateTo, instanceUuid);
-
- if (attachedNovaServerId.isGetResource()) {
- handleNovaGetResource(translateTo, relationTemplate, relationshipTemplateId, heatFileName,
- attachedVolumeId, (String) attachedNovaServerId.getEntityId());
- } else {
- logger.warn("Heat resource: '" + translateTo.getResourceId() + "' with type: '"
- + translateTo.getResource().getType()
- + "' include 'instance_uuid' property without 'get_resource' function, therefore this "
- + "resource will be ignored in TOSCA translation.");
+ private AttachedResourceId getAttachedResourceId(TranslateTo translateTo, String propertyName) {
+ Optional<AttachedResourceId> attachedResourceId = HeatToToscaUtil.extractAttachedResourceId(translateTo,
+ propertyName);
+ if (!attachedResourceId.isPresent()) {
+ throw new CoreException(new MissingMandatoryPropertyErrorBuilder(propertyName).build());
+ }
+ return attachedResourceId.get();
+ }
+
+ private void handleNovaGetResource(TranslateTo translateTo, RelationshipTemplate relationTemplate,
+ AttachedResourceId volResourceId, String novaResourceId) {
+ RequirementAssignment requirement = new RequirementAssignment();
+ String toscaCapabilityAttachment = ToscaCapabilityType.NATIVE_ATTACHMENT;
+ requirement.setCapability(toscaCapabilityAttachment);
+ if (volResourceId.isGetResource()) {
+ createVolumeNovaRelationshipForVolGetResource(translateTo, relationTemplate, volResourceId, requirement);
+ } else if (volResourceId.isGetParam() && volResourceId.getEntityId() instanceof String) {
+ createVolumeNovaRelationshipForVolGetParam(translateTo, relationTemplate, volResourceId, requirement);
+ }
+ translateNovaServerResource(translateTo, novaResourceId, requirement);
}
- }
-
- @Override
- protected Optional<ToscaTopologyTemplateElements> getTranslatedToscaTopologyElement(
- TranslateTo translateTo) {
- if (isEssentialRequirementsValid(translateTo)) {
- return Optional.of(ToscaTopologyTemplateElements.RELATIONSHIP_TEMPLATE);
- } else {
- return Optional.empty();
+
+ private void translateNovaServerResource(TranslateTo translateTo, String novaResourceId,
+ RequirementAssignment requirement) {
+ Resource novaServerResource =
+ getResource(translateTo.getHeatOrchestrationTemplate(), novaResourceId, translateTo.getHeatFileName());
+ if (!StringUtils.equals(HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource(),
+ novaServerResource.getType())) {
+ logger.warn(LOG_UNSUPPORTED_VOLUME_ATTACHMENT_MSG, translateTo.getResourceId(),
+ novaServerResource.getType(), HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource());
+ return;
+ }
+ Optional<String> translatedNovaServerId = ResourceTranslationFactory.getInstance(novaServerResource)
+ .translateResource(translateTo.getHeatFileName(), translateTo.getServiceTemplate(),
+ translateTo.getHeatOrchestrationTemplate(), novaServerResource, novaResourceId,
+ translateTo.getContext());
+
+ if (translatedNovaServerId.isPresent() && StringUtils.isNotEmpty(requirement.getNode())) {
+ NodeTemplate novaServerNodeTemplate = DataModelUtil
+ .getNodeTemplate(translateTo.getServiceTemplate(), translatedNovaServerId.get());
+ DataModelUtil.addRequirementAssignment(novaServerNodeTemplate, ToscaConstants
+ .LOCAL_STORAGE_REQUIREMENT_ID, requirement);
+ //Add volume information to consolidation data
+ ConsolidationDataUtil.updateComputeConsolidationDataVolumes(translateTo,
+ novaServerNodeTemplate.getType(), translatedNovaServerId.get(), ToscaConstants
+ .LOCAL_STORAGE_REQUIREMENT_ID, requirement);
+ }
}
- }
- private AttachedResourceId getAttachedResourceId(TranslateTo translateTo, String propertyName) {
- Optional<AttachedResourceId> attachedResourceId =
- HeatToToscaUtil.extractAttachedResourceId(translateTo, propertyName);
- if (!attachedResourceId.isPresent()) {
- throw new CoreException(new MissingMandatoryPropertyErrorBuilder(propertyName).build());
+ private void createVolumeNovaRelationshipForVolGetParam(TranslateTo translateTo,
+ RelationshipTemplate relationTemplate,
+ AttachedResourceId volResourceId,
+ RequirementAssignment requirement) {
+ String volumeResourceIdParamName = (String) volResourceId.getEntityId();
+ if (translateTo.getContext().getHeatSharedResourcesByParam().containsKey(volumeResourceIdParamName)
+ && !isHeatFileNested(translateTo, translateTo.getHeatFileName())) {
+ handleSharedVolume(translateTo, relationTemplate, requirement, volumeResourceIdParamName);
+ } else {
+ handleUnsharedVolume(translateTo, relationTemplate, requirement, volumeResourceIdParamName);
+ }
}
- return attachedResourceId.get();
- }
-
- private void handleNovaGetResource(TranslateTo translateTo, RelationshipTemplate relationTemplate,
- String relationshipTemplateId, String heatFileName,
- AttachedResourceId volResourceId, String novaResourceId) {
- RequirementAssignment requirement = new RequirementAssignment();
- String toscaCapabilityAttachment = "tosca.capabilities.Attachment";
- requirement.setCapability(toscaCapabilityAttachment);
- if (volResourceId.isGetResource()) {
- Resource volServerResource = getResource(translateTo.getHeatOrchestrationTemplate(),
- (String) volResourceId.getTranslatedId(), heatFileName);
- if (!StringUtils.equals(HeatResourcesTypes.CINDER_VOLUME_RESOURCE_TYPE.getHeatResource(),
- volServerResource.getType())) {
- logger.warn(UNSUPPORTED_VOLUME_ATTACHMENT_MSG, translateTo.getResourceId(), volServerResource.getType(),
- HeatResourcesTypes.CINDER_VOLUME_RESOURCE_TYPE.getHeatResource());
- return;
- }
- requirement.setNode((String) volResourceId.getTranslatedId());
- requirement.setRelationship(relationshipTemplateId);
- DataModelUtil
- .addRelationshipTemplate(translateTo.getServiceTemplate(), relationshipTemplateId,
- relationTemplate);
- } else if (volResourceId.isGetParam() && volResourceId.getEntityId() instanceof String) {
- String volumeResourceIdParamName = (String) volResourceId.getEntityId();
- if (translateTo.getContext().getHeatSharedResourcesByParam()
- .containsKey(volumeResourceIdParamName) && !isHeatFileNested(translateTo, heatFileName)) {
- Resource volServerResource =
- translateTo.getContext().getHeatSharedResourcesByParam().get(volumeResourceIdParamName)
- .getHeatResource();
+
+ private void handleSharedVolume(TranslateTo translateTo, RelationshipTemplate relationTemplate,
+ RequirementAssignment requirement, String volumeResourceIdParamName) {
+ Resource volServerResource = translateTo.getContext().getHeatSharedResourcesByParam()
+ .get(volumeResourceIdParamName).getHeatResource();
if (!StringUtils.equals(HeatResourcesTypes.CINDER_VOLUME_RESOURCE_TYPE.getHeatResource(),
- volServerResource.getType())) {
- logger.warn(UNSUPPORTED_VOLUME_ATTACHMENT_MSG, translateTo.getResourceId(), volServerResource.getType(),
- HeatResourcesTypes.CINDER_VOLUME_RESOURCE_TYPE.getHeatResource());
- return;
+ volServerResource.getType())) {
+ logger.warn(LOG_UNSUPPORTED_VOLUME_ATTACHMENT_MSG, translateTo.getResourceId(),
+ volServerResource.getType(),
+ HeatResourcesTypes.CINDER_VOLUME_RESOURCE_TYPE.getHeatResource());
+ return;
}
- requirement.setNode(
- translateTo.getContext().getHeatSharedResourcesByParam().get(volumeResourceIdParamName)
- .getTranslatedId());
- requirement.setRelationship(relationshipTemplateId);
- DataModelUtil
- .addRelationshipTemplate(translateTo.getServiceTemplate(), relationshipTemplateId,
+ requirement.setNode(translateTo.getContext().getHeatSharedResourcesByParam().get(volumeResourceIdParamName)
+ .getTranslatedId());
+ requirement.setRelationship(translateTo.getTranslatedId());
+ DataModelUtil.addRelationshipTemplate(translateTo.getServiceTemplate(), translateTo.getTranslatedId(),
+ relationTemplate);
+ }
+
+ private void createVolumeNovaRelationshipForVolGetResource(TranslateTo translateTo,
+ RelationshipTemplate relationTemplate,
+ AttachedResourceId volResourceId,
+ RequirementAssignment requirement) {
+ Resource volServerResource = getResource(translateTo.getHeatOrchestrationTemplate(),
+ (String) volResourceId.getTranslatedId(), translateTo.getHeatFileName());
+ if (!StringUtils.equals(HeatResourcesTypes.CINDER_VOLUME_RESOURCE_TYPE.getHeatResource(),
+ volServerResource.getType())) {
+ logger.warn(LOG_UNSUPPORTED_VOLUME_ATTACHMENT_MSG, translateTo.getResourceId(), volServerResource.getType(),
+ HeatResourcesTypes.CINDER_VOLUME_RESOURCE_TYPE.getHeatResource());
+ return;
+ }
+ requirement.setNode((String) volResourceId.getTranslatedId());
+ requirement.setRelationship(translateTo.getTranslatedId());
+ DataModelUtil.addRelationshipTemplate(translateTo.getServiceTemplate(), translateTo.getTranslatedId(),
relationTemplate);
- } else {
- handleUnsharedVolume(translateTo, relationTemplate, relationshipTemplateId, heatFileName,
- requirement, volumeResourceIdParamName);
- }
}
- Resource novaServerResource =
- getResource(translateTo.getHeatOrchestrationTemplate(), novaResourceId, heatFileName);
- if (!StringUtils.equals(HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource(),
- novaServerResource.getType())) {
- logger.warn(UNSUPPORTED_VOLUME_ATTACHMENT_MSG,translateTo.getResourceId(),
- novaServerResource.getType(), HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource());
- return;
+
+ private void handleUnsharedVolume(TranslateTo translateTo, RelationshipTemplate relationTemplate,
+ RequirementAssignment requirement, String volumeResourceId) {
+ List<FileData> allFilesData = translateTo.getContext().getManifest().getContent().getData();
+ Optional<FileData> fileData = HeatToToscaUtil.getFileData(translateTo.getHeatFileName(), allFilesData);
+ if (fileData.isPresent()) {
+ Optional<ResourceFileDataAndIDs> fileDataContainingResource =
+ new VolumeTranslationHelper(logger)
+ .getFileDataContainingVolume(fileData.get().getData(), volumeResourceId, translateTo,
+ FileData.Type.HEAT_VOL);
+ fileDataContainingResource.ifPresent(resourceFileDataAndIDs -> addRelationshipToServiceTemplate(
+ translateTo, relationTemplate, requirement, resourceFileDataAndIDs));
+ }
}
- Optional<String> translatedNovaServerId =
- ResourceTranslationFactory.getInstance(novaServerResource)
- .translateResource(heatFileName, translateTo.getServiceTemplate(),
- translateTo.getHeatOrchestrationTemplate(), novaServerResource, novaResourceId,
- translateTo.getContext());
-
- if (translatedNovaServerId.isPresent() && StringUtils.isNotEmpty(requirement.getNode())) {
- NodeTemplate novaServerNodeTemplate = DataModelUtil
- .getNodeTemplate(translateTo.getServiceTemplate(), translatedNovaServerId.get());
- DataModelUtil.addRequirementAssignment(novaServerNodeTemplate, ToscaConstants
- .LOCAL_STORAGE_REQUIREMENT_ID, requirement);
- //Add volume information to consolidation data
- ConsolidationDataUtil.updateComputeConsolidationDataVolumes(translateTo,
- novaServerNodeTemplate.getType(), translatedNovaServerId.get(), ToscaConstants
- .LOCAL_STORAGE_REQUIREMENT_ID, requirement);
+
+ private boolean isHeatFileNested(TranslateTo translateTo, String heatFileName) {
+ return translateTo.getContext().getNestedHeatsFiles().contains(heatFileName);
}
- }
-
- private void handleUnsharedVolume(TranslateTo translateTo, RelationshipTemplate relationTemplate,
- String relationshipTemplateId, String heatFileName,
- RequirementAssignment requirement, String volumeResourceId) {
- List<FileData> allFilesData = translateTo.getContext().getManifest().getContent().getData();
- Optional<FileData> fileData = HeatToToscaUtil.getFileData(heatFileName, allFilesData);
- if (fileData.isPresent()) {
- Optional<ResourceFileDataAndIDs> fileDataContainingResource =
- new VolumeTranslationHelper(logger)
- .getFileDataContainingVolume(fileData.get().getData(), volumeResourceId, translateTo,
- FileData.Type.HEAT_VOL);
- fileDataContainingResource.ifPresent(
- resourceFileDataAndIDs -> addRelationshipToServiceTemplate(translateTo, relationTemplate,
- relationshipTemplateId, requirement, resourceFileDataAndIDs));
+
+ private void addRelationshipToServiceTemplate(TranslateTo translateTo,
+ RelationshipTemplate relationTemplate,
+ RequirementAssignment requirement,
+ ResourceFileDataAndIDs resourceFileDataAndIDs) {
+ String translatedId = resourceFileDataAndIDs.getTranslatedResourceId();
+ String toscaVolIdPropName =
+ HeatToToscaUtil.getToscaPropertyName(translateTo, HeatConstants.VOL_ID_PROPERTY_NAME);
+ relationTemplate.getProperties().put(toscaVolIdPropName, translatedId);
+ requirement.setNode(translatedId);
+ requirement.setRelationship(translateTo.getTranslatedId());
+ DataModelUtil.addRelationshipTemplate(translateTo.getServiceTemplate(), translateTo.getTranslatedId(),
+ relationTemplate);
}
- }
-
- private boolean isHeatFileNested(TranslateTo translateTo, String heatFileName) {
- return translateTo.getContext().getNestedHeatsFiles().contains(heatFileName);
- }
-
- private void addRelationshipToServiceTemplate(TranslateTo translateTo,
- RelationshipTemplate relationTemplate,
- String relationshipTemplateId,
- RequirementAssignment requirement,
- ResourceFileDataAndIDs resourceFileDataAndIDs) {
- String translatedId = resourceFileDataAndIDs.getTranslatedResourceId();
- String toscaVolIdPropName =
- HeatToToscaUtil.getToscaPropertyName(translateTo, HeatConstants.VOL_ID_PROPERTY_NAME);
- relationTemplate.getProperties().put(toscaVolIdPropName, translatedId);
- requirement.setNode(translatedId);
- requirement.setRelationship(relationshipTemplateId);
- DataModelUtil.addRelationshipTemplate(translateTo.getServiceTemplate(), relationshipTemplateId,
- relationTemplate);
- }
}
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/ResourceTranslationCinderVolumeImpl.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationCinderVolumeImpl.java
index 5b36d39ec0..fd6f28cec9 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationCinderVolumeImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationCinderVolumeImpl.java
@@ -1,76 +1,71 @@
-/*-
- * ============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.Map;
+
+import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
import org.openecomp.sdc.heat.datatypes.HeatBoolean;
import org.openecomp.sdc.heat.services.HeatConstants;
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.mapping.TranslatorHeatToToscaPropertyConverter;
-import java.util.Map;
-
public class ResourceTranslationCinderVolumeImpl extends ResourceTranslationBase {
- @Override
- public void translate(TranslateTo translateTo) {
- NodeTemplate nodeTemplate = new NodeTemplate();
- nodeTemplate.setType(ToscaNodeType.CINDER_VOLUME);
- nodeTemplate.setProperties(TranslatorHeatToToscaPropertyConverter
- .getToscaPropertiesSimpleConversion(translateTo.getServiceTemplate(),translateTo.
- getResourceId(),translateTo.getResource().getProperties(),
- nodeTemplate.getProperties(), translateTo.getHeatFileName(),
- translateTo.getHeatOrchestrationTemplate(), translateTo.getResource().getType(),
- nodeTemplate, translateTo.getContext()));
- handleSizeProperty(nodeTemplate.getProperties());
- String toscaReadOnlyPropName =
- HeatToToscaUtil.getToscaPropertyName(translateTo, HeatConstants.READ_ONLY_PROPERTY_NAME);
- Object readOnlyPropVal = nodeTemplate.getProperties().get(toscaReadOnlyPropName);
- if (readOnlyPropVal != null && !(readOnlyPropVal instanceof Map)) {
- nodeTemplate.getProperties().put(toscaReadOnlyPropName, HeatBoolean.eval(readOnlyPropVal));
- }
- DataModelUtil.addNodeTemplate(translateTo.getServiceTemplate(), translateTo.getTranslatedId(),
- nodeTemplate);
- }
-
+ private static final String VOLUME_SIZE_PROPERTY_NAME = "size";
- private void handleSizeProperty(Map<String, Object> nodeTemplateProperties) {
- Object size = nodeTemplateProperties.get("size");
- if (size == null) {
- return;
+ @Override
+ public void translate(TranslateTo translateTo) {
+ NodeTemplate nodeTemplate = new NodeTemplate();
+ nodeTemplate.setType(ToscaNodeType.CINDER_VOLUME);
+ nodeTemplate.setProperties(TranslatorHeatToToscaPropertyConverter
+ .getToscaPropertiesSimpleConversion(translateTo.getServiceTemplate(),
+ translateTo.getResourceId(), translateTo.getResource().getProperties(),
+ nodeTemplate.getProperties(), translateTo.getHeatFileName(),
+ translateTo.getHeatOrchestrationTemplate(), translateTo.getResource().getType(),
+ nodeTemplate, translateTo.getContext()));
+ handleSizeProperty(nodeTemplate.getProperties());
+ String toscaReadOnlyPropName =
+ HeatToToscaUtil.getToscaPropertyName(translateTo, HeatConstants.READ_ONLY_PROPERTY_NAME);
+ Object readOnlyPropVal = nodeTemplate.getProperties().get(toscaReadOnlyPropName);
+ if (readOnlyPropVal != null && !(readOnlyPropVal instanceof Map)) {
+ nodeTemplate.getProperties().put(toscaReadOnlyPropName, HeatBoolean.eval(readOnlyPropVal));
+ }
+ DataModelUtil.addNodeTemplate(translateTo.getServiceTemplate(), translateTo.getTranslatedId(),
+ nodeTemplate);
}
- if (size instanceof Map) {
- Map<String, Object> propMap = (Map) size;
- for (Map.Entry entry : propMap.entrySet()) {
- String val = "(" + entry.getKey() + " : " + entry.getValue() + ") * 1024";
- nodeTemplateProperties.put("size", val);
- return;
- }
- } else {
- nodeTemplateProperties.put("size", size + "*1024");
+
+ private void handleSizeProperty(Map<String, Object> nodeTemplateProperties) {
+ Object size = nodeTemplateProperties.get(VOLUME_SIZE_PROPERTY_NAME);
+ if (size == null) {
+ return;
+ }
+ if (size instanceof Map) {
+ Map<String, Object> propMap = (Map) size;
+ Map.Entry<String, Object> entry = propMap.entrySet().iterator().next();
+ String val = "(" + entry.getKey() + " : " + entry.getValue() + ") * 1024";
+ nodeTemplateProperties.put(VOLUME_SIZE_PROPERTY_NAME, val);
+ } else {
+ nodeTemplateProperties.put(VOLUME_SIZE_PROPERTY_NAME, size + "*1024");
+ }
}
- }
}
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 6f223e6937..75b2394f6c 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
@@ -25,8 +25,9 @@ import static org.openecomp.sdc.translator.services.heattotosca.HeatToToscaLogCo
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 com.google.common.collect.ImmutableList;
+
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -320,9 +321,9 @@ public class ResourceTranslationContrailServiceInstanceImpl extends ResourceTran
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());
+ List<String> validNetworksForConnections = ImmutableList.of(
+ HeatResourcesTypes.NEUTRON_NET_RESOURCE_TYPE.getHeatResource(),
+ HeatResourcesTypes.CONTRAIL_VIRTUAL_NETWORK_RESOURCE_TYPE.getHeatResource());
if (!(interfacePropertyValue instanceof Map)) {
return;
}
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 3e3983ff88..d3faefd627 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
@@ -17,6 +17,7 @@
package org.openecomp.sdc.translator.services.heattotosca.impl.resourcetranslation;
import static org.openecomp.sdc.translator.services.heattotosca.Constants.SECURITY_GROUPS_PROPERTY_NAME;
+import static org.openecomp.sdc.translator.services.heattotosca.HeatToToscaLogConstants.LOG_UNSUPPORTED_RESOURCE_REQUIREMENT_CONNECTION;
import com.google.common.collect.ImmutableList;
@@ -224,10 +225,9 @@ public class ResourceTranslationNeutronPortImpl extends ResourceTranslationBase
List<String> supportedTypes,
Resource heatResource,
final String propertyName) {
- if (!isResourceTypeSupported(heatResource, supportedTypes)) {
+ if (isUnsupportedResourceType(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
+ logger.warn(LOG_UNSUPPORTED_RESOURCE_REQUIREMENT_CONNECTION, propertyName, translateTo
.getResourceId(), heatResource.getType(), supportedResourceTypes);
return true;
}
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/SecurityRulesToPortResourceConnection.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/SecurityRulesToPortResourceConnection.java
index 46219b3079..7573374b65 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/SecurityRulesToPortResourceConnection.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/SecurityRulesToPortResourceConnection.java
@@ -16,6 +16,8 @@
package org.openecomp.sdc.translator.services.heattotosca.impl.resourcetranslation;
+import static org.openecomp.sdc.translator.services.heattotosca.HeatToToscaLogConstants.LOG_UNSUPPORTED_SECURITY_RULE_PORT_CAPABILITY_CONNECTION;
+
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -120,10 +122,8 @@ class SecurityRulesToPortResourceConnection extends ResourceConnectionUsingCapab
List<String> supportedTypes) {
- if (!resourceTranslationBase.isResourceTypeSupported(connectedResource, supportedTypes)) {
- logger.warn("Nested resource '{}' property '{}' is pointing to resource with type '{}' which is not "
- + "supported for capability '{}' connection, (security rules to port connection)."
- + "Supported types are: '{}', therefore, this TOSCA capability will not be connected.",
+ if (resourceTranslationBase.isUnsupportedResourceType(connectedResource, supportedTypes)) {
+ logger.warn(LOG_UNSUPPORTED_SECURITY_RULE_PORT_CAPABILITY_CONNECTION,
nestedResourceId, nestedPropertyName, connectedResource.getType(),
connectionPointId, supportedTypes.toString());