Search in sources :

Example 1 with DeleteInstanceRequest

use of com.google.bigtable.admin.v2.DeleteInstanceRequest in project java-docs-samples by GoogleCloudPlatform.

the class DeleteInstance method deleteInstance.

// Delete the instance specified by `instanceName`
// if it's present in the given project and zone.
public static void deleteInstance(String project, String zone, String instanceName) throws IOException, InterruptedException, ExecutionException {
    // clean up any remaining background resources.
    try (InstancesClient instancesClient = InstancesClient.create()) {
        System.out.printf("Deleting instance: %s ", instanceName);
        // Describe which instance is to be deleted.
        DeleteInstanceRequest deleteInstanceRequest = DeleteInstanceRequest.newBuilder().setProject(project).setZone(zone).setInstance(instanceName).build();
        OperationFuture<Operation, Operation> operation = instancesClient.deleteAsync(deleteInstanceRequest);
        // Wait for the operation to complete.
        Operation response = operation.get();
        if (response.hasError()) {
            System.out.println("Instance deletion failed ! ! " + response);
            return;
        }
        System.out.println("Operation Status: " + response.getStatus());
    }
}
Also used : InstancesClient(com.google.cloud.compute.v1.InstancesClient) Operation(com.google.cloud.compute.v1.Operation) DeleteInstanceRequest(com.google.cloud.compute.v1.DeleteInstanceRequest)

Example 2 with DeleteInstanceRequest

use of com.google.bigtable.admin.v2.DeleteInstanceRequest in project java-bigtable by googleapis.

the class BaseBigtableInstanceAdminClient method deleteInstance.

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
 * Delete an instance from a project.
 *
 * <p>Sample code:
 *
 * <pre>{@code
 * try (BaseBigtableInstanceAdminClient baseBigtableInstanceAdminClient =
 *     BaseBigtableInstanceAdminClient.create()) {
 *   String name = InstanceName.of("[PROJECT]", "[INSTANCE]").toString();
 *   baseBigtableInstanceAdminClient.deleteInstance(name);
 * }
 * }</pre>
 *
 * @param name Required. The unique name of the instance to be deleted. Values are of the form
 *     `projects/{project}/instances/{instance}`.
 * @throws com.google.api.gax.rpc.ApiException if the remote call fails
 */
public final void deleteInstance(String name) {
    DeleteInstanceRequest request = DeleteInstanceRequest.newBuilder().setName(name).build();
    deleteInstance(request);
}
Also used : DeleteInstanceRequest(com.google.bigtable.admin.v2.DeleteInstanceRequest)

Example 3 with DeleteInstanceRequest

use of com.google.bigtable.admin.v2.DeleteInstanceRequest in project java-bigtable by googleapis.

the class BaseBigtableInstanceAdminClientTest method deleteInstanceTest2.

@Test
public void deleteInstanceTest2() throws Exception {
    Empty expectedResponse = Empty.newBuilder().build();
    mockBigtableInstanceAdmin.addResponse(expectedResponse);
    String name = "name3373707";
    client.deleteInstance(name);
    List<AbstractMessage> actualRequests = mockBigtableInstanceAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    DeleteInstanceRequest actualRequest = ((DeleteInstanceRequest) actualRequests.get(0));
    Assert.assertEquals(name, actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : Empty(com.google.protobuf.Empty) AbstractMessage(com.google.protobuf.AbstractMessage) ByteString(com.google.protobuf.ByteString) DeleteInstanceRequest(com.google.bigtable.admin.v2.DeleteInstanceRequest) Test(org.junit.Test)

Example 4 with DeleteInstanceRequest

use of com.google.bigtable.admin.v2.DeleteInstanceRequest in project java-bigtable by googleapis.

the class BaseBigtableInstanceAdminClientTest method deleteInstanceTest.

@Test
public void deleteInstanceTest() throws Exception {
    Empty expectedResponse = Empty.newBuilder().build();
    mockBigtableInstanceAdmin.addResponse(expectedResponse);
    InstanceName name = InstanceName.of("[PROJECT]", "[INSTANCE]");
    client.deleteInstance(name);
    List<AbstractMessage> actualRequests = mockBigtableInstanceAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    DeleteInstanceRequest actualRequest = ((DeleteInstanceRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : InstanceName(com.google.bigtable.admin.v2.InstanceName) Empty(com.google.protobuf.Empty) AbstractMessage(com.google.protobuf.AbstractMessage) DeleteInstanceRequest(com.google.bigtable.admin.v2.DeleteInstanceRequest) Test(org.junit.Test)

Example 5 with DeleteInstanceRequest

use of com.google.bigtable.admin.v2.DeleteInstanceRequest in project java-bigtable by googleapis.

the class BaseBigtableInstanceAdminClient method deleteInstance.

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
 * Delete an instance from a project.
 *
 * <p>Sample code:
 *
 * <pre>{@code
 * try (BaseBigtableInstanceAdminClient baseBigtableInstanceAdminClient =
 *     BaseBigtableInstanceAdminClient.create()) {
 *   InstanceName name = InstanceName.of("[PROJECT]", "[INSTANCE]");
 *   baseBigtableInstanceAdminClient.deleteInstance(name);
 * }
 * }</pre>
 *
 * @param name Required. The unique name of the instance to be deleted. Values are of the form
 *     `projects/{project}/instances/{instance}`.
 * @throws com.google.api.gax.rpc.ApiException if the remote call fails
 */
public final void deleteInstance(InstanceName name) {
    DeleteInstanceRequest request = DeleteInstanceRequest.newBuilder().setName(name == null ? null : name.toString()).build();
    deleteInstance(request);
}
Also used : DeleteInstanceRequest(com.google.bigtable.admin.v2.DeleteInstanceRequest)

Aggregations

DeleteInstanceRequest (com.google.bigtable.admin.v2.DeleteInstanceRequest)4 AbstractMessage (com.google.protobuf.AbstractMessage)2 Empty (com.google.protobuf.Empty)2 Test (org.junit.Test)2 InstanceName (com.google.bigtable.admin.v2.InstanceName)1 DeleteInstanceRequest (com.google.cloud.compute.v1.DeleteInstanceRequest)1 InstancesClient (com.google.cloud.compute.v1.InstancesClient)1 Operation (com.google.cloud.compute.v1.Operation)1 ByteString (com.google.protobuf.ByteString)1