Search in sources :

Example 26 with HostAndPort

use of com.google.common.net.HostAndPort in project intellij-community by JetBrains.

the class HttpProxySettingsUi method isValid.

private boolean isValid() {
    if (myUseHTTPProxyRb.isSelected()) {
        String host = getText(myProxyHostTextField);
        if (host == null) {
            return false;
        }
        try {
            HostAndPort parsedHost = HostAndPort.fromString(host);
            if (parsedHost.hasPort()) {
                return false;
            }
            host = parsedHost.getHostText();
            try {
                InetAddresses.forString(host);
                return true;
            } catch (IllegalArgumentException e) {
            // it is not an IPv4 or IPv6 literal
            }
            InternetDomainName.from(host);
        } catch (IllegalArgumentException e) {
            return false;
        }
        if (myProxyAuthCheckBox.isSelected()) {
            return !StringUtil.isEmptyOrSpaces(myProxyLoginTextField.getText()) && myProxyPasswordTextField.getPassword().length > 0;
        }
    }
    return true;
}
Also used : HostAndPort(com.google.common.net.HostAndPort)

Example 27 with HostAndPort

use of com.google.common.net.HostAndPort in project druid by druid-io.

the class KafkaSimpleConsumer method findLeader.

private PartitionMetadata findLeader() throws InterruptedException {
    for (HostAndPort broker : replicaBrokers) {
        SimpleConsumer consumer = null;
        try {
            log.info("Finding new leader from Kafka brokers, try broker [%s]", broker.toString());
            consumer = new SimpleConsumer(broker.getHostText(), broker.getPort(), SO_TIMEOUT, BUFFER_SIZE, leaderLookupClientId);
            TopicMetadataResponse resp = consumer.send(new TopicMetadataRequest(Collections.singletonList(topic)));
            List<TopicMetadata> metaData = resp.topicsMetadata();
            for (TopicMetadata item : metaData) {
                if (topic.equals(item.topic())) {
                    for (PartitionMetadata part : item.partitionsMetadata()) {
                        if (part.partitionId() == partitionId) {
                            return part;
                        }
                    }
                }
            }
        } catch (Exception e) {
            ensureNotInterrupted(e);
            log.warn(e, "error communicating with Kafka Broker [%s] to find leader for [%s] - [%s]", broker, topic, partitionId);
        } finally {
            if (consumer != null) {
                consumer.close();
            }
        }
    }
    return null;
}
Also used : HostAndPort(com.google.common.net.HostAndPort) TopicMetadataRequest(kafka.javaapi.TopicMetadataRequest) TopicMetadataResponse(kafka.javaapi.TopicMetadataResponse) PartitionMetadata(kafka.javaapi.PartitionMetadata) SimpleConsumer(kafka.javaapi.consumer.SimpleConsumer) TopicMetadata(kafka.javaapi.TopicMetadata)

Example 28 with HostAndPort

use of com.google.common.net.HostAndPort in project druid by druid-io.

the class ListenerDiscovererTest method testFullService.

