Search in sources :

Example 1 with ServiceAnnouncement

use of com.facebook.airlift.discovery.client.ServiceAnnouncement in project presto by prestodb.

the class TestingPrestoServer method updateConnectorIdAnnouncement.

private static void updateConnectorIdAnnouncement(Announcer announcer, ConnectorId connectorId, InternalNodeManager nodeManager) {
    // 
    // This code was copied from PrestoServer, and is a hack that should be removed when the connectorId property is removed
    // 
    // get existing announcement
    ServiceAnnouncement announcement = getPrestoAnnouncement(announcer.getServiceAnnouncements());
    // update connectorIds property
    Map<String, String> properties = new LinkedHashMap<>(announcement.getProperties());
    String property = nullToEmpty(properties.get("connectorIds"));
    Set<String> connectorIds = new LinkedHashSet<>(Splitter.on(',').trimResults().omitEmptyStrings().splitToList(property));
    connectorIds.add(connectorId.toString());
    properties.put("connectorIds", Joiner.on(',').join(connectorIds));
    // update announcement
    announcer.removeServiceAnnouncement(announcement.getId());
    announcer.addServiceAnnouncement(serviceAnnouncement(announcement.getType()).addProperties(properties).build());
    announcer.forceAnnounce();
    nodeManager.refreshNodes();
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ServiceAnnouncement(com.facebook.airlift.discovery.client.ServiceAnnouncement) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with ServiceAnnouncement

use of com.facebook.airlift.discovery.client.ServiceAnnouncement in project presto by prestodb.

the class TestingPrestoServer method updateThriftServerAddressAnnouncement.

// TODO: announcement does not work for coordinator
private static void updateThriftServerAddressAnnouncement(Announcer announcer, int thriftPort, InternalNodeManager nodeManager) {
    // get existing announcement
    ServiceAnnouncement announcement = getPrestoAnnouncement(announcer.getServiceAnnouncements());
    // update announcement and thrift port property
    Map<String, String> properties = new LinkedHashMap<>(announcement.getProperties());
    properties.put("thriftServerPort", String.valueOf(thriftPort));
    announcer.removeServiceAnnouncement(announcement.getId());
    announcer.addServiceAnnouncement(serviceAnnouncement(announcement.getType()).addProperties(properties).build());
    announcer.forceAnnounce();
    nodeManager.refreshNodes();
}
Also used : ServiceAnnouncement(com.facebook.airlift.discovery.client.ServiceAnnouncement) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with ServiceAnnouncement

use of com.facebook.airlift.discovery.client.ServiceAnnouncement in project presto by prestodb.

the class PrestoServer method updateThriftServerPort.

private static void updateThriftServerPort(Announcer announcer, DriftServer driftServer) {
    // get existing announcement
    ServiceAnnouncement announcement = getPrestoAnnouncement(announcer.getServiceAnnouncements());
    // drift server::start can be called multiple times
    driftServer.start();
    // update announcement and thrift port property
    int thriftPort = ((DriftNettyServerTransport) driftServer.getServerTransport()).getPort();
    Map<String, String> properties = new LinkedHashMap<>(announcement.getProperties());
    properties.put("thriftServerPort", String.valueOf(thriftPort));
    announcer.removeServiceAnnouncement(announcement.getId());
    announcer.addServiceAnnouncement(serviceAnnouncement(announcement.getType()).addProperties(properties).build());
    announcer.forceAnnounce();
}
Also used : DriftNettyServerTransport(com.facebook.drift.transport.netty.server.DriftNettyServerTransport) ServiceAnnouncement(com.facebook.airlift.discovery.client.ServiceAnnouncement) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with ServiceAnnouncement

use of com.facebook.airlift.discovery.client.ServiceAnnouncement in project presto by prestodb.

the class PrestoServer method updateConnectorIds.

private static void updateConnectorIds(Announcer announcer, CatalogManager metadata, ServerConfig serverConfig, NodeSchedulerConfig schedulerConfig) {
    // get existing announcement
    ServiceAnnouncement announcement = getPrestoAnnouncement(announcer.getServiceAnnouncements());
    // get existing connectorIds
    String property = nullToEmpty(announcement.getProperties().get("connectorIds"));
    List<String> values = Splitter.on(',').trimResults().omitEmptyStrings().splitToList(property);
    Set<String> connectorIds = new LinkedHashSet<>(values);
    // automatically build connectorIds if not configured
    if (connectorIds.isEmpty()) {
        List<Catalog> catalogs = metadata.getCatalogs();
        // if this is a dedicated coordinator, only add jmx
        if (serverConfig.isCoordinator() && !schedulerConfig.isIncludeCoordinator()) {
            catalogs.stream().map(Catalog::getConnectorId).filter(connectorId -> connectorId.getCatalogName().equals("jmx")).map(Object::toString).forEach(connectorIds::add);
        } else {
            catalogs.stream().map(Catalog::getConnectorId).map(Object::toString).forEach(connectorIds::add);
        }
    }
    // build announcement with updated sources
    ServiceAnnouncementBuilder builder = serviceAnnouncement(announcement.getType());
    for (Map.Entry<String, String> entry : announcement.getProperties().entrySet()) {
        if (!entry.getKey().equals("connectorIds")) {
            builder.addProperty(entry.getKey(), entry.getValue());
        }
    }
    builder.addProperty("connectorIds", Joiner.on(',').join(connectorIds));
    // update announcement
    announcer.removeServiceAnnouncement(announcement.getId());
    announcer.addServiceAnnouncement(builder.build());
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ServiceAnnouncementBuilder(com.facebook.airlift.discovery.client.ServiceAnnouncement.ServiceAnnouncementBuilder) ServiceAnnouncement(com.facebook.airlift.discovery.client.ServiceAnnouncement) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) Catalog(com.facebook.presto.metadata.Catalog)

Aggregations

ServiceAnnouncement (com.facebook.airlift.discovery.client.ServiceAnnouncement)4 LinkedHashMap (java.util.LinkedHashMap)4 LinkedHashSet (java.util.LinkedHashSet)2 ServiceAnnouncementBuilder (com.facebook.airlift.discovery.client.ServiceAnnouncement.ServiceAnnouncementBuilder)1 DriftNettyServerTransport (com.facebook.drift.transport.netty.server.DriftNettyServerTransport)1 Catalog (com.facebook.presto.metadata.Catalog)1 Map (java.util.Map)1