Search in sources :

Example 1 with BigtableTableAdminSettings

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

the class TestBigtableHBaseVeneerSettings method testAdminSettingsBasicKeys.

@Test
public void testAdminSettingsBasicKeys() throws IOException {
    String adminHost = "testadmin.example.com";
    String userAgent = "test-user-agent";
    String fakeTracingCookie = "fake-tracing-cookie";
    Credentials credentials = Mockito.mock(Credentials.class);
    configuration.set(BIGTABLE_ADMIN_HOST_KEY, adminHost);
    configuration.setInt(BIGTABLE_PORT_KEY, TEST_PORT);
    configuration.set(CUSTOM_USER_AGENT_KEY, userAgent);
    configuration.setBoolean(BIGTABLE_USE_PLAINTEXT_NEGOTIATION, true);
    configuration.set(BIGTABLE_USE_SERVICE_ACCOUNTS_KEY, "true");
    configuration.set(BIGTABLE_TRACING_COOKIE, fakeTracingCookie);
    configuration = BigtableConfiguration.withCredentials(configuration, credentials);
    BigtableHBaseVeneerSettings settings = (BigtableHBaseVeneerSettings) BigtableHBaseSettings.create(configuration);
    BigtableTableAdminSettings adminSettings = settings.getTableAdminSettings();
    assertEquals(TEST_PROJECT_ID, adminSettings.getProjectId());
    assertEquals(TEST_INSTANCE_ID, adminSettings.getInstanceId());
    assertEquals(TEST_INSTANCE_ID, settings.getInstanceId());
    assertEquals(adminHost + ":" + TEST_PORT, adminSettings.getStubSettings().getEndpoint());
    Map<String, String> headers = adminSettings.getStubSettings().getHeaderProvider().getHeaders();
    assertTrue(headers.get(GrpcUtil.USER_AGENT_KEY.name()).contains(userAgent));
    assertTrue(headers.get("cookie").equals(fakeTracingCookie));
    assertEquals(credentials, adminSettings.getStubSettings().getCredentialsProvider().getCredentials());
}
Also used : BigtableTableAdminSettings(com.google.cloud.bigtable.admin.v2.BigtableTableAdminSettings) Credentials(com.google.auth.Credentials) Test(org.junit.Test)

Example 2 with BigtableTableAdminSettings

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

the class HelloWorldTest method beforeClass.

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

Example 3 with BigtableTableAdminSettings

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

the class BigtableTableAdminSettingsTest method testToString.

@Test
public void testToString() throws IOException {
    BigtableTableAdminSettings defaultSettings = BigtableTableAdminSettings.newBuilder().setProjectId("our-project-85").setInstanceId("our-instance-06").build();
    checkToString(defaultSettings);
    BigtableTableAdminSettings.Builder builder = defaultSettings.toBuilder();
    BigtableTableAdminStubSettings.Builder stubSettings = builder.stubSettings().setEndpoint("example.com:1234");
    stubSettings.getBackupSettings().setRetrySettings(RetrySettings.newBuilder().setTotalTimeout(Duration.ofMinutes(812)).build());
    BigtableTableAdminSettings settings = builder.build();
    checkToString(settings);
    assertThat(defaultSettings.toString()).doesNotContain("endpoint=example.com:1234");
    assertThat(settings.toString()).contains("endpoint=example.com:1234");
    assertThat(defaultSettings.toString()).doesNotContain("totalTimeout=PT13H32M");
    assertThat(settings.toString()).contains("totalTimeout=PT13H32M");
    int nonStaticFields = 0;
    for (Field field : BigtableTableAdminStubSettings.class.getDeclaredFields()) {
        if (!Modifier.isStatic(field.getModifiers())) {
            nonStaticFields++;
        }
    }
    // failure will signal about adding a new settings property
    assertThat(SETTINGS_LIST.length).isEqualTo(nonStaticFields);
}
Also used : Field(java.lang.reflect.Field) BigtableTableAdminStubSettings(com.google.cloud.bigtable.admin.v2.stub.BigtableTableAdminStubSettings) Test(org.junit.Test)

