Class OsConfigServiceClient (2.17.0)

public class OsConfigServiceClient implements BackgroundResource

Service Description: OS Config API

The OS Config service is a server-side component that you can use to manage package installations and patch jobs for virtual machine 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 (OsConfigServiceClient osConfigServiceClient = OsConfigServiceClient.create()) {
   PatchJobs.ExecutePatchJobRequest request =
       PatchJobs.ExecutePatchJobRequest.newBuilder()
           .setParent(ProjectName.of("[PROJECT]").toString())
           .setDescription("description-1724546052")
           .setInstanceFilter(PatchJobs.PatchInstanceFilter.newBuilder().build())
           .setPatchConfig(PatchJobs.PatchConfig.newBuilder().build())
           .setDuration(Duration.newBuilder().build())
           .setDryRun(true)
           .setDisplayName("displayName1714148973")
           .setRollout(PatchJobs.PatchRollout.newBuilder().build())
           .build();
   PatchJobs.PatchJob response = osConfigServiceClient.executePatchJob(request);
 }
 

Note: close() needs to be called on the OsConfigServiceClient 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 OsConfigServiceSettings 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
 OsConfigServiceSettings osConfigServiceSettings =
     OsConfigServiceSettings.newBuilder()
         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
         .build();
 OsConfigServiceClient osConfigServiceClient =
     OsConfigServiceClient.create(osConfigServiceSettings);
 

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
 OsConfigServiceSettings osConfigServiceSettings =
     OsConfigServiceSettings.newBuilder().setEndpoint(myEndpoint).build();
 OsConfigServiceClient osConfigServiceClient =
     OsConfigServiceClient.create(osConfigServiceSettings);
 

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
 OsConfigServiceSettings osConfigServiceSettings =
     OsConfigServiceSettings.newHttpJsonBuilder().build();
 OsConfigServiceClient osConfigServiceClient =
     OsConfigServiceClient.create(osConfigServiceSettings);
 

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

Inheritance

java.lang.Object > OsConfigServiceClient

Implements

BackgroundResource

Static Methods

create()

public static final OsConfigServiceClient create()

Constructs an instance of OsConfigServiceClient with default settings.

Returns
TypeDescription
OsConfigServiceClient
Exceptions
TypeDescription
IOException

create(OsConfigServiceSettings settings)

public static final OsConfigServiceClient create(OsConfigServiceSettings settings)

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

create(OsConfigServiceStub stub)

public static final OsConfigServiceClient create(OsConfigServiceStub stub)

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

Parameter
NameDescription
stubOsConfigServiceStub
Returns
TypeDescription
OsConfigServiceClient

Constructors

OsConfigServiceClient(OsConfigServiceSettings settings)

protected OsConfigServiceClient(OsConfigServiceSettings settings)

Constructs an instance of OsConfigServiceClient, 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
settingsOsConfigServiceSettings

OsConfigServiceClient(OsConfigServiceStub stub)

protected OsConfigServiceClient(OsConfigServiceStub stub)
Parameter
NameDescription
stubOsConfigServiceStub

Methods

awaitTermination(long duration, TimeUnit unit)

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

cancelPatchJob(PatchJobs.CancelPatchJobRequest request)

public final PatchJobs.PatchJob cancelPatchJob(PatchJobs.CancelPatchJobRequest request)

Cancel a patch job. The patch job must be active. Canceled patch jobs cannot be restarted.

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 (OsConfigServiceClient osConfigServiceClient = OsConfigServiceClient.create()) {
   PatchJobs.CancelPatchJobRequest request =
       PatchJobs.CancelPatchJobRequest.newBuilder()
           .setName(PatchJobName.of("[PROJECT]", "[PATCH_JOB]").toString())
           .build();
   PatchJobs.PatchJob response = osConfigServiceClient.cancelPatchJob(request);
 }
 
Parameter
NameDescription
requestPatchJobs.CancelPatchJobRequest

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

Returns
TypeDescription
PatchJobs.PatchJob

cancelPatchJobCallable()

public final UnaryCallable<PatchJobs.CancelPatchJobRequest,PatchJobs.PatchJob> cancelPatchJobCallable()

Cancel a patch job. The patch job must be active. Canceled patch jobs cannot be restarted.

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 (OsConfigServiceClient osConfigServiceClient = OsConfigServiceClient.create()) {
   PatchJobs.CancelPatchJobRequest request =
       PatchJobs.CancelPatchJobRequest.newBuilder()
           .setName(PatchJobName.of("[PROJECT]", "[PATCH_JOB]").toString())
           .build();
   ApiFuture<PatchJobs.PatchJob> future =
       osConfigServiceClient.cancelPatchJobCallable().futureCall(request);
   // Do something.
   PatchJobs.PatchJob response = future.get();
 }
 
Returns
TypeDescription
UnaryCallable<CancelPatchJobRequest,PatchJob>

close()

public final void close()

createPatchDeployment(PatchDeployments.CreatePatchDeploymentRequest request)

public final PatchDeployments.PatchDeployment createPatchDeployment(PatchDeployments.CreatePatchDeploymentRequest request)

