Search in sources :

Example 11 with Service

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

the class HttpServerBuilderTest method nullExtraRolesWithExplitRealm.

@Test
public void nullExtraRolesWithExplitRealm() {
    final String[] extraRoles = null;
    final Service mockService = Mockito.mock(Service.class);
    HttpServer server = new HttpServer.Builder().withSpnego("HTTP/localhost.localdomain@EXAMPLE.COM", "EXAMPLE.COM", extraRoles).withHandler(mockService, Serialization.JSON).build();
    assertNull(server.getConfig().getAllowedRoles());
    assertArrayEquals(new String[] { "EXAMPLE.COM" }, server.getAllowedRealms("EXAMPLE.COM", server.getConfig()));
}
Also used : Service(org.apache.calcite.avatica.remote.Service) Test(org.junit.Test)

Example 12 with Service

use of org.apache.calcite.avatica.remote.Service 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)

Example 13 with Service

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

the class JsonHandlerTest method testExecuteRequestWithNumberParameter.

@Test
public void testExecuteRequestWithNumberParameter() {
    final List<TypedValue> expectedParameterValues = new ArrayList<>();
    final Service service = new ParameterValuesCheckingService(expectedParameterValues);
    final JsonService jsonService = new LocalJsonService(service);
    final JsonHandler jsonHandler = new JsonHandler(jsonService, NoopMetricsSystem.getInstance());
    final List<TypedValue> parameterValues = Arrays.asList(TypedValue.create("NUMBER", new BigDecimal("123")), TypedValue.create("STRING", "calcite"));
    jsonHandler.apply("{'request':'execute'," + "'parameterValues':[{'type':'NUMBER','value':123}," + "{'type':'STRING','value':'calcite'}]}");
    assertThat(expectedParameterValues.size(), is(2));
    assertThat(expectedParameterValues.get(0), is(parameterValues.get(0)));
    assertThat(expectedParameterValues.get(1), is(parameterValues.get(1)));
}
Also used : LocalJsonService(org.apache.calcite.avatica.remote.LocalJsonService) ArrayList(java.util.ArrayList) JsonHandler(org.apache.calcite.avatica.remote.JsonHandler) JsonService(org.apache.calcite.avatica.remote.JsonService) Service(org.apache.calcite.avatica.remote.Service) LocalJsonService(org.apache.calcite.avatica.remote.LocalJsonService) JsonService(org.apache.calcite.avatica.remote.JsonService) LocalJsonService(org.apache.calcite.avatica.remote.LocalJsonService) BigDecimal(java.math.BigDecimal) TypedValue(org.apache.calcite.avatica.remote.TypedValue) Test(org.junit.Test)

Example 14 with Service

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

the class HttpServerCustomizerTest method onlyJettyCustomizersAllowed.

@Test
public void onlyJettyCustomizersAllowed() {
    Service service = new LocalService(mockMeta);
    List<ServerCustomizer<UnsupportedServer>> unsupportedCustomizers = new ArrayList<>();
    unsupportedCustomizers.add(new ServerCustomizer<UnsupportedServer>() {

        @Override
        public void customize(UnsupportedServer server) {
        }
    });
    thrown.expect(IllegalArgumentException.class);
    thrown.expectMessage("Only Jetty Server customizers are supported");
    HttpServer.Builder.<UnsupportedServer>newBuilder().withHandler(service, Driver.Serialization.PROTOBUF).withServerCustomizers(unsupportedCustomizers, UnsupportedServer.class).withPort(0).build();
}
Also used : ArrayList(java.util.ArrayList) Service(org.apache.calcite.avatica.remote.Service) LocalService(org.apache.calcite.avatica.remote.LocalService) LocalService(org.apache.calcite.avatica.remote.LocalService) Test(org.junit.Test)

Aggregations

Service (org.apache.calcite.avatica.remote.Service)14 Test (org.junit.Test)11 LocalService (org.apache.calcite.avatica.remote.LocalService)4 ArrayList (java.util.ArrayList)2 Meta (org.apache.calcite.avatica.Meta)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 CacheBuilder (com.google.common.cache.CacheBuilder)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 File (java.io.File)1 IOException (java.io.IOException)1 BigDecimal (java.math.BigDecimal)1 Map (java.util.Map)1 ServletException (javax.servlet.ServletException)1 JsonHandler (org.apache.calcite.avatica.remote.JsonHandler)1 JsonService (org.apache.calcite.avatica.remote.JsonService)1 LocalJsonService (org.apache.calcite.avatica.remote.LocalJsonService)1 TypedValue (org.apache.calcite.avatica.remote.TypedValue)1 HttpServer (org.apache.calcite.avatica.server.HttpServer)1 Server (org.apache.druid.client.selector.Server)1