}
private static void updateDatasources(Announcer announcer, Metadata metadata, ServerConfig serverConfig, NodeSchedulerConfig schedulerConfig)
{
// get existing announcement
ServiceAnnouncement announcement = getPrestoAnnouncement(announcer.getServiceAnnouncements());
// get existing sources
String property = nullToEmpty(announcement.getProperties().get("datasources"));
List<String> values = Splitter.on(',').trimResults().omitEmptyStrings().splitToList(property);
Set<String> datasources = new LinkedHashSet<>(values);
// automatically build sources if not configured
if (datasources.isEmpty()) {
Set<String> catalogs = metadata.getCatalogNames().keySet();
// if this is a dedicated coordinator, only add jmx
if (serverConfig.isCoordinator() && !schedulerConfig.isIncludeCoordinator()) {
if (catalogs.contains("jmx")) {
datasources.add("jmx");
}
}
else {
datasources.addAll(catalogs);
}
}
// build announcement with updated sources
ServiceAnnouncementBuilder builder = serviceAnnouncement(announcement.getType());
for (Map.Entry<String, String> entry : announcement.getProperties().entrySet()) {
if (!entry.getKey().equals("datasources")) {
builder.addProperty(entry.getKey(), entry.getValue());
}
}
builder.addProperty("datasources", Joiner.on(',').join(datasources));
// update announcement
announcer.removeServiceAnnouncement(announcement.getId());
announcer.addServiceAnnouncement(builder.build());
}