View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.omid.transaction;
19  
20  import com.google.common.annotations.VisibleForTesting;
21  import com.google.inject.Inject;
22  import com.google.inject.name.Named;
23  import org.apache.omid.YAMLUtils;
24  import org.apache.omid.metrics.MetricsRegistry;
25  import org.apache.omid.tools.hbase.SecureHBaseConfig;
26  import org.apache.omid.tso.client.OmidClientConfiguration.PostCommitMode;
27  import org.apache.omid.tso.client.OmidClientConfiguration;
28  import org.apache.hadoop.conf.Configuration;
29  import org.apache.hadoop.hbase.HBaseConfiguration;
30  
31  /**
32   * Configuration for HBase's Omid client side
33   */
34  public class HBaseOmidClientConfiguration extends SecureHBaseConfig {
35  
36      private static final String DEFAULT_CONFIG_FILE_NAME = "default-hbase-omid-client-config.yml";
37      private static final String CONFIG_FILE_NAME = "hbase-omid-client-config.yml";
38      private Configuration hbaseConfiguration = HBaseConfiguration.create();
39      private String commitTableName;
40      @Inject
41      private OmidClientConfiguration omidClientConfiguration;
42      private MetricsRegistry metrics;
43  
44      // ----------------------------------------------------------------------------------------------------------------
45      // Instantiation
46      // ----------------------------------------------------------------------------------------------------------------
47      public HBaseOmidClientConfiguration() {
48          this(CONFIG_FILE_NAME);
49      }
50  
51      @VisibleForTesting
52      HBaseOmidClientConfiguration(String configFileName) {
53          new YAMLUtils().loadSettings(configFileName, DEFAULT_CONFIG_FILE_NAME, this);
54      }
55  
56      // ----------------------------------------------------------------------------------------------------------------
57      // Getters and setters for config params
58      // ----------------------------------------------------------------------------------------------------------------
59  
60      public Configuration getHBaseConfiguration() {
61          return hbaseConfiguration;
62      }
63  
64      public void setHBaseConfiguration(Configuration hbaseConfiguration) {
65          this.hbaseConfiguration = hbaseConfiguration;
66      }
67  
68      public PostCommitMode getPostCommitMode() {
69          return omidClientConfiguration.getPostCommitMode();
70      }
71  
72      public void setPostCommitMode(PostCommitMode postCommitMode) {
73          omidClientConfiguration.setPostCommitMode(postCommitMode);
74      }
75  
76      public String getCommitTableName() {
77          return commitTableName;
78      }
79  
80      @Inject(optional = true)
81      @Named("omid.client.hbase.commitTableName")
82      public void setCommitTableName(String commitTableName) {
83          this.commitTableName = commitTableName;
84      }
85  
86      public OmidClientConfiguration getOmidClientConfiguration() {
87          return omidClientConfiguration;
88      }
89  
90      public void setOmidClientConfiguration(OmidClientConfiguration omidClientConfiguration) {
91          this.omidClientConfiguration = omidClientConfiguration;
92      }
93  
94      public MetricsRegistry getMetrics() {
95          return metrics;
96      }
97  
98      @Inject(optional = true)
99      @Named("omid.client.hbase.metrics")
100     public void setMetrics(MetricsRegistry metrics) {
101         this.metrics = metrics;
102     }
103 
104     // Delegation to make end-user life better
105 
106     public OmidClientConfiguration.ConnType getConnectionType() {
107         return omidClientConfiguration.getConnectionType();
108     }
109 
110     public void setReconnectionDelayInSecs(int reconnectionDelayInSecs) {
111         omidClientConfiguration.setReconnectionDelayInSecs(reconnectionDelayInSecs);
112     }
113 
114     public void setExecutorThreads(int executorThreads) {
115         omidClientConfiguration.setExecutorThreads(executorThreads);
116     }
117 
118     public int getRequestTimeoutInMs() {
119         return omidClientConfiguration.getRequestTimeoutInMs();
120     }
121 
122     public void setConnectionString(String connectionString) {
123         omidClientConfiguration.setConnectionString(connectionString);
124     }
125 
126     public void setRequestTimeoutInMs(int requestTimeoutInMs) {
127         omidClientConfiguration.setRequestTimeoutInMs(requestTimeoutInMs);
128     }
129 
130     public void setZkConnectionTimeoutInSecs(int zkConnectionTimeoutInSecs) {
131         omidClientConfiguration.setZkConnectionTimeoutInSecs(zkConnectionTimeoutInSecs);
132     }
133 
134     public void setConnectionType(OmidClientConfiguration.ConnType connectionType) {
135         omidClientConfiguration.setConnectionType(connectionType);
136     }
137 
138     public void setRequestMaxRetries(int requestMaxRetries) {
139         omidClientConfiguration.setRequestMaxRetries(requestMaxRetries);
140     }
141 
142     public int getZkConnectionTimeoutInSecs() {
143         return omidClientConfiguration.getZkConnectionTimeoutInSecs();
144     }
145 
146     public void setRetryDelayInMs(int retryDelayInMs) {
147         omidClientConfiguration.setRetryDelayInMs(retryDelayInMs);
148     }
149 
150     public int getExecutorThreads() {
151         return omidClientConfiguration.getExecutorThreads();
152     }
153 
154     public int getRetryDelayInMs() {
155         return omidClientConfiguration.getRetryDelayInMs();
156     }
157 
158     public String getConnectionString() {
159         return omidClientConfiguration.getConnectionString();
160     }
161 
162     public int getRequestMaxRetries() {
163         return omidClientConfiguration.getRequestMaxRetries();
164     }
165 
166     public int getReconnectionDelayInSecs() {
167         return omidClientConfiguration.getReconnectionDelayInSecs();
168     }
169 
170 }