List of usage examples for com.google.common.net HostAndPort fromParts
public static HostAndPort fromParts(String host, int port)
From source file:com.facebook.swift.service.unframed.UnframedTestSuite.java
private <T> ListenableFuture<T> createUnframedClient(ThriftClientManager clientManager, Class<T> clientType, int servicePort) throws Exception { return clientManager.createClient( new UnframedClientConnector(HostAndPort.fromParts("localhost", servicePort)), clientType); }
From source file:io.prestosql.jdbc.PrestoDriverUri.java
private PrestoDriverUri(URI uri, Properties driverProperties) throws SQLException { this.uri = requireNonNull(uri, "uri is null"); address = HostAndPort.fromParts(uri.getHost(), uri.getPort()); properties = mergeConnectionProperties(uri, driverProperties); validateConnectionProperties(properties); // enable SSL by default for standard port useSecureConnection = SSL.getValue(properties).orElse(uri.getPort() == 443); initCatalogAndSchema();/*from w ww. j av a 2 s .c o m*/ }
From source file:ezbake.discovery.stethoscope.server.StethoscopeServiceHandler.java
@VisibleForTesting static String endpointToString(Endpoint endpoint) { return HostAndPort.fromParts(endpoint.getHostname(), endpoint.getPort()).toString(); }
From source file:org.jclouds.virtualbox.functions.IMachineToSshClient.java
@Override public SshClient apply(final IMachine vm) { String sshPort = "22"; String guestIdentity = vm.getExtraData(GUEST_OS_USER); String guestCredential = vm.getExtraData(GUEST_OS_PASSWORD); LoginCredentials loginCredentials = LoginCredentials.builder().user(guestIdentity).password(guestCredential) .authenticateSudo(true).build(); String clientIpAddress = null; long nicSlot = 0; while (nicSlot < 4 && Strings.isNullOrEmpty(clientIpAddress)) { INetworkAdapter networkAdapter = vm.getNetworkAdapter(nicSlot); if (networkAdapter.getAttachmentType().equals(NetworkAttachmentType.NAT)) { for (String nameProtocolnumberAddressInboudportGuestTargetport : networkAdapter.getNATEngine() .getRedirects()) {/* w w w .j av a 2 s .co m*/ Iterable<String> stuff = Splitter.on(',') .split(nameProtocolnumberAddressInboudportGuestTargetport); String protocolNumber = Iterables.get(stuff, 1); String hostAddress = Iterables.get(stuff, 2); String inboundPort = Iterables.get(stuff, 3); String targetPort = Iterables.get(stuff, 5); if ("1".equals(protocolNumber) && "22".equals(targetPort)) { clientIpAddress = hostAddress; sshPort = inboundPort; } } } else if (networkAdapter.getAttachmentType().equals(NetworkAttachmentType.Bridged)) { clientIpAddress = networkUtils.getIpAddressFromNicSlot(vm.getName(), networkAdapter.getSlot()); } else if (networkAdapter.getAttachmentType().equals(NetworkAttachmentType.HostOnly)) { clientIpAddress = networkUtils.getValidHostOnlyIpFromVm(vm.getName()); } nicSlot++; } return sshClientFactory.create(HostAndPort.fromParts(clientIpAddress, Integer.parseInt(sshPort)), loginCredentials); }
From source file:org.jclouds.virtualbox.functions.admin.StartVBoxIfNotAlreadyRunning.java
@PostConstruct public void start() { URI provider = providerSupplier.get(); NodeMetadata hostNodeMetadata = hardcodedHostToHostNodeMetadata.apply(host.get()); if (!socketTester.apply(HostAndPort.fromParts(provider.getHost(), provider.getPort()))) { logger.debug("disabling password access"); runScriptOnNodeFactory.create(hostNodeMetadata, exec("VBoxManage setproperty websrvauthlibrary null"), runAsRoot(false).wrapInInitScript(false)).init().call(); logger.debug(">> starting vboxwebsrv"); String vboxwebsrv = "vboxwebsrv -t0 -v -b -H " + providerSupplier.get().getHost(); runScriptOnNodeFactory/*from ww w . j a v a 2 s .c o m*/ .create(hostNodeMetadata, exec(vboxwebsrv), runAsRoot(false).wrapInInitScript(false).blockOnComplete(false).nameTask("vboxwebsrv")) .init().call(); if (!socketTester.apply(HostAndPort.fromParts(provider.getHost(), provider.getPort()))) { throw new UncheckedTimeoutException( String.format("could not connect to virtualbox at %s", provider)); } } manager = managerForNode.apply(host); manager.connect(provider.toASCIIString(), "", ""); if (logger.isDebugEnabled()) if (manager.getSessionObject().getState() != SessionState.Unlocked) logger.warn("manager is not in unlocked state " + manager.getSessionObject().getState()); }
From source file:com.dwitech.eap.consulee.scan.ConsulRegistrationClient.java
private HostAndPort getConsulHostAndPort() { return HostAndPort.fromParts(consulConfig.getConsulHost(), Integer.parseInt(consulConfig.getConsulPort())) .withDefaultPort(8500); }
From source file:brooklyn.networking.portforwarding.PortForwarderIptables.java
@Override public HostAndPort openPortForwarding(MachineLocation targetMachine, int targetPort, Optional<Integer> optionalPublicPort, Protocol protocol, Cidr accessingCidr) { String targetIp = ((MachineLocation) targetMachine).getAddress().getHostAddress(); if (targetIp == null) { throw new IllegalStateException("Failed to open port-forarding for machine " + targetMachine + " because its location has no target ip: " + targetMachine); }/*from w w w . ja va2s.c o m*/ HostAndPort targetSide = HostAndPort.fromParts(targetIp, targetPort); HostAndPort newFrontEndpoint = openPortForwarding(targetSide, optionalPublicPort, protocol, accessingCidr); log.debug("Enabled port-forwarding for {} port {} (VM {}), via {}", new Object[] { targetMachine, targetPort, targetMachine, newFrontEndpoint }); return newFrontEndpoint; }
From source file:org.apache.omid.tso.NetworkInterfaceUtils.java
public static String getTSOHostAndPort(TSOServerConfig config) throws SocketException, UnknownHostException { // Build TSO host:port string and validate it final String tsoNetIfaceName = config.getNetworkIfaceName(); InetAddress addr = getIPAddressFromNetworkInterface(tsoNetIfaceName); final int tsoPort = config.getPort(); String tsoHostAndPortAsString = "N/A"; try {/* w ww . j a va 2 s . c om*/ tsoHostAndPortAsString = HostAndPort.fromParts(addr.getHostAddress(), tsoPort).toString(); } catch (IllegalArgumentException e) { LOG.error("Cannot parse TSO host:port string {}", tsoHostAndPortAsString); throw e; } return tsoHostAndPortAsString; }
From source file:com.spotify.folsom.ketama.SrvKetamaClient.java
public void updateDNS() { synchronized (sync) { if (shutdown) { return; }/*from w w w . j av a 2 s.co m*/ long ttl = TimeUnit.SECONDS.convert(period, periodUnit); try { List<LookupResult> lookupResults = srvResolver.resolve(srvRecord); List<HostAndPort> hosts = Lists.newArrayListWithCapacity(lookupResults.size()); for (LookupResult lookupResult : lookupResults) { hosts.add(HostAndPort.fromParts(lookupResult.host(), lookupResult.port())); ttl = Math.min(ttl, lookupResult.ttl()); } List<HostAndPort> newAddresses = Ordering.from(HostAndPortComparator.INSTANCE).sortedCopy(hosts); if (!newAddresses.equals(addresses)) { addresses = newAddresses; log.info("Connecting to " + newAddresses); List<AddressAndClient> addressAndClients = getAddressesAndClients(newAddresses); setPendingClient(addressAndClients); } } finally { long delay = clamp(MIN_DNS_WAIT_TIME, MAX_DNS_WAIT_TIME, ttl); refreshJob = this.executor.schedule(refreshRunnable, delay, TimeUnit.SECONDS); } } }
From source file:ezbake.thrift.ThriftServerPool.java
private void startService(EzBakeBaseThriftService service, String serviceName, String applicationName, String securityId) throws Exception { checkNotNull(service);/*w w w . j a v a2s . co m*/ checkNotNull(serviceName); HostAndPort hostAndPort = HostAndPort.fromParts("localhost", portNumber); if (applicationName == null) { discovery.registerEndpoint(serviceName, hostAndPort.toString()); discovery.setSecurityIdForCommonService(serviceName, securityId); } else { discovery.registerEndpoint(applicationName, serviceName, hostAndPort.toString()); discovery.setSecurityIdForApplication(applicationName, securityId); } // Give the service it's own EzConfiguration with the correct security ID properties.setProperty(EzBakePropertyConstants.EZBAKE_SECURITY_ID, securityId); service.setConfigurationProperties(properties); TServer server; switch (thriftConfiguration.getServerMode()) { case Simple: if (thriftConfiguration.useSSL()) { server = ThriftUtils.startSslSimpleServer(service.getThriftProcessor(), portNumber++, properties); } else { server = ThriftUtils.startSimpleServer(service.getThriftProcessor(), portNumber++); } break; case HsHa: if (thriftConfiguration.useSSL()) { logger.warn("ThriftUtils based HsHa doesn't currently support SSL."); throw new RuntimeException("Unsupported server mode. (HsHa with SSL)"); } server = ThriftUtils.startHshaServer(service.getThriftProcessor(), portNumber++); break; case ThreadedPool: if (thriftConfiguration.useSSL()) { server = ThriftUtils.startSslThreadedPoolServer(service.getThriftProcessor(), portNumber++, properties); } else { server = ThriftUtils.startThreadedPoolServer(service.getThriftProcessor(), portNumber++); } break; default: throw new RuntimeException("Unrecognized server mode"); } thriftServers.add(server); }