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()));
}
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();
}
}
}
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)));
}
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();
}
Aggregations