Search in sources :

Example 1 with EXECUTING

use of build.bazel.remote.execution.v2.ExecutionStage.Value.EXECUTING in project bazel-buildfarm by bazelbuild.

the class Hist method printHistogram.

@SuppressWarnings("CatchMayIgnoreException")
private static void printHistogram(Instance instance) {
    int executing = 0;
    String pageToken = "";
    do {
        ImmutableList.Builder<Operation> operations = new ImmutableList.Builder<>();
        for (; ; ) {
            try {
                pageToken = instance.listOperations(1024, pageToken, "", operations);
            } catch (io.grpc.StatusRuntimeException e) {
                continue;
            }
            break;
        }
        for (Operation operation : operations.build()) {
            try {
                ExecuteOperationMetadata metadata = operation.getMetadata().unpack(ExecuteOperationMetadata.class);
                if (metadata.getStage().equals(ExecutionStage.Value.EXECUTING)) {
                    executing++;
                }
            } catch (InvalidProtocolBufferException e) {
            }
        }
    } while (!pageToken.equals(""));
    printHistogramValue(executing);
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) NettyChannelBuilder(io.grpc.netty.NettyChannelBuilder) ExecuteOperationMetadata(build.bazel.remote.execution.v2.ExecuteOperationMetadata) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) Operation(com.google.longrunning.Operation)

Example 2 with EXECUTING

use of build.bazel.remote.execution.v2.ExecutionStage.Value.EXECUTING in project bazel-buildfarm by bazelbuild.

the class ExecutionServiceTest method keepaliveIsCancelledWithContext.

@SuppressWarnings("unchecked")
@Test
public void keepaliveIsCancelledWithContext() throws Exception {
    ScheduledExecutorService keepaliveScheduler = newSingleThreadScheduledExecutor();
    ExecutionService service = new ExecutionService(instance, /* keepaliveAfter=*/
    1, // far enough in the future that we'll get scheduled and
    SECONDS, /* keepaliveUnit=*/
    keepaliveScheduler, new LogMetricsPublisher(// cancelled without executing
    MetricsConfig.getDefaultInstance()));
    ServerCallStreamObserver<Operation> response = mock(ServerCallStreamObserver.class);
    RequestMetadata requestMetadata = RequestMetadata.newBuilder().build();
    Operation operation = Operation.newBuilder().setName("immediately-cancelled-watch-operation").build();
    KeepaliveWatcher watcher = service.createWatcher(response, requestMetadata);
    watcher.observe(operation);
    ListenableFuture<?> future = watcher.getFuture();
    assertThat(future).isNotNull();
    ArgumentCaptor<Runnable> onCancelHandlerCaptor = ArgumentCaptor.forClass(Runnable.class);
    verify(response, times(1)).setOnCancelHandler(onCancelHandlerCaptor.capture());
    Runnable onCancelHandler = onCancelHandlerCaptor.getValue();
    onCancelHandler.run();
    assertThat(future.isCancelled()).isTrue();
    assertThat(shutdownAndAwaitTermination(keepaliveScheduler, 1, SECONDS)).isTrue();
    // should only get one call for the real operation
    verify(response, times(1)).onNext(operation);
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) KeepaliveWatcher(build.buildfarm.server.ExecutionService.KeepaliveWatcher) LogMetricsPublisher(build.buildfarm.metrics.log.LogMetricsPublisher) Operation(com.google.longrunning.Operation) RequestMetadata(build.bazel.remote.execution.v2.RequestMetadata) Test(org.junit.Test)

Example 3 with EXECUTING

use of build.bazel.remote.execution.v2.ExecutionStage.Value.EXECUTING in project bazel-buildfarm by bazelbuild.

the class Cat method printOperation.

