All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.google.cloud.tpu.v1.stub.GrpcTpuStub Maven / Gradle / Ivy

Go to download

Cloud TPU are Google's custom-developed application-specific integrated circuits (ASICs) used to accelerate machine learning workloads.

There is a newer version: 2.55.0
Show newest version
/*
 * Copyright 2024 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.cloud.tpu.v1.stub;

import static com.google.cloud.tpu.v1.TpuClient.ListAcceleratorTypesPagedResponse;
import static com.google.cloud.tpu.v1.TpuClient.ListLocationsPagedResponse;
import static com.google.cloud.tpu.v1.TpuClient.ListNodesPagedResponse;
import static com.google.cloud.tpu.v1.TpuClient.ListTensorFlowVersionsPagedResponse;

import com.google.api.gax.core.BackgroundResource;
import com.google.api.gax.core.BackgroundResourceAggregation;
import com.google.api.gax.grpc.GrpcCallSettings;
import com.google.api.gax.grpc.GrpcStubCallableFactory;
import com.google.api.gax.rpc.ClientContext;
import com.google.api.gax.rpc.OperationCallable;
import com.google.api.gax.rpc.RequestParamsBuilder;
import com.google.api.gax.rpc.UnaryCallable;
import com.google.cloud.location.GetLocationRequest;
import com.google.cloud.location.ListLocationsRequest;
import com.google.cloud.location.ListLocationsResponse;
import com.google.cloud.location.Location;
import com.google.cloud.tpu.v1.AcceleratorType;
import com.google.cloud.tpu.v1.CreateNodeRequest;
import com.google.cloud.tpu.v1.DeleteNodeRequest;
import com.google.cloud.tpu.v1.GetAcceleratorTypeRequest;
import com.google.cloud.tpu.v1.GetNodeRequest;
import com.google.cloud.tpu.v1.GetTensorFlowVersionRequest;
import com.google.cloud.tpu.v1.ListAcceleratorTypesRequest;
import com.google.cloud.tpu.v1.ListAcceleratorTypesResponse;
import com.google.cloud.tpu.v1.ListNodesRequest;
import com.google.cloud.tpu.v1.ListNodesResponse;
import com.google.cloud.tpu.v1.ListTensorFlowVersionsRequest;
import com.google.cloud.tpu.v1.ListTensorFlowVersionsResponse;
import com.google.cloud.tpu.v1.Node;
import com.google.cloud.tpu.v1.OperationMetadata;
import com.google.cloud.tpu.v1.ReimageNodeRequest;
import com.google.cloud.tpu.v1.StartNodeRequest;
import com.google.cloud.tpu.v1.StopNodeRequest;
import com.google.cloud.tpu.v1.TensorFlowVersion;
import com.google.longrunning.Operation;
import com.google.longrunning.stub.GrpcOperationsStub;
import io.grpc.MethodDescriptor;
import io.grpc.protobuf.ProtoUtils;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import javax.annotation.Generated;

// AUTO-GENERATED DOCUMENTATION AND CLASS.
/**
 * gRPC stub implementation for the Tpu service API.
 *
 * 

This class is for advanced usage and reflects the underlying API directly. */ @Generated("by gapic-generator-java") public class GrpcTpuStub extends TpuStub { private static final MethodDescriptor listNodesMethodDescriptor = MethodDescriptor.newBuilder() .setType(MethodDescriptor.MethodType.UNARY) .setFullMethodName("google.cloud.tpu.v1.Tpu/ListNodes") .setRequestMarshaller(ProtoUtils.marshaller(ListNodesRequest.getDefaultInstance())) .setResponseMarshaller(ProtoUtils.marshaller(ListNodesResponse.getDefaultInstance())) .build(); private static final MethodDescriptor getNodeMethodDescriptor = MethodDescriptor.newBuilder() .setType(MethodDescriptor.MethodType.UNARY) .setFullMethodName("google.cloud.tpu.v1.Tpu/GetNode") .setRequestMarshaller(ProtoUtils.marshaller(GetNodeRequest.getDefaultInstance())) .setResponseMarshaller(ProtoUtils.marshaller(Node.getDefaultInstance())) .build(); private static final MethodDescriptor createNodeMethodDescriptor = MethodDescriptor.newBuilder() .setType(MethodDescriptor.MethodType.UNARY) .setFullMethodName("google.cloud.tpu.v1.Tpu/CreateNode") .setRequestMarshaller(ProtoUtils.marshaller(CreateNodeRequest.getDefaultInstance())) .setResponseMarshaller(ProtoUtils.marshaller(Operation.getDefaultInstance())) .build(); private static final MethodDescriptor deleteNodeMethodDescriptor = MethodDescriptor.newBuilder() .setType(MethodDescriptor.MethodType.UNARY) .setFullMethodName("google.cloud.tpu.v1.Tpu/DeleteNode") .setRequestMarshaller(ProtoUtils.marshaller(DeleteNodeRequest.getDefaultInstance())) .setResponseMarshaller(ProtoUtils.marshaller(Operation.getDefaultInstance())) .build(); private static final MethodDescriptor reimageNodeMethodDescriptor = MethodDescriptor.newBuilder() .setType(MethodDescriptor.MethodType.UNARY) .setFullMethodName("google.cloud.tpu.v1.Tpu/ReimageNode") .setRequestMarshaller(ProtoUtils.marshaller(ReimageNodeRequest.getDefaultInstance())) .setResponseMarshaller(ProtoUtils.marshaller(Operation.getDefaultInstance())) .build(); private static final MethodDescriptor stopNodeMethodDescriptor = MethodDescriptor.newBuilder() .setType(MethodDescriptor.MethodType.UNARY) .setFullMethodName("google.cloud.tpu.v1.Tpu/StopNode") .setRequestMarshaller(ProtoUtils.marshaller(StopNodeRequest.getDefaultInstance())) .setResponseMarshaller(ProtoUtils.marshaller(Operation.getDefaultInstance())) .build(); private static final MethodDescriptor startNodeMethodDescriptor = MethodDescriptor.newBuilder() .setType(MethodDescriptor.MethodType.UNARY) .setFullMethodName("google.cloud.tpu.v1.Tpu/StartNode") .setRequestMarshaller(ProtoUtils.marshaller(StartNodeRequest.getDefaultInstance())) .setResponseMarshaller(ProtoUtils.marshaller(Operation.getDefaultInstance())) .build(); private static final MethodDescriptor< ListTensorFlowVersionsRequest, ListTensorFlowVersionsResponse> listTensorFlowVersionsMethodDescriptor = MethodDescriptor .newBuilder() .setType(MethodDescriptor.MethodType.UNARY) .setFullMethodName("google.cloud.tpu.v1.Tpu/ListTensorFlowVersions") .setRequestMarshaller( ProtoUtils.marshaller(ListTensorFlowVersionsRequest.getDefaultInstance())) .setResponseMarshaller( ProtoUtils.marshaller(ListTensorFlowVersionsResponse.getDefaultInstance())) .build(); private static final MethodDescriptor getTensorFlowVersionMethodDescriptor = MethodDescriptor.newBuilder() .setType(MethodDescriptor.MethodType.UNARY) .setFullMethodName("google.cloud.tpu.v1.Tpu/GetTensorFlowVersion") .setRequestMarshaller( ProtoUtils.marshaller(GetTensorFlowVersionRequest.getDefaultInstance())) .setResponseMarshaller(ProtoUtils.marshaller(TensorFlowVersion.getDefaultInstance())) .build(); private static final MethodDescriptor listAcceleratorTypesMethodDescriptor = MethodDescriptor.newBuilder() .setType(MethodDescriptor.MethodType.UNARY) .setFullMethodName("google.cloud.tpu.v1.Tpu/ListAcceleratorTypes") .setRequestMarshaller( ProtoUtils.marshaller(ListAcceleratorTypesRequest.getDefaultInstance())) .setResponseMarshaller( ProtoUtils.marshaller(ListAcceleratorTypesResponse.getDefaultInstance())) .build(); private static final MethodDescriptor getAcceleratorTypeMethodDescriptor = MethodDescriptor.newBuilder() .setType(MethodDescriptor.MethodType.UNARY) .setFullMethodName("google.cloud.tpu.v1.Tpu/GetAcceleratorType") .setRequestMarshaller( ProtoUtils.marshaller(GetAcceleratorTypeRequest.getDefaultInstance())) .setResponseMarshaller(ProtoUtils.marshaller(AcceleratorType.getDefaultInstance())) .build(); private static final MethodDescriptor listLocationsMethodDescriptor = MethodDescriptor.newBuilder() .setType(MethodDescriptor.MethodType.UNARY) .setFullMethodName("google.cloud.location.Locations/ListLocations") .setRequestMarshaller( ProtoUtils.marshaller(ListLocationsRequest.getDefaultInstance())) .setResponseMarshaller( ProtoUtils.marshaller(ListLocationsResponse.getDefaultInstance())) .build(); private static final MethodDescriptor getLocationMethodDescriptor = MethodDescriptor.newBuilder() .setType(MethodDescriptor.MethodType.UNARY) .setFullMethodName("google.cloud.location.Locations/GetLocation") .setRequestMarshaller(ProtoUtils.marshaller(GetLocationRequest.getDefaultInstance())) .setResponseMarshaller(ProtoUtils.marshaller(Location.getDefaultInstance())) .build(); private final UnaryCallable listNodesCallable; private final UnaryCallable listNodesPagedCallable; private final UnaryCallable getNodeCallable; private final UnaryCallable createNodeCallable; private final OperationCallable createNodeOperationCallable; private final UnaryCallable deleteNodeCallable; private final OperationCallable deleteNodeOperationCallable; private final UnaryCallable reimageNodeCallable; private final OperationCallable reimageNodeOperationCallable; private final UnaryCallable stopNodeCallable; private final OperationCallable stopNodeOperationCallable; private final UnaryCallable startNodeCallable; private final OperationCallable startNodeOperationCallable; private final UnaryCallable listTensorFlowVersionsCallable; private final UnaryCallable listTensorFlowVersionsPagedCallable; private final UnaryCallable getTensorFlowVersionCallable; private final UnaryCallable listAcceleratorTypesCallable; private final UnaryCallable listAcceleratorTypesPagedCallable; private final UnaryCallable getAcceleratorTypeCallable; private final UnaryCallable listLocationsCallable; private final UnaryCallable listLocationsPagedCallable; private final UnaryCallable getLocationCallable; private final BackgroundResource backgroundResources; private final GrpcOperationsStub operationsStub; private final GrpcStubCallableFactory callableFactory; public static final GrpcTpuStub create(TpuStubSettings settings) throws IOException { return new GrpcTpuStub(settings, ClientContext.create(settings)); } public static final GrpcTpuStub create(ClientContext clientContext) throws IOException { return new GrpcTpuStub(TpuStubSettings.newBuilder().build(), clientContext); } public static final GrpcTpuStub create( ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { return new GrpcTpuStub(TpuStubSettings.newBuilder().build(), clientContext, callableFactory); } /** * Constructs an instance of GrpcTpuStub, using the given settings. This is protected so that it * is easy to make a subclass, but otherwise, the static factory methods should be preferred. */ protected GrpcTpuStub(TpuStubSettings settings, ClientContext clientContext) throws IOException { this(settings, clientContext, new GrpcTpuCallableFactory()); } /** * Constructs an instance of GrpcTpuStub, using the given settings. This is protected so that it * is easy to make a subclass, but otherwise, the static factory methods should be preferred. */ protected GrpcTpuStub( TpuStubSettings settings, ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { this.callableFactory = callableFactory; this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory); GrpcCallSettings listNodesTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(listNodesMethodDescriptor) .setParamsExtractor( request -> { RequestParamsBuilder builder = RequestParamsBuilder.create(); builder.add("parent", String.valueOf(request.getParent())); return builder.build(); }) .build(); GrpcCallSettings getNodeTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(getNodeMethodDescriptor) .setParamsExtractor( request -> { RequestParamsBuilder builder = RequestParamsBuilder.create(); builder.add("name", String.valueOf(request.getName())); return builder.build(); }) .build(); GrpcCallSettings createNodeTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(createNodeMethodDescriptor) .setParamsExtractor( request -> { RequestParamsBuilder builder = RequestParamsBuilder.create(); builder.add("parent", String.valueOf(request.getParent())); return builder.build(); }) .build(); GrpcCallSettings deleteNodeTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(deleteNodeMethodDescriptor) .setParamsExtractor( request -> { RequestParamsBuilder builder = RequestParamsBuilder.create(); builder.add("name", String.valueOf(request.getName())); return builder.build(); }) .build(); GrpcCallSettings reimageNodeTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(reimageNodeMethodDescriptor) .setParamsExtractor( request -> { RequestParamsBuilder builder = RequestParamsBuilder.create(); builder.add("name", String.valueOf(request.getName())); return builder.build(); }) .build(); GrpcCallSettings stopNodeTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(stopNodeMethodDescriptor) .setParamsExtractor( request -> { RequestParamsBuilder builder = RequestParamsBuilder.create(); builder.add("name", String.valueOf(request.getName())); return builder.build(); }) .build(); GrpcCallSettings startNodeTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(startNodeMethodDescriptor) .setParamsExtractor( request -> { RequestParamsBuilder builder = RequestParamsBuilder.create(); builder.add("name", String.valueOf(request.getName())); return builder.build(); }) .build(); GrpcCallSettings listTensorFlowVersionsTransportSettings = GrpcCallSettings .newBuilder() .setMethodDescriptor(listTensorFlowVersionsMethodDescriptor) .setParamsExtractor( request -> { RequestParamsBuilder builder = RequestParamsBuilder.create(); builder.add("parent", String.valueOf(request.getParent())); return builder.build(); }) .build(); GrpcCallSettings getTensorFlowVersionTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(getTensorFlowVersionMethodDescriptor) .setParamsExtractor( request -> { RequestParamsBuilder builder = RequestParamsBuilder.create(); builder.add("name", String.valueOf(request.getName())); return builder.build(); }) .build(); GrpcCallSettings listAcceleratorTypesTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(listAcceleratorTypesMethodDescriptor) .setParamsExtractor( request -> { RequestParamsBuilder builder = RequestParamsBuilder.create(); builder.add("parent", String.valueOf(request.getParent())); return builder.build(); }) .build(); GrpcCallSettings getAcceleratorTypeTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(getAcceleratorTypeMethodDescriptor) .setParamsExtractor( request -> { RequestParamsBuilder builder = RequestParamsBuilder.create(); builder.add("name", String.valueOf(request.getName())); return builder.build(); }) .build(); GrpcCallSettings listLocationsTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(listLocationsMethodDescriptor) .setParamsExtractor( request -> { RequestParamsBuilder builder = RequestParamsBuilder.create(); builder.add("name", String.valueOf(request.getName())); return builder.build(); }) .build(); GrpcCallSettings getLocationTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(getLocationMethodDescriptor) .setParamsExtractor( request -> { RequestParamsBuilder builder = RequestParamsBuilder.create(); builder.add("name", String.valueOf(request.getName())); return builder.build(); }) .build(); this.listNodesCallable = callableFactory.createUnaryCallable( listNodesTransportSettings, settings.listNodesSettings(), clientContext); this.listNodesPagedCallable = callableFactory.createPagedCallable( listNodesTransportSettings, settings.listNodesSettings(), clientContext); this.getNodeCallable = callableFactory.createUnaryCallable( getNodeTransportSettings, settings.getNodeSettings(), clientContext); this.createNodeCallable = callableFactory.createUnaryCallable( createNodeTransportSettings, settings.createNodeSettings(), clientContext); this.createNodeOperationCallable = callableFactory.createOperationCallable( createNodeTransportSettings, settings.createNodeOperationSettings(), clientContext, operationsStub); this.deleteNodeCallable = callableFactory.createUnaryCallable( deleteNodeTransportSettings, settings.deleteNodeSettings(), clientContext); this.deleteNodeOperationCallable = callableFactory.createOperationCallable( deleteNodeTransportSettings, settings.deleteNodeOperationSettings(), clientContext, operationsStub); this.reimageNodeCallable = callableFactory.createUnaryCallable( reimageNodeTransportSettings, settings.reimageNodeSettings(), clientContext); this.reimageNodeOperationCallable = callableFactory.createOperationCallable( reimageNodeTransportSettings, settings.reimageNodeOperationSettings(), clientContext, operationsStub); this.stopNodeCallable = callableFactory.createUnaryCallable( stopNodeTransportSettings, settings.stopNodeSettings(), clientContext); this.stopNodeOperationCallable = callableFactory.createOperationCallable( stopNodeTransportSettings, settings.stopNodeOperationSettings(), clientContext, operationsStub); this.startNodeCallable = callableFactory.createUnaryCallable( startNodeTransportSettings, settings.startNodeSettings(), clientContext); this.startNodeOperationCallable = callableFactory.createOperationCallable( startNodeTransportSettings, settings.startNodeOperationSettings(), clientContext, operationsStub); this.listTensorFlowVersionsCallable = callableFactory.createUnaryCallable( listTensorFlowVersionsTransportSettings, settings.listTensorFlowVersionsSettings(), clientContext); this.listTensorFlowVersionsPagedCallable = callableFactory.createPagedCallable( listTensorFlowVersionsTransportSettings, settings.listTensorFlowVersionsSettings(), clientContext); this.getTensorFlowVersionCallable = callableFactory.createUnaryCallable( getTensorFlowVersionTransportSettings, settings.getTensorFlowVersionSettings(), clientContext); this.listAcceleratorTypesCallable = callableFactory.createUnaryCallable( listAcceleratorTypesTransportSettings, settings.listAcceleratorTypesSettings(), clientContext); this.listAcceleratorTypesPagedCallable = callableFactory.createPagedCallable( listAcceleratorTypesTransportSettings, settings.listAcceleratorTypesSettings(), clientContext); this.getAcceleratorTypeCallable = callableFactory.createUnaryCallable( getAcceleratorTypeTransportSettings, settings.getAcceleratorTypeSettings(), clientContext); this.listLocationsCallable = callableFactory.createUnaryCallable( listLocationsTransportSettings, settings.listLocationsSettings(), clientContext); this.listLocationsPagedCallable = callableFactory.createPagedCallable( listLocationsTransportSettings, settings.listLocationsSettings(), clientContext); this.getLocationCallable = callableFactory.createUnaryCallable( getLocationTransportSettings, settings.getLocationSettings(), clientContext); this.backgroundResources = new BackgroundResourceAggregation(clientContext.getBackgroundResources()); } public GrpcOperationsStub getOperationsStub() { return operationsStub; } @Override public UnaryCallable listNodesCallable() { return listNodesCallable; } @Override public UnaryCallable listNodesPagedCallable() { return listNodesPagedCallable; } @Override public UnaryCallable getNodeCallable() { return getNodeCallable; } @Override public UnaryCallable createNodeCallable() { return createNodeCallable; } @Override public OperationCallable createNodeOperationCallable() { return createNodeOperationCallable; } @Override public UnaryCallable deleteNodeCallable() { return deleteNodeCallable; } @Override public OperationCallable deleteNodeOperationCallable() { return deleteNodeOperationCallable; } @Override public UnaryCallable reimageNodeCallable() { return reimageNodeCallable; } @Override public OperationCallable reimageNodeOperationCallable() { return reimageNodeOperationCallable; } @Override public UnaryCallable stopNodeCallable() { return stopNodeCallable; } @Override public OperationCallable stopNodeOperationCallable() { return stopNodeOperationCallable; } @Override public UnaryCallable startNodeCallable() { return startNodeCallable; } @Override public OperationCallable startNodeOperationCallable() { return startNodeOperationCallable; } @Override public UnaryCallable listTensorFlowVersionsCallable() { return listTensorFlowVersionsCallable; } @Override public UnaryCallable listTensorFlowVersionsPagedCallable() { return listTensorFlowVersionsPagedCallable; } @Override public UnaryCallable getTensorFlowVersionCallable() { return getTensorFlowVersionCallable; } @Override public UnaryCallable listAcceleratorTypesCallable() { return listAcceleratorTypesCallable; } @Override public UnaryCallable listAcceleratorTypesPagedCallable() { return listAcceleratorTypesPagedCallable; } @Override public UnaryCallable getAcceleratorTypeCallable() { return getAcceleratorTypeCallable; } @Override public UnaryCallable listLocationsCallable() { return listLocationsCallable; } @Override public UnaryCallable listLocationsPagedCallable() { return listLocationsPagedCallable; } @Override public UnaryCallable getLocationCallable() { return getLocationCallable; } @Override public final void close() { try { backgroundResources.close(); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalStateException("Failed to close resource", e); } } @Override public void shutdown() { backgroundResources.shutdown(); } @Override public boolean isShutdown() { return backgroundResources.isShutdown(); } @Override public boolean isTerminated() { return backgroundResources.isTerminated(); } @Override public void shutdownNow() { backgroundResources.shutdownNow(); } @Override public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { return backgroundResources.awaitTermination(duration, unit); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy