re base code
[sdc.git] / common-app-api / src / main / java / org / openecomp / sdc / common / util / HealthCheckUtil.java
1 package org.openecomp.sdc.common.util;
2
3 import org.apache.commons.collections.CollectionUtils;
4 import org.openecomp.sdc.common.api.HealthCheckInfo;
5 import org.openecomp.sdc.common.log.wrappers.Logger;
6
7 import java.util.ArrayList;
8 import java.util.Collection;
9 import java.util.List;
10
11 import static org.openecomp.sdc.common.api.HealthCheckInfo.HealthCheckStatus.DOWN;
12
13 public class HealthCheckUtil {
14
15     private static Logger log = Logger.getLogger(HealthCheckUtil.class.getName());
16     public boolean getAggregateStatus(List<HealthCheckInfo> healthCheckInfos, Collection<String> excludes) {
17         boolean status = true;
18         excludes = CollectionUtils.isEmpty(excludes) ? new ArrayList<>() : excludes;
19         for (HealthCheckInfo healthCheckInfo : healthCheckInfos) {
20             if (!excludes.contains(healthCheckInfo.getHealthCheckComponent()) && healthCheckInfo.getHealthCheckStatus().equals(DOWN)) {
21                 log.debug("Component {} is reported as DOWN - Aggregated HC will be DOWN", healthCheckInfo.getHealthCheckComponent());
22                 status = false;
23                 break;
24             }
25         }
26
27         return status;
28     }
29
30     public String getAggregateDescription(List<HealthCheckInfo> healthCheckInfos, String parentDescription) {
31
32         StringBuilder sb = new StringBuilder();
33         healthCheckInfos.forEach(x -> {
34             if (x.getHealthCheckStatus() == DOWN) {
35                 sb.append("Component ").append(x.getHealthCheckComponent()).append(" is Down, ");
36             }
37         });
38
39         return sb.length() > 0 ? sb.substring(0, sb.length() - 1) : "";
40     }
41
42 }