private static void printOperation(Operation operation) {
    System.out.println("Operation: " + operation.getName());
    System.out.println("Done: " + (operation.getDone() ? "true" : "false"));
    System.out.println("Metadata:");
    try {
        ExecuteOperationMetadata metadata;
        RequestMetadata requestMetadata;
        if (operation.getMetadata().is(QueuedOperationMetadata.class)) {
            QueuedOperationMetadata queuedOperationMetadata = operation.getMetadata().unpack(QueuedOperationMetadata.class);
            metadata = queuedOperationMetadata.getExecuteOperationMetadata();
            requestMetadata = queuedOperationMetadata.getRequestMetadata();
        } else if (operation.getMetadata().is(ExecutingOperationMetadata.class)) {
            ExecutingOperationMetadata executingMetadata = operation.getMetadata().unpack(ExecutingOperationMetadata.class);
            System.out.println("  Started At: " + new Date(executingMetadata.getStartedAt()));
            System.out.println("  Executing On: " + executingMetadata.getExecutingOn());
            metadata = executingMetadata.getExecuteOperationMetadata();
            requestMetadata = executingMetadata.getRequestMetadata();
        } else if (operation.getMetadata().is(CompletedOperationMetadata.class)) {
            CompletedOperationMetadata completedMetadata = operation.getMetadata().unpack(CompletedOperationMetadata.class);
            metadata = completedMetadata.getExecuteOperationMetadata();
            requestMetadata = completedMetadata.getRequestMetadata();
        } else {
            metadata = operation.getMetadata().unpack(ExecuteOperationMetadata.class);
            requestMetadata = null;
        }
        System.out.println("  Stage: " + metadata.getStage());
        System.out.println("  Action: " + DigestUtil.toString(metadata.getActionDigest()));
        System.out.println("  Stdout Stream: " + metadata.getStdoutStreamName());
        System.out.println("  Stderr Stream: " + metadata.getStderrStreamName());
        if (requestMetadata != null) {
            printRequestMetadata(requestMetadata);
        }
    } catch (InvalidProtocolBufferException e) {
        System.out.println("  UNKNOWN TYPE: " + e.getMessage());
    }
    if (operation.getDone()) {
        switch(operation.getResultCase()) {
            case RESPONSE:
                System.out.println("Response:");
                try {
                    printExecuteResponse(operation.getResponse().unpack(ExecuteResponse.class));
                } catch (InvalidProtocolBufferException e) {
                    System.out.println("  UNKNOWN RESPONSE TYPE: " + operation.getResponse());
                }
                break;
            case ERROR:
                System.out.println("Error: " + Code.forNumber(operation.getError().getCode()));
                break;
            default:
                System.out.println("  UNKNOWN RESULT!");
                break;
        }
    }
}
Also used : ExecutingOperationMetadata(build.buildfarm.v1test.ExecutingOperationMetadata) ExecuteOperationMetadata(build.bazel.remote.execution.v2.ExecuteOperationMetadata) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ExecuteResponse(build.bazel.remote.execution.v2.ExecuteResponse) QueuedOperationMetadata(build.buildfarm.v1test.QueuedOperationMetadata) CompletedOperationMetadata(build.buildfarm.v1test.CompletedOperationMetadata) Date(java.util.Date) RequestMetadata(build.bazel.remote.execution.v2.RequestMetadata)

Example 4 with EXECUTING

use of build.bazel.remote.execution.v2.ExecutionStage.Value.EXECUTING in project bazel-buildfarm by bazelbuild.

the class AbstractServerInstance method pollOperation.

@Override
public boolean pollOperation(String operationName, ExecutionStage.Value stage) {
    if (stage != ExecutionStage.Value.QUEUED && stage != ExecutionStage.Value.EXECUTING) {
        return false;
    }
    Operation operation = getOperation(operationName);
    if (operation == null) {
        return false;
    }
    if (isCancelled(operation)) {
        return false;
    }
    ExecuteOperationMetadata metadata = expectExecuteOperationMetadata(operation);
    if (metadata == null) {
        return false;
    }
    // stage limitation to {QUEUED, EXECUTING} above is required
    return metadata.getStage() == stage;
}
Also used : ExecuteOperationMetadata(build.bazel.remote.execution.v2.ExecuteOperationMetadata) QueuedOperation(build.buildfarm.v1test.QueuedOperation) EnrichedOperation(build.buildfarm.operations.EnrichedOperation) Operation(com.google.longrunning.Operation)

Example 5 with EXECUTING

use of build.bazel.remote.execution.v2.ExecutionStage.Value.EXECUTING in project bazel-buildfarm by bazelbuild.

the class MemoryInstance method putOperation.

