Search in sources :

Example 76 with BindException

use of java.net.BindException in project GNS by MobilityFirst.

the class GNSApp method startDNS.

private void startDNS() throws SecurityException, SocketException, UnknownHostException {
    try {
        if (Config.getGlobalBoolean(GNSConfig.GNSC.DNS_GNS_ONLY)) {
            dnsTranslator = new DnsTranslator(Inet4Address.getByName("0.0.0.0"), 53, requestHandler);
            dnsTranslator.start();
        } else if (Config.getGlobalBoolean(GNSConfig.GNSC.DNS_ONLY)) {
            if (Config.getGlobalString(GNSConfig.GNSC.GNS_SERVER_IP) == GNSConfig.NONE) {
                GNSConfig.getLogger().severe("FAILED TO START DNS SERVER: GNS Server IP must be specified");
                return;
            }
            GNSConfig.getLogger().info("GNS Server IP" + Config.getGlobalString(GNSConfig.GNSC.GNS_SERVER_IP));
            udpDnsServer = new UdpDnsServer(Inet4Address.getByName("0.0.0.0"), 53, Config.getGlobalString(GNSConfig.GNSC.DNS_UPSTREAM_SERVER_IP), Config.getGlobalString(GNSConfig.GNSC.GNS_SERVER_IP), requestHandler);
            udpDnsServer.start();
        } else {
            udpDnsServer = new UdpDnsServer(Inet4Address.getByName("0.0.0.0"), 53, Config.getGlobalString(GNSConfig.GNSC.DNS_UPSTREAM_SERVER_IP), null, requestHandler);
            udpDnsServer.start();
        }
    } catch (BindException e) {
        GNSConfig.getLogger().warning("Not running DNS Service because it needs root permission! " + "If you want DNS run the server using sudo.");
    }
}
Also used : BindException(java.net.BindException) DnsTranslator(edu.umass.cs.gnsserver.gnamed.DnsTranslator) UdpDnsServer(edu.umass.cs.gnsserver.gnamed.UdpDnsServer)

Example 77 with BindException

use of java.net.BindException in project GNS by MobilityFirst.

the class GNSHttpsServer method tryPort.

/**
   * Try to start the http server at the port.
   *
   * @param port
   * @return true if it was started
   */
@Override
public boolean tryPort(int port) {
    try {
        InetSocketAddress addr = new InetSocketAddress(port);
        httpsServer = HttpsServer.create(addr, 0);
        SSLContext sslContext = createSSLContext();
        httpsServer.setHttpsConfigurator(new HttpsConfigurator(sslContext) {

            @Override
            public void configure(HttpsParameters parameters) {
                // initialise the SSL context
                SSLContext context = getSSLContext();
                SSLEngine engine = context.createSSLEngine();
                //parameters.setNeedClientAuth(false);
                parameters.setCipherSuites(engine.getEnabledCipherSuites());
                parameters.setProtocols(engine.getEnabledProtocols());
                // get the default parameters
                SSLParameters sslParameters = context.getDefaultSSLParameters();
                sslParameters.setNeedClientAuth(true);
                parameters.setNeedClientAuth(true);
                parameters.setSSLParameters(sslParameters);
            }
        });
        httpsServer.createContext("/", new EchoHttpHandler());
        httpsServer.createContext("/" + GNS_PATH, new DefaultHttpHandler());
        httpsServer.setExecutor(Executors.newCachedThreadPool());
        httpsServer.start();
        // Need to do this for the places where we expose the secure http service to the user
        requestHandler.setHttpsServerPort(port);
        LOG.log(Level.INFO, "HTTPS server is listening on port {0}", port);
        return true;
    } catch (BindException e) {
        LOG.log(Level.FINE, "HTTPS server failed to start on port {0} due to {1}", new Object[] { port, e.getMessage() });
        return false;
    } catch (IOException | NoSuchAlgorithmException | KeyStoreException | CertificateException | UnrecoverableKeyException | KeyManagementException e) {
        LOG.log(Level.FINE, "HTTPS server failed to start on port {0} due to {1}", new Object[] { port, e.getMessage() });
        e.printStackTrace();
        return false;
    }
}
Also used : HttpsConfigurator(com.sun.net.httpserver.HttpsConfigurator) InetSocketAddress(java.net.InetSocketAddress) SSLEngine(javax.net.ssl.SSLEngine) HttpsParameters(com.sun.net.httpserver.HttpsParameters) BindException(java.net.BindException) CertificateException(java.security.cert.CertificateException) SSLContext(javax.net.ssl.SSLContext) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) KeyStoreException(java.security.KeyStoreException) KeyManagementException(java.security.KeyManagementException) SSLParameters(javax.net.ssl.SSLParameters) UnrecoverableKeyException(java.security.UnrecoverableKeyException)

Example 78 with BindException

