Class SimulatorClient (0.7.0)

public class SimulatorClient implements BackgroundResource

Service Description: Policy Simulator API service.

Policy Simulator is a collection of endpoints for creating, running, and viewing a Replay. A Replay is a type of simulation that lets you see how your principals' access to resources might change if you changed your IAM policy.

During a Replay, Policy Simulator re-evaluates, or replays, past access attempts under both the current policy and your proposed policy, and compares those results to determine how your principals' access might change under the proposed policy.

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 (SimulatorClient simulatorClient = SimulatorClient.create()) {
   ReplayName name =
       ReplayName.ofProjectLocationReplayName("[PROJECT]", "[LOCATION]", "[REPLAY]");
   Replay response = simulatorClient.getReplay(name);
 }
 

Note: close() needs to be called on the SimulatorClient 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 SimulatorSettings 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
 SimulatorSettings simulatorSettings =
     SimulatorSettings.newBuilder()
         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
         .build();
 SimulatorClient simulatorClient = SimulatorClient.create(simulatorSettings);
 

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
 SimulatorSettings simulatorSettings =
     SimulatorSettings.newBuilder().setEndpoint(myEndpoint).build();
 SimulatorClient simulatorClient = SimulatorClient.create(simulatorSettings);
 

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
 SimulatorSettings simulatorSettings = SimulatorSettings.newHttpJsonBuilder().build();
 SimulatorClient simulatorClient = SimulatorClient.create(simulatorSettings);
 

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

Inheritance

java.lang.Object > SimulatorClient

Implements

BackgroundResource

Static Methods

create()

public static final SimulatorClient create()

Constructs an instance of SimulatorClient with default settings.

Returns
TypeDescription
SimulatorClient
Exceptions
TypeDescription
IOException

create(SimulatorSettings settings)

public static final SimulatorClient create(SimulatorSettings settings)

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

create(SimulatorStub stub)

public static final SimulatorClient create(SimulatorStub stub)

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

Parameter
NameDescription
stubSimulatorStub
Returns
TypeDescription
SimulatorClient

Constructors

SimulatorClient(SimulatorSettings settings)

protected SimulatorClient(SimulatorSettings settings)

Constructs an instance of SimulatorClient, 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
settingsSimulatorSettings

SimulatorClient(SimulatorStub stub)

protected SimulatorClient(SimulatorStub stub)
Parameter
NameDescription
stubSimulatorStub

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

createReplayAsync(CreateReplayRequest request)

public final OperationFuture<Replay,ReplayOperationMetadata> createReplayAsync(CreateReplayRequest request)

Creates and starts a Replay using the given ReplayConfig.

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 (SimulatorClient simulatorClient = SimulatorClient.create()) {
   CreateReplayRequest request =
       CreateReplayRequest.newBuilder()
           .setParent("parent-995424086")
           .setReplay(Replay.newBuilder().build())
           .build();
   Replay response = simulatorClient.createReplayAsync(request).get();
 }
 
Parameter
NameDescription
requestCreateReplayRequest

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

Returns
TypeDescription
OperationFuture<Replay,ReplayOperationMetadata>

createReplayAsync(String parent, Replay replay)

public final OperationFuture<Replay,ReplayOperationMetadata> createReplayAsync(String parent, Replay replay)

Creates and starts a Replay using the given ReplayConfig.

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 (SimulatorClient simulatorClient = SimulatorClient.create()) {
   String parent = "parent-995424086";
   Replay replay = Replay.newBuilder().build();
   Replay response = simulatorClient.createReplayAsync(parent, replay).get();
 }
 
Parameters
NameDescription
parentString

Required. The parent resource where this Replay will be created. This resource must be a project, folder, or organization with a location.

Example: projects/my-example-project/locations/global

replayReplay

Required. The Replay to create. Set Replay.ReplayConfig to configure the replay.

Returns
TypeDescription
OperationFuture<Replay,ReplayOperationMetadata>

createReplayCallable()

public final UnaryCallable<CreateReplayRequest,Operation> createReplayCallable()

Creates and starts a Replay using the given ReplayConfig.

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 (SimulatorClient simulatorClient = SimulatorClient.create()) {
   CreateReplayRequest request =
       CreateReplayRequest.newBuilder()
           .setParent("parent-995424086")
           .setReplay(Replay.newBuilder().build())
           .build();
   ApiFuture<Operation> future = simulatorClient.createReplayCallable().futureCall(request);
   // Do something.
   Operation response = future.get();
 }
 
