Search in sources :

Example 1 with Backup

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

the class BaseBigtableTableAdminClient method deleteBackup.

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
 * Deletes a pending or completed Cloud Bigtable backup.
 *
 * <p>Sample code:
 *
 * <pre>{@code
 * try (BaseBigtableTableAdminClient baseBigtableTableAdminClient =
 *     BaseBigtableTableAdminClient.create()) {
 *   BackupName name = BackupName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[BACKUP]");
 *   baseBigtableTableAdminClient.deleteBackup(name);
 * }
 * }</pre>
 *
 * @param name Required. Name of the backup to delete. Values are of the form
 *     `projects/{project}/instances/{instance}/clusters/{cluster}/backups/{backup}`.
 * @throws com.google.api.gax.rpc.ApiException if the remote call fails
 */
public final void deleteBackup(BackupName name) {
    DeleteBackupRequest request = DeleteBackupRequest.newBuilder().setName(name == null ? null : name.toString()).build();
    deleteBackup(request);
}
Also used : DeleteBackupRequest(com.google.bigtable.admin.v2.DeleteBackupRequest)

Example 2 with Backup

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

the class BaseBigtableTableAdminClient method deleteBackup.

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
 * Deletes a pending or completed Cloud Bigtable backup.
 *
 * <p>Sample code:
 *
 * <pre>{@code
 * try (BaseBigtableTableAdminClient baseBigtableTableAdminClient =
 *     BaseBigtableTableAdminClient.create()) {
 *   String name = BackupName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[BACKUP]").toString();
 *   baseBigtableTableAdminClient.deleteBackup(name);
 * }
 * }</pre>
 *
 * @param name Required. Name of the backup to delete. Values are of the form
 *     `projects/{project}/instances/{instance}/clusters/{cluster}/backups/{backup}`.
 * @throws com.google.api.gax.rpc.ApiException if the remote call fails
 */
public final void deleteBackup(String name) {
    DeleteBackupRequest request = DeleteBackupRequest.newBuilder().setName(name).build();
    deleteBackup(request);
}
Also used : DeleteBackupRequest(com.google.bigtable.admin.v2.DeleteBackupRequest)

Example 3 with Backup

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

the class BaseBigtableTableAdminClientTest method updateBackupTest.

