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