Search in sources :

Example 1 with HostAndPort

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;
}
Also used : HostAndPort(com.google.common.net.HostAndPort) IAE(io.druid.java.util.common.IAE)

Example 2 with HostAndPort

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);
}
Also used : HashMap(java.util.HashMap) IOException(java.io.IOException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) HostAndPort(com.google.common.net.HostAndPort) KeeperException(org.apache.zookeeper.KeeperException)

Example 3 with HostAndPort

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);
}
Also used : HostAndPort(com.google.common.net.HostAndPort) Announcer(io.druid.curator.announcement.Announcer) Test(org.junit.Test)

Example 4 with HostAndPort

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);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Request(com.metamx.http.client.Request) AtomicReference(java.util.concurrent.atomic.AtomicReference) Duration(org.joda.time.Duration) SequenceInputStreamResponseHandler(com.metamx.http.client.response.SequenceInputStreamResponseHandler) HostAndPort(com.google.common.net.HostAndPort) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ByteArrayInputStream(java.io.ByteArrayInputStream) Test(org.junit.Test)

Example 5 with HostAndPort

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());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Request(com.metamx.http.client.Request) AtomicReference(java.util.concurrent.atomic.AtomicReference) Duration(org.joda.time.Duration) SequenceInputStreamResponseHandler(com.metamx.http.client.response.SequenceInputStreamResponseHandler) HostAndPort(com.google.common.net.HostAndPort) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ByteArrayInputStream(java.io.ByteArrayInputStream) Test(org.junit.Test)

Aggregations

HostAndPort (com.google.common.net.HostAndPort)45 IOException (java.io.IOException)8 Test (org.junit.Test)7 InetSocketAddress (java.net.InetSocketAddress)5 InputStream (java.io.InputStream)4 ArrayList (java.util.ArrayList)4 Request (com.metamx.http.client.Request)3 SequenceInputStreamResponseHandler (com.metamx.http.client.response.SequenceInputStreamResponseHandler)3 SystemException (com.torodb.core.exceptions.SystemException)3 JCommander (com.beust.jcommander.JCommander)2 Console (com.beust.jcommander.internal.Console)2 OpTime (com.eightkdata.mongowp.OpTime)2 UnreachableMongoServerException (com.eightkdata.mongowp.client.core.UnreachableMongoServerException)2 MongoException (com.eightkdata.mongowp.exceptions.MongoException)2 Charsets (com.google.common.base.Charsets)2 Throwables (com.google.common.base.Throwables)2 Service (com.google.common.util.concurrent.Service)2 CreationException (com.google.inject.CreationException)2 NoSyncSourceFoundException (com.torodb.mongodb.repl.exceptions.NoSyncSourceFoundException)2 BackendPasswordConfig (com.torodb.packaging.config.model.backend.BackendPasswordConfig)2