854cf51aa2c1cf228f3bef282c1b8079c5a2ce5e
[sdc.git] /
1 /*
2  * Copyright © 2016-2018 European Support Limited
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation;
18
19 import java.util.ArrayList;
20 import java.util.HashMap;
21 import java.util.List;
22 import java.util.Map;
23
24 import org.apache.commons.collections4.MapUtils;
25 import org.onap.sdc.tosca.datatypes.model.RequirementAssignment;
26
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;
32
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;
36
37     public Map<String,List<RequirementAssignmentData>> getVolumes() {
38         return volumes;
39     }
40
41     public void setVolumes(Map<String,List<RequirementAssignmentData>> volumes) {
42         this.volumes = volumes;
43     }
44
45     public Map<String, List<String>> getPorts() {
46         return ports;
47     }
48
49     public void setPorts(Map<String, List<String>> ports) {
50         this.ports = ports;
51     }
52
53     public void addPort(String portType, String portNodeTemplateId) {
54         if (this.ports == null) {
55             this.ports = new HashMap<>();
56         }
57         this.ports.putIfAbsent(portType, new ArrayList<>());
58         this.ports.get(portType).add(portNodeTemplateId);
59     }
60
61     public void addVolume(String requirementId, RequirementAssignment requirementAssignment) {
62         if (this.volumes == null) {
63             this.volumes = new HashMap<>();
64         }
65         this.volumes.computeIfAbsent(requirementAssignment.getNode(), k -> new ArrayList<>())
66                 .add(new RequirementAssignmentData(requirementId,
67                 requirementAssignment));
68     }
69
70     /**
71      * Collect all ports of each type from compute.
72      *
73      * @param portTypeToIds will be populated with all port of each type
74      */
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());
80             }
81         }
82     }
83 }