use of com.google.common.net.HostAndPort in project druid by druid-io.
the class DruidNode method init.
private void init(String serviceName, String host, Integer port) {
Preconditions.checkNotNull(serviceName);
this.serviceName = serviceName;
if (host == null && port == null) {
host = getDefaultHost();
port = -1;
} else {
final HostAndPort hostAndPort;
if (host != null) {
hostAndPort = HostAndPort.fromString(host);
if (port != null && hostAndPort.hasPort() && port != hostAndPort.getPort()) {
throw new IAE("Conflicting host:port [%s] and port [%d] settings", host, port);
}
} else {
hostAndPort = HostAndPort.fromParts(getDefaultHost(), port);
}
host = hostAndPort.getHostText();
if (hostAndPort.hasPort()) {
port = hostAndPort.getPort();
}
if (port == null) {
port = SocketUtil.findOpenPort(8080);
}
}
this.port = port;
this.host = host;
}
use of com.google.common.net.HostAndPort in project druid by druid-io.
the class ListenerDiscoverer method getCurrentNodes.
Map<HostAndPort, Long> getCurrentNodes(final String listener_key) throws IOException {
final HashMap<HostAndPort, Long> retVal = new HashMap<>();
final String zkPath = listeningAnnouncerConfig.getAnnouncementPath(listener_key);
final Collection<String> children;
try {
children = cf.getChildren().forPath(zkPath);
} catch (org.apache.zookeeper.KeeperException.NoNodeException e) {
LOG.debug(e, "No path found at [%s]", zkPath);
return ImmutableMap.of();
} catch (Exception e) {
throw new IOException("Error getting children for " + zkPath, e);
}
for (String child : children) {
final String childPath = ZKPaths.makePath(zkPath, child);
try {
final byte[] data;
try {
data = cf.getData().decompressed().forPath(childPath);
} catch (Exception e) {
throw new IOException("Error getting data for " + childPath, e);
}
if (data == null) {
LOG.debug("Lost data at path [%s]", childPath);
continue;
}
final HostAndPort hostAndPort = HostAndPort.fromString(child);
final Long l = ByteBuffer.wrap(data).getLong();
retVal.put(hostAndPort, l);
} catch (IllegalArgumentException iae) {
LOG.warn(iae, "Error parsing [%s]", childPath);
}
}
return ImmutableMap.copyOf(retVal);
}
use of com.google.common.net.HostAndPort in project druid by druid-io.
the class ListenerResourceAnnouncerTest method testStartCorrect.
@Test
public void testStartCorrect() throws Exception {
final Announcer announcer = EasyMock.createStrictMock(Announcer.class);
final HostAndPort node = HostAndPort.fromString("some_host");
final ListenerResourceAnnouncer resourceAnnouncer = new ListenerResourceAnnouncer(announcer, listeningAnnouncerConfig, listenerKey, node) {
};
announcer.announce(EasyMock.eq(ZKPaths.makePath(announcePath, node.getHostText())), EasyMock.aryEq(resourceAnnouncer.getAnnounceBytes()));
EasyMock.expectLastCall().once();
EasyMock.replay(announcer);
resourceAnnouncer.start();
EasyMock.verify(announcer);
}
use of com.google.common.net.HostAndPort in project druid by druid-io.
the class LookupCoordinatorManagerTest method testDeleteAllTierMissing.
@Test
public void testDeleteAllTierMissing() throws Exception {
final HttpResponseHandler<InputStream, InputStream> responseHandler = EasyMock.createStrictMock(HttpResponseHandler.class);
final LookupCoordinatorManager manager = new LookupCoordinatorManager(client, discoverer, mapper, configManager, lookupCoordinatorManagerConfig) {
@Override
HttpResponseHandler<InputStream, InputStream> makeResponseHandler(final AtomicInteger returnCode, final AtomicReference<String> reasonString) {
returnCode.set(404);
reasonString.set("");
return responseHandler;
}
};
final HostAndPort hostAndPort = HostAndPort.fromParts("someHost", 8080);
final Collection<String> drop = ImmutableList.of("lookup1");
EasyMock.expect(discoverer.getNodes(LookupModule.getTierListenerPath(LOOKUP_TIER))).andReturn(ImmutableList.of(hostAndPort)).once();
final SettableFuture<InputStream> future = SettableFuture.create();
future.set(new ByteArrayInputStream(new byte[0]));
EasyMock.expect(client.go(EasyMock.<Request>anyObject(), EasyMock.<SequenceInputStreamResponseHandler>anyObject(), EasyMock.<Duration>anyObject())).andReturn(future).once();
EasyMock.replay(client, discoverer, responseHandler);
manager.deleteAllOnTier(LOOKUP_TIER, drop);
EasyMock.verify(client, discoverer, responseHandler);
}
use of com.google.common.net.HostAndPort in project druid by druid-io.
the class LookupCoordinatorManagerTest method testDeleteAllTierContinuesOnMissing.
@Test
public void testDeleteAllTierContinuesOnMissing() throws Exception {
final HttpResponseHandler<InputStream, InputStream> responseHandler = EasyMock.createStrictMock(HttpResponseHandler.class);
final AtomicInteger responseHandlerCalls = new AtomicInteger(0);
final LookupCoordinatorManager manager = new LookupCoordinatorManager(client, discoverer, mapper, configManager, lookupCoordinatorManagerConfig) {
@Override
HttpResponseHandler<InputStream, InputStream> makeResponseHandler(final AtomicInteger returnCode, final AtomicReference<String> reasonString) {
if (responseHandlerCalls.getAndIncrement() == 0) {
returnCode.set(404);
reasonString.set("Not Found");
} else {
returnCode.set(202);
reasonString.set("");
}
return responseHandler;
}
};
final HostAndPort hostAndPort = HostAndPort.fromParts("someHost", 8080);
final Collection<String> drop = ImmutableList.of("lookup1");
EasyMock.expect(discoverer.getNodes(LookupModule.getTierListenerPath(LOOKUP_TIER))).andReturn(ImmutableList.of(hostAndPort, hostAndPort)).once();
final SettableFuture<InputStream> future = SettableFuture.create();
future.set(new ByteArrayInputStream(new byte[0]));
EasyMock.expect(client.go(EasyMock.<Request>anyObject(), EasyMock.<SequenceInputStreamResponseHandler>anyObject(), EasyMock.<Duration>anyObject())).andReturn(future).times(2);
EasyMock.replay(client, discoverer, responseHandler);
manager.deleteAllOnTier(LOOKUP_TIER, drop);
EasyMock.verify(client, discoverer, responseHandler);
Assert.assertEquals(2, responseHandlerCalls.get());
}
Aggregations