com.google.cloud.tpu.v1.stub.TpuStubSettings Maven / Gradle / Ivy
Show all versions of google-cloud-tpu Show documentation
/*
* 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.core.ApiFunction;
import com.google.api.core.ApiFuture;
import com.google.api.core.ObsoleteApi;
import com.google.api.gax.core.GaxProperties;
import com.google.api.gax.core.GoogleCredentialsProvider;
import com.google.api.gax.core.InstantiatingExecutorProvider;
import com.google.api.gax.grpc.GaxGrpcProperties;
import com.google.api.gax.grpc.GrpcTransportChannel;
import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
import com.google.api.gax.grpc.ProtoOperationTransformers;
import com.google.api.gax.longrunning.OperationSnapshot;
import com.google.api.gax.longrunning.OperationTimedPollAlgorithm;
import com.google.api.gax.retrying.RetrySettings;
import com.google.api.gax.rpc.ApiCallContext;
import com.google.api.gax.rpc.ApiClientHeaderProvider;
import com.google.api.gax.rpc.ClientContext;
import com.google.api.gax.rpc.OperationCallSettings;
import com.google.api.gax.rpc.PageContext;
import com.google.api.gax.rpc.PagedCallSettings;
import com.google.api.gax.rpc.PagedListDescriptor;
import com.google.api.gax.rpc.PagedListResponseFactory;
import com.google.api.gax.rpc.StatusCode;
import com.google.api.gax.rpc.StubSettings;
import com.google.api.gax.rpc.TransportChannelProvider;
import com.google.api.gax.rpc.UnaryCallSettings;
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.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import com.google.longrunning.Operation;
import java.io.IOException;
import java.time.Duration;
import java.util.List;
import javax.annotation.Generated;
// AUTO-GENERATED DOCUMENTATION AND CLASS.
/**
* Settings class to configure an instance of {@link TpuStub}.
*
* The default instance has everything set to sensible defaults:
*
*
* - The default service address (tpu.googleapis.com) and default port (443) are used.
*
- Credentials are acquired automatically through Application Default Credentials.
*
- Retries are configured for idempotent methods but not for non-idempotent methods.
*
*
* The builder of this class is recursive, so contained classes are themselves builders. When
* build() is called, the tree of builders is called to create the complete settings object.
*
*
For example, to set the
* [RetrySettings](https://cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.retrying.RetrySettings)
* of getNode:
*
*
{@code
* // This snippet has been automatically generated and should be regarded as a code template only.
* // It will require modifications to work:
* // - It may require correct/in-range values for request initialization.
* // - It may require specifying regional endpoints when creating the service client as shown in
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
* TpuStubSettings.Builder tpuSettingsBuilder = TpuStubSettings.newBuilder();
* tpuSettingsBuilder
* .getNodeSettings()
* .setRetrySettings(
* tpuSettingsBuilder
* .getNodeSettings()
* .getRetrySettings()
* .toBuilder()
* .setInitialRetryDelayDuration(Duration.ofSeconds(1))
* .setInitialRpcTimeoutDuration(Duration.ofSeconds(5))
* .setMaxAttempts(5)
* .setMaxRetryDelayDuration(Duration.ofSeconds(30))
* .setMaxRpcTimeoutDuration(Duration.ofSeconds(60))
* .setRetryDelayMultiplier(1.3)
* .setRpcTimeoutMultiplier(1.5)
* .setTotalTimeoutDuration(Duration.ofSeconds(300))
* .build());
* TpuStubSettings tpuSettings = tpuSettingsBuilder.build();
* }
*
* Please refer to the [Client Side Retry
* Guide](https://github.com/googleapis/google-cloud-java/blob/main/docs/client_retries.md) for
* additional support in setting retries.
*
* To configure the RetrySettings of a Long Running Operation method, create an
* OperationTimedPollAlgorithm object and update the RPC's polling algorithm. For example, to
* configure the RetrySettings for createNode:
*
*
{@code
* // This snippet has been automatically generated and should be regarded as a code template only.
* // It will require modifications to work:
* // - It may require correct/in-range values for request initialization.
* // - It may require specifying regional endpoints when creating the service client as shown in
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
* TpuStubSettings.Builder tpuSettingsBuilder = TpuStubSettings.newBuilder();
* TimedRetryAlgorithm timedRetryAlgorithm =
* OperationalTimedPollAlgorithm.create(
* RetrySettings.newBuilder()
* .setInitialRetryDelayDuration(Duration.ofMillis(500))
* .setRetryDelayMultiplier(1.5)
* .setMaxRetryDelayDuration(Duration.ofMillis(5000))
* .setTotalTimeoutDuration(Duration.ofHours(24))
* .build());
* tpuSettingsBuilder
* .createClusterOperationSettings()
* .setPollingAlgorithm(timedRetryAlgorithm)
* .build();
* }
*/
@Generated("by gapic-generator-java")
public class TpuStubSettings extends StubSettings {
/** The default scopes of the service. */
private static final ImmutableList DEFAULT_SERVICE_SCOPES =
ImmutableList.builder().add("https://www.googleapis.com/auth/cloud-platform").build();
private final PagedCallSettings
listNodesSettings;
private final UnaryCallSettings getNodeSettings;
private final UnaryCallSettings createNodeSettings;
private final OperationCallSettings
createNodeOperationSettings;
private final UnaryCallSettings deleteNodeSettings;
private final OperationCallSettings
deleteNodeOperationSettings;
private final UnaryCallSettings reimageNodeSettings;
private final OperationCallSettings
reimageNodeOperationSettings;
private final UnaryCallSettings stopNodeSettings;
private final OperationCallSettings
stopNodeOperationSettings;
private final UnaryCallSettings startNodeSettings;
private final OperationCallSettings
startNodeOperationSettings;
private final PagedCallSettings<
ListTensorFlowVersionsRequest,
ListTensorFlowVersionsResponse,
ListTensorFlowVersionsPagedResponse>
listTensorFlowVersionsSettings;
private final UnaryCallSettings
getTensorFlowVersionSettings;
private final PagedCallSettings<
ListAcceleratorTypesRequest,
ListAcceleratorTypesResponse,
ListAcceleratorTypesPagedResponse>
listAcceleratorTypesSettings;
private final UnaryCallSettings
getAcceleratorTypeSettings;
private final PagedCallSettings<
ListLocationsRequest, ListLocationsResponse, ListLocationsPagedResponse>
listLocationsSettings;
private final UnaryCallSettings getLocationSettings;
private static final PagedListDescriptor
LIST_NODES_PAGE_STR_DESC =
new PagedListDescriptor() {
@Override
public String emptyToken() {
return "";
}
@Override
public ListNodesRequest injectToken(ListNodesRequest payload, String token) {
return ListNodesRequest.newBuilder(payload).setPageToken(token).build();
}
@Override
public ListNodesRequest injectPageSize(ListNodesRequest payload, int pageSize) {
return ListNodesRequest.newBuilder(payload).setPageSize(pageSize).build();
}
@Override
public Integer extractPageSize(ListNodesRequest payload) {
return payload.getPageSize();
}
@Override
public String extractNextToken(ListNodesResponse payload) {
return payload.getNextPageToken();
}
@Override
public Iterable extractResources(ListNodesResponse payload) {
return payload.getNodesList();
}
};
private static final PagedListDescriptor<
ListTensorFlowVersionsRequest, ListTensorFlowVersionsResponse, TensorFlowVersion>
LIST_TENSOR_FLOW_VERSIONS_PAGE_STR_DESC =
new PagedListDescriptor<
ListTensorFlowVersionsRequest, ListTensorFlowVersionsResponse, TensorFlowVersion>() {
@Override
public String emptyToken() {
return "";
}
@Override
public ListTensorFlowVersionsRequest injectToken(
ListTensorFlowVersionsRequest payload, String token) {
return ListTensorFlowVersionsRequest.newBuilder(payload).setPageToken(token).build();
}
@Override
public ListTensorFlowVersionsRequest injectPageSize(
ListTensorFlowVersionsRequest payload, int pageSize) {
return ListTensorFlowVersionsRequest.newBuilder(payload)
.setPageSize(pageSize)
.build();
}
@Override
public Integer extractPageSize(ListTensorFlowVersionsRequest payload) {
return payload.getPageSize();
}
@Override
public String extractNextToken(ListTensorFlowVersionsResponse payload) {
return payload.getNextPageToken();
}
@Override
public Iterable extractResources(
ListTensorFlowVersionsResponse payload) {
return payload.getTensorflowVersionsList();
}
};
private static final PagedListDescriptor<
ListAcceleratorTypesRequest, ListAcceleratorTypesResponse, AcceleratorType>
LIST_ACCELERATOR_TYPES_PAGE_STR_DESC =
new PagedListDescriptor<
ListAcceleratorTypesRequest, ListAcceleratorTypesResponse, AcceleratorType>() {
@Override
public String emptyToken() {
return "";
}
@Override
public ListAcceleratorTypesRequest injectToken(
ListAcceleratorTypesRequest payload, String token) {
return ListAcceleratorTypesRequest.newBuilder(payload).setPageToken(token).build();
}
@Override
public ListAcceleratorTypesRequest injectPageSize(
ListAcceleratorTypesRequest payload, int pageSize) {
return ListAcceleratorTypesRequest.newBuilder(payload).setPageSize(pageSize).build();
}
@Override
public Integer extractPageSize(ListAcceleratorTypesRequest payload) {
return payload.getPageSize();
}
@Override
public String extractNextToken(ListAcceleratorTypesResponse payload) {
return payload.getNextPageToken();
}
@Override
public Iterable extractResources(
ListAcceleratorTypesResponse payload) {
return payload.getAcceleratorTypesList();
}
};
private static final PagedListDescriptor
LIST_LOCATIONS_PAGE_STR_DESC =
new PagedListDescriptor() {
@Override
public String emptyToken() {
return "";
}
@Override
public ListLocationsRequest injectToken(ListLocationsRequest payload, String token) {
return ListLocationsRequest.newBuilder(payload).setPageToken(token).build();
}
@Override
public ListLocationsRequest injectPageSize(ListLocationsRequest payload, int pageSize) {
return ListLocationsRequest.newBuilder(payload).setPageSize(pageSize).build();
}
@Override
public Integer extractPageSize(ListLocationsRequest payload) {
return payload.getPageSize();
}
@Override
public String extractNextToken(ListLocationsResponse payload) {
return payload.getNextPageToken();
}
@Override
public Iterable extractResources(ListLocationsResponse payload) {
return payload.getLocationsList();
}
};
private static final PagedListResponseFactory<
ListNodesRequest, ListNodesResponse, ListNodesPagedResponse>
LIST_NODES_PAGE_STR_FACT =
new PagedListResponseFactory<
ListNodesRequest, ListNodesResponse, ListNodesPagedResponse>() {
@Override
public ApiFuture getFuturePagedResponse(
UnaryCallable callable,
ListNodesRequest request,
ApiCallContext context,
ApiFuture futureResponse) {
PageContext pageContext =
PageContext.create(callable, LIST_NODES_PAGE_STR_DESC, request, context);
return ListNodesPagedResponse.createAsync(pageContext, futureResponse);
}
};
private static final PagedListResponseFactory<
ListTensorFlowVersionsRequest,
ListTensorFlowVersionsResponse,
ListTensorFlowVersionsPagedResponse>
LIST_TENSOR_FLOW_VERSIONS_PAGE_STR_FACT =
new PagedListResponseFactory<
ListTensorFlowVersionsRequest,
ListTensorFlowVersionsResponse,
ListTensorFlowVersionsPagedResponse>() {
@Override
public ApiFuture getFuturePagedResponse(
UnaryCallable
callable,
ListTensorFlowVersionsRequest request,
ApiCallContext context,
ApiFuture futureResponse) {
PageContext<
ListTensorFlowVersionsRequest,
ListTensorFlowVersionsResponse,
TensorFlowVersion>
pageContext =
PageContext.create(
callable, LIST_TENSOR_FLOW_VERSIONS_PAGE_STR_DESC, request, context);
return ListTensorFlowVersionsPagedResponse.createAsync(pageContext, futureResponse);
}
};
private static final PagedListResponseFactory<
ListAcceleratorTypesRequest,
ListAcceleratorTypesResponse,
ListAcceleratorTypesPagedResponse>
LIST_ACCELERATOR_TYPES_PAGE_STR_FACT =
new PagedListResponseFactory<
ListAcceleratorTypesRequest,
ListAcceleratorTypesResponse,
ListAcceleratorTypesPagedResponse>() {
@Override
public ApiFuture getFuturePagedResponse(
UnaryCallable callable,
ListAcceleratorTypesRequest request,
ApiCallContext context,
ApiFuture futureResponse) {
PageContext<
ListAcceleratorTypesRequest, ListAcceleratorTypesResponse, AcceleratorType>
pageContext =
PageContext.create(
callable, LIST_ACCELERATOR_TYPES_PAGE_STR_DESC, request, context);
return ListAcceleratorTypesPagedResponse.createAsync(pageContext, futureResponse);
}
};
private static final PagedListResponseFactory<
ListLocationsRequest, ListLocationsResponse, ListLocationsPagedResponse>
LIST_LOCATIONS_PAGE_STR_FACT =
new PagedListResponseFactory<
ListLocationsRequest, ListLocationsResponse, ListLocationsPagedResponse>() {
@Override
public ApiFuture getFuturePagedResponse(
UnaryCallable callable,
ListLocationsRequest request,
ApiCallContext context,
ApiFuture futureResponse) {
PageContext pageContext =
PageContext.create(callable, LIST_LOCATIONS_PAGE_STR_DESC, request, context);
return ListLocationsPagedResponse.createAsync(pageContext, futureResponse);
}
};
/** Returns the object with the settings used for calls to listNodes. */
public PagedCallSettings
listNodesSettings() {
return listNodesSettings;
}
/** Returns the object with the settings used for calls to getNode. */
public UnaryCallSettings getNodeSettings() {
return getNodeSettings;
}
/** Returns the object with the settings used for calls to createNode. */
public UnaryCallSettings createNodeSettings() {
return createNodeSettings;
}
/** Returns the object with the settings used for calls to createNode. */
public OperationCallSettings
createNodeOperationSettings() {
return createNodeOperationSettings;
}
/** Returns the object with the settings used for calls to deleteNode. */
public UnaryCallSettings deleteNodeSettings() {
return deleteNodeSettings;
}
/** Returns the object with the settings used for calls to deleteNode. */
public OperationCallSettings
deleteNodeOperationSettings() {
return deleteNodeOperationSettings;
}
/** Returns the object with the settings used for calls to reimageNode. */
public UnaryCallSettings reimageNodeSettings() {
return reimageNodeSettings;
}
/** Returns the object with the settings used for calls to reimageNode. */
public OperationCallSettings
reimageNodeOperationSettings() {
return reimageNodeOperationSettings;
}
/** Returns the object with the settings used for calls to stopNode. */
public UnaryCallSettings stopNodeSettings() {
return stopNodeSettings;
}
/** Returns the object with the settings used for calls to stopNode. */
public OperationCallSettings
stopNodeOperationSettings() {
return stopNodeOperationSettings;
}
/** Returns the object with the settings used for calls to startNode. */
public UnaryCallSettings startNodeSettings() {
return startNodeSettings;
}
/** Returns the object with the settings used for calls to startNode. */
public OperationCallSettings
startNodeOperationSettings() {
return startNodeOperationSettings;
}
/** Returns the object with the settings used for calls to listTensorFlowVersions. */
public PagedCallSettings<
ListTensorFlowVersionsRequest,
ListTensorFlowVersionsResponse,
ListTensorFlowVersionsPagedResponse>
listTensorFlowVersionsSettings() {
return listTensorFlowVersionsSettings;
}
/** Returns the object with the settings used for calls to getTensorFlowVersion. */
public UnaryCallSettings
getTensorFlowVersionSettings() {
return getTensorFlowVersionSettings;
}
/** Returns the object with the settings used for calls to listAcceleratorTypes. */
public PagedCallSettings<
ListAcceleratorTypesRequest,
ListAcceleratorTypesResponse,
ListAcceleratorTypesPagedResponse>
listAcceleratorTypesSettings() {
return listAcceleratorTypesSettings;
}
/** Returns the object with the settings used for calls to getAcceleratorType. */
public UnaryCallSettings
getAcceleratorTypeSettings() {
return getAcceleratorTypeSettings;
}
/** Returns the object with the settings used for calls to listLocations. */
public PagedCallSettings
listLocationsSettings() {
return listLocationsSettings;
}
/** Returns the object with the settings used for calls to getLocation. */
public UnaryCallSettings getLocationSettings() {
return getLocationSettings;
}
public TpuStub createStub() throws IOException {
if (getTransportChannelProvider()
.getTransportName()
.equals(GrpcTransportChannel.getGrpcTransportName())) {
return GrpcTpuStub.create(this);
}
throw new UnsupportedOperationException(
String.format(
"Transport not supported: %s", getTransportChannelProvider().getTransportName()));
}
/** Returns the default service name. */
@Override
public String getServiceName() {
return "tpu";
}
/** Returns a builder for the default ExecutorProvider for this service. */
public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() {
return InstantiatingExecutorProvider.newBuilder();
}
/** Returns the default service endpoint. */
@ObsoleteApi("Use getEndpoint() instead")
public static String getDefaultEndpoint() {
return "tpu.googleapis.com:443";
}
/** Returns the default mTLS service endpoint. */
public static String getDefaultMtlsEndpoint() {
return "tpu.mtls.googleapis.com:443";
}
/** Returns the default service scopes. */
public static List getDefaultServiceScopes() {
return DEFAULT_SERVICE_SCOPES;
}
/** Returns a builder for the default credentials for this service. */
public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilder() {
return GoogleCredentialsProvider.newBuilder()
.setScopesToApply(DEFAULT_SERVICE_SCOPES)
.setUseJwtAccessWithScope(true);
}
/** Returns a builder for the default ChannelProvider for this service. */
public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() {
return InstantiatingGrpcChannelProvider.newBuilder()
.setMaxInboundMessageSize(Integer.MAX_VALUE);
}
public static TransportChannelProvider defaultTransportChannelProvider() {
return defaultGrpcTransportProviderBuilder().build();
}
public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() {
return ApiClientHeaderProvider.newBuilder()
.setGeneratedLibToken("gapic", GaxProperties.getLibraryVersion(TpuStubSettings.class))
.setTransportToken(
GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion());
}
/** Returns a new builder for this class. */
public static Builder newBuilder() {
return Builder.createDefault();
}
/** Returns a new builder for this class. */
public static Builder newBuilder(ClientContext clientContext) {
return new Builder(clientContext);
}
/** Returns a builder containing all the values of this settings class. */
public Builder toBuilder() {
return new Builder(this);
}
protected TpuStubSettings(Builder settingsBuilder) throws IOException {
super(settingsBuilder);
listNodesSettings = settingsBuilder.listNodesSettings().build();
getNodeSettings = settingsBuilder.getNodeSettings().build();
createNodeSettings = settingsBuilder.createNodeSettings().build();
createNodeOperationSettings = settingsBuilder.createNodeOperationSettings().build();
deleteNodeSettings = settingsBuilder.deleteNodeSettings().build();
deleteNodeOperationSettings = settingsBuilder.deleteNodeOperationSettings().build();
reimageNodeSettings = settingsBuilder.reimageNodeSettings().build();
reimageNodeOperationSettings = settingsBuilder.reimageNodeOperationSettings().build();
stopNodeSettings = settingsBuilder.stopNodeSettings().build();
stopNodeOperationSettings = settingsBuilder.stopNodeOperationSettings().build();
startNodeSettings = settingsBuilder.startNodeSettings().build();
startNodeOperationSettings = settingsBuilder.startNodeOperationSettings().build();
listTensorFlowVersionsSettings = settingsBuilder.listTensorFlowVersionsSettings().build();
getTensorFlowVersionSettings = settingsBuilder.getTensorFlowVersionSettings().build();
listAcceleratorTypesSettings = settingsBuilder.listAcceleratorTypesSettings().build();
getAcceleratorTypeSettings = settingsBuilder.getAcceleratorTypeSettings().build();
listLocationsSettings = settingsBuilder.listLocationsSettings().build();
getLocationSettings = settingsBuilder.getLocationSettings().build();
}
/** Builder for TpuStubSettings. */
public static class Builder extends StubSettings.Builder {
private final ImmutableList> unaryMethodSettingsBuilders;
private final PagedCallSettings.Builder<
ListNodesRequest, ListNodesResponse, ListNodesPagedResponse>
listNodesSettings;
private final UnaryCallSettings.Builder getNodeSettings;
private final UnaryCallSettings.Builder createNodeSettings;
private final OperationCallSettings.Builder
createNodeOperationSettings;
private final UnaryCallSettings.Builder deleteNodeSettings;
private final OperationCallSettings.Builder
deleteNodeOperationSettings;
private final UnaryCallSettings.Builder reimageNodeSettings;
private final OperationCallSettings.Builder
reimageNodeOperationSettings;
private final UnaryCallSettings.Builder stopNodeSettings;
private final OperationCallSettings.Builder
stopNodeOperationSettings;
private final UnaryCallSettings.Builder startNodeSettings;
private final OperationCallSettings.Builder
startNodeOperationSettings;
private final PagedCallSettings.Builder<
ListTensorFlowVersionsRequest,
ListTensorFlowVersionsResponse,
ListTensorFlowVersionsPagedResponse>
listTensorFlowVersionsSettings;
private final UnaryCallSettings.Builder
getTensorFlowVersionSettings;
private final PagedCallSettings.Builder<
ListAcceleratorTypesRequest,
ListAcceleratorTypesResponse,
ListAcceleratorTypesPagedResponse>
listAcceleratorTypesSettings;
private final UnaryCallSettings.Builder
getAcceleratorTypeSettings;
private final PagedCallSettings.Builder<
ListLocationsRequest, ListLocationsResponse, ListLocationsPagedResponse>
listLocationsSettings;
private final UnaryCallSettings.Builder getLocationSettings;
private static final ImmutableMap>
RETRYABLE_CODE_DEFINITIONS;
static {
ImmutableMap.Builder> definitions =
ImmutableMap.builder();
definitions.put(
"no_retry_0_codes", ImmutableSet.copyOf(Lists.newArrayList()));
RETRYABLE_CODE_DEFINITIONS = definitions.build();
}
private static final ImmutableMap RETRY_PARAM_DEFINITIONS;
static {
ImmutableMap.Builder definitions = ImmutableMap.builder();
RetrySettings settings = null;
settings =
RetrySettings.newBuilder()
.setInitialRpcTimeoutDuration(Duration.ofMillis(60000L))
.setRpcTimeoutMultiplier(1.0)
.setMaxRpcTimeoutDuration(Duration.ofMillis(60000L))
.setTotalTimeoutDuration(Duration.ofMillis(60000L))
.build();
definitions.put("no_retry_0_params", settings);
RETRY_PARAM_DEFINITIONS = definitions.build();
}
protected Builder() {
this(((ClientContext) null));
}
protected Builder(ClientContext clientContext) {
super(clientContext);
listNodesSettings = PagedCallSettings.newBuilder(LIST_NODES_PAGE_STR_FACT);
getNodeSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
createNodeSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
createNodeOperationSettings = OperationCallSettings.newBuilder();
deleteNodeSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
deleteNodeOperationSettings = OperationCallSettings.newBuilder();
reimageNodeSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
reimageNodeOperationSettings = OperationCallSettings.newBuilder();
stopNodeSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
stopNodeOperationSettings = OperationCallSettings.newBuilder();
startNodeSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
startNodeOperationSettings = OperationCallSettings.newBuilder();
listTensorFlowVersionsSettings =
PagedCallSettings.newBuilder(LIST_TENSOR_FLOW_VERSIONS_PAGE_STR_FACT);
getTensorFlowVersionSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
listAcceleratorTypesSettings =
PagedCallSettings.newBuilder(LIST_ACCELERATOR_TYPES_PAGE_STR_FACT);
getAcceleratorTypeSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
listLocationsSettings = PagedCallSettings.newBuilder(LIST_LOCATIONS_PAGE_STR_FACT);
getLocationSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
unaryMethodSettingsBuilders =
ImmutableList.>of(
listNodesSettings,
getNodeSettings,
createNodeSettings,
deleteNodeSettings,
reimageNodeSettings,
stopNodeSettings,
startNodeSettings,
listTensorFlowVersionsSettings,
getTensorFlowVersionSettings,
listAcceleratorTypesSettings,
getAcceleratorTypeSettings,
listLocationsSettings,
getLocationSettings);
initDefaults(this);
}
protected Builder(TpuStubSettings settings) {
super(settings);
listNodesSettings = settings.listNodesSettings.toBuilder();
getNodeSettings = settings.getNodeSettings.toBuilder();
createNodeSettings = settings.createNodeSettings.toBuilder();
createNodeOperationSettings = settings.createNodeOperationSettings.toBuilder();
deleteNodeSettings = settings.deleteNodeSettings.toBuilder();
deleteNodeOperationSettings = settings.deleteNodeOperationSettings.toBuilder();
reimageNodeSettings = settings.reimageNodeSettings.toBuilder();
reimageNodeOperationSettings = settings.reimageNodeOperationSettings.toBuilder();
stopNodeSettings = settings.stopNodeSettings.toBuilder();
stopNodeOperationSettings = settings.stopNodeOperationSettings.toBuilder();
startNodeSettings = settings.startNodeSettings.toBuilder();
startNodeOperationSettings = settings.startNodeOperationSettings.toBuilder();
listTensorFlowVersionsSettings = settings.listTensorFlowVersionsSettings.toBuilder();
getTensorFlowVersionSettings = settings.getTensorFlowVersionSettings.toBuilder();
listAcceleratorTypesSettings = settings.listAcceleratorTypesSettings.toBuilder();
getAcceleratorTypeSettings = settings.getAcceleratorTypeSettings.toBuilder();
listLocationsSettings = settings.listLocationsSettings.toBuilder();
getLocationSettings = settings.getLocationSettings.toBuilder();
unaryMethodSettingsBuilders =
ImmutableList.>of(
listNodesSettings,
getNodeSettings,
createNodeSettings,
deleteNodeSettings,
reimageNodeSettings,
stopNodeSettings,
startNodeSettings,
listTensorFlowVersionsSettings,
getTensorFlowVersionSettings,
listAcceleratorTypesSettings,
getAcceleratorTypeSettings,
listLocationsSettings,
getLocationSettings);
}
private static Builder createDefault() {
Builder builder = new Builder(((ClientContext) null));
builder.setTransportChannelProvider(defaultTransportChannelProvider());
builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build());
builder.setInternalHeaderProvider(defaultApiClientHeaderProviderBuilder().build());
builder.setMtlsEndpoint(getDefaultMtlsEndpoint());
builder.setSwitchToMtlsEndpointAllowed(true);
return initDefaults(builder);
}
private static Builder initDefaults(Builder builder) {
builder
.listNodesSettings()
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes"))
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params"));
builder
.getNodeSettings()
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes"))
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params"));
builder
.createNodeSettings()
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes"))
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params"));
builder
.deleteNodeSettings()
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes"))
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params"));
builder
.reimageNodeSettings()
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes"))
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params"));
builder
.stopNodeSettings()
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes"))
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params"));
builder
.startNodeSettings()
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes"))
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params"));
builder
.listTensorFlowVersionsSettings()
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes"))
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params"));
builder
.getTensorFlowVersionSettings()
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes"))
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params"));
builder
.listAcceleratorTypesSettings()
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes"))
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params"));
builder
.getAcceleratorTypeSettings()
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes"))
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params"));
builder
.listLocationsSettings()
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes"))
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params"));
builder
.getLocationSettings()
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes"))
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params"));
builder
.createNodeOperationSettings()
.setInitialCallSettings(
UnaryCallSettings.newUnaryCallSettingsBuilder()
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes"))
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params"))
.build())
.setResponseTransformer(ProtoOperationTransformers.ResponseTransformer.create(Node.class))
.setMetadataTransformer(
ProtoOperationTransformers.MetadataTransformer.create(OperationMetadata.class))
.setPollingAlgorithm(
OperationTimedPollAlgorithm.create(
RetrySettings.newBuilder()
.setInitialRetryDelayDuration(Duration.ofMillis(5000L))
.setRetryDelayMultiplier(1.5)
.setMaxRetryDelayDuration(Duration.ofMillis(45000L))
.setInitialRpcTimeoutDuration(Duration.ZERO)
.setRpcTimeoutMultiplier(1.0)
.setMaxRpcTimeoutDuration(Duration.ZERO)
.setTotalTimeoutDuration(Duration.ofMillis(300000L))
.build()));
builder
.deleteNodeOperationSettings()
.setInitialCallSettings(
UnaryCallSettings.newUnaryCallSettingsBuilder()
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes"))
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params"))
.build())
.setResponseTransformer(ProtoOperationTransformers.ResponseTransformer.create(Node.class))
.setMetadataTransformer(
ProtoOperationTransformers.MetadataTransformer.create(OperationMetadata.class))
.setPollingAlgorithm(
OperationTimedPollAlgorithm.create(
RetrySettings.newBuilder()
.setInitialRetryDelayDuration(Duration.ofMillis(5000L))
.setRetryDelayMultiplier(1.5)
.setMaxRetryDelayDuration(Duration.ofMillis(45000L))
.setInitialRpcTimeoutDuration(Duration.ZERO)
.setRpcTimeoutMultiplier(1.0)
.setMaxRpcTimeoutDuration(Duration.ZERO)
.setTotalTimeoutDuration(Duration.ofMillis(300000L))
.build()));
builder
.reimageNodeOperationSettings()
.setInitialCallSettings(
UnaryCallSettings.newUnaryCallSettingsBuilder()
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes"))
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params"))
.build())
.setResponseTransformer(ProtoOperationTransformers.ResponseTransformer.create(Node.class))
.setMetadataTransformer(
ProtoOperationTransformers.MetadataTransformer.create(OperationMetadata.class))
.setPollingAlgorithm(
OperationTimedPollAlgorithm.create(
RetrySettings.newBuilder()
.setInitialRetryDelayDuration(Duration.ofMillis(5000L))
.setRetryDelayMultiplier(1.5)
.setMaxRetryDelayDuration(Duration.ofMillis(45000L))
.setInitialRpcTimeoutDuration(Duration.ZERO)
.setRpcTimeoutMultiplier(1.0)
.setMaxRpcTimeoutDuration(Duration.ZERO)
.setTotalTimeoutDuration(Duration.ofMillis(300000L))
.build()));
builder
.stopNodeOperationSettings()
.setInitialCallSettings(
UnaryCallSettings.newUnaryCallSettingsBuilder()
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes"))
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params"))
.build())
.setResponseTransformer(ProtoOperationTransformers.ResponseTransformer.create(Node.class))
.setMetadataTransformer(
ProtoOperationTransformers.MetadataTransformer.create(OperationMetadata.class))
.setPollingAlgorithm(
OperationTimedPollAlgorithm.create(
RetrySettings.newBuilder()
.setInitialRetryDelayDuration(Duration.ofMillis(5000L))
.setRetryDelayMultiplier(1.5)
.setMaxRetryDelayDuration(Duration.ofMillis(45000L))
.setInitialRpcTimeoutDuration(Duration.ZERO)
.setRpcTimeoutMultiplier(1.0)
.setMaxRpcTimeoutDuration(Duration.ZERO)
.setTotalTimeoutDuration(Duration.ofMillis(300000L))
.build()));
builder
.startNodeOperationSettings()
.setInitialCallSettings(
UnaryCallSettings.newUnaryCallSettingsBuilder()
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes"))
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params"))
.build())
.setResponseTransformer(ProtoOperationTransformers.ResponseTransformer.create(Node.class))
.setMetadataTransformer(
ProtoOperationTransformers.MetadataTransformer.create(OperationMetadata.class))
.setPollingAlgorithm(
OperationTimedPollAlgorithm.create(
RetrySettings.newBuilder()
.setInitialRetryDelayDuration(Duration.ofMillis(5000L))
.setRetryDelayMultiplier(1.5)
.setMaxRetryDelayDuration(Duration.ofMillis(45000L))
.setInitialRpcTimeoutDuration(Duration.ZERO)
.setRpcTimeoutMultiplier(1.0)
.setMaxRpcTimeoutDuration(Duration.ZERO)
.setTotalTimeoutDuration(Duration.ofMillis(300000L))
.build()));
return builder;
}
/**
* Applies the given settings updater function to all of the unary API methods in this service.
*
* Note: This method does not support applying settings to streaming methods.
*/
public Builder applyToAllUnaryMethods(
ApiFunction, Void> settingsUpdater) {
super.applyToAllUnaryMethods(unaryMethodSettingsBuilders, settingsUpdater);
return this;
}
public ImmutableList> unaryMethodSettingsBuilders() {
return unaryMethodSettingsBuilders;
}
/** Returns the builder for the settings used for calls to listNodes. */
public PagedCallSettings.Builder
listNodesSettings() {
return listNodesSettings;
}
/** Returns the builder for the settings used for calls to getNode. */
public UnaryCallSettings.Builder getNodeSettings() {
return getNodeSettings;
}
/** Returns the builder for the settings used for calls to createNode. */
public UnaryCallSettings.Builder createNodeSettings() {
return createNodeSettings;
}
/** Returns the builder for the settings used for calls to createNode. */
public OperationCallSettings.Builder
createNodeOperationSettings() {
return createNodeOperationSettings;
}
/** Returns the builder for the settings used for calls to deleteNode. */
public UnaryCallSettings.Builder deleteNodeSettings() {
return deleteNodeSettings;
}
/** Returns the builder for the settings used for calls to deleteNode. */
public OperationCallSettings.Builder
deleteNodeOperationSettings() {
return deleteNodeOperationSettings;
}
/** Returns the builder for the settings used for calls to reimageNode. */
public UnaryCallSettings.Builder reimageNodeSettings() {
return reimageNodeSettings;
}
/** Returns the builder for the settings used for calls to reimageNode. */
public OperationCallSettings.Builder
reimageNodeOperationSettings() {
return reimageNodeOperationSettings;
}
/** Returns the builder for the settings used for calls to stopNode. */
public UnaryCallSettings.Builder stopNodeSettings() {
return stopNodeSettings;
}
/** Returns the builder for the settings used for calls to stopNode. */
public OperationCallSettings.Builder
stopNodeOperationSettings() {
return stopNodeOperationSettings;
}
/** Returns the builder for the settings used for calls to startNode. */
public UnaryCallSettings.Builder startNodeSettings() {
return startNodeSettings;
}
/** Returns the builder for the settings used for calls to startNode. */
public OperationCallSettings.Builder
startNodeOperationSettings() {
return startNodeOperationSettings;
}
/** Returns the builder for the settings used for calls to listTensorFlowVersions. */
public PagedCallSettings.Builder<
ListTensorFlowVersionsRequest,
ListTensorFlowVersionsResponse,
ListTensorFlowVersionsPagedResponse>
listTensorFlowVersionsSettings() {
return listTensorFlowVersionsSettings;
}
/** Returns the builder for the settings used for calls to getTensorFlowVersion. */
public UnaryCallSettings.Builder
getTensorFlowVersionSettings() {
return getTensorFlowVersionSettings;
}
/** Returns the builder for the settings used for calls to listAcceleratorTypes. */
public PagedCallSettings.Builder<
ListAcceleratorTypesRequest,
ListAcceleratorTypesResponse,
ListAcceleratorTypesPagedResponse>
listAcceleratorTypesSettings() {
return listAcceleratorTypesSettings;
}
/** Returns the builder for the settings used for calls to getAcceleratorType. */
public UnaryCallSettings.Builder
getAcceleratorTypeSettings() {
return getAcceleratorTypeSettings;
}
/** Returns the builder for the settings used for calls to listLocations. */
public PagedCallSettings.Builder<
ListLocationsRequest, ListLocationsResponse, ListLocationsPagedResponse>
listLocationsSettings() {
return listLocationsSettings;
}
/** Returns the builder for the settings used for calls to getLocation. */
public UnaryCallSettings.Builder getLocationSettings() {
return getLocationSettings;
}
@Override
public TpuStubSettings build() throws IOException {
return new TpuStubSettings(this);
}
}
}