Class ResourceSettingsServiceClient (1.8.0)

public class ResourceSettingsServiceClient implements 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:

  1. 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.
  2. 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.
  3. 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.

Inheritance

java.lang.Object > ResourceSettingsServiceClient

Implements

BackgroundResource

Static Methods

create()

public static final ResourceSettingsServiceClient create()

Constructs an instance of ResourceSettingsServiceClient with default settings.

Returns
TypeDescription
ResourceSettingsServiceClient
Exceptions
TypeDescription
IOException

create(ResourceSettingsServiceSettings settings)

public static final ResourceSettingsServiceClient create(ResourceSettingsServiceSettings settings)

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.

Parameter
NameDescription
settingsResourceSettingsServiceSettings
Returns
TypeDescription
ResourceSettingsServiceClient
Exceptions
TypeDescription
IOException

create(ResourceSettingsServiceStub stub)

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).

Parameter
NameDescription
stubResourceSettingsServiceStub
Returns
TypeDescription
ResourceSettingsServiceClient

Constructors

ResourceSettingsServiceClient(ResourceSettingsServiceSettings settings)

protected ResourceSettingsServiceClient(ResourceSettingsServiceSettings settings)

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.

Parameter
NameDescription
settingsResourceSettingsServiceSettings

ResourceSettingsServiceClient(ResourceSettingsServiceStub stub)

protected ResourceSettingsServiceClient(ResourceSettingsServiceStub stub)
Parameter
NameDescription
stubResourceSettingsServiceStub

Methods

awaitTermination(long duration, TimeUnit unit)

public boolean awaitTermination(long duration, TimeUnit unit)
Parameters
NameDescription
durationlong
unitTimeUnit
Returns
TypeDescription
boolean
Exceptions
TypeDescription
InterruptedException

close()

public final void close()

getSetting(GetSettingRequest request)

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);
 }
 
Parameter
NameDescription
requestGetSettingRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
Setting

getSetting(SettingName name)

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);
 }
 
Parameter
NameDescription
nameSettingName

Required. The name of the setting to get. See Setting for naming requirements.

Returns
TypeDescription
Setting

getSetting(String name)

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);
 }
 
Parameter
NameDescription
nameString

Required. The name of the setting to get. See Setting for naming requirements.

Returns
TypeDescription
Setting

getSettingCallable()

public final 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();
 }
 
Returns
TypeDescription
UnaryCallable<GetSettingRequest,Setting>

getSettings()

public final ResourceSettingsServiceSettings getSettings()
Returns
TypeDescription
ResourceSettingsServiceSettings

getStub()

public ResourceSettingsServiceStub getStub()
Returns
TypeDescription
ResourceSettingsServiceStub

isShutdown()

public boolean isShutdown()
Returns
TypeDescription
boolean

isTerminated()

public boolean isTerminated()
Returns
TypeDescription
boolean

listSettings(ResourceName parent)

public final ResourceSettingsServiceClient.ListSettingsPagedResponse listSettings(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);
   }
 }
 
Parameter
NameDescription
parentcom.google.api.resourcenames.ResourceName

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}

Returns
TypeDescription
ResourceSettingsServiceClient.ListSettingsPagedResponse

listSettings(ListSettingsRequest request)

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);
   }
 }
 
Parameter
NameDescription
requestListSettingsRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
ResourceSettingsServiceClient.ListSettingsPagedResponse

listSettings(String parent)

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);
   }
 }
 
Parameter
NameDescription
parentString

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}

Returns
TypeDescription
ResourceSettingsServiceClient.ListSettingsPagedResponse

listSettingsCallable()

public final 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;
     }
   }
 }
 
Returns
TypeDescription
UnaryCallable<ListSettingsRequest,ListSettingsResponse>

listSettingsPagedCallable()

public final 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);
   }
 }
 
Returns
TypeDescription
UnaryCallable<ListSettingsRequest,ListSettingsPagedResponse>

shutdown()

public void shutdown()

shutdownNow()

public void shutdownNow()

updateSetting(UpdateSettingRequest request)

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);
 }
 
Parameter
NameDescription
requestUpdateSettingRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
Setting

updateSettingCallable()

public final 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();
 }
 
Returns
TypeDescription
UnaryCallable<UpdateSettingRequest,Setting>