Class OsConfigZonalServiceClient (2.24.0)

public class OsConfigZonalServiceClient implements BackgroundResource

Service Description: Zonal OS Config API

The OS Config service is the server-side component that allows users to manage package installations and patch jobs for Compute Engine VM instances.

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 (OsConfigZonalServiceClient osConfigZonalServiceClient =
     OsConfigZonalServiceClient.create()) {
   OSPolicyAssignmentName name =
       OSPolicyAssignmentName.of("[PROJECT]", "[LOCATION]", "[OS_POLICY_ASSIGNMENT]");
   OSPolicyAssignment response = osConfigZonalServiceClient.getOSPolicyAssignment(name);
 }
 

Note: close() needs to be called on the OsConfigZonalServiceClient 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 OsConfigZonalServiceSettings 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
 OsConfigZonalServiceSettings osConfigZonalServiceSettings =
     OsConfigZonalServiceSettings.newBuilder()
         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
         .build();
 OsConfigZonalServiceClient osConfigZonalServiceClient =
     OsConfigZonalServiceClient.create(osConfigZonalServiceSettings);
 

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
 OsConfigZonalServiceSettings osConfigZonalServiceSettings =
     OsConfigZonalServiceSettings.newBuilder().setEndpoint(myEndpoint).build();
 OsConfigZonalServiceClient osConfigZonalServiceClient =
     OsConfigZonalServiceClient.create(osConfigZonalServiceSettings);
 

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
 OsConfigZonalServiceSettings osConfigZonalServiceSettings =
     OsConfigZonalServiceSettings.newHttpJsonBuilder().build();
 OsConfigZonalServiceClient osConfigZonalServiceClient =
     OsConfigZonalServiceClient.create(osConfigZonalServiceSettings);
 

Please refer to the GitHub repository's samples for more quickstart code snippets.

Inheritance

java.lang.Object > OsConfigZonalServiceClient

Implements

BackgroundResource

Static Methods

create()

public static final OsConfigZonalServiceClient create()

Constructs an instance of OsConfigZonalServiceClient with default settings.

Returns
TypeDescription
OsConfigZonalServiceClient
Exceptions
TypeDescription
IOException

create(OsConfigZonalServiceSettings settings)

public static final OsConfigZonalServiceClient create(OsConfigZonalServiceSettings settings)

Constructs an instance of OsConfigZonalServiceClient, 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
settingsOsConfigZonalServiceSettings
Returns
TypeDescription
OsConfigZonalServiceClient
Exceptions
TypeDescription
IOException

create(OsConfigZonalServiceStub stub)

public static final OsConfigZonalServiceClient create(OsConfigZonalServiceStub stub)

Constructs an instance of OsConfigZonalServiceClient, using the given stub for making calls. This is for advanced usage - prefer using create(OsConfigZonalServiceSettings).

Parameter
NameDescription
stubOsConfigZonalServiceStub
Returns
TypeDescription
OsConfigZonalServiceClient

Constructors

OsConfigZonalServiceClient(OsConfigZonalServiceSettings settings)

protected OsConfigZonalServiceClient(OsConfigZonalServiceSettings settings)

Constructs an instance of OsConfigZonalServiceClient, 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
settingsOsConfigZonalServiceSettings

OsConfigZonalServiceClient(OsConfigZonalServiceStub stub)

protected OsConfigZonalServiceClient(OsConfigZonalServiceStub stub)
Parameter
NameDescription
stubOsConfigZonalServiceStub

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

createOSPolicyAssignmentAsync(CreateOSPolicyAssignmentRequest request)

public final OperationFuture<OSPolicyAssignment,OSPolicyAssignmentOperationMetadata> createOSPolicyAssignmentAsync(CreateOSPolicyAssignmentRequest request)

Create an OS policy assignment.

This method also creates the first revision of the OS policy assignment.

This method returns a long running operation (LRO) that contains the rollout details. The rollout can be cancelled by cancelling the LRO.

For more information, see Method: projects.locations.osPolicyAssignments.operations.cancel.

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 (OsConfigZonalServiceClient osConfigZonalServiceClient =
     OsConfigZonalServiceClient.create()) {
   CreateOSPolicyAssignmentRequest request =
       CreateOSPolicyAssignmentRequest.newBuilder()
           .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
           .setOsPolicyAssignment(OSPolicyAssignment.newBuilder().build())
           .setOsPolicyAssignmentId("osPolicyAssignmentId-44079074")
           .build();
   OSPolicyAssignment response =
       osConfigZonalServiceClient.createOSPolicyAssignmentAsync(request).get();
 }
 
