Search in sources :

Example 1 with NamespaceBundle

use of org.apache.pulsar.common.naming.NamespaceBundle in project incubator-pulsar by apache.

the class ResourceQuotasBase method internalSetNamespaceBundleResourceQuota.

@SuppressWarnings("deprecation")
protected void internalSetNamespaceBundleResourceQuota(String bundleRange, ResourceQuota quota) {
    validateSuperUserAccess();
    validatePoliciesReadOnlyAccess();
    Policies policies = getNamespacePolicies(namespaceName);
    if (!namespaceName.isGlobal()) {
        validateClusterOwnership(namespaceName.getCluster());
        validateClusterForProperty(namespaceName.getProperty(), namespaceName.getCluster());
    }
    NamespaceBundle nsBundle = validateNamespaceBundleRange(namespaceName, policies.bundles, bundleRange);
    try {
        pulsar().getLocalZkCacheService().getResourceQuotaCache().setQuota(nsBundle, quota);
        log.info("[{}] Successfully set resource quota for namespace bundle {}", clientAppId(), nsBundle.toString());
    } catch (KeeperException.NoNodeException e) {
        log.warn("[{}] Failed to set 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 set resource quota for namespace bundle {}", clientAppId(), nsBundle.toString());
        throw new RestException(e);
    }
}
Also used : NamespaceBundle(org.apache.pulsar.common.naming.NamespaceBundle) Policies(org.apache.pulsar.common.policies.data.Policies) RestException(org.apache.pulsar.broker.web.RestException) KeeperException(org.apache.zookeeper.KeeperException) KeeperException(org.apache.zookeeper.KeeperException) RestException(org.apache.pulsar.broker.web.RestException)

Example 2 with NamespaceBundle

use of org.apache.pulsar.common.naming.NamespaceBundle in project incubator-pulsar by apache.

the class NamespaceBundleTest method testCompareTo.

@Test
public void testCompareTo() throws Exception {
    NamespaceBundle bundle = factory.getBundle(NamespaceName.get("pulsar/use/ns1"), Range.range(0l, BoundType.CLOSED, 0x40000000L, BoundType.OPEN));
    NamespaceBundle bundle2 = factory.getBundle(NamespaceName.get("pulsar/use/ns1"), Range.range(0x20000000l, BoundType.CLOSED, 0x40000000L, BoundType.OPEN));
    try {
        bundle.compareTo(bundle2);
        fail("Should have failed due to overlap ranges");
    } catch (IllegalArgumentException iae) {
    // OK, expected
    }
    NamespaceBundle bundle0 = factory.getBundle(NamespaceName.get("pulsar/use/ns1"), Range.range(0l, BoundType.CLOSED, 0x10000000L, BoundType.OPEN));
    assertTrue(bundle0.compareTo(bundle2) < 0);
    assertTrue(bundle2.compareTo(bundle0) > 0);
    NamespaceBundle bundle1 = factory.getBundle(NamespaceName.get("pulsar/use/ns1"), Range.range(0l, BoundType.CLOSED, 0x20000000L, BoundType.OPEN));
    assertTrue(bundle1.compareTo(bundle2) < 0);
    NamespaceBundle bundle3 = factory.getBundle(NamespaceName.get("pulsar/use/ns1"), Range.range(0l, BoundType.CLOSED, 0x40000000L, BoundType.OPEN));
    assertTrue(bundle.compareTo(bundle3) == 0);
    NamespaceBundle otherBundle = factory.getBundle(NamespaceName.get("pulsar/use/ns2"), Range.range(0x10000000l, BoundType.CLOSED, 0x30000000L, BoundType.OPEN));
    assertTrue(otherBundle.compareTo(bundle0) > 0);
}
Also used : NamespaceBundle(org.apache.pulsar.common.naming.NamespaceBundle) Test(org.testng.annotations.Test)

Example 3 with NamespaceBundle

use of org.apache.pulsar.common.naming.NamespaceBundle in project incubator-pulsar by apache.

the class NamespaceBundleTest method testToString.

@Test
public void testToString() throws Exception {
    NamespaceBundle bundle0 = factory.getBundle(NamespaceName.get("pulsar/use/ns1"), Range.range(0l, BoundType.CLOSED, 0x10000000L, BoundType.OPEN));
    assertEquals(bundle0.toString(), "pulsar/use/ns1/0x00000000_0x10000000");
    bundle0 = factory.getBundle(NamespaceName.get("pulsar/use/ns1"), Range.range(0x10000000l, BoundType.CLOSED, NamespaceBundles.FULL_UPPER_BOUND, BoundType.CLOSED));
    assertEquals(bundle0.toString(), "pulsar/use/ns1/0x10000000_0xffffffff");
}
Also used : NamespaceBundle(org.apache.pulsar.common.naming.NamespaceBundle) Test(org.testng.annotations.Test)

Example 4 with NamespaceBundle

use of org.apache.pulsar.common.naming.NamespaceBundle in project incubator-pulsar by apache.

the class NamespaceBundleTest method testGetBundle.

