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);
}
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);
}
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;
}
}
}
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;
}
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;
}
Aggregations