Search in sources :

Example 16 with RequestMetadata

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;
        }
    }
}
Also used : ExecutingOperationMetadata(build.buildfarm.v1test.ExecutingOperationMetadata) ExecuteOperationMetadata(build.bazel.remote.execution.v2.ExecuteOperationMetadata) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ExecuteResponse(build.bazel.remote.execution.v2.ExecuteResponse) QueuedOperationMetadata(build.buildfarm.v1test.QueuedOperationMetadata) CompletedOperationMetadata(build.buildfarm.v1test.CompletedOperationMetadata) Date(java.util.Date) RequestMetadata(build.bazel.remote.execution.v2.RequestMetadata)

Example 17 with RequestMetadata

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());
        }
    }
}
Also used : SearchJobsRequest(com.google.cloud.talent.v4beta1.SearchJobsRequest) SearchJobsResponse(com.google.cloud.talent.v4beta1.SearchJobsResponse) TenantName(com.google.cloud.talent.v4beta1.TenantName) JobServiceClient(com.google.cloud.talent.v4beta1.JobServiceClient) Duration(com.google.protobuf.Duration) RequestMetadata(com.google.cloud.talent.v4beta1.RequestMetadata) CommuteFilter(com.google.cloud.talent.v4beta1.CommuteFilter) JobQuery(com.google.cloud.talent.v4beta1.JobQuery) LatLng(com.google.type.LatLng) Job(com.google.cloud.talent.v4beta1.Job) CommuteMethod(com.google.cloud.talent.v4beta1.CommuteMethod)

Example 18 with RequestMetadata

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());
        }
    }
}
Also used : SearchJobsRequest(com.google.cloud.talent.v4beta1.SearchJobsRequest) SearchJobsResponse(com.google.cloud.talent.v4beta1.SearchJobsResponse) TenantName(com.google.cloud.talent.v4beta1.TenantName) HistogramQuery(com.google.cloud.talent.v4beta1.HistogramQuery) JobServiceClient(com.google.cloud.talent.v4beta1.JobServiceClient) Job(com.google.cloud.talent.v4beta1.Job) RequestMetadata(com.google.cloud.talent.v4beta1.RequestMetadata)