@Test
public void testGetBundle() throws Exception {
    NamespaceBundle bundle = factory.getBundle(NamespaceName.get("pulsar/use/ns1"), Range.range(0L, BoundType.CLOSED, 0xffffffffL, BoundType.CLOSED));
    assertNotNull(bundle);
    NamespaceBundle bundle2 = factory.getBundle(NamespaceName.get("pulsar/use/ns1"), Range.range(0L, BoundType.CLOSED, 0xffffffffL, BoundType.CLOSED));
    // Don't call equals and make sure those two are the same instance
    assertEquals(bundle, bundle2);
}
Also used : NamespaceBundle(org.apache.pulsar.common.naming.NamespaceBundle) Test(org.testng.annotations.Test)

Example 5 with NamespaceBundle

use of org.apache.pulsar.common.naming.NamespaceBundle in project incubator-pulsar by apache.

the class NamespaceBundleTest method testConstructor.

@Test
public void testConstructor() {
    try {
        new NamespaceBundle(null, null, null);
        fail("Should have failed w/ null pointer exception");
    } catch (NullPointerException npe) {
    // OK, expected
    }
    try {
        new NamespaceBundle(NamespaceName.get("pulsar.old.ns"), null, null);
        fail("Should have failed w/ illegal argument exception");
    } catch (IllegalArgumentException iae) {
    // OK, expected
    }
    try {
        new NamespaceBundle(NamespaceName.get("pulsar/use/ns"), Range.range(0L, BoundType.CLOSED, 0L, BoundType.OPEN), null);
        fail("Should have failed w/ illegal argument exception");
    } catch (IllegalArgumentException iae) {
    // OK, expected
    }
    try {
        new NamespaceBundle(NamespaceName.get("pulsar/use/ns"), Range.range(0L, BoundType.OPEN, 1L, BoundType.OPEN), null);
        fail("Should have failed w/ illegal argument exception");
    } catch (IllegalArgumentException iae) {
    // OK, expected
    }
    try {
        new NamespaceBundle(NamespaceName.get("pulsar/use/ns"), Range.range(1L, BoundType.CLOSED, 1L, BoundType.OPEN), null);
        fail("Should have failed w/ illegal argument exception");
    } catch (IllegalArgumentException iae) {
    // OK, expected
    }
    try {
        new NamespaceBundle(NamespaceName.get("pulsar/use/ns"), Range.range(0L, BoundType.CLOSED, 1L, BoundType.CLOSED), null);
        fail("Should have failed w/ illegal argument exception");
    } catch (IllegalArgumentException iae) {
    // OK, expected
    }
    try {
        new NamespaceBundle(NamespaceName.get("pulsar/use/ns"), Range.range(0L, BoundType.CLOSED, NamespaceBundles.FULL_UPPER_BOUND, BoundType.OPEN), null);
        fail("Should have failed w/ illegal argument exception");
    } catch (IllegalArgumentException iae) {
    // OK, expected
    }
    try {
        new NamespaceBundle(NamespaceName.get("pulsar/use/ns"), Range.range(0L, BoundType.CLOSED, NamespaceBundles.FULL_UPPER_BOUND, BoundType.CLOSED), null);
        fail("Should have failed w/ null pointer exception");
    } catch (NullPointerException npe) {
    // OK, expected
    }
    NamespaceBundle bundle = new NamespaceBundle(NamespaceName.get("pulsar/use/ns"), Range.range(0L, BoundType.CLOSED, 1L, BoundType.OPEN), factory);
    assertTrue(bundle.getKeyRange().lowerEndpoint().equals(0L));
    assertEquals(bundle.getKeyRange().lowerBoundType(), BoundType.CLOSED);
    assertTrue(bundle.getKeyRange().upperEndpoint().equals(1L));
    assertEquals(bundle.getKeyRange().upperBoundType(), BoundType.OPEN);
    assertEquals(bundle.getNamespaceObject().toString(), "pulsar/use/ns");
}
Also used : NamespaceBundle(org.apache.pulsar.common.naming.NamespaceBundle) Test(org.testng.annotations.Test)

Aggregations

NamespaceBundle (org.apache.pulsar.common.naming.NamespaceBundle)66 Test (org.testng.annotations.Test)42 NamespaceName (org.apache.pulsar.common.naming.NamespaceName)23 NamespaceBundles (org.apache.pulsar.common.naming.NamespaceBundles)18 TopicName (org.apache.pulsar.common.naming.TopicName)18 KeeperException (org.apache.zookeeper.KeeperException)17 Field (java.lang.reflect.Field)14 RestException (org.apache.pulsar.broker.web.RestException)14 PulsarServerException (org.apache.pulsar.broker.PulsarServerException)13 Policies (org.apache.pulsar.common.policies.data.Policies)13 PulsarAdminException (org.apache.pulsar.client.admin.PulsarAdminException)11 ExecutionException (java.util.concurrent.ExecutionException)10 URL (java.net.URL)9 List (java.util.List)9 CompletableFuture (java.util.concurrent.CompletableFuture)8 URI (java.net.URI)7 AtomicReference (java.util.concurrent.atomic.AtomicReference)7 WebApplicationException (javax.ws.rs.WebApplicationException)7 LoadManager (org.apache.pulsar.broker.loadbalance.LoadManager)7 PersistentTopic (org.apache.pulsar.broker.service.persistent.PersistentTopic)7