use of com.google.rpc.PreconditionFailure.Violation in project bazel-buildfarm by bazelbuild.
the class AbstractServerInstance method logFailedStatus.
protected void logFailedStatus(Digest actionDigest, com.google.rpc.Status status) {
String message = format("%s: %s: %s\n", DigestUtil.toString(actionDigest), Code.forNumber(status.getCode()), status.getMessage());
for (Any detail : status.getDetailsList()) {
if (detail.is(PreconditionFailure.class)) {
message += " PreconditionFailure:\n";
PreconditionFailure preconditionFailure;
try {
preconditionFailure = detail.unpack(PreconditionFailure.class);
for (Violation violation : preconditionFailure.getViolationsList()) {
message += format(" Violation: %s %s: %s\n", violation.getType(), violation.getSubject(), violation.getDescription());
}
} catch (InvalidProtocolBufferException e) {
message += " " + e.getMessage();
}
} else {
message += " Unknown Detail\n";
}
}
getLogger().info(message);
}
use of com.google.rpc.PreconditionFailure.Violation 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);
}
use of com.google.rpc.PreconditionFailure.Violation 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");
}
use of com.google.rpc.PreconditionFailure.Violation 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);
}
use of com.google.rpc.PreconditionFailure.Violation 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);
}
Aggregations