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