use of io.swagger.annotations.ApiResponses in project pulsar by yahoo.
the class Properties method deleteProperty.
@DELETE
@Path("/{property}")
@ApiOperation(value = "elete a property and all namespaces and destinations under it.")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission"), @ApiResponse(code = 404, message = "Property does not exist"), @ApiResponse(code = 409, message = "The property still has active namespaces") })
public void deleteProperty(@PathParam("property") String property) {
validateSuperUserAccess();
validatePoliciesReadOnlyAccess();
boolean isPropertyEmpty = false;
try {
isPropertyEmpty = getListOfNamespaces(property).isEmpty();
} catch (KeeperException.NoNodeException e) {
log.warn("[{}] Failed to delete property {}: does not exist", clientAppId(), property);
throw new RestException(Status.NOT_FOUND, "The property does not exist");
} catch (Exception e) {
log.error("[{}] Failed to get property status {}", clientAppId(), property, e);
throw new RestException(e);
}
if (!isPropertyEmpty) {
log.warn("[{}] Failed to delete property {}: not empty", clientAppId(), property);
throw new RestException(Status.CONFLICT, "The property still has active namespaces");
}
try {
// First try to delete every cluster z-node
for (String cluster : globalZk().getChildren(path("policies", property), false)) {
globalZk().delete(path("policies", property, cluster), -1);
}
globalZk().delete(path("policies", property), -1);
log.info("[{}] Deleted property {}", clientAppId(), property);
} catch (Exception e) {
log.error("[{}] Failed to delete property {}", clientAppId(), property, e);
throw new RestException(e);
}
}
use of io.swagger.annotations.ApiResponses in project pulsar by yahoo.
the class ResourceQuotas method setDefaultResourceQuota.
@POST
@ApiOperation(value = "Set the default quota", response = String.class, responseContainer = "Set")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission") })
public void setDefaultResourceQuota(ResourceQuota quota) throws Exception {
validateSuperUserAccess();
validatePoliciesReadOnlyAccess();
try {
pulsar().getLocalZkCacheService().getResourceQuotaCache().setDefaultQuota(quota);
} catch (Exception e) {
log.error("[{}] Failed to get default resource quota", clientAppId());
throw new RestException(e);
}
}
use of io.swagger.annotations.ApiResponses in project pulsar by yahoo.
the class ResourceQuotas method removeNamespaceBundleResourceQuota.
@DELETE
@Path("/{property}/{cluster}/{namespace}/{bundle}")
@ApiOperation(value = "Remove resource quota for a namespace.")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission"), @ApiResponse(code = 409, message = "Concurrent modification") })
public void removeNamespaceBundleResourceQuota(@PathParam("property") String property, @PathParam("cluster") String cluster, @PathParam("namespace") String namespace, @PathParam("bundle") String bundleRange) {
validateSuperUserAccess();
validatePoliciesReadOnlyAccess();
Policies policies = getNamespacePolicies(property, cluster, namespace);
if (!cluster.equals(Namespaces.GLOBAL_CLUSTER)) {
validateClusterOwnership(cluster);
validateClusterForProperty(property, cluster);
}
NamespaceName fqnn = new NamespaceName(property, cluster, namespace);
NamespaceBundle nsBundle = validateNamespaceBundleRange(fqnn, policies.bundles, bundleRange);
try {
pulsar().getLocalZkCacheService().getResourceQuotaCache().unsetQuota(nsBundle);
log.info("[{}] Successfully unset resource quota for namespace bundle {}", clientAppId(), nsBundle.toString());
} catch (KeeperException.NoNodeException e) {
log.warn("[{}] Failed to unset resource quota for namespace bundle {}: concurrent modification", clientAppId(), nsBundle.toString());
throw new RestException(Status.CONFLICT, "Cuncurrent modification on namespace bundle quota");
} catch (Exception e) {
log.error("[{}] Failed to unset resource quota for namespace bundle {}", clientAppId(), nsBundle.toString());
throw new RestException(e);
}
}
use of io.swagger.annotations.ApiResponses in project pulsar by yahoo.
the class Clusters method deleteNamespaceIsolationPolicy.
@DELETE
@Path("/{cluster}/namespaceIsolationPolicies/{policyName}")
@ApiOperation(value = "Delete namespace isolation policy")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission or plicy is read only"), @ApiResponse(code = 412, message = "Cluster doesn't exist") })
public void deleteNamespaceIsolationPolicy(@PathParam("cluster") String cluster, @PathParam("policyName") String policyName) throws Exception {
validateSuperUserAccess();
validateClusterExists(cluster);
validatePoliciesReadOnlyAccess();
try {
String nsIsolationPolicyPath = path("clusters", cluster, "namespaceIsolationPolicies");
NamespaceIsolationPolicies nsIsolationPolicies = namespaceIsolationPoliciesCache().get(nsIsolationPolicyPath).orElseGet(() -> {
try {
this.createNamespaceIsolationPolicyNode(nsIsolationPolicyPath);
return new NamespaceIsolationPolicies();
} catch (KeeperException | InterruptedException e) {
throw new RestException(e);
}
});
nsIsolationPolicies.deletePolicy(policyName);
globalZk().setData(nsIsolationPolicyPath, jsonMapper().writeValueAsBytes(nsIsolationPolicies.getPolicies()), -1);
// make sure that the cache content will be refreshed for the next read access
namespaceIsolationPoliciesCache().invalidate(nsIsolationPolicyPath);
} catch (KeeperException.NoNodeException nne) {
log.warn("[{}] Failed to update brokers/{}/namespaceIsolationPolicies: Does not exist", clientAppId(), cluster);
throw new RestException(Status.NOT_FOUND, "NamespaceIsolationPolicies for cluster " + cluster + " does not exist");
} catch (Exception e) {
log.error("[{}] Failed to update brokers/{}/namespaceIsolationPolicies/{}", clientAppId(), cluster, policyName, e);
throw new RestException(e);
}
}
use of io.swagger.annotations.ApiResponses in project pulsar by yahoo.
the class Clusters method getNamespaceIsolationPolicy.
@GET
@Path("/{cluster}/namespaceIsolationPolicies/{policyName}")
@ApiOperation(value = "Get a single namespace isolation policy assigned in the cluster", response = NamespaceIsolationData.class)
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission"), @ApiResponse(code = 404, message = "Policy doesn't exist"), @ApiResponse(code = 412, message = "Cluster doesn't exist") })
public NamespaceIsolationData getNamespaceIsolationPolicy(@PathParam("cluster") String cluster, @PathParam("policyName") String policyName) throws Exception {
validateSuperUserAccess();
validateClusterExists(cluster);
try {
NamespaceIsolationPolicies nsIsolationPolicies = namespaceIsolationPoliciesCache().get(path("clusters", cluster, "namespaceIsolationPolicies")).orElseThrow(() -> new RestException(Status.NOT_FOUND, "NamespaceIsolationPolicies for cluster " + cluster + " does not exist"));
// construct the response to NamespaceisolationData map
if (!nsIsolationPolicies.getPolicies().containsKey(policyName)) {
log.info("[{}] Cannot find NamespaceIsolationPolicy {} for cluster {}", policyName, cluster);
throw new RestException(Status.NOT_FOUND, "Cannot find NamespaceIsolationPolicy " + policyName + " for cluster " + cluster);
}
return nsIsolationPolicies.getPolicies().get(policyName);
} catch (RestException re) {
throw re;
} catch (Exception e) {
log.error("[{}] Failed to get clusters/{}/namespaceIsolationPolicies/{}", clientAppId(), cluster, e);
throw new RestException(e);
}
}
Aggregations