use of com.google.bigtable.admin.v2.ProjectName in project java-docs-samples by GoogleCloudPlatform.
the class Quickstart method quickstart.
public void quickstart(String projectId, String secretId) throws Exception {
// the "close" method on the client to safely clean up any remaining background resources.
try (SecretManagerServiceClient client = SecretManagerServiceClient.create()) {
// Build the parent name from the project.
ProjectName projectName = ProjectName.of(projectId);
// Create the parent secret.
Secret secret = Secret.newBuilder().setReplication(Replication.newBuilder().setAutomatic(Replication.Automatic.newBuilder().build()).build()).build();
Secret createdSecret = client.createSecret(projectName, secretId, secret);
// Add a secret version.
SecretPayload payload = SecretPayload.newBuilder().setData(ByteString.copyFromUtf8("hello world!")).build();
SecretVersion addedVersion = client.addSecretVersion(createdSecret.getName(), payload);
// Access the secret version.
AccessSecretVersionResponse response = client.accessSecretVersion(addedVersion.getName());
// Print the secret payload.
//
// WARNING: Do not print the secret in a production environment - this
// snippet is showing how to access the secret material.
String data = response.getPayload().getData().toStringUtf8();
System.out.printf("Plaintext: %s\n", data);
}
}
use of com.google.bigtable.admin.v2.ProjectName in project divolte-collector by divolte.
the class GoogleCloudPubSubSinkConfiguration method createTopic.
private static void createTopic(final String hostPort, final TransportChannelProvider channelProvider, final ProjectTopicName topic) {
final TopicAdminClient topicClient;
try {
final TopicAdminSettings topicAdminSettings = TopicAdminSettings.newBuilder().setTransportChannelProvider(channelProvider).setCredentialsProvider(NoCredentialsProvider.create()).build();
topicClient = TopicAdminClient.create(topicAdminSettings);
} catch (final IOException e) {
throw new UncheckedIOException(String.format("Error creating topic %s for pub/sub emulator %s", topic, hostPort), e);
}
final ProjectName project = ProjectName.of(topic.getProject());
if (Streams.stream(topicClient.listTopics(project).iterateAll()).map(Topic::getName).map(ProjectTopicName::parse).noneMatch(topic::equals)) {
logger.info("Initializing Pub/Sub emulator topic: {}", topic);
topicClient.createTopic(topic);
}
}
use of com.google.bigtable.admin.v2.ProjectName in project java-bigtable by googleapis.
the class BaseBigtableInstanceAdminClientTest method listInstancesTest.
@Test
public void listInstancesTest() throws Exception {
ListInstancesResponse expectedResponse = ListInstancesResponse.newBuilder().addAllInstances(new ArrayList<Instance>()).addAllFailedLocations(new ArrayList<String>()).setNextPageToken("nextPageToken-1386094857").build();
mockBigtableInstanceAdmin.addResponse(expectedResponse);
ProjectName parent = ProjectName.of("[PROJECT]");
ListInstancesResponse actualResponse = client.listInstances(parent);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockBigtableInstanceAdmin.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListInstancesRequest actualRequest = ((ListInstancesRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.bigtable.admin.v2.ProjectName in project java-bigtable by googleapis.
the class BaseBigtableInstanceAdminClientTest method createInstanceTest.
@Test
public void createInstanceTest() throws Exception {
Instance expectedResponse = Instance.newBuilder().setName(InstanceName.of("[PROJECT]", "[INSTANCE]").toString()).setDisplayName("displayName1714148973").putAllLabels(new HashMap<String, String>()).setCreateTime(Timestamp.newBuilder().build()).build();
Operation resultOperation = Operation.newBuilder().setName("createInstanceTest").setDone(true).setResponse(Any.pack(expectedResponse)).build();
mockBigtableInstanceAdmin.addResponse(resultOperation);
ProjectName parent = ProjectName.of("[PROJECT]");
String instanceId = "instanceId902024336";
Instance instance = Instance.newBuilder().build();
Map<String, Cluster> clusters = new HashMap<>();
Instance actualResponse = client.createInstanceAsync(parent, instanceId, instance, clusters).get();
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockBigtableInstanceAdmin.getRequests();
Assert.assertEquals(1, actualRequests.size());
CreateInstanceRequest actualRequest = ((CreateInstanceRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertEquals(instanceId, actualRequest.getInstanceId());
Assert.assertEquals(instance, actualRequest.getInstance());
Assert.assertEquals(clusters, actualRequest.getClustersMap());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.bigtable.admin.v2.ProjectName in project java-bigquerydatatransfer by googleapis.
the class CreatePlayTransfer method createPlayTransfer.
public static void createPlayTransfer(String projectId, TransferConfig transferConfig) throws IOException {
try (DataTransferServiceClient client = DataTransferServiceClient.create()) {
ProjectName parent = ProjectName.of(projectId);
CreateTransferConfigRequest request = CreateTransferConfigRequest.newBuilder().setParent(parent.toString()).setTransferConfig(transferConfig).build();
TransferConfig config = client.createTransferConfig(request);
System.out.println("play transfer created successfully :" + config.getName());
} catch (ApiException ex) {
System.out.print("play transfer was not created." + ex.toString());
}
}
Aggregations