use of com.google.cloud.bigtable.admin.v2.BigtableInstanceAdminClient in project java-docs-samples by GoogleCloudPlatform.
the class CreateBackupTestIT method setUp.
@BeforeClass
public static void setUp() throws IOException {
projectId = requireEnv(PROJECT_ENV);
try (BigtableInstanceAdminClient instanceAdmin = BigtableInstanceAdminClient.create(projectId)) {
CreateInstanceRequest request = CreateInstanceRequest.of(INSTANCE_ID).addCluster(CLUSTER_ID, ZONE_ID, 1, StorageType.SSD);
Instance instance = instanceAdmin.createInstance(request);
} catch (IOException e) {
System.out.println("Error during BeforeClass while creating instance: \n" + e.toString());
throw (e);
}
try (BigtableTableAdminClient tableAdmin = BigtableTableAdminClient.create(projectId, INSTANCE_ID)) {
// Create a table.
tableAdmin.createTable(CreateTableRequest.of(TABLE_ID).addFamily(COLUMN_FAMILY_NAME));
} catch (IOException e) {
System.out.println("Error during BeforeClass while creating table: \n" + e.toString());
throw (e);
}
// Get the sample's base directory (the one containing a pom.xml file)
String baseDir = System.getProperty("basedir");
// Emulate the function locally by running the Functions Framework Maven plugin
emulatorProcess = new ProcessBuilder().command("mvn", "function:run").directory(new File(baseDir)).start();
}
use of com.google.cloud.bigtable.admin.v2.BigtableInstanceAdminClient in project java-docs-samples by GoogleCloudPlatform.
the class BulkWriteTest method beforeClass.
@BeforeClass
public static void beforeClass() {
projectId = requireEnv(PROJECT_ENV);
try (BigtableInstanceAdminClient instanceAdmin = BigtableInstanceAdminClient.create(projectId)) {
CreateInstanceRequest request = CreateInstanceRequest.of(INSTANCE_ID).addCluster(CLUSTER_ID, ZONE_ID, 1, StorageType.SSD);
Instance instance = instanceAdmin.createInstance(request);
} catch (IOException e) {
System.out.println("Error during BeforeClass while creating instance: \n" + e.toString());
Assert.fail();
}
}
use of com.google.cloud.bigtable.admin.v2.BigtableInstanceAdminClient 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));
}
use of com.google.cloud.bigtable.admin.v2.BigtableInstanceAdminClient 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);
}
Aggregations