String type = null;
if (settings.containsKey("es_connection")) {
Map<String, Object> sourceClientSettings = (Map<String, Object>) settings.get("es_connection");
type = XContentMapValues.nodeStringValue(sourceClientSettings.get("type"), null);
if (Utils.isEmpty(type)) {
throw new SettingsException("es_connection/type element of configuration structure not found or empty");
}
if ("local".equalsIgnoreCase(type)) {
sourceClient = new SourceClientESClient(client);
} else if ("remote".equalsIgnoreCase(type)) {
sourceClient = new SourceClientESTransportClient(sourceClientSettings);
} else if ("rest".equalsIgnoreCase(type)) {
sourceClient = new SourceClientREST(sourceClientSettings);
} else {
throw new SettingsException("es_connection/type value '" + type
+ "' is invalid. Use one of local, remote, rest");
}
} else {
throw new SettingsException("'es_connection' element of river configuration structure not found");
}
Map<String, Map<String, Object>> indexersMap = (Map<String, Map<String, Object>>) settings.get("indexers");
if (indexersMap != null && !indexersMap.isEmpty()) {
for (String name : indexersMap.keySet()) {
name = name.trim();
if (indexers.containsKey(name)) {
throw new SettingsException("Duplicate 'indexers/" + name + "' section");
}
Map<String, Object> ic = indexersMap.get(name);
SysinfoType infoType = SysinfoType.parseConfiguration((String) ic.get("info_type"));
String indexName = configMandatoryString(ic, "index_name", name);
String typeName = configMandatoryString(ic, "index_type", name);
long indexingPeriod = Utils.parseTimeValue(ic, "period", 30, TimeUnit.SECONDS);
Map<String, String> params = (Map<String, String>) ic.get("params");
indexers.put(name, new SysinfoIndexer(name, sourceClient, client, infoType, indexName, typeName,
indexingPeriod, params));
}
} else {
throw new SettingsException("'indexers' element of river configuration structure not found or is empty");
}
logger.info("Sysinfo River configured for connection type '{}' and {} indexers.", type, indexers.size());
}