Search in sources :

Example 6 with RestException

use of org.apache.pulsar.broker.web.RestException in project incubator-pulsar by apache.

the class Namespaces method getNamespacesForCluster.

@GET
@Path("/{property}/{cluster}")
@ApiOperation(hidden = true, value = "Get the list of all the namespaces for a certain property on single cluster.", response = String.class, responseContainer = "Set")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission"), @ApiResponse(code = 404, message = "Property or cluster doesn't exist") })
public List<String> getNamespacesForCluster(@PathParam("property") String property, @PathParam("cluster") String cluster) {
    validateAdminAccessOnProperty(property);
    List<String> namespaces = Lists.newArrayList();
    if (!clusters().contains(cluster)) {
        log.warn("[{}] Failed to get namespace list for property: {}/{} - Cluster does not exist", clientAppId(), property, cluster);
        throw new RestException(Status.NOT_FOUND, "Cluster does not exist");
    }
    try {
        for (String namespace : globalZk().getChildren(path(POLICIES, property, cluster), false)) {
            namespaces.add(String.format("%s/%s/%s", property, cluster, namespace));
        }
    } catch (KeeperException.NoNodeException e) {
    // NoNode means there are no namespaces for this property on the specified cluster, returning empty list
    } catch (Exception e) {
        log.error("[{}] Failed to get namespaces list: {}", clientAppId(), e);
        throw new RestException(e);
    }
    namespaces.sort(null);
    return namespaces;
}
Also used : RestException(org.apache.pulsar.broker.web.RestException) KeeperException(org.apache.zookeeper.KeeperException) RestException(org.apache.pulsar.broker.web.RestException) KeeperException(org.apache.zookeeper.KeeperException) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 7 with RestException

use of org.apache.pulsar.broker.web.RestException in project incubator-pulsar by apache.

the class AdminResource method getNamespacePolicies.

protected Policies getNamespacePolicies(String property, String cluster, String namespace) {
    try {
        Policies policies = policiesCache().get(AdminResource.path(POLICIES, property, cluster, namespace)).orElseThrow(() -> new RestException(Status.NOT_FOUND, "Namespace does not exist"));
        // fetch bundles from LocalZK-policies
        NamespaceBundles bundles = pulsar().getNamespaceService().getNamespaceBundleFactory().getBundles(NamespaceName.get(property, cluster, namespace));
        BundlesData bundleData = NamespaceBundleFactory.getBundlesData(bundles);
        policies.bundles = bundleData != null ? bundleData : policies.bundles;
        return policies;
    } catch (RestException re) {
        throw re;
    } catch (Exception e) {
        log.error("[{}] Failed to get namespace policies {}/{}/{}", clientAppId(), property, cluster, namespace, e);
        throw new RestException(e);
    }
}
Also used : NamespaceIsolationPolicies(org.apache.pulsar.common.policies.impl.NamespaceIsolationPolicies) LocalPolicies(org.apache.pulsar.common.policies.data.LocalPolicies) Policies(org.apache.pulsar.common.policies.data.Policies) NamespaceBundles(org.apache.pulsar.common.naming.NamespaceBundles) RestException(org.apache.pulsar.broker.web.RestException) BundlesData(org.apache.pulsar.common.policies.data.BundlesData) RestException(org.apache.pulsar.broker.web.RestException) KeeperException(org.apache.zookeeper.KeeperException) MalformedURLException(java.net.MalformedURLException) WebApplicationException(javax.ws.rs.WebApplicationException)

Example 8 with RestException

use of org.apache.pulsar.broker.web.RestException in project incubator-pulsar by apache.

the class AdminResource method validateTopicName.

protected void validateTopicName(String property, String namespace, String encodedTopic) {
    String topic = Codec.decode(encodedTopic);
    try {
        this.namespaceName = NamespaceName.get(property, namespace);
        this.topicName = TopicName.get(domain(), namespaceName, topic);
    } catch (IllegalArgumentException e) {
        log.warn("[{}] Failed to validate topic name {}://{}/{}/{}", clientAppId(), domain(), property, namespace, topic, e);
        throw new RestException(Status.PRECONDITION_FAILED, "Topic name is not valid");
    }
    this.topicName = TopicName.get(domain(), namespaceName, topic);
}
Also used : RestException(org.apache.pulsar.broker.web.RestException)

