Search in sources :

Example 11 with PreconditionFailure

use of com.google.rpc.PreconditionFailure 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)

Example 12 with PreconditionFailure

use of com.google.rpc.PreconditionFailure in project bazel-buildfarm by bazelbuild.

the class AbstractServerInstanceTest method undeclaredWorkingDirectoryIsInvalid.

@Test
public void undeclaredWorkingDirectoryIsInvalid() {
    AbstractServerInstance instance = new DummyServerInstance();
    Digest inputRootDigest = DIGEST_UTIL.compute(Directory.getDefaultInstance());
    PreconditionFailure.Builder preconditionFailureBuilder = PreconditionFailure.newBuilder();
    instance.validateCommand(Command.newBuilder().addArguments("foo").setWorkingDirectory("not/an/input").build(), inputRootDigest, ImmutableSet.of(), ImmutableSet.of(), ImmutableMap.of(inputRootDigest, Directory.getDefaultInstance()), preconditionFailureBuilder);
    PreconditionFailure preconditionFailure = preconditionFailureBuilder.build();
    assertThat(preconditionFailure.getViolationsCount()).isEqualTo(1);
    Violation violation = preconditionFailure.getViolationsList().get(0);
    assertThat(violation.getType()).isEqualTo(VIOLATION_TYPE_INVALID);
    assertThat(violation.getSubject()).isEqualTo(INVALID_COMMAND);
    assertThat(violation.getDescription()).isEqualTo("working directory is not an input directory");
}
Also used : Violation(com.google.rpc.PreconditionFailure.Violation) PreconditionFailure(com.google.rpc.PreconditionFailure) Digest(build.bazel.remote.execution.v2.Digest) Test(org.junit.Test)

Example 13 with PreconditionFailure

use of com.google.rpc.PreconditionFailure in project bazel-buildfarm by bazelbuild.

the class AbstractServerInstanceTest method duplicateFileInputIsInvalid.

@Test
public void duplicateFileInputIsInvalid() {
    PreconditionFailure.Builder preconditionFailure = PreconditionFailure.newBuilder();
    AbstractServerInstance.validateActionInputDirectory(ACTION_INPUT_ROOT_DIRECTORY_PATH, Directory.newBuilder().addAllFiles(ImmutableList.of(FileNode.newBuilder().setName("foo").build(), FileNode.newBuilder().setName("foo").build())).build(), /* pathDigests=*/
    new Stack<>(), /* visited=*/
    Sets.newHashSet(), /* directoriesIndex=*/
    Maps.newHashMap(), /* onInputFile=*/
    file -> {
    }, /* onInputDirectorie=*/
    directory -> {
    }, /* onInputDigest=*/
    digest -> {
    }, preconditionFailure);
    assertThat(preconditionFailure.getViolationsCount()).isEqualTo(1);
    Violation violation = preconditionFailure.getViolationsList().get(0);
    assertThat(violation.getType()).isEqualTo(VIOLATION_TYPE_INVALID);
    assertThat(violation.getSubject()).isEqualTo("/: foo");
    assertThat(violation.getDescription()).isEqualTo(DUPLICATE_DIRENT);
}
Also used : Violation(com.google.rpc.PreconditionFailure.Violation) PreconditionFailure(com.google.rpc.PreconditionFailure) Test(org.junit.Test)

Example 14 with PreconditionFailure

use of com.google.rpc.PreconditionFailure in project bazel-buildfarm by bazelbuild.

the class AbstractServerInstanceTest method unsortedDirectoryInputIsInvalid.

@Test
public void unsortedDirectoryInputIsInvalid() {
    Directory emptyDirectory = Directory.getDefaultInstance();
    Digest emptyDirectoryDigest = DIGEST_UTIL.compute(emptyDirectory);
    PreconditionFailure.Builder preconditionFailure = PreconditionFailure.newBuilder();
    AbstractServerInstance.validateActionInputDirectory(ACTION_INPUT_ROOT_DIRECTORY_PATH, Directory.newBuilder().addAllDirectories(ImmutableList.of(DirectoryNode.newBuilder().setName("foo").setDigest(emptyDirectoryDigest).build(), DirectoryNode.newBuilder().setName("bar").setDigest(emptyDirectoryDigest).build())).build(), /* pathDigests=*/
    new Stack<>(), /* visited=*/
    Sets.newHashSet(), /* directoriesIndex=*/
    ImmutableMap.of(emptyDirectoryDigest, emptyDirectory), /* onInputFiles=*/
    file -> {
    }, /* onInputDirectories=*/
    directory -> {
    }, /* onInputDigests=*/
    digest -> {
    }, preconditionFailure);
    assertThat(preconditionFailure.getViolationsCount()).isEqualTo(1);
    Violation violation = preconditionFailure.getViolationsList().get(0);
    assertThat(violation.getType()).isEqualTo(VIOLATION_TYPE_INVALID);
    assertThat(violation.getSubject()).isEqualTo("/: foo > bar");
    assertThat(violation.getDescription()).isEqualTo(DIRECTORY_NOT_SORTED);
}
Also used : Violation(com.google.rpc.PreconditionFailure.Violation) PreconditionFailure(com.google.rpc.PreconditionFailure) Digest(build.bazel.remote.execution.v2.Digest) OutputDirectory(build.bazel.remote.execution.v2.OutputDirectory) Directory(build.bazel.remote.execution.v2.Directory) Test(org.junit.Test)

