This project has retired. For details please refer to its Attic page.
Chart xref
View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  package org.apache.hadoop.chukwa.hicc.bean;
20  
21  
22  import java.net.URI;
23  import java.net.URISyntaxException;
24  import java.util.ArrayList;
25  import java.util.HashMap;
26  import java.util.List;
27  
28  import javax.xml.bind.annotation.XmlAccessType;
29  import javax.xml.bind.annotation.XmlAccessorType;
30  import javax.xml.bind.annotation.XmlRootElement;
31  
32  @XmlRootElement
33  @XmlAccessorType(XmlAccessType.PUBLIC_MEMBER)
34  public class Chart {
35    private String id;
36    private ChartType type;
37    private String title;
38    private List<SeriesMetaData> series;
39    private boolean xLabelOn;
40    private boolean yLabelOn;
41    private boolean yRightLabelOn;
42    private int width;
43    private int height;
44    private List<String> xLabelRange;
45    private HashMap<String, Long> xLabelRangeHash;
46    private boolean legend = true;
47    private String xLabel = "";
48    private String yLabel = "";
49    private String yRightLabel = "";
50    private double max = 0;
51    private double min = 0;
52    private boolean userDefinedMax = true;
53    private boolean userDefinedMin = true;
54    private String yUnitType = "";
55    private String icon = "";
56    private String bannerText = "";
57    private String suffixText = "";
58    private String threshold = "";
59  
60    public Chart(String id) {
61      this.id = id;
62      this.type = ChartType.TIME_SERIES;
63      this.title = "Untitled Chart";
64      this.xLabelOn = true;
65      this.yLabelOn = true;
66      this.width = 100;
67      this.height = 100;
68      this.legend = true;
69      this.max = 0;
70      this.userDefinedMax = false;
71      this.userDefinedMin = false;
72    }
73  
74    public ChartType getType() {
75      return this.type;
76    }
77    
78    public void setType(ChartType type) {
79      this.type = type;
80    }
81  
82    public void setYMax(double max) {
83      this.max = max;
84      this.userDefinedMax = true;
85    }
86  
87    public double getYMax() {
88      return this.max;
89    }
90  
91    public boolean getUserDefinedMax() {
92      return this.userDefinedMax;
93    }
94  
95    public void setYMin(double min) {
96      this.min = min;
97      this.userDefinedMin = true;
98    }
99  
100   public double getYMin() {
101     return this.min;
102   }
103 
104   public boolean getUserDefinedMin() {
105     return this.userDefinedMin;
106   }
107 
108   public void setSize(int width, int height) {
109     this.width = width;
110     this.height = height;
111   }
112 
113   public int getWidth() {
114     return this.width;
115   }
116 
117   public int getHeight() {
118     return this.height;
119   }
120 
121   public void setTitle(String title) {
122     this.title = title;
123   }
124 
125   public String getTitle() {
126     return this.title;
127   }
128 
129   public void setId(String id) {
130     this.id = id;
131   }
132 
133   public String getId() {
134     return this.id;
135   }
136 
137   public void setSeries(List<SeriesMetaData> series) {
138     this.series = series;
139   }
140   
141   public List<SeriesMetaData> getSeries() {
142     return this.series;
143   }
144   
145   public void setXAxisLabelsOn(boolean toggle) {
146     xLabelOn = toggle;
147   }
148 
149   public boolean isXAxisLabelsOn() {
150     return xLabelOn;
151   }
152 
153   public void setYAxisLabels(boolean toggle) {
154     yLabelOn = toggle;
155   }
156 
157   public boolean isYAxisLabelsOn() {
158     return yLabelOn;
159   }
160 
161   public void setYAxisRightLabels(boolean toggle) {
162     yRightLabelOn = toggle;
163   }
164 
165   public boolean isYAxisRightLabelsOn() {
166     return yRightLabelOn;
167   }
168 
169   public void setXAxisLabel(String label) {
170     xLabel = label;
171   }
172 
173   public String getXAxisLabel() {
174     return xLabel;
175   }
176 
177   public void setYAxisLabel(String label) {
178     yLabel = label;
179   }
180 
181   public String getYAxisLabel() {
182     return yLabel;
183   }
184 
185   public void setYAxisRightLabel(String label) {
186     yRightLabel = label;
187   }
188 
189   public String getYAxisRightLabel() {
190     return yRightLabel;
191   }
192 
193   public void setXLabelsRange(List<String> range) {
194     xLabelRange = range;
195     xLabelRangeHash = new HashMap<String, Long>();
196     long value = 0;
197     for (String label : range) {
198       xLabelRangeHash.put(label, value);
199       value++;
200     }
201   }
202 
203   public List<String> getXLabelsRange() {
204     return xLabelRange;
205   }
206   
207   public void setLegend(boolean toggle) {
208     legend = toggle;
209   }
210 
211   public boolean getLegend() {
212     return legend;
213   }
214 
215   public void setYUnitType(String yUnitType) {
216     this.yUnitType = yUnitType;
217   }
218   
219   public String getYUnitType() {
220     return this.yUnitType;
221   }
222 
223   public void setIcon(String icon) {
224     this.icon = icon;
225   }
226 
227   public String getIcon() {
228     return this.icon;
229   }
230 
231   public void setBannerText(String bannerText) {
232     this.bannerText = bannerText;
233   }
234 
235   public String getBannerText() {
236     return this.bannerText;
237   }
238 
239   public void setSuffixText(String suffixText) {
240     this.suffixText = suffixText;
241   }
242 
243   public String getSuffixText() {
244     return this.suffixText;
245   }
246 
247   public void setThreshold(String direction) {
248     this.threshold = direction;
249   }
250   
251   public String getThreshold() {
252     return this.threshold;
253   }
254 
255   /**
256    * Create a chart object.
257    * @param id is unique chart identifier
258    * @param title is searchable name of the chart
259    * @param metrics is list of metric names to render chart
260    * @param source is data source name
261    * @param yunitType is y axis unit type
262    * @return Chart object
263    * @throws URISyntaxException if metrics name can not compose valid URL syntax
264    */
265   public static synchronized Chart createChart(String id,
266       String title, String[] metrics, String source, String yunitType) throws URISyntaxException {
267     Chart chart = new Chart(id);
268     chart.setYUnitType(yunitType);
269     chart.setTitle(title);
270     ArrayList<SeriesMetaData> series = new ArrayList<SeriesMetaData>();
271     for(String metric : metrics) {
272       SeriesMetaData s = new SeriesMetaData();
273       s.setLabel(metric + "/" + source);
274       s.setUrl(new URI("/hicc/v1/metrics/series/" + metric + "/"
275         + source));
276       LineOptions l = new LineOptions();
277       s.setLineOptions(l);
278       series.add(s);
279     }
280     chart.setSeries(series);
281     return chart;
282     
283   }
284   
285   /**
286    * Create a chart in HBase by specifying parameters.
287    * @param id is unique chart identifier
288    * @param title is searchable name of the chart
289    * @param metrics is list of metric names to render ring chart
290    * @param source is data source name
291    * @param suffixLabel is text label to append to metric values
292    * @param direction sets the threshold to have either upper limit or lower limit
293    * @return Chart object
294    * @throws URISyntaxException if metrics name can not compose valid URL syntax
295    */
296   public static synchronized Chart createCircle(String id,
297       String title, String[] metrics, String source, String suffixLabel, String direction) throws URISyntaxException {
298     Chart chart = new Chart(id);
299     chart.setSuffixText(suffixLabel);
300     chart.setTitle(title);
301     chart.setThreshold(direction);
302     ArrayList<SeriesMetaData> series = new ArrayList<SeriesMetaData>();
303     for(String metric : metrics) {
304       SeriesMetaData s = new SeriesMetaData();
305       s.setLabel(metric + "/" + source);
306       s.setUrl(new URI("/hicc/v1/metrics/series/" + metric + "/"
307         + source));
308       series.add(s);
309     }
310     chart.setSeries(series);
311     return chart;
312     
313   }
314   
315   /**
316    * Create a tile in HBase by specifying parameters.
317    * @param id is unique tile identifier
318    * @param title is searchable name of the tile widget
319    * @param bannerText is description of the tile widget
320    * @param suffixLabel is text label to append to metric values
321    * @param metrics is list of metric names to render tile widget
322    * @param source is data source name
323    * @param icon is emoji symbol to render beside tile widget
324    * @return Chart object
325    * @throws URISyntaxException if metrics name can not compose valid URL syntax
326    */
327   public static synchronized Chart createTile(String id, String title, 
328       String bannerText, String suffixLabel, String[] metrics, String source, 
329       String icon) throws URISyntaxException {
330     Chart chart = new Chart(id);
331     chart.setTitle(title);
332     chart.setBannerText(bannerText);
333     chart.setSuffixText(suffixLabel);
334     chart.setIcon(icon);
335     List<SeriesMetaData> smd = new ArrayList<SeriesMetaData>();
336     for (String metric : metrics) {
337       SeriesMetaData series = new SeriesMetaData();
338       series.setUrl(new URI("/hicc/v1/metrics/series/" + metric + "/" + source));
339       smd.add(series);
340     }
341     chart.setSeries(smd);
342     return chart;
343   }
344 }