Skip to content

DATAES-314 - NodeClientFactoryBean doesn't shutdown ES on destroy lif… #333

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 22, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*/
package org.springframework.data.elasticsearch.client;

import static java.util.Arrays.*;

import java.io.IOException;
import java.io.InputStream;
import java.util.Collection;
Expand Down Expand Up @@ -51,6 +49,7 @@ public class NodeClientFactoryBean implements FactoryBean<Client>, InitializingB
private boolean local;
private boolean enableHttp;
private String clusterName;
private Node node;
private NodeClient nodeClient;
private String pathData;
private String pathHome;
Expand Down Expand Up @@ -99,10 +98,17 @@ public boolean isSingleton() {
@Override
public void afterPropertiesSet() throws Exception {

nodeClient = (NodeClient) new TestNode(Settings.builder().put(loadConfig()).put("transport.type", "netty4")
.put("http.type", "netty4").put("path.home", this.pathHome).put("path.data", this.pathData)
.put("cluster.name", this.clusterName).put("node.max_local_storage_nodes", 100).build(),
asList(Netty4Plugin.class)).start().client();
Settings settings = Settings.builder() //
.put(loadConfig()) //
.put("transport.type", "netty4") //
.put("http.type", "netty4") //
.put("path.home", this.pathHome) //
.put("path.data", this.pathData) //
.put("cluster.name", this.clusterName) //
.put("node.max_local_storage_nodes", 100) //
.build();
node = new TestNode(settings, Collections.singletonList(Netty4Plugin.class));
nodeClient = (NodeClient) node.start().client();
}

private Settings loadConfig() throws IOException {
Expand Down Expand Up @@ -144,9 +150,10 @@ public void setPathConfiguration(String configuration) {
@Override
public void destroy() throws Exception {
try {
logger.info("Closing elasticSearch client");
if (nodeClient != null) {
nodeClient.close();
// NodeClient.close() is a noop, no need to call it here
logger.info("Closing elasticSearch node");
if (node != null) {
node.close();
}
} catch (final Exception e) {
logger.error("Error closing ElasticSearch client: ", e);
Expand Down