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 java.util.ArrayList;
20 import java.util.HashMap;
21 import java.util.List;
24 import org.apache.commons.collections4.MapUtils;
25 import org.onap.sdc.tosca.datatypes.model.RequirementAssignment;
27 public class ComputeTemplateConsolidationData extends EntityConsolidationData {
28 // key - volume node template id
29 // value - List of requirement id and the requirement assignment on the
30 // compute node which connect to this volume
31 private Map<String,List<RequirementAssignmentData>> volumes;
33 // key - port type (port id excluding index),
34 // value - List of connected port node template ids, with this port type
35 private Map<String, List<String>> ports;
37 public Map<String,List<RequirementAssignmentData>> getVolumes() {
41 public void setVolumes(Map<String,List<RequirementAssignmentData>> volumes) {
42 this.volumes = volumes;
45 public Map<String, List<String>> getPorts() {
49 public void setPorts(Map<String, List<String>> ports) {
53 public void addPort(String portType, String portNodeTemplateId) {
54 if (this.ports == null) {
55 this.ports = new HashMap<>();
57 this.ports.putIfAbsent(portType, new ArrayList<>());
58 this.ports.get(portType).add(portNodeTemplateId);
61 public void addVolume(String requirementId, RequirementAssignment requirementAssignment) {
62 if (this.volumes == null) {
63 this.volumes = new HashMap<>();
65 this.volumes.computeIfAbsent(requirementAssignment.getNode(), k -> new ArrayList<>())
66 .add(new RequirementAssignmentData(requirementId,
67 requirementAssignment));
71 * Collect all ports of each type from compute.
73 * @param portTypeToIds will be populated with all port of each type
75 public void collectAllPortsOfEachTypeFromCompute(Map<String, List<String>> portTypeToIds) {
76 if (MapUtils.isNotEmpty(ports)) {
77 for (Map.Entry<String, List<String>> portTypeToIdEntry : ports.entrySet()) {
78 portTypeToIds.putIfAbsent(portTypeToIdEntry.getKey(), new ArrayList<>());
79 portTypeToIds.get(portTypeToIdEntry.getKey()).addAll(portTypeToIdEntry.getValue());