Search in sources :

Example 71 with Client

use of org.elasticsearch.client.Client in project fess by codelibs.

the class EsDataStoreImpl method storeData.

@Override
protected void storeData(final DataConfig dataConfig, final IndexUpdateCallback callback, final Map<String, String> paramMap, final Map<String, String> scriptMap, final Map<String, Object> defaultDataMap) {
    final String hostsStr = paramMap.get(HOSTS);
    if (StringUtil.isBlank(hostsStr)) {
        logger.info("hosts is empty.");
        return;
    }
    final long readInterval = getReadInterval(paramMap);
    final Settings settings = Settings.builder().put(paramMap.entrySet().stream().filter(e -> e.getKey().startsWith(SETTINGS_PREFIX)).collect(Collectors.toMap(e -> e.getKey().replaceFirst("^settings\\.", StringUtil.EMPTY), e -> e.getValue()))).build();
    logger.info("Connecting to " + hostsStr + " with [" + settings.toDelimitedString(',') + "]");
    final InetSocketTransportAddress[] addresses = split(hostsStr, ",").get(stream -> stream.map(h -> {
        final String[] values = h.trim().split(":");
        try {
            if (values.length == 1) {
                return new InetSocketTransportAddress(InetAddress.getByName(values[0]), 9300);
            } else if (values.length == 2) {
                return new InetSocketTransportAddress(InetAddress.getByName(values[0]), Integer.parseInt(values[1]));
            }
        } catch (final Exception e) {
            logger.warn("Failed to parse address: " + h, e);
        }
        return null;
    }).filter(v -> v != null).toArray(n -> new InetSocketTransportAddress[n]));
    try (PreBuiltTransportClient client = new PreBuiltTransportClient(settings)) {
        client.addTransportAddresses(addresses);
        processData(dataConfig, callback, paramMap, scriptMap, defaultDataMap, readInterval, client);
    }
}
Also used : CrawlingAccessException(org.codelibs.fess.crawler.exception.CrawlingAccessException) Constants(org.codelibs.fess.Constants) MultipleCrawlingAccessException(org.codelibs.fess.crawler.exception.MultipleCrawlingAccessException) SearchHits(org.elasticsearch.search.SearchHits) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) IndexUpdateCallback(org.codelibs.fess.ds.IndexUpdateCallback) QueryBuilders(org.elasticsearch.index.query.QueryBuilders) InetAddress(java.net.InetAddress) LinkedHashMap(java.util.LinkedHashMap) StreamUtil.split(org.codelibs.core.stream.StreamUtil.split) Settings(org.elasticsearch.common.settings.Settings) Map(java.util.Map) SearchResponse(org.elasticsearch.action.search.SearchResponse) DataConfig(org.codelibs.fess.es.config.exentity.DataConfig) SearchHit(org.elasticsearch.search.SearchHit) DataStoreCrawlingException(org.codelibs.fess.exception.DataStoreCrawlingException) Logger(org.slf4j.Logger) InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress) Client(org.elasticsearch.client.Client) StringUtil(org.codelibs.core.lang.StringUtil) BulkResponse(org.elasticsearch.action.bulk.BulkResponse) DataStoreException(org.codelibs.fess.exception.DataStoreException) PreBuiltTransportClient(org.elasticsearch.transport.client.PreBuiltTransportClient) Collectors(java.util.stream.Collectors) ComponentUtil(org.codelibs.fess.util.ComponentUtil) SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) FailureUrlService(org.codelibs.fess.app.service.FailureUrlService) BulkRequestBuilder(org.elasticsearch.action.bulk.BulkRequestBuilder) PreBuiltTransportClient(org.elasticsearch.transport.client.PreBuiltTransportClient) InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress) Settings(org.elasticsearch.common.settings.Settings) CrawlingAccessException(org.codelibs.fess.crawler.exception.CrawlingAccessException) MultipleCrawlingAccessException(org.codelibs.fess.crawler.exception.MultipleCrawlingAccessException) DataStoreCrawlingException(org.codelibs.fess.exception.DataStoreCrawlingException) DataStoreException(org.codelibs.fess.exception.DataStoreException)

