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.manifest.FileData;
25 import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate;
26 import org.openecomp.sdc.heat.datatypes.model.HeatResourcesTypes;
27 import org.openecomp.sdc.heat.datatypes.model.Resource;
28 import org.openecomp.sdc.tosca.datatypes.ToscaCapabilityType;
29 import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
30 import org.openecomp.sdc.tosca.datatypes.ToscaRelationshipType;
31 import org.openecomp.sdc.tosca.datatypes.model.CapabilityDefinition;
32 import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate;
33 import org.openecomp.sdc.tosca.datatypes.model.NodeType;
34 import org.openecomp.sdc.tosca.datatypes.model.RequirementDefinition;
35 import org.openecomp.sdc.tosca.services.ToscaConstants;
36 import org.openecomp.sdc.translator.datatypes.heattotosca.AttachedResourceId;
37 import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo;
38 import org.openecomp.sdc.translator.services.heattotosca.Constants;
39 import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil;
41 import java.util.ArrayList;
42 import java.util.Collections;
43 import java.util.List;
45 import java.util.Optional;
46 import java.util.function.Predicate;
49 class SecurityRulesToPortResourceConnection extends ResourceConnectionUsingCapabilityHelper {
50 SecurityRulesToPortResourceConnection(ResourceTranslationNestedImpl resourceTranslationNested,
51 TranslateTo translateTo, FileData nestedFileData,
52 NodeTemplate substitutionNodeTemplate, NodeType nodeType) {
53 super(resourceTranslationNested, translateTo, nestedFileData, substitutionNodeTemplate,
58 protected boolean isDesiredNodeTemplateType(NodeTemplate nodeTemplate) {
59 return nodeTemplate.getType().equals(ToscaNodeType.NEUTRON_PORT);
63 protected List<Predicate<CapabilityDefinition>> getPredicatesListForConnectionPoints() {
64 ArrayList<Predicate<CapabilityDefinition>> predicates = new ArrayList<>();
65 predicates.add(cap -> cap.getType().equals(ToscaCapabilityType.NATIVE_ATTACHMENT));
70 protected Optional<List<String>> getConnectorPropertyParamName(String heatResourceId,
71 Resource heatResource,
72 HeatOrchestrationTemplate
73 nestedHeatOrchestrationTemplate,
74 String nestedHeatFileName) {
77 mdcDataDebugMessage.debugEntryMessage(null, null);
79 Object securityGroups =
80 heatResource.getProperties().get(Constants.SECURITY_GROUPS_PROPERTY_NAME);
81 List<String> paramsList = new ArrayList<>();
82 if (securityGroups instanceof List) {
83 ((List) securityGroups).forEach(group -> {
84 Optional<AttachedResourceId> attachedResourceId = HeatToToscaUtil
85 .extractAttachedResourceId(nestedFileData.getFile(), nestedHeatOrchestrationTemplate,
86 translateTo.getContext(), group);
87 if (attachedResourceId.isPresent()
88 && attachedResourceId.get().isGetParam()
89 && attachedResourceId.get().getEntityId() instanceof String) {
90 paramsList.add((String) attachedResourceId.get().getEntityId());
94 mdcDataDebugMessage.debugExitMessage(null, null);
95 return Optional.of(paramsList);
98 mdcDataDebugMessage.debugExitMessage(null, null);
99 return Optional.empty();
103 protected String getDesiredResourceType() {
104 return HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource();
108 void addRequirementToConnectResources(
109 Map.Entry<String, CapabilityDefinition> connectionPointEntry, List<String> paramNames) {
112 mdcDataDebugMessage.debugEntryMessage(null, null);
114 if (paramNames == null || paramNames.isEmpty()) {
117 List<String> supportedSecurityRulesTypes = Collections
118 .singletonList(HeatResourcesTypes.NEUTRON_SECURITY_GROUP_RESOURCE_TYPE.getHeatResource());
120 for (String paramName : paramNames) {
121 addRequirementToConnectResource(connectionPointEntry, supportedSecurityRulesTypes, paramName);
124 mdcDataDebugMessage.debugExitMessage(null, null);
128 boolean validateResourceTypeSupportedForReqCreation(String nestedResourceId,
129 String nestedPropertyName,
130 String connectionPointId,
131 Resource connectedResource,
132 List<String> supportedTypes) {
135 mdcDataDebugMessage.debugEntryMessage(null, null);
137 if (!resourceTranslationBase.isResourceTypeSupported(connectedResource, supportedTypes)) {
138 logger.warn("Nested resource '" + nestedResourceId + "' property '" + nestedPropertyName
139 + "' is pointing to resource with type '" + connectedResource.getType()
140 + "' which is not supported for capability '" + connectionPointId
141 + "' connection, (security rules to port connection). Supported types are: '"
142 + supportedTypes.toString() + "', therefore, this TOSCA capability will not be "
145 mdcDataDebugMessage.debugExitMessage(null, null);
149 mdcDataDebugMessage.debugExitMessage(null, null);
154 Map.Entry<String, RequirementDefinition> createRequirementDefinition(String capabilityKey) {
157 mdcDataDebugMessage.debugEntryMessage(null, null);
159 RequirementDefinition definition = new RequirementDefinition();
160 definition.setCapability(capabilityKey);
161 definition.setRelationship(ToscaRelationshipType.ATTACHES_TO);
162 mdcDataDebugMessage.debugExitMessage(null, null);
163 return new Map.Entry<String, RequirementDefinition>() {
165 public String getKey() {
166 return ToscaConstants.PORT_REQUIREMENT_ID;
170 public RequirementDefinition getValue() {
175 public RequirementDefinition setValue(RequirementDefinition value) {