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.HashMap;
24 import java.util.HashSet;
25 import java.util.List;
29 import org.apache.commons.collections4.MapUtils;
30 import org.onap.sdc.tosca.datatypes.model.RequirementAssignment;
32 public class ComputeTemplateConsolidationData extends EntityConsolidationData {
33 // key - volume node template id
34 // value - List of requirement id and the requirement assignment on the
35 // compute node which connect to this volume
36 private Multimap<String, RequirementAssignmentData> volumes;
38 // key - port type (port id excluding index),
39 // value - List of connected port node template ids, with this port type
40 private Map<String, List<String>> ports;
42 public Multimap<String, RequirementAssignmentData> getVolumes() {
46 public void setVolumes(Multimap<String, RequirementAssignmentData> volumes) {
47 this.volumes = volumes;
50 public Map<String, List<String>> getPorts() {
54 public void setPorts(Map<String, List<String>> ports) {
58 public void addPort(String portType, String portNodeTemplateId) {
59 if (this.ports == null) {
60 this.ports = new HashMap<>();
62 this.ports.putIfAbsent(portType, new ArrayList<>());
63 this.ports.get(portType).add(portNodeTemplateId);
66 public void addVolume(String requirementId, RequirementAssignment requirementAssignment) {
67 if (this.volumes == null) {
68 this.volumes = ArrayListMultimap.create();
70 this.volumes.put(requirementAssignment.getNode(), new RequirementAssignmentData(requirementId,
71 requirementAssignment));
75 * Collect all ports of each type from compute.
77 * @param portTypeToIds will be populated with all port of each type
79 public void collectAllPortsOfEachTypeFromCompute(Map<String, List<String>> portTypeToIds) {
80 if (MapUtils.isNotEmpty(ports)) {
81 for (Map.Entry<String, List<String>> portTypeToIdEntry : ports.entrySet()) {
82 portTypeToIds.putIfAbsent(portTypeToIdEntry.getKey(), new ArrayList<>());
83 portTypeToIds.get(portTypeToIdEntry.getKey()).addAll(portTypeToIdEntry.getValue());
89 * Is number of port from each compute type legal.
93 public boolean isNumberOfPortFromEachTypeLegal() {
94 Map<String, List<String>> currPortsMap = getPorts();
95 return MapUtils.isEmpty(currPortsMap) || currPortsMap.values().stream()
96 .allMatch(portList -> portList.size() == 1);
99 public Set<String> getPortsIds() {
100 return MapUtils.isEmpty(getPorts()) ? new HashSet<>() : getPorts().keySet();
103 public int getNumberOfPorts() {
104 return getPortsIds().size();