Search in sources :

Example 6 with LocalService

use of org.apache.calcite.avatica.remote.LocalService in project calcite-avatica by apache.

the class StandaloneServer method start.

public void start() {
    if (null != server) {
        LOG.error("The server was already started");
        Unsafe.systemExit(ExitCodes.ALREADY_STARTED.ordinal());
        return;
    }
    try {
        JdbcMeta meta = new JdbcMeta(url);
        LocalService service = new LocalService(meta);
        // Construct the server
        this.server = new HttpServer.Builder().withHandler(service, serialization).withPort(port).build();
        // Then start it
        server.start();
        LOG.info("Started Avatica server on port {} with serialization {}", server.getPort(), serialization);
    } catch (Exception e) {
        LOG.error("Failed to start Avatica server", e);
        Unsafe.systemExit(ExitCodes.START_FAILED.ordinal());
    }
}
Also used : JdbcMeta(org.apache.calcite.avatica.jdbc.JdbcMeta) LocalService(org.apache.calcite.avatica.remote.LocalService)

Example 7 with LocalService

use of org.apache.calcite.avatica.remote.LocalService in project phoenix by apache.

the class QueryServer method run.

@Override
public int run(String[] args) throws Exception {
    logProcessInfo(getConf());
    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);
        // handle secure cluster credentials
        if (isKerberos && !disableSpnego) {
            String 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.");
        }
        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.getLoginUser();
            // 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 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)
            builder.withSpnego(ugi.getUserName(), additionalAllowedRealms).withAutomaticLogin(keytab).withImpersonation(new PhoenixDoAsCallback(ugi, getConf()));
        }
        // Build and start the HttpServer
        server = builder.build();
        server.start();
        runningLatch.countDown();
        server.join();
        return 0;
    } catch (Throwable t) {
        LOG.fatal("Unrecoverable service error. Shutting down.", t);
        this.t = t;
        return -1;
    }
}
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

LocalService (org.apache.calcite.avatica.remote.LocalService)7 JdbcMeta (org.apache.calcite.avatica.jdbc.JdbcMeta)5 HttpServer (org.apache.calcite.avatica.server.HttpServer)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 Meta (org.apache.calcite.avatica.Meta)2 Driver (org.apache.calcite.avatica.remote.Driver)2 Service (org.apache.calcite.avatica.remote.Service)2 StringContains.containsString (org.hamcrest.core.StringContains.containsString)2 BeforeClass (org.junit.BeforeClass)2 Parameters (org.junit.runners.Parameterized.Parameters)2 CacheBuilder (com.google.common.cache.CacheBuilder)1 Configuration (org.apache.hadoop.conf.Configuration)1 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)1 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)1 JcaX509v3CertificateBuilder (org.bouncycastle.cert.jcajce.JcaX509v3CertificateBuilder)1 JcaContentSignerBuilder (org.bouncycastle.operator.jcajce.JcaContentSignerBuilder)1