org.apache.calcite.avatica.server.HttpServer Java Examples

The following examples show how to use org.apache.calcite.avatica.server.HttpServer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KarelDbMain.java    From kareldb with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
    try {
        if (args.length < 1) {
            LOG.error("Properties file is required to start");
            System.exit(1);
        }
        KarelDbConfig config = new KarelDbConfig(args[0]);
        KarelDbEngine engine = KarelDbEngine.getInstance();
        engine.configure(config);
        engine.init();
        LOG.info("Starting leader election...");
        KarelDbLeaderElector elector = new KarelDbLeaderElector(config, engine);
        elector.init();
        boolean isLeader = elector.isLeader();
        LOG.info("Leader elected, starting server...");
        HttpServer server = start(config, elector);
        LOG.info("Server started, listening for requests...");
        LOG.info("KarelDB is at your service...");
        server.join();
    } catch (Exception e) {
        LOG.error("Server died unexpectedly: ", e);
        System.exit(1);
    }
}
 
Example #2
Source File: JdbcServer.java    From Quicksql with MIT License 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    OptionsParser parser = new OptionsParser(args);
    final int port = Integer.parseInt(parser.getOptionValue(SubmitOption.PORT));
    final String[] mainArgs = new String[]{FullyRemoteJdbcMetaFactory.class.getName()};

    HttpServer server = Main.start(mainArgs, port, new HandlerFactory() {
        @Override
        public AbstractHandler createHandler(Service service) {
            return new AvaticaJsonHandler(service);
        }
    });
    InetAddress address = InetAddress.getLocalHost();
    String hostName = "localhost";
    if (address != null) {
         hostName = StringUtils.isNotBlank(address.getHostName()) ? address.getHostName() : address
            .getHostAddress();
    }
    String url = Driver.CONNECT_STRING_PREFIX + "url=http://" + hostName + ":" + server.getPort();
    System.out.println("Quicksql server started, Please connect : " + url);
    server.join();
}
 
Example #3
Source File: AlternatingRemoteMetaTest.java    From calcite-avatica with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void beforeClass() throws Exception {
  final String[] mainArgs = new String[] { FullyRemoteJdbcMetaFactory.class.getName() };

  // Bind to '0' to pluck an ephemeral port instead of expecting a certain one to be free

  StringBuilder sb = new StringBuilder();
  for (int i = 0; i < 2; i++) {
    if (sb.length() > 0) {
      sb.append(",");
    }
    HttpServer jsonServer = Main.start(mainArgs, 0, new HandlerFactory() {
      @Override public AbstractHandler createHandler(Service service) {
        return new AvaticaJsonHandler(service);
      }
    });
    ACTIVE_SERVERS.add(jsonServer);
    sb.append("http://localhost:").append(jsonServer.getPort());
  }

  url = AlternatingDriver.PREFIX + "url=" + sb.toString();
}
 
Example #4
Source File: KarelDbMain.java    From kareldb with Apache License 2.0 5 votes vote down vote up
public static HttpServer start(KarelDbConfig config, KarelDbLeaderElector elector) throws SQLException {
    Meta meta = create(config);
    Service service = new LocalService(meta);
    AvaticaHandler localHandler = new AvaticaJsonHandler(service);
    AvaticaHandler handler = new DynamicAvaticaJsonHandler(config, localHandler, elector);
    HttpServer server = new HttpServerExtension(elector.getIdentity(), handler, config);
    server.start();
    return server;
}
 
Example #5
Source File: StandaloneServer.java    From calcite-avatica with Apache License 2.0 5 votes vote down vote up
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());
  }
}
 
Example #6
Source File: AvaticaServersForTest.java    From calcite-avatica with Apache License 2.0 5 votes vote down vote up
/**
 * Starts Avatica server and cache.
 */
public void startServer(HandlerFactory factory, Service service, Serialization serialization,
                        MetricsSystemConfiguration metricsConfig,
                        AvaticaServerConfiguration serverConfig) {
  AvaticaHandler handler = factory.getHandler(service, serialization,
          metricsConfig, serverConfig);
  final HttpServer server = new HttpServer.Builder().withHandler(handler)
          .withPort(0).build();
  server.start();
  serversBySerialization.put(serialization, server);
}
 
Example #7
Source File: AvaticaServersForTest.java    From calcite-avatica with Apache License 2.0 5 votes vote down vote up
/**
 * Stops the servers currently running.
 *
 * @throws Exception If there is an error stopping a server
 */
