Search in sources :

Example 41 with Policies

use of org.apache.pulsar.common.policies.data.Policies in project incubator-pulsar by apache.

the class PoliciesDataTest method bundlesPolicies.

@Test
void bundlesPolicies() throws JsonGenerationException, JsonMappingException, IOException {
    ObjectMapper jsonMapper = ObjectMapperFactory.create();
    String oldJsonPolicy = "{\"auth_policies\":{\"namespace_auth\":{},\"destination_auth\":{}},\"replication_clusters\":[]," + "\"backlog_quota_map\":{},\"persistence\":null,\"latency_stats_sample_rate\":{},\"message_ttl_in_seconds\":0}";
    Policies policies = jsonMapper.readValue(oldJsonPolicy.getBytes(), Policies.class);
    assertEquals(policies, new Policies());
    String newJsonPolicy = "{\"auth_policies\":{\"namespace_auth\":{},\"destination_auth\":{}},\"replication_clusters\":[],\"bundles\":null," + "\"backlog_quota_map\":{},\"persistence\":null,\"latency_stats_sample_rate\":{},\"message_ttl_in_seconds\":0}";
    OldPolicies oldPolicies = jsonMapper.readValue(newJsonPolicy.getBytes(), OldPolicies.class);
    assertEquals(oldPolicies, new OldPolicies());
}
Also used : Policies(org.apache.pulsar.common.policies.data.Policies) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.testng.annotations.Test)

Example 42 with Policies

use of org.apache.pulsar.common.policies.data.Policies in project incubator-pulsar by apache.

the class PoliciesDataTest method bundlesData.

@Test
void bundlesData() throws JsonParseException, JsonMappingException, IOException {
    ObjectMapper jsonMapper = ObjectMapperFactory.create();
    String newJsonPolicy = "{\"auth_policies\":{\"namespace_auth\":{},\"destination_auth\":{}},\"replication_clusters\":[],\"bundles\":{\"boundaries\":[\"0x00000000\",\"0xffffffff\"]},\"backlog_quota_map\":{},\"persistence\":null,\"latency_stats_sample_rate\":{}}";
    List<String> bundleSet = Lists.newArrayList();
    bundleSet.add("0x00000000");
    bundleSet.add("0xffffffff");
    String newBundlesDataString = "{\"boundaries\":[\"0x00000000\",\"0xffffffff\"]}";
    BundlesData data = jsonMapper.readValue(newBundlesDataString.getBytes(), BundlesData.class);
    assertEquals(data.getBoundaries(), bundleSet);
    Policies policies = jsonMapper.readValue(newJsonPolicy.getBytes(), Policies.class);
    Policies expected = new Policies();
    expected.bundles = data;
    assertEquals(policies, expected);
}
Also used : Policies(org.apache.pulsar.common.policies.data.Policies) BundlesData(org.apache.pulsar.common.policies.data.BundlesData) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.testng.annotations.Test)

Example 43 with Policies

use of org.apache.pulsar.common.policies.data.Policies in project incubator-pulsar by apache.

the class NamespacesBase method internalUnsubscribeNamespaceBundle.

@SuppressWarnings("deprecation")
protected void internalUnsubscribeNamespaceBundle(String subscription, String bundleRange, boolean authoritative) {
    validateAdminAccessOnProperty(namespaceName.getProperty());
    Policies policies = getNamespacePolicies(namespaceName);
    if (namespaceName.isGlobal()) {
        // check cluster ownership for a given global namespace: redirect if peer-cluster owns it
        validateGlobalNamespaceOwnership(namespaceName);
    } else {
        validateClusterOwnership(namespaceName.getCluster());
        validateClusterForProperty(namespaceName.getProperty(), namespaceName.getCluster());
    }
    validateNamespaceBundleOwnership(namespaceName, policies.bundles, bundleRange, authoritative, true);
    unsubscribe(namespaceName, bundleRange, subscription);
    log.info("[{}] Successfully unsubscribed {} on namespace bundle {}/{}", clientAppId(), subscription, namespaceName, bundleRange);
}
Also used : PersistencePolicies(org.apache.pulsar.common.policies.data.PersistencePolicies) RetentionPolicies(org.apache.pulsar.common.policies.data.RetentionPolicies) Policies(org.apache.pulsar.common.policies.data.Policies)

Example 44 with Policies

use of org.apache.pulsar.common.policies.data.Policies in project incubator-pulsar by apache.

the class NamespacesBase method internalUnloadNamespaceBundle.

