Search in sources :

Example 1 with LocalZooKeeperCache

use of org.apache.pulsar.zookeeper.LocalZooKeeperCache in project incubator-pulsar by apache.

the class PulsarService method startZkCacheService.

private void startZkCacheService() throws PulsarServerException {
    LOG.info("starting configuration cache service");
    this.localZkCache = new LocalZooKeeperCache(getZkClient(), getOrderedExecutor(), this.cacheExecutor);
    this.globalZkCache = new GlobalZooKeeperCache(getZooKeeperClientFactory(), (int) config.getZooKeeperSessionTimeoutMillis(), config.getGlobalZookeeperServers(), getOrderedExecutor(), this.cacheExecutor);
    try {
        this.globalZkCache.start();
    } catch (IOException e) {
        throw new PulsarServerException(e);
    }
    this.configurationCacheService = new ConfigurationCacheService(getGlobalZkCache(), this.config.getClusterName());
    this.localZkCacheService = new LocalZooKeeperCacheService(getLocalZkCache(), this.configurationCacheService);
}
Also used : GlobalZooKeeperCache(org.apache.pulsar.zookeeper.GlobalZooKeeperCache) LocalZooKeeperCache(org.apache.pulsar.zookeeper.LocalZooKeeperCache) ConfigurationCacheService(org.apache.pulsar.broker.cache.ConfigurationCacheService) IOException(java.io.IOException) LocalZooKeeperCacheService(org.apache.pulsar.broker.cache.LocalZooKeeperCacheService)

Example 2 with LocalZooKeeperCache

use of org.apache.pulsar.zookeeper.LocalZooKeeperCache in project incubator-pulsar by apache.

the class LoadBalancerTest method testGetLeastLoadedBasic.

@Test(enabled = false)
public void testGetLeastLoadedBasic() throws Exception {
    LocalZooKeeperCache mockCache = mock(LocalZooKeeperCache.class);
    Set<String> activeBrokers = Sets.newHashSet("prod1-broker1.messaging.use.example.com:8080", "prod1-broker2.messaging.use.example.com:8080", "prod1-broker3.messaging.use.example.com:8080");
    when(mockCache.getChildren(SimpleLoadManagerImpl.LOADBALANCE_BROKERS_ROOT)).thenReturn(activeBrokers);
    Field zkCacheField = PulsarService.class.getDeclaredField("localZkCache");
    zkCacheField.setAccessible(true);
    LocalZooKeeperCache originalLZK1 = (LocalZooKeeperCache) zkCacheField.get(pulsarServices[0]);
    LocalZooKeeperCache originalLZK2 = (LocalZooKeeperCache) zkCacheField.get(pulsarServices[1]);
    zkCacheField.set(pulsarServices[0], mockCache);
    zkCacheField.set(pulsarServices[1], mockCache);
    LoadManager loadManager = new SimpleLoadManagerImpl(pulsarServices[0]);
    // TODO move to its own test
    PulsarResourceDescription rd = new PulsarResourceDescription();
    rd.put("memory", new ResourceUsage(1024, 4096));
    rd.put("cpu", new ResourceUsage(10, 100));
    rd.put("bandwidthIn", new ResourceUsage(250 * 1024, 1024 * 1024));
    rd.put("bandwidthOut", new ResourceUsage(550 * 1024, 1024 * 1024));
    ResourceUnit ru1 = new SimpleResourceUnit("http://prod1-broker1.messaging.use.example.com:8080", rd);
    Set<ResourceUnit> rus = new HashSet<ResourceUnit>();
    rus.add(ru1);
    LoadRanker lr = new ResourceAvailabilityRanker();
    AtomicReference<Map<Long, Set<ResourceUnit>>> sortedRankingsInstance = new AtomicReference<>(Maps.newTreeMap());
    sortedRankingsInstance.get().put(lr.getRank(rd), rus);
    Field sortedRankings = SimpleLoadManagerImpl.class.getDeclaredField("sortedRankings");
    sortedRankings.setAccessible(true);
    sortedRankings.set(loadManager, sortedRankingsInstance);
    ResourceUnit found = ((SimpleLoadManagerImpl) loadManager).getLeastLoaded(NamespaceName.get("pulsar/use/primary-ns.10")).get();
    assertEquals("http://prod1-broker1.messaging.use.example.com:8080", found.getResourceId());
    zkCacheField.set(pulsarServices[0], originalLZK1);
    zkCacheField.set(pulsarServices[1], originalLZK2);
}
Also used : PulsarResourceDescription(org.apache.pulsar.broker.loadbalance.impl.PulsarResourceDescription) LocalZooKeeperCache(org.apache.pulsar.zookeeper.LocalZooKeeperCache) SystemResourceUsage(org.apache.pulsar.policies.data.loadbalancer.SystemResourceUsage) ResourceUsage(org.apache.pulsar.policies.data.loadbalancer.ResourceUsage) ResourceAvailabilityRanker(org.apache.pulsar.broker.loadbalance.impl.ResourceAvailabilityRanker) AtomicReference(java.util.concurrent.atomic.AtomicReference) SimpleResourceUnit(org.apache.pulsar.broker.loadbalance.impl.SimpleResourceUnit) Field(java.lang.reflect.Field) SimpleResourceUnit(org.apache.pulsar.broker.loadbalance.impl.SimpleResourceUnit) SimpleLoadManagerImpl(org.apache.pulsar.broker.loadbalance.impl.SimpleLoadManagerImpl) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 3 with LocalZooKeeperCache

use of org.apache.pulsar.zookeeper.LocalZooKeeperCache in project incubator-pulsar by apache.

the class SimpleLoadManagerImplTest method testPrimarySecondary.

@Test(enabled = false)
public void testPrimarySecondary() throws Exception {
    createNamespacePolicies(pulsar1);
    LocalZooKeeperCache mockCache = mock(LocalZooKeeperCache.class);
    ZooKeeperChildrenCache zooKeeperChildrenCache = mock(ZooKeeperChildrenCache.class);
    Set<String> activeBrokers = Sets.newHashSet("prod2-broker7.messaging.use.example.com:8080", "prod2-broker8.messaging.use.example.com:8080", "prod2-broker9.messaging.use.example.com:8080");
    when(mockCache.getChildren(SimpleLoadManagerImpl.LOADBALANCE_BROKERS_ROOT)).thenReturn(activeBrokers);
    when(zooKeeperChildrenCache.get()).thenReturn(activeBrokers);
    when(zooKeeperChildrenCache.get(SimpleLoadManagerImpl.LOADBALANCE_BROKERS_ROOT)).thenReturn(activeBrokers);
    Field zkCacheField = PulsarService.class.getDeclaredField("localZkCache");
    zkCacheField.setAccessible(true);
    LocalZooKeeperCache originalLZK1 = (LocalZooKeeperCache) zkCacheField.get(pulsar1);
    LocalZooKeeperCache originalLZK2 = (LocalZooKeeperCache) zkCacheField.get(pulsar2);
    log.info("lzk are {} 2: {}", originalLZK1.getChildren(SimpleLoadManagerImpl.LOADBALANCE_BROKERS_ROOT), originalLZK2.getChildren(SimpleLoadManagerImpl.LOADBALANCE_BROKERS_ROOT));
    zkCacheField.set(pulsar1, mockCache);
    LocalZooKeeperCache newZk = (LocalZooKeeperCache) pulsar1.getLocalZkCache();
    log.info("lzk mocked are {}", newZk.getChildren(SimpleLoadManagerImpl.LOADBALANCE_BROKERS_ROOT));
    ZooKeeperChildrenCache availableActiveBrokers = new ZooKeeperChildrenCache(pulsar1.getLocalZkCache(), SimpleLoadManagerImpl.LOADBALANCE_BROKERS_ROOT);
    log.info("lzk mocked active brokers are {}", availableActiveBrokers.get(SimpleLoadManagerImpl.LOADBALANCE_BROKERS_ROOT));
    LoadManager loadManager = new SimpleLoadManagerImpl(pulsar1);
    PulsarResourceDescription rd = new PulsarResourceDescription();
    rd.put("memory", new ResourceUsage(1024, 4096));
    rd.put("cpu", new ResourceUsage(10, 100));
    rd.put("bandwidthIn", new ResourceUsage(250 * 1024, 1024 * 1024));
    rd.put("bandwidthOut", new ResourceUsage(550 * 1024, 1024 * 1024));
    ResourceUnit ru1 = new SimpleResourceUnit("http://prod2-broker7.messaging.usw.example.com:8080", rd);
    Set<ResourceUnit> rus = new HashSet<ResourceUnit>();
    rus.add(ru1);
    LoadRanker lr = new ResourceAvailabilityRanker();
    AtomicReference<Map<Long, Set<ResourceUnit>>> sortedRankingsInstance = new AtomicReference<>(Maps.newTreeMap());
    sortedRankingsInstance.get().put(lr.getRank(rd), rus);
    Field sortedRankings = SimpleLoadManagerImpl.class.getDeclaredField("sortedRankings");
    sortedRankings.setAccessible(true);
    sortedRankings.set(loadManager, sortedRankingsInstance);
    ResourceUnit found = ((SimpleLoadManagerImpl) loadManager).getLeastLoaded(NamespaceName.get("pulsar/use/primary-ns.10")).get();
    assertEquals(found.getResourceId(), ru1.getResourceId());
    zkCacheField.set(pulsar1, originalLZK1);
}
Also used : PulsarResourceDescription(org.apache.pulsar.broker.loadbalance.impl.PulsarResourceDescription) LocalZooKeeperCache(org.apache.pulsar.zookeeper.LocalZooKeeperCache) SystemResourceUsage(org.apache.pulsar.policies.data.loadbalancer.SystemResourceUsage) ResourceUsage(org.apache.pulsar.policies.data.loadbalancer.ResourceUsage) ResourceAvailabilityRanker(org.apache.pulsar.broker.loadbalance.impl.ResourceAvailabilityRanker) AtomicReference(java.util.concurrent.atomic.AtomicReference) SimpleResourceUnit(org.apache.pulsar.broker.loadbalance.impl.SimpleResourceUnit) Field(java.lang.reflect.Field) SimpleResourceUnit(org.apache.pulsar.broker.loadbalance.impl.SimpleResourceUnit) SimpleLoadManagerImpl(org.apache.pulsar.broker.loadbalance.impl.SimpleLoadManagerImpl) ZooKeeperChildrenCache(org.apache.pulsar.zookeeper.ZooKeeperChildrenCache) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 4 with LocalZooKeeperCache

