1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.omid.transaction;
19
20 import org.apache.phoenix.thirdparty.com.google.common.annotations.VisibleForTesting;
21 import com.google.inject.Inject;
22 import com.google.inject.name.Named;
23 import org.apache.commons.beanutils.BeanUtils;
24 import org.apache.omid.YAMLUtils;
25 import org.apache.omid.metrics.MetricsRegistry;
26 import org.apache.omid.tools.hbase.SecureHBaseConfig;
27 import org.apache.omid.tso.client.OmidClientConfiguration.ConflictDetectionLevel;
28 import org.apache.omid.tso.client.OmidClientConfiguration.PostCommitMode;
29 import org.apache.omid.tso.client.OmidClientConfiguration;
30 import org.apache.hadoop.conf.Configuration;
31 import org.apache.hadoop.hbase.HBaseConfiguration;
32
33 import java.lang.reflect.InvocationTargetException;
34 import java.util.Map;
35
36
37
38
39 public class HBaseOmidClientConfiguration extends SecureHBaseConfig {
40
41 private static final String DEFAULT_CONFIG_FILE_NAME = "default-hbase-omid-client-config.yml";
42 private static final String CONFIG_FILE_NAME = "hbase-omid-client-config.yml";
43 private Configuration hbaseConfiguration = HBaseConfiguration.create();
44 private String commitTableName;
45 @Inject
46 private OmidClientConfiguration omidClientConfiguration;
47 private MetricsRegistry metrics;
48
49
50
51
52
53 public static HBaseOmidClientConfiguration loadFromString(String yamlContent) {
54 return new HBaseOmidClientConfiguration(new YAMLUtils().loadStringAsMap(yamlContent));
55 }
56
57 public HBaseOmidClientConfiguration() {
58 this(CONFIG_FILE_NAME);
59 }
60
61 public <K, V> HBaseOmidClientConfiguration(Map<String, ? extends Object> properties) {
62 try {
63 BeanUtils.populate(this, properties);
64 } catch (IllegalAccessException | InvocationTargetException e) {
65 throw new IllegalStateException(e);
66 }
67 }
68
69 @VisibleForTesting
70 HBaseOmidClientConfiguration(String configFileName) {
71 new YAMLUtils().loadSettings(configFileName, DEFAULT_CONFIG_FILE_NAME, this);
72 }
73
74
75
76
77
78 public Configuration getHBaseConfiguration() {
79 return hbaseConfiguration;
80 }
81
82 public void setHBaseConfiguration(Configuration hbaseConfiguration) {
83 this.hbaseConfiguration = hbaseConfiguration;
84 }
85
86 public PostCommitMode getPostCommitMode() {
87 return omidClientConfiguration.getPostCommitMode();
88 }
89
90 public void setPostCommitMode(PostCommitMode postCommitMode) {
91 omidClientConfiguration.setPostCommitMode(postCommitMode);
92 }
93
94 public ConflictDetectionLevel getConflictAnalysisLevel() {
95 return omidClientConfiguration.getConflictAnalysisLevel();
96 }
97
98 public void setConflictAnalysisLevel(ConflictDetectionLevel conflictAnalysisLevel) {
99 omidClientConfiguration.setConflictAnalysisLevel(conflictAnalysisLevel);
100 }
101
102 public String getCommitTableName() {
103 return commitTableName;
104 }
105
106 @Inject(optional = true)
107 @Named("omid.client.hbase.commitTableName")
108 public void setCommitTableName(String commitTableName) {
109 this.commitTableName = commitTableName;
110 }
111
112 public OmidClientConfiguration getOmidClientConfiguration() {
113 return omidClientConfiguration;
114 }
115
116 public void setOmidClientConfiguration(OmidClientConfiguration omidClientConfiguration) {
117 this.omidClientConfiguration = omidClientConfiguration;
118 }
119
120 public MetricsRegistry getMetrics() {
121 return metrics;
122 }
123
124 @Inject(optional = true)
125 @Named("omid.client.hbase.metrics")
126 public void setMetrics(MetricsRegistry metrics) {
127 this.metrics = metrics;
128 }
129
130
131
132 public OmidClientConfiguration.ConnType getConnectionType() {
133 return omidClientConfiguration.getConnectionType();
134 }
135
136 public void setReconnectionDelayInSecs(int reconnectionDelayInSecs) {
137 omidClientConfiguration.setReconnectionDelayInSecs(reconnectionDelayInSecs);
138 }
139
140 public void setExecutorThreads(int executorThreads) {
141 omidClientConfiguration.setExecutorThreads(executorThreads);
142 }
143
144 public int getRequestTimeoutInMs() {
145 return omidClientConfiguration.getRequestTimeoutInMs();
146 }
147
148 public void setConnectionString(String connectionString) {
149 omidClientConfiguration.setConnectionString(connectionString);
150 }
151
152 public void setRequestTimeoutInMs(int requestTimeoutInMs) {
153 omidClientConfiguration.setRequestTimeoutInMs(requestTimeoutInMs);
154 }
155
156 public void setZkConnectionTimeoutInSecs(int zkConnectionTimeoutInSecs) {
157 omidClientConfiguration.setZkConnectionTimeoutInSecs(zkConnectionTimeoutInSecs);
158 }
159
160 public void setConnectionType(OmidClientConfiguration.ConnType connectionType) {
161 omidClientConfiguration.setConnectionType(connectionType);
162 }
163
164 public void setRequestMaxRetries(int requestMaxRetries) {
165 omidClientConfiguration.setRequestMaxRetries(requestMaxRetries);
166 }
167
168 public int getZkConnectionTimeoutInSecs() {
169 return omidClientConfiguration.getZkConnectionTimeoutInSecs();
170 }
171
172 public void setRetryDelayInMs(int retryDelayInMs) {
173 omidClientConfiguration.setRetryDelayInMs(retryDelayInMs);
174 }
175
176 public int getExecutorThreads() {
177 return omidClientConfiguration.getExecutorThreads();
178 }
179
180 public int getRetryDelayInMs() {
181 return omidClientConfiguration.getRetryDelayInMs();
182 }
183
184 public String getConnectionString() {
185 return omidClientConfiguration.getConnectionString();
186 }
187
188 public int getRequestMaxRetries() {
189 return omidClientConfiguration.getRequestMaxRetries();
190 }
191
192 public int getReconnectionDelayInSecs() {
193 return omidClientConfiguration.getReconnectionDelayInSecs();
194 }
195
196 }