@Test
public void updateBackupTest() throws Exception {
    Backup expectedResponse = Backup.newBuilder().setName(BackupName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[BACKUP]").toString()).setSourceTable("sourceTable-95372173").setExpireTime(Timestamp.newBuilder().build()).setStartTime(Timestamp.newBuilder().build()).setEndTime(Timestamp.newBuilder().build()).setSizeBytes(-1796325715).setEncryptionInfo(EncryptionInfo.newBuilder().build()).build();
    mockBigtableTableAdmin.addResponse(expectedResponse);
    Backup backup = Backup.newBuilder().build();
    FieldMask updateMask = FieldMask.newBuilder().build();
    Backup actualResponse = client.updateBackup(backup, updateMask);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockBigtableTableAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    UpdateBackupRequest actualRequest = ((UpdateBackupRequest) actualRequests.get(0));
    Assert.assertEquals(backup, actualRequest.getBackup());
    Assert.assertEquals(updateMask, actualRequest.getUpdateMask());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) Backup(com.google.bigtable.admin.v2.Backup) UpdateBackupRequest(com.google.bigtable.admin.v2.UpdateBackupRequest) FieldMask(com.google.protobuf.FieldMask) Test(org.junit.Test)

Example 4 with Backup

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

the class BigtableTableAdminClientTest method testListBackups.

@Test
public void testListBackups() {
    // Setup
    Mockito.when(mockStub.listBackupsPagedCallable()).thenReturn(mockListBackupCallable);
    com.google.bigtable.admin.v2.ListBackupsRequest testRequest = com.google.bigtable.admin.v2.ListBackupsRequest.newBuilder().setParent(NameUtil.formatClusterName(PROJECT_ID, INSTANCE_ID, CLUSTER_ID)).build();
    // 3 Backups spread across 2 pages
    List<com.google.bigtable.admin.v2.Backup> expectedProtos = Lists.newArrayList();
    for (int i = 0; i < 3; i++) {
        expectedProtos.add(com.google.bigtable.admin.v2.Backup.newBuilder().setName(NameUtil.formatBackupName(PROJECT_ID, INSTANCE_ID, CLUSTER_ID, BACKUP_ID + i)).build());
    }
    // 2 on the first page
    ListBackupsPage page0 = Mockito.mock(ListBackupsPage.class);
    Mockito.when(page0.getValues()).thenReturn(expectedProtos.subList(0, 2));
    Mockito.when(page0.hasNextPage()).thenReturn(true);
    // 1 on the last page
    ListBackupsPage page1 = Mockito.mock(ListBackupsPage.class);
    Mockito.when(page1.getValues()).thenReturn(expectedProtos.subList(2, 3));
    // Link page0 to page1
    Mockito.when(page0.getNextPageAsync()).thenReturn(ApiFutures.immediateFuture(page1));
    // Link page to the response
    ListBackupsPagedResponse response0 = Mockito.mock(ListBackupsPagedResponse.class);
    Mockito.when(response0.getPage()).thenReturn(page0);
    Mockito.when(mockListBackupCallable.futureCall(testRequest)).thenReturn(ApiFutures.immediateFuture(response0));
    // Execute
    List<String> actualResults = adminClient.listBackups(CLUSTER_ID);
    // Verify
    List<String> expectedResults = Lists.newArrayList();
    for (com.google.bigtable.admin.v2.Backup expectedProto : expectedProtos) {
        expectedResults.add(NameUtil.extractBackupIdFromBackupName(expectedProto.getName()));
    }
    assertThat(actualResults).containsExactlyElementsIn(expectedResults);
}
Also used : ListBackupsPage(com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListBackupsPage) Backup(com.google.cloud.bigtable.admin.v2.models.Backup) ByteString(com.google.protobuf.ByteString) ListBackupsRequest(com.google.bigtable.admin.v2.ListBackupsRequest) ListBackupsPagedResponse(com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListBackupsPagedResponse) Test(org.junit.Test)

Example 5 with Backup

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

the class BaseBigtableTableAdminClientTest method createBackupTest2.

@Test
public void createBackupTest2() throws Exception {
    Backup expectedResponse = Backup.newBuilder().setName(BackupName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[BACKUP]").toString()).setSourceTable("sourceTable-95372173").setExpireTime(Timestamp.newBuilder().build()).setStartTime(Timestamp.newBuilder().build()).setEndTime(Timestamp.newBuilder().build()).setSizeBytes(-1796325715).setEncryptionInfo(EncryptionInfo.newBuilder().build()).build();
    Operation resultOperation = Operation.newBuilder().setName("createBackupTest").setDone(true).setResponse(Any.pack(expectedResponse)).build();
    mockBigtableTableAdmin.addResponse(resultOperation);
    String parent = "parent-995424086";
    String backupId = "backupId2121930365";
    Backup backup = Backup.newBuilder().build();
    Backup actualResponse = client.createBackupAsync(parent, backupId, backup).get();
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockBigtableTableAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateBackupRequest actualRequest = ((CreateBackupRequest) actualRequests.get(0));
    Assert.assertEquals(parent, actualRequest.getParent());
    Assert.assertEquals(backupId, actualRequest.getBackupId());
    Assert.assertEquals(backup, actualRequest.getBackup());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : CreateBackupRequest(com.google.bigtable.admin.v2.CreateBackupRequest) AbstractMessage(com.google.protobuf.AbstractMessage) Backup(com.google.bigtable.admin.v2.Backup) Operation(com.google.longrunning.Operation) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)15 Backup (com.google.bigtable.admin.v2.Backup)10 AbstractMessage (com.google.protobuf.AbstractMessage)8 ByteString (com.google.protobuf.ByteString)7 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)5 StatusRuntimeException (io.grpc.StatusRuntimeException)5 BackupName (com.google.bigtable.admin.v2.BackupName)4 ListBackupsRequest (com.google.bigtable.admin.v2.ListBackupsRequest)4 ListBackupsPagedResponse (com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListBackupsPagedResponse)4 ClusterName (com.google.bigtable.admin.v2.ClusterName)3 DeleteBackupRequest (com.google.bigtable.admin.v2.DeleteBackupRequest)3 GetBackupRequest (com.google.bigtable.admin.v2.GetBackupRequest)3 Backup (com.google.cloud.bigtable.admin.v2.models.Backup)3 CreateBackupRequest (com.google.bigtable.admin.v2.CreateBackupRequest)2 ListBackupsResponse (com.google.bigtable.admin.v2.ListBackupsResponse)2 ListBackupsPage (com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListBackupsPage)2 Operation (com.google.longrunning.Operation)2 FieldMask (com.google.protobuf.FieldMask)2 ExecutionException (java.util.concurrent.ExecutionException)2 ApiFuture (com.google.api.core.ApiFuture)1