use of org.apache.pulsar.metadata.api.MetadataStoreException.NotFoundException 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;
}
use of org.apache.pulsar.metadata.api.MetadataStoreException.NotFoundException in project pulsar by apache.
the class ClustersBase method deleteFailureDomain.
@DELETE
@Path("/{cluster}/failureDomains/{domainName}")
@ApiOperation(value = "Delete the failure domain of the cluster", notes = "This operation requires Pulsar superuser privileges.")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission or policy is read only"), @ApiResponse(code = 404, message = "FailureDomain doesn't exist"), @ApiResponse(code = 412, message = "Cluster doesn't exist"), @ApiResponse(code = 500, message = "Internal server error") })
public void deleteFailureDomain(@ApiParam(value = "The cluster name", required = true) @PathParam("cluster") String cluster, @ApiParam(value = "The failure domain name", required = true) @PathParam("domainName") String domainName) throws Exception {
validateSuperUserAccess();
validateClusterExists(cluster);
try {
clusterResources().getFailureDomainResources().deleteFailureDomain(cluster, domainName);
} catch (NotFoundException nne) {
log.warn("[{}] Domain {} does not exist in {}", clientAppId(), domainName, cluster);
throw new RestException(Status.NOT_FOUND, "Domain-name " + domainName + " or cluster " + cluster + " does not exist");
} catch (Exception e) {
log.error("[{}] Failed to delete domain {} in cluster {}", clientAppId(), domainName, cluster, e);
throw new RestException(e);
}
}
use of org.apache.pulsar.metadata.api.MetadataStoreException.NotFoundException in project pulsar by apache.
the class ClustersBase method updateCluster.
@POST
@Path("/{cluster}")
@ApiOperation(value = "Update the configuration for a cluster.", notes = "This operation requires Pulsar superuser privileges.")
@ApiResponses(value = { @ApiResponse(code = 204, message = "Cluster has been updated."), @ApiResponse(code = 403, message = "Don't have admin permission or policies are read-only."), @ApiResponse(code = 404, message = "Cluster doesn't exist."), @ApiResponse(code = 500, message = "Internal server error.") })
public void updateCluster(@ApiParam(value = "The cluster name", required = true) @PathParam("cluster") String cluster, @ApiParam(value = "The cluster data", required = true, examples = @Example(value = @ExampleProperty(mediaType = MediaType.APPLICATION_JSON, value = "{\n" + " 'serviceUrl': 'http://pulsar.example.com:8080',\n" + " 'brokerServiceUrl': 'pulsar://pulsar.example.com:6651'\n" + "}"))) ClusterDataImpl clusterData) {
validateSuperUserAccess();
validatePoliciesReadOnlyAccess();
try {
clusterResources().updateCluster(cluster, old -> clusterData);
log.info("[{}] Updated cluster {}", clientAppId(), cluster);
} catch (NotFoundException e) {
log.warn("[{}] Failed to update cluster {}: Does not exist", clientAppId(), cluster);
throw new RestException(Status.NOT_FOUND, "Cluster does not exist");
} catch (Exception e) {
log.error("[{}] Failed to update cluster {}", clientAppId(), cluster, e);
throw new RestException(e);
}
}
use of org.apache.pulsar.metadata.api.MetadataStoreException.NotFoundException in project pulsar by apache.
the class ClustersBase method setPeerClusterNames.
@POST
@Path("/{cluster}/peers")
@ApiOperation(value = "Update peer-cluster-list for a cluster.", notes = "This operation requires Pulsar superuser privileges.")
@ApiResponses(value = { @ApiResponse(code = 204, message = "Cluster has been updated."), @ApiResponse(code = 403, message = "Don't have admin permission or policies are read-only."), @ApiResponse(code = 404, message = "Cluster doesn't exist."), @ApiResponse(code = 412, message = "Peer cluster doesn't exist."), @ApiResponse(code = 500, message = "Internal server error.") })
public void setPeerClusterNames(@ApiParam(value = "The cluster name", required = true) @PathParam("cluster") String cluster, @ApiParam(value = "The list of peer cluster names", required = true, examples = @Example(value = @ExampleProperty(mediaType = MediaType.APPLICATION_JSON, value = "[\n" + " 'cluster-a',\n" + " 'cluster-b'\n" + "]"))) LinkedHashSet<String> peerClusterNames) {
validateSuperUserAccess();
validatePoliciesReadOnlyAccess();
// validate if peer-cluster exist
if (peerClusterNames != null && !peerClusterNames.isEmpty()) {
for (String peerCluster : peerClusterNames) {
try {
if (cluster.equalsIgnoreCase(peerCluster)) {
throw new RestException(Status.PRECONDITION_FAILED, cluster + " itself can't be part of peer-list");
}
clusterResources().getCluster(peerCluster).orElseThrow(() -> new RestException(Status.PRECONDITION_FAILED, "Peer cluster " + peerCluster + " does not exist"));
} catch (RestException e) {
log.warn("[{}] Peer cluster doesn't exist from {}, {}", clientAppId(), peerClusterNames, e.getMessage());
throw e;
} catch (Exception e) {
log.warn("[{}] Failed to validate peer-cluster list {}, {}", clientAppId(), peerClusterNames, e.getMessage());
throw new RestException(e);
}
}
}
try {
clusterResources().updateCluster(cluster, old -> old.clone().peerClusterNames(peerClusterNames).build());
log.info("[{}] Successfully added peer-cluster {} for {}", clientAppId(), peerClusterNames, cluster);
} catch (NotFoundException e) {
log.warn("[{}] Failed to update cluster {}: Does not exist", clientAppId(), cluster);
throw new RestException(Status.NOT_FOUND, "Cluster does not exist");
} catch (Exception e) {
log.error("[{}] Failed to update cluster {}", clientAppId(), cluster, e);
throw new RestException(e);
}
}
use of org.apache.pulsar.metadata.api.MetadataStoreException.NotFoundException in project pulsar by apache.
the class NamespacesBase method internalSetBookieAffinityGroup.
protected void internalSetBookieAffinityGroup(BookieAffinityGroupData bookieAffinityGroup) {
validateSuperUserAccess();
log.info("[{}] Setting bookie-affinity-group {} for namespace {}", clientAppId(), bookieAffinityGroup, this.namespaceName);
if (namespaceName.isGlobal()) {
// check cluster ownership for a given global namespace: redirect if peer-cluster owns it
validateGlobalNamespaceOwnership(namespaceName);
} else {
validateClusterOwnership(namespaceName.getCluster());
validateClusterForTenant(namespaceName.getTenant(), namespaceName.getCluster());
}
try {
getLocalPolicies().setLocalPoliciesWithCreate(namespaceName, oldPolicies -> {
LocalPolicies localPolicies = oldPolicies.map(policies -> new LocalPolicies(policies.bundles, bookieAffinityGroup, policies.namespaceAntiAffinityGroup)).orElseGet(() -> new LocalPolicies(defaultBundle(), bookieAffinityGroup, null));
log.info("[{}] Successfully updated local-policies configuration: namespace={}, map={}", clientAppId(), namespaceName, localPolicies);
return localPolicies;
});
} catch (NotFoundException e) {
log.warn("[{}] Failed to update local-policy configuration for namespace {}: does not exist", clientAppId(), namespaceName);
throw new RestException(Status.NOT_FOUND, "Namespace does not exist");
} catch (Exception e) {
log.error("[{}] Failed to update local-policy configuration for namespace {}", clientAppId(), namespaceName, e);
throw new RestException(e);
}
}
Aggregations