View Javadoc

1   package org.apache.helix.healthcheck;
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.log4j.Logger;
23  
24  import java.util.Map;
25  
26  public class Stat
27  {
28  
29    private static final Logger _logger = Logger.getLogger(Stat.class);
30  
31    public final static String OP_TYPE = "HTTP_OP";
32    public final static String MEASUREMENT_TYPE = "MEASUREMENT";
33    public final static String RESOURCE_NAME = "RESOURCE_NAME";
34    public final static String PARTITION_NAME = "PARTITION_NAME";
35    public final static String NODE_NAME = "NODE_NAME";
36    public final static String TIMESTAMP = "TIMESTAMP";
37    public final static String RETURN_STATUS = "RETURN_STATUS";
38    public final static String METRIC_NAME = "METRIC_NAME";
39    public final static String AGG_TYPE = "AGG_TYPE";
40  
41    public String _opType;
42    public String _measurementType;
43    public String _resourceName;
44    public String _partitionName;
45    public String _nodeName;
46    public String _returnStatus;
47    public String _metricName;
48    public String _aggTypeName;
49    public String _timestamp;
50  
51    public Stat(String opType, String measurementType, String resourceName,
52        String partitionName, String nodeName)
53    {
54      // this(opType, measurementType, resourceName, partitionName, nodeName,
55      // null, null, null);
56      this(opType, measurementType, resourceName, partitionName, nodeName, null,
57          null, null);
58    }
59  
60    public Stat(String opType, String measurementType, String resourceName,
61        String partitionName, String nodeName, String returnStatus,
62        String metricName, AggregationType aggType)
63    {
64      this._opType = opType;
65      this._measurementType = measurementType;
66      this._resourceName = resourceName;
67      this._partitionName = partitionName;
68      this._nodeName = nodeName;
69      this._returnStatus = returnStatus;
70      this._metricName = metricName;
71      this._aggTypeName = null;
72      if (aggType != null)
73      {
74        this._aggTypeName = aggType.getName();
75      }
76  
77      _timestamp = String.valueOf(System.currentTimeMillis());
78    }
79  
80    public Stat(Map<String, String> in)
81    {
82      _opType = in.get(OP_TYPE);
83      _measurementType = in.get(MEASUREMENT_TYPE);
84      _resourceName = in.get(RESOURCE_NAME);
85      _partitionName = in.get(PARTITION_NAME);
86      _nodeName = in.get(NODE_NAME);
87      _timestamp = String.valueOf(System.currentTimeMillis());
88    }
89  
90    public void setAggType(AggregationType aggType)
91    {
92      this._aggTypeName = aggType.getName();
93    }
94  
95    @Override
96    public boolean equals(Object obj)
97    {
98      if (!(obj instanceof Stat))
99      {
100       return false;
101     }
102     Stat other = (Stat) obj;
103     if (!_partitionName.equals(other._partitionName))
104     {
105       return false;
106     }
107     if (!_opType.equals(other._opType))
108     {
109       return false;
110     }
111     if (!_measurementType.equals(other._measurementType))
112     {
113       return false;
114     }
115     if (!_resourceName.equals(other._resourceName))
116     {
117       return false;
118     }
119     if (!_nodeName.equals(other._nodeName))
120     {
121       return false;
122     }
123     return true;
124   }
125 
126   @Override
127   public int hashCode()
128   {
129     return (_partitionName + _opType + _measurementType + _resourceName + _nodeName)
130         .hashCode();
131   }
132 
133   public void addAlert(long value)
134   {
135     // TODO Auto-generated method stub
136 
137   }
138 
139   public String toString()
140   {
141     return _nodeName + "." + _resourceName + "." + _partitionName + "."
142         + _opType + "." + _measurementType + "." + _returnStatus + "."
143         + _metricName + "." + _aggTypeName;
144   }
145 }