Search in sources :

Example 6 with ModifyColumnFamiliesRequest

use of com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest in project java-bigtable by googleapis.

the class TableAdminExample method modifyColumnFamilyRule.

/**
 * Demonstrates how to modify a column family's rule.
 */
public void modifyColumnFamilyRule() {
    System.out.printf("%nUpdating column family %s GC rule%n", COLUMN_FAMILY_1);
    // [START bigtable_update_gc_rule]
    // Updates the column family metadata to update the GC rule.
    // Updates a column family GC rule.
    VersionRule versionRule = GCRULES.maxVersions(1);
    try {
        // ModifyColumnFamiliesRequest can be used both for adding and modifying families, here it is
        // being used to modify a family
        // Updates column family with given GC rule.
        ModifyColumnFamiliesRequest updateRequest = ModifyColumnFamiliesRequest.of(tableId).updateFamily(COLUMN_FAMILY_1, versionRule);
        adminClient.modifyFamilies(updateRequest);
        System.out.printf("Column family %s GC rule updated%n", COLUMN_FAMILY_1);
    } catch (NotFoundException e) {
        System.err.println("Failed to modify a non-existent column family: " + e.getMessage());
    }
// [END bigtable_update_gc_rule]
}
Also used : NotFoundException(com.google.api.gax.rpc.NotFoundException) VersionRule(com.google.cloud.bigtable.admin.v2.models.GCRules.VersionRule) ModifyColumnFamiliesRequest(com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest)

Example 7 with ModifyColumnFamiliesRequest

use of com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest in project java-bigtable by googleapis.

the class BigtableTableAdminClientTests method testModifyFamilies.

@Test
public void testModifyFamilies() {
    // Setup
    Mockito.when(mockStub.modifyColumnFamiliesCallable()).thenReturn(mockModifyTableCallable);
    com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest expectedRequest = com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest.newBuilder().setName(TABLE_NAME).addModifications(Modification.newBuilder().setId("cf").setCreate(ColumnFamily.newBuilder().setGcRule(GcRule.getDefaultInstance()))).build();
    com.google.bigtable.admin.v2.Table fakeResponse = com.google.bigtable.admin.v2.Table.newBuilder().setName(TABLE_NAME).putColumnFamilies("cf", ColumnFamily.newBuilder().setGcRule(GcRule.getDefaultInstance()).build()).build();
    Mockito.when(mockModifyTableCallable.futureCall(expectedRequest)).thenReturn(ApiFutures.immediateFuture(fakeResponse));
    // Execute
    Table actualResult = adminClient.modifyFamilies(ModifyColumnFamiliesRequest.of(TABLE_ID).addFamily("cf"));
    // Verify
    assertThat(actualResult).isEqualTo(Table.fromProto(fakeResponse));
}
Also used : Table(com.google.cloud.bigtable.admin.v2.models.Table) Test(org.junit.Test)

Example 8 with ModifyColumnFamiliesRequest

use of com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest in project java-bigtable by googleapis.

the class BigtableTableAdminClientIT method modifyFamilies.

