com.google.cloud.tpu.v2.stub.HttpJsonTpuStub Maven / Gradle / Ivy
/*
* 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.v2.stub;
import static com.google.cloud.tpu.v2.TpuClient.ListAcceleratorTypesPagedResponse;
import static com.google.cloud.tpu.v2.TpuClient.ListLocationsPagedResponse;
import static com.google.cloud.tpu.v2.TpuClient.ListNodesPagedResponse;
import static com.google.cloud.tpu.v2.TpuClient.ListRuntimeVersionsPagedResponse;
import com.google.api.HttpRule;
import com.google.api.core.InternalApi;
import com.google.api.gax.core.BackgroundResource;
import com.google.api.gax.core.BackgroundResourceAggregation;
import com.google.api.gax.httpjson.ApiMethodDescriptor;
import com.google.api.gax.httpjson.HttpJsonCallSettings;
import com.google.api.gax.httpjson.HttpJsonOperationSnapshot;
import com.google.api.gax.httpjson.HttpJsonStubCallableFactory;
import com.google.api.gax.httpjson.ProtoMessageRequestFormatter;
import com.google.api.gax.httpjson.ProtoMessageResponseParser;
import com.google.api.gax.httpjson.ProtoRestSerializer;
import com.google.api.gax.httpjson.longrunning.stub.HttpJsonOperationsStub;
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.v2.AcceleratorType;
import com.google.cloud.tpu.v2.CreateNodeRequest;
import com.google.cloud.tpu.v2.DeleteNodeRequest;
import com.google.cloud.tpu.v2.GenerateServiceIdentityRequest;
import com.google.cloud.tpu.v2.GenerateServiceIdentityResponse;
import com.google.cloud.tpu.v2.GetAcceleratorTypeRequest;
import com.google.cloud.tpu.v2.GetGuestAttributesRequest;
import com.google.cloud.tpu.v2.GetGuestAttributesResponse;
import com.google.cloud.tpu.v2.GetNodeRequest;
import com.google.cloud.tpu.v2.GetRuntimeVersionRequest;
import com.google.cloud.tpu.v2.ListAcceleratorTypesRequest;
import com.google.cloud.tpu.v2.ListAcceleratorTypesResponse;
import com.google.cloud.tpu.v2.ListNodesRequest;
import com.google.cloud.tpu.v2.ListNodesResponse;
import com.google.cloud.tpu.v2.ListRuntimeVersionsRequest;
import com.google.cloud.tpu.v2.ListRuntimeVersionsResponse;
import com.google.cloud.tpu.v2.Node;
import com.google.cloud.tpu.v2.OperationMetadata;
import com.google.cloud.tpu.v2.RuntimeVersion;
import com.google.cloud.tpu.v2.StartNodeRequest;
import com.google.cloud.tpu.v2.StopNodeRequest;
import com.google.cloud.tpu.v2.UpdateNodeRequest;
import com.google.common.collect.ImmutableMap;
import com.google.longrunning.Operation;
import com.google.protobuf.Empty;
import com.google.protobuf.TypeRegistry;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import javax.annotation.Generated;
// AUTO-GENERATED DOCUMENTATION AND CLASS.
/**
* REST 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 HttpJsonTpuStub extends TpuStub {
private static final TypeRegistry typeRegistry =
TypeRegistry.newBuilder()
.add(Empty.getDescriptor())
.add(OperationMetadata.getDescriptor())
.add(Node.getDescriptor())
.build();
private static final ApiMethodDescriptor
listNodesMethodDescriptor =
ApiMethodDescriptor.newBuilder()
.setFullMethodName("google.cloud.tpu.v2.Tpu/ListNodes")
.setHttpMethod("GET")
.setType(ApiMethodDescriptor.MethodType.UNARY)
.setRequestFormatter(
ProtoMessageRequestFormatter.newBuilder()
.setPath(
"/v2/{parent=projects/*/locations/*}/nodes",
request -> {
Map fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putPathParam(fields, "parent", request.getParent());
return fields;
})
.setQueryParamsExtractor(
request -> {
Map> fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putQueryParam(fields, "pageSize", request.getPageSize());
serializer.putQueryParam(fields, "pageToken", request.getPageToken());
serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int");
return fields;
})
.setRequestBodyExtractor(request -> null)
.build())
.setResponseParser(
ProtoMessageResponseParser.newBuilder()
.setDefaultInstance(ListNodesResponse.getDefaultInstance())
.setDefaultTypeRegistry(typeRegistry)
.build())
.build();
private static final ApiMethodDescriptor getNodeMethodDescriptor =
ApiMethodDescriptor.newBuilder()
.setFullMethodName("google.cloud.tpu.v2.Tpu/GetNode")
.setHttpMethod("GET")
.setType(ApiMethodDescriptor.MethodType.UNARY)
.setRequestFormatter(
ProtoMessageRequestFormatter.newBuilder()
.setPath(
"/v2/{name=projects/*/locations/*/nodes/*}",
request -> {
Map fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putPathParam(fields, "name", request.getName());
return fields;
})
.setQueryParamsExtractor(
request -> {
Map> fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int");
return fields;
})
.setRequestBodyExtractor(request -> null)
.build())
.setResponseParser(
ProtoMessageResponseParser.newBuilder()
.setDefaultInstance(Node.getDefaultInstance())
.setDefaultTypeRegistry(typeRegistry)
.build())
.build();
private static final ApiMethodDescriptor
createNodeMethodDescriptor =
ApiMethodDescriptor.newBuilder()
.setFullMethodName("google.cloud.tpu.v2.Tpu/CreateNode")
.setHttpMethod("POST")
.setType(ApiMethodDescriptor.MethodType.UNARY)
.setRequestFormatter(
ProtoMessageRequestFormatter.newBuilder()
.setPath(
"/v2/{parent=projects/*/locations/*}/nodes",
request -> {
Map fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putPathParam(fields, "parent", request.getParent());
return fields;
})
.setQueryParamsExtractor(
request -> {
Map> fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putQueryParam(fields, "nodeId", request.getNodeId());
serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int");
return fields;
})
.setRequestBodyExtractor(
request ->
ProtoRestSerializer.create().toBody("node", request.getNode(), true))
.build())
.setResponseParser(
ProtoMessageResponseParser.newBuilder()
.setDefaultInstance(Operation.getDefaultInstance())
.setDefaultTypeRegistry(typeRegistry)
.build())
.setOperationSnapshotFactory(
(CreateNodeRequest request, Operation response) ->
HttpJsonOperationSnapshot.create(response))
.build();
private static final ApiMethodDescriptor
deleteNodeMethodDescriptor =
ApiMethodDescriptor.newBuilder()
.setFullMethodName("google.cloud.tpu.v2.Tpu/DeleteNode")
.setHttpMethod("DELETE")
.setType(ApiMethodDescriptor.MethodType.UNARY)
.setRequestFormatter(
ProtoMessageRequestFormatter.newBuilder()
.setPath(
"/v2/{name=projects/*/locations/*/nodes/*}",
request -> {
Map fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putPathParam(fields, "name", request.getName());
return fields;
})
.setQueryParamsExtractor(
request -> {
Map> fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int");
return fields;
})
.setRequestBodyExtractor(request -> null)
.build())
.setResponseParser(
ProtoMessageResponseParser.newBuilder()
.setDefaultInstance(Operation.getDefaultInstance())
.setDefaultTypeRegistry(typeRegistry)
.build())
.setOperationSnapshotFactory(
(DeleteNodeRequest request, Operation response) ->
HttpJsonOperationSnapshot.create(response))
.build();
private static final ApiMethodDescriptor stopNodeMethodDescriptor =
ApiMethodDescriptor.newBuilder()
.setFullMethodName("google.cloud.tpu.v2.Tpu/StopNode")
.setHttpMethod("POST")
.setType(ApiMethodDescriptor.MethodType.UNARY)
.setRequestFormatter(
ProtoMessageRequestFormatter.newBuilder()
.setPath(
"/v2/{name=projects/*/locations/*/nodes/*}:stop",
request -> {
Map fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putPathParam(fields, "name", request.getName());
return fields;
})
.setQueryParamsExtractor(
request -> {
Map> fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int");
return fields;
})
.setRequestBodyExtractor(
request ->
ProtoRestSerializer.create()
.toBody("*", request.toBuilder().clearName().build(), true))
.build())
.setResponseParser(
ProtoMessageResponseParser.newBuilder()
.setDefaultInstance(Operation.getDefaultInstance())
.setDefaultTypeRegistry(typeRegistry)
.build())
.setOperationSnapshotFactory(
(StopNodeRequest request, Operation response) ->
HttpJsonOperationSnapshot.create(response))
.build();
private static final ApiMethodDescriptor startNodeMethodDescriptor =
ApiMethodDescriptor.newBuilder()
.setFullMethodName("google.cloud.tpu.v2.Tpu/StartNode")
.setHttpMethod("POST")
.setType(ApiMethodDescriptor.MethodType.UNARY)
.setRequestFormatter(
ProtoMessageRequestFormatter.newBuilder()
.setPath(
"/v2/{name=projects/*/locations/*/nodes/*}:start",
request -> {
Map fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putPathParam(fields, "name", request.getName());
return fields;
})
.setQueryParamsExtractor(
request -> {
Map> fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int");
return fields;
})
.setRequestBodyExtractor(
request ->
ProtoRestSerializer.create()
.toBody("*", request.toBuilder().clearName().build(), true))
.build())
.setResponseParser(
ProtoMessageResponseParser.newBuilder()
.setDefaultInstance(Operation.getDefaultInstance())
.setDefaultTypeRegistry(typeRegistry)
.build())
.setOperationSnapshotFactory(
(StartNodeRequest request, Operation response) ->
HttpJsonOperationSnapshot.create(response))
.build();
private static final ApiMethodDescriptor
updateNodeMethodDescriptor =
ApiMethodDescriptor.newBuilder()
.setFullMethodName("google.cloud.tpu.v2.Tpu/UpdateNode")
.setHttpMethod("PATCH")
.setType(ApiMethodDescriptor.MethodType.UNARY)
.setRequestFormatter(
ProtoMessageRequestFormatter.newBuilder()
.setPath(
"/v2/{node.name=projects/*/locations/*/nodes/*}",
request -> {
Map fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putPathParam(
fields, "node.name", request.getNode().getName());
return fields;
})
.setQueryParamsExtractor(
request -> {
Map> fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putQueryParam(fields, "updateMask", request.getUpdateMask());
serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int");
return fields;
})
.setRequestBodyExtractor(
request ->
ProtoRestSerializer.create().toBody("node", request.getNode(), true))
.build())
.setResponseParser(
ProtoMessageResponseParser.newBuilder()
.setDefaultInstance(Operation.getDefaultInstance())
.setDefaultTypeRegistry(typeRegistry)
.build())
.setOperationSnapshotFactory(
(UpdateNodeRequest request, Operation response) ->
HttpJsonOperationSnapshot.create(response))
.build();
private static final ApiMethodDescriptor<
GenerateServiceIdentityRequest, GenerateServiceIdentityResponse>
generateServiceIdentityMethodDescriptor =
ApiMethodDescriptor
.newBuilder()
.setFullMethodName("google.cloud.tpu.v2.Tpu/GenerateServiceIdentity")
.setHttpMethod("POST")
.setType(ApiMethodDescriptor.MethodType.UNARY)
.setRequestFormatter(
ProtoMessageRequestFormatter.newBuilder()
.setPath(
"/v2/{parent=projects/*/locations/*}:generateServiceIdentity",
request -> {
Map fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putPathParam(fields, "parent", request.getParent());
return fields;
})
.setQueryParamsExtractor(
request -> {
Map> fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int");
return fields;
})
.setRequestBodyExtractor(
request ->
ProtoRestSerializer.create()
.toBody("*", request.toBuilder().clearParent().build(), true))
.build())
.setResponseParser(
ProtoMessageResponseParser.newBuilder()
.setDefaultInstance(GenerateServiceIdentityResponse.getDefaultInstance())
.setDefaultTypeRegistry(typeRegistry)
.build())
.build();
private static final ApiMethodDescriptor<
ListAcceleratorTypesRequest, ListAcceleratorTypesResponse>
listAcceleratorTypesMethodDescriptor =
ApiMethodDescriptor
.newBuilder()
.setFullMethodName("google.cloud.tpu.v2.Tpu/ListAcceleratorTypes")
.setHttpMethod("GET")
.setType(ApiMethodDescriptor.MethodType.UNARY)
.setRequestFormatter(
ProtoMessageRequestFormatter.newBuilder()
.setPath(
"/v2/{parent=projects/*/locations/*}/acceleratorTypes",
request -> {
Map fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putPathParam(fields, "parent", request.getParent());
return fields;
})
.setQueryParamsExtractor(
request -> {
Map> fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putQueryParam(fields, "filter", request.getFilter());
serializer.putQueryParam(fields, "orderBy", request.getOrderBy());
serializer.putQueryParam(fields, "pageSize", request.getPageSize());
serializer.putQueryParam(fields, "pageToken", request.getPageToken());
serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int");
return fields;
})
.setRequestBodyExtractor(request -> null)
.build())
.setResponseParser(
ProtoMessageResponseParser.newBuilder()
.setDefaultInstance(ListAcceleratorTypesResponse.getDefaultInstance())
.setDefaultTypeRegistry(typeRegistry)
.build())
.build();
private static final ApiMethodDescriptor
getAcceleratorTypeMethodDescriptor =
ApiMethodDescriptor.newBuilder()
.setFullMethodName("google.cloud.tpu.v2.Tpu/GetAcceleratorType")
.setHttpMethod("GET")
.setType(ApiMethodDescriptor.MethodType.UNARY)
.setRequestFormatter(
ProtoMessageRequestFormatter.newBuilder()
.setPath(
"/v2/{name=projects/*/locations/*/acceleratorTypes/*}",
request -> {
Map fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putPathParam(fields, "name", request.getName());
return fields;
})
.setQueryParamsExtractor(
request -> {
Map> fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int");
return fields;
})
.setRequestBodyExtractor(request -> null)
.build())
.setResponseParser(
ProtoMessageResponseParser.newBuilder()
.setDefaultInstance(AcceleratorType.getDefaultInstance())
.setDefaultTypeRegistry(typeRegistry)
.build())
.build();
private static final ApiMethodDescriptor
listRuntimeVersionsMethodDescriptor =
ApiMethodDescriptor.newBuilder()
.setFullMethodName("google.cloud.tpu.v2.Tpu/ListRuntimeVersions")
.setHttpMethod("GET")
.setType(ApiMethodDescriptor.MethodType.UNARY)
.setRequestFormatter(
ProtoMessageRequestFormatter.newBuilder()
.setPath(
"/v2/{parent=projects/*/locations/*}/runtimeVersions",
request -> {
Map fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putPathParam(fields, "parent", request.getParent());
return fields;
})
.setQueryParamsExtractor(
request -> {
Map> fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putQueryParam(fields, "filter", request.getFilter());
serializer.putQueryParam(fields, "orderBy", request.getOrderBy());
serializer.putQueryParam(fields, "pageSize", request.getPageSize());
serializer.putQueryParam(fields, "pageToken", request.getPageToken());
serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int");
return fields;
})
.setRequestBodyExtractor(request -> null)
.build())
.setResponseParser(
ProtoMessageResponseParser.newBuilder()
.setDefaultInstance(ListRuntimeVersionsResponse.getDefaultInstance())
.setDefaultTypeRegistry(typeRegistry)
.build())
.build();
private static final ApiMethodDescriptor
getRuntimeVersionMethodDescriptor =
ApiMethodDescriptor.newBuilder()
.setFullMethodName("google.cloud.tpu.v2.Tpu/GetRuntimeVersion")
.setHttpMethod("GET")
.setType(ApiMethodDescriptor.MethodType.UNARY)
.setRequestFormatter(
ProtoMessageRequestFormatter.newBuilder()
.setPath(
"/v2/{name=projects/*/locations/*/runtimeVersions/*}",
request -> {
Map fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putPathParam(fields, "name", request.getName());
return fields;
})
.setQueryParamsExtractor(
request -> {
Map> fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int");
return fields;
})
.setRequestBodyExtractor(request -> null)
.build())
.setResponseParser(
ProtoMessageResponseParser.newBuilder()
.setDefaultInstance(RuntimeVersion.getDefaultInstance())
.setDefaultTypeRegistry(typeRegistry)
.build())
.build();
private static final ApiMethodDescriptor
getGuestAttributesMethodDescriptor =
ApiMethodDescriptor.newBuilder()
.setFullMethodName("google.cloud.tpu.v2.Tpu/GetGuestAttributes")
.setHttpMethod("POST")
.setType(ApiMethodDescriptor.MethodType.UNARY)
.setRequestFormatter(
ProtoMessageRequestFormatter.newBuilder()
.setPath(
"/v2/{name=projects/*/locations/*/nodes/*}:getGuestAttributes",
request -> {
Map fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putPathParam(fields, "name", request.getName());
return fields;
})
.setQueryParamsExtractor(
request -> {
Map> fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int");
return fields;
})
.setRequestBodyExtractor(
request ->
ProtoRestSerializer.create()
.toBody("*", request.toBuilder().clearName().build(), true))
.build())
.setResponseParser(
ProtoMessageResponseParser.newBuilder()
.setDefaultInstance(GetGuestAttributesResponse.getDefaultInstance())
.setDefaultTypeRegistry(typeRegistry)
.build())
.build();
private static final ApiMethodDescriptor
listLocationsMethodDescriptor =
ApiMethodDescriptor.newBuilder()
.setFullMethodName("google.cloud.location.Locations/ListLocations")
.setHttpMethod("GET")
.setType(ApiMethodDescriptor.MethodType.UNARY)
.setRequestFormatter(
ProtoMessageRequestFormatter.newBuilder()
.setPath(
"/v2/{name=projects/*}/locations",
request -> {
Map fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putPathParam(fields, "name", request.getName());
return fields;
})
.setQueryParamsExtractor(
request -> {
Map> fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int");
return fields;
})
.setRequestBodyExtractor(request -> null)
.build())
.setResponseParser(
ProtoMessageResponseParser.newBuilder()
.setDefaultInstance(ListLocationsResponse.getDefaultInstance())
.setDefaultTypeRegistry(typeRegistry)
.build())
.build();
private static final ApiMethodDescriptor
getLocationMethodDescriptor =
ApiMethodDescriptor.newBuilder()
.setFullMethodName("google.cloud.location.Locations/GetLocation")
.setHttpMethod("GET")
.setType(ApiMethodDescriptor.MethodType.UNARY)
.setRequestFormatter(
ProtoMessageRequestFormatter.newBuilder()
.setPath(
"/v2/{name=projects/*/locations/*}",
request -> {
Map fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putPathParam(fields, "name", request.getName());
return fields;
})
.setQueryParamsExtractor(
request -> {
Map> fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int");
return fields;
})
.setRequestBodyExtractor(request -> null)
.build())
.setResponseParser(
ProtoMessageResponseParser.newBuilder()
.setDefaultInstance(Location.getDefaultInstance())
.setDefaultTypeRegistry(typeRegistry)
.build())
.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 stopNodeCallable;
private final OperationCallable
stopNodeOperationCallable;
private final UnaryCallable startNodeCallable;
private final OperationCallable
startNodeOperationCallable;
private final UnaryCallable updateNodeCallable;
private final OperationCallable
updateNodeOperationCallable;
private final UnaryCallable
generateServiceIdentityCallable;
private final UnaryCallable
listAcceleratorTypesCallable;
private final UnaryCallable
listAcceleratorTypesPagedCallable;
private final UnaryCallable
getAcceleratorTypeCallable;
private final UnaryCallable
listRuntimeVersionsCallable;
private final UnaryCallable
listRuntimeVersionsPagedCallable;
private final UnaryCallable getRuntimeVersionCallable;
private final UnaryCallable
getGuestAttributesCallable;
private final UnaryCallable listLocationsCallable;
private final UnaryCallable
listLocationsPagedCallable;
private final UnaryCallable getLocationCallable;
private final BackgroundResource backgroundResources;
private final HttpJsonOperationsStub httpJsonOperationsStub;
private final HttpJsonStubCallableFactory callableFactory;
public static final HttpJsonTpuStub create(TpuStubSettings settings) throws IOException {
return new HttpJsonTpuStub(settings, ClientContext.create(settings));
}
public static final HttpJsonTpuStub create(ClientContext clientContext) throws IOException {
return new HttpJsonTpuStub(TpuStubSettings.newHttpJsonBuilder().build(), clientContext);
}
public static final HttpJsonTpuStub create(
ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException {
return new HttpJsonTpuStub(
TpuStubSettings.newHttpJsonBuilder().build(), clientContext, callableFactory);
}
/**
* Constructs an instance of HttpJsonTpuStub, 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 HttpJsonTpuStub(TpuStubSettings settings, ClientContext clientContext)
throws IOException {
this(settings, clientContext, new HttpJsonTpuCallableFactory());
}
/**
* Constructs an instance of HttpJsonTpuStub, 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 HttpJsonTpuStub(
TpuStubSettings settings,
ClientContext clientContext,
HttpJsonStubCallableFactory callableFactory)
throws IOException {
this.callableFactory = callableFactory;
this.httpJsonOperationsStub =
HttpJsonOperationsStub.create(
clientContext,
callableFactory,
typeRegistry,
ImmutableMap.builder()
.put(
"google.longrunning.Operations.CancelOperation",
HttpRule.newBuilder()
.setPost("/v2/{name=projects/*/locations/*/operations/*}:cancel")
.build())
.put(
"google.longrunning.Operations.DeleteOperation",
HttpRule.newBuilder()
.setDelete("/v2/{name=projects/*/locations/*/operations/*}")
.build())
.put(
"google.longrunning.Operations.GetOperation",
HttpRule.newBuilder()
.setGet("/v2/{name=projects/*/locations/*/operations/*}")
.build())
.put(
"google.longrunning.Operations.ListOperations",
HttpRule.newBuilder()
.setGet("/v2/{name=projects/*/locations/*}/operations")
.build())
.build());
HttpJsonCallSettings listNodesTransportSettings =
HttpJsonCallSettings.newBuilder()
.setMethodDescriptor(listNodesMethodDescriptor)
.setTypeRegistry(typeRegistry)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("parent", String.valueOf(request.getParent()));
return builder.build();
})
.build();
HttpJsonCallSettings getNodeTransportSettings =
HttpJsonCallSettings.newBuilder()
.setMethodDescriptor(getNodeMethodDescriptor)
.setTypeRegistry(typeRegistry)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("name", String.valueOf(request.getName()));
return builder.build();
})
.build();
HttpJsonCallSettings createNodeTransportSettings =
HttpJsonCallSettings.newBuilder()
.setMethodDescriptor(createNodeMethodDescriptor)
.setTypeRegistry(typeRegistry)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("parent", String.valueOf(request.getParent()));
return builder.build();
})
.build();
HttpJsonCallSettings deleteNodeTransportSettings =
HttpJsonCallSettings.newBuilder()
.setMethodDescriptor(deleteNodeMethodDescriptor)
.setTypeRegistry(typeRegistry)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("name", String.valueOf(request.getName()));
return builder.build();
})
.build();
HttpJsonCallSettings stopNodeTransportSettings =
HttpJsonCallSettings.newBuilder()
.setMethodDescriptor(stopNodeMethodDescriptor)
.setTypeRegistry(typeRegistry)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("name", String.valueOf(request.getName()));
return builder.build();
})
.build();
HttpJsonCallSettings startNodeTransportSettings =
HttpJsonCallSettings.newBuilder()
.setMethodDescriptor(startNodeMethodDescriptor)
.setTypeRegistry(typeRegistry)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("name", String.valueOf(request.getName()));
return builder.build();
})
.build();
HttpJsonCallSettings updateNodeTransportSettings =
HttpJsonCallSettings.newBuilder()
.setMethodDescriptor(updateNodeMethodDescriptor)
.setTypeRegistry(typeRegistry)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("node.name", String.valueOf(request.getNode().getName()));
return builder.build();
})
.build();
HttpJsonCallSettings
generateServiceIdentityTransportSettings =
HttpJsonCallSettings
.newBuilder()
.setMethodDescriptor(generateServiceIdentityMethodDescriptor)
.setTypeRegistry(typeRegistry)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("parent", String.valueOf(request.getParent()));
return builder.build();
})
.build();
HttpJsonCallSettings
listAcceleratorTypesTransportSettings =
HttpJsonCallSettings
.newBuilder()
.setMethodDescriptor(listAcceleratorTypesMethodDescriptor)
.setTypeRegistry(typeRegistry)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("parent", String.valueOf(request.getParent()));
return builder.build();
})
.build();
HttpJsonCallSettings
getAcceleratorTypeTransportSettings =
HttpJsonCallSettings.newBuilder()
.setMethodDescriptor(getAcceleratorTypeMethodDescriptor)
.setTypeRegistry(typeRegistry)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("name", String.valueOf(request.getName()));
return builder.build();
})
.build();
HttpJsonCallSettings
listRuntimeVersionsTransportSettings =
HttpJsonCallSettings
.newBuilder()
.setMethodDescriptor(listRuntimeVersionsMethodDescriptor)
.setTypeRegistry(typeRegistry)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("parent", String.valueOf(request.getParent()));
return builder.build();
})
.build();
HttpJsonCallSettings
getRuntimeVersionTransportSettings =
HttpJsonCallSettings.newBuilder()
.setMethodDescriptor(getRuntimeVersionMethodDescriptor)
.setTypeRegistry(typeRegistry)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("name", String.valueOf(request.getName()));
return builder.build();
})
.build();
HttpJsonCallSettings
getGuestAttributesTransportSettings =
HttpJsonCallSettings.newBuilder()
.setMethodDescriptor(getGuestAttributesMethodDescriptor)
.setTypeRegistry(typeRegistry)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("name", String.valueOf(request.getName()));
return builder.build();
})
.build();
HttpJsonCallSettings
listLocationsTransportSettings =
HttpJsonCallSettings.newBuilder()
.setMethodDescriptor(listLocationsMethodDescriptor)
.setTypeRegistry(typeRegistry)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("name", String.valueOf(request.getName()));
return builder.build();
})
.build();
HttpJsonCallSettings getLocationTransportSettings =
HttpJsonCallSettings.newBuilder()
.setMethodDescriptor(getLocationMethodDescriptor)
.setTypeRegistry(typeRegistry)
.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,
httpJsonOperationsStub);
this.deleteNodeCallable =
callableFactory.createUnaryCallable(
deleteNodeTransportSettings, settings.deleteNodeSettings(), clientContext);
this.deleteNodeOperationCallable =
callableFactory.createOperationCallable(
deleteNodeTransportSettings,
settings.deleteNodeOperationSettings(),
clientContext,
httpJsonOperationsStub);
this.stopNodeCallable =
callableFactory.createUnaryCallable(
stopNodeTransportSettings, settings.stopNodeSettings(), clientContext);
this.stopNodeOperationCallable =
callableFactory.createOperationCallable(
stopNodeTransportSettings,
settings.stopNodeOperationSettings(),
clientContext,
httpJsonOperationsStub);
this.startNodeCallable =
callableFactory.createUnaryCallable(
startNodeTransportSettings, settings.startNodeSettings(), clientContext);
this.startNodeOperationCallable =
callableFactory.createOperationCallable(
startNodeTransportSettings,
settings.startNodeOperationSettings(),
clientContext,
httpJsonOperationsStub);
this.updateNodeCallable =
callableFactory.createUnaryCallable(
updateNodeTransportSettings, settings.updateNodeSettings(), clientContext);
this.updateNodeOperationCallable =
callableFactory.createOperationCallable(
updateNodeTransportSettings,
settings.updateNodeOperationSettings(),
clientContext,
httpJsonOperationsStub);
this.generateServiceIdentityCallable =
callableFactory.createUnaryCallable(
generateServiceIdentityTransportSettings,
settings.generateServiceIdentitySettings(),
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.listRuntimeVersionsCallable =
callableFactory.createUnaryCallable(
listRuntimeVersionsTransportSettings,
settings.listRuntimeVersionsSettings(),
clientContext);
this.listRuntimeVersionsPagedCallable =
callableFactory.createPagedCallable(
listRuntimeVersionsTransportSettings,
settings.listRuntimeVersionsSettings(),
clientContext);
this.getRuntimeVersionCallable =
callableFactory.createUnaryCallable(
getRuntimeVersionTransportSettings,
settings.getRuntimeVersionSettings(),
clientContext);
this.getGuestAttributesCallable =
callableFactory.createUnaryCallable(
getGuestAttributesTransportSettings,
settings.getGuestAttributesSettings(),
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());
}
@InternalApi
public static List getMethodDescriptors() {
List methodDescriptors = new ArrayList<>();
methodDescriptors.add(listNodesMethodDescriptor);
methodDescriptors.add(getNodeMethodDescriptor);
methodDescriptors.add(createNodeMethodDescriptor);
methodDescriptors.add(deleteNodeMethodDescriptor);
methodDescriptors.add(stopNodeMethodDescriptor);
methodDescriptors.add(startNodeMethodDescriptor);
methodDescriptors.add(updateNodeMethodDescriptor);
methodDescriptors.add(generateServiceIdentityMethodDescriptor);
methodDescriptors.add(listAcceleratorTypesMethodDescriptor);
methodDescriptors.add(getAcceleratorTypeMethodDescriptor);
methodDescriptors.add(listRuntimeVersionsMethodDescriptor);
methodDescriptors.add(getRuntimeVersionMethodDescriptor);
methodDescriptors.add(getGuestAttributesMethodDescriptor);
methodDescriptors.add(listLocationsMethodDescriptor);
methodDescriptors.add(getLocationMethodDescriptor);
return methodDescriptors;
}
public HttpJsonOperationsStub getHttpJsonOperationsStub() {
return httpJsonOperationsStub;
}
@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 stopNodeCallable() {
return stopNodeCallable;
}
@Override
public OperationCallable stopNodeOperationCallable() {
return stopNodeOperationCallable;
}
@Override
public UnaryCallable startNodeCallable() {
return startNodeCallable;
}
@Override
public OperationCallable startNodeOperationCallable() {
return startNodeOperationCallable;
}
@Override
public UnaryCallable updateNodeCallable() {
return updateNodeCallable;
}
@Override
public OperationCallable
updateNodeOperationCallable() {
return updateNodeOperationCallable;
}
@Override
public UnaryCallable
generateServiceIdentityCallable() {
return generateServiceIdentityCallable;
}
@Override
public UnaryCallable
listAcceleratorTypesCallable() {
return listAcceleratorTypesCallable;
}
@Override
public UnaryCallable
listAcceleratorTypesPagedCallable() {
return listAcceleratorTypesPagedCallable;
}
@Override
public UnaryCallable getAcceleratorTypeCallable() {
return getAcceleratorTypeCallable;
}
@Override
public UnaryCallable
listRuntimeVersionsCallable() {
return listRuntimeVersionsCallable;
}
@Override
public UnaryCallable
listRuntimeVersionsPagedCallable() {
return listRuntimeVersionsPagedCallable;
}
@Override
public UnaryCallable getRuntimeVersionCallable() {
return getRuntimeVersionCallable;
}
@Override
public UnaryCallable
getGuestAttributesCallable() {
return getGuestAttributesCallable;
}
@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);
}
}