diff options
author | 2018-02-22 14:32:06 +0530 | |
---|---|---|
committer | 2018-02-28 09:56:30 +0000 | |
commit | 51e051e86f9f5d10c9439e9e5e57d1e9ee8f8e06 (patch) | |
tree | 957583dc6b93667d7024c7258716d6c6b96776c2 /openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java | |
parent | bc169d4b132891052cc8c642e18e642afd04464f (diff) |
VLAN tagging - Pattern 1A, 1C1
1. Implementation for supporting VLAN
tagging in Pattern 1A and 1C1 heats
2. Updated code for switch case refactor with
command design pattern
3. Added unit tests and bug fixes
Change-Id: I54938ffd6673f865b4506a890ec8e7b9c54597b1
Issue-ID: SDC-1036
Signed-off-by: ojasdubey <ojas.dubey@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java')
24 files changed, 2044 insertions, 967 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/TranslationContext.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/TranslationContext.java index 6f77f22625..8175072bbc 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/TranslationContext.java +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/TranslationContext.java @@ -1,5 +1,5 @@ /* - * Copyright © 2016-2017 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. @@ -16,6 +16,8 @@ package org.openecomp.sdc.translator.datatypes.heattotosca; +import com.google.common.collect.ArrayListMultimap; +import com.google.common.collect.ListMultimap; import org.apache.commons.collections.MapUtils; import org.openecomp.config.api.Configuration; import org.openecomp.config.api.ConfigurationManager; @@ -92,6 +94,9 @@ public class TranslationContext { private Set<String> nodeTemplateIdsPointingToStWithoutNodeTemplates = new HashSet<>(); + //Key - service template name, value - Map of key: node template id, value: proerties with %index% + private Map<String, ListMultimap<String, String>> indexVarProperties = new HashMap<>(); + static { Configuration config = ConfigurationManager.lookup(); translationMapping = @@ -171,6 +176,25 @@ public class TranslationContext { .addCleanedNodeTemplate(nodeTemplateId, unifiedCompositionEntity, nodeTemplate); } + public Optional<List<String>> getIndexVarProperties(String serviceTemplateName, + String nodeTemplateId) { + ListMultimap<String, String> serviceTemplateIndexVarProperties = this.indexVarProperties + .get(serviceTemplateName); + if (Objects.nonNull(serviceTemplateIndexVarProperties)) { + return Optional.of(this.indexVarProperties.get(serviceTemplateName).get(nodeTemplateId)); + } + return Optional.empty(); + } + + public void addIndexVarProperties(String serviceTemplateName, + String nodeTemplateId, + List<String> indexVarProperties) { + this.indexVarProperties.putIfAbsent(serviceTemplateName, ArrayListMultimap.create()); + this.indexVarProperties + .get(serviceTemplateName) + .putAll(nodeTemplateId, indexVarProperties); + } + public NodeTemplate getCleanedNodeTemplate(String serviceTemplateName, String nodeTemplateId) { return this.unifiedSubstitutionData.get(serviceTemplateName) diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/composition/UnifiedCompositionData.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/composition/UnifiedCompositionData.java index a3635391ba..08db3be2a9 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/composition/UnifiedCompositionData.java +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/composition/UnifiedCompositionData.java @@ -1,8 +1,25 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.composition; import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.ComputeTemplateConsolidationData; import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.NestedTemplateConsolidationData; import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.PortTemplateConsolidationData; +import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.SubInterfaceTemplateConsolidationData; import java.util.ArrayList; import java.util.List; @@ -20,6 +37,7 @@ public class UnifiedCompositionData { */ private List<PortTemplateConsolidationData> portTemplateConsolidationDataList; + private List<SubInterfaceTemplateConsolidationData> subInterfaceTemplateConsolidationDataList; private NestedTemplateConsolidationData nestedTemplateConsolidationData; @@ -75,6 +93,26 @@ public class UnifiedCompositionData { } /** + * Gets sub interface template consolidation data list. + * + * @return the sub interface template consolidation data list + */ + public List<SubInterfaceTemplateConsolidationData> getSubInterfaceTemplateConsolidationDataList() { + return subInterfaceTemplateConsolidationDataList; + } + + /** + * Sets sub interface template consolidation data list. + * + * @param subInterfaceTemplateConsolidationDataList the sub interface template consolidation data + * list + */ + public void setSubInterfaceTemplateConsolidationDataList( + List<SubInterfaceTemplateConsolidationData> subInterfaceTemplateConsolidationDataList) { + this.subInterfaceTemplateConsolidationDataList = subInterfaceTemplateConsolidationDataList; + } + + /** * Gets nested template consolidation data. * * @return the nested template consolidation data diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/composition/UnifiedCompositionEntity.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/composition/UnifiedCompositionEntity.java index d0bb826904..58a9092616 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/composition/UnifiedCompositionEntity.java +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/composition/UnifiedCompositionEntity.java @@ -1,8 +1,35 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.composition; public enum UnifiedCompositionEntity { - Compute, - Port, - Nested, - Other; + COMPUTE("Compute"), + PORT("Port"), + NESTED("Nested"), + SUB_INTERFACE("SubInterface"), + OTHER("Other"); + + private String displayName; + + UnifiedCompositionEntity(String displayName) { + this.displayName = displayName; + } + + public String getDisplayName() { + return displayName; + } } diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/composition/commands/CommandImplNames.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/composition/commands/CommandImplNames.java new file mode 100644 index 0000000000..8fa2c74b1b --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/composition/commands/CommandImplNames.java @@ -0,0 +1,30 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.composition.commands; + +public class CommandImplNames { + + private static final String COMMANDS_IMPL_BASE_PACKAGE = + "org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.composition.commands.impl"; + + public static final String COMPUTE_NEW_NODE_TEMPLATE_ID_GENERATOR_IMPL = + COMMANDS_IMPL_BASE_PACKAGE + ".ComputeNewNodeTemplateIdGenerator"; + public static final String PORT_NEW_NODE_TEMPLATE_ID_GENERATOR_IMPL = + COMMANDS_IMPL_BASE_PACKAGE + ".PortNewNodeTemplateIdGenerator"; + public static final String SUB_INTERFACE_NEW_NODE_TEMPLATE_ID_GENERATOR_IMPL = + COMMANDS_IMPL_BASE_PACKAGE + ".SubInterfaceNewNodeTemplateIdGenerator"; +} diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/composition/commands/UnifiedSubstitutionNodeTemplateIdGenerator.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/composition/commands/UnifiedSubstitutionNodeTemplateIdGenerator.java new file mode 100644 index 0000000000..a932859807 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/composition/commands/UnifiedSubstitutionNodeTemplateIdGenerator.java @@ -0,0 +1,25 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.composition.commands; + +import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.composition.to.UnifiedCompositionTo; + +import java.util.Optional; + +public interface UnifiedSubstitutionNodeTemplateIdGenerator { + public Optional<String> generate(UnifiedCompositionTo unifiedCompositionTo, String originalNodeTemplateId); +} diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/composition/commands/impl/ComputeNewNodeTemplateIdGenerator.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/composition/commands/impl/ComputeNewNodeTemplateIdGenerator.java new file mode 100644 index 0000000000..c39a26c545 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/composition/commands/impl/ComputeNewNodeTemplateIdGenerator.java @@ -0,0 +1,32 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.composition.commands.impl; + +import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.composition.commands.UnifiedSubstitutionNodeTemplateIdGenerator; +import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.composition.to.UnifiedCompositionTo; +import org.openecomp.sdc.translator.services.heattotosca.UnifiedCompositionUtil; + +import java.util.Optional; + +public class ComputeNewNodeTemplateIdGenerator implements UnifiedSubstitutionNodeTemplateIdGenerator { + + @Override + public Optional<String> generate(UnifiedCompositionTo unifiedCompositionTo, String originalNodeTemplateId) { + return Optional.ofNullable(UnifiedCompositionUtil.getNewComputeNodeTemplateId( + unifiedCompositionTo.getServiceTemplate(), originalNodeTemplateId)); + } +} diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/composition/commands/impl/PortNewNodeTemplateIdGenerator.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/composition/commands/impl/PortNewNodeTemplateIdGenerator.java new file mode 100644 index 0000000000..e70ac165e2 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/composition/commands/impl/PortNewNodeTemplateIdGenerator.java @@ -0,0 +1,46 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.composition.commands.impl; + +import static org.openecomp.sdc.translator.services.heattotosca.UnifiedCompositionUtil.getConnectedComputeConsolidationData; +import static org.openecomp.sdc.translator.services.heattotosca.UnifiedCompositionUtil.getNewPortNodeTemplateId; + +import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate; +import org.openecomp.sdc.tosca.services.DataModelUtil; +import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.composition.commands.UnifiedSubstitutionNodeTemplateIdGenerator; +import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.composition.to.UnifiedCompositionTo; +import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.ComputeTemplateConsolidationData; + +import java.util.Objects; +import java.util.Optional; + +public class PortNewNodeTemplateIdGenerator implements UnifiedSubstitutionNodeTemplateIdGenerator { + + @Override + public Optional<String> generate(UnifiedCompositionTo unifiedCompositionTo, String originalNodeTemplateId) { + ComputeTemplateConsolidationData connectedComputeConsolidationData = + getConnectedComputeConsolidationData(unifiedCompositionTo.getUnifiedCompositionDataList(), + originalNodeTemplateId); + if (Objects.nonNull(connectedComputeConsolidationData)) { + NodeTemplate connectedComputeNodeTemplate = DataModelUtil.getNodeTemplate(unifiedCompositionTo + .getServiceTemplate(), connectedComputeConsolidationData.getNodeTemplateId()); + return Optional.of(getNewPortNodeTemplateId(originalNodeTemplateId, connectedComputeNodeTemplate.getType(), + connectedComputeConsolidationData)); + } + return Optional.empty(); + } +} diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/composition/commands/impl/SubInterfaceNewNodeTemplateIdGenerator.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/composition/commands/impl/SubInterfaceNewNodeTemplateIdGenerator.java new file mode 100644 index 0000000000..5aafa1aac5 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/composition/commands/impl/SubInterfaceNewNodeTemplateIdGenerator.java @@ -0,0 +1,69 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.composition.commands.impl; + +import static org.openecomp.sdc.translator.services.heattotosca.UnifiedCompositionUtil.getConnectedComputeConsolidationData; +import static org.openecomp.sdc.translator.services.heattotosca.UnifiedCompositionUtil.getNewSubInterfaceNodeTemplateId; + +import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate; +import org.openecomp.sdc.tosca.services.DataModelUtil; +import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.composition.UnifiedCompositionData; +import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.composition.commands.UnifiedSubstitutionNodeTemplateIdGenerator; +import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.composition.to.UnifiedCompositionTo; +import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.ComputeTemplateConsolidationData; +import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.SubInterfaceTemplateConsolidationData; +import org.openecomp.sdc.translator.services.heattotosca.UnifiedCompositionUtil; + +import java.util.Collection; +import java.util.List; +import java.util.Objects; +import java.util.Optional; + +public class SubInterfaceNewNodeTemplateIdGenerator implements UnifiedSubstitutionNodeTemplateIdGenerator { + + @Override + public Optional<String> generate(UnifiedCompositionTo unifiedCompositionTo, String originalNodeTemplateId) { + SubInterfaceTemplateConsolidationData subInterfaceTemplateConsolidationData = + getSubInterfaceTemplateConsolidationDataById(unifiedCompositionTo.getUnifiedCompositionDataList(), + originalNodeTemplateId); + if (Objects.nonNull(subInterfaceTemplateConsolidationData)) { + String parentPortNodeTemplateId = subInterfaceTemplateConsolidationData.getParentPortNodeTemplateId(); + ComputeTemplateConsolidationData connectedComputeConsolidationData = + getConnectedComputeConsolidationData(unifiedCompositionTo.getUnifiedCompositionDataList(), + parentPortNodeTemplateId); + if (Objects.nonNull(connectedComputeConsolidationData)) { + NodeTemplate connectedComputeNodeTemplate = DataModelUtil.getNodeTemplate(unifiedCompositionTo + .getServiceTemplate(), connectedComputeConsolidationData.getNodeTemplateId()); + return Optional.of(getNewSubInterfaceNodeTemplateId(unifiedCompositionTo.getServiceTemplate(), + connectedComputeNodeTemplate.getType(), connectedComputeConsolidationData, + subInterfaceTemplateConsolidationData, unifiedCompositionTo.getContext())); + } + } + return Optional.empty(); + } + + private static SubInterfaceTemplateConsolidationData getSubInterfaceTemplateConsolidationDataById( + List<UnifiedCompositionData> unifiedCompositionDataList, + String subInterfaceNodeTemplateId) { + return unifiedCompositionDataList.stream() + .map(UnifiedCompositionUtil::getSubInterfaceTemplateConsolidationDataList) + .flatMap(Collection::stream) + .filter(subInterfaceTemplateConsolidationData -> subInterfaceNodeTemplateId + .equals(subInterfaceTemplateConsolidationData.getNodeTemplateId())) + .findFirst().orElse(null); + } +} diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/composition/to/UnifiedCompositionTo.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/composition/to/UnifiedCompositionTo.java new file mode 100644 index 0000000000..56c647129f --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/composition/to/UnifiedCompositionTo.java @@ -0,0 +1,73 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.composition.to; + +import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate; +import org.openecomp.sdc.translator.datatypes.heattotosca.TranslationContext; +import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.composition.UnifiedCompositionData; + +import java.util.List; + +public class UnifiedCompositionTo { + private ServiceTemplate serviceTemplate; + private ServiceTemplate substitutionServiceTemplate; + private List<UnifiedCompositionData> unifiedCompositionDataList; + private TranslationContext context; + + public UnifiedCompositionTo(ServiceTemplate serviceTemplate, + ServiceTemplate substitutionServiceTemplate, + List<UnifiedCompositionData> unifiedCompositionDataList, + TranslationContext context) { + this.serviceTemplate = serviceTemplate; + this.substitutionServiceTemplate = substitutionServiceTemplate; + this.unifiedCompositionDataList = unifiedCompositionDataList; + this.context = context; + } + + public ServiceTemplate getServiceTemplate() { + return serviceTemplate; + } + + public void setServiceTemplate(ServiceTemplate serviceTemplate) { + this.serviceTemplate = serviceTemplate; + } + + public ServiceTemplate getSubstitutionServiceTemplate() { + return substitutionServiceTemplate; + } + + public void setSubstitutionServiceTemplate(ServiceTemplate substitutionServiceTemplate) { + this.substitutionServiceTemplate = substitutionServiceTemplate; + } + + public List<UnifiedCompositionData> getUnifiedCompositionDataList() { + return unifiedCompositionDataList; + } + + public void setUnifiedCompositionDataList( + List<UnifiedCompositionData> unifiedCompositionDataList) { + this.unifiedCompositionDataList = unifiedCompositionDataList; + } + + public TranslationContext getContext() { + return context; + } + + public void setContext(TranslationContext context) { + this.context = context; + } +} diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/PortTemplateConsolidationData.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/PortTemplateConsolidationData.java index 0eacd4de3c..5d372370e3 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/PortTemplateConsolidationData.java +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/PortTemplateConsolidationData.java @@ -19,7 +19,9 @@ package org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolid import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.ListMultimap; import com.google.common.collect.Multimaps; + import java.util.List; +import java.util.Set; /** @@ -27,10 +29,29 @@ import java.util.List; */ public class PortTemplateConsolidationData extends EntityConsolidationData { - // key - subport type - for ResourceGroup it is the nested file name - // value - List of subports of that type in the port - private final ListMultimap<String, SubInterfaceTemplateConsolidationData> subInterfaceConsolidationData = - Multimaps.synchronizedListMultimap(ArrayListMultimap.create()); + // key - sub-interface type - for ResourceGroup it is the nested file name + // value - List of sub-interfaces of that type in the port + private final ListMultimap<String, SubInterfaceTemplateConsolidationData> subInterfaceConsolidationData = + Multimaps.synchronizedListMultimap(ArrayListMultimap.create()); + + private String networkRole; + + public String getNetworkRole() { + return networkRole; + } + + public void setNetworkRole(String networkRole) { + this.networkRole = networkRole; + } + + public List<SubInterfaceTemplateConsolidationData> getSubInterfaceConsolidationData( + String subInterfaceType) { + return this.subInterfaceConsolidationData.get(subInterfaceType); + } + + public Set<String> getAllSubInterfaceNodeTypes() { + return this.subInterfaceConsolidationData.keySet(); + } public void addSubInterfaceConsolidationData(String subPortType, SubInterfaceTemplateConsolidationData @@ -43,29 +64,26 @@ public class PortTemplateConsolidationData extends EntityConsolidationData { other.subInterfaceConsolidationData.keySet()); } - public void copyMappedInto(ListMultimap<String, SubInterfaceTemplateConsolidationData> subInterfaceTypeToEntity) { + public void copyMappedInto(ListMultimap<String, SubInterfaceTemplateConsolidationData> subInterfaceTypeToEntity) { subInterfaceTypeToEntity.putAll(this.subInterfaceConsolidationData); } - public void copyFlatInto(List<SubInterfaceTemplateConsolidationData> subInterfaceTemplateConsolidationDataList) { - subInterfaceTemplateConsolidationDataList.addAll(subInterfaceConsolidationData.values()); - } + public void copyFlatInto(List<SubInterfaceTemplateConsolidationData> subInterfaceTemplateConsolidationDataList) { + subInterfaceTemplateConsolidationDataList.addAll(subInterfaceConsolidationData.values()); + } public boolean isNumberOfSubInterfacesPerTypeSimilar(PortTemplateConsolidationData other) { + return this.subInterfaceConsolidationData.isEmpty() && other.subInterfaceConsolidationData.isEmpty() + || !this.subInterfaceConsolidationData.isEmpty() && !other.subInterfaceConsolidationData.isEmpty() + && this.subInterfaceConsolidationData.keySet().stream().allMatch( + subInterfaceType -> calculateSize(other.subInterfaceConsolidationData.get(subInterfaceType)) + == calculateSize(this.subInterfaceConsolidationData.get(subInterfaceType))); - if (this.subInterfaceConsolidationData.isEmpty() && - other.subInterfaceConsolidationData.isEmpty()) { - return true; - } - - return !this.subInterfaceConsolidationData.isEmpty() - && !other.subInterfaceConsolidationData.isEmpty() - && this.subInterfaceConsolidationData.keySet().stream().allMatch(subInterfaceType -> - calculateSize(other.subInterfaceConsolidationData.get(subInterfaceType)) == - calculateSize(this.subInterfaceConsolidationData.get(subInterfaceType))); } private int calculateSize(List<SubInterfaceTemplateConsolidationData> subInterfaces) { return subInterfaces == null ? 0 : subInterfaces.size(); } + + }
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationDataUtil.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationDataUtil.java index 0a94d2a3d9..f5eac507f1 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationDataUtil.java +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationDataUtil.java @@ -1,5 +1,22 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.openecomp.sdc.translator.services.heattotosca; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; import org.openecomp.core.utilities.file.FileUtils; @@ -8,6 +25,7 @@ import org.openecomp.sdc.datatypes.configuration.ImplementationConfiguration; import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate; import org.openecomp.sdc.heat.datatypes.model.HeatResourcesTypes; import org.openecomp.sdc.heat.datatypes.model.Resource; +import org.openecomp.sdc.tosca.datatypes.ToscaNodeType; import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate; import org.openecomp.sdc.tosca.datatypes.model.RequirementAssignment; import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate; @@ -28,6 +46,7 @@ import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolida import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.PortConsolidationData; import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.PortTemplateConsolidationData; import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.RequirementAssignmentData; +import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.SubInterfaceTemplateConsolidationData; import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.TypeComputeConsolidationData; import org.openecomp.sdc.translator.services.heattotosca.errors.DuplicateResourceIdsInDifferentFilesErrorBuilder; @@ -37,6 +56,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.Optional; /** @@ -47,6 +67,9 @@ public class ConsolidationDataUtil { private static final String UNDERSCORE = "_"; private static final String DIGIT_REGEX = "\\d+"; + private ConsolidationDataUtil() { + } + /** * Gets compute template consolidation data. * @@ -106,10 +129,11 @@ public class ConsolidationDataUtil { * @param portNodeTemplateId the port node template id * @return the port template consolidation data */ - public static PortTemplateConsolidationData getPortTemplateConsolidationData( - TranslationContext context, - ServiceTemplate serviceTemplate, - String portNodeTemplateId) { + public static PortTemplateConsolidationData getPortTemplateConsolidationData(TranslationContext context, + ServiceTemplate serviceTemplate, + String portResourceId, + String portResourceType, + String portNodeTemplateId) { ConsolidationData consolidationData = context.getConsolidationData(); String serviceTemplateFileName = ToscaUtil.getServiceTemplateFileName(serviceTemplate); @@ -128,15 +152,98 @@ public class ConsolidationDataUtil { PortTemplateConsolidationData portTemplateConsolidationData = filePortConsolidationData.getPortTemplateConsolidationData(portNodeTemplateId); if (portTemplateConsolidationData == null) { + portTemplateConsolidationData = getInitPortTemplateConsolidationData(portNodeTemplateId, + portResourceId, portResourceType); + filePortConsolidationData.setPortTemplateConsolidationData(portNodeTemplateId, portTemplateConsolidationData); + } + + return portTemplateConsolidationData; + } + + private static PortTemplateConsolidationData getInitPortTemplateConsolidationData(String portNodeTemplateId, + String portResourceId, + String portResourceType) { + PortTemplateConsolidationData portTemplateConsolidationData = new PortTemplateConsolidationData(); + portTemplateConsolidationData.setNodeTemplateId(portNodeTemplateId); + Optional<String> portNetworkRole = HeatToToscaUtil.evaluateNetworkRoleFromResourceId(portResourceId, + portResourceType); + portNetworkRole.ifPresent(portTemplateConsolidationData::setNetworkRole); + return portTemplateConsolidationData; + } + + public static Optional<SubInterfaceTemplateConsolidationData> getSubInterfaceTemplateConsolidationData( + TranslateTo subInterfaceTo, + String subInterfaceNodeTemplateId) { + Optional<String> parentPortNodeTemplateId = + HeatToToscaUtil.getSubInterfaceParentPortNodeTemplateId(subInterfaceTo); + if (parentPortNodeTemplateId.isPresent()) { + return Optional.ofNullable(getSubInterfaceTemplateConsolidationData(subInterfaceTo, + parentPortNodeTemplateId.get(), subInterfaceNodeTemplateId)); + } + return Optional.empty(); + } + + private static SubInterfaceTemplateConsolidationData getSubInterfaceTemplateConsolidationData( + TranslateTo subInterfaceTo, + String parentPortNodeTemplateId, + String subInterfaceNodeTemplateId) { + + ConsolidationData consolidationData = subInterfaceTo.getContext().getConsolidationData(); + String serviceTemplateFileName = ToscaUtil.getServiceTemplateFileName(subInterfaceTo.getServiceTemplate()); + + PortConsolidationData portConsolidationData = consolidationData.getPortConsolidationData(); + + FilePortConsolidationData filePortConsolidationData = portConsolidationData + .getFilePortConsolidationData(serviceTemplateFileName); + + if (filePortConsolidationData == null) { + filePortConsolidationData = new FilePortConsolidationData(); + portConsolidationData.setFilePortConsolidationData(serviceTemplateFileName, + filePortConsolidationData); + } + + PortTemplateConsolidationData portTemplateConsolidationData = + filePortConsolidationData.getPortTemplateConsolidationData(parentPortNodeTemplateId); + if (portTemplateConsolidationData == null) { portTemplateConsolidationData = new PortTemplateConsolidationData(); - portTemplateConsolidationData.setNodeTemplateId(portNodeTemplateId); - filePortConsolidationData.setPortTemplateConsolidationData(portNodeTemplateId, + portTemplateConsolidationData.setNodeTemplateId(parentPortNodeTemplateId); + filePortConsolidationData.setPortTemplateConsolidationData(parentPortNodeTemplateId, portTemplateConsolidationData); } - return portTemplateConsolidationData; + return getSubInterfaceResourceTemplateConsolidationData(subInterfaceTo.getResource(), portTemplateConsolidationData, + subInterfaceNodeTemplateId, parentPortNodeTemplateId); } + private static SubInterfaceTemplateConsolidationData getSubInterfaceResourceTemplateConsolidationData( + Resource resource, + PortTemplateConsolidationData portTemplateConsolidationData, + String subInterfaceNodeTemplateId, + String parentPortNodeTemplateId) { + String subInterfaceType = ToscaNodeType.VLAN_SUB_INTERFACE_RESOURCE_TYPE_PREFIX + + FileUtils.getFileWithoutExtention(HeatToToscaUtil.getSubInterfaceResourceType(resource)); + SubInterfaceTemplateConsolidationData data = new SubInterfaceTemplateConsolidationData(); + data.setNodeTemplateId(subInterfaceNodeTemplateId); + data.setParentPortNodeTemplateId(parentPortNodeTemplateId); + if (CollectionUtils.isNotEmpty(portTemplateConsolidationData.getSubInterfaceConsolidationData(subInterfaceType))) { + boolean isNewSubInterface = true; + List<SubInterfaceTemplateConsolidationData> subInterfaceTemplateConsolidationDataList = + portTemplateConsolidationData.getSubInterfaceConsolidationData(subInterfaceType); + for (SubInterfaceTemplateConsolidationData subInterfaceTemplateConsolidationData : + subInterfaceTemplateConsolidationDataList) { + if (subInterfaceNodeTemplateId.equals(subInterfaceTemplateConsolidationData.getNodeTemplateId())) { + data = subInterfaceTemplateConsolidationData; + isNewSubInterface = false; + } + } + if (isNewSubInterface) { + portTemplateConsolidationData.addSubInterfaceConsolidationData(subInterfaceType, data); + } + } else { + portTemplateConsolidationData.addSubInterfaceConsolidationData(subInterfaceType, data); + } + return data; + } /** * Gets nested template consolidation data. @@ -250,10 +357,13 @@ public class ConsolidationDataUtil { * * @param translateTo the translate to * @param computeNodeType the compute node type + * @param portResourceId the port resource id * @param portNodeTemplateId the port node template id */ public static void updatePortInConsolidationData(TranslateTo translateTo, String computeNodeType, + String portResourceId, + String portResourceType, String portNodeTemplateId) { TranslationContext translationContext = translateTo.getContext(); ServiceTemplate serviceTemplate = translateTo.getServiceTemplate(); @@ -262,7 +372,8 @@ public class ConsolidationDataUtil { translateTo.getTranslatedId()); computeTemplateConsolidationData.addPort(getPortType(portNodeTemplateId), portNodeTemplateId); // create port in consolidation data - getPortTemplateConsolidationData(translationContext, serviceTemplate, portNodeTemplateId); + getPortTemplateConsolidationData(translationContext, serviceTemplate, portResourceId, + portResourceType, portNodeTemplateId); } /** @@ -278,12 +389,7 @@ public class ConsolidationDataUtil { String nodeTemplateId, String requirementId, RequirementAssignment requirementAssignment) { ConsolidationEntityType consolidationEntityType = ConsolidationEntityType.OTHER; - HeatOrchestrationTemplate heatOrchestrationTemplate = translateTo - .getHeatOrchestrationTemplate(); - TranslationContext translationContext = translateTo.getContext(); - - consolidationEntityType.setEntityType(heatOrchestrationTemplate, sourceResource, - targetResource, translateTo.getContext()); + consolidationEntityType.setEntityType(sourceResource, targetResource, translateTo.getContext()); // Add resource dependency information in nodesConnectedIn if the target node // is a consolidation entity if (isConsolidationEntity(consolidationEntityType.getTargetEntityType())) { @@ -304,10 +410,7 @@ public class ConsolidationDataUtil { private static boolean isConsolidationEntity(ConsolidationEntityType consolidationEntityType) { - return (consolidationEntityType == ConsolidationEntityType.COMPUTE - || consolidationEntityType == ConsolidationEntityType.PORT - || consolidationEntityType == ConsolidationEntityType.NESTED - || consolidationEntityType == ConsolidationEntityType.VFC_NESTED); + return ConsolidationEntityType.getSupportedConsolidationEntities().contains(consolidationEntityType); } /** @@ -340,8 +443,17 @@ public class ConsolidationDataUtil { entityConsolidationData = getComputeTemplateConsolidationData(translationContext, serviceTemplate, nodeType, translateTo.getTranslatedId()); } else if (consolidationEntityType == ConsolidationEntityType.PORT) { - entityConsolidationData = getPortTemplateConsolidationData(translationContext, - serviceTemplate, translateTo.getTranslatedId()); + entityConsolidationData = getPortTemplateConsolidationData(translationContext, serviceTemplate, + translateTo.getResourceId(), translateTo.getResource().getType(), translateTo + .getTranslatedId()); + } else if (consolidationEntityType == ConsolidationEntityType.SUB_INTERFACE + && Objects.nonNull(serviceTemplate.getTopology_template().getNode_templates() + .get(translateTo.getTranslatedId()))) { + Optional<SubInterfaceTemplateConsolidationData> subInterfaceTemplateConsolidationData = + getSubInterfaceTemplateConsolidationData(translateTo, translateTo.getTranslatedId()); + if (subInterfaceTemplateConsolidationData.isPresent()) { + entityConsolidationData = subInterfaceTemplateConsolidationData.get(); + } } else if (consolidationEntityType == ConsolidationEntityType.VFC_NESTED || consolidationEntityType == ConsolidationEntityType.NESTED) { entityConsolidationData = @@ -350,17 +462,15 @@ public class ConsolidationDataUtil { translateTo.getTranslatedId()); } - if (Objects.isNull(entityConsolidationData)) { - return; - } + if (Objects.nonNull(entityConsolidationData)) { + if (Objects.isNull(entityConsolidationData.getNodesConnectedOut())) { + entityConsolidationData.setNodesConnectedOut(new HashMap<>()); + } - if (Objects.isNull(entityConsolidationData.getNodesConnectedOut())) { - entityConsolidationData.setNodesConnectedOut(new HashMap<>()); + entityConsolidationData.getNodesConnectedOut() + .computeIfAbsent(nodeTemplateId, k -> new ArrayList<>()) + .add(requirementAssignmentData); } - - entityConsolidationData.getNodesConnectedOut() - .computeIfAbsent(nodeTemplateId, k -> new ArrayList<>()) - .add(requirementAssignmentData); } /** @@ -386,7 +496,7 @@ public class ConsolidationDataUtil { if (consolidationEntityType == ConsolidationEntityType.COMPUTE) { NodeTemplate computeNodeTemplate = DataModelUtil.getNodeTemplate(serviceTemplate, dependentNodeTemplateId); - String nodeType = null; + String nodeType; if (Objects.isNull(computeNodeTemplate)) { Resource targetResource = translateTo.getHeatOrchestrationTemplate().getResources().get(targetResourceId); @@ -403,8 +513,18 @@ public class ConsolidationDataUtil { entityConsolidationData = getComputeTemplateConsolidationData(translationContext, serviceTemplate, nodeType, dependentNodeTemplateId); } else if (consolidationEntityType == ConsolidationEntityType.PORT) { - entityConsolidationData = getPortTemplateConsolidationData(translationContext, - serviceTemplate, dependentNodeTemplateId); + entityConsolidationData = getPortTemplateConsolidationData(translationContext, serviceTemplate, + translateTo.getResourceId(), translateTo.getResource().getType(), dependentNodeTemplateId); + } else if (consolidationEntityType == ConsolidationEntityType.SUB_INTERFACE) { + Resource targetResource = + translateTo.getHeatOrchestrationTemplate().getResources().get(targetResourceId); + TranslateTo subInterfaceTo = new TranslateTo(translateTo.getHeatFileName(), serviceTemplate, translateTo + .getHeatOrchestrationTemplate(), targetResource, targetResourceId, null, translationContext); + Optional<SubInterfaceTemplateConsolidationData> subInterfaceTemplateConsolidationData = + getSubInterfaceTemplateConsolidationData(subInterfaceTo, targetResourceId); + if (subInterfaceTemplateConsolidationData.isPresent()) { + entityConsolidationData = subInterfaceTemplateConsolidationData.get(); + } } else if (consolidationEntityType == ConsolidationEntityType.NESTED || consolidationEntityType == ConsolidationEntityType.VFC_NESTED) { entityConsolidationData = getNestedTemplateConsolidationData(translationContext, @@ -501,9 +621,9 @@ public class ConsolidationDataUtil { public static boolean isVolumeResource(HeatOrchestrationTemplate heatOrchestrationTemplate, String resourceId) { String resourceType = heatOrchestrationTemplate.getResources().get(resourceId).getType(); - return (resourceType.equals(HeatResourcesTypes.CINDER_VOLUME_RESOURCE_TYPE.getHeatResource()) + return resourceType.equals(HeatResourcesTypes.CINDER_VOLUME_RESOURCE_TYPE.getHeatResource()) || resourceType.equals(HeatResourcesTypes.CINDER_VOLUME_ATTACHMENT_RESOURCE_TYPE - .getHeatResource())); + .getHeatResource()); } /** @@ -514,9 +634,9 @@ public class ConsolidationDataUtil { */ public static boolean isVolumeResource(Resource resource) { String resourceType = resource.getType(); - return (resourceType.equals(HeatResourcesTypes.CINDER_VOLUME_RESOURCE_TYPE.getHeatResource()) + return resourceType.equals(HeatResourcesTypes.CINDER_VOLUME_RESOURCE_TYPE.getHeatResource()) || resourceType.equals(HeatResourcesTypes.CINDER_VOLUME_ATTACHMENT_RESOURCE_TYPE - .getHeatResource())); + .getHeatResource()); } /** @@ -579,10 +699,9 @@ public class ConsolidationDataUtil { } if (ConsolidationDataUtil.isPortResource(heatOrchestrationTemplate, contrailSharedResourceId)) { - NodeTemplate nodeTemplate = DataModelUtil.getNodeTemplate(serviceTemplate, - sharedTranslatedResourceId); - EntityConsolidationData entityConsolidationData = getPortTemplateConsolidationData(context, - serviceTemplate, sharedTranslatedResourceId); + Resource resource = heatOrchestrationTemplate.getResources().get(contrailSharedResourceId); + EntityConsolidationData entityConsolidationData = getPortTemplateConsolidationData(context, serviceTemplate, + contrailSharedResourceId, resource.getType(), sharedTranslatedResourceId); List<GetAttrFuncData> getAttrFuncDataList = entityConsolidationData .getOutputParametersGetAttrIn(); removeParamNameFromAttrFuncList(paramName, getAttrFuncDataList); diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationEntityType.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationEntityType.java index 8e6e9024fb..dd7825b9a5 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationEntityType.java +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationEntityType.java @@ -1,13 +1,34 @@ -package org.openecomp.sdc.translator.services.heattotosca; +/* + * 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. + */ -import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate; -import org.openecomp.sdc.heat.datatypes.model.Resource; -import org.openecomp.sdc.translator.datatypes.heattotosca.TranslationContext; +package org.openecomp.sdc.translator.services.heattotosca; import static org.openecomp.sdc.translator.services.heattotosca.ConsolidationDataUtil.isComputeResource; import static org.openecomp.sdc.translator.services.heattotosca.ConsolidationDataUtil.isPortResource; import static org.openecomp.sdc.translator.services.heattotosca.ConsolidationDataUtil.isVolumeResource; +import org.openecomp.sdc.heat.datatypes.model.Resource; +import org.openecomp.sdc.translator.datatypes.heattotosca.TranslationContext; + +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; +import java.util.stream.Collectors; + /** * The enum Entity type. */ @@ -19,7 +40,7 @@ public enum ConsolidationEntityType { //Simple nested VFC (nested file with one compute) or a complex VFC (nested ST with more than //one compute) VFC_NESTED, - SUB_PORT, + SUB_INTERFACE, OTHER; private ConsolidationEntityType sourceEntityType; @@ -33,39 +54,54 @@ public enum ConsolidationEntityType { return targetEntityType; } + /** * Sets entity type. * - * @param heatOrchestrationTemplate the heat orchestration template * @param sourceResource the source resource * @param targetResource the target resource */ - public void setEntityType(HeatOrchestrationTemplate heatOrchestrationTemplate, - Resource sourceResource, + public void setEntityType(Resource sourceResource, Resource targetResource, TranslationContext context) { targetEntityType = - getEntityType(heatOrchestrationTemplate, targetResource, context); + getEntityType(targetResource, context); sourceEntityType = - getEntityType(heatOrchestrationTemplate, sourceResource, context); + getEntityType(sourceResource, context); + } + + private static final Set<ConsolidationEntityType> consolidationEntityTypes = initConsolidationEntities(); + + private static Set<ConsolidationEntityType> initConsolidationEntities() { + Set<ConsolidationEntityType> consolidationEntityTypes = new HashSet<>(Arrays.asList(ConsolidationEntityType + .values())); + return Collections.unmodifiableSet(consolidationEntityTypes.stream() + .filter(entity -> entity != ConsolidationEntityType.OTHER + && entity != ConsolidationEntityType.VOLUME) + .collect(Collectors.toSet())); + } + + public static Set<ConsolidationEntityType> getSupportedConsolidationEntities() { + return consolidationEntityTypes; } - private ConsolidationEntityType getEntityType(HeatOrchestrationTemplate heatOrchestrationTemplate, - Resource resource, TranslationContext context) { + private ConsolidationEntityType getEntityType(Resource resource, TranslationContext context) { + ConsolidationEntityType consolidationEntityType = ConsolidationEntityType.OTHER; if (isComputeResource(resource)) { - return ConsolidationEntityType.COMPUTE; + consolidationEntityType = ConsolidationEntityType.COMPUTE; } else if (isPortResource(resource)) { - return ConsolidationEntityType.PORT; + consolidationEntityType = ConsolidationEntityType.PORT; + } else if (HeatToToscaUtil.isSubInterfaceResource(resource, context)) { + consolidationEntityType = ConsolidationEntityType.SUB_INTERFACE; } else if (isVolumeResource(resource)) { - return ConsolidationEntityType.VOLUME; + consolidationEntityType = ConsolidationEntityType.VOLUME; } else if (HeatToToscaUtil.isNestedResource(resource)) { if (HeatToToscaUtil.isNestedVfcResource(resource, context)) { - return ConsolidationEntityType.VFC_NESTED; + consolidationEntityType = ConsolidationEntityType.VFC_NESTED; } else { - return ConsolidationEntityType.NESTED; + consolidationEntityType = ConsolidationEntityType.NESTED; } - } else { - return ConsolidationEntityType.OTHER; } + return consolidationEntityType; } }
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationService.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationService.java index bc5a3c7e3a..c4762037a6 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationService.java +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationService.java @@ -920,6 +920,8 @@ public class ConsolidationService { } } } + unifiedCompositionData.setSubInterfaceTemplateConsolidationDataList( + subInterfaceTemplateConsolidationDataList); unifiedCompositionDataList.add(unifiedCompositionData); } @@ -1034,13 +1036,13 @@ public class ConsolidationService { List<String> getPropertiesWithIdenticalVal(UnifiedCompositionEntity entity) { switch (entity) { - case Compute: + case COMPUTE: return getComputePropertiesWithIdenticalVal(); - case Other: + case OTHER: return getComputePropertiesWithIdenticalVal(); - case Port: + case PORT: return getPortPropertiesWithIdenticalVal(); default: diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/Constants.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/Constants.java index 63990862ba..98e650719e 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/Constants.java +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/Constants.java @@ -1,61 +1,29 @@ -/*- - * ============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; public class Constants { //Service Template - Template Names - public static final String COMMON_GLOBAL_TEMPLATE_NAME = "CommonGlobalTypes"; - public static final String CINDER_VOLUME_TEMPLATE_NAME = "CinderVolumeGlobalTypes"; - public static final String CONTRAIL_VIRTUAL_NETWORK_TEMPLATE_NAME = - "ContrailVirtualNetworkGlobalType"; - public static final String CONTRAIL_NETWORK_RULE_TEMPLATE_NAME = "ContrailNetworkRuleGlobalType"; - public static final String CONTRAILV2_VIRTUAL_NETWORK_TEMPLATE_NAME = - "ContrailV2VirtualNetworkGlobalType"; - public static final String CONTRAILV2_NETWORK_RULE_TEMPLATE_NAME = - "ContrailV2NetworkRuleGlobalType"; - public static final String CONTRAILV2_VIRTUAL_MACHINE_INTERFACE_TEMPLATE_NAME = - "ContrailV2VirtualMachineInterfaceGlobalType"; - public static final String NEUTRON_NET_TEMPLATE_NAME = "NeutronNetGlobalTypes"; - public static final String NEUTRON_PORT_TEMPLATE_NAME = "NeutronPortGlobalTypes"; - public static final String NEUTRON_SECURITY_RULES_TEMPLATE_NAME = - "NeutronSecurityRulesGlobalTypes"; - public static final String NOVA_SERVER_TEMPLATE_NAME = "NovaServerGlobalTypes"; - public static final String ABSTRACT_SUBSTITUTE_TEMPLATE_NAME = "AbstractSubstituteGlobalTypes"; public static final String GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME = "GlobalSubstitutionTypes"; - public static final String CONTRAIL_COMPUTE_TEMPLATE_NAME = "ContrailComputeGlobalTypes"; - public static final String CONTRAIL_PORT_TEMPLATE_NAME = "ContrailPortGlobalTypes"; - public static final String CONTRAIL_ABSTRACT_SUBSTITUTE_TEMPLATE_NAME = - "ContrailAbstractSubstituteGlobalTypes"; public static final String MAIN_TEMPLATE_NAME = "Main"; - public static final String PORT_TEMPLATE_NAME = "PortGlobalTypes"; - public static final String COMPUTE_TEMPLATE_NAME = "ComputeGlobalTypes"; - public static final String NETWORK_TEMPLATE_NAME = "NetworkGlobalTypes"; - public static final String SUB_INTERFACE_TEMPLATE_NAME = "SubInterfaceGlobalTypes"; - public static final String CONTRAILV2_VLAN_SUB_INTERFACE_TEMPLATE_NAME = - "ContrailV2VLANSubInterfaceGlobalType"; //properties public static final String MAX_INSTANCES_PROPERTY_NAME = "max_instances"; public static final String DESCRIPTION_PROPERTY_NAME = "description"; public static final String NAME_PROPERTY_NAME = "name"; - public static final String RULES_PROPERTY_NAME = "rules"; public static final String SECURITY_GROUPS_PROPERTY_NAME = "security_groups"; public static final String PORT_PROPERTY_NAME = "port"; //General @@ -64,9 +32,10 @@ public class Constants { public static final String SERVICE_INSTANCE_PORT_PREFIX = "port_"; public static final String SERVICE_INSTANCE_LINK_PREFIX = "link_"; //Unified model - public static final String COMPUTE_IDENTICAL_VALUE_PROPERTY_PREFIX = "vm_"; - public static final String COMPUTE_IDENTICAL_VALUE_PROPERTY_SUFFIX = "_name"; - public static final String PORT_IDENTICAL_VALUE_PROPERTY_PREFIX = "port_"; + static final String COMPUTE_IDENTICAL_VALUE_PROPERTY_PREFIX = "vm_"; + static final String COMPUTE_IDENTICAL_VALUE_PROPERTY_SUFFIX = "_name"; + static final String PORT_IDENTICAL_VALUE_PROPERTY_PREFIX = "port_"; + static final String SUB_INTERFACE_PROPERTY_VALUE_PREFIX = "subinterface_"; public static final String ABSTRACT_NODE_TEMPLATE_ID_PREFIX = "abstract_"; private Constants() { diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/HeatToToscaUtil.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/HeatToToscaUtil.java index dafd8e6207..370f48915a 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/HeatToToscaUtil.java +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/HeatToToscaUtil.java @@ -1,5 +1,5 @@ /* - * Copyright © 2016-2017 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. @@ -36,6 +36,7 @@ import org.openecomp.sdc.heat.datatypes.manifest.FileData; import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate; import org.openecomp.sdc.heat.datatypes.model.HeatResourcesTypes; import org.openecomp.sdc.heat.datatypes.model.Resource; +import org.openecomp.sdc.heat.datatypes.model.ResourceReferenceFunctions; import org.openecomp.sdc.heat.datatypes.structure.HeatStructureTree; import org.openecomp.sdc.heat.datatypes.structure.ValidationStructureList; import org.openecomp.sdc.heat.services.HeatConstants; @@ -45,6 +46,7 @@ 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.ToscaElementTypes; +import org.openecomp.sdc.tosca.datatypes.ToscaFunctions; import org.openecomp.sdc.tosca.datatypes.ToscaNodeType; import org.openecomp.sdc.tosca.datatypes.ToscaRelationshipType; import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; @@ -76,12 +78,15 @@ import org.openecomp.sdc.translator.datatypes.heattotosca.to.FileDataCollection; import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo; import org.openecomp.sdc.translator.services.heattotosca.errors.ResourceNotFoundInHeatFileErrorBuilder; import org.openecomp.sdc.translator.services.heattotosca.globaltypes.GlobalTypesGenerator; +import org.openecomp.sdc.translator.services.heattotosca.helper.ContrailV2VirtualMachineInterfaceHelper; import org.openecomp.sdc.translator.services.heattotosca.helper.FunctionTranslationHelper; +import org.openecomp.sdc.translator.services.heattotosca.impl.resourcetranslation.ResourceTranslationBase; import org.openecomp.sdc.translator.services.heattotosca.mapping.TranslatorHeatToToscaPropertyConverter; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; @@ -100,9 +105,11 @@ public class HeatToToscaUtil { private static final Logger LOGGER = LoggerFactory.getLogger(HeatToToscaUtil.class); public static final String FQ_NAME = "fq_name"; public static final String GET_PARAM = "get_param"; - private static final String FORWARDER = "forwarder"; private static final String GET_ATTR = "get_attr"; private static final String GET_RESOURCE = "get_resource"; + private static final String VMI = "vmi"; + private static final String NEUTRON_PORT_IDENTIFIER = "port"; + private static final String UNDERSCORE = "_"; /** * Load and translate template data translator output. @@ -285,7 +292,7 @@ public class HeatToToscaUtil { List<String> filenames, Set<String> referenced) { Object resourceDef = resource.getProperties().get(HeatConstants.RESOURCE_DEF_PROPERTY_NAME); - Object innerTypeDef = ((Map) resourceDef).get("type"); + Object innerTypeDef = ((Map) resourceDef).get(HeatConstants.RESOURCE_DEF_TYPE_PROPERTY_NAME); if (innerTypeDef instanceof String) { String internalResourceType = (String) innerTypeDef; if (filenames.contains(internalResourceType)) { @@ -519,12 +526,14 @@ public class HeatToToscaUtil { if (resourceType.equals(HeatResourcesTypes.RESOURCE_GROUP_RESOURCE_TYPE.getHeatResource())) { Object resourceDef = resource.getProperties().get(HeatConstants.RESOURCE_DEF_PROPERTY_NAME); - if (!(((Map) resourceDef).get("type") instanceof String)) { + if (!(((Map) resourceDef).get(HeatConstants.RESOURCE_DEF_TYPE_PROPERTY_NAME) instanceof + String)) { //currently only resource group which is poinitng to nested heat file is supported //dynamic type is currently not supported return false; } - String internalResourceType = (String) ((Map) resourceDef).get("type"); + String internalResourceType = (String) ((Map) resourceDef).get(HeatConstants + .RESOURCE_DEF_TYPE_PROPERTY_NAME); if (isYamlFile(internalResourceType)) { return true; } @@ -535,6 +544,108 @@ public class HeatToToscaUtil { } /** + * Checks if the current HEAT resource if of type sub interface. + * + * @param resource the resource + * @return true if the resource is of sub interface type and false otherwise + */ + public static boolean isSubInterfaceResource(Resource resource, TranslationContext context) { + if (!ToggleableFeature.VLAN_TAGGING.isActive()) { + //Remove this once feature is stable and moved to production + return false; + } + //Check if resource group is a nested resource + if (!isNestedResource(resource)) { + return false; + } + Optional<String> nestedHeatFileName = HeatToToscaUtil.getNestedHeatFileName(resource); + return nestedHeatFileName.filter(fileName -> + isNestedVlanResource(fileName, context)).isPresent(); + } + + private static boolean isNestedVlanResource(String nestedHeatFileName, + TranslationContext translationContext) { + HeatOrchestrationTemplate nestedHeatOrchestrationTemplate = new YamlUtil() + .yamlToObject(translationContext.getFileContent(nestedHeatFileName), + HeatOrchestrationTemplate.class); + return Objects.nonNull(nestedHeatOrchestrationTemplate.getResources()) + && nestedHeatOrchestrationTemplate.getResources().values().stream() + .anyMatch(new ContrailV2VirtualMachineInterfaceHelper()::isVlanSubInterfaceResource); + } + + public static Optional<String> getSubInterfaceParentPortNodeTemplateId(TranslateTo subInterfaceTo) { + String subInterfaceResourceType = getSubInterfaceResourceType(subInterfaceTo.getResource()); + HeatOrchestrationTemplate nestedHeatOrchestrationTemplate = new YamlUtil() + .yamlToObject(subInterfaceTo.getContext().getFileContent(subInterfaceResourceType), + HeatOrchestrationTemplate.class); + if (Objects.isNull(nestedHeatOrchestrationTemplate.getResources())) { + return Optional.empty(); + } + for (Map.Entry<String, Resource> resourceEntry : nestedHeatOrchestrationTemplate + .getResources().entrySet()) { + Resource resource = resourceEntry.getValue(); + if (isVmiRefsPropertyExists(resource)) { + Object toscaPropertyValue = + TranslatorHeatToToscaPropertyConverter.getToscaPropertyValue(subInterfaceTo.getServiceTemplate(), + resourceEntry.getKey(), HeatConstants.VMI_REFS_PROPERTY_NAME, + resource.getProperties().get(HeatConstants.VMI_REFS_PROPERTY_NAME), + resource.getType(), subInterfaceResourceType, nestedHeatOrchestrationTemplate, + null, subInterfaceTo.getContext()); + return getParentNodeTemplateIdFromPropertyValue(toscaPropertyValue, subInterfaceTo); + } + } + return Optional.empty(); + } + + private static boolean isVmiRefsPropertyExists(Resource resource) { + return HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE + .getHeatResource().equals(resource.getType()) + && MapUtils.isNotEmpty(resource.getProperties()) + && resource.getProperties().containsKey(HeatConstants.VMI_REFS_PROPERTY_NAME); + } + + public static String getSubInterfaceResourceType(Resource resource) { + if (!HeatToToscaUtil.isYamlFile(resource.getType())) { + return ((Map) resource.getProperties() + .get(HeatConstants.RESOURCE_DEF_PROPERTY_NAME)) + .get(HeatConstants.RESOURCE_DEF_TYPE_PROPERTY_NAME) + .toString(); + } + return resource.getType(); + } + + private static Optional<String> getParentNodeTemplateIdFromPropertyValue(Object toscaPropertyValue, + TranslateTo subInterfaceTo) { + if (toscaPropertyValue instanceof List + && ((List) toscaPropertyValue).get(0) instanceof Map) { + Resource subInterfaceResource = subInterfaceTo.getResource(); + Map<String, String> toscaPropertyValueMap = (Map) ((List) toscaPropertyValue).get(0); + String parentPortPropertyInput = toscaPropertyValueMap.get(ToscaFunctions.GET_INPUT + .getDisplayName()); + Map<String, Object> resourceDefPropertiesMap; + if (!isYamlFile(subInterfaceResource.getType())) { + resourceDefPropertiesMap = (Map)((Map) subInterfaceResource + .getProperties().get(HeatConstants.RESOURCE_DEF_PROPERTY_NAME)) + .get(HeatConstants.RESOURCE_DEF_PROPERTIES); + } else { + resourceDefPropertiesMap = subInterfaceResource.getProperties(); + } + Object parentPortObj = resourceDefPropertiesMap.get(parentPortPropertyInput); + if (parentPortObj instanceof Map) { + Map<String, String> parentPortPropertyValue = (Map) parentPortObj; + if (parentPortPropertyValue.keySet().contains(ResourceReferenceFunctions + .GET_RESOURCE.getFunction())) { + return ResourceTranslationBase.getResourceTranslatedId(subInterfaceTo.getHeatFileName(), + subInterfaceTo.getHeatOrchestrationTemplate(), + parentPortPropertyValue.get(ResourceReferenceFunctions.GET_RESOURCE.getFunction()), + subInterfaceTo.getContext()); + } + } + } + return Optional.empty(); + } + + /** * Checks if the nested resource represents a VFC or a complex VFC (Heat file should contain at * least one or more compute nodes). * @@ -573,7 +684,8 @@ public class HeatToToscaUtil { if (resourceType.equals(HeatResourcesTypes.RESOURCE_GROUP_RESOURCE_TYPE.getHeatResource())) { Object resourceDef = resource.getProperties().get(HeatConstants.RESOURCE_DEF_PROPERTY_NAME); - String internalResourceType = (String) ((Map) resourceDef).get("type"); + String internalResourceType = (String) ((Map) resourceDef).get(HeatConstants + .RESOURCE_DEF_TYPE_PROPERTY_NAME); return Optional.of(internalResourceType); } return Optional.of(resourceType); @@ -592,14 +704,15 @@ public class HeatToToscaUtil { String resourceType = resource.getType(); if (resourceType.equals(HeatResourcesTypes.RESOURCE_GROUP_RESOURCE_TYPE.getHeatResource())) { Object resourceDef = resource.getProperties().get(HeatConstants.RESOURCE_DEF_PROPERTY_NAME); - String internalResourceType = (String) ((Map) resourceDef).get("type"); + String internalResourceType = (String) ((Map) resourceDef).get(HeatConstants + .RESOURCE_DEF_TYPE_PROPERTY_NAME); return Optional.of(internalResourceType); } else { return Optional.of(resourceType); } } - private static boolean isYamlFile(String fileName) { + public static boolean isYamlFile(String fileName) { return fileName.endsWith(".yaml") || fileName.endsWith(".yml"); } @@ -800,7 +913,10 @@ public class HeatToToscaUtil { return Optional.empty(); } Optional<AttachedPropertyVal> extractedProperty = extractProperty(property); - return extractedProperty.flatMap(HeatToToscaUtil::getParameterName); + if (extractedProperty.isPresent()) { + return getParameterName(extractedProperty.get()); + } + return Optional.empty(); } private static Optional<String> getParameterName(AttachedPropertyVal extractedProperty) { @@ -1063,25 +1179,22 @@ public class HeatToToscaUtil { * Checks if the source and target resource is a valid candidate for adding tosca dependency * relationship. * - * @param heatOrchestrationTemplate the heat orchestration template * @param sourceResource the source resource * @param targetResource the target resource * @param dependencyEntity the dependency entity * @return true if the candidate resources are a valid combination for the dependency relationship - * and false otherwise + * and false otherwise */ - public static boolean isValidDependsOnCandidate(HeatOrchestrationTemplate - heatOrchestrationTemplate, - Resource sourceResource, + public static boolean isValidDependsOnCandidate(Resource sourceResource, Resource targetResource, ConsolidationEntityType dependencyEntity, TranslationContext context) { - dependencyEntity - .setEntityType(heatOrchestrationTemplate, sourceResource, targetResource, context); + dependencyEntity.setEntityType(sourceResource, targetResource, context); ConsolidationEntityType sourceEntityType = dependencyEntity.getSourceEntityType(); ConsolidationEntityType targetEntityType = dependencyEntity.getTargetEntityType(); - return ConsolidationTypesConnectivity.isDependsOnRelationshipValid(sourceEntityType, targetEntityType); + return ConsolidationTypesConnectivity + .isDependsOnRelationshipValid(sourceEntityType, targetEntityType); } private static Map<String, Object> managerSubstitutionNodeTemplateProperties( @@ -1183,17 +1296,12 @@ public class HeatToToscaUtil { flatNodeType.getCapabilities() .entrySet() .stream() - .filter(capabilityNodeEntry -> shouldCapabilityNeedsToBeAdded(capabilityNodeEntry.getKey())) .forEach(capabilityNodeEntry -> addCapabilityToSubMapping( templateName, capabilityNodeEntry, nodeTypeCapabilitiesDefinition, capabilitySubstitutionMapping)); } } - private static boolean shouldCapabilityNeedsToBeAdded(String capabilityKey) { - return !capabilityKey.contains(FORWARDER) || ToggleableFeature.FORWARDER_CAPABILITY.isActive(); - } - public static boolean shouldAnnotationsToBeAdded() { return ToggleableFeature.ANNOTATIONS.isActive(); } @@ -1204,7 +1312,7 @@ public class HeatToToscaUtil { Map<String, List<String>> capabilitySubstitutionMapping) { String capabilityKey; List<String> capabilityMapping; - capabilityKey = capabilityNodeEntry.getKey() + "_" + templateName; + capabilityKey = capabilityNodeEntry.getKey() + UNDERSCORE + templateName; nodeTypeCapabilitiesDefinition.put(capabilityKey, capabilityNodeEntry.getValue().clone()); capabilityMapping = new ArrayList<>(); capabilityMapping.add(templateName); @@ -1243,7 +1351,7 @@ public class HeatToToscaUtil { requirementMapping.add(templateName); requirementMapping.add(requirementNodeEntry.getKey()); requirementSubstitutionMapping - .put(requirementNodeEntry.getKey() + "_" + templateName, requirementMapping); + .put(requirementNodeEntry.getKey() + UNDERSCORE + templateName, requirementMapping); if (Objects.isNull(requirementNodeEntryValue.getNode())) { requirementNodeEntryValue.setOccurrences(new Object[]{1, 1}); } @@ -1354,4 +1462,66 @@ public class HeatToToscaUtil { return serviceTemplatesMap; } + public static String getNestedResourceTypePrefix(TranslateTo translateTo) { + String nestedFileName = translateTo.getResource().getType(); + if (isSubInterfaceResource(translateTo.getResource(), translateTo.getContext()) + && isSubInterfaceBoundToPort(translateTo)) { + return ToscaNodeType.VLAN_SUB_INTERFACE_RESOURCE_TYPE_PREFIX; + } + return ToscaNodeType.NESTED_HEAT_RESOURCE_TYPE_PREFIX; + } + + private static boolean isSubInterfaceBoundToPort(TranslateTo translateTo) { + return HeatToToscaUtil.getSubInterfaceParentPortNodeTemplateId(translateTo).isPresent(); + } + + //Method evaluate the network role from sub interface node template id, designed considering + // only single sub interface present in nested file else it will return null + public static Optional<String> getNetworkRoleFromResource(Resource resource, + TranslationContext translationContext) { + Optional<String> networkRole = Optional.empty(); + Optional<String> nestedHeatFileName = HeatToToscaUtil.getNestedHeatFileName(resource); + + if (!nestedHeatFileName.isPresent()) { + return networkRole; + } + + HeatOrchestrationTemplate nestedHeatOrchestrationTemplate = new YamlUtil() + .yamlToObject(translationContext.getFileContent(nestedHeatFileName.get()), + HeatOrchestrationTemplate.class); + + if (MapUtils.isNotEmpty(nestedHeatOrchestrationTemplate.getResources())) { + ContrailV2VirtualMachineInterfaceHelper contrailV2VirtualMachineInterfaceHelper = + new ContrailV2VirtualMachineInterfaceHelper(); + Optional<Map.Entry<String, Resource>> vlanSubinterfaceResource = nestedHeatOrchestrationTemplate + .getResources().entrySet().stream() + .filter(resourceEntry -> contrailV2VirtualMachineInterfaceHelper + .isVlanSubInterfaceResource(resourceEntry.getValue())) + .findFirst(); + if (vlanSubinterfaceResource.isPresent()) { + Map.Entry<String, Resource> vlanSubinterfaceResourceEntry = vlanSubinterfaceResource.get(); + networkRole = evaluateNetworkRoleFromResourceId(vlanSubinterfaceResourceEntry.getKey(), + vlanSubinterfaceResourceEntry.getValue().getType()); + } + } + return networkRole; + } + + public static Optional<String> evaluateNetworkRoleFromResourceId(String resourceId, String resourceType) { + String[] splitStr = resourceId.toLowerCase().split(UNDERSCORE); + List<String> splitList = Arrays.asList(splitStr); + + if (resourceType.equals(HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource())) { + if (splitList.contains(VMI)) { + return Optional.of(splitList.get(splitList.indexOf(VMI) - 1)); + } + } + + if (resourceType.equals(HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource())) { + if (splitList.contains(NEUTRON_PORT_IDENTIFIER)) { + return Optional.of(splitList.get(splitList.indexOf(NEUTRON_PORT_IDENTIFIER) - 1)); + } + } + 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/UnifiedCompositionService.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/UnifiedCompositionService.java index cfab3fc022..84a9dcf442 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/UnifiedCompositionService.java +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/UnifiedCompositionService.java @@ -1,25 +1,40 @@ /* - * ============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; +import static org.openecomp.sdc.tosca.services.DataModelUtil.getClonedObject; +import static org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.composition.UnifiedCompositionEntity.COMPUTE; +import static org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.composition.UnifiedCompositionEntity.PORT; +import static org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.composition.UnifiedCompositionEntity.SUB_INTERFACE; +import static org.openecomp.sdc.translator.services.heattotosca.Constants.ABSTRACT_NODE_TEMPLATE_ID_PREFIX; +import static org.openecomp.sdc.translator.services.heattotosca.Constants.COMPUTE_IDENTICAL_VALUE_PROPERTY_PREFIX; +import static org.openecomp.sdc.translator.services.heattotosca.Constants.COMPUTE_IDENTICAL_VALUE_PROPERTY_SUFFIX; +import static org.openecomp.sdc.translator.services.heattotosca.Constants.PORT_IDENTICAL_VALUE_PROPERTY_PREFIX; +import static org.openecomp.sdc.translator.services.heattotosca.Constants.SUB_INTERFACE_PROPERTY_VALUE_PREFIX; +import static org.openecomp.sdc.translator.services.heattotosca.UnifiedCompositionUtil.getComputeTypeSuffix; +import static org.openecomp.sdc.translator.services.heattotosca.UnifiedCompositionUtil.getConnectedComputeConsolidationData; +import static org.openecomp.sdc.translator.services.heattotosca.UnifiedCompositionUtil.getNewComputeNodeTemplateId; +import static org.openecomp.sdc.translator.services.heattotosca.UnifiedCompositionUtil.getNewPortNodeTemplateId; +import static org.openecomp.sdc.translator.services.heattotosca.UnifiedCompositionUtil.getNewSubInterfaceNodeTemplateId; +import static org.openecomp.sdc.translator.services.heattotosca.UnifiedCompositionUtil.getSubInterfacePortTemplateConsolidationData; +import static org.openecomp.sdc.translator.services.heattotosca.UnifiedCompositionUtil.getSubInterfaceTemplateConsolidationDataList; +import static org.openecomp.sdc.translator.services.heattotosca.UnifiedCompositionUtil.getSubInterfaceTypeSuffix; + +import com.google.common.collect.ListMultimap; import org.apache.commons.collections.map.HashedMap; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; @@ -31,8 +46,6 @@ import org.openecomp.config.api.ConfigurationManager; import org.openecomp.core.utilities.CommonMethods; import org.openecomp.sdc.datatypes.configuration.ImplementationConfiguration; 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.openecomp.sdc.tosca.datatypes.ToscaGroupType; import org.openecomp.sdc.tosca.datatypes.ToscaNodeType; @@ -49,9 +62,9 @@ import org.openecomp.sdc.tosca.datatypes.model.PropertyDefinition; import org.openecomp.sdc.tosca.datatypes.model.PropertyType; import org.openecomp.sdc.tosca.datatypes.model.RelationshipTemplate; import org.openecomp.sdc.tosca.datatypes.model.RequirementAssignment; -import org.openecomp.sdc.tosca.datatypes.model.RequirementDefinition; import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate; import org.openecomp.sdc.tosca.datatypes.model.SubstitutionMapping; +import org.openecomp.sdc.tosca.datatypes.model.heatextend.ParameterDefinitionExt; import org.openecomp.sdc.tosca.datatypes.model.heatextend.PropertyTypeExt; import org.openecomp.sdc.tosca.services.DataModelUtil; import org.openecomp.sdc.tosca.services.ToscaAnalyzerService; @@ -63,6 +76,9 @@ import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.compositi import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.composition.UnifiedCompositionEntity; import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.composition.UnifiedCompositionMode; import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.composition.UnifiedSubstitutionData; +import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.composition.commands.CommandImplNames; +import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.composition.commands.UnifiedSubstitutionNodeTemplateIdGenerator; +import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.composition.to.UnifiedCompositionTo; import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.ComputeTemplateConsolidationData; import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.ConsolidationData; import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.EntityConsolidationData; @@ -72,11 +88,12 @@ import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolida import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.NestedTemplateConsolidationData; import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.PortTemplateConsolidationData; import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.RequirementAssignmentData; +import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.SubInterfaceTemplateConsolidationData; import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.TypeComputeConsolidationData; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; +import java.util.EnumMap; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; @@ -86,42 +103,41 @@ import java.util.Objects; import java.util.Optional; import java.util.Set; import java.util.regex.Pattern; - -import static org.openecomp.sdc.tosca.services.DataModelUtil.getClonedObject; -import static org.openecomp.sdc.translator.services.heattotosca.Constants.ABSTRACT_NODE_TEMPLATE_ID_PREFIX; -import static org.openecomp.sdc.translator.services.heattotosca.Constants.COMPUTE_IDENTICAL_VALUE_PROPERTY_PREFIX; -import static org.openecomp.sdc.translator.services.heattotosca.Constants.COMPUTE_IDENTICAL_VALUE_PROPERTY_SUFFIX; -import static org.openecomp.sdc.translator.services.heattotosca.Constants.PORT_IDENTICAL_VALUE_PROPERTY_PREFIX; +import java.util.stream.Collectors; public class UnifiedCompositionService { - protected static Logger logger = - (Logger) LoggerFactory.getLogger(UnifiedCompositionService.class); - private static Map<String, ImplementationConfiguration> unifiedCompositionImplMap; + private static final Map<String, ImplementationConfiguration> unifiedCompositionImplMap; + + private static final EnumMap<UnifiedCompositionEntity, String> unifiedSubstitutionNodeTemplateIdGeneratorImplMap; static { Configuration config = ConfigurationManager.lookup(); unifiedCompositionImplMap = config.populateMap(ConfigConstants.MANDATORY_UNIFIED_MODEL_NAMESPACE, ConfigConstants.UNIFIED_COMPOSITION_IMPL_KEY, ImplementationConfiguration.class); + unifiedSubstitutionNodeTemplateIdGeneratorImplMap = new EnumMap<>(UnifiedCompositionEntity.class); + initNodeTemplateIdGeneratorImplMap(); + } + private static void initNodeTemplateIdGeneratorImplMap() { + unifiedSubstitutionNodeTemplateIdGeneratorImplMap.put(COMPUTE, CommandImplNames + .COMPUTE_NEW_NODE_TEMPLATE_ID_GENERATOR_IMPL); + unifiedSubstitutionNodeTemplateIdGeneratorImplMap.put(PORT, CommandImplNames + .PORT_NEW_NODE_TEMPLATE_ID_GENERATOR_IMPL); + unifiedSubstitutionNodeTemplateIdGeneratorImplMap.put(SUB_INTERFACE, CommandImplNames + .SUB_INTERFACE_NEW_NODE_TEMPLATE_ID_GENERATOR_IMPL); } - private ConsolidationService consolidationService = new ConsolidationService(); + private final ConsolidationService consolidationService = new ConsolidationService(); private static List<EntityConsolidationData> getPortConsolidationDataList( List<String> portIds, List<UnifiedCompositionData> unifiedCompositionDataList) { - List<EntityConsolidationData> portConsolidationDataList = new ArrayList<>(); - for (UnifiedCompositionData unifiedCompositionData : unifiedCompositionDataList) { - for (PortTemplateConsolidationData portTemplateConsolidationData : unifiedCompositionData - .getPortTemplateConsolidationDataList()) { - if (portIds.contains(portTemplateConsolidationData.getNodeTemplateId())) { - portConsolidationDataList.add(portTemplateConsolidationData); - } - } - } - return portConsolidationDataList; + return unifiedCompositionDataList.stream() + .flatMap(unifiedCompositionData -> unifiedCompositionData.getPortTemplateConsolidationDataList().stream()) + .filter(portTemplateConsolidationData -> portIds.contains(portTemplateConsolidationData.getNodeTemplateId())) + .collect(Collectors.toList()); } /** @@ -170,9 +186,7 @@ public class UnifiedCompositionService { if (CollectionUtils.isEmpty(unifiedCompositionDataList)) { return Optional.empty(); } - UnifiedCompositionData unifiedCompositionData = unifiedCompositionDataList.get(0); - String templateName = - getTemplateName(serviceTemplate, unifiedCompositionData, substitutionNodeTypeId, index); + String templateName = getTemplateName(substitutionNodeTypeId, index); ServiceTemplate substitutionServiceTemplate = HeatToToscaUtil.createInitSubstitutionServiceTemplate(templateName); @@ -183,11 +197,14 @@ public class UnifiedCompositionService { context); handlePorts(serviceTemplate, substitutionServiceTemplate, unifiedCompositionDataList, computeNodeType, context); - createOutputParameters(serviceTemplate, substitutionServiceTemplate, unifiedCompositionDataList, - computeNodeType, context); + + UnifiedCompositionTo unifiedCompositionTo = new UnifiedCompositionTo(serviceTemplate, + substitutionServiceTemplate, unifiedCompositionDataList, context); + handleSubInterfaces(unifiedCompositionTo); + createOutputParameters(unifiedCompositionTo, computeNodeType); NodeType substitutionGlobalNodeType = handleSubstitutionGlobalNodeType(serviceTemplate, substitutionServiceTemplate, - context, unifiedCompositionData, substitutionNodeTypeId, index); + context, substitutionNodeTypeId); HeatToToscaUtil.handleSubstitutionMapping(context, substitutionNodeTypeId, @@ -224,9 +241,13 @@ public class UnifiedCompositionService { directiveList.add(ToscaConstants.NODE_TEMPLATE_DIRECTIVE_SUBSTITUTABLE); substitutionNodeTemplate.setDirectives(directiveList); substitutionNodeTemplate.setType(substituteNodeTypeId); - Optional<Map<String, Object>> abstractSubstitutionProperties = - createAbstractSubstitutionProperties(serviceTemplate, - substitutionServiceTemplate, unifiedCompositionDataList, context); + Map<String, ParameterDefinition> substitutionTemplateInputs = DataModelUtil + .getInputParameters(substitutionServiceTemplate); + Optional<Map<String, Object>> abstractSubstitutionProperties = Optional.empty(); + if (Objects.nonNull(substitutionTemplateInputs)) { + abstractSubstitutionProperties = createAbstractSubstitutionProperties(serviceTemplate, + substitutionTemplateInputs, unifiedCompositionDataList, context); + } abstractSubstitutionProperties.ifPresent(substitutionNodeTemplate::setProperties); //Add substitution filtering property @@ -237,9 +258,7 @@ public class UnifiedCompositionService { substitutionNodeTemplate, count); //Add index_value property addIndexValueProperty(substitutionNodeTemplate); - String substituteNodeTemplateId = - getSubstituteNodeTemplateId(serviceTemplate, unifiedCompositionDataList.get(0), - substituteNodeTypeId, index); + String substituteNodeTemplateId = getSubstituteNodeTemplateId(substituteNodeTypeId, index); //Add node template id and related abstract node template id in context addUnifiedSubstitionData(context, serviceTemplate, unifiedCompositionDataList, substituteNodeTemplateId); @@ -287,18 +306,27 @@ public class UnifiedCompositionService { List<UnifiedCompositionData> unifiedCompositionDataList, TranslationContext context) { for (UnifiedCompositionData unifiedCompositionData : unifiedCompositionDataList) { + //Clean compute node template data from top level service template ComputeTemplateConsolidationData computeTemplateConsolidationData = unifiedCompositionData.getComputeTemplateConsolidationData(); cleanServiceTemplate(serviceTemplate, computeTemplateConsolidationData, context); + //Clean port node template data from top level service template List<PortTemplateConsolidationData> portTemplateConsolidationDataList = getPortTemplateConsolidationDataList(unifiedCompositionData); for (PortTemplateConsolidationData portTemplateConsolidationData : portTemplateConsolidationDataList) { cleanServiceTemplate(serviceTemplate, portTemplateConsolidationData, context); } - } + //Clean sub-interface node template data from top level service template + List<SubInterfaceTemplateConsolidationData> subInterfaceTemplateConsolidationDataList = + getSubInterfaceTemplateConsolidationDataList(unifiedCompositionData); + for (SubInterfaceTemplateConsolidationData subInterfaceTemplateConsolidationData : + subInterfaceTemplateConsolidationDataList) { + cleanServiceTemplate(serviceTemplate, subInterfaceTemplateConsolidationData, context); + } + } } /** @@ -322,10 +350,10 @@ public class UnifiedCompositionService { } public void updateSubstitutionNodeTypePrefix(ServiceTemplate substitutionServiceTemplate) { - Map<String, NodeTemplate> node_templates = + Map<String, NodeTemplate> nodeTemplates = substitutionServiceTemplate.getTopology_template().getNode_templates(); - for (Map.Entry<String, NodeTemplate> nodeTemplateEntry : node_templates.entrySet()) { + for (Map.Entry<String, NodeTemplate> nodeTemplateEntry : nodeTemplates.entrySet()) { String nodeTypeId = nodeTemplateEntry.getValue().getType(); NodeType origNodeType = substitutionServiceTemplate.getNode_types().get(nodeTypeId); if (Objects.nonNull(origNodeType) @@ -409,8 +437,7 @@ public class UnifiedCompositionService { nestedServiceTemplate.getTopology_template().getSubstitution_mappings(); String nodeTypeId = substitutionMappings.getNode_type(); - Optional<String> newNestedNodeTypeId = - getNewNestedNodeTypeId(mainServiceTemplate, nestedServiceTemplate, context); + Optional<String> newNestedNodeTypeId = getNewNestedNodeTypeId(nestedServiceTemplate, context); ServiceTemplate globalSubstitutionServiceTemplate = context.getGlobalSubstitutionServiceTemplate(); @@ -480,7 +507,7 @@ public class UnifiedCompositionService { .getPortTemplateConsolidationData(portNodeTemplateId)); handleNodeTypeProperties(nestedServiceTemplate, - portEntityConsolidationDataList, portNodeTemplate, UnifiedCompositionEntity.Port, + portEntityConsolidationDataList, portNodeTemplate, UnifiedCompositionEntity.PORT, null, context); } } @@ -499,8 +526,6 @@ public class UnifiedCompositionService { updateNodeTypeProperties(nestedServiceTemplate, globalSubstitutionServiceTemplate, indexedNewNestedNodeTypeId); - //addComputeNodeTypeToGlobalST(); - } private void updateNodeTypeProperties(ServiceTemplate nestedServiceTemplate, @@ -555,7 +580,7 @@ public class UnifiedCompositionService { ToscaUtil.getServiceTemplateFileName(Constants.GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME), newNestedNodeTypeId); return globalNodeTypeIndex > 0 ? newNestedNodeTypeId + "_" - + String.valueOf(globalNodeTypeIndex) : newNestedNodeTypeId; + + globalNodeTypeIndex : newNestedNodeTypeId; } private void updateUnifiedNestedTemplates(ServiceTemplate mainServiceTemplate, @@ -615,21 +640,19 @@ public class UnifiedCompositionService { } public void handleComplexVfcType(ServiceTemplate serviceTemplate, TranslationContext context) { - SubstitutionMapping substitution_mappings = + SubstitutionMapping substitutionMapping = serviceTemplate.getTopology_template().getSubstitution_mappings(); - if (Objects.isNull(substitution_mappings)) { + if (Objects.isNull(substitutionMapping)) { return; } ServiceTemplate globalSubstitutionServiceTemplate = context.getGlobalSubstitutionServiceTemplate(); - String substitutionNT = substitution_mappings.getNode_type(); + String substitutionNT = substitutionMapping.getNode_type(); if (globalSubstitutionServiceTemplate.getNode_types().containsKey(substitutionNT)) { - //todo - remove comment after integration with AT&T -// globalSubstitutionServiceTemplate.getNode_types().get(substitutionNT).setDerived_from -// (ToscaNodeType.COMPLEX_VFC_NODE_TYPE); + //This needs to be done when catalog is ready for complex VFC } } @@ -666,6 +689,30 @@ public class UnifiedCompositionService { newPortNodeTemplateId, portNodesConnectedOut, context); } } + //For sub-interface + //Add requirements in the abstract node template for nodes connected out for ports + updateSubInterfaceNodesConnectedOut(serviceTemplate, unifiedCompositionData, + computeTemplateConsolidationData, computeType, context); + } + } + + private void updateSubInterfaceNodesConnectedOut(ServiceTemplate serviceTemplate, + UnifiedCompositionData unifiedCompositionData, + ComputeTemplateConsolidationData computeTemplateConsolidationData, + String computeType, + TranslationContext context) { + List<SubInterfaceTemplateConsolidationData> subInterfaceTemplateConsolidationDataList = + getSubInterfaceTemplateConsolidationDataList(unifiedCompositionData); + for (SubInterfaceTemplateConsolidationData subInterfaceTemplateConsolidationData : + subInterfaceTemplateConsolidationDataList) { + String newSubInterfaceNodeTemplateId = getNewSubInterfaceNodeTemplateId(serviceTemplate, computeType, + computeTemplateConsolidationData, subInterfaceTemplateConsolidationData, context); + Map<String, List<RequirementAssignmentData>> subInterfaceNodesConnectedOut = + subInterfaceTemplateConsolidationData.getNodesConnectedOut(); + if (subInterfaceNodesConnectedOut != null) { + updateRequirementInAbstractNodeTemplate(serviceTemplate, subInterfaceTemplateConsolidationData, + newSubInterfaceNodeTemplateId, subInterfaceNodesConnectedOut, context); + } } } @@ -694,13 +741,13 @@ public class UnifiedCompositionService { } String singleComputeId = computeType.getAllComputeNodeTemplateIds().iterator().next(); - if (Objects.nonNull(singleComputeId)) { + if (Objects.nonNull(singleComputeId) && (Objects.nonNull(nestedTemplateConsolidationData))) { updateRequirementInNestedNodeTemplate(serviceTemplate, nestedTemplateConsolidationData, singleComputeId, nodesConnectedOut); } } - protected void updNodesConnectedInConnectivity(ServiceTemplate serviceTemplate, + private void updNodesConnectedInConnectivity(ServiceTemplate serviceTemplate, List<UnifiedCompositionData> unifiedCompositionDataList, TranslationContext context) { @@ -725,6 +772,10 @@ public class UnifiedCompositionService { updNodesConnectedInConnectivity(serviceTemplate, portTemplateConsolidationData, newPortNodeTemplateId, context, false); } + + //Update requirements in the node template which pointing to the sub-interface + updateSubInterfaceNodesConnectedIn(serviceTemplate, unifiedCompositionData, + computeTemplateConsolidationData, computeType, context); } } @@ -754,7 +805,7 @@ public class UnifiedCompositionService { //Update the requirement assignment object in the original node template if (isNested) { updateRequirementForNestedCompositionNodesConnectedIn(serviceTemplate, - requirementAssignmentData, entityConsolidationData, newNodeTemplateId, context); + requirementAssignmentData, newNodeTemplateId); } else { updateRequirementForNodesConnectedIn(serviceTemplate, requirementAssignmentData, entityConsolidationData, entry.getKey(), newNodeTemplateId, context); @@ -764,6 +815,22 @@ public class UnifiedCompositionService { } } + private void updateSubInterfaceNodesConnectedIn(ServiceTemplate serviceTemplate, + UnifiedCompositionData unifiedCompositionData, + ComputeTemplateConsolidationData computeTemplateConsolidationData, + String computeType, + TranslationContext context) { + List<SubInterfaceTemplateConsolidationData> subInterfaceTemplateConsolidationDataList = + getSubInterfaceTemplateConsolidationDataList(unifiedCompositionData); + for (SubInterfaceTemplateConsolidationData subInterfaceTemplateConsolidationData : + subInterfaceTemplateConsolidationDataList) { + String newSubInterfaceNodeTemplateId = getNewSubInterfaceNodeTemplateId(serviceTemplate, computeType, + computeTemplateConsolidationData, subInterfaceTemplateConsolidationData, context); + updNodesConnectedInConnectivity(serviceTemplate, subInterfaceTemplateConsolidationData, + newSubInterfaceNodeTemplateId, context, false); + } + } + protected void updNestedCompositionNodesConnectedInConnectivity( ServiceTemplate serviceTemplate, UnifiedCompositionData unifiedCompositionData, @@ -781,24 +848,7 @@ public class UnifiedCompositionService { } -// protected void updNestedCompositionNodesConnectedOutConnectivity( -// ServiceTemplate serviceTemplate, -// UnifiedCompositionData unifiedCompositionData, -// TranslationContext context) { -// NestedTemplateConsolidationData nestedTemplateConsolidationData = unifiedCompositionData -// .getNestedTemplateConsolidationData(); -// //Update requirements in the node template which pointing to the nested nodes -// String serviceTemplateFileName = ToscaUtil.getServiceTemplateFileName(serviceTemplate); -// Optional<String> newNestedNodeTemplateId = context.getUnifiedNestedNodeTemplateId( -// serviceTemplateFileName, nestedTemplateConsolidationData.getNodeTemplateId()); -// newNestedNodeTemplateId.ifPresent( -// newNestedNodeTemplateIdVal -> updNodesConnectedOutConnectivity(serviceTemplate, -// nestedTemplateConsolidationData, -// newNestedNodeTemplateIdVal, context, true)); -// -// } - - protected void updVolumeConnectivity(ServiceTemplate serviceTemplate, + private void updVolumeConnectivity(ServiceTemplate serviceTemplate, List<UnifiedCompositionData> unifiedCompositionDataList, TranslationContext context) { @@ -817,7 +867,7 @@ public class UnifiedCompositionService { } } - protected void updGroupsConnectivity(ServiceTemplate serviceTemplate, + private void updGroupsConnectivity(ServiceTemplate serviceTemplate, List<UnifiedCompositionData> unifiedCompositionDataList, TranslationContext context) { @@ -825,21 +875,23 @@ public class UnifiedCompositionService { ComputeTemplateConsolidationData computeTemplateConsolidationData = unifiedCompositionData .getComputeTemplateConsolidationData(); //Add requirements in the abstract node template for nodes connected in for computes - String newComputeNodeTemplateId = getNewComputeNodeTemplateId(serviceTemplate, - computeTemplateConsolidationData.getNodeTemplateId()); updGroupsConnectivity(serviceTemplate, computeTemplateConsolidationData, context); - String computeType = getComputeTypeSuffix(serviceTemplate, computeTemplateConsolidationData - .getNodeTemplateId()); //Add requirements in the abstract node template for nodes connected in for ports List<PortTemplateConsolidationData> portTemplateConsolidationDataList = getPortTemplateConsolidationDataList(unifiedCompositionData); for (PortTemplateConsolidationData portTemplateConsolidationData : portTemplateConsolidationDataList) { - String newPortNodeTemplateId = getNewPortNodeTemplateId(portTemplateConsolidationData - .getNodeTemplateId(), computeType, computeTemplateConsolidationData); updGroupsConnectivity(serviceTemplate, portTemplateConsolidationData, context); } + + //Add requirements in the abstract node template for nodes connected in for subInterface + List<SubInterfaceTemplateConsolidationData> subInterfaceTemplateConsolidationDataList = + getSubInterfaceTemplateConsolidationDataList(unifiedCompositionData); + for (SubInterfaceTemplateConsolidationData subInterfaceTemplateConsolidationData : + subInterfaceTemplateConsolidationDataList) { + updGroupsConnectivity(serviceTemplate, subInterfaceTemplateConsolidationData, context); + } } } @@ -853,25 +905,27 @@ public class UnifiedCompositionService { String abstractNodeTemplateId = context.getUnifiedAbstractNodeTemplateId( serviceTemplate, entityConsolidationData.getNodeTemplateId()); Map<String, GroupDefinition> groups = serviceTemplate.getTopology_template().getGroups(); - if (groups != null) { - for (String groupId : groupIds) { - GroupDefinition groupDefinition = groups.get(groupId); - if (groupDefinition != null) { - List<String> groupMembers = groupDefinition.getMembers(); - if (groupMembers.contains(oldNodeTemplateId)) { - //Replace the old node template id - groupMembers.remove(oldNodeTemplateId); - if (!groupMembers.contains(abstractNodeTemplateId)) { - //Add the abstract node template id if not already present - groupMembers.add(abstractNodeTemplateId); - } - } + if (groups == null) { + return; + } + for (String groupId : groupIds) { + GroupDefinition groupDefinition = groups.get(groupId); + if (groupDefinition == null) { + continue; + } + List<String> groupMembers = groupDefinition.getMembers(); + if (groupMembers.contains(oldNodeTemplateId)) { + //Replace the old node template id + groupMembers.remove(oldNodeTemplateId); + if (!groupMembers.contains(abstractNodeTemplateId)) { + //Add the abstract node template id if not already present + groupMembers.add(abstractNodeTemplateId); } } } } - protected void updOutputParamGetAttrInConnectivity( + private void updOutputParamGetAttrInConnectivity( ServiceTemplate serviceTemplate, List<UnifiedCompositionData> unifiedComposotionDataList, TranslationContext context) { for (UnifiedCompositionData unifiedCompositionData : unifiedComposotionDataList) { @@ -899,10 +953,30 @@ public class UnifiedCompositionService { portTemplateConsolidationData.getNodeTemplateId(), newPortNodeTemplateId, context, false); } + + updateSubInterfaceOutputParamGetAttrIn(serviceTemplate, unifiedCompositionData, + computeTemplateConsolidationData, computeType, context); + } + } + + private void updateSubInterfaceOutputParamGetAttrIn(ServiceTemplate serviceTemplate, + UnifiedCompositionData unifiedCompositionData, + ComputeTemplateConsolidationData computeTemplateConsolidationData, + String computeType, + TranslationContext context) { + List<SubInterfaceTemplateConsolidationData> subInterfaceTemplateConsolidationDataList = + getSubInterfaceTemplateConsolidationDataList(unifiedCompositionData); + for (SubInterfaceTemplateConsolidationData subInterfaceTemplateConsolidationData : + subInterfaceTemplateConsolidationDataList) { + String newSubInterfaceNodeTemplateId = getNewSubInterfaceNodeTemplateId(serviceTemplate, computeType, + computeTemplateConsolidationData, subInterfaceTemplateConsolidationData, context); + updOutputParamGetAttrInConnectivity(serviceTemplate, subInterfaceTemplateConsolidationData, + subInterfaceTemplateConsolidationData.getNodeTemplateId(), newSubInterfaceNodeTemplateId, context, + false); } } - protected void updNodesGetAttrInConnectivity( + private void updNodesGetAttrInConnectivity( ServiceTemplate serviceTemplate, List<UnifiedCompositionData> unifiedComposotionDataList, TranslationContext context) { @@ -934,6 +1008,28 @@ public class UnifiedCompositionService { portTemplateConsolidationData.getNodeTemplateId(), newPotNodeTemplateId, context, consolidationNodeTemplateIdAndType, false); } + + updateSubInterfaceNodesGetAttrIn(serviceTemplate, unifiedCompositionData, + computeTemplateConsolidationData, computeType, consolidationNodeTemplateIdAndType, context); + } + } + + private void updateSubInterfaceNodesGetAttrIn(ServiceTemplate serviceTemplate, + UnifiedCompositionData unifiedCompositionData, + ComputeTemplateConsolidationData computeTemplateConsolidationData, + String computeType, + Map<String, UnifiedCompositionEntity> consolidationNodeTemplateIdAndType, + TranslationContext context) { + List<SubInterfaceTemplateConsolidationData> subInterfaceTemplateConsolidationDataList = + getSubInterfaceTemplateConsolidationDataList(unifiedCompositionData); + for (SubInterfaceTemplateConsolidationData subInterfaceTemplateConsolidationData : + subInterfaceTemplateConsolidationDataList) { + String newSubInterfaceNodeTemplateId = getNewSubInterfaceNodeTemplateId(serviceTemplate, computeType, + computeTemplateConsolidationData, subInterfaceTemplateConsolidationData, context); + updNodeGetAttrInConnectivity(serviceTemplate, subInterfaceTemplateConsolidationData, + subInterfaceTemplateConsolidationData.getNodeTemplateId(), + newSubInterfaceNodeTemplateId, context, + consolidationNodeTemplateIdAndType, false); } } @@ -1018,9 +1114,7 @@ public class UnifiedCompositionService { private void updateRequirementForNestedCompositionNodesConnectedIn( ServiceTemplate serviceTemplate, RequirementAssignmentData requirementAssignmentData, - EntityConsolidationData entityConsolidationData, - String newNodeTemplateId, - TranslationContext context) { + String newNodeTemplateId) { ToscaAnalyzerService toscaAnalyzerService = new ToscaAnalyzerServiceImpl(); String newAbstractUnifiedNodeTemplateId = newNodeTemplateId; RequirementAssignment requirementAssignment = requirementAssignmentData @@ -1064,11 +1158,10 @@ public class UnifiedCompositionService { String capabilityId = entry.getKey(); CapabilityDefinition capabilityDefinition = entry.getValue(); String capabilityType = capabilityDefinition.getType(); - if (capabilityType.equals(requirementAssignment.getCapability())) { + if (capabilityType.equals(requirementAssignment.getCapability()) + && capabilityId.endsWith(newNodeTemplateId)) { //Matching capability type found..Check if the id ends with new node template id - if (capabilityId.endsWith(newNodeTemplateId)) { - return Optional.ofNullable(capabilityId); - } + return Optional.ofNullable(capabilityId); } } return Optional.empty(); @@ -1154,38 +1247,6 @@ public class UnifiedCompositionService { } } - private NodeTemplate getAbstractNodeTemplate( - ServiceTemplate serviceTemplate, - UnifiedCompositionEntity unifiedCompositionEntity, - ComputeTemplateConsolidationData computeTemplateConsolidationData, - PortTemplateConsolidationData portTemplateConsolidationData, - TranslationContext context) { - String abstractNodeTemplateId = - getAbstractNodeTemplateId(serviceTemplate, unifiedCompositionEntity, - computeTemplateConsolidationData, portTemplateConsolidationData, context); - - return DataModelUtil.getNodeTemplate(serviceTemplate, - abstractNodeTemplateId); - } - - private String getAbstractNodeTemplateId( - ServiceTemplate serviceTemplate, - UnifiedCompositionEntity unifiedCompositionEntity, - ComputeTemplateConsolidationData computeTemplateConsolidationData, - PortTemplateConsolidationData portTemplateConsolidationData, - TranslationContext context) { - switch (unifiedCompositionEntity) { - case Compute: - return context.getUnifiedAbstractNodeTemplateId(serviceTemplate, - computeTemplateConsolidationData.getNodeTemplateId()); - case Port: - return context.getUnifiedAbstractNodeTemplateId(serviceTemplate, - portTemplateConsolidationData.getNodeTemplateId()); - default: - return null; - } - } - private void updNodeGetAttrInConnectivity( ServiceTemplate serviceTemplate, EntityConsolidationData entityConsolidationData, @@ -1198,13 +1259,14 @@ public class UnifiedCompositionService { return; } - for (String sourceNodeTemplateId : nodesGetAttrIn.keySet()) { + for (Map.Entry<String, List<GetAttrFuncData>> nodesGetAttrInEntry : nodesGetAttrIn.entrySet()) { + String sourceNodeTemplateId = nodesGetAttrInEntry.getKey(); NodeTemplate sourceNodeTemplate = DataModelUtil.getNodeTemplate(serviceTemplate, sourceNodeTemplateId); if (!isNested && consolidationNodeTemplateIdAndType.keySet().contains(sourceNodeTemplateId)) { continue; } - List<GetAttrFuncData> getAttrFuncDataList = nodesGetAttrIn.get(sourceNodeTemplateId); + List<GetAttrFuncData> getAttrFuncDataList = nodesGetAttrInEntry.getValue(); for (GetAttrFuncData getAttrFuncData : getAttrFuncDataList) { Object propertyValue = DataModelUtil.getPropertyValue(sourceNodeTemplate, getAttrFuncData.getFieldName()); @@ -1237,12 +1299,8 @@ public class UnifiedCompositionService { } } - private String getTemplateName(ServiceTemplate serviceTemplate, - UnifiedCompositionData unifiedCompositionData, - String nodeTypeId, + private String getTemplateName(String nodeTypeId, Integer index) { - ComputeTemplateConsolidationData computeTemplateConsolidationData = - unifiedCompositionData.getComputeTemplateConsolidationData(); String computeType = getComputeTypeSuffix(nodeTypeId); String templateName = "Nested_" + computeType; if (Objects.nonNull(index)) { @@ -1251,23 +1309,6 @@ public class UnifiedCompositionService { return templateName; } - private String getComputeTypeSuffix(ServiceTemplate serviceTemplate, - String computeNodeTemplateId) { - NodeTemplate computeNodeTemplate = - DataModelUtil.getNodeTemplate(serviceTemplate, computeNodeTemplateId); - return getComputeTypeSuffix(computeNodeTemplate.getType()); - } - - /** - * Gets compute type. - * - * @param computeType the compute node type abc.def.vFSB - * @return the compute type e.g.:vFSB - */ - private String getComputeTypeSuffix(String computeType) { - return DataModelUtil.getNamespaceSuffix(computeType); - } - private void updOutputParamGetAttrInConnectivity(ServiceTemplate serviceTemplate, EntityConsolidationData entityConsolidationData, String oldNodeTemplateId, @@ -1334,13 +1375,9 @@ public class UnifiedCompositionService { return true; } } -// Map.Entry<String, Object> functionMapEntry = -// (Map.Entry<String, Object>) ((Map) valueObject).entrySet().iterator().next(); -// return isIncludeToscaFunc(functionMapEntry.getValue(), toscaFunction); - } else if (valueObject instanceof List) { for (Object valueEntity : (List) valueObject) { - if (isIncludeToscaFunc(valueEntity, toscaFunction) == true) { + if (isIncludeToscaFunc(valueEntity, toscaFunction)) { return true; } } @@ -1348,19 +1385,18 @@ public class UnifiedCompositionService { return false; } - private void createOutputParameters(ServiceTemplate serviceTemplate, - ServiceTemplate substitutionServiceTemplate, - List<UnifiedCompositionData> unifiedCompositionDataList, - String computeNodeType, TranslationContext context) { + private void createOutputParameters(UnifiedCompositionTo unifiedCompositionTo, + String computeNodeType) { - createOutputParametersForCompute(serviceTemplate, substitutionServiceTemplate, - unifiedCompositionDataList, context); - createOutputParameterForPorts(serviceTemplate, substitutionServiceTemplate, - unifiedCompositionDataList, computeNodeType, context); + createOutputParametersForCompute(unifiedCompositionTo.getServiceTemplate(), + unifiedCompositionTo.getSubstitutionServiceTemplate(), unifiedCompositionTo.getUnifiedCompositionDataList(), + unifiedCompositionTo.getContext()); + createOutputParameterForPorts(unifiedCompositionTo.getSubstitutionServiceTemplate(), + unifiedCompositionTo.getUnifiedCompositionDataList(), computeNodeType, unifiedCompositionTo.getContext()); + createOutputParameterForSubInterfaces(unifiedCompositionTo, computeNodeType); } private void createOutputParameterForPorts( - ServiceTemplate serviceTemplate, ServiceTemplate substitutionServiceTemplate, List<UnifiedCompositionData> unifiedCompositionDataList, String connectedComputeNodeType, @@ -1379,28 +1415,31 @@ public class UnifiedCompositionService { connectedComputeNodeType, unifiedCompositionData.getComputeTemplateConsolidationData()); addOutputParameters(portTemplateConsolidationData, newPortNodeTemplateId, - serviceTemplate, substitutionServiceTemplate, unifiedCompositionDataList, context); + substitutionServiceTemplate, unifiedCompositionDataList, context); } } } - //The ID should be <vm_type>_<port_type> or <vm_type>_<portNodeTemplateId> - private String getNewPortNodeTemplateId( - String portNodeTemplateId, - String connectedComputeNodeType, - ComputeTemplateConsolidationData computeTemplateConsolidationData) { + private void createOutputParameterForSubInterfaces(UnifiedCompositionTo unifiedCompositionTo, + String connectedComputeNodeType) { + for (UnifiedCompositionData unifiedCompositionData : unifiedCompositionTo.getUnifiedCompositionDataList()) { + List<SubInterfaceTemplateConsolidationData> subInterfaceTemplateConsolidationDataList = + getSubInterfaceTemplateConsolidationDataList(unifiedCompositionData); + if (CollectionUtils.isEmpty(subInterfaceTemplateConsolidationDataList)) { + return; + } - StringBuilder newPortNodeTemplateId = new StringBuilder(); - String portType = ConsolidationDataUtil.getPortType(portNodeTemplateId); - newPortNodeTemplateId.append(DataModelUtil.getNamespaceSuffix(connectedComputeNodeType)); - if (computeTemplateConsolidationData.getPorts().get(portType).size() > 1) { - //single port - newPortNodeTemplateId.append("_").append(portNodeTemplateId); - } else { - //consolidation port - newPortNodeTemplateId.append("_").append(portType); + for (SubInterfaceTemplateConsolidationData subInterfaceTemplateConsolidationData : + subInterfaceTemplateConsolidationDataList) { + String newSubInterfaceNodeTemplateId = getNewSubInterfaceNodeTemplateId(unifiedCompositionTo + .getServiceTemplate(), connectedComputeNodeType, unifiedCompositionData + .getComputeTemplateConsolidationData(), subInterfaceTemplateConsolidationData, + unifiedCompositionTo.getContext()); + addOutputParameters(subInterfaceTemplateConsolidationData, newSubInterfaceNodeTemplateId, + unifiedCompositionTo.getSubstitutionServiceTemplate(), unifiedCompositionTo.getUnifiedCompositionDataList(), + unifiedCompositionTo.getContext()); + } } - return newPortNodeTemplateId.toString(); } private void createOutputParametersForCompute( @@ -1417,33 +1456,31 @@ public class UnifiedCompositionService { getNewComputeNodeTemplateId(serviceTemplate, computeTemplateConsolidationData.getNodeTemplateId()); addOutputParameters(computeTemplateConsolidationData, newComputeNodeTemplateId, - serviceTemplate, substitutionServiceTemplate, unifiedCompositionDataList, context); + substitutionServiceTemplate, unifiedCompositionDataList, context); } } private void addOutputParameters(EntityConsolidationData entityConsolidationData, String newNodeTemplateId, - ServiceTemplate serviceTemplate, ServiceTemplate substitutionServiceTemplate, List<UnifiedCompositionData> unifiedCompositionDataList, TranslationContext context) { - handleNodesGetAttrIn(entityConsolidationData, newNodeTemplateId, serviceTemplate, - substitutionServiceTemplate, unifiedCompositionDataList, context); + handleNodesGetAttrIn(entityConsolidationData, newNodeTemplateId, substitutionServiceTemplate, + unifiedCompositionDataList, context); - handleOutputParamGetAttrIn(entityConsolidationData, newNodeTemplateId, serviceTemplate, + handleOutputParamGetAttrIn(entityConsolidationData, newNodeTemplateId, substitutionServiceTemplate, context); } private void handleOutputParamGetAttrIn(EntityConsolidationData entityConsolidationData, String newNodeTemplateId, - ServiceTemplate serviceTemplate, ServiceTemplate substitutionServiceTemplate, TranslationContext context) { List<GetAttrFuncData> outputParametersGetAttrIn = entityConsolidationData.getOutputParametersGetAttrIn(); if (!CollectionUtils.isEmpty(outputParametersGetAttrIn)) { for (GetAttrFuncData getAttrFuncData : outputParametersGetAttrIn) { - createAndAddOutputParameter(entityConsolidationData, newNodeTemplateId, + createAndAddOutputParameter(newNodeTemplateId, substitutionServiceTemplate, getAttrFuncData, context); } } @@ -1451,29 +1488,28 @@ public class UnifiedCompositionService { private void handleNodesGetAttrIn(EntityConsolidationData entityConsolidationData, String newNodeTemplateId, - ServiceTemplate serviceTemplate, ServiceTemplate substitutionServiceTemplate, List<UnifiedCompositionData> unifiedCompositionDataList, TranslationContext context) { Map<String, List<GetAttrFuncData>> getAttrIn = entityConsolidationData.getNodesGetAttrIn(); - - if (!MapUtils.isEmpty(getAttrIn)) { - Map<String, UnifiedCompositionEntity> consolidationNodeTemplateIdAndType = - getAllConsolidationNodeTemplateIdAndType(unifiedCompositionDataList); - for (String sourceNodeTemplateId : getAttrIn.keySet()) { - if (!consolidationNodeTemplateIdAndType.keySet().contains(sourceNodeTemplateId)) { - List<GetAttrFuncData> getAttrFuncDataList = getAttrIn.get(sourceNodeTemplateId); - for (GetAttrFuncData getAttrFuncData : getAttrFuncDataList) { - createAndAddOutputParameter(entityConsolidationData, newNodeTemplateId, - substitutionServiceTemplate, getAttrFuncData, context); - } + if (MapUtils.isEmpty(getAttrIn)) { + return; + } + Map<String, UnifiedCompositionEntity> consolidationNodeTemplateIdAndType = + getAllConsolidationNodeTemplateIdAndType(unifiedCompositionDataList); + for (Map.Entry<String, List<GetAttrFuncData>> getAttrInEntry : getAttrIn.entrySet()) { + String sourceNodeTemplateId = getAttrInEntry.getKey(); + if (!consolidationNodeTemplateIdAndType.keySet().contains(sourceNodeTemplateId)) { + List<GetAttrFuncData> getAttrFuncDataList = getAttrInEntry.getValue(); + for (GetAttrFuncData getAttrFuncData : getAttrFuncDataList) { + createAndAddOutputParameter(newNodeTemplateId, + substitutionServiceTemplate, getAttrFuncData, context); } } } } - private void createAndAddOutputParameter(EntityConsolidationData entityConsolidationData, - String newNodeTemplateId, + private void createAndAddOutputParameter(String newNodeTemplateId, ServiceTemplate substitutionServiceTemplate, GetAttrFuncData getAttrFuncData, TranslationContext context) { @@ -1499,8 +1535,8 @@ public class UnifiedCompositionService { NodeTemplate nodeTemplate = DataModelUtil.getNodeTemplate(substitutionServiceTemplate, newNodeTemplateId); //Get the type and entry schema of the output parameter from the node type flat hierarchy - String outputParameterType = null; - EntrySchema outputParameterEntrySchema = null; + String outputParameterType; + EntrySchema outputParameterEntrySchema; NodeType nodeTypeWithFlatHierarchy = HeatToToscaUtil.getNodeTypeWithFlatHierarchy(nodeTemplate.getType(), substitutionServiceTemplate, context); @@ -1524,18 +1560,6 @@ public class UnifiedCompositionService { outputParameter.setEntry_schema(outputParameterEntrySchema); } - private String getNewInputParameterType(NodeTemplate nodeTemplate, - ServiceTemplate serviceTemplate, - String inputParameterName, - TranslationContext context) { - NodeType nodeTypeWithFlatHierarchy = - HeatToToscaUtil.getNodeTypeWithFlatHierarchy(nodeTemplate.getType(), - serviceTemplate, context); - String parameterType = nodeTypeWithFlatHierarchy.getProperties() - .get(inputParameterName).getType(); - return getUnifiedInputParameterType(parameterType); - } - private AttributeDefinition getOutputParameterDefinitionFromAttributes(NodeType nodeTypeWithFlatHierarchy, String outputParameterName) { @@ -1548,29 +1572,6 @@ public class UnifiedCompositionService { return outputParameterDefinition; } - private String getUnifiedInputParameterType(String parameterType) { - String unifiedInputParameterType = null; - if (Objects.nonNull(parameterType)) { - if (parameterType.equalsIgnoreCase(PropertyType.STRING.getDisplayName()) - || parameterType.equalsIgnoreCase(PropertyType.INTEGER.getDisplayName()) - || parameterType.equalsIgnoreCase(PropertyType.FLOAT.getDisplayName()) - || parameterType.equalsIgnoreCase(PropertyType.BOOLEAN.getDisplayName()) - || parameterType.equalsIgnoreCase(PropertyType.TIMESTAMP.getDisplayName()) - || parameterType.equalsIgnoreCase(PropertyType.NULL.getDisplayName()) - || parameterType.equalsIgnoreCase(PropertyType.SCALAR_UNIT_SIZE.getDisplayName()) - || parameterType.equalsIgnoreCase(PropertyType.SCALAR_UNIT_FREQUENCY.getDisplayName())) { - unifiedInputParameterType = parameterType.toLowerCase(); - } else if (parameterType.equalsIgnoreCase(PropertyType.MAP.getDisplayName()) - || parameterType.equalsIgnoreCase(PropertyType.LIST.getDisplayName()) - || parameterType.equalsIgnoreCase(PropertyTypeExt.JSON.getDisplayName())) { - unifiedInputParameterType = PropertyTypeExt.JSON.getDisplayName(); - } else { - unifiedInputParameterType = parameterType; - } - } - return unifiedInputParameterType; - } - private String getNewSubstitutionOutputParameterId(String newNodeTemplateId, String attributeName) { return newNodeTemplateId + "_" + attributeName; @@ -1599,6 +1600,16 @@ public class UnifiedCompositionService { substituteNodeTemplateId); } } + //Add Sub-interface template mapping information + List<SubInterfaceTemplateConsolidationData> subInterfaceTemplateConsolidationDataList = + getSubInterfaceTemplateConsolidationDataList(unifiedCompositionData); + if (CollectionUtils.isNotEmpty(subInterfaceTemplateConsolidationDataList)) { + for (SubInterfaceTemplateConsolidationData subInterfaceTemplateConsolidationData : + subInterfaceTemplateConsolidationDataList) { + context.addUnifiedSubstitutionData(serviceTemplateFileName, + subInterfaceTemplateConsolidationData.getNodeTemplateId(), substituteNodeTemplateId); + } + } } } @@ -1617,14 +1628,8 @@ public class UnifiedCompositionService { nodeTemplate.setProperties(properties); } - private String getSubstituteNodeTemplateId(ServiceTemplate serviceTemplate, - UnifiedCompositionData unifiedCompositionData, - String nodeTypeId, + private String getSubstituteNodeTemplateId(String nodeTypeId, Integer index) { - String computeNodeTemplateId = - unifiedCompositionData.getComputeTemplateConsolidationData().getNodeTemplateId(); - NodeTemplate computeNodeTemplate = - DataModelUtil.getNodeTemplate(serviceTemplate, computeNodeTemplateId); String nodeTemplateId = ABSTRACT_NODE_TEMPLATE_ID_PREFIX + DataModelUtil .getNamespaceSuffix(nodeTypeId); if (Objects.nonNull(index)) { @@ -1664,18 +1669,10 @@ public class UnifiedCompositionService { return nodeTypeId; } - private String getNewComputeNodeTemplateId( - ServiceTemplate serviceTemplate, - String computeNodeTemplateId) { - return getComputeTypeSuffix(serviceTemplate, computeNodeTemplateId); - } - private NodeType handleSubstitutionGlobalNodeType(ServiceTemplate serviceTemplate, ServiceTemplate substitutionServiceTemplate, TranslationContext context, - UnifiedCompositionData unifiedCompositionData, - String substitutionNodeTypeId, - Integer index) { + String substitutionNodeTypeId) { NodeType substitutionNodeType = new ToscaAnalyzerServiceImpl() .createInitSubstitutionNodeType(substitutionServiceTemplate, ToscaNodeType.VFC_ABSTRACT_SUBSTITUTE); @@ -1735,9 +1732,9 @@ public class UnifiedCompositionService { Map<String, List<String>> portIdsPerPortType = UnifiedCompositionUtil .collectAllPortsFromEachTypesFromComputes(computeConsolidationDataList); - for (String portType : portIdsPerPortType.keySet()) { + for (Map.Entry<String, List<String>> portIdsPerPortTypeEntry : portIdsPerPortType.entrySet()) { List<EntityConsolidationData> portTemplateConsolidationDataList = - getPortConsolidationDataList(portIdsPerPortType.get(portType), + getPortConsolidationDataList(portIdsPerPortTypeEntry.getValue(), unifiedCompositionDataList); if (CollectionUtils.isEmpty(portTemplateConsolidationDataList)) { continue; @@ -1765,7 +1762,7 @@ public class UnifiedCompositionService { removeConnectivityOut(portTemplateConsolidationData, newPortNodeTemplate); handleProperties(serviceTemplate, newPortNodeTemplate, - substitutionServiceTemplate, UnifiedCompositionEntity.Port, + substitutionServiceTemplate, UnifiedCompositionEntity.PORT, portTemplateConsolidationDataList, computeTemplateConsolidationData, unifiedCompositionDataList, context); @@ -1790,6 +1787,156 @@ public class UnifiedCompositionService { } + private void handleSubInterfaces(UnifiedCompositionTo unifiedCompositionTo) { + if (unifiedCompositionTo.getUnifiedCompositionDataList().size() > 1) { + handleConsolidationSubInterfaces(unifiedCompositionTo); + } else { + handleSingleSubInterfaces(unifiedCompositionTo); + } + } + + private void handleSingleSubInterfaces(UnifiedCompositionTo unifiedCompositionTo) { + UnifiedCompositionData unifiedCompositionData = unifiedCompositionTo.getUnifiedCompositionDataList().get(0); + List<SubInterfaceTemplateConsolidationData> subInterfaceTemplateConsolidationDataList = + getSubInterfaceTemplateConsolidationDataList(unifiedCompositionData); + for (SubInterfaceTemplateConsolidationData subInterfaceTemplateConsolidationData : + subInterfaceTemplateConsolidationDataList) { + List<SubInterfaceTemplateConsolidationData> subInterfaceDataList = new ArrayList<>(); + subInterfaceDataList.add(subInterfaceTemplateConsolidationData); + createSubInterfaceSubstitutionNodeTemplate(unifiedCompositionTo, subInterfaceDataList); + } + } + + private void handleConsolidationSubInterfaces(UnifiedCompositionTo unifiedCompositionTo) { + Collection<ComputeTemplateConsolidationData> computeConsolidationDataList = + (Collection) getComputeConsolidationDataList(unifiedCompositionTo.getUnifiedCompositionDataList()); + + Map<String, List<String>> portIdsPerPortType = UnifiedCompositionUtil + .collectAllPortsFromEachTypesFromComputes(computeConsolidationDataList); + + for (Map.Entry<String, List<String>> portIdsPerPortTypeEntry : portIdsPerPortType.entrySet()) { + List<EntityConsolidationData> portEntityConsolidationDataList = + getPortConsolidationDataList(portIdsPerPortTypeEntry.getValue(), + unifiedCompositionTo.getUnifiedCompositionDataList()); + if (CollectionUtils.isEmpty(portEntityConsolidationDataList)) { + continue; + } + + List<PortTemplateConsolidationData> portTemplateConsolidationDataList = + portEntityConsolidationDataList.stream() + .map(data -> (PortTemplateConsolidationData) data) + .collect(Collectors.toList()); + + ListMultimap<String, SubInterfaceTemplateConsolidationData> subInterfacesByType = UnifiedCompositionUtil + .collectAllSubInterfacesOfEachTypesFromPorts(portTemplateConsolidationDataList); + Set<String> subInterfaceTypes = subInterfacesByType.keySet(); + for (String subInterfaceType: subInterfaceTypes) { + List<SubInterfaceTemplateConsolidationData> subInterfaceTemplateConsolidationDataList = + subInterfacesByType.get(subInterfaceType); + createSubInterfaceSubstitutionNodeTemplate(unifiedCompositionTo, subInterfaceTemplateConsolidationDataList); + } + } + } + + private void createSubInterfaceSubstitutionNodeTemplate(UnifiedCompositionTo unifiedCompositionTo, + List<SubInterfaceTemplateConsolidationData> + subInterfaceTemplateConsolidationDataList) { + SubInterfaceTemplateConsolidationData subInterfaceTemplateConsolidationData = + subInterfaceTemplateConsolidationDataList.get(0); + PortTemplateConsolidationData portTemplateConsolidationData = + getSubInterfacePortTemplateConsolidationData(unifiedCompositionTo.getServiceTemplate(), + subInterfaceTemplateConsolidationData, unifiedCompositionTo.getContext()); + + if (Objects.isNull(portTemplateConsolidationData)) { + return; + } + + String originalSubInterfaceNodeTemplateId = subInterfaceTemplateConsolidationDataList.get(0) + .getNodeTemplateId(); + NodeTemplate originalSubInterfaceNodeTemplate = + DataModelUtil.getNodeTemplate(unifiedCompositionTo.getServiceTemplate(), originalSubInterfaceNodeTemplateId); + if (Objects.isNull(originalSubInterfaceNodeTemplate)) { + return; + } + NodeTemplate newSubInterfaceNodeTemplate = originalSubInterfaceNodeTemplate.clone(); + ComputeTemplateConsolidationData connectedComputeConsolidationData = + getConnectedComputeConsolidationData(unifiedCompositionTo.getUnifiedCompositionDataList(), + portTemplateConsolidationData.getNodeTemplateId()); + if (Objects.nonNull(connectedComputeConsolidationData)) { + NodeTemplate connectedComputeNodeTemplate = DataModelUtil.getNodeTemplate(unifiedCompositionTo + .getServiceTemplate(), connectedComputeConsolidationData.getNodeTemplateId()); + String newSubInterfaceNodeTemplateId = getNewSubInterfaceNodeTemplateId(unifiedCompositionTo + .getServiceTemplate(), connectedComputeNodeTemplate.getType(), connectedComputeConsolidationData, + subInterfaceTemplateConsolidationData, unifiedCompositionTo.getContext()); + DataModelUtil.addNodeTemplate(unifiedCompositionTo.getSubstitutionServiceTemplate(), + newSubInterfaceNodeTemplateId, newSubInterfaceNodeTemplate); + List<EntityConsolidationData> entityConsolidationDataList = + new ArrayList<>(subInterfaceTemplateConsolidationDataList); + //Remove all the existing properties as we are going to create new based on the + // naming convention for the substitution + handleSubInterfaceProperties(unifiedCompositionTo, newSubInterfaceNodeTemplate, entityConsolidationDataList, + portTemplateConsolidationData); + //Update requirements for relationships between the consolidation entities + handleConsolidationEntitiesRequirementConnectivity(newSubInterfaceNodeTemplate, unifiedCompositionTo + .getServiceTemplate(), unifiedCompositionTo.getContext()); + removeConnectivityOut(subInterfaceTemplateConsolidationData,newSubInterfaceNodeTemplate); + } + } + + private void handleSubInterfaceProperties(UnifiedCompositionTo unifiedCompositionTo, + NodeTemplate newSubInterfaceNodeTemplate, + List<EntityConsolidationData> + entityConsolidationDataList, + PortTemplateConsolidationData + portTemplateConsolidationData) { + UnifiedCompositionData unifiedCompositionData = unifiedCompositionTo.getUnifiedCompositionDataList().get(0); + ServiceTemplate serviceTemplate = unifiedCompositionTo.getServiceTemplate(); + TranslationContext context = unifiedCompositionTo.getContext(); + newSubInterfaceNodeTemplate.setProperties(new HashMap<>()); + for (EntityConsolidationData entityConsolidationData : entityConsolidationDataList) { + String nodeTemplateId = entityConsolidationData.getNodeTemplateId(); + Optional<List<String>> indexVarProperties = + context.getIndexVarProperties(ToscaUtil.getServiceTemplateFileName(serviceTemplate), + nodeTemplateId); + Map<String, Object> properties = + DataModelUtil.getNodeTemplateProperties(serviceTemplate, nodeTemplateId); + if (MapUtils.isEmpty(properties)) { + continue; + } + + for (Map.Entry<String, Object> propertyEntry : properties.entrySet()) { + NodeType nodeTypeWithFlatHierarchy = + HeatToToscaUtil.getNodeTypeWithFlatHierarchy(newSubInterfaceNodeTemplate.getType(), + serviceTemplate, context); + PropertyDefinition propertyDefinition = + nodeTypeWithFlatHierarchy.getProperties().get(propertyEntry.getKey()); + String propertyType = propertyDefinition.getType(); + //Handle service_template_filter property for subinterface as we should not create inputs + // for this property + if (propertyEntry.getKey().equals(ToscaConstants.SERVICE_TEMPLATE_FILTER_PROPERTY_NAME)) { + handleSubInterfaceServiceTemplateFilterProperty(newSubInterfaceNodeTemplate, + propertyEntry.getKey(), propertyEntry.getValue(), serviceTemplate, + unifiedCompositionTo.getSubstitutionServiceTemplate()); + } else if (indexVarProperties.isPresent() + && indexVarProperties.get().contains(propertyEntry.getKey())) { + //Handle index property + handleIndexVarProperty(propertyEntry.getKey(), propertyEntry.getValue(), + newSubInterfaceNodeTemplate); + } else { + Optional<String> parameterId = + updateProperty(serviceTemplate, nodeTemplateId, newSubInterfaceNodeTemplate, + propertyEntry, UnifiedCompositionEntity.SUB_INTERFACE, unifiedCompositionData + .getComputeTemplateConsolidationData(), portTemplateConsolidationData, + unifiedCompositionTo.getUnifiedCompositionDataList(), context); + parameterId.ifPresent( + parameterIdValue -> addPropertyInputParameter(propertyType, + unifiedCompositionTo.getSubstitutionServiceTemplate(), + propertyDefinition.getEntry_schema(), parameterIdValue)); + } + } + } + } + private NodeTemplate getNodeTemplate(String nodeTemplateId, ServiceTemplate serviceTemplate, TranslationContext context) { @@ -1813,8 +1960,6 @@ public class UnifiedCompositionService { unifiedCompositionDataList.get(0).getComputeTemplateConsolidationData(); handleComputeNodeTemplate(serviceTemplate, substitutionServiceTemplate, unifiedCompositionDataList, context); - ServiceTemplate globalSubstitutionServiceTemplate = - HeatToToscaUtil.fetchGlobalSubstitutionServiceTemplate(serviceTemplate, context); return handleComputeNodeType(serviceTemplate, substitutionServiceTemplate, computeTemplateConsolidationData); } @@ -1834,11 +1979,6 @@ public class UnifiedCompositionService { return computeNodeTypeId; } - private String getComputeNodeType(String nodeType) { - String computeTypeSuffix = getComputeTypeSuffix(nodeType); - return ToscaNodeType.COMPUTE_TYPE_PREFIX + "." + computeTypeSuffix; - } - private void handleComputeNodeTemplate(ServiceTemplate serviceTemplate, ServiceTemplate substitutionServiceTemplate, List<UnifiedCompositionData> unifiedCompositionDataList, @@ -1851,12 +1991,12 @@ public class UnifiedCompositionService { removeConnectivityOut(computeTemplateConsolidationData, newComputeNodeTemplate); removeVolumeConnectivity(computeTemplateConsolidationData, newComputeNodeTemplate); - List<EntityConsolidationData> computeConsoliadtionDataList = + List<EntityConsolidationData> computeConsolidationDataList = getComputeConsolidationDataList(unifiedCompositionDataList); handleProperties(serviceTemplate, newComputeNodeTemplate, - substitutionServiceTemplate, UnifiedCompositionEntity.Compute, - computeConsoliadtionDataList, computeTemplateConsolidationData, unifiedCompositionDataList, + substitutionServiceTemplate, COMPUTE, + computeConsolidationDataList, computeTemplateConsolidationData, unifiedCompositionDataList, context); String newComputeNodeTemplateId = getNewComputeNodeTemplateId(serviceTemplate, @@ -1869,7 +2009,7 @@ public class UnifiedCompositionService { .addNodeTemplate(substitutionServiceTemplate, newComputeNodeTemplateId, newComputeNodeTemplate); //Add the node template mapping in the context for handling requirement updation - for (EntityConsolidationData data : computeConsoliadtionDataList) { + for (EntityConsolidationData data : computeConsolidationDataList) { String newComputeTemplateId = getNewComputeNodeTemplateId(serviceTemplate, computeTemplateConsolidationData.getNodeTemplateId()); context.addSubstitutionServiceTemplateUnifiedSubstitutionData(ToscaUtil @@ -1878,25 +2018,11 @@ public class UnifiedCompositionService { } } - private void updateComputeNodeType(ServiceTemplate serviceTemplate, - String nodeTemplateId, - NodeTemplate newComputeNodeTemplate) { - String computeNodeType = getComputeNodeType(newComputeNodeTemplate.getType()); - NodeType origNodeType = serviceTemplate.getNode_types().get(newComputeNodeTemplate.getType()); - DataModelUtil.removeNodeType(serviceTemplate, newComputeNodeTemplate.getType()); - DataModelUtil.addNodeType(serviceTemplate, computeNodeType, origNodeType); - newComputeNodeTemplate.setType(computeNodeType); - DataModelUtil.addNodeTemplate(serviceTemplate, nodeTemplateId, newComputeNodeTemplate); - } - private List<EntityConsolidationData> getComputeConsolidationDataList( List<UnifiedCompositionData> unifiedCompositionDataList) { - List<EntityConsolidationData> computeConsolidationDataList = new ArrayList<>(); - for (UnifiedCompositionData unifiedCompositionData : unifiedCompositionDataList) { - computeConsolidationDataList - .add(unifiedCompositionData.getComputeTemplateConsolidationData()); - } - return computeConsolidationDataList; + return unifiedCompositionDataList.stream() + .map(UnifiedCompositionData::getComputeTemplateConsolidationData) + .collect(Collectors.toList()); } @@ -1908,8 +2034,6 @@ public class UnifiedCompositionService { ComputeTemplateConsolidationData computeTemplateConsolidationData, List<UnifiedCompositionData> unifiedCompositionDataList, TranslationContext context) { - List<String> propertiesWithIdenticalVal = - consolidationService.getPropertiesWithIdenticalVal(unifiedCompositionEntity); nodeTemplate.setProperties(new HashedMap()); handleNodeTemplateProperties(serviceTemplate, nodeTemplate, substitutionServiceTemplate, unifiedCompositionEntity, entityConsolidationDataList, computeTemplateConsolidationData, @@ -1936,6 +2060,9 @@ public class UnifiedCompositionService { for (EntityConsolidationData entityConsolidationData : entityConsolidationDataList) { String nodeTemplateId = entityConsolidationData.getNodeTemplateId(); + Optional<List<String>> indexVarProperties = + context.getIndexVarProperties(ToscaUtil.getServiceTemplateFileName(serviceTemplate), + nodeTemplateId); Map<String, Object> properties = DataModelUtil.getNodeTemplateProperties(serviceTemplate, nodeTemplateId); if (MapUtils.isEmpty(properties)) { @@ -1960,17 +2087,67 @@ public class UnifiedCompositionService { propertyType.equals(PropertyType.LIST.getDisplayName()) ? propertyDefinition .getEntry_schema() : null, substitutionServiceTemplate); + } else if (indexVarProperties.isPresent() + && indexVarProperties.get().contains(propertyEntry.getKey())) { + //Handle index property + handleIndexVarProperty(propertyEntry.getKey(), propertyEntry.getValue(), nodeTemplate); } else { Optional<String> parameterId = updateProperty(serviceTemplate, nodeTemplateId, nodeTemplate, propertyEntry, - unifiedCompositionEntity, computeTemplateConsolidationData, + unifiedCompositionEntity, computeTemplateConsolidationData, null, unifiedCompositionDataList, context); - //todo - define list of type which will match the node property type (instead of string) parameterId.ifPresent( parameterIdValue -> addPropertyInputParameter(propertyType, substitutionServiceTemplate, - propertyDefinition.getEntry_schema(), parameterIdValue, context)); + propertyDefinition.getEntry_schema(), parameterIdValue)); + } + } + } + } + + private void handleIndexVarProperty(String propertyKey, Object propertyValue, + NodeTemplate nodeTemplate) { + //Retain properties translated from %index% value in heat + nodeTemplate.getProperties().put(propertyKey, propertyValue); + } + + private void handleSubInterfaceServiceTemplateFilterProperty(NodeTemplate nodeTemplate, + String propertyKey, + Object propertyValue, + ServiceTemplate serviceTemplate, + ServiceTemplate substitutionServiceTemplate) { + //Retain service_template_filter (Can be present in a sub-interface resource-def) + nodeTemplate.getProperties().put(propertyKey, propertyValue); + Object serviceTemplateFilterProperty = + nodeTemplate.getProperties().get(ToscaConstants.SERVICE_TEMPLATE_FILTER_PROPERTY_NAME); + if (!(serviceTemplateFilterProperty instanceof Map)) { + return; + } + Map<String, Object> serviceTemplatePropertyMap = (Map<String, Object>) + serviceTemplateFilterProperty; + Object countPropertyVal = serviceTemplatePropertyMap.get(ToscaConstants.COUNT_PROPERTY_NAME); + //Check if the value of the count property is a tosca function + if (!isPropertyContainsToscaFunction(countPropertyVal)) { + return; + } + Map<String, Object> countPropertyValMap = (Map<String, Object>) countPropertyVal; + //If the value is in the form of get_input add an input parameter in current service + // template + if (countPropertyValMap.keySet().contains(ToscaFunctions.GET_INPUT.getDisplayName())) { + String countPropertyInputName = countPropertyValMap.get(ToscaFunctions.GET_INPUT + .getDisplayName()).toString(); + //Get the input parameter definition from top level where the resource group was present + ParameterDefinitionExt parameterDefinition = (ParameterDefinitionExt) + DataModelUtil.getInputParameters(serviceTemplate).get(countPropertyInputName); + if (Objects.nonNull(parameterDefinition)) { + //Remove annotations if any for the nested service template + parameterDefinition.setAnnotations(null); + DataModelUtil.getInputParameters(substitutionServiceTemplate) + .put(countPropertyInputName, parameterDefinition); + if (Objects.nonNull(countPropertyInputName)) { + //Remove the input from top level + DataModelUtil.getInputParameters(serviceTemplate).remove(countPropertyInputName); } } } @@ -1987,11 +2164,11 @@ public class UnifiedCompositionService { Optional<NodeType> enrichNodeType; List<String> enrichProperties; - if (compositionEntity.equals(UnifiedCompositionEntity.Port)) { + if (compositionEntity.equals(UnifiedCompositionEntity.PORT)) { enrichNodeType = toscaAnalyzerService.fetchNodeType(ToscaNodeType.NETWORK_PORT, context.getGlobalServiceTemplates().values()); - enrichProperties = context.getEnrichPortResourceProperties(); + enrichProperties = TranslationContext.getEnrichPortResourceProperties(); if (!enrichNodeType.isPresent() || Objects.isNull(enrichProperties)) { return; } @@ -2028,7 +2205,7 @@ public class UnifiedCompositionService { String inputParamId = getParameterId(nodeTemplateId, nodeTemplate, enrichPropertyName, - compositionEntity, computeTemplateConsolidationData); + compositionEntity, computeTemplateConsolidationData, null); Map<String, String> propertyValMap = new HashMap<>(); context @@ -2047,7 +2224,7 @@ public class UnifiedCompositionService { addPropertyInputParameter(propertyType, substitutionServiceTemplate, enrichNodeType .getProperties().get(enrichPropertyName).getEntry_schema(), - inputParamId, context); + inputParamId); } } @@ -2078,9 +2255,11 @@ public class UnifiedCompositionService { private void addPropertyInputParameter(String propertyType, ServiceTemplate substitutionServiceTemplate, - EntrySchema entrySchema, String parameterId, - TranslationContext context) { - if (isParameterBelongsToEnrichedPortProperties(parameterId, context)) { + EntrySchema entrySchema, String parameterId) { + if (Objects.isNull(propertyType)) { + return; + } + if (isParameterBelongsToEnrichedPortProperties(parameterId)) { addInputParameter(parameterId, propertyType, propertyType.equals(PropertyType.LIST.getDisplayName()) ? entrySchema : null, @@ -2102,9 +2281,8 @@ public class UnifiedCompositionService { } } - private boolean isParameterBelongsToEnrichedPortProperties(String parameterId, - TranslationContext context) { - List enrichPortResourceProperties = context.getEnrichPortResourceProperties(); + private boolean isParameterBelongsToEnrichedPortProperties(String parameterId) { + List enrichPortResourceProperties = TranslationContext.getEnrichPortResourceProperties(); for (int i = 0; i < enrichPortResourceProperties.size(); i++) { if (parameterId.contains((CharSequence) enrichPortResourceProperties.get(i))) { @@ -2116,11 +2294,8 @@ public class UnifiedCompositionService { } private boolean isPropertySimpleType(String propertyType) { - return !Objects.isNull(propertyType) && - (propertyType.equalsIgnoreCase(PropertyType.STRING.getDisplayName()) - || propertyType.equalsIgnoreCase(PropertyType.INTEGER.getDisplayName()) - || propertyType.equalsIgnoreCase(PropertyType.FLOAT.getDisplayName()) - || propertyType.equalsIgnoreCase(PropertyType.BOOLEAN.getDisplayName())); + return !Objects.isNull(propertyType) + && (PropertyType.getSimplePropertyTypes().contains(propertyType.toLowerCase())); } private String analyzeParameterType(String propertyType) { @@ -2129,7 +2304,7 @@ public class UnifiedCompositionService { } private String analyzeEntrySchemaType(String propertyType, EntrySchema entrySchema) { - return propertyType.equalsIgnoreCase(PropertyType.LIST.getDisplayName()) ? + return propertyType.equalsIgnoreCase(PropertyType.LIST.getDisplayName()) && entrySchema != null ? entrySchema.getType() : null; } @@ -2198,34 +2373,28 @@ public class UnifiedCompositionService { UnifiedCompositionEntity unifiedCompositionEntity, List<UnifiedCompositionData> unifiedCompositionDataList) { - String inputParamId; + String inputParamId = null; Map<String, Object> propertyVal = new HashMap<>(); switch (unifiedCompositionEntity) { - case Compute: + case COMPUTE: inputParamId = COMPUTE_IDENTICAL_VALUE_PROPERTY_PREFIX + propertyId + COMPUTE_IDENTICAL_VALUE_PROPERTY_SUFFIX; - propertyVal.put(ToscaFunctions.GET_INPUT.getDisplayName(), inputParamId); nodeTemplate.getProperties().put(propertyId, propertyVal); - - return inputParamId; - - case Port: + break; + case PORT: String portType = ConsolidationDataUtil.getPortType(nodeTemplateId); ComputeTemplateConsolidationData computeTemplateConsolidationData = getConnectedComputeConsolidationData(unifiedCompositionDataList, nodeTemplateId); - inputParamId = getInputParamIdForPort(nodeTemplateId, propertyId, portType, - computeTemplateConsolidationData); - + inputParamId = getInputParamIdForPort(nodeTemplateId, propertyId, portType, computeTemplateConsolidationData); propertyVal.put(ToscaFunctions.GET_INPUT.getDisplayName(), inputParamId); nodeTemplate.getProperties().put(propertyId, propertyVal); - - return inputParamId; - + break; default: - return null; + break; } + return inputParamId; } private String getInputParamIdForPort(String nodeTemplateId, String propertyId, String portType, @@ -2234,12 +2403,12 @@ public class UnifiedCompositionService { if (Objects.isNull(computeTemplateConsolidationData) || computeTemplateConsolidationData.getPorts().get(portType).size() > 1) { inputParamId = - UnifiedCompositionEntity.Port.name().toLowerCase() + "_" + nodeTemplateId + "_" + + UnifiedCompositionEntity.PORT.getDisplayName().toLowerCase() + "_" + nodeTemplateId + "_" + propertyId; } else { inputParamId = - UnifiedCompositionEntity.Port.name().toLowerCase() + "_" + portType + "_" + UnifiedCompositionEntity.PORT.getDisplayName().toLowerCase() + "_" + portType + "_" + propertyId; } return inputParamId; @@ -2267,6 +2436,7 @@ public class UnifiedCompositionService { Map.Entry<String, Object> propertyEntry, UnifiedCompositionEntity compositionEntity, ComputeTemplateConsolidationData computeTemplateConsolidationData, + PortTemplateConsolidationData portTemplateConsolidationData, List<UnifiedCompositionData> unifiedCompositionDataList, TranslationContext context) { @@ -2278,16 +2448,13 @@ public class UnifiedCompositionService { String inputParamId = getParameterId(nodeTemplateId, nodeTemplate, propertyEntry.getKey(), compositionEntity, - computeTemplateConsolidationData); - Map<String, List<String>> propertyVal = getPropertyValueInputParam(nodeTemplateId, - nodeTemplate, inputParamId); + computeTemplateConsolidationData, portTemplateConsolidationData); + Map<String, List<String>> propertyVal = getPropertyValueInputParam(inputParamId); nodeTemplate.getProperties().put(propertyEntry.getKey(), propertyVal); return Optional.of(inputParamId); } - private Map<String, List<String>> getPropertyValueInputParam(String nodeTemplateId, - NodeTemplate nodeTemplate, - String inputParamId) { + private Map<String, List<String>> getPropertyValueInputParam(String inputParamId) { Map<String, List<String>> propertyVal = new HashMap<>(); List<String> getInputFuncParams = new ArrayList<>(); getInputFuncParams.add(inputParamId); @@ -2335,8 +2502,8 @@ public class UnifiedCompositionService { for (List<Object> getAttrFunc : clonedGetAttrFuncList) { String targetNodeTemplateId = (String) getAttrFunc.get(0); if (consolidationNodeTemplateIds.contains(targetNodeTemplateId)) { - updatePropertyGetAttrFunc(serviceTemplate, unifiedCompositionDataList, context, - consolidationNodeTemplateIdAndType, targetNodeTemplateId, getAttrFunc); + updatePropertyGetAttrFunc(serviceTemplate, unifiedCompositionDataList, + consolidationNodeTemplateIdAndType, targetNodeTemplateId, getAttrFunc, context); } } nodeTemplate.getProperties().put(propertyEntry.getKey(), clonedPropertyValue); @@ -2345,19 +2512,6 @@ public class UnifiedCompositionService { return false; } - private boolean isGetAttrFromConsolidationNodesIsFromSameType(String sourceNodeTemplateId, - Set<String> nodeTemplateIdsFromConsolidation, - Map<String, String> - nodeTemplateIdToType) { - for (String idFromConsolidation : nodeTemplateIdsFromConsolidation) { - if (isGetAttrNodeTemplateFromSameType(sourceNodeTemplateId, idFromConsolidation, - nodeTemplateIdToType)) { - return true; - } - } - return false; - } - private boolean isGetAttrNodeTemplateFromSameType(String sourceNodeTemplateId, String targetNodeTemplateId, Map<String, String> nodeTemplateIdToType) { @@ -2374,37 +2528,33 @@ public class UnifiedCompositionService { private void updatePropertyGetAttrFunc( ServiceTemplate serviceTemplate, List<UnifiedCompositionData> unifiedCompositionDataList, - TranslationContext context, Map<String, UnifiedCompositionEntity> consolidationNodeTemplateIdAndType, String targetNodeTemplateId, - List<Object> getAttrFunc) { + List<Object> getAttrFunc, TranslationContext context) { UnifiedCompositionEntity targetCompositionEntity = consolidationNodeTemplateIdAndType.get(targetNodeTemplateId); String targetNewNodeTemplateId = getNewNodeTemplateId(serviceTemplate, unifiedCompositionDataList, targetNodeTemplateId, - targetCompositionEntity); + targetCompositionEntity, context); getAttrFunc.set(0, targetNewNodeTemplateId); } private String getNewNodeTemplateId(ServiceTemplate serviceTemplate, List<UnifiedCompositionData> unifiedCompositionDataList, String nodeTemplateId, - UnifiedCompositionEntity compositionEntity) { - switch (compositionEntity) { - case Compute: - return getNewComputeNodeTemplateId(serviceTemplate, nodeTemplateId); - case Port: - ComputeTemplateConsolidationData connectedComputeConsolidationData = - getConnectedComputeConsolidationData( - unifiedCompositionDataList, nodeTemplateId); - NodeTemplate connectedComputeNodeTemplate = - DataModelUtil.getNodeTemplate(serviceTemplate, - connectedComputeConsolidationData.getNodeTemplateId()); - return getNewPortNodeTemplateId(nodeTemplateId, connectedComputeNodeTemplate.getType(), - connectedComputeConsolidationData); - default: - return null; + UnifiedCompositionEntity compositionEntity, + TranslationContext context) { + String newNodeTemplateId = nodeTemplateId; + String nodeTemplateIdGeneratorImpl = unifiedSubstitutionNodeTemplateIdGeneratorImplMap.get(compositionEntity); + UnifiedSubstitutionNodeTemplateIdGenerator nodeTemplateIdGenerator = + CommonMethods.newInstance(nodeTemplateIdGeneratorImpl, UnifiedSubstitutionNodeTemplateIdGenerator.class); + UnifiedCompositionTo unifiedCompositionTo = new UnifiedCompositionTo(serviceTemplate, null, + unifiedCompositionDataList, context); + Optional<String> generatedNodeTemplateId = nodeTemplateIdGenerator.generate(unifiedCompositionTo, nodeTemplateId); + if (generatedNodeTemplateId.isPresent()) { + newNodeTemplateId = generatedNodeTemplateId.get(); } + return newNodeTemplateId; } private String getNewNodeTemplateId(String origNodeTemplateId, @@ -2413,11 +2563,11 @@ public class UnifiedCompositionService { TranslationContext context) { ConsolidationData consolidationData = context.getConsolidationData(); - if (isIdIsOfExpectedType(origNodeTemplateId, UnifiedCompositionEntity.Port, + if (isIdIsOfExpectedType(origNodeTemplateId, UnifiedCompositionEntity.PORT, serviceTemplateFileName, context)) { return handleIdOfPort(origNodeTemplateId, serviceTemplateFileName, consolidationData); - } else if (isIdIsOfExpectedType(origNodeTemplateId, UnifiedCompositionEntity.Compute, + } else if (isIdIsOfExpectedType(origNodeTemplateId, COMPUTE, serviceTemplateFileName, context)) { NodeTemplate nodeTemplate = getComputeNodeTemplate(origNodeTemplateId, serviceTemplate, context); @@ -2427,21 +2577,6 @@ public class UnifiedCompositionService { return null; } - private ComputeTemplateConsolidationData getConnectedComputeConsolidationData( - List<UnifiedCompositionData> unifiedCompositionDataList, - String portNodeTemplateId) { - for (UnifiedCompositionData unifiedCompositionData : unifiedCompositionDataList) { - Collection<List<String>> portsCollection = - unifiedCompositionData.getComputeTemplateConsolidationData().getPorts().values(); - for (List<String> portIdList : portsCollection) { - if (portIdList.contains(portNodeTemplateId)) { - return unifiedCompositionData.getComputeTemplateConsolidationData(); - } - } - } - return null; - } - private Object getClonedPropertyValue(Map.Entry<String, Object> propertyEntry) { if (propertyEntry.getValue() instanceof Map) { return getClonedObject(propertyEntry.getValue(), Map.class); @@ -2454,23 +2589,49 @@ public class UnifiedCompositionService { private String getParameterId(String nodeTemplateId, NodeTemplate nodeTemplate, String propertyId, UnifiedCompositionEntity unifiedCompositionEntity, - ComputeTemplateConsolidationData computeTemplateConsolidationData) { + ComputeTemplateConsolidationData + computeTemplateConsolidationData, + PortTemplateConsolidationData portTemplateConsolidationData) { + String paramterId = propertyId; switch (unifiedCompositionEntity) { - case Compute: - return UnifiedCompositionEntity.Compute.name().toLowerCase() + "_" + case COMPUTE: + paramterId = COMPUTE.getDisplayName().toLowerCase() + "_" + getComputeTypeSuffix(nodeTemplate.getType()) + "_" + propertyId; - case Port: + break; + case PORT: String portType = ConsolidationDataUtil.getPortType(nodeTemplateId); if (Objects.isNull(computeTemplateConsolidationData) || computeTemplateConsolidationData.getPorts().get(portType).size() > 1) { - return UnifiedCompositionEntity.Port.name().toLowerCase() + "_" + nodeTemplateId + "_" + paramterId = UnifiedCompositionEntity.PORT.getDisplayName().toLowerCase() + "_" + + nodeTemplateId + "_" + propertyId; + } else { + paramterId = UnifiedCompositionEntity.PORT.getDisplayName().toLowerCase() + "_" + portType + "_" + propertyId; } - return UnifiedCompositionEntity.Port.name().toLowerCase() + "_" + portType + "_" - + propertyId; + break; + case SUB_INTERFACE: + String subInterfaceType = getSubInterfaceTypeSuffix(nodeTemplate.getType()); + if (Objects.isNull(portTemplateConsolidationData) + || isSubInterfaceNodeTemplateIdParameter(portTemplateConsolidationData, nodeTemplate)) { + paramterId = UnifiedCompositionEntity.SUB_INTERFACE.getDisplayName().toLowerCase() + "_" + + nodeTemplateId + "_" + propertyId; + } else { + paramterId = UnifiedCompositionEntity.SUB_INTERFACE.getDisplayName().toLowerCase() + "_" + + subInterfaceType + "_" + propertyId; + } + break; default: - return propertyId; + break; } + return paramterId; + } + + private boolean isSubInterfaceNodeTemplateIdParameter(PortTemplateConsolidationData portTemplateConsolidationData, + NodeTemplate nodeTemplate) { + List<SubInterfaceTemplateConsolidationData> subInterfaceTemplateConsolidationDataList = + portTemplateConsolidationData.getSubInterfaceConsolidationData(nodeTemplate.getType()); + return (Objects.nonNull(subInterfaceTemplateConsolidationDataList) + && subInterfaceTemplateConsolidationDataList.size() > 1) ; } private void removeConnectivityOut(EntityConsolidationData entityConsolidationData, @@ -2541,15 +2702,10 @@ public class UnifiedCompositionService { private Optional<Map<String, Object>> createAbstractSubstitutionProperties( ServiceTemplate serviceTemplate, - ServiceTemplate substitutionServiceTemplate, + Map<String, ParameterDefinition> substitutionTemplateInputs, List<UnifiedCompositionData> unifiedCompositionDataList, TranslationContext context) { Map<String, Object> abstractSubstituteProperties = new LinkedHashMap<>(); - Map<String, ParameterDefinition> substitutionTemplateInputs = DataModelUtil - .getInputParameters(substitutionServiceTemplate); - if (substitutionTemplateInputs == null) { - return Optional.empty(); - } //Since all the computes have the same type fetching the type from the first entry NodeTemplate firstComputeNodeTemplate = DataModelUtil.getNodeTemplate(serviceTemplate, unifiedCompositionDataList.get(0) @@ -2564,14 +2720,14 @@ public class UnifiedCompositionService { if (!inputType.equalsIgnoreCase(PropertyType.LIST.getDisplayName())) { if (isIdenticalValueProperty( - substitutionTemplateInputName, inputUnifiedCompositionEntity, context)) { + substitutionTemplateInputName, inputUnifiedCompositionEntity)) { //Handle identical value properties Optional<String> identicalValuePropertyName = getIdenticalValuePropertyName(substitutionTemplateInputName, - inputUnifiedCompositionEntity, context); + inputUnifiedCompositionEntity); identicalValuePropertyName.ifPresent(propertyName -> updateIdenticalPropertyValue(propertyName, - substitutionTemplateInputName, computeType, inputUnifiedCompositionEntity, + substitutionTemplateInputName, inputUnifiedCompositionEntity, unifiedCompositionDataList.get(0), serviceTemplate, abstractSubstituteProperties, context)); } @@ -2580,59 +2736,110 @@ public class UnifiedCompositionService { //Check if the input is of type compute or port List<Object> abstractPropertyValue = new ArrayList<>(); - Object propertyValue = null; switch (inputUnifiedCompositionEntity) { - case Compute: - for (UnifiedCompositionData compositionData : unifiedCompositionDataList) { - ComputeTemplateConsolidationData computeTemplateConsolidationData = - compositionData.getComputeTemplateConsolidationData(); - propertyValue = getComputePropertyValue(substitutionTemplateInputName, - serviceTemplate, computeTemplateConsolidationData); - if (!(propertyValue instanceof Optional)) { - abstractPropertyValue.add(propertyValue); - } - } + case COMPUTE: + createAbstractComputeProperties(unifiedCompositionDataList, + substitutionTemplateInputName, serviceTemplate, abstractPropertyValue); break; - case Port: - for (UnifiedCompositionData compositionData : unifiedCompositionDataList) { - List<PortTemplateConsolidationData> portTemplateConsolidationDataList = - getPortTemplateConsolidationDataList(compositionData); - //Get the input type for this input whether it is of type - // port_<port_node_template_id>_<property_name> or port_<port_type>_<property_name> - PortInputType portInputType = getPortInputType(substitutionTemplateInputName, - compositionData); - for (PortTemplateConsolidationData portTemplateConsolidationData : - portTemplateConsolidationDataList) { - //Get the port property value - String portNodeTemplateId = portTemplateConsolidationData.getNodeTemplateId(); - propertyValue = getPortPropertyValue(substitutionTemplateInputName, - computeType, portInputType, serviceTemplate, - portNodeTemplateId); - //If the value object is Optional.empty it implies that the property name was not - // found in the input name - if (!(propertyValue instanceof Optional)) { - if (!abstractPropertyValue.contains(propertyValue)) { - abstractPropertyValue.add(propertyValue); - } - } - } - } + case PORT: + createAbstractPortProperties(unifiedCompositionDataList, substitutionTemplateInputName, + computeType, serviceTemplate, abstractPropertyValue); + break; + case SUB_INTERFACE: + createAbstractSubInterfaceProperties(unifiedCompositionDataList, + substitutionTemplateInputName, serviceTemplate, abstractPropertyValue); break; default: break; } //Add the property only if it has at least one non-null value - for (Object val : abstractPropertyValue) { - if (Objects.nonNull(val)) { - updateAbstractPropertyValue(substitutionTemplateInputName, inputParameterDefinition, - abstractPropertyValue, abstractSubstituteProperties); - break; - } + if (abstractPropertyValue.stream().anyMatch(Objects::nonNull)) { + updateAbstractPropertyValue(substitutionTemplateInputName, inputParameterDefinition, + abstractPropertyValue, abstractSubstituteProperties); } } return Optional.ofNullable(abstractSubstituteProperties); } + private void createAbstractComputeProperties(List<UnifiedCompositionData> + unifiedCompositionDataList, + String substitutionTemplateInputName, + ServiceTemplate serviceTemplate, + List<Object> abstractPropertyValue) { + for (UnifiedCompositionData compositionData : unifiedCompositionDataList) { + ComputeTemplateConsolidationData computeTemplateConsolidationData = + compositionData.getComputeTemplateConsolidationData(); + Object propertyValue = getComputePropertyValue(substitutionTemplateInputName, + serviceTemplate, computeTemplateConsolidationData); + if (!(propertyValue instanceof Optional)) { + abstractPropertyValue.add(propertyValue); + } + } + } + + private void createAbstractPortProperties(List<UnifiedCompositionData> + unifiedCompositionDataList, + String substitutionTemplateInputName, + String computeType, + ServiceTemplate serviceTemplate, + List<Object> abstractPropertyValue) { + for (UnifiedCompositionData compositionData : unifiedCompositionDataList) { + List<PortTemplateConsolidationData> portTemplateConsolidationDataList = + getPortTemplateConsolidationDataList(compositionData); + //Get the input type for this input whether it is of type + // port_<port_node_template_id>_<property_name> or port_<port_type>_<property_name> + PropertyInputType portInputType = getPortInputType(substitutionTemplateInputName, + compositionData); + for (PortTemplateConsolidationData portTemplateConsolidationData : + portTemplateConsolidationDataList) { + //Get the port property value + String portNodeTemplateId = portTemplateConsolidationData.getNodeTemplateId(); + Object propertyValue = getPortPropertyValue(substitutionTemplateInputName, + computeType, portInputType, serviceTemplate, + portNodeTemplateId); + //If the value object is Optional.empty it implies that the property name was not + // found in the input name + if (!(propertyValue instanceof Optional)) { + abstractPropertyValue.add(propertyValue); + } + } + } + } + + private void createAbstractSubInterfaceProperties(List<UnifiedCompositionData> + unifiedCompositionDataList, + String substitutionTemplateInputName, + ServiceTemplate serviceTemplate, + List<Object> abstractPropertyValue) { + for (UnifiedCompositionData compositionData : unifiedCompositionDataList) { + List<SubInterfaceTemplateConsolidationData> subInterfaceTemplateConsolidationDataList = + getSubInterfaceTemplateConsolidationDataList(compositionData); + //Get the input type for this input whether it is of type + // subInterface_<subinterface_node_template_id>_<property_name> or + // subInterface_<subinterface_type>_<property_name> + PropertyInputType subInterfaceInputType = + getSubInterfaceInputType(substitutionTemplateInputName, compositionData); + for (SubInterfaceTemplateConsolidationData subInterfaceTemplateConsolidationData : + subInterfaceTemplateConsolidationDataList) { + //Get the subInterface property value + String subInterfaceNodeTemplateId = subInterfaceTemplateConsolidationData + .getNodeTemplateId(); + NodeTemplate subInterfaceNodeTemplate = DataModelUtil.getNodeTemplate(serviceTemplate, + subInterfaceNodeTemplateId); + String subInterfaceType = getSubInterfaceTypeSuffix(subInterfaceNodeTemplate + .getType()); + Object propertyValue = getSubInterfacePropertyValue(substitutionTemplateInputName, + subInterfaceType, subInterfaceInputType, serviceTemplate, + subInterfaceNodeTemplateId); + //If the value object is Optional.empty it implies that the property name was not + // found in the input name + if (!(propertyValue instanceof Optional)) { + abstractPropertyValue.add(propertyValue); + } + } + } + } + private void updateAbstractPropertyValue(String substitutionTemplateInputName, ParameterDefinition parameterDefinition, List<Object> abstractPropertyValue, @@ -2642,10 +2849,7 @@ public class UnifiedCompositionService { } else { Object propertyValue = abstractPropertyValue.get(0); String entrySchemaType = parameterDefinition.getEntry_schema().getType(); - if (entrySchemaType.equalsIgnoreCase(PropertyType.STRING.getDisplayName()) - || entrySchemaType.equalsIgnoreCase(PropertyType.INTEGER.getDisplayName()) - || entrySchemaType.equalsIgnoreCase(PropertyType.FLOAT.getDisplayName()) - || entrySchemaType.equalsIgnoreCase(PropertyType.BOOLEAN.getDisplayName()) + if (PropertyType.getSimplePropertyTypes().contains(entrySchemaType.toLowerCase()) || entrySchemaType.equals(PropertyTypeExt.JSON.getDisplayName())) { abstractSubstituteProperties.put(substitutionTemplateInputName, abstractPropertyValue); } else { @@ -2656,7 +2860,6 @@ public class UnifiedCompositionService { private void updateIdenticalPropertyValue(String identicalValuePropertyName, String substitutionTemplateInputName, - String computeType, UnifiedCompositionEntity entity, UnifiedCompositionData unifiedCompositionData, ServiceTemplate serviceTemplate, @@ -2678,73 +2881,95 @@ public class UnifiedCompositionService { private Optional<Object> getIdenticalPropertyValueByType(String identicalValuePropertyName, String substitutionTemplateInputName, UnifiedCompositionEntity entity, - UnifiedCompositionData unifiedCompositionData, + UnifiedCompositionData + unifiedCompositionData, ServiceTemplate serviceTemplate, TranslationContext context) { ComputeTemplateConsolidationData computeTemplateConsolidationData = unifiedCompositionData.getComputeTemplateConsolidationData(); - Optional<Object> computeIdenticalPropertyValue; + Optional<Object> identicalPropertyValue = Optional.empty(); switch (entity) { - case Compute: - computeIdenticalPropertyValue = + case COMPUTE: + identicalPropertyValue = getIdenticalPropertyValue(identicalValuePropertyName, serviceTemplate, - entity, computeTemplateConsolidationData, context); - return computeIdenticalPropertyValue.isPresent() ? Optional.of( - computeIdenticalPropertyValue.get()) : Optional.empty(); - - case Other: - computeIdenticalPropertyValue = + computeTemplateConsolidationData, context); + break; + case OTHER: + identicalPropertyValue = getIdenticalPropertyValue(identicalValuePropertyName, serviceTemplate, - entity, computeTemplateConsolidationData, context); - return computeIdenticalPropertyValue.isPresent() ? Optional.of( - computeIdenticalPropertyValue.get()) : Optional.empty(); - - case Port: + computeTemplateConsolidationData, context); + break; + case PORT: List<PortTemplateConsolidationData> portTemplateConsolidationDataList = unifiedCompositionData.getPortTemplateConsolidationDataList(); for (PortTemplateConsolidationData portTemplateConsolidationData : portTemplateConsolidationDataList) { String portType = ConsolidationDataUtil.getPortType(portTemplateConsolidationData.getNodeTemplateId()); if (substitutionTemplateInputName.contains(portType)) { - return getIdenticalPropertyValue(identicalValuePropertyName, serviceTemplate, - entity, portTemplateConsolidationData, context); + return getIdenticalPropertyValue(identicalValuePropertyName, + serviceTemplate, portTemplateConsolidationData, context); } } + break; + default: + break; } - - return Optional.empty(); - + return identicalPropertyValue; } - private PortInputType getPortInputType(String inputName, - UnifiedCompositionData unifiedCompositionData) { - String portInputPrefix = UnifiedCompositionEntity.Port.name().toLowerCase() + "_"; + private PropertyInputType getPortInputType(String inputName, + UnifiedCompositionData unifiedCompositionData) { + String portInputPrefix = UnifiedCompositionEntity.PORT.getDisplayName().toLowerCase() + "_"; ComputeTemplateConsolidationData computeTemplateConsolidationData = unifiedCompositionData .getComputeTemplateConsolidationData(); List<PortTemplateConsolidationData> portTemplateConsolidationDataList = getPortTemplateConsolidationDataList(unifiedCompositionData); //Scan the available port node template ids to check if the input is of the form // "port_<port_node_template_id>_<property_name>" - for (PortTemplateConsolidationData portTemplateConsolidationData : - portTemplateConsolidationDataList) { - String portNodeTemplateId = portTemplateConsolidationData.getNodeTemplateId(); - String portNodeTemplateIdPrefix = portInputPrefix + portNodeTemplateId; - if (inputName.startsWith(portNodeTemplateIdPrefix)) { - return PortInputType.NodeTemplateId; - } + if (portTemplateConsolidationDataList.stream().map(EntityConsolidationData::getNodeTemplateId) + .map(portNodeTemplateId -> portInputPrefix + portNodeTemplateId).anyMatch(inputName::startsWith)) { + return PropertyInputType.NODE_TEMPLATE_ID; } //Check whether the input is of the form "port_<port_type>_<property_name>" Set<String> portTypes = computeTemplateConsolidationData.getPorts().keySet(); - for (String portType : portTypes) { - String expectedPortTypeSusbtring = portInputPrefix + portType + "_"; - if (inputName.startsWith(expectedPortTypeSusbtring)) { - return PortInputType.PortType; - } + if (portTypes.stream().map(portType -> portInputPrefix + portType + "_").anyMatch(inputName::startsWith)) { + return PropertyInputType.TYPE; + } + return PropertyInputType.OTHER; + } + + private PropertyInputType getSubInterfaceInputType(String inputName, + UnifiedCompositionData unifiedCompositionData) { + String subInterfaceInputPrefix = UnifiedCompositionEntity.SUB_INTERFACE.getDisplayName().toLowerCase() + + "_"; + List<SubInterfaceTemplateConsolidationData> subInterfaceTemplateConsolidationDataList = + getSubInterfaceTemplateConsolidationDataList(unifiedCompositionData); + //Scan the available port node template ids to check if the input is of the form + // "subinterface_<subinterface_node_template_id>_<property_name>" + if (subInterfaceTemplateConsolidationDataList.stream().map(EntityConsolidationData::getNodeTemplateId) + .map(subInterfaceNodeTemplateId -> subInterfaceInputPrefix + + subInterfaceNodeTemplateId) + .anyMatch(inputName::startsWith)) { + return PropertyInputType.NODE_TEMPLATE_ID; + } + //Check whether the input is of the form "subinterface_<subinterface_type>_<property_name>" + Set<String> subInterfaceTypes = new HashSet<>(); + List<PortTemplateConsolidationData> portTemplateConsolidationDataList = + getPortTemplateConsolidationDataList(unifiedCompositionData); + for (PortTemplateConsolidationData portTemplateConsolidationData : + portTemplateConsolidationDataList) { + subInterfaceTypes.addAll(portTemplateConsolidationData.getAllSubInterfaceNodeTypes()); } - return PortInputType.Other; + + if (subInterfaceTypes.stream().map(UnifiedCompositionUtil::getSubInterfaceTypeSuffix) + .map(subInterfaceTypeSuffix -> subInterfaceInputPrefix + subInterfaceTypeSuffix + "_") + .anyMatch(inputName::startsWith)) { + return PropertyInputType.TYPE; + } + return PropertyInputType.OTHER; } private void cleanServiceTemplate(ServiceTemplate serviceTemplate, @@ -2768,8 +2993,8 @@ public class UnifiedCompositionService { context.addCleanedNodeTemplate(ToscaUtil.getServiceTemplateFileName(serviceTemplate), nodeTemplateIdToRemove, entity.getClass() == ComputeTemplateConsolidationData.class - ? UnifiedCompositionEntity.Compute - : UnifiedCompositionEntity.Port, + ? COMPUTE + : UnifiedCompositionEntity.PORT, nodeTemplateToRemove); } @@ -2795,7 +3020,6 @@ public class UnifiedCompositionService { Map<String, GroupDefinition> groups = serviceTemplate.getTopology_template() .getGroups() == null ? new HashMap<>() : serviceTemplate.getTopology_template().getGroups(); - String serviceTemplateFileName = ToscaUtil.getServiceTemplateFileName(serviceTemplate); String nodeRelatedAbstractNodeId = context.getUnifiedAbstractNodeTemplateId(serviceTemplate, entity.getNodeTemplateId()); @@ -2822,25 +3046,6 @@ public class UnifiedCompositionService { groupEntry.getValue().setMembers(members); } - private void updateSubstitutableNodeTemplateRequirements(ServiceTemplate serviceTemplate, - ServiceTemplate substitutionServiceTemplate) { - if (Objects.isNull(substitutionServiceTemplate.getTopology_template())) { - return; - } - - SubstitutionMapping substitution_mappings = - substitutionServiceTemplate.getTopology_template().getSubstitution_mappings(); - - if (Objects.isNull(substitution_mappings)) { - return; - } - - String node_type = substitution_mappings.getNode_type(); - Map<String, List<String>> requirements = substitution_mappings.getRequirements(); - - - } - private void updateSubstitutionMapping(ServiceTemplate serviceTemplate, TranslationContext context) { SubstitutionMapping substitutionMappings = @@ -2938,118 +3143,6 @@ public class UnifiedCompositionService { .ifPresent(unifiedNestedNodeTypeIdVal -> updateNestedNodeTemplate( unifiedNestedNodeTypeIdVal, nestedNodeTemplateId, nestedNodeTemplate, mainServiceTemplate, context)); - - //updateNestedNodeTemplateRequirement(nestedNodeTemplateId, mainServiceTemplate, - //nestedServiceTemplate, context); - - //updateNodeTemplateRequirements(nestedNodeTemplateId, mainServiceTemplate, - //nestedServiceTemplate, context); - - //updateNodeDependencyRequirement(mainServiceTemplate, context, nestedNodeTemplate); - } - - private void updateNestedNodeTemplateRequirement(String nestedNodeTemplateId, - ServiceTemplate mainServiceTemplate, - ServiceTemplate nestedServiceTemplate, - TranslationContext context) { - NestedTemplateConsolidationData nestedTemplateConsolidationData = - ConsolidationDataUtil - .getNestedTemplateConsolidationData(context, mainServiceTemplate, null, - nestedNodeTemplateId); - - FileComputeConsolidationData fileComputeConsolidationData = - context.getConsolidationData().getComputeConsolidationData().getFileComputeConsolidationData - (ToscaUtil.getServiceTemplateFileName(nestedServiceTemplate)); - - - TypeComputeConsolidationData compute = - fileComputeConsolidationData.getAllTypeComputeConsolidationData().iterator().next(); - - if (Objects.isNull(nestedTemplateConsolidationData)) { - return; - } - - Map<String, List<RequirementAssignmentData>> nodesConnectedOut = - nestedTemplateConsolidationData.getNodesConnectedOut(); - - if (MapUtils.isEmpty(nodesConnectedOut)) { - return; - } - - updateRequirements(nestedNodeTemplateId, mainServiceTemplate, nestedServiceTemplate, compute, - nodesConnectedOut); - } - - private void updateRequirements(String nestedNodeTemplateId, ServiceTemplate mainServiceTemplate, - ServiceTemplate nestedServiceTemplate, - TypeComputeConsolidationData compute, - Map<String, List<RequirementAssignmentData>> nodesConnectedOut) { - NodeTemplate nodeTemplate = - DataModelUtil.getNodeTemplate(mainServiceTemplate, nestedNodeTemplateId); - - for (List<RequirementAssignmentData> requirementAssignmentDataList : nodesConnectedOut - .values()) { - for (RequirementAssignmentData data : requirementAssignmentDataList) { - if (!data.getRequirementId().equals("dependency")) { - DataModelUtil.addRequirementAssignment(nodeTemplate, data.getRequirementId(), - cloneRequirementAssignment(data.getRequirementAssignment())); - updateRequirementInSubMapping(nestedServiceTemplate, compute, data); - - } - } - } - - removeUneccessaryRequirements(nodeTemplate); - } - - private void updateRequirementInSubMapping(ServiceTemplate nestedServiceTemplate, - TypeComputeConsolidationData compute, - RequirementAssignmentData data) { - List<String> subMappingRequirement = - Arrays.asList(compute.getAllComputeNodeTemplateIds().iterator().next(), "dependency"); - DataModelUtil.addSubstitutionMappingReq(nestedServiceTemplate, data.getRequirementId(), - subMappingRequirement); - } - - - private RequirementAssignment cloneRequirementAssignment(RequirementAssignment reqToClone) { - RequirementAssignment requirementAssignment = new RequirementAssignment(); - - requirementAssignment.setRelationship(reqToClone.getRelationship()); - requirementAssignment.setNode(reqToClone.getNode()); - requirementAssignment.setCapability(reqToClone.getCapability()); - - return requirementAssignment; - } - - private void removeUneccessaryRequirements(NodeTemplate nodeTemplate) { - List<Map<String, RequirementAssignment>> reqsToRemove = new ArrayList<>(); - for (Map<String, RequirementAssignment> requirementDefinitionMap : nodeTemplate - .getRequirements()) { - if (requirementDefinitionMap.containsKey("dependency")) { - reqsToRemove.add(requirementDefinitionMap); - } - } - - nodeTemplate.getRequirements().removeAll(reqsToRemove); - } - - private RequirementAssignment getRequirementAssignmentFromDefinition( - Map.Entry<String, RequirementDefinition> requirementDefinitionEntry) { - - RequirementAssignment requirementAssignment = new RequirementAssignment(); - if (requirementDefinitionEntry.getValue() instanceof RequirementDefinition) { - requirementAssignment.setCapability(requirementDefinitionEntry.getValue().getCapability()); - requirementAssignment.setNode(requirementDefinitionEntry.getValue().getNode()); - requirementAssignment - .setRelationship(requirementDefinitionEntry.getValue().getRelationship()); - } else if (requirementDefinitionEntry.getValue() instanceof Map) { - Map<String, Object> reqAsMap = (Map<String, Object>) requirementDefinitionEntry.getValue(); - requirementAssignment.setCapability((String) reqAsMap.get("capability")); - requirementAssignment.setNode((String) reqAsMap.get("node")); - requirementAssignment.setRelationship((String) reqAsMap.get("relationship")); - } - return requirementAssignment; } private void updateNestedNodeTemplateProperties(ServiceTemplate nestedServiceTemplate, @@ -3148,8 +3241,7 @@ public class UnifiedCompositionService { } } - private Optional<String> getNewNestedNodeTypeId(ServiceTemplate mainServiceTemplate, - ServiceTemplate nestedServiceTemplate, + private Optional<String> getNewNestedNodeTypeId(ServiceTemplate nestedServiceTemplate, TranslationContext context) { FileComputeConsolidationData fileComputeConsolidationData = context.getConsolidationData().getComputeConsolidationData() @@ -3168,7 +3260,7 @@ public class UnifiedCompositionService { FileComputeConsolidationData fileComputeConsolidationData) { List<TypeComputeConsolidationData> typeComputeConsolidationDatas = new ArrayList<>(fileComputeConsolidationData.getAllTypeComputeConsolidationData()); - if (typeComputeConsolidationDatas.size() == 0) { + if (typeComputeConsolidationDatas.isEmpty()) { return null; } else { String computeNodeType = fileComputeConsolidationData.getAllComputeTypes().iterator().next(); @@ -3300,15 +3392,16 @@ public class UnifiedCompositionService { private Object getPortPropertyValue(String inputName, String computeType, - PortInputType portInputType, + PropertyInputType portInputType, ServiceTemplate serviceTemplate, String portNodeTemplateId) { //Get the input prefix to extract the property name from the input name - String portInputPrefix = getPortInputPrefix( - portNodeTemplateId, portInputType); + String portType = ConsolidationDataUtil.getPortType(portNodeTemplateId); + String portInputPrefix = getPropertyInputPrefix( + portNodeTemplateId, portType, portInputType, UnifiedCompositionEntity.PORT); //Get the property name from the input Optional<String> propertyName = getPropertyNameFromInput(inputName, - UnifiedCompositionEntity.Port, computeType, portInputPrefix); + UnifiedCompositionEntity.PORT, computeType, portInputPrefix); //Get the property value from the node template if (propertyName.isPresent()) { NodeTemplate portNodeTemplate = DataModelUtil.getNodeTemplate(serviceTemplate, @@ -3320,27 +3413,6 @@ public class UnifiedCompositionService { return Optional.empty(); } - private Optional<String> getPortTypeFromInput( - String inputName, - String portNodeTemplateId, - ComputeTemplateConsolidationData computeTemplateConsolidationData) { - String portTypeFromInput = null; - String portInputPrefix = UnifiedCompositionEntity.Port.name().toLowerCase() + "_"; - String portNodeTemplateIdPrefix = portInputPrefix + portNodeTemplateId; - if (inputName.startsWith(portNodeTemplateIdPrefix)) { - return Optional.empty(); - } - Set<String> portTypes = computeTemplateConsolidationData.getPorts().keySet(); - for (String portType : portTypes) { - String expectedPortTypeSusbtring = "_" + portType + "_"; - if (inputName.contains(expectedPortTypeSusbtring)) { - portTypeFromInput = portType; - break; - } - } - return Optional.ofNullable(portTypeFromInput); - } - private Object getComputePropertyValue( String inputName, ServiceTemplate serviceTemplate, @@ -3349,16 +3421,37 @@ public class UnifiedCompositionService { computeTemplateConsolidationData.getNodeTemplateId()); String nodeType = getComputeTypeSuffix(nodeTemplate.getType()); Optional<String> propertyName = - getPropertyNameFromInput(inputName, UnifiedCompositionEntity.Compute, nodeType, null); + getPropertyNameFromInput(inputName, COMPUTE, nodeType, null); if (propertyName.isPresent()) { return getPropertyValueFromNodeTemplate(propertyName.get(), nodeTemplate); } return Optional.empty(); } + private Object getSubInterfacePropertyValue(String inputName, + String subInterfaceTypeSuffix, + PropertyInputType propertyInputType, + ServiceTemplate serviceTemplate, + String subInterfaceNodeTemplateId) { + //Get the input prefix to extract the property name from the input name + String propertyInputPrefix = getPropertyInputPrefix(subInterfaceNodeTemplateId, + subInterfaceTypeSuffix, propertyInputType, UnifiedCompositionEntity.SUB_INTERFACE); + //Get the property name from the input + Optional<String> propertyName = getPropertyNameFromInput(inputName, + UnifiedCompositionEntity.SUB_INTERFACE, null, propertyInputPrefix); + //Get the property value from the node template + if (propertyName.isPresent()) { + NodeTemplate subInterfaceNodeTemplate = DataModelUtil.getNodeTemplate(serviceTemplate, + subInterfaceNodeTemplateId); + if (Objects.nonNull(subInterfaceNodeTemplate)) { + return getPropertyValueFromNodeTemplate(propertyName.get(), subInterfaceNodeTemplate); + } + } + return Optional.empty(); + } + private Optional<Object> getIdenticalPropertyValue(String identicalValuePropertyName, ServiceTemplate serviceTemplate, - UnifiedCompositionEntity unifiedCompositionEntity, EntityConsolidationData entity, TranslationContext context) { NodeTemplate nodeTemplate = @@ -3372,12 +3465,17 @@ public class UnifiedCompositionService { } private UnifiedCompositionEntity getInputCompositionEntity(String inputName) { - UnifiedCompositionEntity inputCompositionEntity = UnifiedCompositionEntity.Other; - String inputType = inputName.substring(0, inputName.indexOf('_')); - if (inputType.equals(UnifiedCompositionEntity.Compute.name().toLowerCase())) { - inputCompositionEntity = UnifiedCompositionEntity.Compute; - } else if (inputType.equals(UnifiedCompositionEntity.Port.name().toLowerCase())) { - inputCompositionEntity = UnifiedCompositionEntity.Port; + UnifiedCompositionEntity inputCompositionEntity = UnifiedCompositionEntity.OTHER; + if (inputName.indexOf('_') != -1) { + String inputType = inputName.substring(0, inputName.indexOf('_')); + if (inputType.equalsIgnoreCase(COMPUTE.getDisplayName())) { + inputCompositionEntity = COMPUTE; + } else if (inputType.equalsIgnoreCase(UnifiedCompositionEntity.PORT.getDisplayName())) { + inputCompositionEntity = UnifiedCompositionEntity.PORT; + } else if (inputType.equalsIgnoreCase(UnifiedCompositionEntity.SUB_INTERFACE + .getDisplayName())) { + inputCompositionEntity = UnifiedCompositionEntity.SUB_INTERFACE; + } } return inputCompositionEntity; } @@ -3385,16 +3483,17 @@ public class UnifiedCompositionService { private Optional<String> getPropertyNameFromInput( String inputName, UnifiedCompositionEntity compositionEntity, - String computeType, String portInputPrefix) { + String entityType, String propertyInputPrefix) { String propertyName = null; switch (compositionEntity) { - case Compute: - propertyName = inputName.substring(inputName.lastIndexOf(computeType) - + computeType.length() + 1); + case COMPUTE: + propertyName = inputName.substring(inputName.lastIndexOf(entityType) + + entityType.length() + 1); break; - case Port: - if (inputName.startsWith(portInputPrefix)) { - propertyName = inputName.split(portInputPrefix)[1]; + case PORT: + case SUB_INTERFACE: + if (inputName.startsWith(propertyInputPrefix)) { + propertyName = inputName.split(propertyInputPrefix)[1]; } break; default: @@ -3403,47 +3502,49 @@ public class UnifiedCompositionService { return Optional.ofNullable(propertyName); } - private String getPortInputPrefix( - String portNodeTemplateId, - PortInputType portInputType) { - String portInputPrefix = UnifiedCompositionEntity.Port.name().toLowerCase() + "_"; - String portType = ConsolidationDataUtil.getPortType(portNodeTemplateId); - if (portInputType == PortInputType.NodeTemplateId) { - portInputPrefix += portNodeTemplateId + "_"; - } else if (portInputType == PortInputType.PortType) { - portInputPrefix += portType + "_"; + private String getPropertyInputPrefix(String nodeTemplateId, + String propertyEntityType, + PropertyInputType propertyInputType, + UnifiedCompositionEntity unifiedCompositionEntity) { + String propertyInputPrefix = unifiedCompositionEntity.getDisplayName().toLowerCase() + "_"; + if (propertyInputType == PropertyInputType.NODE_TEMPLATE_ID) { + propertyInputPrefix += nodeTemplateId + "_"; + } else if (propertyInputType == PropertyInputType.TYPE) { + propertyInputPrefix += propertyEntityType + "_"; } - return portInputPrefix; + return propertyInputPrefix; } private boolean isIdenticalValueProperty(String inputName, - UnifiedCompositionEntity unifiedCompositionEntity, - TranslationContext context) { + UnifiedCompositionEntity unifiedCompositionEntity) { List<String> identicalValuePropertyList = consolidationService.getPropertiesWithIdenticalVal(unifiedCompositionEntity); StringBuilder builder = getPropertyValueStringBuilder(unifiedCompositionEntity); + if (Objects.isNull(builder)) { + return false; + } boolean isMatchingProperty = Pattern.matches(builder.toString(), inputName); - return (isMatchingProperty + return isMatchingProperty && isPropertyFromIdenticalValuesList(inputName, unifiedCompositionEntity, - identicalValuePropertyList)); + identicalValuePropertyList); } private boolean isPropertyFromIdenticalValuesList(String inputName, UnifiedCompositionEntity unifiedCompositionEntity, List<String> identicalValuePropertyList) { switch (unifiedCompositionEntity) { - case Compute: + case COMPUTE: return identicalValuePropertyList.contains(getIdenticalValuePropertyName(inputName, - unifiedCompositionEntity, null).get()); + unifiedCompositionEntity).get()); - case Other: + case OTHER: return identicalValuePropertyList.contains(getIdenticalValuePropertyName(inputName, - unifiedCompositionEntity, null).get()); + unifiedCompositionEntity).get()); - case Port: + case PORT: return getPortPropertyNameFromInput(inputName, identicalValuePropertyList).isPresent(); default: @@ -3465,15 +3566,18 @@ public class UnifiedCompositionService { UnifiedCompositionEntity unifiedCompositionEntity) { switch (unifiedCompositionEntity) { - case Compute: + case COMPUTE: return getComputePropertyValueStringBuilder(); - case Other: + case OTHER: return getComputePropertyValueStringBuilder(); - case Port: + case PORT: return getPortPropertyValueStringBuilder(); + case SUB_INTERFACE: + return getSubInterfacePropertyValueStringBuilder(); + default: return null; } @@ -3494,17 +3598,24 @@ public class UnifiedCompositionService { return builder; } + private StringBuilder getSubInterfacePropertyValueStringBuilder() { + StringBuilder builder; + builder = new StringBuilder(SUB_INTERFACE_PROPERTY_VALUE_PREFIX); + builder.append(".+"); + return builder; + } + private Optional<String> getIdenticalValuePropertyName(String input, - UnifiedCompositionEntity unifiedCompositionEntity, - TranslationContext context) { + UnifiedCompositionEntity + unifiedCompositionEntity) { switch (unifiedCompositionEntity) { - case Compute: + case COMPUTE: return Optional.of(input.split("_")[1]); - case Other: + case OTHER: return Optional.of(input.split("_")[1]); - case Port: + case PORT: return getPortPropertyNameFromInput(input, consolidationService .getPropertiesWithIdenticalVal(unifiedCompositionEntity)); @@ -3533,21 +3644,28 @@ public class UnifiedCompositionService { if (Objects.nonNull(computeTemplateConsolidationData)) { consolidationNodeTemplateIdAndType .put(computeTemplateConsolidationData.getNodeTemplateId(), - UnifiedCompositionEntity.Compute); + COMPUTE); + } + List<SubInterfaceTemplateConsolidationData> subInterfaceTemplateConsolidationDataList = + getSubInterfaceTemplateConsolidationDataList(unifiedCompositionData); + for (SubInterfaceTemplateConsolidationData subInterfaceTemplateConsolidationData : + subInterfaceTemplateConsolidationDataList) { + consolidationNodeTemplateIdAndType.put(subInterfaceTemplateConsolidationData.getNodeTemplateId(), + UnifiedCompositionEntity.SUB_INTERFACE); } List<PortTemplateConsolidationData> portTemplateConsolidationDataList = getPortTemplateConsolidationDataList(unifiedCompositionData); for (PortTemplateConsolidationData portTemplateConsolidationData : portTemplateConsolidationDataList) { consolidationNodeTemplateIdAndType.put(portTemplateConsolidationData.getNodeTemplateId(), - UnifiedCompositionEntity.Port); + UnifiedCompositionEntity.PORT); } NestedTemplateConsolidationData nestedTemplateConsolidationData = unifiedCompositionData.getNestedTemplateConsolidationData(); if (Objects.nonNull(nestedTemplateConsolidationData)) { consolidationNodeTemplateIdAndType .put(nestedTemplateConsolidationData.getNodeTemplateId(), - UnifiedCompositionEntity.Nested); + UnifiedCompositionEntity.NESTED); } } return consolidationNodeTemplateIdAndType; @@ -3559,9 +3677,9 @@ public class UnifiedCompositionService { ArrayList<>() : unifiedCompositionData.getPortTemplateConsolidationDataList(); } - private enum PortInputType { - NodeTemplateId, - PortType, - Other; + private enum PropertyInputType { + NODE_TEMPLATE_ID, + TYPE, + OTHER } } diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/UnifiedCompositionUtil.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/UnifiedCompositionUtil.java index 7f3025408f..4d9a269c2e 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/UnifiedCompositionUtil.java +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/UnifiedCompositionUtil.java @@ -1,15 +1,46 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.openecomp.sdc.translator.services.heattotosca; +import com.google.common.collect.ArrayListMultimap; +import com.google.common.collect.ListMultimap; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; import org.openecomp.sdc.logging.api.Logger; import org.openecomp.sdc.logging.api.LoggerFactory; +import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate; +import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate; +import org.openecomp.sdc.tosca.services.DataModelUtil; +import org.openecomp.sdc.tosca.services.ToscaUtil; +import org.openecomp.sdc.translator.datatypes.heattotosca.TranslationContext; +import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.composition.UnifiedCompositionData; import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.ComputeTemplateConsolidationData; +import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.FilePortConsolidationData; +import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.PortTemplateConsolidationData; +import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.SubInterfaceTemplateConsolidationData; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.stream.Collectors; /** * Utility class for consolidation data collection helper methods. @@ -18,6 +49,10 @@ public class UnifiedCompositionUtil { protected static Logger logger = LoggerFactory.getLogger(UnifiedCompositionUtil.class); + private UnifiedCompositionUtil() { + //Hiding the implicit public constructor + } + /** * Gets all ports per port type, which are connected to the computes from the input * computeTemplateConsolidationDataCollection. @@ -40,6 +75,37 @@ public class UnifiedCompositionUtil { return portTypeToIds; } + static ListMultimap<String, SubInterfaceTemplateConsolidationData> + collectAllSubInterfacesOfEachTypesFromPorts(Collection<PortTemplateConsolidationData> + portTemplateConsolidationDataCollection) { + ListMultimap<String, SubInterfaceTemplateConsolidationData> subInterfaceDataByType = ArrayListMultimap.create(); + for (PortTemplateConsolidationData port : portTemplateConsolidationDataCollection) { + Set<String> allSubInterfaceNodeTypes = port.getAllSubInterfaceNodeTypes(); + if (CollectionUtils.isEmpty(allSubInterfaceNodeTypes)) { + continue; + } + for (String subInterfaceNodeType : allSubInterfaceNodeTypes) { + subInterfaceDataByType.putAll(subInterfaceNodeType, + port.getSubInterfaceConsolidationData(subInterfaceNodeType)); + } + } + return subInterfaceDataByType; + } + + static List<String> getSubInterfaceNodeTemplateIdsByType(PortTemplateConsolidationData + portTemplateConsolidationData, + String subInterfaceType) { + List<String> subInterfaceNodeTemplateIds = new ArrayList<>(); + List<SubInterfaceTemplateConsolidationData> subInterfaceTemplateConsolidationDataList = + portTemplateConsolidationData.getSubInterfaceConsolidationData(subInterfaceType); + if (CollectionUtils.isNotEmpty(subInterfaceTemplateConsolidationDataList)) { + subInterfaceNodeTemplateIds = subInterfaceTemplateConsolidationDataList.stream() + .map(SubInterfaceTemplateConsolidationData::getNodeTemplateId) + .collect(Collectors.toList()); + } + return subInterfaceNodeTemplateIds; + } + private static void addPortsToMap(Map<String, List<String>> portTypeToIds, Map<String, List<String>> ports) { for (Map.Entry<String, List<String>> portTypeToIdEntry : ports.entrySet()) { @@ -48,5 +114,116 @@ public class UnifiedCompositionUtil { } } + static String getComputeTypeSuffix(ServiceTemplate serviceTemplate, + String computeNodeTemplateId) { + NodeTemplate computeNodeTemplate = DataModelUtil.getNodeTemplate(serviceTemplate, computeNodeTemplateId); + if (Objects.nonNull(computeNodeTemplate)) { + return getComputeTypeSuffix(computeNodeTemplate.getType()); + } + return null; + } + + public static String getNewComputeNodeTemplateId(ServiceTemplate serviceTemplate, String computeNodeTemplateId) { + return getComputeTypeSuffix(serviceTemplate, computeNodeTemplateId); + } + + static String getComputeTypeSuffix(String computeType) { + return DataModelUtil.getNamespaceSuffix(computeType); + } + + public static ComputeTemplateConsolidationData getConnectedComputeConsolidationData( + List<UnifiedCompositionData> unifiedCompositionDataList, + String portNodeTemplateId) { + for (UnifiedCompositionData unifiedCompositionData : unifiedCompositionDataList) { + if (Objects.isNull(unifiedCompositionData.getComputeTemplateConsolidationData().getPorts())) { + continue; + } + Collection<List<String>> portsCollection = + unifiedCompositionData.getComputeTemplateConsolidationData().getPorts().values(); + for (List<String> portIdList : portsCollection) { + if (portIdList.contains(portNodeTemplateId)) { + return unifiedCompositionData.getComputeTemplateConsolidationData(); + } + } + } + return null; + } + + //The ID should be <vm_type>_<port_type> or <vm_type>_<portNodeTemplateId> + public static String getNewPortNodeTemplateId( + String portNodeTemplateId, + String connectedComputeNodeType, + ComputeTemplateConsolidationData computeTemplateConsolidationData) { + + StringBuilder newPortNodeTemplateId = new StringBuilder(); + String portType = ConsolidationDataUtil.getPortType(portNodeTemplateId); + newPortNodeTemplateId.append(DataModelUtil.getNamespaceSuffix(connectedComputeNodeType)); + if (computeTemplateConsolidationData.getPorts().get(portType).size() > 1) { + //single port + newPortNodeTemplateId.append("_").append(portNodeTemplateId); + } else { + //consolidation port + newPortNodeTemplateId.append("_").append(portType); + } + return newPortNodeTemplateId.toString(); + } + + public static String getNewSubInterfaceNodeTemplateId(ServiceTemplate serviceTemplate, + String connectedComputeNodeType, + ComputeTemplateConsolidationData computeTemplateConsolidationData, + SubInterfaceTemplateConsolidationData + subInterfaceTemplateConsolidationData, + TranslationContext context) { + //The ID should be <vm_type>_<portType/NodetemplateId>_<subInterface_type> + // or <vm_type>_<portType/NodetemplateId>_<subInterfaceNodeTemplateId> + StringBuilder newSubInterfaceNodeTemplateId = new StringBuilder(); + newSubInterfaceNodeTemplateId.append(getNewPortNodeTemplateId(subInterfaceTemplateConsolidationData + .getParentPortNodeTemplateId(), connectedComputeNodeType, computeTemplateConsolidationData)); + PortTemplateConsolidationData portTemplateConsolidationData = + getSubInterfacePortTemplateConsolidationData(serviceTemplate, subInterfaceTemplateConsolidationData, context); + NodeTemplate subInterfaceNodeTemplate = + DataModelUtil.getNodeTemplate(serviceTemplate, subInterfaceTemplateConsolidationData.getNodeTemplateId()); + if (Objects.nonNull(portTemplateConsolidationData)) { + List<String> subInterfaceNodeTemplateIdsByType = + UnifiedCompositionUtil.getSubInterfaceNodeTemplateIdsByType(portTemplateConsolidationData, + subInterfaceNodeTemplate.getType()); + if (CollectionUtils.isNotEmpty(subInterfaceNodeTemplateIdsByType)) { + //If there are more than one subinterfaces with same type use node template id + if (subInterfaceNodeTemplateIdsByType.size() > 1) { + newSubInterfaceNodeTemplateId.append("_").append(subInterfaceTemplateConsolidationData.getNodeTemplateId()); + } else { + //Add sub interface type since we have only one subinterface per type + String subInterfaceTypeSuffix = getSubInterfaceTypeSuffix(subInterfaceNodeTemplate.getType()); + newSubInterfaceNodeTemplateId.append("_").append(subInterfaceTypeSuffix); + } + return newSubInterfaceNodeTemplateId.toString(); + } + } + return subInterfaceTemplateConsolidationData.getNodeTemplateId(); + } + + static PortTemplateConsolidationData getSubInterfacePortTemplateConsolidationData(ServiceTemplate serviceTemplate, + SubInterfaceTemplateConsolidationData + subInterfaceTemplateConsolidationData, + TranslationContext context) { + FilePortConsolidationData filePortConsolidationData = context.getConsolidationData().getPortConsolidationData() + .getFilePortConsolidationData(ToscaUtil.getServiceTemplateFileName(serviceTemplate)); + PortTemplateConsolidationData portTemplateConsolidationData = null; + if (filePortConsolidationData != null) { + portTemplateConsolidationData = filePortConsolidationData + .getPortTemplateConsolidationData(subInterfaceTemplateConsolidationData.getParentPortNodeTemplateId()); + } + return portTemplateConsolidationData; + } + + static String getSubInterfaceTypeSuffix(String nodeType) { + return DataModelUtil.getNamespaceSuffix(nodeType); + } + + public static List<SubInterfaceTemplateConsolidationData> getSubInterfaceTemplateConsolidationDataList( + UnifiedCompositionData unifiedCompositionData) { + return unifiedCompositionData.getSubInterfaceTemplateConsolidationDataList() == null ? new + ArrayList<>() : unifiedCompositionData.getSubInterfaceTemplateConsolidationDataList(); + } } diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/helper/ContrailV2VirtualMachineInterfaceHelper.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/helper/ContrailV2VirtualMachineInterfaceHelper.java index 0933174296..622f3c1be3 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/helper/ContrailV2VirtualMachineInterfaceHelper.java +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/helper/ContrailV2VirtualMachineInterfaceHelper.java @@ -1,27 +1,27 @@ -/*- - * ============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.helper; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.collections4.MapUtils; import org.openecomp.sdc.heat.datatypes.model.HeatResourcesTypes; import org.openecomp.sdc.heat.datatypes.model.Resource; +import org.openecomp.sdc.heat.datatypes.model.ResourceReferenceFunctions; import org.openecomp.sdc.heat.services.HeatConstants; import org.openecomp.sdc.logging.api.Logger; import org.openecomp.sdc.logging.api.LoggerFactory; @@ -30,6 +30,7 @@ import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate; import org.openecomp.sdc.tosca.datatypes.model.RequirementAssignment; import org.openecomp.sdc.tosca.services.ToscaConstants; import org.openecomp.sdc.translator.datatypes.heattotosca.AttachedResourceId; +import org.openecomp.sdc.translator.datatypes.heattotosca.TranslationContext; import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo; import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslatedHeatResource; import org.openecomp.sdc.translator.services.heattotosca.ConsolidationDataUtil; @@ -37,11 +38,14 @@ import org.openecomp.sdc.translator.services.heattotosca.ConsolidationEntityType import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil; import org.openecomp.sdc.translator.services.heattotosca.impl.resourcetranslation.ResourceTranslationBase; +import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Optional; +import java.util.Set; public class ContrailV2VirtualMachineInterfaceHelper { static Logger logger = @@ -138,7 +142,7 @@ public class ContrailV2VirtualMachineInterfaceHelper { } /** - * Check if the input heat resource is Vlan sub interface resource + * Check if the input heat resource is Vlan sub interface resource. * * @param resource heat resource to be checked * @return true - if input resource is valn sub interface resource flase - otherwise. @@ -154,6 +158,32 @@ public class ContrailV2VirtualMachineInterfaceHelper { return false; } + public boolean isVlanSubInterfaceConnectedToPortIndirectly(TranslateTo translateTo) { + Resource resource = translateTo.getResource(); + TranslationContext context = translateTo.getContext(); + Set<String> nestedHeatsFiles = context.getNestedHeatsFiles(); + Map<String, Object> properties = resource.getProperties(); + + if (MapUtils.isNotEmpty(properties) + && properties.containsKey(HeatConstants.VMI_REFS_PROPERTY_NAME)) { + Map<String, Object> portReference = getPortReference(properties); + + return CollectionUtils.isNotEmpty(nestedHeatsFiles) + && nestedHeatsFiles.contains(translateTo.getHeatFileName()) + && portReference.containsKey(ResourceReferenceFunctions.GET_PARAM.getFunction()); + } + + return false; + } + + private Map<String, Object> getPortReference(Map<String, Object> properties) { + Object portReferenceObj = properties.get(HeatConstants.VMI_REFS_PROPERTY_NAME); + List<Object> portReference = + portReferenceObj instanceof List ? (List<Object>) portReferenceObj : new ArrayList<>(); + return CollectionUtils.isEmpty(portReference) ? new HashMap<>() + : (Map<String, Object>) portReference.get(0); + } + private Optional<Object> getVlanTagPropertyValue(Resource resource) { Object vmiProperties = resource.getProperties() .get(HeatConstants.VMI_PROPERTIES_PROPERTY_NAME); diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/functiontranslation/FunctionTranslationGetAttrImpl.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/functiontranslation/FunctionTranslationGetAttrImpl.java index 1d35795e4c..686a9c89a9 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/functiontranslation/FunctionTranslationGetAttrImpl.java +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/functiontranslation/FunctionTranslationGetAttrImpl.java @@ -1,9 +1,6 @@ -/*- - * ============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 @@ -15,11 +12,12 @@ * 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.functiontranslation; +import static org.openecomp.sdc.translator.services.heattotosca.ConfigConstants.TRANS_MAPPING_DELIMITER_CHAR; + import org.apache.commons.lang3.StringUtils; import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate; import org.openecomp.sdc.heat.datatypes.model.Resource; @@ -30,8 +28,9 @@ import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate; import org.openecomp.sdc.tosca.datatypes.model.Template; import org.openecomp.sdc.tosca.services.YamlUtil; import org.openecomp.sdc.translator.datatypes.heattotosca.TranslationContext; +import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo; import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.EntityConsolidationData; -import org.openecomp.sdc.translator.services.heattotosca.ConfigConstants; +import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.SubInterfaceTemplateConsolidationData; import org.openecomp.sdc.translator.services.heattotosca.ConsolidationDataUtil; import org.openecomp.sdc.translator.services.heattotosca.Constants; import org.openecomp.sdc.translator.services.heattotosca.FunctionTranslation; @@ -243,10 +242,16 @@ public class FunctionTranslationGetAttrImpl implements FunctionTranslation { String attName) { Resource resource = heatOrchestrationTemplate.getResources().get(resourceId); boolean isNestedResource = HeatToToscaUtil.isNestedResource(resource); + String heatPropertyName = propertyName; String toscaPropertyName = propertyName; + //For handling get_attr in inner levels for complex properties + if (propertyName.contains(TRANS_MAPPING_DELIMITER_CHAR)) { + heatPropertyName = propertyName.substring(0, + propertyName.indexOf(TRANS_MAPPING_DELIMITER_CHAR)); + } if (!isNestedResource) { toscaPropertyName = HeatToToscaUtil.getToscaPropertyName(context, resource - .getType(), propertyName); + .getType(), heatPropertyName); } ConsolidationDataUtil .updateNodeGetAttributeIn(entityConsolidationData, @@ -271,13 +276,22 @@ public class FunctionTranslationGetAttrImpl implements FunctionTranslation { return Optional.of( ConsolidationDataUtil.getComputeTemplateConsolidationData(context, serviceTemplate, - computeType, resourceId)); + computeType, resourceTranslatedId)); } else if (ConsolidationDataUtil.isPortResource(heatOrchestrationTemplate, resourceId)) { return Optional.of(ConsolidationDataUtil - .getPortTemplateConsolidationData(context, serviceTemplate, resourceId)); + .getPortTemplateConsolidationData(context, serviceTemplate, resourceId, resource.getType(), + resourceTranslatedId)); + } else if (HeatToToscaUtil.isSubInterfaceResource(resource, context)) { + TranslateTo subInterfaceTo = new TranslateTo(heatFileName, serviceTemplate, heatOrchestrationTemplate, + resource, resourceId, resourceTranslatedId, context); + Optional<SubInterfaceTemplateConsolidationData> subInterfaceTemplateConsolidationData = + ConsolidationDataUtil.getSubInterfaceTemplateConsolidationData(subInterfaceTo, resourceTranslatedId); + if (subInterfaceTemplateConsolidationData.isPresent()) { + return Optional.of(subInterfaceTemplateConsolidationData.get()); + } } else if (HeatToToscaUtil.isNestedResource(resource)) { return Optional.ofNullable(ConsolidationDataUtil - .getNestedTemplateConsolidationData(context, serviceTemplate, heatFileName, resourceId)); + .getNestedTemplateConsolidationData(context, serviceTemplate, heatFileName, resourceTranslatedId)); } return Optional.empty(); } @@ -330,7 +344,7 @@ public class FunctionTranslationGetAttrImpl implements FunctionTranslation { if (isInteger(attributeParamList.get(j))) { continue; } - attributeFullPath.append(ConfigConstants.TRANS_MAPPING_DELIMITER_CHAR); + attributeFullPath.append(TRANS_MAPPING_DELIMITER_CHAR); attributeFullPath.append(attributeParamList.get(j)); } return attributeFullPath.toString(); @@ -341,13 +355,7 @@ public class FunctionTranslationGetAttrImpl implements FunctionTranslation { return false; } - /*try { - Integer.parseInt(String.valueOf(inputNumber)); - return true; - } catch (NumberFormatException exception) { - return false; - }*/ - if(StringUtils.isNumeric(String.valueOf(inputNumber))){ + if (StringUtils.isNumeric(String.valueOf(inputNumber))){ return true; } else { return false; @@ -377,15 +385,7 @@ public class FunctionTranslationGetAttrImpl implements FunctionTranslation { return getResourceTranslatedAttributesList(resource, context); } - if(!(attributeParamList.get(1) instanceof String)){ - //todo - once dynamic attr name will be supported the commented line will be support it in - // the first translation phase. -// Object toscaAttributeValue = getToscaAttributeValue(serviceTemplate, resourceId, propertyName, -// attributeParamList.get(1), resource -// .getType(), heatFileName, heatOrchestrationTemplate, null, context); -// List<Object> dynamicAttrValue = new ArrayList<>(); -// dynamicAttrValue.add(toscaAttributeValue); -// return Optional.of(dynamicAttrValue); + if (!(attributeParamList.get(1) instanceof String)) { 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/ResourceTranslationBase.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationBase.java index 8cccbb8894..6809ce39cf 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationBase.java +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationBase.java @@ -1,21 +1,17 @@ -/*- - * ============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; @@ -77,7 +73,7 @@ public abstract class ResourceTranslationBase { getResourceTranslatedId(heatFileName, heatOrchestrationTemplate, resourceId, context); context.getTranslatedResources().putIfAbsent(heatFileName, new HashSet<>()); - if(isResourceWithSameIdAppearsInOtherFiles(heatFileName, resourceId, context)){ + if (isResourceWithSameIdAppearsInOtherFiles(heatFileName, resourceId, context)) { throw new CoreException( new DuplicateResourceIdsInDifferentFilesErrorBuilder(resourceId).build()); } @@ -106,7 +102,7 @@ public abstract class ResourceTranslationBase { private boolean isResourceWithSameIdAppearsInOtherFiles(String heatFileName, String resourceId, - TranslationContext context){ + TranslationContext context) { Set<String> translatedResourceIdsFromOtherFiles = context.getTranslatedResourceIdsFromOtherFiles(heatFileName); @@ -281,7 +277,7 @@ public abstract class ResourceTranslationBase { .getResource(heatOrchestrationTemplate, dependsOnResourceId, translateTo.getHeatFileName()); if (HeatToToscaUtil - .isValidDependsOnCandidate(heatOrchestrationTemplate, sourceResource, targetResource, + .isValidDependsOnCandidate(sourceResource, targetResource, ConsolidationEntityType.OTHER, translateTo.getContext())) { requirementAssignment.setNode(resourceTranslatedId.get()); requirementAssignment.setCapability(ToscaCapabilityType.NATIVE_NODE); diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationContrailV2VmInterfaceImpl.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationContrailV2VmInterfaceImpl.java index 7d96bd0b40..310cb2b4e3 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationContrailV2VmInterfaceImpl.java +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationContrailV2VmInterfaceImpl.java @@ -1,5 +1,5 @@ /* - * Copyright © 2016-2017 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. @@ -18,6 +18,8 @@ package org.openecomp.sdc.translator.services.heattotosca.impl.resourcetranslati import org.openecomp.sdc.common.togglz.ToggleableFeature; import org.openecomp.sdc.heat.services.HeatConstants; +import org.openecomp.sdc.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; import org.openecomp.sdc.tosca.datatypes.ToscaNodeType; import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate; import org.openecomp.sdc.tosca.services.DataModelUtil; @@ -31,21 +33,24 @@ import java.util.Map; public class ResourceTranslationContrailV2VmInterfaceImpl extends ResourceTranslationBase { + protected static final Logger LOGGER = LoggerFactory.getLogger(ResourceTranslationContrailV2VmInterfaceImpl.class); + final ContrailV2VirtualMachineInterfaceHelper contrailV2VirtualMachineInterfaceHelper = + new ContrailV2VirtualMachineInterfaceHelper(); @Override - protected String generateTranslatedId(TranslateTo translateTo) { - if (!(new ContrailV2VirtualMachineInterfaceHelper().isVlanSubInterfaceResource(translateTo - .getResource())) || ToggleableFeature.VLAN_TAGGING.isActive()) { - return super.generateTranslatedId(translateTo); + protected boolean isEssentialRequirementsValid(TranslateTo translateTo) { + if(contrailV2VirtualMachineInterfaceHelper + .isVlanSubInterfaceResource(translateTo.getResource())) { + return ToggleableFeature.VLAN_TAGGING.isActive() && contrailV2VirtualMachineInterfaceHelper + .isVlanSubInterfaceConnectedToPortIndirectly(translateTo); } - - return null; + return true; } @Override protected void translate(TranslateTo translateTo) { - if (new ContrailV2VirtualMachineInterfaceHelper().isVlanSubInterfaceResource(translateTo - .getResource())) { + if (contrailV2VirtualMachineInterfaceHelper + .isVlanSubInterfaceResource(translateTo.getResource())) { translateVlanSubInterfaceResource(translateTo); } else { translateVirtualMachineInterfaceResource(translateTo); @@ -57,8 +62,8 @@ public class ResourceTranslationContrailV2VmInterfaceImpl extends ResourceTransl NodeTemplate nodeTemplate = new NodeTemplate(); nodeTemplate.setType(ToscaNodeType.CONTRAILV2_VIRTUAL_MACHINE_INTERFACE); nodeTemplate.setProperties(TranslatorHeatToToscaPropertyConverter - .getToscaPropertiesSimpleConversion(translateTo.getServiceTemplate(),translateTo. - getResourceId(),translateTo.getResource().getProperties(), + .getToscaPropertiesSimpleConversion(translateTo.getServiceTemplate(), translateTo. + getResourceId(), translateTo.getResource().getProperties(), nodeTemplate.getProperties(), translateTo.getHeatFileName(), translateTo.getHeatOrchestrationTemplate(), translateTo.getResource().getType(), nodeTemplate, translateTo.getContext())); @@ -70,7 +75,7 @@ public class ResourceTranslationContrailV2VmInterfaceImpl extends ResourceTransl handleVmiMacAddressesInProperties(translateTo, nodeTemplate); - new ContrailV2VirtualMachineInterfaceHelper() + contrailV2VirtualMachineInterfaceHelper .connectVmiToNetwork(this, translateTo, nodeTemplate); DataModelUtil.addNodeTemplate(translateTo.getServiceTemplate(), translateTo.getTranslatedId(), nodeTemplate); @@ -81,12 +86,13 @@ public class ResourceTranslationContrailV2VmInterfaceImpl extends ResourceTransl String toscaVmiMacAddressesName = HeatToToscaUtil.getToscaPropertyName(translateTo, HeatConstants.VMI_MAC_ADDRESSES); String toscaVmiMacAddressesMacAddressesName = - HeatToToscaUtil.getToscaPropertyName(translateTo, HeatConstants.VMI_MAC_ADDRESSES_MAC_ADDRESSES); + HeatToToscaUtil + .getToscaPropertyName(translateTo, HeatConstants.VMI_MAC_ADDRESSES_MAC_ADDRESSES); - if(nodeTemplate.getProperties().containsKey(toscaVmiMacAddressesName)){ + if (nodeTemplate.getProperties().containsKey(toscaVmiMacAddressesName)) { Object macAddressesValue = nodeTemplate.getProperties().get(toscaVmiMacAddressesName); - if(macAddressesValue instanceof Map && ((Map<String, Object>)macAddressesValue).containsKey - (toscaVmiMacAddressesMacAddressesName)){ + if (macAddressesValue instanceof Map && ((Map<String, Object>) macAddressesValue).containsKey + (toscaVmiMacAddressesMacAddressesName)) { updateMacAddressesMacAddressesInProperties(nodeTemplate, toscaVmiMacAddressesName, toscaVmiMacAddressesMacAddressesName, (Map<String, Object>) macAddressesValue); @@ -100,9 +106,9 @@ public class ResourceTranslationContrailV2VmInterfaceImpl extends ResourceTransl Map<String, Object> macAddressesValue) { Object macAddressesMacAddressesValue = macAddressesValue.get(toscaVmiMacAddressesMacAddressesName); - if(macAddressesMacAddressesValue instanceof List){ + if (macAddressesMacAddressesValue instanceof List) { nodeTemplate.getProperties().put(toscaVmiMacAddressesName, macAddressesMacAddressesValue); - }else{ + } else { nodeTemplate.getProperties().remove(toscaVmiMacAddressesName); } } diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationNestedImpl.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationNestedImpl.java index b85fb02795..a3b8009868 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationNestedImpl.java +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationNestedImpl.java @@ -1,47 +1,55 @@ -/*- - * ============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.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; import org.openecomp.core.utilities.file.FileUtils; import org.openecomp.sdc.heat.datatypes.manifest.FileData; +import org.openecomp.sdc.heat.datatypes.model.HeatResourcesTypes; +import org.openecomp.sdc.heat.datatypes.model.Resource; +import org.openecomp.sdc.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.model.NodeTemplate; import org.openecomp.sdc.tosca.datatypes.model.NodeType; +import org.openecomp.sdc.tosca.datatypes.model.RequirementAssignment; import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate; import org.openecomp.sdc.tosca.services.DataModelUtil; import org.openecomp.sdc.tosca.services.ToscaUtil; import org.openecomp.sdc.tosca.services.impl.ToscaAnalyzerServiceImpl; import org.openecomp.sdc.translator.datatypes.heattotosca.TranslationContext; import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo; +import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.SubInterfaceTemplateConsolidationData; import org.openecomp.sdc.translator.services.heattotosca.ConsolidationDataUtil; import org.openecomp.sdc.translator.services.heattotosca.Constants; import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil; import org.openecomp.sdc.translator.services.heattotosca.TranslationService; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; + public class ResourceTranslationNestedImpl extends ResourceTranslationBase { - protected static Logger logger = - (Logger) LoggerFactory.getLogger(ResourceTranslationNestedImpl.class); + private static final String SUB_INTERFACE_COUNT = "count"; + protected static Logger log = LoggerFactory.getLogger(ResourceTranslationNestedImpl.class); @Override public void translate(TranslateTo translateTo) { @@ -49,13 +57,13 @@ public class ResourceTranslationNestedImpl extends ResourceTranslationBase { FileData nestedFileData = HeatToToscaUtil.getFileData(translateTo.getResource().getType(), context); if (nestedFileData == null) { - logger.warn("Nested File '" + translateTo.getResource().getType() + log.warn("Nested File '" + translateTo.getResource().getType() + "' is not exist, therefore, the nested resource with the ID '" + translateTo.getResourceId() + "' will be ignored in TOSCA translation"); return; } String templateName = FileUtils.getFileWithoutExtention(translateTo.getResource().getType()); - String substitutionNodeTypeKey = ToscaNodeType.ABSTRACT_NODE_TYPE_PREFIX + "heat." + String substitutionNodeTypeKey = HeatToToscaUtil.getNestedResourceTypePrefix(translateTo) + templateName; if (!context.getTranslatedServiceTemplates() @@ -66,7 +74,7 @@ public class ResourceTranslationNestedImpl extends ResourceTranslationBase { createSubstitutionServiceTemplate(translateTo, nestedFileData, templateName); //global substitution service template - ServiceTemplate globalSubstitutionServiceTemplate = new HeatToToscaUtil() + ServiceTemplate globalSubstitutionServiceTemplate = HeatToToscaUtil .fetchGlobalSubstitutionServiceTemplate(translateTo.getServiceTemplate(), context); @@ -89,7 +97,7 @@ public class ResourceTranslationNestedImpl extends ResourceTranslationBase { ServiceTemplate substitutionServiceTemplate = context.getTranslatedServiceTemplates() .get(translateTo.getResource().getType()); - if(DataModelUtil.isNodeTemplateSectionMissingFromServiceTemplate(substitutionServiceTemplate)){ + if (DataModelUtil.isNodeTemplateSectionMissingFromServiceTemplate(substitutionServiceTemplate)) { handleSubstitutionServiceTemplateWithoutNodeTemplates( templateName, translateTo); return; @@ -104,6 +112,57 @@ public class ResourceTranslationNestedImpl extends ResourceTranslationBase { //Add nested node template id to consolidation data ConsolidationDataUtil.updateNestedNodeTemplateId(translateTo); + + //Gather consolidation data if the resource group represents a sub interface + if (StringUtils.isNotBlank(substitutionNodeTypeKey) + && substitutionNodeTypeKey.contains(ToscaNodeType + .VLAN_SUB_INTERFACE_RESOURCE_TYPE_PREFIX)) { + populateSubInterfaceTemplateConsolidationData(translateTo, substitutionNodeTemplate); + } + } + + private void populateSubInterfaceTemplateConsolidationData(TranslateTo translateTo, + NodeTemplate nodeTemplate) { + + Optional<SubInterfaceTemplateConsolidationData> subInterfaceTemplateConsolidationData = + ConsolidationDataUtil.getSubInterfaceTemplateConsolidationData(translateTo, translateTo + .getTranslatedId()); + if (!subInterfaceTemplateConsolidationData.isPresent()) { + return; + } + Optional<String> subInterfaceNetworkRole = + HeatToToscaUtil.getNetworkRoleFromResource(translateTo.getResource(), translateTo.getContext()); + subInterfaceNetworkRole.ifPresent(subInterfaceTemplateConsolidationData.get()::setNetworkRole); + Object count = getSubInterfaceCountFromResourceProperties(translateTo); + subInterfaceTemplateConsolidationData.get().setResourceGroupCount(count); + + if (CollectionUtils.isNotEmpty(nodeTemplate.getRequirements())) { + //Add connectivity to network in consolidation data based on resource group link requirements + nodeTemplate.getRequirements().forEach((Map<String, RequirementAssignment> requirementMap) -> + requirementMap.entrySet().stream() + .filter(requirementAssignmentEntry -> ToscaCapabilityType.NATIVE_NETWORK_LINKABLE + .equals(requirementAssignmentEntry.getValue().getCapability())) + .forEach(requirementAssignmentEntry -> subInterfaceTemplateConsolidationData.get() + .addNodesConnectedOut(requirementAssignmentEntry.getValue().getNode(), + requirementAssignmentEntry.getKey(), + requirementAssignmentEntry.getValue()) + ) + ); + } + } + + private Object getSubInterfaceCountFromResourceProperties(TranslateTo translateTo) { + if (Objects.nonNull(translateTo.getHeatOrchestrationTemplate().getResources().get(translateTo + .getResourceId()))) { + Resource resource = translateTo.getHeatOrchestrationTemplate().getResources().get(translateTo + .getResourceId()); + if(HeatResourcesTypes.RESOURCE_GROUP_RESOURCE_TYPE.getHeatResource().equals(resource.getType())) { + return resource.getProperties().get(SUB_INTERFACE_COUNT); + } else if (HeatToToscaUtil.isYamlFile(resource.getType())) { + return HeatConstants.DEFAULT_NESTED_HEAT_RESOURCE_COUNT; + } + } + return null; } private void handleSubstitutionServiceTemplateWithoutNodeTemplates(String templateName, 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 06ba26c97a..2eb1040795 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 @@ -1,21 +1,17 @@ -/*- - * ============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; @@ -415,8 +411,8 @@ public class ResourceTranslationNovaServerImpl extends ResourceTranslationBase { DataModelUtil.addBindingReqFromPortToCompute(novaServerResourceId, portNodeTemplate); // Add ports - ConsolidationDataUtil.updatePortInConsolidationData(translateTo, novaNodeTemplate.getType(), - translatedPortId.get()); + 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() 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 6afaf79cb9..68e3062a64 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 @@ -1,25 +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 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 org.openecomp.sdc.common.errors.CoreException; import org.openecomp.sdc.heat.datatypes.model.HeatResourcesTypes; import org.openecomp.sdc.heat.datatypes.model.Resource; @@ -28,6 +27,7 @@ import org.openecomp.sdc.tosca.datatypes.ToscaFunctions; import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate; import org.openecomp.sdc.tosca.services.DataModelUtil; import org.openecomp.sdc.tosca.services.ToscaConstants; +import org.openecomp.sdc.tosca.services.ToscaUtil; import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo; import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil; import org.openecomp.sdc.translator.services.heattotosca.ResourceTranslationFactory; @@ -49,7 +49,7 @@ public class ResourceTranslationResourceGroupImpl extends ResourceTranslationBas Object resourceDef = translateTo.getResource().getProperties().get(HeatConstants.RESOURCE_DEF_PROPERTY_NAME); Resource nestedResource = new Resource(); - Object typeDefinition = ((Map) resourceDef).get("type"); + 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() @@ -75,10 +75,12 @@ public class ResourceTranslationResourceGroupImpl extends ResourceTranslationBas .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)) { + DataModelUtil.getNodeTemplate(translateTo.getServiceTemplate(), + substitutionNodeTemplateId.get()); + if (!Objects.isNull(substitutionNodeTemplate)) { Map serviceTemplateFilter = (Map<String, Object>) substitutionNodeTemplate.getProperties() .get(ToscaConstants.SERVICE_TEMPLATE_FILTER_PROPERTY_NAME); @@ -93,8 +95,13 @@ public class ResourceTranslationResourceGroupImpl extends ResourceTranslationBas } private void handlingIndexVar(TranslateTo translateTo, NodeTemplate substitutionNodeTemplate) { + List<String> indexVarProperties = new ArrayList<>(); String indexVarValue = getIndexVarValue(translateTo); - replacePropertiesIndexVarValue(indexVarValue, substitutionNodeTemplate.getProperties()); + 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() { @@ -108,21 +115,29 @@ public class ResourceTranslationResourceGroupImpl extends ResourceTranslationBas } private void replacePropertiesIndexVarValue(String indexVarValue, - Map<String, Object> properties) { + Map<String, Object> properties, + List<String> indexVarProperties, + TranslateTo translateTo) { if (properties == null || properties.isEmpty()) { return; } for (Map.Entry<String, Object> propertyEntry : properties.entrySet()) { Object propertyValue = propertyEntry.getValue(); - Object newPropertyValue = getUpdatedPropertyValueWithIndex(indexVarValue, propertyValue); + 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 Object getUpdatedPropertyValueWithIndex(String indexVarValue, Object propertyValue) { + private Object getUpdatedPropertyValueWithIndex(String indexVarValue, Object propertyValue, + List<String> indexVarProperties, + TranslateTo translateTo) { if (propertyValue != null && propertyValue instanceof String) { if (propertyValue.equals(indexVarValue)) { return getNewIndexVarValue(); @@ -151,12 +166,14 @@ public class ResourceTranslationResourceGroupImpl extends ResourceTranslationBas } return propertyValue; //no update is needed } else if (propertyValue instanceof Map && !((Map) propertyValue).isEmpty()) { - replacePropertiesIndexVarValue(indexVarValue, (Map<String, Object>) propertyValue); + 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)); + for (Object entry : (List) propertyValue) { + newPropertyValueList.add(getUpdatedPropertyValueWithIndex(indexVarValue, entry, + indexVarProperties, translateTo)); } return newPropertyValueList; } @@ -183,7 +200,7 @@ public class ResourceTranslationResourceGroupImpl extends ResourceTranslationBas Map serviceTemplateFilter) { boolean mandatory = false; Object countValue = TranslatorHeatToToscaPropertyConverter - .getToscaPropertyValue(translateTo.getServiceTemplate(),translateTo.getResourceId(), + .getToscaPropertyValue(translateTo.getServiceTemplate(), translateTo.getResourceId(), ToscaConstants.COUNT_PROPERTY_NAME, translateTo.getResource().getProperties().get (ToscaConstants.COUNT_PROPERTY_NAME), null, translateTo.getHeatFileName(), translateTo.getHeatOrchestrationTemplate(), |