1 package org.apache.helix.controller.stages;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.helix.HelixDataAccessor;
23 import org.apache.helix.HelixManager;
24 import org.apache.helix.controller.pipeline.AbstractBaseStage;
25 import org.apache.helix.controller.pipeline.StageException;
26 import org.apache.helix.model.InstanceConfig;
27 import org.apache.helix.monitoring.mbeans.ClusterStatusMonitor;
28 import org.apache.log4j.Logger;
29
30
31 public class ReadClusterDataStage extends AbstractBaseStage
32 {
33 private static final Logger logger = Logger
34 .getLogger(ReadClusterDataStage.class.getName());
35 ClusterDataCache _cache;
36
37 public ReadClusterDataStage()
38 {
39 _cache = new ClusterDataCache();
40 }
41
42 @Override
43 public void process(ClusterEvent event) throws Exception
44 {
45 long startTime = System.currentTimeMillis();
46 logger.info("START ReadClusterDataStage.process()");
47
48
49 HelixManager manager = event.getAttribute("helixmanager");
50 if (manager == null)
51 {
52 throw new StageException("HelixManager attribute value is null");
53 }
54 HelixDataAccessor dataAccessor = manager.getHelixDataAccessor();
55 _cache.refresh(dataAccessor);
56
57 ClusterStatusMonitor clusterStatusMonitor = (ClusterStatusMonitor) event.getAttribute("clusterStatusMonitor");
58 if(clusterStatusMonitor != null)
59 {
60 int disabledInstances = 0;
61 int disabledPartitions = 0;
62 for(InstanceConfig config : _cache._instanceConfigMap.values())
63 {
64 if(config.getInstanceEnabled() == false)
65 {
66 disabledInstances++;
67 }
68 if(config.getDisabledPartitions() != null)
69 {
70 disabledPartitions += config.getDisabledPartitions().size();
71 }
72 }
73 clusterStatusMonitor.setClusterStatusCounters(_cache._liveInstanceMap.size(), _cache._instanceConfigMap.size(),
74 disabledInstances, disabledPartitions);
75 }
76
77 event.addAttribute("ClusterDataCache", _cache);
78
79 long endTime = System.currentTimeMillis();
80 logger.info("END ReadClusterDataStage.process(). took: " + (endTime - startTime) + " ms");
81 }
82 }