public static String formatAppProfileName( String projectId, String instanceId, String appProfileId) { return formatInstanceName(projectId, instanceId) + "/appProfiles/" + appProfileId; } }
/** * Creates the request protobuf. This method is considered an internal implementation detail and * not meant to be used by applications. */ @InternalApi public com.google.bigtable.admin.v2.CreateClusterRequest toProto(String projectId) { proto.setParent(NameUtil.formatInstanceName(projectId, instanceId)); proto.getClusterBuilder().setLocation(NameUtil.formatLocationName(projectId, zone)); return proto.build(); }
public static String formatInstanceName(String projectId, String instanceId) { return formatProjectName(projectId) + "/instances/" + instanceId; }
/** * Helper method to construct the table name in format: * projects/{project}/instances/{instance}/tables/{tableId} */ private String getTableName(String tableId) { return NameUtil.formatTableName(projectId, instanceId, tableId); }
/** * Creates the request protobuf to be used in {@link CreateInstanceRequest}. This method is * considered an internal implementation detail and not meant to be used by applications. * * <p>This method is considered an internal implementation detail and not meant to be used by * applications. */ @InternalApi com.google.bigtable.admin.v2.Cluster toEmbeddedProto(String projectId) { proto.getClusterBuilder().setLocation(NameUtil.formatLocationName(projectId, zone)); return proto.getClusterBuilder().build(); } }
/** * Creates the request protobuf. This method is considered an internal implementation detail and * not meant to be used by applications. */ @InternalApi public com.google.bigtable.admin.v2.UpdateAppProfileRequest toProto(String projectId) { String name = NameUtil.formatAppProfileName(projectId, instanceId, appProfileId); proto.getAppProfileBuilder().setName(name); return proto.build(); }
/** * Asynchronously deletes the specified cluster. Please note that an instance must have at least 1 * cluster. To remove the last cluster, please use {@link * BigtableInstanceAdminClient#deleteInstanceAsync(String)}. * * <p>Sample code: * * <pre>{@code * ApiFuture<Void> future = client.deleteClusterAsync("my-instance", "my-cluster"); * future.get(); * }</pre> */ @SuppressWarnings("WeakerAccess") public ApiFuture<Void> deleteClusterAsync(String instanceId, String clusterId) { String name = NameUtil.formatClusterName(projectId, instanceId, clusterId); com.google.bigtable.admin.v2.DeleteClusterRequest request = com.google.bigtable.admin.v2.DeleteClusterRequest.newBuilder() .setName(name.toString()) .build(); return ApiFutures.transform( stub.deleteClusterCallable().futureCall(request), new ApiFunction<Empty, Void>() { @Override public Void apply(Empty input) { return null; } }, MoreExecutors.directExecutor()); }
@Override public List<Instance> apply(com.google.bigtable.admin.v2.ListInstancesResponse proto) { // NOTE: pagination is intentionally ignored. The server does not implement it and never // will. Verify.verify( proto.getNextPageToken().isEmpty(), "Server returned an unexpected paginated response"); ImmutableList.Builder<Instance> instances = ImmutableList.builder(); for (com.google.bigtable.admin.v2.Instance protoInstance : proto.getInstancesList()) { instances.add(Instance.fromProto(protoInstance)); } ImmutableList.Builder<String> failedZones = ImmutableList.builder(); for (String locationStr : proto.getFailedLocationsList()) { failedZones.add(NameUtil.extractZoneIdFromLocationName(locationStr)); } if (!failedZones.build().isEmpty()) { throw new PartialListInstancesException(failedZones.build(), instances.build()); } return instances.build(); } },
@Override public List<String> apply(List<com.google.bigtable.admin.v2.Table> protos) { List<String> results = Lists.newArrayListWithCapacity(protos.size()); for (com.google.bigtable.admin.v2.Table proto : protos) { results.add(NameUtil.extractTableIdFromTableName(proto.getName())); } return results; } },
@InternalApi public com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest toProto( @Nonnull String projectId, @Nonnull String instanceId) { Preconditions.checkNotNull(projectId, "Project id can't be null"); Preconditions.checkNotNull(instanceId, "Instance id can't be null"); String tableName = NameUtil.formatTableName(projectId, instanceId, tableId); return modFamilyRequest.setName(tableName).build(); } }
@Test public void testListClustersFailedZone() { // Setup com.google.bigtable.admin.v2.ListClustersRequest expectedRequest = com.google.bigtable.admin.v2.ListClustersRequest.newBuilder() .setParent(INSTANCE_NAME) .build(); com.google.bigtable.admin.v2.ListClustersResponse expectedResponse = com.google.bigtable.admin.v2.ListClustersResponse.newBuilder() .addClusters(com.google.bigtable.admin.v2.Cluster.newBuilder().setName(CLUSTER_NAME)) .addFailedLocations(NameUtil.formatLocationName(PROJECT_ID, "us-east1-c")) .build(); Mockito.when(mockListClustersCallable.futureCall(expectedRequest)) .thenReturn(ApiFutures.immediateFuture(expectedResponse)); // Execute Exception actualError = null; try { adminClient.listClusters(INSTANCE_ID); } catch (Exception e) { actualError = e; } // Verify assertThat(actualError).isInstanceOf(PartialListClustersException.class); assert actualError != null; PartialListClustersException partialListError = (PartialListClustersException) actualError; assertThat(partialListError.getClusters()) .containsExactly(Cluster.fromProto(expectedResponse.getClusters(0))); assertThat(partialListError.getUnavailableZones()).containsExactly("us-east1-c"); }
/** * Asynchronously get the app profile by id. * * <p>Sample code: * * <pre>{@code * ApiFuture<AppProfile> appProfileFuture = client.getAppProfileAsync("my-instance", "my-app-profile"); * * AppProfile appProfile = appProfileFuture.get(); * }</pre> * * @see AppProfile */ @SuppressWarnings("WeakerAccess") public ApiFuture<AppProfile> getAppProfileAsync(String instanceId, String appProfileId) { String name = NameUtil.formatAppProfileName(projectId, instanceId, appProfileId); GetAppProfileRequest request = GetAppProfileRequest.newBuilder().setName(name.toString()).build(); return ApiFutures.transform( stub.getAppProfileCallable().futureCall(request), new ApiFunction<com.google.bigtable.admin.v2.AppProfile, AppProfile>() { @Override public AppProfile apply(com.google.bigtable.admin.v2.AppProfile proto) { return AppProfile.fromProto(proto); } }, MoreExecutors.directExecutor()); }
/** * Asynchronously gets the cluster representation by ID. * * <p>Sample code: * * <pre>{@code * ApiFuture<Cluster> clusterFuture = client.getClusterAsync("my-instance", "my-cluster"); * Cluster cluster = clusterFuture.get(); * }</pre> */ @SuppressWarnings("WeakerAccess") public ApiFuture<Cluster> getClusterAsync(String instanceId, String clusterId) { String name = NameUtil.formatClusterName(projectId, instanceId, clusterId); com.google.bigtable.admin.v2.GetClusterRequest request = com.google.bigtable.admin.v2.GetClusterRequest.newBuilder().setName(name).build(); return ApiFutures.transform( stub.getClusterCallable().futureCall(request), new ApiFunction<com.google.bigtable.admin.v2.Cluster, Cluster>() { @Override public Cluster apply(com.google.bigtable.admin.v2.Cluster proto) { return Cluster.fromProto(proto); } }, MoreExecutors.directExecutor()); }
@Override public List<Cluster> apply(com.google.bigtable.admin.v2.ListClustersResponse proto) { // NOTE: serverside pagination is not and will not be implemented, so remaining pages // are not fetched. However, if that assumption turns out to be wrong, fail fast to // avoid returning partial data. Verify.verify( proto.getNextPageToken().isEmpty(), "Server returned an unexpected paginated response"); ImmutableList.Builder<Cluster> clusters = ImmutableList.builder(); for (com.google.bigtable.admin.v2.Cluster cluster : proto.getClustersList()) { clusters.add(Cluster.fromProto(cluster)); } ImmutableList.Builder<String> failedZones = ImmutableList.builder(); for (String locationStr : proto.getFailedLocationsList()) { failedZones.add(NameUtil.extractZoneIdFromLocationName(locationStr)); } if (!failedZones.build().isEmpty()) { throw new PartialListClustersException(failedZones.build(), clusters.build()); } return clusters.build(); } },
@Override public List<String> apply(List<com.google.bigtable.admin.v2.Table> protos) { List<String> results = Lists.newArrayListWithCapacity(protos.size()); for (com.google.bigtable.admin.v2.Table proto : protos) { results.add(NameUtil.extractTableIdFromTableName(proto.getName())); } return results; } },
public static String formatTableName(String projectId, String instanceId, String tableId) { return formatInstanceName(projectId, instanceId) + "/tables/" + tableId; }
public static String formatLocationName(String projectId, String zone) { return formatProjectName(projectId) + "/locations/" + zone; }
/** * Creates the request protobuf. This method is considered an internal implementation detail and * not meant to be used by applications. */ @InternalApi public com.google.bigtable.admin.v2.CreateClusterRequest toProto(String projectId) { proto.setParent(NameUtil.formatInstanceName(projectId, instanceId)); proto.getClusterBuilder().setLocation(NameUtil.formatLocationName(projectId, zone)); return proto.build(); }
.setName(NameUtil.formatTableName(PROJECT_ID, INSTANCE_ID, "tableId")) .addModifications( com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest.Modification.newBuilder()
.setName(INSTANCE_NAME + "1") .build()) .addFailedLocations(NameUtil.formatLocationName(PROJECT_ID, "us-east1-d")) .build();