use of build.buildfarm.v1test.CompletedOperationMetadata in project bazel-buildfarm by bazelbuild.
the class AbstractServerInstance method expectRequestMetadata.
protected static RequestMetadata expectRequestMetadata(Operation operation) {
String name = operation.getName();
Any metadata = operation.getMetadata();
QueuedOperationMetadata queuedOperationMetadata = maybeQueuedOperationMetadata(name, metadata);
if (queuedOperationMetadata != null) {
return queuedOperationMetadata.getRequestMetadata();
}
ExecutingOperationMetadata executingOperationMetadata = maybeExecutingOperationMetadata(name, metadata);
if (executingOperationMetadata != null) {
return executingOperationMetadata.getRequestMetadata();
}
CompletedOperationMetadata completedOperationMetadata = maybeCompletedOperationMetadata(name, metadata);
if (completedOperationMetadata != null) {
return completedOperationMetadata.getRequestMetadata();
}
return RequestMetadata.getDefaultInstance();
}
use of build.buildfarm.v1test.CompletedOperationMetadata in project bazel-buildfarm by bazelbuild.
the class MemoryInstanceTest method requeueFailureNotifiesWatchers.
@Test
public void requeueFailureNotifiesWatchers() throws Exception {
ExecuteOperationMetadata metadata = ExecuteOperationMetadata.newBuilder().setActionDigest(simpleActionDigest).setStage(QUEUED).build();
Operation queuedOperation = createOperation("missing-action-operation", metadata);
outstandingOperations.put(queuedOperation.getName(), queuedOperation);
Watcher watcher = mock(Watcher.class);
ListenableFuture<Void> watchFuture = instance.watchOperation(queuedOperation.getName(), watcher);
assertThat(instance.requeueOperation(queuedOperation)).isFalse();
watchFuture.get();
ArgumentCaptor<Operation> operationCaptor = ArgumentCaptor.forClass(Operation.class);
verify(watcher, atLeastOnce()).observe(operationCaptor.capture());
List<Operation> operations = operationCaptor.getAllValues();
Operation erroredOperation = operations.get(operations.size() - 1);
assertThat(erroredOperation.getDone()).isTrue();
CompletedOperationMetadata completedMetadata = erroredOperation.getMetadata().unpack(CompletedOperationMetadata.class);
assertThat(completedMetadata.getExecuteOperationMetadata().getStage()).isEqualTo(COMPLETED);
PreconditionFailure preconditionFailure = PreconditionFailure.newBuilder().addViolations(Violation.newBuilder().setType(VIOLATION_TYPE_MISSING).setSubject("blobs/" + DigestUtil.toString(simpleActionDigest)).setDescription(MISSING_ACTION)).build();
ExecuteResponse executeResponse = ExecuteResponse.newBuilder().setStatus(Status.newBuilder().setCode(Code.FAILED_PRECONDITION.getNumber()).setMessage(invalidActionVerboseMessage(simpleActionDigest, preconditionFailure)).addDetails(Any.pack(preconditionFailure))).build();
assertThat(erroredOperation.getResponse().unpack(ExecuteResponse.class)).isEqualTo(executeResponse);
}
use of build.buildfarm.v1test.CompletedOperationMetadata in project bazel-buildfarm by bazelbuild.
the class ShardInstanceTest method assertResponse.
void assertResponse(ExecuteResponse executeResponse) throws Exception {
ArgumentCaptor<Operation> operationCaptor = ArgumentCaptor.forClass(Operation.class);
verify(mockBackplane, times(1)).putOperation(operationCaptor.capture(), eq(COMPLETED));
Operation erroredOperation = operationCaptor.getValue();
assertThat(erroredOperation.getDone()).isTrue();
CompletedOperationMetadata completedMetadata = erroredOperation.getMetadata().unpack(CompletedOperationMetadata.class);
assertThat(completedMetadata.getExecuteOperationMetadata().getStage()).isEqualTo(COMPLETED);
assertThat(erroredOperation.getResponse().unpack(ExecuteResponse.class)).isEqualTo(executeResponse);
}
use of build.buildfarm.v1test.CompletedOperationMetadata 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.buildfarm.v1test.CompletedOperationMetadata in project bazel-buildfarm by bazelbuild.
the class AbstractServerInstance method errorOperation.
protected void errorOperation(Operation operation, RequestMetadata requestMetadata, com.google.rpc.Status status) throws InterruptedException {
if (operation.getDone()) {
throw new IllegalStateException("Trying to error already completed operation [" + name + "]");
}
ExecuteOperationMetadata metadata = expectExecuteOperationMetadata(operation);
if (metadata == null) {
metadata = ExecuteOperationMetadata.getDefaultInstance();
}
CompletedOperationMetadata completedMetadata = CompletedOperationMetadata.newBuilder().setExecuteOperationMetadata(metadata.toBuilder().setStage(ExecutionStage.Value.COMPLETED).build()).setRequestMetadata(requestMetadata).build();
putOperation(operation.toBuilder().setDone(true).setMetadata(Any.pack(completedMetadata)).setResponse(Any.pack(ExecuteResponse.newBuilder().setStatus(status).build())).build());
}
Aggregations