@Test
public void modifyFamilies() {
    tableAdmin.createTable(CreateTableRequest.of(tableId));
    ModifyColumnFamiliesRequest modifyFamiliesReq = ModifyColumnFamiliesRequest.of(tableId).addFamily("mf1").addFamily("mf2", GCRULES.maxAge(Duration.ofSeconds(1000, 20000))).updateFamily("mf1", GCRULES.union().rule(GCRULES.maxAge(Duration.ofSeconds(100))).rule(GCRULES.maxVersions(1))).addFamily("mf3", GCRULES.intersection().rule(GCRULES.maxAge(Duration.ofSeconds(2000))).rule(GCRULES.maxVersions(10))).addFamily("mf4", GCRULES.intersection().rule(GCRULES.maxAge(Duration.ofSeconds(360)))).addFamily("mf5").addFamily("mf6").dropFamily("mf5").dropFamily("mf6").addFamily("mf7");
    Table tableResponse = tableAdmin.modifyFamilies(modifyFamiliesReq);
    Map<String, ColumnFamily> columnFamilyById = Maps.newHashMap();
    for (ColumnFamily columnFamily : tableResponse.getColumnFamilies()) {
        columnFamilyById.put(columnFamily.getId(), columnFamily);
    }
    assertEquals(5, columnFamilyById.size());
    assertNotNull(columnFamilyById.get("mf1"));
    assertNotNull(columnFamilyById.get("mf2"));
    assertEquals(2, ((UnionRule) columnFamilyById.get("mf1").getGCRule()).getRulesList().size());
    assertEquals(1000, ((DurationRule) columnFamilyById.get("mf2").getGCRule()).getMaxAge().getSeconds());
    assertEquals(20000, ((DurationRule) columnFamilyById.get("mf2").getGCRule()).getMaxAge().getNano());
    assertEquals(2, ((IntersectionRule) columnFamilyById.get("mf3").getGCRule()).getRulesList().size());
    assertEquals(360, ((DurationRule) columnFamilyById.get("mf4").getGCRule()).getMaxAge().getSeconds());
    assertNotNull(columnFamilyById.get("mf7"));
}
Also used : Table(com.google.cloud.bigtable.admin.v2.models.Table) IntersectionRule(com.google.cloud.bigtable.admin.v2.models.GCRules.IntersectionRule) ByteString(com.google.protobuf.ByteString) UnionRule(com.google.cloud.bigtable.admin.v2.models.GCRules.UnionRule) DurationRule(com.google.cloud.bigtable.admin.v2.models.GCRules.DurationRule) ModifyColumnFamiliesRequest(com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest) ColumnFamily(com.google.cloud.bigtable.admin.v2.models.ColumnFamily) Test(org.junit.Test)

Example 9 with ModifyColumnFamiliesRequest

use of com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest in project java-bigtable-hbase by googleapis.

the class TestModifyTableBuilder method testBuildModificationForUpdateFamily.

@Test
public void testBuildModificationForUpdateFamily() {
    HTableDescriptor tableDescriptor = new HTableDescriptor(TableName.valueOf(TABLE_ID));
    HColumnDescriptor addColumn = new HColumnDescriptor(COLUMN_FAMILY);
    tableDescriptor.addFamily(addColumn);
    ModifyTableBuilder actualRequest = ModifyTableBuilder.buildModifications(tableDescriptor, new HTableDescriptor(tableDescriptor));
    ModifyColumnFamiliesRequest expectedRequest = ModifyColumnFamiliesRequest.of(TABLE_ID).updateFamily(COLUMN_FAMILY, buildGarbageCollectionRule(addColumn));
    Assert.assertEquals(expectedRequest.toProto(PROJECT_ID, INSTANCE_ID), actualRequest.build().toProto(PROJECT_ID, INSTANCE_ID));
}
Also used : HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) ModifyColumnFamiliesRequest(com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest) Test(org.junit.Test)

Example 10 with ModifyColumnFamiliesRequest

use of com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest in project java-bigtable-hbase by googleapis.

the class TestAdminClientVeneerApi method testModifyFamilyAsync.

@Test
public void testModifyFamilyAsync() throws Exception {
    ModifyColumnFamiliesRequest request = ModifyColumnFamiliesRequest.of(TABLE_ID_1).addFamily("first-family").addFamily("another-family");
    Future<Table> response = adminClientWrapper.modifyFamiliesAsync(request);
    assertEquals(TABLE_ID_1, response.get().getId());
}
Also used : Table(com.google.cloud.bigtable.admin.v2.models.Table) ModifyColumnFamiliesRequest(com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest) Test(org.junit.Test)

Aggregations

ModifyColumnFamiliesRequest (com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest)13 Test (org.junit.Test)7 AlreadyExistsException (com.google.api.gax.rpc.AlreadyExistsException)5 DurationRule (com.google.cloud.bigtable.admin.v2.models.GCRules.DurationRule)4 VersionRule (com.google.cloud.bigtable.admin.v2.models.GCRules.VersionRule)4 Table (com.google.cloud.bigtable.admin.v2.models.Table)4 IntersectionRule (com.google.cloud.bigtable.admin.v2.models.GCRules.IntersectionRule)3 UnionRule (com.google.cloud.bigtable.admin.v2.models.GCRules.UnionRule)3 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)3 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)3 NotFoundException (com.google.api.gax.rpc.NotFoundException)2 ColumnFamily (com.google.cloud.bigtable.admin.v2.models.ColumnFamily)1 ByteString (com.google.protobuf.ByteString)1 IOException (java.io.IOException)1 HBaseIOException (org.apache.hadoop.hbase.HBaseIOException)1 TableNotFoundException (org.apache.hadoop.hbase.TableNotFoundException)1