List of usage examples for com.google.common.net HostAndPort fromParts
public static HostAndPort fromParts(String host, int port)
From source file:org.apache.accumulo.server.rpc.TServerUtils.java
/** * Create a Thrift SSL server.//from w w w .j a va 2s . c om * * @param address * host and port to bind to * @param processor * TProcessor for the server * @param socketTimeout * Socket timeout * @param sslParams * SSL parameters * @return A ServerAddress with the bound-socket information and the Thrift server */ public static ServerAddress createSslThreadPoolServer(HostAndPort address, TProcessor processor, TProtocolFactory protocolFactory, long socketTimeout, SslConnectionParams sslParams, String serverName, int numThreads, int numSimpleTimerThreads, long timeBetweenThreadChecks) throws TTransportException { TServerSocket transport; try { transport = getSslServerSocket(address.getPort(), (int) socketTimeout, InetAddress.getByName(address.getHostText()), sslParams); } catch (UnknownHostException e) { throw new TTransportException(e); } if (address.getPort() == 0) { address = HostAndPort.fromParts(address.getHostText(), transport.getServerSocket().getLocalPort()); } ThreadPoolExecutor pool = createSelfResizingThreadPool(serverName, numThreads, numSimpleTimerThreads, timeBetweenThreadChecks); return new ServerAddress( createTThreadPoolServer(transport, processor, ThriftUtil.transportFactory(), protocolFactory, pool), address); }
From source file:org.apache.accumulo.server.gc.SimpleGarbageCollector.java
private HostAndPort startStatsService() throws UnknownHostException { Processor<Iface> processor = new Processor<Iface>(TraceWrap.service(this)); int port = instance.getConfiguration().getPort(Property.GC_PORT); long maxMessageSize = instance.getConfiguration().getMemoryInBytes(Property.GENERAL_MAX_MESSAGE_SIZE); HostAndPort result = HostAndPort.fromParts(opts.getAddress(), port); try {/*from ww w . j av a 2s. c om*/ port = TServerUtils.startTServer(result, processor, this.getClass().getSimpleName(), "GC Monitor Service", 2, 1000, maxMessageSize).address.getPort(); } catch (Exception ex) { log.fatal(ex, ex); throw new RuntimeException(ex); } return result; }
From source file:org.apache.hadoop.hbase.rsgroup.RSGroupInfoManagerImpl.java
private List<HostAndPort> getDefaultServers() throws IOException { List<HostAndPort> defaultServers = new LinkedList<HostAndPort>(); for (ServerName server : getOnlineRS()) { HostAndPort hostPort = HostAndPort.fromParts(server.getHostname(), server.getPort()); boolean found = false; for (RSGroupInfo RSGroupInfo : rsGroupMap.values()) { if (!RSGroupInfo.DEFAULT_GROUP.equals(RSGroupInfo.getName()) && RSGroupInfo.containsServer(hostPort)) { found = true;/*from w w w .ja v a 2s . co m*/ break; } } if (!found) { defaultServers.add(hostPort); } } return defaultServers; }
From source file:clocker.docker.entity.DockerInfrastructureImpl.java
@Override public void postStart(Collection<? extends Location> locations) { if (config().get(DOCKER_SHOULD_START_REGISTRY)) { DockerHost firstEntity = (DockerHost) sensors().get(DOCKER_HOST_CLUSTER).sensors() .get(DynamicCluster.FIRST); EntitySpec<DockerRegistry> spec = EntitySpec.create(DockerRegistry.class) .configure(DockerRegistry.DOCKER_HOST, firstEntity) .configure(DockerRegistry.DOCKER_REGISTRY_PORT, config().get(DOCKER_REGISTRY_PORT)); // TODO Mount volume with images stored on it DockerRegistry registry = addChild(spec); LOG.debug("Starting a new Docker Registry with spec {}", spec); Entities.start(registry, ImmutableList.of(firstEntity.getDynamicLocation())); String registryUrl = HostAndPort .fromParts(firstEntity.sensors().get(Attributes.ADDRESS), config().get(DOCKER_REGISTRY_PORT)) .toString();//from w ww. ja v a2s. c o m sensors().set(DOCKER_IMAGE_REGISTRY_URL, registryUrl); sensors().set(DOCKER_IMAGE_REGISTRY, registry); } }
From source file:clocker.docker.entity.DockerHostSshDriver.java
@Override public void customize() { if (isRunning()) { log.info("Stopping running Docker instance at {} before customising", getMachine()); stop();/* ww w .jav a2 s .c om*/ } // Determine OS String os = getMachine().getMachineDetails().getOsDetails().getName(); boolean centos = "centos".equalsIgnoreCase(os); boolean ubuntu = "ubuntu".equalsIgnoreCase(os); if (entity.config().get(DockerInfrastructure.DOCKER_GENERATE_TLS_CERTIFICATES)) { newScript(ImmutableMap.of(NON_STANDARD_LAYOUT, "true"), CUSTOMIZING).body .append(format("cp ca-cert.pem %s/ca.pem", getRunDir()), format("cp server-cert.pem %s/cert.pem", getRunDir()), format("cp server-key.pem %s/key.pem", getRunDir())) .failOnNonZeroResultCode().execute(); } // Add the CA cert as an authorised docker CA for the first host. // This will be used for docker registry etc. String firstHost = entity.sensors().get(AbstractGroup.FIRST).sensors().get(Attributes.HOSTNAME); String certsPath = "/etc/docker/certs.d/" + firstHost + ":" + entity.config().get(DockerInfrastructure.DOCKER_REGISTRY_PORT); newScript(CUSTOMIZING).body .append(chainGroup(sudo("mkdir -p " + certsPath), sudo("cp ca.pem " + certsPath + "/ca.crt"))) .failOnNonZeroResultCode().execute(); // Docker daemon startup arguments EtcdNode etcdNode = getEntity().sensors().get(DockerHost.ETCD_NODE); HostAndPort etcdAuthority = HostAndPort.fromParts(etcdNode.sensors().get(Attributes.SUBNET_ADDRESS), etcdNode.sensors().get(EtcdNode.ETCD_CLIENT_PORT)); List<String> args = MutableList.of(centos ? "--selinux-enabled" : null, "--userland-proxy=false", format("-H tcp://0.0.0.0:%d", getDockerPort()), "-H unix:///var/run/docker.sock", format("--cluster-store=etcd://%s", etcdAuthority.toString()), format("--cluster-advertise=%s:%d", getEntity().sensors().get(Attributes.SUBNET_ADDRESS), getDockerPort()), getStorageOpts(), getDockerRegistryOpts(), "--tlsverify", "--tls", format("--tlscert=%s/cert.pem", getRunDir()), format("--tlskey=%s/key.pem", getRunDir()), format("--tlscacert=%s/ca.pem", getRunDir())); String argv = Joiner.on(" ").skipNulls().join(args); log.debug("Docker daemon args: {}", argv); // Upstart if (ubuntu) { newScript(CUSTOMIZING + "-upstart").body.append( chain(sudo("mkdir -p /etc/default"), format("echo 'DOCKER_OPTS=\"%s\"' | ", argv) + sudo("tee -a /etc/default/docker")), sudo("groupadd -f docker"), sudo(format("gpasswd -a %s docker", getMachine().getUser())), sudo("newgrp docker")).failOnNonZeroResultCode().execute(); } // CentOS if (centos) { newScript(CUSTOMIZING + "-sysconfig").body .append(chain(sudo("mkdir -p /etc/sysconfig"), format("echo 'other_args=\"%s\"' | ", argv) + sudo("tee -a /etc/sysconfig/docker"))) .failOnNonZeroResultCode().execute(); } // SystemD boolean dockerTen = VersionComparator.getInstance().compare(getVersion(), "1.10") >= 0; String service = Os.mergePaths(getInstallDir(), "docker.service"); copyTemplate("classpath://clocker/docker/entity/docker.service", service, true, ImmutableMap.of("args", argv, "daemon", dockerTen ? "daemon" : "-d")); newScript(CUSTOMIZING + "-systemd").body .append(chain(sudo("mkdir -p /etc/systemd/system"), sudo(format("cp %s %s", service, "/etc/systemd/system/docker.service")), ifExecutableElse0("systemctl", sudo("systemctl daemon-reload")))) .failOnNonZeroResultCode().execute(); // Configure volume mappings for the host Map<String, String> mapping = MutableMap.of(); Map<String, String> volumes = getEntity().config().get(DockerHost.DOCKER_HOST_VOLUME_MAPPING); if (volumes != null) { for (String source : volumes.keySet()) { if (Urls.isUrlWithProtocol(source)) { String path = deployArchive(source); mapping.put(path, volumes.get(source)); } else { mapping.put(source, volumes.get(source)); } } } getEntity().sensors().set(DockerHost.DOCKER_HOST_VOLUME_MAPPING, mapping); }
From source file:org.apache.brooklyn.core.location.access.PortForwardManagerImpl.java
@Override public HostAndPort getPublicHostAndPort(PortMapping m) { if (m.publicEndpoint == null) { String hostname = getPublicIpHostname(m.publicIpId); if (hostname == null) throw new IllegalStateException( "No public hostname associated with " + m.publicIpId + " (mapping " + m + ")"); return HostAndPort.fromParts(hostname, m.publicPort); } else {//from w ww.java 2s . co m return m.publicEndpoint; } }
From source file:brooklyn.entity.nosql.couchbase.CouchbaseClusterImpl.java
protected void addServer(Entity serverToAdd) { Preconditions.checkNotNull(serverToAdd); if (serverToAdd.equals(getPrimaryNode())) { // no need to add; but we pass it in anyway because it makes the calling logic easier return;// www. jav a 2 s . c o m } if (!isMemberInCluster(serverToAdd)) { HostAndPort webAdmin = HostAndPort.fromParts(serverToAdd.getAttribute(SoftwareProcess.SUBNET_HOSTNAME), serverToAdd.getAttribute(CouchbaseNode.COUCHBASE_WEB_ADMIN_PORT)); String username = serverToAdd.getConfig(CouchbaseNode.COUCHBASE_ADMIN_USERNAME); String password = serverToAdd.getConfig(CouchbaseNode.COUCHBASE_ADMIN_PASSWORD); if (isClusterInitialized()) { Entities.invokeEffectorWithArgs(this, getPrimaryNode(), CouchbaseNode.SERVER_ADD_AND_REBALANCE, webAdmin.toString(), username, password).getUnchecked(); } else { Entities.invokeEffectorWithArgs(this, getPrimaryNode(), CouchbaseNode.SERVER_ADD, webAdmin.toString(), username, password).getUnchecked(); } //FIXME check feedback of whether the server was added. ((EntityInternal) serverToAdd).setAttribute(CouchbaseNode.IS_IN_CLUSTER, true); } }
From source file:org.apache.brooklyn.entity.nosql.couchbase.CouchbaseClusterImpl.java
protected void addServer(Entity serverToAdd) { Preconditions.checkNotNull(serverToAdd); if (serverToAdd.equals(getPrimaryNode())) { // no need to add; but we pass it in anyway because it makes the calling logic easier return;//from w ww. ja v a 2s . c o m } if (!isMemberInCluster(serverToAdd)) { HostAndPort webAdmin = HostAndPort.fromParts(serverToAdd.getAttribute(SoftwareProcess.SUBNET_HOSTNAME), serverToAdd.getAttribute(CouchbaseNode.COUCHBASE_WEB_ADMIN_PORT)); String username = serverToAdd.getConfig(CouchbaseNode.COUCHBASE_ADMIN_USERNAME); String password = serverToAdd.getConfig(CouchbaseNode.COUCHBASE_ADMIN_PASSWORD); if (isClusterInitialized()) { Entities.invokeEffectorWithArgs(this, getPrimaryNode(), CouchbaseNode.SERVER_ADD_AND_REBALANCE, webAdmin.toString(), username, password).getUnchecked(); } else { Entities.invokeEffectorWithArgs(this, getPrimaryNode(), CouchbaseNode.SERVER_ADD, webAdmin.toString(), username, password).getUnchecked(); } //FIXME check feedback of whether the server was added. ((EntityInternal) serverToAdd).sensors().set(CouchbaseNode.IS_IN_CLUSTER, true); } }
From source file:org.apache.accumulo.server.rpc.TServerUtils.java
public static ServerAddress createSaslThreadPoolServer(HostAndPort address, TProcessor processor, TProtocolFactory protocolFactory, long socketTimeout, SaslServerConnectionParams params, final String serverName, String threadName, final int numThreads, final int numSTThreads, long timeBetweenThreadChecks) throws TTransportException { // We'd really prefer to use THsHaServer (or similar) to avoid 1 RPC == 1 Thread that the TThreadPoolServer does, // but sadly this isn't the case. Because TSaslTransport needs to issue a handshake when it open()'s which will fail // when the server does an accept() to (presumably) wake up the eventing system. log.info("Creating SASL thread pool thrift server on listening on {}:{}", address.getHostText(), address.getPort());// w w w. ja va 2 s . co m TServerSocket transport = new TServerSocket(address.getPort(), (int) socketTimeout); String hostname, fqdn; try { hostname = InetAddress.getByName(address.getHostText()).getCanonicalHostName(); fqdn = InetAddress.getLocalHost().getCanonicalHostName(); } catch (UnknownHostException e) { transport.close(); throw new TTransportException(e); } // If we can't get a real hostname from the provided host test, use the hostname from DNS for localhost if ("0.0.0.0".equals(hostname)) { hostname = fqdn; } // ACCUMULO-3497 an easy sanity check we can perform for the user when SASL is enabled. Clients and servers have to agree upon the FQDN // so that the SASL handshake can occur. If the provided hostname doesn't match the FQDN for this host, fail quickly and inform them to update // their configuration. if (!hostname.equals(fqdn)) { log.error( "Expected hostname of '{}' but got '{}'. Ensure the entries in the Accumulo hosts files (e.g. masters, slaves) are the FQDN for each host when using SASL.", fqdn, hostname); transport.close(); throw new RuntimeException( "SASL requires that the address the thrift server listens on is the same as the FQDN for this host"); } final UserGroupInformation serverUser; try { serverUser = UserGroupInformation.getLoginUser(); } catch (IOException e) { transport.close(); throw new TTransportException(e); } log.debug("Logged in as {}, creating TSaslServerTransport factory with {}/{}", serverUser, params.getKerberosServerPrimary(), hostname); // Make the SASL transport factory with the instance and primary from the kerberos server principal, SASL properties // and the SASL callback handler from Hadoop to ensure authorization ID is the authentication ID. Despite the 'protocol' argument seeming to be useless, it // *must* be the primary of the server. TSaslServerTransport.Factory saslTransportFactory = new TSaslServerTransport.Factory(); saslTransportFactory.addServerDefinition(ThriftUtil.GSSAPI, params.getKerberosServerPrimary(), hostname, params.getSaslProperties(), new SaslRpcServer.SaslGssCallbackHandler()); if (null != params.getSecretManager()) { log.info("Adding DIGEST-MD5 server definition for delegation tokens"); saslTransportFactory.addServerDefinition(ThriftUtil.DIGEST_MD5, params.getKerberosServerPrimary(), hostname, params.getSaslProperties(), new SaslServerDigestCallbackHandler(params.getSecretManager())); } else { log.info("SecretManager is null, not adding support for delegation token authentication"); } // Make sure the TTransportFactory is performing a UGI.doAs TTransportFactory ugiTransportFactory = new UGIAssumingTransportFactory(saslTransportFactory, serverUser); if (address.getPort() == 0) { // If we chose a port dynamically, make a new use it (along with the proper hostname) address = HostAndPort.fromParts(address.getHostText(), transport.getServerSocket().getLocalPort()); log.info("SASL thrift server bound on {}", address); } ThreadPoolExecutor pool = createSelfResizingThreadPool(serverName, numThreads, numSTThreads, timeBetweenThreadChecks); final TThreadPoolServer server = createTThreadPoolServer(transport, processor, ugiTransportFactory, protocolFactory, pool); return new ServerAddress(server, address); }
From source file:brooklyn.entity.nosql.cassandra.CassandraDatacenterImpl.java
@Override public void update() { synchronized (mutex) { // Update our seeds, as necessary seedTracker.refreshSeeds();//from w ww . ja v a 2 s . c om // Choose the first available cluster member to set host and port (and compute one-up) Optional<Entity> upNode = Iterables.tryFind(getMembers(), EntityPredicates.attributeEqualTo(SERVICE_UP, Boolean.TRUE)); if (upNode.isPresent()) { setAttribute(HOSTNAME, upNode.get().getAttribute(Attributes.HOSTNAME)); setAttribute(THRIFT_PORT, upNode.get().getAttribute(CassandraNode.THRIFT_PORT)); List<String> currentNodes = getAttribute(CASSANDRA_CLUSTER_NODES); Set<String> oldNodes = (currentNodes != null) ? ImmutableSet.copyOf(currentNodes) : ImmutableSet.<String>of(); Set<String> newNodes = MutableSet.<String>of(); for (Entity member : getMembers()) { if (member instanceof CassandraNode && Boolean.TRUE.equals(member.getAttribute(SERVICE_UP))) { String hostname = member.getAttribute(Attributes.HOSTNAME); Integer thriftPort = member.getAttribute(CassandraNode.THRIFT_PORT); if (hostname != null && thriftPort != null) { newNodes.add(HostAndPort.fromParts(hostname, thriftPort).toString()); } } } if (Sets.symmetricDifference(oldNodes, newNodes).size() > 0) { setAttribute(CASSANDRA_CLUSTER_NODES, MutableList.copyOf(newNodes)); } } else { setAttribute(HOSTNAME, null); setAttribute(THRIFT_PORT, null); setAttribute(CASSANDRA_CLUSTER_NODES, Collections.<String>emptyList()); } ServiceNotUpLogic.updateNotUpIndicatorRequiringNonEmptyList(this, CASSANDRA_CLUSTER_NODES); } }