Search in sources :

Example 1 with NamespaceBundleFactory

use of com.yahoo.pulsar.common.naming.NamespaceBundleFactory in project pulsar by yahoo.

the class AdminApiTest method setup.

@BeforeMethod
@Override
public void setup() throws Exception {
    conf.setLoadBalancerEnabled(true);
    super.internalSetup();
    bundleFactory = new NamespaceBundleFactory(pulsar, Hashing.crc32());
    // create otherbroker to test redirect on calls that need
    // namespace ownership
    ServiceConfiguration otherconfig = new ServiceConfiguration();
    otherconfig.setBrokerServicePort(SECONDARY_BROKER_PORT);
    otherconfig.setWebServicePort(SECONDARY_BROKER_WEBSERVICE_PORT);
    otherconfig.setLoadBalancerEnabled(false);
    otherconfig.setClusterName("test");
    otherPulsar = startBroker(otherconfig);
    otheradmin = new PulsarAdmin(new URL("http://127.0.0.1" + ":" + SECONDARY_BROKER_WEBSERVICE_PORT), (Authentication) null);
    // 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(com.yahoo.pulsar.common.policies.data.ClusterData) ServiceConfiguration(com.yahoo.pulsar.broker.ServiceConfiguration) PulsarAdmin(com.yahoo.pulsar.client.admin.PulsarAdmin) PropertyAdmin(com.yahoo.pulsar.common.policies.data.PropertyAdmin) Authentication(com.yahoo.pulsar.client.api.Authentication) NamespaceBundleFactory(com.yahoo.pulsar.common.naming.NamespaceBundleFactory) URL(java.net.URL) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 2 with NamespaceBundleFactory

use of com.yahoo.pulsar.common.naming.NamespaceBundleFactory in project pulsar by yahoo.

the class OwnershipCacheTest method setup.

@BeforeMethod
public void setup() throws Exception {
    final int port = 8080;
    selfBrokerUrl = "tcp://localhost:" + port;
    pulsar = mock(PulsarService.class);
    config = mock(ServiceConfiguration.class);
    executor = new OrderedSafeExecutor(1, "test");
    zkCache = new LocalZooKeeperCache(MockZooKeeper.newInstance(), executor);
    localCache = new LocalZooKeeperCacheService(zkCache, null);
    bundleFactory = new NamespaceBundleFactory(pulsar, Hashing.crc32());
    nsService = mock(NamespaceService.class);
    brokerService = mock(BrokerService.class);
    doReturn(CompletableFuture.completedFuture(1)).when(brokerService).unloadServiceUnit(anyObject());
    doReturn(zkCache).when(pulsar).getLocalZkCache();
    doReturn(localCache).when(pulsar).getLocalZkCacheService();
    doReturn(config).when(pulsar).getConfiguration();
    doReturn(nsService).when(pulsar).getNamespaceService();
    doReturn(port).when(config).getBrokerServicePort();
    doReturn(brokerService).when(pulsar).getBrokerService();
    doReturn(webAddress(config)).when(pulsar).getWebServiceAddress();
    doReturn(selfBrokerUrl).when(pulsar).getBrokerServiceUrl();
}
Also used : PulsarService(com.yahoo.pulsar.broker.PulsarService) ServiceConfiguration(com.yahoo.pulsar.broker.ServiceConfiguration) LocalZooKeeperCache(com.yahoo.pulsar.zookeeper.LocalZooKeeperCache) OrderedSafeExecutor(org.apache.bookkeeper.util.OrderedSafeExecutor) NamespaceBundleFactory(com.yahoo.pulsar.common.naming.NamespaceBundleFactory) BrokerService(com.yahoo.pulsar.broker.service.BrokerService) LocalZooKeeperCacheService(com.yahoo.pulsar.broker.cache.LocalZooKeeperCacheService) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 3 with NamespaceBundleFactory

use of com.yahoo.pulsar.common.naming.NamespaceBundleFactory in project pulsar by yahoo.

the class ResourceQuotaCacheTest method setup.

@BeforeMethod
public void setup() throws Exception {
    pulsar = mock(PulsarService.class);
    OrderedSafeExecutor executor = new OrderedSafeExecutor(1, "test");
    zkCache = new LocalZooKeeperCache(MockZooKeeper.newInstance(), executor);
    localCache = new LocalZooKeeperCacheService(zkCache, null);
    bundleFactory = new NamespaceBundleFactory(pulsar, Hashing.crc32());
    doReturn(zkCache).when(pulsar).getLocalZkCache();
    doReturn(localCache).when(pulsar).getLocalZkCacheService();
}
Also used : PulsarService(com.yahoo.pulsar.broker.PulsarService) LocalZooKeeperCache(com.yahoo.pulsar.zookeeper.LocalZooKeeperCache) OrderedSafeExecutor(org.apache.bookkeeper.util.OrderedSafeExecutor) NamespaceBundleFactory(com.yahoo.pulsar.common.naming.NamespaceBundleFactory) LocalZooKeeperCacheService(com.yahoo.pulsar.broker.cache.LocalZooKeeperCacheService) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 4 with NamespaceBundleFactory

use of com.yahoo.pulsar.common.naming.NamespaceBundleFactory in project pulsar by yahoo.

the class NamespaceServiceTest method testSplitAndOwnBundles.

@Test
public void testSplitAndOwnBundles() throws Exception {
    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);
    NamespaceService namespaceService = pulsar.getNamespaceService();
    NamespaceName nsname = new NamespaceName("pulsar/global/ns1");
    DestinationName dn = DestinationName.get("persistent://pulsar/global/ns1/topic-1");
    NamespaceBundles bundles = namespaceService.getNamespaceBundleFactory().getBundles(nsname);
    NamespaceBundle originalBundle = bundles.findBundle(dn);
    // Split bundle and take ownership of split bundles
    CompletableFuture<Void> result = namespaceService.splitAndOwnBundle(originalBundle);
    try {
        result.get();
    } catch (Exception e) {
        // make sure: no failure
        fail("split bundle faild", e);
    }
    NamespaceBundleFactory bundleFactory = this.pulsar.getNamespaceService().getNamespaceBundleFactory();
    NamespaceBundles updatedNsBundles = bundleFactory.getBundles(nsname);
    // new updated bundles shouldn't be null
    assertNotNull(updatedNsBundles);
    List<NamespaceBundle> bundleList = updatedNsBundles.getBundles();
    assertNotNull(bundles);
    NamespaceBundleFactory utilityFactory = NamespaceBundleFactory.createFactory(Hashing.crc32());
    // (1) validate bundleFactory-cache has newly split bundles and removed old parent bundle
    Pair<NamespaceBundles, List<NamespaceBundle>> splitBundles = splitBundles(utilityFactory, nsname, bundles, originalBundle);
    assertNotNull(splitBundles);
    Set<NamespaceBundle> splitBundleSet = new HashSet<>(splitBundles.getRight());
    splitBundleSet.removeAll(bundleList);
    assertTrue(splitBundleSet.isEmpty());
    // (2) validate LocalZookeeper policies updated with newly created split
    // bundles
    String path = joinPath(LOCAL_POLICIES_ROOT, nsname.toString());
    byte[] content = this.pulsar.getLocalZkCache().getZooKeeper().getData(path, null, new Stat());
    Policies policies = ObjectMapperFactory.getThreadLocal().readValue(content, Policies.class);
    NamespaceBundles localZkBundles = bundleFactory.getBundles(nsname, policies.bundles);
    assertTrue(updatedNsBundles.equals(localZkBundles));
    log.info("Policies: {}", policies);
    // (3) validate ownership of new split bundles by local owner
    bundleList.stream().forEach(b -> {
        try {
            byte[] data = this.pulsar.getLocalZkCache().getZooKeeper().getData(ServiceUnitZkUtils.path(b), null, new Stat());
            NamespaceEphemeralData node = ObjectMapperFactory.getThreadLocal().readValue(data, NamespaceEphemeralData.class);
            Assert.assertEquals(node.getNativeUrl(), this.pulsar.getBrokerServiceUrl());
        } catch (Exception e) {
            fail("failed to setup ownership", e);
        }
    });
}
Also used : NamespaceBundle(com.yahoo.pulsar.common.naming.NamespaceBundle) Policies(com.yahoo.pulsar.common.policies.data.Policies) NamespaceBundles(com.yahoo.pulsar.common.naming.NamespaceBundles) Field(java.lang.reflect.Field) NamespaceName(com.yahoo.pulsar.common.naming.NamespaceName) Stat(org.apache.zookeeper.data.Stat) DestinationName(com.yahoo.pulsar.common.naming.DestinationName) NamespaceBundleFactory(com.yahoo.pulsar.common.naming.NamespaceBundleFactory) List(java.util.List) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

