use of org.apache.pulsar.policies.data.loadbalancer.TimeAverageBrokerData in project pulsar by yahoo.
the class ModularLoadManagerStrategyTest method initBrokerData.
private BrokerData initBrokerData() {
LocalBrokerData localBrokerData = new LocalBrokerData();
localBrokerData.setCpu(new ResourceUsage());
localBrokerData.setMemory(new ResourceUsage());
localBrokerData.setBandwidthIn(new ResourceUsage());
localBrokerData.setBandwidthOut(new ResourceUsage());
BrokerData brokerData = new BrokerData(localBrokerData);
TimeAverageBrokerData timeAverageBrokerData = new TimeAverageBrokerData();
brokerData.setTimeAverageData(timeAverageBrokerData);
return brokerData;
}
use of org.apache.pulsar.policies.data.loadbalancer.TimeAverageBrokerData in project pulsar by yahoo.
the class TimeAverageBrokerDataTest method testIllegalArg.
@Test
public void testIllegalArg() {
TimeAverageBrokerData timeAverageBrokerData = new TimeAverageBrokerData();
assertThrows(NullPointerException.class, () -> timeAverageBrokerData.reset(null, null, null));
}
use of org.apache.pulsar.policies.data.loadbalancer.TimeAverageBrokerData in project pulsar by yahoo.
the class TimeAverageBrokerDataTest method testResetMethodOfOneBundlesEmptyBundleMap.
@Test
public void testResetMethodOfOneBundlesEmptyBundleMap() {
TimeAverageBrokerData timeAverageBrokerData = new TimeAverageBrokerData();
Set<String> bundles = new HashSet<>();
bundles.add("a");
Map<String, BundleData> emptyMap = new HashMap<>();
NamespaceBundleStats namespaceBundleStats = new NamespaceBundleStats();
namespaceBundleStats.msgThroughputIn = 1;
namespaceBundleStats.msgThroughputOut = 2;
namespaceBundleStats.msgRateIn = 3;
namespaceBundleStats.msgRateOut = 4;
timeAverageBrokerData.reset(bundles, emptyMap, namespaceBundleStats);
assertEquals(timeAverageBrokerData.getShortTermMsgThroughputIn(), 1);
assertEquals(timeAverageBrokerData.getShortTermMsgThroughputOut(), 2);
assertEquals(timeAverageBrokerData.getShortTermMsgRateIn(), 3);
assertEquals(timeAverageBrokerData.getShortTermMsgRateOut(), 4);
assertEquals(timeAverageBrokerData.getLongTermMsgThroughputIn(), 1);
assertEquals(timeAverageBrokerData.getLongTermMsgThroughputOut(), 2);
assertEquals(timeAverageBrokerData.getLongTermMsgRateIn(), 3);
assertEquals(timeAverageBrokerData.getLongTermMsgRateOut(), 4);
}
use of org.apache.pulsar.policies.data.loadbalancer.TimeAverageBrokerData in project pulsar by yahoo.
the class ModularLoadManagerImpl method writeBundleDataOnZooKeeper.
/**
* As the leader broker, write bundle data aggregated from all brokers to metadata store.
*/
@Override
public void writeBundleDataOnZooKeeper() {
updateBundleData();
// Write the bundle data to metadata store.
List<CompletableFuture<Void>> futures = new ArrayList<>();
for (Map.Entry<String, BundleData> entry : loadData.getBundleData().entrySet()) {
final String bundle = entry.getKey();
final BundleData data = entry.getValue();
futures.add(bundlesCache.readModifyUpdateOrCreate(getBundleDataPath(bundle), __ -> data).thenApply(__ -> null));
}
// Write the time average broker data to metadata store.
for (Map.Entry<String, BrokerData> entry : loadData.getBrokerData().entrySet()) {
final String broker = entry.getKey();
final TimeAverageBrokerData data = entry.getValue().getTimeAverageData();
futures.add(timeAverageBrokerDataCache.readModifyUpdateOrCreate(TIME_AVERAGE_BROKER_ZPATH + "/" + broker, __ -> data).thenApply(__ -> null));
}
try {
FutureUtil.waitForAll(futures).join();
} catch (Exception e) {
log.warn("Error when writing metadata data to store", e);
}
}
use of org.apache.pulsar.policies.data.loadbalancer.TimeAverageBrokerData in project incubator-pulsar by apache.
the class TimeAverageBrokerDataTest method testResetMethodOfOneBundlesEmptyBundleMap.
@Test
public void testResetMethodOfOneBundlesEmptyBundleMap() {
TimeAverageBrokerData timeAverageBrokerData = new TimeAverageBrokerData();
Set<String> bundles = new HashSet<>();
bundles.add("a");
Map<String, BundleData> emptyMap = new HashMap<>();
NamespaceBundleStats namespaceBundleStats = new NamespaceBundleStats();
namespaceBundleStats.msgThroughputIn = 1;
namespaceBundleStats.msgThroughputOut = 2;
namespaceBundleStats.msgRateIn = 3;
namespaceBundleStats.msgRateOut = 4;
timeAverageBrokerData.reset(bundles, emptyMap, namespaceBundleStats);
assertEquals(timeAverageBrokerData.getShortTermMsgThroughputIn(), 1);
assertEquals(timeAverageBrokerData.getShortTermMsgThroughputOut(), 2);
assertEquals(timeAverageBrokerData.getShortTermMsgRateIn(), 3);
assertEquals(timeAverageBrokerData.getShortTermMsgRateOut(), 4);
assertEquals(timeAverageBrokerData.getLongTermMsgThroughputIn(), 1);
assertEquals(timeAverageBrokerData.getLongTermMsgThroughputOut(), 2);
assertEquals(timeAverageBrokerData.getLongTermMsgRateIn(), 3);
assertEquals(timeAverageBrokerData.getLongTermMsgRateOut(), 4);
}
Aggregations