1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.omid;
19
20 import com.google.inject.AbstractModule;
21 import com.google.inject.Provides;
22 import org.apache.omid.tools.hbase.HBaseLogin;
23 import org.apache.omid.tools.hbase.SecureHBaseConfig;
24 import org.apache.hadoop.conf.Configuration;
25 import org.apache.hadoop.hbase.HBaseConfiguration;
26
27 import java.io.IOException;
28
29 public class HBaseConfigModule extends AbstractModule {
30
31 private String principal;
32 private String keytab;
33
34 public HBaseConfigModule(String principal, String keytab) {
35 this.principal = principal;
36 this.keytab = keytab;
37 }
38
39 @Override
40 protected void configure() {
41 }
42
43 @Provides
44 public Configuration provideHBaseConfig() throws IOException {
45 Configuration configuration = HBaseConfiguration.create();
46 SecureHBaseConfig secureHBaseConfig = new SecureHBaseConfig();
47 secureHBaseConfig.setKeytab(keytab);
48 secureHBaseConfig.setPrincipal(principal);
49 HBaseLogin.loginIfNeeded(secureHBaseConfig);
50 return configuration;
51
52 }
53
54
55
56
57
58
59
60 @Override
61 public boolean equals(Object o) {
62
63 if (this == o) return true;
64
65 if (o == null || getClass() != o.getClass()) return false;
66
67 HBaseConfigModule that = (HBaseConfigModule) o;
68
69 if (principal != null ? !principal.equals(that.principal) : that.principal != null) return false;
70 return keytab != null ? keytab.equals(that.keytab) : that.keytab == null;
71
72 }
73
74 @Override
75 public int hashCode() {
76
77 int result = principal != null ? principal.hashCode() : 0;
78 result = 31 * result + (keytab != null ? keytab.hashCode() : 0);
79 return result;
80
81 }
82
83 }