Search in sources :

Example 1 with HttpServer

use of org.apache.calcite.avatica.server.HttpServer in project calcite-avatica by apache.

the class AvaticaSpnegoTest method parameters.

@Parameters
public static List<Object[]> parameters() throws Exception {
    final ArrayList<Object[]> parameters = new ArrayList<>();
    setupClass();
    // Start the KDC
    setupKdc();
    for (boolean tls : new Boolean[] { false, true }) {
        for (Driver.Serialization serialization : new Driver.Serialization[] { Driver.Serialization.JSON, Driver.Serialization.PROTOBUF }) {
            if (tls && System.getProperty("java.vendor").contains("IBM")) {
                // Skip TLS testing on IBM Java due the combination of:
                // - Jetty 9.4.12+ ignores SSL_* ciphers due to security - eclipse/jetty.project#2807
                // - IBM uses SSL_* cipher names for ALL ciphers not following RFC cipher names
                // See eclipse/jetty.project#2807 for details
                LOG.info("Skipping HTTPS test on IBM Java");
                parameters.add(new Object[] { null });
                continue;
            }
            // Build and start the server
            HttpServer.Builder httpServerBuilder = new HttpServer.Builder();
            if (tls) {
                httpServerBuilder = httpServerBuilder.withTLS(KEYSTORE, KEYSTORE_PASSWORD, KEYSTORE, KEYSTORE_PASSWORD);
            }
            HttpServer httpServer = httpServerBuilder.withPort(0).withAutomaticLogin(serverKeytab).withSpnego(SpnegoTestUtil.SERVER_PRINCIPAL, SpnegoTestUtil.REALM).withHandler(localService, serialization).build();
            httpServer.start();
            SERVERS_TO_STOP.add(httpServer);
            String url = "jdbc:avatica:remote:url=" + (tls ? "https://" : "http://") + SpnegoTestUtil.KDC_HOST + ":" + httpServer.getPort() + ";authentication=SPNEGO;serialization=" + serialization;
            if (tls) {
                url += ";truststore=" + KEYSTORE.getAbsolutePath() + ";truststore_password=" + KEYSTORE_PASSWORD;
            }
            LOG.info("JDBC URL {}", url);
            parameters.add(new Object[] { url });
        }
    }
    return parameters;
}
Also used : ArrayList(java.util.ArrayList) HttpServer(org.apache.calcite.avatica.server.HttpServer) Driver(org.apache.calcite.avatica.remote.Driver) Parameters(org.junit.runners.Parameterized.Parameters)

Example 2 with HttpServer

use of org.apache.calcite.avatica.server.HttpServer in project calcite-avatica by apache.

the class AvaticaServersForTest method startServers.

/**
 * Starts an Avatica server for each serialization type.
 */
public void startServers() throws Exception {
    // Bind to '0' to pluck an ephemeral port instead of expecting a certain one to be free
    final HttpServer jsonServer = Main.start(SERVER_ARGS, 0, new Main.HandlerFactory() {

        @Override
        public AvaticaJsonHandler createHandler(Service service) {
            return new AvaticaJsonHandler(service);
        }
    });
    serversBySerialization.put(Serialization.JSON, jsonServer);
    final HttpServer protobufServer = Main.start(SERVER_ARGS, 0, new Main.HandlerFactory() {

        @Override
        public AvaticaProtobufHandler createHandler(Service service) {
            return new AvaticaProtobufHandler(service);
        }
    });
    serversBySerialization.put(Serialization.PROTOBUF, protobufServer);
}
Also used : AvaticaProtobufHandler(org.apache.calcite.avatica.server.AvaticaProtobufHandler) AvaticaJsonHandler(org.apache.calcite.avatica.server.AvaticaJsonHandler) HttpServer(org.apache.calcite.avatica.server.HttpServer) Main(org.apache.calcite.avatica.server.Main)

Example 3 with HttpServer

use of org.apache.calcite.avatica.server.HttpServer in project calcite-avatica by apache.

the class AvaticaServersForTest method startServer.

/**
 * Starts Avatica server and cache.
 */
public void startServer(HandlerFactory factory, Service service, Serialization serialization, MetricsSystemConfiguration metricsConfig, AvaticaServerConfiguration serverConfig) {
    AvaticaHandler handler = factory.getHandler(service, serialization, metricsConfig, serverConfig);
    final HttpServer server = new HttpServer.Builder().withHandler(handler).withPort(0).build();
    server.start();
    serversBySerialization.put(serialization, server);
}
Also used : HttpServer(org.apache.calcite.avatica.server.HttpServer) AvaticaHandler(org.apache.calcite.avatica.server.AvaticaHandler)

Example 4 with HttpServer

use of org.apache.calcite.avatica.server.HttpServer in project calcite-avatica by apache.

the class AvaticaSpnegoTest method stopKdc.

@AfterClass
public static void stopKdc() throws Exception {
    for (HttpServer server : SERVERS_TO_STOP) {
        server.stop();
    }
    if (isKdcStarted) {
        LOG.info("Stopping KDC on {}", kdcPort);
        kdc.stop();
    }
}
Also used : HttpServer(org.apache.calcite.avatica.server.HttpServer) AfterClass(org.junit.AfterClass)

Example 5 with HttpServer

use of org.apache.calcite.avatica.server.HttpServer in project phoenix by apache.

the class QueryServer method run.

@Override
public int run(String[] args) throws Exception {
    logProcessInfo(getConf());
    final boolean loadBalancerEnabled = getConf().getBoolean(QueryServices.PHOENIX_QUERY_SERVER_LOADBALANCER_ENABLED, QueryServicesOptions.DEFAULT_PHOENIX_QUERY_SERVER_LOADBALANCER_ENABLED);
    try {
        final boolean isKerberos = "kerberos".equalsIgnoreCase(getConf().get(QueryServices.QUERY_SERVER_HBASE_SECURITY_CONF_ATTRIB));
        final boolean disableSpnego = getConf().getBoolean(QueryServices.QUERY_SERVER_SPNEGO_AUTH_DISABLED_ATTRIB, QueryServicesOptions.DEFAULT_QUERY_SERVER_SPNEGO_AUTH_DISABLED);
        String hostname;
        final boolean disableLogin = getConf().getBoolean(QueryServices.QUERY_SERVER_DISABLE_KERBEROS_LOGIN, QueryServicesOptions.DEFAULT_QUERY_SERVER_DISABLE_KERBEROS_LOGIN);
        // handle secure cluster credentials
        if (isKerberos && !disableSpnego && !disableLogin) {
            hostname = Strings.domainNamePointerToHostName(DNS.getDefaultHost(getConf().get(QueryServices.QUERY_SERVER_DNS_INTERFACE_ATTRIB, "default"), getConf().get(QueryServices.QUERY_SERVER_DNS_NAMESERVER_ATTRIB, "default")));
            if (LOG.isDebugEnabled()) {
                LOG.debug("Login to " + hostname + " using " + getConf().get(QueryServices.QUERY_SERVER_KEYTAB_FILENAME_ATTRIB) + " and principal " + getConf().get(QueryServices.QUERY_SERVER_KERBEROS_PRINCIPAL_ATTRIB) + ".");
            }
            SecurityUtil.login(getConf(), QueryServices.QUERY_SERVER_KEYTAB_FILENAME_ATTRIB, QueryServices.QUERY_SERVER_KERBEROS_PRINCIPAL_ATTRIB, hostname);
            LOG.info("Login successful.");
        } else {
            hostname = InetAddress.getLocalHost().getHostName();
            LOG.info(" Kerberos is off and hostname is : " + hostname);
        }
        Class<? extends PhoenixMetaFactory> factoryClass = getConf().getClass(QueryServices.QUERY_SERVER_META_FACTORY_ATTRIB, PhoenixMetaFactoryImpl.class, PhoenixMetaFactory.class);
        int port = getConf().getInt(QueryServices.QUERY_SERVER_HTTP_PORT_ATTRIB, QueryServicesOptions.DEFAULT_QUERY_SERVER_HTTP_PORT);
        LOG.debug("Listening on port " + port);
        PhoenixMetaFactory factory = factoryClass.getDeclaredConstructor(Configuration.class).newInstance(getConf());
        Meta meta = factory.create(Arrays.asList(args));
        Service service = new LocalService(meta);
        // Start building the Avatica HttpServer
        final HttpServer.Builder builder = new HttpServer.Builder().withPort(port).withHandler(service, getSerialization(getConf()));
        // Enable SPNEGO and Impersonation when using Kerberos
        if (isKerberos) {
            UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
            LOG.debug("Current user is " + ugi);
            if (!ugi.hasKerberosCredentials()) {
                ugi = UserGroupInformation.getLoginUser();
                LOG.debug("Current user does not have Kerberos credentials, using instead " + ugi);
            }
            // Make sure the proxyuser configuration is up to date
            ProxyUsers.refreshSuperUserGroupsConfiguration(getConf());
            String keytabPath = getConf().get(QueryServices.QUERY_SERVER_KEYTAB_FILENAME_ATTRIB);
            File keytab = new File(keytabPath);
            String httpKeytabPath = getConf().get(QueryServices.QUERY_SERVER_HTTP_KEYTAB_FILENAME_ATTRIB, null);
            String httpPrincipal = getConf().get(QueryServices.QUERY_SERVER_KERBEROS_HTTP_PRINCIPAL_ATTRIB, null);
            File httpKeytab = null;
            if (null != httpKeytabPath)
                httpKeytab = new File(httpKeytabPath);
            String realmsString = getConf().get(QueryServices.QUERY_SERVER_KERBEROS_ALLOWED_REALMS, null);
            String[] additionalAllowedRealms = null;
            if (null != realmsString) {
                additionalAllowedRealms = StringUtils.split(realmsString, ',');
            }
            // Enable SPNEGO and impersonation (through standard Hadoop configuration means)
            if ((null != httpKeytabPath) && (null != httpPrincipal))
                builder.withSpnego(httpPrincipal, additionalAllowedRealms).withAutomaticLogin(httpKeytab).withImpersonation(new PhoenixDoAsCallback(ugi, getConf()));
            else
                builder.withSpnego(ugi.getUserName(), additionalAllowedRealms).withAutomaticLogin(keytab).withImpersonation(new PhoenixDoAsCallback(ugi, getConf()));
        }
        setRemoteUserExtractorIfNecessary(builder, getConf());
        // Build and start the HttpServer
        server = builder.build();
        server.start();
        if (loadBalancerEnabled) {
            registerToServiceProvider(hostname);
        }
        runningLatch.countDown();
        server.join();
        return 0;
    } catch (Throwable t) {
        LOG.fatal("Unrecoverable service error. Shutting down.", t);
        this.t = t;
        return -1;
    } finally {
        if (loadBalancerEnabled) {
            unRegister();
        }
    }
}
Also used : Meta(org.apache.calcite.avatica.Meta) Configuration(org.apache.hadoop.conf.Configuration) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) CacheBuilder(com.google.common.cache.CacheBuilder) Service(org.apache.calcite.avatica.remote.Service) LocalService(org.apache.calcite.avatica.remote.LocalService) HttpServer(org.apache.calcite.avatica.server.HttpServer) LocalService(org.apache.calcite.avatica.remote.LocalService) File(java.io.File) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Aggregations

HttpServer (org.apache.calcite.avatica.server.HttpServer)7 File (java.io.File)2 ArrayList (java.util.ArrayList)2 Driver (org.apache.calcite.avatica.remote.Driver)2 AvaticaJsonHandler (org.apache.calcite.avatica.server.AvaticaJsonHandler)2 Parameters (org.junit.runners.Parameterized.Parameters)2 CacheBuilder (com.google.common.cache.CacheBuilder)1 Meta (org.apache.calcite.avatica.Meta)1 LocalService (org.apache.calcite.avatica.remote.LocalService)1 Service (org.apache.calcite.avatica.remote.Service)1 AvaticaHandler (org.apache.calcite.avatica.server.AvaticaHandler)1 AvaticaProtobufHandler (org.apache.calcite.avatica.server.AvaticaProtobufHandler)1 Main (org.apache.calcite.avatica.server.Main)1 HandlerFactory (org.apache.calcite.avatica.server.Main.HandlerFactory)1 Configuration (org.apache.hadoop.conf.Configuration)1 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)1 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)1 AbstractHandler (org.eclipse.jetty.server.handler.AbstractHandler)1 AfterClass (org.junit.AfterClass)1 BeforeClass (org.junit.BeforeClass)1