3cbdfc798c0900bd5f0df3493ea9684de77dfc9a
[sdc.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.sdc.be.model.operations.migration;
22
23 import org.apache.commons.lang3.StringUtils;
24 import org.openecomp.sdc.be.model.Component;
25 import org.openecomp.sdc.be.model.ComponentInstance;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28
29 import java.util.HashSet;
30 import java.util.List;
31 import java.util.Set;
32 import java.util.stream.Collectors;
33
34 /**
35  * to be moved with all operations to the migration project
36  */
37
38 public class MigrationMalformedDataLogger {
39
40     private static Logger log = LoggerFactory.getLogger(MigrationMalformedDataLogger.class);
41     private static Set<String> malformedVFs = new HashSet<>();
42
43     public static void reportMalformedVF(String vfId, String errorMsg) {
44         log.error(errorMsg);
45         malformedVFs.add(vfId);
46     }
47
48     public static void logMalformedDataMsg(String errorMsg) {
49         log.error(errorMsg);
50     }
51
52     public static void logIfServiceUsingMalformedVfs(Component service) {
53         List<ComponentInstance> componentInstances = service.getComponentInstances();
54         if (componentInstances != null && !componentInstances.isEmpty() && !malformedVFs.isEmpty()) {
55             Set<String> serviceInstances = componentInstances.stream().map(ComponentInstance::getComponentUid).collect(Collectors.toSet());
56             serviceInstances.retainAll(malformedVFs);
57             if (!serviceInstances.isEmpty()) {
58                 log.error(String.format("Service %s with id %s and version %s is using malformed VFs: %s", service.getName(),
59                                                                                                            service.getVersion(),
60                                                                                                            service.getUniqueId(),
61                                                                                                            StringUtils.join(serviceInstances, ',')));
62             }
63         }
64     }
65
66
67 }