Example 4 with BigtableTableAdminSettings

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

the class CassandraMigrationCodelabTest method testRunDoesNotFail.

@Test
public void testRunDoesNotFail() throws Exception {
    projectId = requireEnv("GOOGLE_CLOUD_PROJECT");
    instanceId = requireEnv(INSTANCE_ENV);
    BigtableTableAdminSettings adminSettings = BigtableTableAdminSettings.newBuilder().setProjectId(projectId).setInstanceId(instanceId).build();
    adminClient = BigtableTableAdminClient.create(adminSettings);
    cassandraMigrationCodelab = new CassandraMigrationCodelab(projectId, instanceId, TABLE_ID);
    adminClient.createTable(CreateTableRequest.of(TABLE_ID).addFamily(COLUMN_FAMILY_NAME));
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    System.setOut(new PrintStream(bout));
    cassandraMigrationCodelab.run();
    String output = bout.toString();
    assertThat(output, CoreMatchers.not(CoreMatchers.containsString("Error during")));
    adminClient.deleteTable(TABLE_ID);
}
Also used : PrintStream(java.io.PrintStream) BigtableTableAdminSettings(com.google.cloud.bigtable.admin.v2.BigtableTableAdminSettings) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 5 with BigtableTableAdminSettings

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

the class CreateBackup method accept.

@Override
public void accept(PubSubMessage message, Context context) {
    if (message != null && message.getData() != null) {
        logger.info("Trigger event:" + message.getData());
        try {
            String payload = new String(Base64.getDecoder().decode(message.getData().getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8);
            logger.info("Decoded payload:" + payload);
            CreateBackupMessage cbMessage = mapper.readValue(payload, CreateBackupMessage.class);
            logger.info("CreateBackup message:" + cbMessage.toString());
            logger.info("Submitting the create backup request");
            // Create an admin client
            BigtableTableAdminSettings adminSettings = BigtableTableAdminSettings.newBuilder().setProjectId(cbMessage.getProjectId()).setInstanceId(cbMessage.getInstanceId()).build();
            try (BigtableTableAdminClient adminClient = BigtableTableAdminClient.create(adminSettings)) {
                CreateBackupRequest request = CreateBackupRequest.of(cbMessage.getClusterId(), buildBackupId(cbMessage.getTableId())).setSourceTableId(cbMessage.getTableId()).setExpireTime(buildExpireTime(cbMessage.getExpireHours()));
                Backup backupDetails = adminClient.createBackup(request);
                logger.info("Submitted backup request :" + backupDetails.getId() + ": that will expire at:" + backupDetails.getExpireTime());
            } catch (IOException e) {
                logger.log(Level.SEVERE, "Caught Exception creating backup:" + e.toString(), e);
            }
        } catch (Exception e) {
            logger.log(Level.SEVERE, "Caught Exception running the create backup function:" + e.toString(), e);
        }
        return;
    }
}
Also used : CreateBackupRequest(com.google.cloud.bigtable.admin.v2.models.CreateBackupRequest) CreateBackupMessage(com.example.cloud.bigtable.scheduledbackups.resource.CreateBackupMessage) Backup(com.google.cloud.bigtable.admin.v2.models.Backup) BigtableTableAdminSettings(com.google.cloud.bigtable.admin.v2.BigtableTableAdminSettings) BigtableTableAdminClient(com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient) IOException(java.io.IOException) IOException(java.io.IOException)

Aggregations

BigtableTableAdminSettings (com.google.cloud.bigtable.admin.v2.BigtableTableAdminSettings)12 Test (org.junit.Test)6 BigtableTableAdminClient (com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient)4 BigtableDataSettings (com.google.cloud.bigtable.data.v2.BigtableDataSettings)4 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 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 BigtableTableAdminStubSettings (com.google.cloud.bigtable.admin.v2.stub.BigtableTableAdminStubSettings)1 BigtableDataClient (com.google.cloud.bigtable.data.v2.BigtableDataClient)1