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