Ejemplo n.º 1
0
  private static void updateDatasourcesAnnouncement(Announcer announcer, String connectorId) {
    //
    // This code was copied from PrestoServer, and is a hack that should be removed when the data
    // source property is removed
    //

    // get existing announcement
    ServiceAnnouncement announcement = getPrestoAnnouncement(announcer.getServiceAnnouncements());

    // update datasources property
    Map<String, String> properties = new LinkedHashMap<>(announcement.getProperties());
    String property = nullToEmpty(properties.get("datasources"));
    Set<String> datasources =
        new LinkedHashSet<>(
            Splitter.on(',').trimResults().omitEmptyStrings().splitToList(property));
    datasources.add(connectorId);
    properties.put("datasources", Joiner.on(',').join(datasources));

    // update announcement
    announcer.removeServiceAnnouncement(announcement.getId());
    announcer.addServiceAnnouncement(
        serviceAnnouncement(announcement.getType()).addProperties(properties).build());
    announcer.forceAnnounce();
  }
Ejemplo n.º 2
0
  public TestingPrestoServer(
      boolean coordinator,
      Map<String, String> properties,
      String environment,
      URI discoveryUri,
      List<Module> additionalModules)
      throws Exception {
    this.coordinator = coordinator;
    baseDataDir = Files.createTempDirectory("PrestoTest");

    properties = new HashMap<>(properties);
    String coordinatorPort = properties.remove("http-server.http.port");
    if (coordinatorPort == null) {
      coordinatorPort = "0";
    }

    ImmutableMap.Builder<String, String> serverProperties =
        ImmutableMap.<String, String>builder()
            .putAll(properties)
            .put("coordinator", String.valueOf(coordinator))
            .put("presto.version", "testversion")
            .put("http-client.max-threads", "16")
            .put("task.default-concurrency", "4")
            .put("task.max-worker-threads", "4")
            .put("analyzer.experimental-syntax-enabled", "true");

    if (!properties.containsKey("query.max-memory-per-node")) {
      serverProperties.put("query.max-memory-per-node", "512MB");
    }

    if (coordinator) {
      // TODO: enable failure detector
      serverProperties.put("failure-detector.enabled", "false");
    }

    ImmutableList.Builder<Module> modules =
        ImmutableList.<Module>builder()
            .add(new TestingNodeModule(Optional.ofNullable(environment)))
            .add(new TestingHttpServerModule(parseInt(coordinator ? coordinatorPort : "0")))
            .add(new JsonModule())
            .add(new JaxrsModule(true))
            .add(new MBeanModule())
            .add(new TestingJmxModule())
            .add(new EventModule())
            .add(new TraceTokenModule())
            .add(new ServerMainModule(new SqlParserOptions()))
            .add(
                installModuleIf(
                    NodeSchedulerConfig.class,
                    config -> LEGACY_NETWORK_TOPOLOGY.equalsIgnoreCase(config.getNetworkTopology()),
                    binder ->
                        binder
                            .bind(NetworkTopology.class)
                            .to(LegacyNetworkTopology.class)
                            .in(Scopes.SINGLETON)))
            .add(
                installModuleIf(
                    NodeSchedulerConfig.class,
                    config -> "flat".equalsIgnoreCase(config.getNetworkTopology()),
                    binder ->
                        binder
                            .bind(NetworkTopology.class)
                            .to(FlatNetworkTopology.class)
                            .in(Scopes.SINGLETON)))
            .add(
                binder -> {
                  binder.bind(TestingAccessControlManager.class).in(Scopes.SINGLETON);
                  binder
                      .bind(AccessControlManager.class)
                      .to(TestingAccessControlManager.class)
                      .in(Scopes.SINGLETON);
                  binder
                      .bind(AccessControl.class)
                      .to(AccessControlManager.class)
                      .in(Scopes.SINGLETON);
                  binder
                      .bind(ShutdownAction.class)
                      .to(TestShutdownAction.class)
                      .in(Scopes.SINGLETON);
                  binder.bind(GracefulShutdownHandler.class).in(Scopes.SINGLETON);
                });

    if (discoveryUri != null) {
      requireNonNull(environment, "environment required when discoveryUri is present");
      serverProperties.put("discovery.uri", discoveryUri.toString());
      modules.add(new DiscoveryModule());
    } else {
      modules.add(new TestingDiscoveryModule());
    }

    modules.addAll(additionalModules);

    Bootstrap app = new Bootstrap(modules.build());

    Map<String, String> optionalProperties = new HashMap<>();
    if (environment != null) {
      optionalProperties.put("node.environment", environment);
    }

    Injector injector =
        app.strictConfig()
            .doNotInitializeLogging()
            .setRequiredConfigurationProperties(serverProperties.build())
            .setOptionalConfigurationProperties(optionalProperties)
            .initialize();

    injector.getInstance(Announcer.class).start();

    lifeCycleManager = injector.getInstance(LifeCycleManager.class);

    queryManager = injector.getInstance(QueryManager.class);

    pluginManager = injector.getInstance(PluginManager.class);

    connectorManager = injector.getInstance(ConnectorManager.class);

    server = injector.getInstance(TestingHttpServer.class);
    transactionManager = injector.getInstance(TransactionManager.class);
    metadata = injector.getInstance(Metadata.class);
    accessControl = injector.getInstance(TestingAccessControlManager.class);
    splitManager = injector.getInstance(SplitManager.class);
    clusterMemoryManager = injector.getInstance(ClusterMemoryManager.class);
    localMemoryManager = injector.getInstance(LocalMemoryManager.class);
    nodeManager = injector.getInstance(InternalNodeManager.class);
    serviceSelectorManager = injector.getInstance(ServiceSelectorManager.class);
    gracefulShutdownHandler = injector.getInstance(GracefulShutdownHandler.class);
    taskManager = injector.getInstance(TaskManager.class);
    shutdownAction = injector.getInstance(ShutdownAction.class);
    announcer = injector.getInstance(Announcer.class);

    announcer.forceAnnounce();

    refreshNodes();
  }