Search in sources :

Example 21 with Tuple

use of org.elasticsearch.common.collect.Tuple in project elasticsearch by elastic.

the class RestSimulatePipelineAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) throws IOException {
    Tuple<XContentType, BytesReference> sourceTuple = restRequest.contentOrSourceParam();
    SimulatePipelineRequest request = new SimulatePipelineRequest(sourceTuple.v2(), sourceTuple.v1());
    request.setId(restRequest.param("id"));
    request.setVerbose(restRequest.paramAsBoolean("verbose", false));
    return channel -> client.admin().cluster().simulatePipeline(request, new RestToXContentListener<>(channel));
}
Also used : BytesReference(org.elasticsearch.common.bytes.BytesReference) BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) Settings(org.elasticsearch.common.settings.Settings) XContentType(org.elasticsearch.common.xcontent.XContentType) RestToXContentListener(org.elasticsearch.rest.action.RestToXContentListener) SimulatePipelineRequest(org.elasticsearch.action.ingest.SimulatePipelineRequest) RestRequest(org.elasticsearch.rest.RestRequest) NodeClient(org.elasticsearch.client.node.NodeClient) IOException(java.io.IOException) RestController(org.elasticsearch.rest.RestController) BytesReference(org.elasticsearch.common.bytes.BytesReference) Tuple(org.elasticsearch.common.collect.Tuple) XContentType(org.elasticsearch.common.xcontent.XContentType) SimulatePipelineRequest(org.elasticsearch.action.ingest.SimulatePipelineRequest)

Example 22 with Tuple

use of org.elasticsearch.common.collect.Tuple in project crate by crate.

the class FileReadingIterator method initCollectorState.

private void initCollectorState() {
    lineContext = new LineContext();
    for (LineCollectorExpression<?> collectorExpression : collectorExpressions) {
        collectorExpression.startCollect(lineContext);
    }
    List<Tuple<FileInput, UriWithGlob>> fileInputs = new ArrayList<>(urisWithGlob.size());
    for (UriWithGlob fileUri : urisWithGlob) {
        try {
            FileInput fileInput = getFileInput(fileUri.uri);
            fileInputs.add(new Tuple<>(fileInput, fileUri));
        } catch (IOException e) {
            rethrowUnchecked(e);
        }
    }
    fileInputsIterator = fileInputs.iterator();
}
Also used : LineContext(io.crate.operation.reference.file.LineContext) IOException(java.io.IOException) Tuple(org.elasticsearch.common.collect.Tuple)

Example 23 with Tuple

use of org.elasticsearch.common.collect.Tuple in project crate by crate.

the class TransportDeleteBlobAction method shardOperationOnPrimary.

@Override
protected Tuple<DeleteBlobResponse, DeleteBlobRequest> shardOperationOnPrimary(MetaData metaData, DeleteBlobRequest request) throws Throwable {
    logger.trace("shardOperationOnPrimary {}", request);
    BlobShard blobShard = blobIndicesService.blobShardSafe(request.shardId());
    boolean deleted = blobShard.delete(request.id());
    final DeleteBlobResponse response = new DeleteBlobResponse(deleted);
    return new Tuple<>(response, request);
}
Also used : BlobShard(io.crate.blob.v2.BlobShard) Tuple(org.elasticsearch.common.collect.Tuple)

Example 24 with Tuple

use of org.elasticsearch.common.collect.Tuple in project crate by crate.

the class ExecutionPhasesTask method setupContext.

