Search in sources :

Example 6 with NamespaceBundleFactory

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

the class AdminApiTest method setup.

@BeforeMethod
@Override
public void setup() throws Exception {
    conf.setLoadBalancerEnabled(true);
    conf.setTlsEnabled(true);
    conf.setTlsCertificateFilePath(TLS_SERVER_CERT_FILE_PATH);
    conf.setTlsKeyFilePath(TLS_SERVER_KEY_FILE_PATH);
    super.internalSetup();
    bundleFactory = new NamespaceBundleFactory(pulsar, Hashing.crc32());
    ClientConfiguration clientConf = new ClientConfiguration();
    clientConf.setUseTls(true);
    clientConf.setTlsTrustCertsFilePath(TLS_SERVER_CERT_FILE_PATH);
    adminTls = spy(new PulsarAdmin(brokerUrlTls, clientConf));
    // create otherbroker to test redirect on calls that need
    // namespace ownership
    mockPulsarSetup = new MockedPulsarService(this.conf);
    mockPulsarSetup.setup();
    otherPulsar = mockPulsarSetup.getPulsar();
    otheradmin = mockPulsarSetup.getAdmin();
    // Setup namespaces
    admin.clusters().createCluster("use", new ClusterData("http://127.0.0.1" + ":" + BROKER_WEBSERVICE_PORT));
    PropertyAdmin propertyAdmin = new PropertyAdmin(Lists.newArrayList("role1", "role2"), Sets.newHashSet("use"));
    admin.properties().createProperty("prop-xyz", propertyAdmin);
    admin.namespaces().createNamespace("prop-xyz/use/ns1");
}
Also used : ClusterData(org.apache.pulsar.common.policies.data.ClusterData) PulsarAdmin(org.apache.pulsar.client.admin.PulsarAdmin) PropertyAdmin(org.apache.pulsar.common.policies.data.PropertyAdmin) NamespaceBundleFactory(org.apache.pulsar.common.naming.NamespaceBundleFactory) ClientConfiguration(org.apache.pulsar.client.api.ClientConfiguration) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 7 with NamespaceBundleFactory

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

the class ResourceQuotaCacheTest method setup.

@BeforeMethod
public void setup() throws Exception {
    pulsar = mock(PulsarService.class);
    executor = OrderedScheduler.newSchedulerBuilder().numThreads(1).name("test").build();
    scheduledExecutor = Executors.newSingleThreadScheduledExecutor();
    zkCache = new LocalZooKeeperCache(MockZooKeeper.newInstance(), executor, scheduledExecutor);
    localCache = new LocalZooKeeperCacheService(zkCache, null);
    // set mock pulsar localzkcache
    LocalZooKeeperCacheService localZkCache = mock(LocalZooKeeperCacheService.class);
    ZooKeeperDataCache<LocalPolicies> poilciesCache = mock(ZooKeeperDataCache.class);
    when(pulsar.getLocalZkCacheService()).thenReturn(localZkCache);
    when(localZkCache.policiesCache()).thenReturn(poilciesCache);
    doNothing().when(poilciesCache).registerListener(any());
    bundleFactory = new NamespaceBundleFactory(pulsar, Hashing.crc32());
    doReturn(zkCache).when(pulsar).getLocalZkCache();
    doReturn(localCache).when(pulsar).getLocalZkCacheService();
}
Also used : PulsarService(org.apache.pulsar.broker.PulsarService) LocalZooKeeperCache(org.apache.pulsar.zookeeper.LocalZooKeeperCache) LocalPolicies(org.apache.pulsar.common.policies.data.LocalPolicies) NamespaceBundleFactory(org.apache.pulsar.common.naming.NamespaceBundleFactory) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 8 with NamespaceBundleFactory

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

the class NamespaceBundlesTest method testsplitBundles.

