List of usage examples for com.google.common.net HostAndPort toString
@Override
public String toString()
From source file:org.apache.phoenix.loadbalancer.service.LoadBalanceZookeeperConfImpl.java
@Override public String getFullPathToNode(HostAndPort hostAndPort) { String path = String.format("%s/%s", getParentPath(), hostAndPort.toString()); return path;/*w w w. j a v a 2 s. c om*/ }
From source file:org.apache.brooklyn.entity.messaging.zookeeper.ZooKeeperTestSupport.java
public ZooKeeperTestSupport(final HostAndPort hostAndPort) throws Exception { final int sessionTimeout = 3000; zk = new ZooKeeper(hostAndPort.toString(), sessionTimeout, new Watcher() { @Override/*from w w w . ja v a 2s. co m*/ public void process(WatchedEvent event) { if (event.getState() == Event.KeeperState.SyncConnected) { LOG.debug("Connected to ZooKeeper at {}", hostAndPort); connSignal.countDown(); } else { LOG.info("WatchedEvent at {}: {}", hostAndPort, event.getState()); } } }); connSignal.await(); }
From source file:org.apache.brooklyn.entity.zookeeper.ZooKeeperNodeImpl.java
@Override protected void postStart() { super.postStart(); HostAndPort hap = BrooklynAccessUtils.getBrooklynAccessibleAddress(this, sensors().get(ZOOKEEPER_PORT)); sensors().set(ZooKeeperNode.ZOOKEEPER_ENDPOINT, hap.toString()); sensors().set(Attributes.MAIN_URI, URI.create("zk://" + hap.toString())); }
From source file:org.apache.phoenix.queryserver.register.ZookeeperRegistry.java
@Override public void registerServer(LoadBalanceZookeeperConf configuration, int pqsPort, String zookeeperConnectString, String pqsHost) throws Exception { this.client = CuratorFrameworkFactory.newClient(zookeeperConnectString, new ExponentialBackoffRetry(1000, 10)); this.client.start(); HostAndPort hostAndPort = HostAndPort.fromParts(pqsHost, pqsPort); String path = configuration.getFullPathToNode(hostAndPort); String node = hostAndPort.toString(); this.client.create().creatingParentsIfNeeded().withMode(CreateMode.EPHEMERAL).forPath(path, node.getBytes(StandardCharsets.UTF_8)); Stat stat = this.client.setACL().withACL(configuration.getAcls()).forPath(path); if (stat != null) { LOG.info(" node created with right ACL"); } else {// ww w. jav a 2 s. co m LOG.error("could not create node with right ACL. So, system would exit now."); throw new RuntimeException(" Unable to connect to Zookeeper"); } }
From source file:com.torodb.mongodb.commands.signatures.repl.ReplSetSyncFromCommand.java
@Override public BsonDocument marshallArg(HostAndPort request) { return DefaultBsonValues.newDocument(getCommandName(), DefaultBsonValues.newString(request.toString())); }
From source file:ezbake.thrift.ThriftServerPool.java
private void startService(EzBakeBaseThriftService service, String serviceName, String applicationName, String securityId) throws Exception { checkNotNull(service);//ww w .ja va 2 s . c o 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); }
From source file:org.sfs.vo.ServiceDef.java
public JsonObject toJsonObject() { JsonObject jsonObject = new JsonObject().put("id", id).put("update_ts", toDateTimeString(getLastUpdate())) .put("master_node", master).put("data_node", dataNode).put("document_count", documentCount) .put("available_processors", availableProcessors).put("free_memory", freeMemory) .put("max_memory", maxMemory).put("total_memory", totalMemory); if (fileSystem != null) { JsonObject jsonFileSystem = fileSystem.toJsonObject(); jsonObject = jsonObject.put("file_system", jsonFileSystem); }// w ww . ja va2 s . c o m JsonArray jsonListeners = new JsonArray(); for (HostAndPort publishAddress : publishAddresses) { jsonListeners.add(publishAddress.toString()); } jsonObject.put("publish_addresses", jsonListeners); JsonArray jsonVolumes = new JsonArray(); for (XVolume<? extends XVolume> xVolume : volumes) { jsonVolumes.add(xVolume.toJsonObject()); } jsonObject.put("volumes", jsonVolumes); return jsonObject; }
From source file:com.pinterest.secor.common.KafkaClient.java
public SimpleConsumer createConsumer(TopicPartition topicPartition) { HostAndPort leader = findLeader(topicPartition); LOG.info("leader for topic {} partition {} is {}", topicPartition.getTopic(), topicPartition.getPartition(), leader.toString()); final String clientName = getClientName(topicPartition); return createConsumer(leader.getHostText(), leader.getPort(), clientName); }
From source file:de.qaware.playground.zwitscher.util.servicediscovery.impl.ConsulFabioServiceDiscovery.java
/** * Registeres a service//www. ja va 2s . c o m * * see https://github.com/eBay/fabio/wiki/Service-Configuration */ public synchronized void registerService(String serviceName, String servicePath) { String applicationHost = getOutboundHost(); int applicationPort = getOutboundPort(); HostAndPort consulEndpoint = getConsulHostAndPort(); logger.info("Will register service on host {} and port {} at consul endpoint {}", applicationHost, applicationPort, consulEndpoint.toString()); //generate unique serviceId String serviceId = serviceName + "-" + applicationHost + ":" + applicationPort; String fabioServiceTag = "urlprefix-" + servicePath; //point healthcheck URL to dropwizard metrics healthcheck servlet URL serviceUrl = UrlBuilder.empty().withScheme("http").withHost(applicationHost).withPort(applicationPort) .withPath("/metrics/ping").toUrl(); // Service bei Consul registrieren inklusive einem Health-Check auf die URL des REST-Endpunkts. logger.info("Registering service with ID {} and NAME {} with healthcheck URL {} and inbound ROUTE {}", serviceId, serviceName, serviceUrl, fabioServiceTag); //use consul API to register service ConsulClient client = new ConsulClient(consulEndpoint.toString()); NewService service = new NewService(); service.setId(serviceId); service.setName(serviceName); service.setPort(applicationPort); service.setAddress(applicationHost); List<String> tags = new ArrayList<>(); tags.add(fabioServiceTag); service.setTags(tags); //register health check NewService.Check check = new NewService.Check(); check.setHttp(serviceUrl.toString()); check.setInterval(ConsulFabioServiceDiscovery.HEALTHCHECK_INTERVAL + "s"); service.setCheck(check); client.agentServiceRegister(service); }
From source file:com.torodb.mongodb.utils.cloner.TransactionalDbCloner.java
private void cloneIndex(String dstDb, MongoConnection remoteConnection, WriteMongodTransaction transaction, CloneOptions opts, String fromCol, CollectionOptions collOptions) throws CloningException { try {/* www.j a v a2 s . com*/ String fromDb = opts.getDbToClone(); HostAndPort remoteAddress = remoteConnection.getClientOwner().getAddress(); String remoteAddressString = remoteAddress != null ? remoteAddress.toString() : "local"; logger.info("copying indexes from {}.{} on {} to {}.{} on local server", fromDb, fromCol, remoteAddressString, dstDb, fromCol); Status<?> status; List<IndexOptions> indexes = Lists.newArrayList( ListIndexesRequester.getListCollections(remoteConnection, dstDb, fromCol).getFirstBatch()); if (indexes.isEmpty()) { return; } status = transaction.execute(new Request(dstDb, null, true, null), CreateIndexesCommand.INSTANCE, new CreateIndexesArgument(fromCol, indexes)); if (!status.isOk()) { throw new CloningException("Error while trying to fetch indexes from remote: " + status); } } catch (MongoException ex) { throw new CloningException("Error while trying to fetch indexes from remote", ex); } }