[SDC-31] add mising script got Comformance fix
[sdc.git] / catalog-model / src / main / java / org / openecomp / sdc / be / model / operations / migration / MigrationMalformedDataLogger.java
1 package org.openecomp.sdc.be.model.operations.migration;
2
3 import org.apache.commons.lang3.StringUtils;
4 import org.openecomp.sdc.be.model.Component;
5 import org.openecomp.sdc.be.model.ComponentInstance;
6 import org.slf4j.Logger;
7 import org.slf4j.LoggerFactory;
8
9 import java.util.HashSet;
10 import java.util.List;
11 import java.util.Set;
12 import java.util.stream.Collectors;
13
14 /**
15  * to be moved with all operations to the migration project
16  */
17
18 public class MigrationMalformedDataLogger {
19
20     private static Logger log = LoggerFactory.getLogger(MigrationMalformedDataLogger.class);
21     private static Set<String> malformedVFs = new HashSet<>();
22
23     public static void reportMalformedVF(String vfId, String errorMsg) {
24         log.error(errorMsg);
25         malformedVFs.add(vfId);
26     }
27
28     public static void logMalformedDataMsg(String errorMsg) {
29         log.error(errorMsg);
30     }
31
32     public static void logIfServiceUsingMalformedVfs(Component service) {
33         List<ComponentInstance> componentInstances = service.getComponentInstances();
34         if (componentInstances != null && !componentInstances.isEmpty() && !malformedVFs.isEmpty()) {
35             Set<String> serviceInstances = componentInstances.stream().map(ComponentInstance::getComponentUid).collect(Collectors.toSet());
36             serviceInstances.retainAll(malformedVFs);
37             if (!serviceInstances.isEmpty()) {
38                 log.error(String.format("Service %s is using malformed VFs: %s", service.getUniqueId(), StringUtils.join(serviceInstances, ',')));
39             }
40         }
41     }
42
43
44 }