use of com.google.rpc.PreconditionFailure in project bazel-buildfarm by bazelbuild.
the class ShardWorkerContext method uploadOutputs.
@Override
public void uploadOutputs(Digest actionDigest, ActionResult.Builder resultBuilder, Path actionRoot, Iterable<String> outputFiles, Iterable<String> outputDirs) throws IOException, InterruptedException, StatusException {
PreconditionFailure.Builder preconditionFailure = PreconditionFailure.newBuilder();
for (String outputFile : outputFiles) {
uploadOutputFile(resultBuilder, outputFile, actionRoot, preconditionFailure);
}
for (String outputDir : outputDirs) {
uploadOutputDirectory(resultBuilder, outputDir, actionRoot, preconditionFailure);
}
checkPreconditionFailure(actionDigest, preconditionFailure.build());
/* put together our outputs and update the result */
updateActionResultStdOutputs(resultBuilder);
}
use of com.google.rpc.PreconditionFailure 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 com.google.rpc.PreconditionFailure in project bazel-buildfarm by bazelbuild.
the class ShardInstanceTest method queueActionMissingErrorsOperation.
@Test
public void queueActionMissingErrorsOperation() throws Exception {
Action action = createAction(false);
Digest actionDigest = DIGEST_UTIL.compute(action);
ExecuteEntry executeEntry = ExecuteEntry.newBuilder().setOperationName("missing-action-operation").setActionDigest(actionDigest).setSkipCacheLookup(true).build();
when(mockBackplane.canQueue()).thenReturn(true);
Poller poller = mock(Poller.class);
boolean failedPreconditionExceptionCaught = false;
try {
instance.queue(executeEntry, poller, DEFAULT_TIMEOUT).get(QUEUE_TEST_TIMEOUT_SECONDS, SECONDS);
} catch (ExecutionException e) {
com.google.rpc.Status status = StatusProto.fromThrowable(e);
if (status.getCode() == Code.FAILED_PRECONDITION.getNumber()) {
failedPreconditionExceptionCaught = true;
} else {
e.getCause().printStackTrace();
}
}
assertThat(failedPreconditionExceptionCaught).isTrue();
PreconditionFailure preconditionFailure = PreconditionFailure.newBuilder().addViolations(Violation.newBuilder().setType(VIOLATION_TYPE_MISSING).setSubject("blobs/" + DigestUtil.toString(actionDigest)).setDescription(MISSING_ACTION)).build();
ExecuteResponse executeResponse = ExecuteResponse.newBuilder().setStatus(com.google.rpc.Status.newBuilder().setCode(Code.FAILED_PRECONDITION.getNumber()).setMessage(invalidActionVerboseMessage(actionDigest, preconditionFailure)).addDetails(Any.pack(preconditionFailure))).build();
assertResponse(executeResponse);
verify(poller, atLeastOnce()).pause();
}
use of com.google.rpc.PreconditionFailure in project bazel-buildfarm by bazelbuild.
the class ShardInstanceTest method queueDirectoryMissingErrorsOperation.
@Test
public void queueDirectoryMissingErrorsOperation() throws Exception {
ByteString foo = ByteString.copyFromUtf8("foo");
Digest subdirDigest = DIGEST_UTIL.compute(foo);
Directory inputRoot = Directory.newBuilder().addDirectories(DirectoryNode.newBuilder().setName("missing-subdir").setDigest(subdirDigest)).build();
ByteString inputRootContent = inputRoot.toByteString();
Digest inputRootDigest = DIGEST_UTIL.compute(inputRootContent);
provideBlob(inputRootDigest, inputRootContent);
Action action = createAction(true, true, inputRootDigest, SIMPLE_COMMAND);
Digest actionDigest = DIGEST_UTIL.compute(action);
ExecuteEntry executeEntry = ExecuteEntry.newBuilder().setOperationName("missing-directory-operation").setActionDigest(actionDigest).setSkipCacheLookup(true).build();
when(mockBackplane.propertiesEligibleForQueue(Matchers.anyList())).thenReturn(true);
when(mockBackplane.canQueue()).thenReturn(true);
Poller poller = mock(Poller.class);
boolean failedPreconditionExceptionCaught = false;
try {
instance.queue(executeEntry, poller, DEFAULT_TIMEOUT).get(QUEUE_TEST_TIMEOUT_SECONDS, SECONDS);
} catch (ExecutionException e) {
com.google.rpc.Status status = StatusProto.fromThrowable(e);
if (status.getCode() == Code.FAILED_PRECONDITION.getNumber()) {
failedPreconditionExceptionCaught = true;
} else {
e.getCause().printStackTrace();
}
}
assertThat(failedPreconditionExceptionCaught).isTrue();
PreconditionFailure preconditionFailure = PreconditionFailure.newBuilder().addViolations(Violation.newBuilder().setType(VIOLATION_TYPE_MISSING).setSubject("blobs/" + DigestUtil.toString(subdirDigest)).setDescription("The directory `/missing-subdir` was not found in the CAS.")).build();
ExecuteResponse executeResponse = ExecuteResponse.newBuilder().setStatus(com.google.rpc.Status.newBuilder().setCode(Code.FAILED_PRECONDITION.getNumber()).setMessage(invalidActionVerboseMessage(actionDigest, preconditionFailure)).addDetails(Any.pack(preconditionFailure))).build();
assertResponse(executeResponse);
verify(poller, atLeastOnce()).pause();
}
use of com.google.rpc.PreconditionFailure in project bazel-buildfarm by bazelbuild.
the class ShardInstanceTest method queueActionFailsQueueEligibility.
@Test
public void queueActionFailsQueueEligibility() throws Exception {
Directory inputRoot = Directory.newBuilder().build();
ByteString inputRootContent = inputRoot.toByteString();
Digest inputRootDigest = DIGEST_UTIL.compute(inputRootContent);
provideBlob(inputRootDigest, inputRootContent);
Action action = createAction(true, true, inputRootDigest, SIMPLE_COMMAND);
Digest actionDigest = DIGEST_UTIL.compute(action);
ExecuteEntry executeEntry = ExecuteEntry.newBuilder().setOperationName("missing-directory-operation").setActionDigest(actionDigest).setSkipCacheLookup(true).build();
when(mockBackplane.propertiesEligibleForQueue(Matchers.anyList())).thenReturn(false);
when(mockBackplane.canQueue()).thenReturn(true);
Poller poller = mock(Poller.class);
boolean failedPreconditionExceptionCaught = false;
try {
instance.queue(executeEntry, poller, DEFAULT_TIMEOUT).get(QUEUE_TEST_TIMEOUT_SECONDS, SECONDS);
} catch (ExecutionException e) {
com.google.rpc.Status status = StatusProto.fromThrowable(e);
if (status.getCode() == Code.FAILED_PRECONDITION.getNumber()) {
failedPreconditionExceptionCaught = true;
} else {
e.getCause().printStackTrace();
}
}
assertThat(failedPreconditionExceptionCaught).isTrue();
PreconditionFailure preconditionFailure = PreconditionFailure.newBuilder().addViolations(Violation.newBuilder().setType(VIOLATION_TYPE_INVALID).setSubject(INVALID_PLATFORM).setDescription("properties are not valid for queue eligibility: []")).build();
ExecuteResponse executeResponse = ExecuteResponse.newBuilder().setStatus(com.google.rpc.Status.newBuilder().setCode(Code.FAILED_PRECONDITION.getNumber()).setMessage(invalidActionVerboseMessage(actionDigest, preconditionFailure)).addDetails(Any.pack(preconditionFailure))).build();
assertResponse(executeResponse);
verify(poller, atLeastOnce()).pause();
}
Aggregations