Search in sources :

Example 6 with ServerConnector

use of org.apache.hbase.thirdparty.org.eclipse.jetty.server.ServerConnector in project hbase by apache.

the class HMaster method putUpJettyServer.

// return the actual infoPort, -1 means disable info server.
private int putUpJettyServer() throws IOException {
    if (!conf.getBoolean("hbase.master.infoserver.redirect", true)) {
        return -1;
    }
    final int infoPort = conf.getInt("hbase.master.info.port.orig", HConstants.DEFAULT_MASTER_INFOPORT);
    // -1 is for disabling info server, so no redirecting
    if (infoPort < 0 || infoServer == null) {
        return -1;
    }
    if (infoPort == infoServer.getPort()) {
        // server is already running
        return infoPort;
    }
    final String addr = conf.get("hbase.master.info.bindAddress", "0.0.0.0");
    if (!Addressing.isLocalAddress(InetAddress.getByName(addr))) {
        String msg = "Failed to start redirecting jetty server. Address " + addr + " does not belong to this host. Correct configuration parameter: " + "hbase.master.info.bindAddress";
        LOG.error(msg);
        throw new IOException(msg);
    }
    // TODO I'm pretty sure we could just add another binding to the InfoServer run by
    // the RegionServer and have it run the RedirectServlet instead of standing up
    // a second entire stack here.
    masterJettyServer = new Server();
    final ServerConnector connector = new ServerConnector(masterJettyServer);
    connector.setHost(addr);
    connector.setPort(infoPort);
    masterJettyServer.addConnector(connector);
    masterJettyServer.setStopAtShutdown(true);
    masterJettyServer.setHandler(HttpServer.buildGzipHandler(masterJettyServer.getHandler()));
    final String redirectHostname = StringUtils.isBlank(useThisHostnameInstead) ? null : useThisHostnameInstead;
    final MasterRedirectServlet redirect = new MasterRedirectServlet(infoServer, redirectHostname);
    final WebAppContext context = new WebAppContext(null, "/", null, null, null, null, WebAppContext.NO_SESSIONS);
    context.addServlet(new ServletHolder(redirect), "/*");
    context.setServer(masterJettyServer);
    try {
        masterJettyServer.start();
    } catch (Exception e) {
        throw new IOException("Failed to start redirecting jetty server", e);
    }
    return connector.getLocalPort();
}
Also used : ServerConnector(org.apache.hbase.thirdparty.org.eclipse.jetty.server.ServerConnector) WebAppContext(org.apache.hbase.thirdparty.org.eclipse.jetty.webapp.WebAppContext) Server(org.apache.hbase.thirdparty.org.eclipse.jetty.server.Server) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) InfoServer(org.apache.hadoop.hbase.http.InfoServer) HttpServer(org.apache.hadoop.hbase.http.HttpServer) RpcServer(org.apache.hadoop.hbase.ipc.RpcServer) MasterRedirectServlet(org.apache.hadoop.hbase.master.http.MasterRedirectServlet) ServletHolder(org.apache.hbase.thirdparty.org.eclipse.jetty.servlet.ServletHolder) IOException(java.io.IOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) HBaseIOException(org.apache.hadoop.hbase.HBaseIOException) InterruptedIOException(java.io.InterruptedIOException) RSGroupAdminEndpoint(org.apache.hadoop.hbase.rsgroup.RSGroupAdminEndpoint) AccessDeniedException(org.apache.hadoop.hbase.security.AccessDeniedException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) ExecutionException(java.util.concurrent.ExecutionException) TableNotDisabledException(org.apache.hadoop.hbase.TableNotDisabledException) RemoteProcedureException(org.apache.hadoop.hbase.procedure2.RemoteProcedureException) NoSuchColumnFamilyException(org.apache.hadoop.hbase.regionserver.NoSuchColumnFamilyException) PleaseHoldException(org.apache.hadoop.hbase.PleaseHoldException) ReplicationException(org.apache.hadoop.hbase.replication.ReplicationException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) UnknownRegionException(org.apache.hadoop.hbase.UnknownRegionException) HBaseIOException(org.apache.hadoop.hbase.HBaseIOException) MasterStoppedException(org.apache.hadoop.hbase.exceptions.MasterStoppedException) KeeperException(org.apache.zookeeper.KeeperException) ServerNotRunningYetException(org.apache.hadoop.hbase.ipc.ServerNotRunningYetException) InvalidFamilyOperationException(org.apache.hadoop.hbase.InvalidFamilyOperationException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InterruptedIOException(java.io.InterruptedIOException) TableNotFoundException(org.apache.hadoop.hbase.TableNotFoundException) TimeoutException(java.util.concurrent.TimeoutException) ReplicationPeerNotFoundException(org.apache.hadoop.hbase.ReplicationPeerNotFoundException) PleaseRestartMasterException(org.apache.hadoop.hbase.PleaseRestartMasterException) MasterNotRunningException(org.apache.hadoop.hbase.MasterNotRunningException)

Example 7 with ServerConnector

use of org.apache.hbase.thirdparty.org.eclipse.jetty.server.ServerConnector in project hbase by apache.

the class HttpServer method getConnectorAddress.

/**
 * Get the address that corresponds to a particular connector.
 *
 * @return the corresponding address for the connector, or null if there's no
 *         such connector or the connector is not bounded.
 */
public InetSocketAddress getConnectorAddress(int index) {
    Preconditions.checkArgument(index >= 0);
    if (index > webServer.getConnectors().length) {
        return null;
    }
    ServerConnector c = (ServerConnector) webServer.getConnectors()[index];
    if (c.getLocalPort() == -1 || c.getLocalPort() == -2) {
        // -2 if it has been closed
        return null;
    }
    return new InetSocketAddress(c.getHost(), c.getLocalPort());
}
Also used : ServerConnector(org.apache.hbase.thirdparty.org.eclipse.jetty.server.ServerConnector) InetSocketAddress(java.net.InetSocketAddress)

Example 8 with ServerConnector

use of org.apache.hbase.thirdparty.org.eclipse.jetty.server.ServerConnector in project hbase by apache.

the class HttpServer method openListeners.

/**
 * Open the main listener for the server
 * @throws Exception if the listener cannot be opened or the appropriate port is already in use
 */
void openListeners() throws Exception {
    for (ListenerInfo li : listeners) {
        ServerConnector listener = li.listener;
        if (!li.isManaged || (li.listener.getLocalPort() != -1 && li.listener.getLocalPort() != -2)) {
            // This listener is either started externally, or has not been opened, or has been closed
            continue;
        }
        int port = listener.getPort();
        while (true) {
            // failed to open w/o issuing a close first, even if the port is changed
            try {
                listener.close();
                listener.open();
                LOG.info("Jetty bound to port " + listener.getLocalPort());
                break;
            } catch (IOException ex) {
                if (!(ex instanceof BindException) && !(ex.getCause() instanceof BindException)) {
                    throw ex;
                }
                if (port == 0 || !findPort) {
                    BindException be = new BindException("Port in use: " + listener.getHost() + ":" + listener.getPort());
                    be.initCause(ex);
                    throw be;
                }
            }
            // try the next port number
            listener.setPort(++port);
            Thread.sleep(100);
        }
    }
}
Also used : ServerConnector(org.apache.hbase.thirdparty.org.eclipse.jetty.server.ServerConnector) BindException(java.net.BindException) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException)

