2 * Copyright © 2016-2018 European Support Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation;
19 import com.google.common.collect.ArrayListMultimap;
20 import com.google.common.collect.Multimap;
22 import java.util.ArrayList;
23 import java.util.Collection;
24 import java.util.HashMap;
25 import java.util.HashSet;
26 import java.util.List;
29 import java.util.stream.Collectors;
31 import org.apache.commons.collections4.CollectionUtils;
32 import org.apache.commons.collections4.MapUtils;
33 import org.onap.sdc.tosca.datatypes.model.RequirementAssignment;
36 * The type Entity consolidation data.
38 public class EntityConsolidationData {
40 private String nodeTemplateId;
42 //groups that point to this entity node template
43 private List<String> groupIds;
45 // key - node template id which has connection to this entity
46 // value - List of Requirement assignment data which connect to this entity
47 private Multimap<String, RequirementAssignmentData> nodesConnectedIn;
49 // key - node template id which connected from this entity
50 // List of Requirement assignment data which connect to the key node template id
51 private Multimap<String, RequirementAssignmentData> nodesConnectedOut;
53 //key - node template id which include get attribute function from this entity
54 //value - List of getAttr data
55 private Map<String, List<GetAttrFuncData>> nodesGetAttrIn;
57 //key - node template id which is pointed by this entity using get attribute function
58 //value - List of getAttr data
59 private Map<String, List<GetAttrFuncData>> nodesGetAttrOut;
61 //List of getAttr data
62 private List<GetAttrFuncData> outputParametersGetAttrIn;
64 public String getNodeTemplateId() {
65 return nodeTemplateId;
68 public void setNodeTemplateId(String nodeTemplateId) {
69 this.nodeTemplateId = nodeTemplateId;
73 * Gets group ids point to me.
75 * @return the group ids point to me
77 public List<String> getGroupIds() {
82 * Sets group ids point to me.
84 * @param groupIds the group ids point to me
86 public void setGroupIds(List<String> groupIds) {
87 this.groupIds = groupIds;
92 * Sets node connected to me.
94 * @param nodesConnectedIn the node connected to me
96 public void setNodesConnectedIn(Multimap<String, RequirementAssignmentData> nodesConnectedIn) {
97 this.nodesConnectedIn = nodesConnectedIn;
101 * Add node connected to me.
103 * @param nodeTemplateId the node template id which has connection to me
104 * @param requirementId the requirement id
105 * @param requirementAssignment the requirement assignment
107 public void addNodesConnectedIn(String nodeTemplateId, String requirementId,
108 RequirementAssignment requirementAssignment) {
110 if (this.nodesConnectedIn == null) {
111 this.nodesConnectedIn = ArrayListMultimap.create();
114 this.nodesConnectedIn.get(nodeTemplateId).add(
115 new RequirementAssignmentData(requirementId, requirementAssignment));
119 * Gets node connected to me.
121 * @return the node connected to me
123 public Multimap<String, RequirementAssignmentData> getNodesConnectedIn() {
124 return nodesConnectedIn;
129 * Gets node connected from me.
131 * @return the node connected from me
133 public Multimap<String, RequirementAssignmentData> getNodesConnectedOut() {
134 return nodesConnectedOut;
138 * Sets node connected from me.
140 * @param nodesConnectedOut the node connected from me
142 public void setNodesConnectedOut(Multimap<String, RequirementAssignmentData> nodesConnectedOut) {
143 this.nodesConnectedOut = nodesConnectedOut;
147 * Add nodeConnectedOut.
149 * @param nodeTemplateId the node template id which is connected from me
150 * @param requirementId the requirement id
151 * @param requirementAssignment the requirement assignment
153 public void addNodesConnectedOut(String nodeTemplateId, String requirementId,
154 RequirementAssignment requirementAssignment) {
156 if (this.nodesConnectedOut == null) {
157 this.nodesConnectedOut = ArrayListMultimap.create();
160 this.nodesConnectedOut.get(nodeTemplateId).add(
161 new RequirementAssignmentData(requirementId, requirementAssignment));
165 * Gets nodes get attr in.
167 * @return the get attr in
169 public Map<String, List<GetAttrFuncData>> getNodesGetAttrIn() {
170 return nodesGetAttrIn;
174 * Sets nodes get attr in.
176 * @param nodesGetAttrIn the get attr in
178 public void setNodesGetAttrIn(Map<String, List<GetAttrFuncData>> nodesGetAttrIn) {
179 this.nodesGetAttrIn = nodesGetAttrIn;
183 * Add nodes get attr in data.
185 * @param nodeTemplateId the node template id
186 * @param getAttrFuncData get attr data
188 public void addNodesGetAttrIn(String nodeTemplateId, GetAttrFuncData getAttrFuncData) {
190 if (nodesGetAttrIn == null) {
191 nodesGetAttrIn = new HashMap<>();
194 this.nodesGetAttrIn.putIfAbsent(nodeTemplateId, new ArrayList<>());
195 this.nodesGetAttrIn.get(nodeTemplateId).add(getAttrFuncData);
199 * Gets output parameters get attr from me.
201 * @return the get attr from me
203 public List<GetAttrFuncData> getOutputParametersGetAttrIn() {
204 return outputParametersGetAttrIn;
208 * Sets output parameters get attr from me.
210 * @param outputParametersGetAttrIn the output parameters get attr from me
212 public void setOutputParametersGetAttrIn(List<GetAttrFuncData> outputParametersGetAttrIn) {
213 this.outputParametersGetAttrIn = outputParametersGetAttrIn;
217 * Add output parameters get attr data.
219 * @param getAttrFuncData get attr data
221 public void addOutputParamGetAttrIn(GetAttrFuncData getAttrFuncData) {
223 if (outputParametersGetAttrIn == null) {
224 outputParametersGetAttrIn = new ArrayList<>();
227 this.outputParametersGetAttrIn.add(getAttrFuncData);
231 * Gets nodes get attr out.
233 * @return the get attr out
235 public Map<String, List<GetAttrFuncData>> getNodesGetAttrOut() {
236 return nodesGetAttrOut;
240 * Sets nodes get attr out.
242 * @param nodesGetAttrOut the get attr out
244 public void setNodesGetAttrOut(Map<String, List<GetAttrFuncData>> nodesGetAttrOut) {
245 this.nodesGetAttrOut = nodesGetAttrOut;
249 * Add nodes get attr out data.
251 * @param nodeTemplateId the node template id
252 * @param getAttrFuncData get attr data
254 public void addNodesGetAttrOut(String nodeTemplateId, GetAttrFuncData getAttrFuncData) {
256 if (nodesGetAttrOut == null) {
257 nodesGetAttrOut = new HashMap<>();
260 this.nodesGetAttrOut.putIfAbsent(nodeTemplateId, new ArrayList<>());
261 this.nodesGetAttrOut.get(nodeTemplateId).add(getAttrFuncData);
264 public void removeParamNameFromAttrFuncList(String paramName) {
266 if (outputParametersGetAttrIn == null) {
270 outputParametersGetAttrIn.removeIf(outputParameters -> paramName.equals(outputParameters.getFieldName()));
274 * Per port type compare get attr of entity with given consolidation data list.
276 * @param entityConsolidationDataList consolidation data list
277 * @param portTypeToIds the port type to ids
278 * @return true in case get attr list same for all port types.
279 * otherwise return false
281 public boolean isGetAttrOutFromEntityLegal(Collection<? extends EntityConsolidationData>
282 entityConsolidationDataList, Map<String, List<String>> portTypeToIds) {
283 if (CollectionUtils.isEmpty(entityConsolidationDataList)
284 || MapUtils.isEmpty(portTypeToIds)) {
288 for (String portType : portTypeToIds.keySet()) {
289 Set<GetAttrFuncData> startingGetAttrFunc =
290 getEntityGetAttrFuncAsSet(portType, portTypeToIds);
292 for (EntityConsolidationData entity : entityConsolidationDataList) {
293 Set<GetAttrFuncData> currentGetAttrFuncData =
294 entity.getEntityGetAttrFuncAsSet(portType, portTypeToIds);
295 if (!(startingGetAttrFunc.equals(currentGetAttrFuncData))) {
303 private Set<GetAttrFuncData> getEntityGetAttrFuncAsSet(String portType, Map<String, List<String>> portTypeToIds) {
304 if (MapUtils.isEmpty(nodesGetAttrOut)) {
305 return new HashSet<>();
308 return nodesGetAttrOut.entrySet().stream()
309 .filter(entry -> portType.equals(getPortTypeFromNodeTemplateId(entry.getKey(),
311 .flatMap(entry -> entry.getValue().stream())
312 .collect(Collectors.toSet());
315 private String getPortTypeFromNodeTemplateId(String portNodeTemplateId, Map<String, List<String>> portTypeToIds) {
316 for (Map.Entry<String, List<String>> portTypeToIdEntry : portTypeToIds.entrySet()) {
317 if (portTypeToIdEntry.getValue().contains(portNodeTemplateId)) {
318 return portTypeToIdEntry.getKey();
325 * Add group id information to consolidation data.
327 * @param groupId Group id of which compute node is a part
330 void addGroupId(String groupId) {
331 if (groupIds == null) {
332 groupIds = new ArrayList<>();
334 groupIds.add(groupId);