1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.hadoop.hbase.zookeeper;
21
22 import java.io.IOException;
23
24 import org.apache.hadoop.conf.Configuration;
25 import org.apache.hadoop.hbase.HBaseConfiguration;
26 import org.apache.hadoop.hbase.HBaseInterfaceAudience;
27 import org.apache.hadoop.hbase.classification.InterfaceAudience;
28 import org.apache.zookeeper.KeeperException;
29 import org.apache.zookeeper.ZooKeeperMain;
30
31
32
33
34
35 @InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.TOOLS)
36 public class ZooKeeperMainServer {
37 private static final String SERVER_ARG = "-server";
38
39 public String parse(final Configuration c) {
40 return ZKConfig.getZKQuorumServersString(c);
41 }
42
43
44
45
46
47 private static class HACK_UNTIL_ZOOKEEPER_1897_ZooKeeperMain extends ZooKeeperMain {
48 public HACK_UNTIL_ZOOKEEPER_1897_ZooKeeperMain(String[] args)
49 throws IOException, InterruptedException {
50 super(args);
51 }
52
53
54
55
56
57
58
59 void runCmdLine() throws KeeperException, IOException, InterruptedException {
60 processCmd(this.cl);
61 System.exit(0);
62 }
63 }
64
65
66
67
68
69 private static boolean hasServer(final String args[]) {
70 return args.length > 0 && args[0].equals(SERVER_ARG);
71 }
72
73
74
75
76
77 private static boolean hasCommandLineArguments(final String args[]) {
78 if (hasServer(args)) {
79 if (args.length < 2) throw new IllegalStateException("-server param but no value");
80 return args.length > 2;
81 }
82 return args.length > 0;
83 }
84
85
86
87
88
89 public static void main(String args[]) throws Exception {
90 String [] newArgs = args;
91 if (!hasServer(args)) {
92
93 Configuration conf = HBaseConfiguration.create();
94 String hostport = new ZooKeeperMainServer().parse(conf);
95 if (hostport != null && hostport.length() > 0) {
96 newArgs = new String[args.length + 2];
97 System.arraycopy(args, 0, newArgs, 2, args.length);
98 newArgs[0] = "-server";
99 newArgs[1] = hostport;
100 }
101 }
102
103 if (hasCommandLineArguments(args)) {
104 HACK_UNTIL_ZOOKEEPER_1897_ZooKeeperMain zkm =
105 new HACK_UNTIL_ZOOKEEPER_1897_ZooKeeperMain(newArgs);
106 zkm.runCmdLine();
107 } else {
108 ZooKeeperMain.main(newArgs);
109 }
110 }
111 }