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) {
77 Object securityGroups =
78 heatResource.getProperties().get(Constants.SECURITY_GROUPS_PROPERTY_NAME);
79 List<String> paramsList = new ArrayList<>();
80 if (securityGroups instanceof List) {
81 ((List) securityGroups).forEach(group -> {
82 Optional<AttachedResourceId> attachedResourceId = HeatToToscaUtil
83 .extractAttachedResourceId(nestedFileData.getFile(), nestedHeatOrchestrationTemplate,
84 translateTo.getContext(), group);
85 if (attachedResourceId.isPresent()
86 && attachedResourceId.get().isGetParam()
87 && attachedResourceId.get().getEntityId() instanceof String) {
88 paramsList.add((String) attachedResourceId.get().getEntityId());
92 return Optional.of(paramsList);
95 return Optional.empty();
99 protected String getDesiredResourceType() {
100 return HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource();
104 void addRequirementToConnectResources(
105 Map.Entry<String, CapabilityDefinition> connectionPointEntry, List<String> paramNames) {
109 if (paramNames == null || paramNames.isEmpty()) {
112 List<String> supportedSecurityRulesTypes = Collections
113 .singletonList(HeatResourcesTypes.NEUTRON_SECURITY_GROUP_RESOURCE_TYPE.getHeatResource());
115 for (String paramName : paramNames) {
116 addRequirementToConnectResource(connectionPointEntry, supportedSecurityRulesTypes, paramName);
122 boolean validateResourceTypeSupportedForReqCreation(String nestedResourceId,
123 String nestedPropertyName,
124 String connectionPointId,
125 Resource connectedResource,
126 List<String> supportedTypes) {
130 if (!resourceTranslationBase.isResourceTypeSupported(connectedResource, supportedTypes)) {
131 logger.warn("Nested resource '" + nestedResourceId + "' property '" + nestedPropertyName
132 + "' is pointing to resource with type '" + connectedResource.getType()
133 + "' which is not supported for capability '" + connectionPointId
134 + "' connection, (security rules to port connection). Supported types are: '"
135 + supportedTypes.toString() + "', therefore, this TOSCA capability will not be "
145 Map.Entry<String, RequirementDefinition> createRequirementDefinition(String capabilityKey) {
149 RequirementDefinition definition = new RequirementDefinition();
150 definition.setCapability(capabilityKey);
151 definition.setRelationship(ToscaRelationshipType.ATTACHES_TO);
152 return new Map.Entry<String, RequirementDefinition>() {
154 public String getKey() {
155 return ToscaConstants.PORT_REQUIREMENT_ID;
159 public RequirementDefinition getValue() {
164 public RequirementDefinition setValue(RequirementDefinition value) {