List of usage examples for java.net InetSocketAddress getPort
public final int getPort()
From source file:eu.stratosphere.client.CliFrontendJobManagerConnectionTest.java
@Test public void testManualOptionsOverridesConfig() { try {/*from www . jav a 2 s .com*/ String[] arguments = { "-m", "10.221.130.22:7788" }; CommandLine line = new PosixParser().parse(CliFrontend.getJobManagerAddressOption(new Options()), arguments, false); TestingCliFrontend frontend = new TestingCliFrontend(CliFrontendTestUtils.getConfigDir()); InetSocketAddress address = frontend.getJobManagerAddress(line); assertNotNull(address); assertEquals("10.221.130.22", address.getAddress().getHostAddress()); assertEquals(7788, address.getPort()); } catch (Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); fail("Program caused an exception: " + e.getMessage()); } }
From source file:eu.stratosphere.client.CliFrontendJobManagerConnectionTest.java
@Test public void testManualOptionsOverridesYarn() { try {//from ww w. j a v a2s . c o m String[] arguments = { "-m", "10.221.130.22:7788" }; CommandLine line = new PosixParser().parse(CliFrontend.getJobManagerAddressOption(new Options()), arguments, false); TestingCliFrontend frontend = new TestingCliFrontend(CliFrontendTestUtils.getConfigDirWithYarnFile()); InetSocketAddress address = frontend.getJobManagerAddress(line); assertNotNull(address); assertEquals("10.221.130.22", address.getAddress().getHostAddress()); assertEquals(7788, address.getPort()); } catch (Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); fail("Program caused an exception: " + e.getMessage()); } }
From source file:org.apache.flink.client.CliFrontendAddressConfigurationTest.java
@Test public void testManualOptionsOverridesConfig() { try {/*www . j a v a2 s.c o m*/ CliFrontend frontend = new CliFrontend(CliFrontendTestUtils.getConfigDir()); CommandLineOptions options = mock(CommandLineOptions.class); when(options.getJobManagerAddress()).thenReturn("10.221.130.22:7788"); frontend.updateConfig(options); Configuration config = frontend.getConfiguration(); InetSocketAddress expectedAddress = new InetSocketAddress("10.221.130.22", 7788); checkJobManagerAddress(config, expectedAddress.getHostName(), expectedAddress.getPort()); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
From source file:org.apache.flink.client.CliFrontendAddressConfigurationTest.java
@Test public void testManualOptionsOverridesYarn() { try {/*from w ww . j a v a 2s. co m*/ CliFrontend frontend = new CliFrontend(CliFrontendTestUtils.getConfigDirWithYarnFile()); CommandLineOptions options = mock(CommandLineOptions.class); when(options.getJobManagerAddress()).thenReturn("10.221.130.22:7788"); frontend.updateConfig(options); Configuration config = frontend.getConfiguration(); InetSocketAddress expectedAddress = new InetSocketAddress("10.221.130.22", 7788); checkJobManagerAddress(config, expectedAddress.getHostName(), expectedAddress.getPort()); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
From source file:org.apache.hadoop.hdfs.MiniDFSClusterWithNodeGroup.java
public synchronized void startDataNodes(Configuration conf, int numDataNodes, boolean manageDfsDirs, StartupOption operation, String[] racks, String[] nodeGroups, String[] hosts, long[] simulatedCapacities) throws IOException { conf.set("slave.host.name", "127.0.0.1"); int curDatanodesNum = dataNodes.size(); // for mincluster's the default initialDelay for BRs is 0 if (conf.get(DFSConfigKeys.DFS_BLOCKREPORT_INITIAL_DELAY_KEY) == null) { conf.setLong(DFSConfigKeys.DFS_BLOCKREPORT_INITIAL_DELAY_KEY, 0); }/*from w ww . j a v a 2 s . co m*/ // If minicluster's name node is null assume that the conf has been // set with the right address:port of the name node. // if (nameNode != null) { // set conf from the name node InetSocketAddress nnAddr = nameNode.getNameNodeAddress(); int nameNodePort = nnAddr.getPort(); FileSystem.setDefaultUri(conf, "hdfs://" + nnAddr.getHostName() + ":" + Integer.toString(nameNodePort)); } if (racks != null && numDataNodes > racks.length) { throw new IllegalArgumentException("The length of racks [" + racks.length + "] is less than the number of datanodes [" + numDataNodes + "]."); } if (nodeGroups != null && numDataNodes > nodeGroups.length) { throw new IllegalArgumentException("The length of nodeGroups [" + nodeGroups.length + "] is less than the number of datanodes [" + numDataNodes + "]."); } if (hosts != null && numDataNodes > hosts.length) { throw new IllegalArgumentException("The length of hosts [" + hosts.length + "] is less than the number of datanodes [" + numDataNodes + "]."); } //Generate some hostnames if required if (racks != null && hosts == null) { hosts = new String[numDataNodes]; for (int i = curDatanodesNum; i < curDatanodesNum + numDataNodes; i++) { hosts[i - curDatanodesNum] = "host" + i + ".foo.com"; } } if (simulatedCapacities != null && numDataNodes > simulatedCapacities.length) { throw new IllegalArgumentException("The length of simulatedCapacities [" + simulatedCapacities.length + "] is less than the number of datanodes [" + numDataNodes + "]."); } // Set up the right ports for the datanodes conf.set("dfs.datanode.address", "127.0.0.1:0"); conf.set("dfs.datanode.http.address", "127.0.0.1:0"); conf.set("dfs.datanode.ipc.address", "127.0.0.1:0"); String[] dnArgs = (operation == null || operation != StartupOption.ROLLBACK) ? null : new String[] { operation.getName() }; for (int i = curDatanodesNum; i < curDatanodesNum + numDataNodes; i++) { Configuration dnConf = new Configuration(conf); if (manageDfsDirs) { File dir1 = new File(data_dir, "data" + (2 * i + 1)); File dir2 = new File(data_dir, "data" + (2 * i + 2)); dir1.mkdirs(); dir2.mkdirs(); if (!dir1.isDirectory() || !dir2.isDirectory()) { throw new IOException( "Mkdirs failed to create directory for DataNode " + i + ": " + dir1 + " or " + dir2); } dnConf.set(DataNode.DATA_DIR_KEY, dir1.getPath() + "," + dir2.getPath()); } if (simulatedCapacities != null) { dnConf.setBoolean("dfs.datanode.simulateddatastorage", true); dnConf.setLong(SimulatedFSDataset.CONFIG_PROPERTY_CAPACITY, simulatedCapacities[i - curDatanodesNum]); } LOG.info("Starting DataNode " + i + " with " + DFSConfigKeys.DFS_DATANODE_DATA_DIR_KEY + ": " + dnConf.get(DFSConfigKeys.DFS_DATANODE_DATA_DIR_KEY)); if (hosts != null) { dnConf.set("slave.host.name", hosts[i - curDatanodesNum]); LOG.info("Starting DataNode " + i + " with hostname set to: " + dnConf.get("slave.host.name")); } if (racks != null) { String name = hosts[i - curDatanodesNum]; if (nodeGroups == null) { LOG.info("Adding node with hostname : " + name + " to rack " + racks[i - curDatanodesNum]); StaticMapping.addNodeToRack(name, racks[i - curDatanodesNum]); } else { LOG.info("Adding node with hostname : " + name + " to serverGroup " + nodeGroups[i - curDatanodesNum] + " and rack " + racks[i - curDatanodesNum]); StaticMapping.addNodeToRack(name, racks[i - curDatanodesNum] + nodeGroups[i - curDatanodesNum]); } } Configuration newconf = new Configuration(dnConf); // save config if (hosts != null) { NetUtils.addStaticResolution(hosts[i - curDatanodesNum], "localhost"); } DataNode dn = DataNode.instantiateDataNode(dnArgs, dnConf); if (dn == null) throw new IOException( "Cannot start DataNode in " + dnConf.get(DFSConfigKeys.DFS_DATANODE_DATA_DIR_KEY)); //since the HDFS does things based on IP:port, we need to add the mapping //for IP:port to rackId String ipAddr = dn.getSelfAddr().getAddress().getHostAddress(); if (racks != null) { int port = dn.getSelfAddr().getPort(); if (nodeGroups == null) { LOG.info("Adding node with IP:port : " + ipAddr + ":" + port + " to rack " + racks[i - curDatanodesNum]); StaticMapping.addNodeToRack(ipAddr + ":" + port, racks[i - curDatanodesNum]); } else { LOG.info("Adding node with IP:port : " + ipAddr + ":" + port + " to nodeGroup " + nodeGroups[i - curDatanodesNum] + " and rack " + racks[i - curDatanodesNum]); StaticMapping.addNodeToRack(ipAddr + ":" + port, racks[i - curDatanodesNum] + nodeGroups[i - curDatanodesNum]); } } DataNode.runDatanodeDaemon(dn); dataNodes.add(new DataNodeProperties(dn, newconf, dnArgs)); } curDatanodesNum += numDataNodes; this.numDataNodes += numDataNodes; waitActive(); }
From source file:com.nebkat.junglist.bot.http.EasySSLSocketFactory.java
public Socket connectSocket(Socket sock, InetSocketAddress remoteAddress, InetSocketAddress localAddress, HttpParams params) throws IOException { int connTimeout = HttpConnectionParams.getConnectionTimeout(params); int soTimeout = HttpConnectionParams.getSoTimeout(params); int localPort = localAddress != null ? localAddress.getPort() : -1; SSLSocket sslsock = (SSLSocket) ((sock != null) ? sock : createSocket()); if (localAddress != null) { // we need to bind explicitly if (localPort < 0) { localPort = 0; // indicates "any" }//from w w w . j a va 2 s. c om InetSocketAddress isa = new InetSocketAddress(localAddress.getAddress(), localPort); sslsock.bind(isa); } sslsock.connect(remoteAddress, connTimeout); sslsock.setSoTimeout(soTimeout); return sslsock; }
From source file:org.apache.hadoop.ha.SshFenceByTcpPort.java
private boolean doFence(Session session, InetSocketAddress serviceAddr) throws JSchException { int port = serviceAddr.getPort(); try {//from w ww. j av a 2 s . co m LOG.info("Looking for process running on port " + port); int rc = execCommand(session, "PATH=$PATH:/sbin:/usr/sbin fuser -v -k -n tcp " + port); if (rc == 0) { LOG.info("Successfully killed process that was " + "listening on port " + port); // exit code 0 indicates the process was successfully killed. return true; } else if (rc == 1) { // exit code 1 indicates either that the process was not running // or that fuser didn't have root privileges in order to find it // (eg running as a different user) LOG.info("Indeterminate response from trying to kill service. " + "Verifying whether it is running using nc..."); rc = execCommand(session, "nc -z " + serviceAddr.getHostName() + " " + serviceAddr.getPort()); if (rc == 0) { // the service is still listening - we are unable to fence LOG.warn("Unable to fence - it is running but we cannot kill it"); return false; } else { LOG.info("Verified that the service is down."); return true; } } else { // other } LOG.info("rc: " + rc); return rc == 0; } catch (InterruptedException e) { LOG.warn("Interrupted while trying to fence via ssh", e); return false; } catch (IOException e) { LOG.warn("Unknown failure while trying to fence via ssh", e); return false; } }
From source file:org.olat.core.util.httpclient.EasySSLSocketFactory.java
@Override public Socket connectSocket(int connectTimeout, Socket sock, HttpHost host, InetSocketAddress remoteAddress, InetSocketAddress localAddress, HttpContext context) throws IOException { SSLSocket sslsock = (SSLSocket) ((sock != null) ? sock : createSocket()); int localPort = 0; if (localAddress != null) { // we need to bind explicitly if (localAddress.getPort() < 0) { localPort = 0; // indicates "any" }//from ww w. j av a 2 s.co m InetSocketAddress isa = new InetSocketAddress(localAddress.getAddress(), localPort); sslsock.bind(isa); } sslsock.connect(remoteAddress, 10000); sslsock.setSoTimeout(10000); return sslsock; }
From source file:org.sana.net.http.ssl.EasySSLSocketFactory.java
public Socket connectSocket(Socket arg0, InetSocketAddress arg1, InetSocketAddress arg2, HttpParams arg3) throws IOException, UnknownHostException, ConnectTimeoutException { return connectSocket(arg0, arg1.getHostName(), arg1.getPort(), arg2.getAddress(), arg2.getPort(), arg3); }
From source file:org.hyperic.hq.plugin.netservices.NetServicesCollector.java
protected void netstat() { if (!this.enableNetstat) { return;//from w w w .j a v a 2s . c o m } InetSocketAddress saddr = getSocketAddress(); byte[] address = saddr.getAddress().getAddress(); int port = saddr.getPort(); NetStat netstat; synchronized (sigar) { try { netstat = sigar.getNetStat(address, port); } catch (SigarException e) { return; } } setValue("InboundConnections", netstat.getTcpInboundTotal()); setValue("OutboundConnections", netstat.getTcpOutboundTotal()); setValue("AllInboundConnections", netstat.getAllInboundTotal()); setValue("AllOutboundConnections", netstat.getAllOutboundTotal()); int[] states = netstat.getTcpStates(); for (int i = 0; i < states.length; i++) { setValue("State" + NetConnection.getStateString(i), states[i]); } }