summaryrefslogtreecommitdiffstats
path: root/common-app-api/src/main/java/org/openecomp/sdc/common/util/HealthCheckUtil.java
blob: e0d52060660b10fdcd45a1f8b4a94f6e8babfa01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package org.openecomp.sdc.common.util;

import java.util.List;

import org.openecomp.sdc.common.api.HealthCheckInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class HealthCheckUtil {

    private static Logger log = LoggerFactory.getLogger(HealthCheckUtil.class.getName());

    public static boolean getAggregateStatus(List<HealthCheckInfo> healthCheckInfos) {

        boolean status = true;

        for (HealthCheckInfo healthCheckInfo : healthCheckInfos) {
            if (healthCheckInfo.getHealthCheckStatus().equals(HealthCheckInfo.HealthCheckStatus.DOWN)) {
                log.debug("Component {} is reported as DOWN - Aggregated HC will be DOWN", healthCheckInfo.getHealthCheckComponent());
                status = false;
                break;
            }
        }

        return status;
    }

    public static String getAggregateDescription(List<HealthCheckInfo> healthCheckInfos, String parentDescription) {

        StringBuilder sb = new StringBuilder();
        healthCheckInfos.forEach(x -> {
            if (x.getHealthCheckStatus() == HealthCheckInfo.HealthCheckStatus.DOWN) {
                sb.append("Component ").append(x.getHealthCheckComponent()).append(" is Down, ");
            }
        });

        return sb.length() > 0 ? sb.substring(0, sb.length() - 1) : "";

//        return description;
    }

}