Example 9 with RestException

use of org.apache.pulsar.broker.web.RestException in project incubator-pulsar by apache.

the class BrokersBase method getAllDynamicConfigurations.

@GET
@Path("/configuration/values")
@ApiOperation(value = "Get value of all dynamic configurations' value overridden on local config")
@ApiResponses(value = { @ApiResponse(code = 404, message = "Configuration not found") })
public Map<String, String> getAllDynamicConfigurations() throws Exception {
    ZooKeeperDataCache<Map<String, String>> dynamicConfigurationCache = pulsar().getBrokerService().getDynamicConfigurationCache();
    Map<String, String> configurationMap = null;
    try {
        configurationMap = dynamicConfigurationCache.get(BROKER_SERVICE_CONFIGURATION_PATH).orElseThrow(() -> new RestException(Status.NOT_FOUND, "Couldn't find configuration in zk"));
    } catch (RestException e) {
        LOG.error("[{}] couldn't find any configuration in zk {}", clientAppId(), e.getMessage(), e);
        throw e;
    } catch (Exception e) {
        LOG.error("[{}] Failed to retrieve configuration from zk {}", clientAppId(), e.getMessage(), e);
        throw new RestException(e);
    }
    return configurationMap;
}
Also used : RestException(org.apache.pulsar.broker.web.RestException) Map(java.util.Map) RestException(org.apache.pulsar.broker.web.RestException) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 10 with RestException

use of org.apache.pulsar.broker.web.RestException in project incubator-pulsar by apache.

the class BrokersBase method getActiveBrokers.

@GET
@Path("/{cluster}")
@ApiOperation(value = "Get the list of active brokers (web service addresses) in the cluster.", response = String.class, responseContainer = "Set")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission"), @ApiResponse(code = 404, message = "Cluster doesn't exist") })
public Set<String> getActiveBrokers(@PathParam("cluster") String cluster) throws Exception {
    validateSuperUserAccess();
    validateClusterOwnership(cluster);
    try {
        // Add Native brokers
        return pulsar().getLocalZkCache().getChildren(LoadManager.LOADBALANCE_BROKERS_ROOT);
    } catch (Exception e) {
        LOG.error(String.format("[%s] Failed to get active broker list: cluster=%s", clientAppId(), cluster), e);
        throw new RestException(e);
    }
}
Also used : RestException(org.apache.pulsar.broker.web.RestException) RestException(org.apache.pulsar.broker.web.RestException) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

RestException (org.apache.pulsar.broker.web.RestException)112 KeeperException (org.apache.zookeeper.KeeperException)81 WebApplicationException (javax.ws.rs.WebApplicationException)55 PulsarServerException (org.apache.pulsar.broker.PulsarServerException)55 ExecutionException (java.util.concurrent.ExecutionException)53 PulsarAdminException (org.apache.pulsar.client.admin.PulsarAdminException)51 SubscriptionBusyException (org.apache.pulsar.broker.service.BrokerServiceException.SubscriptionBusyException)49 IOException (java.io.IOException)36 Policies (org.apache.pulsar.common.policies.data.Policies)33 ApiResponses (io.swagger.annotations.ApiResponses)30 Path (javax.ws.rs.Path)29 ApiOperation (io.swagger.annotations.ApiOperation)27 PulsarClientException (org.apache.pulsar.client.api.PulsarClientException)25 ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)24 NotAllowedException (org.apache.pulsar.broker.service.BrokerServiceException.NotAllowedException)24 TopicBusyException (org.apache.pulsar.broker.service.BrokerServiceException.TopicBusyException)24 NotFoundException (org.apache.pulsar.client.admin.PulsarAdminException.NotFoundException)24 PreconditionFailedException (org.apache.pulsar.client.admin.PulsarAdminException.PreconditionFailedException)24 RetentionPolicies (org.apache.pulsar.common.policies.data.RetentionPolicies)24 PersistencePolicies (org.apache.pulsar.common.policies.data.PersistencePolicies)22