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());
}
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);
}
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);
}
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);
}
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;
}
}
Aggregations