Search in sources :

Example 1 with ServiceAnnouncementBuilder

use of io.airlift.discovery.client.ServiceAnnouncement.ServiceAnnouncementBuilder 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(io.airlift.discovery.client.ServiceAnnouncement.ServiceAnnouncementBuilder) ServiceAnnouncement(io.airlift.discovery.client.ServiceAnnouncement) Map(java.util.Map) Catalog(com.facebook.presto.metadata.Catalog)

Aggregations

Catalog (com.facebook.presto.metadata.Catalog)1 ServiceAnnouncement (io.airlift.discovery.client.ServiceAnnouncement)1 ServiceAnnouncementBuilder (io.airlift.discovery.client.ServiceAnnouncement.ServiceAnnouncementBuilder)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1