Search in sources :

Example 1 with LocalService

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

the class HttpBaseTest method setupClass.

public static void setupClass() throws SQLException {
    // Create a self-signed cert
    if (KEYSTORE.isFile()) {
        assertTrue("Failed to delete keystore: " + KEYSTORE, KEYSTORE.delete());
    }
    new CertTool().createSelfSignedCert(KEYSTORE, "avatica", KEYSTORE_PASSWORD);
    if (EMPTY_PW_KEYSTORE.isFile()) {
        assertTrue("Failed to delete keystore: " + EMPTY_PW_KEYSTORE, EMPTY_PW_KEYSTORE.delete());
    }
    new CertTool().createSelfSignedCert(EMPTY_PW_KEYSTORE, "avatica", KEYSTORE_EMPTY_PASSWORD);
    // Create a LocalService around HSQLDB
    JdbcMeta jdbcMeta;
    jdbcMeta = new JdbcMeta(CONNECTION_SPEC.url, CONNECTION_SPEC.username, CONNECTION_SPEC.password);
    localService = new LocalService(jdbcMeta);
}
Also used : JdbcMeta(org.apache.calcite.avatica.jdbc.JdbcMeta) LocalService(org.apache.calcite.avatica.remote.LocalService)

Example 2 with LocalService

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

the class Main method start.

/**
 * Creates and starts an {@link HttpServer} using the given factory to create the Handler.
 *
 * <p>Arguments are as follows:
 * <ul>
 *   <li>args[0]: the {@link org.apache.calcite.avatica.Meta.Factory} class
 *       name
 *   <li>args[1+]: arguments passed along to
 *   {@link org.apache.calcite.avatica.Meta.Factory#create(java.util.List)}
 * </ul>
 *
 * @param args Command-line arguments
 * @param port Server port to bind
 * @param handlerFactory Factory to create the handler used by the server
 */
public static HttpServer start(String[] args, int port, HandlerFactory handlerFactory) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
    String factoryClassName = args[0];
    @SuppressWarnings("unchecked") Class<Meta.Factory> factoryClass = (Class<Meta.Factory>) Class.forName(factoryClassName);
    Meta.Factory factory = factoryClass.getConstructor().newInstance();
    Meta meta = factory.create(Arrays.asList(args).subList(1, args.length));
    Service service = new LocalService(meta);
    HttpServer server = new HttpServer(port, HttpServer.wrapJettyHandler(handlerFactory.createHandler(service)));
    server.start();
    return server;
}
Also used : Meta(org.apache.calcite.avatica.Meta) LocalService(org.apache.calcite.avatica.remote.LocalService) Service(org.apache.calcite.avatica.remote.Service) LocalService(org.apache.calcite.avatica.remote.LocalService)

Example 3 with LocalService

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

the class DigestAuthHttpServerTest method startServer.

@BeforeClass
public static void startServer() throws Exception {
    final String userPropertiesFile = Sources.of(DigestAuthHttpServerTest.class.getResource("/auth-users.properties")).file().getAbsolutePath();
    assertNotNull("Could not find properties file for digest auth users", userPropertiesFile);
    // Create a LocalService around HSQLDB
    final JdbcMeta jdbcMeta = new JdbcMeta(CONNECTION_SPEC.url, CONNECTION_SPEC.username, CONNECTION_SPEC.password);
    LocalService service = new LocalService(jdbcMeta);
    server = new HttpServer.Builder().withDigestAuthentication(userPropertiesFile, new String[] { "users" }).withHandler(service, Driver.Serialization.PROTOBUF).withPort(0).build();
    server.start();
    url = "jdbc:avatica:remote:url=http://localhost:" + server.getPort() + ";authentication=DIGEST;serialization=PROTOBUF";
    // Create and grant permissions to our users
    createHsqldbUsers();
}
Also used : JdbcMeta(org.apache.calcite.avatica.jdbc.JdbcMeta) StringContains.containsString(org.hamcrest.core.StringContains.containsString) LocalService(org.apache.calcite.avatica.remote.LocalService) BeforeClass(org.junit.BeforeClass)

Example 4 with LocalService

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

the class HttpServerCustomizerTest method serverCustomizersInvoked.

// needed for the mocked customizers, not the builder
@SuppressWarnings("unchecked")
@Test
public void serverCustomizersInvoked() {
    ServerCustomizer<Server> mockCustomizer1 = (ServerCustomizer<Server>) mock(ServerCustomizer.class);
    ServerCustomizer<Server> mockCustomizer2 = (ServerCustomizer<Server>) mock(ServerCustomizer.class);
    Service service = new LocalService(mockMeta);
    HttpServer server = HttpServer.Builder.<Server>newBuilder().withHandler(service, Driver.Serialization.PROTOBUF).withServerCustomizers(Arrays.asList(mockCustomizer1, mockCustomizer2), Server.class).withPort(0).build();
    try {
        server.start();
        verify(mockCustomizer2).customize(any(Server.class));
        verify(mockCustomizer1).customize(any(Server.class));
    } finally {
        server.stop();
    }
}
Also used : Server(org.eclipse.jetty.server.Server) 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)

Example 5 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());
    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

LocalService (org.apache.calcite.avatica.remote.LocalService)9 JdbcMeta (org.apache.calcite.avatica.jdbc.JdbcMeta)5 Service (org.apache.calcite.avatica.remote.Service)4 Meta (org.apache.calcite.avatica.Meta)2 HttpServer (org.apache.calcite.avatica.server.HttpServer)2 StringContains.containsString (org.hamcrest.core.StringContains.containsString)2 BeforeClass (org.junit.BeforeClass)2 Test (org.junit.Test)2 CacheBuilder (com.google.common.cache.CacheBuilder)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Configuration (org.apache.hadoop.conf.Configuration)1 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)1 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)1 Server (org.eclipse.jetty.server.Server)1