@Test public void testgetSurveillerStatus_NullParams() throws SerialException, SQLException { HealthCheckEntity hcv = daoService.createHealthCheckEntity(0, cte, region_id, TestDataProvider.getMesosPlatform()); HealthCheckVO hcvo = new HealthCheckVO(); Map<String,String> paramList = new HashMap<String,String>(); paramList.put("DB-JDBC-URL",null); paramList.put("DB-USER",null); paramList.put("DB-PASSWORD","sa"); paramList.put("DB-JDBC-DRIVER-CLASS","org.h2.Driver"); paramList.put("DB-QUERY","test"); paramList.put("DB-EXPECTED-VALUE","test"); hcvo.setParamDetails(paramList); dbHandler.setHealthCheckVO(hcvo); dbHandler.init(hcvo); StatusVO result = dbHandler.getSurveillerStatus(); dbHandler.run(); HealthCheckVO resultVO= dbHandler.getHealthCheckVO(); }
@Override public StatusVO getSurveillerStatus() { Connection connection = null; Statement statement = null; ResultSet rs = null; try { if(paramDetails.get(PARAM_KEY_JDBC_URL) == null || paramDetails.get(PARAM_KEY_JDBC_DRIVER_CLASS) == null || paramDetails.get(PARAM_KEY_USER) == null || paramDetails.get(PARAM_KEY_PWD) == null || paramDetails.get(PARAM_KEY_QUERY) == null || paramDetails.get(PARAM_KEY_EXPVALUE) == null ){ logger.error("Configuration Error : The health check is not having all the mandatory parameters"); return new StatusVO(Status.DOWN, "Configuration Error : The health check is not having all the mandatory parameters"); } Class.forName(paramDetails.get(PARAM_KEY_JDBC_DRIVER_CLASS)).newInstance(); String connectionUrl = paramDetails.get(PARAM_KEY_JDBC_URL); logger.debug("Connecting URL : " + connectionUrl); connection = DriverManager.getConnection(connectionUrl, paramDetails.get(PARAM_KEY_USER), paramDetails.get(PARAM_KEY_PWD)); if (connection == null) { logger.error("Unable to Connect to Database. URL = " + connectionUrl); return new StatusVO(Status.DOWN,"Unable to Connect to Database. URL = " + connectionUrl); } statement = connection.createStatement(); rs = statement.executeQuery(paramDetails.get(PARAM_KEY_QUERY)); if (!rs.next()){ logger.error("SQL Query returned no result Query : " + paramDetails.get(PARAM_KEY_QUERY)); return new StatusVO(Status.DOWN,"SQL Query returned no result Query : " + paramDetails.get(PARAM_KEY_QUERY)); } if(paramDetails.get(PARAM_KEY_EXPVALUE).equals(rs.getString(1))) { return new StatusVO(Status.UP); } else { logger.error("Expected Value does not match from Result returned. Returned result = " + rs.getString(1) + "; Expected result =" + paramDetails.get(PARAM_KEY_EXPVALUE)); return new StatusVO(Status.DOWN,"Expected Value does not match from Result returned. Returned result = " + rs.getString(1) + "; Expected result =" + paramDetails.get(PARAM_KEY_EXPVALUE)); } } catch(SQLException ue){ logger.error("Got SQLException : Unable to Connect to Database. URL = " + paramDetails.get(PARAM_KEY_JDBC_URL), ue); return new StatusVO(Status.DOWN,"Got SQLException : Unable to Connect to Database. URL = " + paramDetails.get(PARAM_KEY_JDBC_URL)); } catch (Exception e) { logger.error("Got Exception while connecting URL = " + paramDetails.get(PARAM_KEY_JDBC_URL), e); return new StatusVO(Status.DOWN,"Got Exception while connecting URL = " + paramDetails.get(PARAM_KEY_JDBC_URL)); }finally{ try { if (rs != null) { rs.close(); } if (statement != null) { statement.close(); } if (connection != null) { connection.close(); } } catch (SQLException e) { logger.error("Got Exception while disconnecting connecting URL = " + paramDetails.get(PARAM_KEY_JDBC_URL), e); }; } }
DBHandler extends SurveillerHandler { @Override public StatusVO getSurveillerStatus() { Connection connection = null; Statement statement = null; ResultSet rs = null; try { if(paramDetails.get(PARAM_KEY_JDBC_URL) == null || paramDetails.get(PARAM_KEY_JDBC_DRIVER_CLASS) == null || paramDetails.get(PARAM_KEY_USER) == null || paramDetails.get(PARAM_KEY_PWD) == null || paramDetails.get(PARAM_KEY_QUERY) == null || paramDetails.get(PARAM_KEY_EXPVALUE) == null ){ logger.error("Configuration Error : The health check is not having all the mandatory parameters"); return new StatusVO(Status.DOWN, "Configuration Error : The health check is not having all the mandatory parameters"); } Class.forName(paramDetails.get(PARAM_KEY_JDBC_DRIVER_CLASS)).newInstance(); String connectionUrl = paramDetails.get(PARAM_KEY_JDBC_URL); logger.debug("Connecting URL : " + connectionUrl); connection = DriverManager.getConnection(connectionUrl, paramDetails.get(PARAM_KEY_USER), paramDetails.get(PARAM_KEY_PWD)); if (connection == null) { logger.error("Unable to Connect to Database. URL = " + connectionUrl); return new StatusVO(Status.DOWN,"Unable to Connect to Database. URL = " + connectionUrl); } statement = connection.createStatement(); rs = statement.executeQuery(paramDetails.get(PARAM_KEY_QUERY)); if (!rs.next()){ logger.error("SQL Query returned no result Query : " + paramDetails.get(PARAM_KEY_QUERY)); return new StatusVO(Status.DOWN,"SQL Query returned no result Query : " + paramDetails.get(PARAM_KEY_QUERY)); } if(paramDetails.get(PARAM_KEY_EXPVALUE).equals(rs.getString(1))) { return new StatusVO(Status.UP); } else { logger.error("Expected Value does not match from Result returned. Returned result = " + rs.getString(1) + "; Expected result =" + paramDetails.get(PARAM_KEY_EXPVALUE)); return new StatusVO(Status.DOWN,"Expected Value does not match from Result returned. Returned result = " + rs.getString(1) + "; Expected result =" + paramDetails.get(PARAM_KEY_EXPVALUE)); } } catch(SQLException ue){ logger.error("Got SQLException : Unable to Connect to Database. URL = " + paramDetails.get(PARAM_KEY_JDBC_URL), ue); return new StatusVO(Status.DOWN,"Got SQLException : Unable to Connect to Database. URL = " + paramDetails.get(PARAM_KEY_JDBC_URL)); } catch (Exception e) { logger.error("Got Exception while connecting URL = " + paramDetails.get(PARAM_KEY_JDBC_URL), e); return new StatusVO(Status.DOWN,"Got Exception while connecting URL = " + paramDetails.get(PARAM_KEY_JDBC_URL)); }finally{ try { if (rs != null) { rs.close(); } if (statement != null) { statement.close(); } if (connection != null) { connection.close(); } } catch (SQLException e) { logger.error("Got Exception while disconnecting connecting URL = " + paramDetails.get(PARAM_KEY_JDBC_URL), e); }; } } }
DBHandler extends SurveillerHandler { @Override public StatusVO getSurveillerStatus() { Connection connection = null; Statement statement = null; ResultSet rs = null; try { if(paramDetails.get(PARAM_KEY_JDBC_URL) == null || paramDetails.get(PARAM_KEY_JDBC_DRIVER_CLASS) == null || paramDetails.get(PARAM_KEY_USER) == null || paramDetails.get(PARAM_KEY_PWD) == null || paramDetails.get(PARAM_KEY_QUERY) == null || paramDetails.get(PARAM_KEY_EXPVALUE) == null ){ logger.error("Configuration Error : The health check is not having all the mandatory parameters"); return new StatusVO(Status.DOWN, "Configuration Error : The health check is not having all the mandatory parameters"); } Class.forName(paramDetails.get(PARAM_KEY_JDBC_DRIVER_CLASS)).newInstance(); String connectionUrl = paramDetails.get(PARAM_KEY_JDBC_URL); logger.debug("Connecting URL : " + connectionUrl); connection = DriverManager.getConnection(connectionUrl, paramDetails.get(PARAM_KEY_USER), paramDetails.get(PARAM_KEY_PWD)); if (connection == null) { logger.error("Unable to Connect to Database. URL = " + connectionUrl); return new StatusVO(Status.DOWN,"Unable to Connect to Database. URL = " + connectionUrl); } statement = connection.createStatement(); rs = statement.executeQuery(paramDetails.get(PARAM_KEY_QUERY)); if (!rs.next()){ logger.error("SQL Query returned no result Query : " + paramDetails.get(PARAM_KEY_QUERY)); return new StatusVO(Status.DOWN,"SQL Query returned no result Query : " + paramDetails.get(PARAM_KEY_QUERY)); } if(paramDetails.get(PARAM_KEY_EXPVALUE).equals(rs.getString(1))) { return new StatusVO(Status.UP); } else { logger.error("Expected Value does not match from Result returned. Returned result = " + rs.getString(1) + "; Expected result =" + paramDetails.get(PARAM_KEY_EXPVALUE)); return new StatusVO(Status.DOWN,"Expected Value does not match from Result returned. Returned result = " + rs.getString(1) + "; Expected result =" + paramDetails.get(PARAM_KEY_EXPVALUE)); } } catch(SQLException ue){ logger.error("Got SQLException : Unable to Connect to Database. URL = " + paramDetails.get(PARAM_KEY_JDBC_URL), ue); return new StatusVO(Status.DOWN,"Got SQLException : Unable to Connect to Database. URL = " + paramDetails.get(PARAM_KEY_JDBC_URL)); } catch (Exception e) { logger.error("Got Exception while connecting URL = " + paramDetails.get(PARAM_KEY_JDBC_URL), e); return new StatusVO(Status.DOWN,"Got Exception while connecting URL = " + paramDetails.get(PARAM_KEY_JDBC_URL)); }finally{ try { if (rs != null) { rs.close(); } if (statement != null) { statement.close(); } if (connection != null) { connection.close(); } } catch (SQLException e) { logger.error("Got Exception while disconnecting connecting URL = " + paramDetails.get(PARAM_KEY_JDBC_URL), e); }; } }  }
DBHandler extends SurveillerHandler { @Override public StatusVO getSurveillerStatus() { Connection connection = null; Statement statement = null; ResultSet rs = null; try { if(paramDetails.get(PARAM_KEY_JDBC_URL) == null || paramDetails.get(PARAM_KEY_JDBC_DRIVER_CLASS) == null || paramDetails.get(PARAM_KEY_USER) == null || paramDetails.get(PARAM_KEY_PWD) == null || paramDetails.get(PARAM_KEY_QUERY) == null || paramDetails.get(PARAM_KEY_EXPVALUE) == null ){ logger.error("Configuration Error : The health check is not having all the mandatory parameters"); return new StatusVO(Status.DOWN, "Configuration Error : The health check is not having all the mandatory parameters"); } Class.forName(paramDetails.get(PARAM_KEY_JDBC_DRIVER_CLASS)).newInstance(); String connectionUrl = paramDetails.get(PARAM_KEY_JDBC_URL); logger.debug("Connecting URL : " + connectionUrl); connection = DriverManager.getConnection(connectionUrl, paramDetails.get(PARAM_KEY_USER), paramDetails.get(PARAM_KEY_PWD)); if (connection == null) { logger.error("Unable to Connect to Database. URL = " + connectionUrl); return new StatusVO(Status.DOWN,"Unable to Connect to Database. URL = " + connectionUrl); } statement = connection.createStatement(); rs = statement.executeQuery(paramDetails.get(PARAM_KEY_QUERY)); if (!rs.next()){ logger.error("SQL Query returned no result Query : " + paramDetails.get(PARAM_KEY_QUERY)); return new StatusVO(Status.DOWN,"SQL Query returned no result Query : " + paramDetails.get(PARAM_KEY_QUERY)); } if(paramDetails.get(PARAM_KEY_EXPVALUE).equals(rs.getString(1))) { return new StatusVO(Status.UP); } else { logger.error("Expected Value does not match from Result returned. Returned result = " + rs.getString(1) + "; Expected result =" + paramDetails.get(PARAM_KEY_EXPVALUE)); return new StatusVO(Status.DOWN,"Expected Value does not match from Result returned. Returned result = " + rs.getString(1) + "; Expected result =" + paramDetails.get(PARAM_KEY_EXPVALUE)); } } catch(SQLException ue){ logger.error("Got SQLException : Unable to Connect to Database. URL = " + paramDetails.get(PARAM_KEY_JDBC_URL), ue); return new StatusVO(Status.DOWN,"Got SQLException : Unable to Connect to Database. URL = " + paramDetails.get(PARAM_KEY_JDBC_URL)); } catch (Exception e) { logger.error("Got Exception while connecting URL = " + paramDetails.get(PARAM_KEY_JDBC_URL), e); return new StatusVO(Status.DOWN,"Got Exception while connecting URL = " + paramDetails.get(PARAM_KEY_JDBC_URL)); }finally{ try { if (rs != null) { rs.close(); } if (statement != null) { statement.close(); } if (connection != null) { connection.close(); } } catch (SQLException e) { logger.error("Got Exception while disconnecting connecting URL = " + paramDetails.get(PARAM_KEY_JDBC_URL), e); }; } }  @Override StatusVO getSurveillerStatus(); }
DBHandler extends SurveillerHandler { @Override public StatusVO getSurveillerStatus() { Connection connection = null; Statement statement = null; ResultSet rs = null; try { if(paramDetails.get(PARAM_KEY_JDBC_URL) == null || paramDetails.get(PARAM_KEY_JDBC_DRIVER_CLASS) == null || paramDetails.get(PARAM_KEY_USER) == null || paramDetails.get(PARAM_KEY_PWD) == null || paramDetails.get(PARAM_KEY_QUERY) == null || paramDetails.get(PARAM_KEY_EXPVALUE) == null ){ logger.error("Configuration Error : The health check is not having all the mandatory parameters"); return new StatusVO(Status.DOWN, "Configuration Error : The health check is not having all the mandatory parameters"); } Class.forName(paramDetails.get(PARAM_KEY_JDBC_DRIVER_CLASS)).newInstance(); String connectionUrl = paramDetails.get(PARAM_KEY_JDBC_URL); logger.debug("Connecting URL : " + connectionUrl); connection = DriverManager.getConnection(connectionUrl, paramDetails.get(PARAM_KEY_USER), paramDetails.get(PARAM_KEY_PWD)); if (connection == null) { logger.error("Unable to Connect to Database. URL = " + connectionUrl); return new StatusVO(Status.DOWN,"Unable to Connect to Database. URL = " + connectionUrl); } statement = connection.createStatement(); rs = statement.executeQuery(paramDetails.get(PARAM_KEY_QUERY)); if (!rs.next()){ logger.error("SQL Query returned no result Query : " + paramDetails.get(PARAM_KEY_QUERY)); return new StatusVO(Status.DOWN,"SQL Query returned no result Query : " + paramDetails.get(PARAM_KEY_QUERY)); } if(paramDetails.get(PARAM_KEY_EXPVALUE).equals(rs.getString(1))) { return new StatusVO(Status.UP); } else { logger.error("Expected Value does not match from Result returned. Returned result = " + rs.getString(1) + "; Expected result =" + paramDetails.get(PARAM_KEY_EXPVALUE)); return new StatusVO(Status.DOWN,"Expected Value does not match from Result returned. Returned result = " + rs.getString(1) + "; Expected result =" + paramDetails.get(PARAM_KEY_EXPVALUE)); } } catch(SQLException ue){ logger.error("Got SQLException : Unable to Connect to Database. URL = " + paramDetails.get(PARAM_KEY_JDBC_URL), ue); return new StatusVO(Status.DOWN,"Got SQLException : Unable to Connect to Database. URL = " + paramDetails.get(PARAM_KEY_JDBC_URL)); } catch (Exception e) { logger.error("Got Exception while connecting URL = " + paramDetails.get(PARAM_KEY_JDBC_URL), e); return new StatusVO(Status.DOWN,"Got Exception while connecting URL = " + paramDetails.get(PARAM_KEY_JDBC_URL)); }finally{ try { if (rs != null) { rs.close(); } if (statement != null) { statement.close(); } if (connection != null) { connection.close(); } } catch (SQLException e) { logger.error("Got Exception while disconnecting connecting URL = " + paramDetails.get(PARAM_KEY_JDBC_URL), e); }; } }  @Override StatusVO getSurveillerStatus();  }