Skip to content

Commit

Permalink
Moving off some deprecated stuff (googleapis#2640)
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettjonesgoogle committed Nov 21, 2017
1 parent ae1b0e7 commit ab10263
Show file tree
Hide file tree
Showing 24 changed files with 72 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ public Page<T> getNextPage() {
return asyncPageFetcher != null
? Uninterruptibles.getUninterruptibly(asyncPageFetcher.getNextPage()) : null;
} catch (ExecutionException ex) {
throw Throwables.propagate(ex.getCause());
Throwables.throwIfUnchecked(ex.getCause());
throw new RuntimeException(ex);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
public class CreateSubscriptionAndConsumeMessages {

public static void main(String... args) throws Exception {
TopicName topic = TopicName.create("my-project-id", "my-topic-id");
SubscriptionName subscription = SubscriptionName.create("my-project-id", "my-topic-id");
TopicName topic = TopicName.of("my-project-id", "my-topic-id");
SubscriptionName subscription = SubscriptionName.of("my-project-id", "my-topic-id");

try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
subscriptionAdminClient.createSubscription(subscription, topic, PushConfig.getDefaultInstance(), 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@
public class CreateTopicAndPublishMessages {

public static void createTopic() throws Exception {
TopicName topic = TopicName.create("my-project-id", "my-topic-id");
TopicName topic = TopicName.of("my-project-id", "my-topic-id");
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
topicAdminClient.createTopic(topic);
}
}

public static void publishMessages() throws Exception {
// [START pubsub_publish]
TopicName topicName = TopicName.create("my-project-id", "my-topic-id");
TopicName topicName = TopicName.of("my-project-id", "my-topic-id");
Publisher publisher = null;
List<ApiFuture<String>> messageIdFutures = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void onFailure(Throwable t) {
// [VARIABLE "my_project"]
// [VARIABLE "my_topic"]
public static void newBuilder(String projectId, String topicId) throws Exception {
TopicName topic = TopicName.create(projectId, topicId);
TopicName topic = TopicName.of(projectId, topicId);
Publisher publisher = Publisher.newBuilder(topic).build();
try {
// ...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private void createSubscriber() throws Exception {
String projectId = "my-project-id";
String subscriptionId = "my-subscription-id";

SubscriptionName subscriptionName = SubscriptionName.create(projectId, subscriptionId);
SubscriptionName subscriptionName = SubscriptionName.of(projectId, subscriptionId);
// Instantiate an asynchronous message receiver
MessageReceiver receiver =
new MessageReceiver() {
Expand Down Expand Up @@ -186,7 +186,7 @@ static List<ReceivedMessage> createSubscriberWithSyncPull(
// String projectId = "my-project-id";
// String subscriptionId = "my-subscription-id";
// int numOfMessages = 10; // max number of messages to be pulled
String subscriptionName = SubscriptionName.create(projectId, subscriptionId).toString();
String subscriptionName = SubscriptionName.of(projectId, subscriptionId).toString();
PullRequest pullRequest =
PullRequest.newBuilder()
.setMaxMessages(numOfMessages)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ public Subscription createSubscription(String topicId, String subscriptionId) th
// [START pubsub_create_pull_subscription]
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
// eg. projectId = "my-test-project", topicId = "my-test-topic"
TopicName topicName = TopicName.create(projectId, topicId);
TopicName topicName = TopicName.of(projectId, topicId);
// eg. subscriptionId = "my-test-subscription"
SubscriptionName subscriptionName =
SubscriptionName.create(projectId, subscriptionId);
SubscriptionName.of(projectId, subscriptionId);
// create a pull subscription with default acknowledgement deadline
Subscription subscription =
subscriptionAdminClient.createSubscription(
Expand All @@ -73,9 +73,9 @@ public Subscription createSubscriptionWithPushEndpoint(String topicId, String su
throws Exception {
// [START pubsub_create_push_subscription]
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
TopicName topicName = TopicName.create(projectId, topicId);
TopicName topicName = TopicName.of(projectId, topicId);
SubscriptionName subscriptionName =
SubscriptionName.create(projectId, subscriptionId);
SubscriptionName.of(projectId, subscriptionId);

// eg. endpoint = "https://my-test-project.appspot.com/push"
PushConfig pushConfig = PushConfig.newBuilder().setPushEndpoint(endpoint).build();
Expand All @@ -95,7 +95,7 @@ public Subscription createSubscriptionWithPushEndpoint(String topicId, String su
public void replacePushConfig(String subscriptionId, String endpoint) throws Exception {
// [START pubsub_update_push_configuration]
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
SubscriptionName subscriptionName = SubscriptionName.create(projectId, subscriptionId);
SubscriptionName subscriptionName = SubscriptionName.of(projectId, subscriptionId);
PushConfig pushConfig = PushConfig.newBuilder().setPushEndpoint(endpoint).build();
subscriptionAdminClient.modifyPushConfig(subscriptionName, pushConfig);
}
Expand All @@ -108,7 +108,7 @@ public ListSubscriptionsPagedResponse listSubscriptions() throws Exception {
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
ListSubscriptionsRequest listSubscriptionsRequest =
ListSubscriptionsRequest.newBuilder()
.setProjectWithProjectName(ProjectName.create(projectId))
.setProjectWithProjectName(ProjectName.of(projectId))
.build();
ListSubscriptionsPagedResponse response =
subscriptionAdminClient.listSubscriptions(listSubscriptionsRequest);
Expand All @@ -125,7 +125,7 @@ public ListSubscriptionsPagedResponse listSubscriptions() throws Exception {
public SubscriptionName deleteSubscription(String subscriptionId) throws Exception {
// [START pubsub_delete_subscription]
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
SubscriptionName subscriptionName = SubscriptionName.create(projectId, subscriptionId);
SubscriptionName subscriptionName = SubscriptionName.of(projectId, subscriptionId);
subscriptionAdminClient.deleteSubscription(subscriptionName);
return subscriptionName;
}
Expand All @@ -136,7 +136,7 @@ public SubscriptionName deleteSubscription(String subscriptionId) throws Excepti
public Policy getSubscriptionPolicy(String subscriptionId) throws Exception {
// [START pubsub_get_subscription_policy]
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
SubscriptionName subscriptionName = SubscriptionName.create(projectId, subscriptionId);
SubscriptionName subscriptionName = SubscriptionName.of(projectId, subscriptionId);
Policy policy = subscriptionAdminClient.getIamPolicy(subscriptionName.toString());
if (policy == null) {
// subscription was not found
Expand All @@ -150,7 +150,7 @@ public Policy getSubscriptionPolicy(String subscriptionId) throws Exception {
public Policy replaceSubscriptionPolicy(String subscriptionId) throws Exception {
// [START pubsub_set_subscription_policy]
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
SubscriptionName subscriptionName = SubscriptionName.create(projectId, subscriptionId);
SubscriptionName subscriptionName = SubscriptionName.of(projectId, subscriptionId);
Policy policy = subscriptionAdminClient.getIamPolicy(subscriptionName.toString());
// Create a role => members binding
Binding binding =
Expand All @@ -174,7 +174,7 @@ public TestIamPermissionsResponse testSubscriptionPermissions(String subscriptio
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
List<String> permissions = new LinkedList<>();
permissions.add("pubsub.subscriptions.get");
SubscriptionName subscriptionName = SubscriptionName.create(projectId, subscriptionId);
SubscriptionName subscriptionName = SubscriptionName.of(projectId, subscriptionId);
TestIamPermissionsResponse testedPermissions =
topicAdminClient.testIamPermissions(subscriptionName.toString(), permissions);
return testedPermissions;
Expand All @@ -186,7 +186,7 @@ public TestIamPermissionsResponse testSubscriptionPermissions(String subscriptio
public Subscription getSubscription(String subscriptionId) throws Exception {
// [START pubsub_get_subscription]
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
SubscriptionName subscriptionName = SubscriptionName.create(projectId, subscriptionId);
SubscriptionName subscriptionName = SubscriptionName.of(projectId, subscriptionId);
Subscription subscription = subscriptionAdminClient.getSubscription(subscriptionName);
return subscription;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public Topic createTopic(String topicId) throws Exception {
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
// projectId <= unique project identifier, eg. "my-project-id"
// topicId <= "my-topic-id"
TopicName topicName = TopicName.create(projectId, topicId);
TopicName topicName = TopicName.of(projectId, topicId);
Topic topic = topicAdminClient.createTopic(topicName);
return topic;
}
Expand All @@ -65,7 +65,7 @@ public ListTopicsPagedResponse listTopics() throws Exception {
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ListTopicsRequest listTopicsRequest =
ListTopicsRequest.newBuilder()
.setProjectWithProjectName(ProjectName.create(projectId))
.setProjectWithProjectName(ProjectName.of(projectId))
.build();
ListTopicsPagedResponse response = topicAdminClient.listTopics(listTopicsRequest);
Iterable<Topic> topics = response.iterateAll();
Expand All @@ -82,7 +82,7 @@ public ListTopicSubscriptionsPagedResponse listTopicSubscriptions(String topicId
throws Exception {
// [START pubsub_list_topic_subscriptions]
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
TopicName topicName = TopicName.create(projectId, topicId);
TopicName topicName = TopicName.of(projectId, topicId);
ListTopicSubscriptionsRequest request =
ListTopicSubscriptionsRequest.newBuilder()
.setTopicWithTopicName(topicName)
Expand All @@ -102,7 +102,7 @@ public ListTopicSubscriptionsPagedResponse listTopicSubscriptions(String topicId
public TopicName deleteTopic(String topicId) throws Exception {
// [START pubsub_delete_topic]
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
TopicName topicName = TopicName.create(projectId, topicId);
TopicName topicName = TopicName.of(projectId, topicId);
topicAdminClient.deleteTopic(topicName);
return topicName;
}
Expand All @@ -113,7 +113,7 @@ public TopicName deleteTopic(String topicId) throws Exception {
public Policy getTopicPolicy(String topicId) throws Exception {
// [START pubsub_get_topic_policy]
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
TopicName topicName = TopicName.create(projectId, topicId);
TopicName topicName = TopicName.of(projectId, topicId);
Policy policy = topicAdminClient.getIamPolicy(topicName.toString());
if (policy == null) {
// topic iam policy was not found
Expand All @@ -127,7 +127,7 @@ public Policy getTopicPolicy(String topicId) throws Exception {
public Policy replaceTopicPolicy(String topicId) throws Exception {
// [START pubsub_set_topic_policy]
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
String topicName = TopicName.create(projectId, topicId).toString();
String topicName = TopicName.of(projectId, topicId).toString();
Policy policy = topicAdminClient.getIamPolicy(topicName);
// add role -> members binding
Binding binding =
Expand All @@ -150,7 +150,7 @@ public TestIamPermissionsResponse testTopicPermissions(String topicId) throws Ex
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
List<String> permissions = new LinkedList<>();
permissions.add("pubsub.topics.get");
TopicName topicName = TopicName.create(projectId, topicId);
TopicName topicName = TopicName.of(projectId, topicId);
TestIamPermissionsResponse testedPermissions =
topicAdminClient.testIamPermissions(topicName.toString(), permissions);
return testedPermissions;
Expand All @@ -162,7 +162,7 @@ public TestIamPermissionsResponse testTopicPermissions(String topicId) throws Ex
public Topic getTopic(String topicId) throws Exception {
// [START pubsub_get_topic]
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
TopicName topicName = TopicName.create(projectId, topicId);
TopicName topicName = TopicName.of(projectId, topicId);
Topic topic = topicAdminClient.getTopic(topicName);
return topic;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static void main(String... args) throws IOException {
.setCredentialsProvider(credentialsProvider)
.build());

TopicName topicName = TopicName.create("my-project-id", "my-topic-id");
TopicName topicName = TopicName.of("my-project-id", "my-topic-id");
// Set the channel and credentials provider when creating a `Publisher`.
// Similarly for Subscriber
Publisher publisher =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -551,8 +551,10 @@ Tuple<ServiceAccountCredentials, BlobInfo> parse(String... args) throws IOExcept
KeyStore keystore = KeyStore.getInstance("PKCS12");
keystore.load(Files.newInputStream(Paths.get(args[0])), PASSWORD);
PrivateKey privateKey = (PrivateKey) keystore.getKey("privatekey", PASSWORD);
ServiceAccountCredentials credentials =
new ServiceAccountCredentials(null, args[1], privateKey, null, null);
ServiceAccountCredentials credentials = ServiceAccountCredentials.newBuilder()
.setClientEmail(args[1])
.setPrivateKey(privateKey)
.build();
return Tuple.of(credentials, BlobInfo.newBuilder(BlobId.of(args[2], args[3])).build());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private static void deleteTestTopics(String projectId, String[] testTopics) thro
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
for (String topicId : testTopics) {
try {
topicAdminClient.deleteTopic(TopicName.create(projectId, topicId));
topicAdminClient.deleteTopic(TopicName.of(projectId, topicId));
System.out.println("Topic deleted : " + topicId);
} catch (Exception e) {
//do nothing catch clause
Expand All @@ -48,7 +48,7 @@ private static void deleteTestSubscriptions(String projectId, String[] subscript
for (String subscriptionId : subscriptions) {
try {
subscriptionAdminClient.deleteSubscription(
SubscriptionName.create(projectId, subscriptionId));
SubscriptionName.of(projectId, subscriptionId));
System.out.println("Subscription deleted : " + subscriptionId);
} catch (Exception e) {
//do nothing catch clause
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ private static String formatForTest(String resourceName) {

@Before
public void setUp() throws Exception {
topicName = TopicName.create(ServiceOptions.getDefaultProjectId(), formatForTest("test-topic"));
topicName = TopicName.of(ServiceOptions.getDefaultProjectId(), formatForTest("test-topic"));
subscriptionName =
SubscriptionName.create(
SubscriptionName.of(
ServiceOptions.getDefaultProjectId(), formatForTest("test-subscription"));

try (TopicAdminClient publisherClient = TopicAdminClient.create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public void replaceSubscriptionPolicyAndTestPermissionsIsSuccessful() throws Exc

private void createTopic(String name) throws Exception {
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
topicAdminClient.createTopic(TopicName.create(projectId, name));
topicAdminClient.createTopic(TopicName.of(projectId, name));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ public void replaceTopicPolicyAndTestPermissionsIsSuccessful() throws Exception
private String createSubscription(String topic, String subscriptionName) throws Exception {
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
Subscription subscription = subscriptionAdminClient.createSubscription(
SubscriptionName.create(projectId, subscriptionName),
TopicName.create(projectId, topic), PushConfig.getDefaultInstance(), 0);
SubscriptionName.of(projectId, subscriptionName),
TopicName.of(projectId, topic), PushConfig.getDefaultInstance(), 0);
return subscription.getName();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ static Value encodeValue(@Nullable Object sanitizedObject) {
+ "Please explicitly set your Project ID in FirestoreOptions.");
this.databasePath =
ResourcePath.create(
DatabaseRootName.create(options.getProjectId(), options.getDatabaseId()));
DatabaseRootName.of(options.getProjectId(), options.getDatabaseId()));
}

@Nonnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static ResourcePath create(String resourceName) {
if (parts.length >= 6 && parts[0].equals("projects") && parts[2].equals("databases")) {
String[] path = Arrays.copyOfRange(parts, 5, parts.length);
return create(
DatabaseRootName.create(parts[1], parts[3]),
DatabaseRootName.of(parts[1], parts[3]),
ImmutableList.<String>builder().add(path).build());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public GrpcFirestoreRpc(final FirestoreOptions options) throws IOException {
FirestoreSettings.Builder settingsBuilder = FirestoreSettings.newBuilder();

DatabaseRootName databaseName = DatabaseRootName
.create(options.getProjectId(), options.getDatabaseId());
.of(options.getProjectId(), options.getDatabaseId());

settingsBuilder.setCredentialsProvider(GrpcTransportOptions.setUpCredentialsProvider(options));
settingsBuilder.setTransportChannelProvider(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ public boolean equals(Object o) {
new DocumentReference(
null,
ResourcePath.create(
DatabaseRootName.create("", ""), ImmutableList.of("coll", "doc"))),
DatabaseRootName.of("", ""), ImmutableList.of("coll", "doc"))),
SINGLE_FIELD_PROTO,
Instant.ofEpochSecond(5, 6),
Instant.ofEpochSecond(3, 4),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ com.google.logging.v2.LogEntry toPb(String projectId) {
com.google.logging.v2.LogEntry.Builder builder = payload.toPb();
builder.putAllLabels(labels);
if (logName != null) {
builder.setLogName(LogName.create(projectId, logName).toString());
builder.setLogName(LogName.of(projectId, logName).toString());
}
if (resource != null) {
builder.setResource(resource.toPb());
Expand Down
Loading

0 comments on commit ab10263

Please sign in to comment.