mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-17 15:03:18 +00:00
Simplify ES client creation (Node, Local, Transport), and default to Node
Changed default client to be NodeClient so we can listen to IP transport.
This commit is contained in:
@@ -68,7 +68,9 @@ public class ElasticSearchLogger {
|
|||||||
|
|
||||||
private static Client client;
|
private static Client client;
|
||||||
|
|
||||||
private static boolean havingTroubles = false;
|
public static enum ClientType {
|
||||||
|
NODE, LOCAL, TRANSPORT
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public ElasticSearchLogger() {
|
public ElasticSearchLogger() {
|
||||||
@@ -269,7 +271,7 @@ public class ElasticSearchLogger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.info("DSpace ElasticSearchLogger Initialized Successfully (I suppose)");
|
log.info("DSpace ElasticSearchLogger Initialized Successfully (I suppose)");
|
||||||
havingTroubles=false;
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.info("Elastic Search crashed during init. " + e.getMessage());
|
log.info("Elastic Search crashed during init. " + e.getMessage());
|
||||||
}
|
}
|
||||||
@@ -405,11 +407,9 @@ public class ElasticSearchLogger {
|
|||||||
|
|
||||||
} catch (RuntimeException re) {
|
} catch (RuntimeException re) {
|
||||||
log.error("RunTimer in ESL:\n" + ExceptionUtils.getStackTrace(re));
|
log.error("RunTimer in ESL:\n" + ExceptionUtils.getStackTrace(re));
|
||||||
havingTroubles=true;
|
|
||||||
throw re;
|
throw re;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error(e.getMessage());
|
log.error(e.getMessage());
|
||||||
havingTroubles=true;
|
|
||||||
} finally {
|
} finally {
|
||||||
client.close();
|
client.close();
|
||||||
}
|
}
|
||||||
@@ -525,10 +525,17 @@ public class ElasticSearchLogger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Transport Client will talk to another server on 9300
|
// Transport Client will talk to another server on 9300
|
||||||
public void createTransportClient(boolean skipCheck) {
|
public void createTransportClient() {
|
||||||
if(havingTroubles && !skipCheck) {
|
// Configurable values for all elasticsearch connection constants
|
||||||
initializeElasticSearch();
|
clusterName = getConfigurationStringWithFallBack("statistics.elasticsearch.clusterName", clusterName);
|
||||||
}
|
indexName = getConfigurationStringWithFallBack("statistics.elasticsearch.indexName", indexName);
|
||||||
|
indexType = getConfigurationStringWithFallBack("statistics.elasticsearch.indexType", indexType);
|
||||||
|
address = getConfigurationStringWithFallBack("statistics.elasticsearch.address", address);
|
||||||
|
port = ConfigurationManager.getIntProperty("statistics.elasticsearch.port", port);
|
||||||
|
storeData = ConfigurationManager.getBooleanProperty("statistics.elasticsearch.storeData", storeData);
|
||||||
|
|
||||||
|
log.info("Creating TransportClient to [Address:" + address + "] [Port:" + port + "] [cluster.name:" + clusterName + "]");
|
||||||
|
|
||||||
Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name", clusterName).build();
|
Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name", clusterName).build();
|
||||||
client = new TransportClient(settings).addTransportAddress(new InetSocketTransportAddress(address, port));
|
client = new TransportClient(settings).addTransportAddress(new InetSocketTransportAddress(address, port));
|
||||||
}
|
}
|
||||||
@@ -537,44 +544,50 @@ public class ElasticSearchLogger {
|
|||||||
//createElasticClient(true);
|
//createElasticClient(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Client getClient() {
|
||||||
|
//Get an available client, otherwise new default is NODE.
|
||||||
|
return getClient(ClientType.NODE);
|
||||||
|
}
|
||||||
|
|
||||||
// Get the already available client, otherwise we will create a new client.
|
// Get the already available client, otherwise we will create a new client.
|
||||||
// TODO Allow for config to determine which architecture / topology to use.
|
// TODO Allow for config to determine which architecture / topology to use.
|
||||||
// - Local Node, store Data
|
// - Local Node, store Data
|
||||||
// - Node Client, must discover a master within ES cluster
|
// - Node Client, must discover a master within ES cluster
|
||||||
// - Transport Client, specify IP address of server running ES.
|
// - Transport Client, specify IP address of server running ES.
|
||||||
public Client getClient() {
|
public Client getClient(ClientType clientType) {
|
||||||
if(client == null) {
|
if(client == null) {
|
||||||
log.error("getClient reports null client");
|
log.error("getClient reports null client");
|
||||||
createNodeClient();
|
|
||||||
|
|
||||||
|
if(clientType == ClientType.TRANSPORT) {
|
||||||
//createElasticClient();
|
createTransportClient();
|
||||||
|
} else {
|
||||||
|
createNodeClient(clientType);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return client;
|
return client;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Node Client will discover other ES nodes running in local JVM
|
// Node Client will discover other ES nodes running in local JVM
|
||||||
public void createNodeClient() {
|
public Client createNodeClient(ClientType clientType) {
|
||||||
NodeBuilder nodeBuilder = NodeBuilder.nodeBuilder().clusterName(clusterName);
|
|
||||||
|
|
||||||
if(storeData) {
|
|
||||||
String dspaceDir = ConfigurationManager.getProperty("dspace.dir");
|
String dspaceDir = ConfigurationManager.getProperty("dspace.dir");
|
||||||
Settings settings = ImmutableSettings.settingsBuilder().put("path.data", dspaceDir + "/elasticsearch/").build();
|
Settings settings = ImmutableSettings.settingsBuilder().put("path.data", dspaceDir + "/elasticsearch/").build();
|
||||||
log.info("Create a Local Node that will store data.");
|
|
||||||
nodeBuilder = nodeBuilder.data(true).local(true).settings(settings);
|
NodeBuilder nodeBuilder = NodeBuilder.nodeBuilder().clusterName(clusterName).data(true).settings(settings);
|
||||||
} else {
|
|
||||||
log.info("Create a nodeClient, that looks for a neighbor to be master.");
|
if(clientType == ClientType.LOCAL) {
|
||||||
nodeBuilder = nodeBuilder.client(true);
|
log.info("Create a Local Node.");
|
||||||
|
nodeBuilder = nodeBuilder.local(true);
|
||||||
|
} else if(clientType == ClientType.NODE) {
|
||||||
|
log.info("Create a nodeClient, allows transport clients to connect");
|
||||||
|
nodeBuilder = nodeBuilder.local(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
Node node = nodeBuilder.node();
|
Node node = nodeBuilder.node();
|
||||||
log.info("Got node");
|
log.info("Got node");
|
||||||
client = node.client();
|
client = node.client();
|
||||||
log.info("Created new node client");
|
log.info("Created new node client");
|
||||||
}
|
return client;
|
||||||
|
|
||||||
public void createElasticClient(boolean skipCheck) {
|
|
||||||
log.info("Creating a new elastic-client");
|
|
||||||
//createTransportClient(skipCheck);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getConfigurationStringWithFallBack(String configurationKey, String defaultFallbackValue) {
|
public String getConfigurationStringWithFallBack(String configurationKey, String defaultFallbackValue) {
|
||||||
|
Reference in New Issue
Block a user