Skip to content
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 @@ -49,6 +49,7 @@
import javax.security.auth.kerberos.KerberosTicket;

import java.io.File;
import java.io.IOException;
import java.security.PrivilegedActionException;
import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -319,32 +320,30 @@ private String connectionString() {
}

private RestHighLevelClient newClient() {
RestHighLevelClient restHighLevelClient = null;

try {
if (StringUtils.isNotBlank(user) && StringUtils.isNotBlank(password) && password.contains("keytab") && new File(password).exists()) {
subject = CredentialsProviderUtil.login(user, password);
}

RestClientBuilder restClientBuilder = getRestClientBuilder(hosts, protocol, user, password, port);
restHighLevelClient = new RestHighLevelClient(restClientBuilder);
boolean exists = false;

try (RestHighLevelClient restHighLevelClient = new RestHighLevelClient(restClientBuilder)) {
LOG.debug("Initialized client");

boolean exists = false;

try {
exists = restHighLevelClient.indices().open(new OpenIndexRequest(this.index), RequestOptions.DEFAULT).isShardsAcknowledged();
} catch (Exception e) {
LOG.warn("Error validating index {}", this.index);
}

if (exists) {
LOG.debug("Index exists");
} else {
LOG.info("Index does not exist");
}
try {
exists = restHighLevelClient.indices().open(new OpenIndexRequest(this.index), RequestOptions.DEFAULT).isShardsAcknowledged();
} catch (Exception e) {
LOG.warn("Error validating index {}", this.index);
}

return restHighLevelClient;
if (exists) {
LOG.debug("Index exists");
} else {
LOG.info("Index does not exist");
}

return restHighLevelClient;
} catch (Throwable t) {
lastLoggedAt.updateAndGet(lastLoggedAt -> {
long now = System.currentTimeMillis();
Expand All @@ -358,6 +357,16 @@ private RestHighLevelClient newClient() {
return lastLoggedAt;
}
});

if (restHighLevelClient != null) {
try {
restHighLevelClient.close();
LOG.debug("Closed RestHighLevelClient after failure");
} catch (IOException e) {
LOG.warn("Error closing RestHighLevelClient: {}", e.getMessage(), e);
}
}

return null;
}
}
Expand Down