aloyszhang commented on code in PR #8941: URL: https://github.com/apache/inlong/pull/8941#discussion_r1379652455
########## inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/resource/queue/pulsar/PulsarUtils.java: ########## @@ -39,54 +65,919 @@ public class PulsarUtils { private PulsarUtils() { } + private static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ISO_OFFSET_DATE_TIME.withZone( + ZoneId.systemDefault()); + + public static final String QUERY_CLUSTERS_PATH = "/admin/v2/clusters"; + public static final String QUERY_BROKERS_PATH = "/admin/v2/brokers"; + public static final String QUERY_TENANTS_PATH = "/admin/v2/tenants"; + public static final String QUERY_NAMESPACE_PATH = "/admin/v2/namespaces"; + public static final String QUERY_PERSISTENT_PATH = "/admin/v2/persistent"; + public static final String LOOKUP_TOPIC_PATH = "/lookup/v2/topic"; + + private static final Gson GSON = new GsonBuilder().create(); // thread safe + + /** + * Get http headers by token. + * + * @param token pulsar token info + * @return add http headers for token info + */ + private static HttpHeaders getHttpHeaders(String token) { + HttpHeaders headers = new HttpHeaders(); + if (StringUtils.isNotEmpty(token)) { + headers.add("Authorization", "Bearer " + token); + } + return headers; + } + + /** + * Get pulsar cluster info list. + * + * @param restTemplate spring framework RestTemplate + * @param clusterInfo pulsar cluster info + * @return list of pulsar cluster infos + * @throws Exception any exception if occurred + */ + public static List<String> getPulsarClusters(RestTemplate restTemplate, PulsarClusterInfo clusterInfo) + throws Exception { + final String url = clusterInfo.getAdminUrl() + QUERY_CLUSTERS_PATH; + return HttpUtils.request(restTemplate, url, HttpMethod.GET, null, getHttpHeaders(clusterInfo.getToken()), + ArrayList.class); + } + /** - * Get pulsar admin info + * Get the list of active brokers. + * + * @param restTemplate spring framework RestTemplate + * @param clusterInfo pulsar cluster info + * @return list of pulsar broker infos + * @throws Exception any exception if occurred + */ + public static List<String> getPulsarBrokers(RestTemplate restTemplate, PulsarClusterInfo clusterInfo) + throws Exception { + List<String> clusters = getPulsarClusters(restTemplate, clusterInfo); + List<String> brokers = new ArrayList<>(); + for (String brokerName : brokers) { Review Comment: why traverse an empty list? Should traverse the clusters instead -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@inlong.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org