List of usage examples for com.google.common.net HostAndPort hasPort
public boolean hasPort()
From source file:org.apache.accumulo.core.util.AddressUtil.java
static public HostAndPort parseAddress(String address, boolean ignoreMissingPort) throws NumberFormatException { address = address.replace('+', ':'); HostAndPort hap = HostAndPort.fromString(address); if (!ignoreMissingPort && !hap.hasPort()) throw new IllegalArgumentException("Address was expected to contain port. address=" + address); return hap;/* ww w . j a va2s . c o m*/ }
From source file:com.dasasian.chok.util.ZkChokUtil.java
public static ZkServer startZkServer(ZkConfiguration conf) { String server = Iterables.getOnlyElement(COMMA_SPLITTER.split(conf.getServers())); HostAndPort hostAndPort = HostAndPort.fromString(server); if (!hostAndPort.hasPort()) { throw new IllegalArgumentException("No Port Specified for ZkServer"); } else {/*from ww w .j av a 2 s. c om*/ String host = hostAndPort.getHostText(); // if (!host.equals("127.0.0.1") && !host.equals("localhost")) { // throw new IllegalArgumentException("Attempting to start ZkServer remotely on " + host + " valid values are 127.0.0.1 or localhost"); // } } ZkServer zkServer = new ZkServer(conf.getDataDir(), conf.getLogDataDir(), new DefaultNameSpaceImpl(conf), hostAndPort.getPort(), conf.getTickTime()); zkServer.start(); return zkServer; }
From source file:org.apache.beam.harness.channel.SocketAddressFactory.java
/** * Parse a {@link SocketAddress} from the given string. *//*from w w w. ja va 2 s . co m*/ 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:org.apache.beam.runners.dataflow.worker.fn.SocketAddressFactory.java
/** Parse a {@link SocketAddress} from the given string. */ 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); }/*from ww w .ja v a 2s. c o m*/ 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.getHost(), hostAndPort.getPort()); } }
From source file:com.streamsets.pipeline.destination.aerospike.AerospikeBeanConfig.java
public static List<Host> getAerospikeHosts(List<Target.ConfigIssue> issues, List<String> connectionString, String configGroupName, String configName, Target.Context context) { List<Host> clusterNodesList = new ArrayList<>(); if (connectionString == null || connectionString.isEmpty()) { issues.add(context.createConfigIssue(configGroupName, configName, AerospikeErrors.AEROSPIKE_01, configName));/*from w ww.j av a 2 s . c o m*/ } else { for (String node : connectionString) { 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; }
From source file:org.apache.slider.core.zk.ZookeeperUtils.java
public static String buildQuorumEntry(HostAndPort hostAndPort, int defaultPort) { String s = hostAndPort.toString(); if (hostAndPort.hasPort()) { return s; } else {//from www.j av a 2 s .c om return s + ":" + defaultPort; } }
From source file:org.voltdb.utils.Collector.java
public static boolean uploadToServer(String collectionFilePath, String host, String username, String password) throws Exception { attemptConnect(host, username, password); SSHTools ssh = new SSHTools(username, null); SFTPSession sftp = null;//from w w w . ja v a 2 s . com HostAndPort hostAndPort = HostAndPort.fromString(host); if (hostAndPort.hasPort()) { sftp = ssh.getSftpSession(username, password, null, hostAndPort.getHostText(), hostAndPort.getPort(), null); } else { sftp = ssh.getSftpSession(username, password, null, host, null); } String rootpath = sftp.exec("pwd").trim(); HashMap<File, File> files = new HashMap<File, File>(); File src = new File(collectionFilePath); File dest = new File(rootpath + File.separator + new File(collectionFilePath).getName()); files.put(src, dest); try { sftp.ensureDirectoriesExistFor(files.values()); sftp.copyOverFiles(files); } finally { if (sftp != null) { sftp.terminate(); } } return true; }
From source file:org.voltdb.utils.Collector.java
public static void attemptConnect(String host, String username, String password) throws Exception { SSHTools ssh = new SSHTools(username, null); try {//from w w w . j ava 2 s . co m HostAndPort hostAndPort = HostAndPort.fromString(host); if (hostAndPort.hasPort()) { ssh.getSftpSession(username, password, null, hostAndPort.getHostText(), hostAndPort.getPort(), null); } else { ssh.getSftpSession(username, password, null, host, null); } } catch (SFTPException e) { String errorMsg = e.getCause().getMessage(); /* * e.getCause() is JSchException and the java exception class name only appears in message * hide java class name and extract error message */ Pattern pattern = Pattern.compile("(java.*Exception: )(.*)"); Matcher matcher = pattern.matcher(errorMsg); if (matcher.matches()) { if (errorMsg.startsWith("java.net.UnknownHostException")) { throw new Exception("Unknown host: " + matcher.group(2)); } else { throw new Exception(matcher.group(2)); } } else { if (errorMsg.equals("Auth cancel") || errorMsg.equals("Auth fail")) { // "Auth cancel" appears when username doesn't exist or password is wrong throw new Exception("Authorization rejected"); } else { throw new Exception(errorMsg.substring(0, 1).toUpperCase() + errorMsg.substring(1)); } } } catch (Exception e) { String errorMsg = e.getMessage(); throw new Exception(errorMsg.substring(0, 1).toUpperCase() + errorMsg.substring(1)); } }
From source file:com.torodb.mongodb.core.MongodServerConfig.java
public MongodServerConfig(HostAndPort hostAndPort) { this.hostAndPort = hostAndPort; Preconditions.checkArgument(hostAndPort.hasPort(), "The host and port of a given mongod server must have a port"); }
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));//from w w w . j ava 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; }