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;
}
Aggregations