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;
24 import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate;
25 import org.openecomp.sdc.heat.datatypes.model.HeatResourcesTypes;
26 import org.openecomp.sdc.heat.datatypes.model.Resource;
27 import org.openecomp.sdc.tosca.datatypes.ToscaCapabilityType;
28 import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
29 import org.openecomp.sdc.tosca.datatypes.ToscaRelationshipType;
30 import org.openecomp.sdc.tosca.datatypes.model.CapabilityDefinition;
31 import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate;
32 import org.openecomp.sdc.tosca.datatypes.model.NodeType;
33 import org.openecomp.sdc.tosca.datatypes.model.RequirementDefinition;
34 import org.openecomp.sdc.tosca.services.ToscaConstants;
35 import org.openecomp.sdc.translator.datatypes.heattotosca.AttachedResourceId;
36 import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo;
37 import org.openecomp.sdc.translator.services.heattotosca.Constants;
38 import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil;
40 import java.util.ArrayList;
41 import java.util.Collections;
42 import java.util.List;
44 import java.util.Optional;
45 import java.util.function.Predicate;
48 class SecurityRulesToPortResourceConnection extends ResourceConnectionUsingCapabilityHelper {
49 SecurityRulesToPortResourceConnection(ResourceTranslationNestedImpl resourceTranslationNested,
50 TranslateTo translateTo, FileData nestedFileData,
51 NodeTemplate substitutionNodeTemplate, NodeType nodeType) {
52 super(resourceTranslationNested, translateTo, nestedFileData, substitutionNodeTemplate,
57 protected boolean isDesiredNodeTemplateType(NodeTemplate nodeTemplate) {
58 return nodeTemplate.getType().equals(ToscaNodeType.NEUTRON_PORT);
62 protected List<Predicate<CapabilityDefinition>> getPredicatesListForConnectionPoints() {
63 ArrayList<Predicate<CapabilityDefinition>> predicates = new ArrayList<>();
64 predicates.add(cap -> cap.getType().equals(ToscaCapabilityType.NATIVE_ATTACHMENT));
69 protected Optional<List<String>> getConnectorPropertyParamName(String heatResourceId,
70 Resource heatResource,
71 HeatOrchestrationTemplate
72 nestedHeatOrchestrationTemplate,
73 String nestedHeatFileName) {
76 mdcDataDebugMessage.debugEntryMessage(null, null);
78 Object securityGroups =
79 heatResource.getProperties().get(Constants.SECURITY_GROUPS_PROPERTY_NAME);
80 List<String> paramsList = new ArrayList<>();
81 if (securityGroups instanceof List) {
82 ((List) securityGroups).forEach(group -> {
83 Optional<AttachedResourceId> attachedResourceId = HeatToToscaUtil
84 .extractAttachedResourceId(nestedFileData.getFile(), nestedHeatOrchestrationTemplate,
85 translateTo.getContext(), group);
86 if (attachedResourceId.isPresent()
87 && attachedResourceId.get().isGetParam()
88 && attachedResourceId.get().getEntityId() instanceof String) {
89 paramsList.add((String) attachedResourceId.get().getEntityId());
93 mdcDataDebugMessage.debugExitMessage(null, null);
94 return Optional.of(paramsList);
97 mdcDataDebugMessage.debugExitMessage(null, null);
98 return Optional.empty();
102 protected String getDesiredResourceType() {
103 return HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource();
107 void addRequirementToConnectResources(
108 Map.Entry<String, CapabilityDefinition> connectionPointEntry, List<String> paramNames) {
111 mdcDataDebugMessage.debugEntryMessage(null, null);
113 if (paramNames == null || paramNames.isEmpty()) {
116 List<String> supportedSecurityRulesTypes = Collections
117 .singletonList(HeatResourcesTypes.NEUTRON_SECURITY_GROUP_RESOURCE_TYPE.getHeatResource());
119 for (String paramName : paramNames) {
120 addRequirementToConnectResource(connectionPointEntry, supportedSecurityRulesTypes, paramName);
123 mdcDataDebugMessage.debugExitMessage(null, null);
127 boolean validateResourceTypeSupportedForReqCreation(String nestedResourceId,
128 String nestedPropertyName,
129 String connectionPointId,
130 Resource connectedResource,
131 List<String> supportedTypes) {
134 mdcDataDebugMessage.debugEntryMessage(null, null);
136 if (!resourceTranslationBase.isResourceTypeSupported(connectedResource, supportedTypes)) {
137 logger.warn("Nested resource '" + nestedResourceId + "' property '" + nestedPropertyName
138 + "' is pointing to resource with type '" + connectedResource.getType()
139 + "' which is not supported for capability '" + connectionPointId
140 + "' connection, (security rules to port connection). Supported types are: '"
141 + supportedTypes.toString() + "', therefore, this TOSCA capability will not be "
144 mdcDataDebugMessage.debugExitMessage(null, null);
148 mdcDataDebugMessage.debugExitMessage(null, null);
153 Map.Entry<String, RequirementDefinition> createRequirementDefinition(String capabilityKey) {
156 mdcDataDebugMessage.debugEntryMessage(null, null);
158 RequirementDefinition definition = new RequirementDefinition();
159 definition.setCapability(capabilityKey);
160 definition.setRelationship(ToscaRelationshipType.ATTACHES_TO);
161 mdcDataDebugMessage.debugExitMessage(null, null);
162 return new Map.Entry<String, RequirementDefinition>() {
164 public String getKey() {
165 return ToscaConstants.PORT_REQUIREMENT_ID;
169 public RequirementDefinition getValue() {
174 public RequirementDefinition setValue(RequirementDefinition value) {