2 * Copyright © 2016-2017 European Support Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.openecomp.sdc.health.impl;
19 import com.amdocs.zusammen.commons.health.data.HealthInfo;
20 import com.amdocs.zusammen.commons.health.data.HealthStatus;
21 import com.amdocs.zusammen.datatypes.SessionContext;
22 import org.openecomp.core.zusammen.api.ZusammenAdaptor;
23 import org.openecomp.core.zusammen.api.ZusammenAdaptorFactory;
24 import org.openecomp.core.zusammen.api.ZusammenUtil;
25 import org.openecomp.sdc.health.HealthCheckDao;
26 import org.openecomp.sdc.health.HealthCheckDaoFactory;
27 import org.openecomp.sdc.health.HealthCheckManager;
28 import org.openecomp.sdc.health.data.HealthCheckStatus;
29 import org.openecomp.sdc.health.data.MonitoredModules;
30 import org.openecomp.sdc.logging.api.Logger;
31 import org.openecomp.sdc.logging.api.LoggerFactory;
33 import java.util.ArrayList;
34 import java.util.Arrays;
35 import java.util.Collection;
36 import java.util.List;
37 import java.util.stream.Collectors;
39 public class HealthCheckManagerImpl implements HealthCheckManager {
41 private static final Logger LOGGER = LoggerFactory.getLogger(HealthCheckManagerImpl.class);
43 private HealthCheckDao healthCheckDao;
45 public HealthCheckManagerImpl() {
46 healthCheckDao = HealthCheckDaoFactory.getInstance().createInterface();
49 public String getBEVersion() {
50 return this.getClass().getPackage().getImplementationVersion();
54 public Collection<org.openecomp.sdc.health.data.HealthInfo> checkHealth() {
55 org.openecomp.sdc.health.data.HealthInfo zeHealthInfo = null;
56 org.openecomp.sdc.health.data.HealthInfo beHealthInfo = new org.openecomp.sdc.health.data.HealthInfo(
57 MonitoredModules.BE, HealthCheckStatus.UP, getBEVersion(), "OK");
58 org.openecomp.sdc.health.data.HealthInfo cassandraHealthInfo = null;
59 String zVersion = "Unknown";
61 SessionContext context = ZusammenUtil.createSessionContext();
62 ZusammenAdaptor zusammenAdaptor = ZusammenAdaptorFactory
63 .getInstance().createInterface();
64 Collection<HealthInfo> zeHealthInfos = new ArrayList<>();
66 zeHealthInfos = zusammenAdaptor.checkHealth(context);
67 } catch (Exception ex) {
68 LOGGER.error(ex.getMessage(), ex);
69 zeHealthInfo = new org.openecomp.sdc.health.data.HealthInfo(
70 MonitoredModules.ZU, HealthCheckStatus.DOWN,
71 zVersion, ex.getMessage());
73 boolean cassandraHealth = false;
74 String description = "OK";
76 cassandraHealth = healthCheckDao.checkHealth();
77 } catch (Exception ex) {
78 LOGGER.error(ex.getMessage(), ex);
79 description = ex.getMessage();
80 cassandraHealthInfo = new org.openecomp.sdc.health.data.HealthInfo(
81 MonitoredModules.CAS, HealthCheckStatus.DOWN, zVersion, ex.getMessage());
83 zVersion = zusammenAdaptor.getVersion(context);
84 if (cassandraHealthInfo == null) {
85 HealthCheckStatus status = cassandraHealth ? HealthCheckStatus.UP : HealthCheckStatus.DOWN;
86 if (!cassandraHealth){
87 description = "Cassandra is not available";
89 cassandraHealthInfo = new org.openecomp.sdc.health.data.HealthInfo(MonitoredModules.CAS, status,
90 healthCheckDao.getVersion(), description);
92 if (zeHealthInfo == null) {
93 List<HealthInfo> downHealth = zeHealthInfos.stream().
94 filter(h -> h.getHealthStatus().equals(HealthStatus.DOWN)).
95 collect(Collectors.toList());
97 if (downHealth.isEmpty()) {
98 zeHealthInfo = new org.openecomp.sdc.health.data.HealthInfo(
99 MonitoredModules.ZU, HealthCheckStatus.UP,
102 String desc = downHealth.stream().map(healthInfo -> healthInfo.getDescription())
103 .collect(Collectors.joining(" , ", "[", "]"));
104 zeHealthInfo = new org.openecomp.sdc.health.data.HealthInfo(
105 MonitoredModules.ZU, HealthCheckStatus.DOWN,
110 } catch (Exception e) {
111 LOGGER.error(e.getMessage(), e);
112 zeHealthInfo = new org.openecomp.sdc.health.data.HealthInfo(
113 MonitoredModules.ZU, HealthCheckStatus.DOWN, zVersion, e.getMessage()
115 cassandraHealthInfo = new org.openecomp.sdc.health.data.HealthInfo(
116 MonitoredModules.CAS, HealthCheckStatus.DOWN, zVersion, e.getMessage());
118 return Arrays.asList(zeHealthInfo, beHealthInfo, cassandraHealthInfo);