@Test(timeout = 60_000L)
public void testFullService() throws Exception {
    final String listenerKey = "listenerKey";
    final String listenerTier = "listenerTier";
    final String listenerTierChild = "tierChild";
    final String tierZkPath = ZKPaths.makePath(listenerTier, listenerTierChild);
    setupServerAndCurator();
    final ExecutorService executorService = Execs.singleThreaded("listenerDiscovererTest--%s");
    closerRule.closeLater(new Closeable() {

        @Override
        public void close() throws IOException {
            executorService.shutdownNow();
        }
    });
    closerRule.closeLater(server);
    closerRule.closeLater(curator);
    curator.start();
    curator.blockUntilConnected(10, TimeUnit.SECONDS);
    Assert.assertEquals("/druid", curator.create().forPath("/druid"));
    final Announcer announcer = new Announcer(curator, executorService);
    closerRule.closeLater(new Closeable() {

        @Override
        public void close() throws IOException {
            announcer.stop();
        }
    });
    final ListeningAnnouncerConfig config = new ListeningAnnouncerConfig(new ZkPathsConfig());
    final ListenerDiscoverer listenerDiscoverer = new ListenerDiscoverer(curator, config);
    listenerDiscoverer.start();
    closerRule.closeLater(new Closeable() {

        @Override
        public void close() throws IOException {
            listenerDiscoverer.stop();
        }
    });
    Assert.assertTrue(listenerDiscoverer.getNodes(listenerKey).isEmpty());
    final HostAndPort node = HostAndPort.fromParts("someHost", 8888);
    final ListenerResourceAnnouncer listenerResourceAnnouncer = new ListenerResourceAnnouncer(announcer, config, listenerKey, node) {
    };
    listenerResourceAnnouncer.start();
    closerRule.closeLater(new Closeable() {

        @Override
        public void close() throws IOException {
            listenerResourceAnnouncer.stop();
        }
    });
    final ListenerResourceAnnouncer tieredListenerResourceAnnouncer = new ListenerResourceAnnouncer(announcer, config, tierZkPath, node) {
    };
    tieredListenerResourceAnnouncer.start();
    closerRule.closeLater(new Closeable() {

        @Override
        public void close() throws IOException {
            tieredListenerResourceAnnouncer.stop();
        }
    });
    announcer.start();
    Assert.assertNotNull(curator.checkExists().forPath(config.getAnnouncementPath(listenerKey)));
    // Have to wait for background syncing
    while (listenerDiscoverer.getNodes(listenerKey).isEmpty()) {
        // Will timeout at test's timeout setting
        Thread.sleep(1);
    }
    Assert.assertEquals(ImmutableSet.of(HostAndPort.fromString(node.toString())), listenerDiscoverer.getNodes(listenerKey));
    // 2nd call of two concurrent getNewNodes should return no entry collection
    listenerDiscoverer.getNewNodes(listenerKey);
    Assert.assertEquals(0, listenerDiscoverer.getNewNodes(listenerKey).size());
    Assert.assertEquals(ImmutableSet.of(listenerKey, listenerTier), ImmutableSet.copyOf(listenerDiscoverer.discoverChildren(null)));
    Assert.assertEquals(ImmutableSet.of(listenerTierChild), ImmutableSet.copyOf(listenerDiscoverer.discoverChildren(listenerTier)));
}
Also used : HostAndPort(com.google.common.net.HostAndPort) Announcer(io.druid.curator.announcement.Announcer) ZkPathsConfig(io.druid.server.initialization.ZkPathsConfig) Closeable(java.io.Closeable) ExecutorService(java.util.concurrent.ExecutorService) IOException(java.io.IOException) Test(org.junit.Test)

Example 29 with HostAndPort

use of com.google.common.net.HostAndPort in project druid by druid-io.

the class ListenerResourceAnnouncerTest method testAnnouncerBehaves.

@Test
public void testAnnouncerBehaves() throws Exception {
    setupServerAndCurator();
    closerRule.closeLater(server);
    curator.start();
    closerRule.closeLater(curator);
    Assert.assertNotNull(curator.create().forPath("/druid"));
    Assert.assertTrue(curator.blockUntilConnected(10, TimeUnit.SECONDS));
    final Announcer announcer = new Announcer(curator, executorService);
    final HostAndPort node = HostAndPort.fromString("localhost");
    final ListenerResourceAnnouncer listenerResourceAnnouncer = new ListenerResourceAnnouncer(announcer, listeningAnnouncerConfig, listenerKey, node) {
    };
    listenerResourceAnnouncer.start();
    announcer.start();
    closerRule.closeLater(new Closeable() {

        @Override
        public void close() throws IOException {
            announcer.stop();
        }
    });
    Assert.assertNotNull(curator.checkExists().forPath(announcePath));
    final String nodePath = ZKPaths.makePath(announcePath, node.getHostText());
    Assert.assertNotNull(curator.checkExists().forPath(nodePath));
    Assert.assertEquals(Longs.BYTES, curator.getData().decompressed().forPath(nodePath).length);
    Assert.assertNull(curator.checkExists().forPath(listeningAnnouncerConfig.getAnnouncementPath(listenerKey + "FOO")));
    listenerResourceAnnouncer.stop();
    listenerResourceAnnouncer.start();
    listenerResourceAnnouncer.start();
    listenerResourceAnnouncer.stop();
    listenerResourceAnnouncer.stop();
    listenerResourceAnnouncer.start();
    listenerResourceAnnouncer.stop();
    listenerResourceAnnouncer.start();
    listenerResourceAnnouncer.stop();
    Assert.assertNull(curator.checkExists().forPath(nodePath));
}
Also used : HostAndPort(com.google.common.net.HostAndPort) Announcer(io.druid.curator.announcement.Announcer) Closeable(java.io.Closeable) IOException(java.io.IOException) Test(org.junit.Test)

Example 30 with HostAndPort

use of com.google.common.net.HostAndPort in project druid by druid-io.

the class LookupCoordinatorManagerTest method testDeleteAllTier.

@Test
public void testDeleteAllTier() 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(200);
            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)

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