Search in sources :

Example 1 with WorkerQueue

use of build.buildfarm.instance.queues.WorkerQueue in project bazel-buildfarm by bazelbuild.

the class MemoryInstance method backplaneStatus.

@Override
public BackplaneStatus backplaneStatus() {
    BackplaneStatus.Builder status = BackplaneStatus.newBuilder();
    OperationQueueStatus.Builder queueStatus = status.getOperationQueueBuilder();
    long totalSize = 0;
    for (WorkerQueue queue : queuedOperations) {
        long size = queue.operations.size();
        queueStatus.addProvisionsBuilder().setName(queue.name).setSize(size);
        totalSize += size;
    }
    queueStatus.setSize(totalSize);
    // TODO active workers - available, but not with any discerning identifier, should rectify this
    return status.build();
}
Also used : BackplaneStatus(build.buildfarm.v1test.BackplaneStatus) WorkerQueue(build.buildfarm.instance.queues.WorkerQueue) OperationQueueStatus(build.buildfarm.v1test.OperationQueueStatus)

Example 2 with WorkerQueue

use of build.buildfarm.instance.queues.WorkerQueue in project bazel-buildfarm by bazelbuild.

the class MemoryInstance method matchSynchronized.

@SuppressWarnings("ConstantConditions")
private void matchSynchronized(Platform platform, MatchListener listener) throws InterruptedException {
    ImmutableList.Builder<Operation> rejectedOperations = ImmutableList.builder();
    boolean matched = false;
    SetMultimap<String, String> provisions = createProvisions(platform);
    WorkerQueue queue = queuedOperations.MatchEligibleQueue(provisions);
    while (!matched && !queue.operations.isEmpty()) {
        Operation operation = queue.operations.remove(0);
        ExecuteOperationMetadata metadata = expectExecuteOperationMetadata(operation);
        Preconditions.checkState(metadata != null, "metadata not found");
        Action action = getUnchecked(expect(metadata.getActionDigest(), Action.parser(), newDirectExecutorService(), RequestMetadata.getDefaultInstance()));
        Preconditions.checkState(action != null, "action not found");
        Command command = getUnchecked(expect(action.getCommandDigest(), Command.parser(), newDirectExecutorService(), RequestMetadata.getDefaultInstance()));
        Preconditions.checkState(command != null, "command not found");
        String operationName = operation.getName();
        DequeueMatchSettings settings = new DequeueMatchSettings();
        if (command == null) {
            cancelOperation(operationName);
        } else if (DequeueMatchEvaluator.shouldKeepOperation(settings, provisions, command)) {
            QueuedOperation queuedOperation = QueuedOperation.newBuilder().setAction(action).setCommand(command).setTree(getCompleteTree(action.getInputRootDigest())).build();
            ByteString queuedOperationBlob = queuedOperation.toByteString();
            Digest queuedOperationDigest = getDigestUtil().compute(queuedOperationBlob);
            // maybe do this elsewhere
            try {
                putBlob(this, queuedOperationDigest, queuedOperationBlob, 60, SECONDS, RequestMetadata.getDefaultInstance());
                QueueEntry queueEntry = QueueEntry.newBuilder().setExecuteEntry(ExecuteEntry.newBuilder().setOperationName(operationName).setActionDigest(metadata.getActionDigest()).setStdoutStreamName(metadata.getStdoutStreamName()).setStderrStreamName(metadata.getStderrStreamName()).setQueuedTimestamp(Timestamps.fromMillis(System.currentTimeMillis()))).setQueuedOperationDigest(queuedOperationDigest).setPlatform(command.getPlatform()).build();
                matched = true;
                if (listener.onEntry(queueEntry)) {
                    onDispatched(operation);
                } else {
                    enqueueOperation(operation);
                }
            } catch (StatusException | IOException e) {
                logger.log(Level.SEVERE, format("could not emplace queued operation: %s", operationName), e);
            }
        } else {
            rejectedOperations.add(operation);
        }
    }
    for (Operation operation : rejectedOperations.build()) {
        requeueOperation(operation);
    }
    if (!matched) {
        synchronized (queue.workers) {
            listener.setOnCancelHandler(() -> queuedOperations.removeWorker(listener));
            listener.onWaitStart();
            queuedOperations.AddWorker(provisions, listener);
        }
    }
}
Also used : WorkerQueue(build.buildfarm.instance.queues.WorkerQueue) Action(build.bazel.remote.execution.v2.Action) DequeueMatchSettings(build.buildfarm.worker.DequeueMatchSettings) Digest(build.bazel.remote.execution.v2.Digest) ImmutableList(com.google.common.collect.ImmutableList) ByteString(com.google.protobuf.ByteString) QueuedOperation(build.buildfarm.v1test.QueuedOperation) Operation(com.google.longrunning.Operation) ByteString(com.google.protobuf.ByteString) QueueEntry(build.buildfarm.v1test.QueueEntry) Command(build.bazel.remote.execution.v2.Command) QueuedOperation(build.buildfarm.v1test.QueuedOperation) ExecuteOperationMetadata(build.bazel.remote.execution.v2.ExecuteOperationMetadata)

Example 3 with WorkerQueue

use of build.buildfarm.instance.queues.WorkerQueue in project bazel-buildfarm by bazelbuild.