Returns
TypeDescription
UnaryCallable<CreateReplayRequest,Operation>

createReplayOperationCallable()

public final OperationCallable<CreateReplayRequest,Replay,ReplayOperationMetadata> createReplayOperationCallable()

Creates and starts a Replay using the given ReplayConfig.

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 (SimulatorClient simulatorClient = SimulatorClient.create()) {
   CreateReplayRequest request =
       CreateReplayRequest.newBuilder()
           .setParent("parent-995424086")
           .setReplay(Replay.newBuilder().build())
           .build();
   OperationFuture<Replay, ReplayOperationMetadata> future =
       simulatorClient.createReplayOperationCallable().futureCall(request);
   // Do something.
   Replay response = future.get();
 }
 
Returns
TypeDescription
OperationCallable<CreateReplayRequest,Replay,ReplayOperationMetadata>

getHttpJsonOperationsClient()

public final OperationsClient getHttpJsonOperationsClient()

Returns the OperationsClient that can be used to query the status of a long-running operation returned by another API method call.

Returns
TypeDescription
OperationsClient

getOperationsClient()

public final OperationsClient getOperationsClient()

Returns the OperationsClient that can be used to query the status of a long-running operation returned by another API method call.

Returns
TypeDescription
OperationsClient

getReplay(GetReplayRequest request)

public final Replay getReplay(GetReplayRequest request)

Gets the specified Replay. Each Replay is available for at least 7 days.

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 (SimulatorClient simulatorClient = SimulatorClient.create()) {
   GetReplayRequest request =
       GetReplayRequest.newBuilder()
           .setName(
               ReplayName.ofProjectLocationReplayName("[PROJECT]", "[LOCATION]", "[REPLAY]")
                   .toString())
           .build();
   Replay response = simulatorClient.getReplay(request);
 }
 
Parameter
NameDescription
requestGetReplayRequest

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

Returns
TypeDescription
Replay

getReplay(ReplayName name)

public final Replay getReplay(ReplayName name)

Gets the specified Replay. Each Replay is available for at least 7 days.

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 (SimulatorClient simulatorClient = SimulatorClient.create()) {
   ReplayName name =
       ReplayName.ofProjectLocationReplayName("[PROJECT]", "[LOCATION]", "[REPLAY]");
   Replay response = simulatorClient.getReplay(name);
 }
 
Parameter
NameDescription
nameReplayName

Required. The name of the Replay to retrieve, in the following format:

{projects|folders|organizations}/{resource-id}/locations/global/replays/{replay-id}, where {resource-id} is the ID of the project, folder, or organization that owns the Replay.

Example: projects/my-example-project/locations/global/replays/506a5f7f-38ce-4d7d-8e03-479ce1833c36

Returns
TypeDescription
Replay

getReplay(String name)

public final Replay getReplay(String name)

Gets the specified Replay. Each Replay is available for at least 7 days.

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 (SimulatorClient simulatorClient = SimulatorClient.create()) {
   String name =
       ReplayName.ofProjectLocationReplayName("[PROJECT]", "[LOCATION]", "[REPLAY]").toString();
   Replay response = simulatorClient.getReplay(name);
 }
 
Parameter
NameDescription
nameString

Required. The name of the Replay to retrieve, in the following format:

{projects|folders|organizations}/{resource-id}/locations/global/replays/{replay-id}, where {resource-id} is the ID of the project, folder, or organization that owns the Replay.

Example: projects/my-example-project/locations/global/replays/506a5f7f-38ce-4d7d-8e03-479ce1833c36

Returns
TypeDescription
Replay

getReplayCallable()

public final UnaryCallable<GetReplayRequest,Replay> getReplayCallable()

Gets the specified Replay. Each Replay is available for at least 7 days.

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 (SimulatorClient simulatorClient = SimulatorClient.create()) {
   GetReplayRequest request =
       GetReplayRequest.newBuilder()
           .setName(
               ReplayName.ofProjectLocationReplayName("[PROJECT]", "[LOCATION]", "[REPLAY]")
                   .toString())
           .build();
   ApiFuture<Replay> future = simulatorClient.getReplayCallable().futureCall(request);
   // Do something.
   Replay response = future.get();
 }
 
Returns
TypeDescription
UnaryCallable<GetReplayRequest,Replay>

getSettings()

public final SimulatorSettings getSettings()
Returns
TypeDescription
SimulatorSettings

getStub()

public SimulatorStub getStub()
Returns
TypeDescription
SimulatorStub

isShutdown()

