Search in sources :

Example 31 with ApiResponses

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);
    }
}
Also used : RestException(com.yahoo.pulsar.broker.web.RestException) KeeperException(org.apache.zookeeper.KeeperException) RestException(com.yahoo.pulsar.broker.web.RestException) KeeperException(org.apache.zookeeper.KeeperException) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 32 with ApiResponses

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);
    }
}
Also used : RestException(com.yahoo.pulsar.broker.web.RestException) RestException(com.yahoo.pulsar.broker.web.RestException) KeeperException(org.apache.zookeeper.KeeperException) POST(javax.ws.rs.POST) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 33 with ApiResponses

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);
    }
}
Also used : NamespaceBundle(com.yahoo.pulsar.common.naming.NamespaceBundle) NamespaceName(com.yahoo.pulsar.common.naming.NamespaceName) Policies(com.yahoo.pulsar.common.policies.data.Policies) RestException(com.yahoo.pulsar.broker.web.RestException) KeeperException(org.apache.zookeeper.KeeperException) RestException(com.yahoo.pulsar.broker.web.RestException) KeeperException(org.apache.zookeeper.KeeperException) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 34 with ApiResponses

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);
    }
}
Also used : NamespaceIsolationPolicies(com.yahoo.pulsar.common.policies.impl.NamespaceIsolationPolicies) RestException(com.yahoo.pulsar.broker.web.RestException) KeeperException(org.apache.zookeeper.KeeperException) RestException(com.yahoo.pulsar.broker.web.RestException) JsonGenerationException(com.fasterxml.jackson.core.JsonGenerationException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 35 with ApiResponses

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);
    }
}
Also used : NamespaceIsolationPolicies(com.yahoo.pulsar.common.policies.impl.NamespaceIsolationPolicies) RestException(com.yahoo.pulsar.broker.web.RestException) RestException(com.yahoo.pulsar.broker.web.RestException) JsonGenerationException(com.fasterxml.jackson.core.JsonGenerationException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

ApiResponses (io.swagger.annotations.ApiResponses)612 ApiOperation (io.swagger.annotations.ApiOperation)607 Path (javax.ws.rs.Path)319 Produces (javax.ws.rs.Produces)223 Counted (com.codahale.metrics.annotation.Counted)210 Timed (com.codahale.metrics.annotation.Timed)193 GET (javax.ws.rs.GET)169 POST (javax.ws.rs.POST)119 TimedResource (org.killbill.commons.metrics.TimedResource)111 Consumes (javax.ws.rs.Consumes)109 Authorisation (no.arkivlab.hioa.nikita.webapp.security.Authorisation)94 Authorisation (nikita.webapp.security.Authorisation)87 PUT (javax.ws.rs.PUT)66 UUID (java.util.UUID)62 DELETE (javax.ws.rs.DELETE)62 AuditEvent (org.graylog2.audit.jersey.AuditEvent)59 TenantContext (org.killbill.billing.util.callcontext.TenantContext)58 RestException (com.yahoo.pulsar.broker.web.RestException)54 ApiResponse (io.swagger.annotations.ApiResponse)53 CallContext (org.killbill.billing.util.callcontext.CallContext)51