@Test
public void testsplitBundles() throws Exception {
    NamespaceName nsname = NamespaceName.get("pulsar/global/ns1");
    TopicName topicName = TopicName.get("persistent://pulsar/global/ns1/topic-1");
    NamespaceBundles bundles = factory.getBundles(nsname);
    NamespaceBundle bundle = bundles.findBundle(topicName);
    final int numberSplitBundles = 4;
    // (1) split in 4
    Pair<NamespaceBundles, List<NamespaceBundle>> splitBundles = factory.splitBundles(bundle, numberSplitBundles);
    // existing_no_bundles(1) +
    // additional_new_split_bundle(4) -
    // parent_target_bundle(1)
    int totalExpectedSplitBundles = bundles.getBundles().size() + numberSplitBundles - 1;
    validateSplitBundlesRange(bundles.getFullBundle(), splitBundles.getRight());
    assertEquals(totalExpectedSplitBundles, splitBundles.getLeft().getBundles().size());
    // (2) split in 4: first bundle from above split bundles
    NamespaceBundleFactory utilityFactory = getNamespaceBundleFactory();
    NamespaceBundles bundles2 = splitBundles.getLeft();
    NamespaceBundle testChildBundle = bundles2.getBundles().get(0);
    Pair<NamespaceBundles, List<NamespaceBundle>> splitChildBundles = splitBundlesUtilFactory(utilityFactory, nsname, bundles2, testChildBundle, numberSplitBundles);
    // existing_no_bundles(4) +
    // additional_new_split_bundle(4) -
    // parent_target_bundle(1)
    totalExpectedSplitBundles = bundles2.getBundles().size() + numberSplitBundles - 1;
    validateSplitBundlesRange(testChildBundle, splitChildBundles.getRight());
    assertEquals(totalExpectedSplitBundles, splitChildBundles.getLeft().getBundles().size());
    // (3) split in 3: second bundle from above split bundles
    NamespaceBundle testChildBundl2 = bundles2.getBundles().get(1);
    Pair<NamespaceBundles, List<NamespaceBundle>> splitChildBundles2 = splitBundlesUtilFactory(utilityFactory, nsname, bundles2, testChildBundl2, 3);
    // existing_no_bundles(4) +
    // additional_new_split_bundle(3) -
    // parent_target_bundle(1)
    totalExpectedSplitBundles = bundles2.getBundles().size() + 3 - 1;
    validateSplitBundlesRange(testChildBundl2, splitChildBundles2.getRight());
    assertEquals(totalExpectedSplitBundles, splitChildBundles2.getLeft().getBundles().size());
}
Also used : NamespaceBundle(org.apache.pulsar.common.naming.NamespaceBundle) NamespaceName(org.apache.pulsar.common.naming.NamespaceName) NamespaceBundles(org.apache.pulsar.common.naming.NamespaceBundles) NamespaceBundleFactory(org.apache.pulsar.common.naming.NamespaceBundleFactory) ArrayList(java.util.ArrayList) List(java.util.List) TopicName(org.apache.pulsar.common.naming.TopicName) Test(org.testng.annotations.Test)

Example 9 with NamespaceBundleFactory

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

the class AntiAffinityNamespaceGroupTest method setup.

@BeforeMethod
void setup() throws Exception {
    // Start local bookkeeper ensemble
    bkEnsemble = new LocalBookkeeperEnsemble(3, ZOOKEEPER_PORT, PortManager.nextFreePort());
    bkEnsemble.start();
    // Start broker 1
    ServiceConfiguration config1 = new ServiceConfiguration();
    config1.setLoadManagerClassName(ModularLoadManagerImpl.class.getName());
    config1.setClusterName("use");
    config1.setWebServicePort(PRIMARY_BROKER_WEBSERVICE_PORT);
    config1.setZookeeperServers("127.0.0.1" + ":" + ZOOKEEPER_PORT);
    config1.setBrokerServicePort(PRIMARY_BROKER_PORT);
    config1.setFailureDomainsEnabled(true);
    config1.setLoadBalancerEnabled(true);
    config1.setAdvertisedAddress("localhost");
    createCluster(bkEnsemble.getZkClient(), config1);
    pulsar1 = new PulsarService(config1);
    pulsar1.start();
    primaryHost = String.format("%s:%d", "localhost", PRIMARY_BROKER_WEBSERVICE_PORT);
    url1 = new URL("http://127.0.0.1" + ":" + PRIMARY_BROKER_WEBSERVICE_PORT);
    admin1 = new PulsarAdmin(url1, (Authentication) null);
    // Start broker 2
    ServiceConfiguration config2 = new ServiceConfiguration();
    config2.setLoadManagerClassName(ModularLoadManagerImpl.class.getName());
    config2.setClusterName("use");
    config2.setWebServicePort(SECONDARY_BROKER_WEBSERVICE_PORT);
    config2.setZookeeperServers("127.0.0.1" + ":" + ZOOKEEPER_PORT);
    config2.setBrokerServicePort(SECONDARY_BROKER_PORT);
    config2.setFailureDomainsEnabled(true);
    pulsar2 = new PulsarService(config2);
    secondaryHost = String.format("%s:%d", "localhost", SECONDARY_BROKER_WEBSERVICE_PORT);
    pulsar2.start();
    url2 = new URL("http://127.0.0.1" + ":" + SECONDARY_BROKER_WEBSERVICE_PORT);
    admin2 = new PulsarAdmin(url2, (Authentication) null);
    primaryLoadManager = (ModularLoadManagerImpl) getField(pulsar1.getLoadManager().get(), "loadManager");
    secondaryLoadManager = (ModularLoadManagerImpl) getField(pulsar2.getLoadManager().get(), "loadManager");
    nsFactory = new NamespaceBundleFactory(pulsar1, Hashing.crc32());
    Thread.sleep(100);
}
Also used : ServiceConfiguration(org.apache.pulsar.broker.ServiceConfiguration) PulsarService(org.apache.pulsar.broker.PulsarService) PulsarAdmin(org.apache.pulsar.client.admin.PulsarAdmin) Authentication(org.apache.pulsar.client.api.Authentication) NamespaceBundleFactory(org.apache.pulsar.common.naming.NamespaceBundleFactory) LocalBookkeeperEnsemble(org.apache.pulsar.zookeeper.LocalBookkeeperEnsemble) ModularLoadManagerImpl(org.apache.pulsar.broker.loadbalance.impl.ModularLoadManagerImpl) URL(java.net.URL) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 10 with NamespaceBundleFactory

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

