Search in sources :

Example 1 with RequestSender

use of org.codelibs.elasticsearch.idxproxy.sender.RequestSender in project elasticsearch-indexing-proxy by codelibs.

the class IndexingProxyService method launchRequestSender.

private void launchRequestSender(final String index, final long filePosition, final long version, final ActionListener<Map<String, Object>> listener) {
    if (logger.isDebugEnabled()) {
        logger.debug("Launching RequestSender(" + index + ")");
    }
    final Map<String, Object> source = new HashMap<>();
    source.put(IndexingProxyPlugin.NODE_NAME, nodeName());
    source.put(IndexingProxyPlugin.FILE_POSITION, filePosition);
    source.put(IndexingProxyPlugin.TIMESTAMP, new Date());
    source.put(DOC_TYPE, "index");
    final IndexRequestBuilder builder = client.prepareIndex(IndexingProxyPlugin.INDEX_NAME, IndexingProxyPlugin.TYPE_NAME, index).setSource(source).setRefreshPolicy(RefreshPolicy.WAIT_UNTIL);
    if (version > 0) {
        builder.setVersion(version);
    } else {
        builder.setCreate(true);
    }
    builder.execute(wrap(res -> {
        if (res.getResult() == Result.CREATED || res.getResult() == Result.UPDATED) {
            final RequestSender sender = new RequestSender(settings, client, threadPool, namedWriteableRegistry, nodeName(), dataPath, index, dataFileFormat, docSenderMap, logger);
            final RequestSender oldSender = docSenderMap.put(index, sender);
            if (oldSender != null) {
                oldSender.terminate();
            }
            threadPool.schedule(TimeValue.ZERO, Names.GENERIC, sender);
            listener.onResponse(source);
        } else {
            listener.onFailure(new ElasticsearchException("Failed to update .idxproxy index: " + res));
        }
    }, listener::onFailure));
}
Also used : IndexRequestBuilder(org.elasticsearch.action.index.IndexRequestBuilder) ElasticsearchException(org.elasticsearch.ElasticsearchException) IndexingProxyPlugin(org.codelibs.elasticsearch.idxproxy.IndexingProxyPlugin) Arrays(java.util.Arrays) Date(java.util.Date) WriteRequestHandler(org.codelibs.elasticsearch.idxproxy.action.WriteRequestHandler) Environment(org.elasticsearch.env.Environment) FileTime(java.nio.file.attribute.FileTime) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) JsonXContent(org.elasticsearch.common.xcontent.json.JsonXContent) QueryBuilders(org.elasticsearch.index.query.QueryBuilders) DeleteRequest(org.elasticsearch.action.delete.DeleteRequest) IndexRequest(org.elasticsearch.action.index.IndexRequest) Settings(org.elasticsearch.common.settings.Settings) UpdateResponse(org.elasticsearch.action.update.UpdateResponse) LifecycleListener(org.elasticsearch.common.component.LifecycleListener) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) Map(java.util.Map) DeleteByQueryRequest(org.elasticsearch.index.reindex.DeleteByQueryRequest) Streams(org.elasticsearch.common.io.Streams) ThreadPool(org.elasticsearch.threadpool.ThreadPool) Path(java.nio.file.Path) RefreshPolicy(org.elasticsearch.action.support.WriteRequest.RefreshPolicy) CreateRequest(org.codelibs.elasticsearch.idxproxy.action.CreateRequest) WriteResponse(org.codelibs.elasticsearch.idxproxy.action.WriteResponse) SearchHit(org.elasticsearch.search.SearchHit) ActionRequest(org.elasticsearch.action.ActionRequest) ActionFilter(org.elasticsearch.action.support.ActionFilter) ActionFilters(org.elasticsearch.action.support.ActionFilters) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) ToXContent(org.elasticsearch.common.xcontent.ToXContent) Reader(java.io.Reader) PrivilegedAction(java.security.PrivilegedAction) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) List(java.util.List) IndexingProxyStreamInput(org.codelibs.elasticsearch.idxproxy.stream.IndexingProxyStreamInput) IndexRequestBuilder(org.elasticsearch.action.index.IndexRequestBuilder) Strings(org.apache.logging.log4j.util.Strings) TransportResponseHandler(org.elasticsearch.transport.TransportResponseHandler) AccessController(java.security.AccessController) TransportException(org.elasticsearch.transport.TransportException) ProxyActionFilter(org.codelibs.elasticsearch.idxproxy.action.ProxyActionFilter) XContentFactory(org.elasticsearch.common.xcontent.XContentFactory) CreateRequestHandler(org.codelibs.elasticsearch.idxproxy.action.CreateRequestHandler) ClusterService(org.elasticsearch.cluster.service.ClusterService) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) UpdateRequestBuilder(org.elasticsearch.action.update.UpdateRequestBuilder) ActionListener.wrap(org.elasticsearch.action.ActionListener.wrap) HashMap(java.util.HashMap) IndexingProxyStreamOutput(org.codelibs.elasticsearch.idxproxy.stream.IndexingProxyStreamOutput) Names(org.elasticsearch.threadpool.ThreadPool.Names) StandardCopyOption(java.nio.file.StandardCopyOption) ArrayList(java.util.ArrayList) Inject(org.elasticsearch.common.inject.Inject) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) RequestUtils(org.codelibs.elasticsearch.idxproxy.util.RequestUtils) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) TimeValue(org.elasticsearch.common.unit.TimeValue) BiConsumer(java.util.function.BiConsumer) Result(org.elasticsearch.action.DocWriteResponse.Result) TransportService(org.elasticsearch.transport.TransportService) UpdateByQueryRequest(org.elasticsearch.index.reindex.UpdateByQueryRequest) CreateResponse(org.codelibs.elasticsearch.idxproxy.action.CreateResponse) RequestSender(org.codelibs.elasticsearch.idxproxy.sender.RequestSender) FileAccessUtils(org.codelibs.elasticsearch.idxproxy.util.FileAccessUtils) PluginComponent(org.codelibs.elasticsearch.idxproxy.IndexingProxyPlugin.PluginComponent) Iterator(java.util.Iterator) Files(java.nio.file.Files) ActionResponse(org.elasticsearch.action.ActionResponse) Client(org.elasticsearch.client.Client) IOException(java.io.IOException) PingResponse(org.codelibs.elasticsearch.idxproxy.action.PingResponse) ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) UpdateRequest(org.elasticsearch.action.update.UpdateRequest) InputStreamReader(java.io.InputStreamReader) AbstractLifecycleComponent(org.elasticsearch.common.component.AbstractLifecycleComponent) PingRequest(org.codelibs.elasticsearch.idxproxy.action.PingRequest) Consumer(java.util.function.Consumer) LocalNodeMasterListener(org.elasticsearch.cluster.LocalNodeMasterListener) Paths(java.nio.file.Paths) WriteRequest(org.codelibs.elasticsearch.idxproxy.action.WriteRequest) PingRequestHandler(org.codelibs.elasticsearch.idxproxy.action.PingRequestHandler) Collections(java.util.Collections) BulkRequest(org.elasticsearch.action.bulk.BulkRequest) ActionListener(org.elasticsearch.action.ActionListener) RequestSender(org.codelibs.elasticsearch.idxproxy.sender.RequestSender) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ElasticsearchException(org.elasticsearch.ElasticsearchException) Date(java.util.Date)

Aggregations

IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 StandardCopyOption (java.nio.file.StandardCopyOption)1 FileTime (java.nio.file.attribute.FileTime)1 AccessController (java.security.AccessController)1 PrivilegedAction (java.security.PrivilegedAction)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1