Parameter
NameDescription
requestCreateOSPolicyAssignmentRequest

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

Returns
TypeDescription
OperationFuture<OSPolicyAssignment,OSPolicyAssignmentOperationMetadata>

createOSPolicyAssignmentAsync(LocationName parent, OSPolicyAssignment osPolicyAssignment, String osPolicyAssignmentId)

public final OperationFuture<OSPolicyAssignment,OSPolicyAssignmentOperationMetadata> createOSPolicyAssignmentAsync(LocationName parent, OSPolicyAssignment osPolicyAssignment, String osPolicyAssignmentId)

Create an OS policy assignment.

This method also creates the first revision of the OS policy assignment.

This method returns a long running operation (LRO) that contains the rollout details. The rollout can be cancelled by cancelling the LRO.

For more information, see Method: projects.locations.osPolicyAssignments.operations.cancel.

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 (OsConfigZonalServiceClient osConfigZonalServiceClient =
     OsConfigZonalServiceClient.create()) {
   LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
   OSPolicyAssignment osPolicyAssignment = OSPolicyAssignment.newBuilder().build();
   String osPolicyAssignmentId = "osPolicyAssignmentId-44079074";
   OSPolicyAssignment response =
       osConfigZonalServiceClient
           .createOSPolicyAssignmentAsync(parent, osPolicyAssignment, osPolicyAssignmentId)
           .get();
 }
 
Parameters
NameDescription
parentLocationName

Required. The parent resource name in the form: projects/{project}/locations/{location}

osPolicyAssignmentOSPolicyAssignment

Required. The OS policy assignment to be created.

osPolicyAssignmentIdString

Required. The logical name of the OS policy assignment in the project with the following restrictions:

  • Must contain only lowercase letters, numbers, and hyphens.
  • Must start with a letter.
  • Must be between 1-63 characters.
  • Must end with a number or a letter.
  • Must be unique within the project.

Returns
TypeDescription
OperationFuture<OSPolicyAssignment,OSPolicyAssignmentOperationMetadata>

createOSPolicyAssignmentAsync(String parent, OSPolicyAssignment osPolicyAssignment, String osPolicyAssignmentId)

public final OperationFuture<OSPolicyAssignment,OSPolicyAssignmentOperationMetadata> createOSPolicyAssignmentAsync(String parent, OSPolicyAssignment osPolicyAssignment, String osPolicyAssignmentId)

Create an OS policy assignment.

This method also creates the first revision of the OS policy assignment.

This method returns a long running operation (LRO) that contains the rollout details. The rollout can be cancelled by cancelling the LRO.

For more information, see Method: projects.locations.osPolicyAssignments.operations.cancel.

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 (OsConfigZonalServiceClient osConfigZonalServiceClient =
     OsConfigZonalServiceClient.create()) {
   String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString();
   OSPolicyAssignment osPolicyAssignment = OSPolicyAssignment.newBuilder().build();
   String osPolicyAssignmentId = "osPolicyAssignmentId-44079074";
   OSPolicyAssignment response =
       osConfigZonalServiceClient
           .createOSPolicyAssignmentAsync(parent, osPolicyAssignment, osPolicyAssignmentId)
           .get();
 }
 
Parameters
NameDescription
parentString

Required. The parent resource name in the form: projects/{project}/locations/{location}

osPolicyAssignmentOSPolicyAssignment

Required. The OS policy assignment to be created.

osPolicyAssignmentIdString

Required. The logical name of the OS policy assignment in the project with the following restrictions:

  • Must contain only lowercase letters, numbers, and hyphens.
  • Must start with a letter.
  • Must be between 1-63 characters.
  • Must end with a number or a letter.
  • Must be unique within the project.

Returns
TypeDescription
OperationFuture<OSPolicyAssignment,OSPolicyAssignmentOperationMetadata>

createOSPolicyAssignmentCallable()

public final UnaryCallable<CreateOSPolicyAssignmentRequest,Operation> createOSPolicyAssignmentCallable()

Create an OS policy assignment.

This method also creates the first revision of the OS policy assignment.

This method returns a long running operation (LRO) that contains the rollout details. The rollout can be cancelled by cancelling the LRO.

