@Test public void testGetSurveillerStatus() 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("PORT","443"); paramList.put("IP","sa"); hcvo.setParamDetails(paramList); paramDetails = paramList; init(hcvo); StatusVO result =getSurveillerStatus(); }
@Override public StatusVO getSurveillerStatus() { if(paramDetails.get(PARAM_KEY_IP)==null || paramDetails.get(PARAM_KEY_PORT)==null ){ logger.error("The IP address and PORT is null"); throw new IllegalArgumentException("The IP & PORT cannot be null"); } Socket socket = new Socket(); try { socket.connect(new InetSocketAddress(paramDetails.get(PARAM_KEY_IP), Integer.parseInt(paramDetails.get(PARAM_KEY_PORT))), TIME_OUT); if(socket.isConnected()){ return new StatusVO(Status.UP); }else{ return new StatusVO(Status.DOWN,"Port is not open : " + " IP = " + paramDetails.get(PARAM_KEY_IP) + "; PORT = " + paramDetails.get(PARAM_KEY_PORT)); } }catch (Exception e) { logger.error("Got Exception while connecting to Socket", e); return new StatusVO(Status.DOWN, e.getMessage() + " : IP = " + paramDetails.get(PARAM_KEY_IP) + "; PORT = " + paramDetails.get(PARAM_KEY_PORT)); }finally{ try { socket.close(); } catch (IOException e) { logger.error("Got Exception while closing the connection", e); } } }
TCPHandler extends SurveillerHandler { @Override public StatusVO getSurveillerStatus() { if(paramDetails.get(PARAM_KEY_IP)==null || paramDetails.get(PARAM_KEY_PORT)==null ){ logger.error("The IP address and PORT is null"); throw new IllegalArgumentException("The IP & PORT cannot be null"); } Socket socket = new Socket(); try { socket.connect(new InetSocketAddress(paramDetails.get(PARAM_KEY_IP), Integer.parseInt(paramDetails.get(PARAM_KEY_PORT))), TIME_OUT); if(socket.isConnected()){ return new StatusVO(Status.UP); }else{ return new StatusVO(Status.DOWN,"Port is not open : " + " IP = " + paramDetails.get(PARAM_KEY_IP) + "; PORT = " + paramDetails.get(PARAM_KEY_PORT)); } }catch (Exception e) { logger.error("Got Exception while connecting to Socket", e); return new StatusVO(Status.DOWN, e.getMessage() + " : IP = " + paramDetails.get(PARAM_KEY_IP) + "; PORT = " + paramDetails.get(PARAM_KEY_PORT)); }finally{ try { socket.close(); } catch (IOException e) { logger.error("Got Exception while closing the connection", e); } } } }
TCPHandler extends SurveillerHandler { @Override public StatusVO getSurveillerStatus() { if(paramDetails.get(PARAM_KEY_IP)==null || paramDetails.get(PARAM_KEY_PORT)==null ){ logger.error("The IP address and PORT is null"); throw new IllegalArgumentException("The IP & PORT cannot be null"); } Socket socket = new Socket(); try { socket.connect(new InetSocketAddress(paramDetails.get(PARAM_KEY_IP), Integer.parseInt(paramDetails.get(PARAM_KEY_PORT))), TIME_OUT); if(socket.isConnected()){ return new StatusVO(Status.UP); }else{ return new StatusVO(Status.DOWN,"Port is not open : " + " IP = " + paramDetails.get(PARAM_KEY_IP) + "; PORT = " + paramDetails.get(PARAM_KEY_PORT)); } }catch (Exception e) { logger.error("Got Exception while connecting to Socket", e); return new StatusVO(Status.DOWN, e.getMessage() + " : IP = " + paramDetails.get(PARAM_KEY_IP) + "; PORT = " + paramDetails.get(PARAM_KEY_PORT)); }finally{ try { socket.close(); } catch (IOException e) { logger.error("Got Exception while closing the connection", e); } } }  }
TCPHandler extends SurveillerHandler { @Override public StatusVO getSurveillerStatus() { if(paramDetails.get(PARAM_KEY_IP)==null || paramDetails.get(PARAM_KEY_PORT)==null ){ logger.error("The IP address and PORT is null"); throw new IllegalArgumentException("The IP & PORT cannot be null"); } Socket socket = new Socket(); try { socket.connect(new InetSocketAddress(paramDetails.get(PARAM_KEY_IP), Integer.parseInt(paramDetails.get(PARAM_KEY_PORT))), TIME_OUT); if(socket.isConnected()){ return new StatusVO(Status.UP); }else{ return new StatusVO(Status.DOWN,"Port is not open : " + " IP = " + paramDetails.get(PARAM_KEY_IP) + "; PORT = " + paramDetails.get(PARAM_KEY_PORT)); } }catch (Exception e) { logger.error("Got Exception while connecting to Socket", e); return new StatusVO(Status.DOWN, e.getMessage() + " : IP = " + paramDetails.get(PARAM_KEY_IP) + "; PORT = " + paramDetails.get(PARAM_KEY_PORT)); }finally{ try { socket.close(); } catch (IOException e) { logger.error("Got Exception while closing the connection", e); } } }  @Override StatusVO getSurveillerStatus(); }
TCPHandler extends SurveillerHandler { @Override public StatusVO getSurveillerStatus() { if(paramDetails.get(PARAM_KEY_IP)==null || paramDetails.get(PARAM_KEY_PORT)==null ){ logger.error("The IP address and PORT is null"); throw new IllegalArgumentException("The IP & PORT cannot be null"); } Socket socket = new Socket(); try { socket.connect(new InetSocketAddress(paramDetails.get(PARAM_KEY_IP), Integer.parseInt(paramDetails.get(PARAM_KEY_PORT))), TIME_OUT); if(socket.isConnected()){ return new StatusVO(Status.UP); }else{ return new StatusVO(Status.DOWN,"Port is not open : " + " IP = " + paramDetails.get(PARAM_KEY_IP) + "; PORT = " + paramDetails.get(PARAM_KEY_PORT)); } }catch (Exception e) { logger.error("Got Exception while connecting to Socket", e); return new StatusVO(Status.DOWN, e.getMessage() + " : IP = " + paramDetails.get(PARAM_KEY_IP) + "; PORT = " + paramDetails.get(PARAM_KEY_PORT)); }finally{ try { socket.close(); } catch (IOException e) { logger.error("Got Exception while closing the connection", e); } } }  @Override StatusVO getSurveillerStatus();  }