Search in sources :

Example 1 with VersionRule

use of com.google.cloud.bigtable.admin.v2.models.GCRules.VersionRule 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 2 with VersionRule

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

the class TableAdminExample method addFamilyWithMaxVersionsRule.

/**
 * Demonstrates how to create a new instance of the VersionRule.
 */
public void addFamilyWithMaxVersionsRule() {
    System.out.printf("%nCreating column family %s with max versions GC rule%n", COLUMN_FAMILY_2);
    // [START bigtable_create_family_gc_max_versions]
    // Creates a column family with GC policy : most recent N versions
    // where 1 = most recent version
    // Defines the GC policy to retain only the most recent 2 versions.
    VersionRule versionRule = GCRULES.maxVersions(2);
    // Creates column family with given GC rule.
    try {
        // ModifyColumnFamiliesRequest can be used both for adding and modifying families, here it is
        // being used to add a family
        ModifyColumnFamiliesRequest columnFamiliesRequest = ModifyColumnFamiliesRequest.of(tableId).addFamily(COLUMN_FAMILY_2, versionRule);
        adminClient.modifyFamilies(columnFamiliesRequest);
        System.out.println("Created column family: " + COLUMN_FAMILY_2);
    } catch (AlreadyExistsException e) {
        System.err.println("Failed to create column family with rule, already exists: " + e.getMessage());
    }
// [END bigtable_create_family_gc_max_versions]
}
Also used : AlreadyExistsException(com.google.api.gax.rpc.AlreadyExistsException) VersionRule(com.google.cloud.bigtable.admin.v2.models.GCRules.VersionRule) ModifyColumnFamiliesRequest(com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest)

Example 3 with VersionRule

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

the class TableAdminExampleTest method testCreateIntersectionRule.

@Test
public void testCreateIntersectionRule() {
    // Intersection rule
    tableAdmin.addFamilyWithIntersectionRule();
    DurationRule maxAgeRule = GCRULES.maxAge(5, TimeUnit.DAYS);
    VersionRule versionRule = GCRULES.maxVersions(2);
    IntersectionRule intersectionCondition = GCRULES.intersection().rule(maxAgeRule).rule(versionRule);
    boolean intersectionRule = ruleCheck(intersectionCondition);
    assertTrue(intersectionRule);
}
Also used : IntersectionRule(com.google.cloud.bigtable.admin.v2.models.GCRules.IntersectionRule) DurationRule(com.google.cloud.bigtable.admin.v2.models.GCRules.DurationRule) VersionRule(com.google.cloud.bigtable.admin.v2.models.GCRules.VersionRule) Test(org.junit.Test)

Example 4 with VersionRule

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

the class BigtableTableAdminClientIT method createTable.

@Test
public void createTable() {
    assume().withMessage("Emulator doesn't return proper responses for CreateTable").that(testEnvRule.env()).isNotInstanceOf(EmulatorEnv.class);
    CreateTableRequest createTableReq = CreateTableRequest.of(tableId).addFamily("cf1").addFamily("cf2", GCRULES.maxVersions(10)).addSplit(ByteString.copyFromUtf8("b")).addSplit(ByteString.copyFromUtf8("q"));
    Table tableResponse = tableAdmin.createTable(createTableReq);
    assertEquals(tableId, tableResponse.getId());
    Map<String, ColumnFamily> columnFamilyById = Maps.newHashMap();
    for (ColumnFamily columnFamily : tableResponse.getColumnFamilies()) {
        columnFamilyById.put(columnFamily.getId(), columnFamily);
    }
    assertEquals(2, tableResponse.getColumnFamilies().size());
    assertFalse(columnFamilyById.get("cf1").hasGCRule());
    assertTrue(columnFamilyById.get("cf2").hasGCRule());
    assertEquals(10, ((VersionRule) columnFamilyById.get("cf2").getGCRule()).getMaxVersions());
}
Also used : Table(com.google.cloud.bigtable.admin.v2.models.Table) ByteString(com.google.protobuf.ByteString) CreateTableRequest(com.google.cloud.bigtable.admin.v2.models.CreateTableRequest) ColumnFamily(com.google.cloud.bigtable.admin.v2.models.ColumnFamily) Test(org.junit.Test)

Example 5 with VersionRule

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

the class GCRulesTest method versions.

@Test
public void versions() {
    VersionRule actual = GCRULES.maxVersions(10);
    GcRule expected = buildVersionsRule(10);
    assertNotNull(actual.getMaxVersions());
    assertThat(actual.toProto()).isEqualTo(expected);
}
Also used : GcRule(com.google.bigtable.admin.v2.GcRule) VersionRule(com.google.cloud.bigtable.admin.v2.models.GCRules.VersionRule) Test(org.junit.Test)

Aggregations

VersionRule (com.google.cloud.bigtable.admin.v2.models.GCRules.VersionRule)9 Test (org.junit.Test)6 DurationRule (com.google.cloud.bigtable.admin.v2.models.GCRules.DurationRule)5 IntersectionRule (com.google.cloud.bigtable.admin.v2.models.GCRules.IntersectionRule)4 ModifyColumnFamiliesRequest (com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest)4 AlreadyExistsException (com.google.api.gax.rpc.AlreadyExistsException)3 UnionRule (com.google.cloud.bigtable.admin.v2.models.GCRules.UnionRule)3 ColumnFamily (com.google.cloud.bigtable.admin.v2.models.ColumnFamily)2 NotFoundException (com.google.api.gax.rpc.NotFoundException)1 GcRule (com.google.bigtable.admin.v2.GcRule)1 CreateTableRequest (com.google.cloud.bigtable.admin.v2.models.CreateTableRequest)1 Table (com.google.cloud.bigtable.admin.v2.models.Table)1 ByteString (com.google.protobuf.ByteString)1