Search in sources :

Example 1 with ServiceUnitId

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

the class SimpleLoadManagerImpl method getAvailableBrokers.

private Map<Long, Set<ResourceUnit>> getAvailableBrokers(ServiceUnitId serviceUnitId) throws Exception {
    Map<Long, Set<ResourceUnit>> availableBrokers = sortedRankings.get();
    if (availableBrokers.isEmpty()) {
        // Create a map with all available brokers with no load information
        Set<String> activeBrokers = availableActiveBrokers.get(LOADBALANCE_BROKERS_ROOT);
        List<String> brokersToShuffle = new ArrayList<>(activeBrokers);
        Collections.shuffle(brokersToShuffle);
        activeBrokers = new HashSet<>(brokersToShuffle);
        availableBrokers = Maps.newTreeMap();
        for (String broker : activeBrokers) {
            ResourceUnit resourceUnit = new SimpleResourceUnit(String.format("http://%s", broker), new PulsarResourceDescription());
            availableBrokers.computeIfAbsent(0L, key -> Sets.newTreeSet()).add(resourceUnit);
        }
        log.info("Choosing at random from broker list: [{}]", availableBrokers.values());
    }
    return availableBrokers;
}
Also used : ResourceUnit(com.yahoo.pulsar.broker.loadbalance.ResourceUnit) CreateMode(org.apache.zookeeper.CreateMode) LoadingCache(com.google.common.cache.LoadingCache) Ids(org.apache.zookeeper.ZooDefs.Ids) URL(java.net.URL) LoggerFactory(org.slf4j.LoggerFactory) NamespaceBundleStats(com.yahoo.pulsar.common.policies.data.loadbalancer.NamespaceBundleStats) Stat(org.apache.zookeeper.data.Stat) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) BrokerHostUsage(com.yahoo.pulsar.broker.loadbalance.BrokerHostUsage) PlacementStrategy(com.yahoo.pulsar.broker.loadbalance.PlacementStrategy) TreeMultimap(com.google.common.collect.TreeMultimap) Map(java.util.Map) ZooKeeperCacheListener(com.yahoo.pulsar.zookeeper.ZooKeeperCacheListener) PulsarService(com.yahoo.pulsar.broker.PulsarService) Set(java.util.Set) ZooKeeperChildrenCache(com.yahoo.pulsar.zookeeper.ZooKeeperChildrenCache) ResourceUnitRanking(com.yahoo.pulsar.common.policies.data.loadbalancer.ResourceUnitRanking) Executors(java.util.concurrent.Executors) ZkUtils(org.apache.bookkeeper.util.ZkUtils) Sets(com.google.common.collect.Sets) ObjectMapperFactory(com.yahoo.pulsar.common.util.ObjectMapperFactory) CacheLoader(com.google.common.cache.CacheLoader) Metrics(com.yahoo.pulsar.broker.stats.Metrics) List(java.util.List) AdminResource(com.yahoo.pulsar.broker.admin.AdminResource) ResourceUnit(com.yahoo.pulsar.broker.loadbalance.ResourceUnit) SystemResourceUsage(com.yahoo.pulsar.common.policies.data.loadbalancer.SystemResourceUsage) CacheBuilder(com.google.common.cache.CacheBuilder) LoadManager(com.yahoo.pulsar.broker.loadbalance.LoadManager) LocalDateTime(java.time.LocalDateTime) HashMap(java.util.HashMap) Multimap(com.google.common.collect.Multimap) AtomicReference(java.util.concurrent.atomic.AtomicReference) StringUtils.isNotEmpty(org.apache.commons.lang3.StringUtils.isNotEmpty) ArrayList(java.util.ArrayList) ResourceType(com.yahoo.pulsar.common.policies.data.loadbalancer.SystemResourceUsage.ResourceType) HashSet(java.util.HashSet) Lists(com.google.common.collect.Lists) LoadReport(com.yahoo.pulsar.common.policies.data.loadbalancer.LoadReport) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Charsets(com.google.common.base.Charsets) RemovalNotification(com.google.common.cache.RemovalNotification) ServiceUnitId(com.yahoo.pulsar.common.naming.ServiceUnitId) Logger(org.slf4j.Logger) ZooKeeperDataCache(com.yahoo.pulsar.zookeeper.ZooKeeperDataCache) Iterator(java.util.Iterator) KeeperException(org.apache.zookeeper.KeeperException) MalformedURLException(java.net.MalformedURLException) SystemUtils(org.apache.commons.lang3.SystemUtils) PulsarAdmin(com.yahoo.pulsar.client.admin.PulsarAdmin) IOException(java.io.IOException) NamespaceName(com.yahoo.pulsar.common.naming.NamespaceName) Maps(com.google.common.collect.Maps) TimeUnit(java.util.concurrent.TimeUnit) ServiceConfiguration(com.yahoo.pulsar.broker.ServiceConfiguration) TreeMap(java.util.TreeMap) RemovalListener(com.google.common.cache.RemovalListener) ResourceQuota(com.yahoo.pulsar.common.policies.data.ResourceQuota) PulsarServerException(com.yahoo.pulsar.broker.PulsarServerException) Collections(java.util.Collections) Set(java.util.Set) HashSet(java.util.HashSet) ArrayList(java.util.ArrayList)

Aggregations

Charsets (com.google.common.base.Charsets)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 CacheBuilder (com.google.common.cache.CacheBuilder)1 CacheLoader (com.google.common.cache.CacheLoader)1 LoadingCache (com.google.common.cache.LoadingCache)1 RemovalListener (com.google.common.cache.RemovalListener)1 RemovalNotification (com.google.common.cache.RemovalNotification)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 Multimap (com.google.common.collect.Multimap)1 Sets (com.google.common.collect.Sets)1 TreeMultimap (com.google.common.collect.TreeMultimap)1 PulsarServerException (com.yahoo.pulsar.broker.PulsarServerException)1 PulsarService (com.yahoo.pulsar.broker.PulsarService)1 ServiceConfiguration (com.yahoo.pulsar.broker.ServiceConfiguration)1 AdminResource (com.yahoo.pulsar.broker.admin.AdminResource)1 BrokerHostUsage (com.yahoo.pulsar.broker.loadbalance.BrokerHostUsage)1 LoadManager (com.yahoo.pulsar.broker.loadbalance.LoadManager)1 PlacementStrategy (com.yahoo.pulsar.broker.loadbalance.PlacementStrategy)1 ResourceUnit (com.yahoo.pulsar.broker.loadbalance.ResourceUnit)1