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