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;
34 import org.openecomp.sdc.translator.services.heattotosca.ConsolidationDataUtil;
37 * The type Entity consolidation data.
39 public class EntityConsolidationData {
41 private String nodeTemplateId;
43 //groups that point to this entity node template
44 private List<String> groupIds;
46 // key - node template id which has connection to this entity
47 // value - List of Requirement assignment data which connect to this entity
48 private Multimap<String, RequirementAssignmentData> nodesConnectedIn;
50 // key - node template id which connected from this entity
51 // List of Requirement assignment data which connect to the key node template id
52 private Multimap<String, RequirementAssignmentData> nodesConnectedOut;
54 //key - node template id which include get attribute function from this entity
55 //value - List of getAttr data
56 private Map<String, List<GetAttrFuncData>> nodesGetAttrIn;
58 //key - node template id which is pointed by this entity using get attribute function
59 //value - List of getAttr data
60 private Map<String, List<GetAttrFuncData>> nodesGetAttrOut;
62 //List of getAttr data
63 private List<GetAttrFuncData> outputParametersGetAttrIn;
65 public String getNodeTemplateId() {
66 return nodeTemplateId;
69 public void setNodeTemplateId(String nodeTemplateId) {
70 this.nodeTemplateId = nodeTemplateId;
74 * Gets group ids point to me.
76 * @return the group ids point to me
78 public List<String> getGroupIds() {
83 * Sets group ids point to me.
85 * @param groupIds the group ids point to me
87 public void setGroupIds(List<String> groupIds) {
88 this.groupIds = groupIds;
93 * Sets node connected to me.
95 * @param nodesConnectedIn the node connected to me
97 public void setNodesConnectedIn(Multimap<String, RequirementAssignmentData> nodesConnectedIn) {
98 this.nodesConnectedIn = nodesConnectedIn;
102 * Add node connected to me.
104 * @param nodeTemplateId the node template id which has connection to me
105 * @param requirementId the requirement id
106 * @param requirementAssignment the requirement assignment
108 public void addNodesConnectedIn(String nodeTemplateId, String requirementId,
109 RequirementAssignment requirementAssignment) {
111 if (this.nodesConnectedIn == null) {
112 this.nodesConnectedIn = ArrayListMultimap.create();
115 this.nodesConnectedIn.get(nodeTemplateId).add(
116 new RequirementAssignmentData(requirementId, requirementAssignment));
120 * Gets node connected to me.
122 * @return the node connected to me
124 public Multimap<String, RequirementAssignmentData> getNodesConnectedIn() {
125 return nodesConnectedIn;
130 * Gets node connected from me.
132 * @return the node connected from me
134 public Multimap<String, RequirementAssignmentData> getNodesConnectedOut() {
135 return nodesConnectedOut;
139 * Sets node connected from me.
141 * @param nodesConnectedOut the node connected from me
143 public void setNodesConnectedOut(Multimap<String, RequirementAssignmentData> nodesConnectedOut) {
144 this.nodesConnectedOut = nodesConnectedOut;
148 * Add nodeConnectedOut.
150 * @param nodeTemplateId the node template id which is connected from me
151 * @param requirementId the requirement id
152 * @param requirementAssignment the requirement assignment
154 public void addNodesConnectedOut(String nodeTemplateId, String requirementId,
155 RequirementAssignment requirementAssignment) {
157 if (this.nodesConnectedOut == null) {
158 this.nodesConnectedOut = ArrayListMultimap.create();
161 this.nodesConnectedOut.get(nodeTemplateId).add(
162 new RequirementAssignmentData(requirementId, requirementAssignment));
166 * Gets nodes get attr in.
168 * @return the get attr in
170 public Map<String, List<GetAttrFuncData>> getNodesGetAttrIn() {
171 return nodesGetAttrIn;
175 * Sets nodes get attr in.
177 * @param nodesGetAttrIn the get attr in
179 public void setNodesGetAttrIn(Map<String, List<GetAttrFuncData>> nodesGetAttrIn) {
180 this.nodesGetAttrIn = nodesGetAttrIn;
184 * Add nodes get attr in data.
186 * @param nodeTemplateId the node template id
187 * @param getAttrFuncData get attr data
189 public void addNodesGetAttrIn(String nodeTemplateId, GetAttrFuncData getAttrFuncData) {
191 if (nodesGetAttrIn == null) {
192 nodesGetAttrIn = new HashMap<>();
195 this.nodesGetAttrIn.putIfAbsent(nodeTemplateId, new ArrayList<>());
196 this.nodesGetAttrIn.get(nodeTemplateId).add(getAttrFuncData);
200 * Gets output parameters get attr from me.
202 * @return the get attr from me
204 public List<GetAttrFuncData> getOutputParametersGetAttrIn() {
205 return outputParametersGetAttrIn;
209 * Sets output parameters get attr from me.
211 * @param outputParametersGetAttrIn the output parameters get attr from me
213 public void setOutputParametersGetAttrIn(List<GetAttrFuncData> outputParametersGetAttrIn) {
214 this.outputParametersGetAttrIn = outputParametersGetAttrIn;
218 * Add output parameters get attr data.
220 * @param getAttrFuncData get attr data
222 public void addOutputParamGetAttrIn(GetAttrFuncData getAttrFuncData) {
224 if (outputParametersGetAttrIn == null) {
225 outputParametersGetAttrIn = new ArrayList<>();
228 this.outputParametersGetAttrIn.add(getAttrFuncData);
232 * Gets nodes get attr out.
234 * @return the get attr out
236 public Map<String, List<GetAttrFuncData>> getNodesGetAttrOut() {
237 return nodesGetAttrOut;
241 * Sets nodes get attr out.
243 * @param nodesGetAttrOut the get attr out
245 public void setNodesGetAttrOut(Map<String, List<GetAttrFuncData>> nodesGetAttrOut) {
246 this.nodesGetAttrOut = nodesGetAttrOut;
250 * Add nodes get attr out data.
252 * @param nodeTemplateId the node template id
253 * @param getAttrFuncData get attr data
255 public void addNodesGetAttrOut(String nodeTemplateId, GetAttrFuncData getAttrFuncData) {
257 if (nodesGetAttrOut == null) {
258 nodesGetAttrOut = new HashMap<>();
261 this.nodesGetAttrOut.putIfAbsent(nodeTemplateId, new ArrayList<>());
262 this.nodesGetAttrOut.get(nodeTemplateId).add(getAttrFuncData);
265 public void removeParamNameFromAttrFuncList(String paramName) {
267 if (outputParametersGetAttrIn == null) {
271 outputParametersGetAttrIn.removeIf(outputParameters -> paramName.equals(outputParameters.getFieldName()));
275 * Per port type compare get attr of entity with given consolidation data list.
277 * @param entityConsolidationDataList consolidation data list
278 * @param portTypeToIds the port type to ids
279 * @return true in case get attr list same for all port types.
280 * otherwise return false
282 public boolean isGetAttrOutFromEntityLegal(Collection<? extends EntityConsolidationData>
283 entityConsolidationDataList, Map<String, List<String>> portTypeToIds) {
284 if (CollectionUtils.isEmpty(entityConsolidationDataList)
285 || MapUtils.isEmpty(portTypeToIds)) {
289 for (String portType : portTypeToIds.keySet()) {
290 Set<GetAttrFuncData> startingGetAttrFunc =
291 getEntityGetAttrFuncAsSet(portType);
293 for (EntityConsolidationData entity : entityConsolidationDataList) {
294 Set<GetAttrFuncData> currentGetAttrFuncData =
295 entity.getEntityGetAttrFuncAsSet(portType);
296 if (!(startingGetAttrFunc.equals(currentGetAttrFuncData))) {
304 private Set<GetAttrFuncData> getEntityGetAttrFuncAsSet(String portType) {
305 if (MapUtils.isEmpty(nodesGetAttrOut)) {
306 return new HashSet<>();
309 return nodesGetAttrOut.entrySet().stream()
310 .filter(entry -> portType.equals(ConsolidationDataUtil.getPortType(entry.getKey())))
311 .flatMap(entry -> entry.getValue().stream())
312 .collect(Collectors.toSet());
316 * Add group id information to consolidation data.
318 * @param groupId Group id of which compute node is a part
321 void addGroupId(String groupId) {
322 if (groupIds == null) {
323 groupIds = new ArrayList<>();
325 groupIds.add(groupId);