public boolean isShutdown()
Returns
TypeDescription
boolean

isTerminated()

public boolean isTerminated()
Returns
TypeDescription
boolean

listReplayResults(ListReplayResultsRequest request)

public final SimulatorClient.ListReplayResultsPagedResponse listReplayResults(ListReplayResultsRequest request)

Lists the results of running a Replay.

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 (SimulatorClient simulatorClient = SimulatorClient.create()) {
   ListReplayResultsRequest request =
       ListReplayResultsRequest.newBuilder()
           .setParent(
               ReplayName.ofProjectLocationReplayName("[PROJECT]", "[LOCATION]", "[REPLAY]")
                   .toString())
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .build();
   for (ReplayResult element : simulatorClient.listReplayResults(request).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
NameDescription
requestListReplayResultsRequest

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

Returns
TypeDescription
SimulatorClient.ListReplayResultsPagedResponse

listReplayResults(ReplayName parent)

public final SimulatorClient.ListReplayResultsPagedResponse listReplayResults(ReplayName parent)

Lists the results of running a Replay.

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 (SimulatorClient simulatorClient = SimulatorClient.create()) {
   ReplayName parent =
       ReplayName.ofProjectLocationReplayName("[PROJECT]", "[LOCATION]", "[REPLAY]");
   for (ReplayResult element : simulatorClient.listReplayResults(parent).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
NameDescription
parentReplayName

Required. The Replay whose results are listed, in the following format:

{projects|folders|organizations}/{resource-id}/locations/global/replays/{replay-id}

Example: projects/my-project/locations/global/replays/506a5f7f-38ce-4d7d-8e03-479ce1833c36

Returns
TypeDescription
SimulatorClient.ListReplayResultsPagedResponse

listReplayResults(String parent)

public final SimulatorClient.ListReplayResultsPagedResponse listReplayResults(String parent)

Lists the results of running a Replay.

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 (SimulatorClient simulatorClient = SimulatorClient.create()) {
   String parent =
       ReplayName.ofProjectLocationReplayName("[PROJECT]", "[LOCATION]", "[REPLAY]").toString();
   for (ReplayResult element : simulatorClient.listReplayResults(parent).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
NameDescription
parentString

Required. The Replay whose results are listed, in the following format:

{projects|folders|organizations}/{resource-id}/locations/global/replays/{replay-id}

Example: projects/my-project/locations/global/replays/506a5f7f-38ce-4d7d-8e03-479ce1833c36

Returns
TypeDescription
SimulatorClient.ListReplayResultsPagedResponse

listReplayResultsCallable()

public final UnaryCallable<ListReplayResultsRequest,ListReplayResultsResponse> listReplayResultsCallable()

Lists the results of running a Replay.

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 (SimulatorClient simulatorClient = SimulatorClient.create()) {
   ListReplayResultsRequest request =
       ListReplayResultsRequest.newBuilder()
           .setParent(
               ReplayName.ofProjectLocationReplayName("[PROJECT]", "[LOCATION]", "[REPLAY]")
                   .toString())
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .build();
   while (true) {
     ListReplayResultsResponse response =
         simulatorClient.listReplayResultsCallable().call(request);
     for (ReplayResult element : response.getReplayResultsList()) {
       // doThingsWith(element);
     }
     String nextPageToken = response.getNextPageToken();
     if (!Strings.isNullOrEmpty(nextPageToken)) {
       request = request.toBuilder().setPageToken(nextPageToken).build();
     } else {
       break;
     }
   }
 }
 
Returns
TypeDescription
UnaryCallable<ListReplayResultsRequest,ListReplayResultsResponse>

listReplayResultsPagedCallable()

public final UnaryCallable<ListReplayResultsRequest,SimulatorClient.ListReplayResultsPagedResponse> listReplayResultsPagedCallable()

Lists the results of running a Replay.

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 (SimulatorClient simulatorClient = SimulatorClient.create()) {
   ListReplayResultsRequest request =
       ListReplayResultsRequest.newBuilder()
           .setParent(
               ReplayName.ofProjectLocationReplayName("[PROJECT]", "[LOCATION]", "[REPLAY]")
                   .toString())
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .build();
   ApiFuture<ReplayResult> future =
       simulatorClient.listReplayResultsPagedCallable().futureCall(request);
   // Do something.
   for (ReplayResult element : future.get().iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Returns
TypeDescription
UnaryCallable<ListReplayResultsRequest,ListReplayResultsPagedResponse>

shutdown()

public void shutdown()

shutdownNow()

public void shutdownNow()