For more information, see Method: projects.locations.osPolicyAssignments.operations.cancel.

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 (OsConfigZonalServiceClient osConfigZonalServiceClient =
     OsConfigZonalServiceClient.create()) {
   CreateOSPolicyAssignmentRequest request =
       CreateOSPolicyAssignmentRequest.newBuilder()
           .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
           .setOsPolicyAssignment(OSPolicyAssignment.newBuilder().build())
           .setOsPolicyAssignmentId("osPolicyAssignmentId-44079074")
           .build();
   ApiFuture<Operation> future =
       osConfigZonalServiceClient.createOSPolicyAssignmentCallable().futureCall(request);
   // Do something.
   Operation response = future.get();
 }
 
Returns
TypeDescription
UnaryCallable<CreateOSPolicyAssignmentRequest,Operation>

createOSPolicyAssignmentOperationCallable()

public final OperationCallable<CreateOSPolicyAssignmentRequest,OSPolicyAssignment,OSPolicyAssignmentOperationMetadata> createOSPolicyAssignmentOperationCallable()

Create an OS policy assignment.

This method also creates the first revision of the OS policy assignment.

This method returns a long running operation (LRO) that contains the rollout details. The rollout can be cancelled by cancelling the LRO.

For more information, see Method: projects.locations.osPolicyAssignments.operations.cancel.

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 (OsConfigZonalServiceClient osConfigZonalServiceClient =
     OsConfigZonalServiceClient.create()) {
   CreateOSPolicyAssignmentRequest request =
       CreateOSPolicyAssignmentRequest.newBuilder()
           .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
           .setOsPolicyAssignment(OSPolicyAssignment.newBuilder().build())
           .setOsPolicyAssignmentId("osPolicyAssignmentId-44079074")
           .build();
   OperationFuture<OSPolicyAssignment, OSPolicyAssignmentOperationMetadata> future =
       osConfigZonalServiceClient
           .createOSPolicyAssignmentOperationCallable()
           .futureCall(request);
   // Do something.
   OSPolicyAssignment response = future.get();
 }
 
Returns
TypeDescription
OperationCallable<CreateOSPolicyAssignmentRequest,OSPolicyAssignment,OSPolicyAssignmentOperationMetadata>

deleteOSPolicyAssignmentAsync(DeleteOSPolicyAssignmentRequest request)

public final OperationFuture<Empty,OSPolicyAssignmentOperationMetadata> deleteOSPolicyAssignmentAsync(DeleteOSPolicyAssignmentRequest request)

Delete the OS policy assignment.

This method creates a new revision of the OS policy assignment.

This method returns a long running operation (LRO) that contains the rollout details. The rollout can be cancelled by cancelling the LRO.

If the LRO completes and is not cancelled, all revisions associated with the OS policy assignment are deleted.

For more information, see Method: projects.locations.osPolicyAssignments.operations.cancel.

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 (OsConfigZonalServiceClient osConfigZonalServiceClient =
     OsConfigZonalServiceClient.create()) {
   DeleteOSPolicyAssignmentRequest request =
       DeleteOSPolicyAssignmentRequest.newBuilder()
           .setName(
               OSPolicyAssignmentName.of("[PROJECT]", "[LOCATION]", "[OS_POLICY_ASSIGNMENT]")
                   .toString())
           .build();
   osConfigZonalServiceClient.deleteOSPolicyAssignmentAsync(request).get();
 }
 
Parameter
NameDescription
requestDeleteOSPolicyAssignmentRequest

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

Returns
TypeDescription
OperationFuture<Empty,OSPolicyAssignmentOperationMetadata>

deleteOSPolicyAssignmentAsync(OSPolicyAssignmentName name)

public final OperationFuture<Empty,OSPolicyAssignmentOperationMetadata> deleteOSPolicyAssignmentAsync(OSPolicyAssignmentName name)

Delete the OS policy assignment.

This method creates a new revision of the OS policy assignment.

This method returns a long running operation (LRO) that contains the rollout details. The rollout can be cancelled by cancelling the LRO.

If the LRO completes and is not cancelled, all revisions associated with the OS policy assignment are deleted.

For more information, see Method: projects.locations.osPolicyAssignments.operations.cancel.

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 (OsConfigZonalServiceClient osConfigZonalServiceClient =
     OsConfigZonalServiceClient.create()) {
   OSPolicyAssignmentName name =
       OSPolicyAssignmentName.of("[PROJECT]", "[LOCATION]", "[OS_POLICY_ASSIGNMENT]");
   osConfigZonalServiceClient.deleteOSPolicyAssignmentAsync(name).get();
 }
 
Parameter
NameDescription