1 package org.openecomp.sdc.translator.services.heattotosca;
3 import org.apache.commons.collections4.CollectionUtils;
4 import org.apache.commons.collections4.MapUtils;
5 import org.openecomp.sdc.logging.api.Logger;
6 import org.openecomp.sdc.logging.api.LoggerFactory;
7 import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.composition.UnifiedCompositionData;
8 import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.ComputeTemplateConsolidationData;
10 import java.util.Collection;
11 import java.util.HashMap;
12 import java.util.HashSet;
13 import java.util.List;
18 * Utility class for consolidation data collection helper methods.
20 public class UnifiedCompositionUtil {
22 protected static Logger logger = (Logger) LoggerFactory.getLogger(UnifiedCompositionUtil.class);
25 * Gets all ports per port type, which are connected to the computes from the input
26 * computeTemplateConsolidationDataCollection.
28 * @param computeTemplateConsolidationDataCollection collection of compute template
30 * @return set of port ids, per port type
32 public static Map<String, Set<String>> collectAllPortsFromEachTypesFromComputes(
33 Collection<ComputeTemplateConsolidationData> computeTemplateConsolidationDataCollection) {
34 Map<String, Set<String>> portTypeToIds = new HashMap<>();
36 for (ComputeTemplateConsolidationData compute : computeTemplateConsolidationDataCollection) {
37 Map<String, List<String>> ports = compute.getPorts();
38 if (!MapUtils.isEmpty(ports)) {
39 addPortsToMap(portTypeToIds, ports);
46 private static void addPortsToMap(Map<String, Set<String>> portTypeToIds,
47 Map<String, List<String>> ports) {
48 for (Map.Entry<String, List<String>> portTypeToIdEntry : ports.entrySet()) {
49 portTypeToIds.putIfAbsent(portTypeToIdEntry.getKey(), new HashSet<>());
50 portTypeToIds.get(portTypeToIdEntry.getKey()).addAll(portTypeToIdEntry.getValue());