Search in sources :

Example 1 with FailureDomainResources

use of org.apache.pulsar.broker.resources.ClusterResources.FailureDomainResources in project pulsar by apache.

the class ClustersBase method getFailureDomains.

@GET
@Path("/{cluster}/failureDomains")
@ApiOperation(value = "Get the cluster failure domains.", response = FailureDomainImpl.class, responseContainer = "Map", notes = "This operation requires Pulsar superuser privileges.")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission"), @ApiResponse(code = 500, message = "Internal server error") })
public Map<String, FailureDomainImpl> getFailureDomains(@ApiParam(value = "The cluster name", required = true) @PathParam("cluster") String cluster) throws Exception {
    validateSuperUserAccess();
    Map<String, FailureDomainImpl> domains = Maps.newHashMap();
    try {
        FailureDomainResources fdr = clusterResources().getFailureDomainResources();
        for (String domainName : fdr.listFailureDomains(cluster)) {
            try {
                Optional<FailureDomainImpl> domain = fdr.getFailureDomain(cluster, domainName);
                domain.ifPresent(failureDomain -> domains.put(domainName, failureDomain));
            } catch (Exception e) {
                log.warn("Failed to get domain {}", domainName, e);
            }
        }
    } catch (NotFoundException e) {
        log.warn("[{}] Failure-domain is not configured for cluster {}", clientAppId(), cluster, e);
        return Collections.emptyMap();
    } catch (Exception e) {
        log.error("[{}] Failed to get failure-domains for cluster {}", clientAppId(), cluster, e);
        throw new RestException(e);
    }
    return domains;
}
Also used : FailureDomainImpl(org.apache.pulsar.common.policies.data.FailureDomainImpl) RestException(org.apache.pulsar.broker.web.RestException) NotFoundException(org.apache.pulsar.metadata.api.MetadataStoreException.NotFoundException) FailureDomainResources(org.apache.pulsar.broker.resources.ClusterResources.FailureDomainResources) RestException(org.apache.pulsar.broker.web.RestException) NotFoundException(org.apache.pulsar.metadata.api.MetadataStoreException.NotFoundException) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 FailureDomainResources (org.apache.pulsar.broker.resources.ClusterResources.FailureDomainResources)1 RestException (org.apache.pulsar.broker.web.RestException)1 FailureDomainImpl (org.apache.pulsar.common.policies.data.FailureDomainImpl)1 NotFoundException (org.apache.pulsar.metadata.api.MetadataStoreException.NotFoundException)1