public String getHostText() { return hostAndPort.getHostText(); }
@Nullable private static String extractHost(@Nullable final String hostAndPort) { if (hostAndPort == null) { return null; } return HostAndPort.fromString(hostAndPort).getHostText(); }
/** * Build up to a hosts only list * @param hostAndPorts * @return a list of the hosts only */ public static String buildHostsOnlyList(List<HostAndPort> hostAndPorts) { StringBuilder sb = new StringBuilder(); for (HostAndPort hostAndPort : hostAndPorts) { sb.append(hostAndPort.getHostText()).append(","); } if (sb.length() > 0) { sb.delete(sb.length() - 1, sb.length()); } return sb.toString(); }
public MinimalTransportClient(Settings settings, Set<HostAndPort> hostAndPorts) { super(settings, unmodifiableList(singletonList(Netty4Plugin.class))); boolean connectedToOneHost = false; for (HostAndPort hostAndPort : hostAndPorts) { try { addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(hostAndPort.getHostText()), hostAndPort.getPortOrDefault(9001))); connectedToOneHost = true; } catch (UnknownHostException e) { LOG.debug("Can not resolve host [" + hostAndPort.getHostText() + "]", e); } } if (!connectedToOneHost) { throw new IllegalStateException(format("Can not connect to one node from [%s]", hostAndPorts.stream() .map(h -> format("%s:%d", h.getHostText(), h.getPortOrDefault(9001))) .collect(Collectors.joining(",")))); } }
public KafkaSimpleConsumer(String topic, int partitionId, String clientId, List<String> brokers, boolean earliest) { List<HostAndPort> brokerList = new ArrayList<>(); for (String broker : brokers) { HostAndPort brokerHostAndPort = HostAndPort.fromString(broker); Preconditions.checkArgument( brokerHostAndPort.getHostText() != null && !brokerHostAndPort.getHostText().isEmpty() && brokerHostAndPort.hasPort(), "kafka broker [%s] is not valid, must be <host>:<port>", broker ); brokerList.add(brokerHostAndPort); } this.allBrokers = Collections.unmodifiableList(brokerList); this.topic = topic; this.partitionId = partitionId; this.clientId = StringUtils.format("%s_%d_%s", topic, partitionId, clientId); this.leaderLookupClientId = clientId + "leaderLookup"; this.replicaBrokers = new ArrayList<>(); this.replicaBrokers.addAll(this.allBrokers); this.earliest = earliest; log.info( "KafkaSimpleConsumer initialized with clientId [%s] for message consumption and clientId [%s] for leader lookup", this.clientId, this.leaderLookupClientId ); }
private static void addHostToClient(HostAndPort host, TransportClient client) { try { client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(host.getHostText()), host.getPortOrDefault(9001))); } catch (UnknownHostException e) { throw new IllegalStateException("Can not resolve host [" + host + "]", e); } }
private static Iterable<InetSocketAddress> getZkAddresses(URI uri) { String zkServers = getZKServersFromDLUri(uri); String[] zkServerList = StringUtils.split(zkServers, ','); ImmutableList.Builder<InetSocketAddress> builder = ImmutableList.builder(); for (String zkServer : zkServerList) { HostAndPort hostAndPort = HostAndPort.fromString(zkServer).withDefaultPort(2181); builder.add(InetSocketAddress.createUnresolved( hostAndPort.getHostText(), hostAndPort.getPort())); } return builder.build(); }
.withDefaultPort(port); LOG.info("Connecting to {}:{}", hp.getHostText(), hp.getPort()); return new URI(THRIFT_SCHEMA, null, hp.getHostText(), hp.getPort(), null, null, null);
private SimpleConsumer createConsumer(TopicPartition topicPartition) { HostAndPort leader = findLeader(topicPartition); if (leader == null) { LOG.warn("no leader for topic {} partition {}", topicPartition.getTopic(), topicPartition.getPartition()); return null; } LOG.debug("leader for topic {} partition {} is {}", topicPartition.getTopic(), topicPartition.getPartition(), leader); final String clientName = getClientName(topicPartition); return createConsumer(leader.getHostText(), leader.getPort(), clientName); }
DruidServerHolder(DruidServer druidServer) { this.druidServer = druidServer; try { HostAndPort hostAndPort = HostAndPort.fromString(druidServer.getHost()); this.syncer = new ChangeRequestHttpSyncer<>( smileMapper, httpClient, executor, new URL(druidServer.getScheme(), hostAndPort.getHostText(), hostAndPort.getPort(), "/"), "/druid-internal/v1/segments", SEGMENT_LIST_RESP_TYPE_REF, config.getServerTimeout(), config.getServerUnstabilityTimeout(), createSyncListener() ); } catch (MalformedURLException ex) { throw new IAE(ex, "Failed to construct server URL."); } }
if (host != null) { hostAndPort = HostAndPort.fromString(host); host = hostAndPort.getHostText(); portFromHostConfig = hostAndPort.hasPort() ? hostAndPort.getPort() : null; if (plainTextPort != null && portFromHostConfig != null && !plainTextPort.equals(portFromHostConfig)) {
public ProgressMonitor(SecorConfig config) throws Exception { mConfig = config; mZookeeperConnector = new ZookeeperConnector(mConfig); try { Class timestampClass = Class.forName(mConfig.getKafkaClientClass()); this.mKafkaClient = (KafkaClient) timestampClass.newInstance(); this.mKafkaClient.init(config); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { throw new RuntimeException(e); } mMessageParser = (MessageParser) ReflectionUtil.createMessageParser( mConfig.getMessageParserClass(), mConfig); mPrefix = mConfig.getMonitoringPrefix(); if (Strings.isNullOrEmpty(mPrefix)) { mPrefix = "secor"; } if (mConfig.getStatsDHostPort() != null && !mConfig.getStatsDHostPort().isEmpty()) { HostAndPort hostPort = HostAndPort.fromString(mConfig.getStatsDHostPort()); mStatsDClient = new NonBlockingStatsDClient(null, hostPort.getHostText(), hostPort.getPort(), mConfig.getStatsDDogstatsdConstantTags()); } }
try { log.info("Finding new leader from Kafka brokers, try broker [%s]", broker.toString()); consumer = new SimpleConsumer(broker.getHostText(), broker.getPort(), SO_TIMEOUT_MILLIS, BUFFER_SIZE, leaderLookupClientId); TopicMetadataResponse resp = consumer.send(new TopicMetadataRequest(Collections.singletonList(topic)));
@Override public SimpleConsumer load(HostAndPort host) throws Exception { LOGGER.info("Creating new Consumer for {}", host); return new SimpleConsumer(host.getHostText(), host.getPort(), 10000, 1024, "consumer"); } }
private SingularityHostState getHostState() { final boolean master = isMaster(); final RuntimeMXBean mxBean = ManagementFactory.getRuntimeMXBean(); final long uptime = mxBean.getUptime(); final long now = System.currentTimeMillis(); final Optional<Long> lastOfferTimestamp = getLastOfferTimestamp(); final Optional<Long> millisSinceLastOfferTimestamp = lastOfferTimestamp.isPresent() ? Optional.of(now - lastOfferTimestamp.get()) : Optional.<Long> absent(); String mesosMaster = null; Optional<MasterInfo> mesosMasterInfo = getMaster(); if (mesosMasterInfo.isPresent()) { mesosMaster = MesosUtils.getMasterHostAndPort(mesosMasterInfo.get()); } double cachedCpus = 0; double cachedMemoryBytes = 0; int numCachedOffers = 0; for (Offer offer : offerCache.peekOffers()) { cachedCpus += MesosUtils.getNumCpus(offer); cachedMemoryBytes += MesosUtils.getMemory(offer); numCachedOffers++; } return new SingularityHostState(master, uptime, scheduler.getState().name(), millisSinceLastOfferTimestamp, hostAndPort.getHostText(), hostAndPort.getHostText(), mesosMaster, scheduler.isRunning(), numCachedOffers, cachedCpus, cachedMemoryBytes); }
String hostHeader = request.getHeader(HttpHeaders.HOST); if (hostHeader != null && virtualHost.isPresent()) { hostHeader = HostAndPort.fromString(hostHeader).getHostText(); String virtualHostSuffix = "." + virtualHost.get(); if (!hostHeader.equals(virtualHost.get())) {
build.bind(address.getHostText(), address.getPort()); } catch (InterruptedException e) { addError(e);
@Override public boolean apply(HostAndPort input) { if (input.getHostText().indexOf(publicIpPrefix) == -1) return false; String id = input.getHostText().replace(publicIpPrefix, ""); NodeMetadata node = nodes.get(id); return node != null && node.getStatus() == Status.RUNNING; }
private AssociationMetadata associationMetadataFromPortMapping(PortMapping portMapping) { String publicIpId = portMapping.getPublicEndpoint().getHostText(); HostAndPort publicEndpoint = portMapping.getPublicEndpoint(); Location location = portMapping.getTarget(); int privatePort = portMapping.getPrivatePort(); return new AssociationMetadata(publicIpId, publicEndpoint, location, privatePort); }
private UserAndHostAndPort parseUserAndHostAndPort(String val, int defaultPort) { UserAndHostAndPort result = parseUserAndHostAndPort(val); if (!result.getHostAndPort().hasPort()) { result = UserAndHostAndPort.fromParts(result.getUser(), result.getHostAndPort().getHostText(), defaultPort); } return result; } }