View Javadoc

1   package org.apache.helix.mock.participant;
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.HashMap;
23  import java.util.Map;
24  
25  import org.apache.helix.alerts.StatsHolder;
26  import org.apache.helix.healthcheck.HealthReportProvider;
27  
28  
29  public class MockEspressoHealthReportProvider extends HealthReportProvider {
30  
31  	private final String _reportName = "RestQueryStats";
32  	private HashMap<String, Map<String,String>> _statMap;
33  	private final String DB_NAME = "DBName";
34  	
35  	public MockEspressoHealthReportProvider()
36  	{
37  		super();
38  		_statMap = new HashMap<String, Map<String,String>>();
39  	}
40  	
41  	public String buildMapKey(String dbName)
42  	{
43  		return _reportName+"@"+DB_NAME+"="+dbName;
44  	}
45  	
46  	public void setStat(String dbName, String statName, String statVal)
47  	{
48  		String currTime = String.valueOf(System.currentTimeMillis());
49  		setStat(dbName, statName, statVal, currTime);
50  	}
51  	
52  	/*
53  	 * This version takes a fixed timestamp to ease with testing
54  	 */
55  	public void setStat(String dbName, String statName, String statVal, String timestamp)
56  	{
57  		String key = buildMapKey(dbName);
58  		Map<String, String> dbStatMap = _statMap.get(key);
59  		if (dbStatMap == null) {
60  			dbStatMap = new HashMap<String,String>();
61  			_statMap.put(key, dbStatMap);
62  		}
63  		dbStatMap.put(statName,  statVal);
64  		dbStatMap.put(StatsHolder.TIMESTAMP_NAME, timestamp);
65  	}
66  	
67  	@Override
68  	public Map<String, String> getRecentHealthReport() {
69  		return null;
70  	}
71  
72  	@Override
73  	public Map<String, Map<String, String>> getRecentPartitionHealthReport() {
74  		return _statMap;
75  	}
76  	
77  	@Override
78  	public void resetStats() {
79  	_statMap.clear();
80  	}
81  	
82  	public String getReportName() 
83  	{
84  		return _reportName;
85  	}
86  
87  }