Example 19 with RequestMetadata

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);
}
Also used : HttpURLConnection(java.net.HttpURLConnection) ExecuteOperationMetadata(build.bazel.remote.execution.v2.ExecuteOperationMetadata) ExecutingOperationMetadata(build.buildfarm.v1test.ExecutingOperationMetadata) DirectoryNode(build.bazel.remote.execution.v2.DirectoryNode) ExecutionStage(build.bazel.remote.execution.v2.ExecutionStage) Blob(build.buildfarm.cas.ContentAddressableStorage.Blob) StatusProto(io.grpc.protobuf.StatusProto) Tree(build.buildfarm.v1test.Tree) Map(java.util.Map) ServerCapabilities(build.bazel.remote.execution.v2.ServerCapabilities) Status(io.grpc.Status) ServerCallStreamObserver(io.grpc.stub.ServerCallStreamObserver) CacheCapabilities(build.bazel.remote.execution.v2.CacheCapabilities) OutputDirectory(build.bazel.remote.execution.v2.OutputDirectory) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ActionCache(build.buildfarm.ac.ActionCache) EntryLimitException(build.buildfarm.common.EntryLimitException) Set(java.util.Set) MoreExecutors.directExecutor(com.google.common.util.concurrent.MoreExecutors.directExecutor) VIOLATION_TYPE_MISSING(build.buildfarm.common.Errors.VIOLATION_TYPE_MISSING) DirectoryEntry(build.buildfarm.common.TreeIterator.DirectoryEntry) ByteStreams(com.google.common.io.ByteStreams) Any(com.google.protobuf.Any) Actions.checkPreconditionFailure(build.buildfarm.common.Actions.checkPreconditionFailure) Directory(build.bazel.remote.execution.v2.Directory) Iterables(com.google.common.collect.Iterables) Command(build.bazel.remote.execution.v2.Command) MoreExecutors.newDirectExecutorService(com.google.common.util.concurrent.MoreExecutors.newDirectExecutorService) QueuedOperation(build.buildfarm.v1test.QueuedOperation) ResultsCachePolicy(build.bazel.remote.execution.v2.ResultsCachePolicy) DigestUtil(build.buildfarm.common.DigestUtil) Action(build.bazel.remote.execution.v2.Action) Actions.asExecutionStatus(build.buildfarm.common.Actions.asExecutionStatus) Watcher(build.buildfarm.common.Watcher) VIOLATION_TYPE_INVALID(build.buildfarm.common.Errors.VIOLATION_TYPE_INVALID) FileNode(build.bazel.remote.execution.v2.FileNode) StreamSupport(java.util.stream.StreamSupport) WorkerListMessage(build.buildfarm.v1test.WorkerListMessage) Nullable(javax.annotation.Nullable) Futures.immediateFuture(com.google.common.util.concurrent.Futures.immediateFuture) Executor(java.util.concurrent.Executor) PreconditionFailure(com.google.rpc.PreconditionFailure) IOException(java.io.IOException) FutureCallback(com.google.common.util.concurrent.FutureCallback) ExecutionException(java.util.concurrent.ExecutionException) Futures(com.google.common.util.concurrent.Futures) WorkerProfileMessage(build.buildfarm.v1test.WorkerProfileMessage) Utils.putBlob(build.buildfarm.instance.Utils.putBlob) ExecuteResponse(build.bazel.remote.execution.v2.ExecuteResponse) QueryStringDecoder(io.netty.handler.codec.http.QueryStringDecoder) Preconditions(com.google.common.base.Preconditions) Trees.enumerateTreeFileDigests(build.buildfarm.common.Trees.enumerateTreeFileDigests) Futures.transform(com.google.common.util.concurrent.Futures.transform) NoSuchFileException(java.nio.file.NoSuchFileException) Context(io.grpc.Context) Futures.transformAsync(com.google.common.util.concurrent.Futures.transformAsync) URL(java.net.URL) SymlinkAbsolutePathStrategy(build.bazel.remote.execution.v2.SymlinkAbsolutePathStrategy) URISyntaxException(java.net.URISyntaxException) RequestMetadata(build.bazel.remote.execution.v2.RequestMetadata) ContentAddressableStorage(build.buildfarm.cas.ContentAddressableStorage) ActionKey(build.buildfarm.common.DigestUtil.ActionKey) SettableFuture(com.google.common.util.concurrent.SettableFuture) TokenizableIterator(build.buildfarm.common.TokenizableIterator) Digest(build.bazel.remote.execution.v2.Digest) CasIndexResults(build.buildfarm.common.CasIndexResults) URI(java.net.URI) ImmutableSet(com.google.common.collect.ImmutableSet) ExecutionCapabilities(build.bazel.remote.execution.v2.ExecutionCapabilities) ActionCacheUpdateCapabilities(build.bazel.remote.execution.v2.ActionCacheUpdateCapabilities) OutputFile(build.bazel.remote.execution.v2.OutputFile) UUID(java.util.UUID) Logger(java.util.logging.Logger) Platform(build.bazel.remote.execution.v2.Platform) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Instance(build.buildfarm.instance.Instance) Sets(com.google.common.collect.Sets) Parser(com.google.protobuf.Parser) ByteString(com.google.protobuf.ByteString) QueuedOperationMetadata(build.buildfarm.v1test.QueuedOperationMetadata) SymlinkNode(build.bazel.remote.execution.v2.SymlinkNode) Size(build.buildfarm.common.Size) MoreExecutors.listeningDecorator(com.google.common.util.concurrent.MoreExecutors.listeningDecorator) GetClientStartTimeRequest(build.buildfarm.v1test.GetClientStartTimeRequest) EnrichedOperation(build.buildfarm.operations.EnrichedOperation) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) StatusException(io.grpc.StatusException) Operation(com.google.longrunning.Operation) Stack(java.util.Stack) Level(java.util.logging.Level) HashSet(java.util.HashSet) ImmutableList(com.google.common.collect.ImmutableList) GetClientStartTimeResult(build.buildfarm.v1test.GetClientStartTimeResult) DAYS(java.util.concurrent.TimeUnit.DAYS) FindOperationsResults(build.buildfarm.operations.FindOperationsResults) ActionResult(build.bazel.remote.execution.v2.ActionResult) Code(com.google.rpc.Code) ExecutorService(java.util.concurrent.ExecutorService) OutputStream(java.io.OutputStream) Violation(com.google.rpc.PreconditionFailure.Violation) Response(build.bazel.remote.execution.v2.BatchReadBlobsResponse.Response) PrepareWorkerForGracefulShutDownRequestResults(build.buildfarm.v1test.PrepareWorkerForGracefulShutDownRequestResults) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) ExecutionPolicy(build.bazel.remote.execution.v2.ExecutionPolicy) BatchUpdateBlobsResponse(build.bazel.remote.execution.v2.BatchUpdateBlobsResponse) Write(build.buildfarm.common.Write) Futures.catchingAsync(com.google.common.util.concurrent.Futures.catchingAsync) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) DigestMismatchException(build.buildfarm.cas.DigestMismatchException) Futures.immediateFailedFuture(com.google.common.util.concurrent.Futures.immediateFailedFuture) AsyncFunction(com.google.common.util.concurrent.AsyncFunction) VisibleForTesting(com.google.common.annotations.VisibleForTesting) SECONDS(java.util.concurrent.TimeUnit.SECONDS) CompletedOperationMetadata(build.buildfarm.v1test.CompletedOperationMetadata) InputStream(java.io.InputStream) MoreExecutors.directExecutor(com.google.common.util.concurrent.MoreExecutors.directExecutor) Executor(java.util.concurrent.Executor) Digest(build.bazel.remote.execution.v2.Digest) OutputDirectory(build.bazel.remote.execution.v2.OutputDirectory) ImmutableList(com.google.common.collect.ImmutableList)

