public void process(ClusterEvent event) throws Exception
{
long startTime = System.currentTimeMillis();
log.info("START ExternalViewComputeStage.process()");
HelixManager manager = event.getAttribute("helixmanager");
Map<String, Resource> resourceMap =
event.getAttribute(AttributeName.RESOURCES.toString());
ClusterDataCache cache = event.getAttribute("ClusterDataCache");
if (manager == null || resourceMap == null || cache == null)
{
throw new StageException("Missing attributes in event:" + event
+ ". Requires ClusterManager|RESOURCES|DataCache");
}
HelixDataAccessor dataAccessor = manager.getHelixDataAccessor();
CurrentStateOutput currentStateOutput =
event.getAttribute(AttributeName.CURRENT_STATE.toString());
List<ExternalView> newExtViews = new ArrayList<ExternalView>();
List<PropertyKey> keys = new ArrayList<PropertyKey>();
for (String resourceName : resourceMap.keySet())
{
ExternalView view = new ExternalView(resourceName);
// view.setBucketSize(currentStateOutput.getBucketSize(resourceName));
// if resource ideal state has bucket size, set it
// otherwise resource has been dropped, use bucket size from current state instead
Resource resource = resourceMap.get(resourceName);
if (resource.getBucketSize() > 0)
{
view.setBucketSize(resource.getBucketSize());
}
else
{
view.setBucketSize(currentStateOutput.getBucketSize(resourceName));
}
for (Partition partition : resource.getPartitions())
{
Map<String, String> currentStateMap =
currentStateOutput.getCurrentStateMap(resourceName, partition);
if (currentStateMap != null && currentStateMap.size() > 0)
{
// Set<String> disabledInstances
// = cache.getDisabledInstancesForResource(resource.toString());
for (String instance : currentStateMap.keySet())
{
// if (!disabledInstances.contains(instance))
// {
view.setState(partition.getPartitionName(),
instance,
currentStateMap.get(instance));
// }
}
}
}
// Update cluster status monitor mbean
ClusterStatusMonitor clusterStatusMonitor =
(ClusterStatusMonitor) event.getAttribute("clusterStatusMonitor");
if (clusterStatusMonitor != null)
{
clusterStatusMonitor.onExternalViewChange(view,
cache._idealStateMap.get(view.getResourceName()));
}
// compare the new external view with current one, set only on different
Map<String, ExternalView> curExtViews =
dataAccessor.getChildValuesMap(manager.getHelixDataAccessor()
.keyBuilder()
.externalViews());
ExternalView curExtView = curExtViews.get(resourceName);
if (curExtView == null || !curExtView.getRecord().equals(view.getRecord()))
{
keys.add(manager.getHelixDataAccessor().keyBuilder().externalView(resourceName));
newExtViews.add(view);
// dataAccessor.setProperty(PropertyType.EXTERNALVIEW, view,
// resourceName);
}
}