public Map getTenantsList()

in src/main/java/org/apache/pulsar/manager/service/impl/TenantsServiceImpl.java [62:135]


    public Map<String, Object> getTenantsList(Integer pageNum, Integer pageSize, String requestHost) {
        Map<String, Object> tenantsMap = Maps.newHashMap();
        List<Map<String, Object>> tenantsArray = new ArrayList<>();
        if (directRequestBroker) {
            List<String> tenantsList;
            try {
                tenantsList = pulsarAdminService.tenants(requestHost).getTenants();
            } catch (PulsarAdminException e) {
                PulsarAdminOperationException pulsarAdminOperationException
                        = new PulsarAdminOperationException("Failed to get tenants list.");
                log.error(pulsarAdminOperationException.getMessage(), e);
                throw pulsarAdminOperationException;
            }

            if (!tenantsList.isEmpty()) {
                Optional<TopicStatsEntity> topicStatsEntityOptional = topicsStatsRepository.findMaxTime();
                Map<String, TopicStatsEntity> topicStatsEntityMap = Maps.newHashMap();
                if (topicStatsEntityOptional.isPresent()) {
                    TopicStatsEntity topicStatsEntity = topicStatsEntityOptional.get();
                    String environment = request.getHeader("environment");
                    Page<TopicStatsEntity> tenantCountPage = brokerStatsService.findByMultiTenant(
                            1, 1, environment, tenantsList, topicStatsEntity.getTimestamp());
                    tenantCountPage.count(true);
                    Page<TopicStatsEntity> tenantAllCountPage = brokerStatsService.findByMultiTenant(1,
                            (int)tenantCountPage.getTotal(), environment, tenantsList, topicStatsEntity.getTimestamp());
                    for (TopicStatsEntity statsEntity : tenantAllCountPage) {
                        topicStatsEntityMap.put(statsEntity.getTenant(), statsEntity);
                    }
                }
                for (String tenant : tenantsList) {
                    TenantInfo tenantInfo;
                    try {
                        tenantInfo = pulsarAdminService.tenants(requestHost).getTenantInfo(tenant);
                    } catch (PulsarAdminException e) {
                        PulsarAdminOperationException pulsarAdminOperationException
                                = new PulsarAdminOperationException("Failed to get tenant info.");
                        log.error(pulsarAdminOperationException.getMessage(), e);
                        throw pulsarAdminOperationException;
                    }
                    Map<String, Object> tenantEntity = Maps.newHashMap();
                    tenantEntity.put("tenant", tenant);
                    tenantEntity.put("adminRoles", String.join(",", tenantInfo.getAdminRoles()));
                    tenantEntity.put("allowedClusters", String.join(",",  tenantInfo.getAllowedClusters()));
                    List<String> namespacesList;
                    try {
                        namespacesList = pulsarAdminService.namespaces(requestHost).getNamespaces(tenant);
                    } catch (PulsarAdminException e) {
                        PulsarAdminOperationException pulsarAdminOperationException
                                = new PulsarAdminOperationException("Failed to get namespaces list.");
                        log.error(pulsarAdminOperationException.getMessage(), e);
                        throw pulsarAdminOperationException;
                    }
                    tenantEntity.put("namespaces", namespacesList.size());
                    if (topicStatsEntityMap.get(tenant) != null ) {
                        TopicStatsEntity topicStatsEntity = topicStatsEntityMap.get(tenant);
                        tenantEntity.put("inMsg", topicStatsEntity.getMsgRateIn());
                        tenantEntity.put("outMsg", topicStatsEntity.getMsgRateOut());
                        tenantEntity.put("inBytes", topicStatsEntity.getMsgThroughputIn());
                        tenantEntity.put("outBytes", topicStatsEntity.getMsgThroughputOut());
                        tenantEntity.put("storageSize", topicStatsEntity.getStorageSize());
                    }
                    tenantsArray.add(tenantEntity);
                }
                tenantsMap.put("isPage", false);
                tenantsMap.put("total", tenantsList.size());
                tenantsMap.put("data", tenantsArray);
                tenantsMap.put("pageNum", 1);
                tenantsMap.put("pageSize", tenantsList.size());
            }
        } else {
           // to do query from local database
        }
        return tenantsMap;
    }