1- package io .github .protocol .pulsar ;
1+ package io .github .protocol .pulsar . admin . jdk ;
22
33import com .fasterxml .jackson .core .type .TypeReference ;
44
77import java .util .List ;
88import java .util .Map ;
99
10- public class PersistentTopicsImpl implements Topics {
10+ public abstract class BaseTopicsImpl implements Topics {
1111
1212 protected final InnerHttpClient httpClient ;
1313
14- private static final String BASE_URL_PERSISTENT_DOMAIN = "/admin/v2" + "/persistent" ;
15-
16- public PersistentTopicsImpl (InnerHttpClient httpClient ) {
14+ public BaseTopicsImpl (InnerHttpClient httpClient ) {
1715 this .httpClient = httpClient ;
1816 }
1917
20- public String getDomainBaseUrl () {
21- return "/admin/v2" + "/persistent" ;
22- }
18+ protected abstract String getDomainBaseUrl ();
2319
2420 @ Override
2521 public void createPartitionedTopic (String tenant , String namespace , String encodedTopic , int numPartitions ,
2622 boolean createLocalTopicOnly ) throws PulsarAdminException {
27- String url = String .format ("%s/%s/%s/%s%s" , "/admin/v2" + "/persistent" , tenant , namespace , encodedTopic ,
28- "/partitions" );
23+ String url = String .format ("%s/%s/%s/%s%s" , getDomainBaseUrl (), tenant , namespace , encodedTopic , "/partitions" );
2924 try {
3025 HttpResponse <String > response = httpClient .put (url , numPartitions , "createLocalTopicOnly" ,
3126 String .valueOf (createLocalTopicOnly ));
@@ -42,8 +37,7 @@ public void createPartitionedTopic(String tenant, String namespace, String encod
4237 @ Override
4338 public void deletePartitionedTopic (String tenant , String namespace , String encodedTopic , boolean force ,
4439 boolean authoritative ) throws PulsarAdminException {
45- String url = String .format ("%s/%s/%s/%s%s" , "/admin/v2" + "/persistent" , tenant , namespace , encodedTopic ,
46- "/partitions" );
40+ String url = String .format ("%s/%s/%s/%s%s" , getDomainBaseUrl (), tenant , namespace , encodedTopic , "/partitions" );
4741 try {
4842 HttpResponse <String > response = httpClient .delete (url , "force" , String .valueOf (force ),
4943 "authoritative" , String .valueOf (authoritative ));
@@ -61,8 +55,7 @@ public void deletePartitionedTopic(String tenant, String namespace, String encod
6155 public void updatePartitionedTopic (String tenant , String namespace , String encodedTopic ,
6256 boolean updateLocalTopicOnly , boolean authoritative ,
6357 boolean force , int numPartitions ) throws PulsarAdminException {
64- String url = String .format ("%s/%s/%s/%s%s" , "/admin/v2" + "/persistent" , tenant , namespace , encodedTopic ,
65- "/partitions" );
58+ String url = String .format ("%s/%s/%s/%s%s" , getDomainBaseUrl (), tenant , namespace , encodedTopic , "/partitions" );
6659 try {
6760 HttpResponse <String > response = httpClient .post (url , numPartitions , "updateLocalTopicOnly" ,
6861 String .valueOf (updateLocalTopicOnly ),
@@ -82,8 +75,7 @@ public void updatePartitionedTopic(String tenant, String namespace, String encod
8275 public PartitionedTopicMetadata getPartitionedMetadata (String tenant , String namespace , String encodedTopic ,
8376 boolean checkAllowAutoCreation , boolean authoritative )
8477 throws PulsarAdminException {
85- String url = String .format ("%s/%s/%s/%s%s" , "/admin/v2" + "/persistent" ,
86- tenant , namespace , encodedTopic , "/partitions" );
78+ String url = String .format ("%s/%s/%s/%s%s" , getDomainBaseUrl (), tenant , namespace , encodedTopic , "/partitions" );
8779 try {
8880 HttpResponse <String > response = httpClient .get (url ,
8981 "checkAllowAutoCreation" , String .valueOf (checkAllowAutoCreation ),
@@ -102,7 +94,7 @@ public PartitionedTopicMetadata getPartitionedMetadata(String tenant, String nam
10294 @ Override
10395 public void createNonPartitionedTopic (String tenant , String namespace , String encodedTopic , boolean authoritative ,
10496 Map <String , String > properties ) throws PulsarAdminException {
105- String url = String .format ("%s/%s/%s/%s" , "/admin/v2" + "/persistent" , tenant , namespace , encodedTopic );
97+ String url = String .format ("%s/%s/%s/%s" , getDomainBaseUrl () , tenant , namespace , encodedTopic );
10698 try {
10799 HttpResponse <String > response = httpClient .put (url , properties ,
108100 "authoritative" , String .valueOf (authoritative ));
@@ -119,7 +111,7 @@ public void createNonPartitionedTopic(String tenant, String namespace, String en
119111 @ Override
120112 public void deleteTopic (String tenant , String namespace , String encodedTopic , boolean force , boolean authoritative )
121113 throws PulsarAdminException {
122- String url = String .format ("%s/%s/%s/%s" , "/admin/v2" + "/persistent" , tenant , namespace , encodedTopic );
114+ String url = String .format ("%s/%s/%s/%s" , getDomainBaseUrl () , tenant , namespace , encodedTopic );
123115 try {
124116 HttpResponse <String > response = httpClient .delete (url ,
125117 "force" , String .valueOf (force ),
@@ -137,7 +129,7 @@ public void deleteTopic(String tenant, String namespace, String encodedTopic, bo
137129 @ Override
138130 public List <String > getList (String tenant , String namespace , String bundle , boolean includeSystemTopic )
139131 throws PulsarAdminException {
140- String url = String .format ("%s/%s/%s" , "/admin/v2" + "/persistent" , tenant , namespace );
132+ String url = String .format ("%s/%s/%s" , getDomainBaseUrl () , tenant , namespace );
141133 try {
142134 HttpResponse <String > response ;
143135 if (bundle != null ) {
@@ -164,7 +156,7 @@ public List<String> getList(String tenant, String namespace, String bundle, bool
164156 @ Override
165157 public List <String > getPartitionedTopicList (String tenant , String namespace , boolean includeSystemTopic )
166158 throws PulsarAdminException {
167- String url = String .format ("%s/%s/%s%s" , "/admin/v2" + "/persistent" , tenant , namespace , UrlConst .PARTITIONED );
159+ String url = String .format ("%s/%s/%s%s" , getDomainBaseUrl () , tenant , namespace , UrlConst .PARTITIONED );
168160 try {
169161 HttpResponse <String > response = httpClient .get (url , "includeSystemTopic" ,
170162 String .valueOf (includeSystemTopic ));
@@ -184,7 +176,7 @@ public List<String> getPartitionedTopicList(String tenant, String namespace, boo
184176 @ Override
185177 public void createMissedPartitions (String tenant , String namespace , String encodedTopic )
186178 throws PulsarAdminException {
187- String url = String .format ("%s/%s/%s/%s%s" , "/admin/v2" + "/persistent" , tenant , namespace , encodedTopic ,
179+ String url = String .format ("%s/%s/%s/%s%s" , getDomainBaseUrl () , tenant , namespace , encodedTopic ,
188180 UrlConst .CREATE_MISSED_PARTITIONS );
189181 try {
190182 HttpResponse <String > response = httpClient .post (url );
@@ -202,7 +194,7 @@ public void createMissedPartitions(String tenant, String namespace, String encod
202194 @ Override
203195 public MessageIdImpl getLastMessageId (String tenant , String namespace , String encodedTopic , boolean authoritative )
204196 throws PulsarAdminException {
205- String url = String .format ("%s/%s/%s/%s%s" , "/admin/v2" + "/persistent" , tenant , namespace , encodedTopic ,
197+ String url = String .format ("%s/%s/%s/%s%s" , getDomainBaseUrl () , tenant , namespace , encodedTopic ,
206198 UrlConst .LAST_MESSAGE_ID );
207199 try {
208200 HttpResponse <String > response = httpClient .get (url , "authoritative" , String .valueOf (authoritative ));
@@ -220,7 +212,7 @@ public MessageIdImpl getLastMessageId(String tenant, String namespace, String en
220212 @ Override
221213 public RetentionPolicies getRetention (String tenant , String namespace , String encodedTopic , boolean isGlobal ,
222214 boolean applied , boolean authoritative ) throws PulsarAdminException {
223- String url = String .format ("%s/%s/%s/%s%s" , "/admin/v2" + "/persistent" , tenant , namespace , encodedTopic ,
215+ String url = String .format ("%s/%s/%s/%s%s" , getDomainBaseUrl () , tenant , namespace , encodedTopic ,
224216 UrlConst .RETENTION );
225217 try {
226218 HttpResponse <String > response = httpClient .get (url ,
@@ -241,7 +233,7 @@ public RetentionPolicies getRetention(String tenant, String namespace, String en
241233 @ Override
242234 public void setRetention (String tenant , String namespace , String encodedTopic , boolean authoritative ,
243235 boolean isGlobal , RetentionPolicies retention ) throws PulsarAdminException {
244- String url = String .format ("%s/%s/%s/%s%s" , "/admin/v2" + "/persistent" , tenant , namespace , encodedTopic ,
236+ String url = String .format ("%s/%s/%s/%s%s" , getDomainBaseUrl () , tenant , namespace , encodedTopic ,
245237 UrlConst .RETENTION );
246238 try {
247239 HttpResponse <String > response = httpClient .post (url , retention ,
@@ -260,7 +252,7 @@ public void setRetention(String tenant, String namespace, String encodedTopic, b
260252 @ Override
261253 public void removeRetention (String tenant , String namespace , String encodedTopic , boolean authoritative )
262254 throws PulsarAdminException {
263- String url = String .format ("%s/%s/%s/%s%s" , "/admin/v2" + "/persistent" , tenant , namespace , encodedTopic ,
255+ String url = String .format ("%s/%s/%s/%s%s" , getDomainBaseUrl () , tenant , namespace , encodedTopic ,
264256 UrlConst .RETENTION );
265257 try {
266258 HttpResponse <String > response = httpClient .delete (url , "authoritative" , String .valueOf (authoritative ));
@@ -279,7 +271,7 @@ public Map<BacklogQuotaType, BacklogQuota> getBacklogQuotaMap(String tenant, Str
279271 String encodedTopic , boolean applied ,
280272 boolean authoritative , boolean isGlobal )
281273 throws PulsarAdminException {
282- String url = String .format ("%s/%s/%s/%s%s" , "/admin/v2" + "/persistent" , tenant , namespace , encodedTopic ,
274+ String url = String .format ("%s/%s/%s/%s%s" , getDomainBaseUrl () , tenant , namespace , encodedTopic ,
283275 UrlConst .BACKLOG_QUOTA_MAP );
284276 try {
285277 HttpResponse <String > response = httpClient .get (url ,
@@ -302,7 +294,7 @@ public Map<BacklogQuotaType, BacklogQuota> getBacklogQuotaMap(String tenant, Str
302294 public void setBacklogQuota (String tenant , String namespace , String encodedTopic , boolean authoritative ,
303295 boolean isGlobal , BacklogQuotaType backlogQuotaType , BacklogQuota backlogQuota )
304296 throws PulsarAdminException {
305- String url = String .format ("%s/%s/%s/%s%s" , "/admin/v2" + "/persistent" , tenant , namespace , encodedTopic ,
297+ String url = String .format ("%s/%s/%s/%s%s" , getDomainBaseUrl () , tenant , namespace , encodedTopic ,
306298 UrlConst .BACKLOG_QUOTA );
307299 try {
308300 HttpResponse <String > response = httpClient .post (url , backlogQuota ,
@@ -323,7 +315,7 @@ public void setBacklogQuota(String tenant, String namespace, String encodedTopic
323315 public void removeBacklogQuota (String tenant , String namespace , String encodedTopic ,
324316 BacklogQuotaType backlogQuotaType , boolean authoritative , boolean isGlobal )
325317 throws PulsarAdminException {
326- String url = String .format ("%s/%s/%s/%s%s" , "/admin/v2" + "/persistent" , tenant , namespace , encodedTopic ,
318+ String url = String .format ("%s/%s/%s/%s%s" , getDomainBaseUrl () , tenant , namespace , encodedTopic ,
327319 UrlConst .BACKLOG_QUOTA );
328320 try {
329321 HttpResponse <String > response = httpClient .delete (url ,
@@ -343,7 +335,7 @@ public void removeBacklogQuota(String tenant, String namespace, String encodedTo
343335 @ Override
344336 public PersistentOfflineTopicStats getBacklog (String tenant , String namespace , String encodedTopic ,
345337 boolean authoritative ) throws PulsarAdminException {
346- String url = String .format ("%s/%s/%s/%s%s" , "/admin/v2" + "/persistent" , tenant , namespace , encodedTopic ,
338+ String url = String .format ("%s/%s/%s/%s%s" , getDomainBaseUrl () , tenant , namespace , encodedTopic ,
347339 UrlConst .BACKLOG );
348340 try {
349341 HttpResponse <String > response = httpClient .get (url , "authoritative" , String .valueOf (authoritative ));
@@ -361,7 +353,7 @@ public PersistentOfflineTopicStats getBacklog(String tenant, String namespace, S
361353 @ Override
362354 public long getBacklogSizeByMessageId (String tenant , String namespace , String encodedTopic , boolean authoritative ,
363355 MessageIdImpl messageId ) throws PulsarAdminException {
364- String url = String .format ("%s/%s/%s/%s%s" , "/admin/v2" + "/persistent" , tenant , namespace , encodedTopic ,
356+ String url = String .format ("%s/%s/%s/%s%s" , getDomainBaseUrl () , tenant , namespace , encodedTopic ,
365357 UrlConst .BACKLOG_SIZE );
366358 try {
367359 HttpResponse <String > response = httpClient .put (url , messageId , "authoritative" ,
@@ -376,5 +368,4 @@ public long getBacklogSizeByMessageId(String tenant, String namespace, String en
376368 throw new PulsarAdminException (e );
377369 }
378370 }
379-
380371}
0 commit comments