summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-sdc-translator-lib
diff options
context:
space:
mode:
authorojasdubey <ojas.dubey@amdocs.com>2018-05-16 16:15:06 +0530
committerojasdubey <ojas.dubey@amdocs.com>2018-05-17 15:00:50 +0530
commita48b61432ce6857377fe1b5ea655fc4f3cc54c00 (patch)
treebdd366ae0b90a730f9d329f79842e4388f00c5e1 /openecomp-be/lib/openecomp-sdc-translator-lib
parentb3e6cef09aac0221854916a2146c6cd9f75db8a6 (diff)
Refactor Onboarding Translator code
1. Fixed sonar violations 2. Fixed static analysis issues 2. Refactored methods for code smells Change-Id: I0d33c93156ddfaa43769a98f086e269b43c24cd2 Issue-ID: SDC-1331 Signed-off-by: ojasdubey <ojas.dubey@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-translator-lib')
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationContrailVirtualNetworkImpl.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/resourcetranslation/ResourceTranslationDefaultImpl.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/resourcetranslation/ResourceTranslationNeutronNetImpl.java58
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationNeutronSecurityGroupImpl.java44
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationNeutronSubnetImpl.java208
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationNovaServerGroupsImpl.java289
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationNovaServerImpl.java764
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationResourceGroupImpl.java347
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/SecurityRulesToPortResourceConnection.java231
9 files changed, 1004 insertions, 1031 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationContrailVirtualNetworkImpl.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationContrailVirtualNetworkImpl.java
index cd92fe3f6c..0dea8b7172 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationContrailVirtualNetworkImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationContrailVirtualNetworkImpl.java
@@ -1,44 +1,39 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- * ============LICENSE_END=========================================================
*/
package org.openecomp.sdc.translator.services.heattotosca.impl.resourcetranslation;
-import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
+import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
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 ResourceTranslationContrailVirtualNetworkImpl extends ResourceTranslationBase {
- @Override
- public void translate(TranslateTo translateTo) {
- NodeTemplate nodeTemplate = new NodeTemplate();
- nodeTemplate.setType(ToscaNodeType.CONTRAIL_VIRTUAL_NETWORK);
- nodeTemplate.setProperties(TranslatorHeatToToscaPropertyConverter
- .getToscaPropertiesSimpleConversion(translateTo.getServiceTemplate(),translateTo.
- getResourceId(),translateTo.getResource().getProperties(),
- nodeTemplate.getProperties(), translateTo.getHeatFileName(),
- translateTo.getHeatOrchestrationTemplate(), translateTo.getResource().getType(),
- nodeTemplate, translateTo.getContext()));
- DataModelUtil.addNodeTemplate(translateTo.getServiceTemplate(),
- translateTo.getTranslatedId(),nodeTemplate);
- }
+ @Override
+ public void translate(TranslateTo translateTo) {
+ NodeTemplate nodeTemplate = new NodeTemplate();
+ nodeTemplate.setType(ToscaNodeType.CONTRAIL_VIRTUAL_NETWORK);
+ nodeTemplate.setProperties(TranslatorHeatToToscaPropertyConverter
+ .getToscaPropertiesSimpleConversion(translateTo.getServiceTemplate(),
+ translateTo.getResourceId(), translateTo.getResource().getProperties(),
+ nodeTemplate.getProperties(), translateTo.getHeatFileName(),
+ translateTo.getHeatOrchestrationTemplate(), translateTo.getResource().getType(),
+ nodeTemplate, translateTo.getContext()));
+ DataModelUtil.addNodeTemplate(translateTo.getServiceTemplate(), translateTo.getTranslatedId(), nodeTemplate);
+ }
}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationDefaultImpl.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationDefaultImpl.java
index 1d6fb124c2..cacf7a5f3f 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationDefaultImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationDefaultImpl.java
@@ -1,49 +1,44 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- * ============LICENSE_END=========================================================
*/
package org.openecomp.sdc.translator.services.heattotosca.impl.resourcetranslation;
+import java.util.Optional;
+
import org.openecomp.sdc.tosca.datatypes.ToscaTopologyTemplateElements;
import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo;
-import java.util.Optional;
-
public class ResourceTranslationDefaultImpl extends ResourceTranslationBase {
- @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");
- }
-
- @Override
- protected String generateTranslatedId(TranslateTo translateTo) {
- return null;
- }
-
- @Override
- protected Optional<ToscaTopologyTemplateElements> getTranslatedToscaTopologyElement(
- TranslateTo translateTo) {
- return Optional.empty();
- }
+ @Override
+ public void translate(TranslateTo translateTo) {
+ //no translation is needed, this default is used for unsupported resources
+ logger.warn("Heat resource: '{}' with type: '{}' is not supported, will be ignored in TOSCA translation",
+ translateTo.getResourceId(), translateTo.getResource().getType());
+ }
+
+ @Override
+ protected String generateTranslatedId(TranslateTo translateTo) {
+ return null;
+ }
+
+ @Override
+ protected Optional<ToscaTopologyTemplateElements> getTranslatedToscaTopologyElement(
+ TranslateTo translateTo) {
+ return Optional.empty();
+ }
}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationNeutronNetImpl.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationNeutronNetImpl.java
index b1ad847db6..3fc05f43a1 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationNeutronNetImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationNeutronNetImpl.java
@@ -1,28 +1,24 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- * ============LICENSE_END=========================================================
*/
package org.openecomp.sdc.translator.services.heattotosca.impl.resourcetranslation;
+import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
import org.openecomp.sdc.heat.services.HeatConstants;
import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
-import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
import org.openecomp.sdc.tosca.services.DataModelUtil;
import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo;
import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil;
@@ -31,27 +27,27 @@ import org.openecomp.sdc.translator.services.heattotosca.mapping.TranslatorHeatT
public class ResourceTranslationNeutronNetImpl extends ResourceTranslationBase {
- @Override
- public void translate(TranslateTo translateTo) {
- NodeTemplate nodeTemplate = new NodeTemplate();
- nodeTemplate.setType(ToscaNodeType.NEUTRON_NET);
- nodeTemplate.setProperties(TranslatorHeatToToscaPropertyConverter
- .getToscaPropertiesSimpleConversion(translateTo.getServiceTemplate(),translateTo.
- getResourceId(),translateTo.getResource().getProperties(),
- nodeTemplate.getProperties(), translateTo.getHeatFileName(),
- translateTo.getHeatOrchestrationTemplate(), translateTo.getResource().getType(),
- nodeTemplate, translateTo.getContext()));
-
- HeatToToscaUtil.mapBoolean(nodeTemplate, HeatToToscaUtil
- .getToscaPropertyName(translateTo, HeatConstants.PORT_SECURITY_ENABLED_PROPERTY_NAME));
- HeatToToscaUtil.mapBoolean(nodeTemplate, HeatToToscaUtil
- .getToscaPropertyName(translateTo, HeatConstants.SHARED_PROPERTY_NAME));
- HeatToToscaUtil.mapBoolean(nodeTemplate, HeatToToscaUtil
- .getToscaPropertyName(translateTo, HeatConstants.ADMIN_STATE_UP_PROPERTY_NAME));
-
- DataModelUtil.addNodeTemplate(translateTo.getServiceTemplate(), translateTo.getTranslatedId(),
- nodeTemplate);
- }
+ @Override
+ public void translate(TranslateTo translateTo) {
+ NodeTemplate nodeTemplate = new NodeTemplate();
+ nodeTemplate.setType(ToscaNodeType.NEUTRON_NET);
+ nodeTemplate.setProperties(TranslatorHeatToToscaPropertyConverter
+ .getToscaPropertiesSimpleConversion(translateTo.getServiceTemplate(),
+ translateTo.getResourceId(), translateTo.getResource().getProperties(),
+ nodeTemplate.getProperties(), translateTo.getHeatFileName(),
+ translateTo.getHeatOrchestrationTemplate(), translateTo.getResource().getType(),
+ nodeTemplate, translateTo.getContext()));
+
+ HeatToToscaUtil.mapBoolean(nodeTemplate, HeatToToscaUtil
+ .getToscaPropertyName(translateTo, HeatConstants.PORT_SECURITY_ENABLED_PROPERTY_NAME));
+ HeatToToscaUtil.mapBoolean(nodeTemplate, HeatToToscaUtil
+ .getToscaPropertyName(translateTo, HeatConstants.SHARED_PROPERTY_NAME));
+ HeatToToscaUtil.mapBoolean(nodeTemplate, HeatToToscaUtil
+ .getToscaPropertyName(translateTo, HeatConstants.ADMIN_STATE_UP_PROPERTY_NAME));
+
+ DataModelUtil.addNodeTemplate(translateTo.getServiceTemplate(), translateTo.getTranslatedId(),
+ nodeTemplate);
+ }
}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationNeutronSecurityGroupImpl.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationNeutronSecurityGroupImpl.java
index 74cf8a3a54..060544fd1b 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationNeutronSecurityGroupImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationNeutronSecurityGroupImpl.java
@@ -1,27 +1,23 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- * ============LICENSE_END=========================================================
*/
package org.openecomp.sdc.translator.services.heattotosca.impl.resourcetranslation;
-import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
+import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
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;
@@ -29,20 +25,20 @@ import org.openecomp.sdc.translator.services.heattotosca.mapping.TranslatorHeatT
public class ResourceTranslationNeutronSecurityGroupImpl extends ResourceTranslationBase {
- @Override
- public void translate(TranslateTo translateTo) {
- NodeTemplate nodeTemplate = new NodeTemplate();
- nodeTemplate.setType(ToscaNodeType.NEUTRON_SECURITY_RULES);
- nodeTemplate.setProperties(TranslatorHeatToToscaPropertyConverter
- .getToscaPropertiesSimpleConversion(translateTo.getServiceTemplate(),translateTo.
- getResourceId(),translateTo.getResource().getProperties(),
- nodeTemplate.getProperties(), translateTo.getHeatFileName(),
- translateTo.getHeatOrchestrationTemplate(), translateTo.getResource().getType(),
- nodeTemplate, translateTo.getContext()));
-
- DataModelUtil.addNodeTemplate(translateTo.getServiceTemplate(), translateTo.getTranslatedId(),
- nodeTemplate);
- }
+ @Override
+ public void translate(TranslateTo translateTo) {
+ NodeTemplate nodeTemplate = new NodeTemplate();
+ nodeTemplate.setType(ToscaNodeType.NEUTRON_SECURITY_RULES);
+ nodeTemplate.setProperties(TranslatorHeatToToscaPropertyConverter
+ .getToscaPropertiesSimpleConversion(translateTo.getServiceTemplate(),
+ translateTo.getResourceId(), translateTo.getResource().getProperties(),
+ nodeTemplate.getProperties(), translateTo.getHeatFileName(),
+ translateTo.getHeatOrchestrationTemplate(), translateTo.getResource().getType(),
+ nodeTemplate, translateTo.getContext()));
+
+ DataModelUtil.addNodeTemplate(translateTo.getServiceTemplate(), translateTo.getTranslatedId(),
+ nodeTemplate);
+ }
}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationNeutronSubnetImpl.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationNeutronSubnetImpl.java
index 01f9de27bb..dfb738d534 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationNeutronSubnetImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationNeutronSubnetImpl.java
@@ -1,5 +1,5 @@
/*
- * Copyright © 2018 European Support Limited
+ * Copyright © 2016-2018 European Support Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -12,17 +12,24 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
-*/
+ */
package org.openecomp.sdc.translator.services.heattotosca.impl.resourcetranslation;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+
+import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
+import org.onap.sdc.tosca.datatypes.model.ParameterDefinition;
+import org.onap.sdc.tosca.datatypes.model.PropertyType;
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.heat.services.HeatConstants;
+import org.openecomp.sdc.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
import org.openecomp.sdc.tosca.datatypes.ToscaFunctions;
-import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
-import org.onap.sdc.tosca.datatypes.model.ParameterDefinition;
-import org.onap.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;
@@ -32,131 +39,124 @@ import org.openecomp.sdc.translator.services.heattotosca.ResourceTranslationFact
import org.openecomp.sdc.translator.services.heattotosca.errors.MissingMandatoryPropertyErrorBuilder;
import org.openecomp.sdc.translator.services.heattotosca.mapping.TranslatorHeatToToscaPropertyConverter;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Optional;
-
public class ResourceTranslationNeutronSubnetImpl extends ResourceTranslationBase {
- @Override
- public void translate(TranslateTo translateTo) {
- Optional<AttachedResourceId> subnetNetwork = getAttachedNetworkResource(translateTo);
+ private static final Logger logger = LoggerFactory.getLogger(ResourceTranslationNeutronSubnetImpl.class);
+ private static final String IP_VERSION_PROPERTY_NAME = "ip_version";
- if (!subnetNetwork.isPresent() || !subnetNetwork.get().isGetResource()) {
- return;
+ @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()) {
+ return;
+ }
+ NodeTemplate networkNodeTemplate = DataModelUtil.getNodeTemplate(translateTo.getServiceTemplate(),
+ translatedNetworkId.get());
+ Map<String, Map<String, Object>> subNetMap = (Map<String, Map<String, Object>>) networkNodeTemplate
+ .getProperties().get(HeatConstants.SUBNETS_PROPERTY_NAME);
+ if (subNetMap == null) {
+ subNetMap = addSubnetProperties(translateTo, networkNodeTemplate);
+ }
+ Map<String, Object> properties = TranslatorHeatToToscaPropertyConverter
+ .getToscaPropertiesSimpleConversion(translateTo.getServiceTemplate(),
+ translateTo.getResourceId(), translateTo.getResource().getProperties(), null,
+ translateTo.getHeatFileName(), translateTo.getHeatOrchestrationTemplate(),
+ translateTo.getResource().getType(), networkNodeTemplate, translateTo.getContext());
+ subNetMap.put(translateTo.getResourceId(), properties);
}
- 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);
+ private Map<String, Map<String, Object>> addSubnetProperties(TranslateTo translateTo,
+ NodeTemplate networkNodeTemplate) {
+ Map<String, Map<String, Object>> subNetMap = new HashMap<>();
+ networkNodeTemplate.getProperties().put(HeatConstants.SUBNETS_PROPERTY_NAME, subNetMap);
TranslatorHeatToToscaPropertyConverter
- .setSimpleProperty(translateTo.getServiceTemplate(),translateTo.getTranslatedId(),
- translateTo.getResource().getProperties(),
- translateTo.getHeatFileName(), translateTo.getResource().getType(),
- translateTo.getHeatOrchestrationTemplate(), translateTo.getContext(),
- networkNodeTemplate.getProperties(), "enable_dhcp",
- ToscaConstants.DHCP_ENABLED_PROPERTY_NAME, networkNodeTemplate); //dhcp_enabled
+ .setSimpleProperty(translateTo.getServiceTemplate(), translateTo.getTranslatedId(),
+ translateTo.getResource().getProperties(),
+ translateTo.getHeatFileName(), translateTo.getResource().getType(),
+ translateTo.getHeatOrchestrationTemplate(), translateTo.getContext(),
+ networkNodeTemplate.getProperties(), HeatConstants.ENABLE_DHCP_PROPERTY_NAME,
+ ToscaConstants.DHCP_ENABLED_PROPERTY_NAME, networkNodeTemplate); //dhcp_enabled
TranslatorHeatToToscaPropertyConverter
- .setSimpleProperty(translateTo.getServiceTemplate(),translateTo.getTranslatedId(),
- translateTo.getResource().getProperties(),
- translateTo.getHeatFileName(), translateTo.getResource().getType(),
- translateTo.getHeatOrchestrationTemplate(), translateTo.getContext(),
- networkNodeTemplate.getProperties(), "ip_version", null, networkNodeTemplate);
+ .setSimpleProperty(translateTo.getServiceTemplate(), translateTo.getTranslatedId(),
+ translateTo.getResource().getProperties(),
+ translateTo.getHeatFileName(), translateTo.getResource().getType(),
+ translateTo.getHeatOrchestrationTemplate(), translateTo.getContext(),
+ networkNodeTemplate.getProperties(), IP_VERSION_PROPERTY_NAME, null, networkNodeTemplate);
handleDhcpProperty(translateTo, networkNodeTemplate);
- }
-
- Map<String, Object> properties;
- properties = TranslatorHeatToToscaPropertyConverter
- .getToscaPropertiesSimpleConversion(translateTo.getServiceTemplate(),translateTo.
- getResourceId(),translateTo.getResource().getProperties(), null,
- translateTo.getHeatFileName(), translateTo.getHeatOrchestrationTemplate(),
- translateTo.getResource().getType(), networkNodeTemplate, translateTo.getContext());
-
- subNetMap.put(translateTo.getResourceId(), properties);
+ return subNetMap;
}
- }
-
- @Override
- protected String generateTranslatedId(TranslateTo translateTo) {
- Optional<AttachedResourceId> subnetNetwork = getAttachedNetworkResource(translateTo);
- if (!subnetNetwork.isPresent() || !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;
+ @Override
+ protected String generateTranslatedId(TranslateTo translateTo) {
+ Optional<AttachedResourceId> subnetNetwork = getAttachedNetworkResource(translateTo);
+ if (!subnetNetwork.get().isGetResource()) {
+ logger.warn("Heat resource: '{}' with type: '{}' include 'network_id/'network'' property without "
+ + "'get_resource' function, therefore this resource will be ignored in TOSCA translation.",
+ translateTo.getResourceId(), translateTo.getResource().getType());
+ return null;
+ }
+ return (String) subnetNetwork.get().getTranslatedId();
}
- return (String) subnetNetwork.get().getTranslatedId();
- }
- 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) {
+ private void handleDhcpProperty(TranslateTo translateTo, NodeTemplate networkNodeTemplate) {
+ Object dhcpEnabled = networkNodeTemplate.getProperties().get(ToscaConstants.DHCP_ENABLED_PROPERTY_NAME);
+ if (!(dhcpEnabled instanceof Map)) {
+ return;
+ }
+ Object dhcpEnabledParameterName = ((Map) dhcpEnabled).get(ToscaFunctions.GET_INPUT.getDisplayName());
+ if (dhcpEnabledParameterName == null) {
+ return;
+ }
ParameterDefinition dhcpParameterDefinition = null;
if (translateTo.getServiceTemplate().getTopology_template().getInputs() != null) {
- dhcpParameterDefinition =
- translateTo.getServiceTemplate().getTopology_template().getInputs()
- .get(dhcpEnabledParameterName);
+ dhcpParameterDefinition =
+ translateTo.getServiceTemplate().getTopology_template().getInputs().get(dhcpEnabledParameterName);
}
if (dhcpParameterDefinition == null) {
- logger.warn("Missing input parameter " + dhcpEnabledParameterName);
+ logger.warn("Missing input parameter : {} ", dhcpEnabledParameterName);
} else {
- Object defaultVal = dhcpParameterDefinition.get_default();
- if (defaultVal != null) {
+ Object defaultVal = dhcpParameterDefinition.get_default();
+ if (defaultVal == null) {
+ return;
+ }
try {
- Boolean booleanValue = HeatBoolean.eval(defaultVal);
- dhcpParameterDefinition.set_default(booleanValue);
+ Boolean booleanValue = HeatBoolean.eval(defaultVal);
+ dhcpParameterDefinition.set_default(booleanValue);
} catch (CoreException coreException) {
- 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'.", coreException);
+ dhcpParameterDefinition.set_default(true);
+ logger.warn("Parameter '{}' used for {} boolean property, but it's value is not a valid boolean "
+ + "value, therefore {} property will be set with default value of 'true'.",
+ dhcpEnabledParameterName, ToscaConstants.DHCP_ENABLED_PROPERTY_NAME, ToscaConstants
+ .DHCP_ENABLED_PROPERTY_NAME, coreException);
}
dhcpParameterDefinition.setType(PropertyType.BOOLEAN.getDisplayName());
- }
}
- }
}
- }
- private Optional<AttachedResourceId> getAttachedNetworkResource(TranslateTo translateTo) {
- Optional<AttachedResourceId> subnetNetwork;
- Optional<AttachedResourceId> attachedNetworkId =
- HeatToToscaUtil.extractAttachedResourceId(translateTo, "network_id");
- if (!attachedNetworkId.isPresent()) {
- Optional<AttachedResourceId> attachedNetwork =
- HeatToToscaUtil.extractAttachedResourceId(translateTo, "network");
- if (!attachedNetwork.isPresent()) {
+ private Optional<AttachedResourceId> getAttachedNetworkResource(TranslateTo translateTo) {
+ Optional<AttachedResourceId> attachedNetworkId =
+ HeatToToscaUtil.extractAttachedResourceId(translateTo, HeatConstants.NETWORK_ID_PROPERTY_NAME);
+ if (attachedNetworkId.isPresent()) {
+ return attachedNetworkId;
+ }
+ Optional<AttachedResourceId> attachedNetwork =
+ HeatToToscaUtil.extractAttachedResourceId(translateTo, HeatConstants.NETWORK_PROPERTY_NAME);
+ if (attachedNetwork.isPresent()) {
+ return attachedNetwork;
+ }
throw new CoreException(
- new MissingMandatoryPropertyErrorBuilder("network_id/'network'").build());
- } else {
- subnetNetwork = attachedNetwork;
- }
- } else {
- subnetNetwork = attachedNetworkId;
+ new MissingMandatoryPropertyErrorBuilder(HeatConstants.NETWORK_ID_PROPERTY_NAME + "/"
+ + HeatConstants.NETWORK_PROPERTY_NAME).build());
}
- 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/resourcetranslation/ResourceTranslationNovaServerGroupsImpl.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationNovaServerGroupsImpl.java
index 81301920f7..ccd02955cd 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationNovaServerGroupsImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationNovaServerGroupsImpl.java
@@ -1,189 +1,188 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- * ============LICENSE_END=========================================================
*/
package org.openecomp.sdc.translator.services.heattotosca.impl.resourcetranslation;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+
import org.apache.commons.collections4.CollectionUtils;
+import org.onap.sdc.tosca.datatypes.model.GroupDefinition;
+import org.onap.sdc.tosca.datatypes.model.PolicyDefinition;
import org.openecomp.sdc.heat.datatypes.model.Resource;
+import org.openecomp.sdc.heat.services.HeatConstants;
import org.openecomp.sdc.tosca.datatypes.ToscaGroupType;
import org.openecomp.sdc.tosca.datatypes.ToscaPolicyType;
import org.openecomp.sdc.tosca.datatypes.ToscaTopologyTemplateElements;
-import org.onap.sdc.tosca.datatypes.model.GroupDefinition;
-import org.onap.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;
-import java.util.Optional;
-
-
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 String generateTranslatedId(TranslateTo translateTo) {
- return isEssentialRequirementsValid(translateTo) ? getTranslatedGroupId(
- translateTo.getResourceId()) : null;
- }
-
- @Override
- protected boolean isEssentialRequirementsValid(TranslateTo translateTo) {
- return validatePolicyType(translateTo);
- }
-
- @Override
- protected Optional<ToscaTopologyTemplateElements> getTranslatedToscaTopologyElement(
- TranslateTo translateTo) {
- if (isEssentialRequirementsValid(translateTo)) {
- return Optional.of(ToscaTopologyTemplateElements.GROUP);
- } else {
- return Optional.empty();
+ private static final String AFFINITY = "affinity";
+ private static final String ANTI_AFFINITY = "anti-affinity";
+ private static final List<String> supportedPolicies = Arrays.asList(AFFINITY, ANTI_AFFINITY);
+
+ @Override
+ protected String generateTranslatedId(TranslateTo translateTo) {
+ return isEssentialRequirementsValid(translateTo) ? getTranslatedGroupId(
+ translateTo.getResourceId()) : null;
}
- }
- private boolean validatePolicyType(TranslateTo translateTo) {
- Map<String, Object> properties = translateTo.getResource().getProperties();
- if (Objects.isNull(properties) || Objects.isNull(properties.get("policies"))) {
- return true;
+ @Override
+ protected boolean isEssentialRequirementsValid(TranslateTo translateTo) {
+ return validatePolicyType(translateTo);
}
- Object policies = properties.get("policies");
- if (!(policies instanceof List)) {
- return false;
+ @Override
+ protected Optional<ToscaTopologyTemplateElements> getTranslatedToscaTopologyElement(
+ TranslateTo translateTo) {
+ if (isEssentialRequirementsValid(translateTo)) {
+ return Optional.of(ToscaTopologyTemplateElements.GROUP);
+ } else {
+ return Optional.empty();
+ }
}
- for (Object policy : (List) policies) {
- if (!isValidPolicyType(policy, translateTo.getResourceId(), translateTo.getResource())) {
- return false;
- }
+ private boolean validatePolicyType(TranslateTo translateTo) {
+ Map<String, Object> properties = translateTo.getResource().getProperties();
+ if (Objects.isNull(properties)
+ || Objects.isNull(properties.get(HeatConstants.SERVER_GROUP_POLICIES_PROPERTY_NAME))) {
+ return true;
+ }
+
+ Object policies = properties.get(HeatConstants.SERVER_GROUP_POLICIES_PROPERTY_NAME);
+ if (!(policies instanceof List)) {
+ return false;
+ }
+
+ for (Object policy : (List) policies) {
+ if (!isValidPolicyType(policy, translateTo.getResourceId(), translateTo.getResource())) {
+ return false;
+ }
+ }
+ return true;
}
- return true;
- }
- private boolean isValidPolicyType(Object policy, String resourceId, Resource resource) {
- if (!(policy instanceof String)) {
- return false;
+ private boolean isValidPolicyType(Object policy, String resourceId, Resource resource) {
+ if (!(policy instanceof String)) {
+ return false;
+ }
+
+ if (!supportedPolicies.contains(policy)) {
+ String unsupportedPolicy = policy.toString();
+ logger.warn("Resource '{}'({}) contains unsupported policy '{}'. This resource is been ignored during "
+ + "the translation", resourceId, resource.getType(), unsupportedPolicy);
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ protected void translate(TranslateTo translateTo) {
+ String resourceId = translateTo.getResourceId();
+ List<String> toscaPolicyTypes = getToscaPolicies(translateTo.getResource(), resourceId);
+ if (!CollectionUtils.isEmpty(toscaPolicyTypes)) {
+ String translatedGroupId = addGroupToTopology(translateTo, resourceId);
+ addPoliciesToTopology(translateTo, translatedGroupId, toscaPolicyTypes);
+ }
}
- if ((policy instanceof String) && !supportedPolicies.contains(policy)) {
- logger.warn("Resource '" + resourceId + "'(" + resource.getType()
- + ") contains unsupported policy '" + policy.toString()
- + "'. This resource is been ignored during the translation");
- return false;
+ private void addPoliciesToTopology(TranslateTo translateTo, String policyTargetEntityId,
+ List<String> toscaPolicyTypes) {
+ logger.info("******** Start creating policies for resource '%s' ********",
+ translateTo.getResourceId());
+ 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(Collections.singletonList(policyTargetEntityId));
+ policyDefinition.setProperties(TranslatorHeatToToscaPropertyConverter
+ .getToscaPropertiesSimpleConversion(translateTo.getServiceTemplate(),
+ translateTo.getResourceId(), translateTo.getResource().getProperties(),
+ policyDefinition.getProperties(), translateTo.getHeatFileName(),
+ translateTo.getHeatOrchestrationTemplate(), translateTo.getResource().getType(),
+ policyDefinition, translateTo.getContext()));
+ policyDefinition.getProperties().put(
+ policy.equals(ToscaPolicyType.PLACEMENT_ANTILOCATE) ? "container_type"
+ : AFFINITY, "host");
+ String policyId = getTranslatedPolicyId(translateTo, toscaPolicyTypes, i);
+ DataModelUtil
+ .addPolicyDefinition(translateTo.getServiceTemplate(), policyId, policyDefinition);
+ logger.info("******** Policy '%s' created ********", policy);
+ }
+
+ logger
+ .info("******** All policies for resource '%s' created successfully ********",
+ translateTo.getResourceId());
}
- return true;
- }
+ private String getTranslatedPolicyId(TranslateTo translateTo, List<String> toscaPolicyTypes,
+ int policyIndex) {
+ return translateTo.getResourceId() + (toscaPolicyTypes.size() > 1 ? policyIndex : "")
+ + "_policy";
+ }
- @Override
- protected void translate(TranslateTo translateTo) {
- String resourceId = translateTo.getResourceId();
- List<String> toscaPolicyTypes = getToscaPolicies(translateTo.getResource(), resourceId);
- if (!CollectionUtils.isEmpty(toscaPolicyTypes)) {
- String translatedGroupId = addGroupToTopology(translateTo, resourceId);
- addPoliciesToTopology(translateTo, translatedGroupId, toscaPolicyTypes);
+ private String 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.NATIVE_ROOT);
+ String translatedGroupId = getTranslatedGroupId(resourceId);
+ DataModelUtil
+ .addGroupDefinitionToTopologyTemplate(translateTo.getServiceTemplate(),
+ translatedGroupId, group);
+ logger.info("******** Creating group '%s' for resource '%s' ********", resourceId, resourceId);
+ return translatedGroupId;
}
- }
-
- private void addPoliciesToTopology(TranslateTo translateTo, String policyTargetEntityId,
- List<String> toscaPolicyTypes) {
- logger.info("******** Start creating policies for resource '%s' ********",
- translateTo.getResourceId());
- 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(policyTargetEntityId));
- policyDefinition.setProperties(TranslatorHeatToToscaPropertyConverter
- .getToscaPropertiesSimpleConversion(translateTo.getServiceTemplate(),
- translateTo.getResourceId(),translateTo.getResource().getProperties(),
- policyDefinition.getProperties(), translateTo.getHeatFileName(),
- translateTo.getHeatOrchestrationTemplate(), translateTo.getResource().getType(),
- policyDefinition, translateTo.getContext()));
- policyDefinition.getProperties().put(
- policy.equals(ToscaPolicyType.PLACEMENT_ANTILOCATE) ? "container_type"
- : AFFINITY, "host");
- String policyId = getTranslatedPolicyId(translateTo, toscaPolicyTypes, i);
- DataModelUtil
- .addPolicyDefinition(translateTo.getServiceTemplate(), policyId, policyDefinition);
- logger.info("******** Policy '%s' created ********", policy);
+
+ private String getTranslatedGroupId(String resourceId) {
+ return resourceId + "_group";
}
- logger
- .info("******** All policies for resource '%s' created successfully ********",
- translateTo.getResourceId());
- }
-
- private String getTranslatedPolicyId(TranslateTo translateTo, List<String> toscaPolicyTypes,
- int policyIndex) {
- return translateTo.getResourceId() + (toscaPolicyTypes.size() > 1 ? policyIndex : "")
- + "_policy";
- }
-
- private String 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.NATIVE_ROOT);
- String translatedGroupId = getTranslatedGroupId(resourceId);
- DataModelUtil
- .addGroupDefinitionToTopologyTemplate(translateTo.getServiceTemplate(),
- translatedGroupId, group);
- logger.info("******** Creating group '%s' for resource '%s' ********", resourceId, resourceId);
- return translatedGroupId;
- }
-
- private String getTranslatedGroupId(String resourceId) {
- return resourceId + "_group";
- }
-
- 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);
+ private List<String> getToscaPolicies(Resource resource, String resourceId) {
+ Map<String, Object> properties = resource.getProperties();
+ if (Objects.isNull(properties)
+ || Objects.isNull(properties.get(HeatConstants.SERVER_GROUP_POLICIES_PROPERTY_NAME))) {
+ return Collections.singletonList(ToscaPolicyType.PLACEMENT_ANTILOCATE);
+ }
+
+ List<Object> policies = (List) properties.get(HeatConstants.SERVER_GROUP_POLICIES_PROPERTY_NAME);
+ List<String> retList = new ArrayList<>();
+ policies.forEach(policy -> {
+ if (isValidPolicyType(policy, resourceId, resource)) {
+ retList.add(getToscaPolicyByHotPolicy(policy));
+ }
+ });
+ return retList;
}
- List<Object> policies = (List) properties.get("policies");
- List<String> retList = new ArrayList<>();
- policies.forEach(policy -> {
- if (isValidPolicyType(policy, resourceId, resource)) {
- retList.add(getToscaPolicyByHotPolicy(policy));
- }
- });
- return retList;
- }
-
- private String getToscaPolicyByHotPolicy(Object policy) {
- if (Objects.equals(policy, AFFINITY)) {
- return ToscaPolicyType.PLACEMENT_COLOCATE;
- } else {
- return ToscaPolicyType.PLACEMENT_ANTILOCATE;
+ private String getToscaPolicyByHotPolicy(Object policy) {
+ if (Objects.equals(policy, AFFINITY)) {
+ return ToscaPolicyType.PLACEMENT_COLOCATE;
+ } else {
+ return ToscaPolicyType.PLACEMENT_ANTILOCATE;
+ }
}
- }
}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationNovaServerImpl.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationNovaServerImpl.java
index 09439e2ea1..e865984468 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationNovaServerImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationNovaServerImpl.java
@@ -16,23 +16,37 @@
package org.openecomp.sdc.translator.services.heattotosca.impl.resourcetranslation;
+import static org.openecomp.sdc.heat.services.HeatConstants.SNAPSHOT_ID_PROPERTY_NAME;
+import static org.openecomp.sdc.heat.services.HeatConstants.VOL_ID_PROPERTY_NAME;
+
+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;
+
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
+import org.onap.sdc.tosca.datatypes.model.GroupDefinition;
+import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
+import org.onap.sdc.tosca.datatypes.model.NodeType;
+import org.onap.sdc.tosca.datatypes.model.RelationshipTemplate;
+import org.onap.sdc.tosca.datatypes.model.RequirementAssignment;
+import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate;
import org.openecomp.sdc.heat.datatypes.model.HeatResourcesTypes;
+import org.openecomp.sdc.heat.datatypes.model.PropertiesMapKeyTypes;
import org.openecomp.sdc.heat.datatypes.model.Resource;
+import org.openecomp.sdc.heat.datatypes.model.ResourceReferenceFunctions;
import org.openecomp.sdc.heat.services.HeatConstants;
import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
import org.openecomp.sdc.tosca.datatypes.ToscaCapabilityType;
import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
import org.openecomp.sdc.tosca.datatypes.ToscaRelationshipType;
-import org.onap.sdc.tosca.datatypes.model.GroupDefinition;
-import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
-import org.onap.sdc.tosca.datatypes.model.NodeType;
-import org.onap.sdc.tosca.datatypes.model.RelationshipTemplate;
-import org.onap.sdc.tosca.datatypes.model.RequirementAssignment;
-import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
import org.openecomp.sdc.tosca.services.DataModelUtil;
import org.openecomp.sdc.tosca.services.ToscaConstants;
import org.openecomp.sdc.translator.datatypes.heattotosca.AttachedResourceId;
@@ -48,422 +62,394 @@ import org.openecomp.sdc.translator.services.heattotosca.NameExtractor;
import org.openecomp.sdc.translator.services.heattotosca.ResourceTranslationFactory;
import org.openecomp.sdc.translator.services.heattotosca.mapping.TranslatorHeatToToscaPropertyConverter;
-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 {
+ private static final Logger logger = LoggerFactory.getLogger(ResourceTranslationNovaServerImpl.class);
+ private static final String BLOCK_DEVICE_MAPPING_DEVICE_NAME = "device_name";
+ private static final String VOL_ATTACH_DEVICE_PROPERTY_NAME = "device";
+
+ @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(),
+ translateTo.getResourceId(), translateTo.getTranslatedId());
+ //create compute in consolidation data
+ ConsolidationDataUtil.getComputeTemplateConsolidationData(context, serviceTemplate,
+ nodeTypeRef, translateTo.getTranslatedId());
+ NodeTemplate novaNodeTemplate = new NodeTemplate();
+ novaNodeTemplate.setType(nodeTypeRef);
+ HeatOrchestrationTemplate heatOrchestrationTemplate =
+ translateTo.getHeatOrchestrationTemplate();
+ novaNodeTemplate.setProperties(TranslatorHeatToToscaPropertyConverter
+ .getToscaPropertiesSimpleConversion(serviceTemplate, translateTo.getResourceId(),
+ properties, novaNodeTemplate.getProperties(), heatFileName,
+ heatOrchestrationTemplate, translateTo.getResource().getType(),
+ novaNodeTemplate, context));
+ HeatToToscaUtil.mapBoolean(novaNodeTemplate, HeatToToscaUtil
+ .getToscaPropertyName(translateTo, HeatConstants.CONFIG_DRIVE_PROPERTY_NAME));
+ manageNovaServerNetwork(translateTo, novaNodeTemplate);
+ manageNovaServerBlockDeviceMapping(translateTo, novaNodeTemplate);
+ manageNovaServerGroupMapping(translateTo, novaNodeTemplate);
+ DataModelUtil.addNodeTemplate(serviceTemplate, translateTo.getTranslatedId(), novaNodeTemplate);
+ }
+ private void manageNovaServerGroupMapping(TranslateTo translateTo,
+ NodeTemplate novaNodeTemplate) {
+ Map<String, Object> properties = translateTo.getResource().getProperties();
+ if (isSchedulerHintsPropExist(properties)) {
+ Object schedulerHints = properties.get(ResourceReferenceFunctions.SCHEDULER_HINTS.getFunction());
+ if (schedulerHints instanceof Map) {
+ addServerGroupHintsToPoliciesGroups(translateTo,
+ novaNodeTemplate, (Map<String, Object>) schedulerHints);
+ } else {
+ logger.warn("'scheduler_hints' property of resource '{}' is not valid. This property should be a map",
+ translateTo.getResourceId());
+ }
+ }
+ }
-public class ResourceTranslationNovaServerImpl extends ResourceTranslationBase {
- protected static Logger 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(),
- translateTo.getResourceId(), translateTo.getTranslatedId(), context);
-
- //create compute in consolidation data
- ConsolidationDataUtil.getComputeTemplateConsolidationData(context, serviceTemplate,
- nodeTypeRef, translateTo.getTranslatedId());
-
- NodeTemplate novaNodeTemplate = new NodeTemplate();
- novaNodeTemplate.setType(nodeTypeRef);
- HeatOrchestrationTemplate heatOrchestrationTemplate =
- translateTo.getHeatOrchestrationTemplate();
- novaNodeTemplate.setProperties(TranslatorHeatToToscaPropertyConverter
- .getToscaPropertiesSimpleConversion(serviceTemplate, translateTo.getResourceId(),
- properties, novaNodeTemplate.getProperties(), heatFileName,
- heatOrchestrationTemplate, translateTo.getResource().getType(),
- novaNodeTemplate, context));
-
- HeatToToscaUtil.mapBoolean(novaNodeTemplate, HeatToToscaUtil
- .getToscaPropertyName(translateTo, HeatConstants.CONFIG_DRIVE_PROPERTY_NAME));
-
- manageNovaServerNetwork(translateTo, novaNodeTemplate);
- manageNovaServerBlockDeviceMapping(translateTo, novaNodeTemplate);
- manageNovaServerGroupMapping(translateTo, context, properties, heatFileName, serviceTemplate,
- novaNodeTemplate, heatOrchestrationTemplate);
- DataModelUtil.addNodeTemplate(serviceTemplate, translateTo.getTranslatedId(), novaNodeTemplate);
- }
-
- private void manageNovaServerGroupMapping(TranslateTo translateTo, TranslationContext context,
- Map<String, Object> properties, String heatFileName,
- ServiceTemplate serviceTemplate,
- NodeTemplate novaNodeTemplate,
- HeatOrchestrationTemplate heatOrchestrationTemplate) {
- if (isSchedulerHintsPropExist(properties)) {
- Object schedulerHints = properties.get("scheduler_hints");
- if (schedulerHints instanceof Map) {
- addServerGroupHintsToPoliciesGroups(translateTo, context, heatFileName, serviceTemplate,
- novaNodeTemplate, 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 addServerGroupHintsToPoliciesGroups(TranslateTo translateTo,
+ NodeTemplate novaNodeTemplate,
+ Map<String, Object> schedulerHints) {
+ for (Object hint : schedulerHints.values()) {
+ Optional<AttachedResourceId> attachedResourceId = HeatToToscaUtil
+ .extractAttachedResourceId(translateTo.getHeatFileName(), translateTo
+ .getHeatOrchestrationTemplate(), translateTo.getContext(), hint);
+ if (attachedResourceId.isPresent()) {
+ AttachedResourceId serverGroupResourceId = attachedResourceId.get();
+ Object serverGroupResourceToTranslate = serverGroupResourceId.getEntityId();
+ if (serverGroupResourceId.isGetResource()) {
+ addServerGroupHintGetResource(translateTo, novaNodeTemplate, serverGroupResourceToTranslate);
+ } else if (serverGroupResourceId.isGetParam() && serverGroupResourceToTranslate instanceof String) {
+ addServerGroupHintGetParam(translateTo, novaNodeTemplate, serverGroupResourceToTranslate);
+ }
+ }
+ }
}
- }
-
- private void addServerGroupHintsToPoliciesGroups(TranslateTo translateTo,
- TranslationContext context, String heatFileName,
- ServiceTemplate serviceTemplate,
- NodeTemplate novaNodeTemplate,
- 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,
- novaNodeTemplate);
- }
- } else if (serverGroupResourceId.isGetParam()
- && serverGroupResourceToTranslate instanceof String) {
- TranslatedHeatResource
- translatedServerGroupResource =
- context.getHeatSharedResourcesByParam().get(serverGroupResourceToTranslate);
- if (Objects.nonNull(translatedServerGroupResource)
- && !HeatToToscaUtil.isHeatFileNested(translateTo, translateTo.getHeatFileName())
- && isResourceTypeServerGroup(translatedServerGroupResource)) {
+
+ private void addServerGroupHintGetParam(TranslateTo translateTo, NodeTemplate novaNodeTemplate,
+ Object serverGroupResourceToTranslate) {
+ TranslatedHeatResource translatedServerGroupResource = translateTo.getContext()
+ .getHeatSharedResourcesByParam().get(serverGroupResourceToTranslate);
+ if (Objects.nonNull(translatedServerGroupResource)
+ && !HeatToToscaUtil.isHeatFileNested(translateTo, translateTo.getHeatFileName())
+ && isResourceTypeServerGroup(translatedServerGroupResource)) {
Map<String, GroupDefinition> groups =
- serviceTemplate.getTopology_template().getGroups();
- if(MapUtils.isNotEmpty(groups) && Objects.nonNull(groups.get(translatedServerGroupResource
- .getTranslatedId()))) {
- groups
- .get(translatedServerGroupResource.getTranslatedId()).getMembers()
- .add(translateTo.getTranslatedId());
- //Add group Id to compute consolidation data
- updateComputeConsolidationDataGroup(translateTo, novaNodeTemplate,
- translatedServerGroupResource.getTranslatedId());
+ translateTo.getServiceTemplate().getTopology_template().getGroups();
+ if (MapUtils.isNotEmpty(groups) && Objects.nonNull(groups.get(translatedServerGroupResource
+ .getTranslatedId()))) {
+ groups.get(translatedServerGroupResource.getTranslatedId()).getMembers()
+ .add(translateTo.getTranslatedId());
+ //Add group Id to compute consolidation data
+ updateComputeConsolidationDataGroup(translateTo, novaNodeTemplate,
+ translatedServerGroupResource.getTranslatedId());
}
- }
}
- }
}
- }
-
- private boolean isResourceTypeServerGroup(TranslatedHeatResource translatedServerGroupResource) {
- return translatedServerGroupResource.getHeatResource().getType().equals(HeatResourcesTypes.NOVA_SERVER_GROUP_RESOURCE_TYPE.getHeatResource());
- }
-
- private void updateComputeConsolidationDataGroup(TranslateTo translateTo,
- NodeTemplate novaNodeTemplate,
- String groupId) {
- TranslationContext translationContext = translateTo.getContext();
- ServiceTemplate serviceTemplate = translateTo.getServiceTemplate();
- ComputeTemplateConsolidationData computeTemplateConsolidationData = ConsolidationDataUtil
- .getComputeTemplateConsolidationData(translationContext, serviceTemplate,
- novaNodeTemplate.getType(),
- translateTo.getTranslatedId());
- ConsolidationDataUtil.updateGroupIdInConsolidationData(computeTemplateConsolidationData,
- groupId);
- }
-
- 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,
- NodeTemplate novaNodeTemplate) {
- 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());
- updateComputeConsolidationDataGroup(translateTo, novaNodeTemplate,
- serverGroupTranslatedId.get());
+ private void addServerGroupHintGetResource(TranslateTo translateTo, NodeTemplate novaNodeTemplate,
+ Object serverGroupResourceToTranslate) {
+ boolean isHintOfTypeNovaServerGroup = isHintOfTypeNovaServerGroup(translateTo
+ .getHeatOrchestrationTemplate(), serverGroupResourceToTranslate);
+ if (isHintOfTypeNovaServerGroup) {
+ addNovaServerToPolicyGroup(translateTo, (String) serverGroupResourceToTranslate, novaNodeTemplate);
+ }
}
- }
-
- private boolean isSchedulerHintsPropExist(Map<String, Object> properties) {
- return !MapUtils.isEmpty(properties) && Objects.nonNull(properties.get("scheduler_hints"));
- }
-
- private void manageNovaServerBlockDeviceMapping(TranslateTo translateTo,
- NodeTemplate novaNodeTemplate) {
- String heatFileName = translateTo.getHeatFileName();
- TranslationContext context = translateTo.getContext();
- ServiceTemplate serviceTemplate = translateTo.getServiceTemplate();
- Resource resource = translateTo.getResource();
- String resourceId = translateTo.getResourceId();
- String novaServerTranslatedId = translateTo.getTranslatedId();
- HeatOrchestrationTemplate heatOrchestrationTemplate = translateTo
- .getHeatOrchestrationTemplate();
- List<Map<String, Object>> blockDeviceMappingList = getBlockDeviceMappingList(resource);
- if (CollectionUtils.isEmpty(blockDeviceMappingList)) {
- return;
+
+ private boolean isResourceTypeServerGroup(TranslatedHeatResource translatedServerGroupResource) {
+ return translatedServerGroupResource.getHeatResource().getType()
+ .equals(HeatResourcesTypes.NOVA_SERVER_GROUP_RESOURCE_TYPE.getHeatResource());
}
- 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) {
- Optional<AttachedResourceId> attachedSnapshotId = HeatToToscaUtil
- .extractAttachedResourceId(heatFileName, heatOrchestrationTemplate, context,
- snapshotIdObject);
- if (attachedSnapshotId.isPresent()) {
- volumeResourceId = novaServerTranslatedId + "_" + attachedSnapshotId.get().getEntityId();
- String deviceName = (String) blockDeviceMapping.get("device_name");
- String relationshipId = novaServerTranslatedId + "_" + index;
-
- createVolumeAttachesToRelationship(serviceTemplate, deviceName, novaServerTranslatedId,
- volumeResourceId, relationshipId);
- createCinderVolumeNodeTemplate(serviceTemplate, translateTo.getResourceId(),
- volumeResourceId, heatFileName, blockDeviceMapping, heatOrchestrationTemplate,
- context);
- connectNovaServerToVolume(novaNodeTemplate, volumeResourceId, relationshipId,
- translateTo);
+ private void updateComputeConsolidationDataGroup(TranslateTo translateTo,
+ NodeTemplate novaNodeTemplate,
+ String groupId) {
+ TranslationContext translationContext = translateTo.getContext();
+ ServiceTemplate serviceTemplate = translateTo.getServiceTemplate();
+ ComputeTemplateConsolidationData computeTemplateConsolidationData = ConsolidationDataUtil
+ .getComputeTemplateConsolidationData(translationContext, serviceTemplate,
+ novaNodeTemplate.getType(), translateTo.getTranslatedId());
+ ConsolidationDataUtil.updateGroupIdInConsolidationData(computeTemplateConsolidationData, groupId);
+ }
+
+ 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,
+ String resourceToTranslate,
+ NodeTemplate novaNodeTemplate) {
+ Resource serverGroup =
+ HeatToToscaUtil.getResource(translateTo.getHeatOrchestrationTemplate(), resourceToTranslate,
+ translateTo.getHeatFileName());
+ Optional<String> serverGroupTranslatedId = ResourceTranslationFactory.getInstance(serverGroup)
+ .translateResource(translateTo.getHeatFileName(), translateTo.getServiceTemplate(),
+ translateTo.getHeatOrchestrationTemplate(), serverGroup, resourceToTranslate,
+ translateTo.getContext());
+ if (serverGroupTranslatedId.isPresent()) {
+ translateTo.getServiceTemplate().getTopology_template().getGroups().get(serverGroupTranslatedId.get())
+ .getMembers().add(translateTo.getTranslatedId());
+ updateComputeConsolidationDataGroup(translateTo, novaNodeTemplate, serverGroupTranslatedId.get());
+ }
+ }
+
+ private boolean isSchedulerHintsPropExist(Map<String, Object> properties) {
+ return !MapUtils.isEmpty(properties)
+ && Objects.nonNull(properties.get(ResourceReferenceFunctions.SCHEDULER_HINTS.getFunction()));
+ }
+
+ private void manageNovaServerBlockDeviceMapping(TranslateTo translateTo,
+ NodeTemplate novaNodeTemplate) {
+ Resource resource = translateTo.getResource();
+ List<Map<String, Object>> blockDeviceMappingList = getBlockDeviceMappingList(resource);
+ if (CollectionUtils.isEmpty(blockDeviceMappingList)) {
+ return;
+ }
+ int index = 0;
+ for (Map<String, Object> blockDeviceMapping : blockDeviceMappingList) {
+ index = connectBlockDeviceToNovaServer(translateTo, novaNodeTemplate, index, blockDeviceMapping);
+ }
+ }
+
+ private int connectBlockDeviceToNovaServer(TranslateTo translateTo, NodeTemplate novaNodeTemplate, int index,
+ Map<String, Object> blockDeviceMapping) {
+ Object volumeIdObject = blockDeviceMapping.get(VOL_ID_PROPERTY_NAME);
+ Object snapshotIdObject = blockDeviceMapping.get(SNAPSHOT_ID_PROPERTY_NAME);
+
+ if (volumeIdObject == null && snapshotIdObject == null) {
+ logger.warn("Resource '{}' has block_device_mapping property with empty/missing volume_id and snapshot_id "
+ + "properties. Entry number {}, this entry will be ignored in TOSCA translation.",
+ translateTo.getResourceId(), (index + 1));
+ index++;
+ return index;
+ }
+ if (volumeIdObject == null) {
+ connectBlockDeviceUsingSnapshotId(translateTo, novaNodeTemplate, snapshotIdObject, index,
+ blockDeviceMapping);
+ } else {
+ connectBlockDeviceUsingVolumeId(translateTo, novaNodeTemplate, volumeIdObject);
}
- } else {
+ index++;
+ return index;
+ }
+
+ private void connectBlockDeviceUsingVolumeId(TranslateTo translateTo, NodeTemplate novaNodeTemplate,
+ Object volumeIdObject) {
Optional<AttachedResourceId> attachedVolumeId = HeatToToscaUtil
- .extractAttachedResourceId(heatFileName, heatOrchestrationTemplate, context,
- volumeIdObject);
+ .extractAttachedResourceId(translateTo.getHeatFileName(), translateTo.getHeatOrchestrationTemplate(),
+ translateTo.getContext(), volumeIdObject);
if (attachedVolumeId.isPresent() && attachedVolumeId.get().isGetResource()) {
- connectNovaServerToVolume(novaNodeTemplate,
- (String) attachedVolumeId.get().getTranslatedId(), null, translateTo);
+ connectNovaServerToVolume(novaNodeTemplate, (String) attachedVolumeId.get().getTranslatedId(), null,
+ translateTo);
}
- }
- index++;
}
- }
-
- private void connectNovaServerToVolume(NodeTemplate novaNodeTemplate, String volumeResourceId,
- String relationshipId, TranslateTo translateTo) {
- RequirementAssignment requirementAssignment = new RequirementAssignment();
- requirementAssignment.setCapability(ToscaCapabilityType.NATIVE_ATTACHMENT);
- requirementAssignment.setNode(volumeResourceId);
- if (relationshipId != null) {
- requirementAssignment.setRelationship(relationshipId);
- } else {
- requirementAssignment
- .setRelationship(ToscaRelationshipType.NATIVE_ATTACHES_TO);
+
+ private void connectBlockDeviceUsingSnapshotId(TranslateTo translateTo, NodeTemplate novaNodeTemplate,
+ Object snapshotIdObject, int index,
+ Map<String, Object> blockDeviceMapping) {
+ String novaServerTranslatedId = translateTo.getTranslatedId();
+ String volumeResourceId;
+ Optional<AttachedResourceId> attachedSnapshotId = HeatToToscaUtil
+ .extractAttachedResourceId(translateTo.getHeatFileName(), translateTo.getHeatOrchestrationTemplate(),
+ translateTo.getContext(), snapshotIdObject);
+ if (attachedSnapshotId.isPresent()) {
+ volumeResourceId = novaServerTranslatedId + "_" + attachedSnapshotId.get().getEntityId();
+ String deviceName = (String) blockDeviceMapping.get(BLOCK_DEVICE_MAPPING_DEVICE_NAME);
+ String relationshipId = novaServerTranslatedId + "_" + index;
+ createVolumeAttachesToRelationship(translateTo.getServiceTemplate(), deviceName, novaServerTranslatedId,
+ volumeResourceId, relationshipId);
+ createCinderVolumeNodeTemplate(translateTo, volumeResourceId, blockDeviceMapping);
+ connectNovaServerToVolume(novaNodeTemplate, volumeResourceId, relationshipId,
+ translateTo);
+ }
}
- DataModelUtil
- .addRequirementAssignment(novaNodeTemplate, ToscaConstants.LOCAL_STORAGE_REQUIREMENT_ID,
- requirementAssignment);
- //Add volume consolidation data
- ConsolidationDataUtil.updateComputeConsolidationDataVolumes(translateTo, novaNodeTemplate
- .getType(), translateTo.getTranslatedId(), ToscaConstants.LOCAL_STORAGE_REQUIREMENT_ID,
- requirementAssignment);
- }
-
- private void createCinderVolumeNodeTemplate(ServiceTemplate serviceTemplate, String resourceId,
- String volumeResourceId, String heatFileName,
- Map<String, Object> blockDeviceMapping,
- HeatOrchestrationTemplate heatOrchestrationTemplate,
- TranslationContext context) {
- NodeTemplate cinderVolumeNodeTemplate = new NodeTemplate();
- cinderVolumeNodeTemplate.setType(ToscaNodeType.CINDER_VOLUME);
- cinderVolumeNodeTemplate.setProperties(TranslatorHeatToToscaPropertyConverter
- .getToscaPropertiesSimpleConversion(serviceTemplate, resourceId, 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);
- Map<String, Object> properties = new HashMap<>();
- properties.put("instance_uuid", novaServerTranslatedId);
- properties.put("volume_id", volumeId);
- if (deviceName != null) {
- properties.put("device", deviceName);
+
+ private void connectNovaServerToVolume(NodeTemplate novaNodeTemplate, String volumeResourceId,
+ String relationshipId, TranslateTo translateTo) {
+ RequirementAssignment requirementAssignment = new RequirementAssignment();
+ requirementAssignment.setCapability(ToscaCapabilityType.NATIVE_ATTACHMENT);
+ requirementAssignment.setNode(volumeResourceId);
+ if (relationshipId != null) {
+ requirementAssignment.setRelationship(relationshipId);
+ } else {
+ requirementAssignment
+ .setRelationship(ToscaRelationshipType.NATIVE_ATTACHES_TO);
+ }
+ DataModelUtil.addRequirementAssignment(novaNodeTemplate, ToscaConstants.LOCAL_STORAGE_REQUIREMENT_ID,
+ requirementAssignment);
+ //Add volume consolidation data
+ ConsolidationDataUtil.updateComputeConsolidationDataVolumes(translateTo, novaNodeTemplate.getType(),
+ translateTo.getTranslatedId(), ToscaConstants.LOCAL_STORAGE_REQUIREMENT_ID, requirementAssignment);
}
- relationshipTemplate.setProperties(properties);
- DataModelUtil.addRelationshipTemplate(serviceTemplate, relationshipId, relationshipTemplate);
- }
+ private void createCinderVolumeNodeTemplate(TranslateTo translateTo,
+ String volumeResourceId,
+ Map<String, Object> blockDeviceMapping) {
+ NodeTemplate cinderVolumeNodeTemplate = new NodeTemplate();
+ cinderVolumeNodeTemplate.setType(ToscaNodeType.CINDER_VOLUME);
+ cinderVolumeNodeTemplate.setProperties(TranslatorHeatToToscaPropertyConverter
+ .getToscaPropertiesSimpleConversion(translateTo.getServiceTemplate(), translateTo.getResourceId(),
+ blockDeviceMapping, null,
+ translateTo.getHeatFileName(), translateTo.getHeatOrchestrationTemplate(),
+ HeatResourcesTypes.CINDER_VOLUME_RESOURCE_TYPE.getHeatResource(),
+ cinderVolumeNodeTemplate, translateTo.getContext()));
+ DataModelUtil.addNodeTemplate(translateTo.getServiceTemplate(), volumeResourceId, cinderVolumeNodeTemplate);
+ }
- private List<Map<String, Object>> getBlockDeviceMappingList(Resource resource) {
- if (Objects.isNull(resource.getProperties())) {
- return Collections.emptyList();
+ private void createVolumeAttachesToRelationship(ServiceTemplate serviceTemplate,
+ String deviceName, String novaServerTranslatedId,
+ String volumeId, String relationshipId) {
+ RelationshipTemplate relationshipTemplate = new RelationshipTemplate();
+ relationshipTemplate.setType(ToscaRelationshipType.CINDER_VOLUME_ATTACHES_TO);
+ Map<String, Object> properties = new HashMap<>();
+ properties.put(ToscaConstants.INSTANCE_UUID_PROPERTY_NAME, novaServerTranslatedId);
+ properties.put(ToscaConstants.VOL_ID_PROPERTY_NAME, volumeId);
+ if (deviceName != null) {
+ properties.put(VOL_ATTACH_DEVICE_PROPERTY_NAME, deviceName);
+ }
+ relationshipTemplate.setProperties(properties);
+ DataModelUtil.addRelationshipTemplate(serviceTemplate, relationshipId, relationshipTemplate);
}
- 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;
+
+ 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(HeatConstants.BLOCK_DEVICE_MAPPING);
+ List<Map<String, Object>> blockDeviceMappingV2List =
+ (List<Map<String, Object>>) resource.getProperties().get(HeatConstants.BLOCK_DEVICE_MAPPING_V2);
+
+ if (blockDeviceMappingList != null && blockDeviceMappingV2List != null) {
+ blockDeviceMappingList.addAll(blockDeviceMappingV2List);
+ } else if (CollectionUtils.isEmpty(blockDeviceMappingList)
+ && CollectionUtils.isEmpty(blockDeviceMappingV2List)) {
+ return Collections.emptyList();
+
+ } else {
+ blockDeviceMappingList =
+ blockDeviceMappingList != null ? blockDeviceMappingList : blockDeviceMappingV2List;
+ }
+ return blockDeviceMappingList;
}
- return blockDeviceMappingList;
- }
- private void manageNovaServerNetwork(TranslateTo translateTo,
- NodeTemplate novaNodeTemplate) {
- Resource resource = translateTo.getResource();
- String translatedId = translateTo.getTranslatedId();
+ private void manageNovaServerNetwork(TranslateTo translateTo,
+ NodeTemplate novaNodeTemplate) {
+ Resource resource = translateTo.getResource();
+ String translatedId = translateTo.getTranslatedId();
- if (resource.getProperties() == null) {
- return;
- }
- Object networks = resource.getProperties().get("networks");
- if(Objects.isNull(networks)
- || !(networks instanceof List)){
- return;
- }
+ if (resource.getProperties() == null) {
+ return;
+ }
+ Object networks = resource.getProperties().get(PropertiesMapKeyTypes.NETWORKS.getKeyMap());
+ if (Objects.isNull(networks) || !(networks instanceof List)) {
+ return;
+ }
+
+ List<Map<String, Object>> heatNetworkList = (List<Map<String, Object>>) networks;
- List<Map<String, Object>> heatNetworkList =
- (List<Map<String, Object>>) networks;
+ for (Map<String, Object> heatNetwork : heatNetworkList) {
+ getOrTranslatePortTemplate(translateTo, heatNetwork.get(
+ Constants.PORT_PROPERTY_NAME), translatedId, novaNodeTemplate);
+ }
+ }
- for (Map<String, Object> heatNetwork : heatNetworkList) {
- getOrTranslatePortTemplate(translateTo, heatNetwork.get(
- Constants.PORT_PROPERTY_NAME), translatedId, novaNodeTemplate);
+ private void getOrTranslatePortTemplate(TranslateTo translateTo,
+ Object port,
+ String novaServerResourceId,
+ NodeTemplate novaNodeTemplate) {
+ String heatFileName = translateTo.getHeatFileName();
+ HeatOrchestrationTemplate heatOrchestrationTemplate = translateTo.getHeatOrchestrationTemplate();
+ TranslationContext context = translateTo.getContext();
+ Optional<AttachedResourceId> attachedPortId = HeatToToscaUtil
+ .extractAttachedResourceId(heatFileName, heatOrchestrationTemplate, context, port);
+ if (!attachedPortId.isPresent() || !attachedPortId.get().isGetResource()) {
+ return;
+ }
+ String resourceId = (String) attachedPortId.get().getEntityId();
+ Resource portResource = HeatToToscaUtil.getResource(heatOrchestrationTemplate, resourceId, heatFileName);
+ if (!isSupportedPortResource(portResource)) {
+ logger.warn("NovaServer connect to port resource with id : {} and type : {}. This resource type is not "
+ + "supported, therefore the connection to the port is ignored. Supported types are: {}, {}",
+ resourceId, portResource.getType(), 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(HeatConstants.PORT_TUPLE_REFS))) {
+ novaNodeTemplate.getProperties().put(ToscaConstants.CONTRAIL_SERVICE_INSTANCE_IND, true);
+ }
+ }
+ ServiceTemplate serviceTemplate = translateTo.getServiceTemplate();
+ Optional<String> translatedPortId = ResourceTranslationFactory.getInstance(portResource)
+ .translateResource(heatFileName, serviceTemplate, heatOrchestrationTemplate, portResource,
+ resourceId, context);
+ if (translatedPortId.isPresent()) {
+ NodeTemplate portNodeTemplate =
+ DataModelUtil.getNodeTemplate(serviceTemplate, translatedPortId.get());
+ DataModelUtil.addBindingReqFromPortToCompute(novaServerResourceId, portNodeTemplate);
+ // Add ports
+ ConsolidationDataUtil.updatePortInConsolidationData(translateTo, novaNodeTemplate.getType(), resourceId,
+ portResource.getType(), translatedPortId.get());
+ } else {
+ logger.warn("NovaServer connect to port resource with id : {} and type : {}. This resource type is not "
+ + "supported, therefore the connection to the port is ignored.", resourceId, portResource
+ .getType());
+ }
}
- }
-
- private void getOrTranslatePortTemplate(TranslateTo translateTo,
- Object port,
- String novaServerResourceId,
- NodeTemplate novaNodeTemplate) {
- String heatFileName = translateTo.getHeatFileName();
- HeatOrchestrationTemplate heatOrchestrationTemplate = translateTo
- .getHeatOrchestrationTemplate();
- ServiceTemplate serviceTemplate = translateTo.getServiceTemplate();
- TranslationContext context = translateTo.getContext();
-
- Optional<AttachedResourceId> attachedPortId = HeatToToscaUtil
- .extractAttachedResourceId(heatFileName, heatOrchestrationTemplate, context, port);
-
- if (!attachedPortId.isPresent()) {
- return;
+
+ private boolean isSupportedPortResource(Resource portResource) {
+ return Arrays.asList(HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource(),
+ HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource())
+ .contains(portResource.getType());
}
- 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);
+
+ private String createLocalNodeType(ServiceTemplate serviceTemplate, Resource resource,
+ String resourceId, String translatedId) {
+ NameExtractor nodeTypeNameExtractor = TranslationContext.getNameExtractorImpl(resource.getType());
+ String nodeTypeName =
+ nodeTypeNameExtractor.extractNodeTypeName(resource, resourceId, translatedId);
+
+ if (!isNodeTypeCreated(serviceTemplate, nodeTypeName)) {
+ DataModelUtil.addNodeType(serviceTemplate, nodeTypeName, createNodeType());
}
- }
- Optional<String> translatedPortId = ResourceTranslationFactory.getInstance(portResource)
- .translateResource(heatFileName, serviceTemplate, heatOrchestrationTemplate, portResource,
- resourceId, context);
- if (translatedPortId.isPresent()) {
- NodeTemplate portNodeTemplate =
- DataModelUtil.getNodeTemplate(serviceTemplate, translatedPortId.get());
- DataModelUtil.addBindingReqFromPortToCompute(novaServerResourceId, portNodeTemplate);
-
- // Add ports
- ConsolidationDataUtil.updatePortInConsolidationData(translateTo, novaNodeTemplate.getType(), resourceId,
- portResource.getType(), translatedPortId.get());
- } 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.");
- }
+ return nodeTypeName;
}
- }
+ /**
+ * Get property Regex matcher list.
+ *
+ * @return Regex expression per nova resource property, while nova node type name is consider when
+ * setting the name value.
+ */
+ public List<PropertyRegexMatcher> getPropertyRegexMatchersForNovaNodeType() {
+ List<PropertyRegexMatcher> propertyRegexMatchers = new ArrayList<>(3);
+ propertyRegexMatchers
+ .add(new PropertyRegexMatcher(Constants.NAME_PROPERTY_NAME,
+ Arrays.asList(".+_name$", ".+_names$", ".+_name_[0-9]+"), "_name"));
+ propertyRegexMatchers
+ .add(new PropertyRegexMatcher("image", Collections.singletonList(".+_image_name$"),
+ "_image_name"));
+ propertyRegexMatchers
+ .add(new PropertyRegexMatcher("flavor", Collections.singletonList(".+_flavor_name$"),
+ "_flavor_name"));
+ return propertyRegexMatchers;
+ }
- private String createLocalNodeType(ServiceTemplate serviceTemplate, Resource resource, String
- resourceId,
- String translatedId, TranslationContext context) {
- NameExtractor nodeTypeNameExtractor = context.getNameExtractorImpl(resource.getType());
- String nodeTypeName =
- nodeTypeNameExtractor.extractNodeTypeName(resource, resourceId, translatedId);
+ private boolean isNodeTypeCreated(ServiceTemplate serviceTemplate, String nodeTypeName) {
+ return !MapUtils.isEmpty(serviceTemplate.getNode_types())
+ && Objects.nonNull(serviceTemplate.getNode_types().get(nodeTypeName));
+ }
- if (!isNodeTypeCreated(serviceTemplate, nodeTypeName)) {
- DataModelUtil.addNodeType(serviceTemplate, nodeTypeName, createNodeType());
+ private NodeType createNodeType() {
+ NodeType nodeType = new NodeType();
+ nodeType.setDerived_from(ToscaNodeType.NOVA_SERVER);
+ return nodeType;
}
- return nodeTypeName;
- }
-
- /**
- * Get property Regx matcher list.
- *
- * @return Regex exprission per nova resource property, while nova node type name is consider when
- * setting the name value.
- */
- public List<PropertyRegexMatcher> getPropertyRegexMatchersForNovaNodeType() {
- List<PropertyRegexMatcher> propertyRegexMatchers = new ArrayList<>();
- propertyRegexMatchers
- .add(new PropertyRegexMatcher(Constants.NAME_PROPERTY_NAME,
- Arrays.asList(".+_name$", ".+_names$", ".+_name_[0-9]+"), "_name"));
- propertyRegexMatchers
- .add(new PropertyRegexMatcher("image", Collections.singletonList(".+_image_name$"),
- "_image_name"));
- propertyRegexMatchers
- .add(new PropertyRegexMatcher("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);
- 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/resourcetranslation/ResourceTranslationResourceGroupImpl.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationResourceGroupImpl.java
index 7c50fd16e6..9899479088 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationResourceGroupImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationResourceGroupImpl.java
@@ -19,12 +19,19 @@ package org.openecomp.sdc.translator.services.heattotosca.impl.resourcetranslati
import static org.openecomp.sdc.heat.services.HeatConstants.RESOURCE_DEF_TYPE_PROPERTY_NAME;
import static org.openecomp.sdc.heat.services.HeatConstants.RESOURCE_GROUP_INDEX_VAR_DEFAULT_VALUE;
+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 org.onap.sdc.tosca.datatypes.model.NodeTemplate;
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.onap.sdc.tosca.datatypes.model.NodeTemplate;
import org.openecomp.sdc.tosca.services.DataModelUtil;
import org.openecomp.sdc.tosca.services.ToscaConstants;
import org.openecomp.sdc.tosca.services.ToscaUtil;
@@ -34,189 +41,197 @@ import org.openecomp.sdc.translator.services.heattotosca.ResourceTranslationFact
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.Objects;
-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(RESOURCE_DEF_TYPE_PROPERTY_NAME);
- 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;
+ private static final String NESTED_RESOURCE_METADATA = "metadata";
+
+ @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(RESOURCE_DEF_TYPE_PROPERTY_NAME);
+ if (!(typeDefinition instanceof String)) {
+ logger.warn("Resource '{}' of type '{}' with resourceDef which is not pointing to nested heat file is not"
+ + " supported and will be ignored in the translation ", translateTo.getResourceId(),
+ HeatResourcesTypes.RESOURCE_GROUP_RESOURCE_TYPE.getHeatResource());
+ return;
+ }
+ String type = (String) typeDefinition;
+ if (!HeatToToscaUtil.isYmlFileType(type)) {
+ logger.warn("Resource '{}' of type '{}' with resourceDef which is not pointing to nested heat file is not"
+ + " supported and will be ignored in the translation ", translateTo.getResourceId(),
+ HeatResourcesTypes.RESOURCE_GROUP_RESOURCE_TYPE.getHeatResource());
+ return;
+ }
+
+ nestedResource.setType(type);
+ nestedResource.setProperties((Map<String, Object>) ((Map) resourceDef).get(HeatConstants
+ .RESOURCE_DEF_PROPERTIES));
+ nestedResource.setMetadata(((Map) resourceDef).get(NESTED_RESOURCE_METADATA));
+
+ Optional<String> substitutionNodeTemplateId =
+ ResourceTranslationFactory.getInstance(nestedResource)
+ .translateResource(heatFileName, translateTo.getServiceTemplate(),
+ translateTo.getHeatOrchestrationTemplate(), nestedResource,
+ translateTo.getResourceId(), translateTo.getContext());
+
+ substitutionNodeTemplateId.ifPresent(nodeTemplateId -> addSubstitutionNodeTemplate(translateTo,
+ nodeTemplateId));
}
- 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());
- if (!Objects.isNull(substitutionNodeTemplate)) {
- Map serviceTemplateFilter = (Map<String, Object>) substitutionNodeTemplate.getProperties()
- .get(ToscaConstants.SERVICE_TEMPLATE_FILTER_PROPERTY_NAME);
-
- populateServiceTemplateFilterProperties(translateTo, substitutionNodeTemplate,
- serviceTemplateFilter);
+ private void addSubstitutionNodeTemplate(TranslateTo translateTo, String substitutionNodeTemplateId) {
+ NodeTemplate substitutionNodeTemplate =
+ DataModelUtil.getNodeTemplate(translateTo.getServiceTemplate(), substitutionNodeTemplateId);
+ if (Objects.isNull(substitutionNodeTemplate)) {
+ return;
+ }
+ Map<String, Object> 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(),
+ DataModelUtil.addNodeTemplate(translateTo.getServiceTemplate(), substitutionNodeTemplateId,
substitutionNodeTemplate);
- }
}
- }
-
- private void handlingIndexVar(TranslateTo translateTo, NodeTemplate substitutionNodeTemplate) {
- List<String> indexVarProperties = new ArrayList<>();
- String indexVarValue = getIndexVarValue(translateTo);
- replacePropertiesIndexVarValue(indexVarValue, substitutionNodeTemplate.getProperties(),
- indexVarProperties, translateTo);
- //Add index var properties to context for unified model later
- translateTo.getContext().addIndexVarProperties(ToscaUtil.getServiceTemplateFileName(translateTo
- .getServiceTemplate()), translateTo.getTranslatedId(), indexVarProperties);
- }
-
- 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,
- List<String> indexVarProperties,
- TranslateTo translateTo) {
- if (properties == null || properties.isEmpty()) {
- return;
+
+ private void handlingIndexVar(TranslateTo translateTo, NodeTemplate substitutionNodeTemplate) {
+ List<String> indexVarProperties = new ArrayList<>();
+ String indexVarValue = getIndexVarValue(translateTo);
+ replacePropertiesIndexVarValue(indexVarValue, substitutionNodeTemplate.getProperties(), indexVarProperties,
+ translateTo);
+ //Add index var properties to context for unified model later
+ translateTo.getContext().addIndexVarProperties(ToscaUtil.getServiceTemplateFileName(translateTo
+ .getServiceTemplate()), translateTo.getTranslatedId(), indexVarProperties);
}
- for (Map.Entry<String, Object> propertyEntry : properties.entrySet()) {
- Object propertyValue = propertyEntry.getValue();
- if (propertyValue != null && propertyValue.equals(RESOURCE_GROUP_INDEX_VAR_DEFAULT_VALUE)) {
- indexVarProperties.add(propertyEntry.getKey());
- }
- Object newPropertyValue = getUpdatedPropertyValueWithIndex(indexVarValue, propertyValue,
- indexVarProperties, translateTo);
- if (newPropertyValue != null) {
- properties.put(propertyEntry.getKey(), newPropertyValue);
- }
+ private Map<String, List<String>> getNewIndexVarValue() {
+ final Map<String, List<String>> newIndexVarValue = new HashMap<>();
+ List<String> 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 Object getUpdatedPropertyValueWithIndex(String indexVarValue, Object propertyValue,
- List<String> indexVarProperties,
- TranslateTo translateTo) {
- if (propertyValue != null && propertyValue instanceof String) {
- 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);
- }
+
+ private void replacePropertiesIndexVarValue(String indexVarValue,
+ Map<String, Object> properties,
+ List<String> indexVarProperties,
+ TranslateTo translateTo) {
+ if (properties == null || properties.isEmpty()) {
+ return;
}
- if (!value.isEmpty()) {
- concatList.add(value);
+
+ for (Map.Entry<String, Object> propertyEntry : properties.entrySet()) {
+ Object propertyValue = propertyEntry.getValue();
+ if (propertyValue != null && propertyValue.equals(RESOURCE_GROUP_INDEX_VAR_DEFAULT_VALUE)) {
+ indexVarProperties.add(propertyEntry.getKey());
+ }
+ Object newPropertyValue = getUpdatedPropertyValueWithIndex(indexVarValue, propertyValue,
+ indexVarProperties, translateTo);
+ if (newPropertyValue != null) {
+ properties.put(propertyEntry.getKey(), newPropertyValue);
+ }
}
+ }
- 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,
- indexVarProperties, translateTo);
- return propertyValue;
- } else if (propertyValue instanceof List && !((List) propertyValue).isEmpty()) {
- List newPropertyValueList = new ArrayList<>();
- for (Object entry : (List) propertyValue) {
- newPropertyValueList.add(getUpdatedPropertyValueWithIndex(indexVarValue, entry,
- indexVarProperties, translateTo));
- }
- return newPropertyValueList;
+ private Object getUpdatedPropertyValueWithIndex(String indexVarValue, Object propertyValue,
+ List<String> indexVarProperties,
+ TranslateTo translateTo) {
+ if (propertyValue instanceof String) {
+ return handleStringPropertyValueWithIndex(indexVarValue, propertyValue);
+ } else if (propertyValue instanceof Map && !((Map) propertyValue).isEmpty()) {
+ return handleMapPropertyValueWithIndex(indexVarValue, propertyValue, indexVarProperties, translateTo);
+ } else if (propertyValue instanceof List && !((List) propertyValue).isEmpty()) {
+ return handleListPropertyValueWithIndex(indexVarValue, (List) propertyValue, indexVarProperties,
+ translateTo);
+ }
+ return propertyValue;
}
- 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;
+
+ private Object handleListPropertyValueWithIndex(String indexVarValue, List propertyValue,
+ List<String> indexVarProperties, TranslateTo translateTo) {
+ List<Object> newPropertyValueList = new ArrayList<>();
+ for (Object entry : propertyValue) {
+ newPropertyValueList.add(getUpdatedPropertyValueWithIndex(indexVarValue, entry,
+ indexVarProperties, translateTo));
+ }
+ return newPropertyValueList;
}
- if (indexVar instanceof String) {
- return (String) indexVar;
- } else {
- throw new CoreException(
- new InvalidPropertyValueErrorBuilder("index_var", indexVar.toString(), "String").build());
+ private Object handleMapPropertyValueWithIndex(String indexVarValue, Object propertyValue,
+ List<String> indexVarProperties, TranslateTo translateTo) {
+ replacePropertiesIndexVarValue(indexVarValue, (Map<String, Object>) propertyValue, indexVarProperties,
+ translateTo);
+ return propertyValue;
}
- }
-
- private void populateServiceTemplateFilterProperties(TranslateTo translateTo,
- NodeTemplate substitutionNodeTemplate,
- Map serviceTemplateFilter) {
- boolean mandatory = false;
- Object countValue = TranslatorHeatToToscaPropertyConverter
- .getToscaPropertyValue(translateTo.getServiceTemplate(), translateTo.getResourceId(),
- 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);
+
+ private Object handleStringPropertyValueWithIndex(String indexVarValue, Object propertyValue) {
+ 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
}
- if (countValue instanceof Integer && (Integer) countValue > 0) {
- mandatory = true;
+
+ 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;
+ }
+ throw new CoreException(
+ new InvalidPropertyValueErrorBuilder(HeatConstants.INDEX_PROPERTY_NAME,
+ indexVar.toString(), "String").build());
}
- if (countValue == null) {
- mandatory = true;
+
+ private void populateServiceTemplateFilterProperties(TranslateTo translateTo,
+ NodeTemplate substitutionNodeTemplate,
+ Map<String, Object> serviceTemplateFilter) {
+ boolean mandatory = false;
+ Object countValue = TranslatorHeatToToscaPropertyConverter
+ .getToscaPropertyValue(translateTo.getServiceTemplate(), translateTo.getResourceId(),
+ 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(ToscaConstants.MANDATORY_PROPERTY_NAME, mandatory);
}
- 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/resourcetranslation/SecurityRulesToPortResourceConnection.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/SecurityRulesToPortResourceConnection.java
index b42c7f7132..46219b3079 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/SecurityRulesToPortResourceConnection.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/SecurityRulesToPortResourceConnection.java
@@ -1,25 +1,32 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- * ============LICENSE_END=========================================================
*/
package org.openecomp.sdc.translator.services.heattotosca.impl.resourcetranslation;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.function.Predicate;
+
+import org.onap.sdc.tosca.datatypes.model.CapabilityDefinition;
+import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
+import org.onap.sdc.tosca.datatypes.model.NodeType;
+import org.onap.sdc.tosca.datatypes.model.RequirementDefinition;
import org.openecomp.sdc.heat.datatypes.manifest.FileData;
import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate;
import org.openecomp.sdc.heat.datatypes.model.HeatResourcesTypes;
@@ -27,145 +34,129 @@ 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.onap.sdc.tosca.datatypes.model.CapabilityDefinition;
-import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
-import org.onap.sdc.tosca.datatypes.model.NodeType;
-import org.onap.sdc.tosca.datatypes.model.RequirementDefinition;
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.Constants;
import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.function.Predicate;
-
class SecurityRulesToPortResourceConnection extends ResourceConnectionUsingCapabilityHelper {
- 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);
- }
-
- @Override
- protected List<Predicate<CapabilityDefinition>> getPredicatesListForConnectionPoints() {
- ArrayList<Predicate<CapabilityDefinition>> predicates = new ArrayList<>();
- predicates.add(cap -> cap.getType().equals(ToscaCapabilityType.NATIVE_ATTACHMENT));
- return predicates;
- }
-
- @Override
- protected Optional<List<String>> getConnectorPropertyParamName(String heatResourceId,
- Resource heatResource,
- HeatOrchestrationTemplate
- nestedHeatOrchestrationTemplate,
- String nestedHeatFileName) {
-
-
-
- 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()
- && attachedResourceId.get().isGetParam()
- && attachedResourceId.get().getEntityId() instanceof String) {
- paramsList.add((String) attachedResourceId.get().getEntityId());
- }
- });
-
- return Optional.of(paramsList);
+ SecurityRulesToPortResourceConnection(ResourceTranslationNestedImpl resourceTranslationNested,
+ TranslateTo translateTo, FileData nestedFileData,
+ NodeTemplate substitutionNodeTemplate, NodeType nodeType) {
+ super(resourceTranslationNested, translateTo, nestedFileData, substitutionNodeTemplate,
+ nodeType);
}
- return Optional.empty();
- }
-
- @Override
- protected String getDesiredResourceType() {
- return HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource();
- }
-
- @Override
- void addRequirementToConnectResources(
- Map.Entry<String, CapabilityDefinition> connectionPointEntry, List<String> paramNames) {
+ @Override
+ protected boolean isDesiredNodeTemplateType(NodeTemplate nodeTemplate) {
+ return nodeTemplate.getType().equals(ToscaNodeType.NEUTRON_PORT);
+ }
+ @Override
+ protected List<Predicate<CapabilityDefinition>> getPredicatesListForConnectionPoints() {
+ ArrayList<Predicate<CapabilityDefinition>> predicates = new ArrayList<>(1);
+ predicates.add(cap -> cap.getType().equals(ToscaCapabilityType.NATIVE_ATTACHMENT));
+ return predicates;
+ }
+ @Override
+ protected Optional<List<String>> getConnectorPropertyParamName(String heatResourceId,
+ Resource heatResource,
+ HeatOrchestrationTemplate
+ nestedHeatOrchestrationTemplate,
+ String nestedHeatFileName) {
+
+
+ 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()
+ && attachedResourceId.get().isGetParam()
+ && attachedResourceId.get().getEntityId() instanceof String) {
+ paramsList.add((String) attachedResourceId.get().getEntityId());
+ }
+ });
+
+ return Optional.of(paramsList);
+ }
- if (paramNames == null || paramNames.isEmpty()) {
- return;
+ return Optional.empty();
}
- List<String> supportedSecurityRulesTypes = Collections
- .singletonList(HeatResourcesTypes.NEUTRON_SECURITY_GROUP_RESOURCE_TYPE.getHeatResource());
- for (String paramName : paramNames) {
- addRequirementToConnectResource(connectionPointEntry, supportedSecurityRulesTypes, paramName);
+ @Override
+ protected String getDesiredResourceType() {
+ return HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource();
}
- }
-
- @Override
- boolean validateResourceTypeSupportedForReqCreation(String nestedResourceId,
- String nestedPropertyName,
- String connectionPointId,
- Resource connectedResource,
- List<String> supportedTypes) {
+ @Override
+ void addRequirementToConnectResources(
+ Map.Entry<String, CapabilityDefinition> connectionPointEntry, List<String> paramNames) {
+ if (paramNames == null || paramNames.isEmpty()) {
+ return;
+ }
+ List<String> supportedSecurityRulesTypes = Collections
+ .singletonList(HeatResourcesTypes.NEUTRON_SECURITY_GROUP_RESOURCE_TYPE.getHeatResource());
- if (!resourceTranslationBase.isResourceTypeSupported(connectedResource, supportedTypes)) {
- logger.warn("Nested resource '" + nestedResourceId + "' property '" + nestedPropertyName
- + "' is pointing to resource with type '" + connectedResource.getType()
- + "' which is not supported for capability '" + connectionPointId
- + "' connection, (security rules to port connection). Supported types are: '"
- + supportedTypes.toString() + "', therefore, this TOSCA capability will not be "
- + "connected.");
+ for (String paramName : paramNames) {
+ addRequirementToConnectResource(connectionPointEntry, supportedSecurityRulesTypes, paramName);
+ }
- return false;
}
- return true;
- }
+ @Override
+ boolean validateResourceTypeSupportedForReqCreation(String nestedResourceId,
+ String nestedPropertyName,
+ String connectionPointId,
+ Resource connectedResource,
+ List<String> supportedTypes) {
- @Override
- Map.Entry<String, RequirementDefinition> createRequirementDefinition(String capabilityKey) {
+ if (!resourceTranslationBase.isResourceTypeSupported(connectedResource, supportedTypes)) {
+ logger.warn("Nested resource '{}' property '{}' is pointing to resource with type '{}' which is not "
+ + "supported for capability '{}' connection, (security rules to port connection)."
+ + "Supported types are: '{}', therefore, this TOSCA capability will not be connected.",
+ nestedResourceId, nestedPropertyName, connectedResource.getType(),
+ connectionPointId, supportedTypes.toString());
+ return false;
+ }
- RequirementDefinition definition = new RequirementDefinition();
- definition.setCapability(capabilityKey);
- definition.setRelationship(ToscaRelationshipType.ATTACHES_TO);
- return new Map.Entry<String, RequirementDefinition>() {
- @Override
- public String getKey() {
- return ToscaConstants.PORT_REQUIREMENT_ID;
- }
-
- @Override
- public RequirementDefinition getValue() {
- return definition;
- }
+ return true;
+ }
- @Override
- public RequirementDefinition setValue(RequirementDefinition value) {
- return null;
- }
- };
- }
+ @Override
+ Map.Entry<String, RequirementDefinition> createRequirementDefinition(String capabilityKey) {
+
+
+ RequirementDefinition definition = new RequirementDefinition();
+ definition.setCapability(capabilityKey);
+ definition.setRelationship(ToscaRelationshipType.ATTACHES_TO);
+ 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;
+ }
+ };
+ }
}