use of build.bazel.remote.execution.v2.ExecutionStage.Value.COMPLETED in project bazel-buildfarm by bazelbuild.
the class ReportResultStage method reportPolled.
private OperationContext reportPolled(OperationContext operationContext) throws InterruptedException {
String operationName = operationContext.operation.getName();
ActionResult.Builder resultBuilder = operationContext.executeResponse.getResultBuilder();
resultBuilder.getExecutionMetadataBuilder().setOutputUploadStartTimestamp(Timestamps.fromMillis(System.currentTimeMillis()));
boolean blacklist = false;
try {
workerContext.uploadOutputs(operationContext.queueEntry.getExecuteEntry().getActionDigest(), resultBuilder, operationContext.execDir, operationContext.command.getOutputFilesList(), operationContext.command.getOutputDirectoriesList());
} catch (StatusException e) {
ExecuteResponse executeResponse = operationContext.executeResponse.build();
if (executeResponse.getStatus().getCode() == Code.OK.getNumber() && executeResponse.getResult().getExitCode() == 0) {
// something about the outputs was malformed - fail the operation with this status if not
// already failing
Status status = StatusProto.fromThrowable(e);
if (status == null) {
logger.log(Level.SEVERE, String.format("no rpc status from exception for %s", operationName), e);
status = asExecutionStatus(e);
}
operationContext.executeResponse.setStatus(status);
if (isRetriable(status)) {
blacklist = true;
}
}
} catch (InterruptedException | ClosedByInterruptException e) {
// cancellation here should not be logged
return null;
} catch (IOException e) {
logger.log(Level.SEVERE, String.format("error uploading outputs for %s", operationName), e);
return null;
}
Operation operation = operationContext.operation;
ExecuteOperationMetadata metadata;
try {
metadata = operation.getMetadata().unpack(ExecutingOperationMetadata.class).getExecuteOperationMetadata();
} catch (InvalidProtocolBufferException e) {
logger.log(Level.SEVERE, String.format("invalid execute operation metadata for %s", operationName), e);
return null;
}
Timestamp now = Timestamps.fromMillis(System.currentTimeMillis());
resultBuilder.getExecutionMetadataBuilder().setWorkerCompletedTimestamp(now).setOutputUploadCompletedTimestamp(now);
ExecuteResponse executeResponse = operationContext.executeResponse.build();
if (blacklist || (!operationContext.action.getDoNotCache() && executeResponse.getStatus().getCode() == Code.OK.getNumber() && executeResponse.getResult().getExitCode() == 0)) {
try {
if (blacklist) {
workerContext.blacklistAction(metadata.getActionDigest().getHash());
} else {
workerContext.putActionResult(DigestUtil.asActionKey(metadata.getActionDigest()), executeResponse.getResult());
}
} catch (IOException e) {
logger.log(Level.SEVERE, String.format("error reporting action result for %s", operationName), e);
return null;
}
}
CompletedOperationMetadata completedMetadata = CompletedOperationMetadata.newBuilder().setExecuteOperationMetadata(metadata.toBuilder().setStage(COMPLETED).build()).setRequestMetadata(operationContext.queueEntry.getExecuteEntry().getRequestMetadata()).build();
Operation completedOperation = operation.toBuilder().setDone(true).setMetadata(Any.pack(completedMetadata)).setResponse(Any.pack(executeResponse)).build();
operationContext.poller.pause();
try {
if (!workerContext.putOperation(completedOperation)) {
return null;
}
} catch (IOException e) {
logger.log(Level.SEVERE, String.format("error reporting operation complete for %s", operationName), e);
return null;
}
return operationContext.toBuilder().setOperation(completedOperation).build();
}
Aggregations