Search in sources :

Example 31 with NamespaceName

use of com.yahoo.pulsar.common.naming.NamespaceName in project pulsar by yahoo.

the class Namespaces method unloadNamespaceBundle.

@PUT
@Path("/{property}/{cluster}/{namespace}/{bundle}/unload")
@ApiOperation(value = "Unload a namespace bundle")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission") })
public void unloadNamespaceBundle(@PathParam("property") String property, @PathParam("cluster") String cluster, @PathParam("namespace") String namespace, @PathParam("bundle") String bundleRange, @QueryParam("authoritative") @DefaultValue("false") boolean authoritative) {
    log.info("[{}] Unloading namespace bundle {}/{}/{}/{}", clientAppId(), property, cluster, namespace, bundleRange);
    validateSuperUserAccess();
    Policies policies = getNamespacePolicies(property, cluster, namespace);
    if (!cluster.equals(Namespaces.GLOBAL_CLUSTER)) {
        validateClusterOwnership(cluster);
        validateClusterForProperty(property, cluster);
    }
    NamespaceName fqnn = new NamespaceName(property, cluster, namespace);
    validatePoliciesReadOnlyAccess();
    NamespaceBundle nsBundle = validateNamespaceBundleOwnership(fqnn, policies.bundles, bundleRange, authoritative, true);
    try {
        pulsar().getNamespaceService().unloadNamespaceBundle(nsBundle);
        log.info("[{}] Successfully unloaded namespace bundle {}", clientAppId(), nsBundle.toString());
    } catch (Exception e) {
        log.error("[{}] Failed to unload namespace bundle {}/{}", clientAppId(), fqnn.toString(), bundleRange, e);
        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) PersistencePolicies(com.yahoo.pulsar.common.policies.data.PersistencePolicies) RetentionPolicies(com.yahoo.pulsar.common.policies.data.RetentionPolicies) RestException(com.yahoo.pulsar.broker.web.RestException) RestException(com.yahoo.pulsar.broker.web.RestException) WebApplicationException(javax.ws.rs.WebApplicationException) SubscriptionBusyException(com.yahoo.pulsar.broker.service.BrokerServiceException.SubscriptionBusyException) KeeperException(org.apache.zookeeper.KeeperException) PulsarAdminException(com.yahoo.pulsar.client.admin.PulsarAdminException) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) PulsarServerException(com.yahoo.pulsar.broker.PulsarServerException) Path(javax.ws.rs.Path) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Example 32 with NamespaceName

use of com.yahoo.pulsar.common.naming.NamespaceName in project pulsar by yahoo.

the class Namespaces method unsubscribeNamespaceBundle.

@POST
@Path("/{property}/{cluster}/{namespace}/{bundle}/unsubscribe/{subscription}")
@ApiOperation(value = "Unsubscribes the given subscription on all destinations on a namespace bundle.")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission"), @ApiResponse(code = 404, message = "Namespace does not exist") })
public void unsubscribeNamespaceBundle(@PathParam("property") String property, @PathParam("cluster") String cluster, @PathParam("namespace") String namespace, @PathParam("subscription") String subscription, @PathParam("bundle") String bundleRange, @QueryParam("authoritative") @DefaultValue("false") boolean authoritative) {
    validateAdminAccessOnProperty(property);
    Policies policies = getNamespacePolicies(property, cluster, namespace);
    if (!cluster.equals(Namespaces.GLOBAL_CLUSTER)) {
        validateClusterOwnership(cluster);
        validateClusterForProperty(property, cluster);
    }
    NamespaceName nsName = new NamespaceName(property, cluster, namespace);
    validateNamespaceBundleOwnership(nsName, policies.bundles, bundleRange, authoritative, true);
    unsubscribe(nsName, bundleRange, subscription);
    log.info("[{}] Successfully unsubscribed {} on namespace bundle {}/{}", clientAppId(), subscription, nsName.toString(), bundleRange);
}
Also used : NamespaceName(com.yahoo.pulsar.common.naming.NamespaceName) Policies(com.yahoo.pulsar.common.policies.data.Policies) PersistencePolicies(com.yahoo.pulsar.common.policies.data.PersistencePolicies) RetentionPolicies(com.yahoo.pulsar.common.policies.data.RetentionPolicies) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 33 with NamespaceName

