View Javadoc

1   package org.apache.helix.controller.stages;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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  }