the class ModularLoadManagerImplTest method setup.

@BeforeMethod
void setup() throws Exception {
    // Start local bookkeeper ensemble
    bkEnsemble = new LocalBookkeeperEnsemble(3, ZOOKEEPER_PORT, PortManager.nextFreePort());
    bkEnsemble.start();
    // Start broker 1
    ServiceConfiguration config1 = new ServiceConfiguration();
    config1.setLoadManagerClassName(ModularLoadManagerImpl.class.getName());
    config1.setClusterName("use");
    config1.setWebServicePort(PRIMARY_BROKER_WEBSERVICE_PORT);
    config1.setZookeeperServers("127.0.0.1" + ":" + ZOOKEEPER_PORT);
    config1.setBrokerServicePort(PRIMARY_BROKER_PORT);
    pulsar1 = new PulsarService(config1);
    pulsar1.start();
    primaryHost = String.format("%s:%d", InetAddress.getLocalHost().getHostName(), PRIMARY_BROKER_WEBSERVICE_PORT);
    url1 = new URL("http://127.0.0.1" + ":" + PRIMARY_BROKER_WEBSERVICE_PORT);
    admin1 = new PulsarAdmin(url1, (Authentication) null);
    // Start broker 2
    ServiceConfiguration config2 = new ServiceConfiguration();
    config2.setLoadManagerClassName(ModularLoadManagerImpl.class.getName());
    config2.setClusterName("use");
    config2.setWebServicePort(SECONDARY_BROKER_WEBSERVICE_PORT);
    config2.setZookeeperServers("127.0.0.1" + ":" + ZOOKEEPER_PORT);
    config2.setBrokerServicePort(SECONDARY_BROKER_PORT);
    pulsar2 = new PulsarService(config2);
    secondaryHost = String.format("%s:%d", InetAddress.getLocalHost().getHostName(), SECONDARY_BROKER_WEBSERVICE_PORT);
    pulsar2.start();
    url2 = new URL("http://127.0.0.1" + ":" + SECONDARY_BROKER_WEBSERVICE_PORT);
    admin2 = new PulsarAdmin(url2, (Authentication) null);
    primaryLoadManager = (ModularLoadManagerImpl) getField(pulsar1.getLoadManager().get(), "loadManager");
    secondaryLoadManager = (ModularLoadManagerImpl) getField(pulsar2.getLoadManager().get(), "loadManager");
    nsFactory = new NamespaceBundleFactory(pulsar1, Hashing.crc32());
    Thread.sleep(100);
}
Also used : ServiceConfiguration(org.apache.pulsar.broker.ServiceConfiguration) PulsarService(org.apache.pulsar.broker.PulsarService) PulsarAdmin(org.apache.pulsar.client.admin.PulsarAdmin) Authentication(org.apache.pulsar.client.api.Authentication) NamespaceBundleFactory(org.apache.pulsar.common.naming.NamespaceBundleFactory) LocalBookkeeperEnsemble(org.apache.pulsar.zookeeper.LocalBookkeeperEnsemble) ModularLoadManagerImpl(org.apache.pulsar.broker.loadbalance.impl.ModularLoadManagerImpl) URL(java.net.URL) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

NamespaceBundleFactory (org.apache.pulsar.common.naming.NamespaceBundleFactory)10 BeforeMethod (org.testng.annotations.BeforeMethod)5 List (java.util.List)4 PulsarService (org.apache.pulsar.broker.PulsarService)4 NamespaceBundle (org.apache.pulsar.common.naming.NamespaceBundle)4 NamespaceBundles (org.apache.pulsar.common.naming.NamespaceBundles)4 NamespaceName (org.apache.pulsar.common.naming.NamespaceName)4 TopicName (org.apache.pulsar.common.naming.TopicName)4 Test (org.testng.annotations.Test)4 ServiceConfiguration (org.apache.pulsar.broker.ServiceConfiguration)3 PulsarAdmin (org.apache.pulsar.client.admin.PulsarAdmin)3 Field (java.lang.reflect.Field)2 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 ModularLoadManagerImpl (org.apache.pulsar.broker.loadbalance.impl.ModularLoadManagerImpl)2 Authentication (org.apache.pulsar.client.api.Authentication)2 LocalPolicies (org.apache.pulsar.common.policies.data.LocalPolicies)2 Policies (org.apache.pulsar.common.policies.data.Policies)2 LocalBookkeeperEnsemble (org.apache.pulsar.zookeeper.LocalBookkeeperEnsemble)2