Search in sources :

Example 11 with BigtableTableAdminSettings

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

the class NativeImageBigtableTest method setUp.

@Before
public void setUp() throws IOException {
    // Create instance if not present
    BigtableInstanceAdminSettings instanceAdminSettings = BigtableInstanceAdminSettings.newBuilder().setProjectId(PROJECT_ID).build();
    BigtableInstanceAdminClient instanceAdminClient = BigtableInstanceAdminClient.create(instanceAdminSettings);
    if (!instanceAdminClient.exists(INSTANCE_NAME)) {
        instanceAdminClient.createInstance(CreateInstanceRequest.of(INSTANCE_NAME).addCluster("cluster", "us-central1-f", 3, StorageType.SSD).setType(Instance.Type.PRODUCTION).addLabel("example", "instance_admin"));
    }
    BigtableTableAdminSettings adminClientSettings = BigtableTableAdminSettings.newBuilder().setInstanceId(INSTANCE_NAME).setProjectId(PROJECT_ID).build();
    BigtableDataSettings clientSettings = BigtableDataSettings.newBuilder().setInstanceId(INSTANCE_NAME).setProjectId(PROJECT_ID).build();
    adminClient = BigtableTableAdminClient.create(adminClientSettings);
    tableName = TABLE_SUFFIX + UUID.randomUUID().toString().replace("-", "");
    NativeImageBigtableSample.createTable(adminClient, tableName);
    dataClient = BigtableDataClient.create(clientSettings);
    // To test output stream
    originalOut = System.out;
    bout = new ByteArrayOutputStream();
    System.setOut(new PrintStream(bout));
}
Also used : PrintStream(java.io.PrintStream) BigtableTableAdminSettings(com.google.cloud.bigtable.admin.v2.BigtableTableAdminSettings) BigtableInstanceAdminClient(com.google.cloud.bigtable.admin.v2.BigtableInstanceAdminClient) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BigtableDataSettings(com.google.cloud.bigtable.data.v2.BigtableDataSettings) BigtableInstanceAdminSettings(com.google.cloud.bigtable.admin.v2.BigtableInstanceAdminSettings) Before(org.junit.Before)

Example 12 with BigtableTableAdminSettings

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

the class NativeImageBigtableSample method main.

/**
 * Entrypoint to the BigTable sample application.
 */
public static void main(String[] args) throws IOException {
    String projectId = ServiceOptions.getDefaultProjectId();
    BigtableTableAdminSettings adminClientSettings = BigtableTableAdminSettings.newBuilder().setInstanceId(INSTANCE_NAME).setProjectId(projectId).build();
    BigtableDataSettings clientSettings = BigtableDataSettings.newBuilder().setInstanceId(INSTANCE_NAME).setProjectId(projectId).build();
    BigtableInstanceAdminSettings instanceAdminSettings = BigtableInstanceAdminSettings.newBuilder().setProjectId(projectId).build();
    BigtableTableAdminClient adminClient = BigtableTableAdminClient.create(adminClientSettings);
    BigtableDataClient standardClient = BigtableDataClient.create(clientSettings);
    BigtableInstanceAdminClient instanceAdminClient = BigtableInstanceAdminClient.create(instanceAdminSettings);
    if (!instanceAdminClient.exists(INSTANCE_NAME)) {
        instanceAdminClient.createInstance(CreateInstanceRequest.of(INSTANCE_NAME).addCluster("cluster", "us-central1-f", 3, StorageType.SSD).setType(Instance.Type.PRODUCTION).addLabel("example", "instance_admin"));
    }
    String tableName = TABLE_NAME + UUID.randomUUID().toString().replace("-", "");
    createTable(adminClient, tableName);
    // Add data into table
    ImmutableMap<String, Long> dataWithLong = ImmutableMap.of("connected_cell", 1L, "connected_wifi", 1L);
    ImmutableMap<String, String> dataWithStrings = ImmutableMap.of("os_build", "PQ2A.190405.003");
    long timestamp = System.currentTimeMillis() * 1000;
    insertData(standardClient, tableName, timestamp, dataWithLong, dataWithStrings);
    readData(standardClient, tableName);
    // Clean up
    deleteTable(adminClient, tableName);
}
Also used : BigtableTableAdminSettings(com.google.cloud.bigtable.admin.v2.BigtableTableAdminSettings) BigtableInstanceAdminClient(com.google.cloud.bigtable.admin.v2.BigtableInstanceAdminClient) ByteString(com.google.protobuf.ByteString) BigtableTableAdminClient(com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient) BigtableDataClient(com.google.cloud.bigtable.data.v2.BigtableDataClient) BigtableDataSettings(com.google.cloud.bigtable.data.v2.BigtableDataSettings) BigtableInstanceAdminSettings(com.google.cloud.bigtable.admin.v2.BigtableInstanceAdminSettings)

