2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.translator.services.heattotosca.impl.resourcetranslation;
23 import org.openecomp.sdc.heat.datatypes.model.HeatResourcesTypes;
24 import org.openecomp.sdc.heat.datatypes.model.Resource;
25 import org.openecomp.sdc.heat.services.HeatConstants;
26 import org.openecomp.sdc.logging.api.Logger;
27 import org.openecomp.sdc.logging.api.LoggerFactory;
28 import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
29 import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate;
30 import org.openecomp.sdc.tosca.services.DataModelUtil;
31 import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo;
32 import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil;
33 import org.openecomp.sdc.translator.services.heattotosca.helper.ContrailV2VirtualMachineInterfaceHelper;
34 import org.openecomp.sdc.translator.services.heattotosca.mapping.TranslatorHeatToToscaPropertyConverter;
36 import java.util.Arrays;
37 import java.util.List;
38 import java.util.Objects;
39 import java.util.Optional;
42 public class ResourceTranslationContrailV2VlanSubInterfaceImpl extends ResourceTranslationBase {
43 protected static Logger logger =
44 (Logger) LoggerFactory.getLogger(ResourceTranslationContrailV2VlanSubInterfaceImpl.class);
47 protected void translate(TranslateTo translateTo) {
50 mdcDataDebugMessage.debugEntryMessage(null, null);
52 NodeTemplate nodeTemplate = new NodeTemplate();
53 nodeTemplate.setType(ToscaNodeType.CONTRAILV2_VLAN_SUB_INTERFACE);
55 nodeTemplate.setProperties(TranslatorHeatToToscaPropertyConverter
56 .getToscaPropertiesSimpleConversion(translateTo.getServiceTemplate(),translateTo.
57 getResourceId(),translateTo.getResource().getProperties(),
58 nodeTemplate.getProperties(), translateTo.getHeatFileName(),
59 translateTo.getHeatOrchestrationTemplate(), translateTo.getResource().getType(),
60 nodeTemplate, translateTo.getContext()));
62 new ContrailV2VirtualMachineInterfaceHelper()
63 .connectVmiToNetwork(this, translateTo, nodeTemplate);
64 connectSubInterfaceToInterface(translateTo, nodeTemplate);
65 DataModelUtil.addNodeTemplate(translateTo.getServiceTemplate(), translateTo.getTranslatedId(),
68 mdcDataDebugMessage.debugExitMessage(null, null);
71 //connection to shared interface is not supported
72 private void connectSubInterfaceToInterface(TranslateTo translateTo,
73 NodeTemplate vlanSubInterfaceNodeTemplate) {
76 mdcDataDebugMessage.debugEntryMessage(null, null);
78 Object interfaceRefs =
79 translateTo.getResource().getProperties().get(HeatConstants.VMI_REFS_PROPERTY_NAME);
80 if (Objects.isNull(interfaceRefs) || !(interfaceRefs instanceof List)
81 || ((List) interfaceRefs).size() == 0) {
84 List<String> acceptableResourceTypes = Arrays
85 .asList(HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE
87 HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource());
88 if (((List) interfaceRefs).size() > 1) {
89 logger.warn("Heat resource: '" + translateTo.getResourceId() + "' with type: '"
90 + translateTo.getResource().getType()
91 + "' include '" + HeatConstants.VMI_REFS_PROPERTY_NAME
92 + "' property with more than one interface values, only "
93 + "the first interface will be connected, "
94 + "all rest will be ignored in TOSCA translation.");
96 Object interfaceRef = ((List) interfaceRefs).get(0);
98 Optional<String> interfaceResourceId =
99 HeatToToscaUtil.extractContrailGetResourceAttachedHeatResourceId(interfaceRef);
100 if (interfaceResourceId.isPresent()) { // get_resource
101 Resource interfaceResource = HeatToToscaUtil
102 .getResource(translateTo.getHeatOrchestrationTemplate(), interfaceResourceId.get(),
103 translateTo.getHeatFileName());
105 if (acceptableResourceTypes.contains(interfaceResource.getType())
106 && !(new ContrailV2VirtualMachineInterfaceHelper()
107 .isVlanSubInterfaceResource(interfaceResource))) {
108 Optional<String> interfaceResourceTranslatedId =
109 getResourceTranslatedId(translateTo.getHeatFileName(),
110 translateTo.getHeatOrchestrationTemplate(), interfaceResourceId.get(),
111 translateTo.getContext());
112 interfaceResourceTranslatedId.ifPresent(interfaceResourceTranslatedIdVal -> HeatToToscaUtil
113 .addBindingReqFromSubInterfaceToInterface(vlanSubInterfaceNodeTemplate,
114 interfaceResourceTranslatedIdVal));
116 logger.warn("Heat resource: '" + translateTo.getResourceId() + "' with type: '"
117 + translateTo.getResource().getType()
118 + "' include '" + HeatConstants.VMI_REFS_PROPERTY_NAME
119 + "' property which is connect to unsupported/incorrect "
120 + (true == (new ContrailV2VirtualMachineInterfaceHelper()
121 .isVlanSubInterfaceResource(interfaceResource)) ? "Vlan Sub interface " : "")
122 + "resource '" + interfaceResourceId.get() + "' with type '"
123 + interfaceResource.getType()
124 + "', therefore, this connection will be ignored in TOSCA translation.");
128 mdcDataDebugMessage.debugExitMessage(null, null);