Example 72 with Client

use of org.elasticsearch.client.Client in project nutch by apache.

the class TestElasticIndexWriter method setup.

@Before
public void setup() {
    conf = NutchConfiguration.create();
    conf.addResource("nutch-site-test.xml");
    bulkRequestSuccessful = false;
    clusterSaturated = false;
    curNumFailures = 0;
    maxNumFailures = 0;
    Settings settings = Settings.builder().build();
    ThreadPool threadPool = new ThreadPool(settings);
    // customize the ES client to simulate responses from an ES cluster
    client = new AbstractClient(settings, threadPool) {

        @Override
        public void close() {
        }

        @Override
        protected <Request extends ActionRequest, Response extends ActionResponse, RequestBuilder extends ActionRequestBuilder<Request, Response, RequestBuilder>> void doExecute(Action<Request, Response, RequestBuilder> action, Request request, ActionListener<Response> listener) {
            BulkResponse response = null;
            if (clusterSaturated) {
                // pretend the cluster is saturated
                curNumFailures++;
                if (curNumFailures >= maxNumFailures) {
                    // pretend the cluster is suddenly no longer saturated
                    clusterSaturated = false;
                }
                // respond with a failure
                BulkItemResponse failed = new BulkItemResponse(0, OpType.INDEX, new BulkItemResponse.Failure("nutch", "index", "failure0", new EsRejectedExecutionException("saturated")));
                response = new BulkResponse(new BulkItemResponse[] { failed }, 0);
            } else {
                // respond successfully
                BulkItemResponse success = new BulkItemResponse(0, OpType.INDEX, new IndexResponse(new ShardId("nutch", UUID.randomUUID().toString(), 0), "index", "index0", 0, true));
                response = new BulkResponse(new BulkItemResponse[] { success }, 0);
            }
            listener.onResponse((Response) response);
        }
    };
    // customize the plugin to signal successful bulk operations
    testIndexWriter = new ElasticIndexWriter() {

        @Override
        protected Client makeClient(Configuration conf) {
            return client;
        }

        @Override
        protected BulkProcessor.Listener bulkProcessorListener() {
            return new BulkProcessor.Listener() {

                @Override
                public void afterBulk(long executionId, BulkRequest request, BulkResponse response) {
                    if (!response.hasFailures()) {
                        bulkRequestSuccessful = true;
                    }
                }

                @Override
                public void afterBulk(long executionId, BulkRequest request, Throwable failure) {
                }

                @Override
                public void beforeBulk(long executionId, BulkRequest request) {
                }
            };
        }
    };
}
Also used : ActionListener(org.elasticsearch.action.ActionListener) ActionRequestBuilder(org.elasticsearch.action.ActionRequestBuilder) Configuration(org.apache.hadoop.conf.Configuration) NutchConfiguration(org.apache.nutch.util.NutchConfiguration) AbstractClient(org.elasticsearch.client.support.AbstractClient) ThreadPool(org.elasticsearch.threadpool.ThreadPool) ActionRequest(org.elasticsearch.action.ActionRequest) BulkRequest(org.elasticsearch.action.bulk.BulkRequest) BulkItemResponse(org.elasticsearch.action.bulk.BulkItemResponse) BulkResponse(org.elasticsearch.action.bulk.BulkResponse) IndexResponse(org.elasticsearch.action.index.IndexResponse) BulkItemResponse(org.elasticsearch.action.bulk.BulkItemResponse) ActionResponse(org.elasticsearch.action.ActionResponse) BulkResponse(org.elasticsearch.action.bulk.BulkResponse) ShardId(org.elasticsearch.index.shard.ShardId) IndexResponse(org.elasticsearch.action.index.IndexResponse) BulkProcessor(org.elasticsearch.action.bulk.BulkProcessor) BulkRequest(org.elasticsearch.action.bulk.BulkRequest) Client(org.elasticsearch.client.Client) AbstractClient(org.elasticsearch.client.support.AbstractClient) Settings(org.elasticsearch.common.settings.Settings) EsRejectedExecutionException(org.elasticsearch.common.util.concurrent.EsRejectedExecutionException) Before(org.junit.Before)

