Class SnapshotsClient

  • All Implemented Interfaces:
    com.google.api.gax.core.BackgroundResource, AutoCloseable

    @Generated("by gapic-generator-java")
    public class SnapshotsClient
    extends Object
    implements com.google.api.gax.core.BackgroundResource
    Service Description: The Snapshots API.

    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 (SnapshotsClient snapshotsClient = SnapshotsClient.create()) {
       String project = "project-309310695";
       String snapshot = "snapshot284874180";
       Snapshot response = snapshotsClient.get(project, snapshot);
     }
     

    Note: close() needs to be called on the SnapshotsClient 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 SnapshotsSettings 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
     SnapshotsSettings snapshotsSettings =
         SnapshotsSettings.newBuilder()
             .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
             .build();
     SnapshotsClient snapshotsClient = SnapshotsClient.create(snapshotsSettings);
     

    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
     SnapshotsSettings snapshotsSettings =
         SnapshotsSettings.newBuilder().setEndpoint(myEndpoint).build();
     SnapshotsClient snapshotsClient = SnapshotsClient.create(snapshotsSettings);
     

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

    • Constructor Detail

      • SnapshotsClient

        protected SnapshotsClient​(SnapshotsSettings settings)
                           throws IOException
        Constructs an instance of SnapshotsClient, 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
      • SnapshotsClient

        protected SnapshotsClient​(SnapshotsStub stub)
    • Method Detail

      • create

        public static final SnapshotsClient create​(SnapshotsSettings settings)
                                            throws IOException
        Constructs an instance of SnapshotsClient, 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 SnapshotsClient create​(SnapshotsStub stub)
        Constructs an instance of SnapshotsClient, using the given stub for making calls. This is for advanced usage - prefer using create(SnapshotsSettings).
      • deleteAsync

        public final com.google.api.gax.longrunning.OperationFuture<Operation,​Operation> deleteAsync​(String project,
                                                                                                           String snapshot)
        Deletes the specified Snapshot resource. Keep in mind that deleting a single snapshot might not necessarily delete all the data on that snapshot. If any data on the snapshot that is marked for deletion is needed for subsequent snapshots, the data will be moved to the next corresponding snapshot. For more information, see Deleting snapshots.

        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 (SnapshotsClient snapshotsClient = SnapshotsClient.create()) {
           String project = "project-309310695";
           String snapshot = "snapshot284874180";
           Operation response = snapshotsClient.deleteAsync(project, snapshot).get();
         }
         
        Parameters:
        project - Project ID for this request.
        snapshot - Name of the Snapshot resource to delete.
        Throws:
        com.google.api.gax.rpc.ApiException - if the remote call fails
      • deleteAsync

        @BetaApi("The surface for long-running operations is not stable yet and may change in the future.")
        public final com.google.api.gax.longrunning.OperationFuture<Operation,​Operation> deleteAsync​(DeleteSnapshotRequest request)
        Deletes the specified Snapshot resource. Keep in mind that deleting a single snapshot might not necessarily delete all the data on that snapshot. If any data on the snapshot that is marked for deletion is needed for subsequent snapshots, the data will be moved to the next corresponding snapshot. For more information, see Deleting snapshots.

        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 (SnapshotsClient snapshotsClient = SnapshotsClient.create()) {
           DeleteSnapshotRequest request =
               DeleteSnapshotRequest.newBuilder()
                   .setProject("project-309310695")
                   .setRequestId("requestId693933066")
                   .setSnapshot("snapshot284874180")
                   .build();
           Operation response = snapshotsClient.deleteAsync(request).get();
         }
         
        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
      • deleteOperationCallable

        public final com.google.api.gax.rpc.OperationCallable<DeleteSnapshotRequest,​Operation,​Operation> deleteOperationCallable()
        Deletes the specified Snapshot resource. Keep in mind that deleting a single snapshot might not necessarily delete all the data on that snapshot. If any data on the snapshot that is marked for deletion is needed for subsequent snapshots, the data will be moved to the next corresponding snapshot. For more information, see Deleting snapshots.

        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 (SnapshotsClient snapshotsClient = SnapshotsClient.create()) {
           DeleteSnapshotRequest request =
               DeleteSnapshotRequest.newBuilder()
                   .setProject("project-309310695")
                   .setRequestId("requestId693933066")
                   .setSnapshot("snapshot284874180")
                   .build();
           OperationFuture<Operation, Operation> future =
               snapshotsClient.deleteOperationCallable().futureCall(request);
           // Do something.
           Operation response = future.get();
         }
         
      • deleteCallable

        public final com.google.api.gax.rpc.UnaryCallable<DeleteSnapshotRequest,​Operation> deleteCallable()
        Deletes the specified Snapshot resource. Keep in mind that deleting a single snapshot might not necessarily delete all the data on that snapshot. If any data on the snapshot that is marked for deletion is needed for subsequent snapshots, the data will be moved to the next corresponding snapshot. For more information, see Deleting snapshots.

        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 (SnapshotsClient snapshotsClient = SnapshotsClient.create()) {
           DeleteSnapshotRequest request =
               DeleteSnapshotRequest.newBuilder()
                   .setProject("project-309310695")
                   .setRequestId("requestId693933066")
                   .setSnapshot("snapshot284874180")
                   .build();
           ApiFuture<Operation> future = snapshotsClient.deleteCallable().futureCall(request);
           // Do something.
           Operation response = future.get();
         }
         
      • get

        public final Snapshot get​(String project,
                                  String snapshot)
        Returns the specified Snapshot resource.

        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 (SnapshotsClient snapshotsClient = SnapshotsClient.create()) {
           String project = "project-309310695";
           String snapshot = "snapshot284874180";
           Snapshot response = snapshotsClient.get(project, snapshot);
         }
         
        Parameters:
        project - Project ID for this request.
        snapshot - Name of the Snapshot resource to return.
        Throws:
        com.google.api.gax.rpc.ApiException - if the remote call fails
      • get

        public final Snapshot get​(GetSnapshotRequest request)
        Returns the specified Snapshot resource.

        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 (SnapshotsClient snapshotsClient = SnapshotsClient.create()) {
           GetSnapshotRequest request =
               GetSnapshotRequest.newBuilder()
                   .setProject("project-309310695")
                   .setSnapshot("snapshot284874180")
                   .build();
           Snapshot response = snapshotsClient.get(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
      • getCallable

        public final com.google.api.gax.rpc.UnaryCallable<GetSnapshotRequest,​Snapshot> getCallable()
        Returns the specified Snapshot resource.

        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 (SnapshotsClient snapshotsClient = SnapshotsClient.create()) {
           GetSnapshotRequest request =
               GetSnapshotRequest.newBuilder()
                   .setProject("project-309310695")
                   .setSnapshot("snapshot284874180")
                   .build();
           ApiFuture<Snapshot> future = snapshotsClient.getCallable().futureCall(request);
           // Do something.
           Snapshot response = future.get();
         }
         
      • getIamPolicy

        public final Policy getIamPolicy​(String project,
                                         String resource)
        Gets the access control policy for a resource. May be empty if no such policy or resource exists.

        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 (SnapshotsClient snapshotsClient = SnapshotsClient.create()) {
           String project = "project-309310695";
           String resource = "resource-341064690";
           Policy response = snapshotsClient.getIamPolicy(project, resource);
         }
         
        Parameters:
        project - Project ID for this request.
        resource - Name or id of the resource for this request.
        Throws:
        com.google.api.gax.rpc.ApiException - if the remote call fails
      • getIamPolicy

        public final Policy getIamPolicy​(GetIamPolicySnapshotRequest request)
        Gets the access control policy for a resource. May be empty if no such policy or resource exists.

        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 (SnapshotsClient snapshotsClient = SnapshotsClient.create()) {
           GetIamPolicySnapshotRequest request =
               GetIamPolicySnapshotRequest.newBuilder()
                   .setOptionsRequestedPolicyVersion(-574521795)
                   .setProject("project-309310695")
                   .setResource("resource-341064690")
                   .build();
           Policy response = snapshotsClient.getIamPolicy(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
      • getIamPolicyCallable

        public final com.google.api.gax.rpc.UnaryCallable<GetIamPolicySnapshotRequest,​Policy> getIamPolicyCallable()
        Gets the access control policy for a resource. May be empty if no such policy or resource exists.

        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 (SnapshotsClient snapshotsClient = SnapshotsClient.create()) {
           GetIamPolicySnapshotRequest request =
               GetIamPolicySnapshotRequest.newBuilder()
                   .setOptionsRequestedPolicyVersion(-574521795)
                   .setProject("project-309310695")
                   .setResource("resource-341064690")
                   .build();
           ApiFuture<Policy> future = snapshotsClient.getIamPolicyCallable().futureCall(request);
           // Do something.
           Policy response = future.get();
         }
         
      • insertAsync

        public final com.google.api.gax.longrunning.OperationFuture<Operation,​Operation> insertAsync​(String project,
                                                                                                           Snapshot snapshotResource)
        Creates a snapshot in the specified project using the data included in the request. For regular snapshot creation, consider using this method instead of disks.createSnapshot, as this method supports more features, such as creating snapshots in a project different from the source disk project.

        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 (SnapshotsClient snapshotsClient = SnapshotsClient.create()) {
           String project = "project-309310695";
           Snapshot snapshotResource = Snapshot.newBuilder().build();
           Operation response = snapshotsClient.insertAsync(project, snapshotResource).get();
         }
         
        Parameters:
        project - Project ID for this request.
        snapshotResource - The body resource for this request
        Throws:
        com.google.api.gax.rpc.ApiException - if the remote call fails
      • insertAsync

        @BetaApi("The surface for long-running operations is not stable yet and may change in the future.")
        public final com.google.api.gax.longrunning.OperationFuture<Operation,​Operation> insertAsync​(InsertSnapshotRequest request)
        Creates a snapshot in the specified project using the data included in the request. For regular snapshot creation, consider using this method instead of disks.createSnapshot, as this method supports more features, such as creating snapshots in a project different from the source disk project.

        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 (SnapshotsClient snapshotsClient = SnapshotsClient.create()) {
           InsertSnapshotRequest request =
               InsertSnapshotRequest.newBuilder()
                   .setProject("project-309310695")
                   .setRequestId("requestId693933066")
                   .setSnapshotResource(Snapshot.newBuilder().build())
                   .build();
           Operation response = snapshotsClient.insertAsync(request).get();
         }
         
        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
      • insertOperationCallable

        public final com.google.api.gax.rpc.OperationCallable<InsertSnapshotRequest,​Operation,​Operation> insertOperationCallable()
        Creates a snapshot in the specified project using the data included in the request. For regular snapshot creation, consider using this method instead of disks.createSnapshot, as this method supports more features, such as creating snapshots in a project different from the source disk project.

        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 (SnapshotsClient snapshotsClient = SnapshotsClient.create()) {
           InsertSnapshotRequest request =
               InsertSnapshotRequest.newBuilder()
                   .setProject("project-309310695")
                   .setRequestId("requestId693933066")
                   .setSnapshotResource(Snapshot.newBuilder().build())
                   .build();
           OperationFuture<Operation, Operation> future =
               snapshotsClient.insertOperationCallable().futureCall(request);
           // Do something.
           Operation response = future.get();
         }
         
      • insertCallable

        public final com.google.api.gax.rpc.UnaryCallable<InsertSnapshotRequest,​Operation> insertCallable()
        Creates a snapshot in the specified project using the data included in the request. For regular snapshot creation, consider using this method instead of disks.createSnapshot, as this method supports more features, such as creating snapshots in a project different from the source disk project.

        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 (SnapshotsClient snapshotsClient = SnapshotsClient.create()) {
           InsertSnapshotRequest request =
               InsertSnapshotRequest.newBuilder()
                   .setProject("project-309310695")
                   .setRequestId("requestId693933066")
                   .setSnapshotResource(Snapshot.newBuilder().build())
                   .build();
           ApiFuture<Operation> future = snapshotsClient.insertCallable().futureCall(request);
           // Do something.
           Operation response = future.get();
         }
         
      • list

        public final SnapshotsClient.ListPagedResponse list​(String project)
        Retrieves the list of Snapshot resources contained within the specified project.

        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 (SnapshotsClient snapshotsClient = SnapshotsClient.create()) {
           String project = "project-309310695";
           for (Snapshot element : snapshotsClient.list(project).iterateAll()) {
             // doThingsWith(element);
           }
         }
         
        Parameters:
        project - Project ID for this request.
        Throws:
        com.google.api.gax.rpc.ApiException - if the remote call fails
      • list

        public final SnapshotsClient.ListPagedResponse list​(ListSnapshotsRequest request)
        Retrieves the list of Snapshot resources contained within the specified project.

        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 (SnapshotsClient snapshotsClient = SnapshotsClient.create()) {
           ListSnapshotsRequest request =
               ListSnapshotsRequest.newBuilder()
                   .setFilter("filter-1274492040")
                   .setMaxResults(1128457243)
                   .setOrderBy("orderBy-1207110587")
                   .setPageToken("pageToken873572522")
                   .setProject("project-309310695")
                   .setReturnPartialSuccess(true)
                   .build();
           for (Snapshot element : snapshotsClient.list(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
      • listPagedCallable

        public final com.google.api.gax.rpc.UnaryCallable<ListSnapshotsRequest,​SnapshotsClient.ListPagedResponse> listPagedCallable()
        Retrieves the list of Snapshot resources contained within the specified project.

        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 (SnapshotsClient snapshotsClient = SnapshotsClient.create()) {
           ListSnapshotsRequest request =
               ListSnapshotsRequest.newBuilder()
                   .setFilter("filter-1274492040")
                   .setMaxResults(1128457243)
                   .setOrderBy("orderBy-1207110587")
                   .setPageToken("pageToken873572522")
                   .setProject("project-309310695")
                   .setReturnPartialSuccess(true)
                   .build();
           ApiFuture<Snapshot> future = snapshotsClient.listPagedCallable().futureCall(request);
           // Do something.
           for (Snapshot element : future.get().iterateAll()) {
             // doThingsWith(element);
           }
         }
         
      • listCallable

        public final com.google.api.gax.rpc.UnaryCallable<ListSnapshotsRequest,​SnapshotList> listCallable()
        Retrieves the list of Snapshot resources contained within the specified project.

        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 (SnapshotsClient snapshotsClient = SnapshotsClient.create()) {
           ListSnapshotsRequest request =
               ListSnapshotsRequest.newBuilder()
                   .setFilter("filter-1274492040")
                   .setMaxResults(1128457243)
                   .setOrderBy("orderBy-1207110587")
                   .setPageToken("pageToken873572522")
                   .setProject("project-309310695")
                   .setReturnPartialSuccess(true)
                   .build();
           while (true) {
             SnapshotList response = snapshotsClient.listCallable().call(request);
             for (Snapshot element : response.getItemsList()) {
               // doThingsWith(element);
             }
             String nextPageToken = response.getNextPageToken();
             if (!Strings.isNullOrEmpty(nextPageToken)) {
               request = request.toBuilder().setPageToken(nextPageToken).build();
             } else {
               break;
             }
           }
         }
         
      • setIamPolicy

        public final Policy setIamPolicy​(String project,
                                         String resource,
                                         GlobalSetPolicyRequest globalSetPolicyRequestResource)
        Sets the access control policy on the specified resource. Replaces any existing policy.

        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 (SnapshotsClient snapshotsClient = SnapshotsClient.create()) {
           String project = "project-309310695";
           String resource = "resource-341064690";
           GlobalSetPolicyRequest globalSetPolicyRequestResource =
               GlobalSetPolicyRequest.newBuilder().build();
           Policy response =
               snapshotsClient.setIamPolicy(project, resource, globalSetPolicyRequestResource);
         }
         
        Parameters:
        project - Project ID for this request.
        resource - Name or id of the resource for this request.
        globalSetPolicyRequestResource - The body resource for this request
        Throws:
        com.google.api.gax.rpc.ApiException - if the remote call fails
      • setIamPolicy

        public final Policy setIamPolicy​(SetIamPolicySnapshotRequest request)
        Sets the access control policy on the specified resource. Replaces any existing policy.

        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 (SnapshotsClient snapshotsClient = SnapshotsClient.create()) {
           SetIamPolicySnapshotRequest request =
               SetIamPolicySnapshotRequest.newBuilder()
                   .setGlobalSetPolicyRequestResource(GlobalSetPolicyRequest.newBuilder().build())
                   .setProject("project-309310695")
                   .setResource("resource-341064690")
                   .build();
           Policy response = snapshotsClient.setIamPolicy(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
      • setIamPolicyCallable

        public final com.google.api.gax.rpc.UnaryCallable<SetIamPolicySnapshotRequest,​Policy> setIamPolicyCallable()
        Sets the access control policy on the specified resource. Replaces any existing policy.

        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 (SnapshotsClient snapshotsClient = SnapshotsClient.create()) {
           SetIamPolicySnapshotRequest request =
               SetIamPolicySnapshotRequest.newBuilder()
                   .setGlobalSetPolicyRequestResource(GlobalSetPolicyRequest.newBuilder().build())
                   .setProject("project-309310695")
                   .setResource("resource-341064690")
                   .build();
           ApiFuture<Policy> future = snapshotsClient.setIamPolicyCallable().futureCall(request);
           // Do something.
           Policy response = future.get();
         }
         
      • setLabelsAsync

        public final com.google.api.gax.longrunning.OperationFuture<Operation,​Operation> setLabelsAsync​(String project,
                                                                                                              String resource,
                                                                                                              GlobalSetLabelsRequest globalSetLabelsRequestResource)
        Sets the labels on a snapshot. To learn more about labels, read the Labeling Resources documentation.

        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 (SnapshotsClient snapshotsClient = SnapshotsClient.create()) {
           String project = "project-309310695";
           String resource = "resource-341064690";
           GlobalSetLabelsRequest globalSetLabelsRequestResource =
               GlobalSetLabelsRequest.newBuilder().build();
           Operation response =
               snapshotsClient.setLabelsAsync(project, resource, globalSetLabelsRequestResource).get();
         }
         
        Parameters:
        project - Project ID for this request.
        resource - Name or id of the resource for this request.
        globalSetLabelsRequestResource - The body resource for this request
        Throws:
        com.google.api.gax.rpc.ApiException - if the remote call fails
      • setLabelsAsync

        @BetaApi("The surface for long-running operations is not stable yet and may change in the future.")
        public final com.google.api.gax.longrunning.OperationFuture<Operation,​Operation> setLabelsAsync​(SetLabelsSnapshotRequest request)
        Sets the labels on a snapshot. To learn more about labels, read the Labeling Resources documentation.

        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 (SnapshotsClient snapshotsClient = SnapshotsClient.create()) {
           SetLabelsSnapshotRequest request =
               SetLabelsSnapshotRequest.newBuilder()
                   .setGlobalSetLabelsRequestResource(GlobalSetLabelsRequest.newBuilder().build())
                   .setProject("project-309310695")
                   .setResource("resource-341064690")
                   .build();
           Operation response = snapshotsClient.setLabelsAsync(request).get();
         }
         
        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
      • setLabelsOperationCallable

        public final com.google.api.gax.rpc.OperationCallable<SetLabelsSnapshotRequest,​Operation,​Operation> setLabelsOperationCallable()
        Sets the labels on a snapshot. To learn more about labels, read the Labeling Resources documentation.

        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 (SnapshotsClient snapshotsClient = SnapshotsClient.create()) {
           SetLabelsSnapshotRequest request =
               SetLabelsSnapshotRequest.newBuilder()
                   .setGlobalSetLabelsRequestResource(GlobalSetLabelsRequest.newBuilder().build())
                   .setProject("project-309310695")
                   .setResource("resource-341064690")
                   .build();
           OperationFuture<Operation, Operation> future =
               snapshotsClient.setLabelsOperationCallable().futureCall(request);
           // Do something.
           Operation response = future.get();
         }
         
      • setLabelsCallable

        public final com.google.api.gax.rpc.UnaryCallable<SetLabelsSnapshotRequest,​Operation> setLabelsCallable()
        Sets the labels on a snapshot. To learn more about labels, read the Labeling Resources documentation.

        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 (SnapshotsClient snapshotsClient = SnapshotsClient.create()) {
           SetLabelsSnapshotRequest request =
               SetLabelsSnapshotRequest.newBuilder()
                   .setGlobalSetLabelsRequestResource(GlobalSetLabelsRequest.newBuilder().build())
                   .setProject("project-309310695")
                   .setResource("resource-341064690")
                   .build();
           ApiFuture<Operation> future = snapshotsClient.setLabelsCallable().futureCall(request);
           // Do something.
           Operation response = future.get();
         }
         
      • testIamPermissions

        public final TestPermissionsResponse testIamPermissions​(String project,
                                                                String resource,
                                                                TestPermissionsRequest testPermissionsRequestResource)
        Returns permissions that a caller has on the specified resource.

        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 (SnapshotsClient snapshotsClient = SnapshotsClient.create()) {
           String project = "project-309310695";
           String resource = "resource-341064690";
           TestPermissionsRequest testPermissionsRequestResource =
               TestPermissionsRequest.newBuilder().build();
           TestPermissionsResponse response =
               snapshotsClient.testIamPermissions(project, resource, testPermissionsRequestResource);
         }
         
        Parameters:
        project - Project ID for this request.
        resource - Name or id of the resource for this request.
        testPermissionsRequestResource - The body resource for this request
        Throws:
        com.google.api.gax.rpc.ApiException - if the remote call fails
      • testIamPermissions

        public final TestPermissionsResponse testIamPermissions​(TestIamPermissionsSnapshotRequest request)
        Returns permissions that a caller has on the specified resource.

        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 (SnapshotsClient snapshotsClient = SnapshotsClient.create()) {
           TestIamPermissionsSnapshotRequest request =
               TestIamPermissionsSnapshotRequest.newBuilder()
                   .setProject("project-309310695")
                   .setResource("resource-341064690")
                   .setTestPermissionsRequestResource(TestPermissionsRequest.newBuilder().build())
                   .build();
           TestPermissionsResponse response = snapshotsClient.testIamPermissions(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
      • testIamPermissionsCallable

        public final com.google.api.gax.rpc.UnaryCallable<TestIamPermissionsSnapshotRequest,​TestPermissionsResponse> testIamPermissionsCallable()
        Returns permissions that a caller has on the specified resource.

        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 (SnapshotsClient snapshotsClient = SnapshotsClient.create()) {
           TestIamPermissionsSnapshotRequest request =
               TestIamPermissionsSnapshotRequest.newBuilder()
                   .setProject("project-309310695")
                   .setResource("resource-341064690")
                   .setTestPermissionsRequestResource(TestPermissionsRequest.newBuilder().build())
                   .build();
           ApiFuture<TestPermissionsResponse> future =
               snapshotsClient.testIamPermissionsCallable().futureCall(request);
           // Do something.
           TestPermissionsResponse response = future.get();
         }
         
      • shutdown

        public void shutdown()
        Specified by:
        shutdown in interface com.google.api.gax.core.BackgroundResource
      • isShutdown

        public boolean isShutdown()
        Specified by:
        isShutdown in interface com.google.api.gax.core.BackgroundResource
      • isTerminated

        public boolean isTerminated()
        Specified by:
        isTerminated in interface com.google.api.gax.core.BackgroundResource
      • shutdownNow

        public void shutdownNow()
        Specified by:
        shutdownNow in interface com.google.api.gax.core.BackgroundResource