@Override
public boolean putOperation(Operation operation) throws InterruptedException {
    String operationName = operation.getName();
    if (isQueued(operation)) {
        // destroy any monitors for this queued operation
        // any race should be resolved in a failure to requeue
        Watchdog requeuer = requeuers.remove(operationName);
        if (requeuer != null) {
            requeuer.stop();
        }
        Watchdog operationTimeoutDelay = operationTimeoutDelays.remove(operationName);
        if (operationTimeoutDelay != null) {
            operationTimeoutDelay.stop();
        }
    }
    if (!super.putOperation(operation)) {
        return false;
    }
    if (operation.getDone()) {
        // destroy requeue timer
        Watchdog requeuer = requeuers.remove(operationName);
        if (requeuer != null) {
            requeuer.stop();
        }
        // destroy action timed out failure
        Watchdog operationTimeoutDelay = operationTimeoutDelays.remove(operationName);
        if (operationTimeoutDelay != null) {
            operationTimeoutDelay.stop();
        }
        String operationStatus = "terminated";
        if (isCancelled(operation)) {
            operationStatus = "cancelled";
        } else if (isComplete(operation)) {
            operationStatus = "completed";
        }
        logger.log(Level.INFO, format("Operation %s was %s", operationName, operationStatus));
    } else if (isExecuting(operation)) {
        Watchdog requeuer = requeuers.get(operationName);
        if (requeuer == null) {
            // restore a requeuer if a worker indicates they are executing
            onDispatched(operation);
        } else {
            requeuer.pet();
        }
        // Create a delayed fuse timed out failure
        // This is in effect if the worker does not respond
        // within a configured delay with operation action timeout results
        com.google.rpc.Status.Builder status = com.google.rpc.Status.newBuilder();
        Action action = getActionForTimeoutMonitor(operation, status);
        if (action == null) {
            // prevent further activity of this operation, since it can not
            // transition to execution without independent provision of action blob
            // or reconfiguration of operation metadata
            // force an immediate error completion of the operation
            errorOperation(operation, RequestMetadata.getDefaultInstance(), status.build());
            return false;
        }
        Duration actionTimeout = null;
        if (action.hasTimeout()) {
            actionTimeout = action.getTimeout();
        } else if (config.hasDefaultActionTimeout()) {
            actionTimeout = config.getDefaultActionTimeout();
        }
        if (actionTimeout != null) {
            Duration delay = config.getOperationCompletedDelay();
            Duration timeout = Duration.newBuilder().setSeconds(actionTimeout.getSeconds() + delay.getSeconds()).setNanos(actionTimeout.getNanos() + delay.getNanos()).build();
            // this is an overuse of Watchdog, we will never pet it
            Watchdog operationTimeoutDelay = new Watchdog(timeout, () -> {
                operationTimeoutDelays.remove(operationName);
                try {
                    expireOperation(operation);
                } catch (InterruptedException e) {
                    Thread.currentThread().interrupt();
                }
            });
            operationTimeoutDelays.put(operationName, operationTimeoutDelay);
            new Thread(operationTimeoutDelay).start();
        }
    }
    return true;
}
Also used : Action(build.bazel.remote.execution.v2.Action) Watchdog(build.buildfarm.common.Watchdog) MultimapBuilder(com.google.common.collect.MultimapBuilder) CacheBuilder(com.google.common.cache.CacheBuilder) NettyChannelBuilder(io.grpc.netty.NettyChannelBuilder) Duration(com.google.protobuf.Duration) ByteString(com.google.protobuf.ByteString)

Aggregations

ExecuteOperationMetadata (build.bazel.remote.execution.v2.ExecuteOperationMetadata)5 Operation (com.google.longrunning.Operation)5 ByteString (com.google.protobuf.ByteString)3 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)3 RequestMetadata (build.bazel.remote.execution.v2.RequestMetadata)2 ExecutionPolicy (build.buildfarm.v1test.ExecutionPolicy)2 ImmutableList (com.google.common.collect.ImmutableList)2 Duration (com.google.protobuf.Duration)2 NettyChannelBuilder (io.grpc.netty.NettyChannelBuilder)2 IOException (java.io.IOException)2 Test (org.junit.Test)2 Action (build.bazel.remote.execution.v2.Action)1 ActionResult (build.bazel.remote.execution.v2.ActionResult)1 Command (build.bazel.remote.execution.v2.Command)1 EnvironmentVariable (build.bazel.remote.execution.v2.Command.EnvironmentVariable)1 ExecuteResponse (build.bazel.remote.execution.v2.ExecuteResponse)1 Watchdog (build.buildfarm.common.Watchdog)1 LogMetricsPublisher (build.buildfarm.metrics.log.LogMetricsPublisher)1 EnrichedOperation (build.buildfarm.operations.EnrichedOperation)1 KeepaliveWatcher (build.buildfarm.server.ExecutionService.KeepaliveWatcher)1