Search in sources :

Example 51 with NamespaceName

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

the class NamespacesTest method testSplitBundleWithUnDividedRange.

@Test
public void testSplitBundleWithUnDividedRange() throws Exception {
    URL localWebServiceUrl = new URL(pulsar.getWebServiceAddress());
    String bundledNsLocal = "test-bundled-namespace-1";
    BundlesData bundleData = new BundlesData(Lists.newArrayList("0x00000000", "0x08375b1a", "0x08375b1b", "0xffffffff"));
    createBundledTestNamespaces(this.testProperty, this.testLocalCluster, bundledNsLocal, bundleData);
    final NamespaceName testNs = NamespaceName.get(this.testProperty, this.testLocalCluster, bundledNsLocal);
    OwnershipCache MockOwnershipCache = spy(pulsar.getNamespaceService().getOwnershipCache());
    doNothing().when(MockOwnershipCache).disableOwnership(any(NamespaceBundle.class));
    Field ownership = NamespaceService.class.getDeclaredField("ownershipCache");
    ownership.setAccessible(true);
    ownership.set(pulsar.getNamespaceService(), MockOwnershipCache);
    mockWebUrl(localWebServiceUrl, testNs);
    // split bundles
    try {
        namespaces.splitNamespaceBundle(testProperty, testLocalCluster, bundledNsLocal, "0x08375b1a_0x08375b1b", false, false);
    } catch (RestException re) {
        assertEquals(re.getResponse().getStatus(), Status.PRECONDITION_FAILED.getStatusCode());
    }
}
Also used : NamespaceBundle(org.apache.pulsar.common.naming.NamespaceBundle) NamespaceName(org.apache.pulsar.common.naming.NamespaceName) Field(java.lang.reflect.Field) OwnershipCache(org.apache.pulsar.broker.namespace.OwnershipCache) BundlesData(org.apache.pulsar.common.policies.data.BundlesData) RestException(org.apache.pulsar.broker.web.RestException) URL(java.net.URL) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Example 52 with NamespaceName

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

the class NamespacesTest method testValidateTopicOwnership.

@Test
public void testValidateTopicOwnership() throws Exception {
    try {
        URL localWebServiceUrl = new URL(pulsar.getWebServiceAddress());
        String bundledNsLocal = "test-bundled-namespace-1";
        BundlesData bundleData = new BundlesData(Lists.newArrayList("0x00000000", "0xffffffff"));
        createBundledTestNamespaces(this.testProperty, this.testLocalCluster, bundledNsLocal, bundleData);
        final NamespaceName testNs = NamespaceName.get(this.testProperty, this.testLocalCluster, bundledNsLocal);
        OwnershipCache MockOwnershipCache = spy(pulsar.getNamespaceService().getOwnershipCache());
        doNothing().when(MockOwnershipCache).disableOwnership(any(NamespaceBundle.class));
        Field ownership = NamespaceService.class.getDeclaredField("ownershipCache");
        ownership.setAccessible(true);
        ownership.set(pulsar.getNamespaceService(), MockOwnershipCache);
        TopicName topicName = TopicName.get(testNs.getPersistentTopicName("my-topic"));
        PersistentTopics topics = spy(new PersistentTopics());
        topics.setServletContext(new MockServletContext());
        topics.setPulsar(pulsar);
        doReturn(false).when(topics).isRequestHttps();
        doReturn("test").when(topics).clientAppId();
        mockWebUrl(localWebServiceUrl, testNs);
        doReturn("persistent").when(topics).domain();
        try {
            topics.validateTopicName(topicName.getProperty(), topicName.getCluster(), topicName.getNamespacePortion(), topicName.getEncodedLocalName());
            topics.validateAdminOperationOnTopic(false);
        } catch (RestException e) {
            fail("validateAdminAccessOnProperty failed");
        }
    } catch (RestException e) {
        fail("validateAdminAccessOnProperty failed");
    }
}
Also used : NamespaceBundle(org.apache.pulsar.common.naming.NamespaceBundle) NamespaceName(org.apache.pulsar.common.naming.NamespaceName) Field(java.lang.reflect.Field) OwnershipCache(org.apache.pulsar.broker.namespace.OwnershipCache) BundlesData(org.apache.pulsar.common.policies.data.BundlesData) RestException(org.apache.pulsar.broker.web.RestException) PersistentTopics(org.apache.pulsar.broker.admin.v1.PersistentTopics) URL(java.net.URL) TopicName(org.apache.pulsar.common.naming.TopicName) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Example 53 with NamespaceName

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

the class NamespaceBundleFactory method onUpdate.

@Override
public void onUpdate(String path, LocalPolicies data, Stat stat) {
    final NamespaceName namespace = NamespaceName.get(getNamespaceFromPoliciesPath(path));
    try {
        LOG.info("Policy updated for namespace {}, refreshing the bundle cache.", namespace);
        // invalidate the bundle cache to fetch new bundle data from the policies
        bundlesCache.synchronous().invalidate(namespace);
    } catch (Exception e) {
        LOG.error("Failed to update the policy change for ns {}", namespace, e);
    }
}
Also used : NamespaceName(org.apache.pulsar.common.naming.NamespaceName)

Example 54 with NamespaceName

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