Example 73 with Client

use of org.elasticsearch.client.Client in project elasticsearch-skywalker by jprante.

the class AbstractNodeTest method closeAllNodes.

public void closeAllNodes() {
    for (Client client : clients.values()) {
        client.close();
    }
    clients.clear();
    for (Node node : nodes.values()) {
        node.close();
    }
    nodes.clear();
}
Also used : Node(org.elasticsearch.node.Node) Client(org.elasticsearch.client.Client)

Example 74 with Client

use of org.elasticsearch.client.Client in project elasticsearch-skywalker by jprante.

the class AbstractNodeTest method closeNode.

public void closeNode(String id) {
    Client client = clients.remove(id);
    if (client != null) {
        client.close();
    }
    Node node = nodes.remove(id);
    if (node != null) {
        node.close();
    }
}
Also used : Node(org.elasticsearch.node.Node) Client(org.elasticsearch.client.Client)

Example 75 with Client

use of org.elasticsearch.client.Client in project elasticsearch-skywalker by jprante.

the class AbstractNodeTest method buildNode.

public Node buildNode(String id, Settings settings) {
    String settingsSource = getClass().getName().replace('.', '/') + ".yml";
    Settings finalSettings = settingsBuilder().loadFromClasspath(settingsSource).put(defaultSettings).put(settings).put("name", id).build();
    if (finalSettings.get("gateway.type") == null) {
        // default to non gateway
        finalSettings = settingsBuilder().put(finalSettings).put("gateway.type", "none").build();
    }
    if (finalSettings.get("cluster.routing.schedule") != null) {
        // decrease the routing schedule so new nodes will be added quickly
        finalSettings = settingsBuilder().put(finalSettings).put("cluster.routing.schedule", "50ms").build();
    }
    Node node = nodeBuilder().settings(finalSettings).build();
    Client client = node.client();
    nodes.put(id, node);
    clients.put(id, client);
    return node;
}
Also used : Node(org.elasticsearch.node.Node) Client(org.elasticsearch.client.Client) ImmutableSettings(org.elasticsearch.common.settings.ImmutableSettings) Settings(org.elasticsearch.common.settings.Settings)

Aggregations

Client (org.elasticsearch.client.Client)164 CreateSnapshotResponse (org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse)42 Settings (org.elasticsearch.common.settings.Settings)38 Path (java.nio.file.Path)30 RestoreSnapshotResponse (org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse)28 PutRepositoryResponse (org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse)24 ArrayList (java.util.ArrayList)23 ClusterHealthResponse (org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse)23 IOException (java.io.IOException)20 Matchers.containsString (org.hamcrest.Matchers.containsString)20 IndexRequestBuilder (org.elasticsearch.action.index.IndexRequestBuilder)18 ClusterState (org.elasticsearch.cluster.ClusterState)17 ExecutionException (java.util.concurrent.ExecutionException)16 SearchResponse (org.elasticsearch.action.search.SearchResponse)14 ClusterAdminClient (org.elasticsearch.client.ClusterAdminClient)13 ClusterService (org.elasticsearch.cluster.service.ClusterService)10 List (java.util.List)9 ActionRequestValidationException (org.elasticsearch.action.ActionRequestValidationException)9 CloseIndexResponse (org.elasticsearch.action.admin.indices.close.CloseIndexResponse)9 OpenIndexResponse (org.elasticsearch.action.admin.indices.open.OpenIndexResponse)9