public Socket createSocket(StarterNode host, int port) throws IOException { if(!isStarted()) return null; Resolver r = host.find(Resolver.class); if(r == null || !r.isStarted()) return null; Socket s = getSocket(); s.connect(new InetSocketAddress(r.getInetAddress(), port), getTimeout()); return s; }
public Resolver(String hostname) { this.hostname = hostname; log(Level.DEBUG, "New dns resolver"); }
@Test public void testStart() throws Exception { MockHttpServer server = new MockHttpServer(false); server.addResourceHandler(staticFiles); server.start(); HttpClientStarter cnx = new HttpClientStarter(); HostStarter localhost = addConnection(cnx); localhost.find(SSLStarter.class).doStart(); localhost.find(Resolver.class).doStart(); logger.debug("resolver started for localhost:" + localhost.find(Resolver.class).isStarted()); cnx.doStart(); Assert.assertTrue("Apache HttpClient failed to start", cnx.isStarted()); cnx.stop(); server.stop(); }
@Override public boolean startConnection() { boolean started = false; if(getResolver().isStarted()) { try { DriverManager.setLoginTimeout(getTimeout()); con = DriverManager.getConnection(url, user, passwd); started = true; } catch (SQLException e) { log(Level.ERROR, e, "Sql error for %s: %s", url, e); } } return started; }
public HostStarter(HostInfo host) { super(); this.host = host; this.runningname = host.getName() + ":notrunning"; registerStarter(new Resolver(host.getDnsName())); }
@Test public void testConnectTwice() throws Exception { MockHttpServer server = new MockHttpServer(false); server.addResourceHandler(staticFiles); server.start(); HttpClientStarter cnx = new HttpClientStarter(); HostStarter localhost = addConnection(cnx); localhost.find(Resolver.class).doStart(); cnx.doStart(); TestHttpProbe p = new TestHttpProbe(); p.setMainStore(new RrdDbStoreFactory(), empty); p.setHost(localhost); p.setPort(server.getURI().toURL().getPort()); p.configure(); p.checkStore(); localhost.addProbe(p); localhost.getParent().startCollect(); // Run twice, to detect failure management in the probe localhost.collectAll(); shouldFail = false; Thread.sleep(1500); localhost.collectAll(); Assert.assertTrue("Didn't try to collect", p.collected); server.stop(); }
@Override public boolean start() { if(!getResolver().isStarted()) return false; boolean started = startConnection(); if(started) { uptime = setUptime(); log(Level.DEBUG, "Uptime for %s = %ds", this, uptime); } return started; }
resolver = getParent().registerStarter(new Resolver(url.getHost()));
@Test public void testConnectSSL() throws Exception { MockHttpServer server = new MockHttpServer(true); server.addResourceHandler(staticFiles); server.start(); HttpClientStarter cnx = new HttpClientStarter(); HostStarter localhost = addConnection(cnx); localhost.find(Resolver.class).doStart(); localhost.find(SSLStarter.class).doStart(); cnx.doStart(); TestHttpProbe p = new TestHttpProbe(); p.setMainStore(new RrdDbStoreFactory(), empty); p.setHost(localhost); p.setPort(server.getURI().toURL().getPort()); p.setScheme("https"); p.configure(); p.checkStore(); localhost.addProbe(p); localhost.getParent().startCollect(); Assert.assertTrue(p.find(SSLStarter.class).isStarted()); shouldFail = false; localhost.collectAll(); Assert.assertTrue("Didn't try to collect", p.collected); server.stop(); }
@Override public Map<String, Number> getNewSampleValues() { Resolver resolv = find(Resolver.class); if(!resolv.isStarted()) return null; try { TimeInfo ti = client.getTime(resolv.getInetAddress(), port); ti.computeDetails(); NtpV3Packet pkct = ti.getMessage(); Map<String, Number> retValues = new HashMap<String, Number>(4); retValues.put("RootDelay", pkct.getRootDelayInMillisDouble()); retValues.put("RootDispersion", pkct.getRootDispersionInMillisDouble()); retValues.put("Offset", ti.getOffset()); retValues.put("Delay", ti.getDelay()); return retValues; } catch (IOException e) { log(Level.ERROR, e, "NTP IO exception %s", e); } return null; }
@Override public void configure(PropertiesManager pm) { super.configure(pm); starterKey = getLevel().getParent().registerStarter(new Resolver(bmcname)).getKey(); }
@Override public boolean start() { boolean started = false; try { address = InetAddress.getByName(hostname); started = true; } catch (UnknownHostException e) { log(Level.ERROR, e, "DNS host name %s can't be found", hostname); } return started; }
@Override public boolean startConnection() { Resolver resolver = getLevel().find(Resolver.class, starterKey); if(resolver == null || !resolver.isStarted()) { return false; ConnectionHandle handle = connector.createConnection(resolver.getInetAddress()); connector.setTimeout(handle, getTimeout() * 1000);
public Resolver getResolver() { String hostName = getHostName(); Resolver r = getLevel().find(Resolver.class); if(r == null) { r = new Resolver(hostName); getLevel().registerStarter(r); } return r; }
@Override public boolean startConnection() { Resolver resolver = getLevel().find(Resolver.class); if(!resolver.isStarted()) return false; address = new UdpAddress(resolver.getInetAddress(), port); } else if(TCP.equals(proto.toLowerCase())) { address = new TcpAddress(resolver.getInetAddress(), port); } else { return false;