List of usage examples for com.google.common.net HostAndPort fromString
public static HostAndPort fromString(String hostPortString)
From source file:org.kududb.util.NetUtil.java
/** * Parse a "host:port" pair into a {@link HostAndPort} object. If there is no * port specified in the string, then 'defaultPort' is used. * * @param addrString A host or a "host:port" pair. * @param defaultPort Default port to use if no port is specified in addrString. * @return The HostAndPort object constructed from addrString. *//*from w w w. j a va 2 s . co m*/ public static HostAndPort parseString(String addrString, int defaultPort) { return addrString.indexOf(':') == -1 ? HostAndPort.fromParts(addrString, defaultPort) : HostAndPort.fromString(addrString); }
From source file:org.apache.druid.server.http.HostAndPortWithScheme.java
public static HostAndPortWithScheme fromString(String scheme, String hostPortString) { return new HostAndPortWithScheme(checkAndGetScheme(scheme), HostAndPort.fromString(hostPortString)); }
From source file:com.linecorp.armeria.client.Endpoint.java
/** * Parse the authority part of a URI. The authority part may have one of the following formats: * <ul>/*from w w w.ja v a2s .c om*/ * <li>{@code "group:<groupName>"} for a group endpoint</li> * <li>{@code "<host>:<port>"} for a host endpoint</li> * <li>{@code "<host>"} for a host endpoint with no port number specified</li> * </ul> */ public static Endpoint parse(String authority) { requireNonNull(authority, "authority"); if (authority.startsWith("group:")) { return ofGroup(authority.substring(6)); } final HostAndPort parsed = HostAndPort.fromString(authority).withDefaultPort(0); return new Endpoint(parsed.getHostText(), parsed.getPort(), 1000); }
From source file:com.twitter.distributedlog.client.serverset.DLZkServerSet.java
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())); }//w ww .j a v a2 s. c o m return builder.build(); }
From source file:com.mgmtp.perfload.core.console.util.HostAndPortConverter.java
@Override public HostAndPort convert(final String value) { try {// w ww.j av a 2 s. co m return HostAndPort.fromString(value).withDefaultPort(DEFAULT_PORT); } catch (IllegalStateException ex) { throw new ParameterException(getErrorString(value, "host and port")); } }
From source file:io.mandrel.common.bson.HostAndPortCodec.java
@Override public HostAndPort decode(final BsonReader reader, final DecoderContext decoderContext) { return HostAndPort.fromString(reader.readString()); }
From source file:org.apache.beam.harness.channel.SocketAddressFactory.java
/** * Parse a {@link SocketAddress} from the given string. *///from w ww .j a va 2 s . c om public static SocketAddress createFrom(String value) { if (value.startsWith(UNIX_DOMAIN_SOCKET_PREFIX)) { // Unix Domain Socket address. // Create the underlying file for the Unix Domain Socket. String filePath = value.substring(UNIX_DOMAIN_SOCKET_PREFIX.length()); File file = new File(filePath); if (!file.isAbsolute()) { throw new IllegalArgumentException("File path must be absolute: " + filePath); } try { if (file.createNewFile()) { // If this application created the file, delete it when the application exits. file.deleteOnExit(); } } catch (IOException ex) { throw new RuntimeException(ex); } // Create the SocketAddress referencing the file. return new DomainSocketAddress(file); } else { // Standard TCP/IP address. HostAndPort hostAndPort = HostAndPort.fromString(value); checkArgument(hostAndPort.hasPort(), "Address must be a unix:// path or be in the form host:port. Got: %s", value); return new InetSocketAddress(hostAndPort.getHostText(), hostAndPort.getPort()); } }
From source file:co.cask.cdap.explore.security.JobHistoryServerTokenUtils.java
/** * Gets a JHS delegation token and stores it in the given Credentials. * * @return the same Credentials instance as the one given in parameter. *///from ww w.j a va2s .c om public static Credentials obtainToken(Configuration configuration, Credentials credentials) { if (!UserGroupInformation.isSecurityEnabled()) { return credentials; } String historyServerAddress = configuration.get("mapreduce.jobhistory.address"); HostAndPort hostAndPort = HostAndPort.fromString(historyServerAddress); try { LOG.info("Obtaining delegation token for JHS"); ResourceMgrDelegate resourceMgrDelegate = new ResourceMgrDelegate(new YarnConfiguration(configuration)); MRClientCache clientCache = new MRClientCache(configuration, resourceMgrDelegate); MRClientProtocol hsProxy = clientCache.getInitializedHSProxy(); GetDelegationTokenRequest request = new GetDelegationTokenRequestPBImpl(); request.setRenewer(YarnUtils.getYarnTokenRenewer(configuration)); InetSocketAddress address = new InetSocketAddress(hostAndPort.getHostText(), hostAndPort.getPort()); Token<TokenIdentifier> token = ConverterUtils .convertFromYarn(hsProxy.getDelegationToken(request).getDelegationToken(), address); credentials.addToken(new Text(token.getService()), token); return credentials; } catch (Exception e) { LOG.error("Failed to get secure token for JHS at {}.", hostAndPort, e); throw Throwables.propagate(e); } }
From source file:com.google.devtools.kythe.platform.shared.RemoteFileData.java
public RemoteFileData(String addr) { HostAndPort hp = HostAndPort.fromString(addr); ChannelImpl channel = NettyChannelBuilder.forAddress(new InetSocketAddress(hp.getHostText(), hp.getPort())) .build();/*from w ww . j a v a 2s . c o m*/ stub = FileDataServiceGrpc.newStub(channel); }
From source file:com.streamsets.pipeline.destination.aerospike.AerospikeValidationUtil.java
public List<Host> validateConnectionString(List<Stage.ConfigIssue> issues, String connectionString, String configGroupName, String configName, Stage.Context context) { List<Host> clusterNodesList = new ArrayList<>(); if (connectionString == null || connectionString.isEmpty()) { issues.add(context.createConfigIssue(configGroupName, configName, AerospikeErrors.AEROSPIKE_01, configName));/*ww w.j a v a 2 s. c o m*/ } else { String[] nodes = connectionString.split(","); for (String node : nodes) { try { HostAndPort hostAndPort = HostAndPort.fromString(node); if (!hostAndPort.hasPort() || hostAndPort.getPort() < 0) { issues.add(context.createConfigIssue(configGroupName, configName, AerospikeErrors.AEROSPIKE_02, connectionString)); } else { clusterNodesList.add(new Host(hostAndPort.getHostText(), hostAndPort.getPort())); } } catch (IllegalArgumentException e) { issues.add(context.createConfigIssue(configGroupName, configName, AerospikeErrors.AEROSPIKE_02, connectionString)); } } } return clusterNodesList; }