use of org.apache.pulsar.zookeeper.LocalZooKeeperCache in project incubator-pulsar by apache.

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 = OrderedScheduler.newSchedulerBuilder().numThreads(1).name("test").build();
    scheduledExecutor = Executors.newScheduledThreadPool(2);
    zkCache = new LocalZooKeeperCache(MockZooKeeper.newInstance(), executor, scheduledExecutor);
    localCache = spy(new LocalZooKeeperCacheService(zkCache, null));
    ZooKeeperDataCache<LocalPolicies> poilciesCache = mock(ZooKeeperDataCache.class);
    when(pulsar.getLocalZkCacheService()).thenReturn(localCache);
    when(localCache.policiesCache()).thenReturn(poilciesCache);
    doNothing().when(poilciesCache).registerListener(any());
    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(org.apache.pulsar.broker.PulsarService) ServiceConfiguration(org.apache.pulsar.broker.ServiceConfiguration) LocalZooKeeperCache(org.apache.pulsar.zookeeper.LocalZooKeeperCache) LocalPolicies(org.apache.pulsar.common.policies.data.LocalPolicies) NamespaceBundleFactory(org.apache.pulsar.common.naming.NamespaceBundleFactory) BrokerService(org.apache.pulsar.broker.service.BrokerService) LocalZooKeeperCacheService(org.apache.pulsar.broker.cache.LocalZooKeeperCacheService) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 5 with LocalZooKeeperCache

use of org.apache.pulsar.zookeeper.LocalZooKeeperCache 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)

Aggregations

LocalZooKeeperCache (org.apache.pulsar.zookeeper.LocalZooKeeperCache)5 Field (java.lang.reflect.Field)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 PulsarService (org.apache.pulsar.broker.PulsarService)2 LocalZooKeeperCacheService (org.apache.pulsar.broker.cache.LocalZooKeeperCacheService)2 PulsarResourceDescription (org.apache.pulsar.broker.loadbalance.impl.PulsarResourceDescription)2 ResourceAvailabilityRanker (org.apache.pulsar.broker.loadbalance.impl.ResourceAvailabilityRanker)2 SimpleLoadManagerImpl (org.apache.pulsar.broker.loadbalance.impl.SimpleLoadManagerImpl)2 SimpleResourceUnit (org.apache.pulsar.broker.loadbalance.impl.SimpleResourceUnit)2 NamespaceBundleFactory (org.apache.pulsar.common.naming.NamespaceBundleFactory)2 LocalPolicies (org.apache.pulsar.common.policies.data.LocalPolicies)2 ResourceUsage (org.apache.pulsar.policies.data.loadbalancer.ResourceUsage)2 SystemResourceUsage (org.apache.pulsar.policies.data.loadbalancer.SystemResourceUsage)2 BeforeMethod (org.testng.annotations.BeforeMethod)2 Test (org.testng.annotations.Test)2 IOException (java.io.IOException)1 TreeMap (java.util.TreeMap)1