Aggregations

ServerConnector (org.apache.hbase.thirdparty.org.eclipse.jetty.server.ServerConnector)8 Server (org.apache.hbase.thirdparty.org.eclipse.jetty.server.Server)4 IOException (java.io.IOException)3 InfoServer (org.apache.hadoop.hbase.http.InfoServer)3 ServletHolder (org.apache.hbase.thirdparty.org.eclipse.jetty.servlet.ServletHolder)3 InterruptedIOException (java.io.InterruptedIOException)2 HttpConfiguration (org.apache.hbase.thirdparty.org.eclipse.jetty.server.HttpConfiguration)2 HttpConnectionFactory (org.apache.hbase.thirdparty.org.eclipse.jetty.server.HttpConnectionFactory)2 SecureRequestCustomizer (org.apache.hbase.thirdparty.org.eclipse.jetty.server.SecureRequestCustomizer)2 SslConnectionFactory (org.apache.hbase.thirdparty.org.eclipse.jetty.server.SslConnectionFactory)2 ServletContextHandler (org.apache.hbase.thirdparty.org.eclipse.jetty.servlet.ServletContextHandler)2 SslContextFactory (org.apache.hbase.thirdparty.org.eclipse.jetty.util.ssl.SslContextFactory)2 QueuedThreadPool (org.apache.hbase.thirdparty.org.eclipse.jetty.util.thread.QueuedThreadPool)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 BindException (java.net.BindException)1 InetSocketAddress (java.net.InetSocketAddress)1 UnknownHostException (java.net.UnknownHostException)1 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1