use of java.net.BindException in project hadoop by apache.

the class DatanodeHttpServer method start.

public void start() throws IOException {
    if (httpServer != null) {
        InetSocketAddress infoAddr = DataNode.getInfoAddr(conf);
        ChannelFuture f = httpServer.bind(infoAddr);
        try {
            f.syncUninterruptibly();
        } catch (Throwable e) {
            if (e instanceof BindException) {
                throw NetUtils.wrapException(null, 0, infoAddr.getHostName(), infoAddr.getPort(), (SocketException) e);
            } else {
                throw e;
            }
        }
        httpAddress = (InetSocketAddress) f.channel().localAddress();
        LOG.info("Listening HTTP traffic on " + httpAddress);
    }
    if (httpsServer != null) {
        InetSocketAddress secInfoSocAddr = NetUtils.createSocketAddr(conf.getTrimmed(DFS_DATANODE_HTTPS_ADDRESS_KEY, DFS_DATANODE_HTTPS_ADDRESS_DEFAULT));
        ChannelFuture f = httpsServer.bind(secInfoSocAddr);
        try {
            f.syncUninterruptibly();
        } catch (Throwable e) {
            if (e instanceof BindException) {
                throw NetUtils.wrapException(null, 0, secInfoSocAddr.getHostName(), secInfoSocAddr.getPort(), (SocketException) e);
            } else {
                throw e;
            }
        }
        httpsAddress = (InetSocketAddress) f.channel().localAddress();
        LOG.info("Listening HTTPS traffic on " + httpsAddress);
    }
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) SocketException(java.net.SocketException) InetSocketAddress(java.net.InetSocketAddress) BindException(java.net.BindException)

Example 79 with BindException

use of java.net.BindException in project hadoop by apache.

the class TestRefreshCallQueue method setUp.

@Before
public void setUp() throws Exception {
    // We want to count additional events, so we reset here
    mockQueueConstructions = 0;
    mockQueuePuts = 0;
    int portRetries = 5;
    int nnPort;
    for (; portRetries > 0; --portRetries) {
        // Pick a random port in the range [30000,60000).
        nnPort = 30000 + rand.nextInt(30000);
        config = new Configuration();
        callQueueConfigKey = "ipc." + nnPort + ".callqueue.impl";
        config.setClass(callQueueConfigKey, MockCallQueue.class, BlockingQueue.class);
        config.set("hadoop.security.authorization", "true");
        FileSystem.setDefaultUri(config, "hdfs://localhost:" + nnPort);
        fs = FileSystem.get(config);
        try {
            cluster = new MiniDFSCluster.Builder(config).nameNodePort(nnPort).build();
            cluster.waitActive();
            break;
        } catch (BindException be) {
        // Retry with a different port number.
        }
    }
    if (portRetries == 0) {
        // Bail if we get very unlucky with our choice of ports.
        fail("Failed to pick an ephemeral port for the NameNode RPC server.");
    }
}
Also used : MiniDFSCluster(org.apache.hadoop.hdfs.MiniDFSCluster) Configuration(org.apache.hadoop.conf.Configuration) BindException(java.net.BindException) Before(org.junit.Before)

Example 80 with BindException

use of java.net.BindException in project robovm by robovm.

the class OldSocketTest method test_ConstructorLjava_lang_StringILjava_net_InetAddressI2.

public void test_ConstructorLjava_lang_StringILjava_net_InetAddressI2() throws IOException {
    Socket s1 = new Socket("www.google.com", 80, null, 0);
    try {
        Socket s2 = new Socket("www.google.com", 80, null, s1.getLocalPort());
        try {
            s2.close();
        } catch (IOException ignored) {
        }
        fail("second connect should have failed with EADDRINUSE");
    } catch (BindException expected) {
    // success!
    } finally {
        try {
            s1.close();
        } catch (IOException ignored) {
        }
    }
}
Also used : BindException(java.net.BindException) IOException(java.io.IOException) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket)

Aggregations

BindException (java.net.BindException)104 IOException (java.io.IOException)34 InetSocketAddress (java.net.InetSocketAddress)25 ServerSocket (java.net.ServerSocket)22 Test (org.junit.Test)22 File (java.io.File)12 SocketException (java.net.SocketException)10 Configuration (org.apache.hadoop.conf.Configuration)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 InterruptedIOException (java.io.InterruptedIOException)5 MiniDFSNNTopology (org.apache.hadoop.hdfs.MiniDFSNNTopology)5 InetAddress (java.net.InetAddress)4 UnknownHostException (java.net.UnknownHostException)4 RemoteException (java.rmi.RemoteException)4 NIOServerCnxnFactory (org.apache.zookeeper.server.NIOServerCnxnFactory)4 ZooKeeperServer (org.apache.zookeeper.server.ZooKeeperServer)4 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)3 Socket (java.net.Socket)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3