the class NamespaceIsolationPoliciesTest method testBrokerAssignment.

@Test
public void testBrokerAssignment() throws Exception {
    NamespaceIsolationPolicies policies = this.getDefaultTestPolicies();
    NamespaceName ns = NamespaceName.get("pulsar/use/testns-1");
    SortedSet<BrokerStatus> primaryCandidates = new TreeSet<>();
    BrokerStatus primary = new BrokerStatus("prod1-broker1.messaging.use.example.com", true, 0);
    BrokerStatus secondary = new BrokerStatus("prod1-broker4.use.example.com", true, 0);
    BrokerStatus shared = new BrokerStatus("use.example.com", true, 0);
    SortedSet<BrokerStatus> secondaryCandidates = new TreeSet<>();
    SortedSet<BrokerStatus> sharedCandidates = new TreeSet<>();
    policies.assignBroker(ns, primary, primaryCandidates, secondaryCandidates, sharedCandidates);
    assertEquals(primaryCandidates.size(), 1);
    assertEquals(secondaryCandidates.size(), 0);
    assertEquals(sharedCandidates.size(), 0);
    assertTrue(primaryCandidates.first().equals(primary));
    policies.assignBroker(ns, secondary, primaryCandidates, secondaryCandidates, sharedCandidates);
    assertEquals(primaryCandidates.size(), 1);
    assertEquals(secondaryCandidates.size(), 1);
    assertEquals(sharedCandidates.size(), 0);
    assertTrue(secondaryCandidates.first().equals(secondary));
    policies.assignBroker(NamespaceName.get("pulsar/use1/testns-1"), shared, primaryCandidates, secondaryCandidates, sharedCandidates);
    assertEquals(primaryCandidates.size(), 1);
    assertEquals(secondaryCandidates.size(), 1);
    assertEquals(sharedCandidates.size(), 1);
    assertTrue(sharedCandidates.first().equals(shared));
}
Also used : NamespaceIsolationPolicies(org.apache.pulsar.common.policies.impl.NamespaceIsolationPolicies) NamespaceName(org.apache.pulsar.common.naming.NamespaceName) TreeSet(java.util.TreeSet) BrokerStatus(org.apache.pulsar.common.policies.data.BrokerStatus) Test(org.testng.annotations.Test)

Example 55 with NamespaceName

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

the class PulsarService method loadNamespaceTopics.

/**
 * Load all the topics contained in a namespace
 *
 * @param bundle
 *            <code>NamespaceBundle</code> to identify the service unit
 * @throws Exception
 */
public void loadNamespaceTopics(NamespaceBundle bundle) {
    executor.submit(() -> {
        LOG.info("Loading all topics on bundle: {}", bundle);
        NamespaceName nsName = bundle.getNamespaceObject();
        List<CompletableFuture<Topic>> persistentTopics = Lists.newArrayList();
        long topicLoadStart = System.nanoTime();
        for (String topic : getNamespaceService().getListOfTopics(nsName)) {
            try {
                TopicName topicName = TopicName.get(topic);
                if (bundle.includes(topicName)) {
                    CompletableFuture<Topic> future = brokerService.getTopic(topic);
                    if (future != null) {
                        persistentTopics.add(future);
                    }
                }
            } catch (Throwable t) {
                LOG.warn("Failed to preload topic {}", topic, t);
            }
        }
        if (!persistentTopics.isEmpty()) {
            FutureUtil.waitForAll(persistentTopics).thenRun(() -> {
                double topicLoadTimeSeconds = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - topicLoadStart) / 1000.0;
                LOG.info("Loaded {} topics on {} -- time taken: {} seconds", persistentTopics.size(), bundle, topicLoadTimeSeconds);
            });
        }
        return null;
    });
}
Also used : NamespaceName(org.apache.pulsar.common.naming.NamespaceName) CompletableFuture(java.util.concurrent.CompletableFuture) Topic(org.apache.pulsar.broker.service.Topic) TopicName(org.apache.pulsar.common.naming.TopicName)

Aggregations

NamespaceName (org.apache.pulsar.common.naming.NamespaceName)99 WebTarget (javax.ws.rs.client.WebTarget)52 PulsarAdminException (org.apache.pulsar.client.admin.PulsarAdminException)52 Test (org.testng.annotations.Test)27 NamespaceBundle (org.apache.pulsar.common.naming.NamespaceBundle)26 List (java.util.List)15 MockedPulsarServiceBaseTest (org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)13 RestException (org.apache.pulsar.broker.web.RestException)13 TopicName (org.apache.pulsar.common.naming.TopicName)13 Field (java.lang.reflect.Field)12 URL (java.net.URL)11 NamespaceBundles (org.apache.pulsar.common.naming.NamespaceBundles)11 Policies (org.apache.pulsar.common.policies.data.Policies)10 PulsarServerException (org.apache.pulsar.broker.PulsarServerException)8 BundlesData (org.apache.pulsar.common.policies.data.BundlesData)8 KeeperException (org.apache.zookeeper.KeeperException)8 ArrayList (java.util.ArrayList)7 Map (java.util.Map)7 HashSet (java.util.HashSet)6 CompletableFuture (java.util.concurrent.CompletableFuture)6