use of com.yahoo.pulsar.common.naming.NamespaceName in project pulsar by yahoo.

the class Namespaces method clearNamespaceBacklog.

@POST
@Path("/{property}/{cluster}/{namespace}/clearBacklog")
@ApiOperation(value = "Clear backlog for all destinations on a namespace.")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission"), @ApiResponse(code = 404, message = "Namespace does not exist") })
public void clearNamespaceBacklog(@PathParam("property") String property, @PathParam("cluster") String cluster, @PathParam("namespace") String namespace, @QueryParam("authoritative") @DefaultValue("false") boolean authoritative) {
    validateAdminAccessOnProperty(property);
    NamespaceName nsName = new NamespaceName(property, cluster, namespace);
    try {
        NamespaceBundles bundles = pulsar().getNamespaceService().getNamespaceBundleFactory().getBundles(nsName);
        Exception exception = null;
        for (NamespaceBundle nsBundle : bundles.getBundles()) {
            try {
                // clear
                if (pulsar().getNamespaceService().getOwner(nsBundle).isPresent()) {
                    // TODO: make this admin call asynchronous
                    pulsar().getAdminClient().namespaces().clearNamespaceBundleBacklog(nsName.toString(), nsBundle.getBundleRange());
                }
            } catch (Exception e) {
                if (exception == null) {
                    exception = e;
                }
            }
        }
        if (exception != null) {
            if (exception instanceof PulsarAdminException) {
                throw new RestException((PulsarAdminException) exception);
            } else {
                throw new RestException(exception.getCause());
            }
        }
    } catch (WebApplicationException wae) {
        throw wae;
    } catch (Exception e) {
        throw new RestException(e);
    }
    log.info("[{}] Successfully cleared backlog on all the bundles for namespace {}", clientAppId(), nsName.toString());
}
Also used : NamespaceBundle(com.yahoo.pulsar.common.naming.NamespaceBundle) NamespaceName(com.yahoo.pulsar.common.naming.NamespaceName) WebApplicationException(javax.ws.rs.WebApplicationException) NamespaceBundles(com.yahoo.pulsar.common.naming.NamespaceBundles) RestException(com.yahoo.pulsar.broker.web.RestException) PulsarAdminException(com.yahoo.pulsar.client.admin.PulsarAdminException) RestException(com.yahoo.pulsar.broker.web.RestException) WebApplicationException(javax.ws.rs.WebApplicationException) SubscriptionBusyException(com.yahoo.pulsar.broker.service.BrokerServiceException.SubscriptionBusyException) KeeperException(org.apache.zookeeper.KeeperException) PulsarAdminException(com.yahoo.pulsar.client.admin.PulsarAdminException) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) PulsarServerException(com.yahoo.pulsar.broker.PulsarServerException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 34 with NamespaceName

use of com.yahoo.pulsar.common.naming.NamespaceName in project pulsar by yahoo.

the class Namespaces method splitNamespaceBundle.

@PUT
@Path("/{property}/{cluster}/{namespace}/{bundle}/split")
@ApiOperation(value = "Split a namespace bundle")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission") })
public void splitNamespaceBundle(@PathParam("property") String property, @PathParam("cluster") String cluster, @PathParam("namespace") String namespace, @PathParam("bundle") String bundleRange, @QueryParam("authoritative") @DefaultValue("false") boolean authoritative) {
    log.info("[{}] Split namespace bundle {}/{}/{}/{}", clientAppId(), property, cluster, namespace, bundleRange);
    validateSuperUserAccess();
    Policies policies = getNamespacePolicies(property, cluster, namespace);
    if (!cluster.equals(Namespaces.GLOBAL_CLUSTER)) {
        validateClusterOwnership(cluster);
        validateClusterForProperty(property, cluster);
    }
    NamespaceName fqnn = new NamespaceName(property, cluster, namespace);
    validatePoliciesReadOnlyAccess();
    NamespaceBundle nsBundle = validateNamespaceBundleOwnership(fqnn, policies.bundles, bundleRange, authoritative, true);
    try {
        pulsar().getNamespaceService().splitAndOwnBundle(nsBundle).get();
        log.info("[{}] Successfully split namespace bundle {}", clientAppId(), nsBundle.toString());
    } catch (Exception e) {
        log.error("[{}] Failed to split namespace bundle {}/{}", clientAppId(), fqnn.toString(), bundleRange, e);
        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) PersistencePolicies(com.yahoo.pulsar.common.policies.data.PersistencePolicies) RetentionPolicies(com.yahoo.pulsar.common.policies.data.RetentionPolicies) RestException(com.yahoo.pulsar.broker.web.RestException) RestException(com.yahoo.pulsar.broker.web.RestException) WebApplicationException(javax.ws.rs.WebApplicationException) SubscriptionBusyException(com.yahoo.pulsar.broker.service.BrokerServiceException.SubscriptionBusyException) KeeperException(org.apache.zookeeper.KeeperException) PulsarAdminException(com.yahoo.pulsar.client.admin.PulsarAdminException) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) PulsarServerException(com.yahoo.pulsar.broker.PulsarServerException) Path(javax.ws.rs.Path) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Example 35 with NamespaceName

use of com.yahoo.pulsar.common.naming.NamespaceName in project pulsar by yahoo.

the class ResourceQuotasImpl method setNamespaceBundleResourceQuota.

public void setNamespaceBundleResourceQuota(String namespace, String bundle, ResourceQuota quota) throws PulsarAdminException {
    try {
        NamespaceName ns = new NamespaceName(namespace);
        request(quotas.path(ns.getProperty()).path(ns.getCluster()).path(ns.getLocalName()).path(bundle)).post(Entity.entity(quota, MediaType.APPLICATION_JSON), ErrorData.class);
    } catch (Exception e) {
        throw getApiException(e);
    }
}
Also used : NamespaceName(com.yahoo.pulsar.common.naming.NamespaceName) PulsarAdminException(com.yahoo.pulsar.client.admin.PulsarAdminException)

Aggregations

NamespaceName (com.yahoo.pulsar.common.naming.NamespaceName)93 NamespaceBundle (com.yahoo.pulsar.common.naming.NamespaceBundle)41 Test (org.testng.annotations.Test)40 PulsarAdminException (com.yahoo.pulsar.client.admin.PulsarAdminException)38 RestException (com.yahoo.pulsar.broker.web.RestException)25 Policies (com.yahoo.pulsar.common.policies.data.Policies)18 ApiOperation (io.swagger.annotations.ApiOperation)17 ApiResponses (io.swagger.annotations.ApiResponses)17 Path (javax.ws.rs.Path)17 KeeperException (org.apache.zookeeper.KeeperException)17 PulsarServerException (com.yahoo.pulsar.broker.PulsarServerException)16 MockedPulsarServiceBaseTest (com.yahoo.pulsar.broker.auth.MockedPulsarServiceBaseTest)14 RetentionPolicies (com.yahoo.pulsar.common.policies.data.RetentionPolicies)14 NamespaceBundles (com.yahoo.pulsar.common.naming.NamespaceBundles)13 Field (java.lang.reflect.Field)13 URL (java.net.URL)13 WebApplicationException (javax.ws.rs.WebApplicationException)13 PersistencePolicies (com.yahoo.pulsar.common.policies.data.PersistencePolicies)12 NoNodeException (org.apache.zookeeper.KeeperException.NoNodeException)10 SubscriptionBusyException (com.yahoo.pulsar.broker.service.BrokerServiceException.SubscriptionBusyException)9