public void stopServers() throws Exception {
  Iterator<Entry<Serialization, HttpServer>> servers =
      serversBySerialization.entrySet().iterator();
  while (servers.hasNext()) {
    try {
      servers.next().getValue().stop();
    } finally {
      // Still remove it if we failed to stop it
      servers.remove();
    }
  }
}
 
Example #8
Source File: AvaticaServersForTest.java    From calcite-avatica with Apache License 2.0 5 votes vote down vote up
/**
 * Computes an array of parameters to support JUnit's parameterized tests. The Object array
 * actually contains a {@link Serialization} and the {@link HttpServer} instance in that order.
 *
 * @return A list of arrays of Serialization and HttpServer pairs.
 */
public List<Object[]> getJUnitParameters() {
  List<Object[]> params = new ArrayList<>(serversBySerialization.size());

  for (Entry<Serialization, HttpServer> servers : serversBySerialization.entrySet()) {
    params.add(new Object[]{ servers.getKey(), servers.getValue() });
  }

  return params;
}
 
Example #9
Source File: ConnectionPropertiesTest.java    From calcite-avatica with Apache License 2.0 5 votes vote down vote up
public ConnectionPropertiesTest(Driver.Serialization serialization,
                                  HttpServer server) {
  this.server = server;
  this.port = this.server.getPort();
  this.serialization = serialization;
  this.url = SERVERS.getJdbcUrl(port, serialization);
}
 
Example #10
Source File: AlternatingRemoteMetaTest.java    From calcite-avatica with Apache License 2.0 5 votes vote down vote up
@AfterClass public static void afterClass() throws Exception {
  for (HttpServer server : ACTIVE_SERVERS) {
    if (server != null) {
      server.stop();
    }
  }
}
 
Example #11
Source File: Main.java    From quark with Apache License 2.0 5 votes vote down vote up
public void run(String[] args) throws Exception {
  logJVMInfo();
  try {

    Class<? extends Meta.Factory> factoryClass = QuarkMetaFactoryImpl.class;

    Meta.Factory factory =
        factoryClass.getDeclaredConstructor().newInstance();
    Meta meta = factory.create(Arrays.asList(args));

    int port = 8765;
    if (QuarkMetaFactoryImpl.serverConfig.port != 0) {
      port = QuarkMetaFactoryImpl.serverConfig.port;
    }
    LOG.debug("Listening on port " + port);

    final HandlerFactory handlerFactory = new HandlerFactory();
    Service service = new LocalService(meta);
    server = new HttpServer(port, getHandler(service, handlerFactory));
    Class.forName("com.qubole.quark.fatjdbc.QuarkDriver");
    server.start();
    runningLatch.countDown();
    server.join();
  } catch (Throwable t) {
    LOG.fatal("Unrecoverable service error. Shutting down.", t);
    this.t = t;
  }
}
 
Example #12
Source File: RemoteMetaTest.java    From calcite-avatica with Apache License 2.0 4 votes vote down vote up
public RemoteMetaTest(Driver.Serialization serialization, HttpServer server) {
  this.server = server;
  this.port = this.server.getPort();
  this.serialization = serialization;
  this.url = SERVERS.getJdbcUrl(port, serialization);
}
 
Example #13
Source File: RemoteHttpClientTest.java    From calcite-avatica with Apache License 2.0 4 votes vote down vote up
public RemoteHttpClientTest(Driver.Serialization serialization, HttpServer server) {
  this.server = server;
  this.port = this.server.getPort();
  this.serialization = serialization;
  this.url = SERVERS.getJdbcUrl(port, serialization);
}
 
Example #14
Source File: ArrayTypeTest.java    From calcite-avatica with Apache License 2.0 4 votes vote down vote up
public ArrayTypeTest(Serialization serialization, HttpServer server) {
  this.server = server;
  this.port = this.server.getPort();
  this.serialization = serialization;
  this.url = SERVERS.getJdbcUrl(port, serialization);
}
 
Example #15
Source File: HttpBaseTest.java    From calcite-avatica with Apache License 2.0 4 votes vote down vote up
@AfterClass public static void stopServers() throws KrbException {
  for (HttpServer server : SERVERS_TO_STOP) {
    server.stop();
  }
  SERVERS_TO_STOP.clear();
}
 
Example #16
Source File: Main.java    From quark with Apache License 2.0 4 votes vote down vote up
/**
 * @return the port number this instance is bound to, or {@code -1} if the server is not running.
 */
@VisibleForTesting
public HttpServer getServer() {
  return server;
}