private void setupContext(Map<String, Collection<NodeOperation>> operationByServer, List<ExecutionPhase> handlerPhases, List<BatchConsumer> handlerConsumers) throws Throwable {
    assert handlerPhases.size() == handlerConsumers.size() : "handlerPhases size must match handlerConsumers size";
    String localNodeId = clusterService.localNode().getId();
    Collection<NodeOperation> localNodeOperations = operationByServer.remove(localNodeId);
    if (localNodeOperations == null) {
        localNodeOperations = Collections.emptyList();
    }
    // + 1 for localJobContext which is always created
    InitializationTracker initializationTracker = new InitializationTracker(operationByServer.size() + 1);
    List<Tuple<ExecutionPhase, BatchConsumer>> handlerPhaseAndReceiver = createHandlerPhaseAndReceivers(handlerPhases, handlerConsumers, initializationTracker);
    JobExecutionContext.Builder builder = jobContextService.newBuilder(jobId(), localNodeId, operationByServer.keySet());
    List<CompletableFuture<Bucket>> directResponseFutures = contextPreparer.prepareOnHandler(localNodeOperations, builder, handlerPhaseAndReceiver, new SharedShardContexts(indicesService));
    JobExecutionContext localJobContext = jobContextService.createContext(builder);
    List<PageBucketReceiver> pageBucketReceivers = getHandlerBucketReceivers(localJobContext, handlerPhaseAndReceiver);
    int bucketIdx = 0;
    /*
         * If you touch anything here make sure the following tests pass with > 1k iterations:
         *
         * Seed: 112E1807417E925A - testInvalidPatternSyntax
         * Seed: Any              - testRegularSelectWithFewAvailableThreadsShouldNeverGetStuck
         * Seed: CC456FF5004F35D3 - testFailureOfJoinDownstream
         */
    if (!localNodeOperations.isEmpty() && !directResponseFutures.isEmpty()) {
        CompletableFutures.allAsList(directResponseFutures).whenComplete(new SetBucketCallback(pageBucketReceivers, bucketIdx, initializationTracker));
        bucketIdx++;
        try {
            // initializationTracker for localNodeOperations is triggered via SetBucketCallback
            localJobContext.start();
        } catch (Throwable t) {
            accountFailureForRemoteOperations(operationByServer, initializationTracker, handlerPhaseAndReceiver, t);
            return;
        }
    } else {
        try {
            localJobContext.start();
            initializationTracker.jobInitialized();
        } catch (Throwable t) {
            initializationTracker.jobInitializationFailed(t);
            accountFailureForRemoteOperations(operationByServer, initializationTracker, handlerPhaseAndReceiver, t);
            return;
        }
    }
    sendJobRequests(localNodeId, operationByServer, pageBucketReceivers, handlerPhaseAndReceiver, bucketIdx, initializationTracker);
}
Also used : NodeOperation(io.crate.operation.NodeOperation) CompletableFuture(java.util.concurrent.CompletableFuture) SharedShardContexts(io.crate.action.job.SharedShardContexts) Tuple(org.elasticsearch.common.collect.Tuple)

Example 25 with Tuple

use of org.elasticsearch.common.collect.Tuple in project crate by crate.

the class Assignments method convert.

/**
     * convert assignments into a tuple of fqn column names and the symbols.
     * <p>
     * <pre>
     *     {
     *         users.age:  users.age + 1,
     *         users.name: users.name || 'foo'
     *
     *     }
     * </pre>
     * becomes
     * <pre>
     *     ( [users.age, users.name], [users.age + 1, users.name || 'foo'] )
     * </pre>
     *
     * @return a tuple or null if the input is null.
     */
public static Tuple<String[], Symbol[]> convert(@Nonnull Map<Reference, ? extends Symbol> assignments) {
    String[] assignmentColumns = new String[assignments.size()];
    Symbol[] assignmentSymbols = new Symbol[assignments.size()];
    int i = 0;
    for (Map.Entry<Reference, ? extends Symbol> entry : assignments.entrySet()) {
        Reference key = entry.getKey();
        assignmentColumns[i] = key.ident().columnIdent().fqn();
        assignmentSymbols[i] = entry.getValue();
        i++;
    }
    return new Tuple<>(assignmentColumns, assignmentSymbols);
}
Also used : Reference(io.crate.metadata.Reference) Map(java.util.Map) Tuple(org.elasticsearch.common.collect.Tuple)

Aggregations

Tuple (org.elasticsearch.common.collect.Tuple)50 IOException (java.io.IOException)18 ArrayList (java.util.ArrayList)17 HashMap (java.util.HashMap)12 List (java.util.List)12 Map (java.util.Map)12 Settings (org.elasticsearch.common.settings.Settings)8 CountDownLatch (java.util.concurrent.CountDownLatch)7 HashSet (java.util.HashSet)6 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)6 Matchers.containsString (org.hamcrest.Matchers.containsString)6 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)5 Supplier (org.apache.logging.log4j.util.Supplier)5 TaskInfo (org.elasticsearch.tasks.TaskInfo)5 Set (java.util.Set)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 Consumer (java.util.function.Consumer)4 ElasticsearchException (org.elasticsearch.ElasticsearchException)4 Version (org.elasticsearch.Version)4 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)4