Skip to content

Commit 3221bae

Browse files
ContainerAnalysis: Update topic id (GoogleCloudPlatform#1505)
updated container analysis topic id
1 parent 5336724 commit 3221bae

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

container-registry/container-analysis/src/main/java/com/example/containeranalysis/Subscriptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public synchronized void receiveMessage(PubsubMessage message, AckReplyConsumer
7878
public static Subscription createOccurrenceSubscription(String subId, String projectId)
7979
throws IOException, StatusRuntimeException, InterruptedException {
8080
// This topic id will automatically receive messages when Occurrences are added or modified
81-
String topicId = "container-analysis-occurrences-v1beta1";
81+
String topicId = "container-analysis-occurrences-v1";
8282
ProjectTopicName topicName = ProjectTopicName.of(projectId, topicId);
8383
ProjectSubscriptionName subName = ProjectSubscriptionName.of(projectId, subId);
8484

container-registry/container-analysis/src/test/java/com/example/containeranalysis/SamplesTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
import com.google.cloud.devtools.containeranalysis.v1.ContainerAnalysisClient;
2424
import com.google.cloud.pubsub.v1.Subscriber;
2525
import com.google.cloud.pubsub.v1.SubscriptionAdminClient;
26+
import com.google.cloud.pubsub.v1.TopicAdminClient;
2627
import com.google.pubsub.v1.ProjectSubscriptionName;
28+
import com.google.pubsub.v1.ProjectTopicName;
2729
import io.grafeas.v1.DiscoveryNote;
2830
import io.grafeas.v1.DiscoveryOccurrence;
2931
import io.grafeas.v1.DiscoveryOccurrence.AnalysisStatus;
@@ -202,6 +204,14 @@ public void testOccurrencesForNote() throws Exception {
202204
public void testPubSub() throws Exception {
203205
int newCount;
204206
int tries;
207+
// create new topic and subscription if needed
208+
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
209+
String topicId = "container-analysis-occurrences-v1";
210+
ProjectTopicName topicName = ProjectTopicName.of(PROJECT_ID, topicId);
211+
topicAdminClient.createTopic(topicName);
212+
} catch (StatusRuntimeException e) {
213+
System.out.println("Topic already exists");
214+
}
205215
ProjectSubscriptionName subName = ProjectSubscriptionName.of(PROJECT_ID, subId);
206216
try {
207217
Subscriptions.createOccurrenceSubscription(subId, PROJECT_ID);

0 commit comments

Comments
 (0)