List of usage examples for com.google.common.net HostAndPort getPort
public int getPort()
From source file:brooklyn.qa.load.SimulatedJBoss7ServerImpl.java
@Override protected void connectSensors() { boolean simulateEntity = getConfig(SIMULATE_ENTITY); boolean simulateExternalMonitoring = getConfig(SIMULATE_EXTERNAL_MONITORING); if (!simulateEntity && !simulateExternalMonitoring) { super.connectSensors(); return;//from w w w . ja va 2 s . c om } HostAndPort hp = BrooklynAccessUtils.getBrooklynAccessibleAddress(this, getAttribute(MANAGEMENT_HTTP_PORT) + getConfig(PORT_INCREMENT)); String managementUri = String.format("http://%s:%s/management/subsystem/web/connector/http/read-resource", hp.getHostText(), hp.getPort()); setAttribute(MANAGEMENT_URL, managementUri); if (simulateExternalMonitoring) { // TODO What would set this normally, if not doing connectServiceUpIsRunning? setAttribute(SERVICE_PROCESS_IS_RUNNING, true); } else { // if simulating entity, then simulate work of periodic HTTP request; TODO but not parsing JSON response String uriToPoll = (simulateEntity) ? "http://localhost:8081" : managementUri; httpFeed = HttpFeed.builder().entity(this).period(200).baseUri(uriToPoll) .credentials(getConfig(MANAGEMENT_USER), getConfig(MANAGEMENT_PASSWORD)) .poll(new HttpPollConfig<Integer>(MANAGEMENT_STATUS) .onSuccess(HttpValueFunctions.responseCode())) .build(); // Polls over ssh for whether process is running connectServiceUpIsRunning(); } functionFeed = FunctionFeed.builder().entity(this).period(5000) .poll(new FunctionPollConfig<Boolean, Boolean>(MANAGEMENT_URL_UP).callable(new Callable<Boolean>() { private int counter = 0; public Boolean call() { setAttribute(REQUEST_COUNT, (counter++ % 100)); setAttribute(ERROR_COUNT, (counter++ % 100)); setAttribute(TOTAL_PROCESSING_TIME, (counter++ % 100)); setAttribute(MAX_PROCESSING_TIME, (counter++ % 100)); setAttribute(BYTES_RECEIVED, (long) (counter++ % 100)); setAttribute(BYTES_SENT, (long) (counter++ % 100)); return true; } })).build(); addEnricher(Enrichers.builder().updatingMap(Attributes.SERVICE_NOT_UP_INDICATORS).from(MANAGEMENT_URL_UP) .computing(Functionals.ifNotEquals(true).value("Management URL not reachable")).build()); }
From source file:org.apache.brooklyn.entity.nosql.couchbase.CouchbaseNodeImpl.java
protected void renameServerToPublicHostname() { // http://docs.couchbase.com/couchbase-manual-2.5/cb-install/#couchbase-getting-started-hostnames URI apiUri = null;//from w w w .ja va2 s . c om try { HostAndPort accessible = BrooklynAccessUtils.getBrooklynAccessibleAddress(this, getAttribute(COUCHBASE_WEB_ADMIN_PORT)); apiUri = URI.create(String.format("http://%s:%d/node/controller/rename", accessible.getHostText(), accessible.getPort())); UsernamePasswordCredentials credentials = new UsernamePasswordCredentials( getConfig(COUCHBASE_ADMIN_USERNAME), getConfig(COUCHBASE_ADMIN_PASSWORD)); HttpToolResponse response = HttpTool.httpPost( // the uri is required by the HttpClientBuilder in order to set the AuthScope of the credentials HttpTool.httpClientBuilder().uri(apiUri).credentials(credentials).build(), apiUri, MutableMap.of(HttpHeaders.CONTENT_TYPE, MediaType.FORM_DATA.toString(), HttpHeaders.ACCEPT, "*/*", // this appears needed; without it we get org.apache.http.NoHttpResponseException !? HttpHeaders.AUTHORIZATION, HttpTool.toBasicAuthorizationValue(credentials)), Charsets.UTF_8.encode("hostname=" + Urls.encode(accessible.getHostText())).array()); log.debug("Renamed Couchbase server " + this + " via " + apiUri + ": " + response); if (!HttpTool.isStatusCodeHealthy(response.getResponseCode())) { log.warn("Invalid response code, renaming {} ({}): {}", new Object[] { apiUri, response.getResponseCode(), response.getContentAsString() }); } } catch (Exception e) { Exceptions.propagateIfFatal(e); log.warn("Error renaming server, using " + apiUri + ": " + e, e); } }
From source file:org.apache.brooklyn.qa.load.SimulatedJBoss7ServerImpl.java
@Override protected void connectSensors() { boolean simulateEntity = getConfig(SIMULATE_ENTITY); boolean simulateExternalMonitoring = getConfig(SIMULATE_EXTERNAL_MONITORING); if (!simulateEntity && !simulateExternalMonitoring) { super.connectSensors(); return;/* www . j a v a 2s .com*/ } HostAndPort hp = BrooklynAccessUtils.getBrooklynAccessibleAddress(this, getAttribute(MANAGEMENT_HTTP_PORT) + getConfig(PORT_INCREMENT)); String managementUri = String.format("http://%s:%s/management/subsystem/web/connector/http/read-resource", hp.getHostText(), hp.getPort()); sensors().set(MANAGEMENT_URL, managementUri); if (simulateExternalMonitoring) { // TODO What would set this normally, if not doing connectServiceUpIsRunning? sensors().set(SERVICE_PROCESS_IS_RUNNING, true); } else { // if simulating entity, then simulate work of periodic HTTP request; TODO but not parsing JSON response String uriToPoll = (simulateEntity) ? "http://localhost:8081" : managementUri; httpFeed = HttpFeed.builder().entity(this).period(200).baseUri(uriToPoll) .credentials(getConfig(MANAGEMENT_USER), getConfig(MANAGEMENT_PASSWORD)) .poll(new HttpPollConfig<Integer>(MANAGEMENT_STATUS) .onSuccess(HttpValueFunctions.responseCode())) .build(); // Polls over ssh for whether process is running connectServiceUpIsRunning(); } functionFeed = FunctionFeed.builder().entity(this).period(5000) .poll(new FunctionPollConfig<Boolean, Boolean>(MANAGEMENT_URL_UP).callable(new Callable<Boolean>() { private int counter = 0; public Boolean call() { sensors().set(REQUEST_COUNT, (counter++ % 100)); sensors().set(ERROR_COUNT, (counter++ % 100)); sensors().set(TOTAL_PROCESSING_TIME, (counter++ % 100)); sensors().set(MAX_PROCESSING_TIME, (counter++ % 100)); sensors().set(BYTES_RECEIVED, (long) (counter++ % 100)); sensors().set(BYTES_SENT, (long) (counter++ % 100)); return true; } })).build(); enrichers() .add(Enrichers.builder().updatingMap(Attributes.SERVICE_NOT_UP_INDICATORS).from(MANAGEMENT_URL_UP) .computing(Functionals.ifNotEquals(true).value("Management URL not reachable")).build()); }
From source file:brooklyn.entity.nosql.couchbase.CouchbaseNodeImpl.java
protected void renameServerToPublicHostname() { // http://docs.couchbase.com/couchbase-manual-2.5/cb-install/#couchbase-getting-started-hostnames URI apiUri = null;/* w ww .ja v a2 s.c o m*/ try { HostAndPort accessible = BrooklynAccessUtils.getBrooklynAccessibleAddress(this, getAttribute(COUCHBASE_WEB_ADMIN_PORT)); apiUri = URI.create(String.format("http://%s:%d/node/controller/rename", accessible.getHostText(), accessible.getPort())); UsernamePasswordCredentials credentials = new UsernamePasswordCredentials( getConfig(COUCHBASE_ADMIN_USERNAME), getConfig(COUCHBASE_ADMIN_PASSWORD)); HttpToolResponse response = HttpTool.httpPost( // the uri is required by the HttpClientBuilder in order to set the AuthScope of the credentials HttpTool.httpClientBuilder().uri(apiUri).credentials(credentials).build(), apiUri, MutableMap.of(HttpHeaders.CONTENT_TYPE, MediaType.FORM_DATA.toString(), HttpHeaders.ACCEPT, "*/*", // this appears needed; without it we get org.apache.http.NoHttpResponseException !? HttpHeaders.AUTHORIZATION, HttpTool.toBasicAuthorizationValue(credentials)), Charsets.UTF_8.encode("hostname=" + Urls.encode(accessible.getHostText())).array()); log.debug("Renamed Couchbase server " + this + " via " + apiUri + ": " + response); if (!HttpTool.isStatusCodeHealthy(response.getResponseCode())) { log.warn("Invalid response code, renaming " + apiUri + ": " + response); } } catch (Exception e) { Exceptions.propagateIfFatal(e); log.warn("Error renaming server, using " + apiUri + ": " + e, e); } }
From source file:org.apache.brooklyn.entity.chef.KnifeConvergeTaskFactory.java
protected Integer knifeWhichPort(HostAndPort hostAndPort) { if (port == null) { if (Boolean.TRUE.equals(portOmittedToUseKnifeDefault)) // user has explicitly said to use knife default, omitting port here return null; // default is to use the machine port return hostAndPort.getPort(); }//www . j a v a 2s . co m if (port == -1) { // port was supplied by user, then portDefault (true or false) port = null; Integer whichPort = knifeWhichPort(hostAndPort); log.warn("knife port conflicting instructions for " + this + " at entity " + entity() + " on " + hostAndPort + "; using default (" + whichPort + ")"); return whichPort; } if (portOmittedToUseKnifeDefault != null) { // portDefault was specified (true or false), then overridden with a port log.warn("knife port conflicting instructions for " + this + " at entity " + entity() + " on " + hostAndPort + "; using supplied port " + port); } // port was supplied by user, use that return port; }
From source file:brooklyn.entity.mesos.framework.marathon.MarathonPortForwarder.java
@Override public void openFirewallPort(Entity entity, int port, Protocol protocol, Cidr accessingCidr) { LOG.debug("Open iptables rule for {}, {}, {}, {}", new Object[] { this, entity, port, protocol, accessingCidr }); if (cluster.config().get(MesosCluster.SDN_ENABLE)) { HostAndPort target = portmap.get(HostAndPort.fromParts(marathonHostname, port)); addIptablesRule(port, target);/* w ww .j av a 2 s . c o m*/ String profile = entity.getApplicationId(); // TODO allow other Calico profiles String command = BashCommands.sudo(String.format( "calicoctl profile %s rule add inbound allow tcp to ports %d", profile, target.getPort())); CalicoModule calico = (CalicoModule) cluster.sensors().get(MesosCluster.SDN_PROVIDER); calico.execCalicoCommand(slave, command); } }
From source file:org.hillview.dataset.RemoteDataSet.java
public RemoteDataSet(final HostAndPort serverEndpoint, final int remoteHandle) { this.serverEndpoint = serverEndpoint; this.remoteHandle = remoteHandle; this.stub = HillviewServerGrpc .newStub(NettyChannelBuilder.forAddress(serverEndpoint.getHost(), serverEndpoint.getPort()) .maxInboundMessageSize(HillviewServer.MAX_MESSAGE_SIZE).executor(executorService) .eventLoopGroup(workerElg).usePlaintext(true) // channel is unencrypted. .build());/*w w w . j a v a2 s . c om*/ }
From source file:org.apache.accumulo.server.monitor.servlets.TServersServlet.java
private void doDetailTable(HttpServletRequest req, StringBuilder sb, HostAndPort address, int numTablets, TabletStats total, TabletStats historical) { Table detailTable = new Table("tServerDetail", "Details"); detailTable.setSubCaption(address.getHostText() + ":" + address.getPort()); detailTable.addSortableColumn("Hosted Tablets", new NumberType<Integer>(), null); detailTable.addSortableColumn("Entries", new NumberType<Long>(), null); detailTable.addSortableColumn("Minor Compacting", new NumberType<Integer>(), null); detailTable.addSortableColumn("Major Compacting", new NumberType<Integer>(), null); detailTable.addSortableColumn("Splitting", new NumberType<Integer>(), null); detailTable.addRow(numTablets, total.numEntries, total.minors.status, total.majors.status, historical.splits.status);// w ww .j a v a 2 s. c om detailTable.generate(req, sb); }
From source file:io.airlift.drift.transport.netty.ConnectionFactory.java
@Override public Future<Channel> getConnection(HostAndPort address) { try {/* ww w.j av a2 s . c o m*/ Bootstrap bootstrap = new Bootstrap().group(group).channel(NioSocketChannel.class) .option(CONNECT_TIMEOUT_MILLIS, saturatedCast(connectTimeout.toMillis())) .handler(new ThriftClientInitializer(messageFraming, messageEncoding, requestTimeout, socksProxy, sslContext)); Promise<Channel> promise = group.next().newPromise(); bootstrap.connect(new InetSocketAddress(address.getHost(), address.getPort())) .addListener((ChannelFutureListener) future -> notifyConnect(future, promise)); return promise; } catch (Throwable e) { return group.next().newFailedFuture(new TTransportException(e)); } }
From source file:io.druid.firehose.kafka.KafkaSimpleConsumer.java
private PartitionMetadata findLeader() throws InterruptedException { for (HostAndPort broker : replicaBrokers) { SimpleConsumer consumer = null;//ww w . j a v a2s. co m 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; }