the class MemoryInstance method matchOperation.

@Override
protected boolean matchOperation(Operation operation) throws InterruptedException {
    ExecuteOperationMetadata metadata = expectExecuteOperationMetadata(operation);
    Preconditions.checkState(metadata != null, "metadata not found");
    Action action = getUnchecked(expect(metadata.getActionDigest(), Action.parser(), newDirectExecutorService(), RequestMetadata.getDefaultInstance()));
    Preconditions.checkState(action != null, "action not found");
    Command command = getUnchecked(expect(action.getCommandDigest(), Command.parser(), newDirectExecutorService(), RequestMetadata.getDefaultInstance()));
    Preconditions.checkState(command != null, "command not found");
    Tree tree = getCompleteTree(action.getInputRootDigest());
    QueuedOperation queuedOperation = QueuedOperation.newBuilder().setAction(action).setCommand(command).setTree(tree).build();
    ByteString queuedOperationBlob = queuedOperation.toByteString();
    Digest queuedOperationDigest = getDigestUtil().compute(queuedOperationBlob);
    String operationName = operation.getName();
    try {
        putBlob(this, queuedOperationDigest, queuedOperationBlob, 60, SECONDS, RequestMetadata.getDefaultInstance());
    } catch (StatusException | IOException e) {
        logger.log(Level.SEVERE, format("could not emplace queued operation: %s", operationName), e);
        return false;
    }
    ImmutableList.Builder<Worker> rejectedWorkers = new ImmutableList.Builder<>();
    boolean dispatched = false;
    WorkerQueue queue = queuedOperations.MatchEligibleQueue(createProvisions(command.getPlatform()));
    DequeueMatchSettings settings = new DequeueMatchSettings();
    synchronized (queue.workers) {
        while (!dispatched && !queue.workers.isEmpty()) {
            Worker worker = queue.workers.remove(0);
            if (!DequeueMatchEvaluator.shouldKeepOperation(settings, worker.getProvisions(), command)) {
                rejectedWorkers.add(worker);
            } else {
                QueueEntry queueEntry = QueueEntry.newBuilder().setExecuteEntry(ExecuteEntry.newBuilder().setOperationName(operationName).setActionDigest(metadata.getActionDigest()).setStdoutStreamName(metadata.getStdoutStreamName()).setStderrStreamName(metadata.getStderrStreamName()).setQueuedTimestamp(Timestamps.fromMillis(System.currentTimeMillis()))).setQueuedOperationDigest(queuedOperationDigest).setPlatform(command.getPlatform()).build();
                dispatched = worker.getListener().onEntry(queueEntry);
                if (dispatched) {
                    onDispatched(operation);
                }
            }
        }
        Iterables.addAll(queue.workers, rejectedWorkers.build());
    }
    return dispatched;
}
Also used : Action(build.bazel.remote.execution.v2.Action) WorkerQueue(build.buildfarm.instance.queues.WorkerQueue) DequeueMatchSettings(build.buildfarm.worker.DequeueMatchSettings) Digest(build.bazel.remote.execution.v2.Digest) ByteString(com.google.protobuf.ByteString) ImmutableList(com.google.common.collect.ImmutableList) MultimapBuilder(com.google.common.collect.MultimapBuilder) CacheBuilder(com.google.common.cache.CacheBuilder) NettyChannelBuilder(io.grpc.netty.NettyChannelBuilder) ByteString(com.google.protobuf.ByteString) IOException(java.io.IOException) QueueEntry(build.buildfarm.v1test.QueueEntry) StatusException(io.grpc.StatusException) Command(build.bazel.remote.execution.v2.Command) QueuedOperation(build.buildfarm.v1test.QueuedOperation) ExecuteOperationMetadata(build.bazel.remote.execution.v2.ExecuteOperationMetadata) Tree(build.buildfarm.v1test.Tree) Worker(build.buildfarm.instance.queues.Worker)

Aggregations

WorkerQueue (build.buildfarm.instance.queues.WorkerQueue)3 Action (build.bazel.remote.execution.v2.Action)2 Command (build.bazel.remote.execution.v2.Command)2 Digest (build.bazel.remote.execution.v2.Digest)2 ExecuteOperationMetadata (build.bazel.remote.execution.v2.ExecuteOperationMetadata)2 QueueEntry (build.buildfarm.v1test.QueueEntry)2 QueuedOperation (build.buildfarm.v1test.QueuedOperation)2 DequeueMatchSettings (build.buildfarm.worker.DequeueMatchSettings)2 ImmutableList (com.google.common.collect.ImmutableList)2 ByteString (com.google.protobuf.ByteString)2 Worker (build.buildfarm.instance.queues.Worker)1 BackplaneStatus (build.buildfarm.v1test.BackplaneStatus)1 OperationQueueStatus (build.buildfarm.v1test.OperationQueueStatus)1 Tree (build.buildfarm.v1test.Tree)1 CacheBuilder (com.google.common.cache.CacheBuilder)1 MultimapBuilder (com.google.common.collect.MultimapBuilder)1 Operation (com.google.longrunning.Operation)1 StatusException (io.grpc.StatusException)1 NettyChannelBuilder (io.grpc.netty.NettyChannelBuilder)1 IOException (java.io.IOException)1