Example 15 with PreconditionFailure

use of com.google.rpc.PreconditionFailure in project bazel-buildfarm by bazelbuild.

the class MemoryInstance method getActionForTimeoutMonitor.

@SuppressWarnings({ "ProtoBuilderReturnValueIgnored", "ReturnValueIgnored" })
private Action getActionForTimeoutMonitor(Operation operation, com.google.rpc.Status.Builder status) throws InterruptedException {
    Digest actionDigest = expectActionDigest(operation);
    if (actionDigest == null) {
        logger.log(Level.WARNING, format("Could not determine Action Digest for operation %s", operation.getName()));
        String message = String.format("Could not determine Action Digest from Operation %s", operation.getName());
        status.setCode(com.google.rpc.Code.INTERNAL.getNumber()).setMessage(message);
        return null;
    }
    ByteString actionBlob = getBlob(actionDigest);
    if (actionBlob == null) {
        logger.log(Level.WARNING, format("Action %s for operation %s went missing, cannot initiate execution monitoring", DigestUtil.toString(actionDigest), operation.getName()));
        PreconditionFailure.Builder preconditionFailureBuilder = PreconditionFailure.newBuilder();
        preconditionFailureBuilder.addViolationsBuilder().setType(VIOLATION_TYPE_MISSING).setSubject("blobs/" + DigestUtil.toString(actionDigest)).setDescription(MISSING_ACTION);
        PreconditionFailure preconditionFailure = preconditionFailureBuilder.build();
        status.setCode(com.google.rpc.Code.FAILED_PRECONDITION.getNumber()).setMessage(invalidActionVerboseMessage(actionDigest, preconditionFailure)).addDetails(Any.pack(preconditionFailure)).build();
        return null;
    }
    try {
        return Action.parseFrom(actionBlob);
    } catch (InvalidProtocolBufferException e) {
        logger.log(Level.WARNING, format("Could not parse Action %s for Operation %s", DigestUtil.toString(actionDigest), operation.getName()), e);
        PreconditionFailure.Builder preconditionFailureBuilder = PreconditionFailure.newBuilder();
        preconditionFailureBuilder.addViolationsBuilder().setType(VIOLATION_TYPE_INVALID).setSubject(INVALID_ACTION).setDescription("Action " + DigestUtil.toString(actionDigest));
        PreconditionFailure preconditionFailure = preconditionFailureBuilder.build();
        status.setCode(com.google.rpc.Code.FAILED_PRECONDITION.getNumber()).setMessage(invalidActionVerboseMessage(actionDigest, preconditionFailure)).addDetails(Any.pack(preconditionFailure)).build();
        return null;
    }
}
Also used : PreconditionFailure(com.google.rpc.PreconditionFailure) Digest(build.bazel.remote.execution.v2.Digest) ByteString(com.google.protobuf.ByteString) MultimapBuilder(com.google.common.collect.MultimapBuilder) CacheBuilder(com.google.common.cache.CacheBuilder) NettyChannelBuilder(io.grpc.netty.NettyChannelBuilder) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ByteString(com.google.protobuf.ByteString)

Aggregations

PreconditionFailure (com.google.rpc.PreconditionFailure)26 Test (org.junit.Test)18 Digest (build.bazel.remote.execution.v2.Digest)13 Violation (com.google.rpc.PreconditionFailure.Violation)12 ExecuteResponse (build.bazel.remote.execution.v2.ExecuteResponse)10 ByteString (com.google.protobuf.ByteString)9 Action (build.bazel.remote.execution.v2.Action)8 Directory (build.bazel.remote.execution.v2.Directory)6 Actions.checkPreconditionFailure (build.buildfarm.common.Actions.checkPreconditionFailure)6 Poller (build.buildfarm.common.Poller)6 ExecuteEntry (build.buildfarm.v1test.ExecuteEntry)6 Operation (com.google.longrunning.Operation)6 Status (io.grpc.Status)6 ExecutionException (java.util.concurrent.ExecutionException)6 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)5 ExecuteOperationMetadata (build.bazel.remote.execution.v2.ExecuteOperationMetadata)4 Watcher (build.buildfarm.common.Watcher)4 Any (com.google.protobuf.Any)4 QueueEntry (build.buildfarm.v1test.QueueEntry)3 QueuedOperation (build.buildfarm.v1test.QueuedOperation)3