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;
}
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;
}
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)));
}
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));
}
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);
}
Aggregations