align with es221

main
Jörg Prante 3 years ago
parent 9c606eebdd
commit b7d3184200

@ -8,6 +8,8 @@ import java.util.concurrent.TimeUnit;
public interface BasicClient extends Closeable {
void init(Settings settings);
void putClusterSetting(String key, Object value, long timeout, TimeUnit timeUnit);
/**
@ -23,8 +25,6 @@ public interface BasicClient extends Closeable {
*/
ElasticsearchClient getClient();
void init(Settings settings);
/**
* Get cluster name.
* @return the cluster name

@ -65,7 +65,7 @@ public interface BulkClient extends BasicClient, Flushable {
* Delete request.
*
* @param indexDefinition the index definition
* @param id the id
* @param id the id
* @return this
*/
BulkClient delete(IndexDefinition indexDefinition, String id);
@ -85,7 +85,7 @@ public interface BulkClient extends BasicClient, Flushable {
* Note that updates only work correctly when all operations between nodes are synchronized.
*
* @param indexDefinition the index definition
* @param id the id
* @param id the id
* @param source the source
* @return this
*/
@ -95,7 +95,7 @@ public interface BulkClient extends BasicClient, Flushable {
* Update document. Use with precaution! Does not work in all cases.
*
* @param indexDefinition the index definition
* @param id the id
* @param id the id
* @param source the source
* @return this
*/

@ -131,6 +131,7 @@ public abstract class AbstractAdminClient extends AbstractBasicClient implements
if (isIndexDefinitionDisabled(indexDefinition)) {
return -1;
}
ensureClientIsPresent();
String index = indexDefinition.getFullIndexName();
GetSettingsRequest request = new GetSettingsRequest().indices(index);
GetSettingsResponse response = client.execute(GetSettingsAction.INSTANCE, request).actionGet();
@ -168,6 +169,7 @@ public abstract class AbstractAdminClient extends AbstractBasicClient implements
if (index == null) {
return Collections.emptyMap();
}
ensureClientIsPresent();
GetAliasesRequest getAliasesRequest = new GetAliasesRequest().indices(index);
return getFilters(client.execute(GetAliasesAction.INSTANCE, getAliasesRequest).actionGet());
}
@ -331,7 +333,7 @@ public abstract class AbstractAdminClient extends AbstractBasicClient implements
}
}
if (candidateIndices.isEmpty()) {
logger.info("no candidates found");
logger.info("no candidates found");
return new EmptyPruneResult();
}
if (mintokeep > 0 && candidateIndices.size() <= mintokeep) {

@ -71,9 +71,9 @@ public abstract class AbstractBasicClient implements BasicClient {
@Override
public void init(Settings settings) {
this.settings = settings;
if (closed.compareAndSet(false, true)) {
logger.log(Level.INFO, "initializing with settings = " + settings.toDelimitedString(','));
this.settings = settings;
setClient(createClient(settings));
}
}
@ -176,6 +176,7 @@ public abstract class AbstractBasicClient implements BasicClient {
@Override
public boolean isIndexExists(IndexDefinition indexDefinition) {
ensureClientIsPresent();
IndicesExistsRequest indicesExistsRequest = new IndicesExistsRequest();
indicesExistsRequest.indices(indexDefinition.getFullIndexName());
IndicesExistsResponse indicesExistsResponse =
@ -185,18 +186,17 @@ public abstract class AbstractBasicClient implements BasicClient {
@Override
public void close() throws IOException {
ensureClientIsPresent();
if (closed.compareAndSet(false, true)) {
closeClient(settings);
if (scheduler != null) {
scheduler.shutdown();
}
closeClient(settings);
}
}
protected abstract ElasticsearchClient createClient(Settings settings);
protected abstract void closeClient(Settings settings) throws IOException;
protected abstract void closeClient(Settings settings);
protected void updateIndexSetting(String index, String key, Object value, long timeout, TimeUnit timeUnit) {
ensureClientIsPresent();

@ -191,8 +191,10 @@ public abstract class AbstractBulkClient extends AbstractBasicClient implements
@Override
public BulkClient index(IndexRequest indexRequest) {
ensureClientIsPresent();
bulkProcessor.add(indexRequest);
if (bulkProcessor != null) {
ensureClientIsPresent();
bulkProcessor.add(indexRequest);
}
return this;
}

@ -94,7 +94,6 @@ public class DefaultIndexDefinition implements IndexDefinition {
if (settings.get("settings") != null && settings.get("mapping") != null) {
setSettings(findSettingsFrom(settings.get("settings")));
setMappings(findMappingsFrom(settings.get("mapping")));
setReplicaCount(settings.getAsInt("replica", 0));
boolean shift = settings.getAsBoolean("shift", false);
setShift(shift);
if (shift) {

@ -9,7 +9,6 @@ import org.elasticsearch.client.ElasticsearchClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.threadpool.ThreadPool;
import org.xbib.elx.common.AbstractBulkClient;
import java.io.IOException;
/**
* Elasticsearch HTTP bulk client.
@ -35,7 +34,7 @@ public class HttpBulkClient extends AbstractBulkClient implements ElasticsearchC
}
@Override
protected void closeClient(Settings settings) throws IOException {
protected void closeClient(Settings settings) {
helper.closeClient(settings);
}

@ -9,7 +9,6 @@ import org.elasticsearch.client.ElasticsearchClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.threadpool.ThreadPool;
import org.xbib.elx.common.AbstractSearchClient;
import java.io.IOException;
/**
* Elasticsearch HTTP search client.
@ -35,7 +34,7 @@ public class HttpSearchClient extends AbstractSearchClient implements Elasticsea
}
@Override
protected void closeClient(Settings settings) throws IOException {
protected void closeClient(Settings settings) {
helper.closeClient(settings);
}

@ -3,7 +3,6 @@ package org.xbib.elx.node;
import org.elasticsearch.client.ElasticsearchClient;
import org.elasticsearch.common.settings.Settings;
import org.xbib.elx.common.AbstractAdminClient;
import java.io.IOException;
public class NodeAdminClient extends AbstractAdminClient {
@ -20,7 +19,7 @@ public class NodeAdminClient extends AbstractAdminClient {
}
@Override
public void closeClient(Settings settings) throws IOException {
public void closeClient(Settings settings) {
helper.closeClient(settings);
}
}

@ -3,7 +3,6 @@ package org.xbib.elx.node;
import org.elasticsearch.client.ElasticsearchClient;
import org.elasticsearch.common.settings.Settings;
import org.xbib.elx.common.AbstractBulkClient;
import java.io.IOException;
public class NodeBulkClient extends AbstractBulkClient {
@ -20,7 +19,7 @@ public class NodeBulkClient extends AbstractBulkClient {
}
@Override
public void closeClient(Settings settings) throws IOException {
public void closeClient(Settings settings) {
helper.closeClient(settings);
}
}

@ -40,11 +40,15 @@ public class NodeClientHelper {
key -> innerCreateClient(settings));
}
public void closeClient(Settings settings) throws IOException {
ElasticsearchClient client = clientMap.remove(settings.get("cluster.name"));
if (client != null) {
logger.debug("closing node...");
node.close();
public void closeClient(Settings settings) {
clientMap.remove(settings.get("cluster.name"));
logger.debug("closing node...");
if (node != null) {
try {
node.close();
} catch (IOException e) {
logger.log(Level.WARN, e.getMessage(), e);
}
node = null;
}
}

@ -3,7 +3,6 @@ package org.xbib.elx.node;
import org.elasticsearch.client.ElasticsearchClient;
import org.elasticsearch.common.settings.Settings;
import org.xbib.elx.common.AbstractSearchClient;
import java.io.IOException;
public class NodeSearchClient extends AbstractSearchClient {
@ -20,7 +19,7 @@ public class NodeSearchClient extends AbstractSearchClient {
}
@Override
public void closeClient(Settings settings) throws IOException {
public void closeClient(Settings settings) {
helper.closeClient(settings);
}
}

Loading…
Cancel
Save