2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.sdc.health.impl;
23 import com.amdocs.zusammen.commons.health.data.HealthInfo;
24 import com.amdocs.zusammen.commons.health.data.HealthStatus;
25 import com.amdocs.zusammen.datatypes.SessionContext;
26 import org.openecomp.core.zusammen.api.ZusammenAdaptor;
27 import org.openecomp.core.zusammen.api.ZusammenAdaptorFactory;
28 import org.openecomp.core.zusammen.api.ZusammenUtil;
29 import org.openecomp.sdc.health.HealthCheckDao;
30 import org.openecomp.sdc.health.HealthCheckDaoFactory;
31 import org.openecomp.sdc.health.HealthCheckManager;
32 import org.openecomp.sdc.health.data.HealthCheckStatus;
33 import org.openecomp.sdc.health.data.MonitoredModules;
34 import org.openecomp.sdc.logging.api.Logger;
35 import org.openecomp.sdc.logging.api.LoggerFactory;
36 import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage;
38 import java.util.ArrayList;
39 import java.util.Arrays;
40 import java.util.Collection;
41 import java.util.List;
42 import java.util.stream.Collectors;
44 public class HealthCheckManagerImpl implements HealthCheckManager {
46 private static MdcDataDebugMessage mdcDataDebugMessage;
47 private HealthCheckDao healthCheckDao;
49 private static final Logger logger;
52 mdcDataDebugMessage = new MdcDataDebugMessage();
53 logger = LoggerFactory.getLogger(HealthCheckManagerImpl.class);
56 public HealthCheckManagerImpl() {
57 healthCheckDao = HealthCheckDaoFactory.getInstance().createInterface();
60 public String getBEVersion() {
61 return this.getClass().getPackage().getImplementationVersion();
65 public Collection<org.openecomp.sdc.health.data.HealthInfo> checkHealth() {
66 org.openecomp.sdc.health.data.HealthInfo zeHealthInfo = null;
67 org.openecomp.sdc.health.data.HealthInfo beHealthInfo = new org.openecomp.sdc.health.data.HealthInfo(
68 MonitoredModules.BE, HealthCheckStatus.UP, getBEVersion(), "OK");
69 org.openecomp.sdc.health.data.HealthInfo cassandraHealthInfo = null;
70 String zVersion = "Unknown";
72 SessionContext context = ZusammenUtil.createSessionContext();
73 ZusammenAdaptor zusammenAdaptor = ZusammenAdaptorFactory
74 .getInstance().createInterface();
75 Collection<HealthInfo> zeHealthInfos = new ArrayList<>();
77 zeHealthInfos = zusammenAdaptor.checkHealth(context);
78 } catch (Exception ex) {
79 logger.error(ex.getMessage(), ex);
80 zeHealthInfo = new org.openecomp.sdc.health.data.HealthInfo(
81 MonitoredModules.ZU, HealthCheckStatus.DOWN,
82 zVersion, ex.getMessage());
84 boolean cassandraHealth = false;
85 String description = "OK";
87 cassandraHealth = healthCheckDao.checkHealth();
88 } catch (Exception ex) {
89 logger.error(ex.getMessage(), ex);
90 description = ex.getMessage();
91 cassandraHealthInfo = new org.openecomp.sdc.health.data.HealthInfo(
92 MonitoredModules.CAS, HealthCheckStatus.DOWN, zVersion, ex.getMessage());
94 zVersion = zusammenAdaptor.getVersion(context);
95 if (cassandraHealthInfo == null) {
96 HealthCheckStatus status = cassandraHealth ? HealthCheckStatus.UP : HealthCheckStatus.DOWN;
97 if (!cassandraHealth){
98 description = "Cassandra is not available";
100 cassandraHealthInfo = new org.openecomp.sdc.health.data.HealthInfo(MonitoredModules.CAS, status,
101 healthCheckDao.getVersion(), description);
103 if (zeHealthInfo == null) {
104 List<HealthInfo> downHealth = zeHealthInfos.stream().
105 filter(h -> h.getHealthStatus().equals(HealthStatus.DOWN)).
106 collect(Collectors.toList());
108 if (downHealth.isEmpty()) {
109 zeHealthInfo = new org.openecomp.sdc.health.data.HealthInfo(
110 MonitoredModules.ZU, HealthCheckStatus.UP,
113 String desc = downHealth.stream().map(healthInfo -> healthInfo.getDescription())
114 .collect(Collectors.joining(" , ", "[", "]"));
115 zeHealthInfo = new org.openecomp.sdc.health.data.HealthInfo(
116 MonitoredModules.ZU, HealthCheckStatus.DOWN,
121 } catch (Exception e) {
122 logger.error(e.getMessage(), e);
123 zeHealthInfo = new org.openecomp.sdc.health.data.HealthInfo(
124 MonitoredModules.ZU, HealthCheckStatus.DOWN, zVersion, e.getMessage()
126 cassandraHealthInfo = new org.openecomp.sdc.health.data.HealthInfo(
127 MonitoredModules.CAS, HealthCheckStatus.DOWN, zVersion, e.getMessage());
129 return Arrays.asList(zeHealthInfo, beHealthInfo, cassandraHealthInfo);