Search in sources :

Example 1 with COMPLETED

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));
            }
        }
    }
}
Also used : Path(java.nio.file.Path) Digest(build.bazel.remote.execution.v2.Digest) Command(build.bazel.remote.execution.v2.Command) ExecutedActionMetadata(build.bazel.remote.execution.v2.ExecutedActionMetadata) QueuedOperation(build.buildfarm.v1test.QueuedOperation) IOException(java.io.IOException) Directory(build.bazel.remote.execution.v2.Directory)

Example 2 with COMPLETED

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);
}
Also used : PreconditionFailure(com.google.rpc.PreconditionFailure) ExecuteOperationMetadata(build.bazel.remote.execution.v2.ExecuteOperationMetadata) Watcher(build.buildfarm.common.Watcher) ExecuteResponse(build.bazel.remote.execution.v2.ExecuteResponse) Operation(com.google.longrunning.Operation) CompletedOperationMetadata(build.buildfarm.v1test.CompletedOperationMetadata) Test(org.junit.Test)

Example 3 with COMPLETED

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);
}
Also used : Action(build.bazel.remote.execution.v2.Action) PreconditionFailure(com.google.rpc.PreconditionFailure) Digest(build.bazel.remote.execution.v2.Digest) ExecuteResponse(build.bazel.remote.execution.v2.ExecuteResponse) ByteString(com.google.protobuf.ByteString) QueuedOperation(build.buildfarm.v1test.QueuedOperation) Operation(com.google.longrunning.Operation) QueueEntry(build.buildfarm.v1test.QueueEntry) Test(org.junit.Test)

Example 4 with COMPLETED

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();
}
Also used : Digest(build.bazel.remote.execution.v2.Digest) ExecuteEntry(build.buildfarm.v1test.ExecuteEntry) Watcher(build.buildfarm.common.Watcher) ActionKey(build.buildfarm.common.DigestUtil.ActionKey) ExecuteResponse(build.bazel.remote.execution.v2.ExecuteResponse) ByteString(com.google.protobuf.ByteString) QueuedOperation(build.buildfarm.v1test.QueuedOperation) Operation(com.google.longrunning.Operation) QueueEntry(build.buildfarm.v1test.QueueEntry) RequestMetadata(build.bazel.remote.execution.v2.RequestMetadata) ActionResult(build.bazel.remote.execution.v2.ActionResult) Poller(build.buildfarm.common.Poller) Test(org.junit.Test)

Example 5 with COMPLETED

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);
}
Also used : Violation(com.google.rpc.PreconditionFailure.Violation) PreconditionFailure(com.google.rpc.PreconditionFailure) OperationsGrpc(com.google.longrunning.OperationsGrpc) ByteStreamGrpc(com.google.bytestream.ByteStreamGrpc) OperationQueueGrpc(build.buildfarm.v1test.OperationQueueGrpc) ExecutionGrpc(build.bazel.remote.execution.v2.ExecutionGrpc) ActionCacheGrpc(build.bazel.remote.execution.v2.ActionCacheGrpc) ContentAddressableStorageGrpc(build.bazel.remote.execution.v2.ContentAddressableStorageGrpc) Digest(build.bazel.remote.execution.v2.Digest) ExecuteOperationMetadata(build.bazel.remote.execution.v2.ExecuteOperationMetadata) ExecuteResponse(build.bazel.remote.execution.v2.ExecuteResponse) Operation(com.google.longrunning.Operation) Test(org.junit.Test)

Aggregations

Operation (com.google.longrunning.Operation)6 ExecuteResponse (build.bazel.remote.execution.v2.ExecuteResponse)5 ByteString (com.google.protobuf.ByteString)5 Test (org.junit.Test)5 ActionResult (build.bazel.remote.execution.v2.ActionResult)4 Digest (build.bazel.remote.execution.v2.Digest)4 ExecuteOperationMetadata (build.bazel.remote.execution.v2.ExecuteOperationMetadata)4 QueuedOperation (build.buildfarm.v1test.QueuedOperation)4 CompletedOperationMetadata (build.buildfarm.v1test.CompletedOperationMetadata)3 PreconditionFailure (com.google.rpc.PreconditionFailure)3 IOException (java.io.IOException)3 Action (build.bazel.remote.execution.v2.Action)2 Command (build.bazel.remote.execution.v2.Command)2 ExecutedActionMetadata (build.bazel.remote.execution.v2.ExecutedActionMetadata)2 ActionKey (build.buildfarm.common.DigestUtil.ActionKey)2 Poller (build.buildfarm.common.Poller)2 Watcher (build.buildfarm.common.Watcher)2 ExecuteEntry (build.buildfarm.v1test.ExecuteEntry)2 QueueEntry (build.buildfarm.v1test.QueueEntry)2 Path (java.nio.file.Path)2