@Generated(value="by gapic-generator") @BetaApi public class AutoscalingPolicyServiceClient extends Object implements com.google.api.gax.core.BackgroundResource
This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:
try (AutoscalingPolicyServiceClient autoscalingPolicyServiceClient = AutoscalingPolicyServiceClient.create()) {
RegionName parent = RegionName.of("[PROJECT]", "[REGION]");
AutoscalingPolicy policy = AutoscalingPolicy.newBuilder().build();
AutoscalingPolicy response = autoscalingPolicyServiceClient.createAutoscalingPolicy(parent, policy);
}
Note: close() needs to be called on the autoscalingPolicyServiceClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().
The surface of this class includes several types of Java methods for each of the API's methods:
See the individual methods for example code.
Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parse method to extract the individual identifiers contained within names that are returned.
This class can be customized by passing in a custom instance of AutoscalingPolicyServiceSettings to create(). For example:
To customize credentials:
AutoscalingPolicyServiceSettings autoscalingPolicyServiceSettings =
AutoscalingPolicyServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
AutoscalingPolicyServiceClient autoscalingPolicyServiceClient =
AutoscalingPolicyServiceClient.create(autoscalingPolicyServiceSettings);
To customize the endpoint:
AutoscalingPolicyServiceSettings autoscalingPolicyServiceSettings =
AutoscalingPolicyServiceSettings.newBuilder().setEndpoint(myEndpoint).build();
AutoscalingPolicyServiceClient autoscalingPolicyServiceClient =
AutoscalingPolicyServiceClient.create(autoscalingPolicyServiceSettings);
Modifier and Type | Class and Description |
---|---|
static class |
AutoscalingPolicyServiceClient.ListAutoscalingPoliciesFixedSizeCollection |
static class |
AutoscalingPolicyServiceClient.ListAutoscalingPoliciesPage |
static class |
AutoscalingPolicyServiceClient.ListAutoscalingPoliciesPagedResponse |
Modifier | Constructor and Description |
---|---|
protected |
AutoscalingPolicyServiceClient(AutoscalingPolicyServiceSettings settings)
Constructs an instance of AutoscalingPolicyServiceClient, using the given settings.
|
protected |
AutoscalingPolicyServiceClient(AutoscalingPolicyServiceStub stub) |
protected AutoscalingPolicyServiceClient(AutoscalingPolicyServiceSettings settings) throws IOException
IOException
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") protected AutoscalingPolicyServiceClient(AutoscalingPolicyServiceStub stub)
public static final AutoscalingPolicyServiceClient create() throws IOException
IOException
public static final AutoscalingPolicyServiceClient create(AutoscalingPolicyServiceSettings settings) throws IOException
IOException
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") public static final AutoscalingPolicyServiceClient create(AutoscalingPolicyServiceStub stub)
public final AutoscalingPolicyServiceSettings getSettings()
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") public AutoscalingPolicyServiceStub getStub()
public final AutoscalingPolicy createAutoscalingPolicy(RegionName parent, AutoscalingPolicy policy)
Sample code:
try (AutoscalingPolicyServiceClient autoscalingPolicyServiceClient = AutoscalingPolicyServiceClient.create()) {
RegionName parent = RegionName.of("[PROJECT]", "[REGION]");
AutoscalingPolicy policy = AutoscalingPolicy.newBuilder().build();
AutoscalingPolicy response = autoscalingPolicyServiceClient.createAutoscalingPolicy(parent, policy);
}
parent
- Required. The "resource name" of the region or location, as described in
https://cloud.google.com/apis/design/resource_names.
* For `projects.regions.autoscalingPolicies.create`, the resource name has the following format: `projects/{project_id}/regions/{region}`
* For `projects.locations.autoscalingPolicies.create`, the resource name has the following format: `projects/{project_id}/locations/{location}`
policy
- Required. The autoscaling policy to create.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final AutoscalingPolicy createAutoscalingPolicy(String parent, AutoscalingPolicy policy)
Sample code:
try (AutoscalingPolicyServiceClient autoscalingPolicyServiceClient = AutoscalingPolicyServiceClient.create()) {
RegionName parent = RegionName.of("[PROJECT]", "[REGION]");
AutoscalingPolicy policy = AutoscalingPolicy.newBuilder().build();
AutoscalingPolicy response = autoscalingPolicyServiceClient.createAutoscalingPolicy(parent.toString(), policy);
}
parent
- Required. The "resource name" of the region or location, as described in
https://cloud.google.com/apis/design/resource_names.
* For `projects.regions.autoscalingPolicies.create`, the resource name has the following format: `projects/{project_id}/regions/{region}`
* For `projects.locations.autoscalingPolicies.create`, the resource name has the following format: `projects/{project_id}/locations/{location}`
policy
- Required. The autoscaling policy to create.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final AutoscalingPolicy createAutoscalingPolicy(CreateAutoscalingPolicyRequest request)
Sample code:
try (AutoscalingPolicyServiceClient autoscalingPolicyServiceClient = AutoscalingPolicyServiceClient.create()) {
RegionName parent = RegionName.of("[PROJECT]", "[REGION]");
AutoscalingPolicy policy = AutoscalingPolicy.newBuilder().build();
CreateAutoscalingPolicyRequest request = CreateAutoscalingPolicyRequest.newBuilder()
.setParent(parent.toString())
.setPolicy(policy)
.build();
AutoscalingPolicy response = autoscalingPolicyServiceClient.createAutoscalingPolicy(request);
}
request
- The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<CreateAutoscalingPolicyRequest,AutoscalingPolicy> createAutoscalingPolicyCallable()
Sample code:
try (AutoscalingPolicyServiceClient autoscalingPolicyServiceClient = AutoscalingPolicyServiceClient.create()) {
RegionName parent = RegionName.of("[PROJECT]", "[REGION]");
AutoscalingPolicy policy = AutoscalingPolicy.newBuilder().build();
CreateAutoscalingPolicyRequest request = CreateAutoscalingPolicyRequest.newBuilder()
.setParent(parent.toString())
.setPolicy(policy)
.build();
ApiFuture<AutoscalingPolicy> future = autoscalingPolicyServiceClient.createAutoscalingPolicyCallable().futureCall(request);
// Do something
AutoscalingPolicy response = future.get();
}
public final AutoscalingPolicy updateAutoscalingPolicy(AutoscalingPolicy policy)
Disabled check for update_mask, because all updates will be full replacements.
Sample code:
try (AutoscalingPolicyServiceClient autoscalingPolicyServiceClient = AutoscalingPolicyServiceClient.create()) {
AutoscalingPolicy policy = AutoscalingPolicy.newBuilder().build();
AutoscalingPolicy response = autoscalingPolicyServiceClient.updateAutoscalingPolicy(policy);
}
policy
- Required. The updated autoscaling policy.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final AutoscalingPolicy updateAutoscalingPolicy(UpdateAutoscalingPolicyRequest request)
Disabled check for update_mask, because all updates will be full replacements.
Sample code:
try (AutoscalingPolicyServiceClient autoscalingPolicyServiceClient = AutoscalingPolicyServiceClient.create()) {
AutoscalingPolicy policy = AutoscalingPolicy.newBuilder().build();
UpdateAutoscalingPolicyRequest request = UpdateAutoscalingPolicyRequest.newBuilder()
.setPolicy(policy)
.build();
AutoscalingPolicy response = autoscalingPolicyServiceClient.updateAutoscalingPolicy(request);
}
request
- The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<UpdateAutoscalingPolicyRequest,AutoscalingPolicy> updateAutoscalingPolicyCallable()
Disabled check for update_mask, because all updates will be full replacements.
Sample code:
try (AutoscalingPolicyServiceClient autoscalingPolicyServiceClient = AutoscalingPolicyServiceClient.create()) {
AutoscalingPolicy policy = AutoscalingPolicy.newBuilder().build();
UpdateAutoscalingPolicyRequest request = UpdateAutoscalingPolicyRequest.newBuilder()
.setPolicy(policy)
.build();
ApiFuture<AutoscalingPolicy> future = autoscalingPolicyServiceClient.updateAutoscalingPolicyCallable().futureCall(request);
// Do something
AutoscalingPolicy response = future.get();
}
public final AutoscalingPolicy getAutoscalingPolicy(AutoscalingPolicyName name)
Sample code:
try (AutoscalingPolicyServiceClient autoscalingPolicyServiceClient = AutoscalingPolicyServiceClient.create()) {
AutoscalingPolicyName name = AutoscalingPolicyName.of("[PROJECT]", "[REGION]", "[AUTOSCALING_POLICY]");
AutoscalingPolicy response = autoscalingPolicyServiceClient.getAutoscalingPolicy(name);
}
name
- Required. The "resource name" of the autoscaling policy, as described in
https://cloud.google.com/apis/design/resource_names.
* For `projects.regions.autoscalingPolicies.get`, the resource name of the policy has the following format: `projects/{project_id}/regions/{region}/autoscalingPolicies/{policy_id}`
* For `projects.locations.autoscalingPolicies.get`, the resource name of the policy has the following format: `projects/{project_id}/locations/{location}/autoscalingPolicies/{policy_id}`
com.google.api.gax.rpc.ApiException
- if the remote call failspublic final AutoscalingPolicy getAutoscalingPolicy(String name)
Sample code:
try (AutoscalingPolicyServiceClient autoscalingPolicyServiceClient = AutoscalingPolicyServiceClient.create()) {
AutoscalingPolicyName name = AutoscalingPolicyName.of("[PROJECT]", "[REGION]", "[AUTOSCALING_POLICY]");
AutoscalingPolicy response = autoscalingPolicyServiceClient.getAutoscalingPolicy(name.toString());
}
name
- Required. The "resource name" of the autoscaling policy, as described in
https://cloud.google.com/apis/design/resource_names.
* For `projects.regions.autoscalingPolicies.get`, the resource name of the policy has the following format: `projects/{project_id}/regions/{region}/autoscalingPolicies/{policy_id}`
* For `projects.locations.autoscalingPolicies.get`, the resource name of the policy has the following format: `projects/{project_id}/locations/{location}/autoscalingPolicies/{policy_id}`
com.google.api.gax.rpc.ApiException
- if the remote call failspublic final AutoscalingPolicy getAutoscalingPolicy(GetAutoscalingPolicyRequest request)
Sample code:
try (AutoscalingPolicyServiceClient autoscalingPolicyServiceClient = AutoscalingPolicyServiceClient.create()) {
AutoscalingPolicyName name = AutoscalingPolicyName.of("[PROJECT]", "[REGION]", "[AUTOSCALING_POLICY]");
GetAutoscalingPolicyRequest request = GetAutoscalingPolicyRequest.newBuilder()
.setName(name.toString())
.build();
AutoscalingPolicy response = autoscalingPolicyServiceClient.getAutoscalingPolicy(request);
}
request
- The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<GetAutoscalingPolicyRequest,AutoscalingPolicy> getAutoscalingPolicyCallable()
Sample code:
try (AutoscalingPolicyServiceClient autoscalingPolicyServiceClient = AutoscalingPolicyServiceClient.create()) {
AutoscalingPolicyName name = AutoscalingPolicyName.of("[PROJECT]", "[REGION]", "[AUTOSCALING_POLICY]");
GetAutoscalingPolicyRequest request = GetAutoscalingPolicyRequest.newBuilder()
.setName(name.toString())
.build();
ApiFuture<AutoscalingPolicy> future = autoscalingPolicyServiceClient.getAutoscalingPolicyCallable().futureCall(request);
// Do something
AutoscalingPolicy response = future.get();
}
public final AutoscalingPolicyServiceClient.ListAutoscalingPoliciesPagedResponse listAutoscalingPolicies(RegionName parent)
Sample code:
try (AutoscalingPolicyServiceClient autoscalingPolicyServiceClient = AutoscalingPolicyServiceClient.create()) {
RegionName parent = RegionName.of("[PROJECT]", "[REGION]");
for (AutoscalingPolicy element : autoscalingPolicyServiceClient.listAutoscalingPolicies(parent).iterateAll()) {
// doThingsWith(element);
}
}
parent
- Required. The "resource name" of the region or location, as described in
https://cloud.google.com/apis/design/resource_names.
* For `projects.regions.autoscalingPolicies.list`, the resource name of the region has the following format: `projects/{project_id}/regions/{region}`
* For `projects.locations.autoscalingPolicies.list`, the resource name of the location has the following format: `projects/{project_id}/locations/{location}`
com.google.api.gax.rpc.ApiException
- if the remote call failspublic final AutoscalingPolicyServiceClient.ListAutoscalingPoliciesPagedResponse listAutoscalingPolicies(String parent)
Sample code:
try (AutoscalingPolicyServiceClient autoscalingPolicyServiceClient = AutoscalingPolicyServiceClient.create()) {
RegionName parent = RegionName.of("[PROJECT]", "[REGION]");
for (AutoscalingPolicy element : autoscalingPolicyServiceClient.listAutoscalingPolicies(parent.toString()).iterateAll()) {
// doThingsWith(element);
}
}
parent
- Required. The "resource name" of the region or location, as described in
https://cloud.google.com/apis/design/resource_names.
* For `projects.regions.autoscalingPolicies.list`, the resource name of the region has the following format: `projects/{project_id}/regions/{region}`
* For `projects.locations.autoscalingPolicies.list`, the resource name of the location has the following format: `projects/{project_id}/locations/{location}`
com.google.api.gax.rpc.ApiException
- if the remote call failspublic final AutoscalingPolicyServiceClient.ListAutoscalingPoliciesPagedResponse listAutoscalingPolicies(ListAutoscalingPoliciesRequest request)
Sample code:
try (AutoscalingPolicyServiceClient autoscalingPolicyServiceClient = AutoscalingPolicyServiceClient.create()) {
RegionName parent = RegionName.of("[PROJECT]", "[REGION]");
ListAutoscalingPoliciesRequest request = ListAutoscalingPoliciesRequest.newBuilder()
.setParent(parent.toString())
.build();
for (AutoscalingPolicy element : autoscalingPolicyServiceClient.listAutoscalingPolicies(request).iterateAll()) {
// doThingsWith(element);
}
}
request
- The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<ListAutoscalingPoliciesRequest,AutoscalingPolicyServiceClient.ListAutoscalingPoliciesPagedResponse> listAutoscalingPoliciesPagedCallable()
Sample code:
try (AutoscalingPolicyServiceClient autoscalingPolicyServiceClient = AutoscalingPolicyServiceClient.create()) {
RegionName parent = RegionName.of("[PROJECT]", "[REGION]");
ListAutoscalingPoliciesRequest request = ListAutoscalingPoliciesRequest.newBuilder()
.setParent(parent.toString())
.build();
ApiFuture<ListAutoscalingPoliciesPagedResponse> future = autoscalingPolicyServiceClient.listAutoscalingPoliciesPagedCallable().futureCall(request);
// Do something
for (AutoscalingPolicy element : future.get().iterateAll()) {
// doThingsWith(element);
}
}
public final com.google.api.gax.rpc.UnaryCallable<ListAutoscalingPoliciesRequest,ListAutoscalingPoliciesResponse> listAutoscalingPoliciesCallable()
Sample code:
try (AutoscalingPolicyServiceClient autoscalingPolicyServiceClient = AutoscalingPolicyServiceClient.create()) {
RegionName parent = RegionName.of("[PROJECT]", "[REGION]");
ListAutoscalingPoliciesRequest request = ListAutoscalingPoliciesRequest.newBuilder()
.setParent(parent.toString())
.build();
while (true) {
ListAutoscalingPoliciesResponse response = autoscalingPolicyServiceClient.listAutoscalingPoliciesCallable().call(request);
for (AutoscalingPolicy element : response.getPoliciesList()) {
// doThingsWith(element);
}
String nextPageToken = response.getNextPageToken();
if (!Strings.isNullOrEmpty(nextPageToken)) {
request = request.toBuilder().setPageToken(nextPageToken).build();
} else {
break;
}
}
}
public final void deleteAutoscalingPolicy(AutoscalingPolicyName name)
Sample code:
try (AutoscalingPolicyServiceClient autoscalingPolicyServiceClient = AutoscalingPolicyServiceClient.create()) {
AutoscalingPolicyName name = AutoscalingPolicyName.of("[PROJECT]", "[REGION]", "[AUTOSCALING_POLICY]");
autoscalingPolicyServiceClient.deleteAutoscalingPolicy(name);
}
name
- Required. The "resource name" of the autoscaling policy, as described in
https://cloud.google.com/apis/design/resource_names.
* For `projects.regions.autoscalingPolicies.delete`, the resource name of the policy has the following format: `projects/{project_id}/regions/{region}/autoscalingPolicies/{policy_id}`
* For `projects.locations.autoscalingPolicies.delete`, the resource name of the policy has the following format: `projects/{project_id}/locations/{location}/autoscalingPolicies/{policy_id}`
com.google.api.gax.rpc.ApiException
- if the remote call failspublic final void deleteAutoscalingPolicy(String name)
Sample code:
try (AutoscalingPolicyServiceClient autoscalingPolicyServiceClient = AutoscalingPolicyServiceClient.create()) {
AutoscalingPolicyName name = AutoscalingPolicyName.of("[PROJECT]", "[REGION]", "[AUTOSCALING_POLICY]");
autoscalingPolicyServiceClient.deleteAutoscalingPolicy(name.toString());
}
name
- Required. The "resource name" of the autoscaling policy, as described in
https://cloud.google.com/apis/design/resource_names.
* For `projects.regions.autoscalingPolicies.delete`, the resource name of the policy has the following format: `projects/{project_id}/regions/{region}/autoscalingPolicies/{policy_id}`
* For `projects.locations.autoscalingPolicies.delete`, the resource name of the policy has the following format: `projects/{project_id}/locations/{location}/autoscalingPolicies/{policy_id}`
com.google.api.gax.rpc.ApiException
- if the remote call failspublic final void deleteAutoscalingPolicy(DeleteAutoscalingPolicyRequest request)
Sample code:
try (AutoscalingPolicyServiceClient autoscalingPolicyServiceClient = AutoscalingPolicyServiceClient.create()) {
AutoscalingPolicyName name = AutoscalingPolicyName.of("[PROJECT]", "[REGION]", "[AUTOSCALING_POLICY]");
DeleteAutoscalingPolicyRequest request = DeleteAutoscalingPolicyRequest.newBuilder()
.setName(name.toString())
.build();
autoscalingPolicyServiceClient.deleteAutoscalingPolicy(request);
}
request
- The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<DeleteAutoscalingPolicyRequest,Empty> deleteAutoscalingPolicyCallable()
Sample code:
try (AutoscalingPolicyServiceClient autoscalingPolicyServiceClient = AutoscalingPolicyServiceClient.create()) {
AutoscalingPolicyName name = AutoscalingPolicyName.of("[PROJECT]", "[REGION]", "[AUTOSCALING_POLICY]");
DeleteAutoscalingPolicyRequest request = DeleteAutoscalingPolicyRequest.newBuilder()
.setName(name.toString())
.build();
ApiFuture<Void> future = autoscalingPolicyServiceClient.deleteAutoscalingPolicyCallable().futureCall(request);
// Do something
future.get();
}
public final void close()
close
in interface AutoCloseable
public void shutdown()
shutdown
in interface com.google.api.gax.core.BackgroundResource
public boolean isShutdown()
isShutdown
in interface com.google.api.gax.core.BackgroundResource
public boolean isTerminated()
isTerminated
in interface com.google.api.gax.core.BackgroundResource
public void shutdownNow()
shutdownNow
in interface com.google.api.gax.core.BackgroundResource
public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException
awaitTermination
in interface com.google.api.gax.core.BackgroundResource
InterruptedException
Copyright © 2019 Google LLC. All rights reserved.