This project has retired. For details please refer to its
Attic page.
NodeActivityPlugin xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.chukwa.inputtools.plugin.nodeactivity;
20
21
22 import org.apache.hadoop.chukwa.inputtools.mdl.DataConfig;
23 import org.apache.hadoop.chukwa.inputtools.plugin.ExecPlugin;
24 import org.apache.hadoop.chukwa.inputtools.plugin.IPlugin;
25 import org.json.simple.JSONObject;
26
27 public class NodeActivityPlugin extends ExecPlugin {
28 private String cmde = null;
29 private DataConfig dataConfig = null;
30
31 public NodeActivityPlugin() {
32 dataConfig = new DataConfig();
33 cmde = dataConfig.get("mdl.plugin.NodeActivityPlugin.cmde");
34 }
35
36 @Override
37 public String getCmde() {
38 return cmde;
39 }
40
41 @Override
42 public JSONObject postProcess(JSONObject execResult) {
43 try {
44 if ( (Integer) execResult.get("status") < 0) {
45 return execResult;
46 }
47
48 String res = (String) execResult.get("stdout");
49
50 String[] tab = res.split("\n");
51 int totalFreeNode = 0;
52 int totalUsedNode = 0;
53 int totalDownNode = 0;
54
55 for (int i = 0; i < tab.length; i++) {
56 if (tab[i].indexOf("state =") < 0) {
57 tab[i] = null;
58 continue;
59 }
60
61 String[] line = tab[i].split("state =");
62 tab[i] = null;
63
64 if (line[1].trim().equals("free")) {
65 totalFreeNode++;
66 } else if (line[1].trim().equals("job-exclusive")) {
67 totalUsedNode++;
68 } else {
69 totalDownNode++;
70 }
71 }
72
73 execResult.put("totalFreeNode", totalFreeNode);
74 execResult.put("totalUsedNode", totalUsedNode);
75 execResult.put("totalDownNode", totalDownNode);
76 execResult.put("source", "NodeActivity");
77
78 execResult.put("status", 100);
79
80 } catch (Throwable e) {
81 try {
82 execResult.put("source", "NodeActivity");
83 execResult.put("status", -100);
84 execResult.put("errorLog", e.getMessage());
85 } catch (Exception e1) {
86 e1.printStackTrace();
87 }
88 e.printStackTrace();
89
90 }
91
92 return execResult;
93 }
94
95 public static void main(String[] args) {
96 IPlugin plugin = new NodeActivityPlugin();
97 JSONObject result = plugin.execute();
98 System.out.print("Result: " + result);
99
100 }
101
102 }