* ============LICENSE_START==========================================
* ONAP Portal
* ===================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ===================================================================
*
* Unless otherwise specified, all software contained herein is licensed
*/
package org.onap.portalapp.portal.listener;
-import java.io.IOException;
-import java.util.HashSet;
+import java.time.Instant;
import java.util.List;
-import java.util.Set;
-import java.util.UUID;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
private static boolean uebUp;
private static boolean frontEndUp;
private static boolean backEndUp;
- private static boolean dbClusterStatusOk;
private static boolean dbPermissionsOk;
private static boolean zookeeperStatusOk;
private static boolean cassandraStatusOk;
+ private static String APPLICATION = "Portal";
/**
* Read directly by external classes.
return databaseUp;
}
- public static boolean isClusterStatusOk() {
- return dbClusterStatusOk;
- }
-
public static boolean isDatabasePermissionsOk() {
return dbPermissionsOk;
}
int numIntervalsCassandraNotHealthy = 0;
logger.debug(EELFLoggerDelegate.debugLogger, "monitorEPHealth thread started");
+
long sleepInterval = (Long
.valueOf(SystemProperties.getProperty(EPCommonSystemProperties.HEALTH_POLL_INTERVAL_SECONDS)) * 1000);
logger.debug(EELFLoggerDelegate.debugLogger,
"monitorEPHealth: Polling health every " + sleepInterval + " milliseconds. Alerting every "
+ (sleepInterval * numIntervalsBetweenAlerts) / 1000 + " seconds when component remains down.");
-
+
while (true) {
+ logger.debug(EELFLoggerDelegate.debugLogger,
+ "monitorEPHealth: Test Connection to all");
//
// Get DB status. If down, signal alert once every X intervals.
//
}
}
- dbClusterStatusOk = this.checkClusterStatus();
- if (dbClusterStatusOk == false) {
- if ((numIntervalsClusterNotHealthy % numIntervalsBetweenAlerts) == 0) {
- logger.debug(EELFLoggerDelegate.debugLogger,
- "monitorEPHealth: cluster nodes down, logging to error log to trigger alert.");
- EPLogUtil.logEcompError(logger, EPAppMessagesEnum.BeHealthCheckMySqlError);
- numIntervalsClusterNotHealthy++;
- } else {
- numIntervalsClusterNotHealthy = 0;
- }
- }
-
dbPermissionsOk = this.checkDatabasePermissions();
if (dbPermissionsOk == false) {
if ((numIntervalsDatabasePermissionsIncorrect % numIntervalsBetweenAlerts) == 0) {
numIntervalsDatabasePermissionsIncorrect = 0;
}
}
-
- zookeeperStatusOk = this.checkZookeeperStatus();
- if (zookeeperStatusOk == false) {
- if ((numIntervalsZookeeperNotHealthy % numIntervalsBetweenAlerts) == 0) {
- logger.debug(EELFLoggerDelegate.debugLogger,
- "monitorEPHealth: cluster nodes down, logging to error log to trigger alert.");
- EPLogUtil.logEcompError(logger, EPAppMessagesEnum.MusicHealthCheckZookeeperError);
- numIntervalsZookeeperNotHealthy++;
- } else {
- numIntervalsZookeeperNotHealthy = 0;
+ org.onap.portalapp.music.util.MusicUtil MusicUtilSDK = new org.onap.portalapp.music.util.MusicUtil();
+ if(MusicUtilSDK.isMusicEnable()){
+
+ zookeeperStatusOk = this.checkZookeeperStatus();
+
+ if (zookeeperStatusOk == false) {
+ if ((numIntervalsZookeeperNotHealthy % numIntervalsBetweenAlerts) == 0) {
+ logger.debug(EELFLoggerDelegate.debugLogger,
+ "monitorEPHealth: cluster nodes down, logging to error log to trigger alert.");
+ EPLogUtil.logEcompError(logger, EPAppMessagesEnum.MusicHealthCheckZookeeperError);
+ numIntervalsZookeeperNotHealthy++;
+ } else {
+ numIntervalsZookeeperNotHealthy = 0;
+ }
}
- }
- cassandraStatusOk = this.checkCassandraStatus();
- if (cassandraStatusOk == false) {
- if ((numIntervalsCassandraNotHealthy % numIntervalsBetweenAlerts) == 0) {
- logger.debug(EELFLoggerDelegate.debugLogger,
- "monitorEPHealth: cluster nodes down, logging to error log to trigger alert.");
- EPLogUtil.logEcompError(logger, EPAppMessagesEnum.MusicHealthCheckCassandraError);
- numIntervalsCassandraNotHealthy++;
- } else {
- numIntervalsCassandraNotHealthy = 0;
+ cassandraStatusOk = this.checkCassandraStatus();
+ if (cassandraStatusOk == false) {
+ if ((numIntervalsCassandraNotHealthy % numIntervalsBetweenAlerts) == 0) {
+ logger.debug(EELFLoggerDelegate.debugLogger,
+ "monitorEPHealth: cluster nodes down, logging to error log to trigger alert.");
+ EPLogUtil.logEcompError(logger, EPAppMessagesEnum.MusicHealthCheckCassandraError);
+ numIntervalsCassandraNotHealthy++;
+ } else {
+ numIntervalsCassandraNotHealthy = 0;
+ }
}
}
+
//
// Get UEB status. Publish a bogus message to EP inbox, if 200 OK
// returned, status is Up.
monitorEPHealth();
} catch (InterruptedException e) {
logger.debug(EELFLoggerDelegate.debugLogger, "healthMonitorThread interrupted", e);
- } catch (Exception e) {
+ }
+ catch (Exception e) {
logger.error(EELFLoggerDelegate.errorLogger, "healthMonitorThread failed", e);
}
}
return isUp;
}
- private boolean checkClusterStatus() {
- boolean isUp = false;
- Session localSession = null;
- try {
- localSession = sessionFactory.openSession();
- if (localSession != null) {
- // If all nodes are unhealthy in a cluster, this will throw an
- // exception
- String sql = "select * from mysql.user";
- Query query = localSession.createSQLQuery(sql);
- @SuppressWarnings("unchecked")
- List<String> queryList = query.list();
- if (queryList != null) {
- isUp = true;
- }
- }
- } catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger, "checkClusterStatus failed", e);
- if ((e.getCause() != null) && (e.getCause().getMessage() != null)) {
- logger.error(EELFLoggerDelegate.errorLogger, "checkClusterStatus failure cause", e.getCause());
- }
- isUp = false;
- } finally {
- if (localSession != null) {
- localSession.close();
- }
- }
- return isUp;
- }
-
private boolean checkZookeeperStatus() {
String[] zookeeperNodes = MusicUtil.getMyZkHost().split(",");
}
private Boolean getAdminKeySpace() {
- String musicKeySpace = MusicProperties.getProperty(MusicProperties.MUSIC_SESSION_KEYSPACE );
- //deletePortalHealthcheck(musicKeySpace);
+ String musicKeySpace = MusicProperties.getProperty(MusicProperties.MUSIC_SESSION_KEYSPACE);
+ Instant creationTime = Instant.now();
PreparedQueryObject pQuery = new PreparedQueryObject();
- pQuery.appendQueryString("insert into "+musicKeySpace+".healthcheck (id) values (?)");
- pQuery.addValue(UUID.randomUUID());
+ pQuery.appendQueryString(
+ "UPDATE " + musicKeySpace + ".health_check SET creation_time = ? WHERE primary_id = ?");
+ pQuery.addValue(creationTime.toString());
+ pQuery.addValue(APPLICATION);
try {
- MusicCore.nonKeyRelatedPut(pQuery, MusicUtil.EVENTUAL);
+ MusicCore.nonKeyRelatedPut(pQuery, MusicUtil.CRITICAL);
} catch (MusicServiceException e) {
- logger.error(EELFLoggerDelegate.errorLogger, "getAdminKeySpace() failed", e.getCause());
return Boolean.FALSE;
}
- return Boolean.TRUE;
- }
+ return Boolean.TRUE;
-
- private void deletePortalHealthcheck(String musicKeySpace) {
- PreparedQueryObject pQuery = new PreparedQueryObject();
- pQuery.appendQueryString("TRUNCATE "+musicKeySpace+".healthcheck");
- try {
- MusicCore.nonKeyRelatedPut(pQuery, MusicUtil.EVENTUAL);
- } catch (MusicServiceException e) {
- logger.error(EELFLoggerDelegate.errorLogger, "deletePortalHealthcheck() failed", e.getCause());
- }
}
+
private boolean checkDatabasePermissions() {
boolean isUp = false;