Example 20 with RequestMetadata

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);
}
Also used : Status(io.grpc.Status) Actions.asExecutionStatus(build.buildfarm.common.Actions.asExecutionStatus) StatusException(io.grpc.StatusException) Digest(build.bazel.remote.execution.v2.Digest) ExecuteOperationMetadata(build.bazel.remote.execution.v2.ExecuteOperationMetadata) ByteString(com.google.protobuf.ByteString) RequestMetadata(build.bazel.remote.execution.v2.RequestMetadata) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

RequestMetadata (build.bazel.remote.execution.v2.RequestMetadata)17 Digest (build.bazel.remote.execution.v2.Digest)11 ByteString (com.google.protobuf.ByteString)8 ServerCallStreamObserver (io.grpc.stub.ServerCallStreamObserver)7 ActionResult (build.bazel.remote.execution.v2.ActionResult)6 ExecuteOperationMetadata (build.bazel.remote.execution.v2.ExecuteOperationMetadata)6 ExecuteResponse (build.bazel.remote.execution.v2.ExecuteResponse)6 ActionKey (build.buildfarm.common.DigestUtil.ActionKey)6 Operation (com.google.longrunning.Operation)6 DigestUtil (build.buildfarm.common.DigestUtil)5 Watcher (build.buildfarm.common.Watcher)5 Write (build.buildfarm.common.Write)5 Instance (build.buildfarm.instance.Instance)5 QueuedOperation (build.buildfarm.v1test.QueuedOperation)4 Job (com.google.cloud.talent.v4beta1.Job)4 JobServiceClient (com.google.cloud.talent.v4beta1.JobServiceClient)4 RequestMetadata (com.google.cloud.talent.v4beta1.RequestMetadata)4 SearchJobsRequest (com.google.cloud.talent.v4beta1.SearchJobsRequest)4 Duration (com.google.protobuf.Duration)4 Test (org.junit.Test)4