use of build.bazel.remote.execution.v2.ExecutionStage.Value.COMPLETED in project bazel-buildfarm by bazelbuild.
the class InputFetcher method fetchPolled.
private long fetchPolled(Stopwatch stopwatch) throws InterruptedException {
String operationName = operationContext.queueEntry.getExecuteEntry().getOperationName();
logger.log(Level.FINE, format("fetching inputs: %s", operationName));
ExecutedActionMetadata.Builder executedAction = operationContext.executeResponse.getResultBuilder().getExecutionMetadataBuilder().setInputFetchStartTimestamp(Timestamps.fromMillis(System.currentTimeMillis()));
final Map<Digest, Directory> directoriesIndex;
QueuedOperation queuedOperation;
Path execDir;
try {
queuedOperation = workerContext.getQueuedOperation(operationContext.queueEntry);
if (queuedOperation == null || !isQueuedOperationValid(queuedOperation)) {
if (queuedOperation != null) {
logger.log(Level.SEVERE, format("invalid queued operation: %s", operationName));
}
owner.error().put(operationContext);
return 0;
}
if (queuedOperation.hasTree()) {
directoriesIndex = DigestUtil.proxyDirectoriesIndex(queuedOperation.getTree().getDirectoriesMap());
} else {
// TODO remove legacy interpretation and field after transition
directoriesIndex = workerContext.getDigestUtil().createDirectoriesIndex(queuedOperation.getLegacyTree());
}
execDir = workerContext.createExecDir(operationName, directoriesIndex, queuedOperation.getAction(), queuedOperation.getCommand());
} catch (IOException e) {
logger.log(Level.SEVERE, format("error creating exec dir for %s", operationName), e);
owner.error().put(operationContext);
return 0;
}
success = true;
/* tweak command executable used */
String programName = queuedOperation.getCommand().getArguments(0);
Directory root = directoriesIndex.get(queuedOperation.getTree().getRootDigest());
Command command = queuedOperation.getCommand().toBuilder().clearArguments().addArguments(getExecutablePath(programName, root, directoriesIndex)).addAllArguments(Iterables.skip(queuedOperation.getCommand().getArgumentsList(), 1)).build();
executedAction.setInputFetchCompletedTimestamp(Timestamps.fromMillis(System.currentTimeMillis()));
// we are now responsible for destroying the exec dir if anything goes wrong
boolean completed = false;
try {
long fetchUSecs = stopwatch.elapsed(MICROSECONDS);
proceedToOutput(queuedOperation.getAction(), command, execDir);
completed = true;
return stopwatch.elapsed(MICROSECONDS) - fetchUSecs;
} finally {
if (!completed) {
try {
workerContext.destroyExecDir(execDir);
} catch (IOException e) {
logger.log(Level.SEVERE, format("error deleting exec dir for %s after interrupt", operationName));
}
}
}
}
use of build.bazel.remote.execution.v2.ExecutionStage.Value.COMPLETED 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.bazel.remote.execution.v2.ExecutionStage.Value.COMPLETED in project bazel-buildfarm by bazelbuild.
the class ShardInstanceTest method requeueFailsOnMissingDirectory.
@Test
public void requeueFailsOnMissingDirectory() throws Exception {
String operationName = "missing-directory-operation";
Digest missingDirectoryDigest = Digest.newBuilder().setHash("missing-directory").setSizeBytes(1).build();
when(mockBackplane.propertiesEligibleForQueue(Matchers.anyList())).thenReturn(true);
when(mockBackplane.getOperation(eq(operationName))).thenReturn(Operation.newBuilder().setName(operationName).setMetadata(Any.pack(ExecuteOperationMetadata.newBuilder().setStage(QUEUED).build())).build());
Action action = createAction(true, true, missingDirectoryDigest, SIMPLE_COMMAND);
Digest actionDigest = DIGEST_UTIL.compute(action);
QueueEntry queueEntry = QueueEntry.newBuilder().setExecuteEntry(ExecuteEntry.newBuilder().setOperationName(operationName).setSkipCacheLookup(true).setActionDigest(actionDigest)).build();
instance.requeueOperation(queueEntry, Durations.fromSeconds(60)).get();
ArgumentCaptor<Operation> operationCaptor = ArgumentCaptor.forClass(Operation.class);
verify(mockBackplane, times(1)).putOperation(operationCaptor.capture(), eq(COMPLETED));
Operation operation = operationCaptor.getValue();
assertThat(operation.getResponse().is(ExecuteResponse.class)).isTrue();
ExecuteResponse executeResponse = operation.getResponse().unpack(ExecuteResponse.class);
com.google.rpc.Status status = executeResponse.getStatus();
PreconditionFailure preconditionFailure = PreconditionFailure.newBuilder().addViolations(Violation.newBuilder().setType(VIOLATION_TYPE_MISSING).setSubject("blobs/" + DigestUtil.toString(missingDirectoryDigest)).setDescription("The directory `/` was not found in the CAS.")).build();
com.google.rpc.Status expectedStatus = com.google.rpc.Status.newBuilder().setCode(Code.FAILED_PRECONDITION.getNumber()).setMessage(invalidActionVerboseMessage(actionDigest, preconditionFailure)).addDetails(Any.pack(preconditionFailure)).build();
assertThat(status).isEqualTo(expectedStatus);
}
use of build.bazel.remote.execution.v2.ExecutionStage.Value.COMPLETED in project bazel-buildfarm by bazelbuild.
the class ShardInstanceTest method duplicateExecutionsServedFromCacheAreForcedToSkipLookup.
@Test
public void duplicateExecutionsServedFromCacheAreForcedToSkipLookup() throws Exception {
ActionKey actionKey = DigestUtil.asActionKey(Digest.newBuilder().setHash("test").build());
ActionResult actionResult = ActionResult.newBuilder().addOutputFiles(OutputFile.newBuilder().setPath("does-not-exist").setDigest(Digest.newBuilder().setHash("dne").setSizeBytes(1))).setStdoutDigest(Digest.newBuilder().setHash("stdout").setSizeBytes(1)).setStderrDigest(Digest.newBuilder().setHash("stderr").setSizeBytes(1)).build();
when(mockBackplane.canQueue()).thenReturn(true);
when(mockBackplane.canPrequeue()).thenReturn(true);
when(mockBackplane.getActionResult(actionKey)).thenReturn(actionResult);
Digest actionDigest = actionKey.getDigest();
RequestMetadata requestMetadata = RequestMetadata.newBuilder().setToolDetails(ToolDetails.newBuilder().setToolName("buildfarm-test").setToolVersion("0.1")).setCorrelatedInvocationsId(UUID.randomUUID().toString()).setToolInvocationId(UUID.randomUUID().toString()).setActionId(actionDigest.getHash()).build();
String operationName = "cache-served-operation";
ExecuteEntry cacheServedExecuteEntry = ExecuteEntry.newBuilder().setOperationName(operationName).setActionDigest(actionDigest).setRequestMetadata(requestMetadata).build();
Poller poller = mock(Poller.class);
instance.queue(cacheServedExecuteEntry, poller, DEFAULT_TIMEOUT).get(QUEUE_TEST_TIMEOUT_SECONDS, SECONDS);
verify(poller, times(1)).pause();
verify(mockBackplane, never()).queue(any(QueueEntry.class), any(Operation.class));
ArgumentCaptor<Operation> cacheCheckOperationCaptor = ArgumentCaptor.forClass(Operation.class);
verify(mockBackplane, times(1)).putOperation(cacheCheckOperationCaptor.capture(), eq(CACHE_CHECK));
Operation cacheCheckOperation = cacheCheckOperationCaptor.getValue();
assertThat(cacheCheckOperation.getName()).isEqualTo(operationName);
ArgumentCaptor<Operation> completedOperationCaptor = ArgumentCaptor.forClass(Operation.class);
verify(mockBackplane, times(1)).putOperation(completedOperationCaptor.capture(), eq(COMPLETED));
Operation completedOperation = completedOperationCaptor.getValue();
assertThat(completedOperation.getName()).isEqualTo(operationName);
ExecuteResponse executeResponse = completedOperation.getResponse().unpack(ExecuteResponse.class);
assertThat(executeResponse.getResult()).isEqualTo(actionResult);
assertThat(executeResponse.getCachedResult()).isTrue();
Watcher mockWatcher = mock(Watcher.class);
instance.execute(actionDigest, /* skipCacheLookup=*/
false, ExecutionPolicy.getDefaultInstance(), ResultsCachePolicy.getDefaultInstance(), requestMetadata, /* watcher=*/
mockWatcher);
verify(mockWatcher, times(1)).observe(any(Operation.class));
ArgumentCaptor<ExecuteEntry> executeEntryCaptor = ArgumentCaptor.forClass(ExecuteEntry.class);
verify(mockBackplane, times(1)).prequeue(executeEntryCaptor.capture(), any(Operation.class));
ExecuteEntry executeEntry = executeEntryCaptor.getValue();
assertThat(executeEntry.getSkipCacheLookup()).isTrue();
}
use of build.bazel.remote.execution.v2.ExecutionStage.Value.COMPLETED in project bazel-buildfarm by bazelbuild.
the class BuildFarmServerTest method actionWithExcessiveTimeoutFailsValidation.
@Test
public void actionWithExcessiveTimeoutFailsValidation() throws IOException, InterruptedException {
Digest actionDigestWithExcessiveTimeout = createAction(Action.newBuilder().setTimeout(Duration.newBuilder().setSeconds(9000)));
Operation failedOperation = executeAction(actionDigestWithExcessiveTimeout);
assertThat(failedOperation.getDone()).isTrue();
assertThat(failedOperation.getMetadata().unpack(ExecuteOperationMetadata.class).getStage()).isEqualTo(COMPLETED);
ExecuteResponse executeResponse = failedOperation.getResponse().unpack(ExecuteResponse.class);
com.google.rpc.Status status = executeResponse.getStatus();
assertThat(status.getCode()).isEqualTo(Code.FAILED_PRECONDITION.getNumber());
assertThat(status.getDetailsCount()).isEqualTo(1);
PreconditionFailure preconditionFailure = status.getDetailsList().get(0).unpack(PreconditionFailure.class);
assertThat(preconditionFailure.getViolationsCount()).isEqualTo(1);
Violation violation = preconditionFailure.getViolationsList().get(0);
assertThat(violation.getType()).isEqualTo(VIOLATION_TYPE_INVALID);
}
Aggregations