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 java.util.Collections;
23  import java.util.HashMap;
24  import java.util.Map;
25  
26  import org.apache.helix.HelixDataAccessor;
27  import org.apache.helix.HelixProperty;
28  import org.apache.helix.PropertyType;
29  import org.apache.helix.PropertyKey.Builder;
30  import org.apache.helix.model.AlertStatus;
31  import org.apache.helix.model.Alerts;
32  import org.apache.helix.model.HealthStat;
33  import org.apache.helix.model.LiveInstance;
34  import org.apache.helix.model.PersistentStats;
35  
36  
37  public class HealthDataCache
38  {
39    Map<String, LiveInstance> _liveInstanceMap;
40  
41    Map<String, Map<String, HealthStat>> _healthStatMap;
42    HealthStat _globalStats; // DON'T THINK I WILL USE THIS ANYMORE
43    PersistentStats _persistentStats;
44    Alerts _alerts;
45    AlertStatus _alertStatus;
46  
47    public HealthStat getGlobalStats()
48    {
49      return _globalStats;
50    }
51  
52    public PersistentStats getPersistentStats()
53    {
54      return _persistentStats;
55    }
56  
57    public Alerts getAlerts()
58    {
59      return _alerts;
60    }
61  
62    public AlertStatus getAlertStatus()
63    {
64      return _alertStatus;
65    }
66  
67    public Map<String, HealthStat> getHealthStats(String instanceName)
68    {
69      Map<String, HealthStat> map = _healthStatMap.get(instanceName);
70      if (map != null)
71      {
72        return map;
73      } else
74      {
75        return Collections.emptyMap();
76      }
77    }
78  
79    public Map<String, LiveInstance> getLiveInstances()
80    {
81      return _liveInstanceMap;
82    }
83  
84    public boolean refresh(HelixDataAccessor accessor)
85    {
86      Builder keyBuilder = accessor.keyBuilder();
87      _liveInstanceMap = accessor.getChildValuesMap(keyBuilder.liveInstances());
88  
89      Map<String, Map<String, HealthStat>> hsMap = new HashMap<String, Map<String, HealthStat>>();
90  
91      for (String instanceName : _liveInstanceMap.keySet())
92      {
93        // xxx clearly getting znodes for the instance here...so get the
94        // timestamp!
95  
96        Map<String, HealthStat> childValuesMap = accessor
97            .getChildValuesMap(keyBuilder.healthReports(instanceName));
98        hsMap.put(instanceName, childValuesMap);
99      }
100     _healthStatMap = Collections.unmodifiableMap(hsMap);
101     _persistentStats = accessor.getProperty(keyBuilder.persistantStat());
102     _alerts = accessor.getProperty(keyBuilder.alerts());
103     _alertStatus = accessor.getProperty(keyBuilder.alertStatus());
104 
105     return true;
106 
107   }
108 
109 }