96
96
public class Admin implements KeywordExecutable {
97
97
private static final Logger log = LoggerFactory .getLogger (Admin .class );
98
98
99
- static class AdminOpts extends ServerUtilOpts {
100
- @ Parameter (names = {"-f" , "--force" },
101
- description = "force the given server to stop by removing its lock" )
102
- boolean force = false ;
99
+ private static class SubCommandOpts {
100
+ @ Parameter (names = {"-h" , "-?" , "--help" , "-help" }, help = true )
101
+ public boolean help = false ;
103
102
}
104
103
105
104
@ Parameters (commandDescription = "stop the tablet server on the given hosts" )
106
- static class StopCommand {
105
+ static class StopCommand extends SubCommandOpts {
106
+ @ Parameter (names = {"-f" , "--force" },
107
+ description = "force the given server to stop by removing its lock" )
108
+ boolean force = false ;
107
109
@ Parameter (description = "<host> {<host> ... }" )
108
110
List <String > args = new ArrayList <>();
109
111
}
110
112
111
113
@ Parameters (commandDescription = "Ping tablet servers. If no arguments, pings all." )
112
- static class PingCommand {
114
+ static class PingCommand extends SubCommandOpts {
113
115
@ Parameter (description = "{<host> ... }" )
114
116
List <String > args = new ArrayList <>();
115
117
}
116
118
117
119
@ Parameters (commandDescription = "print tablets that are offline in online tables" )
118
- static class CheckTabletsCommand {
120
+ static class CheckTabletsCommand extends SubCommandOpts {
119
121
@ Parameter (names = "--fixFiles" , description = "Remove dangling file pointers" )
120
122
boolean fixFiles = false ;
121
123
@@ -125,17 +127,17 @@ static class CheckTabletsCommand {
125
127
}
126
128
127
129
@ Parameters (commandDescription = "stop the manager" )
128
- static class StopManagerCommand {}
130
+ static class StopManagerCommand extends SubCommandOpts {}
129
131
130
132
@ Deprecated (since = "2.1.0" )
131
133
@ Parameters (commandDescription = "stop the master (DEPRECATED -- use stopManager instead)" )
132
134
static class StopMasterCommand {}
133
135
134
136
@ Parameters (commandDescription = "stop all tablet servers and the manager" )
135
- static class StopAllCommand {}
137
+ static class StopAllCommand extends SubCommandOpts {}
136
138
137
139
@ Parameters (commandDescription = "list Accumulo instances in zookeeper" )
138
- static class ListInstancesCommand {
140
+ static class ListInstancesCommand extends SubCommandOpts {
139
141
@ Parameter (names = "--print-errors" , description = "display errors while listing instances" )
140
142
boolean printErrors = false ;
141
143
@ Parameter (names = "--print-all" ,
@@ -144,13 +146,13 @@ static class ListInstancesCommand {
144
146
}
145
147
146
148
@ Parameters (commandDescription = "Accumulo volume utility" )
147
- static class VolumesCommand {
149
+ static class VolumesCommand extends SubCommandOpts {
148
150
@ Parameter (names = {"-l" , "--list" }, description = "list volumes currently in use" )
149
151
boolean printErrors = false ;
150
152
}
151
153
152
154
@ Parameters (commandDescription = "print out non-default configuration settings" )
153
- static class DumpConfigCommand {
155
+ static class DumpConfigCommand extends SubCommandOpts {
154
156
@ Parameter (names = {"-a" , "--all" },
155
157
description = "print the system and all table configurations" )
156
158
boolean allConfiguration = false ;
@@ -173,13 +175,13 @@ static class DumpConfigCommand {
173
175
+ "necessary." ;
174
176
175
177
@ Parameters (commandDescription = RV_DEPRECATION_MSG )
176
- static class RandomizeVolumesCommand {
178
+ static class RandomizeVolumesCommand extends SubCommandOpts {
177
179
@ Parameter (names = {"-t" }, description = "table to update" , required = true )
178
180
String tableName = null ;
179
181
}
180
182
181
183
@ Parameters (commandDescription = "Verify all Tablets are assigned to tablet servers" )
182
- static class VerifyTabletAssignmentsCommand {
184
+ static class VerifyTabletAssignmentsCommand extends SubCommandOpts {
183
185
@ Parameter (names = {"-v" , "--verbose" },
184
186
description = "verbose mode (prints locations of tablets)" )
185
187
boolean verbose = false ;
@@ -194,14 +196,14 @@ static class ChangeSecretCommand {}
194
196
195
197
@ Parameters (
196
198
commandDescription = "List or delete Tablet Server locks. Default with no arguments is to list the locks." )
197
- static class TabletServerLocksCommand {
199
+ static class TabletServerLocksCommand extends SubCommandOpts {
198
200
@ Parameter (names = "-delete" , description = "specify a tablet server lock to delete" )
199
201
String delete = null ;
200
202
}
201
203
202
204
@ Parameters (
203
205
commandDescription = "Deletes specific instance name or id from zookeeper or cleans up all old instances." )
204
- static class DeleteZooInstanceCommand {
206
+ static class DeleteZooInstanceCommand extends SubCommandOpts {
205
207
@ Parameter (names = {"-i" , "--instance" }, description = "the instance name or id to delete" )
206
208
String instance ;
207
209
@ Parameter (names = {"-c" , "--clean" },
@@ -214,7 +216,7 @@ static class DeleteZooInstanceCommand {
214
216
}
215
217
216
218
@ Parameters (commandDescription = "Restore Zookeeper data from a file." )
217
- static class RestoreZooCommand {
219
+ static class RestoreZooCommand extends SubCommandOpts {
218
220
@ Parameter (names = "--overwrite" )
219
221
boolean overwrite = false ;
220
222
@@ -224,7 +226,7 @@ static class RestoreZooCommand {
224
226
225
227
@ Parameters (commandNames = "fate" ,
226
228
commandDescription = "Operations performed on the Manager FaTE system." )
227
- static class FateOpsCommand {
229
+ static class FateOpsCommand extends SubCommandOpts {
228
230
@ Parameter (description = "[<txId>...]" )
229
231
List <String > txList = new ArrayList <>();
230
232
@@ -255,6 +257,15 @@ static class FateOpsCommand {
255
257
List <String > states = new ArrayList <>();
256
258
}
257
259
260
+ @ Parameters (commandDescription = "show service status" )
261
+ public static class ServiceStatusCmdOpts extends SubCommandOpts {
262
+ @ Parameter (names = "--json" , description = "provide output in json format (--noHosts ignored)" )
263
+ boolean json = false ;
264
+ @ Parameter (names = "--noHosts" ,
265
+ description = "provide a summary of service counts without host details" )
266
+ boolean noHosts = false ;
267
+ }
268
+
258
269
public static void main (String [] args ) {
259
270
new Admin ().execute (args );
260
271
}
@@ -277,13 +288,12 @@ public String description() {
277
288
@ SuppressFBWarnings (value = "DM_EXIT" , justification = "System.exit okay for CLI tool" )
278
289
@ Override
279
290
public void execute (final String [] args ) {
280
- boolean everything ;
281
291
282
- AdminOpts opts = new AdminOpts ();
292
+ ServerUtilOpts opts = new ServerUtilOpts ();
283
293
JCommander cl = new JCommander (opts );
284
294
cl .setProgramName ("accumulo admin" );
285
295
286
- ServiceStatusCmd . Opts serviceStatusCommandOpts = new ServiceStatusCmd . Opts ();
296
+ ServiceStatusCmdOpts serviceStatusCommandOpts = new ServiceStatusCmdOpts ();
287
297
cl .addCommand ("serviceStatus" , serviceStatusCommandOpts );
288
298
289
299
ChangeSecretCommand changeSecretCommand = new ChangeSecretCommand ();
@@ -337,11 +347,21 @@ public void execute(final String[] args) {
337
347
338
348
cl .parse (args );
339
349
340
- if (opts . help || cl .getParsedCommand () == null ) {
350
+ if (cl .getParsedCommand () == null ) {
341
351
cl .usage ();
342
352
return ;
343
353
}
344
354
355
+ for (var command : cl .getCommands ().entrySet ()) {
356
+ var objects = command .getValue ().getObjects ();
357
+ for (var obj : objects ) {
358
+ if (obj instanceof SubCommandOpts && ((SubCommandOpts ) obj ).help ) {
359
+ command .getValue ().usage ();
360
+ return ;
361
+ }
362
+ }
363
+ }
364
+
345
365
ServerContext context = opts .getServerContext ();
346
366
347
367
AccumuloConfiguration conf = context .getConfiguration ();
@@ -380,7 +400,7 @@ public void execute(final String[] args) {
380
400
}
381
401
382
402
} else if (cl .getParsedCommand ().equals ("stop" )) {
383
- stopTabletServer (context , stopOpts .args , opts .force );
403
+ stopTabletServer (context , stopOpts .args , stopOpts .force );
384
404
} else if (cl .getParsedCommand ().equals ("dumpConfig" )) {
385
405
printConfig (context , dumpConfigCommand );
386
406
} else if (cl .getParsedCommand ().equals ("volumes" )) {
@@ -402,15 +422,19 @@ public void execute(final String[] args) {
402
422
} else if (cl .getParsedCommand ().equals ("fate" )) {
403
423
executeFateOpsCommand (context , fateOpsCommand );
404
424
} else if (cl .getParsedCommand ().equals ("serviceStatus" )) {
405
- printServiceStatus (context , serviceStatusCommandOpts );
406
- } else {
407
- everything = cl .getParsedCommand ().equals ("stopAll" );
425
+ ServiceStatusCmd ssc = new ServiceStatusCmd ();
426
+ ssc .execute (context , serviceStatusCommandOpts .json , serviceStatusCommandOpts .noHosts );
427
+ } else if (cl .getParsedCommand ().equals ("stopManager" )
428
+ || cl .getParsedCommand ().equals ("stopAll" )) {
429
+ boolean everything = cl .getParsedCommand ().equals ("stopAll" );
408
430
409
431
if (everything ) {
410
432
flushAll (context );
411
433
}
412
434
413
435
stopServer (context , everything );
436
+ } else {
437
+ cl .usage ();
414
438
}
415
439
416
440
if (rc != 0 ) {
@@ -430,11 +454,6 @@ public void execute(final String[] args) {
430
454
}
431
455
}
432
456
433
- private static void printServiceStatus (ServerContext context , ServiceStatusCmd .Opts opts ) {
434
- ServiceStatusCmd ssc = new ServiceStatusCmd ();
435
- ssc .execute (context , opts );
436
- }
437
-
438
457
private static int ping (ClientContext context , List <String > args ) {
439
458
440
459
InstanceOperations io = context .instanceOperations ();
0 commit comments