Example 13 with BigtableTableAdminSettings

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

the class TableAdminExampleTest method beforeClass.

@BeforeClass
public static void beforeClass() throws IOException {
    initializeVariables();
    BigtableTableAdminSettings adminSettings = BigtableTableAdminSettings.newBuilder().setInstanceId(instanceId).setProjectId(projectId).build();
    adminClient = BigtableTableAdminClient.create(adminSettings);
}
Also used : BigtableTableAdminSettings(com.google.cloud.bigtable.admin.v2.BigtableTableAdminSettings) BeforeClass(org.junit.BeforeClass)

Example 14 with BigtableTableAdminSettings

use of com.google.cloud.bigtable.admin.v2.BigtableTableAdminSettings in project native-image-support-java by GoogleCloudPlatform.

the class BigTableSampleApplication method main.

/**
 * Entrypoint to the BigTable sample application.
 */
public static void main(String[] args) throws IOException {
    String projectId = ServiceOptions.getDefaultProjectId();
    BigtableTableAdminSettings adminClientSettings = BigtableTableAdminSettings.newBuilder().setInstanceId(INSTANCE_NAME).setProjectId(projectId).build();
    BigtableDataSettings clientSettings = BigtableDataSettings.newBuilder().setInstanceId(INSTANCE_NAME).setProjectId(projectId).build();
    BigtableTableAdminClient adminClient = BigtableTableAdminClient.create(adminClientSettings);
    BigtableDataClient standardClient = BigtableDataClient.create(clientSettings);
    String tableName = TABLE_NAME + UUID.randomUUID().toString();
    createTable(adminClient, tableName);
    insertData(standardClient, tableName);
    readData(standardClient, tableName);
    // Clean up
    deleteTable(adminClient, tableName);
}
Also used : BigtableTableAdminSettings(com.google.cloud.bigtable.admin.v2.BigtableTableAdminSettings) ByteString(com.google.protobuf.ByteString) BigtableTableAdminClient(com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient) BigtableDataClient(com.google.cloud.bigtable.data.v2.BigtableDataClient) BigtableDataSettings(com.google.cloud.bigtable.data.v2.BigtableDataSettings)

Aggregations

BigtableTableAdminSettings (com.google.cloud.bigtable.admin.v2.BigtableTableAdminSettings)13 Test (org.junit.Test)6 BigtableTableAdminClient (com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient)5 BigtableDataSettings (com.google.cloud.bigtable.data.v2.BigtableDataSettings)5 NoCredentialsProvider (com.google.api.gax.core.NoCredentialsProvider)2 BigtableInstanceAdminClient (com.google.cloud.bigtable.admin.v2.BigtableInstanceAdminClient)2 BigtableInstanceAdminSettings (com.google.cloud.bigtable.admin.v2.BigtableInstanceAdminSettings)2 BigtableDataClient (com.google.cloud.bigtable.data.v2.BigtableDataClient)2 ByteString (com.google.protobuf.ByteString)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 PrintStream (java.io.PrintStream)2 BeforeClass (org.junit.BeforeClass)2 CreateBackupMessage (com.example.cloud.bigtable.scheduledbackups.resource.CreateBackupMessage)1 CredentialsProvider (com.google.api.gax.core.CredentialsProvider)1 InstantiatingGrpcChannelProvider (com.google.api.gax.grpc.InstantiatingGrpcChannelProvider)1 NotFoundException (com.google.api.gax.rpc.NotFoundException)1 Credentials (com.google.auth.Credentials)1 Backup (com.google.cloud.bigtable.admin.v2.models.Backup)1 Cluster (com.google.cloud.bigtable.admin.v2.models.Cluster)1 CreateBackupRequest (com.google.cloud.bigtable.admin.v2.models.CreateBackupRequest)1