1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.giraph.benchmark;
20
21 import org.apache.commons.cli.CommandLine;
22 import org.apache.commons.cli.Options;
23 import org.apache.log4j.Logger;
24
25
26
27
28 public class BenchmarkOption {
29
30 public static final BenchmarkOption HELP =
31 new BenchmarkOption("h", "help", false, "Help");
32
33 public static final BenchmarkOption VERBOSE =
34 new BenchmarkOption("v", "verbose", false, "Verbose");
35
36 public static final BenchmarkOption WORKERS =
37 new BenchmarkOption("w", "workers", true, "Number of workers",
38 "Need to choose the number of workers (-w)");
39
40 public static final BenchmarkOption SUPERSTEPS =
41 new BenchmarkOption("s", "supersteps", true,
42 "Supersteps to execute before finishing",
43 "Need to set the number of supersteps (-s)");
44
45 public static final BenchmarkOption VERTICES =
46 new BenchmarkOption("V", "aggregateVertices", true,
47 "Aggregate vertices", "Need to set the aggregate vertices (-V)");
48
49 public static final BenchmarkOption EDGES_PER_VERTEX =
50 new BenchmarkOption("e", "edgesPerVertex", true,
51 "Edges per vertex",
52 "Need to set the number of edges per vertex (-e)");
53
54 public static final BenchmarkOption LOCAL_EDGES_MIN_RATIO =
55 new BenchmarkOption(
56 "l", "localEdgesMinRatio", true,
57 "Minimum ratio of partition-local edges (default is 0)");
58
59 public static final BenchmarkOption JYTHON =
60 new BenchmarkOption("j", "jython", false, "Use jython implementation");
61
62 public static final BenchmarkOption SCRIPT_PATH =
63 new BenchmarkOption("sp", "scriptPath", true,
64 "Path to script for computation, can be local or HDFS path");
65
66
67 private String shortOption;
68
69 private String longOption;
70
71 private boolean hasArgument;
72
73 private String description;
74
75
76
77
78 private String missingMessage;
79
80
81
82
83
84
85
86
87
88 public BenchmarkOption(String shortOption, String longOption,
89 boolean hasArgument, String description) {
90 this(shortOption, longOption, hasArgument, description, null);
91 }
92
93
94
95
96
97
98
99
100
101
102 public BenchmarkOption(String shortOption, String longOption,
103 boolean hasArgument, String description, String missingMessage) {
104 this.shortOption = shortOption;
105 this.longOption = longOption;
106 this.hasArgument = hasArgument;
107 this.description = description;
108 this.missingMessage = missingMessage;
109 }
110
111
112
113
114
115
116 public boolean isRequired() {
117 return missingMessage != null;
118 }
119
120
121
122
123
124
125 public void addToOptions(Options options) {
126 options.addOption(shortOption, longOption, hasArgument, description);
127 }
128
129
130
131
132
133
134
135
136
137
138 public boolean checkOption(CommandLine cmd, Logger log) {
139 if (!isRequired()) {
140 return true;
141 }
142 if (!cmd.hasOption(shortOption)) {
143 log.info(missingMessage);
144 return false;
145 }
146 return true;
147 }
148
149
150
151
152
153
154
155 public boolean optionTurnedOn(CommandLine cmd) {
156 return cmd.hasOption(shortOption);
157 }
158
159
160
161
162
163
164
165
166 public String getOptionValue(CommandLine cmd) {
167 return cmd.getOptionValue(shortOption);
168 }
169
170
171
172
173
174
175
176 public int getOptionIntValue(CommandLine cmd) {
177 return Integer.parseInt(getOptionValue(cmd));
178 }
179
180
181
182
183
184
185
186
187
188
189 public int getOptionIntValue(CommandLine cmd, int defaultValue) {
190 return optionTurnedOn(cmd) ? getOptionIntValue(cmd) : defaultValue;
191 }
192
193
194
195
196
197
198
199 public long getOptionLongValue(CommandLine cmd) {
200 return Long.parseLong(getOptionValue(cmd));
201 }
202
203
204
205
206
207
208
209 public float getOptionFloatValue(CommandLine cmd) {
210 return Float.parseFloat(getOptionValue(cmd));
211 }
212
213
214
215
216
217
218
219
220
221
222 public float getOptionFloatValue(CommandLine cmd, float defaultValue) {
223 return optionTurnedOn(cmd) ? getOptionFloatValue(cmd) : defaultValue;
224 }
225 }