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.http;
21
22 import java.io.IOException;
23 import java.net.URI;
24
25 import javax.servlet.http.HttpServlet;
26
27 import org.apache.hadoop.hbase.classification.InterfaceAudience;
28 import org.apache.hadoop.conf.Configuration;
29
30
31
32
33
34
35
36
37
38 @InterfaceAudience.Private
39 public class InfoServer {
40
41 private static final String HBASE_APP_DIR = "hbase-webapps";
42 private final org.apache.hadoop.hbase.http.HttpServer httpServer;
43
44
45
46
47
48
49
50
51
52
53
54 public InfoServer(String name, String bindAddress, int port, boolean findPort,
55 final Configuration c)
56 throws IOException {
57 HttpConfig httpConfig = new HttpConfig(c);
58 HttpServer.Builder builder =
59 new org.apache.hadoop.hbase.http.HttpServer.Builder();
60
61 builder.setName(name).addEndpoint(URI.create(httpConfig.getSchemePrefix() +
62 bindAddress + ":" +
63 port)).setAppDir(HBASE_APP_DIR).setFindPort(findPort).setConf(c);
64 String logDir = System.getProperty("hbase.log.dir");
65 if (logDir != null) {
66 builder.setLogDir(logDir);
67 }
68 if (httpConfig.isSecure()) {
69 builder.keyPassword(c.get("ssl.server.keystore.keypassword"))
70 .keyStore(c.get("ssl.server.keystore.location"),
71 c.get("ssl.server.keystore.password"),
72 c.get("ssl.server.keystore.type", "jks"))
73 .trustStore(c.get("ssl.server.truststore.location"),
74 c.get("ssl.server.truststore.password"),
75 c.get("ssl.server.truststore.type", "jks"));
76 }
77
78 if ("kerberos".equalsIgnoreCase(c.get(HttpServer.HTTP_UI_AUTHENTICATION, null))) {
79 builder.setUsernameConfKey(HttpServer.HTTP_SPNEGO_AUTHENTICATION_PRINCIPAL_KEY)
80 .setKeytabConfKey(HttpServer.HTTP_SPNEGO_AUTHENTICATION_KEYTAB_KEY)
81 .setKerberosNameRulesKey(HttpServer.HTTP_SPNEGO_AUTHENTICATION_KRB_NAME_KEY)
82 .setSignatureSecretFileKey(
83 HttpServer.HTTP_AUTHENTICATION_SIGNATURE_SECRET_FILE_KEY)
84 .setSecurityEnabled(true);
85 }
86 this.httpServer = builder.build();
87 }
88
89 public void addServlet(String name, String pathSpec,
90 Class<? extends HttpServlet> clazz) {
91 this.httpServer.addServlet(name, pathSpec, clazz);
92 }
93
94 public void setAttribute(String name, Object value) {
95 this.httpServer.setAttribute(name, value);
96 }
97
98 public void start() throws IOException {
99 this.httpServer.start();
100 }
101
102 @Deprecated
103 public int getPort() {
104 return this.httpServer.getPort();
105 }
106
107 public void stop() throws Exception {
108 this.httpServer.stop();
109 }
110
111 }