List of usage examples for com.google.common.net HostAndPort fromParts
public static HostAndPort fromParts(String host, int port)
From source file:ws.prager.camel.consul.ConsulRegistry.java
private ConsulRegistry(Builder builder) { this.hostname = builder.hostname; this.port = builder.port; logger.debug("get consul client for: " + hostname + ":" + port); HostAndPort hostAndPort = HostAndPort.fromParts(hostname, port); this.consul = Consul.builder().withHostAndPort(hostAndPort).build(); }
From source file:org.apache.brooklyn.core.network.OnSubnetNetworkEnricher.java
@Override protected Optional<HostAndPort> getMappedEndpoint(Entity source, MachineLocation machine, int port) { String address = source.sensors().get(Attributes.SUBNET_ADDRESS); if (Strings.isNonBlank(address)) { return Optional.of(HostAndPort.fromParts(address, port)); } else {/*from ww w . ja v a2 s . c om*/ return Optional.absent(); } }
From source file:org.jclouds.proxy.internal.GuiceProxyConfig.java
@Override public Optional<HostAndPort> getProxy() { if (host == null) return Optional.absent(); Integer port = this.port; if (port == null) { switch (type) { case HTTP: port = 80;/* w w w . j av a 2 s .c o m*/ break; case SOCKS: port = 1080; break; default: throw new IllegalArgumentException(type + " not supported"); } } return Optional.of(HostAndPort.fromParts(host, port)); }
From source file:gobblin.source.extractor.extract.kafka.KafkaPartition.java
public void setLeader(int leaderId, String leaderHost, int leaderPort) { this.leader = new KafkaLeader(leaderId, HostAndPort.fromParts(leaderHost, leaderPort)); }
From source file:com.facebook.presto.jdbc.QueryExecutor.java
@Nullable private static HostAndPort getSystemSocksProxy() { URI uri = URI.create("socket://0.0.0.0:80"); for (Proxy proxy : ProxySelector.getDefault().select(uri)) { if (proxy.type() == Proxy.Type.SOCKS) { if (proxy.address() instanceof InetSocketAddress) { InetSocketAddress address = (InetSocketAddress) proxy.address(); return HostAndPort.fromParts(address.getHostString(), address.getPort()); }// w w w. j a va 2 s .c om } } return null; }
From source file:org.apache.aurora.scheduler.http.LeaderRedirect.java
private Optional<HostAndPort> getLeaderHttp() { Optional<ServiceInstance> leadingScheduler = getLeader(); if (leadingScheduler.isPresent() && leadingScheduler.get().isSetServiceEndpoint()) { Endpoint leaderHttp = leadingScheduler.get().getServiceEndpoint(); if (leaderHttp != null && leaderHttp.isSetHost() && leaderHttp.isSetPort()) { return Optional.of(HostAndPort.fromParts(leaderHttp.getHost(), leaderHttp.getPort())); }/* w w w. j av a 2s .c om*/ } LOG.warn("Leader service instance seems to be incomplete: " + leadingScheduler); return Optional.absent(); }
From source file:com.pinterest.secor.common.KafkaClient.java
private HostAndPort findLeader(TopicPartition topicPartition) { SimpleConsumer consumer = null;// w w w . ja v a2 s . c o m try { LOG.info("looking up leader for topic {} partition {}", topicPartition.getTopic(), topicPartition.getPartition()); consumer = createConsumer(mConfig.getKafkaSeedBrokerHost(), mConfig.getKafkaSeedBrokerPort(), "leaderLookup"); List<String> topics = new ArrayList<String>(); topics.add(topicPartition.getTopic()); TopicMetadataRequest request = new TopicMetadataRequest(topics); TopicMetadataResponse response = consumer.send(request); List<TopicMetadata> metaData = response.topicsMetadata(); for (TopicMetadata item : metaData) { for (PartitionMetadata part : item.partitionsMetadata()) { if (part.partitionId() == topicPartition.getPartition()) { return HostAndPort.fromParts(part.leader().host(), part.leader().port()); } } } } finally { if (consumer != null) { consumer.close(); } } return null; }
From source file:org.jclouds.vsphere.functions.VirtualMachineToSshClient.java
@Override public SshClient apply(final VirtualMachine vm) { SshClient client = null;/*w w w . ja v a 2s.c om*/ String clientIpAddress = vm.getGuest().getIpAddress(); String sshPort = "22"; while (!vm.getGuest().getToolsStatus().equals(VirtualMachineToolsStatus.toolsOk) || clientIpAddress.isEmpty()) { int timeoutValue = 1000; int timeoutUnits = 500; Predicate<String> tester = Predicates2.retry(ipAddressTester, timeoutValue, timeoutUnits, TimeUnit.MILLISECONDS); boolean passed = false; while (vm.getRuntime().getPowerState().equals(VirtualMachinePowerState.poweredOn) && !passed) { clientIpAddress = Strings.nullToEmpty(vm.getGuest().getIpAddress()); passed = tester.apply(clientIpAddress); } } LoginCredentials loginCredentials = LoginCredentials.builder().user("root").password(password).build(); checkNotNull(clientIpAddress, "clientIpAddress"); client = sshClientFactory.create(HostAndPort.fromParts(clientIpAddress, Integer.parseInt(sshPort)), loginCredentials); checkNotNull(client); return client; }
From source file:com.dropbox.presto.kafka.KafkaHiveClient.java
public static com.facebook.presto.hive.HiveCluster createHiveCluster(KafkaPluginConfig kafkaPluginConfig, KafkaClientConfig config) {//from ww w . j a va2 s . co m URI uri = checkNotNull(kafkaPluginConfig.getMetastoreUri(), "metastoreUri is null"); String scheme = uri.getScheme(); checkArgument(!isNullOrEmpty(scheme), "metastoreUri scheme is missing: %s", uri); if (scheme.equalsIgnoreCase("thrift")) { checkArgument(uri.getHost() != null, "metastoreUri host is missing: %s", uri); checkArgument(uri.getPort() != -1, "metastoreUri port is missing: %s", uri); HostAndPort address = HostAndPort.fromParts(uri.getHost(), uri.getPort()); com.facebook.presto.hive.HiveMetastoreClientFactory factory = new com.facebook.presto.hive.HiveMetastoreClientFactory( config.getMetastoreSocksProxy(), config.getMetastoreTimeout()); return new com.facebook.presto.hive.StaticHiveCluster(address, factory); } throw new IllegalArgumentException("unsupported metastoreUri: " + uri); }
From source file:com.groupon.mesos.scheduler.SchedulerDriverContext.java
SchedulerDriverContext(final FrameworkInfo frameworkInfo) throws IOException { this.frameworkInfo.set(checkNotNull(frameworkInfo, "frameworkInfo is null")); this.driverUpid = UPID.fromParts(UUID.randomUUID().toString(), HostAndPort.fromParts(frameworkInfo.getHostname(), NetworkUtil.findUnusedPort())); // If the framework info sent in has an id, we are in failover mode from the start. failover.set(hasFrameworkId(frameworkInfo)); }