@SuppressWarnings("deprecation")
public void internalUnloadNamespaceBundle(String bundleRange, boolean authoritative) {
    log.info("[{}] Unloading namespace bundle {}/{}", clientAppId(), namespaceName, bundleRange);
    validateSuperUserAccess();
    Policies policies = getNamespacePolicies(namespaceName);
    if (namespaceName.isGlobal()) {
        // check cluster ownership for a given global namespace: redirect if peer-cluster owns it
        validateGlobalNamespaceOwnership(namespaceName);
    } else {
        validateClusterOwnership(namespaceName.getCluster());
        validateClusterForProperty(namespaceName.getProperty(), namespaceName.getCluster());
    }
    validatePoliciesReadOnlyAccess();
    if (!isBundleOwnedByAnyBroker(namespaceName, policies.bundles, bundleRange)) {
        log.info("[{}] Namespace bundle is not owned by any broker {}/{}", clientAppId(), namespaceName, bundleRange);
        return;
    }
    NamespaceBundle nsBundle = validateNamespaceBundleOwnership(namespaceName, 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(), namespaceName, bundleRange, e);
        throw new RestException(e);
    }
}
Also used : NamespaceBundle(org.apache.pulsar.common.naming.NamespaceBundle) PersistencePolicies(org.apache.pulsar.common.policies.data.PersistencePolicies) RetentionPolicies(org.apache.pulsar.common.policies.data.RetentionPolicies) Policies(org.apache.pulsar.common.policies.data.Policies) RestException(org.apache.pulsar.broker.web.RestException) RestException(org.apache.pulsar.broker.web.RestException) SubscriptionBusyException(org.apache.pulsar.broker.service.BrokerServiceException.SubscriptionBusyException) WebApplicationException(javax.ws.rs.WebApplicationException) KeeperException(org.apache.zookeeper.KeeperException) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) ExecutionException(java.util.concurrent.ExecutionException) PulsarServerException(org.apache.pulsar.broker.PulsarServerException)

Example 45 with Policies

use of org.apache.pulsar.common.policies.data.Policies in project incubator-pulsar by apache.

the class NamespacesBase method internalClearNamespaceBundleBacklogForSubscription.

@SuppressWarnings("deprecation")
protected void internalClearNamespaceBundleBacklogForSubscription(String subscription, String bundleRange, boolean authoritative) {
    validateAdminAccessOnProperty(namespaceName.getProperty());
    Policies policies = getNamespacePolicies(namespaceName);
    if (namespaceName.isGlobal()) {
        // check cluster ownership for a given global namespace: redirect if peer-cluster owns it
        validateGlobalNamespaceOwnership(namespaceName);
    } else {
        validateClusterOwnership(namespaceName.getCluster());
        validateClusterForProperty(namespaceName.getProperty(), namespaceName.getCluster());
    }
    validateNamespaceBundleOwnership(namespaceName, policies.bundles, bundleRange, authoritative, true);
    clearBacklog(namespaceName, bundleRange, subscription);
    log.info("[{}] Successfully cleared backlog for subscription {} on namespace bundle {}/{}", clientAppId(), subscription, namespaceName, bundleRange);
}
Also used : PersistencePolicies(org.apache.pulsar.common.policies.data.PersistencePolicies) RetentionPolicies(org.apache.pulsar.common.policies.data.RetentionPolicies) Policies(org.apache.pulsar.common.policies.data.Policies)

Aggregations

Policies (org.apache.pulsar.common.policies.data.Policies)93 KeeperException (org.apache.zookeeper.KeeperException)43 RetentionPolicies (org.apache.pulsar.common.policies.data.RetentionPolicies)40 PersistencePolicies (org.apache.pulsar.common.policies.data.PersistencePolicies)39 RestException (org.apache.pulsar.broker.web.RestException)34 PulsarServerException (org.apache.pulsar.broker.PulsarServerException)30 SubscriptionBusyException (org.apache.pulsar.broker.service.BrokerServiceException.SubscriptionBusyException)28 Stat (org.apache.zookeeper.data.Stat)26 WebApplicationException (javax.ws.rs.WebApplicationException)24 ExecutionException (java.util.concurrent.ExecutionException)23 PulsarAdminException (org.apache.pulsar.client.admin.PulsarAdminException)23 Test (org.testng.annotations.Test)21 NamespaceBundle (org.apache.pulsar.common.naming.NamespaceBundle)15 TopicName (org.apache.pulsar.common.naming.TopicName)14 ApiOperation (io.swagger.annotations.ApiOperation)13 ApiResponses (io.swagger.annotations.ApiResponses)13 Path (javax.ws.rs.Path)13 ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)13 NotAllowedException (org.apache.pulsar.broker.service.BrokerServiceException.NotAllowedException)11 NamespaceName (org.apache.pulsar.common.naming.NamespaceName)11