1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.omid.tso;
19
20 import org.apache.phoenix.thirdparty.com.google.common.annotations.VisibleForTesting;
21 import com.google.inject.AbstractModule;
22 import com.google.inject.Provides;
23 import org.apache.curator.framework.CuratorFramework;
24 import org.apache.omid.timestamp.storage.ZKModule;
25 import org.apache.omid.tso.LeaseManagement.LeaseManagementException;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28
29 import javax.inject.Named;
30 import javax.inject.Singleton;
31
32 import static org.apache.omid.tso.TSOServer.TSO_HOST_AND_PORT_KEY;
33
34 public class HALeaseManagementModule extends AbstractModule {
35
36 private static final Logger LOG = LoggerFactory.getLogger(HALeaseManagementModule.class);
37
38 private long leasePeriodInMs = 10_000;
39 private String tsoLeasePath = "/tso-lease";
40 private String currentTsoPath = "/current-tso";
41 private String zkCluster = "localhost:2181";
42 private String zkNamespace = "omid";
43
44
45
46
47
48 public HALeaseManagementModule() {
49
50 }
51
52 @VisibleForTesting
53 public HALeaseManagementModule(long leasePeriodInMs, String tsoLeasePath, String currentTsoPath,
54 String zkCluster, String zkNamespace) {
55
56 this.leasePeriodInMs = leasePeriodInMs;
57 this.tsoLeasePath = tsoLeasePath;
58 this.currentTsoPath = currentTsoPath;
59 this.zkCluster = zkCluster;
60 this.zkNamespace = zkNamespace;
61
62 }
63
64 @Override
65 protected void configure() {
66
67 install(new ZKModule(zkCluster, zkNamespace));
68
69 }
70
71 @Provides
72 @Singleton
73 LeaseManagement provideLeaseManager(@Named(TSO_HOST_AND_PORT_KEY) String tsoHostAndPort,
74 TSOChannelHandler tsoChannelHandler,
75 TSOStateManager stateManager,
76 CuratorFramework zkClient,
77 Panicker panicker) throws LeaseManagementException {
78
79 LOG.info("Connection to HA cluster [{}]", zkClient.getState());
80
81 return new LeaseManager(tsoHostAndPort,
82 tsoChannelHandler,
83 stateManager,
84 leasePeriodInMs,
85 tsoLeasePath,
86 currentTsoPath,
87 zkClient,
88 panicker);
89
90 }
91
92
93
94
95
96 public String getCurrentTsoPath() {
97 return currentTsoPath;
98 }
99
100 public void setCurrentTsoPath(String currentTsoPath) {
101 this.currentTsoPath = currentTsoPath;
102 }
103
104 public long getLeasePeriodInMs() {
105 return leasePeriodInMs;
106 }
107
108 public void setLeasePeriodInMs(long leasePeriodInMs) {
109 this.leasePeriodInMs = leasePeriodInMs;
110 }
111
112 public String getTsoLeasePath() {
113 return tsoLeasePath;
114 }
115
116 public void setTsoLeasePath(String tsoLeasePath) {
117 this.tsoLeasePath = tsoLeasePath;
118 }
119
120 public String getZkCluster() {
121 return zkCluster;
122 }
123
124 public void setZkCluster(String zkCluster) {
125 this.zkCluster = zkCluster;
126 }
127
128 public String getZkNamespace() {
129 return zkNamespace;
130 }
131
132 public void setZkNamespace(String zkNamespace) {
133 this.zkNamespace = zkNamespace;
134 }
135
136 }