Create an OS Config patch deployment.

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 (OsConfigServiceClient osConfigServiceClient = OsConfigServiceClient.create()) {
   PatchDeployments.CreatePatchDeploymentRequest request =
       PatchDeployments.CreatePatchDeploymentRequest.newBuilder()
           .setParent(ProjectName.of("[PROJECT]").toString())
           .setPatchDeploymentId("patchDeploymentId-1180405976")
           .setPatchDeployment(PatchDeployments.PatchDeployment.newBuilder().build())
           .build();
   PatchDeployments.PatchDeployment response =
       osConfigServiceClient.createPatchDeployment(request);
 }
 
Parameter
NameDescription
requestPatchDeployments.CreatePatchDeploymentRequest

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

Returns
TypeDescription
PatchDeployments.PatchDeployment

createPatchDeployment(ProjectName parent, PatchDeployments.PatchDeployment patchDeployment, String patchDeploymentId)

public final PatchDeployments.PatchDeployment createPatchDeployment(ProjectName parent, PatchDeployments.PatchDeployment patchDeployment, String patchDeploymentId)

Create an OS Config patch deployment.

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 (OsConfigServiceClient osConfigServiceClient = OsConfigServiceClient.create()) {
   ProjectName parent = ProjectName.of("[PROJECT]");
   PatchDeployments.PatchDeployment patchDeployment =
       PatchDeployments.PatchDeployment.newBuilder().build();
   String patchDeploymentId = "patchDeploymentId-1180405976";
   PatchDeployments.PatchDeployment response =
       osConfigServiceClient.createPatchDeployment(parent, patchDeployment, patchDeploymentId);
 }
 
Parameters
NameDescription
parentProjectName

Required. The project to apply this patch deployment to in the form projects/*.

patchDeploymentPatchDeployments.PatchDeployment

Required. The patch deployment to create.

patchDeploymentIdString

Required. A name for the patch deployment in the project. When creating a name the following rules apply:

  • 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
PatchDeployments.PatchDeployment

createPatchDeployment(String parent, PatchDeployments.PatchDeployment patchDeployment, String patchDeploymentId)

public final PatchDeployments.PatchDeployment createPatchDeployment(String parent, PatchDeployments.PatchDeployment patchDeployment, String patchDeploymentId)

Create an OS Config patch deployment.

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 (OsConfigServiceClient osConfigServiceClient = OsConfigServiceClient.create()) {
   String parent = ProjectName.of("[PROJECT]").toString();
   PatchDeployments.PatchDeployment patchDeployment =
       PatchDeployments.PatchDeployment.newBuilder().build();
   String patchDeploymentId = "patchDeploymentId-1180405976";
   PatchDeployments.PatchDeployment response =
       osConfigServiceClient.createPatchDeployment(parent, patchDeployment, patchDeploymentId);
 }
 
Parameters
NameDescription
parentString

Required. The project to apply this patch deployment to in the form projects/*.

patchDeploymentPatchDeployments.PatchDeployment

Required. The patch deployment to create.

patchDeploymentIdString

Required. A name for the patch deployment in the project. When creating a name the following rules apply:

  • 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
PatchDeployments.PatchDeployment

createPatchDeploymentCallable()

public final UnaryCallable<PatchDeployments.CreatePatchDeploymentRequest,PatchDeployments.PatchDeployment> createPatchDeploymentCallable()

Create an OS Config patch deployment.

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 (OsConfigServiceClient osConfigServiceClient = OsConfigServiceClient.create()) {
   PatchDeployments.CreatePatchDeploymentRequest request =
       PatchDeployments.CreatePatchDeploymentRequest.newBuilder()
           .setParent(ProjectName.of("[PROJECT]").toString())
           .setPatchDeploymentId("patchDeploymentId-1180405976")
           .setPatchDeployment(PatchDeployments.PatchDeployment.newBuilder().build())
           .build();
   ApiFuture<PatchDeployments.PatchDeployment> future =
       osConfigServiceClient.createPatchDeploymentCallable().futureCall(request);
   // Do something.
   PatchDeployments.PatchDeployment response = future.get();
 }
 
Returns
TypeDescription
UnaryCallable<CreatePatchDeploymentRequest,PatchDeployment>

deletePatchDeployment(PatchDeploymentName name)

public final void deletePatchDeployment(PatchDeploymentName name)

Delete an OS Config patch deployment.

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 (OsConfigServiceClient osConfigServiceClient = OsConfigServiceClient.create()) {
   PatchDeploymentName name = PatchDeploymentName.of("[PROJECT]", "[PATCH_DEPLOYMENT]");
   osConfigServiceClient.deletePatchDeployment(name);
 }
 
Parameter
NameDescription
namePatchDeploymentName

Required. The resource name of the patch deployment in the form projects/*/patchDeployments/*.

deletePatchDeployment(PatchDeployments.DeletePatchDeploymentRequest request)

public final void deletePatchDeployment(PatchDeployments.DeletePatchDeploymentRequest request)

Delete an OS Config patch deployment.

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