use of com.b2international.index.es.client.tcp.EsTcpClient in project snow-owl by b2ihealthcare.
the class EsIndexClientFactory method createClient.
@Override
public IndexClient createClient(String name, ObjectMapper mapper, Mappings mappings, Map<String, Object> settings) {
final boolean persistent = settings.containsKey(DATA_DIRECTORY);
final Object dataSetting = settings.getOrDefault(DATA_DIRECTORY, DEFAULT_PATH);
final Object configSetting = settings.getOrDefault(CONFIG_DIRECTORY, DEFAULT_PATH);
final Path dataDirectory = dataSetting instanceof Path ? (Path) dataSetting : Paths.get((String) dataSetting);
final Path configDirectory = configSetting instanceof Path ? (Path) configSetting : Paths.get((String) configSetting);
// generic ES cluster settings
final String clusterName = (String) settings.getOrDefault(CLUSTER_NAME, DEFAULT_CLUSTER_NAME);
final Object connectTimeoutSetting = settings.getOrDefault(CONNECT_TIMEOUT, DEFAULT_CONNECT_TIMEOUT);
final Object socketTimeoutSetting = settings.getOrDefault(SOCKET_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);
final int connectTimeout = connectTimeoutSetting instanceof Integer ? (int) connectTimeoutSetting : Integer.parseInt((String) connectTimeoutSetting);
final int socketTimeout = socketTimeoutSetting instanceof Integer ? (int) socketTimeoutSetting : Integer.parseInt((String) socketTimeoutSetting);
final String username = (String) settings.getOrDefault(CLUSTER_USERNAME, "");
final String password = (String) settings.getOrDefault(CLUSTER_PASSWORD, "");
final EsClient client;
if (settings.containsKey(CLUSTER_URL)) {
final String clusterUrl = (String) settings.get(CLUSTER_URL);
client = EsClient.create(new EsClientConfiguration(clusterName, clusterUrl, username, password, connectTimeout, socketTimeout));
} else {
// Start an embedded ES node only if a cluster URL is not set
Node node = EsNode.getInstance(clusterName, configDirectory, dataDirectory, persistent);
// check sysprop to force HTTP client when still using embedded mode
if (System.getProperty("so.index.es.useHttp") != null) {
client = EsClient.create(new EsClientConfiguration(clusterName, "http://127.0.0.1:9200", username, password, connectTimeout, socketTimeout));
} else {
// and use the local NodeClient to communicate via the embedded node
client = new EsTcpClient(node.client());
}
}
return new EsIndexClient(new EsIndexAdmin(client, mapper, name, mappings, settings), mapper);
}
Aggregations