use of com.google.cloud.talent.v4.RequestMetadata in project bazel-buildfarm by bazelbuild.
the class Cat method printOperation.
private static void printOperation(Operation operation) {
System.out.println("Operation: " + operation.getName());
System.out.println("Done: " + (operation.getDone() ? "true" : "false"));
System.out.println("Metadata:");
try {
ExecuteOperationMetadata metadata;
RequestMetadata requestMetadata;
if (operation.getMetadata().is(QueuedOperationMetadata.class)) {
QueuedOperationMetadata queuedOperationMetadata = operation.getMetadata().unpack(QueuedOperationMetadata.class);
metadata = queuedOperationMetadata.getExecuteOperationMetadata();
requestMetadata = queuedOperationMetadata.getRequestMetadata();
} else if (operation.getMetadata().is(ExecutingOperationMetadata.class)) {
ExecutingOperationMetadata executingMetadata = operation.getMetadata().unpack(ExecutingOperationMetadata.class);
System.out.println(" Started At: " + new Date(executingMetadata.getStartedAt()));
System.out.println(" Executing On: " + executingMetadata.getExecutingOn());
metadata = executingMetadata.getExecuteOperationMetadata();
requestMetadata = executingMetadata.getRequestMetadata();
} else if (operation.getMetadata().is(CompletedOperationMetadata.class)) {
CompletedOperationMetadata completedMetadata = operation.getMetadata().unpack(CompletedOperationMetadata.class);
metadata = completedMetadata.getExecuteOperationMetadata();
requestMetadata = completedMetadata.getRequestMetadata();
} else {
metadata = operation.getMetadata().unpack(ExecuteOperationMetadata.class);
requestMetadata = null;
}
System.out.println(" Stage: " + metadata.getStage());
System.out.println(" Action: " + DigestUtil.toString(metadata.getActionDigest()));
System.out.println(" Stdout Stream: " + metadata.getStdoutStreamName());
System.out.println(" Stderr Stream: " + metadata.getStderrStreamName());
if (requestMetadata != null) {
printRequestMetadata(requestMetadata);
}
} catch (InvalidProtocolBufferException e) {
System.out.println(" UNKNOWN TYPE: " + e.getMessage());
}
if (operation.getDone()) {
switch(operation.getResultCase()) {
case RESPONSE:
System.out.println("Response:");
try {
printExecuteResponse(operation.getResponse().unpack(ExecuteResponse.class));
} catch (InvalidProtocolBufferException e) {
System.out.println(" UNKNOWN RESPONSE TYPE: " + operation.getResponse());
}
break;
case ERROR:
System.out.println("Error: " + Code.forNumber(operation.getError().getCode()));
break;
default:
System.out.println(" UNKNOWN RESULT!");
break;
}
}
}
use of com.google.cloud.talent.v4.RequestMetadata in project java-docs-samples by GoogleCloudPlatform.
the class CommuteSearchJobs method searchJobs.
// Search Jobs with histogram queries.
public static void searchJobs(String projectId, String tenantId) throws IOException {
// the "close" method on the client to safely clean up any remaining background resources.
try (JobServiceClient jobServiceClient = JobServiceClient.create()) {
TenantName parent = TenantName.of(projectId, tenantId);
String domain = "www.example.com";
String sessionId = "Hashed session identifier";
String userId = "Hashed user identifier";
RequestMetadata requestMetadata = RequestMetadata.newBuilder().setDomain(domain).setSessionId(sessionId).setUserId(userId).build();
CommuteMethod commuteMethod = CommuteMethod.DRIVING;
long seconds = 3600L;
Duration travelDuration = Duration.newBuilder().setSeconds(seconds).build();
double latitude = 37.422408;
double longitude = -122.084068;
LatLng startCoordinates = LatLng.newBuilder().setLatitude(latitude).setLongitude(longitude).build();
CommuteFilter commuteFilter = CommuteFilter.newBuilder().setCommuteMethod(commuteMethod).setTravelDuration(travelDuration).setStartCoordinates(startCoordinates).build();
JobQuery jobQuery = JobQuery.newBuilder().setCommuteFilter(commuteFilter).build();
SearchJobsRequest request = SearchJobsRequest.newBuilder().setParent(parent.toString()).setRequestMetadata(requestMetadata).setJobQuery(jobQuery).build();
for (SearchJobsResponse.MatchingJob responseItem : jobServiceClient.searchJobs(request).iterateAll()) {
System.out.format("Job summary: %s%n", responseItem.getJobSummary());
System.out.format("Job title snippet: %s%n", responseItem.getJobTitleSnippet());
Job job = responseItem.getJob();
System.out.format("Job name: %s%n", job.getName());
System.out.format("Job title: %s%n", job.getTitle());
}
}
}
use of com.google.cloud.talent.v4.RequestMetadata in project java-docs-samples by GoogleCloudPlatform.
the class HistogramSearchJobs method searchJobs.
// Search Jobs with histogram queries.
public static void searchJobs(String projectId, String tenantId, String query) throws IOException {
// the "close" method on the client to safely clean up any remaining background resources.
try (JobServiceClient jobServiceClient = JobServiceClient.create()) {
TenantName parent = TenantName.of(projectId, tenantId);
String domain = "http://www.jobUrl.com";
String sessionId = "Hashed session identifier";
String userId = "Hashed user identifier";
RequestMetadata requestMetadata = RequestMetadata.newBuilder().setDomain(domain).setSessionId(sessionId).setUserId(userId).build();
HistogramQuery histogramQueriesElement = HistogramQuery.newBuilder().setHistogramQuery(query).build();
SearchJobsRequest request = SearchJobsRequest.newBuilder().setParent(parent.toString()).setRequestMetadata(requestMetadata).addHistogramQueries(histogramQueriesElement).build();
for (SearchJobsResponse.MatchingJob responseItem : jobServiceClient.searchJobs(request).iterateAll()) {
System.out.format("Job summary: %s%n", responseItem.getJobSummary());
System.out.format("Job title snippet: %s%n", responseItem.getJobTitleSnippet());
Job job = responseItem.getJob();
System.out.format("Job name: %s%n", job.getName());
System.out.format("Job title: %s%n", job.getTitle());
}
}
}
use of com.google.cloud.talent.v4.RequestMetadata in project bazel-buildfarm by bazelbuild.
the class AbstractServerInstance method findMissingActionResultOutputs.
protected ListenableFuture<Iterable<Digest>> findMissingActionResultOutputs(@Nullable ActionResult result, Executor executor, RequestMetadata requestMetadata) {
if (result == null) {
return immediateFuture(ImmutableList.of());
}
ImmutableList.Builder<Digest> digests = ImmutableList.builder();
digests.addAll(Iterables.transform(result.getOutputFilesList(), OutputFile::getDigest));
// findMissingBlobs will weed out empties
digests.add(result.getStdoutDigest());
digests.add(result.getStderrDigest());
ListenableFuture<Void> digestsCompleteFuture = immediateFuture(null);
Executor contextExecutor = Context.current().fixedContextExecutor(executor);
for (OutputDirectory directory : result.getOutputDirectoriesList()) {
// TODO make tree cache
// create an async function here to avoid initiating the calls to expect immediately
// no synchronization required on digests, since only one request is running at a time
AsyncFunction<Void, Void> next = v -> transform(expect(directory.getTreeDigest(), build.bazel.remote.execution.v2.Tree.parser(), executor, requestMetadata), tree -> {
digests.addAll(enumerateTreeFileDigests(tree));
return null;
}, executor);
digestsCompleteFuture = transformAsync(digestsCompleteFuture, next, contextExecutor);
}
return transformAsync(digestsCompleteFuture, v -> findMissingBlobs(digests.build(), requestMetadata), contextExecutor);
}
use of com.google.cloud.talent.v4.RequestMetadata in project bazel-buildfarm by bazelbuild.
the class AbstractServerInstance method requeueOperation.
@VisibleForTesting
public boolean requeueOperation(Operation operation) throws InterruptedException {
String name = operation.getName();
ExecuteOperationMetadata metadata = expectExecuteOperationMetadata(operation);
RequestMetadata requestMetadata = expectRequestMetadata(operation);
if (metadata == null) {
// ensure that watchers are notified
String message = format("Operation %s does not contain ExecuteOperationMetadata", name);
errorOperation(operation, requestMetadata, com.google.rpc.Status.newBuilder().setCode(Code.INTERNAL.getNumber()).setMessage(message).build());
return false;
}
if (metadata.getStage() != ExecutionStage.Value.QUEUED) {
// ensure that watchers are notified
String message = format("Operation %s stage is not QUEUED", name);
errorOperation(operation, requestMetadata, com.google.rpc.Status.newBuilder().setCode(com.google.rpc.Code.INTERNAL.getNumber()).setMessage(message).build());
return false;
}
Digest actionDigest = metadata.getActionDigest();
try {
validateActionDigest(name, actionDigest, requestMetadata);
} catch (StatusException e) {
com.google.rpc.Status status = StatusProto.fromThrowable(e);
if (status == null) {
getLogger().log(Level.SEVERE, "no rpc status from exception", e);
status = com.google.rpc.Status.newBuilder().setCode(Status.fromThrowable(e).getCode().value()).build();
}
logFailedStatus(actionDigest, status);
errorOperation(operation, requestMetadata, status);
return false;
}
getLogger().info(format("%s::requeueOperation(%s): %s", getName(), DigestUtil.toString(actionDigest), name));
return putOperation(operation);
}
Aggregations