View Javadoc

1   // Autogenerated Jamon implementation
2   // /home/jenkins/jenkins-slave/workspace/hbase_generate_website/hbase/hbase-server/src/main/jamon/org/apache/hadoop/hbase/tmpl/common/TaskMonitorTmpl.jamon
3   
4   package org.apache.hadoop.hbase.tmpl.common;
5   
6   // 20, 1
7   import java.util.*;
8   // 21, 1
9   import org.apache.hadoop.hbase.monitoring.*;
10  // 22, 1
11  import org.apache.hadoop.util.StringUtils;
12  // 23, 1
13  import org.owasp.esapi.ESAPI;
14  // 24, 1
15  import org.owasp.esapi.errors.EncodingException;
16  
17  public class TaskMonitorTmplImpl
18    extends org.jamon.AbstractTemplateImpl
19    implements org.apache.hadoop.hbase.tmpl.common.TaskMonitorTmpl.Intf
20  
21  {
22    private final String format;
23    private final TaskMonitor taskMonitor;
24    private final String filter;
25    // 31, 1
26    
27      public String encodeFilter() {
28      try {
29      return ESAPI.encoder().encodeForURL(filter);
30      }catch(EncodingException e) {}
31      return ESAPI.encoder().encodeForHTML(filter);
32      }
33  
34    protected static org.apache.hadoop.hbase.tmpl.common.TaskMonitorTmpl.ImplData __jamon_setOptionalArguments(org.apache.hadoop.hbase.tmpl.common.TaskMonitorTmpl.ImplData p_implData)
35    {
36      if(! p_implData.getFormat__IsNotDefault())
37      {
38        p_implData.setFormat("html");
39      }
40      if(! p_implData.getTaskMonitor__IsNotDefault())
41      {
42        p_implData.setTaskMonitor(TaskMonitor.get());
43      }
44      if(! p_implData.getFilter__IsNotDefault())
45      {
46        p_implData.setFilter("general");
47      }
48      return p_implData;
49    }
50    public TaskMonitorTmplImpl(org.jamon.TemplateManager p_templateManager, org.apache.hadoop.hbase.tmpl.common.TaskMonitorTmpl.ImplData p_implData)
51    {
52      super(p_templateManager, __jamon_setOptionalArguments(p_implData));
53      format = p_implData.getFormat();
54      taskMonitor = p_implData.getTaskMonitor();
55      filter = p_implData.getFilter();
56    }
57    
58    @Override public void renderNoFlush(final java.io.Writer jamonWriter)
59      throws java.io.IOException
60    {
61      // 39, 1
62      
63  List<? extends MonitoredTask> tasks = taskMonitor.getTasks();
64  Iterator<? extends MonitoredTask> iter = tasks.iterator();
65  // apply requested filter
66  while (iter.hasNext()) {
67    MonitoredTask t = iter.next();
68    if (filter.equals("general")) {
69      if (t instanceof MonitoredRPCHandler)
70        iter.remove();
71    } else if (filter.equals("handler")) {
72      if (!(t instanceof MonitoredRPCHandler))
73        iter.remove();
74    } else if (filter.equals("rpc")) {
75      if (!(t instanceof MonitoredRPCHandler) || 
76          !((MonitoredRPCHandler) t).isRPCRunning())
77        iter.remove();
78    } else if (filter.equals("operation")) {
79      if (!(t instanceof MonitoredRPCHandler) || 
80          !((MonitoredRPCHandler) t).isOperationRunning())
81        iter.remove();
82    }
83  }
84  long now = System.currentTimeMillis();
85  Collections.reverse(tasks);
86  boolean first = true;
87  
88      // 65, 1
89      if (format.equals("json"))
90      {
91        // 65, 29
92        jamonWriter.write("\n[");
93        // 66, 2
94        for (MonitoredTask task : tasks)
95        {
96          // 66, 36
97          if (first)
98          {
99            // 66, 48
100           first = false;
101         }
102         // 66, 77
103         else
104         {
105           // 66, 84
106           jamonWriter.write(",");
107         }
108         // 66, 91
109         org.jamon.escaping.Escaping.HTML.write(org.jamon.emit.StandardEmitter.valueOf(task.toJSON()), jamonWriter);
110       }
111       // 66, 117
112       jamonWriter.write("]\n");
113     }
114     // 67, 1
115     else
116     {
117       // 67, 8
118       jamonWriter.write("\n<h2>Tasks</h2>\n  <ul class=\"nav nav-pills\">\n    <li ");
119       // 70, 9
120       if (filter.equals("all"))
121       {
122         // 70, 36
123         jamonWriter.write("class=\"active\"");
124       }
125       // 70, 56
126       jamonWriter.write("><a href=\"?filter=all\">Show All Monitored Tasks</a></li>\n    <li ");
127       // 71, 9
128       if (filter.equals("general"))
129       {
130         // 71, 40
131         jamonWriter.write("class=\"active\"");
132       }
133       // 71, 60
134       jamonWriter.write("><a href=\"?filter=general\">Show non-RPC Tasks</a></li>\n    <li ");
135       // 72, 9
136       if (filter.equals("handler"))
137       {
138         // 72, 40
139         jamonWriter.write("class=\"active\"");
140       }
141       // 72, 60
142       jamonWriter.write("><a href=\"?filter=handler\">Show All RPC Handler Tasks</a></li>\n    <li ");
143       // 73, 9
144       if (filter.equals("rpc"))
145       {
146         // 73, 36
147         jamonWriter.write("class=\"active\"");
148       }
149       // 73, 56
150       jamonWriter.write("><a href=\"?filter=rpc\">Show Active RPC Calls</a></li>\n    <li ");
151       // 74, 9
152       if (filter.equals("operation"))
153       {
154         // 74, 42
155         jamonWriter.write("class=\"active\"");
156       }
157       // 74, 62
158       jamonWriter.write("><a href=\"?filter=operation\">Show Client Operations</a></li>\n    <li><a href=\"?format=json&filter=");
159       // 75, 38
160       org.jamon.escaping.Escaping.HTML.write(org.jamon.emit.StandardEmitter.valueOf(encodeFilter()), jamonWriter);
161       // 75, 58
162       jamonWriter.write("\">View as JSON</a></li>\n  </ul>\n  ");
163       // 77, 3
164       if (tasks.isEmpty())
165       {
166         // 77, 25
167         jamonWriter.write("\n    <p>No tasks currently running on this node.</p>\n  ");
168       }
169       // 79, 3
170       else
171       {
172         // 79, 10
173         jamonWriter.write("\n    <table class=\"table\">\n    <tr>\n      <th>Start Time</th>\n      <th>Description</th>\n      <th>State</th>\n      <th>Status</th>\n    </tr>\n    ");
174         // 87, 5
175         for (MonitoredTask task : tasks )
176         {
177           // 87, 40
178           jamonWriter.write("\n    <tr class=\"");
179           // 88, 16
180           {
181             // 88, 16
182             __jamon_innerUnit__stateCss(jamonWriter, task.getState() );
183           }
184           // 88, 55
185           jamonWriter.write("\">\n      <td>");
186           // 89, 11
187           org.jamon.escaping.Escaping.HTML.write(org.jamon.emit.StandardEmitter.valueOf(new Date(task.getStartTime())), jamonWriter);
188           // 89, 46
189           jamonWriter.write("</td>\n      <td>");
190           // 90, 11
191           org.jamon.escaping.Escaping.HTML.write(org.jamon.emit.StandardEmitter.valueOf(task.getDescription()), jamonWriter);
192           // 90, 38
193           jamonWriter.write("</td>\n      <td>");
194           // 91, 11
195           org.jamon.escaping.Escaping.HTML.write(org.jamon.emit.StandardEmitter.valueOf(task.getState()), jamonWriter);
196           // 91, 32
197           jamonWriter.write("\n          (since ");
198           // 92, 18
199           org.jamon.escaping.Escaping.HTML.write(org.jamon.emit.StandardEmitter.valueOf(StringUtils.formatTimeDiff(now, task.getStateTime())), jamonWriter);
200           // 92, 76
201           jamonWriter.write(" ago)\n      </td>\n      <td>");
202           // 94, 11
203           org.jamon.escaping.Escaping.HTML.write(org.jamon.emit.StandardEmitter.valueOf(task.getStatus()), jamonWriter);
204           // 94, 33
205           jamonWriter.write("\n          (since ");
206           // 95, 18
207           org.jamon.escaping.Escaping.HTML.write(org.jamon.emit.StandardEmitter.valueOf(StringUtils.formatTimeDiff(now, task.getStatusTime())), jamonWriter);
208           // 95, 77
209           jamonWriter.write(" \n          ago)</td>\n    </tr>\n    ");
210         }
211         // 98, 12
212         jamonWriter.write("\n    </table>\n\n  ");
213       }
214       // 101, 9
215       jamonWriter.write("\n");
216     }
217     // 102, 7
218     jamonWriter.write("\n\n\n");
219   }
220   
221   
222   // 105, 1
223   private void __jamon_innerUnit__stateCss(final java.io.Writer jamonWriter, final MonitoredTask.State state)
224     throws java.io.IOException
225   {
226     // 109, 1
227            if (state == MonitoredTask.State.COMPLETE) { 
228     // 109, 68
229     jamonWriter.write("alert alert-success");
230     // 109, 87
231      } 
232     // 110, 1
233       else if (state == MonitoredTask.State.ABORTED)  { 
234     // 110, 68
235     jamonWriter.write("alert alert-error");
236     // 110, 85
237        } 
238   }
239   
240   
241 }