use of org.apache.helix.controller.pipeline.StageException in project helix by apache.
the class TaskAssignmentStage method process.
@Override
public void process(ClusterEvent event) throws Exception {
HelixManager manager = event.getAttribute(AttributeName.helixmanager.name());
Map<String, Resource> resourceMap = event.getAttribute(AttributeName.RESOURCES_TO_REBALANCE.name());
MessageThrottleStageOutput messageOutput = event.getAttribute(AttributeName.MESSAGES_THROTTLE.name());
ClusterDataCache cache = event.getAttribute(AttributeName.ClusterDataCache.name());
Map<String, LiveInstance> liveInstanceMap = cache.getLiveInstances();
if (manager == null || resourceMap == null || messageOutput == null || cache == null || liveInstanceMap == null) {
throw new StageException("Missing attributes in event:" + event + ". Requires HelixManager|RESOURCES|MESSAGES_THROTTLE|DataCache|liveInstanceMap");
}
HelixDataAccessor dataAccessor = manager.getHelixDataAccessor();
List<Message> messagesToSend = new ArrayList<Message>();
for (String resourceName : resourceMap.keySet()) {
Resource resource = resourceMap.get(resourceName);
for (Partition partition : resource.getPartitions()) {
List<Message> messages = messageOutput.getMessages(resourceName, partition);
messagesToSend.addAll(messages);
}
}
List<Message> outputMessages = batchMessage(dataAccessor.keyBuilder(), messagesToSend, resourceMap, liveInstanceMap, manager.getProperties());
sendMessages(dataAccessor, outputMessages);
// TODO: Need also count messages from task rebalancer
if (!cache.isTaskCache()) {
ClusterStatusMonitor clusterStatusMonitor = event.getAttribute(AttributeName.clusterStatusMonitor.name());
if (clusterStatusMonitor != null) {
clusterStatusMonitor.increaseMessageReceived(outputMessages);
}
}
long cacheStart = System.currentTimeMillis();
cache.cacheMessages(outputMessages);
long cacheEnd = System.currentTimeMillis();
logger.debug("Caching messages took " + (cacheEnd - cacheStart) + " ms");
}
Aggregations