summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java')
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/AttachedResourceId.java65
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/ResourceReferenceType.java25
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/to/FileDataCollection.java123
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/to/ResourceFileDataAndIDs.java70
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/to/TranslateTo.java132
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/to/TranslatedHeatResource.java49
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/impl/heattotosca/HeatToToscaTranslatorFactoryImpl.java34
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/impl/heattotosca/HeatToToscaTranslatorImpl.java134
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/Constants.java60
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/HeatToToscaUtil.java503
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ResourceTranslation.java37
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ResourceTranslationFactory.java107
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/TranslationContext.java172
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/TranslationService.java344
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/errors/IncorrectResourceReferenceErrorBuilder.java51
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/errors/InvalidPropertyValueErrorBuilder.java47
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/errors/MissingMandatoryPropertyErrorBuilder.java43
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/errors/NotInSyncNumberOfInterfacesErrorBuilder.java44
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/errors/ReferenceToUnsupportedResourceErrorBuilder.java52
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/errors/ResourceNotFoundInHeatFileErrorBuilder.java52
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/errors/TranslatorErrorCodes.java31
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/AbstractSubstituteGlobalType.java167
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/CinderVolumeGlobalType.java242
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/CommonGlobalTypes.java500
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/ContrailAbstractSubstituteGlobalType.java196
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/ContrailComputeGlobalType.java128
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/ContrailNetworkRuleGlobalType.java227
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/ContrailPortGlobalType.java107
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/ContrailV2NetworkRuleGlobalType.java274
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/ContrailV2VirtualMachineInterfaceGlobalType.java136
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/ContrailV2VirtualNetworkGlobalType.java239
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/ContrailVirtualNetworkGlobalType.java134
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/GlobalTypesGenerator.java128
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/GlobalTypesUtil.java69
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/NeutronNetGlobalType.java143
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/NeutronPortGlobalType.java203
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/NeutronSecurityRulesGlobalType.java175
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/NovaServerGlobalType.java307
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/helper/ContrailTranslationHelper.java65
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/helper/NameExtractorService.java33
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/helper/PropertyRegexMatcher.java69
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/helper/VolumeTranslationHelper.java172
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/helper/impl/NameExtractorServiceImpl.java95
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/BaseResourceConnection.java174
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ContrailV2VmInterfaceToNetResourceConnection.java139
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/NovaAndPortResourceConnectionHelper.java106
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/NovaToVolResourceConnection.java228
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/PortToNetResourceConnection.java200
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationBase.java456
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationCinderVolumeAttachmentImpl.java202
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationCinderVolumeImpl.java77
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationContrailAttachPolicyImpl.java141
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationContrailNetworkPolicyImpl.java53
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationContrailServiceInstanceImpl.java663
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationContrailServiceTemplateImpl.java100
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationContrailV2NetworkPolicyImpl.java49
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationContrailV2VirtualNetworkImpl.java209
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationContrailV2VmInterfaceImpl.java126
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationContrailVirtualNetworkImpl.java51
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationDefaultImpl.java41
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationNestedImpl.java781
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationNeutronNetImpl.java52
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationNeutronPortImpl.java233
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationNeutronSecurityGroupImpl.java47
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationNeutronSubnetImpl.java170
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationNovaServerGroupsImpl.java119
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationNovaServerImpl.java419
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationResourceGroupImpl.java202
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/SecurityRulesToPortResourceConnection.java203
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/mapping/TranslatorHeatToToscaFunctionConverter.java410
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/mapping/TranslatorHeatToToscaParameterConverter.java271
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/mapping/TranslatorHeatToToscaPropertyConverter.java146
72 files changed, 12052 insertions, 0 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/AttachedResourceId.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/AttachedResourceId.java
new file mode 100644
index 0000000000..4286666392
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/AttachedResourceId.java
@@ -0,0 +1,65 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.datatypes.heattotosca;
+
+public class AttachedResourceId {
+ private Object translatedId;
+ private Object entityId;
+ private ResourceReferenceType resourceReferenceType;
+
+ /**
+ * Instantiates a new Attached resource id.
+ *
+ * @param translatedId the translated id
+ * @param entityId the entity id
+ * @param resourceReferenceType the resource reference type
+ */
+ public AttachedResourceId(Object translatedId, Object entityId,
+ ResourceReferenceType resourceReferenceType) {
+ this.translatedId = translatedId;
+ this.resourceReferenceType = resourceReferenceType;
+ this.entityId = entityId;
+ }
+
+ public Object getEntityId() {
+ return entityId;
+ }
+
+ public Object getTranslatedId() {
+ return translatedId;
+ }
+
+ public ResourceReferenceType getResourceReferenceType() {
+ return resourceReferenceType;
+ }
+
+ public boolean isGetResource() {
+ return resourceReferenceType == ResourceReferenceType.GET_RESOURCE;
+ }
+
+ public boolean isGetParam() {
+ return resourceReferenceType == ResourceReferenceType.GET_PARAM;
+ }
+
+ public boolean isGetAttr() {
+ return resourceReferenceType == ResourceReferenceType.GET_ATTR;
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/ResourceReferenceType.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/ResourceReferenceType.java
new file mode 100644
index 0000000000..81ccd69a66
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/ResourceReferenceType.java
@@ -0,0 +1,25 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.datatypes.heattotosca;
+
+public enum ResourceReferenceType {
+ GET_RESOURCE, GET_PARAM, GET_ATTR, OTHER
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/to/FileDataCollection.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/to/FileDataCollection.java
new file mode 100644
index 0000000000..a9147b838f
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/to/FileDataCollection.java
@@ -0,0 +1,123 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.datatypes.heattotosca.to;
+
+
+import org.openecomp.sdc.heat.datatypes.manifest.FileData;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+public class FileDataCollection {
+
+ Collection<FileData> baseFiles;
+ Collection<FileData> addOnFiles;
+ Collection<FileData> nestedFiles;
+ Collection<FileData> artifactFiles;
+
+ public Collection<FileData> getBaseFile() {
+ return baseFiles;
+ }
+
+ public void setBaseFile(Collection<FileData> baseFiles) {
+ this.baseFiles = baseFiles;
+ }
+
+ public Collection<FileData> getAddOnFiles() {
+ return addOnFiles;
+ }
+
+ public void setAddOnFiles(Collection<FileData> addOnFiles) {
+ this.addOnFiles = addOnFiles;
+ }
+
+ public Collection<FileData> getNestedFiles() {
+ return nestedFiles;
+ }
+
+ public void setNestedFiles(Collection<FileData> nestedFiles) {
+ this.nestedFiles = nestedFiles;
+ }
+
+ public Collection<FileData> getBaseFiles() {
+ return baseFiles;
+ }
+
+ public void setBaseFiles(Collection<FileData> baseFiles) {
+ this.baseFiles = baseFiles;
+ }
+
+ public Collection<FileData> getArtifactFiles() {
+ return artifactFiles;
+ }
+
+ public void setArtifactFiles(Collection<FileData> artifactFiles) {
+ this.artifactFiles = artifactFiles;
+ }
+
+ /**
+ * Add add on files.
+ *
+ * @param addonFile the addon file
+ */
+ public void addAddOnFiles(FileData addonFile) {
+ if (this.addOnFiles == null) {
+ this.addOnFiles = new ArrayList<>();
+ }
+ this.addOnFiles.add(addonFile);
+ }
+
+ /**
+ * Add nested files.
+ *
+ * @param nestedFile the nested file
+ */
+ public void addNestedFiles(FileData nestedFile) {
+ if (this.nestedFiles == null) {
+ this.nestedFiles = new ArrayList<>();
+ }
+ this.nestedFiles.add(nestedFile);
+ }
+
+ /**
+ * Add base files.
+ *
+ * @param baseFile the base file
+ */
+ public void addBaseFiles(FileData baseFile) {
+ if (this.baseFiles == null) {
+ this.baseFiles = new ArrayList<>();
+ }
+ this.baseFiles.add(baseFile);
+ }
+
+ /**
+ * Add artifact files.
+ *
+ * @param artifactFile the artifact file
+ */
+ public void addArtifactFiles(FileData artifactFile) {
+ if (this.artifactFiles == null) {
+ this.artifactFiles = new ArrayList<>();
+ }
+ this.artifactFiles.add(artifactFile);
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/to/ResourceFileDataAndIDs.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/to/ResourceFileDataAndIDs.java
new file mode 100644
index 0000000000..b8349444d7
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/to/ResourceFileDataAndIDs.java
@@ -0,0 +1,70 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.datatypes.heattotosca.to;
+
+
+import org.openecomp.sdc.heat.datatypes.manifest.FileData;
+
+public class ResourceFileDataAndIDs {
+ private String resourceId;
+ private String translatedResourceId;
+ private FileData fileData;
+
+ public ResourceFileDataAndIDs() {
+ }
+
+ /**
+ * Instantiates a new Resource file data and i ds.
+ *
+ * @param resourceId the resource id
+ * @param translatedResourceId the translated resource id
+ * @param fileData the file data
+ */
+ public ResourceFileDataAndIDs(String resourceId, String translatedResourceId, FileData fileData) {
+ this.resourceId = resourceId;
+ this.translatedResourceId = translatedResourceId;
+ this.fileData = fileData;
+ }
+
+ public String getResourceId() {
+ return resourceId;
+ }
+
+ public void setResourceId(String resourceId) {
+ this.resourceId = resourceId;
+ }
+
+ public String getTranslatedResourceId() {
+ return translatedResourceId;
+ }
+
+ public void setTranslatedResourceId(String translatedResourceId) {
+ this.translatedResourceId = translatedResourceId;
+ }
+
+ public FileData getFileData() {
+ return fileData;
+ }
+
+ public void setFileData(FileData fileData) {
+ this.fileData = fileData;
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/to/TranslateTo.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/to/TranslateTo.java
new file mode 100644
index 0000000000..6c56715f79
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/to/TranslateTo.java
@@ -0,0 +1,132 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.datatypes.heattotosca.to;
+
+
+import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate;
+import org.openecomp.sdc.heat.datatypes.model.Resource;
+import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate;
+import org.openecomp.sdc.translator.services.heattotosca.TranslationContext;
+
+public class TranslateTo {
+ private String heatFileName;
+ private ServiceTemplate serviceTemplate;
+ private HeatOrchestrationTemplate heatOrchestrationTemplate;
+ private Resource resource;
+ private String resourceId;
+ private String translatedId;
+ private TranslationContext context;
+
+ public TranslateTo() {
+ }
+
+ /**
+ * Instantiates a new Translate to.
+ *
+ * @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 translatedId the translated id
+ * @param context the context
+ */
+ public TranslateTo(String heatFileName, ServiceTemplate serviceTemplate,
+ HeatOrchestrationTemplate heatOrchestrationTemplate, Resource resource,
+ String resourceId, String translatedId, TranslationContext context) {
+ this.heatFileName = heatFileName;
+ this.serviceTemplate = serviceTemplate;
+ this.heatOrchestrationTemplate = heatOrchestrationTemplate;
+ this.resource = resource;
+ this.resourceId = resourceId;
+ this.translatedId = translatedId;
+ this.context = context;
+ }
+
+ public String getHeatFileName() {
+ return heatFileName;
+ }
+
+ public void setHeatFileName(String heatFileName) {
+ this.heatFileName = heatFileName;
+ }
+
+ public ServiceTemplate getServiceTemplate() {
+ return serviceTemplate;
+ }
+
+ public void setServiceTemplate(ServiceTemplate serviceTemplate) {
+ this.serviceTemplate = serviceTemplate;
+ }
+
+ public HeatOrchestrationTemplate getHeatOrchestrationTemplate() {
+ return heatOrchestrationTemplate;
+ }
+
+ public void setHeatOrchestrationTemplate(HeatOrchestrationTemplate heatOrchestrationTemplate) {
+ this.heatOrchestrationTemplate = heatOrchestrationTemplate;
+ }
+
+ public Resource getResource() {
+ return resource;
+ }
+
+ public void setResource(Resource resource) {
+ this.resource = resource;
+ }
+
+ public String getResourceId() {
+ return resourceId;
+ }
+
+ public void setResourceId(String resourceId) {
+ this.resourceId = resourceId;
+ }
+
+ public String getTranslatedId() {
+ return translatedId;
+ }
+
+ public void setTranslatedId(String translatedId) {
+ this.translatedId = translatedId;
+ }
+
+ public TranslationContext getContext() {
+ return context;
+ }
+
+ public void setContext(TranslationContext context) {
+ this.context = context;
+ }
+
+ @Override
+ public String toString() {
+ return "TranslateTo{"
+ + "heatFileName='" + heatFileName + '\''
+ + ", serviceTemplate=" + serviceTemplate
+ + ", heatOrchestrationTemplate=" + heatOrchestrationTemplate
+ + ", resource=" + resource
+ + ", resourceId='" + resourceId + '\''
+ + ", translatedId='" + translatedId + '\''
+ + ", context=" + context
+ + '}';
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/to/TranslatedHeatResource.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/to/TranslatedHeatResource.java
new file mode 100644
index 0000000000..da46e56018
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/to/TranslatedHeatResource.java
@@ -0,0 +1,49 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.datatypes.heattotosca.to;
+
+import org.openecomp.sdc.heat.datatypes.model.Resource;
+
+public class TranslatedHeatResource {
+ private String translatedId;
+ private Resource heatResource;
+
+ public TranslatedHeatResource(String translatedId, Resource heatResource) {
+ this.translatedId = translatedId;
+ this.heatResource = heatResource;
+ }
+
+ public String getTranslatedId() {
+ return translatedId;
+ }
+
+ public void setTranslatedId(String translatedId) {
+ this.translatedId = translatedId;
+ }
+
+ public Resource getHeatResource() {
+ return heatResource;
+ }
+
+ public void setHeatResource(Resource heatResource) {
+ this.heatResource = heatResource;
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/impl/heattotosca/HeatToToscaTranslatorFactoryImpl.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/impl/heattotosca/HeatToToscaTranslatorFactoryImpl.java
new file mode 100644
index 0000000000..57f753f103
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/impl/heattotosca/HeatToToscaTranslatorFactoryImpl.java
@@ -0,0 +1,34 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.impl.heattotosca;
+
+import org.openecomp.core.translator.api.HeatToToscaTranslator;
+import org.openecomp.core.translator.factory.HeatToToscaTranslatorFactory;
+
+public class HeatToToscaTranslatorFactoryImpl extends HeatToToscaTranslatorFactory {
+
+ private static HeatToToscaTranslator INSTANCE = new HeatToToscaTranslatorImpl();
+
+ @Override
+ public HeatToToscaTranslator createInterface() {
+ return new HeatToToscaTranslatorImpl();
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/impl/heattotosca/HeatToToscaTranslatorImpl.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/impl/heattotosca/HeatToToscaTranslatorImpl.java
new file mode 100644
index 0000000000..0a6986816c
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/impl/heattotosca/HeatToToscaTranslatorImpl.java
@@ -0,0 +1,134 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.impl.heattotosca;
+
+import org.apache.commons.collections4.MapUtils;
+import org.openecomp.core.translator.api.HeatToToscaTranslator;
+import org.openecomp.core.translator.datatypes.TranslatorOutput;
+import org.openecomp.core.utilities.file.FileUtils;
+import org.openecomp.core.utilities.json.JsonUtil;
+import org.openecomp.core.validation.api.ValidationManager;
+import org.openecomp.core.validation.errors.Messages;
+import org.openecomp.core.validation.factory.ValidationManagerFactory;
+import org.openecomp.core.validation.types.MessageContainerUtil;
+import org.openecomp.sdc.common.utils.AsdcCommon;
+import org.openecomp.sdc.datatypes.error.ErrorLevel;
+import org.openecomp.sdc.datatypes.error.ErrorMessage;
+import org.openecomp.sdc.heat.datatypes.manifest.FileData;
+import org.openecomp.sdc.heat.datatypes.manifest.ManifestContent;
+import org.openecomp.sdc.heat.datatypes.manifest.ManifestFile;
+import org.openecomp.sdc.translator.services.heattotosca.TranslationContext;
+import org.openecomp.sdc.translator.services.heattotosca.TranslationService;
+
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class HeatToToscaTranslatorImpl implements HeatToToscaTranslator {
+
+ private TranslationContext translationContext = new TranslationContext();
+ private ValidationManager validationManager =
+ ValidationManagerFactory.getInstance().createInterface();
+ private boolean isValid = false;
+
+
+ @Override
+ public void addManifest(String name, byte[] content) {
+ ManifestContent manifestData = JsonUtil.json2Object(new String(content), ManifestContent.class);
+ ManifestFile manifest = new ManifestFile();
+ manifest.setName(name);
+ manifest.setContent(manifestData);
+ translationContext.setManifest(manifest);
+ translationContext.addFile(name, content);
+ validationManager.addFile(AsdcCommon.MANIFEST_NAME, content);
+ addFilesFromManifestToTranslationContextManifestFilesMap(manifestData.getData());
+ isValid = false;
+ }
+
+ @Override
+ public void addFile(String name, byte[] content) {
+ translationContext.addFile(name, content);
+ validationManager.addFile(name, content);
+ isValid = false;
+ }
+
+ @Override
+ public void addFile(String name, InputStream content) {
+ addFile(name, FileUtils.toByteArray(content));
+ }
+
+
+ @Override
+ public Map<String, List<ErrorMessage>> validate() {
+
+ Map<String, List<ErrorMessage>> errors = new HashMap<>();
+ if (translationContext.getManifest() == null) {
+ ErrorMessage.ErrorMessageUtil.addMessage(AsdcCommon.MANIFEST_NAME, errors)
+ .add(new ErrorMessage(ErrorLevel.ERROR, Messages.MANIFEST_NOT_EXIST.getErrorMessage()));
+ return errors;
+ }
+
+ if (MapUtils.isEmpty(errors)) {
+ errors = validationManager.validate();
+ }
+ if (MapUtils.isEmpty(errors)) {
+ isValid = true;
+ }
+ return errors;
+ }
+
+ @Override
+ public TranslatorOutput translate() {
+ TranslationService translationService = new TranslationService();
+ TranslatorOutput translatorOutput = new TranslatorOutput();
+ if (!isValid) {
+ Map<String, List<ErrorMessage>> errors = validate();
+
+ if (MapUtils.isNotEmpty(MessageContainerUtil.getMessageByLevel(ErrorLevel.ERROR, errors))) {
+ translatorOutput.setErrorMessages(errors);
+ return translatorOutput;
+ }
+ }
+
+ translatorOutput = translationService.translateHeatFiles(translationContext);
+ return translatorOutput;
+ }
+
+ @Override
+ public void addExternalArtifacts(String name, byte[] content) {
+ translationContext.addExternalArtifacts(name, content);
+ }
+
+ @Override
+ public void addExternalArtifacts(String name, InputStream content) {
+ addExternalArtifacts(name, FileUtils.toByteArray(content));
+ }
+
+ private void addFilesFromManifestToTranslationContextManifestFilesMap(
+ List<FileData> fileDataListFromManifest) {
+ for (FileData fileFromManfiest : fileDataListFromManifest) {
+ translationContext.addManifestFile(fileFromManfiest.getFile(), fileFromManfiest.getType());
+ }
+ }
+
+
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/Constants.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/Constants.java
new file mode 100644
index 0000000000..abd6c27a21
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/Constants.java
@@ -0,0 +1,60 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca;
+
+public class Constants {
+ //Service Template - Template Names
+ public static final String COMMON_GLOBAL_TEMPLATE_NAME = "CommonGlobalTypes";
+ public static final String CINDER_VOLUME_TEMPLATE_NAME = "CinderVolumeGlobalTypes";
+ public static final String CONTRAIL_VIRTUAL_NETWORK_TEMPLATE_NAME =
+ "ContrailVirtualNetworkGlobalType";
+ public static final String CONTRAIL_NETWORK_RULE_TEMPLATE_NAME = "ContrailNetworkRuleGlobalType";
+ public static final String CONTRAILV2_VIRTUAL_NETWORK_TEMPLATE_NAME =
+ "ContrailV2VirtualNetworkGlobalType";
+ public static final String CONTRAILV2_NETWORK_RULE_TEMPLATE_NAME =
+ "ContrailV2NetworkRuleGlobalType";
+ public static final String CONTRAILV2_VIRTUAL_MACHINE_INTERFACE_TEMPLATE_NAME =
+ "ContrailV2VirtualMachineInterfaceGlobalType";
+ public static final String NEUTRON_NET_TEMPLATE_NAME = "NeutronNetGlobalTypes";
+ public static final String NEUTRON_PORT_TEMPLATE_NAME = "NeutronPortGlobalTypes";
+ public static final String NEUTRON_SECURITY_RULES_TEMPLATE_NAME =
+ "NeutronSecurityRulesGlobalTypes";
+ public static final String NOVA_SERVER_TEMPLATE_NAME = "NovaServerGlobalTypes";
+ public static final String ABSTRACT_SUBSTITUTE_TEMPLATE_NAME = "AbstractSubstituteGlobalTypes";
+ public static final String GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME = "GlobalSubstitutionTypes";
+ public static final String CONTRAIL_COMPUTE_TEMPLATE_NAME = "ContrailComputeGlobalTypes";
+ public static final String CONTRAIL_PORT_TEMPLATE_NAME = "ContrailPortGlobalTypes";
+ public static final String CONTRAIL_ABSTRACT_SUBSTITUTE_TEMPLATE_NAME =
+ "ContrailAbstractSubstituteGlobalTypes";
+ //properties
+ public static final String MAX_INSTANCES_PROPERTY_NAME = "max_instances";
+ public static final String DESCRIPTION_PROPERTY_NAME = "description";
+ public static final String NAME_PROPERTY_NAME = "name";
+ public static final String RULES_PROPERTY_NAME = "rules";
+ public static final String SECURITY_GROUPS_PROPERTY_NAME = "security_groups";
+ public static final String PORT_PROPERTY_NAME = "port";
+ //General
+ public static final String PROP = "properties";
+ public static final String ATTR = "attributes";
+
+ private Constants() {
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/HeatToToscaUtil.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/HeatToToscaUtil.java
new file mode 100644
index 0000000000..f245a6dee6
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/HeatToToscaUtil.java
@@ -0,0 +1,503 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca;
+
+import org.apache.commons.collections4.CollectionUtils;
+import org.openecomp.core.utilities.yaml.YamlUtil;
+import org.openecomp.sdc.common.errors.CoreException;
+import org.openecomp.sdc.heat.datatypes.HeatBoolean;
+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.ToscaServiceModel;
+import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate;
+import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate;
+import org.openecomp.sdc.tosca.services.ToscaUtil;
+import org.openecomp.sdc.translator.datatypes.heattotosca.AttachedResourceId;
+import org.openecomp.sdc.translator.datatypes.heattotosca.ResourceReferenceType;
+import org.openecomp.sdc.translator.datatypes.heattotosca.to.FileDataCollection;
+import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo;
+import org.openecomp.sdc.translator.services.heattotosca.errors.ResourceNotFoundInHeatFileErrorBuilder;
+import org.openecomp.sdc.translator.services.heattotosca.mapping.TranslatorHeatToToscaFunctionConverter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.Collection;
+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.stream.Collectors;
+
+public class HeatToToscaUtil {
+
+ protected static Logger logger = LoggerFactory.getLogger(HeatToToscaUtil.class);
+
+
+ /**
+ * Build list of files to search optional.
+ *
+ * @param heatFileName the heat file name
+ * @param filesDataList the files data list
+ * @param types the types
+ * @return the optional
+ */
+ public static Optional<List<FileData>> buildListOfFilesToSearch(String heatFileName,
+ List<FileData> filesDataList,
+ FileData.Type... types) {
+ List<FileData> list = new ArrayList<>(filesDataList);
+ Optional<FileData> resourceFileData = HeatToToscaUtil.getFileData(heatFileName, filesDataList);
+ if (resourceFileData.isPresent() && Objects.nonNull(resourceFileData.get().getData())) {
+ list.addAll(resourceFileData.get().getData());
+ }
+ return Optional.ofNullable(HeatToToscaUtil.getFilteredListOfFileDataByTypes(list, types));
+ }
+
+ public static List<FileData> getFilteredListOfFileDataByTypes(List<FileData> filesToSearch,
+ FileData.Type... types) {
+ return filesToSearch.stream().filter(FileData.buildFileDataPredicateByType(types))
+ .collect(Collectors.toList());
+ }
+
+ /**
+ * Gets file data.
+ *
+ * @param heatFileName the heat file name
+ * @param fileDataList the file data list
+ * @return the file data
+ */
+ public static Optional<FileData> getFileData(String heatFileName,
+ Collection<FileData> fileDataList) {
+ for (FileData file : fileDataList) {
+ if (file.getFile().equals(heatFileName)) {
+ return Optional.of(file);
+ }
+ }
+ return Optional.empty();
+ }
+
+ static FileDataCollection getFileCollectionsByFilter(List<FileData> fileDataList,
+ Set<FileData.Type> typeFilter,
+ TranslationContext translationContext) {
+ FileDataCollection fileDataCollection = new FileDataCollection();
+ Map<String, FileData> filteredFiles = filterFileDataListByType(fileDataList, typeFilter);
+ Set<String> referenced = new HashSet<>();
+ List<String> filenames = extractFilenamesFromFileDataList(filteredFiles.values());
+
+ for (FileData fileData : filteredFiles.values()) {
+ String fileName = fileData.getFile();
+
+ if (FileData.isHeatFile(fileData.getType())) {
+ if (fileData.getBase() != null && fileData.getBase().equals(true)) {
+ fileDataCollection.addBaseFiles(fileData);
+ }
+ HeatOrchestrationTemplate heatOrchestrationTemplate = new YamlUtil()
+ .yamlToObject(translationContext.getFileContent(fileName),
+ HeatOrchestrationTemplate.class);
+ for (Resource resource : heatOrchestrationTemplate.getResources().values()) {
+ if (filenames.contains(resource.getType())) {
+ handleNestedFile(translationContext, fileDataCollection, filteredFiles, referenced,
+ resource.getType());
+ } else if (resource.getType()
+ .equals(HeatResourcesTypes.RESOURCE_GROUP_RESOURCE_TYPE.getHeatResource())) {
+ Object resourceDef =
+ resource.getProperties().get(HeatConstants.RESOURCE_DEF_PROPERTY_NAME);
+ Object innerTypeDef = ((Map) resourceDef).get("type");
+ if (innerTypeDef instanceof String) {
+ String internalResourceType = (String) innerTypeDef;
+ if (filenames.contains(internalResourceType)) {
+ handleNestedFile(translationContext, fileDataCollection, filteredFiles, referenced,
+ internalResourceType);
+ }
+ }
+ }
+ }
+
+ } else {
+ fileDataCollection.addArtifactFiles(fileData);
+ filteredFiles.remove(fileData.getFile());
+ }
+ }
+
+ referenced.forEach(filteredFiles::remove);
+ if (!CollectionUtils.isEmpty(fileDataCollection.getBaseFile())) {
+ for (FileData fileData : fileDataCollection.getBaseFile()) {
+ filteredFiles.remove(fileData.getFile());
+ }
+ }
+ fileDataCollection.setAddOnFiles(filteredFiles.values());
+ return fileDataCollection;
+ }
+
+ private static void handleNestedFile(TranslationContext translationContext,
+ FileDataCollection fileDataCollection,
+ Map<String, FileData> filteredFiles, Set<String> referenced,
+ String nestedFileName) {
+ referenced.add(nestedFileName);
+ fileDataCollection.addNestedFiles(filteredFiles.get(nestedFileName));
+ translationContext.getNestedHeatsFiles().add(nestedFileName);
+ }
+
+ private static Map<String, FileData> filterFileDataListByType(List<FileData> fileDataList,
+ Set<FileData.Type> typesToGet) {
+ Map<String, FileData> filtered = new HashMap<>();
+ fileDataList.stream().filter(file -> typesToGet.contains(file.getType()))
+ .forEach(file -> filtered.put(file.getFile(), file));
+ return filtered;
+ }
+
+ private static List<String> extractFilenamesFromFileDataList(Collection<FileData> fileDataList) {
+ return fileDataList.stream().map(FileData::getFile).collect(Collectors.toList());
+ }
+
+ /**
+ * Extract attached resource id optional.
+ *
+ * @param translateTo the translate to
+ * @param propertyName the property name
+ * @return the optional
+ */
+ public static Optional<AttachedResourceId> extractAttachedResourceId(TranslateTo translateTo,
+ String propertyName) {
+ Object propertyValue = translateTo.getResource().getProperties().get(propertyName);
+ if (propertyValue == null) {
+ return Optional.empty();
+ }
+ return extractAttachedResourceId(translateTo.getHeatFileName(),
+ translateTo.getHeatOrchestrationTemplate(), translateTo.getContext(), propertyValue);
+ }
+
+ /**
+ * Extract attached resource id optional.
+ *
+ * @param heatFileName the heat file name
+ * @param heatOrchestrationTemplate the heat orchestration template
+ * @param context the context
+ * @param propertyValue the property value
+ * @return the optional
+ */
+ public static Optional<AttachedResourceId> extractAttachedResourceId(String heatFileName,
+ HeatOrchestrationTemplate heatOrchestrationTemplate,
+ TranslationContext context,
+ Object propertyValue) {
+
+ Object entity;
+ Object translatedId;
+
+ if (Objects.isNull(propertyValue)) {
+ return Optional.empty();
+ }
+
+ ResourceReferenceType referenceType = ResourceReferenceType.OTHER;
+ if (propertyValue instanceof Map && !((Map) propertyValue).isEmpty()) {
+ Map<String, Object> propMap = (Map) propertyValue;
+ Map.Entry<String, Object> entry = propMap.entrySet().iterator().next();
+ entity = entry.getValue();
+ String key = entry.getKey();
+ switch (key) {
+ case "get_resource":
+ referenceType = ResourceReferenceType.GET_RESOURCE;
+ break;
+ case "get_param":
+ referenceType = ResourceReferenceType.GET_PARAM;
+ break;
+ case "get_attr":
+ referenceType = ResourceReferenceType.GET_ATTR;
+ break;
+ default:
+ }
+ translatedId = TranslatorHeatToToscaFunctionConverter
+ .getToscaFunction(entry.getKey(), entry.getValue(), heatFileName,
+ heatOrchestrationTemplate, null, context);
+ if (translatedId instanceof String
+ && !TranslatorHeatToToscaFunctionConverter.isResourceSupported((String) translatedId)) {
+ translatedId = null;
+ }
+
+ } else {
+ translatedId = propertyValue;
+ entity = propertyValue;
+ }
+
+ return Optional.of(new AttachedResourceId(translatedId, entity, referenceType));
+ }
+
+ /**
+ * Gets contrail attached heat resource id.
+ *
+ * @param attachedResource the attached resource
+ * @return the contrail attached heat resource id
+ */
+ public static Optional<String> getContrailAttachedHeatResourceId(
+ AttachedResourceId attachedResource) {
+ if (attachedResource == null) {
+ return Optional.empty();
+ }
+
+ if (attachedResource.isGetResource()) {
+ return Optional.of((String) attachedResource.getEntityId());
+ }
+ if (attachedResource.isGetAttr() && (attachedResource.getEntityId() instanceof List)
+ && ((List) attachedResource.getEntityId()).size() > 1
+ && ((List) attachedResource.getEntityId()).get(1).equals("fq_name")) {
+ return Optional.of((String) ((List) attachedResource.getEntityId()).get(0));
+ }
+
+ return Optional.empty();
+ }
+
+ /**
+ * Extract property optional.
+ *
+ * @param propertyValue the property value
+ * @return the optional
+ */
+ public static Optional<AttachedResourceId> extractProperty(Object propertyValue) {
+
+ Object entity;
+ if (Objects.isNull(propertyValue)) {
+ return Optional.empty();
+ }
+
+ ResourceReferenceType referenceType = ResourceReferenceType.OTHER;
+ if (propertyValue instanceof Map && !((Map) propertyValue).isEmpty()) {
+ Map<String, Object> propMap = (Map) propertyValue;
+ Map.Entry<String, Object> entry = propMap.entrySet().iterator().next();
+ entity = entry.getValue();
+ String key = entry.getKey();
+ switch (key) {
+ case "get_resource":
+ referenceType = ResourceReferenceType.GET_RESOURCE;
+ break;
+ case "get_param":
+ referenceType = ResourceReferenceType.GET_PARAM;
+ break;
+ case "get_attr":
+ referenceType = ResourceReferenceType.GET_ATTR;
+ break;
+ default:
+ }
+
+ } else {
+ entity = propertyValue;
+ }
+
+ return Optional.of(new AttachedResourceId(null, entity, referenceType));
+ }
+
+ /**
+ * Map boolean.
+ *
+ * @param nodeTemplate the node template
+ * @param propertyKey the property key
+ */
+ public static void mapBoolean(NodeTemplate nodeTemplate, String propertyKey) {
+ Object value = nodeTemplate.getProperties().get(propertyKey);
+ if (value != null && !(value instanceof Map)) {
+ nodeTemplate.getProperties().put(propertyKey, HeatBoolean.eval(value));
+ }
+ }
+
+ /**
+ * Map boolean list.
+ *
+ * @param nodeTemplate the node template
+ * @param propertyListKey the property list key
+ */
+ public static void mapBooleanList(NodeTemplate nodeTemplate, String propertyListKey) {
+ Object listValue = nodeTemplate.getProperties().get(propertyListKey);
+ if (listValue instanceof List) {
+ List booleanList = ((List) listValue);
+ for (int i = 0; i < booleanList.size(); i++) {
+ Object value = booleanList.get(i);
+ if (value != null && !(value instanceof Map)) {
+ booleanList.set(i, HeatBoolean.eval(value));
+ }
+ }
+ }
+ }
+
+
+ public static boolean isYmlFileType(String filename) {
+ return (filename.indexOf("yaml") > 0 || filename.indexOf("yml") > 0);
+ }
+
+ /**
+ * Is nested resource boolean.
+ *
+ * @param resource the resource
+ * @return the boolean
+ */
+ public static boolean isNestedResource(Resource resource) {
+ String resourceType = resource.getType();
+
+ if (resourceType.equals(HeatResourcesTypes.RESOURCE_GROUP_RESOURCE_TYPE.getHeatResource())) {
+ Object resourceDef = resource.getProperties().get(HeatConstants.RESOURCE_DEF_PROPERTY_NAME);
+ String internalResourceType = (String) ((Map) resourceDef).get("type");
+ if (isYamlFile(internalResourceType)) {
+ return true;
+ }
+ } else if (isYamlFile(resourceType)) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Gets nested file.
+ *
+ * @param resource the resource
+ * @return the nested file
+ */
+ public static Optional<String> getNestedFile(Resource resource) {
+ if (!isNestedResource(resource)) {
+ return Optional.empty();
+ }
+ String resourceType = resource.getType();
+ if (resourceType.equals(HeatResourcesTypes.RESOURCE_GROUP_RESOURCE_TYPE.getHeatResource())) {
+ Object resourceDef = resource.getProperties().get(HeatConstants.RESOURCE_DEF_PROPERTY_NAME);
+ String internalResourceType = (String) ((Map) resourceDef).get("type");
+ return Optional.of(internalResourceType);
+ } else {
+ return Optional.of(resourceType);
+ }
+ }
+
+ private static boolean isYamlFile(String fileName) {
+ return fileName.endsWith(".yaml") || fileName.endsWith(".yml");
+ }
+
+ /**
+ * Gets resource.
+ *
+ * @param heatOrchestrationTemplate the heat orchestration template
+ * @param resourceId the resource id
+ * @param heatFileName the heat file name
+ * @return the resource
+ */
+ public static Resource getResource(HeatOrchestrationTemplate heatOrchestrationTemplate,
+ String resourceId, String heatFileName) {
+ Resource resource = heatOrchestrationTemplate.getResources().get(resourceId);
+ if (resource == null) {
+ throw new CoreException(
+ new ResourceNotFoundInHeatFileErrorBuilder(resourceId, heatFileName).build());
+ }
+ return resource;
+ }
+
+ public static boolean isHeatFileNested(TranslateTo translateTo, String heatFileName) {
+ return translateTo.getContext().getNestedHeatsFiles().contains(heatFileName);
+ }
+
+ /**
+ * Extract contrail get resource attached heat resource id string.
+ *
+ * @param propertyValue the property value
+ * @return the string
+ */
+ public static String extractContrailGetResourceAttachedHeatResourceId(Object propertyValue) {
+ if (propertyValue == null) {
+ return null;
+ }
+
+ Object value;
+ if (propertyValue instanceof Map) {
+ if (((Map) propertyValue).containsKey("get_attr")) {
+ value = ((Map) propertyValue).get("get_attr");
+ if (value instanceof List) {
+ if (((List) value).size() == 2 && ((List) value).get(1).equals("fq_name")) {
+ if (((List) value).get(0) instanceof String) {
+ return (String) ((List) value).get(0);
+ } else {
+ logger.warn("invalid format of 'get_attr' function - " + propertyValue.toString());
+ }
+ }
+ }
+ } else if (((Map) propertyValue).containsKey("get_resource")) {
+ value = ((Map) propertyValue).get("get_resource");
+ if (value instanceof String) {
+ return (String) value;
+ } else {
+ logger.warn("invalid format of 'get_resource' function - " + propertyValue.toString());
+ }
+ } else {
+ Collection<Object> valCollection = ((Map) propertyValue).values();
+ for (Object entryValue : valCollection) {
+ String ret = extractContrailGetResourceAttachedHeatResourceId(entryValue);
+ if (ret != null) {
+ return ret;
+ }
+
+ }
+ }
+ } else if (propertyValue instanceof List) {
+ for (Object prop : (List) propertyValue) {
+ String ret = extractContrailGetResourceAttachedHeatResourceId(prop);
+ if (ret != null) {
+ return ret;
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Gets tosca service model.
+ *
+ * @param translateTo the translate to
+ * @return the tosca service model
+ */
+ public static ToscaServiceModel getToscaServiceModel(TranslateTo translateTo) {
+ Map<String, ServiceTemplate> serviceTemplates =
+ new HashMap<>(translateTo.getContext().getGlobalServiceTemplates());
+ Collection<ServiceTemplate> tmpServiceTemplates =
+ translateTo.getContext().getTranslatedServiceTemplates().values();
+ for (ServiceTemplate serviceTemplate : tmpServiceTemplates) {
+ ToscaUtil.addServiceTemplateToMapWithKeyFileName(serviceTemplates, serviceTemplate);
+ }
+ return new ToscaServiceModel(null, serviceTemplates,
+ ToscaUtil.getServiceTemplateFileName(translateTo.getResource().getType()));
+ }
+
+ /**
+ * Gets service template from context.
+ *
+ * @param serviceTemplateFileName the service template file name
+ * @param context the context
+ * @return the service template from context
+ */
+ public static Optional<ServiceTemplate> getServiceTemplateFromContext(
+ String serviceTemplateFileName, TranslationContext context) {
+ for (ServiceTemplate serviceTemplate : context.getTranslatedServiceTemplates().values()) {
+ if (ToscaUtil.getServiceTemplateFileName(serviceTemplate).equals(serviceTemplateFileName)) {
+ return Optional.of(serviceTemplate);
+ }
+ }
+
+ 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/ResourceTranslation.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ResourceTranslation.java
new file mode 100644
index 0000000000..231eb42c03
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ResourceTranslation.java
@@ -0,0 +1,37 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca;
+
+
+import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate;
+import org.openecomp.sdc.heat.datatypes.model.Resource;
+import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate;
+
+import java.util.Optional;
+
+public interface ResourceTranslation {
+
+ //return the Id of translated object (NodeTemplate, RelationshipTemplate and etc)
+ Optional<String> translateResource(String heatFileName, ServiceTemplate serviceTemplate,
+ HeatOrchestrationTemplate heatOrchestrationTemplate,
+ Resource resource, String resourceId,
+ TranslationContext context);
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ResourceTranslationFactory.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ResourceTranslationFactory.java
new file mode 100644
index 0000000000..730c2ddd7a
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ResourceTranslationFactory.java
@@ -0,0 +1,107 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca;
+
+
+import org.openecomp.sdc.heat.datatypes.model.HeatResourcesTypes;
+import org.openecomp.sdc.heat.datatypes.model.Resource;
+
+import org.openecomp.sdc.translator.services.heattotosca.impl.ResourceTranslationBase;
+import org.openecomp.sdc.translator.services.heattotosca.impl.ResourceTranslationCinderVolumeAttachmentImpl;
+import org.openecomp.sdc.translator.services.heattotosca.impl.ResourceTranslationCinderVolumeImpl;
+import org.openecomp.sdc.translator.services.heattotosca.impl.ResourceTranslationContrailAttachPolicyImpl;
+import org.openecomp.sdc.translator.services.heattotosca.impl.ResourceTranslationContrailNetworkPolicyImpl;
+import org.openecomp.sdc.translator.services.heattotosca.impl.ResourceTranslationContrailServiceInstanceImpl;
+import org.openecomp.sdc.translator.services.heattotosca.impl.ResourceTranslationContrailServiceTemplateImpl;
+import org.openecomp.sdc.translator.services.heattotosca.impl.ResourceTranslationContrailV2NetworkPolicyImpl;
+import org.openecomp.sdc.translator.services.heattotosca.impl.ResourceTranslationContrailV2VirtualNetworkImpl;
+import org.openecomp.sdc.translator.services.heattotosca.impl.ResourceTranslationContrailV2VmInterfaceImpl;
+import org.openecomp.sdc.translator.services.heattotosca.impl.ResourceTranslationContrailVirtualNetworkImpl;
+import org.openecomp.sdc.translator.services.heattotosca.impl.ResourceTranslationDefaultImpl;
+import org.openecomp.sdc.translator.services.heattotosca.impl.ResourceTranslationNestedImpl;
+import org.openecomp.sdc.translator.services.heattotosca.impl.ResourceTranslationNeutronNetImpl;
+import org.openecomp.sdc.translator.services.heattotosca.impl.ResourceTranslationNeutronPortImpl;
+import org.openecomp.sdc.translator.services.heattotosca.impl.ResourceTranslationNeutronSecurityGroupImpl;
+import org.openecomp.sdc.translator.services.heattotosca.impl.ResourceTranslationNeutronSubnetImpl;
+import org.openecomp.sdc.translator.services.heattotosca.impl.ResourceTranslationNovaServerGroupsImpl;
+import org.openecomp.sdc.translator.services.heattotosca.impl.ResourceTranslationNovaServerImpl;
+import org.openecomp.sdc.translator.services.heattotosca.impl.ResourceTranslationResourceGroupImpl;
+
+import java.util.Objects;
+
+public class ResourceTranslationFactory {
+
+ /**
+ * Gets instance.
+ *
+ * @param resource the resource
+ * @return the instance
+ */
+ public static ResourceTranslationBase getInstance(Resource resource) {
+ HeatResourcesTypes heatResource = HeatResourcesTypes.findByHeatResource(resource.getType());
+ if (Objects.isNull(heatResource)) {
+ if (HeatToToscaUtil.isYmlFileType(resource.getType())) {
+ return new ResourceTranslationNestedImpl();
+ }
+ return new ResourceTranslationDefaultImpl();
+ }
+ switch (heatResource) {
+ case NOVA_SERVER_RESOURCE_TYPE:
+ return new ResourceTranslationNovaServerImpl();
+ case NOVA_SERVER_GROUP_RESOURCE_TYPE:
+ return new ResourceTranslationNovaServerGroupsImpl();
+ case NEUTRON_SECURITY_GROUP_RESOURCE_TYPE:
+ return new ResourceTranslationNeutronSecurityGroupImpl();
+ case NEUTRON_PORT_RESOURCE_TYPE:
+ return new ResourceTranslationNeutronPortImpl();
+ case CONTRAIL_VIRTUAL_NETWORK_RESOURCE_TYPE:
+ return new ResourceTranslationContrailVirtualNetworkImpl();
+ case CONTRAIL_V2_VIRTUAL_NETWORK_RESOURCE_TYPE:
+ return new ResourceTranslationContrailV2VirtualNetworkImpl();
+ case CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE:
+ return new ResourceTranslationContrailV2VmInterfaceImpl();
+ case CINDER_VOLUME_RESOURCE_TYPE:
+ return new ResourceTranslationCinderVolumeImpl();
+ case CINDER_VOLUME_ATTACHMENT_RESOURCE_TYPE:
+ return new ResourceTranslationCinderVolumeAttachmentImpl();
+ case NEUTRON_NET_RESOURCE_TYPE:
+ return new ResourceTranslationNeutronNetImpl();
+ case NEUTRON_SUBNET_RESOURCE_TYPE:
+ return new ResourceTranslationNeutronSubnetImpl();
+ case CONTRAIL_NETWORK_RULE_RESOURCE_TYPE:
+ return new ResourceTranslationContrailNetworkPolicyImpl();
+ case CONTRAIL_V2_NETWORK_RULE_RESOURCE_TYPE:
+ return new ResourceTranslationContrailV2NetworkPolicyImpl();
+ case CONTRAIL_NETWORK_ATTACH_RULE_RESOURCE_TYPE:
+ return new ResourceTranslationContrailAttachPolicyImpl();
+ case RESOURCE_GROUP_RESOURCE_TYPE:
+ return new ResourceTranslationResourceGroupImpl();
+ case CONTRAIL_SERVICE_TEMPLATE:
+ return new ResourceTranslationContrailServiceTemplateImpl();
+ case CONTRAIL_SERVICE_INSTANCE:
+ return new ResourceTranslationContrailServiceInstanceImpl();
+ default:
+ return new ResourceTranslationDefaultImpl();
+ }
+ }
+
+
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/TranslationContext.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/TranslationContext.java
new file mode 100644
index 0000000000..a242eda3f0
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/TranslationContext.java
@@ -0,0 +1,172 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca;
+
+import org.openecomp.core.utilities.file.FileContentHandler;
+import org.openecomp.core.utilities.file.FileUtils;
+import org.openecomp.core.utilities.json.JsonUtil;
+import org.openecomp.sdc.common.utils.AsdcCommon;
+import org.openecomp.sdc.heat.datatypes.manifest.FileData;
+import org.openecomp.sdc.heat.datatypes.manifest.ManifestFile;
+import org.openecomp.sdc.heat.datatypes.model.Resource;
+import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate;
+import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslatedHeatResource;
+import org.openecomp.sdc.translator.services.heattotosca.globaltypes.GlobalTypesGenerator;
+
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+
+public class TranslationContext {
+
+
+ private static Map<String, Map<String, Map<String, String>>> translationMapping;
+ private static Map<String, ServiceTemplate> globalServiceTemplates;
+
+ static {
+
+ String propertyFileName = AsdcCommon.HEAT_TO_TOSCA_MAPPING_CONF;
+ InputStream is = FileUtils.getFileInputStream(propertyFileName);
+ translationMapping = JsonUtil.json2Object(is, Map.class);
+ globalServiceTemplates = GlobalTypesGenerator.getGlobalTypesServiceTemplate();
+ }
+
+ private ManifestFile manifest;
+
+ private FileContentHandler files = new FileContentHandler();
+
+ private Map<String, FileData.Type> manifestFiles = new HashMap<>();
+ //Key - file name, value - file type
+ private Set<String> nestedHeatsFiles = new HashSet<>();
+ private FileContentHandler externalArtifacts = new FileContentHandler();
+
+ private Map<String, Set<String>> translatedResources = new HashMap<>();
+ // Key - heat file name,value - set of heat resource ids which were translated
+ private Map<String, Set<String>> heatStackGroupMembers = new HashMap<>();
+ // Key - heat file name, value - translated Node template id
+ private Map<String, Map<String, String>> translatedIds = new HashMap<>();
+ // Key - heat file name, value - Map with Key - heat resource Id, Value - tosca entity template id
+ private Map<String, ServiceTemplate> translatedServiceTemplates = new HashMap<>();
+ // key - service template type, value - translated service templates
+ private Map<String, TranslatedHeatResource> heatSharedResourcesByParam = new HashMap<>();
+ //key - heat param name, value - shared resource data
+
+ public void addManifestFile(String fileName, FileData.Type fileType) {
+ this.manifestFiles.put(fileName, fileType);
+ }
+
+ public Set<String> getNestedHeatsFiles() {
+ return nestedHeatsFiles;
+ }
+
+ public Map<String, Set<String>> getHeatStackGroupMembers() {
+ return heatStackGroupMembers;
+ }
+
+ public FileContentHandler getFiles() {
+ return files;
+ }
+
+ public void setFiles(Map<String, byte[]> files) {
+ this.files.putAll(files);
+ }
+
+ public InputStream getFileContent(String fileName) {
+ return files.getFileContent(fileName);
+ }
+
+ public void addFile(String name, byte[] content) {
+ files.addFile(name, content);
+ }
+
+ public ManifestFile getManifest() {
+ return manifest;
+ }
+
+ public void setManifest(ManifestFile manifest) {
+ this.manifest = manifest;
+ }
+
+ public Map<String, Set<String>> getTranslatedResources() {
+ return translatedResources;
+ }
+
+ public Map<String, Map<String, String>> getTranslatedIds() {
+ return translatedIds;
+ }
+
+ // get tosca name from mapping configuration file
+ //element type - parameter/attribute
+ // element name - heat parameter/attribute name
+ //return value - tosca parameter/attribute name
+ public String getElementMapping(String resourceType, String elementType, String elementName) {
+ return translationMapping.get(resourceType).get(elementType).get(elementName);
+ }
+
+ public Map<String, String> getElementMapping(String resourceType, String elementType) {
+ return translationMapping.get(resourceType).get(elementType);
+ }
+
+ public Set<String> getElementSet(String resourceType, String elementType) {
+ return translationMapping.get(resourceType).get(elementType).keySet();
+ }
+
+ public Map<String, ServiceTemplate> getTranslatedServiceTemplates() {
+ return translatedServiceTemplates;
+ }
+
+ public ServiceTemplate getGlobalSubstitutionServiceTemplate() {
+ return getTranslatedServiceTemplates().get(Constants.GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME);
+ }
+
+ public FileContentHandler getExternalArtifacts() {
+ return externalArtifacts;
+ }
+
+ public void addExternalArtifacts(String name, byte[] content) {
+ this.externalArtifacts.addFile(name, content);
+ }
+
+
+ public Map<String, TranslatedHeatResource> getHeatSharedResourcesByParam() {
+ return heatSharedResourcesByParam;
+ }
+
+ public void addHeatSharedResourcesByParam(String parameterName, String resourceId,
+ Resource resource) {
+ this.addHeatSharedResourcesByParam(parameterName,
+ new TranslatedHeatResource(resourceId, resource));
+ }
+
+ public void addHeatSharedResourcesByParam(String parameterName,
+ TranslatedHeatResource translatedHeatResource) {
+ this.heatSharedResourcesByParam.put(parameterName, translatedHeatResource);
+ }
+
+ public Map<String, ServiceTemplate> getGlobalServiceTemplates() {
+ return globalServiceTemplates;
+ }
+
+
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/TranslationService.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/TranslationService.java
new file mode 100644
index 0000000000..1d90d8b2af
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/TranslationService.java
@@ -0,0 +1,344 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca;
+
+import org.openecomp.core.translator.datatypes.TranslatorOutput;
+import org.openecomp.core.utilities.file.FileContentHandler;
+import org.openecomp.core.utilities.file.FileUtils;
+import org.openecomp.core.utilities.yaml.YamlUtil;
+import org.openecomp.sdc.common.errors.CoreException;
+import org.openecomp.sdc.heat.datatypes.manifest.FileData;
+import org.openecomp.sdc.heat.datatypes.model.Environment;
+import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate;
+import org.openecomp.sdc.heat.datatypes.model.Output;
+import org.openecomp.sdc.heat.datatypes.model.Resource;
+import org.openecomp.sdc.heat.datatypes.structure.ValidationStructureList;
+import org.openecomp.sdc.heat.services.tree.HeatTreeManager;
+import org.openecomp.sdc.heat.services.tree.HeatTreeManagerUtil;
+import org.openecomp.sdc.tosca.datatypes.ToscaGroupType;
+import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
+import org.openecomp.sdc.tosca.datatypes.model.GroupDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.Metadata;
+import org.openecomp.sdc.tosca.datatypes.model.ParameterDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate;
+import org.openecomp.sdc.tosca.datatypes.model.TopologyTemplate;
+import org.openecomp.sdc.tosca.services.ToscaConstants;
+import org.openecomp.sdc.tosca.services.ToscaFileOutputService;
+import org.openecomp.sdc.tosca.services.ToscaUtil;
+import org.openecomp.sdc.tosca.services.impl.ToscaFileOutputServiceCsarImpl;
+import org.openecomp.sdc.translator.datatypes.heattotosca.AttachedResourceId;
+import org.openecomp.sdc.translator.datatypes.heattotosca.to.FileDataCollection;
+import org.openecomp.sdc.translator.services.heattotosca.errors.ResourceNotFoundInHeatFileErrorBuilder;
+import org.openecomp.sdc.translator.services.heattotosca.globaltypes.GlobalTypesGenerator;
+import org.openecomp.sdc.translator.services.heattotosca.mapping.TranslatorHeatToToscaParameterConverter;
+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;
+
+
+public class TranslationService {
+
+ protected static Logger logger = LoggerFactory.getLogger(TranslationService.class);
+
+ /**
+ * Gets types to process by translator.
+ *
+ * @return the types to process by translator
+ */
+ public static Set<FileData.Type> getTypesToProcessByTranslator() {
+ Set<FileData.Type> types = new HashSet<>();
+ types.add(FileData.Type.HEAT);
+ types.add(FileData.Type.HEAT_VOL);
+ return types;
+ }
+
+ /**
+ * Translate heat files translator output.
+ *
+ * @param translationContext the translation context
+ * @return the translator output
+ */
+ public TranslatorOutput translateHeatFiles(TranslationContext translationContext) {
+ ServiceTemplate mainServiceTemplate = createMainServiceTemplate(translationContext);
+ List<FileData> fileDataList = translationContext.getManifest().getContent().getData();
+ FileDataCollection fileDataCollection = HeatToToscaUtil.getFileCollectionsByFilter(fileDataList,
+ TranslationService.getTypesToProcessByTranslator(), translationContext);
+
+ if (fileDataCollection.getBaseFile() != null) {
+ for (FileData fileData : fileDataCollection.getBaseFile()) {
+ translateHeatFile(mainServiceTemplate, fileData, translationContext);
+ }
+ }
+ if (fileDataCollection.getAddOnFiles() != null) {
+ for (FileData fileData : fileDataCollection.getAddOnFiles()) {
+ translateHeatFile(mainServiceTemplate, fileData, translationContext);
+ }
+ }
+
+ ToscaServiceModel toscaServiceModel =
+ createToscaServiceModel(mainServiceTemplate, translationContext);
+
+ TranslatorOutput translatorOutput = new TranslatorOutput();
+ translatorOutput.setToscaServiceModel(toscaServiceModel);
+ return translatorOutput;
+ }
+
+ private ToscaServiceModel createToscaServiceModel(ServiceTemplate entryDefinitionServiceTemplate,
+ TranslationContext translationContext) {
+ return new ToscaServiceModel(getCsarArtifactFiles(translationContext),
+ getServiceTemplates(translationContext),
+ ToscaUtil.getServiceTemplateFileName(entryDefinitionServiceTemplate));
+ }
+
+ private Map<String, ServiceTemplate> getServiceTemplates(TranslationContext translationContext) {
+ List<ServiceTemplate> serviceTemplates = new ArrayList<>();
+ serviceTemplates.addAll(GlobalTypesGenerator.getGlobalTypesServiceTemplate().values());
+ serviceTemplates.addAll(translationContext.getTranslatedServiceTemplates().values());
+ Map<String, ServiceTemplate> serviceTemplatesMap = new HashMap<>();
+
+ for (ServiceTemplate template : serviceTemplates) {
+ serviceTemplatesMap.put(ToscaUtil.getServiceTemplateFileName(template), template);
+ }
+ return serviceTemplatesMap;
+ }
+
+ private FileContentHandler getCsarArtifactFiles(TranslationContext translationContext) {
+ FileContentHandler artifactFiles = new FileContentHandler();
+ artifactFiles.setFiles(translationContext.getFiles());
+ artifactFiles.setFiles(translationContext.getExternalArtifacts());
+
+ HeatTreeManager heatTreeManager =
+ HeatTreeManagerUtil.initHeatTreeManager(translationContext.getFiles());
+ heatTreeManager.createTree();
+ ValidationStructureList validationStructureList =
+ new ValidationStructureList(heatTreeManager.getTree());
+ byte[] validationStructureFile =
+ FileUtils.convertToBytes(validationStructureList, FileUtils.FileExtension.JSON);
+ artifactFiles.addFile("HEAT.meta", validationStructureFile);
+
+ return artifactFiles;
+ }
+
+ private ServiceTemplate createMainServiceTemplate(TranslationContext translationContext) {
+ ServiceTemplate mainServiceTemplate = new ServiceTemplate();
+ translationContext.getTranslatedServiceTemplates().put("Main", mainServiceTemplate);
+ Metadata templateMetadata = new Metadata();
+ templateMetadata.setTemplate_name("Main");
+ mainServiceTemplate.setTosca_definitions_version(ToscaConstants.TOSCA_DEFINITIONS_VERSION);
+ mainServiceTemplate.setMetadata(templateMetadata);
+ mainServiceTemplate.setTopology_template(new TopologyTemplate());
+ mainServiceTemplate.setImports(GlobalTypesGenerator.getGlobalTypesImportList());
+
+ return mainServiceTemplate;
+ }
+
+ /**
+ * Translate heat file.
+ *
+ * @param serviceTemplate the service template
+ * @param heatFileData the heat file data
+ * @param context the context
+ */
+ public void translateHeatFile(ServiceTemplate serviceTemplate, FileData heatFileData,
+ TranslationContext context) {
+ String heatFileName = heatFileData.getFile();
+ HeatOrchestrationTemplate heatOrchestrationTemplate = new YamlUtil()
+ .yamlToObject(context.getFileContent(heatFileName), HeatOrchestrationTemplate.class);
+
+ translateInputParameters(serviceTemplate, heatOrchestrationTemplate, heatFileData, context,
+ heatFileName);
+ translateResources(heatFileName, serviceTemplate, heatOrchestrationTemplate, context);
+ translateOutputParameters(serviceTemplate, heatOrchestrationTemplate, heatFileData,
+ heatFileName, context);
+ createHeatStackGroup(serviceTemplate, heatFileData, heatOrchestrationTemplate, context);
+
+ if (Objects.nonNull(heatFileData.getData())) {
+ heatFileData.getData().stream().filter(data -> data.getType() == FileData.Type.HEAT_VOL)
+ .forEach(data -> translateHeatFile(serviceTemplate, data, context));
+ }
+ }
+
+ private void createHeatStackGroup(ServiceTemplate serviceTemplate, FileData heatFileData,
+ HeatOrchestrationTemplate heatOrchestrationTemplate,
+ TranslationContext context) {
+ ToscaFileOutputService toscaFileOutputService = new ToscaFileOutputServiceCsarImpl();
+ String fileName = heatFileData.getFile();
+ final String fileNameWoExtension =
+ FileUtils.getFileWithoutExtention(fileName);//.heatFileData.getFile().split("\\.")[0];
+
+ GroupDefinition groupDefinition = new GroupDefinition();
+ groupDefinition.setType(ToscaGroupType.HEAT_STACK.getDisplayName());
+ groupDefinition.setProperties(new HashMap<>());
+ groupDefinition.getProperties()
+ .put("heat_file", "../" + toscaFileOutputService.getArtifactsFolderName() + "/" + fileName);
+ String hotDescription = heatOrchestrationTemplate.getDescription();
+ if (hotDescription != null && !hotDescription.isEmpty()) {
+ groupDefinition.getProperties().put(Constants.DESCRIPTION_PROPERTY_NAME, hotDescription);
+ }
+ groupDefinition.setMembers(new ArrayList<>());
+ Map<String, Set<String>> heatStackGroupMembers = context.getHeatStackGroupMembers();
+ if (heatStackGroupMembers.get(fileName) == null) {
+ return; //not creating a group when no resources are present in the heat input
+ }
+ groupDefinition.getMembers().addAll(heatStackGroupMembers.get(fileName));
+ if (serviceTemplate.getTopology_template().getGroups() == null) {
+ Map<String, GroupDefinition> groups = new HashMap<>();
+ serviceTemplate.getTopology_template().setGroups(groups);
+ }
+ serviceTemplate.getTopology_template().getGroups().put(fileNameWoExtension, groupDefinition);
+ }
+
+ private void translateInputParameters(ServiceTemplate serviceTemplate,
+ HeatOrchestrationTemplate heatOrchestrationTemplate,
+ FileData heatFileData, TranslationContext context,
+ String heatFileName) {
+
+ if (heatOrchestrationTemplate.getParameters() == null) {
+ return;
+ }
+
+ Map<String, ParameterDefinition> parameterDefinitionMap =
+ TranslatorHeatToToscaParameterConverter
+ .parameterConverter(heatOrchestrationTemplate.getParameters(),
+ heatOrchestrationTemplate, heatFileName, context);
+ Environment heatEnvFile = getHeatEnvFile(heatFileData, context);
+ Map<String, Object> parameters = heatEnvFile.getParameters();
+ Object parameterValue;
+ if (parameters != null) {
+ for (Map.Entry<String, ParameterDefinition> entry : parameterDefinitionMap.entrySet()) {
+ String paramName = entry.getKey();
+ parameterValue = parameters.get(paramName);
+ if (parameterValue != null) {
+ entry.getValue().set_default(TranslatorHeatToToscaParameterConverter
+ .getToscaParameterDefaultValue(parameterValue, entry.getValue().getType(),
+ heatFileName, heatOrchestrationTemplate, context));
+ }
+ }
+ }
+
+ Map<String, ParameterDefinition> inputs = serviceTemplate.getTopology_template().getInputs();
+ if (Objects.isNull(inputs)) {
+ serviceTemplate.getTopology_template().setInputs(parameterDefinitionMap);
+ } else {
+ inputs.putAll(parameterDefinitionMap);
+ }
+ }
+
+ private void translateOutputParameters(ServiceTemplate serviceTemplate,
+ HeatOrchestrationTemplate heatOrchestrationTemplate,
+ FileData heatFileData, String heatFileName,
+ TranslationContext context) {
+ if (heatOrchestrationTemplate.getOutputs() == null) {
+ return;
+ }
+ Map<String, ParameterDefinition> parameterDefinitionMap =
+ TranslatorHeatToToscaParameterConverter
+ .parameterOutputConverter(heatOrchestrationTemplate.getOutputs(),
+ heatOrchestrationTemplate, heatFileName, context);
+ if (serviceTemplate.getTopology_template().getOutputs() != null) {
+ serviceTemplate.getTopology_template().getOutputs().putAll(parameterDefinitionMap);
+ } else {
+ serviceTemplate.getTopology_template().setOutputs(parameterDefinitionMap);
+ }
+
+ if (heatFileData.getBase() != null && heatFileData.getBase().equals(true)) {
+ updateSharedResources(serviceTemplate, heatFileName, heatOrchestrationTemplate,
+ heatOrchestrationTemplate.getOutputs(), context);
+ }
+ }
+
+ private void updateSharedResources(ServiceTemplate serviceTemplate, String heatFileName,
+ HeatOrchestrationTemplate heatOrchestrationTemplate,
+ Map<String, Output> outputs, TranslationContext context) {
+ for (Map.Entry<String, Output> paramName : outputs.entrySet()) {
+ Optional<AttachedResourceId> attachedSharedResourceId = HeatToToscaUtil
+ .extractAttachedResourceId(heatFileName, heatOrchestrationTemplate, context,
+ paramName.getValue().getValue());
+ if (attachedSharedResourceId.isPresent() && attachedSharedResourceId.get().isGetResource()
+ && attachedSharedResourceId.get().getTranslatedId() != null) {
+ String sharedTranslatedResourceId =
+ attachedSharedResourceId.get().getTranslatedId().toString();
+ updateSharedResource(serviceTemplate, context, paramName, sharedTranslatedResourceId,
+ heatOrchestrationTemplate.getResources()
+ .get(attachedSharedResourceId.get().getEntityId()));
+ } else {
+ String contrailSharedResourceId = HeatToToscaUtil
+ .extractContrailGetResourceAttachedHeatResourceId(paramName.getValue().getValue());
+ if (contrailSharedResourceId != null
+ && context.getTranslatedIds().get(heatFileName).get(contrailSharedResourceId) != null) {
+ updateSharedResource(serviceTemplate, context, paramName,
+ context.getTranslatedIds().get(heatFileName).get(contrailSharedResourceId),
+ heatOrchestrationTemplate.getResources().get(contrailSharedResourceId));
+ }
+ }
+ }
+ if (serviceTemplate.getTopology_template().getOutputs() != null
+ && serviceTemplate.getTopology_template().getOutputs().size() == 0) {
+ serviceTemplate.getTopology_template().setOutputs(null);
+ }
+ }
+
+ private void updateSharedResource(ServiceTemplate serviceTemplate, TranslationContext context,
+ Map.Entry<String, Output> paramName,
+ String sharedTranslatedResourceId, Resource resource) {
+ context.addHeatSharedResourcesByParam(paramName.getKey(), sharedTranslatedResourceId, resource);
+ serviceTemplate.getTopology_template().getOutputs().remove(paramName.getKey());
+ }
+
+ private void translateResources(String heatFileName, ServiceTemplate serviceTemplate,
+ HeatOrchestrationTemplate heatOrchestrationTemplate,
+ TranslationContext context) {
+ for (String resourceId : heatOrchestrationTemplate.getResources().keySet()) {
+ Resource resource = heatOrchestrationTemplate.getResources().get(resourceId);
+ if (resource == null) {
+ throw new CoreException(
+ new ResourceNotFoundInHeatFileErrorBuilder(resourceId, heatFileName).build());
+ }
+ ResourceTranslationFactory.getInstance(resource)
+ .translateResource(heatFileName, serviceTemplate, heatOrchestrationTemplate, resource,
+ resourceId, context);
+ }
+ }
+
+ private Environment getHeatEnvFile(FileData heatFileData, TranslationContext context) {
+ List<FileData> fileRelatedDataList = heatFileData.getData();
+ if (fileRelatedDataList == null) {
+ return new Environment();
+ }
+ for (FileData fileRelatedData : fileRelatedDataList) {
+ if (fileRelatedData.getType().equals(FileData.Type.HEAT_ENV)) {
+ return new YamlUtil().yamlToObject(context.getFileContent(fileRelatedData.getFile()),
+ Environment.class);
+ }
+ }
+ return new Environment();
+ }
+
+
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/errors/IncorrectResourceReferenceErrorBuilder.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/errors/IncorrectResourceReferenceErrorBuilder.java
new file mode 100644
index 0000000000..c713855f60
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/errors/IncorrectResourceReferenceErrorBuilder.java
@@ -0,0 +1,51 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca.errors;
+
+import org.openecomp.sdc.common.errors.BaseErrorBuilder;
+import org.openecomp.sdc.common.errors.ErrorCategory;
+
+public class IncorrectResourceReferenceErrorBuilder extends BaseErrorBuilder {
+
+ private static final String INCORRECT_RESOURCE_REFERENCE_MSG =
+ "resource id '%s' with type '%s' has reference to resource '%s' with"
+ + " type '%s' in property '%s'. Invalid type, resource type should be type of '%s'.";
+
+ /**
+ * Instantiates a new Incorrect resource reference error builder.
+ *
+ * @param sourceResourceId the source resource id
+ * @param sourceResourceType the source resource type
+ * @param targetResourceId the target resource id
+ * @param targetResourceType the target resource type
+ * @param property the property
+ * @param validType the valid type
+ */
+ public IncorrectResourceReferenceErrorBuilder(String sourceResourceId, String sourceResourceType,
+ String targetResourceId, String targetResourceType,
+ String property, String validType) {
+ getErrorCodeBuilder().withId(TranslatorErrorCodes.INCORRECT_RESOURCE_REFERENCE);
+ getErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION);
+ getErrorCodeBuilder().withMessage(String
+ .format(INCORRECT_RESOURCE_REFERENCE_MSG, sourceResourceId, sourceResourceType,
+ targetResourceId, targetResourceType, property, validType));
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/errors/InvalidPropertyValueErrorBuilder.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/errors/InvalidPropertyValueErrorBuilder.java
new file mode 100644
index 0000000000..a16c341545
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/errors/InvalidPropertyValueErrorBuilder.java
@@ -0,0 +1,47 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca.errors;
+
+import org.openecomp.sdc.common.errors.BaseErrorBuilder;
+import org.openecomp.sdc.common.errors.ErrorCategory;
+
+
+public class InvalidPropertyValueErrorBuilder extends BaseErrorBuilder {
+
+ private static final String INVALID_FILED_VALUE_MSG =
+ "'%s' property has invalid value. Actual value is '%s' while '%s' value expected.";
+
+ /**
+ * Instantiates a new Invalid property value error builder.
+ *
+ * @param propertyName the property name
+ * @param actualValue the actual value
+ * @param expectedValue the expected value
+ */
+ public InvalidPropertyValueErrorBuilder(String propertyName, String actualValue,
+ String expectedValue) {
+ getErrorCodeBuilder().withId(TranslatorErrorCodes.INVALID_PROPERTY_VALUE);
+ getErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION);
+ getErrorCodeBuilder().withMessage(
+ String.format(INVALID_FILED_VALUE_MSG, propertyName, actualValue, expectedValue));
+ }
+
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/errors/MissingMandatoryPropertyErrorBuilder.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/errors/MissingMandatoryPropertyErrorBuilder.java
new file mode 100644
index 0000000000..6e06fef930
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/errors/MissingMandatoryPropertyErrorBuilder.java
@@ -0,0 +1,43 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca.errors;
+
+import org.openecomp.sdc.common.errors.BaseErrorBuilder;
+import org.openecomp.sdc.common.errors.ErrorCategory;
+
+
+public class MissingMandatoryPropertyErrorBuilder extends BaseErrorBuilder {
+
+ private static final String MANDATORY_PROPERTY_IS_MISSING_MSG =
+ "Mandatory property '%s' is missing";
+
+ /**
+ * Instantiates a new Missing mandatory property error builder.
+ *
+ * @param propertyName the property name
+ */
+ public MissingMandatoryPropertyErrorBuilder(String propertyName) {
+ getErrorCodeBuilder().withId(TranslatorErrorCodes.MISSING_MANDATORY_PROPERTY);
+ getErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION);
+ getErrorCodeBuilder()
+ .withMessage(String.format(MANDATORY_PROPERTY_IS_MISSING_MSG, propertyName));
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/errors/NotInSyncNumberOfInterfacesErrorBuilder.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/errors/NotInSyncNumberOfInterfacesErrorBuilder.java
new file mode 100644
index 0000000000..810c09880e
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/errors/NotInSyncNumberOfInterfacesErrorBuilder.java
@@ -0,0 +1,44 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca.errors;
+
+import org.openecomp.sdc.common.errors.BaseErrorBuilder;
+import org.openecomp.sdc.common.errors.ErrorCategory;
+
+
+public class NotInSyncNumberOfInterfacesErrorBuilder extends BaseErrorBuilder {
+
+ private static final String NOT_IN_SYNC_NUMBER_OF_INTERFACES_MSG =
+ "More than one ServiceInstance pointing to the same "
+ + "ServiceTemplate '%s', with different number of interfaces.";
+
+ /**
+ * Instantiates a new Not in sync number of interfaces error builder.
+ *
+ * @param serviceTemplateResourceId the service template resource id
+ */
+ public NotInSyncNumberOfInterfacesErrorBuilder(String serviceTemplateResourceId) {
+ getErrorCodeBuilder().withId(TranslatorErrorCodes.NOT_IN_SYNC_NUMBER_OF_INTERFACES);
+ getErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION);
+ getErrorCodeBuilder().withMessage(
+ String.format(NOT_IN_SYNC_NUMBER_OF_INTERFACES_MSG, serviceTemplateResourceId));
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/errors/ReferenceToUnsupportedResourceErrorBuilder.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/errors/ReferenceToUnsupportedResourceErrorBuilder.java
new file mode 100644
index 0000000000..5b48cb2c59
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/errors/ReferenceToUnsupportedResourceErrorBuilder.java
@@ -0,0 +1,52 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca.errors;
+
+import org.openecomp.sdc.common.errors.BaseErrorBuilder;
+import org.openecomp.sdc.common.errors.ErrorCategory;
+
+
+public class ReferenceToUnsupportedResourceErrorBuilder extends BaseErrorBuilder {
+
+ private static final String REFERENCE_TO_UNSUPPORTED_RESOURCE_MSG =
+ "Resource id '%s' with type '%s' has reference to"
+ + " unsupported resource '%s' with type '%s' in property '%s'";
+
+ /**
+ * Instantiates a new Reference to unsupported resource error builder.
+ *
+ * @param sourceResourceId the source resource id
+ * @param sourceResourceType the source resource type
+ * @param targetResourceId the target resource id
+ * @param targetResourceType the target resource type
+ * @param property the property
+ */
+ public ReferenceToUnsupportedResourceErrorBuilder(String sourceResourceId,
+ String sourceResourceType,
+ String targetResourceId,
+ String targetResourceType, String property) {
+ getErrorCodeBuilder().withId(TranslatorErrorCodes.REFERENCE_TO_UNSUPPORTED_RESOURCE);
+ getErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION);
+ getErrorCodeBuilder().withMessage(String
+ .format(REFERENCE_TO_UNSUPPORTED_RESOURCE_MSG, sourceResourceId, sourceResourceType,
+ targetResourceId, targetResourceType, property));
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/errors/ResourceNotFoundInHeatFileErrorBuilder.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/errors/ResourceNotFoundInHeatFileErrorBuilder.java
new file mode 100644
index 0000000000..7fac501e76
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/errors/ResourceNotFoundInHeatFileErrorBuilder.java
@@ -0,0 +1,52 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca.errors;
+
+import org.openecomp.sdc.common.errors.ErrorCategory;
+import org.openecomp.sdc.common.errors.ErrorCode;
+
+public class ResourceNotFoundInHeatFileErrorBuilder {
+
+ private static final String RESOURCE_NOT_FOUND_IN_FILE_ERR_ID =
+ "RESOURCE_NOT_FOUND_IN_FILE_ERR_ID";
+ private static final String RESOURCE_NOT_FOUND_IN_FILE_ERR_MSG =
+ "resource with id = %s was not found in heat file = %s.";
+
+ private final ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder();
+
+ /**
+ * Instantiates a new Resource not found in heat file error builder.
+ *
+ * @param resourceId the resource id
+ * @param heatfileName the heatfile name
+ */
+ public ResourceNotFoundInHeatFileErrorBuilder(String resourceId, String heatfileName) {
+ builder.withId(RESOURCE_NOT_FOUND_IN_FILE_ERR_ID);
+ builder.withCategory(ErrorCategory.APPLICATION);
+ builder
+ .withMessage(String.format(RESOURCE_NOT_FOUND_IN_FILE_ERR_MSG, resourceId, heatfileName));
+ }
+
+ public ErrorCode build() {
+ return builder.build();
+ }
+
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/errors/TranslatorErrorCodes.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/errors/TranslatorErrorCodes.java
new file mode 100644
index 0000000000..f9b873adca
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/errors/TranslatorErrorCodes.java
@@ -0,0 +1,31 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca.errors;
+
+public class TranslatorErrorCodes {
+ public static final String MISSING_MANDATORY_PROPERTY = "MISSING_MANDATORY_PROPERTY";
+ public static final String HEAT_TO_TOSCA_MAPPING_COLLISION = "HEAT_TO_TOSCA_MAPPING_COLLISION";
+ public static final String INCORRECT_RESOURCE_REFERENCE = "INCORRECT_RESOURCE_REFERENCE";
+ public static final String REFERENCE_TO_UNSUPPORTED_RESOURCE =
+ "REFERENCE_TO_UNSUPPORTED_RESOURCE";
+ public static final String NOT_IN_SYNC_NUMBER_OF_INTERFACES = "NOT_IN_SYNC_NUMBER_OF_INTERFACES";
+ public static final String INVALID_PROPERTY_VALUE = "INVALID_PROPERTY_VALUE";
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/AbstractSubstituteGlobalType.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/AbstractSubstituteGlobalType.java
new file mode 100644
index 0000000000..221a9e522b
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/AbstractSubstituteGlobalType.java
@@ -0,0 +1,167 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca.globaltypes;
+
+import org.openecomp.sdc.tosca.datatypes.ToscaDataType;
+import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
+import org.openecomp.sdc.tosca.datatypes.model.Constraint;
+import org.openecomp.sdc.tosca.datatypes.model.DataType;
+import org.openecomp.sdc.tosca.datatypes.model.NodeType;
+import org.openecomp.sdc.tosca.datatypes.model.PropertyDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.PropertyType;
+import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate;
+import org.openecomp.sdc.tosca.services.DataModelUtil;
+import org.openecomp.sdc.tosca.services.ToscaConstants;
+import org.openecomp.sdc.translator.services.heattotosca.Constants;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+
+public class AbstractSubstituteGlobalType {
+
+ private AbstractSubstituteGlobalType() {
+ }
+
+ /**
+ * Create service template service template.
+ *
+ * @return the service template
+ */
+ public static ServiceTemplate createServiceTemplate() {
+ ServiceTemplate serviceTemplate = new ServiceTemplate();
+ serviceTemplate.setTosca_definitions_version(ToscaConstants.TOSCA_DEFINITIONS_VERSION);
+ serviceTemplate.setMetadata(
+ DataModelUtil.createMetadata(Constants.ABSTRACT_SUBSTITUTE_TEMPLATE_NAME, "1.0.0", null));
+ serviceTemplate.setImports(GlobalTypesUtil.createCommonImportList());
+ serviceTemplate.setDescription("Abstract Substitute Global Types");
+ serviceTemplate.setData_types(createGlobalDataTypes());
+ serviceTemplate.setNode_types(createGlobalNodeTypes());
+ return serviceTemplate;
+ }
+
+ private static Map<String, NodeType> createGlobalNodeTypes() {
+ Map<String, NodeType> globalNodeTypes = new HashMap<>();
+ globalNodeTypes.put(ToscaNodeType.ABSTRACT_SUBSTITUTE.getDisplayName(),
+ createAbstractSubstituteNodeType());
+ return globalNodeTypes;
+ }
+
+ private static NodeType createAbstractSubstituteNodeType() {
+ NodeType nodeType = new NodeType();
+ nodeType.setDerived_from(ToscaNodeType.ROOT.getDisplayName());
+ nodeType.setProperties(createAbstractSubstituteProperties());
+ return nodeType;
+ }
+
+ private static Map<String, PropertyDefinition> createAbstractSubstituteProperties() {
+ Map<String, PropertyDefinition> props = new HashMap<>();
+ props.put(ToscaConstants.SERVICE_TEMPLATE_FILTER_PROPERTY_NAME, DataModelUtil
+ .createPropertyDefinition(ToscaDataType.SUBSTITUTION_FILTERING.getDisplayName(),
+ "Substitution Filter", true, null, null, null, null));
+
+ return props;
+ }
+
+
+ private static Map<String, DataType> createGlobalDataTypes() {
+ Map<String, DataType> globalDataTypes = new HashMap<>();
+ globalDataTypes.put(ToscaDataType.SUBSTITUTION_FILTER.getDisplayName(),
+ createSubstitutionFilterDataType());
+ globalDataTypes.put(ToscaDataType.SUBSTITUTION_FILTERING.getDisplayName(),
+ createSubstitutionFilteringDataType());
+ return globalDataTypes;
+ }
+
+ private static DataType createSubstitutionFilterDataType() {
+ DataType dataType = new DataType();
+ dataType.setDerived_from(ToscaDataType.ROOT.getDisplayName());
+ dataType.setDescription("Substitution Filter");
+ Map<String, PropertyDefinition> properties = new HashMap<>();
+ properties.put(ToscaConstants.COUNT_PROPERTY_NAME, DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Count", false, null, null,
+ null, 1));
+ properties.put(ToscaConstants.SCALING_ENABLED_PROPERTY_NAME, DataModelUtil
+ .createPropertyDefinition(PropertyType.BOOLEAN.getDisplayName(),
+ "Indicates whether service scaling is enabled", false, null, null, null, true));
+ properties.put(ToscaConstants.SUBSTITUTE_SERVICE_TEMPLATE_PROPERTY_NAME, DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "Substitute Service Template", true, null, null, null, null));
+ properties.put("mandatory", DataModelUtil
+ .createPropertyDefinition(PropertyType.BOOLEAN.getDisplayName(), "Mandatory", false, null,
+ null, null, true));
+ properties.put("index_variable", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Index variable", false,
+ createMinLengthConstraint(), null, null, "%index%"));
+
+ dataType.setProperties(properties);
+ return dataType;
+ }
+
+ private static List<Constraint> createMinLengthConstraint() {
+ List<Constraint> constraints;
+ constraints = new ArrayList<>();
+ Constraint constraint = new Constraint();
+ constraint.setMin_length(3);
+ constraints.add(constraint);
+ return constraints;
+ }
+
+ private static DataType createSubstitutionFilteringDataType() {
+ DataType dataType = new DataType();
+ dataType.setDerived_from(ToscaDataType.ROOT.getDisplayName());
+ dataType.setDescription("Substitution Filter");
+ Map<String, PropertyDefinition> properties = new HashMap<>();
+ properties.put(ToscaConstants.COUNT_PROPERTY_NAME, DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Count", false, null, null,
+ null, 1));
+ properties.put(ToscaConstants.INDEX_VALUE_PROPERTY_NAME, DataModelUtil
+ .createPropertyDefinition(PropertyType.INTEGER.getDisplayName(),
+ "Index value of the substitution service template runtime instance", false,
+ createIndexValueConstraint(), null, null, 0));
+ properties.put(ToscaConstants.SCALING_ENABLED_PROPERTY_NAME, DataModelUtil
+ .createPropertyDefinition(PropertyType.BOOLEAN.getDisplayName(),
+ "Indicates whether service scaling is enabled", false, null, null, null, true));
+ properties.put(ToscaConstants.SUBSTITUTE_SERVICE_TEMPLATE_PROPERTY_NAME, DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "Substitute Service Template", true, null, null, null, null));
+ properties.put("mandatory", DataModelUtil
+ .createPropertyDefinition(PropertyType.BOOLEAN.getDisplayName(), "Mandatory", false, null,
+ null, null, true));
+
+
+ dataType.setProperties(properties);
+ return dataType;
+ }
+
+ private static List<Constraint> createIndexValueConstraint() {
+ List<Constraint> constraints;
+ constraints = new ArrayList<>();
+ Constraint constraint = new Constraint();
+ constraint.setGreater_or_equal(0);
+ constraints.add(constraint);
+ return constraints;
+ }
+
+
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/CinderVolumeGlobalType.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/CinderVolumeGlobalType.java
new file mode 100644
index 0000000000..72f3043225
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/CinderVolumeGlobalType.java
@@ -0,0 +1,242 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca.globaltypes;
+
+import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
+import org.openecomp.sdc.tosca.datatypes.ToscaRelationshipType;
+import org.openecomp.sdc.tosca.datatypes.model.AttributeDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.Constraint;
+import org.openecomp.sdc.tosca.datatypes.model.NodeType;
+import org.openecomp.sdc.tosca.datatypes.model.PropertyDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.PropertyType;
+import org.openecomp.sdc.tosca.datatypes.model.RelationshipType;
+import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate;
+import org.openecomp.sdc.tosca.services.DataModelUtil;
+import org.openecomp.sdc.tosca.services.ToscaConstants;
+import org.openecomp.sdc.translator.services.heattotosca.Constants;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class CinderVolumeGlobalType {
+
+ /**
+ * Create service template service template.
+ *
+ * @return the service template
+ */
+ public static ServiceTemplate createServiceTemplate() {
+ ServiceTemplate cinderVolumeServiceTemplate = new ServiceTemplate();
+ cinderVolumeServiceTemplate
+ .setTosca_definitions_version(ToscaConstants.TOSCA_DEFINITIONS_VERSION);
+ cinderVolumeServiceTemplate.setMetadata(
+ DataModelUtil.createMetadata(Constants.CINDER_VOLUME_TEMPLATE_NAME, "1.0.0", null));
+ cinderVolumeServiceTemplate.setDescription("Cinder Volume TOSCA Global Types");
+ cinderVolumeServiceTemplate.setRelationship_types(createGlobalRelationshipTypes());
+ cinderVolumeServiceTemplate.setNode_types(createGlobalNodeTypes());
+ return cinderVolumeServiceTemplate;
+ }
+
+ private static Map<String, NodeType> createGlobalNodeTypes() {
+ Map<String, NodeType> globalNodeTypes = new HashMap<>();
+ globalNodeTypes.put(ToscaNodeType.CINDER_VOLUME.getDisplayName(), createCinderVolumeNodeType());
+ return globalNodeTypes;
+ }
+
+ private static NodeType createCinderVolumeNodeType() {
+ NodeType cinderVolumeNodeType = new NodeType();
+ cinderVolumeNodeType.setDerived_from(ToscaNodeType.BLOCK_STORAGE.getDisplayName());
+ cinderVolumeNodeType.setProperties(createCinderVolumeProperties());
+ cinderVolumeNodeType.setAttributes(createCinderVolumeAttributes());
+ return cinderVolumeNodeType;
+ }
+
+ private static Map<String, RelationshipType> createGlobalRelationshipTypes() {
+ Map<String, RelationshipType> globalRelationshipTypes = new HashMap<>();
+ globalRelationshipTypes.put(ToscaRelationshipType.CINDER_VOLUME_ATTACHES_TO.getDisplayName(),
+ createCinderVolumeAttachesToRelationshipType());
+ return globalRelationshipTypes;
+ }
+
+ private static RelationshipType createCinderVolumeAttachesToRelationshipType() {
+ RelationshipType cinderVolumeAttachesToRelationType = new RelationshipType();
+ cinderVolumeAttachesToRelationType
+ .setDerived_from(ToscaRelationshipType.NATIVE_ATTACHES_TO.getDisplayName());
+ cinderVolumeAttachesToRelationType
+ .setDescription("This type represents an attachment relationship for associating volume");
+
+ Map<String, PropertyDefinition> cinderVolumeAttachesToProps = new HashMap<>();
+ cinderVolumeAttachesToProps.put("location", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "The location where the volume is exposed on the instance, mountpoint", false, null,
+ null, null, null)); //overridden location prop from attachesTo
+ cinderVolumeAttachesToProps.put("instance_uuid", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "The ID of the server to which the volume attaches", true, null, null, null, null));
+ cinderVolumeAttachesToProps.put("volume_id", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "The ID of the volume to be attached", true, null, null, null, null));
+ cinderVolumeAttachesToRelationType.setProperties(cinderVolumeAttachesToProps);
+
+ Map<String, AttributeDefinition> cinderVolumeAttachesToAttributes = new HashMap<>();
+ cinderVolumeAttachesToAttributes.put("show", DataModelUtil
+ .createAttributeDefinition(PropertyType.STRING.getDisplayName(),
+ "Detailed information about resource", null, null, null));
+ cinderVolumeAttachesToRelationType.setAttributes(cinderVolumeAttachesToAttributes);
+
+ return cinderVolumeAttachesToRelationType;
+ }
+
+ private static Map<String, PropertyDefinition> createCinderVolumeProperties() {
+ Map<String, PropertyDefinition> cinderVolumePropertyDefMap = new HashMap<>();
+ cinderVolumePropertyDefMap.put("availability_zone", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "The availability zone in which the volume will be created", false, null, null, null,
+ null));
+ cinderVolumePropertyDefMap.put("backup_id", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "If specified, the backup to create the volume from", false, null, null, null, null));
+ cinderVolumePropertyDefMap.put(Constants.DESCRIPTION_PROPERTY_NAME, DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "A description of the volume", false, null, null, null, null));
+ cinderVolumePropertyDefMap.put("image", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "If specified, the name or ID of the image to create the volume from", false, null,
+ null, null, null));
+ cinderVolumePropertyDefMap.put("metadata", DataModelUtil
+ .createPropertyDefinition(PropertyType.MAP.getDisplayName(),
+ "Key/value pairs to associate with the volume", false, null, null,
+ DataModelUtil.createEntrySchema(PropertyType.STRING.getDisplayName(), null, null),
+ null));
+ cinderVolumePropertyDefMap.put("multiattach", DataModelUtil
+ .createPropertyDefinition(PropertyType.BOOLEAN.getDisplayName(),
+ "Whether allow the volume to be attached more than once", false, null, null, null,
+ null));
+ cinderVolumePropertyDefMap.put(Constants.NAME_PROPERTY_NAME, DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "A name used to distinguish the volume", false, null, null, null, null));
+ cinderVolumePropertyDefMap.put("read_only", DataModelUtil
+ .createPropertyDefinition(PropertyType.BOOLEAN.getDisplayName(),
+ "Enables or disables read-only access mode of volume", false, null, null, null, null));
+ cinderVolumePropertyDefMap.put("scheduler_hints", DataModelUtil
+ .createPropertyDefinition(PropertyType.MAP.getDisplayName(),
+ "Arbitrary key-value pairs specified by the client "
+ + "to help the Cinder scheduler creating a volume",
+ false, null, null,
+ DataModelUtil.createEntrySchema(PropertyType.STRING.getDisplayName(), null, null),
+ null));
+ cinderVolumePropertyDefMap.put("size", DataModelUtil
+ .createPropertyDefinition(PropertyType.SCALAR_UNIT_SIZE.getDisplayName(),
+ "The requested storage size (default unit is MB)", false, getSizeConstraints(), null,
+ null, null));
+ cinderVolumePropertyDefMap.put("source_volid", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "If specified, the volume to use as source", false, null, null, null, null));
+ cinderVolumePropertyDefMap.put("volume_type", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "If specified, the type of volume to use, mapping to a specific backend", false, null,
+ null, null, null));
+ cinderVolumePropertyDefMap.put("delete_on_termination", DataModelUtil
+ .createPropertyDefinition(PropertyType.BOOLEAN.getDisplayName(),
+ "Indicate whether the volume should be deleted when the server is terminated", false,
+ null, null, null, null));
+ cinderVolumePropertyDefMap.put("boot_index", DataModelUtil
+ .createPropertyDefinition(PropertyType.INTEGER.getDisplayName(),
+ "Integer used for ordering the boot disks", false, null, null, null, null));
+ cinderVolumePropertyDefMap.put("device_type", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Device type", false,
+ getDeviceTypeConstraints(), null, null, null));
+ cinderVolumePropertyDefMap.put("disk_bus", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "Bus of the device: hypervisor driver chooses a suitable default if omitted", false,
+ getDiskBusConstraints(), null, null, null));
+ cinderVolumePropertyDefMap.put("swap_size", DataModelUtil
+ .createPropertyDefinition(PropertyType.SCALAR_UNIT_SIZE.getDisplayName(),
+ "The size of the swap, in MB", false, null, null, null, null));
+
+ return cinderVolumePropertyDefMap;
+ }
+
+ private static Map<String, AttributeDefinition> createCinderVolumeAttributes() {
+ Map<String, AttributeDefinition> cinderVolumeAttributesDefMap = new HashMap<>();
+ cinderVolumeAttributesDefMap.put("attachments", DataModelUtil
+ .createAttributeDefinition(PropertyType.STRING.getDisplayName(),
+ "The list of attachments of the volume", null,
+ DataModelUtil.createEntrySchema(PropertyType.STRING.getDisplayName(), null, null),
+ null));
+ cinderVolumeAttributesDefMap.put("bootable", DataModelUtil
+ .createAttributeDefinition(PropertyType.BOOLEAN.getDisplayName(),
+ "Boolean indicating if the volume can be booted or not", null, null, null));
+ cinderVolumeAttributesDefMap.put("created_at", DataModelUtil
+ .createAttributeDefinition(PropertyType.TIMESTAMP.getDisplayName(),
+ "The timestamp indicating volume creation", null, null, null));
+ cinderVolumeAttributesDefMap.put("display_description", DataModelUtil
+ .createAttributeDefinition(PropertyType.STRING.getDisplayName(),
+ "Description of the volume", null, null, null));
+ cinderVolumeAttributesDefMap.put("display_name", DataModelUtil
+ .createAttributeDefinition(PropertyType.STRING.getDisplayName(), "Name of the volume", null,
+ null, null));
+ cinderVolumeAttributesDefMap.put("encrypted", DataModelUtil
+ .createAttributeDefinition(PropertyType.BOOLEAN.getDisplayName(),
+ "Boolean indicating if the volume is encrypted or not", null, null, null));
+ cinderVolumeAttributesDefMap.put("metadata_values", DataModelUtil
+ .createAttributeDefinition(PropertyType.MAP.getDisplayName(),
+ "Key/value pairs associated with the volume in raw dict form", null,
+ DataModelUtil.createEntrySchema(PropertyType.STRING.getDisplayName(), null, null),
+ null));
+ cinderVolumeAttributesDefMap.put("show", DataModelUtil
+ .createAttributeDefinition(PropertyType.STRING.getDisplayName(),
+ "Detailed information about resource", null, null, null));
+ cinderVolumeAttributesDefMap.put("status", DataModelUtil
+ .createAttributeDefinition(PropertyType.STRING.getDisplayName(),
+ "The current status of the volume", null, null, null));
+ return cinderVolumeAttributesDefMap;
+ }
+
+ private static List<Constraint> getDeviceTypeConstraints() {
+ Constraint validValues;
+ List<Constraint> constraints = new ArrayList<>();
+ validValues = DataModelUtil.createValidValuesConstraint("cdrom", "disk");
+ constraints.add(validValues);
+ return constraints;
+ }
+
+ private static List<Constraint> getDiskBusConstraints() {
+ Constraint validValues;
+ List<Constraint> constraints = new ArrayList<>();
+ validValues =
+ DataModelUtil.createValidValuesConstraint("ide", "lame_bus", "scsi", "usb", "virtio");
+ constraints.add(validValues);
+ return constraints;
+ }
+
+
+ private static List<Constraint> getSizeConstraints() {
+ List<Constraint> constraints;
+ constraints = new ArrayList<>();
+ Constraint constraint = new Constraint();
+ constraint.setGreater_or_equal("1 GB");
+ constraints.add(constraint);
+ return constraints;
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/CommonGlobalTypes.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/CommonGlobalTypes.java
new file mode 100644
index 0000000000..43a4782149
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/CommonGlobalTypes.java
@@ -0,0 +1,500 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca.globaltypes;
+
+
+import org.openecomp.sdc.tosca.datatypes.ToscaCapabilityType;
+import org.openecomp.sdc.tosca.datatypes.ToscaDataType;
+import org.openecomp.sdc.tosca.datatypes.ToscaGroupType;
+import org.openecomp.sdc.tosca.datatypes.ToscaPolicyType;
+import org.openecomp.sdc.tosca.datatypes.ToscaRelationshipType;
+import org.openecomp.sdc.tosca.datatypes.model.AttributeDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.CapabilityType;
+import org.openecomp.sdc.tosca.datatypes.model.Constraint;
+import org.openecomp.sdc.tosca.datatypes.model.DataType;
+import org.openecomp.sdc.tosca.datatypes.model.GroupType;
+import org.openecomp.sdc.tosca.datatypes.model.Import;
+import org.openecomp.sdc.tosca.datatypes.model.PolicyType;
+import org.openecomp.sdc.tosca.datatypes.model.PropertyDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.PropertyType;
+import org.openecomp.sdc.tosca.datatypes.model.RelationshipType;
+import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate;
+import org.openecomp.sdc.tosca.services.DataModelUtil;
+import org.openecomp.sdc.tosca.services.ToscaConstants;
+import org.openecomp.sdc.tosca.services.ToscaUtil;
+import org.openecomp.sdc.translator.services.heattotosca.Constants;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class CommonGlobalTypes {
+
+ /**
+ * Create service template service template.
+ *
+ * @return the service template
+ */
+ public static ServiceTemplate createServiceTemplate() {
+ ServiceTemplate serviceTemplate = new ServiceTemplate();
+ serviceTemplate.setTosca_definitions_version(ToscaConstants.TOSCA_DEFINITIONS_VERSION);
+ serviceTemplate.setMetadata(
+ DataModelUtil.createMetadata(Constants.COMMON_GLOBAL_TEMPLATE_NAME, "1.0.0", null));
+ serviceTemplate.setDescription("TOSCA Global Types");
+ serviceTemplate.setData_types(createGlobalDataTypes());
+ serviceTemplate.setGroup_types(createGroupTypes());
+ serviceTemplate.setPolicy_types(createPolicyTypes());
+ serviceTemplate.setRelationship_types(createRelationTypes());
+ serviceTemplate.setCapability_types(createCapabilityTypes());
+ serviceTemplate.setImports(createImportList());
+ return serviceTemplate;
+ }
+
+ private static Map<String, CapabilityType> createCapabilityTypes() {
+ Map<String, CapabilityType> capabilityMap = new HashMap<>();
+ capabilityMap.put(ToscaCapabilityType.METRIC.getDisplayName(), createMetricCapabilityType());
+ capabilityMap
+ .put(ToscaCapabilityType.METRIC_CEILOMETER.getDisplayName(), createMetricCeilometerType());
+ capabilityMap.put(ToscaCapabilityType.METRIC_SNMP_TRAP.getDisplayName(), createMetricSnmpType(
+ "A node type that includes the Metric capability"
+ + " indicates that it can be monitored using snmp trap."));
+ capabilityMap.put(ToscaCapabilityType.METRIC_SNMP_POLLING.getDisplayName(),
+ createMetricSnmpType(
+ "A node type that includes the Metric capability indicates"
+ + " that it can be monitored using snmp polling."));
+ return capabilityMap;
+ }
+
+
+ private static CapabilityType createMetricSnmpType(String description) {
+ CapabilityType capabilityType = new CapabilityType();
+ capabilityType.setDerived_from(ToscaCapabilityType.METRIC.getDisplayName());
+ capabilityType.setDescription(description);
+ capabilityType.setProperties(createCapabilityMetricSnmpProperties());
+
+ return capabilityType;
+ }
+
+
+ private static Map<String, PropertyDefinition> createCapabilityMetricSnmpProperties() {
+ Map<String, PropertyDefinition> propertyDefinitionMap = new HashMap<>();
+ propertyDefinitionMap.put("oid", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Object Id of the metric",
+ true, null, null, null, null));
+ return propertyDefinitionMap;
+ }
+
+ private static CapabilityType createMetricCeilometerType() {
+ CapabilityType capabilityType = new CapabilityType();
+ capabilityType.setDerived_from(ToscaCapabilityType.METRIC.getDisplayName());
+ capabilityType.setDescription(
+ "A node type that includes the Metric capability"
+ + " indicates that it can be monitored using ceilometer.");
+ capabilityType.setProperties(createCapabilityMetricCeilometerProperties());
+ return capabilityType;
+ }
+
+
+ private static Map<String, PropertyDefinition> createCapabilityMetricCeilometerProperties() {
+ Map<String, PropertyDefinition> propertyDefinitionMap = new HashMap<>();
+ propertyDefinitionMap.put(Constants.NAME_PROPERTY_NAME, DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "Ceilometer metric type name to monitor. (The name ceilometer is using)", true, null,
+ null, null, null));
+ return propertyDefinitionMap;
+ }
+
+ private static Map<String, Import> createImportList() {
+ Map<String, Import> importsMap = new HashMap<>();
+ importsMap.put(ToscaConstants.NATIVE_TYPES_SERVICE_TEMPLATE_NAME, GlobalTypesUtil
+ .createServiceTemplateImport(ToscaConstants.NATIVE_TYPES_SERVICE_TEMPLATE_NAME));
+ return importsMap;
+ }
+
+ /**
+ * Create metric capability type capability type.
+ *
+ * @return the capability type
+ */
+ public static CapabilityType createMetricCapabilityType() {
+ CapabilityType capabilityType = new CapabilityType();
+ capabilityType.setDerived_from(ToscaCapabilityType.NFV_METRIC.getDisplayName());
+ capabilityType.setDescription(
+ "A node type that includes the Metric capability indicates that it can be monitored.");
+ capabilityType.setProperties(createCapabilityMetricProperties());
+ capabilityType.setAttributes(createCapabilityMetricAttributes());
+ return capabilityType;
+ }
+
+ private static Map<String, AttributeDefinition> createCapabilityMetricAttributes() {
+ Map<String, AttributeDefinition> attributeDefinitionMap = new HashMap<>();
+
+ attributeDefinitionMap.put("value", DataModelUtil
+ .createAttributeDefinition(PropertyType.STRING.getDisplayName(), "Runtime monitored value",
+ null, null, null));
+ return attributeDefinitionMap;
+ }
+
+ private static Map<String, PropertyDefinition> createCapabilityMetricProperties() {
+ Map<String, PropertyDefinition> propertyDefinitionMap = new HashMap<>();
+ propertyDefinitionMap.put("type", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "Type of the metric value, for an example, Cumulative, Delta, Gauge and etc.", true,
+ null, null, null, null));
+ propertyDefinitionMap.put("unit", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Unit of the metric value",
+ true, null, null, null, null));
+ propertyDefinitionMap.put("category", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "Category of the metric, for an example, compute, disk, network, storage and etc.",
+ false, null, null, null, null));
+ propertyDefinitionMap.put(Constants.DESCRIPTION_PROPERTY_NAME, DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Description of the metric",
+ false, null, null, null, null));
+ return propertyDefinitionMap;
+ }
+
+ private static Map<String, RelationshipType> createRelationTypes() {
+ Map<String, RelationshipType> globalRelationshipTypes = new HashMap<>();
+ globalRelationshipTypes.put(ToscaRelationshipType.ATTACHES_TO.getDisplayName(),
+ createAttachesToRelationshipType());
+ return globalRelationshipTypes;
+ }
+
+ private static RelationshipType createAttachesToRelationshipType() {
+ RelationshipType attachesToRelationType = new RelationshipType();
+ attachesToRelationType.setDerived_from(ToscaRelationshipType.ROOT.getDisplayName());
+ attachesToRelationType.setDescription("This type represents an attachment relationship");
+ return attachesToRelationType;
+ }
+
+ private static Map<String, PolicyType> createPolicyTypes() {
+ Map<String, PolicyType> globalPolicyTypes = new HashMap<>();
+ globalPolicyTypes
+ .put(ToscaPolicyType.PLACEMENT_ANTILOCATE.getDisplayName(), createAntilocatePolicyType());
+ globalPolicyTypes
+ .put(ToscaPolicyType.PLACEMENT_COLOCATE.getDisplayName(), createColocatePolicyType());
+ globalPolicyTypes.put(ToscaPolicyType.PLACEMENT_VALET_AFFINITY.getDisplayName(),
+ createValetAffinityPolicyType());
+ globalPolicyTypes.put(ToscaPolicyType.PLACEMENT_VALET_DIVERSITY.getDisplayName(),
+ createValetDiversityPolicyType());
+ globalPolicyTypes.put(ToscaPolicyType.PLACEMENT_VALET_EXCLUSIVITY.getDisplayName(),
+ createValetExclusivityPolicyType());
+ return globalPolicyTypes;
+ }
+
+ private static PolicyType createValetDiversityPolicyType() {
+ PolicyType policyType = new PolicyType();
+ policyType.setDerived_from(ToscaPolicyType.PLACEMENT.getDisplayName());
+ policyType.setDescription("Valet Diversity");
+ policyType.setProperties(new HashMap<>());
+ policyType.getProperties().put("level", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "diversity", false,
+ DataModelUtil.createValidValuesConstraintsList("host", "rack"), null, null, "host"));
+
+ return policyType;
+ }
+
+ private static PolicyType createValetExclusivityPolicyType() {
+ PolicyType policyType = new PolicyType();
+ policyType.setDerived_from(ToscaPolicyType.PLACEMENT.getDisplayName());
+ policyType.setDescription("Valet Exclusivity");
+ policyType.setProperties(addNamePropertyToPolicyType());
+ policyType.setProperties(new HashMap<>());
+ policyType.getProperties().put("level", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "exclusivity", false,
+ DataModelUtil.createValidValuesConstraintsList("host", "rack"), null, null, "host"));
+ return policyType;
+ }
+
+ private static PolicyType createValetAffinityPolicyType() {
+ PolicyType policyType = new PolicyType();
+ policyType.setDerived_from(ToscaPolicyType.PLACEMENT.getDisplayName());
+ policyType.setDescription("Valet Affinity");
+ policyType.setProperties(new HashMap<>());
+ policyType.getProperties().put("level", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "affinity", false,
+ DataModelUtil.createValidValuesConstraintsList("host", "rack"), null, null, "host"));
+
+ return policyType;
+ }
+
+
+ private static PolicyType createColocatePolicyType() {
+ PolicyType policyType = new PolicyType();
+ policyType.setDerived_from(ToscaPolicyType.PLACEMENT.getDisplayName());
+ policyType.setDescription("Keep associated nodes (groups of nodes) based upon affinity value");
+ policyType.setProperties(addNamePropertyToPolicyType());
+ policyType.getProperties().put("affinity", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "affinity", true,
+ DataModelUtil.createValidValuesConstraintsList("host", "region", "compute"), null, null,
+ null));
+
+ return policyType;
+ }
+
+ private static PolicyType createAntilocatePolicyType() {
+ PolicyType policyType = new PolicyType();
+ policyType.setDerived_from(ToscaPolicyType.PLACEMENT.getDisplayName());
+ policyType.setDescription("My placement policy for separation based upon container type value");
+ policyType.setProperties(addNamePropertyToPolicyType());
+ policyType.getProperties().put("container_type", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "container type", false,
+ DataModelUtil.createValidValuesConstraintsList("host", "region", "compute"), null, null,
+ null));
+ return policyType;
+ }
+
+ private static Map<String, PropertyDefinition> addNamePropertyToPolicyType() {
+ Map<String, PropertyDefinition> policyTypeProperties = new HashMap<>();
+ policyTypeProperties.put(Constants.NAME_PROPERTY_NAME, DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "The name of the policy",
+ false, null, null, null, null));
+ return policyTypeProperties;
+ }
+
+ private static Map<String, GroupType> createGroupTypes() {
+ Map<String, GroupType> globalGroupTypes = new HashMap<>();
+ globalGroupTypes.put(ToscaGroupType.HEAT_STACK.getDisplayName(), createHeatStackGroupType());
+ return globalGroupTypes;
+ }
+
+ private static GroupType createHeatStackGroupType() {
+ GroupType heatStackGroupType = new GroupType();
+ heatStackGroupType.setDerived_from(ToscaGroupType.ROOT.getDisplayName());
+ heatStackGroupType
+ .setDescription("Grouped all heat resources which are in the same heat stack");
+ heatStackGroupType.setProperties(createHeatStackGroupProperties());
+
+ return heatStackGroupType;
+ }
+
+ private static Map<String, PropertyDefinition> createHeatStackGroupProperties() {
+ Map<String, PropertyDefinition> propertiesDef = new HashMap<>();
+ propertiesDef.put("heat_file", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "Heat file which associate to this group/heat stack", true, null, null, null, null));
+ propertiesDef.put(Constants.DESCRIPTION_PROPERTY_NAME, DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Heat file description",
+ false, null, null, null, null));
+ return propertiesDef;
+ }
+
+
+ /**
+ * Create common service template import import.
+ *
+ * @return the import
+ */
+ public static Import createCommonServiceTemplateImport() {
+ Import commonServiceTemplateImport = new Import();
+ commonServiceTemplateImport
+ .setFile(ToscaUtil.getServiceTemplateFileName(Constants.COMMON_GLOBAL_TEMPLATE_NAME));
+ return commonServiceTemplateImport;
+ }
+
+ private static Map<String, DataType> createGlobalDataTypes() {
+ Map<String, DataType> globalDataTypes = new HashMap<>();
+ globalDataTypes.put(ToscaDataType.NETWORK_ALLOCATION_POOL.getDisplayName(),
+ createAllocationPoolDataType());
+ globalDataTypes
+ .put(ToscaDataType.NETWORK_HOST_ROUTE.getDisplayName(), createHostRouteDataType());
+ globalDataTypes.put(ToscaDataType.NEUTRON_SUBNET.getDisplayName(), createSubnetDataType());
+ globalDataTypes
+ .put(ToscaDataType.NETWORK_ADDRESS_PAIR.getDisplayName(), createAddressPairDataType());
+ globalDataTypes.put(ToscaDataType.CONTRAIL_STATIC_ROUTE.getDisplayName(),
+ createContrailStaticRouteDataType());
+ globalDataTypes.put(ToscaDataType.CONTRAIL_ADDRESS_PAIR.getDisplayName(),
+ createContrailAddressPairDataType());
+ return globalDataTypes;
+ }
+
+ private static DataType createContrailStaticRouteDataType() {
+ DataType dataType = new DataType();
+ dataType.setDerived_from(ToscaDataType.ROOT.getDisplayName());
+ dataType.setDescription("static route");
+ Map<String, PropertyDefinition> prop = new HashMap<>();
+
+ prop.put("prefix", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Route prefix", false, null,
+ null, null, null));
+ prop.put("next_hop", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Next hop", false, null,
+ null, null, null));
+ prop.put("next_hop_type", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Next hop type", false,
+ null, null, null, null));
+
+ dataType.setProperties(prop);
+ return dataType;
+ }
+
+ private static DataType createContrailAddressPairDataType() {
+ DataType dataType = new DataType();
+ dataType.setDerived_from(ToscaDataType.ROOT.getDisplayName());
+ dataType.setDescription("Address Pair");
+ Map<String, PropertyDefinition> prop = new HashMap<>();
+
+ prop.put("prefix", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "IP address prefix", false,
+ null, null, null, null));
+ prop.put("mac_address", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Mac address", false, null,
+ null, null, null));
+ prop.put("address_mode", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "Address mode active-active or active-standy", false,
+ DataModelUtil.createValidValuesConstraintsList("active-active", "active-standby"), null,
+ null, null));
+
+ dataType.setProperties(prop);
+ return dataType;
+ }
+
+ private static DataType createAddressPairDataType() {
+ DataType addressPairDataType = new DataType();
+ addressPairDataType.setDerived_from(ToscaDataType.ROOT.getDisplayName());
+ addressPairDataType.setDescription("MAC/IP address pairs");
+ Map<String, PropertyDefinition> addressPairProp = new HashMap<>();
+
+ addressPairProp.put("ip_address", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "IP address", false, null,
+ null, null, null));
+ addressPairProp.put("mac_address", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "MAC address", false, null,
+ null, null, null));
+ addressPairDataType.setProperties(addressPairProp);
+
+ return addressPairDataType;
+ }
+
+ private static DataType createHostRouteDataType() {
+ DataType hostRouteDataType = new DataType();
+ hostRouteDataType.setDerived_from(ToscaDataType.ROOT.getDisplayName());
+ hostRouteDataType.setDescription("Host route info for the subnet");
+
+ Map<String, PropertyDefinition> hostRoutePoolProp = new HashMap<>();
+ hostRoutePoolProp.put("destination", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "The destination for static route", false, null, null, null, null));
+ hostRoutePoolProp.put("nexthop", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "The next hop for the destination", false, null, null, null, null));
+ hostRouteDataType.setProperties(hostRoutePoolProp);
+
+ return hostRouteDataType;
+ }
+
+ private static DataType createAllocationPoolDataType() {
+ DataType allocationPoolDataType = new DataType();
+ allocationPoolDataType.setDerived_from(ToscaDataType.ROOT.getDisplayName());
+ allocationPoolDataType.setDescription("The start and end addresses for the allocation pool");
+
+ Map<String, PropertyDefinition> allocationPoolProp = new HashMap<>();
+ allocationPoolProp.put("start", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "Start address for the allocation pool", false, null, null, null, null));
+ allocationPoolProp.put("end", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "End address for the allocation pool", false, null, null, null, null));
+ allocationPoolDataType.setProperties(allocationPoolProp);
+
+ return allocationPoolDataType;
+ }
+
+ private static DataType createSubnetDataType() {
+ DataType subnetDataType = new DataType();
+ subnetDataType.setDerived_from(ToscaDataType.ROOT.getDisplayName());
+ subnetDataType.setDescription(
+ "A subnet represents an IP address block that can "
+ + "be used for assigning IP addresses to virtual instances");
+
+ Map<String, PropertyDefinition> subnetProp = new HashMap<>();
+ subnetProp.put("allocation_pools", DataModelUtil
+ .createPropertyDefinition(PropertyType.LIST.getDisplayName(),
+ "The start and end addresses for the allocation pools", false, null, null, DataModelUtil
+ .createEntrySchema(ToscaDataType.NETWORK_ALLOCATION_POOL.getDisplayName(), null,
+ null), null));
+ subnetProp.put("cidr", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "The CIDR", false, null,
+ null, null, null));
+ subnetProp.put("dns_nameservers", DataModelUtil
+ .createPropertyDefinition(PropertyType.LIST.getDisplayName(),
+ "A specified set of DNS name servers to be used", false, null, null,
+ DataModelUtil.createEntrySchema(PropertyType.STRING.getDisplayName(), null, null),
+ new ArrayList<String>()));
+ subnetProp.put("enable_dhcp", DataModelUtil
+ .createPropertyDefinition(PropertyType.BOOLEAN.getDisplayName(),
+ "Set to true if DHCP is enabled and false if DHCP is disabled", false, null, null, null,
+ true));
+ subnetProp.put("gateway_ip", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "The gateway IP address",
+ false, null, null, null, null));
+ subnetProp.put("host_routes", DataModelUtil
+ .createPropertyDefinition(PropertyType.LIST.getDisplayName(), "The gateway IP address",
+ false, null, null, DataModelUtil
+ .createEntrySchema(ToscaDataType.NETWORK_HOST_ROUTE.getDisplayName(), null, null),
+ null));
+ subnetProp.put("ip_version", DataModelUtil
+ .createPropertyDefinition(PropertyType.INTEGER.getDisplayName(), "The gateway IP address",
+ false, DataModelUtil.createValidValuesConstraintsList("4", "6"), null, null, 4));
+ subnetProp.put("ipv6_address_mode", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "IPv6 address mode", false,
+ DataModelUtil
+ .createValidValuesConstraintsList("dhcpv6-stateful", "dhcpv6-stateless", "slaac"),
+ null, null, null));
+ subnetProp.put("ipv6_ra_mode", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "IPv6 RA (Router Advertisement) mode", false, DataModelUtil
+ .createValidValuesConstraintsList("dhcpv6-stateful", "dhcpv6-stateless", "slaac"),
+ null, null, null));
+ subnetProp.put(Constants.NAME_PROPERTY_NAME, DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "The name of the subnet",
+ false, null, null, null, null));
+ subnetProp.put("prefixlen", DataModelUtil
+ .createPropertyDefinition(PropertyType.INTEGER.getDisplayName(),
+ "Prefix length for subnet allocation from subnet pool", false,
+ createPrefixlenConstraint(), null, null, null));
+ subnetProp.put("subnetpool", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "The name or ID of the subnet pool", false, null, null, null, null));
+ subnetProp.put("tenant_id", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "The ID of the tenant who owns the network", false, null, null, null, null));
+ subnetProp.put("value_specs", DataModelUtil
+ .createPropertyDefinition(PropertyType.MAP.getDisplayName(),
+ "Extra parameters to include in the request", false, null, null,
+ DataModelUtil.createEntrySchema(PropertyType.STRING.getDisplayName(), null, null),
+ new HashMap<>()));
+ subnetDataType.setProperties(subnetProp);
+
+ return subnetDataType;
+ }
+
+ private static List<Constraint> createPrefixlenConstraint() {
+ List<Constraint> constraints = new ArrayList<>();
+ Constraint constraint = new Constraint();
+ constraint.setGreater_or_equal(0);
+ constraints.add(constraint);
+ return constraints;
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/ContrailAbstractSubstituteGlobalType.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/ContrailAbstractSubstituteGlobalType.java
new file mode 100644
index 0000000000..7b0b810b61
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/ContrailAbstractSubstituteGlobalType.java
@@ -0,0 +1,196 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca.globaltypes;
+
+import org.openecomp.sdc.tosca.datatypes.ToscaDataType;
+import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
+import org.openecomp.sdc.tosca.datatypes.model.AttributeDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.DataType;
+import org.openecomp.sdc.tosca.datatypes.model.NodeType;
+import org.openecomp.sdc.tosca.datatypes.model.PropertyDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.PropertyType;
+import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate;
+import org.openecomp.sdc.tosca.services.DataModelUtil;
+import org.openecomp.sdc.tosca.services.ToscaConstants;
+import org.openecomp.sdc.translator.services.heattotosca.Constants;
+
+import java.util.HashMap;
+import java.util.Map;
+
+
+public class ContrailAbstractSubstituteGlobalType {
+
+ /**
+ * Create service template service template.
+ *
+ * @return the service template
+ */
+ public static ServiceTemplate createServiceTemplate() {
+ ServiceTemplate serviceTemplate = new ServiceTemplate();
+ serviceTemplate.setTosca_definitions_version(ToscaConstants.TOSCA_DEFINITIONS_VERSION);
+ serviceTemplate.setMetadata(
+ DataModelUtil.createMetadata(Constants
+ .CONTRAIL_ABSTRACT_SUBSTITUTE_TEMPLATE_NAME, "1.0.0", null));
+ serviceTemplate.setImports(GlobalTypesUtil.createCommonImportList());
+ serviceTemplate.setDescription("Contrail Abstract Substitute Global Types");
+ serviceTemplate.setData_types(createGlobalDataTypes());
+ serviceTemplate.setNode_types(createGlobalNodeTypes());
+ return serviceTemplate;
+ }
+
+ private static Map<String, NodeType> createGlobalNodeTypes() {
+ Map<String, NodeType> globalNodeTypes = new HashMap<>();
+ globalNodeTypes.put(ToscaNodeType.CONTRAIL_ABSTRACT_SUBSTITUTE.getDisplayName(),
+ createContrailAbstractSubstituteNodeType());
+ return globalNodeTypes;
+ }
+
+ private static NodeType createContrailAbstractSubstituteNodeType() {
+ NodeType nodeType = new NodeType();
+ nodeType.setDerived_from(ToscaNodeType.ABSTRACT_SUBSTITUTE.getDisplayName());
+ nodeType.setProperties(createContrailAbstractSubstituteProperties());
+ nodeType.setAttributes(createContrailAbstractSubstituteAttributes());
+
+ return nodeType;
+ }
+
+ private static Map<String, AttributeDefinition> createContrailAbstractSubstituteAttributes() {
+ Map<String, AttributeDefinition> attributesDefMap = new HashMap<>();
+ attributesDefMap.put("service_instance_name", DataModelUtil
+ .createAttributeDefinition(PropertyType.STRING.getDisplayName(),
+ "The name of the service instance", null, null, null));
+ attributesDefMap.put("fq_name", DataModelUtil
+ .createAttributeDefinition(PropertyType.STRING.getDisplayName(),
+ "The FQ name of the service instance", null, null, null));
+ attributesDefMap.put("status", DataModelUtil
+ .createAttributeDefinition(PropertyType.STRING.getDisplayName(),
+ "Status of the service instance", null, null, null));
+ attributesDefMap.put("service_template_name", DataModelUtil
+ .createAttributeDefinition(PropertyType.STRING.getDisplayName(),
+ "Service Template of the Service Instance", null, null, null));
+ attributesDefMap.put("virtual_machines", DataModelUtil
+ .createAttributeDefinition(PropertyType.STRING.getDisplayName(),
+ "Service VMs for the Service Instance", null, null, null));
+ attributesDefMap.put("active_vms", DataModelUtil
+ .createAttributeDefinition(PropertyType.STRING.getDisplayName(),
+ "Number of service VMs active for this Service Instance", null, null, null));
+ attributesDefMap.put("tenant_id", DataModelUtil
+ .createAttributeDefinition(PropertyType.STRING.getDisplayName(),
+ "Tenant id of the Service Instance", null, null, null));
+ attributesDefMap.put("show", DataModelUtil
+ .createAttributeDefinition(PropertyType.STRING.getDisplayName(), "All attributes", null,
+ null, null));
+
+ return attributesDefMap;
+ }
+
+ private static Map<String, PropertyDefinition> createContrailAbstractSubstituteProperties() {
+ Map<String, PropertyDefinition> props = new HashMap<>();
+ props.put("service_template_name", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Service template name",
+ false, null, null, null, null));
+ props.put("service_mode", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Service mode", true,
+ DataModelUtil
+ .createValidValuesConstraintsList("transparent", "in-network", "in-network-nat"),
+ null, null, null));
+ props.put("service_type", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Service type", true,
+ DataModelUtil.createValidValuesConstraintsList("firewall", "analyzer", "source-nat",
+ "loadbalancer"), null, null, null));
+ props.put("image_name", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Image name", true, null,
+ null, null, null));
+ props.put("flavor", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "flavor", false, null, null,
+ null, null));
+ props.put("service_interface_type_list", DataModelUtil
+ .createPropertyDefinition(PropertyType.LIST.getDisplayName(), "List of interface types",
+ true, null, null, DataModelUtil
+ .createEntrySchema(PropertyType.STRING.getDisplayName(), null, DataModelUtil
+ .createValidValuesConstraintsList("management", "left", "right", "other")),
+ null));
+ props.put("shared_ip_list", DataModelUtil
+ .createPropertyDefinition(PropertyType.LIST.getDisplayName(), "Shared ips enabled", false,
+ null, null,
+ DataModelUtil.createEntrySchema(PropertyType.BOOLEAN.getDisplayName(), null, null),
+ null));
+ props.put("static_routes_list", DataModelUtil
+ .createPropertyDefinition(PropertyType.LIST.getDisplayName(), "Static routes enabled",
+ false, null, null,
+ DataModelUtil.createEntrySchema(PropertyType.BOOLEAN.getDisplayName(), null, null),
+ null));
+ props.put("ordered_interfaces", DataModelUtil
+ .createPropertyDefinition(PropertyType.BOOLEAN.getDisplayName(),
+ "Indicates if service interface are ordered", false, null, null, null, false));
+ props.put("availability_zone_enable", DataModelUtil
+ .createPropertyDefinition(PropertyType.BOOLEAN.getDisplayName(),
+ "Indicates availability zone is enabled", false, null, null, null, false));
+ props.put("availability_zone", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "Availability zone to create servers in", false, null, null, null, null));
+ props.put("service_instance_name", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Service instance name",
+ true, null, null, null, null));
+ props.put("interface_list", DataModelUtil
+ .createPropertyDefinition(PropertyType.LIST.getDisplayName(), "List of interfaces", false,
+ null, null, DataModelUtil
+ .createEntrySchema(ToscaDataType.CONTRAIL_INTERFACE_DATA.getDisplayName(), null,
+ null), null));
+ return props;
+ }
+
+
+ private static Map<String, DataType> createGlobalDataTypes() {
+ Map<String, DataType> globalDataTypes = new HashMap<>();
+ globalDataTypes
+ .put(ToscaDataType.CONTRAIL_INTERFACE_DATA.getDisplayName(), createInterfaceDataType());
+ return globalDataTypes;
+ }
+
+ private static DataType createInterfaceDataType() {
+ DataType dataType = new DataType();
+ dataType.setDerived_from(ToscaDataType.ROOT.getDisplayName());
+ dataType.setDescription("Interface Data");
+ Map<String, PropertyDefinition> propertyDefMap = new HashMap<>();
+ propertyDefMap.put("virtual_network", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "Virtual Network for this interface", true, null, null, null, null));
+ propertyDefMap.put("ip_address", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "IP for this interface",
+ false, null, null, null, null));
+ propertyDefMap.put("static_routes", DataModelUtil
+ .createPropertyDefinition(PropertyType.LIST.getDisplayName(),
+ "An ordered list of static routes to be added to this interface", false, null, null,
+ DataModelUtil
+ .createEntrySchema(ToscaDataType.CONTRAIL_STATIC_ROUTE.getDisplayName(), null,
+ null), null));
+ propertyDefMap.put("allowed_address_pairs", DataModelUtil
+ .createPropertyDefinition(PropertyType.LIST.getDisplayName(),
+ "List of allowed address pair for this interface", false, null, null, DataModelUtil
+ .createEntrySchema(ToscaDataType.CONTRAIL_ADDRESS_PAIR.getDisplayName(), null,
+ null), null));
+ dataType.setProperties(propertyDefMap);
+ return dataType;
+ }
+
+
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/ContrailComputeGlobalType.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/ContrailComputeGlobalType.java
new file mode 100644
index 0000000000..50faec0c69
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/ContrailComputeGlobalType.java
@@ -0,0 +1,128 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca.globaltypes;
+
+import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
+import org.openecomp.sdc.tosca.datatypes.model.AttributeDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.NodeType;
+import org.openecomp.sdc.tosca.datatypes.model.PropertyDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.PropertyType;
+import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate;
+import org.openecomp.sdc.tosca.services.DataModelUtil;
+import org.openecomp.sdc.tosca.services.ToscaConstants;
+import org.openecomp.sdc.translator.services.heattotosca.Constants;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class ContrailComputeGlobalType {
+
+ /**
+ * Create service template service template.
+ *
+ * @return the service template
+ */
+ public static ServiceTemplate createServiceTemplate() {
+ ServiceTemplate serviceTemplate = new ServiceTemplate();
+ serviceTemplate.setTosca_definitions_version(ToscaConstants.TOSCA_DEFINITIONS_VERSION);
+ serviceTemplate.setMetadata(
+ DataModelUtil.createMetadata(Constants.CONTRAIL_COMPUTE_TEMPLATE_NAME, "1.0.0", null));
+ serviceTemplate.setDescription("Contrail Compute TOSCA Global Types");
+ serviceTemplate.setImports(GlobalTypesUtil.createCommonImportList());
+ serviceTemplate.setNode_types(createGlobalNodeTypes());
+ return serviceTemplate;
+ }
+
+
+ private static Map<String, NodeType> createGlobalNodeTypes() {
+ Map<String, NodeType> globalNodeTypes = new HashMap<>();
+ globalNodeTypes
+ .put(ToscaNodeType.CONTRAIL_COMPUTE.getDisplayName(), createContrailComputeNodeType());
+ return globalNodeTypes;
+ }
+
+ private static NodeType createContrailComputeNodeType() {
+ NodeType nodeType = new NodeType();
+ nodeType.setDerived_from(ToscaNodeType.COMPUTE.getDisplayName());
+ nodeType.setProperties(createContrailComputeProperties());
+ nodeType.setAttributes(createContrailComputeAttributes());
+ return nodeType;
+ }
+
+
+ private static Map<String, PropertyDefinition> createContrailComputeProperties() {
+ Map<String, PropertyDefinition> propertyDefMap = new HashMap<>();
+ propertyDefMap.put("service_instance_name", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Service instance name",
+ true, null, null, null, null));
+ propertyDefMap.put("service_template_name", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Service template name",
+ false, null, null, null, null));
+ propertyDefMap.put("image_name", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Image name", true, null,
+ null, null, null));
+ propertyDefMap.put("service_mode", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Service mode", true,
+ DataModelUtil
+ .createValidValuesConstraintsList("transparent", "in-network", "in-network-nat"),
+ null, null, null));
+ propertyDefMap.put("service_type", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Service type", true,
+ DataModelUtil.createValidValuesConstraintsList("firewall", "analyzer", "source-nat",
+ "loadbalancer"), null, null, null));
+ propertyDefMap.put("image_name", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Image name", true, null,
+ null, null, null));
+ propertyDefMap.put("flavor", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "flavor", false, null, null,
+ null, null));
+ propertyDefMap.put("availability_zone_enable", DataModelUtil
+ .createPropertyDefinition(PropertyType.BOOLEAN.getDisplayName(),
+ "Indicates availability zone is enabled", false, null, null, null, false));
+ propertyDefMap.put("availability_zone", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "Availability zone to create servers in", false, null, null, null, null));
+ return propertyDefMap;
+ }
+
+ private static Map<String, AttributeDefinition> createContrailComputeAttributes() {
+ Map<String, AttributeDefinition> attributesDefMap = new HashMap<>();
+ attributesDefMap.put("fq_name", DataModelUtil
+ .createAttributeDefinition(PropertyType.STRING.getDisplayName(), "fq_name", null, null,
+ null));
+ attributesDefMap.put("status", DataModelUtil
+ .createAttributeDefinition(PropertyType.STRING.getDisplayName(), "status of the compute",
+ null, null, null));
+ attributesDefMap.put("virtual_machines", DataModelUtil
+ .createAttributeDefinition(PropertyType.STRING.getDisplayName(), "VMs of this compute",
+ null, null, null));
+ attributesDefMap.put("active_vms", DataModelUtil
+ .createAttributeDefinition(PropertyType.STRING.getDisplayName(), "Number of active VMs",
+ null, null, null));
+ attributesDefMap.put("tenant_id", DataModelUtil
+ .createAttributeDefinition(PropertyType.STRING.getDisplayName(), "Tenant id of the VM",
+ null, null, null));
+ attributesDefMap.put("show", DataModelUtil
+ .createAttributeDefinition(PropertyType.STRING.getDisplayName(), "All attributes", null,
+ null, null));
+ return attributesDefMap;
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/ContrailNetworkRuleGlobalType.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/ContrailNetworkRuleGlobalType.java
new file mode 100644
index 0000000000..0081ad5a78
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/ContrailNetworkRuleGlobalType.java
@@ -0,0 +1,227 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca.globaltypes;
+
+import org.openecomp.sdc.tosca.datatypes.ToscaCapabilityType;
+import org.openecomp.sdc.tosca.datatypes.ToscaDataType;
+import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
+import org.openecomp.sdc.tosca.datatypes.ToscaRelationshipType;
+import org.openecomp.sdc.tosca.datatypes.model.AttributeDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.DataType;
+import org.openecomp.sdc.tosca.datatypes.model.NodeType;
+import org.openecomp.sdc.tosca.datatypes.model.PropertyDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.PropertyType;
+import org.openecomp.sdc.tosca.datatypes.model.RequirementDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate;
+import org.openecomp.sdc.tosca.services.DataModelUtil;
+import org.openecomp.sdc.tosca.services.ToscaConstants;
+import org.openecomp.sdc.translator.services.heattotosca.Constants;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class ContrailNetworkRuleGlobalType {
+ /**
+ * Create service template service template.
+ *
+ * @return the service template
+ */
+ public static ServiceTemplate createServiceTemplate() {
+ ServiceTemplate contrailNetworkRuleServiceTemplate = new ServiceTemplate();
+ contrailNetworkRuleServiceTemplate
+ .setTosca_definitions_version(ToscaConstants.TOSCA_DEFINITIONS_VERSION);
+ contrailNetworkRuleServiceTemplate.setMetadata(
+ DataModelUtil.createMetadata(Constants.CONTRAIL_NETWORK_RULE_TEMPLATE_NAME, "1.0.0", null));
+ contrailNetworkRuleServiceTemplate.setImports(GlobalTypesUtil.createCommonImportList());
+ contrailNetworkRuleServiceTemplate.setDescription("Contrail Network Rule Global Types");
+ contrailNetworkRuleServiceTemplate.setData_types(createGlobalDataTypes());
+ contrailNetworkRuleServiceTemplate.setNode_types(createGlobalNodeTypes());
+ return contrailNetworkRuleServiceTemplate;
+ }
+
+
+ private static Map<String, DataType> createGlobalDataTypes() {
+ Map<String, DataType> globalDataTypes = new HashMap<>();
+ globalDataTypes.put(ToscaDataType.CONTRAIL_NETWORK_RULE_PORT_PAIRS.getDisplayName(),
+ createRulePortPairsDataType());
+ globalDataTypes.put(ToscaDataType.CONTRAIL_NETWORK_RULE.getDisplayName(), createRuleDataType());
+ globalDataTypes.put(ToscaDataType.CONTRAIL_NETWORK_RULE_VIRTUAL_NETWORK.getDisplayName(),
+ createRuleVirtualNetworkDataType());
+ globalDataTypes.put(ToscaDataType.CONTRAIL_NETWORK_RULE_LIST.getDisplayName(),
+ createPolicyRulesListDataType());
+ return globalDataTypes;
+ }
+
+ private static DataType createRuleDataType() {
+ DataType dataType = new DataType();
+ dataType.setDerived_from(ToscaDataType.ROOT.getDisplayName());
+ dataType.setDescription("policy rule");
+ Map<String, PropertyDefinition> properties = new HashMap<>();
+ properties.put("direction", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Direction", false, null,
+ null, null, null));
+ properties.put("protocol", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Protocol", false, null,
+ null, null, null));
+ properties.put("src_ports", DataModelUtil
+ .createPropertyDefinition(PropertyType.LIST.getDisplayName(), "Source ports", false, null,
+ null, DataModelUtil
+ .createEntrySchema(ToscaDataType.CONTRAIL_NETWORK_RULE_PORT_PAIRS.getDisplayName(),
+ null, null), null));
+ properties.put("dst_ports", DataModelUtil
+ .createPropertyDefinition(PropertyType.LIST.getDisplayName(), "Destination ports", false,
+ null, null, DataModelUtil
+ .createEntrySchema(ToscaDataType.CONTRAIL_NETWORK_RULE_PORT_PAIRS.getDisplayName(),
+ null, null), null));
+ properties.put("dst_addresses", DataModelUtil
+ .createPropertyDefinition(PropertyType.LIST.getDisplayName(), "Destination addresses",
+ false, null, null, DataModelUtil.createEntrySchema(
+ ToscaDataType.CONTRAIL_NETWORK_RULE_VIRTUAL_NETWORK.getDisplayName(), null, null),
+ null));
+ properties.put("apply_service", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Service to apply", false,
+ null, null, null, null));
+ properties.put("src_addresses", DataModelUtil
+ .createPropertyDefinition(PropertyType.LIST.getDisplayName(), "Source addresses", false,
+ null, null, DataModelUtil.createEntrySchema(
+ ToscaDataType.CONTRAIL_NETWORK_RULE_VIRTUAL_NETWORK.getDisplayName(), null, null),
+ null));
+
+ dataType.setProperties(properties);
+ return dataType;
+
+ }
+
+
+ private static DataType createRuleVirtualNetworkDataType() {
+ DataType dataType = new DataType();
+ dataType.setDerived_from(ToscaDataType.ROOT.getDisplayName());
+ dataType.setDescription("source and destination addresses");
+ Map<String, PropertyDefinition> properties = new HashMap<>();
+
+ properties.put("virtual_network", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Virtual network", false,
+ null, null, null, null));
+
+ dataType.setProperties(properties);
+ return dataType;
+ }
+
+ private static DataType createPolicyRulesListDataType() {
+ DataType dataType = new DataType();
+ dataType.setDerived_from(ToscaDataType.ROOT.getDisplayName());
+ dataType.setDescription("list of policy rules");
+ Map<String, PropertyDefinition> properties = new HashMap<>();
+
+ properties.put("policy_rule", DataModelUtil
+ .createPropertyDefinition(PropertyType.LIST.getDisplayName(), "Contrail network rule",
+ false, null, null, DataModelUtil
+ .createEntrySchema(ToscaDataType.CONTRAIL_NETWORK_RULE.getDisplayName(), null,
+ null), null));
+
+ dataType.setProperties(properties);
+ return dataType;
+ }
+
+
+ private static DataType createRulePortPairsDataType() {
+ DataType dataType = new DataType();
+ dataType.setDerived_from(ToscaDataType.ROOT.getDisplayName());
+ dataType.setDescription("source and destination port pairs");
+ Map<String, PropertyDefinition> properties = new HashMap<>();
+
+ properties.put("start_port", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Start port", false, null,
+ null, null, null));
+ properties.put("end_port", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "End port", false, null,
+ null, null, null));
+
+ dataType.setProperties(properties);
+ return dataType;
+ }
+
+ private static Map<String, NodeType> createGlobalNodeTypes() {
+ Map<String, NodeType> globalNodeTypes = new HashMap<>();
+ globalNodeTypes.put(ToscaNodeType.CONTRAIL_NETWORK_RULE.getDisplayName(),
+ createContrailNetworkRuleNodeType());
+ return globalNodeTypes;
+ }
+
+ private static NodeType createContrailNetworkRuleNodeType() {
+ NodeType contrailNetworkRuleNodeType = new NodeType();
+ contrailNetworkRuleNodeType.setDerived_from(ToscaNodeType.ROOT.getDisplayName());
+ contrailNetworkRuleNodeType.setProperties(createContrailNetworkRuleProperties());
+ contrailNetworkRuleNodeType.setAttributes(createContrailNetworkRuleAttributes());
+ contrailNetworkRuleNodeType.setRequirements(createContrailNetworkRuleRequirements());
+ return contrailNetworkRuleNodeType;
+ }
+
+
+ private static Map<String, PropertyDefinition> createContrailNetworkRuleProperties() {
+ Map<String, PropertyDefinition> contrailNetworkRulePropertyDefMap = new HashMap<>();
+ contrailNetworkRulePropertyDefMap.put(Constants.NAME_PROPERTY_NAME, DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "A symbolic name for this contrail network rule", false, null, null, null, null));
+ contrailNetworkRulePropertyDefMap.put("entries", DataModelUtil
+ .createPropertyDefinition(ToscaDataType.CONTRAIL_NETWORK_RULE_LIST.getDisplayName(),
+ "A symbolic name for this contrail network rule", false, null, null, null, null));
+
+ return contrailNetworkRulePropertyDefMap;
+ }
+
+
+ private static Map<String, AttributeDefinition> createContrailNetworkRuleAttributes() {
+ Map<String, AttributeDefinition> contrailNetworkRuleAttributesDefMap = new HashMap<>();
+ contrailNetworkRuleAttributesDefMap.put("fq_name", DataModelUtil
+ .createAttributeDefinition(PropertyType.STRING.getDisplayName(), "fq_name", null, null,
+ null));
+ contrailNetworkRuleAttributesDefMap.put("tenant_id", DataModelUtil
+ .createAttributeDefinition(PropertyType.STRING.getDisplayName(), "tenant_id", null, null,
+ null));
+ contrailNetworkRuleAttributesDefMap.put("rules", DataModelUtil
+ .createAttributeDefinition(PropertyType.LIST.getDisplayName(), "List of rules", null,
+ DataModelUtil.createEntrySchema(PropertyType.STRING.getDisplayName(), null, null),
+ null));
+ contrailNetworkRuleAttributesDefMap.put("show", DataModelUtil
+ .createAttributeDefinition(PropertyType.STRING.getDisplayName(), "All attributes.", null,
+ null, null));
+
+ return contrailNetworkRuleAttributesDefMap;
+ }
+
+ private static List<Map<String, RequirementDefinition>> createContrailNetworkRuleRequirements() {
+ final List<Map<String, RequirementDefinition>> requirements = new ArrayList<>();
+ final Map<String, RequirementDefinition>
+ contrailNetworkRuleRequirementsDefMap = new HashMap<>();
+ RequirementDefinition req = new RequirementDefinition();
+ req.setCapability(ToscaCapabilityType.ATTACHMENT.getDisplayName());
+ req.setOccurrences(new Object[]{0, ToscaConstants.UNBOUNDED});
+ req.setNode(ToscaNodeType.NETWORK.getDisplayName());
+ req.setRelationship(ToscaRelationshipType.ATTACHES_TO.getDisplayName());
+ contrailNetworkRuleRequirementsDefMap.put("network", req);
+ requirements.add(contrailNetworkRuleRequirementsDefMap);
+
+ return requirements;
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/ContrailPortGlobalType.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/ContrailPortGlobalType.java
new file mode 100644
index 0000000000..1590372813
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/ContrailPortGlobalType.java
@@ -0,0 +1,107 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca.globaltypes;
+
+import org.openecomp.sdc.tosca.datatypes.ToscaDataType;
+import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
+import org.openecomp.sdc.tosca.datatypes.model.AttributeDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.NodeType;
+import org.openecomp.sdc.tosca.datatypes.model.PropertyDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.PropertyType;
+import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate;
+import org.openecomp.sdc.tosca.services.DataModelUtil;
+import org.openecomp.sdc.tosca.services.ToscaConstants;
+import org.openecomp.sdc.translator.services.heattotosca.Constants;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class ContrailPortGlobalType {
+ /**
+ * Create service template service template.
+ *
+ * @return the service template
+ */
+ public static ServiceTemplate createServiceTemplate() {
+ ServiceTemplate serviceTemplate = new ServiceTemplate();
+ serviceTemplate.setTosca_definitions_version(ToscaConstants.TOSCA_DEFINITIONS_VERSION);
+ serviceTemplate.setMetadata(
+ DataModelUtil.createMetadata(Constants.CONTRAIL_PORT_TEMPLATE_NAME, "1.0.0", null));
+ serviceTemplate.setImports(GlobalTypesUtil.createCommonImportList());
+ serviceTemplate.setDescription("Contrail Port TOSCA Global Types");
+ serviceTemplate.setNode_types(createGlobalNodeTypes());
+ return serviceTemplate;
+ }
+
+ private static Map<String, NodeType> createGlobalNodeTypes() {
+ Map<String, NodeType> globalNodeTypes = new HashMap<>();
+ globalNodeTypes.put(ToscaNodeType.CONTRAIL_PORT.getDisplayName(), createContrailPortNodeType());
+ return globalNodeTypes;
+ }
+
+ private static NodeType createContrailPortNodeType() {
+ NodeType nodeType = new NodeType();
+ nodeType.setDerived_from(ToscaNodeType.NETWORK_PORT.getDisplayName());
+ nodeType.setProperties(createContrailPortProperties());
+ nodeType.setAttributes(createContrailPortAttributes());
+ return nodeType;
+ }
+
+ private static Map<String, PropertyDefinition> createContrailPortProperties() {
+ Map<String, PropertyDefinition> propertyDefMap = new HashMap<>();
+ propertyDefMap.put("interface_type", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Interface type", true,
+ DataModelUtil.createValidValuesConstraintsList("management", "left", "right", "other"),
+ null, null, null));
+ propertyDefMap.put("shared_ip", DataModelUtil
+ .createPropertyDefinition(PropertyType.BOOLEAN.getDisplayName(), "Shared ip enabled", false,
+ null, null, null, false));
+ propertyDefMap.put("static_route", DataModelUtil
+ .createPropertyDefinition(PropertyType.BOOLEAN.getDisplayName(), "Static route enabled",
+ false, null, null, null, false));
+ propertyDefMap.put("virtual_network", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "Virtual Network for this interface", true, null, null, null, null));
+ propertyDefMap.put("static_routes", DataModelUtil
+ .createPropertyDefinition(PropertyType.LIST.getDisplayName(),
+ "An ordered list of static routes to be added to this interface", false, null, null,
+ DataModelUtil
+ .createEntrySchema(ToscaDataType.CONTRAIL_STATIC_ROUTE.getDisplayName(), null,
+ null), null));
+ propertyDefMap.put("allowed_address_pairs", DataModelUtil
+ .createPropertyDefinition(PropertyType.LIST.getDisplayName(),
+ "List of allowed address pair for this interface", false, null, null, DataModelUtil
+ .createEntrySchema(ToscaDataType.CONTRAIL_ADDRESS_PAIR.getDisplayName(), null,
+ null), null));
+ propertyDefMap.put("ip_address", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "IP for this interface",
+ false, null, null, null, null));
+ return propertyDefMap;
+ }
+
+ private static Map<String, AttributeDefinition> createContrailPortAttributes() {
+ Map<String, AttributeDefinition> attributesDefMap = new HashMap<>();
+ attributesDefMap.put("fq_name", DataModelUtil
+ .createAttributeDefinition(PropertyType.STRING.getDisplayName(), "fq_name", null, null,
+ null));
+ return attributesDefMap;
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/ContrailV2NetworkRuleGlobalType.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/ContrailV2NetworkRuleGlobalType.java
new file mode 100644
index 0000000000..4141aa7f0a
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/ContrailV2NetworkRuleGlobalType.java
@@ -0,0 +1,274 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca.globaltypes;
+
+import org.openecomp.sdc.tosca.datatypes.ToscaCapabilityType;
+import org.openecomp.sdc.tosca.datatypes.ToscaDataType;
+import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
+import org.openecomp.sdc.tosca.datatypes.ToscaRelationshipType;
+import org.openecomp.sdc.tosca.datatypes.model.AttributeDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.DataType;
+import org.openecomp.sdc.tosca.datatypes.model.NodeType;
+import org.openecomp.sdc.tosca.datatypes.model.PropertyDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.PropertyType;
+import org.openecomp.sdc.tosca.datatypes.model.RequirementDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate;
+import org.openecomp.sdc.tosca.services.DataModelUtil;
+import org.openecomp.sdc.tosca.services.ToscaConstants;
+import org.openecomp.sdc.translator.services.heattotosca.Constants;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class ContrailV2NetworkRuleGlobalType {
+ /**
+ * Create service template service template.
+ *
+ * @return the service template
+ */
+ public static ServiceTemplate createServiceTemplate() {
+ ServiceTemplate contrailNetworkRuleServiceTemplate = new ServiceTemplate();
+ contrailNetworkRuleServiceTemplate
+ .setTosca_definitions_version(ToscaConstants.TOSCA_DEFINITIONS_VERSION);
+ contrailNetworkRuleServiceTemplate.setMetadata(
+ DataModelUtil.createMetadata(Constants
+ .CONTRAILV2_NETWORK_RULE_TEMPLATE_NAME, "1.0.0", null));
+ contrailNetworkRuleServiceTemplate.setImports(GlobalTypesUtil.createCommonImportList());
+ contrailNetworkRuleServiceTemplate.setDescription("Contrail V2 Network Rule Global Types");
+ contrailNetworkRuleServiceTemplate.setData_types(createGlobalDataTypes());
+ contrailNetworkRuleServiceTemplate.setNode_types(createGlobalNodeTypes());
+ return contrailNetworkRuleServiceTemplate;
+ }
+
+
+ private static Map<String, DataType> createGlobalDataTypes() {
+ Map<String, DataType> globalDataTypes = new HashMap<>();
+ globalDataTypes.put(ToscaDataType.CONTRAILV2_NETWORK_RULE_SRC_PORT_PAIRS.getDisplayName(),
+ createRuleSrcPortPairsDataType());
+ globalDataTypes.put(ToscaDataType.CONTRAILV2_NETWORK_RULE_DST_PORT_PAIRS.getDisplayName(),
+ createRuleDstPortPairsDataType());
+ globalDataTypes
+ .put(ToscaDataType.CONTRAILV2_NETWORK_RULE.getDisplayName(), createRuleDataType());
+ globalDataTypes.put(ToscaDataType.CONTRAILV2_NETWORK_RULE_DST_VIRTUAL_NETWORK.getDisplayName(),
+ createRuleDstVirtualNetworkDataType());
+ globalDataTypes.put(ToscaDataType.CONTRAILV2_NETWORK_RULE_SRC_VIRTUAL_NETWORK.getDisplayName(),
+ createRuleSrcVirtualNetworkDataType());
+ globalDataTypes.put(ToscaDataType.CONTRAILV2_NETWORK_RULE_LIST.getDisplayName(),
+ createPolicyRulesListDataType());
+ globalDataTypes.put(ToscaDataType.CONTRAILV2_NETWORK_RULE_ACTION_LIST.getDisplayName(),
+ createRuleActionListDataType());
+ return globalDataTypes;
+ }
+
+ private static DataType createRuleDataType() {
+ DataType dataType = new DataType();
+ dataType.setDerived_from(ToscaDataType.ROOT.getDisplayName());
+ dataType.setDescription("policy rule");
+ Map<String, PropertyDefinition> properties = new HashMap<>();
+ properties.put("network_policy_entries_policy_rule_direction", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Direction", false, null,
+ null, null, null));
+ properties.put("network_policy_entries_policy_rule_protocol", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Protocol", false, null,
+ null, null, null));
+ properties.put("network_policy_entries_policy_rule_src_ports", DataModelUtil
+ .createPropertyDefinition(PropertyType.LIST.getDisplayName(), "Source ports", false, null,
+ null, DataModelUtil.createEntrySchema(
+ ToscaDataType.CONTRAILV2_NETWORK_RULE_SRC_PORT_PAIRS.getDisplayName(), null, null),
+ null));
+ properties.put("network_policy_entries_policy_rule_dst_ports", DataModelUtil
+ .createPropertyDefinition(PropertyType.LIST.getDisplayName(), "Destination ports", false,
+ null, null, DataModelUtil.createEntrySchema(
+ ToscaDataType.CONTRAILV2_NETWORK_RULE_DST_PORT_PAIRS.getDisplayName(), null, null),
+ null));
+ properties.put("network_policy_entries_policy_rule_dst_addresses", DataModelUtil
+ .createPropertyDefinition(PropertyType.LIST.getDisplayName(), "Destination addresses",
+ false, null, null, DataModelUtil.createEntrySchema(
+ ToscaDataType.CONTRAILV2_NETWORK_RULE_DST_VIRTUAL_NETWORK.getDisplayName(), null,
+ null), null));
+ properties.put("network_policy_entries_policy_rule_src_addresses", DataModelUtil
+ .createPropertyDefinition(PropertyType.LIST.getDisplayName(), "Source addresses", false,
+ null, null, DataModelUtil.createEntrySchema(
+ ToscaDataType.CONTRAILV2_NETWORK_RULE_SRC_VIRTUAL_NETWORK.getDisplayName(), null,
+ null), null));
+ properties.put("network_policy_entries_policy_rule_action_list", DataModelUtil
+ .createPropertyDefinition(
+ ToscaDataType.CONTRAILV2_NETWORK_RULE_ACTION_LIST.getDisplayName(), "Action list",
+ false, null, null, null, null));
+
+ dataType.setProperties(properties);
+ return dataType;
+
+ }
+
+
+ private static DataType createRuleDstVirtualNetworkDataType() {
+ DataType dataType = new DataType();
+ dataType.setDerived_from(ToscaDataType.ROOT.getDisplayName());
+ dataType.setDescription("destination addresses");
+ Map<String, PropertyDefinition> properties = new HashMap<>();
+
+ properties.put("network_policy_entries_policy_rule_dst_addresses_virtual_network", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "Destination addresses Virtual network", false, null, null, null, null));
+
+ dataType.setProperties(properties);
+ return dataType;
+ }
+
+ private static DataType createRuleSrcVirtualNetworkDataType() {
+ DataType dataType = new DataType();
+ dataType.setDerived_from(ToscaDataType.ROOT.getDisplayName());
+ dataType.setDescription("source addresses");
+ Map<String, PropertyDefinition> properties = new HashMap<>();
+
+ properties.put("network_policy_entries_policy_rule_src_addresses_virtual_network", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "Source addresses Virtual network", false, null, null, null, null));
+
+ dataType.setProperties(properties);
+ return dataType;
+ }
+
+ private static DataType createPolicyRulesListDataType() {
+ DataType dataType = new DataType();
+ dataType.setDerived_from(ToscaDataType.ROOT.getDisplayName());
+ dataType.setDescription("list of policy rules");
+ Map<String, PropertyDefinition> properties = new HashMap<>();
+
+ properties.put("network_policy_entries_policy_rule", DataModelUtil
+ .createPropertyDefinition(PropertyType.LIST.getDisplayName(), "Contrail network rule",
+ false, null, null, DataModelUtil
+ .createEntrySchema(ToscaDataType.CONTRAILV2_NETWORK_RULE.getDisplayName(), null,
+ null), null));
+
+ dataType.setProperties(properties);
+ return dataType;
+ }
+
+ private static DataType createRuleActionListDataType() {
+ DataType dataType = new DataType();
+ dataType.setDerived_from(ToscaDataType.ROOT.getDisplayName());
+ dataType.setDescription("Action List");
+ Map<String, PropertyDefinition> properties = new HashMap<>();
+
+ properties.put("network_policy_entries_policy_rule_action_list_simple_action", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Simple Action", false,
+ null, null, null, null));
+ properties.put("network_policy_entries_policy_rule_action_list_apply_service", DataModelUtil
+ .createPropertyDefinition(PropertyType.LIST.getDisplayName(), "Apply Service", false, null,
+ null, DataModelUtil.createEntrySchema(PropertyType.STRING.getDisplayName(), null, null),
+ null));
+
+ dataType.setProperties(properties);
+ return dataType;
+ }
+
+ private static DataType createRuleDstPortPairsDataType() {
+ DataType dataType = new DataType();
+ dataType.setDerived_from(ToscaDataType.ROOT.getDisplayName());
+ dataType.setDescription("destination port pairs");
+ Map<String, PropertyDefinition> properties = new HashMap<>();
+
+ properties.put("network_policy_entries_policy_rule_dst_ports_start_port", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Start port", false, null,
+ null, null, null));
+ properties.put("network_policy_entries_policy_rule_dst_ports_end_port", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "End port", false, null,
+ null, null, null));
+
+ dataType.setProperties(properties);
+ return dataType;
+ }
+
+ private static DataType createRuleSrcPortPairsDataType() {
+ DataType dataType = new DataType();
+ dataType.setDerived_from(ToscaDataType.ROOT.getDisplayName());
+ dataType.setDescription("source port pairs");
+ Map<String, PropertyDefinition> properties = new HashMap<>();
+
+ properties.put("network_policy_entries_policy_rule_src_ports_start_port", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Start port", false, null,
+ null, null, null));
+ properties.put("network_policy_entries_policy_rule_src_ports_end_port", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "End port", false, null,
+ null, null, null));
+
+ dataType.setProperties(properties);
+ return dataType;
+ }
+
+ private static Map<String, NodeType> createGlobalNodeTypes() {
+ Map<String, NodeType> globalNodeTypes = new HashMap<>();
+ globalNodeTypes.put(ToscaNodeType.CONTRAILV2_NETWORK_RULE.getDisplayName(),
+ createContrailV2NetworkRuleNodeType());
+ return globalNodeTypes;
+ }
+
+ private static NodeType createContrailV2NetworkRuleNodeType() {
+ NodeType contrailNetworkRuleNodeType = new NodeType();
+ contrailNetworkRuleNodeType.setDerived_from(ToscaNodeType.ROOT.getDisplayName());
+ contrailNetworkRuleNodeType.setProperties(createContrailNetworkRuleProperties());
+ contrailNetworkRuleNodeType.setAttributes(createContrailNetworkRuleAttributes());
+ contrailNetworkRuleNodeType.setRequirements(createContrailNetworkRuleRequirements());
+ return contrailNetworkRuleNodeType;
+ }
+
+
+ private static Map<String, PropertyDefinition> createContrailNetworkRuleProperties() {
+ Map<String, PropertyDefinition> contrailNetworkRulePropertyDefMap = new HashMap<>();
+ contrailNetworkRulePropertyDefMap.put(Constants.NAME_PROPERTY_NAME, DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "A symbolic name for this contrail v2 network rule", false, null, null, null, null));
+ contrailNetworkRulePropertyDefMap.put("network_policy_entries", DataModelUtil
+ .createPropertyDefinition(ToscaDataType.CONTRAILV2_NETWORK_RULE_LIST.getDisplayName(),
+ "A symbolic name for this contrail v2 network rule", false, null, null, null, null));
+
+ return contrailNetworkRulePropertyDefMap;
+ }
+
+
+ private static Map<String, AttributeDefinition> createContrailNetworkRuleAttributes() {
+ Map<String, AttributeDefinition> contrailNetworkRuleAttributesDefMap = new HashMap<>();
+ contrailNetworkRuleAttributesDefMap.put("fq_name", DataModelUtil
+ .createAttributeDefinition(PropertyType.STRING.getDisplayName(), "fq_name", null, null,
+ null));
+
+ return contrailNetworkRuleAttributesDefMap;
+ }
+
+ private static List<Map<String, RequirementDefinition>> createContrailNetworkRuleRequirements() {
+ final List<Map<String, RequirementDefinition>> requirements = new ArrayList<>();
+ final Map<String, RequirementDefinition>
+ contrailNetworkRuleRequirementsDefMap = new HashMap<>();
+ RequirementDefinition req = new RequirementDefinition();
+ req.setCapability(ToscaCapabilityType.ATTACHMENT.getDisplayName());
+ req.setOccurrences(new Object[]{0, ToscaConstants.UNBOUNDED});
+ req.setNode(ToscaNodeType.NETWORK.getDisplayName());
+ req.setRelationship(ToscaRelationshipType.ATTACHES_TO.getDisplayName());
+ contrailNetworkRuleRequirementsDefMap.put("network", req);
+ requirements.add(contrailNetworkRuleRequirementsDefMap);
+
+ return requirements;
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/ContrailV2VirtualMachineInterfaceGlobalType.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/ContrailV2VirtualMachineInterfaceGlobalType.java
new file mode 100644
index 0000000000..75501cb8d4
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/ContrailV2VirtualMachineInterfaceGlobalType.java
@@ -0,0 +1,136 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca.globaltypes;
+
+import org.openecomp.sdc.tosca.datatypes.ToscaDataType;
+import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
+import org.openecomp.sdc.tosca.datatypes.model.AttributeDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.DataType;
+import org.openecomp.sdc.tosca.datatypes.model.NodeType;
+import org.openecomp.sdc.tosca.datatypes.model.PropertyDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.PropertyType;
+import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate;
+import org.openecomp.sdc.tosca.services.DataModelUtil;
+import org.openecomp.sdc.tosca.services.ToscaConstants;
+import org.openecomp.sdc.translator.services.heattotosca.Constants;
+
+import java.util.HashMap;
+import java.util.Map;
+
+class ContrailV2VirtualMachineInterfaceGlobalType {
+ private ContrailV2VirtualMachineInterfaceGlobalType() {
+ }
+
+ public static ServiceTemplate createServiceTemplate() {
+ ServiceTemplate contrailVirtualMachineInterface = new ServiceTemplate();
+ contrailVirtualMachineInterface
+ .setTosca_definitions_version(ToscaConstants.TOSCA_DEFINITIONS_VERSION);
+ contrailVirtualMachineInterface.setMetadata(DataModelUtil
+ .createMetadata(Constants.CONTRAILV2_VIRTUAL_MACHINE_INTERFACE_TEMPLATE_NAME, "1.0.0",
+ null));
+ contrailVirtualMachineInterface.setImports(GlobalTypesUtil.createCommonImportList());
+ contrailVirtualMachineInterface
+ .setDescription("Contrail Virtual Machine Interface TOSCA Global Types");
+ contrailVirtualMachineInterface.setNode_types(createGlobalNodeTypes());
+ contrailVirtualMachineInterface.setData_types(createGlobalDataTypes());
+ return contrailVirtualMachineInterface;
+ }
+
+ private static Map<String, DataType> createGlobalDataTypes() {
+ Map<String, DataType> globalDataTypes = new HashMap<>();
+ globalDataTypes
+ .put(ToscaDataType.CONTRAILV2_VIRTUAL_MACHINE_INTERFACE_PROPERTIES.getDisplayName(),
+ createVmiPropertiesDataType());
+ return globalDataTypes;
+ }
+
+ private static DataType createVmiPropertiesDataType() {
+ DataType dataType = new DataType();
+ dataType.setDerived_from(ToscaDataType.ROOT.getDisplayName());
+ dataType.setDescription("Virtual Machine Interface Properties.");
+ Map<String, PropertyDefinition> properties = new HashMap<>();
+
+ properties.put("virtual_machine_interface_properties_service_interface_type", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Service Interface Type.",
+ false, null, null, null, null));
+ dataType.setProperties(properties);
+ return dataType;
+ }
+
+ private static Map<String, NodeType> createGlobalNodeTypes() {
+ Map<String, NodeType> globalNodeTypes = new HashMap<>();
+ globalNodeTypes.put(ToscaNodeType.CONTRAILV2_VIRTUAL_MACHINE_INTERFACE.getDisplayName(),
+ createVmiNodeType());
+ return globalNodeTypes;
+ }
+
+ private static NodeType createVmiNodeType() {
+ NodeType nodeType = new NodeType();
+ nodeType.setDerived_from(ToscaNodeType.NETWORK_PORT.getDisplayName());
+ nodeType.setProperties(createVmiProperties());
+ nodeType.setAttributes(createVmiAttributes());
+ return nodeType;
+ }
+
+ private static Map<String, AttributeDefinition> createVmiAttributes() {
+ Map<String, AttributeDefinition> vmiAttributesDefMap = new HashMap<>();
+ vmiAttributesDefMap.put("fq_name", DataModelUtil
+ .createAttributeDefinition(PropertyType.STRING.getDisplayName(),
+ "The FQ name of the Virtual Network.", null, null, null));
+ vmiAttributesDefMap.put("show", DataModelUtil
+ .createAttributeDefinition(PropertyType.STRING.getDisplayName(), "All attributes.", null,
+ null, null));
+ return vmiAttributesDefMap;
+ }
+
+ private static Map<String, PropertyDefinition> createVmiProperties() {
+ Map<String, PropertyDefinition> virtualMachineInterfacePropertyDefMap = new HashMap<>();
+ virtualMachineInterfacePropertyDefMap.put(Constants.NAME_PROPERTY_NAME, DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "Virtual Machine Interface name", false, null, null, null, null));
+ virtualMachineInterfacePropertyDefMap.put("virtual_machine_intefrace_mac_addresses",
+ DataModelUtil
+ .createPropertyDefinition(PropertyType.LIST.getDisplayName(), "List of mac addresses.",
+ false, null, null,
+ DataModelUtil.createEntrySchema(PropertyType.STRING.getDisplayName(), null, null),
+ null));
+ virtualMachineInterfacePropertyDefMap.put("virtual_network_refs", DataModelUtil
+ .createPropertyDefinition(PropertyType.LIST.getDisplayName(), "List of virtual networks.",
+ false, null, null,
+ DataModelUtil.createEntrySchema(PropertyType.STRING.getDisplayName(), null, null),
+ null));
+ virtualMachineInterfacePropertyDefMap.put("port_tuple_refs", DataModelUtil
+ .createPropertyDefinition(PropertyType.LIST.getDisplayName(), "List of port tuples.", false,
+ null, null,
+ DataModelUtil.createEntrySchema(PropertyType.STRING.getDisplayName(), null, null),
+ null));
+ virtualMachineInterfacePropertyDefMap.put("security_group_refs", DataModelUtil
+ .createPropertyDefinition(PropertyType.LIST.getDisplayName(), "List of security groups.",
+ false, null, null,
+ DataModelUtil.createEntrySchema(PropertyType.STRING.getDisplayName(), null, null),
+ null));
+ virtualMachineInterfacePropertyDefMap.put("virtual_machine_interface_properties", DataModelUtil
+ .createPropertyDefinition(
+ ToscaDataType.CONTRAILV2_VIRTUAL_MACHINE_INTERFACE_PROPERTIES.getDisplayName(),
+ "virtual machine interface properties.", false, null, null, null, null));
+ return virtualMachineInterfacePropertyDefMap;
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/ContrailV2VirtualNetworkGlobalType.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/ContrailV2VirtualNetworkGlobalType.java
new file mode 100644
index 0000000000..728b9f6149
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/ContrailV2VirtualNetworkGlobalType.java
@@ -0,0 +1,239 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca.globaltypes;
+
+import org.openecomp.sdc.tosca.datatypes.ToscaDataType;
+import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
+import org.openecomp.sdc.tosca.datatypes.model.AttributeDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.CapabilityDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.DataType;
+import org.openecomp.sdc.tosca.datatypes.model.NodeType;
+import org.openecomp.sdc.tosca.datatypes.model.PropertyDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.PropertyType;
+import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate;
+import org.openecomp.sdc.tosca.services.DataModelUtil;
+import org.openecomp.sdc.tosca.services.ToscaConstants;
+import org.openecomp.sdc.translator.services.heattotosca.Constants;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class ContrailV2VirtualNetworkGlobalType {
+
+ /**
+ * Create service template service template.
+ *
+ * @return the service template
+ */
+ public static ServiceTemplate createServiceTemplate() {
+ ServiceTemplate contrailVirtualNetworkServiceTemplate = new ServiceTemplate();
+ contrailVirtualNetworkServiceTemplate
+ .setTosca_definitions_version(ToscaConstants.TOSCA_DEFINITIONS_VERSION);
+ contrailVirtualNetworkServiceTemplate.setMetadata(DataModelUtil
+ .createMetadata(Constants.CONTRAILV2_VIRTUAL_NETWORK_TEMPLATE_NAME, "1.0.0", null));
+ contrailVirtualNetworkServiceTemplate
+ .setDescription("Contrail V2 Virtual Network Global Types");
+ contrailVirtualNetworkServiceTemplate.setImports(GlobalTypesUtil.createCommonImportList());
+ contrailVirtualNetworkServiceTemplate.setNode_types(createGlobalNodeTypes());
+ contrailVirtualNetworkServiceTemplate.setData_types(createGlobalDataTypes());
+ return contrailVirtualNetworkServiceTemplate;
+ }
+
+ private static Map<String, NodeType> createGlobalNodeTypes() {
+ Map<String, NodeType> globalNodeTypes = new HashMap<>();
+ globalNodeTypes.put(ToscaNodeType.CONTRAILV2_VIRTUAL_NETWORK.getDisplayName(),
+ createContrailVirtualNetworkNodeType());
+ return globalNodeTypes;
+ }
+
+ private static NodeType createContrailVirtualNetworkNodeType() {
+ NodeType contrailV2VirtualNetworkNodeType = new NodeType();
+ contrailV2VirtualNetworkNodeType.setDerived_from(ToscaNodeType.NETWORK.getDisplayName());
+ contrailV2VirtualNetworkNodeType.setProperties(createContrailVirtualNetworkProperties());
+ contrailV2VirtualNetworkNodeType.setAttributes(createContrailVirtualNetworkAttributes());
+ contrailV2VirtualNetworkNodeType.setCapabilities(createContrailVirtualNetworkCapabilities());
+ return contrailV2VirtualNetworkNodeType;
+ }
+
+ private static Map<String, CapabilityDefinition> createContrailVirtualNetworkCapabilities() {
+ Map<String, CapabilityDefinition> capabilities = new HashMap<>();
+ capabilities.put("attachment", GlobalTypesUtil.createAttachmentCapability());
+ return capabilities;
+ }
+
+ private static Map<String, PropertyDefinition> createContrailVirtualNetworkProperties() {
+ Map<String, PropertyDefinition> contrailVirtualNetworkPropertyDefMap = new HashMap<>();
+ //contrailVirtualNetworkPropertyDefMap.put("name", DataModelUtil.
+ // createPropertyDefinition(PropertyType.STRING.getDisplayName()
+ // , "Name", false, null, null, null, null));
+ contrailVirtualNetworkPropertyDefMap.put("network_ipam_refs", DataModelUtil
+ .createPropertyDefinition(PropertyType.LIST.getDisplayName(), "IPAM references", false,
+ null, null,
+ DataModelUtil.createEntrySchema(PropertyType.STRING.getDisplayName(), null, null),
+ null));
+ contrailVirtualNetworkPropertyDefMap.put("network_ipam_refs_data", DataModelUtil
+ .createPropertyDefinition(PropertyType.LIST.getDisplayName(), "IPAM references Data", false,
+ null, null, DataModelUtil.createEntrySchema(
+ ToscaDataType.CONTRAILV2_VIRTUAL_NETWORK_IPAM_REF_DATA.getDisplayName(), null,
+ null), null));
+ contrailVirtualNetworkPropertyDefMap.put("network_policy_refs", DataModelUtil
+ .createPropertyDefinition(PropertyType.LIST.getDisplayName(), "Policy references", false,
+ null, null,
+ DataModelUtil.createEntrySchema(PropertyType.STRING.getDisplayName(), null, null),
+ null));
+ contrailVirtualNetworkPropertyDefMap.put("network_policy_refs_data", DataModelUtil
+ .createPropertyDefinition(PropertyType.LIST.getDisplayName(), "Policy references data",
+ false, null, null, DataModelUtil.createEntrySchema(
+ ToscaDataType.CONTRAILV2_VIRTUAL_NETWORK_POLICY_REF_DATA.getDisplayName(), null,
+ null), null));
+ contrailVirtualNetworkPropertyDefMap.put("subnets", DataModelUtil
+ .createPropertyDefinition(PropertyType.MAP.getDisplayName(), "Network related subnets",
+ false, null, null, DataModelUtil
+ .createEntrySchema(ToscaDataType.NEUTRON_SUBNET.getDisplayName(), null, null),
+ null));
+ return contrailVirtualNetworkPropertyDefMap;
+ }
+
+ private static Map<String, DataType> createGlobalDataTypes() {
+ Map<String, DataType> globalDataTypes = new HashMap<>();
+ globalDataTypes.put(ToscaDataType.CONTRAILV2_VIRTUAL_NETWORK_IPAM_REF_DATA.getDisplayName(),
+ createVirtualNetworkIpamRefDataDataType());
+ globalDataTypes.put(
+ ToscaDataType.CONTRAILV2_VIRTUAL_NETWORK_IPAM_REF_DATA_IPAM_SUBNET_LIST.getDisplayName(),
+ createVirtualNetworkIpamRefDataIpanSubnetListDataType());
+ globalDataTypes
+ .put(ToscaDataType.CONTRAILV2_VIRTUAL_NETWORK_IPAM_REF_DATA_IPAM_SUBNET.getDisplayName(),
+ createVirtualNetworkIpamRefDataIpanSubnetDataType());
+ globalDataTypes.put(ToscaDataType.CONTRAILV2_VIRTUAL_NETWORK_POLICY_REF_DATA.getDisplayName(),
+ createVirtualNetworkPolicyRefDataDataType());
+ globalDataTypes
+ .put(ToscaDataType.CONTRAILV2_VIRTUAL_NETWORK_POLICY_REF_DATA_SEQUENCE.getDisplayName(),
+ createVirtualNetworkPolicyRefSequenceDataDataType());
+ return globalDataTypes;
+ }
+
+ private static DataType createVirtualNetworkIpamRefDataDataType() {
+ DataType dataType = new DataType();
+ dataType.setDerived_from(ToscaDataType.ROOT.getDisplayName());
+ dataType.setDescription("Network Ipam Ref Data");
+ Map<String, PropertyDefinition> properties = new HashMap<>();
+
+ properties.put("network_ipam_refs_data_ipam_subnets", DataModelUtil
+ .createPropertyDefinition(PropertyType.LIST.getDisplayName(),
+ "Network ipam refs data ipam subnets", false, null, null, DataModelUtil
+ .createEntrySchema(
+ ToscaDataType.CONTRAILV2_VIRTUAL_NETWORK_IPAM_REF_DATA_IPAM_SUBNET_LIST
+ .getDisplayName(), null, null), null));
+ dataType.setProperties(properties);
+ return dataType;
+ }
+
+ private static DataType createVirtualNetworkIpamRefDataIpanSubnetListDataType() {
+ DataType dataType = new DataType();
+ dataType.setDerived_from(ToscaDataType.ROOT.getDisplayName());
+ dataType.setDescription("Network Ipam Ref Data Subnet List");
+ Map<String, PropertyDefinition> properties = new HashMap<>();
+
+ properties.put("network_ipam_refs_data_ipam_subnets_subnet", DataModelUtil
+ .createPropertyDefinition(
+ ToscaDataType.CONTRAILV2_VIRTUAL_NETWORK_IPAM_REF_DATA_IPAM_SUBNET.getDisplayName(),
+ "Network ipam refs data ipam subnets", false, null, null, null, null));
+ properties.put("network_ipam_refs_data_ipam_subnets_addr_from_start", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "Network ipam refs data ipam subnets addr from start", false, null, null, null, null));
+
+ dataType.setProperties(properties);
+ return dataType;
+ }
+
+ private static DataType createVirtualNetworkIpamRefDataIpanSubnetDataType() {
+ DataType dataType = new DataType();
+ dataType.setDerived_from(ToscaDataType.ROOT.getDisplayName());
+ dataType.setDescription("Network Ipam Ref Data Subnet");
+ Map<String, PropertyDefinition> properties = new HashMap<>();
+
+ properties.put("network_ipam_refs_data_ipam_subnets_subnet_ip_prefix", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "Network ipam refs data ipam subnets ip prefix", false, null, null, null, null));
+ properties.put("network_ipam_refs_data_ipam_subnets_subnet_ip_prefix_len", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "Network ipam refs data ipam subnets ip prefix len", false, null, null, null, null));
+ dataType.setProperties(properties);
+ return dataType;
+ }
+
+
+ private static DataType createVirtualNetworkPolicyRefDataDataType() {
+ DataType dataType = new DataType();
+ dataType.setDerived_from(ToscaDataType.ROOT.getDisplayName());
+ dataType.setDescription("network policy refs data");
+ Map<String, PropertyDefinition> properties = new HashMap<>();
+
+ properties.put("network_policy_refs_data_sequence", DataModelUtil.createPropertyDefinition(
+ ToscaDataType.CONTRAILV2_VIRTUAL_NETWORK_POLICY_REF_DATA_SEQUENCE.getDisplayName(),
+ "Network Policy ref data sequence", false, null, null, null, null));
+
+
+ dataType.setProperties(properties);
+ return dataType;
+ }
+
+
+ private static DataType createVirtualNetworkPolicyRefSequenceDataDataType() {
+ DataType dataType = new DataType();
+ dataType.setDerived_from(ToscaDataType.ROOT.getDisplayName());
+ dataType.setDescription("network policy refs data sequence");
+ Map<String, PropertyDefinition> properties = new HashMap<>();
+
+ properties.put("network_policy_refs_data_sequence_major", DataModelUtil
+ .createPropertyDefinition(PropertyType.INTEGER.getDisplayName(),
+ "Network Policy ref data sequence Major", false, null, null, null, null));
+ properties.put("network_policy_refs_data_sequence_minor", DataModelUtil
+ .createPropertyDefinition(PropertyType.INTEGER.getDisplayName(),
+ "Network Policy ref data sequence Minor", false, null, null, null, null));
+
+ dataType.setProperties(properties);
+ return dataType;
+ }
+
+ private static Map<String, AttributeDefinition> createContrailVirtualNetworkAttributes() {
+ Map<String, AttributeDefinition> contrailVirtualNetworkAttributesDefMap = new HashMap<>();
+ contrailVirtualNetworkAttributesDefMap.put("subnets_name", DataModelUtil
+ .createAttributeDefinition(PropertyType.LIST.getDisplayName(),
+ "Subnets name of this network", null,
+ DataModelUtil.createEntrySchema(PropertyType.STRING.getDisplayName(), null, null),
+ null));
+ contrailVirtualNetworkAttributesDefMap.put("subnets", DataModelUtil
+ .createAttributeDefinition(PropertyType.MAP.getDisplayName(), "Network related subnets",
+ null, DataModelUtil
+ .createEntrySchema(ToscaDataType.NEUTRON_SUBNET.getDisplayName(), null, null),
+ null));
+ contrailVirtualNetworkAttributesDefMap.put("subnets_show", DataModelUtil
+ .createAttributeDefinition(PropertyType.MAP.getDisplayName(),
+ "Detailed information about each subnet", null,
+ DataModelUtil.createEntrySchema(PropertyType.STRING.getDisplayName(), null, null),
+ null));
+ contrailVirtualNetworkAttributesDefMap.put("fq_name", DataModelUtil
+ .createAttributeDefinition(PropertyType.STRING.getDisplayName(), "fq_name", null, null,
+ null));
+ return contrailVirtualNetworkAttributesDefMap;
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/ContrailVirtualNetworkGlobalType.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/ContrailVirtualNetworkGlobalType.java
new file mode 100644
index 0000000000..1014757a2c
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/ContrailVirtualNetworkGlobalType.java
@@ -0,0 +1,134 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca.globaltypes;
+
+import org.openecomp.sdc.tosca.datatypes.ToscaDataType;
+import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
+import org.openecomp.sdc.tosca.datatypes.model.AttributeDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.CapabilityDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.NodeType;
+import org.openecomp.sdc.tosca.datatypes.model.PropertyDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.PropertyType;
+import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate;
+import org.openecomp.sdc.tosca.services.DataModelUtil;
+import org.openecomp.sdc.tosca.services.ToscaConstants;
+import org.openecomp.sdc.translator.services.heattotosca.Constants;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class ContrailVirtualNetworkGlobalType {
+
+ /**
+ * Create service template service template.
+ *
+ * @return the service template
+ */
+ public static ServiceTemplate createServiceTemplate() {
+ ServiceTemplate contrailVirtualNetworkServiceTemplate = new ServiceTemplate();
+ contrailVirtualNetworkServiceTemplate
+ .setTosca_definitions_version(ToscaConstants.TOSCA_DEFINITIONS_VERSION);
+ contrailVirtualNetworkServiceTemplate.setMetadata(DataModelUtil
+ .createMetadata(Constants.CONTRAIL_VIRTUAL_NETWORK_TEMPLATE_NAME, "1.0.0", null));
+ contrailVirtualNetworkServiceTemplate.setDescription("Contrail Virtual Network Global Types");
+ contrailVirtualNetworkServiceTemplate.setImports(GlobalTypesUtil.createCommonImportList());
+ contrailVirtualNetworkServiceTemplate.setNode_types(createGlobalNodeTypes());
+ return contrailVirtualNetworkServiceTemplate;
+ }
+
+ private static Map<String, NodeType> createGlobalNodeTypes() {
+ Map<String, NodeType> globalNodeTypes = new HashMap<>();
+ globalNodeTypes.put(ToscaNodeType.CONTRAIL_VIRTUAL_NETWORK.getDisplayName(),
+ createContrailVirtualNetworkNodeType());
+ return globalNodeTypes;
+ }
+
+ private static NodeType createContrailVirtualNetworkNodeType() {
+ NodeType contrailVirtualNetworkNodeType = new NodeType();
+ contrailVirtualNetworkNodeType.setDerived_from(ToscaNodeType.NETWORK.getDisplayName());
+ contrailVirtualNetworkNodeType.setProperties(createContrailVirtualNetworkProperties());
+ contrailVirtualNetworkNodeType.setAttributes(createContrailVirtualNetworkAttributes());
+ contrailVirtualNetworkNodeType.setCapabilities(createContrailVirtualNetworkCapabilities());
+ return contrailVirtualNetworkNodeType;
+ }
+
+ private static Map<String, CapabilityDefinition> createContrailVirtualNetworkCapabilities() {
+ Map<String, CapabilityDefinition> capabilities = new HashMap<>();
+ capabilities.put("attachment", GlobalTypesUtil.createAttachmentCapability());
+ return capabilities;
+ }
+
+ private static Map<String, PropertyDefinition> createContrailVirtualNetworkProperties() {
+ Map<String, PropertyDefinition> contrailVirtualNetworkPropertyDefMap = new HashMap<>();
+ contrailVirtualNetworkPropertyDefMap.put("shared", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Is virtual network shared",
+ false, null, null, null, null));
+ contrailVirtualNetworkPropertyDefMap.put("external", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "Is virtual network external", false, null, null, null, null));
+ contrailVirtualNetworkPropertyDefMap.put("allow_transit", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "Whether this network should be transitive.", false, null, null, null, null));
+ contrailVirtualNetworkPropertyDefMap.put("route_targets", DataModelUtil
+ .createPropertyDefinition(PropertyType.LIST.getDisplayName(),
+ "route targets associated with the virtual network", false, null, null,
+ DataModelUtil.createEntrySchema(PropertyType.STRING.getDisplayName(), null, null),
+ null));
+ contrailVirtualNetworkPropertyDefMap.put("forwarding_mode", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "forwarding mode of the virtual network", false, null, null, null, null));
+ contrailVirtualNetworkPropertyDefMap.put("flood_unknown_unicast", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "flood L2 packets on network", false, null, null, null, null));
+ contrailVirtualNetworkPropertyDefMap.put("subnets", DataModelUtil
+ .createPropertyDefinition(PropertyType.MAP.getDisplayName(), "Network related subnets",
+ false, null, null, DataModelUtil
+ .createEntrySchema(ToscaDataType.NEUTRON_SUBNET.getDisplayName(), null, null),
+ null));
+ return contrailVirtualNetworkPropertyDefMap;
+ }
+
+ private static Map<String, AttributeDefinition> createContrailVirtualNetworkAttributes() {
+ Map<String, AttributeDefinition> contrailVirtualNetworkAttributesDefMap = new HashMap<>();
+ contrailVirtualNetworkAttributesDefMap.put("subnets_name", DataModelUtil
+ .createAttributeDefinition(PropertyType.LIST.getDisplayName(),
+ "Subnets name of this network", null,
+ DataModelUtil.createEntrySchema(PropertyType.STRING.getDisplayName(), null, null),
+ null));
+ contrailVirtualNetworkAttributesDefMap.put("subnets", DataModelUtil
+ .createAttributeDefinition(PropertyType.MAP.getDisplayName(), "Network related subnets",
+ null, DataModelUtil
+ .createEntrySchema(ToscaDataType.NEUTRON_SUBNET.getDisplayName(), null, null),
+ null));
+ contrailVirtualNetworkAttributesDefMap.put("subnets_show", DataModelUtil
+ .createAttributeDefinition(PropertyType.MAP.getDisplayName(),
+ "Detailed information about each subnet", null,
+ DataModelUtil.createEntrySchema(PropertyType.STRING.getDisplayName(), null, null),
+ null));
+ contrailVirtualNetworkAttributesDefMap.put("fq_name", DataModelUtil
+ .createAttributeDefinition(PropertyType.STRING.getDisplayName(), "fq_name", null, null,
+ null));
+ contrailVirtualNetworkAttributesDefMap.put("show", DataModelUtil
+ .createAttributeDefinition(PropertyType.STRING.getDisplayName(), "All attributes.", null,
+ null, null));
+ return contrailVirtualNetworkAttributesDefMap;
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/GlobalTypesGenerator.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/GlobalTypesGenerator.java
new file mode 100644
index 0000000000..a4ec764e14
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/GlobalTypesGenerator.java
@@ -0,0 +1,128 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca.globaltypes;
+
+import org.openecomp.sdc.tosca.datatypes.model.Import;
+import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate;
+import org.openecomp.sdc.tosca.services.ToscaNativeTypesServiceTemplate;
+import org.openecomp.sdc.tosca.services.ToscaUtil;
+import org.openecomp.sdc.translator.services.heattotosca.Constants;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class GlobalTypesGenerator {
+
+ private GlobalTypesGenerator() {
+ }
+
+ /**
+ * Gets global types service template.
+ *
+ * @return the global types service template
+ */
+ public static Map<String, ServiceTemplate> getGlobalTypesServiceTemplate() {
+ Map<String, ServiceTemplate> serviceTemplates = new HashMap<>();
+
+ ToscaUtil.addServiceTemplateToMapWithKeyFileName(serviceTemplates,
+ CommonGlobalTypes.createServiceTemplate());
+ ToscaUtil.addServiceTemplateToMapWithKeyFileName(serviceTemplates,
+ NovaServerGlobalType.createServiceTemplate());
+ ToscaUtil.addServiceTemplateToMapWithKeyFileName(serviceTemplates,
+ CinderVolumeGlobalType.createServiceTemplate());
+ ToscaUtil.addServiceTemplateToMapWithKeyFileName(serviceTemplates,
+ ContrailVirtualNetworkGlobalType.createServiceTemplate());
+ ToscaUtil.addServiceTemplateToMapWithKeyFileName(serviceTemplates,
+ ContrailV2VirtualNetworkGlobalType.createServiceTemplate());
+ ToscaUtil.addServiceTemplateToMapWithKeyFileName(serviceTemplates,
+ ContrailV2VirtualMachineInterfaceGlobalType.createServiceTemplate());
+ ToscaUtil.addServiceTemplateToMapWithKeyFileName(serviceTemplates,
+ NeutronNetGlobalType.createServiceTemplate());
+ ToscaUtil.addServiceTemplateToMapWithKeyFileName(serviceTemplates,
+ NeutronPortGlobalType.createServiceTemplate());
+ ToscaUtil.addServiceTemplateToMapWithKeyFileName(serviceTemplates,
+ ContrailNetworkRuleGlobalType.createServiceTemplate());
+ ToscaUtil.addServiceTemplateToMapWithKeyFileName(serviceTemplates,
+ ContrailV2NetworkRuleGlobalType.createServiceTemplate());
+ ToscaUtil.addServiceTemplateToMapWithKeyFileName(serviceTemplates,
+ NeutronSecurityRulesGlobalType.createServiceTemplate());
+ ToscaUtil.addServiceTemplateToMapWithKeyFileName(serviceTemplates,
+ AbstractSubstituteGlobalType.createServiceTemplate());
+ ToscaUtil.addServiceTemplateToMapWithKeyFileName(serviceTemplates,
+ ToscaNativeTypesServiceTemplate.createServiceTemplate());
+ ToscaUtil.addServiceTemplateToMapWithKeyFileName(serviceTemplates,
+ ContrailComputeGlobalType.createServiceTemplate());
+ ToscaUtil.addServiceTemplateToMapWithKeyFileName(serviceTemplates,
+ ContrailPortGlobalType.createServiceTemplate());
+ ToscaUtil.addServiceTemplateToMapWithKeyFileName(serviceTemplates,
+ ContrailV2NetworkRuleGlobalType.createServiceTemplate());
+ ToscaUtil.addServiceTemplateToMapWithKeyFileName(serviceTemplates,
+ ContrailV2VirtualNetworkGlobalType.createServiceTemplate());
+ ToscaUtil.addServiceTemplateToMapWithKeyFileName(serviceTemplates,
+ ContrailAbstractSubstituteGlobalType.createServiceTemplate());
+ return serviceTemplates;
+ }
+
+ private static void addGlobalServiceTemplate(Map<String, ServiceTemplate> serviceTemplates,
+ ServiceTemplate commonServiceTemplate) {
+ serviceTemplates
+ .put(ToscaUtil.getServiceTemplateFileName(commonServiceTemplate), commonServiceTemplate);
+ }
+
+ /**
+ * Gets global types import list.
+ *
+ * @return the global types import list
+ */
+ public static Map<String, Import> getGlobalTypesImportList() {
+ Map<String, Import> globalImportMap = new HashMap<>();
+ globalImportMap.put(Constants.COMMON_GLOBAL_TEMPLATE_NAME,
+ GlobalTypesUtil.createServiceTemplateImport(Constants.COMMON_GLOBAL_TEMPLATE_NAME));
+ globalImportMap.put(Constants.NOVA_SERVER_TEMPLATE_NAME,
+ GlobalTypesUtil.createServiceTemplateImport(Constants.NOVA_SERVER_TEMPLATE_NAME));
+ globalImportMap.put(Constants.NEUTRON_PORT_TEMPLATE_NAME,
+ GlobalTypesUtil.createServiceTemplateImport(Constants.NEUTRON_PORT_TEMPLATE_NAME));
+ globalImportMap.put(Constants.NEUTRON_SECURITY_RULES_TEMPLATE_NAME, GlobalTypesUtil
+ .createServiceTemplateImport(Constants.NEUTRON_SECURITY_RULES_TEMPLATE_NAME));
+ globalImportMap.put(Constants.NEUTRON_NET_TEMPLATE_NAME,
+ GlobalTypesUtil.createServiceTemplateImport(Constants.NEUTRON_NET_TEMPLATE_NAME));
+ globalImportMap.put(Constants.CINDER_VOLUME_TEMPLATE_NAME,
+ GlobalTypesUtil.createServiceTemplateImport(Constants.CINDER_VOLUME_TEMPLATE_NAME));
+ globalImportMap.put(Constants.CONTRAIL_VIRTUAL_NETWORK_TEMPLATE_NAME, GlobalTypesUtil
+ .createServiceTemplateImport(Constants.CONTRAIL_VIRTUAL_NETWORK_TEMPLATE_NAME));
+ globalImportMap.put(Constants.CONTRAIL_NETWORK_RULE_TEMPLATE_NAME,
+ GlobalTypesUtil.createServiceTemplateImport(Constants.CONTRAIL_NETWORK_RULE_TEMPLATE_NAME));
+ globalImportMap.put(Constants.ABSTRACT_SUBSTITUTE_TEMPLATE_NAME,
+ GlobalTypesUtil.createServiceTemplateImport(Constants.ABSTRACT_SUBSTITUTE_TEMPLATE_NAME));
+ globalImportMap.put(Constants.CONTRAILV2_VIRTUAL_MACHINE_INTERFACE_TEMPLATE_NAME,
+ GlobalTypesUtil.createServiceTemplateImport(
+ Constants.CONTRAILV2_VIRTUAL_MACHINE_INTERFACE_TEMPLATE_NAME));
+ globalImportMap.put(Constants.CONTRAIL_COMPUTE_TEMPLATE_NAME,
+ GlobalTypesUtil.createServiceTemplateImport(Constants.CONTRAIL_COMPUTE_TEMPLATE_NAME));
+ globalImportMap.put(Constants.CONTRAIL_PORT_TEMPLATE_NAME,
+ GlobalTypesUtil.createServiceTemplateImport(Constants.CONTRAIL_PORT_TEMPLATE_NAME));
+ globalImportMap.put(Constants.CONTRAIL_ABSTRACT_SUBSTITUTE_TEMPLATE_NAME, GlobalTypesUtil
+ .createServiceTemplateImport(Constants.CONTRAIL_ABSTRACT_SUBSTITUTE_TEMPLATE_NAME));
+ return globalImportMap;
+ }
+
+
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/GlobalTypesUtil.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/GlobalTypesUtil.java
new file mode 100644
index 0000000000..9566dec581
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/GlobalTypesUtil.java
@@ -0,0 +1,69 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca.globaltypes;
+
+
+import org.openecomp.sdc.tosca.datatypes.ToscaCapabilityType;
+import org.openecomp.sdc.tosca.datatypes.model.CapabilityDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.Import;
+import org.openecomp.sdc.tosca.services.ToscaUtil;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class GlobalTypesUtil {
+
+
+ /**
+ * Create common import list map.
+ *
+ * @return the map
+ */
+ public static Map<String, Import> createCommonImportList() {
+ Map<String, Import> importsMap = new HashMap<>();
+ importsMap.put("common_definitions", CommonGlobalTypes.createCommonServiceTemplateImport());
+ return importsMap;
+ }
+
+ /**
+ * Create attachment capability capability definition.
+ *
+ * @return the capability definition
+ */
+ public static CapabilityDefinition createAttachmentCapability() {
+ CapabilityDefinition capability = new CapabilityDefinition();
+ capability.setType(ToscaCapabilityType.ATTACHMENT.getDisplayName());
+
+ return capability;
+ }
+
+ /**
+ * Create service template import import.
+ *
+ * @param serviceTemplateName the service template name
+ * @return the import
+ */
+ public static Import createServiceTemplateImport(String serviceTemplateName) {
+ Import serviceTemplateImport = new Import();
+ serviceTemplateImport.setFile(ToscaUtil.getServiceTemplateFileName(serviceTemplateName));
+ return serviceTemplateImport;
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/NeutronNetGlobalType.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/NeutronNetGlobalType.java
new file mode 100644
index 0000000000..2532f87cf5
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/NeutronNetGlobalType.java
@@ -0,0 +1,143 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca.globaltypes;
+
+import org.openecomp.sdc.tosca.datatypes.ToscaDataType;
+import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
+import org.openecomp.sdc.tosca.datatypes.model.AttributeDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.CapabilityDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.NodeType;
+import org.openecomp.sdc.tosca.datatypes.model.PropertyDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.PropertyType;
+import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate;
+import org.openecomp.sdc.tosca.services.DataModelUtil;
+import org.openecomp.sdc.tosca.services.ToscaConstants;
+import org.openecomp.sdc.translator.services.heattotosca.Constants;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class NeutronNetGlobalType {
+ /**
+ * Create service template service template.
+ *
+ * @return the service template
+ */
+ public static ServiceTemplate createServiceTemplate() {
+ ServiceTemplate neutronNetServiceTemplate = new ServiceTemplate();
+ neutronNetServiceTemplate
+ .setTosca_definitions_version(ToscaConstants.TOSCA_DEFINITIONS_VERSION);
+ neutronNetServiceTemplate.setMetadata(
+ DataModelUtil.createMetadata(Constants.NEUTRON_NET_TEMPLATE_NAME, "1.0.0", null));
+ neutronNetServiceTemplate.setDescription("Neutron Network TOSCA Global Types");
+ neutronNetServiceTemplate.setImports(GlobalTypesUtil.createCommonImportList());
+ neutronNetServiceTemplate.setNode_types(createGlobalNodeTypes());
+ return neutronNetServiceTemplate;
+ }
+
+
+ private static Map<String, NodeType> createGlobalNodeTypes() {
+ Map<String, NodeType> globalNodeTypes = new HashMap<>();
+ globalNodeTypes.put(ToscaNodeType.NEUTRON_NET.getDisplayName(), createNeutronNetworkNodeType());
+ return globalNodeTypes;
+ }
+
+ private static NodeType createNeutronNetworkNodeType() {
+ NodeType neutronNetworkNode = new NodeType();
+ neutronNetworkNode.setDerived_from(ToscaNodeType.NETWORK.getDisplayName());
+ neutronNetworkNode.setProperties(createNeutronNetworkProperties());
+ neutronNetworkNode.setAttributes(createNeutronNetworkAttributes());
+ neutronNetworkNode.setCapabilities(createNeutronNetworkCapabilities());
+
+ return neutronNetworkNode;
+ }
+
+ private static Map<String, CapabilityDefinition> createNeutronNetworkCapabilities() {
+ Map<String, CapabilityDefinition> capabilities = new HashMap<>();
+ capabilities.put("attachment", GlobalTypesUtil.createAttachmentCapability());
+ return capabilities;
+ }
+
+ private static Map<String, PropertyDefinition> createNeutronNetworkProperties() {
+ Map<String, PropertyDefinition> neutronNetworkPropertyDefMap = new HashMap<>();
+ neutronNetworkPropertyDefMap.put("admin_state_up", DataModelUtil
+ .createPropertyDefinition(PropertyType.BOOLEAN.getDisplayName(),
+ "A boolean value specifying the administrative status of the network", false, null,
+ null, null, true));
+ neutronNetworkPropertyDefMap.put("dhcp_agent_ids", DataModelUtil
+ .createPropertyDefinition(PropertyType.LIST.getDisplayName(),
+ "The IDs of the DHCP agent to schedule the network", false, null, null,
+ DataModelUtil.createEntrySchema(PropertyType.STRING.getDisplayName(), null, null),
+ null));
+ neutronNetworkPropertyDefMap.put("port_security_enabled", DataModelUtil
+ .createPropertyDefinition(PropertyType.BOOLEAN.getDisplayName(),
+ "Flag to enable/disable port security on the network", false, null, null, null, null));
+ neutronNetworkPropertyDefMap.put("qos_policy", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "The name or ID of QoS policy to attach to this network", false, null, null, null,
+ null));
+ neutronNetworkPropertyDefMap.put("shared", DataModelUtil
+ .createPropertyDefinition(PropertyType.BOOLEAN.getDisplayName(),
+ "Whether this network should be shared across all tenants", false, null, null, null,
+ false));
+ neutronNetworkPropertyDefMap.put("tenant_id", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "The ID of the tenant which will own the network", false, null, null, null, null));
+ neutronNetworkPropertyDefMap.put("value_specs", DataModelUtil
+ .createPropertyDefinition(PropertyType.MAP.getDisplayName(),
+ "Extra parameters to include in the request", false, null, null,
+ DataModelUtil.createEntrySchema(PropertyType.STRING.getDisplayName(), null, null),
+ new HashMap<String, String>()));
+ neutronNetworkPropertyDefMap.put("subnets", DataModelUtil
+ .createPropertyDefinition(PropertyType.MAP.getDisplayName(), "Network related subnets",
+ false, null, null, DataModelUtil
+ .createEntrySchema(ToscaDataType.NEUTRON_SUBNET.getDisplayName(), null, null),
+ null));
+ return neutronNetworkPropertyDefMap;
+ }
+
+ private static Map<String, AttributeDefinition> createNeutronNetworkAttributes() {
+ Map<String, AttributeDefinition> neutronNetworkAttributesDefMap = new HashMap<>();
+ neutronNetworkAttributesDefMap.put("mtu", DataModelUtil
+ .createAttributeDefinition(PropertyType.SCALAR_UNIT_SIZE.getDisplayName(),
+ "The maximum transmission unit size(in bytes) for the network", null, null, null));
+ neutronNetworkAttributesDefMap.put("qos_policy_id", DataModelUtil
+ .createAttributeDefinition(PropertyType.STRING.getDisplayName(),
+ "The QoS policy ID attached to this network", null, null, null));
+ neutronNetworkAttributesDefMap.put("show", DataModelUtil
+ .createAttributeDefinition(PropertyType.STRING.getDisplayName(),
+ "Detailed information about resource", null, null, null));
+ neutronNetworkAttributesDefMap.put("status", DataModelUtil
+ .createAttributeDefinition(PropertyType.STRING.getDisplayName(),
+ "The status of the network", null, null, null));
+ neutronNetworkAttributesDefMap.put("subnets_name", DataModelUtil
+ .createAttributeDefinition(PropertyType.LIST.getDisplayName(),
+ "Subnets name of this network", null,
+ DataModelUtil.createEntrySchema(PropertyType.STRING.getDisplayName(), null, null),
+ null));
+ neutronNetworkAttributesDefMap.put("subnets", DataModelUtil
+ .createAttributeDefinition(PropertyType.MAP.getDisplayName(), "Network related subnets",
+ null, DataModelUtil
+ .createEntrySchema(ToscaDataType.NEUTRON_SUBNET.getDisplayName(), null, null),
+ null));
+ return neutronNetworkAttributesDefMap;
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/NeutronPortGlobalType.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/NeutronPortGlobalType.java
new file mode 100644
index 0000000000..2106b9b3bc
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/NeutronPortGlobalType.java
@@ -0,0 +1,203 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca.globaltypes;
+
+import org.openecomp.sdc.tosca.datatypes.ToscaDataType;
+import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
+import org.openecomp.sdc.tosca.datatypes.model.AttributeDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.CapabilityDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.Constraint;
+import org.openecomp.sdc.tosca.datatypes.model.DataType;
+import org.openecomp.sdc.tosca.datatypes.model.NodeType;
+import org.openecomp.sdc.tosca.datatypes.model.PropertyDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.PropertyType;
+import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate;
+import org.openecomp.sdc.tosca.services.DataModelUtil;
+import org.openecomp.sdc.tosca.services.ToscaConstants;
+import org.openecomp.sdc.translator.services.heattotosca.Constants;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class NeutronPortGlobalType {
+ /**
+ * Create service template service template.
+ *
+ * @return the service template
+ */
+ public static ServiceTemplate createServiceTemplate() {
+ ServiceTemplate neutronPortServiceTemplate = new ServiceTemplate();
+ neutronPortServiceTemplate
+ .setTosca_definitions_version(ToscaConstants.TOSCA_DEFINITIONS_VERSION);
+ neutronPortServiceTemplate.setMetadata(
+ DataModelUtil.createMetadata(Constants.NEUTRON_PORT_TEMPLATE_NAME, "1.0.0", null));
+ neutronPortServiceTemplate.setImports(GlobalTypesUtil.createCommonImportList());
+ neutronPortServiceTemplate.setDescription("Neutron Port TOSCA Global Types");
+ neutronPortServiceTemplate.setData_types(createGlobalDataTypes());
+ neutronPortServiceTemplate.setNode_types(createGlobalNodeTypes());
+ return neutronPortServiceTemplate;
+ }
+
+ private static Map<String, DataType> createGlobalDataTypes() {
+ Map<String, DataType> globalDataTypes = new HashMap<>();
+ globalDataTypes
+ .put(ToscaDataType.NEUTRON_PORT_FIXED_IPS.getDisplayName(), createFixedIpsDataType());
+ return globalDataTypes;
+ }
+
+ private static DataType createFixedIpsDataType() {
+ DataType dataType = new DataType();
+ dataType.setDerived_from(ToscaDataType.ROOT.getDisplayName());
+ dataType.setDescription("subnet/ip_address");
+ Map<String, PropertyDefinition> prop = new HashMap<>();
+
+ prop.put("subnet", DataModelUtil.createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "Subnet in which to allocate the IP address for this port", false, null, null, null, null));
+ prop.put("ip_address", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "IP address desired in the subnet for this port", false, null, null, null, null));
+
+ dataType.setProperties(prop);
+ return dataType;
+ }
+
+ private static Map<String, NodeType> createGlobalNodeTypes() {
+ Map<String, NodeType> globalNodeTypes = new HashMap<>();
+ globalNodeTypes.put(ToscaNodeType.NEUTRON_PORT.getDisplayName(), createNeutronPortNodeType());
+ return globalNodeTypes;
+ }
+
+ private static NodeType createNeutronPortNodeType() {
+ NodeType nodeType = new NodeType();
+ nodeType.setDerived_from(ToscaNodeType.NETWORK_PORT.getDisplayName());
+ nodeType.setProperties(createNeutronPortProperties());
+ nodeType.setAttributes(createNeutronPortAttributes());
+ nodeType.setCapabilities(createNeutronPortCapabilities());
+ return nodeType;
+ }
+
+ private static Map<String, CapabilityDefinition> createNeutronPortCapabilities() {
+ Map<String, CapabilityDefinition> capabilities = new HashMap<>();
+ capabilities.put("attachment", GlobalTypesUtil.createAttachmentCapability());
+ return capabilities;
+ }
+
+ private static Map<String, PropertyDefinition> createNeutronPortProperties() {
+ Map<String, PropertyDefinition> neutronPortPropertyDefMap = new HashMap<>();
+ neutronPortPropertyDefMap.put("admin_state_up", DataModelUtil
+ .createPropertyDefinition(PropertyType.BOOLEAN.getDisplayName(),
+ "A boolean value specifying the administrative status of the network", false, null,
+ null, null, true));
+ neutronPortPropertyDefMap.put("allowed_address_pairs", DataModelUtil
+ .createPropertyDefinition(PropertyType.LIST.getDisplayName(),
+ "Additional MAC/IP address pairs allowed to pass through the port", false, null, null,
+ DataModelUtil
+ .createEntrySchema(ToscaDataType.NETWORK_ADDRESS_PAIR.getDisplayName(), null, null),
+ null));
+ neutronPortPropertyDefMap.put("binding:vnic_type", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "The vnic type to be bound on the neutron port", false, createBindingConstraint(), null,
+ null, null));
+ neutronPortPropertyDefMap.put("device_id", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Device ID of this port",
+ false, null, null, null, null));
+ neutronPortPropertyDefMap.put("device_owner", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "Name of the network owning the port", false, null, null, null, null));
+ neutronPortPropertyDefMap.put("fixed_ips", DataModelUtil
+ .createPropertyDefinition(PropertyType.LIST.getDisplayName(), "Desired IPs for this port",
+ false, null, null, DataModelUtil
+ .createEntrySchema(ToscaDataType.NEUTRON_PORT_FIXED_IPS.getDisplayName(), null,
+ null), null));
+ neutronPortPropertyDefMap.put("mac_address", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "MAC address to give to this port", false, null, null, null, null));
+ neutronPortPropertyDefMap.put(Constants.NAME_PROPERTY_NAME, DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "A symbolic name for this port", false, null, null, null, null));
+ neutronPortPropertyDefMap.put("port_security_enabled", DataModelUtil
+ .createPropertyDefinition(PropertyType.BOOLEAN.getDisplayName(),
+ "Flag to enable/disable port security on the network", false, null, null, null, null));
+ neutronPortPropertyDefMap.put("qos_policy", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "The name or ID of QoS policy to attach to this network", false, null, null, null,
+ null));
+ neutronPortPropertyDefMap.put(Constants.SECURITY_GROUPS_PROPERTY_NAME, DataModelUtil
+ .createPropertyDefinition(PropertyType.LIST.getDisplayName(),
+ "List of security group names or IDs", false, null, null,
+ DataModelUtil.createEntrySchema(PropertyType.STRING.getDisplayName(), null, null),
+ null));
+ neutronPortPropertyDefMap.put("value_specs", DataModelUtil
+ .createPropertyDefinition(PropertyType.MAP.getDisplayName(),
+ "Extra parameters to include in the request", false, null, null,
+ DataModelUtil.createEntrySchema(PropertyType.STRING.getDisplayName(), null, null),
+ new HashMap<String, String>()));
+ neutronPortPropertyDefMap.put("replacement_policy", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "Policy on how to respond to a stack-update for this resource", false,
+ createReplacementPolicyConstrain(), null, null, "AUTO"));
+ neutronPortPropertyDefMap.put("network", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "Network this port belongs to", false, null, null, null, null));
+ return neutronPortPropertyDefMap;
+ }
+
+ private static List<Constraint> createBindingConstraint() {
+ List<Constraint> constraints = new ArrayList<>();
+ Constraint validValues =
+ DataModelUtil.createValidValuesConstraint("macvtap", "direct", "normal");
+ constraints.add(validValues);
+ return constraints;
+ }
+
+ private static List<Constraint> createReplacementPolicyConstrain() {
+ List<Constraint> constraints = new ArrayList<>();
+ Constraint validValues = DataModelUtil.createValidValuesConstraint("REPLACE_ALWAYS", "AUTO");
+ constraints.add(validValues);
+ return constraints;
+ }
+
+ private static Map<String, AttributeDefinition> createNeutronPortAttributes() {
+ Map<String, AttributeDefinition> neutronPortAttributesDefMap = new HashMap<>();
+ neutronPortAttributesDefMap.put("network_id", DataModelUtil
+ .createAttributeDefinition(PropertyType.STRING.getDisplayName(),
+ "Unique identifier for the network owning the port", null, null, null));
+ neutronPortAttributesDefMap.put("qos_policy_id", DataModelUtil
+ .createAttributeDefinition(PropertyType.STRING.getDisplayName(),
+ "The QoS policy ID attached to this network", null, null, null));
+ neutronPortAttributesDefMap.put("show", DataModelUtil
+ .createAttributeDefinition(PropertyType.STRING.getDisplayName(),
+ "Detailed information about resource", null, null, null));
+ neutronPortAttributesDefMap.put("status", DataModelUtil
+ .createAttributeDefinition(PropertyType.STRING.getDisplayName(),
+ "The status of the network", null, null, null));
+ neutronPortAttributesDefMap.put("subnets", DataModelUtil
+ .createAttributeDefinition(PropertyType.LIST.getDisplayName(), "Subnets of this network",
+ null, DataModelUtil.createEntrySchema(PropertyType.STRING.getDisplayName(), null, null),
+ null));
+ neutronPortAttributesDefMap.put("tenant_id", DataModelUtil
+ .createAttributeDefinition(PropertyType.STRING.getDisplayName(), "Tenant owning the port",
+ null, null, null));
+ return neutronPortAttributesDefMap;
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/NeutronSecurityRulesGlobalType.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/NeutronSecurityRulesGlobalType.java
new file mode 100644
index 0000000000..4c5b033e0e
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/NeutronSecurityRulesGlobalType.java
@@ -0,0 +1,175 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca.globaltypes;
+
+import org.openecomp.sdc.tosca.datatypes.ToscaCapabilityType;
+import org.openecomp.sdc.tosca.datatypes.ToscaDataType;
+import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
+import org.openecomp.sdc.tosca.datatypes.ToscaRelationshipType;
+import org.openecomp.sdc.tosca.datatypes.model.AttributeDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.Constraint;
+import org.openecomp.sdc.tosca.datatypes.model.DataType;
+import org.openecomp.sdc.tosca.datatypes.model.NodeType;
+import org.openecomp.sdc.tosca.datatypes.model.PropertyDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.PropertyType;
+import org.openecomp.sdc.tosca.datatypes.model.RequirementDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate;
+import org.openecomp.sdc.tosca.services.DataModelUtil;
+import org.openecomp.sdc.tosca.services.ToscaConstants;
+import org.openecomp.sdc.translator.services.heattotosca.Constants;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class NeutronSecurityRulesGlobalType {
+ /**
+ * Create service template service template.
+ *
+ * @return the service template
+ */
+ public static ServiceTemplate createServiceTemplate() {
+ ServiceTemplate neutronSecurityRulesServiceTemplate = new ServiceTemplate();
+ neutronSecurityRulesServiceTemplate
+ .setTosca_definitions_version(ToscaConstants.TOSCA_DEFINITIONS_VERSION);
+ neutronSecurityRulesServiceTemplate.setMetadata(DataModelUtil
+ .createMetadata(Constants.NEUTRON_SECURITY_RULES_TEMPLATE_NAME, "1.0.0", null));
+ neutronSecurityRulesServiceTemplate.setImports(GlobalTypesUtil.createCommonImportList());
+ neutronSecurityRulesServiceTemplate.setDescription("Neutron Security Rules TOSCA Global Types");
+ neutronSecurityRulesServiceTemplate.setData_types(createGlobalDataTypes());
+ neutronSecurityRulesServiceTemplate.setNode_types(createGlobalNodeTypes());
+ return neutronSecurityRulesServiceTemplate;
+ }
+
+
+ private static Map<String, DataType> createGlobalDataTypes() {
+ Map<String, DataType> globalDataTypes = new HashMap<>();
+ globalDataTypes.put(ToscaDataType.NEUTRON_SECURITY_RULES_RULE.getDisplayName(),
+ createSecurityRulesDataType());
+ return globalDataTypes;
+ }
+
+ private static DataType createSecurityRulesDataType() {
+ DataType addressPairDataType = new DataType();
+ addressPairDataType.setDerived_from(ToscaDataType.ROOT.getDisplayName());
+ addressPairDataType.setDescription("Rules Pairs");
+ Map<String, PropertyDefinition> addressPairProp = new HashMap<>();
+
+ addressPairProp.put("direction", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "The direction in which the security group rule is applied", false,
+ DataModelUtil.createValidValuesConstraintsList("egress", "ingress"), null, null,
+ "ingress"));
+ addressPairProp.put("ethertype", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Ethertype of the traffic",
+ false, DataModelUtil.createValidValuesConstraintsList("IPv4", "IPv6"), null, null,
+ "IPv4"));
+ Constraint portRangeMaxConstraint = new Constraint();
+ portRangeMaxConstraint.setIn_range(new Integer[]{0, 65535});
+ addressPairProp.put("port_range_max", DataModelUtil
+ .createPropertyDefinition(PropertyType.INTEGER.getDisplayName(),
+ "The maximum port number in the range that is matched by the security group rule. ",
+ false, DataModelUtil.getConstrainList(portRangeMaxConstraint), null, null, null));
+ Constraint portRangeMinConstraint = new Constraint();
+ portRangeMinConstraint.setIn_range(new Integer[]{0, 65535});
+ addressPairProp.put("port_range_min", DataModelUtil
+ .createPropertyDefinition(PropertyType.INTEGER.getDisplayName(),
+ "The minimum port number in the range that is matched by the security group rule.",
+ false, DataModelUtil.getConstrainList(portRangeMinConstraint), null, null, null));
+ addressPairProp.put("protocol", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "The protocol that is matched by the security group rule", false,
+ DataModelUtil.createValidValuesConstraintsList("tcp", "udp", "icmp"), null, null,
+ null));
+ addressPairProp.put("remote_group_id", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "The remote group ID to be associated with this security group rule", false, null, null,
+ null, null));
+ addressPairProp.put("remote_ip_prefix", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "The remote IP prefix (CIDR) to be associated with this security group rule", false,
+ null, null, null, null));
+ addressPairProp.put("remote_mode", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "Whether to specify a remote group or a remote IP prefix", false,
+ DataModelUtil.createValidValuesConstraintsList("remote_ip_prefix", "remote_group_id"),
+ null, null, "remote_ip_prefix"));
+ addressPairDataType.setProperties(addressPairProp);
+
+ return addressPairDataType;
+ }
+
+ private static Map<String, NodeType> createGlobalNodeTypes() {
+ Map<String, NodeType> globalNodeTypes = new HashMap<>();
+ globalNodeTypes.put(ToscaNodeType.NEUTRON_SECURITY_RULES.getDisplayName(),
+ createNeutronSecurityRulesNodeType());
+ return globalNodeTypes;
+ }
+
+ private static NodeType createNeutronSecurityRulesNodeType() {
+ NodeType novaServerNodeType = new NodeType();
+ novaServerNodeType.setDerived_from(ToscaNodeType.ROOT.getDisplayName());
+ novaServerNodeType.setProperties(createNeutronSecurityRulesProperties());
+ novaServerNodeType.setAttributes(createNeutronSecurityRulesAttributes());
+ novaServerNodeType.setRequirements(createNeutronSecurityRequirements());
+ return novaServerNodeType;
+ }
+
+ private static List<Map<String, RequirementDefinition>> createNeutronSecurityRequirements() {
+ final List<Map<String, RequirementDefinition>> requirements = new ArrayList<>();
+ final Map<String, RequirementDefinition> portRequirement = new HashMap<>();
+ RequirementDefinition requirementDefinition = new RequirementDefinition();
+ requirementDefinition.setCapability(ToscaCapabilityType.ATTACHMENT.getDisplayName());
+ requirementDefinition.setNode(ToscaNodeType.NEUTRON_PORT.getDisplayName());
+ requirementDefinition.setRelationship(ToscaRelationshipType.ATTACHES_TO.getDisplayName());
+ requirementDefinition.setOccurrences(new Object[]{0, ToscaConstants.UNBOUNDED});
+ portRequirement.put(ToscaConstants.PORT_REQUIREMENT_ID, requirementDefinition);
+ requirements.add(portRequirement);
+
+ return requirements;
+ }
+
+ private static Map<String, PropertyDefinition> createNeutronSecurityRulesProperties() {
+ Map<String, PropertyDefinition> neutronSecurityRulesPropertyDefMap = new HashMap<>();
+ neutronSecurityRulesPropertyDefMap.put(Constants.NAME_PROPERTY_NAME, DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "A symbolic name for this security group, which is not required to be unique.", false,
+ null, null, null, null));
+ neutronSecurityRulesPropertyDefMap.put(Constants.DESCRIPTION_PROPERTY_NAME, DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "Description of the security group", false, null, null, null, null));
+ neutronSecurityRulesPropertyDefMap.put(Constants.RULES_PROPERTY_NAME, DataModelUtil
+ .createPropertyDefinition(PropertyType.LIST.getDisplayName(),
+ "List of security group rules", false, null, null, DataModelUtil
+ .createEntrySchema(ToscaDataType.NEUTRON_SECURITY_RULES_RULE.getDisplayName(), null,
+ null), null));
+ return neutronSecurityRulesPropertyDefMap;
+ }
+
+ private static Map<String, AttributeDefinition> createNeutronSecurityRulesAttributes() {
+ Map<String, AttributeDefinition> neutronSecurityRulesAttributesDefMap = new HashMap<>();
+ neutronSecurityRulesAttributesDefMap.put("show", DataModelUtil
+ .createAttributeDefinition(PropertyType.STRING.getDisplayName(),
+ "Detailed information about resource", null, null, null));
+ return neutronSecurityRulesAttributesDefMap;
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/NovaServerGlobalType.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/NovaServerGlobalType.java
new file mode 100644
index 0000000000..d38d70a4f7
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/NovaServerGlobalType.java
@@ -0,0 +1,307 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca.globaltypes;
+
+import org.openecomp.sdc.tosca.datatypes.ToscaDataType;
+import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
+import org.openecomp.sdc.tosca.datatypes.model.AttributeDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.Constraint;
+import org.openecomp.sdc.tosca.datatypes.model.DataType;
+import org.openecomp.sdc.tosca.datatypes.model.NodeType;
+import org.openecomp.sdc.tosca.datatypes.model.PropertyDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.PropertyType;
+import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate;
+import org.openecomp.sdc.tosca.datatypes.model.heatextend.PropertyTypeExt;
+import org.openecomp.sdc.tosca.services.DataModelUtil;
+import org.openecomp.sdc.tosca.services.ToscaConstants;
+import org.openecomp.sdc.translator.services.heattotosca.Constants;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class NovaServerGlobalType {
+
+ /**
+ * Create service template service template.
+ *
+ * @return the service template
+ */
+ public static ServiceTemplate createServiceTemplate() {
+ ServiceTemplate novaeServerServiceTemplate = new ServiceTemplate();
+ novaeServerServiceTemplate
+ .setTosca_definitions_version(ToscaConstants.TOSCA_DEFINITIONS_VERSION);
+ novaeServerServiceTemplate.setMetadata(
+ DataModelUtil.createMetadata(Constants.NOVA_SERVER_TEMPLATE_NAME, "1.0.0", null));
+ novaeServerServiceTemplate.setDescription("Nova Server TOSCA Global Types");
+ novaeServerServiceTemplate.setImports(GlobalTypesUtil.createCommonImportList());
+ novaeServerServiceTemplate.setData_types(createGlobalDataTypes());
+ novaeServerServiceTemplate.setNode_types(createGlobalNodeTypes());
+ return novaeServerServiceTemplate;
+ }
+
+
+ private static Map<String, NodeType> createGlobalNodeTypes() {
+ Map<String, NodeType> globalNodeTypes = new HashMap<>();
+ globalNodeTypes.put(ToscaNodeType.NOVA_SERVER.getDisplayName(), createNovaServerNodeType());
+ return globalNodeTypes;
+ }
+
+ private static NodeType createNovaServerNodeType() {
+ NodeType novaServerNodeType = new NodeType();
+ novaServerNodeType.setDerived_from(ToscaNodeType.COMPUTE.getDisplayName());
+ novaServerNodeType.setProperties(createNovaServerProperties());
+ novaServerNodeType.setAttributes(createNovaServerAttributes());
+ return novaServerNodeType;
+ }
+
+
+ private static Map<String, PropertyDefinition> createNovaServerProperties() {
+ Map<String, PropertyDefinition> novaServerPropertyDefMap = new HashMap<>();
+ novaServerPropertyDefMap.put("flavor", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "The ID or name of the flavor to boot onto", true, null, null, null, null));
+ novaServerPropertyDefMap.put("admin_pass", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "The administrator password for the server", false, null, null, null, null));
+ novaServerPropertyDefMap.put("availability_zone", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "Availability zone to create servers in", false, null, null, null, null));
+ novaServerPropertyDefMap.put("config_drive", DataModelUtil
+ .createPropertyDefinition(PropertyType.BOOLEAN.getDisplayName(),
+ "enable config drive on the server", false, null, null, null, null));
+ novaServerPropertyDefMap.put("contrail_service_instance_ind", DataModelUtil
+ .createPropertyDefinition(PropertyType.BOOLEAN.getDisplayName(),
+ "Nova server related to service instance indicator", false, null, null, null, false));
+ novaServerPropertyDefMap.put("diskConfig", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "Control how the disk is partitioned when the server is created", false,
+ getDiskConfigConstraints(), null, null, null));
+ novaServerPropertyDefMap.put("flavor_update_policy", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "Policy on how to apply a flavor update", false, getFlavorUpdatePolicyConstraints(),
+ null, null, "RESIZE"));
+ novaServerPropertyDefMap.put("image", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "The ID or name of the image to boot with", false, null, null, null, null));
+ novaServerPropertyDefMap.put("image_update_policy", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "Policy on how to apply an image-id update", false, getImageUpdatePolicyConstraints(),
+ null, null, "REBUILD"));
+ novaServerPropertyDefMap.put("key_name", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "Name of keypair to inject into the server", false, null, null, null, null));
+ novaServerPropertyDefMap.put("metadata", DataModelUtil
+ .createPropertyDefinition(PropertyTypeExt.JSON.getDisplayName(),
+ "Arbitrary JSON metadata to store for this server", false, null, null, null, null));
+ novaServerPropertyDefMap.put(Constants.NAME_PROPERTY_NAME, DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Server name", false, null,
+ null, null, null));
+ novaServerPropertyDefMap.put("personality", DataModelUtil
+ .createPropertyDefinition(PropertyType.MAP.getDisplayName(),
+ "A map of files to create/overwrite on the server upon boot", false, null, null,
+ DataModelUtil.createEntrySchema(PropertyType.STRING.getDisplayName(), null, null),
+ new HashMap<String, String>()));
+ novaServerPropertyDefMap.put("reservation_id", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "A UUID for the set of servers being requested", false, null, null, null, null));
+ novaServerPropertyDefMap.put("scheduler_hints", DataModelUtil
+ .createPropertyDefinition(PropertyType.MAP.getDisplayName(),
+ "Arbitrary key-value pairs specified by the client to help boot a server", false, null,
+ null, DataModelUtil.createEntrySchema(PropertyType.STRING.getDisplayName(), null, null),
+ null));
+ novaServerPropertyDefMap.put(Constants.SECURITY_GROUPS_PROPERTY_NAME, DataModelUtil
+ .createPropertyDefinition(PropertyType.LIST.getDisplayName(),
+ "List of security group names or IDs", false, null, null,
+ DataModelUtil.createEntrySchema(PropertyType.STRING.getDisplayName(), null, null),
+ new ArrayList<>()));
+ novaServerPropertyDefMap.put("software_config_transport", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "How the server should receive the metadata required for software configuration", false,
+ getSoftwareConfigTransportConstraints(), null, null, "POLL_SERVER_CFN"));
+ novaServerPropertyDefMap.put("user_data", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "User data script to be executed by cloud-init", false, null, null, null, ""));
+ novaServerPropertyDefMap.put("user_data_format", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "How the user_data should be formatted for the server", false,
+ getUserDataFormatConstraint(), null, null, "HEAT_CFNTOOLS"));
+ novaServerPropertyDefMap.put("user_data_update_policy", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "Policy on how to apply a user_data update", false,
+ getUserDataUpdatePolicyConstraints(), null, null, "REPLACE"));
+ return novaServerPropertyDefMap;
+ }
+
+ private static Map<String, AttributeDefinition> createNovaServerAttributes() {
+ Map<String, AttributeDefinition> novaServerAttributesDefMap = new HashMap<>();
+ novaServerAttributesDefMap.put("accessIPv4", DataModelUtil
+ .createAttributeDefinition(PropertyType.STRING.getDisplayName(),
+ "The manually assigned alternative public IPv4 address of the server", null, null,
+ null));
+ novaServerAttributesDefMap.put("accessIPv6", DataModelUtil
+ .createAttributeDefinition(PropertyType.STRING.getDisplayName(),
+ "The manually assigned alternative public IPv6 address of the server", null, null,
+ null));
+ novaServerAttributesDefMap.put("addresses", DataModelUtil
+ .createAttributeDefinition(PropertyType.MAP.getDisplayName(),
+ "A dict of all network addresses with corresponding port_id", null, DataModelUtil
+ .createEntrySchema(ToscaDataType.NOVA_SERVER_NETWORK_ADDRESS_INFO.getDisplayName(),
+ null, null), null));
+ novaServerAttributesDefMap.put("console_urls", DataModelUtil
+ .createAttributeDefinition(PropertyType.STRING.getDisplayName(), "URLs of servers consoles",
+ null, null, null));
+ novaServerAttributesDefMap.put("instance_name", DataModelUtil
+ .createAttributeDefinition(PropertyType.STRING.getDisplayName(),
+ "AWS compatible instance name", null, null, null));
+ novaServerAttributesDefMap.put(Constants.NAME_PROPERTY_NAME, DataModelUtil
+ .createAttributeDefinition(PropertyType.STRING.getDisplayName(), "Name of the server", null,
+ null, null));
+ novaServerAttributesDefMap.put("show", DataModelUtil
+ .createAttributeDefinition(PropertyType.STRING.getDisplayName(),
+ "Detailed information about resource", null, null, null));
+ return novaServerAttributesDefMap;
+ }
+
+ private static List<Constraint> getUserDataFormatConstraint() {
+ List<Constraint> constraints;
+ Constraint validValues;
+ constraints = new ArrayList<>();
+ validValues =
+ DataModelUtil.createValidValuesConstraint("SOFTWARE_CONFIG", "RAW", "HEAT_CFNTOOLS");
+ constraints.add(validValues);
+ return constraints;
+ }
+
+ private static List<Constraint> getUserDataUpdatePolicyConstraints() {
+ List<Constraint> constraints;
+ Constraint validValues;
+ constraints = new ArrayList<>();
+ validValues = DataModelUtil.createValidValuesConstraint("REPLACE", "IGNORE");
+ constraints.add(validValues);
+ return constraints;
+ }
+
+ private static List<Constraint> getSoftwareConfigTransportConstraints() {
+ List<Constraint> constraints;
+ Constraint validValues;
+ constraints = new ArrayList<>();
+ validValues = DataModelUtil
+ .createValidValuesConstraint("POLL_SERVER_CFN", "POLL_SERVER_HEAT", "POLL_TEMP_URL",
+ "ZAQAR_MESSAGE");
+ constraints.add(validValues);
+ return constraints;
+ }
+
+ private static List<Constraint> getImageUpdatePolicyConstraints() {
+ List<Constraint> constraints;
+ Constraint validValues;
+ constraints = new ArrayList<>();
+ validValues = DataModelUtil
+ .createValidValuesConstraint("REBUILD_PRESERVE_EPHEMERAL", "REPLACE", "REBUILD");
+ constraints.add(validValues);
+ return constraints;
+ }
+
+ private static List<Constraint> getFlavorUpdatePolicyConstraints() {
+ Constraint validValues;
+ List<Constraint> constraints = new ArrayList<>();
+ validValues = DataModelUtil.createValidValuesConstraint("RESIZE", "REPLACE");
+ constraints.add(validValues);
+ return constraints;
+ }
+
+ private static List<Constraint> getDiskConfigConstraints() {
+ List<Constraint> constraints = new ArrayList<>();
+ Constraint validValues = DataModelUtil.createValidValuesConstraint("AUTO", "MANUAL");
+ constraints.add(validValues);
+ return constraints;
+ }
+
+ private static Map<String, DataType> createGlobalDataTypes() {
+ Map<String, DataType> globalDataTypes = new HashMap<>();
+ globalDataTypes.put(ToscaDataType.NOVA_SERVER_PORT_EXTRA_PROPERTIES.getDisplayName(),
+ createPortExtraDataDataType());
+ globalDataTypes.put(ToscaDataType.NOVA_SERVER_NETWORK_ADDRESS_INFO.getDisplayName(),
+ createAddressInfoDataType());
+ return globalDataTypes;
+ }
+
+ private static DataType createAddressInfoDataType() {
+ DataType addressInfoDataType = new DataType();
+ addressInfoDataType.setDerived_from(ToscaDataType.NETWORK_NETWORK_INFO.getDisplayName());
+ addressInfoDataType.setDescription("Network addresses with corresponding port id");
+
+ Map<String, PropertyDefinition> addressInfoProp = new HashMap<>();
+ addressInfoProp.put("port_id", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Port id", false, null,
+ null, null, null));
+ addressInfoDataType.setProperties(addressInfoProp);
+
+ return addressInfoDataType;
+ }
+
+
+ private static DataType createPortExtraDataDataType() {
+ DataType portExtraDataType = new DataType();
+ portExtraDataType.setDerived_from(ToscaDataType.ROOT.getDisplayName());
+ portExtraDataType.setDescription("Nova server network expand properties for port");
+ Map<String, PropertyDefinition> portExtraPropMap = new HashMap<>();
+
+ portExtraPropMap.put("admin_state_up", DataModelUtil
+ .createPropertyDefinition(PropertyType.BOOLEAN.getDisplayName(),
+ "The administrative state of this port", false, null, null, null, true));
+ portExtraPropMap.put("allowed_address_pairs", DataModelUtil
+ .createPropertyDefinition(PropertyType.LIST.getDisplayName(),
+ "Additional MAC/IP address pairs allowed to pass through the port", false, null, null,
+ DataModelUtil
+ .createEntrySchema(ToscaDataType.NETWORK_ADDRESS_PAIR.getDisplayName(), null, null),
+ null));
+
+ List<Constraint> bindingVnicConstraints = new ArrayList<>();
+ Constraint validValues =
+ DataModelUtil.createValidValuesConstraint("macvtap", "direct", "normal");
+ bindingVnicConstraints.add(validValues);
+ portExtraPropMap.put("binding:vnic_type", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "The vnic type to be bound on the neutron port", false, bindingVnicConstraints, null,
+ null, null));
+
+ portExtraPropMap.put("mac_address", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "MAC address to give to this port", false, null, null, null, null));
+ portExtraPropMap.put("port_security_enabled", DataModelUtil
+ .createPropertyDefinition(PropertyType.BOOLEAN.getDisplayName(),
+ "Flag to enable/disable port security on the port", false, null, null, null, null));
+ portExtraPropMap.put("qos_policy", DataModelUtil
+ .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
+ "The name or ID of QoS policy to attach to this port", false, null, null, null, null));
+ portExtraPropMap.put("value_specs", DataModelUtil
+ .createPropertyDefinition(PropertyType.MAP.getDisplayName(),
+ "Extra parameters to include in the request", false, null, null,
+ DataModelUtil.createEntrySchema(PropertyType.STRING.getDisplayName(), null, null),
+ new HashMap<String, String>()));
+ portExtraDataType.setProperties(portExtraPropMap);
+ return portExtraDataType;
+ }
+
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/helper/ContrailTranslationHelper.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/helper/ContrailTranslationHelper.java
new file mode 100644
index 0000000000..2e1aa9e372
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/helper/ContrailTranslationHelper.java
@@ -0,0 +1,65 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca.helper;
+
+import org.openecomp.sdc.heat.datatypes.model.Resource;
+import org.openecomp.sdc.tosca.services.ToscaConstants;
+import org.openecomp.sdc.translator.services.heattotosca.helper.impl.NameExtractorServiceImpl;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+
+public class ContrailTranslationHelper {
+ /**
+ * Gets compute node type id.
+ *
+ * @param serviceTemplateTranslatedId the service template translated id
+ * @param serviceTemplateResource the service template resource
+ * @return the compute node type id
+ */
+ public String getComputeNodeTypeId(String serviceTemplateTranslatedId,
+ Resource serviceTemplateResource) {
+ NameExtractorService nodeTypeNameExtractor = new NameExtractorServiceImpl();
+ List<PropertyRegexMatcher> propertyRegexMatchers =
+ getPropertiesAndRegexMatchers(nodeTypeNameExtractor);
+ Optional<String> extractedNodeTypeName = nodeTypeNameExtractor
+ .extractNodeTypeNameByPropertiesPriority(serviceTemplateResource.getProperties(),
+ propertyRegexMatchers);
+
+ return ToscaConstants.NODES_PREFIX
+ + (extractedNodeTypeName.isPresent() ? extractedNodeTypeName.get()
+ : "compute_" + serviceTemplateTranslatedId);
+ }
+
+ private List<PropertyRegexMatcher> getPropertiesAndRegexMatchers(
+ NameExtractorService nodeTypeNameExtractor) {
+ List<PropertyRegexMatcher> propertyRegexMatchers = new ArrayList<>();
+ propertyRegexMatchers.add(nodeTypeNameExtractor
+ .getPropertyRegexMatcher("image_name", Collections.singletonList(".+_image_name$"),
+ "_image_name"));
+ propertyRegexMatchers.add(nodeTypeNameExtractor
+ .getPropertyRegexMatcher("flavor", Collections.singletonList(".+_flavor_name$"),
+ "_flavor_name"));
+ return propertyRegexMatchers;
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/helper/NameExtractorService.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/helper/NameExtractorService.java
new file mode 100644
index 0000000000..ed338e2bf5
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/helper/NameExtractorService.java
@@ -0,0 +1,33 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca.helper;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+public interface NameExtractorService {
+ Optional<String> extractNodeTypeNameByPropertiesPriority(
+ Map<String, Object> properties,List<PropertyRegexMatcher> propertiesRegexMatchers);
+
+ PropertyRegexMatcher getPropertyRegexMatcher(String propertyName, List<String> regexMatchers,
+ String propertyValueSearchTerm);
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/helper/PropertyRegexMatcher.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/helper/PropertyRegexMatcher.java
new file mode 100644
index 0000000000..b04234b413
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/helper/PropertyRegexMatcher.java
@@ -0,0 +1,69 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca.helper;
+
+import org.apache.commons.collections.CollectionUtils;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Pattern;
+
+public class PropertyRegexMatcher {
+ private String propertyName;
+ private List<Pattern> regexPatterns;
+ private String stringToSearchForPropertyValue;
+
+ public String getPropertyName() {
+ return propertyName;
+ }
+
+ public void setPropertyName(String propertyName) {
+ this.propertyName = propertyName;
+ }
+
+ /**
+ * Sets regex.
+ *
+ * @param regexPatterns the regex patterns
+ */
+ public void setRegex(List<String> regexPatterns) {
+ if (CollectionUtils.isEmpty(this.regexPatterns)) {
+ this.regexPatterns = new ArrayList<>();
+ }
+
+ for (String regexPattern : regexPatterns) {
+ this.regexPatterns.add(Pattern.compile(regexPattern));
+ }
+ }
+
+ public List<Pattern> getRegexPatterns() {
+ return regexPatterns;
+ }
+
+ public String getStringToSearchForPropertyValue() {
+ return stringToSearchForPropertyValue;
+ }
+
+ public void setStringToSearchForPropertyValue(String stringToSearchForPropertyValue) {
+ this.stringToSearchForPropertyValue = stringToSearchForPropertyValue;
+ }
+
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/helper/VolumeTranslationHelper.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/helper/VolumeTranslationHelper.java
new file mode 100644
index 0000000000..ebd38c89d2
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/helper/VolumeTranslationHelper.java
@@ -0,0 +1,172 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca.helper;
+
+import org.apache.commons.collections4.CollectionUtils;
+import org.openecomp.core.utilities.yaml.YamlUtil;
+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.Output;
+import org.openecomp.sdc.heat.datatypes.model.Resource;
+import org.openecomp.sdc.translator.datatypes.heattotosca.AttachedResourceId;
+import org.openecomp.sdc.translator.datatypes.heattotosca.to.ResourceFileDataAndIDs;
+import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo;
+import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil;
+import org.openecomp.sdc.translator.services.heattotosca.TranslationContext;
+import org.openecomp.sdc.translator.services.heattotosca.impl.ResourceTranslationBase;
+import org.slf4j.Logger;
+
+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 java.util.stream.Collectors;
+
+public class VolumeTranslationHelper {
+ private final Logger logger;
+
+ public VolumeTranslationHelper(Logger logger) {
+ this.logger = logger;
+ }
+
+ /**
+ * Gets file data containing volume.
+ *
+ * @param filesToSearch the files to search
+ * @param resourceId the resource id
+ * @param translateTo the translate to
+ * @param types the types
+ * @return the file data containing volume
+ */
+ public Optional<ResourceFileDataAndIDs> getFileDataContainingVolume(List<FileData> filesToSearch,
+ String resourceId,
+ TranslateTo translateTo,
+ FileData.Type... types) {
+ if (CollectionUtils.isEmpty(filesToSearch)) {
+ return Optional.empty();
+ }
+
+ List<FileData> fileDatas = Objects.isNull(types) ? filesToSearch
+ : HeatToToscaUtil.getFilteredListOfFileDataByTypes(filesToSearch, types);
+ Optional<ResourceFileDataAndIDs> fileDataAndIDs =
+ getResourceFileDataAndIDsForVolumeConnection(resourceId, translateTo, fileDatas);
+ if (fileDataAndIDs.isPresent()) {
+ return fileDataAndIDs;
+ }
+ return Optional.empty();
+ }
+
+ private Optional<ResourceFileDataAndIDs> getResourceFileDataAndIDsForVolumeConnection(
+ String resourceId, TranslateTo translateTo, List<FileData> fileDatas) {
+ for (FileData data : fileDatas) {
+ HeatOrchestrationTemplate heatOrchestrationTemplate = new YamlUtil()
+ .yamlToObject(translateTo.getContext().getFiles().getFileContent(data.getFile()),
+ HeatOrchestrationTemplate.class);
+ Map<String, Output> outputs = heatOrchestrationTemplate.getOutputs();
+ if (Objects.isNull(outputs)) {
+ continue;
+ }
+ Output output = outputs.get(resourceId);
+ if (Objects.nonNull(output)) {
+ Optional<AttachedResourceId> attachedOutputId = HeatToToscaUtil
+ .extractAttachedResourceId(data.getFile(), heatOrchestrationTemplate,
+ translateTo.getContext(), output.getValue());
+ if (attachedOutputId.isPresent()) {
+ AttachedResourceId attachedResourceId = attachedOutputId.get();
+ if (!isOutputIsGetResource(resourceId, data, attachedResourceId)) {
+ continue;
+ }
+ String translatedId = (String) attachedResourceId.getTranslatedId();
+ if (isOutputOfTypeCinderVolume(translateTo, data, heatOrchestrationTemplate,
+ translatedId)) {
+ ResourceFileDataAndIDs fileDataAndIDs =
+ new ResourceFileDataAndIDs((String) attachedResourceId.getEntityId(),
+ translatedId,
+ data);
+ return Optional.of(fileDataAndIDs);
+ } else {
+ logger.warn(
+ "output: '" + resourceId + "' in file '" + data.getFile() + "' is not of type '"
+ + HeatResourcesTypes.CINDER_VOLUME_RESOURCE_TYPE.getHeatResource() + "'");
+ }
+ }
+ } else {
+ logger.warn("output: '" + resourceId + "' in file '" + data.getFile() + "' is not found");
+ }
+ }
+ return Optional.empty();
+ }
+
+ private boolean isOutputOfTypeCinderVolume(TranslateTo translateTo, FileData data,
+ HeatOrchestrationTemplate heatOrchestrationTemplate,
+ String translatedId) {
+ return getResourceByTranslatedResourceId(data.getFile(), heatOrchestrationTemplate,
+ translatedId, translateTo,
+ HeatResourcesTypes.CINDER_VOLUME_RESOURCE_TYPE.getHeatResource())
+ .isPresent();
+ }
+
+ private Optional<List<Map.Entry<String, Resource>>> getResourceByTranslatedResourceId(
+ String fileName, HeatOrchestrationTemplate heatOrchestrationTemplate,
+ String translatedResourceId, TranslateTo translateTo, String heatResourceType) {
+ List<Map.Entry<String, Resource>> list = heatOrchestrationTemplate.getResources().entrySet()
+ .stream()
+ .filter(
+ entry -> getPredicatesForTranslatedIdToResourceId(fileName, 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 fileName, 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 = ResourceTranslationBase
+ .getResourceTranslatedId(fileName, heatOrchestrationTemplate, entry.getKey(), context);
+ return resourceTranslatedId.isPresent()
+ && resourceTranslatedId.get().equals(translatedResourceId);
+ });
+ return list;
+ }
+
+ private boolean isOutputIsGetResource(String resourceId, FileData data,
+ AttachedResourceId attachedResourceId) {
+ if (attachedResourceId.isGetResource()) {
+ return true;
+ } else {
+ logger.warn("output: '" + resourceId + "' in file '" + data.getFile()
+ + "' is not defined as get_resource and therefor not supported.");
+ return false;
+ }
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/helper/impl/NameExtractorServiceImpl.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/helper/impl/NameExtractorServiceImpl.java
new file mode 100644
index 0000000000..9bd3494698
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/helper/impl/NameExtractorServiceImpl.java
@@ -0,0 +1,95 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca.helper.impl;
+
+import org.openecomp.sdc.translator.datatypes.heattotosca.AttachedResourceId;
+import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil;
+import org.openecomp.sdc.translator.services.heattotosca.helper.NameExtractorService;
+import org.openecomp.sdc.translator.services.heattotosca.helper.PropertyRegexMatcher;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.regex.Pattern;
+
+public class NameExtractorServiceImpl implements NameExtractorService {
+
+ @Override
+ public Optional<String> extractNodeTypeNameByPropertiesPriority(
+ Map<String, Object> properties,List<PropertyRegexMatcher> propertiesRegexMatchers) {
+ for (PropertyRegexMatcher propertyRegexMatcher : propertiesRegexMatchers) {
+ Optional<String> parameterNameValue =
+ getPropertyParameterNameValue(properties, propertyRegexMatcher.getPropertyName());
+ if (parameterNameValue.isPresent()) {
+ if (isPropertyValueMatchNamingConvention(propertyRegexMatcher, parameterNameValue.get())) {
+ return Optional.of(parameterNameValue.get().substring(0, parameterNameValue.get()
+ .lastIndexOf(propertyRegexMatcher.getStringToSearchForPropertyValue())));
+ }
+ }
+ }
+
+ return Optional.empty();
+ }
+
+ private boolean isPropertyValueMatchNamingConvention(PropertyRegexMatcher propertyRegexMatcher,
+ String propertyValue) {
+ for (Pattern pattern : propertyRegexMatcher.getRegexPatterns()) {
+ if (pattern.matcher(propertyValue).matches()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private Optional<String> getPropertyParameterNameValue(Map<String, Object> properties,
+ String prop) {
+ Object propObj = properties.get(prop);
+ Optional<AttachedResourceId> property = HeatToToscaUtil.extractProperty(propObj);
+ if (property.isPresent()) {
+ AttachedResourceId extractedProperty = property.get();
+ return getParameterName(extractedProperty);
+ }
+ return Optional.empty();
+ }
+
+ private Optional<String> getParameterName(AttachedResourceId extractedProperty) {
+ if (!extractedProperty.isGetParam()) {
+ return Optional.empty();
+ }
+ Object entityId = extractedProperty.getEntityId();
+ if (entityId instanceof String) {
+ return Optional.of((String) entityId);
+ } else {
+ return Optional.of((String) ((List) entityId).get(0));
+ }
+ }
+
+ @Override
+ public PropertyRegexMatcher getPropertyRegexMatcher(String propertyName,
+ List<String> regexMatchers,
+ String propertyValueSearchTerm) {
+ PropertyRegexMatcher propertyRegexMatcher = new PropertyRegexMatcher();
+ propertyRegexMatcher.setPropertyName(propertyName);
+ propertyRegexMatcher.setRegex(regexMatchers);
+ propertyRegexMatcher.setStringToSearchForPropertyValue(propertyValueSearchTerm);
+ return propertyRegexMatcher;
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/BaseResourceConnection.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/BaseResourceConnection.java
new file mode 100644
index 0000000000..d901ae9c98
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/BaseResourceConnection.java
@@ -0,0 +1,174 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca.impl;
+
+import org.apache.commons.collections4.MapUtils;
+import org.openecomp.core.utilities.yaml.YamlUtil;
+import org.openecomp.sdc.common.errors.CoreException;
+import org.openecomp.sdc.common.errors.ErrorCategory;
+import org.openecomp.sdc.common.errors.ErrorCode;
+import org.openecomp.sdc.heat.datatypes.manifest.FileData;
+import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate;
+import org.openecomp.sdc.heat.datatypes.model.Resource;
+import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate;
+import org.openecomp.sdc.tosca.datatypes.model.NodeType;
+import org.openecomp.sdc.tosca.datatypes.model.RequirementAssignment;
+import org.openecomp.sdc.tosca.datatypes.model.RequirementDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate;
+import org.openecomp.sdc.tosca.services.DataModelUtil;
+import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo;
+import org.openecomp.sdc.translator.services.heattotosca.errors.TranslatorErrorCodes;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+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(ResourceTranslationCinderVolumeAttachmentImpl.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;
+ }
+
+ abstract boolean isDesiredNodeTemplateType(NodeTemplate nodeTemplate);
+
+ abstract List<Predicate<T>> getPredicatesListForConnectionPoints();
+
+ abstract Optional<List<String>> getConnectorParamName(String heatResourceId,
+ Resource heatResource,
+ HeatOrchestrationTemplate
+ nestedHeatOrchestrationTemplate);
+
+ abstract String getDesiredResourceType();
+
+ abstract String getTranslatedResourceIdFromSubstitutionMapping(
+ ServiceTemplate nestedServiceTemplate, Map.Entry<String, T> entry);
+
+ abstract void addRequirementToConnectResources(Map.Entry<String, T> entry,
+ List<String> paramNames);
+
+ abstract List<Map<String, T>> getAllConnectionPoints();
+
+ void connect() {
+ ServiceTemplate nestedServiceTemplate = translateTo.getContext().getTranslatedServiceTemplates()
+ .get(translateTo.getResource().getType());
+ List<String> paramNames = null;
+ 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> entry : connectionPointsMap.entrySet()) {
+ String translatedResourceId =
+ getTranslatedResourceIdFromSubstitutionMapping(nestedServiceTemplate, entry);
+ NodeTemplate nodeTemplate = nestedServiceTemplate.getTopology_template().getNode_templates()
+ .get(translatedResourceId);
+ if (!isDesiredNodeTemplateType(nodeTemplate)) {
+ continue;
+ }
+ paramNames = createResourcesConnection(translatedResourceId, paramNames,
+ nestedHeatOrchestrationTemplate, entry);
+ }
+ }
+ }
+
+ private List<String> createResourcesConnection(String translatedResourceId,
+ List<String> paramNames,
+ HeatOrchestrationTemplate
+ nestedHeatOrchestrationTemplate,
+ Map.Entry<String, T> entry) {
+ List<String> params = paramNames;
+ Optional<List<Map.Entry<String, Resource>>> heatResources =
+ getResourceByTranslatedResourceId(translatedResourceId, nestedHeatOrchestrationTemplate);
+ if (heatResources.isPresent()) {
+ params =
+ addRequirementAndGetConnectorParamsFromResourceProperties(nestedHeatOrchestrationTemplate,
+ entry, params, heatResources.get());
+ }
+ return params;
+ }
+
+ private List<String> addRequirementAndGetConnectorParamsFromResourceProperties(
+ HeatOrchestrationTemplate nestedHeatOrchestrationTemplate, Map.Entry<String, T> entry,
+ List<String> params, List<Map.Entry<String, Resource>> heatResources) {
+ Resource heatResource;
+ for (Map.Entry<String, Resource> resourceEntry : heatResources) {
+ heatResource = resourceEntry.getValue();
+ if (!MapUtils.isEmpty(heatResource.getProperties())) {
+ Optional<List<String>> connectorParamName =
+ getConnectorParamName(resourceEntry.getKey(), heatResource,
+ nestedHeatOrchestrationTemplate);
+ if (!connectorParamName.isPresent()) {
+ break;
+ } else {
+ params = connectorParamName.get();
+ }
+ }
+ Objects.requireNonNull(params);
+ addRequirementToConnectResources(entry, 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());
+ }
+ return resourceByTranslatedResourceId;
+ }
+
+ void createRequirementAssignment(Map.Entry<String, RequirementDefinition> entry, String node,
+ NodeTemplate nodeTemplate) {
+ if (Objects.nonNull(node)) {
+ RequirementAssignment requirementAssignment;
+ requirementAssignment = new RequirementAssignment();
+ requirementAssignment.setRelationship(entry.getValue().getRelationship());
+ requirementAssignment.setCapability(entry.getValue().getCapability());
+ requirementAssignment.setNode(node);
+ DataModelUtil.addRequirementAssignment(nodeTemplate, entry.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/ContrailV2VmInterfaceToNetResourceConnection.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ContrailV2VmInterfaceToNetResourceConnection.java
new file mode 100644
index 0000000000..890d2a76af
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ContrailV2VmInterfaceToNetResourceConnection.java
@@ -0,0 +1,139 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca.impl;
+
+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.tosca.datatypes.ToscaCapabilityType;
+import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
+import org.openecomp.sdc.tosca.datatypes.ToscaRelationshipType;
+import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate;
+import org.openecomp.sdc.tosca.datatypes.model.NodeType;
+import org.openecomp.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.datatypes.heattotosca.to.TranslatedHeatResource;
+import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil;
+
+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;
+
+public class ContrailV2VmInterfaceToNetResourceConnection extends PortToNetResourceConnection {
+
+ 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.getDisplayName());
+ }
+
+ @Override
+ protected Optional<List<String>> getConnectorParamName(String heatResourceId,
+ Resource heatResource,
+ HeatOrchestrationTemplate nestedHeatOrchestrationTemplate) {
+ 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();
+ }
+ 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.");
+ }
+ Object virtualNetworkRef = ((List) virtualNetworkRefs).get(0);
+ Optional<AttachedResourceId> network = HeatToToscaUtil
+ .extractAttachedResourceId(nestedFileData.getFile(), nestedHeatOrchestrationTemplate,
+ translateTo.getContext(), virtualNetworkRef);
+ if (network.isPresent() && network.get().isGetParam()) {
+ networks.add((String) network.get().getEntityId());
+ }
+ return Optional.of(networks);
+ }
+
+ @Override
+ protected String getDesiredResourceType() {
+ return HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource();
+ }
+
+ @Override
+ protected void addRequirementToConnectResources(Map.Entry<String, RequirementDefinition> entry,
+ List<String> paramNames) {
+ for (String paramName : paramNames) {
+ Object paramValue = translateTo.getResource().getProperties().get(paramName);
+ String contrailAttachedResourceId =
+ HeatToToscaUtil.extractContrailGetResourceAttachedHeatResourceId(paramValue);
+ Optional<String> node;
+ if (contrailAttachedResourceId != null) { // contrail get resource
+ node = ResourceTranslationBase.getResourceTranslatedId(translateTo.getHeatFileName(),
+ translateTo.getHeatOrchestrationTemplate(), contrailAttachedResourceId,
+ translateTo.getContext());
+ if (node.isPresent()) {
+ createRequirementAssignment(entry, node.get(), substitutionNodeTemplate);
+ }
+ } else {
+ Optional<AttachedResourceId> attachedResourceId =
+ HeatToToscaUtil.extractAttachedResourceId(translateTo, paramName);
+ if (!attachedResourceId.isPresent()) {
+ return;
+ }
+ AttachedResourceId resourceId = attachedResourceId.get();
+ if (resourceId.isGetParam()) {
+ TranslatedHeatResource shareResource =
+ translateTo.getContext().getHeatSharedResourcesByParam()
+ .get(resourceId.getEntityId());
+ if (Objects.nonNull(shareResource)
+ && !HeatToToscaUtil.isHeatFileNested(translateTo, translateTo.getHeatFileName())) {
+ createRequirementAssignment(entry, shareResource.getTranslatedId(),
+ substitutionNodeTemplate);
+ }
+ }
+ }
+ }
+ }
+
+ @Override
+ protected List<Predicate<RequirementDefinition>> getPredicatesListForConnectionPoints() {
+ ArrayList<Predicate<RequirementDefinition>> predicates = new ArrayList<>();
+ predicates.add(
+ req -> req.getCapability().equals(ToscaCapabilityType.NETWORK_LINKABLE.getDisplayName())
+ && req.getNode().equals(ToscaNodeType.ROOT.getDisplayName())
+ && req.getRelationship().equals(ToscaRelationshipType.NETWORK_LINK_TO.getDisplayName())
+ );
+ return predicates;
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/NovaAndPortResourceConnectionHelper.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/NovaAndPortResourceConnectionHelper.java
new file mode 100644
index 0000000000..bc60a24223
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/NovaAndPortResourceConnectionHelper.java
@@ -0,0 +1,106 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca.impl;
+
+import org.openecomp.sdc.heat.datatypes.manifest.FileData;
+import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate;
+import org.openecomp.sdc.heat.datatypes.model.Resource;
+import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate;
+import org.openecomp.sdc.tosca.datatypes.model.NodeType;
+import org.openecomp.sdc.tosca.datatypes.model.RequirementDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate;
+import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo;
+
+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 class NovaAndPortResourceConnectionHelper
+ extends BaseResourceConnection<RequirementDefinition> {
+ public NovaAndPortResourceConnectionHelper(ResourceTranslationBase resourceTranslationBase,
+ TranslateTo translateTo, FileData nestedFileData,
+ NodeTemplate substitutionNodeTemplate,
+ NodeType nodeType) {
+ super(resourceTranslationBase, translateTo, nestedFileData, substitutionNodeTemplate, nodeType);
+ }
+
+ @Override
+ boolean isDesiredNodeTemplateType(NodeTemplate nodeTemplate) {
+ return false;
+ }
+
+ @Override
+ List<Predicate<RequirementDefinition>> getPredicatesListForConnectionPoints() {
+ return null;
+ }
+
+ @Override
+ Optional<List<String>> getConnectorParamName(String heatResourceId,
+ Resource heatResource,
+ HeatOrchestrationTemplate
+ nestedHeatOrchestrationTemplate) {
+ return null;
+ }
+
+ @Override
+ String getDesiredResourceType() {
+ return null;
+ }
+
+ @Override
+ String getTranslatedResourceIdFromSubstitutionMapping(
+ ServiceTemplate nestedServiceTemplate,Map.Entry<String,
+ RequirementDefinition> entry) {
+ return null;
+ }
+
+ @Override
+ void addRequirementToConnectResources(Map.Entry<String, RequirementDefinition> entry,
+ List<String> paramNames) {
+
+ }
+
+ @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;
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/NovaToVolResourceConnection.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/NovaToVolResourceConnection.java
new file mode 100644
index 0000000000..8bab0dbc50
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/NovaToVolResourceConnection.java
@@ -0,0 +1,228 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca.impl;
+
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.openecomp.sdc.common.errors.CoreException;
+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.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.openecomp.sdc.tosca.datatypes.model.NodeTemplate;
+import org.openecomp.sdc.tosca.datatypes.model.NodeType;
+import org.openecomp.sdc.tosca.datatypes.model.RequirementDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate;
+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.ResourceFileDataAndIDs;
+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.HeatToToscaUtil;
+import org.openecomp.sdc.translator.services.heattotosca.TranslationContext;
+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 NovaAndPortResourceConnectionHelper {
+
+ 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);
+ return toscaAnalyzerService.isTypeOf(nodeTemplate, ToscaNodeType.NOVA_SERVER.getDisplayName(),
+ 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.ATTACHMENT.getDisplayName())
+ && req.getNode().equals(ToscaNodeType.BLOCK_STORAGE.getDisplayName())
+ && req.getRelationship()
+ .equals(ToscaRelationshipType.NATIVE_ATTACHES_TO.getDisplayName()));
+ return predicates;
+ }
+
+ @Override
+ Optional<List<String>> getConnectorParamName(
+ String heatResourceId, Resource heatResource,
+ HeatOrchestrationTemplate nestedHeatOrchestrationTemplate) {
+ Optional<AttachedResourceId> volumeId = HeatToToscaUtil
+ .extractAttachedResourceId(nestedFileData.getFile(), nestedHeatOrchestrationTemplate,
+ translateTo.getContext(), heatResource.getProperties().get("volume_id"));
+ if (volumeId.isPresent() && volumeId.get().isGetParam()) {
+ return Optional.of(Collections.singletonList((String) volumeId.get().getEntityId()));
+ } else {
+ return Optional.empty();
+ }
+ }
+
+ @Override
+ String getDesiredResourceType() {
+ return HeatResourcesTypes.CINDER_VOLUME_ATTACHMENT_RESOURCE_TYPE.getHeatResource();
+ }
+
+ @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);
+ }
+ }
+
+ 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;
+ }
+
+ @Override
+ String getTranslatedResourceIdFromSubstitutionMapping(ServiceTemplate nestedServiceTemplate,
+ Map.Entry<String,
+ RequirementDefinition> entry) {
+ List<String> substitutionMapping =
+ nestedServiceTemplate.getTopology_template().getSubstitution_mappings().getRequirements()
+ .get(entry.getKey());
+ return substitutionMapping.get(0);
+ }
+
+ @Override
+ void addRequirementToConnectResources(Map.Entry<String, RequirementDefinition> entry,
+ List<String> paramNames) {
+ String paramName = paramNames.get(0);
+ Optional<AttachedResourceId> attachedResourceId =
+ HeatToToscaUtil.extractAttachedResourceId(translateTo, paramName);
+ String node;
+ if (!attachedResourceId.isPresent()) {
+ return;
+ }
+ AttachedResourceId attachedResource = attachedResourceId.get();
+ if (attachedResource.isGetResource()) {
+ String volTranslatedId = (String) attachedResource.getTranslatedId();
+ Resource volServerResource = HeatToToscaUtil
+ .getResource(translateTo.getHeatOrchestrationTemplate(), volTranslatedId,
+ translateTo.getHeatFileName());
+ if (!StringUtils.equals(HeatResourcesTypes.CINDER_VOLUME_RESOURCE_TYPE.getHeatResource(),
+ volServerResource.getType())) {
+ logger.warn("Volume attachment used from nested resource " + translateTo.getResourceId()
+ + " is pointing to incorrect resource type(" + volServerResource.getType()
+ + ") for relation through the parameter '" + paramName + "."
+ + " The connection to the volume is ignored. "
+ + "Supported types are: "
+ + HeatResourcesTypes.CINDER_VOLUME_RESOURCE_TYPE.getHeatResource());
+ return;
+ }
+ node = volTranslatedId;
+ createRequirementAssignment(entry, node, substitutionNodeTemplate);
+ } else if (attachedResource.isGetParam()) {
+ TranslatedHeatResource shareResource =
+ translateTo.getContext().getHeatSharedResourcesByParam()
+ .get(attachedResource.getEntityId());
+ if (Objects.nonNull(shareResource)
+ && !HeatToToscaUtil.isHeatFileNested(translateTo, translateTo.getHeatFileName())) {
+ if (!StringUtils.equals(HeatResourcesTypes.CINDER_VOLUME_RESOURCE_TYPE.getHeatResource(),
+ shareResource.getHeatResource().getType())) {
+ logger.warn("Volume attachment used from nested resource " + translateTo.getResourceId()
+ + " is pointing to incorrect resource type("
+ + shareResource.getHeatResource().getType() + ") for relation through the parameter '"
+ + paramName + "."
+ + " The connection to the volume is ignored. "
+ + "Supported types are: "
+ + HeatResourcesTypes.CINDER_VOLUME_RESOURCE_TYPE.getHeatResource());
+ return;
+ }
+ node = shareResource.getTranslatedId();
+ createRequirementAssignment(entry, node, substitutionNodeTemplate);
+ } else 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) attachedResource.getEntityId(), translateTo, FileData.Type.HEAT_VOL);
+ if (fileDataContainingResource.isPresent()) {
+ createRequirementAssignment(entry,
+ fileDataContainingResource.get().getTranslatedResourceId(),
+ 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/PortToNetResourceConnection.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/PortToNetResourceConnection.java
new file mode 100644
index 0000000000..8adfca305e
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/PortToNetResourceConnection.java
@@ -0,0 +1,200 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca.impl;
+
+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.tosca.datatypes.ToscaCapabilityType;
+import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
+import org.openecomp.sdc.tosca.datatypes.ToscaRelationshipType;
+import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate;
+import org.openecomp.sdc.tosca.datatypes.model.NodeType;
+import org.openecomp.sdc.tosca.datatypes.model.RequirementDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate;
+import org.openecomp.sdc.translator.datatypes.heattotosca.AttachedResourceId;
+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.HeatToToscaUtil;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+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;
+
+public class PortToNetResourceConnection extends NovaAndPortResourceConnectionHelper {
+
+ 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.getDisplayName());
+ }
+
+ @Override
+ protected List<Predicate<RequirementDefinition>> getPredicatesListForConnectionPoints() {
+ ArrayList<Predicate<RequirementDefinition>> predicates = new ArrayList<>();
+ predicates.add(
+ req -> req.getCapability().equals(ToscaCapabilityType.NETWORK_LINKABLE.getDisplayName())
+ && req.getNode().equals(ToscaNodeType.ROOT.getDisplayName())
+ && req.getRelationship().equals(
+ ToscaRelationshipType.NETWORK_LINK_TO.getDisplayName()));
+ return predicates;
+ }
+
+ @Override
+ protected Optional<List<String>> getConnectorParamName(String heatResourceId,
+ Resource heatResource,
+ HeatOrchestrationTemplate
+ nestedHeatOrchestrationTemplate) {
+ Optional<AttachedResourceId> network = HeatToToscaUtil
+ .extractAttachedResourceId(nestedFileData.getFile(), nestedHeatOrchestrationTemplate,
+ translateTo.getContext(), heatResource.getProperties().get("network"));
+ if (network.isPresent() && network.get().isGetParam()) {
+ return Optional.of(Collections.singletonList((String) network.get().getEntityId()));
+ } else {
+ network = HeatToToscaUtil
+ .extractAttachedResourceId(nestedFileData.getFile(), nestedHeatOrchestrationTemplate,
+ translateTo.getContext(), heatResource.getProperties().get("network_id"));
+ if (network.isPresent() && network.get().isGetParam()) {
+ 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 getTranslatedResourceIdFromSubstitutionMapping(
+ ServiceTemplate nestedServiceTemplate, Map.Entry<String, RequirementDefinition> entry) {
+ List<String> substitutionMapping =
+ nestedServiceTemplate.getTopology_template().getSubstitution_mappings().getRequirements()
+ .get(entry.getKey());
+ return substitutionMapping.get(0);
+ }
+
+ @Override
+ protected void addRequirementToConnectResources(Map.Entry<String, RequirementDefinition> entry,
+ List<String> paramNames) {
+ 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);
+ if (paramValue == null) {
+ logger.warn(
+ "Nested resource '" + translateTo.getResourceId() + "' is not including property '"
+ + paramName + "' with value for the nested heat file, therefore, '" + entry.getKey()
+ + "' TOSCA requirement will not be connected.");
+ return;
+ }
+ 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());
+
+ Optional<String> targetTranslatedNodeId =
+ getConnectionTargetNodeUsingGetResourceFunc(entry, paramName, paramValue,
+ supportedNetworkTypes);
+ if (targetTranslatedNodeId.isPresent()) {
+ createRequirementAssignment(entry, targetTranslatedNodeId.get(), substitutionNodeTemplate);
+ } else {
+ targetTranslatedNodeId =
+ getConnectionTargetNodeUsingGetParam(entry, paramName, supportedNetworkTypes);
+ if (targetTranslatedNodeId.isPresent()) {
+ createRequirementAssignment(entry, targetTranslatedNodeId.get(), substitutionNodeTemplate);
+ }
+ }
+ }
+
+ private boolean validateResourceTypeSupportedForReqCreation(String sourceResourceId,
+ final String sourcePropertyName,
+ String sourceReqId,
+ Resource targetResource,
+ List<String> supportedTypes) {
+ if (!resourceTranslationBase.isResourceTypeSupported(targetResource, supportedTypes)) {
+ logger.warn("Nested resource '" + sourceResourceId + "' property '" + sourcePropertyName
+ + "' is pointing to a resource with type '" + targetResource.getType()
+ + "' which is not supported for requirement '" + sourceReqId
+ + "' that connect port to network. \nSupported types are: '" + supportedTypes.toString()
+ + "', therefore, this TOSCA requirement will not be connected.");
+ return false;
+ }
+ return true;
+ }
+
+ private Optional<String> getConnectionTargetNodeUsingGetParam(
+ Map.Entry<String, RequirementDefinition> requirementDefinitionEntry, String paramName,
+ List<String> supportedTargetNodeTypes) {
+ Optional<AttachedResourceId> attachedResourceId =
+ HeatToToscaUtil.extractAttachedResourceId(translateTo, paramName);
+ if (!attachedResourceId.isPresent()) {
+ return Optional.empty();
+ }
+ AttachedResourceId resourceId = attachedResourceId.get();
+ if (resourceId.isGetParam()) {
+ TranslatedHeatResource shareResource =
+ translateTo.getContext().getHeatSharedResourcesByParam().get(resourceId.getEntityId());
+ if (Objects.nonNull(shareResource)
+ && !HeatToToscaUtil.isHeatFileNested(translateTo, translateTo.getHeatFileName())) {
+ if (validateResourceTypeSupportedForReqCreation(translateTo.getResourceId(), paramName,
+ requirementDefinitionEntry.getKey(), shareResource.getHeatResource(),
+ supportedTargetNodeTypes)) {
+ return Optional.of(shareResource.getTranslatedId());
+ }
+ }
+ }
+
+ return Optional.empty();
+ }
+
+ private Optional<String> getConnectionTargetNodeUsingGetResourceFunc(
+ Map.Entry<String, RequirementDefinition> requirementDefinitionEntry, String paramName,
+ Object paramValue, List<String> supportedTargetNodeTypes) {
+ String getResourceAttachedResourceId =
+ HeatToToscaUtil.extractContrailGetResourceAttachedHeatResourceId(paramValue);
+ if (getResourceAttachedResourceId != null) { // get resource
+ Resource resource = translateTo.getHeatOrchestrationTemplate().getResources()
+ .get(getResourceAttachedResourceId);
+ if (validateResourceTypeSupportedForReqCreation(translateTo.getResourceId(), paramName,
+ requirementDefinitionEntry.getKey(), resource, supportedTargetNodeTypes)) {
+ return ResourceTranslationBase.getResourceTranslatedId(translateTo.getHeatFileName(),
+ translateTo.getHeatOrchestrationTemplate(), getResourceAttachedResourceId,
+ translateTo.getContext());
+ }
+ }
+
+ 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/ResourceTranslationBase.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationBase.java
new file mode 100644
index 0000000000..45e3830f6f
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationBase.java
@@ -0,0 +1,456 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca.impl;
+
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.collections4.MapUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.openecomp.core.utilities.yaml.YamlUtil;
+import org.openecomp.sdc.common.errors.CoreException;
+import org.openecomp.sdc.heat.datatypes.manifest.FileData;
+import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate;
+import org.openecomp.sdc.heat.datatypes.model.Output;
+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.model.ArtifactDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.AttributeDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.CapabilityDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.Import;
+import org.openecomp.sdc.tosca.datatypes.model.InterfaceDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate;
+import org.openecomp.sdc.tosca.datatypes.model.NodeType;
+import org.openecomp.sdc.tosca.datatypes.model.PropertyDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.RequirementAssignment;
+import org.openecomp.sdc.tosca.datatypes.model.RequirementDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate;
+import org.openecomp.sdc.tosca.services.DataModelUtil;
+import org.openecomp.sdc.tosca.services.ToscaConstants;
+import org.openecomp.sdc.tosca.services.ToscaNativeTypesServiceTemplate;
+import org.openecomp.sdc.translator.datatypes.heattotosca.AttachedResourceId;
+import org.openecomp.sdc.translator.datatypes.heattotosca.to.ResourceFileDataAndIDs;
+import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo;
+import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil;
+import org.openecomp.sdc.translator.services.heattotosca.ResourceTranslation;
+import org.openecomp.sdc.translator.services.heattotosca.ResourceTranslationFactory;
+import org.openecomp.sdc.translator.services.heattotosca.TranslationContext;
+import org.openecomp.sdc.translator.services.heattotosca.TranslationService;
+import org.openecomp.sdc.translator.services.heattotosca.errors.ResourceNotFoundInHeatFileErrorBuilder;
+import org.openecomp.sdc.translator.services.heattotosca.globaltypes.GlobalTypesGenerator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.Collection;
+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.function.Predicate;
+import java.util.stream.Collectors;
+
+public abstract class ResourceTranslationBase implements ResourceTranslation {
+
+ protected static Logger logger = LoggerFactory.getLogger(ResourceTranslationBase.class);
+
+ static Optional<ResourceFileDataAndIDs> getFileDataContainingResource(
+ List<FileData> filesToSearch, String resourceId, TranslationContext context,
+ FileData.Type... types) {
+ if (CollectionUtils.isEmpty(filesToSearch)) {
+ return Optional.empty();
+ }
+
+ List<FileData> fileDatas = Objects.isNull(types) ? filesToSearch
+ : HeatToToscaUtil.getFilteredListOfFileDataByTypes(filesToSearch, types);
+ for (FileData data : fileDatas) {
+ HeatOrchestrationTemplate heatOrchestrationTemplate = new YamlUtil()
+ .yamlToObject(context.getFiles().getFileContent(data.getFile()),
+ HeatOrchestrationTemplate.class);
+ Map<String, Output> outputs = heatOrchestrationTemplate.getOutputs();
+ if (Objects.isNull(outputs)) {
+ continue;
+ }
+ Output output = outputs.get(resourceId);
+ if (Objects.nonNull(output)) {
+ Optional<AttachedResourceId> attachedOutputId = HeatToToscaUtil
+ .extractAttachedResourceId(data.getFile(), heatOrchestrationTemplate, context,
+ output.getValue());
+ if (attachedOutputId.isPresent()) {
+ AttachedResourceId attachedResourceId = attachedOutputId.get();
+ if (!attachedResourceId.isGetResource()) {
+ logger.warn("output: '" + resourceId + "' in file '" + data.getFile()
+ + "' is not defined as get_resource and therefor not supported.");
+ continue;
+ }
+ ResourceFileDataAndIDs fileDataAndIDs =
+ new ResourceFileDataAndIDs((String) attachedResourceId.getEntityId(),
+ (String) attachedResourceId.getTranslatedId(),
+ data);
+ return Optional.of(fileDataAndIDs);
+ }
+ }
+ }
+ return Optional.empty();
+ }
+
+ /**
+ * 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());
+ }
+ TranslateTo translateTo =
+ generateTranslationTo(heatFileName, null, heatOrchestrationTemplate, resource, resourceId,
+ null, context);
+ translatedId =
+ ResourceTranslationFactory.getInstance(resource).generateTranslatedId(translateTo);
+ if (translatedId != null) {
+ context.getTranslatedIds().get(heatFileName).put(resourceId, translatedId);
+ }
+ return Optional.ofNullable(translatedId);
+ }
+
+ 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;
+ }
+
+ protected abstract void translate(TranslateTo translateTo);
+
+ protected String generateTranslatedId(TranslateTo translateTo) {
+ isEssentialRequirementsValid(translateTo);
+ return translateTo.getResourceId();
+ }
+
+ protected boolean isEssentialRequirementsValid(TranslateTo translateTo) {
+ return true;
+ }
+
+ @Override
+ 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 (context.getTranslatedResources().get(heatFileName).contains(resourceId)) {
+ return translatedId;
+ }
+ if (!translatedId.isPresent()) {
+ return Optional.empty();
+ }
+ logger.debug("Translate- file:" + heatFileName + " resource Id:" + resourceId
+ + " translated resource id:" + translatedId.get());
+ translate(new TranslateTo(heatFileName, serviceTemplate, heatOrchestrationTemplate, resource,
+ resourceId, translatedId.get(), context));
+ context.getTranslatedResources().get(heatFileName).add(resourceId);
+
+ if (isNodeTemplate(translatedId.get(), serviceTemplate)) {
+ if (!context.getHeatStackGroupMembers().containsKey(heatFileName)) {
+ context.getHeatStackGroupMembers().put(heatFileName, new HashSet<>());
+ }
+ context.getHeatStackGroupMembers().get(heatFileName).add(translatedId.get());
+ updateResourceDependency(heatFileName, resource, heatOrchestrationTemplate,
+ translatedId.get(), serviceTemplate, context);
+ }
+
+ return translatedId;
+ }
+
+ private void updateResourceDependency(String heatFileName, Resource resource,
+ HeatOrchestrationTemplate heatOrchestrationTemplate,
+ String translatedId, ServiceTemplate serviceTemplate,
+ TranslationContext context) {
+ if (resource.getDepends_on() == null) {
+ return;
+ }
+
+ if (resource.getDepends_on() instanceof List) {
+ List<String> dependsOnList = (List<String>) resource.getDepends_on();
+ for (String dependsOnResourceId : dependsOnList) {
+ addDependOnRequirement(dependsOnResourceId, translatedId, serviceTemplate, heatFileName,
+ heatOrchestrationTemplate, context);
+ }
+ } else {
+ String dependsOnResourceId = (String) resource.getDepends_on();
+ addDependOnRequirement(dependsOnResourceId, translatedId, serviceTemplate, heatFileName,
+ heatOrchestrationTemplate, context);
+ }
+
+ }
+
+ private void addDependOnRequirement(String dependsOnResourceId, String nodeTemplateId,
+ ServiceTemplate serviceTemplate, String heatFileName,
+ HeatOrchestrationTemplate heatOrchestrationTemplate,
+ TranslationContext context) {
+ RequirementAssignment requirementAssignment = new RequirementAssignment();
+ Optional<String> resourceTranslatedId =
+ getResourceTranslatedId(heatFileName, heatOrchestrationTemplate, dependsOnResourceId,
+ context);
+
+ if (resourceTranslatedId.isPresent()
+ && isNodeTemplate(resourceTranslatedId.get(), serviceTemplate)) {
+ requirementAssignment.setNode(resourceTranslatedId.get());
+ requirementAssignment.setCapability(ToscaCapabilityType.NODE.getDisplayName());
+ requirementAssignment.setRelationship(ToscaRelationshipType.DEPENDS_ON.getDisplayName());
+ DataModelUtil.addRequirementAssignment(
+ serviceTemplate.getTopology_template().getNode_templates().get(nodeTemplateId),
+ ToscaConstants.DEPENDS_ON_REQUIREMENT_ID, requirementAssignment);
+ }
+ }
+
+ private boolean isNodeTemplate(String entryId, ServiceTemplate serviceTemplate) {
+ return serviceTemplate.getTopology_template().getNode_templates() != null
+ && serviceTemplate.getTopology_template().getNode_templates().get(entryId) != null;
+ }
+
+ FileData getFileData(String fileName, TranslationContext context) {
+
+ List<FileData> fileDataList = context.getManifest().getContent().getData();
+ for (FileData fileData : fileDataList) {
+ if (TranslationService.getTypesToProcessByTranslator().contains(fileData.getType())
+ && fileData.getFile().equals(fileName)) {
+ return fileData;
+ }
+ }
+ return null;
+ }
+
+ NodeType getNodeTypeWithFlatHierarchy(String nodeTypeId, ServiceTemplate serviceTemplate,
+ TranslationContext context) {
+ NodeType nodeType;
+ if (serviceTemplate != null && serviceTemplate.getNode_types() != null) {
+ nodeType = serviceTemplate.getNode_types().get(nodeTypeId);
+
+ if (nodeType != null) {
+ return enrichNodeType(nodeType, serviceTemplate, context);
+ }
+ }
+ Map<String, Map<String, NodeType>> globalNodeTypesMap = new HashMap<>();
+ Collection<ServiceTemplate> globalNodeTypes =
+ GlobalTypesGenerator.getGlobalTypesServiceTemplate().values();
+ ServiceTemplate nativeNodeTypeServiceTemplate =
+ ToscaNativeTypesServiceTemplate.createServiceTemplate();
+ for (ServiceTemplate globalNodeType : globalNodeTypes) {
+ globalNodeTypesMap
+ .put(globalNodeType.getMetadata().getTemplate_name(), globalNodeType.getNode_types());
+ }
+ if (Objects.nonNull(serviceTemplate) && MapUtils.isNotEmpty(serviceTemplate.getImports())) {
+ for (Map.Entry<String, Import> entry : serviceTemplate.getImports().entrySet()) {
+ if (globalNodeTypesMap.containsKey(entry.getKey())) {
+ Map<String, NodeType> nodeTypes = globalNodeTypesMap.get(entry.getKey());
+ if (nodeTypes != null && nodeTypes.containsKey(nodeTypeId)) {
+ return enrichNodeType(nodeTypes.get(nodeTypeId), serviceTemplate, context);
+ }
+ }
+ if (context.getGlobalSubstitutionServiceTemplate() != null
+ && context.getGlobalSubstitutionServiceTemplate().getNode_types() != null
+ && context.getGlobalSubstitutionServiceTemplate().getNode_types()
+ .containsKey(nodeTypeId)) {
+ return enrichNodeType(
+ context.getGlobalSubstitutionServiceTemplate().getNode_types().get(nodeTypeId),
+ serviceTemplate, context);
+ }
+ if (nativeNodeTypeServiceTemplate.getNode_types().containsKey(nodeTypeId)) {
+ return enrichNodeType(nativeNodeTypeServiceTemplate.getNode_types().get(nodeTypeId),
+ serviceTemplate, context);
+ }
+ }
+ }
+ return new NodeType();
+
+ }
+
+ private NodeType enrichNodeType(NodeType nodeType, ServiceTemplate serviceTemplate,
+ TranslationContext context) {
+ NodeType clonedNodeType;
+
+ if (StringUtils.isEmpty(nodeType.getDerived_from())) {
+ return nodeType.clone();
+ }
+
+ clonedNodeType = enrichNodeType(
+ getNodeTypeWithFlatHierarchy(nodeType.getDerived_from(), serviceTemplate, context),
+ serviceTemplate, context);
+ mergeNodeTypes(clonedNodeType, nodeType);
+ return clonedNodeType;
+
+ }
+
+ private void mergeNodeTypes(NodeType target, NodeType source) {
+ target.setDerived_from(source.getDerived_from());
+ target.setDescription(source.getDescription());
+ target.setVersion(source.getVersion());
+ target.setProperties(
+ mergeMaps(target.getProperties(), source.getProperties(), PropertyDefinition.class));
+ target.setInterfaces(
+ mergeMaps(target.getInterfaces(), source.getInterfaces(), InterfaceDefinition.class));
+ target.setArtifacts(
+ mergeMaps(target.getArtifacts(), source.getArtifacts(), ArtifactDefinition.class));
+ target.setAttributes(
+ mergeMaps(target.getAttributes(), source.getAttributes(), AttributeDefinition.class));
+ target.setCapabilities(
+ mergeMaps(target.getCapabilities(), source.getCapabilities(), CapabilityDefinition.class));
+ target.setRequirements(mergeLists(target.getRequirements(), source.getRequirements(),
+ RequirementDefinition.class));
+ }
+
+ private <T, S> List<Map<T, S>> mergeLists(List<Map<T, S>> target, List<Map<T, S>> source,
+ Class<S> value) {
+ List<Map<T, S>> retList = new ArrayList<>();
+ if (Objects.nonNull(target)) {
+ retList.addAll(target);
+ }
+
+ if (Objects.nonNull(source)) {
+ for (Map<T, S> sourceMap : source) {
+ for (Map.Entry<T, S> entry : sourceMap.entrySet()) {
+ mergeEntryInList(entry.getKey(), entry.getValue(), retList);
+ }
+ }
+ }
+ return retList;
+ }
+
+ <T, S> void mergeEntryInList(T key, S value, List<Map<T, S>> target) {
+ boolean found = false;
+ for (Map<T, S> map : target) {
+ if (map.containsKey(key)) {
+ map.put(key, value);
+ found = true;
+ }
+ }
+
+ if (!found) {
+ Map<T, S> newMap = new HashMap<>();
+ newMap.put(key, value);
+ target.add(newMap);
+ }
+ }
+
+
+ private <T, S> Map<T, S> mergeMaps(Map<T, S> target, Map<T, S> source, Class<S> value) {
+ Map<T, S> retMap = new HashMap<>();
+ if (MapUtils.isNotEmpty(target)) {
+ retMap.putAll(target);
+ }
+
+ if (MapUtils.isNotEmpty(source)) {
+ retMap.putAll(source);
+ }
+ return retMap;
+ }
+
+ Optional<List<Map.Entry<String, Resource>>> getResourceByTranslatedResourceId(
+ String fileName,
+ HeatOrchestrationTemplate heatOrchestrationTemplate,
+ String translatedResourceId,TranslateTo translateTo,String heatResourceType) {
+ List<Map.Entry<String, Resource>> list = heatOrchestrationTemplate.getResources().entrySet()
+ .stream()
+ .filter(
+ entry -> getPredicatesForTranslatedIdToResourceId(fileName, 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 fileName, 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(fileName, heatOrchestrationTemplate, entry.getKey(), context);
+ return resourceTranslatedId.isPresent()
+ && resourceTranslatedId.get().equals(translatedResourceId);
+ });
+ return list;
+ }
+
+ void addBindingReqFromPortToCompute(String computeNodeTemplateId, NodeTemplate portNodeTemplate) {
+ RequirementAssignment requirementAssignment = new RequirementAssignment();
+ requirementAssignment.setCapability(ToscaCapabilityType.NETWORK_BINDABLE.getDisplayName());
+ requirementAssignment.setRelationship(ToscaRelationshipType.NETWORK_BINDS_TO.getDisplayName());
+ requirementAssignment.setNode(computeNodeTemplateId);
+ DataModelUtil.addRequirementAssignment(portNodeTemplate, ToscaConstants.BINDING_REQUIREMENT_ID,
+ requirementAssignment);
+ }
+
+ void addLinkReqFromPortToNetwork(NodeTemplate nodeTemplate, String translatedId) {
+ RequirementAssignment requirement = new RequirementAssignment();
+ requirement.setCapability(ToscaCapabilityType.NETWORK_LINKABLE.getDisplayName());
+ requirement.setRelationship(ToscaRelationshipType.NETWORK_LINK_TO.getDisplayName());
+ requirement.setNode(translatedId);
+ DataModelUtil
+ .addRequirementAssignment(nodeTemplate, ToscaConstants.LINK_REQUIREMENT_ID, requirement);
+ }
+
+ boolean isResourceTypeSupported(Resource resource, List<String> supportedTypes) {
+ return Objects.nonNull(resource) && supportedTypes.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/ResourceTranslationCinderVolumeAttachmentImpl.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationCinderVolumeAttachmentImpl.java
new file mode 100644
index 0000000000..cbad52a95d
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationCinderVolumeAttachmentImpl.java
@@ -0,0 +1,202 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca.impl;
+
+import static org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil.getResource;
+
+import org.apache.commons.lang3.StringUtils;
+import org.openecomp.sdc.common.errors.CoreException;
+import org.openecomp.sdc.heat.datatypes.manifest.FileData;
+import org.openecomp.sdc.heat.datatypes.model.HeatResourcesTypes;
+import org.openecomp.sdc.heat.datatypes.model.Resource;
+import org.openecomp.sdc.tosca.datatypes.ToscaRelationshipType;
+import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate;
+import org.openecomp.sdc.tosca.datatypes.model.RelationshipTemplate;
+import org.openecomp.sdc.tosca.datatypes.model.RequirementAssignment;
+import org.openecomp.sdc.tosca.services.DataModelUtil;
+import org.openecomp.sdc.translator.datatypes.heattotosca.AttachedResourceId;
+import org.openecomp.sdc.translator.datatypes.heattotosca.to.ResourceFileDataAndIDs;
+import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo;
+import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil;
+import org.openecomp.sdc.translator.services.heattotosca.ResourceTranslationFactory;
+import org.openecomp.sdc.translator.services.heattotosca.errors.MissingMandatoryPropertyErrorBuilder;
+import org.openecomp.sdc.translator.services.heattotosca.helper.VolumeTranslationHelper;
+import org.openecomp.sdc.translator.services.heattotosca.mapping.TranslatorHeatToToscaPropertyConverter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+import java.util.Optional;
+
+public class ResourceTranslationCinderVolumeAttachmentImpl extends ResourceTranslationBase {
+ protected static Logger logger =
+ LoggerFactory.getLogger(ResourceTranslationCinderVolumeAttachmentImpl.class);
+
+ @Override
+ protected void translate(TranslateTo translateTo) {
+ String volumeIdPropertyName = "volume_id";
+ RelationshipTemplate relationTemplate = new RelationshipTemplate();
+ relationTemplate.setType(ToscaRelationshipType.CINDER_VOLUME_ATTACHES_TO.getDisplayName());
+ String relationshipTemplateId = translateTo.getTranslatedId();
+ String heatFileName = translateTo.getHeatFileName();
+ relationTemplate.setProperties(TranslatorHeatToToscaPropertyConverter
+ .getToscaPropertiesSimpleConversion(translateTo.getResource().getProperties(),
+ relationTemplate.getProperties(), heatFileName,
+ translateTo.getHeatOrchestrationTemplate(), translateTo.getResource().getType(),
+ relationTemplate, translateTo.getContext()));
+
+ AttachedResourceId attachedVolumeId = getAttachedResourceId(translateTo, volumeIdPropertyName);
+ String instanceUuid = "instance_uuid";
+ 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,
+ String relationshipTemplateId, String heatFileName,
+ AttachedResourceId volResourceId, String novaResourceId) {
+ String toscaCapabilityAttachment = "tosca.capabilities.Attachment";
+ RequirementAssignment requirement = new RequirementAssignment();
+ 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("Volume attachment with id '" + translateTo.getResourceId()
+ + "' is pointing to unsupported resource type(" + volServerResource.getType()
+ + ") through the property 'volume_id'."
+ + " The connection to the volume is ignored. "
+ + "Supported types are: "
+ + 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()) {
+ String volumeResourceIdParamName = (String) volResourceId.getEntityId();
+ if (translateTo.getContext().getHeatSharedResourcesByParam()
+ .containsKey(volumeResourceIdParamName) && !isHeatFileNested(translateTo, heatFileName)) {
+ Resource volServerResource =
+ translateTo.getContext().getHeatSharedResourcesByParam().get(volumeResourceIdParamName)
+ .getHeatResource();
+ if (!StringUtils.equals(HeatResourcesTypes.CINDER_VOLUME_RESOURCE_TYPE.getHeatResource(),
+ volServerResource.getType())) {
+ logger.warn("Volume attachment with id '" + translateTo.getResourceId()
+ + "' is pointing to unsupported resource type(" + volServerResource.getType()
+ + ") through the property 'volume_id'."
+ + " The connection to the volume is ignored. "
+ + "Supported types are: "
+ + HeatResourcesTypes.CINDER_VOLUME_RESOURCE_TYPE.getHeatResource());
+ return;
+ }
+ requirement.setNode(
+ translateTo.getContext().getHeatSharedResourcesByParam().get(volumeResourceIdParamName)
+ .getTranslatedId());
+ requirement.setRelationship(relationshipTemplateId);
+ DataModelUtil
+ .addRelationshipTemplate(translateTo.getServiceTemplate(), relationshipTemplateId,
+ 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("Volume attachment with id '" + translateTo.getResourceId()
+ + "' is pointing to unsupported resource type(" + novaServerResource.getType()
+ + ") through the property 'instance_uuid'."
+ + " The connection to the nova server is ignored. "
+ + "Supported types are: " + HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE
+ .getHeatResource());
+ return;
+ }
+ 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, "local_storage", requirement);
+ }
+ }
+
+ 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);
+ if (fileDataContainingResource.isPresent()) {
+ addRelationshipToServiceTemplate(translateTo, relationTemplate, relationshipTemplateId,
+ requirement, fileDataContainingResource.get());
+ }
+ }
+ }
+
+ 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();
+ relationTemplate.getProperties().put("volume_id", 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/ResourceTranslationCinderVolumeImpl.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationCinderVolumeImpl.java
new file mode 100644
index 0000000000..c1e5fe3900
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationCinderVolumeImpl.java
@@ -0,0 +1,77 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca.impl;
+
+import org.openecomp.sdc.heat.datatypes.HeatBoolean;
+import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
+import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate;
+import org.openecomp.sdc.tosca.services.DataModelUtil;
+import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo;
+import org.openecomp.sdc.translator.services.heattotosca.mapping.TranslatorHeatToToscaPropertyConverter;
+
+import java.util.Map;
+import java.util.Optional;
+
+public class ResourceTranslationCinderVolumeImpl extends ResourceTranslationBase {
+
+ @Override
+ public void translate(TranslateTo translateTo) {
+ NodeTemplate nodeTemplate = new NodeTemplate();
+ nodeTemplate.setType(ToscaNodeType.CINDER_VOLUME.getDisplayName());
+
+ nodeTemplate.setProperties(TranslatorHeatToToscaPropertyConverter
+ .getToscaPropertiesSimpleConversion(translateTo.getResource().getProperties(),
+ nodeTemplate.getProperties(), translateTo.getHeatFileName(),
+ translateTo.getHeatOrchestrationTemplate(), translateTo.getResource().getType(),
+ nodeTemplate, translateTo.getContext()));
+ handleSizeProperty(nodeTemplate.getProperties());
+ Object readOnly = nodeTemplate.getProperties().get("read_only");
+ if (readOnly != null && !(readOnly instanceof Map)) {
+ nodeTemplate.getProperties().put("read_only", HeatBoolean.eval(readOnly));
+ }
+ Optional<String> resourceTranslatedId = getResourceTranslatedId(translateTo.getHeatFileName(),
+ translateTo.getHeatOrchestrationTemplate(), translateTo.getResourceId(),
+ translateTo.getContext());
+ if (resourceTranslatedId.isPresent()) {
+ DataModelUtil.addNodeTemplate(translateTo.getServiceTemplate(), resourceTranslatedId.get(),
+ nodeTemplate);
+ }
+ }
+
+ private void handleSizeProperty(Map<String, Object> nodeTemplateProperties) {
+ Object size = nodeTemplateProperties.get("size");
+ if (size == null) {
+ return;
+ }
+
+ if (size instanceof Map) {
+ Map<String, Object> propMap = (Map) size;
+ if (propMap.entrySet().iterator().hasNext()) {
+ Map.Entry entry = propMap.entrySet().iterator().next();
+ String val = "(" + entry.getKey() + " : " + entry.getValue() + ") * 1024";
+ nodeTemplateProperties.put("size", val);
+ return;
+ }
+ } else {
+ nodeTemplateProperties.put("size", 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/ResourceTranslationContrailAttachPolicyImpl.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationContrailAttachPolicyImpl.java
new file mode 100644
index 0000000000..307e407119
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationContrailAttachPolicyImpl.java
@@ -0,0 +1,141 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca.impl;
+
+import org.openecomp.sdc.common.errors.CoreException;
+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.model.NodeTemplate;
+import org.openecomp.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;
+import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo;
+import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil;
+import org.openecomp.sdc.translator.services.heattotosca.ResourceTranslationFactory;
+import org.openecomp.sdc.translator.services.heattotosca.errors.MissingMandatoryPropertyErrorBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Optional;
+
+public class ResourceTranslationContrailAttachPolicyImpl extends ResourceTranslationBase {
+ protected static Logger logger =
+ LoggerFactory.getLogger(ResourceTranslationContrailAttachPolicyImpl.class);
+
+ @Override
+ protected void translate(TranslateTo translateTo) {
+ String heatFileName = translateTo.getHeatFileName();
+ String translatedNetworkResourceId = getTranslatedNetworkResourceId(translateTo);
+ if (translatedNetworkResourceId == null) {
+ return;
+ }
+
+ NodeTemplate policyNodeTemplate = getTranslatedPolicyNodeTemplate(translateTo, heatFileName);
+ if (policyNodeTemplate != null) {
+ DataModelUtil
+ .addRequirementAssignment(policyNodeTemplate, ToscaConstants.NETWORK_REQUIREMENT_ID,
+ createRequirementAssignment(translatedNetworkResourceId));
+ }
+ }
+
+ private NodeTemplate getTranslatedPolicyNodeTemplate(TranslateTo translateTo,
+ String heatFileName) {
+ Optional<AttachedResourceId> attachedPolicyResourceId =
+ extractAttachedResourceIdHandleMissing(translateTo, "policy");
+ NodeTemplate policyNodeTemplate = new NodeTemplate();
+ Optional<String> policyResourceId =
+ HeatToToscaUtil.getContrailAttachedHeatResourceId(attachedPolicyResourceId.get());
+ if (policyResourceId.isPresent()) {
+ policyNodeTemplate = getPolicyNodeTemplate(translateTo, heatFileName, policyResourceId.get());
+ } else {
+ logger.warn("Heat resource: '" + translateTo.getResourceId() + "' with type: '"
+ + translateTo.getResource().getType()
+ + "' include 'policy' property without 'get_attr' of 'fq_name'/'get_resource'"
+ + " function, therefore this resource will be ignored in TOSCA translation.");
+ }
+ return policyNodeTemplate;
+ }
+
+ private NodeTemplate getPolicyNodeTemplate(TranslateTo translateTo, String heatFileName,
+ String policyResourceId) {
+ Resource policyResource = HeatToToscaUtil
+ .getResource(translateTo.getHeatOrchestrationTemplate(), policyResourceId, heatFileName);
+ Optional<String> translatedPolicyResourceId =
+ ResourceTranslationFactory.getInstance(policyResource)
+ .translateResource(heatFileName, translateTo.getServiceTemplate(),
+ translateTo.getHeatOrchestrationTemplate(), policyResource, policyResourceId,
+ translateTo.getContext());
+ if (!translatedPolicyResourceId.isPresent()) {
+ logger.warn("Heat resource: '" + translateTo.getResourceId() + "' with type: '"
+ + translateTo.getResource().getType()
+ + "' include unsupported policy resource, therefore this "
+ + "resource will be ignored in TOSCA translation. ");
+ return null;
+ }
+ return DataModelUtil
+ .getNodeTemplate(translateTo.getServiceTemplate(),
+ translatedPolicyResourceId.get());
+ }
+
+ private String getTranslatedNetworkResourceId(TranslateTo translateTo) {
+ Optional<AttachedResourceId> attachedNetworkResourceId =
+ extractAttachedResourceIdHandleMissing(translateTo, "network");
+
+ String translatedNetworkResourceId = null;
+ if (attachedNetworkResourceId.get().isGetResource()) {
+ translatedNetworkResourceId = (String) attachedNetworkResourceId.get().getTranslatedId();
+ } else {
+ logger.warn("Heat resource: '" + translateTo.getResourceId() + "' with type: '"
+ + translateTo.getResource().getType()
+ + "' include 'network' property without 'get_resource' function, "
+ + "therefore this resource will be ignored in TOSCA translation.");
+ }
+ return translatedNetworkResourceId;
+ }
+
+ private RequirementAssignment createRequirementAssignment(String translatedNetworkResourceId) {
+ RequirementAssignment requirement = new RequirementAssignment();
+ requirement.setCapability(ToscaCapabilityType.ATTACHMENT.getDisplayName());
+ requirement.setNode(translatedNetworkResourceId);
+ requirement.setRelationship(ToscaRelationshipType.ATTACHES_TO.getDisplayName());
+ return requirement;
+ }
+
+ private Optional<AttachedResourceId> extractAttachedResourceIdHandleMissing(
+ TranslateTo translateTo, String propertyName) {
+ Optional<AttachedResourceId> attachedResourceId =
+ HeatToToscaUtil.extractAttachedResourceId(translateTo, propertyName);
+
+ if (!attachedResourceId.isPresent()) {
+ throw new CoreException(new MissingMandatoryPropertyErrorBuilder(propertyName).build());
+ }
+ return attachedResourceId;
+ }
+
+
+ @Override
+ protected String generateTranslatedId(TranslateTo translateTo) {
+ return extractAttachedResourceIdHandleMissing(translateTo, "network").get().getEntityId()
+ .toString();
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationContrailNetworkPolicyImpl.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationContrailNetworkPolicyImpl.java
new file mode 100644
index 0000000000..8084433fd5
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationContrailNetworkPolicyImpl.java
@@ -0,0 +1,53 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca.impl;
+
+import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
+import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate;
+import org.openecomp.sdc.tosca.services.DataModelUtil;
+import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo;
+import org.openecomp.sdc.translator.services.heattotosca.mapping.TranslatorHeatToToscaPropertyConverter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ResourceTranslationContrailNetworkPolicyImpl extends ResourceTranslationBase {
+
+ protected static Logger logger =
+ LoggerFactory.getLogger(ResourceTranslationContrailNetworkPolicyImpl.class);
+
+ @Override
+ protected void translate(TranslateTo translateTo) {
+
+ NodeTemplate nodeTemplate = new NodeTemplate();
+ nodeTemplate.setType(ToscaNodeType.CONTRAIL_NETWORK_RULE.getDisplayName());
+
+ nodeTemplate.setProperties(TranslatorHeatToToscaPropertyConverter
+ .getToscaPropertiesSimpleConversion(translateTo.getResource().getProperties(),
+ nodeTemplate.getProperties(), translateTo.getHeatFileName(),
+ translateTo.getHeatOrchestrationTemplate(), translateTo.getResource().getType(),
+ nodeTemplate, translateTo.getContext()));
+
+ DataModelUtil.addNodeTemplate(translateTo.getServiceTemplate(), translateTo.getTranslatedId(),
+ nodeTemplate);
+
+
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationContrailServiceInstanceImpl.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationContrailServiceInstanceImpl.java
new file mode 100644
index 0000000000..b2475f28a9
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationContrailServiceInstanceImpl.java
@@ -0,0 +1,663 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca.impl;
+
+import org.openecomp.sdc.common.errors.CoreException;
+import org.openecomp.sdc.heat.datatypes.HeatBoolean;
+import org.openecomp.sdc.heat.datatypes.model.HeatResourcesTypes;
+import org.openecomp.sdc.heat.datatypes.model.Resource;
+import org.openecomp.sdc.heat.services.HeatConstants;
+import org.openecomp.sdc.tosca.datatypes.ToscaCapabilityType;
+import org.openecomp.sdc.tosca.datatypes.ToscaFunctions;
+import org.openecomp.sdc.tosca.datatypes.ToscaGroupType;
+import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
+import org.openecomp.sdc.tosca.datatypes.ToscaRelationshipType;
+import org.openecomp.sdc.tosca.datatypes.model.AttributeDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.GroupDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.Metadata;
+import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate;
+import org.openecomp.sdc.tosca.datatypes.model.NodeType;
+import org.openecomp.sdc.tosca.datatypes.model.ParameterDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.PropertyDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.RequirementAssignment;
+import org.openecomp.sdc.tosca.datatypes.model.RequirementDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate;
+import org.openecomp.sdc.tosca.datatypes.model.SubstitutionMapping;
+import org.openecomp.sdc.tosca.datatypes.model.TopologyTemplate;
+import org.openecomp.sdc.tosca.services.DataModelUtil;
+import org.openecomp.sdc.tosca.services.ToscaConstants;
+import org.openecomp.sdc.tosca.services.ToscaUtil;
+import org.openecomp.sdc.tosca.services.impl.ToscaFileOutputServiceCsarImpl;
+import org.openecomp.sdc.translator.datatypes.heattotosca.AttachedResourceId;
+import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo;
+import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslatedHeatResource;
+import org.openecomp.sdc.translator.services.heattotosca.Constants;
+import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil;
+import org.openecomp.sdc.translator.services.heattotosca.ResourceTranslationFactory;
+import org.openecomp.sdc.translator.services.heattotosca.errors.MissingMandatoryPropertyErrorBuilder;
+import org.openecomp.sdc.translator.services.heattotosca.globaltypes.ContrailAbstractSubstituteGlobalType;
+import org.openecomp.sdc.translator.services.heattotosca.globaltypes.ContrailComputeGlobalType;
+import org.openecomp.sdc.translator.services.heattotosca.globaltypes.GlobalTypesGenerator;
+import org.openecomp.sdc.translator.services.heattotosca.globaltypes.GlobalTypesUtil;
+import org.openecomp.sdc.translator.services.heattotosca.helper.ContrailTranslationHelper;
+import org.openecomp.sdc.translator.services.heattotosca.mapping.TranslatorHeatToToscaFunctionConverter;
+import org.openecomp.sdc.translator.services.heattotosca.mapping.TranslatorHeatToToscaPropertyConverter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+
+public class ResourceTranslationContrailServiceInstanceImpl extends ResourceTranslationBase {
+ protected static Logger logger =
+ LoggerFactory.getLogger(ResourceTranslationContrailServiceInstanceImpl.class);
+
+ @Override
+ public void translate(TranslateTo translateTo) {
+ Resource serviceInstanceResource = translateTo.getResource();
+ AttachedResourceId contrailServiceTemplateAttached =
+ getServiceTemplateAttachedId(translateTo, serviceInstanceResource);
+ if (contrailServiceTemplateAttached.isGetResource()) {
+ String contrailServiceTemplateResourceId =
+ (String) contrailServiceTemplateAttached.getEntityId();
+ Resource contrailServiceTemplateResource = HeatToToscaUtil
+ .getResource(translateTo.getHeatOrchestrationTemplate(),
+ contrailServiceTemplateResourceId, translateTo.getHeatFileName());
+ if (!contrailServiceTemplateResource.getType()
+ .equals(HeatResourcesTypes.CONTRAIL_SERVICE_TEMPLATE.getHeatResource())) {
+ logger.warn("resource id '" + translateTo.getResourceId() + "' with type '"
+ + translateTo.getResource().getType()
+ + "+ has reference to resource '" + contrailServiceTemplateResourceId + "' with type "
+ + "'"
+ + contrailServiceTemplateResource.getType()
+ + "' in property service_template. Invalid type, resource type should be type of '"
+ + HeatResourcesTypes.CONTRAIL_SERVICE_TEMPLATE.getHeatResource()
+ + "', therefore this resource will be ignored in TOSCA translation.");
+ return;
+ }
+ Optional<String> contrailServiceTemplateTranslatedId =
+ ResourceTranslationFactory.getInstance(contrailServiceTemplateResource)
+ .translateResource(translateTo.getHeatFileName(), translateTo.getServiceTemplate(),
+ translateTo.getHeatOrchestrationTemplate(), contrailServiceTemplateResource,
+ contrailServiceTemplateResourceId, translateTo.getContext());
+ if (!contrailServiceTemplateTranslatedId.isPresent()) {
+ logger.warn("Resource id '" + translateTo.getResourceId() + "' with type '"
+ + translateTo.getResource().getType()
+ + "' has reference to unsupported resource '" + contrailServiceTemplateResourceId
+ + "' with type '" + contrailServiceTemplateResource.getType()
+ + "' in property 'service_template'"
+ + ", therefore this resource will be ignored in TOSCA translation.");
+ return;
+ }
+
+ ServiceTemplate globalSubstitutionServiceTemplate =
+ translateTo.getContext().getTranslatedServiceTemplates()
+ .get(Constants.GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME);
+ String contrailStId = ResourceTranslationContrailServiceTemplateImpl
+ .getContrailSubstitutedNodeTypeId(contrailServiceTemplateTranslatedId.get());
+ NodeType substitutedNodeType =
+ DataModelUtil.getNodeType(globalSubstitutionServiceTemplate, contrailStId);
+
+ int numberOfPorts = getServiceInstanceNumberOfPorts(serviceInstanceResource);
+ if (substitutedNodeType.getRequirements() != null
+ && substitutedNodeType.getRequirements().size() != numberOfPorts) {
+ logger.warn("More than one ServiceInstance pointing to the same ServiceTemplate '"
+ + contrailServiceTemplateResourceId + " ' with different number of interfaces."
+ + ", therefore this resource will be ignored in TOSCA translation.");
+ return;
+ }
+
+ addNetworkLinkRequirements(substitutedNodeType, numberOfPorts);
+ NodeTemplate substitutedNodeTemplate =
+ createSubstitutedNodeTemplate(translateTo, contrailServiceTemplateResource, contrailStId,
+ numberOfPorts);
+
+ String computeNodeTypeId = new ContrailTranslationHelper()
+ .getComputeNodeTypeId(contrailServiceTemplateTranslatedId.get(),
+ contrailServiceTemplateResource);
+ boolean orderedInterfaces = getOrderedInterfaces(contrailServiceTemplateResource);
+ ServiceTemplate nestedServiceTemplate =
+ createNestedServiceTemplate(translateTo, computeNodeTypeId, contrailStId,
+ substitutedNodeTemplate, orderedInterfaces);
+ addAbstractSubstitutionProperty(translateTo, substitutedNodeTemplate.getProperties(),
+ nestedServiceTemplate, contrailServiceTemplateResource);
+ translateTo.getContext().getTranslatedServiceTemplates()
+ .put(translateTo.getTranslatedId(), nestedServiceTemplate);
+
+ } else {
+ logger.warn("Heat resource: '" + translateTo.getResourceId() + "' with type: '"
+ + translateTo.getResource().getType()
+ + "' include 'service_template' property without 'get_resource' function, currently not "
+ + "supported, therefore this resource will be ignored in TOSCA translation.");
+ }
+
+ }
+
+ private void addAbstractSubstitutionProperty(TranslateTo translateTo,
+ Map<String, Object> substitutionProperties,
+ ServiceTemplate nestedServiceTemplate,
+ Resource contrailServiceTemplateResource) {
+ Map<String, Object> innerProps = new HashMap<>();
+ innerProps.put(ToscaConstants.SUBSTITUTE_SERVICE_TEMPLATE_PROPERTY_NAME,
+ ToscaUtil.getServiceTemplateFileName(nestedServiceTemplate));
+
+ Object countValue = handleScaleOutProperty(translateTo, innerProps);
+ handleServiceScalingProperty(translateTo, innerProps, contrailServiceTemplateResource);
+
+ boolean mandatory = false;
+ if (countValue instanceof Integer && (Integer) countValue > 0) {
+ mandatory = true;
+ }
+ if (countValue == null) {
+ mandatory = true;
+ }
+ innerProps.put("mandatory", mandatory);
+ substitutionProperties.put(ToscaConstants.SERVICE_TEMPLATE_FILTER_PROPERTY_NAME, innerProps);
+ }
+
+ private Object handleScaleOutProperty(TranslateTo translateTo, Map<String, Object> innerProps) {
+ Object scaleOutPropertyValue =
+ translateTo.getResource().getProperties().get(HeatConstants.SCALE_OUT_PROPERTY_NAME);
+ Object countValue = null;
+ if (scaleOutPropertyValue != null && scaleOutPropertyValue instanceof Map) {
+ countValue = TranslatorHeatToToscaPropertyConverter
+ .getToscaPropertyValue(Constants.MAX_INSTANCES_PROPERTY_NAME,
+ ((Map) scaleOutPropertyValue).get(Constants.MAX_INSTANCES_PROPERTY_NAME), null,
+ translateTo.getHeatFileName(), translateTo.getHeatOrchestrationTemplate(), null,
+ translateTo.getContext());
+ if (countValue != null) {
+ innerProps.put(ToscaConstants.COUNT_PROPERTY_NAME, countValue);
+ } else {
+ innerProps.put(ToscaConstants.COUNT_PROPERTY_NAME, 1);
+ }
+ } else {
+ innerProps.put(ToscaConstants.COUNT_PROPERTY_NAME, 1);
+ }
+ return countValue;
+ }
+
+ private void handleServiceScalingProperty(TranslateTo translateTo, Map<String, Object> innerProps,
+ Resource contrailServiceTemplateResource) {
+ Object serviceScalingPropertyValue = contrailServiceTemplateResource.getProperties()
+ .get(HeatConstants.SERVICE_SCALING_PROPERTY_NAME);
+ Object serviceScalingValue = null;
+ if (serviceScalingPropertyValue != null) {
+ serviceScalingValue = TranslatorHeatToToscaPropertyConverter
+ .getToscaPropertyValue(HeatConstants.SERVICE_SCALING_PROPERTY_NAME,
+ serviceScalingPropertyValue, null, translateTo.getHeatFileName(),
+ translateTo.getHeatOrchestrationTemplate(), null, translateTo.getContext());
+ if (serviceScalingValue != null) {
+ innerProps.put(ToscaConstants.SCALING_ENABLED_PROPERTY_NAME,
+ (HeatBoolean.isValueBoolean(serviceScalingValue)) ? HeatBoolean
+ .eval(serviceScalingValue) : serviceScalingValue);
+ }
+ }
+ }
+
+ private boolean getOrderedInterfaces(Resource contrailServiceTemplate) {
+ Object orderedInterfaces = contrailServiceTemplate.getProperties().get("ordered_interfaces");
+ if (orderedInterfaces == null) {
+ return false;
+ }
+ if (orderedInterfaces instanceof String) {
+ return HeatBoolean.eval(orderedInterfaces);
+ }
+ //if get_param, set default value to true
+ return true;
+ }
+
+ private ServiceTemplate createNestedServiceTemplate(TranslateTo translateTo,
+ String computeNodeTypeId,
+ String substitutedNodeTypeId,
+ NodeTemplate substitutedNodeTemplate,
+ boolean orderedInterfaces) {
+ ServiceTemplate nestedSubstitutionServiceTemplate = new ServiceTemplate();
+ setNestedServiceTemplateGeneralDetails(translateTo, nestedSubstitutionServiceTemplate);
+ String heatStackGroupKey = addHeatStackGroup(translateTo, nestedSubstitutionServiceTemplate);
+ addSubstitutionMappingEntry(nestedSubstitutionServiceTemplate, substitutedNodeTypeId);
+
+ handleInputParameters(nestedSubstitutionServiceTemplate);
+ String computeNodeTemplateId =
+ handleComputeNodeTemplate(translateTo, computeNodeTypeId, nestedSubstitutionServiceTemplate,
+ heatStackGroupKey);
+ handleOutputParameters(nestedSubstitutionServiceTemplate, computeNodeTemplateId);
+ handleServiceInstanceInterfaces(translateTo, nestedSubstitutionServiceTemplate,
+ substitutedNodeTemplate, heatStackGroupKey, orderedInterfaces, computeNodeTemplateId);
+
+ return nestedSubstitutionServiceTemplate;
+ }
+
+ private void handleOutputParameters(ServiceTemplate nestedSubstitutionServiceTemplate,
+ String nodeTemplateId) {
+ if (nodeTemplateId == null) {
+ return;
+ }
+ NodeType contrailAbstractNodeType =
+ ContrailAbstractSubstituteGlobalType.createServiceTemplate().getNode_types()
+ .get(ToscaNodeType.CONTRAIL_ABSTRACT_SUBSTITUTE.getDisplayName());
+ Map<String, AttributeDefinition> contrailAbstractAttributes =
+ contrailAbstractNodeType.getAttributes();
+ Map<String, ParameterDefinition> nestedSubstitutionServiceTemplateOutputs = new HashMap<>();
+
+ if (contrailAbstractAttributes == null) {
+ return;
+ }
+
+ for (String attributeKey : contrailAbstractAttributes.keySet()) {
+ AttributeDefinition abstractAttributeDef = contrailAbstractAttributes.get(attributeKey);
+ if (abstractAttributeDef != null) {
+ Map<String, List> outputValue = new HashMap<>();
+ List outputGetAttributeList = new ArrayList<>();
+ outputGetAttributeList.add(nodeTemplateId);
+ outputGetAttributeList.add(attributeKey);
+ outputValue.put(ToscaFunctions.GET_ATTRIBUTE.getDisplayName(), outputGetAttributeList);
+ nestedSubstitutionServiceTemplateOutputs.put(attributeKey,
+ DataModelUtil.convertAttributeDefToParameterDef(abstractAttributeDef, outputValue));
+ }
+ }
+ if (!nestedSubstitutionServiceTemplateOutputs.isEmpty()) {
+ nestedSubstitutionServiceTemplate.getTopology_template()
+ .setOutputs(nestedSubstitutionServiceTemplateOutputs);
+ }
+ }
+
+ private void handleServiceInstanceInterfaces(TranslateTo translateTo,
+ ServiceTemplate nestedSubstitutionServiceTemplate,
+ NodeTemplate substitutedNodeTemplate,
+ String heatStackGroupKey, boolean orderedInterfaces,
+ String computeNodeTemplateId) {
+ Resource serviceInstanceResource = translateTo.getResource();
+ Object interfaceListProperty = serviceInstanceResource.getProperties().get("interface_list");
+ if (interfaceListProperty == null) {
+ return;
+ }
+ if (interfaceListProperty instanceof List) {
+ for (int index = 0; index < ((List) interfaceListProperty).size(); index++) {
+ Object interfaceEntry = ((List) interfaceListProperty).get(index);
+ handleInterface(translateTo, interfaceEntry, index, nestedSubstitutionServiceTemplate,
+ heatStackGroupKey, substitutedNodeTemplate, orderedInterfaces, computeNodeTemplateId);
+ }
+ } else if (interfaceListProperty instanceof Map) {
+ handleInterface(translateTo, interfaceListProperty, null, nestedSubstitutionServiceTemplate,
+ heatStackGroupKey, substitutedNodeTemplate, orderedInterfaces, computeNodeTemplateId);
+ }
+ }
+
+ private void handleInterface(TranslateTo translateTo, Object interfacePropertyValue,
+ Integer index,
+ ServiceTemplate nestedSubstitutionServiceTemplate,
+ String heatStackGroupKey, NodeTemplate substitutedNodeTemplate,
+ boolean orderedInterfaces, String computeNodeTemplateId) {
+ if (index == null) {
+ index = new Integer(0);
+ }
+ NodeTemplate portNodeTemplate =
+ createPortNodeTemplate(index, orderedInterfaces, computeNodeTemplateId);
+ String portNodeTemplateId = "port_" + index;
+ String portReqMappingKey = "link_" + portNodeTemplateId;
+
+ DataModelUtil
+ .addNodeTemplate(nestedSubstitutionServiceTemplate, portNodeTemplateId, portNodeTemplate);
+ updateSubstitutionMappingRequirement(nestedSubstitutionServiceTemplate, portReqMappingKey,
+ portNodeTemplateId);
+ updateHeatStackGroup(nestedSubstitutionServiceTemplate, heatStackGroupKey, portNodeTemplateId);
+ connectPortToNetwork(translateTo, interfacePropertyValue, substitutedNodeTemplate,
+ portReqMappingKey);
+ }
+
+ private void connectPortToNetwork(TranslateTo translateTo, Object interfacePropertyValue,
+ NodeTemplate substitutedNodeTemplate,
+ String portReqMappingKey) {
+ List<String> validNetworksForConnections = Arrays
+ .asList(HeatResourcesTypes.NEUTRON_NET_RESOURCE_TYPE.getHeatResource(),
+ HeatResourcesTypes.CONTRAIL_VIRTUAL_NETWORK_RESOURCE_TYPE.getHeatResource());
+
+ if (interfacePropertyValue instanceof Map) {
+ Object virtualNetworkValue = ((Map) interfacePropertyValue).get("virtual_network");
+ if (virtualNetworkValue != null) {
+ Optional<AttachedResourceId> networkAttachedResourceId = HeatToToscaUtil
+ .extractAttachedResourceId(translateTo.getHeatFileName(),
+ translateTo.getHeatOrchestrationTemplate(), translateTo.getContext(),
+ virtualNetworkValue);
+ if (networkAttachedResourceId.isPresent()) {
+ Optional<String> networkResourceId =
+ HeatToToscaUtil.getContrailAttachedHeatResourceId(networkAttachedResourceId.get());
+ if (networkResourceId.isPresent()) {
+ Resource networkResource = HeatToToscaUtil
+ .getResource(translateTo.getHeatOrchestrationTemplate(), networkResourceId.get(),
+ translateTo.getHeatFileName());
+ if (validNetworksForConnections.contains(networkResource.getType())) {
+ Optional<String> networkTranslatedId =
+ getResourceTranslatedId(translateTo.getHeatFileName(),
+ translateTo.getHeatOrchestrationTemplate(), networkResourceId.get(),
+ translateTo.getContext());
+ if (networkTranslatedId.isPresent()) {
+ addLinkToNetworkRequirementAssignment(substitutedNodeTemplate,
+ networkTranslatedId.get(), portReqMappingKey);
+ }
+ } else {
+ logger.warn("Heat resource " + translateTo.getResourceId() + " with type "
+ + translateTo.getResource().getType()
+ + " has connection to invalid/not supported network resource, therefore, this "
+ + "connection will be ignored in the translation.");
+ }
+ } else if (networkAttachedResourceId.get().isGetParam()) {
+ TranslatedHeatResource translatedSharedResourceId =
+ translateTo.getContext().getHeatSharedResourcesByParam()
+ .get(networkAttachedResourceId.get().getEntityId());
+ if (Objects.nonNull(translatedSharedResourceId)
+ && !HeatToToscaUtil.isHeatFileNested(translateTo, translateTo.getHeatFileName())) {
+ addLinkToNetworkRequirementAssignment(substitutedNodeTemplate,
+ translatedSharedResourceId.getTranslatedId(), portReqMappingKey);
+ }
+ } else {
+ logger.warn("Heat resource: '" + translateTo.getResourceId() + "' with type: '"
+ + translateTo.getResource().getType()
+ + "' include 'virtual_network' property with value '"
+ + virtualNetworkValue.toString()
+ + "', the connection to this network wasn't found/not supported therefore this "
+ + "connection will be ignored in TOSCA translation for this property.");
+ }
+ }
+ } else {
+ logger.warn("Heat resource: '" + translateTo.getResourceId() + "' with type: '"
+ + translateTo.getResource().getType()
+ + "' missing 'virtual_network' property in 'interface_list' entry, therefore, no "
+ + "network connection is define for this entry.");
+ }
+ }
+ }
+
+ private NodeTemplate createPortNodeTemplate(Integer index, boolean orderedInterfaces,
+ String computeNodeTemplateId) {
+ NodeTemplate portNodeTemplate = new NodeTemplate();
+ portNodeTemplate.setType(ToscaNodeType.CONTRAIL_PORT.getDisplayName());
+ Map<String, Object> portProperties = new HashMap<>();
+ portProperties.put("static_routes", DataModelUtil
+ .createGetInputPropertyValueFromListParameter("interface_list", index, "static_routes"));
+ portProperties.put("virtual_network", DataModelUtil
+ .createGetInputPropertyValueFromListParameter("interface_list", index, "virtual_network"));
+ portProperties.put("allowed_address_pairs", DataModelUtil
+ .createGetInputPropertyValueFromListParameter("interface_list", index,
+ "allowed_address_pairs"));
+ portProperties.put("ip_address", DataModelUtil
+ .createGetInputPropertyValueFromListParameter("interface_list", index, "ip_address"));
+ portProperties.put("static_route",
+ DataModelUtil.createGetInputPropertyValueFromListParameter("static_routes_list", index));
+ portProperties.put("shared_ip",
+ DataModelUtil.createGetInputPropertyValueFromListParameter("shared_ip_list", index));
+ portProperties.put("interface_type", DataModelUtil
+ .createGetInputPropertyValueFromListParameter("service_interface_type_list", index));
+ if (orderedInterfaces) {
+ portProperties.put("order", index);
+ }
+ portNodeTemplate.setProperties(portProperties);
+ addBindingReqFromPortToCompute(computeNodeTemplateId, portNodeTemplate);
+ return portNodeTemplate;
+ }
+
+
+ private void addLinkToNetworkRequirementAssignment(NodeTemplate nodeTemplate,
+ String connectedNodeTranslatedId,
+ String requirementId) {
+ if (nodeTemplate == null || connectedNodeTranslatedId == null) {
+ return;
+ }
+
+ RequirementAssignment requirement = new RequirementAssignment();
+ requirement.setCapability(ToscaCapabilityType.NETWORK_LINKABLE.getDisplayName());
+ requirement.setRelationship(ToscaRelationshipType.NETWORK_LINK_TO.getDisplayName());
+ requirement.setNode(connectedNodeTranslatedId);
+ DataModelUtil.addRequirementAssignment(nodeTemplate, requirementId, requirement);
+ }
+
+ private void updateHeatStackGroup(ServiceTemplate serviceTemplate, String heatStackGroupKey,
+ String memberId) {
+ serviceTemplate.getTopology_template().getGroups().get(heatStackGroupKey).getMembers()
+ .add(memberId);
+ }
+
+ private void updateSubstitutionMappingRequirement(ServiceTemplate serviceTemplate,
+ String portReqMappingKey,
+ String portNodeTemplateId) {
+ List<String> portReqMappingValue = new ArrayList<>();
+ portReqMappingValue.add(portNodeTemplateId);
+ portReqMappingValue.add(ToscaConstants.LINK_REQUIREMENT_ID);
+ DataModelUtil
+ .addSubstitutionMappingReq(serviceTemplate, portReqMappingKey, portReqMappingValue);
+ }
+
+ private void addSubstitutionMappingEntry(ServiceTemplate nestedSubstitutionServiceTemplate,
+ String substitutedNodeTypeId) {
+ SubstitutionMapping substitutionMappings = new SubstitutionMapping();
+ substitutionMappings.setNode_type(substitutedNodeTypeId);
+ DataModelUtil.addSubstitutionMapping(nestedSubstitutionServiceTemplate, substitutionMappings);
+ }
+
+ private void handleInputParameters(ServiceTemplate nestedSubstitutionServiceTemplate) {
+ NodeType contrailAbstractNodeType =
+ ContrailAbstractSubstituteGlobalType.createServiceTemplate().getNode_types()
+ .get(ToscaNodeType.CONTRAIL_ABSTRACT_SUBSTITUTE.getDisplayName());
+ Map<String, PropertyDefinition> contrailAbstractProperties =
+ contrailAbstractNodeType.getProperties();
+ Map<String, ParameterDefinition> nestedSubstitutionServiceTemplateInputs = new HashMap<>();
+
+ for (String propertyKey : contrailAbstractProperties.keySet()) {
+ PropertyDefinition abstractPropertyDef = contrailAbstractProperties.get(propertyKey);
+ if (abstractPropertyDef != null) {
+ nestedSubstitutionServiceTemplateInputs
+ .put(propertyKey, DataModelUtil.convertPropertyDefToParameterDef(abstractPropertyDef));
+
+ }
+ }
+ if (!nestedSubstitutionServiceTemplateInputs.isEmpty()) {
+ nestedSubstitutionServiceTemplate.getTopology_template()
+ .setInputs(nestedSubstitutionServiceTemplateInputs);
+ }
+ }
+
+ private String handleComputeNodeTemplate(TranslateTo translateTo, String computeNodeTypeId,
+ ServiceTemplate nestedSubstitutionServiceTemplate,
+ String heatStackGroupKey) {
+ NodeType contrailComputeNodeType =
+ ContrailComputeGlobalType.createServiceTemplate().getNode_types()
+ .get(ToscaNodeType.CONTRAIL_COMPUTE.getDisplayName());
+ Map<String, PropertyDefinition> contrailComputeProperties =
+ contrailComputeNodeType.getProperties();
+ Map<String, Object> computeNodeTemplateProperties = new HashMap<>();
+
+ if (contrailComputeProperties != null) {
+ for (String computePropertyKey : contrailComputeProperties.keySet()) {
+ Map getInputProperty = new HashMap<>();
+ getInputProperty.put(ToscaFunctions.GET_INPUT.getDisplayName(), computePropertyKey);
+ computeNodeTemplateProperties.put(computePropertyKey, getInputProperty);
+ }
+ }
+
+ NodeTemplate computeNodeTemplate = new NodeTemplate();
+ computeNodeTemplate.setType(computeNodeTypeId);
+ if (!computeNodeTemplateProperties.isEmpty()) {
+ computeNodeTemplate.setProperties(computeNodeTemplateProperties);
+ }
+ String computeNodeTemplateId = translateTo.getTranslatedId();
+ DataModelUtil.addNodeTemplate(nestedSubstitutionServiceTemplate, computeNodeTemplateId,
+ computeNodeTemplate);
+ nestedSubstitutionServiceTemplate.getTopology_template().getGroups().get(heatStackGroupKey)
+ .getMembers().add(computeNodeTemplateId);
+
+ return computeNodeTemplateId;
+ }
+
+ private String addHeatStackGroup(TranslateTo translateTo, ServiceTemplate serviceTemplate) {
+ GroupDefinition serviceInstanceGroupDefinition = new GroupDefinition();
+ serviceInstanceGroupDefinition.setType(ToscaGroupType.HEAT_STACK.getDisplayName());
+ Map<String, Object> groupProperties = new HashMap<>();
+ groupProperties.put("heat_file",
+ "../" + (new ToscaFileOutputServiceCsarImpl()).getArtifactsFolderName() + "/"
+ + translateTo.getHeatFileName());
+ serviceInstanceGroupDefinition.setProperties(groupProperties);
+ serviceInstanceGroupDefinition.setMembers(new ArrayList<>());
+ String heatStackGroupKey = translateTo.getTranslatedId();
+ DataModelUtil.addGroupDefinitionToTopologyTemplate(serviceTemplate, heatStackGroupKey,
+ serviceInstanceGroupDefinition);
+
+ return heatStackGroupKey;
+ }
+
+
+ private void setNestedServiceTemplateGeneralDetails(TranslateTo translateTo,
+ ServiceTemplate nestedSubstitutionServiceTemplate) {
+ Metadata nestedTemplateMetadata = new Metadata();
+ String nestedTemplateName = translateTo.getResourceId();
+ nestedTemplateMetadata.setTemplate_name(nestedTemplateName);
+ nestedSubstitutionServiceTemplate.setMetadata(nestedTemplateMetadata);
+ nestedSubstitutionServiceTemplate
+ .setTosca_definitions_version(ToscaConstants.TOSCA_DEFINITIONS_VERSION);
+ nestedSubstitutionServiceTemplate.setTopology_template(new TopologyTemplate());
+ nestedSubstitutionServiceTemplate.setImports(GlobalTypesGenerator.getGlobalTypesImportList());
+ nestedSubstitutionServiceTemplate.getImports()
+ .put(Constants.GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME, GlobalTypesUtil
+ .createServiceTemplateImport(Constants.GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME));
+ }
+
+ private NodeTemplate createSubstitutedNodeTemplate(TranslateTo translateTo,
+ Resource contrailServiceTemplateResource,
+ String contrailServiceTemplateTranslatedId,
+ int numberOfPorts) {
+
+ translateTo.getServiceTemplate().getImports()
+ .put(Constants.GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME, GlobalTypesUtil
+ .createServiceTemplateImport(Constants.GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME));
+ NodeTemplate substitutesNodeTemplate = new NodeTemplate();
+ substitutesNodeTemplate.setType(contrailServiceTemplateTranslatedId);
+ List<String> directiveList = new ArrayList<>();
+ directiveList.add(ToscaConstants.NODE_TEMPLATE_DIRECTIVE_SUBSTITUTABLE);
+ substitutesNodeTemplate.setDirectives(directiveList);
+ substitutesNodeTemplate.setProperties(TranslatorHeatToToscaPropertyConverter
+ .getToscaPropertiesSimpleConversion(translateTo.getResource().getProperties(),
+ substitutesNodeTemplate.getProperties(), translateTo.getHeatFileName(),
+ translateTo.getHeatOrchestrationTemplate(),
+ HeatResourcesTypes.CONTRAIL_SERVICE_INSTANCE.getHeatResource(), substitutesNodeTemplate,
+ translateTo.getContext()));
+ substitutesNodeTemplate.setProperties(TranslatorHeatToToscaPropertyConverter
+ .getToscaPropertiesSimpleConversion(contrailServiceTemplateResource.getProperties(),
+ substitutesNodeTemplate.getProperties(), translateTo.getHeatFileName(),
+ translateTo.getHeatOrchestrationTemplate(),
+ HeatResourcesTypes.CONTRAIL_SERVICE_TEMPLATE.getHeatResource(), substitutesNodeTemplate,
+ translateTo.getContext()));
+ HeatToToscaUtil.mapBoolean(substitutesNodeTemplate, "availability_zone_enable");
+ HeatToToscaUtil.mapBoolean(substitutesNodeTemplate, "ordered_interfaces");
+
+ Object sharedIpListPropertyValue =
+ contrailServiceTemplateResource.getProperties().get("shared_ip_list");
+ Optional<List<Map<String, List>>> sharedIpTranslatedSplitFun =
+ TranslatorHeatToToscaFunctionConverter
+ .translateFnSplitFunction(sharedIpListPropertyValue, numberOfPorts, true);
+ if (sharedIpTranslatedSplitFun.isPresent()) {
+ substitutesNodeTemplate.getProperties()
+ .put("shared_ip_list", sharedIpTranslatedSplitFun.get());
+ } else {
+ HeatToToscaUtil.mapBooleanList(substitutesNodeTemplate, "shared_ip_list");
+ }
+
+ Object staticRouteListPropertyValue =
+ contrailServiceTemplateResource.getProperties().get("static_routes_list");
+ Optional<List<Map<String, List>>> staticRouteTranslatedSplitFun =
+ TranslatorHeatToToscaFunctionConverter
+ .translateFnSplitFunction(staticRouteListPropertyValue, numberOfPorts, true);
+ if (staticRouteTranslatedSplitFun.isPresent()) {
+ substitutesNodeTemplate.getProperties()
+ .put("static_routes_list", staticRouteTranslatedSplitFun.get());
+ } else {
+ HeatToToscaUtil.mapBooleanList(substitutesNodeTemplate, "static_routes_list");
+ }
+
+ Object serviceInterfaceTypeListPropertyValue =
+ contrailServiceTemplateResource.getProperties().get("service_interface_type_list");
+ Optional<List<Map<String, List>>> serviceInterfaceTypeTranslatedSplitFun =
+ TranslatorHeatToToscaFunctionConverter
+ .translateFnSplitFunction(serviceInterfaceTypeListPropertyValue, numberOfPorts, false);
+ if (serviceInterfaceTypeTranslatedSplitFun.isPresent()) {
+ substitutesNodeTemplate.getProperties()
+ .put("service_interface_type_list", serviceInterfaceTypeTranslatedSplitFun.get());
+ }
+
+ String substitutedNodeTemplateId = translateTo.getTranslatedId();
+ DataModelUtil.addNodeTemplate(translateTo.getServiceTemplate(), substitutedNodeTemplateId,
+ substitutesNodeTemplate);
+ return substitutesNodeTemplate;
+ }
+
+ private void addNetworkLinkRequirements(NodeType nodeType, int numberOfPorts) {
+ if (nodeType.getRequirements() == null) {
+ List<Map<String, RequirementDefinition>> requirementList = new ArrayList<>();
+ for (int i = 0; i < numberOfPorts; i++) {
+ Map<String, RequirementDefinition> requirementDefinitionMap = new HashMap<>();
+ requirementDefinitionMap.put(ToscaConstants.LINK_REQUIREMENT_ID + "_port_" + i,
+ DataModelUtil.createRequirement(ToscaCapabilityType.NETWORK_LINKABLE.getDisplayName(),
+ ToscaNodeType.ROOT.getDisplayName(),
+ ToscaRelationshipType.NETWORK_LINK_TO.getDisplayName(), null));
+ requirementList.add(requirementDefinitionMap);
+ }
+ if (numberOfPorts > 0) {
+ nodeType.setRequirements(requirementList);
+ }
+ }
+ }
+
+ private int getServiceInstanceNumberOfPorts(Resource serviceInstanceResource) {
+ int numberOfPorts;
+ Object interfaceTypeProperty = serviceInstanceResource.getProperties().get("interface_list");
+ if (interfaceTypeProperty == null) {
+ numberOfPorts = 0;
+ } else if (interfaceTypeProperty instanceof List) {
+ numberOfPorts = ((List) interfaceTypeProperty).size();
+ } else if (interfaceTypeProperty instanceof Map) {
+ numberOfPorts = 1;
+ } else {
+ numberOfPorts = 0;
+ }
+
+ return numberOfPorts;
+ }
+
+ private AttachedResourceId getServiceTemplateAttachedId(TranslateTo translateTo,
+ Resource serviceInstanceResource) {
+ Object serviceTemplateProperty =
+ serviceInstanceResource.getProperties().get("service_template");
+ Optional<AttachedResourceId> serviceTemplateId = HeatToToscaUtil
+ .extractAttachedResourceId(translateTo.getHeatFileName(),
+ translateTo.getHeatOrchestrationTemplate(), translateTo.getContext(),
+ serviceTemplateProperty);
+ if (serviceTemplateId.isPresent()) {
+ return serviceTemplateId.get();
+ } else {
+ throw new CoreException(new MissingMandatoryPropertyErrorBuilder("service_template").build());
+ }
+ }
+
+
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationContrailServiceTemplateImpl.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationContrailServiceTemplateImpl.java
new file mode 100644
index 0000000000..e0a3ed422f
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationContrailServiceTemplateImpl.java
@@ -0,0 +1,100 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca.impl;
+
+import org.openecomp.sdc.common.errors.CoreException;
+import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
+import org.openecomp.sdc.tosca.datatypes.model.Metadata;
+import org.openecomp.sdc.tosca.datatypes.model.NodeType;
+import org.openecomp.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.to.TranslateTo;
+import org.openecomp.sdc.translator.services.heattotosca.Constants;
+import org.openecomp.sdc.translator.services.heattotosca.errors.MissingMandatoryPropertyErrorBuilder;
+import org.openecomp.sdc.translator.services.heattotosca.globaltypes.GlobalTypesGenerator;
+import org.openecomp.sdc.translator.services.heattotosca.helper.ContrailTranslationHelper;
+
+import java.util.Map;
+import java.util.Objects;
+
+public class ResourceTranslationContrailServiceTemplateImpl extends ResourceTranslationBase {
+
+ static String getContrailSubstitutedNodeTypeId(String serviceTemplateTranslatedId) {
+ return ToscaConstants.NODES_SUBSTITUTION_PREFIX + serviceTemplateTranslatedId;
+ }
+
+ @Override
+ protected boolean isEssentialRequirementsValid(TranslateTo translateTo) {
+ Map<String, Object> properties = translateTo.getResource().getProperties();
+ if (Objects.isNull(properties) || Objects.isNull(properties.get("image_name"))) {
+ throw new CoreException(new MissingMandatoryPropertyErrorBuilder("image_name").build());
+ }
+ return true;
+ }
+
+ @Override
+ public void translate(TranslateTo translateTo) {
+
+ ServiceTemplate globalSubstitutionServiceTemplate =
+ getGlobalSubstitutionTypesServiceTemplate(translateTo);
+ addSubstitutedNodeType(translateTo, globalSubstitutionServiceTemplate);
+ addComputeNodeType(translateTo, globalSubstitutionServiceTemplate);
+ }
+
+ private void addComputeNodeType(TranslateTo translateTo,
+ ServiceTemplate globalSubstitutionServiceTemplate) {
+ NodeType computeNodeType = new NodeType();
+ computeNodeType.setDerived_from(ToscaNodeType.CONTRAIL_COMPUTE.getDisplayName());
+ String computeNodeTypeId = new ContrailTranslationHelper()
+ .getComputeNodeTypeId(translateTo.getTranslatedId(), translateTo.getResource());
+ DataModelUtil
+ .addNodeType(globalSubstitutionServiceTemplate, computeNodeTypeId, computeNodeType);
+ }
+
+ private void addSubstitutedNodeType(TranslateTo translateTo,
+ ServiceTemplate globalSubstitutionServiceTemplate) {
+ NodeType substitutedNodeType = new NodeType();
+ substitutedNodeType
+ .setDerived_from(ToscaNodeType.CONTRAIL_ABSTRACT_SUBSTITUTE.getDisplayName());
+ DataModelUtil.addNodeType(globalSubstitutionServiceTemplate,
+ getContrailSubstitutedNodeTypeId(translateTo.getTranslatedId()), substitutedNodeType);
+ }
+
+ private ServiceTemplate getGlobalSubstitutionTypesServiceTemplate(TranslateTo translateTo) {
+ ServiceTemplate globalSubstitutionServiceTemplate =
+ translateTo.getContext().getTranslatedServiceTemplates()
+ .get(Constants.GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME);
+ if (globalSubstitutionServiceTemplate == null) {
+ globalSubstitutionServiceTemplate = new ServiceTemplate();
+ Metadata templateMetadata = new Metadata();
+ templateMetadata.setTemplate_name(Constants.GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME);
+ globalSubstitutionServiceTemplate.setMetadata(templateMetadata);
+ globalSubstitutionServiceTemplate.setImports(GlobalTypesGenerator.getGlobalTypesImportList());
+ globalSubstitutionServiceTemplate
+ .setTosca_definitions_version(ToscaConstants.TOSCA_DEFINITIONS_VERSION);
+ translateTo.getContext().getTranslatedServiceTemplates()
+ .put(Constants.GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME,
+ globalSubstitutionServiceTemplate);
+ }
+ return globalSubstitutionServiceTemplate;
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationContrailV2NetworkPolicyImpl.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationContrailV2NetworkPolicyImpl.java
new file mode 100644
index 0000000000..72a25985a8
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationContrailV2NetworkPolicyImpl.java
@@ -0,0 +1,49 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca.impl;
+
+import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
+import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate;
+import org.openecomp.sdc.tosca.services.DataModelUtil;
+import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo;
+import org.openecomp.sdc.translator.services.heattotosca.mapping.TranslatorHeatToToscaPropertyConverter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ResourceTranslationContrailV2NetworkPolicyImpl extends ResourceTranslationBase {
+
+ protected static Logger logger =
+ LoggerFactory.getLogger(ResourceTranslationContrailV2NetworkPolicyImpl.class);
+
+ @Override
+ protected void translate(TranslateTo translateTo) {
+
+ NodeTemplate nodeTemplate = new NodeTemplate();
+ nodeTemplate.setType(ToscaNodeType.CONTRAILV2_NETWORK_RULE.getDisplayName());
+ nodeTemplate.setProperties(TranslatorHeatToToscaPropertyConverter
+ .getToscaPropertiesSimpleConversion(translateTo.getResource().getProperties(),
+ nodeTemplate.getProperties(), translateTo.getHeatFileName(),
+ translateTo.getHeatOrchestrationTemplate(), translateTo.getResource().getType(),
+ nodeTemplate, translateTo.getContext()));
+ DataModelUtil.addNodeTemplate(translateTo.getServiceTemplate(), translateTo.getTranslatedId(),
+ nodeTemplate);
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationContrailV2VirtualNetworkImpl.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationContrailV2VirtualNetworkImpl.java
new file mode 100644
index 0000000000..d81f3196a3
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationContrailV2VirtualNetworkImpl.java
@@ -0,0 +1,209 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca.impl;
+
+import org.apache.commons.collections.CollectionUtils;
+import org.openecomp.sdc.heat.datatypes.model.HeatResourcesTypes;
+import org.openecomp.sdc.heat.datatypes.model.Resource;
+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.model.NodeTemplate;
+import org.openecomp.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;
+import org.openecomp.sdc.translator.datatypes.heattotosca.ResourceReferenceType;
+import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo;
+import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil;
+import org.openecomp.sdc.translator.services.heattotosca.ResourceTranslationFactory;
+import org.openecomp.sdc.translator.services.heattotosca.mapping.TranslatorHeatToToscaPropertyConverter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+public class ResourceTranslationContrailV2VirtualNetworkImpl extends ResourceTranslationBase {
+
+ protected static Logger logger =
+ LoggerFactory.getLogger(ResourceTranslationContrailV2VirtualNetworkImpl.class);
+
+ @Override
+ public void translate(TranslateTo translateTo) {
+
+ NodeTemplate nodeTemplate = new NodeTemplate();
+ nodeTemplate.setType(ToscaNodeType.CONTRAILV2_VIRTUAL_NETWORK.getDisplayName());
+ nodeTemplate.setProperties(TranslatorHeatToToscaPropertyConverter
+ .getToscaPropertiesSimpleConversion(translateTo.getResource().getProperties(),
+ nodeTemplate.getProperties(), translateTo.getHeatFileName(),
+ translateTo.getHeatOrchestrationTemplate(), translateTo.getResource().getType(),
+ nodeTemplate, translateTo.getContext()));
+ Optional<String> resourceTranslatedId = getResourceTranslatedId(translateTo.getHeatFileName(),
+ translateTo.getHeatOrchestrationTemplate(), translateTo.getResourceId(),
+ translateTo.getContext());
+ if (resourceTranslatedId.isPresent()) {
+ DataModelUtil.addNodeTemplate(translateTo.getServiceTemplate(), resourceTranslatedId.get(),
+ nodeTemplate);
+ }
+ linkToPolicyNodeTemplate(translateTo);
+ }
+
+ private void linkToPolicyNodeTemplate(TranslateTo translateTo) {
+ List<AttachedResourceId> networkPolicyIdList = extractNetworkPolicyIdList(translateTo);
+ if (CollectionUtils.isEmpty(networkPolicyIdList)) {
+ return;
+ }
+ for (AttachedResourceId attachedResourceId : networkPolicyIdList) {
+ NodeTemplate policyNodeTemplate = DataModelUtil
+ .getNodeTemplate(translateTo.getServiceTemplate(),
+ (String) attachedResourceId.getTranslatedId());
+ DataModelUtil
+ .addRequirementAssignment(policyNodeTemplate, ToscaConstants.NETWORK_REQUIREMENT_ID,
+ createRequirementAssignment(translateTo.getTranslatedId()));
+ }
+ }
+
+ private List<AttachedResourceId> extractNetworkPolicyIdList(TranslateTo translateTo) {
+
+ Object propertyValue = translateTo.getResource().getProperties().get("network_policy_refs");
+ if (propertyValue != null) {
+ return extractNetworkPolicyId(propertyValue, translateTo);
+ } else {
+ return null;
+ }
+ }
+
+ private List<AttachedResourceId> extractNetworkPolicyId(Object propertyValue,
+ TranslateTo translateTo) {
+ List<AttachedResourceId> attachedResourceIdList = new ArrayList<>();
+
+ if (propertyValue instanceof List) {
+ for (Object value : (List) propertyValue) {
+ attachedResourceIdList.addAll(extractNetworkPolicyId(value, translateTo));
+ }
+ } else {
+ AttachedResourceId resourceId = parsNetworkPolicyId(propertyValue, translateTo);
+ if (resourceId != null) {
+ attachedResourceIdList.add(resourceId);
+ }
+ }
+ return attachedResourceIdList;
+ }
+
+ private AttachedResourceId parsNetworkPolicyId(Object propertyValue, TranslateTo translateTo) {
+
+ Optional<String> translatedPolicyResourceId;
+ String policyResourceId = extractResourceId(propertyValue, translateTo);
+ if (policyResourceId == null) {
+ return null;
+ }
+
+ Resource policyResource = HeatToToscaUtil
+ .getResource(translateTo.getHeatOrchestrationTemplate(), policyResourceId,
+ translateTo.getHeatFileName());
+ if (!policyResource.getType()
+ .equals(HeatResourcesTypes.CONTRAIL_V2_NETWORK_RULE_RESOURCE_TYPE.getHeatResource())) {
+ return null;
+ }
+ translatedPolicyResourceId = ResourceTranslationFactory.getInstance(policyResource)
+ .translateResource(translateTo.getHeatFileName(), translateTo.getServiceTemplate(),
+ translateTo.getHeatOrchestrationTemplate(), policyResource, policyResourceId,
+ translateTo.getContext());
+ if (!translatedPolicyResourceId.isPresent()) {
+ logger.warn("Heat resource: '" + translateTo.getResourceId() + "' with type: '"
+ + translateTo.getResource().getType()
+ + "' property network_policy_refs is referenced to an "
+ + "unsupported resource the connection will be ignored in TOSCA translation.");
+ return null;
+ }
+ return
+ new AttachedResourceId(translatedPolicyResourceId.get(), policyResourceId,
+ ResourceReferenceType.GET_ATTR);
+ }
+
+ private String extractResourceId(Object propertyValue, TranslateTo translateTo) {
+
+ Object value;
+ if (propertyValue instanceof Map) {
+ if (((Map) propertyValue).containsKey("get_attr")) {
+ value = ((Map) propertyValue).get("get_attr");
+ if (value instanceof List) {
+ if (((List) value).size() == 2 && ((List) value).get(1).equals("fq_name")) {
+ if (((List) value).get(0) instanceof String) {
+ return (String) ((List) value).get(0);
+ } else {
+ logger.warn("Heat resource: '" + translateTo.getResourceId() + "' with type: '"
+ + translateTo.getResource().getType()
+ + "' has property with invalid format of 'get_attr' function "
+ + "with 'fq_name' value, therefore this property"
+ + " will be ignored in TOSCA translation.");
+ }
+ }
+ }
+ } else if (((Map) propertyValue).containsKey("get_resource")) {
+ value = ((Map) propertyValue).get("get_resource");
+ if (value instanceof String) {
+ return (String) value;
+ } else {
+ logger.warn("Heat resource: '" + translateTo.getResourceId() + "' with type: '"
+ + translateTo.getResource().getType()
+ + "' has property invalid format of 'get_resource' function, therefore"
+ + " this property will be ignored in TOSCA translation.");
+ }
+ } else {
+ Collection<Object> valCollection = ((Map) propertyValue).values();
+ for (Object entryValue : valCollection) {
+ String ret = extractResourceId(entryValue, translateTo);
+ if (ret != null) {
+ return ret;
+ }
+
+ }
+ }
+ } else if (propertyValue instanceof List) {
+ for (Object prop : (List) propertyValue) {
+ String ret = extractResourceId(prop, translateTo);
+ if (ret != null) {
+ return ret;
+ }
+ }
+ }
+ logger.warn("Heat resource: '" + translateTo.getResourceId() + "' with type: '"
+ + translateTo.getResource().getType()
+ + "' invalid format of property value, therefore "
+ + "this resource will be ignored in TOSCA translation.");
+ return null;
+ }
+
+ private RequirementAssignment createRequirementAssignment(String translatedNetworkResourceId) {
+ RequirementAssignment requirement = new RequirementAssignment();
+ requirement.setCapability(ToscaCapabilityType.ATTACHMENT.getDisplayName());
+ requirement.setNode(translatedNetworkResourceId);
+ requirement.setRelationship(ToscaRelationshipType.ATTACHES_TO.getDisplayName());
+ return requirement;
+ }
+
+
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationContrailV2VmInterfaceImpl.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationContrailV2VmInterfaceImpl.java
new file mode 100644
index 0000000000..14403df002
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationContrailV2VmInterfaceImpl.java
@@ -0,0 +1,126 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca.impl;
+
+import org.openecomp.sdc.heat.datatypes.model.HeatResourcesTypes;
+import org.openecomp.sdc.heat.datatypes.model.Resource;
+import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
+import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate;
+import org.openecomp.sdc.tosca.services.DataModelUtil;
+import org.openecomp.sdc.translator.datatypes.heattotosca.AttachedResourceId;
+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.HeatToToscaUtil;
+import org.openecomp.sdc.translator.services.heattotosca.mapping.TranslatorHeatToToscaPropertyConverter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
+
+
+public class ResourceTranslationContrailV2VmInterfaceImpl extends ResourceTranslationBase {
+ protected static Logger logger =
+ LoggerFactory.getLogger(ResourceTranslationContrailV2VmInterfaceImpl.class);
+
+ @Override
+ protected void translate(TranslateTo translateTo) {
+ NodeTemplate nodeTemplate = new NodeTemplate();
+ nodeTemplate.setType(ToscaNodeType.CONTRAILV2_VIRTUAL_MACHINE_INTERFACE.getDisplayName());
+
+ nodeTemplate.setProperties(TranslatorHeatToToscaPropertyConverter
+ .getToscaPropertiesSimpleConversion(translateTo.getResource().getProperties(),
+ nodeTemplate.getProperties(), translateTo.getHeatFileName(),
+ translateTo.getHeatOrchestrationTemplate(), translateTo.getResource().getType(),
+ nodeTemplate, translateTo.getContext()));
+ handleNetworkRequirement(translateTo, nodeTemplate);
+ Optional<String> resourceTranslatedId = getResourceTranslatedId(translateTo.getHeatFileName(),
+ translateTo.getHeatOrchestrationTemplate(), translateTo.getResourceId(),
+ translateTo.getContext());
+ if (resourceTranslatedId.isPresent()) {
+ DataModelUtil.addNodeTemplate(translateTo.getServiceTemplate(), resourceTranslatedId.get(),
+ nodeTemplate);
+ }
+ }
+
+ private void handleNetworkRequirement(TranslateTo translateTo, NodeTemplate nodeTemplate) {
+ Object virtualNetworkRefs =
+ translateTo.getResource().getProperties().get("virtual_network_refs");
+ if (Objects.isNull(virtualNetworkRefs) || !(virtualNetworkRefs instanceof List)
+ || ((List) virtualNetworkRefs).size() == 0) {
+ return;
+ }
+ List<String> acceptableResourceTypes = Arrays
+ .asList(HeatResourcesTypes.NEUTRON_NET_RESOURCE_TYPE.getHeatResource(),
+ HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_NETWORK_RESOURCE_TYPE.getHeatResource());
+ List virtualNetworkRefList = (List) virtualNetworkRefs;
+ if (virtualNetworkRefList.size() > 1) {
+ logger.warn("Heat resource: '" + translateTo.getResourceId() + "' with type: '"
+ + translateTo.getResource().getType()
+ + "' 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.");
+ }
+ Object virtualNetworkRef = virtualNetworkRefList.get(0);
+ String networkResourceId =
+ HeatToToscaUtil.extractContrailGetResourceAttachedHeatResourceId(virtualNetworkRef);
+ if (Objects.nonNull(networkResourceId)) { // get_resource
+ Resource networkResource = HeatToToscaUtil
+ .getResource(translateTo.getHeatOrchestrationTemplate(), networkResourceId,
+ translateTo.getHeatFileName());
+ if (acceptableResourceTypes.contains(networkResource.getType())) {
+ Optional<String> resourceTranslatedId =
+ getResourceTranslatedId(translateTo.getHeatFileName(),
+ translateTo.getHeatOrchestrationTemplate(), networkResourceId,
+ translateTo.getContext());
+ if (resourceTranslatedId.isPresent()) {
+ addLinkReqFromPortToNetwork(nodeTemplate, resourceTranslatedId.get());
+ }
+ } else {
+ logger.warn("Heat resource: '" + translateTo.getResourceId() + "' with type: '"
+ + translateTo.getResource().getType()
+ + "' include 'virtual_network_refs' property which is connect"
+ + " to unsupported/incorrect resource with type '"
+ + networkResource.getType()
+ + "', therefore, this connection will be ignored in TOSCA translation.");
+ }
+ } else {
+ Optional<AttachedResourceId> attachedResourceId = HeatToToscaUtil
+ .extractAttachedResourceId(translateTo.getHeatFileName(),
+ translateTo.getHeatOrchestrationTemplate(), translateTo.getContext(),
+ virtualNetworkRef);
+ if (attachedResourceId.isPresent() && attachedResourceId.get().isGetParam()) {
+ TranslatedHeatResource translatedSharedResourceId =
+ translateTo.getContext().getHeatSharedResourcesByParam()
+ .get(attachedResourceId.get().getEntityId());
+ if (Objects.nonNull(translatedSharedResourceId)
+ && !HeatToToscaUtil.isHeatFileNested(translateTo, translateTo.getHeatFileName())) {
+ addLinkReqFromPortToNetwork(nodeTemplate, translatedSharedResourceId.getTranslatedId());
+ }
+ }
+ }
+
+
+ }
+
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationContrailVirtualNetworkImpl.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationContrailVirtualNetworkImpl.java
new file mode 100644
index 0000000000..3a3a532d59
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationContrailVirtualNetworkImpl.java
@@ -0,0 +1,51 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca.impl;
+
+import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
+import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate;
+import org.openecomp.sdc.tosca.services.DataModelUtil;
+import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo;
+import org.openecomp.sdc.translator.services.heattotosca.mapping.TranslatorHeatToToscaPropertyConverter;
+
+import java.util.Optional;
+
+public class ResourceTranslationContrailVirtualNetworkImpl extends ResourceTranslationBase {
+
+ @Override
+ public void translate(TranslateTo translateTo) {
+
+ NodeTemplate nodeTemplate = new NodeTemplate();
+ nodeTemplate.setType(ToscaNodeType.CONTRAIL_VIRTUAL_NETWORK.getDisplayName());
+ nodeTemplate.setProperties(TranslatorHeatToToscaPropertyConverter
+ .getToscaPropertiesSimpleConversion(translateTo.getResource().getProperties(),
+ nodeTemplate.getProperties(), translateTo.getHeatFileName(),
+ translateTo.getHeatOrchestrationTemplate(), translateTo.getResource().getType(),
+ nodeTemplate, translateTo.getContext()));
+ Optional<String> resourceTranslatedId = getResourceTranslatedId(translateTo.getHeatFileName(),
+ translateTo.getHeatOrchestrationTemplate(), translateTo.getResourceId(),
+ translateTo.getContext());
+ if (resourceTranslatedId.isPresent()) {
+ DataModelUtil.addNodeTemplate(translateTo.getServiceTemplate(), resourceTranslatedId.get(),
+ nodeTemplate);
+ }
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationDefaultImpl.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationDefaultImpl.java
new file mode 100644
index 0000000000..1182b60a6a
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationDefaultImpl.java
@@ -0,0 +1,41 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca.impl;
+
+import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo;
+
+public class ResourceTranslationDefaultImpl extends ResourceTranslationBase {
+
+ @Override
+ protected String generateTranslatedId(TranslateTo translateTo) {
+ return null;
+ }
+
+ @Override
+ public void translate(TranslateTo translateTo) {
+ //no translation is needed, this default is used for unsupported resources
+ logger.warn("Heat resource: '" + translateTo.getResourceId() + "' with type: '"
+ + translateTo.getResource().getType()
+ + "' is not supported, will be ignored in TOSCA translation");
+
+ }
+
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationNestedImpl.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationNestedImpl.java
new file mode 100644
index 0000000000..2573b6849d
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationNestedImpl.java
@@ -0,0 +1,781 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca.impl;
+
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.collections4.MapUtils;
+import org.openecomp.core.utilities.file.FileUtils;
+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.openecomp.sdc.tosca.datatypes.model.AttributeDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.CapabilityDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.Metadata;
+import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate;
+import org.openecomp.sdc.tosca.datatypes.model.NodeType;
+import org.openecomp.sdc.tosca.datatypes.model.ParameterDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.PropertyDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.PropertyType;
+import org.openecomp.sdc.tosca.datatypes.model.RequirementAssignment;
+import org.openecomp.sdc.tosca.datatypes.model.RequirementDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate;
+import org.openecomp.sdc.tosca.datatypes.model.SubstitutionMapping;
+import org.openecomp.sdc.tosca.datatypes.model.Template;
+import org.openecomp.sdc.tosca.datatypes.model.TopologyTemplate;
+import org.openecomp.sdc.tosca.services.DataModelUtil;
+import org.openecomp.sdc.tosca.services.ToscaConstants;
+import org.openecomp.sdc.tosca.services.ToscaUtil;
+import org.openecomp.sdc.translator.datatypes.heattotosca.AttachedResourceId;
+import org.openecomp.sdc.translator.datatypes.heattotosca.to.ResourceFileDataAndIDs;
+import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo;
+import org.openecomp.sdc.translator.services.heattotosca.Constants;
+import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil;
+import org.openecomp.sdc.translator.services.heattotosca.TranslationContext;
+import org.openecomp.sdc.translator.services.heattotosca.TranslationService;
+import org.openecomp.sdc.translator.services.heattotosca.globaltypes.GlobalTypesGenerator;
+import org.openecomp.sdc.translator.services.heattotosca.globaltypes.GlobalTypesUtil;
+import org.openecomp.sdc.translator.services.heattotosca.mapping.TranslatorHeatToToscaPropertyConverter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+
+public class ResourceTranslationNestedImpl extends ResourceTranslationBase {
+
+ protected static Logger logger = LoggerFactory.getLogger(ResourceTranslationNestedImpl.class);
+
+ @Override
+ public void translate(TranslateTo translateTo) {
+ FileData nestedFileData =
+ getFileData(translateTo.getResource().getType(), translateTo.getContext());
+ String templateName = FileUtils.getFileWithoutExtention(translateTo.getResource().getType());
+ String substitutionNodeTypeKey = ToscaConstants.NODES_SUBSTITUTION_PREFIX + templateName;
+
+ if (!translateTo.getContext().getTranslatedServiceTemplates()
+ .containsKey(translateTo.getResource().getType())) {
+
+ //substitution template
+ ServiceTemplate nestedSubstitutionServiceTemplate = new ServiceTemplate();
+ Metadata templateMetadata = new Metadata();
+ templateMetadata.setTemplate_name(templateName);
+ nestedSubstitutionServiceTemplate.setMetadata(templateMetadata);
+ nestedSubstitutionServiceTemplate
+ .setTosca_definitions_version(ToscaConstants.TOSCA_DEFINITIONS_VERSION);
+ nestedSubstitutionServiceTemplate.setTopology_template(new TopologyTemplate());
+ nestedSubstitutionServiceTemplate.setImports(GlobalTypesGenerator.getGlobalTypesImportList());
+ nestedSubstitutionServiceTemplate.getImports()
+ .put(Constants.GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME, GlobalTypesUtil
+ .createServiceTemplateImport(Constants.GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME));
+
+ TranslationService translationService = new TranslationService();
+
+ translationService.translateHeatFile(nestedSubstitutionServiceTemplate, nestedFileData,
+ translateTo.getContext());
+
+ //global substitution template
+ ServiceTemplate globalSubstitutionServiceTemplate;
+ globalSubstitutionServiceTemplate = translateTo.getContext().getTranslatedServiceTemplates()
+ .get(Constants.GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME);
+ if (globalSubstitutionServiceTemplate == null) {
+ globalSubstitutionServiceTemplate = new ServiceTemplate();
+ templateMetadata = new Metadata();
+ templateMetadata.setTemplate_name(Constants.GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME);
+ globalSubstitutionServiceTemplate.setMetadata(templateMetadata);
+ globalSubstitutionServiceTemplate
+ .setImports(GlobalTypesGenerator.getGlobalTypesImportList());
+ globalSubstitutionServiceTemplate
+ .setTosca_definitions_version(ToscaConstants.TOSCA_DEFINITIONS_VERSION);
+ }
+ translateTo.getServiceTemplate().getImports()
+ .put(Constants.GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME, GlobalTypesUtil
+ .createServiceTemplateImport(Constants.GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME));
+
+
+ //substitution node type
+ NodeType substitutionNodeType = new NodeType();
+ substitutionNodeType.setDerived_from(ToscaNodeType.ABSTRACT_SUBSTITUTE.getDisplayName());
+ substitutionNodeType.setDescription(nestedSubstitutionServiceTemplate.getDescription());
+ substitutionNodeType
+ .setProperties(manageSubstitutionNodeTypeProperties(nestedSubstitutionServiceTemplate));
+ substitutionNodeType
+ .setAttributes(manageSubstitutionNodeTypeAttributes(nestedSubstitutionServiceTemplate));
+ DataModelUtil.addNodeType(globalSubstitutionServiceTemplate, substitutionNodeTypeKey,
+ substitutionNodeType);
+ Map<String, Map<String, List<String>>> substitutionMapping =
+ manageSubstitutionNodeTypeCapabilitiesAndRequirements(substitutionNodeType,
+ nestedSubstitutionServiceTemplate, translateTo);
+ //calculate substitution mapping after capability and requirement expose calculation
+ nestedSubstitutionServiceTemplate.getTopology_template().setSubstitution_mappings(
+ manageSubstitutionTemplateSubstitutionMapping(substitutionNodeTypeKey,
+ substitutionNodeType, substitutionMapping));
+
+ //add new service template
+ translateTo.getContext().getTranslatedServiceTemplates()
+ .put(Constants.GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME,
+ globalSubstitutionServiceTemplate);
+ translateTo.getContext().getTranslatedServiceTemplates()
+ .put(translateTo.getResource().getType(), nestedSubstitutionServiceTemplate);
+ }
+
+ NodeTemplate substitutionNodeTemplate = new NodeTemplate();
+ List<String> directiveList = new ArrayList<>();
+ directiveList.add(ToscaConstants.NODE_TEMPLATE_DIRECTIVE_SUBSTITUTABLE);
+ substitutionNodeTemplate.setDirectives(directiveList);
+ substitutionNodeTemplate.setType(substitutionNodeTypeKey);
+ substitutionNodeTemplate.setProperties(
+ managerSubstitutionNodeTemplateProperties(translateTo, substitutionNodeTemplate,
+ templateName));
+ manageSubstitutionNodeTemplateConnectionPoint(translateTo, nestedFileData,
+ substitutionNodeTemplate);
+ DataModelUtil.addNodeTemplate(translateTo.getServiceTemplate(), translateTo.getTranslatedId(),
+ substitutionNodeTemplate);
+ }
+
+ private void manageSubstitutionNodeTemplateConnectionPoint(TranslateTo translateTo,
+ FileData nestedFileData,
+ NodeTemplate substitutionNodeTemplate) {
+ ServiceTemplate globalSubstitutionTemplate =
+ translateTo.getContext().getTranslatedServiceTemplates()
+ .get(Constants.GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME);
+ NodeType nodeType = globalSubstitutionTemplate.getNode_types().get(
+ ToscaConstants.NODES_SUBSTITUTION_PREFIX
+ + FileUtils.getFileWithoutExtention(translateTo.getResource().getType()));
+ handlePortToNetConnections(translateTo, nestedFileData, substitutionNodeTemplate, nodeType);
+ handleSecurityRulesToPortConnections(translateTo, nestedFileData, substitutionNodeTemplate,
+ nodeType);
+ handleNovaToVolConnection(translateTo, nestedFileData, substitutionNodeTemplate, nodeType);
+ handleContrailV2VmInterfaceToNetworkConnection(translateTo, nestedFileData,
+ substitutionNodeTemplate, nodeType);
+ }
+
+ private void handleContrailV2VmInterfaceToNetworkConnection(TranslateTo translateTo,
+ FileData nestedFileData,
+ NodeTemplate substitutionNodeTemplate,
+ NodeType nodeType) {
+ ContrailV2VmInterfaceToNetResourceConnection linker =
+ new ContrailV2VmInterfaceToNetResourceConnection(this, translateTo, nestedFileData,
+ substitutionNodeTemplate, nodeType);
+ linker.connect();
+ }
+
+ private void handleNovaToVolConnection(TranslateTo translateTo, FileData nestedFileData,
+ NodeTemplate substitutionNodeTemplate, NodeType nodeType) {
+ NovaToVolResourceConnection linker =
+ new NovaToVolResourceConnection(this, translateTo, nestedFileData, substitutionNodeTemplate,
+ nodeType);
+ linker.connect();
+ }
+
+ private void handleSecurityRulesToPortConnections(TranslateTo translateTo,
+ FileData nestedFileData,
+ NodeTemplate substitutionNodeTemplate,
+ NodeType nodeType) {
+ SecurityRulesToPortResourceConnection linker =
+ new SecurityRulesToPortResourceConnection(this, translateTo, nestedFileData,
+ substitutionNodeTemplate, nodeType);
+ linker.connect();
+ }
+
+ private void handlePortToNetConnections(TranslateTo translateTo, FileData nestedFileData,
+ NodeTemplate substitutionNodeTemplate,
+ NodeType nodeType) {
+ PortToNetResourceConnection linker =
+ new PortToNetResourceConnection(this, translateTo, nestedFileData, substitutionNodeTemplate,
+ nodeType);
+ linker.connect();
+ }
+
+ private List<Map<String, RequirementDefinition>> getVolumeRequirements(NodeType nodeType) {
+ List<Map<String, RequirementDefinition>> volumeRequirementsList = new ArrayList<>();
+ List<Map<String, RequirementDefinition>> requirementsList = nodeType.getRequirements();
+
+ for (int i = 0; requirementsList != null && i < requirementsList.size(); i++) {
+ RequirementDefinition req;
+ for (Map.Entry<String, RequirementDefinition> entry : requirementsList.get(i).entrySet()) {
+ req = entry.getValue();
+ if (isVolumeRequirement(req, ToscaCapabilityType.ATTACHMENT.getDisplayName(),
+ ToscaNodeType.BLOCK_STORAGE.getDisplayName(),
+ ToscaRelationshipType.NATIVE_ATTACHES_TO.getDisplayName())) {
+ Map<String, RequirementDefinition> volumeRequirementsMap = new HashMap<>();
+ volumeRequirementsMap.put(entry.getKey(), entry.getValue());
+ volumeRequirementsList.add(volumeRequirementsMap);
+ }
+
+ }
+ }
+ return volumeRequirementsList;
+ }
+
+ private boolean isVolumeRequirement(RequirementDefinition req, String capability, String node,
+ String relationship) {
+ return req.getCapability().equals(capability) && req.getRelationship().equals(relationship)
+ && req.getNode().equals(node);
+ }
+
+ private String getVolumeIdProperty(HeatOrchestrationTemplate heatOrchestrationTemplate,
+ String resourceId) {
+
+ String novaResourceId;
+ String volumeId = null;
+ for (Resource resource : heatOrchestrationTemplate.getResources().values()) {
+ if (resource.getType()
+ .equals(HeatResourcesTypes.CINDER_VOLUME_ATTACHMENT_RESOURCE_TYPE.getHeatResource())) {
+ Optional<String> optNovaResourceId =
+ getToscaPropertyValueSource(HeatConstants.INSTANCE_UUID_PROPERTY_NAME, resource,
+ "get_resource");
+ if (optNovaResourceId.isPresent()) {
+ novaResourceId = optNovaResourceId.get();
+ if (novaResourceId.equals(resourceId)) {
+ Optional<String> optVolumeId =
+ getToscaPropertyValueSource(HeatConstants.VOLUME_ID_PROPERTY_NAME, resource,
+ "get_param");
+ if (optVolumeId.isPresent()) {
+ volumeId = optVolumeId.get();
+ }
+ } else {
+ logger.warn("property:" + HeatConstants.VOLUME_ID_PROPERTY_NAME + " of resource type:"
+ + resource.getType() + " should contain 'get_param' function");
+ }
+ }
+ }
+ }
+ return volumeId;
+ }
+
+ private String getTranslatedVolumeIdByVolumeIdProperty(String volumeId, TranslateTo translateTo) {
+ Optional<AttachedResourceId> volumeIdInfo =
+ HeatToToscaUtil.extractAttachedResourceId(translateTo, volumeId);
+ if (volumeIdInfo.isPresent()) {
+ if (volumeIdInfo.get().isGetResource()) {
+ return null;//(String) volumeIdInfo.get().getTranslatedId();
+ } else if (volumeIdInfo.get().isGetParam()) {
+ List<FileData> allFilesData = translateTo.getContext().getManifest().getContent().getData();
+ Optional<List<FileData>> fileDataList = HeatToToscaUtil
+ .buildListOfFilesToSearch(translateTo.getHeatFileName(), allFilesData,
+ FileData.Type.HEAT_VOL);
+ if (fileDataList.isPresent()) {
+ Optional<ResourceFileDataAndIDs> resourceFileDataAndIDs =
+ getFileDataContainingResource(fileDataList.get(),
+ (String) volumeIdInfo.get().getEntityId(), translateTo.getContext(),
+ FileData.Type.HEAT_VOL);
+ if (resourceFileDataAndIDs.isPresent()) {
+ return resourceFileDataAndIDs.get().getTranslatedResourceId();
+ } else {
+ logger.warn("The attached volume based on volume_id property: " + volumeId + " in "
+ + translateTo.getResourceId()
+ + " can't be found, searching for volume resource id - "
+ + volumeIdInfo.get().getEntityId());
+ return null;
+ }
+ } else {
+ return null;
+ }
+ } else {
+ logger.warn("property:" + volumeId + " of resource :" + volumeIdInfo.get().getEntityId()
+ + " should contain 'get_param' or 'get_resource' function");
+ return null;
+ }
+ } else {
+ logger.warn("property:" + volumeId + " of resource :" + translateTo.getResource().toString()
+ + " is not exist");
+ return null;
+ }
+ }
+
+ private Optional<String> getToscaPropertyValueSource(String propertyName, Resource resource,
+ String key) {
+ Object propertyInstanceUuIdValue;
+ propertyInstanceUuIdValue = resource.getProperties().get(propertyName);
+ if (propertyInstanceUuIdValue instanceof Map) {
+ return Optional.ofNullable((String) ((Map) propertyInstanceUuIdValue).get(key));
+ } else {
+ logger.warn("property:" + propertyName + " of resource type:" + resource.getType()
+ + " should have a value in key value format");
+
+ }
+ return Optional.empty();
+
+ }
+
+ private Map<String, Map<String, List<String>>>
+ manageSubstitutionNodeTypeCapabilitiesAndRequirements(
+ NodeType substitutionNodeType, ServiceTemplate substitutionServiceTemplate,
+ TranslateTo translateTo) {
+
+ Map<String, NodeTemplate> nodeTemplates =
+ substitutionServiceTemplate.getTopology_template().getNode_templates();
+ String templateName;
+ NodeTemplate template;
+ String type;
+ Map<String, Map<String, List<String>>> substitutionMapping = new HashMap<>();
+ if (nodeTemplates == null) {
+ return substitutionMapping;
+ }
+
+ Map<String, List<String>> capabilitySubstitutionMapping = new HashMap<>();
+ Map<String, List<String>> requirementSubstitutionMapping = new HashMap<>();
+ substitutionMapping.put("capability", capabilitySubstitutionMapping);
+ substitutionMapping.put("requirement", requirementSubstitutionMapping);
+ List<Map<String, RequirementDefinition>> nodeTypeRequirementsDefinition;
+ Map<String, RequirementAssignment> nodeTemplateRequirementsAssignment;
+ List<Map<String, RequirementDefinition>> exposedRequirementsDefinition;
+ Map<String, Map<String, RequirementAssignment>> fullFilledRequirementsDefinition =
+ new HashMap<>();
+ Map<String, CapabilityDefinition> nodeTypeCapabilitiesDefinition = new HashMap<>();
+ Map<String, CapabilityDefinition> exposedCapabilitiesDefinition;
+
+ for (Map.Entry<String, NodeTemplate> entry : nodeTemplates.entrySet()) {
+ templateName = entry.getKey();
+ template = entry.getValue();
+ type = template.getType();
+
+ // get requirements
+ nodeTypeRequirementsDefinition =
+ getNodeTypeRequirements(type, templateName, substitutionServiceTemplate,
+ requirementSubstitutionMapping, translateTo.getContext());
+ nodeTemplateRequirementsAssignment = getNodeTemplateRequirements(template);
+ fullFilledRequirementsDefinition.put(templateName, nodeTemplateRequirementsAssignment);
+ //set substitution node type requirements
+ exposedRequirementsDefinition = calculateExposedRequirements(nodeTypeRequirementsDefinition,
+ nodeTemplateRequirementsAssignment);
+ addSubstitutionNodeTypeRequirements(substitutionNodeType, exposedRequirementsDefinition,
+ templateName);
+
+ //get capabilities
+ getNodeTypeCapabilities(nodeTypeCapabilitiesDefinition, capabilitySubstitutionMapping, type,
+ templateName, substitutionServiceTemplate, translateTo.getContext());
+
+ }
+
+ exposedCapabilitiesDefinition = calculateExposedCapabilities(nodeTypeCapabilitiesDefinition,
+ fullFilledRequirementsDefinition);
+ addSubstitutionNodeTypeCapabilities(substitutionNodeType, exposedCapabilitiesDefinition);
+ return substitutionMapping;
+ }
+
+ private Map<String, CapabilityDefinition> calculateExposedCapabilities(
+ Map<String, CapabilityDefinition> nodeTypeCapabilitiesDefinition,
+ Map<String, Map<String, RequirementAssignment>> fullFilledRequirementsDefinitionMap) {
+
+ String capabilityKey;
+ String capability;
+ String node;
+ CapabilityDefinition capabilityDefinition;
+ CapabilityDefinition clonedCapabilityDefinition;
+ for (Map.Entry<String, Map<String, RequirementAssignment>> entry
+ : fullFilledRequirementsDefinitionMap.entrySet()) {
+ for (Map.Entry<String, RequirementAssignment> fullFilledEntry : entry.getValue().entrySet()) {
+
+ capability = fullFilledEntry.getValue().getCapability();
+ fullFilledEntry.getValue().getOccurrences();
+ node = fullFilledEntry.getValue().getNode();
+ capabilityKey = capability + "_" + node;
+ capabilityDefinition = nodeTypeCapabilitiesDefinition.get(capabilityKey);
+ if (capabilityDefinition != null) {
+ clonedCapabilityDefinition = capabilityDefinition.clone();
+ nodeTypeCapabilitiesDefinition.put(capabilityKey, capabilityDefinition.clone());
+ if (evaluateCapabilityFullFilament(clonedCapabilityDefinition)) {
+ nodeTypeCapabilitiesDefinition.remove(capabilityKey);
+ } else {
+ nodeTypeCapabilitiesDefinition.put(capabilityKey, clonedCapabilityDefinition);
+ }
+ }
+ }
+ }
+
+ Map<String, CapabilityDefinition> exposedCapabilitiesDefinition = new HashMap<>();
+ for (Map.Entry<String, CapabilityDefinition> entry : nodeTypeCapabilitiesDefinition
+ .entrySet()) {
+ exposedCapabilitiesDefinition.put(entry.getKey(), entry.getValue());
+ }
+ return exposedCapabilitiesDefinition;
+ }
+
+ private boolean evaluateCapabilityFullFilament(CapabilityDefinition capabilityDefinition) {
+ Object[] occurrences = capabilityDefinition.getOccurrences();
+ if (occurrences == null) {
+ capabilityDefinition.setOccurrences(new Object[]{"0", ToscaConstants.UNBOUNDED});
+ return false;
+ }
+ if (occurrences[1].equals(ToscaConstants.UNBOUNDED)) {
+ return false;
+ }
+
+ if (occurrences[1].equals(1)) {
+ return true;
+ }
+ occurrences[1] = (Integer) occurrences[1] - 1;
+ return false;
+ }
+
+ private boolean evaluateRequirementFullFilament(RequirementDefinition requirementDefinition) {
+ Object[] occurrences = requirementDefinition.getOccurrences();
+ if (occurrences == null) {
+ requirementDefinition.setOccurrences(new Object[]{"0", ToscaConstants.UNBOUNDED});
+ return false;
+ }
+ if (occurrences[1].equals(ToscaConstants.UNBOUNDED)) {
+ return false;
+ }
+
+ if (occurrences[1].equals(1)) {
+ return true;
+ }
+ occurrences[1] = (Integer) occurrences[1] - 1;
+ return false;
+ }
+
+ private void getNodeTypeCapabilities(
+ Map<String, CapabilityDefinition> nodeTypeCapabilitiesDefinition,
+ Map<String, List<String>> capabilitySubstitutionMapping, String type, String templateName,
+ ServiceTemplate serviceTemplate, TranslationContext context) {
+ NodeType nodeType = getNodeTypeWithFlatHierarchy(type, serviceTemplate, context);
+ String capabilityKey;
+ List<String> capabilityMapping;
+ if (nodeType.getCapabilities() != null) {
+ for (Map.Entry<String, CapabilityDefinition> capabilityNodeEntry : nodeType.getCapabilities()
+ .entrySet()) {
+ capabilityKey = capabilityNodeEntry.getKey() + "_" + templateName;
+ nodeTypeCapabilitiesDefinition.put(capabilityKey, capabilityNodeEntry.getValue().clone());
+ capabilityMapping = new ArrayList<>();
+ capabilityMapping.add(templateName);
+ capabilityMapping.add(capabilityNodeEntry.getKey());
+ capabilitySubstitutionMapping.put(capabilityKey, capabilityMapping);
+ }
+ }
+
+ String derivedFrom = nodeType.getDerived_from();
+ if (derivedFrom != null) {
+ getNodeTypeCapabilities(nodeTypeCapabilitiesDefinition, capabilitySubstitutionMapping,
+ derivedFrom, templateName, serviceTemplate, context);
+ }
+ }
+
+ private List<Map<String, RequirementDefinition>> calculateExposedRequirements(
+ List<Map<String, RequirementDefinition>> nodeTypeRequirementsDefinitionList,
+ Map<String, RequirementAssignment> nodeTemplateRequirementsAssignment) {
+ if (nodeTypeRequirementsDefinitionList == null) {
+ return null;
+ }
+ for (Map.Entry<String, RequirementAssignment> entry : nodeTemplateRequirementsAssignment
+ .entrySet()) {
+ if (entry.getValue().getNode() != null) {
+ RequirementDefinition requirementDefinition =
+ getRequirementDefinition(nodeTypeRequirementsDefinitionList, entry.getKey());
+ RequirementDefinition cloneRequirementDefinition;
+ if (requirementDefinition != null) {
+ cloneRequirementDefinition = requirementDefinition.clone();
+ if (!evaluateRequirementFullFilament(cloneRequirementDefinition)) {
+ this.mergeEntryInList(entry.getKey(), cloneRequirementDefinition,
+ nodeTypeRequirementsDefinitionList);
+ } else {
+ removeRequirementsDefinition(nodeTypeRequirementsDefinitionList, entry.getKey());
+ }
+ }
+ } else {
+ for (Map<String, RequirementDefinition> nodeTypeRequirementsMap
+ : nodeTypeRequirementsDefinitionList) {
+ Object max = nodeTypeRequirementsMap.get(entry.getKey()).getOccurrences() != null
+ && nodeTypeRequirementsMap.get(entry.getKey()).getOccurrences().length > 0
+ ? nodeTypeRequirementsMap.get(entry.getKey()).getOccurrences()[1] : 1;
+ Object min = nodeTypeRequirementsMap.get(entry.getKey()).getOccurrences() != null
+ && nodeTypeRequirementsMap.get(entry.getKey()).getOccurrences().length > 0
+ ? nodeTypeRequirementsMap.get(entry.getKey()).getOccurrences()[0] : 1;
+ nodeTypeRequirementsMap.get(entry.getKey()).setOccurrences(new Object[]{min, max});
+ }
+ }
+ }
+ return nodeTypeRequirementsDefinitionList;
+ }
+
+ private void removeRequirementsDefinition(
+ List<Map<String, RequirementDefinition>> nodeTypeRequirementsDefinitionList,
+ String requirementKey) {
+ for (Map<String, RequirementDefinition> reqMap : nodeTypeRequirementsDefinitionList) {
+ reqMap.remove(requirementKey);
+ }
+ }
+
+ private RequirementDefinition getRequirementDefinition(
+ List<Map<String, RequirementDefinition>> nodeTypeRequirementsDefinitionList,
+ String requirementKey) {
+ for (Map<String, RequirementDefinition> requirementMap : nodeTypeRequirementsDefinitionList) {
+ if (requirementMap.containsKey(requirementKey)) {
+ return requirementMap.get(requirementKey);
+ }
+ }
+ return null;
+ }
+
+ private Map<String, RequirementAssignment> getNodeTemplateRequirements(NodeTemplate template) {
+ List<Map<String, RequirementAssignment>> templateRequirements = template.getRequirements();
+
+ Map<String, RequirementAssignment> nodeTemplateRequirementsDefinition = new HashMap<>();
+ if (CollectionUtils.isEmpty(templateRequirements)) {
+ return nodeTemplateRequirementsDefinition;
+ }
+ for (Map<String, RequirementAssignment> requirementAssignmentMap : templateRequirements) {
+ for (Map.Entry<String, RequirementAssignment> requirementEntry : requirementAssignmentMap
+ .entrySet()) {
+ nodeTemplateRequirementsDefinition
+ .put(requirementEntry.getKey(), requirementEntry.getValue());
+ }
+ }
+ return nodeTemplateRequirementsDefinition;
+ }
+
+ private List<Map<String, RequirementDefinition>> getNodeTypeRequirements(String type,
+ String templateName,
+ ServiceTemplate serviceTemplate,
+ Map<String, List<String>> requirementSubstitutionMapping,
+ TranslationContext context) {
+ List<Map<String, RequirementDefinition>> requirementList = null;
+ NodeType nodeType = getNodeTypeWithFlatHierarchy(type, serviceTemplate, context);
+ String derivedFrom = nodeType.getDerived_from();
+ List<String> requirementMapping;
+ if (derivedFrom != null) {
+ requirementList = getNodeTypeRequirements(derivedFrom, templateName, serviceTemplate,
+ requirementSubstitutionMapping, context);
+ }
+ if (requirementList == null) {
+ requirementList = new ArrayList<>();
+ }
+
+ if (nodeType.getRequirements() != null) {
+ for (Map<String, RequirementDefinition> requirementMap : nodeType.getRequirements()) {
+ for (Map.Entry<String, RequirementDefinition> requirementNodeEntry : requirementMap
+ .entrySet()) {
+ if (requirementNodeEntry.getValue().getOccurrences() == null) {
+ requirementNodeEntry.getValue().setOccurrences(new Object[]{1, 1});
+ }
+ Map<String, RequirementDefinition> requirementDef = new HashMap<>();
+ requirementDef.put(requirementNodeEntry.getKey(), requirementNodeEntry.getValue());
+ addRequirementToList(requirementList, requirementDef);
+ requirementMapping = new ArrayList<>();
+ requirementMapping.add(templateName);
+ requirementMapping.add(requirementNodeEntry.getKey());
+ requirementSubstitutionMapping
+ .put(requirementNodeEntry.getKey() + "_" + templateName, requirementMapping);
+ if (requirementNodeEntry.getValue().getNode() == null) {
+ requirementNodeEntry.getValue().setOccurrences(new Object[]{1, 1});
+ }
+ }
+ }
+ }
+
+ return requirementList;
+ }
+
+ private void addRequirementToList(List<Map<String, RequirementDefinition>> requirementList,
+ Map<String, RequirementDefinition> requirementDef) {
+ for (Map.Entry<String, RequirementDefinition> entry : requirementDef.entrySet()) {
+ this.mergeEntryInList(entry.getKey(), entry.getValue(), requirementList);
+ }
+ }
+
+ private void addSubstitutionNodeTypeCapabilities(NodeType substitutionNodeType,
+ Map<String, CapabilityDefinition> capabilities) {
+ if (capabilities == null || capabilities.entrySet().size() == 0) {
+ return;
+ }
+
+ if (MapUtils.isEmpty(substitutionNodeType.getCapabilities())) {
+ substitutionNodeType.setCapabilities(new HashMap<>());
+ }
+ if (capabilities.size() > 0) {
+ substitutionNodeType.setCapabilities(new HashMap<>());
+ }
+ for (Map.Entry<String, CapabilityDefinition> entry : capabilities.entrySet()) {
+ substitutionNodeType.getCapabilities().put(entry.getKey(), entry.getValue());
+ }
+ }
+
+ private void addSubstitutionNodeTypeRequirements(NodeType substitutionNodeType,
+ List<Map<String, RequirementDefinition>> requirementsList,
+ String templateName) {
+ if (requirementsList == null || requirementsList.size() == 0) {
+ return;
+ }
+
+ if (substitutionNodeType.getRequirements() == null) {
+ substitutionNodeType.setRequirements(new ArrayList<>());
+ }
+
+ for (Map<String, RequirementDefinition> requirementDef : requirementsList) {
+ for (Map.Entry<String, RequirementDefinition> entry : requirementDef.entrySet()) {
+ Map<String, RequirementDefinition> requirementMap = new HashMap<>();
+ requirementMap.put(entry.getKey() + "_" + templateName, entry.getValue().clone());
+ substitutionNodeType.getRequirements().add(requirementMap);
+ }
+ }
+ }
+
+
+ private SubstitutionMapping manageSubstitutionTemplateSubstitutionMapping(String nodeTypeKey,
+ NodeType substitutionNodeType,
+ Map<String, Map<String, List<String>>> mapping) {
+ SubstitutionMapping substitutionMapping = new SubstitutionMapping();
+ substitutionMapping.setNode_type(nodeTypeKey);
+ substitutionMapping.setCapabilities(
+ manageCapabilityMapping(substitutionNodeType.getCapabilities(), mapping.get("capability")));
+ substitutionMapping.setRequirements(
+ manageRequirementMapping(substitutionNodeType.getRequirements(),
+ mapping.get("requirement")));
+ return substitutionMapping;
+ }
+
+ private Map<String, List<String>> manageCapabilityMapping(
+ Map<String, CapabilityDefinition> capabilities,
+ Map<String, List<String>> capabilitySubstitutionMapping) {
+ if (capabilities == null) {
+ return null;
+ }
+
+ Map<String, List<String>> capabilityMapping = new HashMap<>();
+ String capabilityKey;
+ List<String> capabilityMap;
+ for (Map.Entry<String, CapabilityDefinition> entry : capabilities.entrySet()) {
+ capabilityKey = entry.getKey();
+ capabilityMap = capabilitySubstitutionMapping.get(capabilityKey);
+ capabilityMapping.put(capabilityKey, capabilityMap);
+ }
+ return capabilityMapping;
+ }
+
+ private Map<String, List<String>> manageRequirementMapping(
+ List<Map<String, RequirementDefinition>> requirementList,
+ Map<String, List<String>> requirementSubstitutionMapping) {
+ if (requirementList == null) {
+ return null;
+ }
+ Map<String, List<String>> requirementMapping = new HashMap<>();
+ String requirementKey;
+ List<String> requirementMap;
+ for (Map<String, RequirementDefinition> requirementDefMap : requirementList) {
+ for (Map.Entry<String, RequirementDefinition> entry : requirementDefMap.entrySet()) {
+ requirementKey = entry.getKey();
+ requirementMap = requirementSubstitutionMapping.get(requirementKey);
+ requirementMapping.put(requirementKey, requirementMap);
+ }
+ }
+ return requirementMapping;
+ }
+
+
+ private Map<String, AttributeDefinition> manageSubstitutionNodeTypeAttributes(
+ ServiceTemplate substitutionServiceTemplate) {
+
+ Map<String, AttributeDefinition> substitutionNodeTypeAttributes = new HashMap<>();
+ Map<String, ParameterDefinition> attributes =
+ substitutionServiceTemplate.getTopology_template().getOutputs();
+ if (attributes == null) {
+ return null;
+ }
+ AttributeDefinition attributeDefinition;
+ String toscaAttributeName;
+
+ for (Map.Entry<String, ParameterDefinition> entry : attributes.entrySet()) {
+ attributeDefinition = new AttributeDefinition();
+ toscaAttributeName = entry.getKey();
+ ParameterDefinition parameterDefinition =
+ substitutionServiceTemplate.getTopology_template().getOutputs().get(toscaAttributeName);
+ if (parameterDefinition.getType() != null && !parameterDefinition.getType().isEmpty()) {
+ attributeDefinition.setType(parameterDefinition.getType());
+ } else {
+ attributeDefinition.setType(PropertyType.STRING.getDisplayName());
+ }
+ attributeDefinition.setDescription(parameterDefinition.getDescription());
+ attributeDefinition.set_default(parameterDefinition.get_default());
+ attributeDefinition.setEntry_schema(parameterDefinition.getEntry_schema());
+ attributeDefinition.setStatus(parameterDefinition.getStatus());
+ substitutionNodeTypeAttributes.put(toscaAttributeName, attributeDefinition);
+ }
+ return substitutionNodeTypeAttributes;
+ }
+
+ private Map<String, PropertyDefinition> manageSubstitutionNodeTypeProperties(
+ ServiceTemplate substitutionServiceTemplate) {
+ Map<String, PropertyDefinition> substitutionNodeTypeProperties = new HashMap<>();
+ Map<String, ParameterDefinition> properties =
+ substitutionServiceTemplate.getTopology_template().getInputs();
+ if (properties == null) {
+ return null;
+ }
+
+ PropertyDefinition propertyDefinition;
+ String toscaPropertyName;
+ for (Map.Entry<String, ParameterDefinition> entry : properties.entrySet()) {
+ toscaPropertyName = entry.getKey();
+ propertyDefinition = new PropertyDefinition();
+ ParameterDefinition parameterDefinition =
+ substitutionServiceTemplate.getTopology_template().getInputs().get(toscaPropertyName);
+ propertyDefinition.setType(parameterDefinition.getType());
+ propertyDefinition.setDescription(parameterDefinition.getDescription());
+ propertyDefinition.setRequired(parameterDefinition.getRequired());
+ propertyDefinition.set_default(parameterDefinition.get_default());
+ propertyDefinition.setConstraints(parameterDefinition.getConstraints());
+ propertyDefinition.setEntry_schema(parameterDefinition.getEntry_schema());
+ propertyDefinition.setStatus(parameterDefinition.getStatus());
+ substitutionNodeTypeProperties.put(toscaPropertyName, propertyDefinition);
+ }
+ return substitutionNodeTypeProperties;
+ }
+
+ private Map<String, Object> managerSubstitutionNodeTemplateProperties(TranslateTo translateTo,
+ Template template,
+ String templateName) {
+ Map<String, Object> substitutionProperties = new HashMap<>();
+ Map<String, Object> heatProperties = translateTo.getResource().getProperties();
+ if (Objects.nonNull(heatProperties)) {
+ for (Map.Entry<String, Object> entry : heatProperties.entrySet()) {
+
+ Object property = TranslatorHeatToToscaPropertyConverter
+ .getToscaPropertyValue(entry.getKey(), entry.getValue(), null,
+ translateTo.getHeatFileName(), translateTo.getHeatOrchestrationTemplate(), template,
+ translateTo.getContext());
+ substitutionProperties.put(entry.getKey(), property);
+ }
+ }
+
+ return addAbstractSubstitutionProperty(templateName, substitutionProperties);
+ }
+
+ private Map<String, Object> addAbstractSubstitutionProperty(String templateName,
+ Map<String, Object> substitutionProperties) {
+ Map<String, Object> innerProps = new HashMap<>();
+ innerProps.put(ToscaConstants.SUBSTITUTE_SERVICE_TEMPLATE_PROPERTY_NAME,
+ ToscaUtil.getServiceTemplateFileName(templateName));
+ substitutionProperties.put(ToscaConstants.SERVICE_TEMPLATE_FILTER_PROPERTY_NAME, innerProps);
+ return substitutionProperties;
+ }
+
+
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationNeutronNetImpl.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationNeutronNetImpl.java
new file mode 100644
index 0000000000..0b4ed61753
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationNeutronNetImpl.java
@@ -0,0 +1,52 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca.impl;
+
+import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
+import org.openecomp.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;
+
+public class ResourceTranslationNeutronNetImpl extends ResourceTranslationBase {
+
+ @Override
+ public void translate(TranslateTo translateTo) {
+
+ NodeTemplate nodeTemplate = new NodeTemplate();
+ nodeTemplate.setType(ToscaNodeType.NEUTRON_NET.getDisplayName());
+ nodeTemplate.setProperties(TranslatorHeatToToscaPropertyConverter
+ .getToscaPropertiesSimpleConversion(translateTo.getResource().getProperties(),
+ nodeTemplate.getProperties(), translateTo.getHeatFileName(),
+ translateTo.getHeatOrchestrationTemplate(), translateTo.getResource().getType(),
+ nodeTemplate, translateTo.getContext()));
+
+ HeatToToscaUtil.mapBoolean(nodeTemplate, "port_security_enabled");
+ HeatToToscaUtil.mapBoolean(nodeTemplate, "shared");
+ HeatToToscaUtil.mapBoolean(nodeTemplate, "admin_state_up");
+
+ DataModelUtil.addNodeTemplate(translateTo.getServiceTemplate(), translateTo.getTranslatedId(),
+ nodeTemplate);
+ }
+
+
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationNeutronPortImpl.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationNeutronPortImpl.java
new file mode 100644
index 0000000000..343462d266
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationNeutronPortImpl.java
@@ -0,0 +1,233 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca.impl;
+
+import org.openecomp.sdc.heat.datatypes.model.HeatResourcesTypes;
+import org.openecomp.sdc.heat.datatypes.model.Resource;
+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.model.NodeTemplate;
+import org.openecomp.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;
+import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo;
+import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslatedHeatResource;
+import org.openecomp.sdc.translator.services.heattotosca.Constants;
+import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil;
+import org.openecomp.sdc.translator.services.heattotosca.ResourceTranslationFactory;
+import org.openecomp.sdc.translator.services.heattotosca.mapping.TranslatorHeatToToscaPropertyConverter;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+
+
+public class ResourceTranslationNeutronPortImpl extends ResourceTranslationBase {
+
+ @Override
+ public void translate(TranslateTo translateTo) {
+
+ NodeTemplate nodeTemplate = new NodeTemplate();
+ nodeTemplate.setType(ToscaNodeType.NEUTRON_PORT.getDisplayName());
+
+ nodeTemplate.setProperties(TranslatorHeatToToscaPropertyConverter
+ .getToscaPropertiesSimpleConversion(translateTo.getResource().getProperties(),
+ nodeTemplate.getProperties(), translateTo.getHeatFileName(),
+ translateTo.getHeatOrchestrationTemplate(), translateTo.getResource().getType(),
+ nodeTemplate, translateTo.getContext()));
+ handleNetworkRequirement(translateTo, nodeTemplate);
+ String resourceTranslatedId = handleSecurityRulesRequirement(translateTo);
+ DataModelUtil
+ .addNodeTemplate(translateTo.getServiceTemplate(), resourceTranslatedId, nodeTemplate);
+ }
+
+ private String handleSecurityRulesRequirement(TranslateTo translateTo) {
+ String resourceTranslatedId = translateTo.getTranslatedId();
+ Map<String, Object> properties = translateTo.getResource().getProperties();
+ Optional<Object> securityGroups =
+ Optional.ofNullable(properties.get(Constants.SECURITY_GROUPS_PROPERTY_NAME));
+ if (securityGroups.isPresent() && securityGroups.get() instanceof List) {
+ List securityGroupsList = (List) securityGroups.get();
+ securityGroupsList.forEach(resourceValue -> {
+ Optional<AttachedResourceId> securityGroupResourceId = HeatToToscaUtil
+ .extractAttachedResourceId(translateTo.getHeatFileName(),
+ translateTo.getHeatOrchestrationTemplate(), translateTo.getContext(),
+ resourceValue);
+ if (securityGroupResourceId.isPresent()) {
+ handleSecurityGroupResourceId(translateTo, resourceTranslatedId,
+ securityGroupResourceId.get());
+ }
+ });
+ }
+ return resourceTranslatedId;
+ }
+
+ private void handleSecurityGroupResourceId(TranslateTo translateTo, String resourceTranslatedId,
+ AttachedResourceId securityGroupResourceId) {
+ List<String> supportedSecurityGroupsTypes = Collections
+ .singletonList(HeatResourcesTypes.NEUTRON_SECURITY_GROUP_RESOURCE_TYPE.getHeatResource());
+ if (securityGroupResourceId.isGetResource()) {
+ handleGetResource(translateTo, resourceTranslatedId, securityGroupResourceId,
+ supportedSecurityGroupsTypes);
+ } else if (securityGroupResourceId.isGetParam()) {
+ handleGetParam(translateTo, resourceTranslatedId, securityGroupResourceId,
+ supportedSecurityGroupsTypes);
+ }
+ }
+
+ private void handleGetParam(TranslateTo translateTo, String resourceTranslatedId,
+ AttachedResourceId securityGroupResourceId,
+ List<String> supportedSecurityGroupsTypes) {
+ TranslatedHeatResource translatedSharedResourceId =
+ translateTo.getContext().getHeatSharedResourcesByParam()
+ .get(securityGroupResourceId.getEntityId());
+ if (Objects.nonNull(translatedSharedResourceId)
+ && !HeatToToscaUtil.isHeatFileNested(translateTo, translateTo.getHeatFileName())) {
+ if (validateResourceTypeSupportedForReqCreation(translateTo, supportedSecurityGroupsTypes,
+ translatedSharedResourceId.getHeatResource(), "security_groups")) {
+ return;
+ }
+ final NodeTemplate securityGroupNodeTemplate = DataModelUtil
+ .getNodeTemplate(translateTo.getServiceTemplate(),
+ translatedSharedResourceId.getTranslatedId());
+ RequirementAssignment requirement = new RequirementAssignment();
+ requirement.setCapability(ToscaCapabilityType.ATTACHMENT.getDisplayName());
+ requirement.setNode(resourceTranslatedId);
+ requirement.setRelationship(ToscaRelationshipType.ATTACHES_TO.getDisplayName());
+ DataModelUtil
+ .addRequirementAssignment(securityGroupNodeTemplate, ToscaConstants.PORT_REQUIREMENT_ID,
+ requirement);
+ }
+ }
+
+ private void handleGetResource(TranslateTo translateTo, String resourceTranslatedId,
+ AttachedResourceId securityGroupResourceId,
+ List<String> supportedSecurityGroupsTypes) {
+ String resourceId = (String) securityGroupResourceId.getEntityId();
+ Resource securityGroupResource = HeatToToscaUtil
+ .getResource(translateTo.getHeatOrchestrationTemplate(), resourceId,
+ translateTo.getHeatFileName());
+ Optional<String> securityGroupTranslatedId =
+ ResourceTranslationFactory.getInstance(securityGroupResource)
+ .translateResource(translateTo.getHeatFileName(), translateTo.getServiceTemplate(),
+ translateTo.getHeatOrchestrationTemplate(), securityGroupResource, resourceId,
+ translateTo.getContext());
+ if (securityGroupTranslatedId.isPresent()) {
+ if (validateResourceTypeSupportedForReqCreation(translateTo, supportedSecurityGroupsTypes,
+ securityGroupResource, "security_groups")) {
+ return;
+ }
+ final NodeTemplate securityGroupNodeTemplate = DataModelUtil
+ .getNodeTemplate(translateTo.getServiceTemplate(), securityGroupTranslatedId.get());
+ RequirementAssignment requirement = new RequirementAssignment();
+ requirement.setCapability(ToscaCapabilityType.ATTACHMENT.getDisplayName());
+ requirement.setNode(resourceTranslatedId);
+ requirement.setRelationship(ToscaRelationshipType.ATTACHES_TO.getDisplayName());
+ DataModelUtil
+ .addRequirementAssignment(securityGroupNodeTemplate, ToscaConstants.PORT_REQUIREMENT_ID,
+ requirement);
+ }
+ }
+
+ private void handleNetworkRequirement(TranslateTo translateTo, NodeTemplate nodeTemplate) {
+ Optional<AttachedResourceId> networkResourceId =
+ HeatToToscaUtil.extractAttachedResourceId(translateTo, "network");
+ if (networkResourceId.isPresent()) {
+ AttachedResourceId attachedResourceId = networkResourceId.get();
+ addRequirementAssignmentForNetworkResource(translateTo, nodeTemplate, attachedResourceId);
+ } else {
+ networkResourceId = HeatToToscaUtil.extractAttachedResourceId(translateTo, "network_id");
+ if (networkResourceId.isPresent()) {
+ AttachedResourceId attachedResourceId = networkResourceId.get();
+ addRequirementAssignmentForNetworkResource(translateTo, nodeTemplate, attachedResourceId);
+ }
+ }
+ }
+
+ private void addRequirementAssignmentForNetworkResource(TranslateTo translateTo,
+ NodeTemplate nodeTemplate,
+ AttachedResourceId attachedResourceId) {
+ String networkTranslatedId;
+ List<String> supportedNetworkTypes =
+ Arrays.asList(HeatResourcesTypes.NEUTRON_NET_RESOURCE_TYPE.getHeatResource(),
+ HeatResourcesTypes.CONTRAIL_VIRTUAL_NETWORK_RESOURCE_TYPE.getHeatResource(),
+ HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_NETWORK_RESOURCE_TYPE.getHeatResource());
+ if (attachedResourceId.isGetResource()) {
+ Resource networkHeatResource = translateTo.getHeatOrchestrationTemplate().getResources()
+ .get(attachedResourceId.getEntityId());
+ if (validateResourceTypeSupportedForReqCreation(translateTo, supportedNetworkTypes,
+ networkHeatResource, "network'\\'network_id")) {
+ return;
+ }
+ networkTranslatedId = (String) attachedResourceId.getTranslatedId();
+ addRequirementAssignment(nodeTemplate, networkTranslatedId);
+ } else if (attachedResourceId.isGetParam()) {
+ TranslatedHeatResource translatedSharedResourceId =
+ translateTo.getContext().getHeatSharedResourcesByParam()
+ .get(attachedResourceId.getEntityId());
+ if (Objects.nonNull(translatedSharedResourceId)
+ && !HeatToToscaUtil.isHeatFileNested(translateTo, translateTo.getHeatFileName())) {
+ if (validateResourceTypeSupportedForReqCreation(translateTo, supportedNetworkTypes,
+ translatedSharedResourceId.getHeatResource(), "network'\\'network_id")) {
+ return;
+ }
+ addRequirementAssignment(nodeTemplate, translatedSharedResourceId.getTranslatedId());
+ }
+ }
+ }
+
+ private void addRequirementAssignment(NodeTemplate nodeTemplate, String translatedId) {
+ RequirementAssignment requirement = new RequirementAssignment();
+ requirement.setCapability(ToscaCapabilityType.NETWORK_LINKABLE.getDisplayName());
+ requirement.setRelationship(ToscaRelationshipType.NETWORK_LINK_TO.getDisplayName());
+ requirement.setNode(translatedId);
+ DataModelUtil
+ .addRequirementAssignment(nodeTemplate, ToscaConstants.LINK_REQUIREMENT_ID, requirement);
+ }
+
+
+ private boolean validateResourceTypeSupportedForReqCreation(TranslateTo translateTo,
+ List<String> supportedTypes,
+ Resource heatResource,
+ final String propertyName) {
+ if (!isResourceTypeValidForRequirement(heatResource, supportedTypes)) {
+ logger.warn(
+ "'" + propertyName + "' property of port resource('" + translateTo.getResourceId()
+ + "') is pointing to a resource of type '" + heatResource.getType() + "' "
+ + "which is not supported for this requirement. "
+ + "Supported types are: " + supportedTypes.toString());
+ return true;
+ }
+ return false;
+ }
+
+ private boolean isResourceTypeValidForRequirement(Resource networkHeatResource,
+ List<String> supportedNetworkTypes) {
+ return Objects.nonNull(networkHeatResource)
+ && supportedNetworkTypes.contains(networkHeatResource.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/ResourceTranslationNeutronSecurityGroupImpl.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationNeutronSecurityGroupImpl.java
new file mode 100644
index 0000000000..cacaf4c5c7
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationNeutronSecurityGroupImpl.java
@@ -0,0 +1,47 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca.impl;
+
+import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
+import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate;
+import org.openecomp.sdc.tosca.services.DataModelUtil;
+import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo;
+import org.openecomp.sdc.translator.services.heattotosca.mapping.TranslatorHeatToToscaPropertyConverter;
+
+public class ResourceTranslationNeutronSecurityGroupImpl extends ResourceTranslationBase {
+
+ @Override
+ public void translate(TranslateTo translateTo) {
+
+ NodeTemplate nodeTemplate = new NodeTemplate();
+ nodeTemplate.setType(ToscaNodeType.NEUTRON_SECURITY_RULES.getDisplayName());
+ nodeTemplate.setProperties(TranslatorHeatToToscaPropertyConverter
+ .getToscaPropertiesSimpleConversion(translateTo.getResource().getProperties(),
+ nodeTemplate.getProperties(), translateTo.getHeatFileName(),
+ translateTo.getHeatOrchestrationTemplate(), translateTo.getResource().getType(),
+ nodeTemplate, translateTo.getContext()));
+
+ DataModelUtil.addNodeTemplate(translateTo.getServiceTemplate(), translateTo.getTranslatedId(),
+ nodeTemplate);
+ }
+
+
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationNeutronSubnetImpl.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationNeutronSubnetImpl.java
new file mode 100644
index 0000000000..8306f57146
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationNeutronSubnetImpl.java
@@ -0,0 +1,170 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca.impl;
+
+import org.openecomp.sdc.common.errors.CoreException;
+import org.openecomp.sdc.heat.datatypes.HeatBoolean;
+import org.openecomp.sdc.heat.datatypes.model.Resource;
+import org.openecomp.sdc.tosca.datatypes.ToscaFunctions;
+import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate;
+import org.openecomp.sdc.tosca.datatypes.model.ParameterDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.PropertyType;
+import org.openecomp.sdc.tosca.services.DataModelUtil;
+import org.openecomp.sdc.tosca.services.ToscaConstants;
+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.ResourceTranslationFactory;
+import org.openecomp.sdc.translator.services.heattotosca.errors.MissingMandatoryPropertyErrorBuilder;
+import org.openecomp.sdc.translator.services.heattotosca.mapping.TranslatorHeatToToscaPropertyConverter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+
+public class ResourceTranslationNeutronSubnetImpl extends ResourceTranslationBase {
+ protected static Logger logger =
+ LoggerFactory.getLogger(ResourceTranslationNeutronSubnetImpl.class);
+
+ @Override
+ protected String generateTranslatedId(TranslateTo translateTo) {
+ Optional<AttachedResourceId> subnetNetwork = getAttachedNetworkResource(translateTo);
+
+ if (!subnetNetwork.get().isGetResource()) {
+ logger.warn("Heat resource: '" + translateTo.getResourceId() + "' with type: '"
+ + translateTo.getResource().getType()
+ + "' include 'network_id/'network'' property without 'get_resource' function,"
+ + " therefore this resource will be ignored in TOSCA translation.");
+ return null;
+ }
+ return (String) subnetNetwork.get().getTranslatedId();
+ }
+
+ @Override
+ public void translate(TranslateTo translateTo) {
+
+ Optional<AttachedResourceId> subnetNetwork = getAttachedNetworkResource(translateTo);
+
+ if (!subnetNetwork.get().isGetResource()) {
+ return;
+ }
+
+ Resource networkResource = HeatToToscaUtil
+ .getResource(translateTo.getHeatOrchestrationTemplate(),
+ (String) subnetNetwork.get().getEntityId(), translateTo.getHeatFileName());
+ Optional<String> translatedNetworkId = ResourceTranslationFactory.getInstance(networkResource)
+ .translateResource(translateTo.getHeatFileName(), translateTo.getServiceTemplate(),
+ translateTo.getHeatOrchestrationTemplate(), networkResource,
+ (String) subnetNetwork.get().getEntityId(), translateTo.getContext());
+ if (translatedNetworkId.isPresent()) {
+ NodeTemplate networkNodeTemplate = DataModelUtil
+ .getNodeTemplate(translateTo.getServiceTemplate(), translatedNetworkId.get());
+
+ Map<String, Map<String, Object>> subNetMap =
+ (Map<String, Map<String, Object>>) networkNodeTemplate.getProperties().get("subnets");
+ if (subNetMap == null) {
+ subNetMap = new HashMap<>();
+ networkNodeTemplate.getProperties().put("subnets", subNetMap);
+ TranslatorHeatToToscaPropertyConverter
+ .setSimpleProperty(translateTo.getResource().getProperties(),
+ translateTo.getHeatFileName(), translateTo.getResource().getType(),
+ translateTo.getHeatOrchestrationTemplate(), translateTo.getContext(),
+ networkNodeTemplate.getProperties(), "enable_dhcp",
+ ToscaConstants.DHCP_ENABLED_PROPERTY_NAME, networkNodeTemplate); //dhcp_enabled
+ TranslatorHeatToToscaPropertyConverter
+ .setSimpleProperty(translateTo.getResource().getProperties(),
+ translateTo.getHeatFileName(), translateTo.getResource().getType(),
+ translateTo.getHeatOrchestrationTemplate(), translateTo.getContext(),
+ networkNodeTemplate.getProperties(), "ip_version", null, networkNodeTemplate);
+ handleDhcpProperty(translateTo, networkNodeTemplate);
+ }
+
+ Map<String, Object> properties;
+ properties = TranslatorHeatToToscaPropertyConverter
+ .getToscaPropertiesSimpleConversion(translateTo.getResource().getProperties(), null,
+ translateTo.getHeatFileName(), translateTo.getHeatOrchestrationTemplate(),
+ translateTo.getResource().getType(), networkNodeTemplate, translateTo.getContext());
+
+ subNetMap.put(translateTo.getResourceId(), properties);
+ }
+ }
+
+ private void handleDhcpProperty(TranslateTo translateTo, NodeTemplate networkNodeTemplate) {
+ Object dhcpEnabled =
+ networkNodeTemplate.getProperties().get(ToscaConstants.DHCP_ENABLED_PROPERTY_NAME);
+ if (dhcpEnabled instanceof Map) {
+ Object dhcpEnabledParameterName =
+ ((Map) dhcpEnabled).get(ToscaFunctions.GET_INPUT.getDisplayName());
+ if (dhcpEnabledParameterName != null) {
+ ParameterDefinition dhcpParameterDefinition = null;
+ if (translateTo.getServiceTemplate().getTopology_template().getInputs() != null) {
+ dhcpParameterDefinition =
+ translateTo.getServiceTemplate().getTopology_template().getInputs()
+ .get(dhcpEnabledParameterName);
+ }
+ if (dhcpParameterDefinition == null) {
+ logger.warn("Missing input parameter " + dhcpEnabledParameterName);
+ } else {
+ Object defaultVal = dhcpParameterDefinition.get_default();
+ if (defaultVal != null) {
+ try {
+ Boolean booleanValue = HeatBoolean.eval(defaultVal);
+ dhcpParameterDefinition.set_default(booleanValue);
+ } catch (CoreException coreException) {
+ //if value is not valid value for boolean set with dhcp_enabled default value = true
+ dhcpParameterDefinition.set_default(true);
+ logger.warn("Parameter '" + dhcpEnabledParameterName + "' used for "
+ + ToscaConstants.DHCP_ENABLED_PROPERTY_NAME
+ + " boolean property, but it's value is not a valid boolean value, therefore "
+ + ToscaConstants.DHCP_ENABLED_PROPERTY_NAME
+ + " property will be set with default value of 'true'.");
+ }
+ dhcpParameterDefinition.setType(PropertyType.BOOLEAN.getDisplayName());
+ }
+ }
+ }
+ }
+ }
+
+ private Optional<AttachedResourceId> getAttachedNetworkResource(TranslateTo translateTo) {
+ Optional<AttachedResourceId> subnetNetwork = Optional.empty();
+ Optional<AttachedResourceId> attachedNetworkId =
+ HeatToToscaUtil.extractAttachedResourceId(translateTo, "network_id");
+ if (!attachedNetworkId.isPresent()) {
+ Optional<AttachedResourceId> attachedNetwork =
+ HeatToToscaUtil.extractAttachedResourceId(translateTo, "network");
+ if (!attachedNetwork.isPresent()) {
+ throw new CoreException(
+ new MissingMandatoryPropertyErrorBuilder("network_id/'network'").build());
+ } else {
+ subnetNetwork = attachedNetwork;
+ }
+ } else {
+ subnetNetwork = attachedNetworkId;
+ }
+ return subnetNetwork;
+ }
+}
+
+
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationNovaServerGroupsImpl.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationNovaServerGroupsImpl.java
new file mode 100644
index 0000000000..7bc0a10957
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationNovaServerGroupsImpl.java
@@ -0,0 +1,119 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca.impl;
+
+import org.apache.commons.collections4.CollectionUtils;
+import org.openecomp.sdc.heat.datatypes.model.Resource;
+import org.openecomp.sdc.tosca.datatypes.ToscaGroupType;
+import org.openecomp.sdc.tosca.datatypes.ToscaPolicyType;
+import org.openecomp.sdc.tosca.datatypes.model.GroupDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.PolicyDefinition;
+import org.openecomp.sdc.tosca.services.DataModelUtil;
+import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo;
+import org.openecomp.sdc.translator.services.heattotosca.mapping.TranslatorHeatToToscaPropertyConverter;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+
+public class ResourceTranslationNovaServerGroupsImpl extends ResourceTranslationBase {
+ private static final String AFFINITY = "affinity";
+ private static final String ANTI_AFFINITY = "anti-affinity";
+ private static List<String> supportedPolicies = Arrays.asList(AFFINITY, ANTI_AFFINITY);
+
+ @Override
+ protected void translate(TranslateTo translateTo) {
+ String resourceId = translateTo.getResourceId();
+ List<String> toscaPolicyTypes = getToscaPolicies(translateTo.getResource(), resourceId);
+ if (!CollectionUtils.isEmpty(toscaPolicyTypes)) {
+ addGroupToTopology(translateTo, resourceId);
+ addPoliciesToTopology(translateTo, resourceId, toscaPolicyTypes);
+ }
+ }
+
+ private void addPoliciesToTopology(TranslateTo translateTo, String resourceId,
+ List<String> toscaPolicyTypes) {
+ logger.info("******** Start creating policies for resource '%s' ********", resourceId);
+ for (int i = 0; i < toscaPolicyTypes.size(); i++) {
+ String policy = toscaPolicyTypes.get(i);
+ logger.info("******** Creating policy '%s' ********", policy);
+ PolicyDefinition policyDefinition = new PolicyDefinition();
+ policyDefinition.setType(policy);
+ policyDefinition.setTargets(Arrays.asList(resourceId));
+ policyDefinition.setProperties(TranslatorHeatToToscaPropertyConverter
+ .getToscaPropertiesSimpleConversion(translateTo.getResource().getProperties(),
+ policyDefinition.getProperties(), translateTo.getHeatFileName(),
+ translateTo.getHeatOrchestrationTemplate(), translateTo.getResource().getType(),
+ policyDefinition, translateTo.getContext()));
+ policyDefinition.getProperties().put(
+ policy.equals(ToscaPolicyType.PLACEMENT_ANTILOCATE.getDisplayName()) ? "container_type"
+ : AFFINITY, "host");
+ String policyId = resourceId + (toscaPolicyTypes.size() > 1 ? i : "");
+ DataModelUtil
+ .addPolicyDefinition(translateTo.getServiceTemplate(), policyId, policyDefinition);
+ logger.info("******** Policy '%s' created ********", policy);
+ }
+
+ logger
+ .info("******** All policies for resource '%s' created successfully ********", resourceId);
+ }
+
+ private void addGroupToTopology(TranslateTo translateTo, String resourceId) {
+ logger.info("******** Start creating group for resource '%s' ********", resourceId);
+ GroupDefinition group = new GroupDefinition();
+ group.setMembers(new ArrayList<>());
+ group.setType(ToscaGroupType.ROOT.getDisplayName());
+ DataModelUtil
+ .addGroupDefinitionToTopologyTemplate(translateTo.getServiceTemplate(), resourceId, group);
+ logger.info("******** Creating group '%s' for resource '%s' ********", resourceId, resourceId);
+ }
+
+ private List<String> getToscaPolicies(Resource resource, String resourceId) {
+
+ Map<String, Object> properties = resource.getProperties();
+ if (Objects.isNull(properties) || Objects.isNull(properties.get("policies"))) {
+ return Arrays.asList(ToscaPolicyType.PLACEMENT_ANTILOCATE.getDisplayName());
+ }
+
+ List policies = (List) properties.get("policies");
+ List<String> retList = new ArrayList<>();
+ policies.forEach(policy -> {
+ if (!supportedPolicies.contains(policy)) {
+ logger.warn("Resource '" + resourceId + "'(" + resource.getType()
+ + ") contains unsupported policy '" + policy.toString()
+ + "'. This resource is been ignored during the translation");
+ } else {
+ retList.add(getToscaPolicyByHotPolicy((String) policy));
+ }
+ });
+ return retList;
+ }
+
+ private String getToscaPolicyByHotPolicy(String name) {
+ if (Objects.equals(name, AFFINITY)) {
+ return ToscaPolicyType.PLACEMENT_COLOCATE.getDisplayName();
+ } else {
+ return ToscaPolicyType.PLACEMENT_ANTILOCATE.getDisplayName();
+ }
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationNovaServerImpl.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationNovaServerImpl.java
new file mode 100644
index 0000000000..59e0691b2b
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationNovaServerImpl.java
@@ -0,0 +1,419 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca.impl;
+
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.collections4.MapUtils;
+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.tosca.datatypes.ToscaCapabilityType;
+import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
+import org.openecomp.sdc.tosca.datatypes.ToscaRelationshipType;
+import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate;
+import org.openecomp.sdc.tosca.datatypes.model.NodeType;
+import org.openecomp.sdc.tosca.datatypes.model.RelationshipTemplate;
+import org.openecomp.sdc.tosca.datatypes.model.RequirementAssignment;
+import org.openecomp.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.AttachedResourceId;
+import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo;
+import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslatedHeatResource;
+import org.openecomp.sdc.translator.services.heattotosca.Constants;
+import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil;
+import org.openecomp.sdc.translator.services.heattotosca.ResourceTranslationFactory;
+import org.openecomp.sdc.translator.services.heattotosca.TranslationContext;
+import org.openecomp.sdc.translator.services.heattotosca.helper.NameExtractorService;
+import org.openecomp.sdc.translator.services.heattotosca.helper.PropertyRegexMatcher;
+import org.openecomp.sdc.translator.services.heattotosca.helper.impl.NameExtractorServiceImpl;
+import org.openecomp.sdc.translator.services.heattotosca.mapping.TranslatorHeatToToscaPropertyConverter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+
+public class ResourceTranslationNovaServerImpl extends ResourceTranslationBase {
+ protected static Logger logger = LoggerFactory.getLogger(ResourceTranslationNovaServerImpl.class);
+
+ @Override
+ protected void translate(TranslateTo translateTo) {
+ TranslationContext context = translateTo.getContext();
+ Map<String, Object> properties = translateTo.getResource().getProperties();
+ String heatFileName = translateTo.getHeatFileName();
+
+ ServiceTemplate serviceTemplate = translateTo.getServiceTemplate();
+
+ String nodeTypeRef =
+ createLocalNodeType(serviceTemplate, translateTo.getResource().getProperties(),
+ translateTo.getTranslatedId());
+
+ NodeTemplate novaNodeTemplate = new NodeTemplate();
+ novaNodeTemplate.setType(nodeTypeRef);
+ HeatOrchestrationTemplate heatOrchestrationTemplate =
+ translateTo.getHeatOrchestrationTemplate();
+ novaNodeTemplate.setProperties(TranslatorHeatToToscaPropertyConverter
+ .getToscaPropertiesSimpleConversion(properties, novaNodeTemplate.getProperties(),
+ heatFileName, heatOrchestrationTemplate, translateTo.getResource().getType(),
+ novaNodeTemplate, context));
+
+ manageNovaServerNetwork(heatFileName, serviceTemplate, heatOrchestrationTemplate,
+ translateTo.getResource(), translateTo.getTranslatedId(), context, novaNodeTemplate);
+ manageNovaServerBlockDeviceMapping(heatFileName, serviceTemplate, novaNodeTemplate,
+ heatOrchestrationTemplate, translateTo.getResource(), translateTo.getResourceId(),
+ translateTo.getTranslatedId(), context);
+
+ manageNovaServerGroupMapping(translateTo, context, properties, heatFileName, serviceTemplate,
+ heatOrchestrationTemplate);
+ DataModelUtil.addNodeTemplate(serviceTemplate, translateTo.getTranslatedId(), novaNodeTemplate);
+ }
+
+ private void manageNovaServerGroupMapping(TranslateTo translateTo, TranslationContext context,
+ Map<String, Object> properties, String heatFileName,
+ ServiceTemplate serviceTemplate,
+ HeatOrchestrationTemplate heatOrchestrationTemplate) {
+ if (isSchedulerHintsPropExist(properties)) {
+ Object schedulerHints = properties.get("scheduler_hints");
+ if (schedulerHints instanceof Map) {
+ addServerGroupHintsToPoliciesProups(translateTo, context, heatFileName, serviceTemplate,
+ heatOrchestrationTemplate, (Map<String, Object>) schedulerHints);
+ } else {
+ logger.warn("'scheduler_hints' property of resource '" + translateTo.getResourceId()
+ + "' is not valid. This property should be a map");
+ }
+ }
+ }
+
+ private void addServerGroupHintsToPoliciesProups(TranslateTo translateTo,
+ TranslationContext context, String heatFileName,
+ ServiceTemplate serviceTemplate,
+ HeatOrchestrationTemplate heatOrchestrationTemplate,
+ Map<String, Object> schedulerHints) {
+ for (Object hint : schedulerHints.values()) {
+ Optional<AttachedResourceId> attachedResourceId = HeatToToscaUtil
+ .extractAttachedResourceId(heatFileName, heatOrchestrationTemplate, context, hint);
+ if (attachedResourceId.isPresent()) {
+ AttachedResourceId serverGroupResourceId = attachedResourceId.get();
+ Object serverGroupResourceToTranslate = serverGroupResourceId.getEntityId();
+ if (serverGroupResourceId.isGetResource()) {
+ boolean isHintOfTypeNovaServerGroup =
+ isHintOfTypeNovaServerGroup(heatOrchestrationTemplate,
+ serverGroupResourceToTranslate);
+ if (isHintOfTypeNovaServerGroup) {
+ addNovaServerToPolicyGroup(translateTo, context, heatFileName, serviceTemplate,
+ heatOrchestrationTemplate, (String) serverGroupResourceToTranslate);
+ }
+ } else if (serverGroupResourceId.isGetParam()) {
+ TranslatedHeatResource translatedServerGroupResource =
+ context.getHeatSharedResourcesByParam().get(serverGroupResourceToTranslate);
+ if (Objects.nonNull(translatedServerGroupResource)
+ && !HeatToToscaUtil.isHeatFileNested(translateTo, translateTo.getHeatFileName())) {
+ serviceTemplate.getTopology_template().getGroups()
+ .get(translatedServerGroupResource.getTranslatedId()).getMembers()
+ .add(translateTo.getTranslatedId());
+ }
+ }
+ }
+ }
+ }
+
+ private boolean isHintOfTypeNovaServerGroup(HeatOrchestrationTemplate heatOrchestrationTemplate,
+ Object resourceToTranslate) {
+ return heatOrchestrationTemplate.getResources().get(resourceToTranslate).getType()
+ .equals(HeatResourcesTypes.NOVA_SERVER_GROUP_RESOURCE_TYPE.getHeatResource());
+ }
+
+ private void addNovaServerToPolicyGroup(TranslateTo translateTo, TranslationContext context,
+ String heatFileName, ServiceTemplate serviceTemplate,
+ HeatOrchestrationTemplate heatOrchestrationTemplate,
+ String resourceToTranslate) {
+ Resource serverGroup =
+ HeatToToscaUtil.getResource(heatOrchestrationTemplate, resourceToTranslate, heatFileName);
+ Optional<String> serverGroupTranslatedId = ResourceTranslationFactory.getInstance(serverGroup)
+ .translateResource(heatFileName, serviceTemplate, heatOrchestrationTemplate, serverGroup,
+ resourceToTranslate, context);
+ if (serverGroupTranslatedId.isPresent()) {
+ serviceTemplate.getTopology_template().getGroups().get(serverGroupTranslatedId.get())
+ .getMembers().add(translateTo.getTranslatedId());
+ }
+ }
+
+ private boolean isSchedulerHintsPropExist(Map<String, Object> properties) {
+ return !MapUtils.isEmpty(properties) && Objects.nonNull(properties.get("scheduler_hints"));
+ }
+
+ private void manageNovaServerBlockDeviceMapping(String heatFileName,
+ ServiceTemplate serviceTemplate,
+ NodeTemplate novaNodeTemplate,
+ HeatOrchestrationTemplate heatOrchestrationTemplate,
+ Resource resource, String resourceId,
+ String novaServerTranslatedId,
+ TranslationContext context) {
+
+ List<Map<String, Object>> blockDeviceMappingList = getBlockDeviceMappingList(resource);
+ if (CollectionUtils.isEmpty(blockDeviceMappingList)) {
+ return;
+ }
+
+ Object volumeIdObject;
+ Object snapshotIdObject;
+ String volumeResourceId;
+ int index = 0;
+ for (Map<String, Object> blockDeviceMapping : blockDeviceMappingList) {
+ volumeIdObject = blockDeviceMapping.get("volume_id");
+ snapshotIdObject = blockDeviceMapping.get("snapshot_id");
+
+ if (volumeIdObject == null && snapshotIdObject == null) {
+ logger.warn("Resource '" + resourceId
+ + "' has block_device_mapping property with empty/missing volume_id and snapshot_id "
+ + "properties. Entry number "
+ + (index + 1) + ", this entry will be ignored in TOSCA translation.");
+ index++;
+ continue;
+ }
+ if (volumeIdObject == null) {
+ String deviceName = (String) blockDeviceMapping.get("device_name");
+ String relationshipId = novaServerTranslatedId + "_" + index;
+
+ Optional<AttachedResourceId> attachedSnapshotId = HeatToToscaUtil
+ .extractAttachedResourceId(heatFileName, heatOrchestrationTemplate, context,
+ snapshotIdObject);
+ volumeResourceId = novaServerTranslatedId + "_" + attachedSnapshotId.get().getEntityId();
+ createVolumeAttachesToRelationship(serviceTemplate, deviceName, novaServerTranslatedId,
+ volumeResourceId, relationshipId);
+ createCinderVolumeNodeTemplate(serviceTemplate, volumeResourceId, heatFileName,
+ blockDeviceMapping, heatOrchestrationTemplate, context);
+ connectNovaServerToVolume(novaNodeTemplate, volumeResourceId, relationshipId);
+ } else {
+ Optional<AttachedResourceId> attachedVolumeId = HeatToToscaUtil
+ .extractAttachedResourceId(heatFileName, heatOrchestrationTemplate, context,
+ volumeIdObject);
+ if (attachedVolumeId.get().isGetResource()) {
+ connectNovaServerToVolume(novaNodeTemplate,
+ (String) attachedVolumeId.get().getTranslatedId(), null);
+ }
+ }
+ index++;
+ }
+ }
+
+ private void connectNovaServerToVolume(NodeTemplate novaNodeTemplate, String volumeResourceId,
+ String relationshipId) {
+ RequirementAssignment requirementAssignment = new RequirementAssignment();
+ requirementAssignment.setCapability(ToscaCapabilityType.ATTACHMENT.getDisplayName());
+ requirementAssignment.setNode(volumeResourceId);
+ if (relationshipId != null) {
+ requirementAssignment.setRelationship(relationshipId);
+ } else {
+ requirementAssignment
+ .setRelationship(ToscaRelationshipType.NATIVE_ATTACHES_TO.getDisplayName());
+ }
+ DataModelUtil
+ .addRequirementAssignment(novaNodeTemplate, ToscaConstants.LOCAL_STORAGE_REQUIREMENT_ID,
+ requirementAssignment);
+ }
+
+ private void createCinderVolumeNodeTemplate(ServiceTemplate serviceTemplate,
+ String volumeResourceId, String heatFileName,
+ Map<String, Object> blockDeviceMapping,
+ HeatOrchestrationTemplate heatOrchestrationTemplate,
+ TranslationContext context) {
+ NodeTemplate cinderVolumeNodeTemplate = new NodeTemplate();
+ cinderVolumeNodeTemplate.setType(ToscaNodeType.CINDER_VOLUME.getDisplayName());
+ cinderVolumeNodeTemplate.setProperties(TranslatorHeatToToscaPropertyConverter
+ .getToscaPropertiesSimpleConversion(blockDeviceMapping, null, heatFileName,
+ heatOrchestrationTemplate,
+ HeatResourcesTypes.CINDER_VOLUME_RESOURCE_TYPE.getHeatResource(),
+ cinderVolumeNodeTemplate, context));
+ DataModelUtil.addNodeTemplate(serviceTemplate, volumeResourceId, cinderVolumeNodeTemplate);
+ }
+
+ private void createVolumeAttachesToRelationship(ServiceTemplate serviceTemplate,
+ String deviceName, String novaServerTranslatedId,
+ String volumeId, String relationshipId) {
+ RelationshipTemplate relationshipTemplate = new RelationshipTemplate();
+ relationshipTemplate.setType(ToscaRelationshipType.CINDER_VOLUME_ATTACHES_TO.getDisplayName());
+ Map<String, Object> properties = new HashMap<>();
+ properties.put("instance_uuid", novaServerTranslatedId);
+ properties.put("volume_id", volumeId);
+ if (deviceName != null) {
+ properties.put("device", deviceName);
+ }
+ relationshipTemplate.setProperties(properties);
+
+ DataModelUtil.addRelationshipTemplate(serviceTemplate, relationshipId, relationshipTemplate);
+ }
+
+ private List<Map<String, Object>> getBlockDeviceMappingList(Resource resource) {
+
+ if (Objects.isNull(resource.getProperties())) {
+ return Collections.emptyList();
+ }
+ List<Map<String, Object>> blockDeviceMappingList =
+ (List<Map<String, Object>>) resource.getProperties().get("block_device_mapping");
+ List<Map<String, Object>> blockDeviceMappingV2List =
+ (List<Map<String, Object>>) resource.getProperties().get("block_device_mapping_v2");
+
+ if (blockDeviceMappingList != null && blockDeviceMappingV2List != null) {
+ blockDeviceMappingList.addAll(blockDeviceMappingV2List);
+ } else if (CollectionUtils.isEmpty(blockDeviceMappingList)
+ && CollectionUtils.isEmpty(blockDeviceMappingV2List)) {
+ return null;
+
+ } else {
+ blockDeviceMappingList =
+ blockDeviceMappingList != null ? blockDeviceMappingList : blockDeviceMappingV2List;
+ }
+ return blockDeviceMappingList;
+ }
+
+ private void manageNovaServerNetwork(String heatFileName, ServiceTemplate serviceTemplate,
+ HeatOrchestrationTemplate heatOrchestrationTemplate,
+ Resource resource, String translatedId,
+ TranslationContext context, NodeTemplate novaNodeTemplate) {
+
+ if (resource.getProperties() == null) {
+ return;
+ }
+ List<Map<String, Object>> heatNetworkList =
+ (List<Map<String, Object>>) resource.getProperties().get("networks");
+
+ if (CollectionUtils.isEmpty(heatNetworkList)) {
+ return;
+ }
+
+ for (Map<String, Object> heatNetwork : heatNetworkList) {
+ getOrTranslatePortTemplate(heatFileName, heatOrchestrationTemplate,
+ heatNetwork.get(Constants.PORT_PROPERTY_NAME), serviceTemplate, translatedId, context,
+ novaNodeTemplate);
+ }
+
+ }
+
+ private void getOrTranslatePortTemplate(String heatFileName,
+ HeatOrchestrationTemplate heatOrchestrationTemplate,
+ Object port, ServiceTemplate serviceTemplate,
+ String novaServerResourceId, TranslationContext context,
+ NodeTemplate novaNodeTemplate) {
+ Optional<AttachedResourceId> attachedPortId = HeatToToscaUtil
+ .extractAttachedResourceId(heatFileName, heatOrchestrationTemplate, context, port);
+
+ if (!attachedPortId.isPresent()) {
+ return;
+ }
+
+ if (attachedPortId.get().isGetResource()) {
+ String resourceId = (String) attachedPortId.get().getEntityId();
+ Resource portResource =
+ HeatToToscaUtil.getResource(heatOrchestrationTemplate, resourceId, heatFileName);
+ if (!Arrays.asList(HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource(),
+ HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource())
+ .contains(portResource.getType())) {
+ logger.warn("NovaServer connect to port resource with id : " + resourceId + " and type : "
+ + portResource.getType()
+ + ". This resource type is not supported, therefore the connection to the port is "
+ + "ignored. "
+ + "Supported types are: "
+ + HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource() + ", "
+ + HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE
+ .getHeatResource());
+ return;
+ } else if (HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE
+ .getHeatResource().equals(portResource.getType())) {
+ Map<String, Object> properties = portResource.getProperties();
+ if (!MapUtils.isEmpty(properties) && Objects.nonNull(properties.get("port_tuple_refs"))) {
+ novaNodeTemplate.getProperties().put("contrail_service_instance_ind", true);
+ }
+ }
+ Optional<String> translatedPortId = ResourceTranslationFactory.getInstance(portResource)
+ .translateResource(heatFileName, serviceTemplate, heatOrchestrationTemplate, portResource,
+ resourceId, context);
+ if (translatedPortId.isPresent()) {
+ NodeTemplate portNodeTemplate =
+ DataModelUtil.getNodeTemplate(serviceTemplate, translatedPortId.get());
+ addBindingReqFromPortToCompute(novaServerResourceId, portNodeTemplate);
+ } else {
+ logger.warn("NovaServer connect to port resource with id : " + resourceId + " and type : "
+ + portResource.getType()
+ + ". This resource type is not supported, therefore the connection to the port is "
+ + "ignored.");
+ }
+ }
+ }
+
+ /**
+ * Create local node type string.
+ *
+ * @param serviceTemplate the service template
+ * @param properties the properties
+ * @param resourceTranslatedId the resource translated id
+ * @return the string
+ */
+ public String createLocalNodeType(ServiceTemplate serviceTemplate, Map<String, Object> properties,
+ String resourceTranslatedId) {
+ NameExtractorService nodeTypeNameExtractor = new NameExtractorServiceImpl();
+ List<PropertyRegexMatcher> propertyRegexMatchers =
+ getPropertiesAndRegexMatchers(nodeTypeNameExtractor);
+ Optional<String> extractedNodeTypeName = nodeTypeNameExtractor
+ .extractNodeTypeNameByPropertiesPriority(properties, propertyRegexMatchers);
+
+ String nodeTypeName = ToscaConstants.NODES_PREFIX
+ + (extractedNodeTypeName.isPresent() ? extractedNodeTypeName.get()
+ : resourceTranslatedId.replace(".", "_"));
+ if (!isNodeTypeCreated(serviceTemplate, nodeTypeName)) {
+ DataModelUtil.addNodeType(serviceTemplate, nodeTypeName, createNodeType());
+ }
+ return nodeTypeName;
+ }
+
+ private List<PropertyRegexMatcher> getPropertiesAndRegexMatchers(
+ NameExtractorService nodeTypeNameExtractor) {
+ List<PropertyRegexMatcher> propertyRegexMatchers = new ArrayList<>();
+ propertyRegexMatchers.add(nodeTypeNameExtractor
+ .getPropertyRegexMatcher(Constants.NAME_PROPERTY_NAME,
+ Arrays.asList(".+_name$", ".+_names$", ".+_name_[0-9]+"), "_name"));
+ propertyRegexMatchers.add(nodeTypeNameExtractor
+ .getPropertyRegexMatcher("image", Collections.singletonList(".+_image_name$"),
+ "_image_name"));
+ propertyRegexMatchers.add(nodeTypeNameExtractor
+ .getPropertyRegexMatcher("flavor", Collections.singletonList(".+_flavor_name$"),
+ "_flavor_name"));
+ return propertyRegexMatchers;
+ }
+
+ private boolean isNodeTypeCreated(ServiceTemplate serviceTemplate, String nodeTypeName) {
+ return !MapUtils.isEmpty(serviceTemplate.getNode_types())
+ && Objects.nonNull(serviceTemplate.getNode_types().get(nodeTypeName));
+ }
+
+ private NodeType createNodeType() {
+ NodeType nodeType = new NodeType();
+ nodeType.setDerived_from(ToscaNodeType.NOVA_SERVER.getDisplayName());
+ return nodeType;
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationResourceGroupImpl.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationResourceGroupImpl.java
new file mode 100644
index 0000000000..4665249351
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/ResourceTranslationResourceGroupImpl.java
@@ -0,0 +1,202 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca.impl;
+
+import org.openecomp.sdc.common.errors.CoreException;
+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.ToscaFunctions;
+import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate;
+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.services.heattotosca.HeatToToscaUtil;
+import org.openecomp.sdc.translator.services.heattotosca.ResourceTranslationFactory;
+import org.openecomp.sdc.translator.services.heattotosca.errors.InvalidPropertyValueErrorBuilder;
+import org.openecomp.sdc.translator.services.heattotosca.mapping.TranslatorHeatToToscaPropertyConverter;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+public class ResourceTranslationResourceGroupImpl extends ResourceTranslationBase {
+
+ @Override
+ protected void translate(TranslateTo translateTo) {
+ final String heatFileName = translateTo.getHeatFileName();
+ Object resourceDef =
+ translateTo.getResource().getProperties().get(HeatConstants.RESOURCE_DEF_PROPERTY_NAME);
+ Resource nestedResource = new Resource();
+ Object typeDefinition = ((Map) resourceDef).get("type");
+ if (!(typeDefinition instanceof String)) {
+ logger.warn("Resource '" + translateTo.getResourceId() + "' of type'"
+ + HeatResourcesTypes.RESOURCE_GROUP_RESOURCE_TYPE.getHeatResource()
+ + "' with resourceDef which is not pointing to nested heat file "
+ + "is not supported and will be ignored in the translation ");
+ return;
+ }
+ String type = (String) typeDefinition;
+ if (!HeatToToscaUtil.isYmlFileType(type)) {
+ logger.warn("Resource '" + translateTo.getResourceId() + "' of type'"
+ + HeatResourcesTypes.RESOURCE_GROUP_RESOURCE_TYPE.getHeatResource()
+ + "' with resourceDef which is not pointing to nested heat "
+ + "file is not supported and will be ignored in the translation ");
+ return;
+ }
+
+ nestedResource.setType(type);
+ nestedResource.setProperties((Map<String, Object>) ((Map) resourceDef).get("properties"));
+ nestedResource.setMetadata(((Map) resourceDef).get("metadata"));
+
+ Optional<String> substitutionNodeTemplateId =
+ ResourceTranslationFactory.getInstance(nestedResource)
+ .translateResource(heatFileName, translateTo.getServiceTemplate(),
+ translateTo.getHeatOrchestrationTemplate(), nestedResource,
+ translateTo.getResourceId(), translateTo.getContext());
+ if (substitutionNodeTemplateId.isPresent()) {
+ NodeTemplate substitutionNodeTemplate = DataModelUtil
+ .getNodeTemplate(translateTo.getServiceTemplate(), substitutionNodeTemplateId.get());
+ Map serviceTemplateFilter = (Map<String, Object>) substitutionNodeTemplate.getProperties()
+ .get(ToscaConstants.SERVICE_TEMPLATE_FILTER_PROPERTY_NAME);
+
+ populateServiceTemplateFilterProperties(translateTo, substitutionNodeTemplate,
+ serviceTemplateFilter);
+ handlingIndexVar(translateTo, substitutionNodeTemplate);
+ DataModelUtil
+ .addNodeTemplate(translateTo.getServiceTemplate(), substitutionNodeTemplateId.get(),
+ substitutionNodeTemplate);
+ }
+
+ }
+
+ private void handlingIndexVar(TranslateTo translateTo, NodeTemplate substitutionNodeTemplate) {
+ String indexVarValue = getIndexVarValue(translateTo);
+ replacePropertiesIndexVarValue(indexVarValue, substitutionNodeTemplate.getProperties());
+ }
+
+ private Map<String, List> getNewIndexVarValue() {
+ final Map<String, List> newIndexVarValue = new HashMap<>();
+ List indexVarValList = new ArrayList<>();
+ indexVarValList.add(ToscaConstants.MODELABLE_ENTITY_NAME_SELF);
+ indexVarValList.add(ToscaConstants.SERVICE_TEMPLATE_FILTER_PROPERTY_NAME);
+ indexVarValList.add(ToscaConstants.INDEX_VALUE_PROPERTY_NAME);
+ newIndexVarValue.put(ToscaFunctions.GET_PROPERTY.getDisplayName(), indexVarValList);
+ return newIndexVarValue;
+ }
+
+ private void replacePropertiesIndexVarValue(String indexVarValue,
+ Map<String, Object> properties) {
+ if (properties == null || properties.isEmpty()) {
+ return;
+ }
+
+ for (Map.Entry<String, Object> propertyEntry : properties.entrySet()) {
+ Object propertyValue = propertyEntry.getValue();
+ Object newPropertyValue = getUpdatedPropertyValueWithIndex(indexVarValue, propertyValue);
+ if (newPropertyValue != null) {
+ properties.put(propertyEntry.getKey(), newPropertyValue);
+ }
+ }
+ }
+
+ private Object getUpdatedPropertyValueWithIndex(String indexVarValue, Object propertyValue) {
+ if (propertyValue instanceof String && propertyValue != null) {
+ if (propertyValue.equals(indexVarValue)) {
+ return getNewIndexVarValue();
+ }
+ if (((String) propertyValue).contains(indexVarValue)) {
+ Map<String, List<Object>> concatMap = new HashMap<>();
+ List<Object> concatList = new ArrayList<>();
+ String value = (String) propertyValue;
+
+ while (value.contains(indexVarValue)) {
+ if (value.indexOf(indexVarValue) == 0) {
+ concatList.add(getNewIndexVarValue());
+ value = value.substring(indexVarValue.length());
+ } else {
+ int end = value.indexOf(indexVarValue);
+ concatList.add(value.substring(0, end));
+ value = value.substring(end);
+ }
+ }
+ if (!value.isEmpty()) {
+ concatList.add(value);
+ }
+
+ concatMap.put(ToscaFunctions.CONCAT.getDisplayName(), concatList);
+ return concatMap;
+ }
+ return propertyValue; //no update is needed
+ } else if (propertyValue instanceof Map && !((Map) propertyValue).isEmpty()) {
+ replacePropertiesIndexVarValue(indexVarValue, (Map<String, Object>) propertyValue);
+ return propertyValue;
+ } else if (propertyValue instanceof List && !((List) propertyValue).isEmpty()) {
+ List newPropertyValueList = new ArrayList<>();
+ for (Object entry : ((List) propertyValue)) {
+ newPropertyValueList.add(getUpdatedPropertyValueWithIndex(indexVarValue, entry));
+ }
+ return newPropertyValueList;
+ }
+ return propertyValue;
+ }
+
+ private String getIndexVarValue(TranslateTo translateTo) {
+ Object indexVar =
+ translateTo.getResource().getProperties().get(HeatConstants.INDEX_PROPERTY_NAME);
+ if (indexVar == null) {
+ return HeatConstants.RESOURCE_GROUP_INDEX_VAR_DEFAULT_VALUE;
+ }
+
+ if (indexVar instanceof String) {
+ return (String) indexVar;
+ } else {
+ throw new CoreException(
+ new InvalidPropertyValueErrorBuilder("index_var", indexVar.toString(), "String").build());
+ }
+ }
+
+ private void populateServiceTemplateFilterProperties(TranslateTo translateTo,
+ NodeTemplate substitutionNodeTemplate,
+ Map serviceTemplateFilter) {
+ boolean mandatory = false;
+ Object countValue = TranslatorHeatToToscaPropertyConverter
+ .getToscaPropertyValue(ToscaConstants.COUNT_PROPERTY_NAME,
+ translateTo.getResource().getProperties().get(ToscaConstants.COUNT_PROPERTY_NAME), null,
+ translateTo.getHeatFileName(), translateTo.getHeatOrchestrationTemplate(),
+ substitutionNodeTemplate, translateTo.getContext());
+
+ if (countValue != null) {
+ serviceTemplateFilter.put(ToscaConstants.COUNT_PROPERTY_NAME, countValue);
+ } else {
+ serviceTemplateFilter.put(ToscaConstants.COUNT_PROPERTY_NAME, 1);
+ }
+ if (countValue instanceof Integer && (Integer) countValue > 0) {
+ mandatory = true;
+ }
+ if (countValue == null) {
+ mandatory = true;
+ }
+ serviceTemplateFilter.put("mandatory", mandatory);
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/SecurityRulesToPortResourceConnection.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/SecurityRulesToPortResourceConnection.java
new file mode 100644
index 0000000000..3c6fef7ffb
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/SecurityRulesToPortResourceConnection.java
@@ -0,0 +1,203 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca.impl;
+
+
+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.tosca.datatypes.ToscaCapabilityType;
+import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
+import org.openecomp.sdc.tosca.datatypes.ToscaRelationshipType;
+import org.openecomp.sdc.tosca.datatypes.model.CapabilityDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate;
+import org.openecomp.sdc.tosca.datatypes.model.NodeType;
+import org.openecomp.sdc.tosca.datatypes.model.RequirementDefinition;
+import org.openecomp.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.AttachedResourceId;
+import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo;
+import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslatedHeatResource;
+import org.openecomp.sdc.translator.services.heattotosca.Constants;
+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.Objects;
+import java.util.Optional;
+import java.util.function.Predicate;
+
+
+class SecurityRulesToPortResourceConnection extends BaseResourceConnection<CapabilityDefinition> {
+ SecurityRulesToPortResourceConnection(ResourceTranslationNestedImpl resourceTranslationNested,
+ TranslateTo translateTo, FileData nestedFileData,
+ NodeTemplate substitutionNodeTemplate, NodeType nodeType) {
+ super(resourceTranslationNested, translateTo, nestedFileData, substitutionNodeTemplate,
+ nodeType);
+ }
+
+ @Override
+ protected boolean isDesiredNodeTemplateType(NodeTemplate nodeTemplate) {
+ return nodeTemplate.getType().equals(ToscaNodeType.NEUTRON_PORT.getDisplayName());
+ }
+
+ @Override
+ protected List<Predicate<CapabilityDefinition>> getPredicatesListForConnectionPoints() {
+ ArrayList<Predicate<CapabilityDefinition>> predicates = new ArrayList<>();
+ predicates.add(cap -> cap.getType().equals(ToscaCapabilityType.ATTACHMENT.getDisplayName()));
+ return predicates;
+ }
+
+ @Override
+ protected Optional<List<String>> getConnectorParamName(
+ String heatResourceId,Resource heatResource,
+ HeatOrchestrationTemplate nestedHeatOrchestrationTemplate) {
+ Object securityGroups =
+ heatResource.getProperties().get(Constants.SECURITY_GROUPS_PROPERTY_NAME);
+ List<String> paramsList = new ArrayList<>();
+ if (securityGroups instanceof List) {
+ ((List) securityGroups).forEach(group -> {
+ Optional<AttachedResourceId> attachedResourceId = HeatToToscaUtil
+ .extractAttachedResourceId(nestedFileData.getFile(), nestedHeatOrchestrationTemplate,
+ translateTo.getContext(), group);
+ if (attachedResourceId.isPresent()) {
+ paramsList.add((String) attachedResourceId.get().getEntityId());
+ }
+ });
+ return Optional.of(paramsList);
+ }
+ return Optional.empty();
+ }
+
+ @Override
+ protected String getDesiredResourceType() {
+ return HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource();
+ }
+
+ @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;
+ }
+
+ @Override
+ void addRequirementToConnectResources(Map.Entry<String, CapabilityDefinition> entry,
+ List<String> paramNames) {
+ paramNames.forEach(p -> {
+ Optional<AttachedResourceId> attachedResourceId =
+ HeatToToscaUtil.extractAttachedResourceId(translateTo, p);
+ String securityRulesNodeId;
+ if (!attachedResourceId.isPresent()) {
+ return;
+ }
+ Map.Entry<String, RequirementDefinition> requirementDefinition =
+ createRequirementDefinition(entry.getKey());
+ AttachedResourceId securityGroupAttachedId = attachedResourceId.get();
+ if (securityGroupAttachedId.isGetResource()) {
+ String securityGroupResourceId = (String) attachedResourceId.get().getEntityId();
+ Resource securityGroupResource = HeatToToscaUtil
+ .getResource(translateTo.getHeatOrchestrationTemplate(), securityGroupResourceId,
+ translateTo.getHeatFileName());
+ Optional<String> translatedSecurityRuleId =
+ ResourceTranslationFactory.getInstance(securityGroupResource)
+ .translateResource(translateTo.getHeatFileName(), translateTo.getServiceTemplate(),
+ translateTo.getHeatOrchestrationTemplate(), securityGroupResource,
+ securityGroupResourceId, translateTo.getContext());
+ if (translatedSecurityRuleId.isPresent()) {
+ NodeTemplate securityRuleNodeTemplate = DataModelUtil
+ .getNodeTemplate(translateTo.getServiceTemplate(), translatedSecurityRuleId.get());
+ createRequirementAssignment(requirementDefinition, translateTo.getTranslatedId(),
+ securityRuleNodeTemplate);
+ } else {
+ logger.warn(
+ securityGroupResource.getType() + "connection to " + securityGroupResource.getType()
+ + " is not supported/invalid, therefore this connection "
+ + "will be ignored in the TOSCA translation");
+ }
+ } else if (securityGroupAttachedId.isGetParam()) {
+ TranslatedHeatResource shareResource =
+ translateTo.getContext().getHeatSharedResourcesByParam()
+ .get(securityGroupAttachedId.getEntityId());
+ if (Objects.nonNull(shareResource)
+ && !HeatToToscaUtil.isHeatFileNested(translateTo, translateTo.getHeatFileName())) {
+ NodeTemplate sharedNodeTemplate = DataModelUtil
+ .getNodeTemplate(translateTo.getServiceTemplate(), shareResource.getTranslatedId());
+ createRequirementAssignment(requirementDefinition, translateTo.getTranslatedId(),
+ sharedNodeTemplate);
+ }
+ }
+ });
+ }
+
+ @Override
+ protected String getTranslatedResourceIdFromSubstitutionMapping(
+ ServiceTemplate nestedServiceTemplate, Map.Entry<String, CapabilityDefinition> entry) {
+ List<String> substitutionMapping =
+ nestedServiceTemplate.getTopology_template().getSubstitution_mappings().getCapabilities()
+ .get(entry.getKey());
+ return substitutionMapping.get(0);
+ }
+
+ private Map.Entry<String, RequirementDefinition> createRequirementDefinition(String key) {
+ RequirementDefinition definition = new RequirementDefinition();
+ definition.setCapability(key);
+ definition.setRelationship(ToscaRelationshipType.ATTACHES_TO.getDisplayName());
+ return new Map.Entry<String, RequirementDefinition>() {
+ @Override
+ public String getKey() {
+ return ToscaConstants.PORT_REQUIREMENT_ID;
+ }
+
+ @Override
+ public RequirementDefinition getValue() {
+ return definition;
+ }
+
+ @Override
+ public RequirementDefinition setValue(RequirementDefinition value) {
+ return null;
+ }
+ };
+ }
+
+
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/mapping/TranslatorHeatToToscaFunctionConverter.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/mapping/TranslatorHeatToToscaFunctionConverter.java
new file mode 100644
index 0000000000..0aa5c5ff96
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/mapping/TranslatorHeatToToscaFunctionConverter.java
@@ -0,0 +1,410 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca.mapping;
+
+import org.openecomp.core.utilities.yaml.YamlUtil;
+import org.openecomp.sdc.heat.datatypes.HeatBoolean;
+import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate;
+import org.openecomp.sdc.heat.datatypes.model.Resource;
+import org.openecomp.sdc.heat.services.HeatConstants;
+import org.openecomp.sdc.tosca.datatypes.ToscaArtifactType;
+import org.openecomp.sdc.tosca.datatypes.ToscaFunctions;
+import org.openecomp.sdc.tosca.datatypes.model.ArtifactDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate;
+import org.openecomp.sdc.tosca.datatypes.model.Template;
+import org.openecomp.sdc.tosca.services.ToscaConstants;
+import org.openecomp.sdc.tosca.services.ToscaFileOutputService;
+import org.openecomp.sdc.tosca.services.impl.ToscaFileOutputServiceCsarImpl;
+import org.openecomp.sdc.translator.services.heattotosca.Constants;
+import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil;
+import org.openecomp.sdc.translator.services.heattotosca.TranslationContext;
+import org.openecomp.sdc.translator.services.heattotosca.impl.ResourceTranslationBase;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+
+public class TranslatorHeatToToscaFunctionConverter {
+ private static final String UNSUPPORTED_RESOURCE = "UNSUPPORTED_RESOURCE_";
+ private static final String UNSUPPORTED_ATTRIBUTE = "UNSUPPORTED_ATTRIBUTE_";
+
+ protected static Set<String> functionNameSet;
+
+ static {
+ functionNameSet = new HashSet<>();
+ functionNameSet.add("get_param");
+ functionNameSet.add("get_attr");
+ functionNameSet.add("get_resource");
+ functionNameSet.add("get_file");
+ }
+
+ /**
+ * Gets tosca function.
+ *
+ * @param functionName the function name
+ * @param function the function
+ * @param heatFileName the heat file name
+ * @param heatOrchestrationTemplate the heat orchestration template
+ * @param template the template
+ * @param context the context
+ * @return the tosca function
+ */
+ public static Object getToscaFunction(String functionName, Object function, String heatFileName,
+ HeatOrchestrationTemplate heatOrchestrationTemplate,
+ Template template, TranslationContext context) {
+ Object returnValue = null;
+ if ("get_param".equals(functionName)) {
+ returnValue =
+ handleGetParamFunction(function, heatFileName, heatOrchestrationTemplate, context);
+ } else if ("get_attr".equals(functionName)) {
+ returnValue =
+ handleGetAttrFunction(function, heatFileName, heatOrchestrationTemplate, context);
+ } else if ("get_resource".equals(functionName)) {
+ returnValue =
+ handleGetResourceFunction(function, heatFileName, heatOrchestrationTemplate, context);
+ } else if ("get_file".equals(functionName)) {
+ returnValue = handleGetFileFunction(function, template);
+ }
+ return returnValue;
+ }
+
+ private static Object handleGetFileFunction(Object function, Template template) {
+ String file = ((String) function).replace("file:///", "");
+ Object returnValue;
+ final String artifactId = file.split("\\.")[0];
+
+ returnValue = new HashMap<>();
+ List artifactParameters = new ArrayList();
+ artifactParameters.add(0, ToscaConstants.MODELABLE_ENTITY_NAME_SELF);
+ ((Map) returnValue).put(ToscaFunctions.GET_ARTIFACT.getDisplayName(), artifactParameters);
+ artifactParameters.add(1, artifactId);
+
+ ToscaFileOutputService toscaFileOutputService = new ToscaFileOutputServiceCsarImpl();
+ if (template != null) {
+ if (template instanceof NodeTemplate) {
+ NodeTemplate nodeTemplate = (NodeTemplate) template;
+ ArtifactDefinition artifactDefinition =
+ createArtifactDefinition(file, toscaFileOutputService);
+ if (nodeTemplate.getArtifacts() == null) {
+ nodeTemplate.setArtifacts(new HashMap<>());
+ }
+ nodeTemplate.getArtifacts().put(artifactId, artifactDefinition);
+ }
+ }
+ return returnValue;
+ }
+
+ private static Object handleGetResourceFunction(Object function, String heatFileName,
+ HeatOrchestrationTemplate
+ heatOrchestrationTemplate,
+ TranslationContext context) {
+ Object returnValue;
+ Optional<String> resourceTranslatedId = ResourceTranslationBase
+ .getResourceTranslatedId(heatFileName, heatOrchestrationTemplate, (String) function,
+ context);
+ if (resourceTranslatedId.isPresent()) {
+ returnValue = resourceTranslatedId.get();
+ } else {
+ returnValue = UNSUPPORTED_RESOURCE + function;
+ }
+ return returnValue;
+ }
+
+ private static Object handleGetAttrFunction(Object function, String heatFileName,
+ HeatOrchestrationTemplate heatOrchestrationTemplate,
+ TranslationContext context) {
+ Object returnValue = new HashMap<>();
+ List<Object> attributeFunctionExpression =
+ translateGetAttributeFunctionExpression(function, heatFileName, heatOrchestrationTemplate,
+ context);
+ if (isResourceSupported(attributeFunctionExpression.get(0).toString())
+ && isAttributeSupported(attributeFunctionExpression.get(0).toString())) {
+ ((Map) returnValue)
+ .put(ToscaFunctions.GET_ATTRIBUTE.getDisplayName(), attributeFunctionExpression);
+ } else {
+ returnValue = attributeFunctionExpression;
+ }
+ return returnValue;
+ }
+
+ private static Object handleGetParamFunction(Object function, String heatFileName,
+ HeatOrchestrationTemplate heatOrchestrationTemplate,
+ TranslationContext context) {
+ Map returnValue = new HashMap<>();
+ returnValue.put(ToscaFunctions.GET_INPUT.getDisplayName(),
+ translateGetParamFunctionExpression(function, heatFileName, heatOrchestrationTemplate,
+ context));
+ return returnValue;
+ }
+
+ private static ArtifactDefinition createArtifactDefinition(Object function,
+ ToscaFileOutputService
+ toscaFileOutputService) {
+ ArtifactDefinition artifactDefinition = new ArtifactDefinition();
+ artifactDefinition.setType(ToscaArtifactType.DEPLOYMENT.getDisplayName());
+ artifactDefinition
+ .setFile("../" + toscaFileOutputService.getArtifactsFolderName() + "/" + function);
+ return artifactDefinition;
+ }
+
+ private static Object translateGetParamFunctionExpression(Object function, String heatFileName,
+ HeatOrchestrationTemplate
+ heatOrchestrationTemplate,
+ TranslationContext context) {
+ Object returnValue = null;
+ if (function instanceof String) {
+ returnValue = function;
+ } else {
+ if (function instanceof List) {
+ returnValue = new ArrayList<>();
+ for (int i = 0; i < ((List) function).size(); i++) {
+ Object paramValue = ((List) function).get(i);
+ if ((paramValue instanceof Map && !((Map) paramValue).isEmpty())) {
+ Map<String, Object> paramMap = (Map) paramValue;
+ Map.Entry<String, Object> entry = paramMap.entrySet().iterator().next();
+ ((List) returnValue).add(
+ getToscaFunction(entry.getKey(), entry.getValue(), heatFileName,
+ heatOrchestrationTemplate, null, context));
+ } else {
+ ((List) returnValue).add(paramValue);
+ }
+ }
+ }
+ }
+
+ return returnValue;
+ }
+
+ private static List<Object> translateGetAttributeFunctionExpression(
+ Object function,String heatFileName,
+ HeatOrchestrationTemplate heatOrchestrationTemplate,
+ TranslationContext context) {
+ List<String> attributeParamList = (List) function;
+ List<Object> toscaAttributeParamList = new ArrayList<>();
+
+ Optional<String> resourceTranslatedId =
+ handleResourceName(attributeParamList.get(0), heatFileName, heatOrchestrationTemplate,
+ context);
+ if (!resourceTranslatedId.isPresent()) {
+ //unsupported resource
+ toscaAttributeParamList.add(UNSUPPORTED_RESOURCE + attributeParamList.get(0));
+ return toscaAttributeParamList;
+ } else {
+ toscaAttributeParamList.add(resourceTranslatedId.get());
+ }
+
+ Optional<List<Object>> toscaAttList =
+ handleAttributeName(attributeParamList, heatOrchestrationTemplate, heatFileName, context);
+ if (!toscaAttList.isPresent()) {
+ //Unsupported attribute
+ toscaAttributeParamList.clear();
+ toscaAttributeParamList
+ .add(UNSUPPORTED_ATTRIBUTE + attributeParamList.get(0) + "." + attributeParamList.get(1));
+ return toscaAttributeParamList;
+ } else {
+ toscaAttributeParamList.addAll(toscaAttList.get());
+ }
+
+ Optional<List<String>> toscaIndexOrKey = handleAttributeIndexOrKey(attributeParamList);
+ if (toscaIndexOrKey.isPresent()) {
+ toscaAttributeParamList.addAll(toscaIndexOrKey.get());
+ }
+
+ return toscaAttributeParamList;
+ }
+
+ private static Optional<List<String>> handleAttributeIndexOrKey(List<String> attributeParamList) {
+ List<String> attributeIndexOrKey = new ArrayList<>();
+ if (attributeParamList.size() < 2) {
+ return Optional.empty();
+ }
+
+ for (int i = 2; i < attributeParamList.size(); i++) {
+ attributeIndexOrKey.add(attributeParamList.get(i));
+ }
+
+ return Optional.of(attributeIndexOrKey);
+ }
+
+ private static Optional<List<Object>> handleAttributeName(List<String> attributeParamList,
+ HeatOrchestrationTemplate
+ heatOrchestrationTemplate,
+ String heatFileName,
+ TranslationContext context) {
+ String resourceId = attributeParamList.get(0);
+ Resource resource =
+ HeatToToscaUtil.getResource(heatOrchestrationTemplate, resourceId, heatFileName);
+
+ if (attributeParamList.size() == 1) {
+ return getResourceTranslatedAttributesList(resource, context);
+ }
+
+ if (HeatToToscaUtil.isNestedResource(resource)) {
+ return getNestedResourceTranslatedAttribute(attributeParamList.get(1));
+ } else {
+ return getResourceTranslatedAttribute(resource, attributeParamList.get(1), context);
+ }
+ }
+
+ private static Optional<List<Object>> getResourceTranslatedAttribute(Resource resource,
+ String attributeName,
+ TranslationContext context) {
+ List<Object> translatedAttributesList = new ArrayList<>();
+ String translatedAttribute =
+ context.getElementMapping(resource.getType(), Constants.ATTR, attributeName);
+ if (translatedAttribute != null) {
+ translatedAttributesList.add(translatedAttribute);
+ return Optional.of(translatedAttributesList);
+ } else { //unsupported attribute
+ return Optional.empty();
+ }
+ }
+
+ private static Optional<List<Object>> getNestedResourceTranslatedAttribute(String attributeName) {
+ List<Object> translatedAttributesList = new ArrayList<>();
+
+ if (attributeName.startsWith(HeatConstants.GET_ATT_FROM_RESOURCE_GROUP_PREFIX)) {
+ String[] attributeSplit = attributeName.split("\\.");
+ if (attributeSplit.length == 2) {
+ translatedAttributesList.add(attributeSplit[1]);
+ } else if (attributeSplit.length == 3) {
+ translatedAttributesList.add(attributeSplit[2]);
+ translatedAttributesList.add(Integer.valueOf(attributeSplit[1]));
+ } else {
+ return Optional.empty();
+ }
+ } else {
+ translatedAttributesList.add(attributeName);
+ }
+ return Optional.of(translatedAttributesList);
+ }
+
+ private static Optional<List<Object>> getResourceTranslatedAttributesList(Resource resource,
+ TranslationContext
+ context) {
+ List<Object> translatedAttributes = new ArrayList<>();
+ if (HeatToToscaUtil.isNestedResource(resource)) {
+ Optional<String> nestedFile = HeatToToscaUtil.getNestedFile(resource);
+ if (!nestedFile.isPresent()) {
+ return Optional.empty();
+ }
+ HeatOrchestrationTemplate nestedHeatOrchestrationTemplate = new YamlUtil()
+ .yamlToObject(context.getFiles().getFileContent(nestedFile.get()),
+ HeatOrchestrationTemplate.class);
+ translatedAttributes.addAll(nestedHeatOrchestrationTemplate.getOutputs().keySet());
+ return Optional.of(translatedAttributes);
+
+ } else {
+ Map<String, String> resourceMappingAttributes =
+ context.getElementMapping(resource.getType(), Constants.ATTR);
+ Set<String> mappingAttributes = new HashSet<>();
+ mappingAttributes
+ .addAll(resourceMappingAttributes.values().stream().collect(Collectors.toList()));
+ translatedAttributes.addAll(mappingAttributes);
+ return Optional.of(translatedAttributes);
+ }
+ }
+
+ private static Optional<String> handleResourceName(String resourceId, String heatFileName,
+ HeatOrchestrationTemplate
+ heatOrchestrationTemplate,
+ TranslationContext context) {
+ return ResourceTranslationBase
+ .getResourceTranslatedId(heatFileName, heatOrchestrationTemplate, resourceId, context);
+ }
+
+ public static boolean isResourceSupported(String translatedResourceId) {
+ return !translatedResourceId.startsWith(UNSUPPORTED_RESOURCE);
+ }
+
+ public static boolean isAttributeSupported(String translatedAttName) {
+ return !translatedAttName.startsWith(UNSUPPORTED_ATTRIBUTE);
+ }
+
+ /**
+ * Translate fn split function optional.
+ *
+ * @param propertyValue the property value
+ * @param listSize the list size
+ * @param includeBooleanValue the include boolean value
+ * @return the optional
+ */
+ public static Optional<List<Map<String, List>>> translateFnSplitFunction(
+ Object propertyValue,int listSize,
+ boolean includeBooleanValue) {
+ List<Map<String, List>> tokenPropertyValueList = new ArrayList<>();
+
+ if (propertyValue instanceof Map && !((Map) propertyValue).isEmpty()) {
+ Map<String, Object> propMap = (Map) propertyValue;
+ Map.Entry<String, Object> entry = propMap.entrySet().iterator().next();
+ Object entity = entry.getValue();
+ String key = entry.getKey();
+ String tokenChar;
+
+ if (key.equals("Fn::Split") && entity instanceof List) {
+ tokenChar = (String) ((List) entity).get(0);
+ Object refParameter = ((List) entity).get(1);
+
+ for (int substringIndex = 0; substringIndex < listSize; substringIndex++) {
+ Map<String, List> tokenPropertyValue = new HashMap<>();
+ tokenPropertyValue.put("token", new ArrayList<>());
+
+ if (refParameter instanceof Map && ((Map) refParameter).get("Ref") != null) {
+ Map<String, String> stringWithToken = new HashMap<>();
+ ((Map) stringWithToken)
+ .put(ToscaFunctions.GET_INPUT.getDisplayName(), ((Map) refParameter).get("Ref"));
+ tokenPropertyValue.get("token").add(stringWithToken);
+ } else if (refParameter instanceof String) {
+ if (includeBooleanValue) {
+ StringBuffer booleanBuffer = new StringBuffer();
+ String[] booleanValueList = ((String) refParameter).split(tokenChar);
+ for (int i = 0; i < booleanValueList.length; i++) {
+ if (i == 0) {
+ booleanBuffer.append(HeatBoolean.eval(booleanValueList[i]));
+ } else {
+ booleanBuffer.append(tokenChar);
+ booleanBuffer.append(HeatBoolean.eval(booleanValueList[i]));
+ }
+ }
+ tokenPropertyValue.get("token").add(booleanBuffer.toString());
+ } else {
+ tokenPropertyValue.get("token").add(refParameter);
+ }
+ }
+ tokenPropertyValue.get("token").add(tokenChar);
+ tokenPropertyValue.get("token").add(substringIndex);
+ tokenPropertyValueList.add(tokenPropertyValue);
+ }
+
+ return Optional.of(tokenPropertyValueList);
+
+ }
+ }
+
+ 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/mapping/TranslatorHeatToToscaParameterConverter.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/mapping/TranslatorHeatToToscaParameterConverter.java
new file mode 100644
index 0000000000..07ab6d1542
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/mapping/TranslatorHeatToToscaParameterConverter.java
@@ -0,0 +1,271 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca.mapping;
+
+import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate;
+import org.openecomp.sdc.heat.datatypes.model.Output;
+import org.openecomp.sdc.heat.datatypes.model.Parameter;
+import org.openecomp.sdc.tosca.datatypes.model.Constraint;
+import org.openecomp.sdc.tosca.datatypes.model.EntrySchema;
+import org.openecomp.sdc.tosca.datatypes.model.ParameterDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.heatextend.ParameterDefinitionExt;
+import org.openecomp.sdc.translator.services.heattotosca.TranslationContext;
+
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class TranslatorHeatToToscaParameterConverter {
+
+
+ private static Map<String, String> parameterTypeMapping;
+ private static Map<String, String> parameterEntrySchemaTypeMapping;
+
+ static {
+ parameterEntrySchemaTypeMapping = new HashMap<>();
+ parameterEntrySchemaTypeMapping.put("list", "string");
+ }
+
+ static {
+ parameterTypeMapping = new HashMap<>();
+ parameterTypeMapping.put("string", "string");
+ parameterTypeMapping.put("number", "float");
+ parameterTypeMapping.put("comma_delimited_list", "list");
+ parameterTypeMapping.put("json", "json");
+ parameterTypeMapping.put("boolean", "boolean");
+ }
+
+ /**
+ * Parameter converter map.
+ *
+ * @param parameters the parameters
+ * @param heatOrchestrationTemplate the heat orchestration template
+ * @param heatFileName the heat file name
+ * @param context the context
+ * @return the map
+ */
+ public static Map<String, ParameterDefinition> parameterConverter(
+ Map<String, Parameter> parameters, HeatOrchestrationTemplate heatOrchestrationTemplate,
+ String heatFileName, TranslationContext context) {
+ Map<String, ParameterDefinition> parameterDefinitionMap = new HashMap<>();
+ for (Map.Entry<String, Parameter> entry : parameters.entrySet()) {
+ //parameterDefinitionMap.put(entry.getKey()+"_"+ FileUtils
+ // .getFileWithoutExtention(heatFileName),getToscaParameter(entry.getValue(),
+ // heatOrchestrationTemplate, heatFileName, context));
+ parameterDefinitionMap.put(entry.getKey(),
+ getToscaParameter(entry.getValue(), heatOrchestrationTemplate, heatFileName, context));
+ }
+ return parameterDefinitionMap;
+ }
+
+ /**
+ * Parameter output converter map.
+ *
+ * @param parameters the parameters
+ * @param heatOrchestrationTemplate the heat orchestration template
+ * @param heatFileName the heat file name
+ * @param context the context
+ * @return the map
+ */
+ public static Map<String, ParameterDefinition> parameterOutputConverter(
+ Map<String, Output> parameters, HeatOrchestrationTemplate heatOrchestrationTemplate,
+ String heatFileName, TranslationContext context) {
+ Map<String, ParameterDefinition> parameterDefinitionMap = new HashMap<>();
+ for (Map.Entry<String, Output> entry : parameters.entrySet()) {
+ //parameterDefinitionMap.put(entry.getKey()+"_"+FileUtils
+ // .getFileWithoutExtention(heatFileName),getToscaOutputParameter(entry.getValue(),
+ // heatOrchestrationTemplate, heatFileName, context));
+ parameterDefinitionMap.put(entry.getKey(),
+ getToscaOutputParameter(entry.getValue(), heatOrchestrationTemplate, heatFileName,
+ context));
+ }
+ return parameterDefinitionMap;
+ }
+
+ /**
+ * Gets tosca parameter.
+ *
+ * @param heatParameter the heat parameter
+ * @param heatOrchestrationTemplate the heat orchestration template
+ * @param heatFileName the heat file name
+ * @param context the context
+ * @return the tosca parameter
+ */
+ public static ParameterDefinitionExt getToscaParameter(Parameter heatParameter,
+ HeatOrchestrationTemplate
+ heatOrchestrationTemplate,
+ String heatFileName,
+ TranslationContext context) {
+
+ ParameterDefinitionExt toscaParameter = new ParameterDefinitionExt();
+ toscaParameter.setType(getToscaParameterType(heatParameter.getType()));
+ toscaParameter.setEntry_schema(getToscaParameterEntrySchema(toscaParameter.getType()));
+ toscaParameter.setLabel(heatParameter.getLabel());
+ toscaParameter.setDescription(heatParameter.getDescription());
+ toscaParameter.set_default(
+ getToscaParameterDefaultValue(heatParameter.get_default(), toscaParameter.getType(),
+ heatFileName, heatOrchestrationTemplate, context));
+ toscaParameter.setHidden(heatParameter.isHidden());
+ toscaParameter.setImmutable(heatParameter.isImmutable());
+ toscaParameter.setConstraints(getToscaConstrains(heatParameter.getConstraints()));
+ return toscaParameter;
+ }
+
+ /**
+ * Gets tosca output parameter.
+ *
+ * @param heatOutputParameter the heat output parameter
+ * @param heatOrchestrationTemplate the heat orchestration template
+ * @param heatFileName the heat file name
+ * @param context the context
+ * @return the tosca output parameter
+ */
+ public static ParameterDefinitionExt getToscaOutputParameter(Output heatOutputParameter,
+ HeatOrchestrationTemplate
+ heatOrchestrationTemplate,
+ String heatFileName,
+ TranslationContext context) {
+
+ ParameterDefinitionExt toscaParameter = new ParameterDefinitionExt();
+ toscaParameter.setDescription(heatOutputParameter.getDescription());
+ toscaParameter.setValue(
+ getToscaParameterDefaultValue(heatOutputParameter.getValue(), toscaParameter.getType(),
+ heatFileName, heatOrchestrationTemplate, context));
+ return toscaParameter;
+ }
+
+ /**
+ * Gets tosca parameter default value.
+ *
+ * @param defaultObj the a default
+ * @param type the type
+ * @param heatFileName the heat file name
+ * @param heatOrchestrationTemplate the heat orchestration template
+ * @param context the context
+ * @return the tosca parameter default value
+ */
+ public static Object getToscaParameterDefaultValue(Object defaultObj, String type,
+ String heatFileName,
+ HeatOrchestrationTemplate
+ heatOrchestrationTemplate,
+ TranslationContext context) {
+
+ if (defaultObj == null) {
+ return null;
+ }
+ if ("list".equals(type)) {
+ if (defaultObj instanceof String) {
+ return Arrays.asList(((String) defaultObj).split(","));
+ } else {
+ return defaultObj;
+ }
+ }
+
+ return getToscaParameterValue(defaultObj, heatFileName, heatOrchestrationTemplate,
+ context);
+ }
+
+ private static Object getToscaParameterValue(Object paramValue, String heatFileName,
+ HeatOrchestrationTemplate heatOrchestrationTemplate,
+ TranslationContext context) {
+ if (paramValue instanceof Map) {
+ Map.Entry<String, Object> functionMapEntry =
+ (Map.Entry<String, Object>) ((Map) paramValue).entrySet().iterator().next();
+ if (TranslatorHeatToToscaFunctionConverter.functionNameSet
+ .contains(functionMapEntry.getKey())) {
+ return TranslatorHeatToToscaFunctionConverter
+ .getToscaFunction(functionMapEntry.getKey(), functionMapEntry.getValue(), heatFileName,
+ heatOrchestrationTemplate, null, context);
+ }
+ }
+
+ return paramValue;
+ }
+
+ private static List<Constraint> getToscaConstrains(List<Map<String, Object>> constraints) {
+ if (constraints == null) {
+ return null;
+ }
+
+ List<Constraint> constraintList = new ArrayList<>();
+
+ for (Map<String, Object> constraint : constraints) {
+ constraintList.addAll(getToscaParameterConstraint(constraint));
+ }
+
+ return constraintList;
+ }
+
+ private static List<Constraint> getToscaParameterConstraint(Map<String, Object> constraint) {
+ List<Constraint> convertedConstraintList = new ArrayList<>();
+ Constraint convertedConstraint;
+
+ if (constraint.containsKey("range")) {
+ convertedConstraint = new Constraint();
+ convertedConstraintList.add(convertedConstraint);
+ Integer min = (Integer) ((Map) constraint.get("range")).get("min");
+ Integer max = (Integer) ((Map) constraint.get("range")).get("max");
+ convertedConstraint.setIn_range(new Integer[]{min, max});
+
+ } else if (constraint.containsKey("length")) {
+ Integer min = (Integer) ((Map) constraint.get("length")).get("min");
+ Integer max = (Integer) ((Map) constraint.get("length")).get("max");
+ if (max != null) {
+ convertedConstraint = new Constraint();
+ convertedConstraintList.add(convertedConstraint);
+ convertedConstraint.setMax_length(max);
+ }
+ if (min != null) {
+ convertedConstraint = new Constraint();
+ convertedConstraintList.add(convertedConstraint);
+ convertedConstraint.setMin_length(min);
+ }
+ } else if (constraint.containsKey("allowed_values")) {
+ convertedConstraint = new Constraint();
+ convertedConstraintList.add(convertedConstraint);
+ convertedConstraint.setValid_values((List) constraint.get("allowed_values"));
+ } else if (constraint.containsKey("allowed_pattern")) {
+ convertedConstraint = new Constraint();
+ convertedConstraintList.add(convertedConstraint);
+ convertedConstraint.setPattern(constraint.get("allowed_pattern"));
+ }
+
+ return convertedConstraintList;
+ }
+
+ private static EntrySchema getToscaParameterEntrySchema(String type) {
+
+ if (!parameterEntrySchemaTypeMapping.containsKey(type)) {
+ return null;
+ }
+
+ EntrySchema entrySchema = new EntrySchema();
+ entrySchema.setType(parameterEntrySchemaTypeMapping.get(type));
+ return entrySchema;
+ }
+
+ protected static String getToscaParameterType(String heatParameterType) {
+ return parameterTypeMapping.get(heatParameterType);
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/mapping/TranslatorHeatToToscaPropertyConverter.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/mapping/TranslatorHeatToToscaPropertyConverter.java
new file mode 100644
index 0000000000..d1079c2dc5
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/mapping/TranslatorHeatToToscaPropertyConverter.java
@@ -0,0 +1,146 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca.mapping;
+
+import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate;
+import org.openecomp.sdc.tosca.datatypes.model.Template;
+import org.openecomp.sdc.translator.services.heattotosca.Constants;
+import org.openecomp.sdc.translator.services.heattotosca.TranslationContext;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class TranslatorHeatToToscaPropertyConverter {
+
+ /**
+ * Gets tosca properties simple conversion.
+ *
+ * @param heatProperties the heat properties
+ * @param toscaProperties the tosca properties
+ * @param heatFileName the heat file name
+ * @param heatOrchestrationTemplate the heat orchestration template
+ * @param resourceType the resource type
+ * @param template the template
+ * @param context the context
+ * @return the tosca properties simple conversion
+ */
+ //Convert property assuming the property type in heat is same as the property type in tosca
+ public static Map<String, Object> getToscaPropertiesSimpleConversion(
+ Map<String, Object> heatProperties, Map<String, Object> toscaProperties, String heatFileName,
+ HeatOrchestrationTemplate heatOrchestrationTemplate, String resourceType, Template template,
+ TranslationContext context) {
+
+ toscaProperties = toscaProperties != null ? toscaProperties : new HashMap<>();
+
+ for (String heatPropertyName : context.getElementSet(resourceType, Constants.PROP)) {
+
+ setSimpleProperty(heatProperties, heatFileName, resourceType, heatOrchestrationTemplate,
+ context, toscaProperties, heatPropertyName, null, template);
+ }
+ return toscaProperties;
+ }
+
+ /**
+ * Sets simple property.
+ *
+ * @param heatProperties the heat properties
+ * @param heatFileName the heat file name
+ * @param resourceType the resource type
+ * @param heatOrchestrationTemplate the heat orchestration template
+ * @param context the context
+ * @param toscaProperties the tosca properties
+ * @param heatPropertyName the heat property name
+ * @param toscaPropertyName the tosca property name
+ * @param template the template
+ */
+ public static void setSimpleProperty(Map<String, Object> heatProperties, String heatFileName,
+ String resourceType,
+ HeatOrchestrationTemplate heatOrchestrationTemplate,
+ TranslationContext context,
+ Map<String, Object> toscaProperties, String heatPropertyName,
+ String toscaPropertyName, Template template) {
+ Object propertyValue = null;
+ if (heatProperties != null) {
+ propertyValue = heatProperties.get(heatPropertyName);
+ }
+ if (propertyValue == null) {
+ return;
+ }
+
+ if (toscaPropertyName == null) {
+ toscaPropertyName = resourceType == null ? heatPropertyName
+ : context.getElementMapping(resourceType, Constants.PROP, heatPropertyName);
+ }
+ toscaProperties.put(toscaPropertyName,
+ getToscaPropertyValue(heatPropertyName, propertyValue, resourceType, heatFileName,
+ heatOrchestrationTemplate, template, context));
+ }
+
+
+ /**
+ * Gets tosca property value.
+ *
+ * @param propertyName the property name
+ * @param propertyValue the property value
+ * @param resourceType the resource type
+ * @param heatFileName the heat file name
+ * @param heatOrchestrationTemplate the heat orchestration template
+ * @param template the template
+ * @param context the context
+ * @return the tosca property value
+ */
+ public static Object getToscaPropertyValue(String propertyName, Object propertyValue,
+ String resourceType, String heatFileName,
+ HeatOrchestrationTemplate heatOrchestrationTemplate,
+ Template template, TranslationContext context) {
+ if (propertyValue instanceof Map && !((Map) propertyValue).isEmpty()) {
+ Map.Entry<String, Object> functionMapEntry =
+ (Map.Entry<String, Object>) ((Map) propertyValue).entrySet().iterator().next();
+ if (TranslatorHeatToToscaFunctionConverter.functionNameSet
+ .contains(functionMapEntry.getKey())) {
+ return TranslatorHeatToToscaFunctionConverter
+ .getToscaFunction(functionMapEntry.getKey(), functionMapEntry.getValue(), heatFileName,
+ heatOrchestrationTemplate, template, context);
+ }
+ Map<String, Object> propertyValueMap = new HashMap<>();
+ for (Map.Entry<String, Object> entry : ((Map<String, Object>) propertyValue).entrySet()) {
+ String toscaPropertyName = resourceType == null ? null : context
+ .getElementMapping(resourceType, Constants.PROP, propertyName + "." + entry.getKey());
+ toscaPropertyName = toscaPropertyName != null ? toscaPropertyName : entry.getKey();
+ propertyValueMap.put(toscaPropertyName,
+ getToscaPropertyValue(propertyName, entry.getValue(), resourceType, heatFileName,
+ heatOrchestrationTemplate, template, context));
+ }
+ return propertyValueMap;
+ } else if (propertyValue instanceof List && !((List) propertyValue).isEmpty()) {
+ List propertyValueArray = new ArrayList<>();
+ for (int i = 0; i < ((List) propertyValue).size(); i++) {
+ propertyValueArray.add(
+ getToscaPropertyValue(propertyName, ((List) propertyValue).get(i), resourceType,
+ heatFileName, heatOrchestrationTemplate, template, context));
+ }
+ return propertyValueArray;
+ }
+ return propertyValue;
+ }
+}