
com.google.cloud.gkehub.v1alpha.stub.HttpJsonGkeHubStub Maven / Gradle / Ivy
Show all versions of google-cloud-gkehub 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.gkehub.v1alpha.stub;
import static com.google.cloud.gkehub.v1alpha.GkeHubClient.ListFeaturesPagedResponse;
import com.google.api.HttpRule;
import com.google.api.core.BetaApi;
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.gkehub.v1alpha.CreateFeatureRequest;
import com.google.cloud.gkehub.v1alpha.DeleteFeatureRequest;
import com.google.cloud.gkehub.v1alpha.Feature;
import com.google.cloud.gkehub.v1alpha.GetFeatureRequest;
import com.google.cloud.gkehub.v1alpha.ListFeaturesRequest;
import com.google.cloud.gkehub.v1alpha.ListFeaturesResponse;
import com.google.cloud.gkehub.v1alpha.OperationMetadata;
import com.google.cloud.gkehub.v1alpha.UpdateFeatureRequest;
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 GkeHub service API.
*
* This class is for advanced usage and reflects the underlying API directly.
*/
@BetaApi
@Generated("by gapic-generator-java")
public class HttpJsonGkeHubStub extends GkeHubStub {
private static final TypeRegistry typeRegistry =
TypeRegistry.newBuilder()
.add(OperationMetadata.getDescriptor())
.add(Empty.getDescriptor())
.add(Feature.getDescriptor())
.build();
private static final ApiMethodDescriptor
listFeaturesMethodDescriptor =
ApiMethodDescriptor.newBuilder()
.setFullMethodName("google.cloud.gkehub.v1alpha.GkeHub/ListFeatures")
.setHttpMethod("GET")
.setType(ApiMethodDescriptor.MethodType.UNARY)
.setRequestFormatter(
ProtoMessageRequestFormatter.newBuilder()
.setPath(
"/v1alpha/{parent=projects/*/locations/*}/features",
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(ListFeaturesResponse.getDefaultInstance())
.setDefaultTypeRegistry(typeRegistry)
.build())
.build();
private static final ApiMethodDescriptor getFeatureMethodDescriptor =
ApiMethodDescriptor.newBuilder()
.setFullMethodName("google.cloud.gkehub.v1alpha.GkeHub/GetFeature")
.setHttpMethod("GET")
.setType(ApiMethodDescriptor.MethodType.UNARY)
.setRequestFormatter(
ProtoMessageRequestFormatter.newBuilder()
.setPath(
"/v1alpha/{name=projects/*/locations/*/features/*}",
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(Feature.getDefaultInstance())
.setDefaultTypeRegistry(typeRegistry)
.build())
.build();
private static final ApiMethodDescriptor
createFeatureMethodDescriptor =
ApiMethodDescriptor.newBuilder()
.setFullMethodName("google.cloud.gkehub.v1alpha.GkeHub/CreateFeature")
.setHttpMethod("POST")
.setType(ApiMethodDescriptor.MethodType.UNARY)
.setRequestFormatter(
ProtoMessageRequestFormatter.newBuilder()
.setPath(
"/v1alpha/{parent=projects/*/locations/*}/features",
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, "featureId", request.getFeatureId());
serializer.putQueryParam(fields, "requestId", request.getRequestId());
serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int");
return fields;
})
.setRequestBodyExtractor(
request ->
ProtoRestSerializer.create()
.toBody("resource", request.getResource(), true))
.build())
.setResponseParser(
ProtoMessageResponseParser.newBuilder()
.setDefaultInstance(Operation.getDefaultInstance())
.setDefaultTypeRegistry(typeRegistry)
.build())
.setOperationSnapshotFactory(
(CreateFeatureRequest request, Operation response) ->
HttpJsonOperationSnapshot.create(response))
.build();
private static final ApiMethodDescriptor
deleteFeatureMethodDescriptor =
ApiMethodDescriptor.newBuilder()
.setFullMethodName("google.cloud.gkehub.v1alpha.GkeHub/DeleteFeature")
.setHttpMethod("DELETE")
.setType(ApiMethodDescriptor.MethodType.UNARY)
.setRequestFormatter(
ProtoMessageRequestFormatter.newBuilder()
.setPath(
"/v1alpha/{name=projects/*/locations/*/features/*}",
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, "force", request.getForce());
serializer.putQueryParam(fields, "requestId", request.getRequestId());
serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int");
return fields;
})
.setRequestBodyExtractor(request -> null)
.build())
.setResponseParser(
ProtoMessageResponseParser.newBuilder()
.setDefaultInstance(Operation.getDefaultInstance())
.setDefaultTypeRegistry(typeRegistry)
.build())
.setOperationSnapshotFactory(
(DeleteFeatureRequest request, Operation response) ->
HttpJsonOperationSnapshot.create(response))
.build();
private static final ApiMethodDescriptor
updateFeatureMethodDescriptor =
ApiMethodDescriptor.newBuilder()
.setFullMethodName("google.cloud.gkehub.v1alpha.GkeHub/UpdateFeature")
.setHttpMethod("PATCH")
.setType(ApiMethodDescriptor.MethodType.UNARY)
.setRequestFormatter(
ProtoMessageRequestFormatter.newBuilder()
.setPath(
"/v1alpha/{name=projects/*/locations/*/features/*}",
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, "requestId", request.getRequestId());
serializer.putQueryParam(fields, "updateMask", request.getUpdateMask());
serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int");
return fields;
})
.setRequestBodyExtractor(
request ->
ProtoRestSerializer.create()
.toBody("resource", request.getResource(), true))
.build())
.setResponseParser(
ProtoMessageResponseParser.newBuilder()
.setDefaultInstance(Operation.getDefaultInstance())
.setDefaultTypeRegistry(typeRegistry)
.build())
.setOperationSnapshotFactory(
(UpdateFeatureRequest request, Operation response) ->
HttpJsonOperationSnapshot.create(response))
.build();
private final UnaryCallable listFeaturesCallable;
private final UnaryCallable
listFeaturesPagedCallable;
private final UnaryCallable getFeatureCallable;
private final UnaryCallable createFeatureCallable;
private final OperationCallable
createFeatureOperationCallable;
private final UnaryCallable deleteFeatureCallable;
private final OperationCallable
deleteFeatureOperationCallable;
private final UnaryCallable updateFeatureCallable;
private final OperationCallable
updateFeatureOperationCallable;
private final BackgroundResource backgroundResources;
private final HttpJsonOperationsStub httpJsonOperationsStub;
private final HttpJsonStubCallableFactory callableFactory;
public static final HttpJsonGkeHubStub create(GkeHubStubSettings settings) throws IOException {
return new HttpJsonGkeHubStub(settings, ClientContext.create(settings));
}
public static final HttpJsonGkeHubStub create(ClientContext clientContext) throws IOException {
return new HttpJsonGkeHubStub(GkeHubStubSettings.newHttpJsonBuilder().build(), clientContext);
}
public static final HttpJsonGkeHubStub create(
ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException {
return new HttpJsonGkeHubStub(
GkeHubStubSettings.newHttpJsonBuilder().build(), clientContext, callableFactory);
}
/**
* Constructs an instance of HttpJsonGkeHubStub, 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 HttpJsonGkeHubStub(GkeHubStubSettings settings, ClientContext clientContext)
throws IOException {
this(settings, clientContext, new HttpJsonGkeHubCallableFactory());
}
/**
* Constructs an instance of HttpJsonGkeHubStub, 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 HttpJsonGkeHubStub(
GkeHubStubSettings 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("/v1alpha/{name=projects/*/locations/*/operations/*}:cancel")
.build())
.put(
"google.longrunning.Operations.DeleteOperation",
HttpRule.newBuilder()
.setDelete("/v1alpha/{name=projects/*/locations/*/operations/*}")
.build())
.put(
"google.longrunning.Operations.GetOperation",
HttpRule.newBuilder()
.setGet("/v1alpha/{name=projects/*/locations/*/operations/*}")
.build())
.put(
"google.longrunning.Operations.ListOperations",
HttpRule.newBuilder()
.setGet("/v1alpha/{name=projects/*/locations/*}/operations")
.build())
.build());
HttpJsonCallSettings listFeaturesTransportSettings =
HttpJsonCallSettings.newBuilder()
.setMethodDescriptor(listFeaturesMethodDescriptor)
.setTypeRegistry(typeRegistry)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("parent", String.valueOf(request.getParent()));
return builder.build();
})
.build();
HttpJsonCallSettings getFeatureTransportSettings =
HttpJsonCallSettings.newBuilder()
.setMethodDescriptor(getFeatureMethodDescriptor)
.setTypeRegistry(typeRegistry)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("name", String.valueOf(request.getName()));
return builder.build();
})
.build();
HttpJsonCallSettings createFeatureTransportSettings =
HttpJsonCallSettings.newBuilder()
.setMethodDescriptor(createFeatureMethodDescriptor)
.setTypeRegistry(typeRegistry)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("parent", String.valueOf(request.getParent()));
return builder.build();
})
.build();
HttpJsonCallSettings deleteFeatureTransportSettings =
HttpJsonCallSettings.newBuilder()
.setMethodDescriptor(deleteFeatureMethodDescriptor)
.setTypeRegistry(typeRegistry)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("name", String.valueOf(request.getName()));
return builder.build();
})
.build();
HttpJsonCallSettings updateFeatureTransportSettings =
HttpJsonCallSettings.newBuilder()
.setMethodDescriptor(updateFeatureMethodDescriptor)
.setTypeRegistry(typeRegistry)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("name", String.valueOf(request.getName()));
return builder.build();
})
.build();
this.listFeaturesCallable =
callableFactory.createUnaryCallable(
listFeaturesTransportSettings, settings.listFeaturesSettings(), clientContext);
this.listFeaturesPagedCallable =
callableFactory.createPagedCallable(
listFeaturesTransportSettings, settings.listFeaturesSettings(), clientContext);
this.getFeatureCallable =
callableFactory.createUnaryCallable(
getFeatureTransportSettings, settings.getFeatureSettings(), clientContext);
this.createFeatureCallable =
callableFactory.createUnaryCallable(
createFeatureTransportSettings, settings.createFeatureSettings(), clientContext);
this.createFeatureOperationCallable =
callableFactory.createOperationCallable(
createFeatureTransportSettings,
settings.createFeatureOperationSettings(),
clientContext,
httpJsonOperationsStub);
this.deleteFeatureCallable =
callableFactory.createUnaryCallable(
deleteFeatureTransportSettings, settings.deleteFeatureSettings(), clientContext);
this.deleteFeatureOperationCallable =
callableFactory.createOperationCallable(
deleteFeatureTransportSettings,
settings.deleteFeatureOperationSettings(),
clientContext,
httpJsonOperationsStub);
this.updateFeatureCallable =
callableFactory.createUnaryCallable(
updateFeatureTransportSettings, settings.updateFeatureSettings(), clientContext);
this.updateFeatureOperationCallable =
callableFactory.createOperationCallable(
updateFeatureTransportSettings,
settings.updateFeatureOperationSettings(),
clientContext,
httpJsonOperationsStub);
this.backgroundResources =
new BackgroundResourceAggregation(clientContext.getBackgroundResources());
}
@InternalApi
public static List getMethodDescriptors() {
List methodDescriptors = new ArrayList<>();
methodDescriptors.add(listFeaturesMethodDescriptor);
methodDescriptors.add(getFeatureMethodDescriptor);
methodDescriptors.add(createFeatureMethodDescriptor);
methodDescriptors.add(deleteFeatureMethodDescriptor);
methodDescriptors.add(updateFeatureMethodDescriptor);
return methodDescriptors;
}
public HttpJsonOperationsStub getHttpJsonOperationsStub() {
return httpJsonOperationsStub;
}
@Override
public UnaryCallable listFeaturesCallable() {
return listFeaturesCallable;
}
@Override
public UnaryCallable listFeaturesPagedCallable() {
return listFeaturesPagedCallable;
}
@Override
public UnaryCallable getFeatureCallable() {
return getFeatureCallable;
}
@Override
public UnaryCallable createFeatureCallable() {
return createFeatureCallable;
}
@Override
public OperationCallable
createFeatureOperationCallable() {
return createFeatureOperationCallable;
}
@Override
public UnaryCallable deleteFeatureCallable() {
return deleteFeatureCallable;
}
@Override
public OperationCallable
deleteFeatureOperationCallable() {
return deleteFeatureOperationCallable;
}
@Override
public UnaryCallable updateFeatureCallable() {
return updateFeatureCallable;
}
@Override
public OperationCallable
updateFeatureOperationCallable() {
return updateFeatureOperationCallable;
}
@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);
}
}