Class ResourceSettingsServiceClient
- java.lang.Object
-
- com.google.cloud.resourcesettings.v1.ResourceSettingsServiceClient
-
- All Implemented Interfaces:
com.google.api.gax.core.BackgroundResource
,AutoCloseable
@Generated("by gapic-generator-java") public class ResourceSettingsServiceClient extends Object implements com.google.api.gax.core.BackgroundResource
Service Description: An interface to interact with resource settings and setting values throughout the resource hierarchy.Services may surface a number of settings for users to control how their resources behave. Values of settings applied on a given Cloud resource are evaluated hierarchically and inherited by all descendants of that resource.
For all requests, returns a `google.rpc.Status` with `google.rpc.Code.PERMISSION_DENIED` if the IAM check fails or the `parent` resource is not in a Cloud Organization. For all requests, returns a `google.rpc.Status` with `google.rpc.Code.INVALID_ARGUMENT` if the request is malformed.
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:
// 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 try (ResourceSettingsServiceClient resourceSettingsServiceClient = ResourceSettingsServiceClient.create()) { SettingName name = SettingName.ofOrganizationSettingNameName("[ORGANIZATION]", "[SETTING_NAME]"); Setting response = resourceSettingsServiceClient.getSetting(name); }
Note: close() needs to be called on the ResourceSettingsServiceClient 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:
- A "flattened" method. With this type of method, the fields of the request type have been converted into function parameters. It may be the case that not all fields are available as parameters, and not every API method will have a flattened method entry point.
- A "request object" method. This type of method only takes one parameter, a request object, which must be constructed before the call. Not every API method will have a request object method.
- A "callable" method. This type of method takes no parameters and returns an immutable API callable object, which can be used to initiate calls to the service.
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 ResourceSettingsServiceSettings to create(). For example:
To customize credentials:
// 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 ResourceSettingsServiceSettings resourceSettingsServiceSettings = ResourceSettingsServiceSettings.newBuilder() .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) .build(); ResourceSettingsServiceClient resourceSettingsServiceClient = ResourceSettingsServiceClient.create(resourceSettingsServiceSettings);
To customize the endpoint:
// 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 ResourceSettingsServiceSettings resourceSettingsServiceSettings = ResourceSettingsServiceSettings.newBuilder().setEndpoint(myEndpoint).build(); ResourceSettingsServiceClient resourceSettingsServiceClient = ResourceSettingsServiceClient.create(resourceSettingsServiceSettings);
To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over the wire:
// 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 ResourceSettingsServiceSettings resourceSettingsServiceSettings = ResourceSettingsServiceSettings.newHttpJsonBuilder().build(); ResourceSettingsServiceClient resourceSettingsServiceClient = ResourceSettingsServiceClient.create(resourceSettingsServiceSettings);
Please refer to the GitHub repository's samples for more quickstart code snippets.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ResourceSettingsServiceClient.ListSettingsFixedSizeCollection
static class
ResourceSettingsServiceClient.ListSettingsPage
static class
ResourceSettingsServiceClient.ListSettingsPagedResponse
-
Constructor Summary
Constructors Modifier Constructor Description protected
ResourceSettingsServiceClient(ResourceSettingsServiceSettings settings)
Constructs an instance of ResourceSettingsServiceClient, using the given settings.protected
ResourceSettingsServiceClient(ResourceSettingsServiceStub stub)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
awaitTermination(long duration, TimeUnit unit)
void
close()
static ResourceSettingsServiceClient
create()
Constructs an instance of ResourceSettingsServiceClient with default settings.static ResourceSettingsServiceClient
create(ResourceSettingsServiceSettings settings)
Constructs an instance of ResourceSettingsServiceClient, using the given settings.static ResourceSettingsServiceClient
create(ResourceSettingsServiceStub stub)
Constructs an instance of ResourceSettingsServiceClient, using the given stub for making calls.Setting
getSetting(GetSettingRequest request)
Gets a setting.Setting
getSetting(SettingName name)
Gets a setting.Setting
getSetting(String name)
Gets a setting.com.google.api.gax.rpc.UnaryCallable<GetSettingRequest,Setting>
getSettingCallable()
Gets a setting.ResourceSettingsServiceSettings
getSettings()
ResourceSettingsServiceStub
getStub()
boolean
isShutdown()
boolean
isTerminated()
ResourceSettingsServiceClient.ListSettingsPagedResponse
listSettings(com.google.api.resourcenames.ResourceName parent)
Lists all the settings that are available on the Cloud resource `parent`.ResourceSettingsServiceClient.ListSettingsPagedResponse
listSettings(ListSettingsRequest request)
Lists all the settings that are available on the Cloud resource `parent`.ResourceSettingsServiceClient.ListSettingsPagedResponse
listSettings(String parent)
Lists all the settings that are available on the Cloud resource `parent`.com.google.api.gax.rpc.UnaryCallable<ListSettingsRequest,ListSettingsResponse>
listSettingsCallable()
Lists all the settings that are available on the Cloud resource `parent`.com.google.api.gax.rpc.UnaryCallable<ListSettingsRequest,ResourceSettingsServiceClient.ListSettingsPagedResponse>
listSettingsPagedCallable()
Lists all the settings that are available on the Cloud resource `parent`.void
shutdown()
void
shutdownNow()
Setting
updateSetting(UpdateSettingRequest request)
Updates a setting.com.google.api.gax.rpc.UnaryCallable<UpdateSettingRequest,Setting>
updateSettingCallable()
Updates a setting.
-
-
-
Constructor Detail
-
ResourceSettingsServiceClient
protected ResourceSettingsServiceClient(ResourceSettingsServiceSettings settings) throws IOException
Constructs an instance of ResourceSettingsServiceClient, 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.- Throws:
IOException
-
ResourceSettingsServiceClient
protected ResourceSettingsServiceClient(ResourceSettingsServiceStub stub)
-
-
Method Detail
-
create
public static final ResourceSettingsServiceClient create() throws IOException
Constructs an instance of ResourceSettingsServiceClient with default settings.- Throws:
IOException
-
create
public static final ResourceSettingsServiceClient create(ResourceSettingsServiceSettings settings) throws IOException
Constructs an instance of ResourceSettingsServiceClient, using the given settings. The channels are created based on the settings passed in, or defaults for any settings that are not set.- Throws:
IOException
-
create
public static final ResourceSettingsServiceClient create(ResourceSettingsServiceStub stub)
Constructs an instance of ResourceSettingsServiceClient, using the given stub for making calls. This is for advanced usage - prefer using create(ResourceSettingsServiceSettings).
-
getSettings
public final ResourceSettingsServiceSettings getSettings()
-
getStub
public ResourceSettingsServiceStub getStub()
-
listSettings
public final ResourceSettingsServiceClient.ListSettingsPagedResponse listSettings(com.google.api.resourcenames.ResourceName parent)
Lists all the settings that are available on the Cloud resource `parent`.Sample 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 try (ResourceSettingsServiceClient resourceSettingsServiceClient = ResourceSettingsServiceClient.create()) { ResourceName parent = new ResourceName() { {@literal @}Override public Map<String, String> getFieldValuesMap() { Map<String, String> fieldValuesMap = new HashMap<>(); fieldValuesMap.put("parent", "organizations/organization-8287"); return fieldValuesMap; } {@literal @}Override public String getFieldValue(String fieldName) { return getFieldValuesMap().get(fieldName); } {@literal @}Override public String toString() { return "organizations/organization-8287"; } }; for (Setting element : resourceSettingsServiceClient.listSettings(parent).iterateAll()) { // doThingsWith(element); } }
- Parameters:
parent
- Required. The Cloud resource that parents the setting. Must be in one of the following forms:- `projects/{project_number}`
- `projects/{project_id}`
- `folders/{folder_id}`
- `organizations/{organization_id}`
- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
listSettings
public final ResourceSettingsServiceClient.ListSettingsPagedResponse listSettings(String parent)
Lists all the settings that are available on the Cloud resource `parent`.Sample 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 try (ResourceSettingsServiceClient resourceSettingsServiceClient = ResourceSettingsServiceClient.create()) { String parent = SettingName.ofProjectNumberSettingNameName("[PROJECT_NUMBER]", "[SETTING_NAME]") .toString(); for (Setting element : resourceSettingsServiceClient.listSettings(parent).iterateAll()) { // doThingsWith(element); } }
- Parameters:
parent
- Required. The Cloud resource that parents the setting. Must be in one of the following forms:- `projects/{project_number}`
- `projects/{project_id}`
- `folders/{folder_id}`
- `organizations/{organization_id}`
- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
listSettings
public final ResourceSettingsServiceClient.ListSettingsPagedResponse listSettings(ListSettingsRequest request)
Lists all the settings that are available on the Cloud resource `parent`.Sample 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 try (ResourceSettingsServiceClient resourceSettingsServiceClient = ResourceSettingsServiceClient.create()) { ListSettingsRequest request = ListSettingsRequest.newBuilder() .setParent("ListSettingsRequest-286838706".toString()) .setPageSize(883849137) .setPageToken("pageToken873572522") .setView(SettingView.forNumber(0)) .build(); for (Setting element : resourceSettingsServiceClient.listSettings(request).iterateAll()) { // doThingsWith(element); } }
- Parameters:
request
- The request object containing all of the parameters for the API call.- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
listSettingsPagedCallable
public final com.google.api.gax.rpc.UnaryCallable<ListSettingsRequest,ResourceSettingsServiceClient.ListSettingsPagedResponse> listSettingsPagedCallable()
Lists all the settings that are available on the Cloud resource `parent`.Sample 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 try (ResourceSettingsServiceClient resourceSettingsServiceClient = ResourceSettingsServiceClient.create()) { ListSettingsRequest request = ListSettingsRequest.newBuilder() .setParent("ListSettingsRequest-286838706".toString()) .setPageSize(883849137) .setPageToken("pageToken873572522") .setView(SettingView.forNumber(0)) .build(); ApiFuture<Setting> future = resourceSettingsServiceClient.listSettingsPagedCallable().futureCall(request); // Do something. for (Setting element : future.get().iterateAll()) { // doThingsWith(element); } }
-
listSettingsCallable
public final com.google.api.gax.rpc.UnaryCallable<ListSettingsRequest,ListSettingsResponse> listSettingsCallable()
Lists all the settings that are available on the Cloud resource `parent`.Sample 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 try (ResourceSettingsServiceClient resourceSettingsServiceClient = ResourceSettingsServiceClient.create()) { ListSettingsRequest request = ListSettingsRequest.newBuilder() .setParent("ListSettingsRequest-286838706".toString()) .setPageSize(883849137) .setPageToken("pageToken873572522") .setView(SettingView.forNumber(0)) .build(); while (true) { ListSettingsResponse response = resourceSettingsServiceClient.listSettingsCallable().call(request); for (Setting element : response.getSettingsList()) { // doThingsWith(element); } String nextPageToken = response.getNextPageToken(); if (!Strings.isNullOrEmpty(nextPageToken)) { request = request.toBuilder().setPageToken(nextPageToken).build(); } else { break; } } }
-
getSetting
public final Setting getSetting(SettingName name)
Gets a setting.Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the setting does not exist.
Sample 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 try (ResourceSettingsServiceClient resourceSettingsServiceClient = ResourceSettingsServiceClient.create()) { SettingName name = SettingName.ofOrganizationSettingNameName("[ORGANIZATION]", "[SETTING_NAME]"); Setting response = resourceSettingsServiceClient.getSetting(name); }
- Parameters:
name
- Required. The name of the setting to get. See [Setting][google.cloud.resourcesettings.v1.Setting] for naming requirements.- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
getSetting
public final Setting getSetting(String name)
Gets a setting.Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the setting does not exist.
Sample 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 try (ResourceSettingsServiceClient resourceSettingsServiceClient = ResourceSettingsServiceClient.create()) { String name = SettingName.ofProjectNumberSettingNameName("[PROJECT_NUMBER]", "[SETTING_NAME]") .toString(); Setting response = resourceSettingsServiceClient.getSetting(name); }
- Parameters:
name
- Required. The name of the setting to get. See [Setting][google.cloud.resourcesettings.v1.Setting] for naming requirements.- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
getSetting
public final Setting getSetting(GetSettingRequest request)
Gets a setting.Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the setting does not exist.
Sample 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 try (ResourceSettingsServiceClient resourceSettingsServiceClient = ResourceSettingsServiceClient.create()) { GetSettingRequest request = GetSettingRequest.newBuilder() .setName( SettingName.ofOrganizationSettingNameName("[ORGANIZATION]", "[SETTING_NAME]") .toString()) .setView(SettingView.forNumber(0)) .build(); Setting response = resourceSettingsServiceClient.getSetting(request); }
- Parameters:
request
- The request object containing all of the parameters for the API call.- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
getSettingCallable
public final com.google.api.gax.rpc.UnaryCallable<GetSettingRequest,Setting> getSettingCallable()
Gets a setting.Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the setting does not exist.
Sample 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 try (ResourceSettingsServiceClient resourceSettingsServiceClient = ResourceSettingsServiceClient.create()) { GetSettingRequest request = GetSettingRequest.newBuilder() .setName( SettingName.ofOrganizationSettingNameName("[ORGANIZATION]", "[SETTING_NAME]") .toString()) .setView(SettingView.forNumber(0)) .build(); ApiFuture<Setting> future = resourceSettingsServiceClient.getSettingCallable().futureCall(request); // Do something. Setting response = future.get(); }
-
updateSetting
public final Setting updateSetting(UpdateSettingRequest request)
Updates a setting.Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the setting does not exist. Returns a `google.rpc.Status` with `google.rpc.Code.FAILED_PRECONDITION` if the setting is flagged as read only. Returns a `google.rpc.Status` with `google.rpc.Code.ABORTED` if the etag supplied in the request does not match the persisted etag of the setting value.
On success, the response will contain only `name`, `local_value` and `etag`. The `metadata` and `effective_value` cannot be updated through this API.
Note: the supplied setting will perform a full overwrite of the `local_value` field.
Sample 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 try (ResourceSettingsServiceClient resourceSettingsServiceClient = ResourceSettingsServiceClient.create()) { UpdateSettingRequest request = UpdateSettingRequest.newBuilder().setSetting(Setting.newBuilder().build()).build(); Setting response = resourceSettingsServiceClient.updateSetting(request); }
- Parameters:
request
- The request object containing all of the parameters for the API call.- Throws:
com.google.api.gax.rpc.ApiException
- if the remote call fails
-
updateSettingCallable
public final com.google.api.gax.rpc.UnaryCallable<UpdateSettingRequest,Setting> updateSettingCallable()
Updates a setting.Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the setting does not exist. Returns a `google.rpc.Status` with `google.rpc.Code.FAILED_PRECONDITION` if the setting is flagged as read only. Returns a `google.rpc.Status` with `google.rpc.Code.ABORTED` if the etag supplied in the request does not match the persisted etag of the setting value.
On success, the response will contain only `name`, `local_value` and `etag`. The `metadata` and `effective_value` cannot be updated through this API.
Note: the supplied setting will perform a full overwrite of the `local_value` field.
Sample 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 try (ResourceSettingsServiceClient resourceSettingsServiceClient = ResourceSettingsServiceClient.create()) { UpdateSettingRequest request = UpdateSettingRequest.newBuilder().setSetting(Setting.newBuilder().build()).build(); ApiFuture<Setting> future = resourceSettingsServiceClient.updateSettingCallable().futureCall(request); // Do something. Setting response = future.get(); }
-
close
public final void close()
- Specified by:
close
in interfaceAutoCloseable
-
shutdown
public void shutdown()
- Specified by:
shutdown
in interfacecom.google.api.gax.core.BackgroundResource
-
isShutdown
public boolean isShutdown()
- Specified by:
isShutdown
in interfacecom.google.api.gax.core.BackgroundResource
-
isTerminated
public boolean isTerminated()
- Specified by:
isTerminated
in interfacecom.google.api.gax.core.BackgroundResource
-
shutdownNow
public void shutdownNow()
- Specified by:
shutdownNow
in interfacecom.google.api.gax.core.BackgroundResource
-
awaitTermination
public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException
- Specified by:
awaitTermination
in interfacecom.google.api.gax.core.BackgroundResource
- Throws:
InterruptedException
-
-