@Test public void testGetServiceStatusEmptyServiceList() throws Exception { PortServiceStatusProvider fixture = new PortServiceStatusProvider(); List<ComponentService> services = new LinkedList(); Map<String, Boolean> result = fixture.getServiceStatus(services); assertNotNull(result); assertEquals(0, result.size()); }
public Map<String, Boolean> getServiceStatus(List<ComponentService> services) { Map<String, Boolean> processStatus = new HashMap<String, Boolean>(); for (ComponentService service : services) { String processName = service.getName(); String port = service.getParameters().get("port"); Result rs = new Result(); try { String[] cmd = { "/bin/sh", "-c", "netstat -nl | grep ':" + port + " '" }; rs = CommandExecutor.executeCommand(cmd); } catch (Exception e) { LOGGER.error(e.getMessage(), e); processStatus.put(service.getRole(), false); } processStatus.put(service.getRole(), false); if (rs.getExitVal() == 0) { processStatus.put(service.getRole(), true); } LOGGER.info(processName + ":" + port + " status - " + processStatus); } return processStatus; }
PortServiceStatusProvider extends ServiceProvider { public Map<String, Boolean> getServiceStatus(List<ComponentService> services) { Map<String, Boolean> processStatus = new HashMap<String, Boolean>(); for (ComponentService service : services) { String processName = service.getName(); String port = service.getParameters().get("port"); Result rs = new Result(); try { String[] cmd = { "/bin/sh", "-c", "netstat -nl | grep ':" + port + " '" }; rs = CommandExecutor.executeCommand(cmd); } catch (Exception e) { LOGGER.error(e.getMessage(), e); processStatus.put(service.getRole(), false); } processStatus.put(service.getRole(), false); if (rs.getExitVal() == 0) { processStatus.put(service.getRole(), true); } LOGGER.info(processName + ":" + port + " status - " + processStatus); } return processStatus; } }
PortServiceStatusProvider extends ServiceProvider { public Map<String, Boolean> getServiceStatus(List<ComponentService> services) { Map<String, Boolean> processStatus = new HashMap<String, Boolean>(); for (ComponentService service : services) { String processName = service.getName(); String port = service.getParameters().get("port"); Result rs = new Result(); try { String[] cmd = { "/bin/sh", "-c", "netstat -nl | grep ':" + port + " '" }; rs = CommandExecutor.executeCommand(cmd); } catch (Exception e) { LOGGER.error(e.getMessage(), e); processStatus.put(service.getRole(), false); } processStatus.put(service.getRole(), false); if (rs.getExitVal() == 0) { processStatus.put(service.getRole(), true); } LOGGER.info(processName + ":" + port + " status - " + processStatus); } return processStatus; }  }
PortServiceStatusProvider extends ServiceProvider { public Map<String, Boolean> getServiceStatus(List<ComponentService> services) { Map<String, Boolean> processStatus = new HashMap<String, Boolean>(); for (ComponentService service : services) { String processName = service.getName(); String port = service.getParameters().get("port"); Result rs = new Result(); try { String[] cmd = { "/bin/sh", "-c", "netstat -nl | grep ':" + port + " '" }; rs = CommandExecutor.executeCommand(cmd); } catch (Exception e) { LOGGER.error(e.getMessage(), e); processStatus.put(service.getRole(), false); } processStatus.put(service.getRole(), false); if (rs.getExitVal() == 0) { processStatus.put(service.getRole(), true); } LOGGER.info(processName + ":" + port + " status - " + processStatus); } return processStatus; }  Map<String, Boolean> getServiceStatus(List<ComponentService> services); }
PortServiceStatusProvider extends ServiceProvider { public Map<String, Boolean> getServiceStatus(List<ComponentService> services) { Map<String, Boolean> processStatus = new HashMap<String, Boolean>(); for (ComponentService service : services) { String processName = service.getName(); String port = service.getParameters().get("port"); Result rs = new Result(); try { String[] cmd = { "/bin/sh", "-c", "netstat -nl | grep ':" + port + " '" }; rs = CommandExecutor.executeCommand(cmd); } catch (Exception e) { LOGGER.error(e.getMessage(), e); processStatus.put(service.getRole(), false); } processStatus.put(service.getRole(), false); if (rs.getExitVal() == 0) { processStatus.put(service.getRole(), true); } LOGGER.info(processName + ":" + port + " status - " + processStatus); } return processStatus; }  Map<String, Boolean> getServiceStatus(List<ComponentService> services);  }