Search in sources :

Example 21 with Instance

use of com.google.cloud.bigtable.admin.v2.models.Instance 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 22 with Instance

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

the class InstanceAdminExample method getInstance.

/**
 * Demonstrates how to get an instance.
 */
public Instance getInstance() {
    System.out.println("\nGet Instance");
    // [START bigtable_get_instance]
    Instance instance = null;
    try {
        instance = adminClient.getInstance(instanceId);
        System.out.println("Instance ID: " + instance.getId());
        System.out.println("Display Name: " + instance.getDisplayName());
        System.out.print("Labels: ");
        Map<String, String> labels = instance.getLabels();
        for (String key : labels.keySet()) {
            System.out.printf("%s - %s", key, labels.get(key));
        }
        System.out.println("\nState: " + instance.getState());
        System.out.println("Type: " + instance.getType());
    } catch (NotFoundException e) {
        System.err.println("Failed to get non-existent instance: " + e.getMessage());
    }
    // [END bigtable_get_instance]
    return instance;
}
Also used : Instance(com.google.cloud.bigtable.admin.v2.models.Instance) NotFoundException(com.google.api.gax.rpc.NotFoundException)

Example 23 with Instance

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

the class BaseBigtableInstanceAdminClientTest method listAppProfilesTest.

@Test
public void listAppProfilesTest() throws Exception {
    AppProfile responsesElement = AppProfile.newBuilder().build();
    ListAppProfilesResponse expectedResponse = ListAppProfilesResponse.newBuilder().setNextPageToken("").addAllAppProfiles(Arrays.asList(responsesElement)).build();
    mockBigtableInstanceAdmin.addResponse(expectedResponse);
    InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
    ListAppProfilesPagedResponse pagedListResponse = client.listAppProfiles(parent);
    List<AppProfile> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getAppProfilesList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockBigtableInstanceAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListAppProfilesRequest actualRequest = ((ListAppProfilesRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : InstanceName(com.google.bigtable.admin.v2.InstanceName) AbstractMessage(com.google.protobuf.AbstractMessage) ListAppProfilesPagedResponse(com.google.cloud.bigtable.admin.v2.BaseBigtableInstanceAdminClient.ListAppProfilesPagedResponse) AppProfile(com.google.bigtable.admin.v2.AppProfile) ListAppProfilesRequest(com.google.bigtable.admin.v2.ListAppProfilesRequest) ListAppProfilesResponse(com.google.bigtable.admin.v2.ListAppProfilesResponse) Test(org.junit.Test)

Example 24 with Instance

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

the class BaseBigtableTableAdminClientTest method listTablesTest.

@Test
public void listTablesTest() throws Exception {
    Table responsesElement = Table.newBuilder().build();
    ListTablesResponse expectedResponse = ListTablesResponse.newBuilder().setNextPageToken("").addAllTables(Arrays.asList(responsesElement)).build();
    mockBigtableTableAdmin.addResponse(expectedResponse);
    InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
    ListTablesPagedResponse pagedListResponse = client.listTables(parent);
    List<Table> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getTablesList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockBigtableTableAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListTablesRequest actualRequest = ((ListTablesRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : InstanceName(com.google.bigtable.admin.v2.InstanceName) Table(com.google.bigtable.admin.v2.Table) AbstractMessage(com.google.protobuf.AbstractMessage) ListTablesRequest(com.google.bigtable.admin.v2.ListTablesRequest) ListTablesResponse(com.google.bigtable.admin.v2.ListTablesResponse) ListTablesPagedResponse(com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListTablesPagedResponse) Test(org.junit.Test)

Example 25 with Instance

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

the class BigtableInstanceAdminClientTest method testUpdateInstance.

@Test
public void testUpdateInstance() {
    // Setup
    Mockito.when(mockStub.partialUpdateInstanceOperationCallable()).thenReturn(mockUpdateInstanceCallable);
    com.google.bigtable.admin.v2.PartialUpdateInstanceRequest expectedRequest = com.google.bigtable.admin.v2.PartialUpdateInstanceRequest.newBuilder().setUpdateMask(FieldMask.newBuilder().addPaths("display_name")).setInstance(com.google.bigtable.admin.v2.Instance.newBuilder().setName(INSTANCE_NAME).setDisplayName("new display name")).build();
    com.google.bigtable.admin.v2.Instance expectedResponse = com.google.bigtable.admin.v2.Instance.newBuilder().setName(INSTANCE_NAME).build();
    mockOperationResult(mockUpdateInstanceCallable, expectedRequest, expectedResponse);
    // Execute
    Instance actualResult = adminClient.updateInstance(UpdateInstanceRequest.of(INSTANCE_ID).setDisplayName("new display name"));
    // Verify
    assertThat(actualResult).isEqualTo(Instance.fromProto(expectedResponse));
}
Also used : Instance(com.google.cloud.bigtable.admin.v2.models.Instance) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)18 Instance (com.google.cloud.bigtable.admin.v2.models.Instance)14 Cluster (com.google.cloud.bigtable.admin.v2.models.Cluster)9 AlreadyExistsException (com.google.api.gax.rpc.AlreadyExistsException)5 ModifyColumnFamiliesRequest (com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest)4 ImmutableList (com.google.common.collect.ImmutableList)4 AbstractMessage (com.google.protobuf.AbstractMessage)4 List (java.util.List)4 NotFoundException (com.google.api.gax.rpc.NotFoundException)3 BigtableInstanceAdminClient (com.google.cloud.bigtable.admin.v2.BigtableInstanceAdminClient)3 BigtableTableAdminClient (com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient)3 AppProfile (com.google.cloud.bigtable.admin.v2.models.AppProfile)3 CreateClusterRequest (com.google.cloud.bigtable.admin.v2.models.CreateClusterRequest)3 CreateInstanceRequest (com.google.cloud.bigtable.admin.v2.models.CreateInstanceRequest)3 ApiFuture (com.google.api.core.ApiFuture)2 ClusterName (com.google.bigtable.admin.v2.ClusterName)2 InstanceName (com.google.bigtable.admin.v2.InstanceName)2 ListAppProfilesRequest (com.google.bigtable.admin.v2.ListAppProfilesRequest)2 ListTablesRequest (com.google.bigtable.admin.v2.ListTablesRequest)2 ListAppProfilesPagedResponse (com.google.cloud.bigtable.admin.v2.BaseBigtableInstanceAdminClient.ListAppProfilesPagedResponse)2