NamespaceBundleFactory (com.yahoo.pulsar.common.naming.NamespaceBundleFactory)4 BeforeMethod (org.testng.annotations.BeforeMethod)3 PulsarService (com.yahoo.pulsar.broker.PulsarService)2 ServiceConfiguration (com.yahoo.pulsar.broker.ServiceConfiguration)2 LocalZooKeeperCacheService (com.yahoo.pulsar.broker.cache.LocalZooKeeperCacheService)2 LocalZooKeeperCache (com.yahoo.pulsar.zookeeper.LocalZooKeeperCache)2 OrderedSafeExecutor (org.apache.bookkeeper.util.OrderedSafeExecutor)2 BrokerService (com.yahoo.pulsar.broker.service.BrokerService)1 PulsarAdmin (com.yahoo.pulsar.client.admin.PulsarAdmin)1 Authentication (com.yahoo.pulsar.client.api.Authentication)1 DestinationName (com.yahoo.pulsar.common.naming.DestinationName)1 NamespaceBundle (com.yahoo.pulsar.common.naming.NamespaceBundle)1 NamespaceBundles (com.yahoo.pulsar.common.naming.NamespaceBundles)1 NamespaceName (com.yahoo.pulsar.common.naming.NamespaceName)1 ClusterData (com.yahoo.pulsar.common.policies.data.ClusterData)1 Policies (com.yahoo.pulsar.common.policies.data.Policies)1 PropertyAdmin (com.yahoo.pulsar.common.policies.data.PropertyAdmin)1 Field (java.lang.reflect.Field)1 URL (java.net.URL)1 HashSet (java.util.HashSet)1