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.tso;
19  
20  import com.google.inject.AbstractModule;
21  import com.google.inject.Provides;
22  import com.google.inject.name.Names;
23  import org.apache.omid.HBaseConfigModule;
24  import org.apache.omid.timestamp.storage.HBaseTimestampStorageConfig;
25  import org.apache.omid.tso.LeaseManagement.LeaseManagementException;
26  import org.slf4j.Logger;
27  import org.slf4j.LoggerFactory;
28  
29  import javax.inject.Singleton;
30  
31  import static org.apache.omid.timestamp.storage.HBaseTimestampStorageConfig.DEFAULT_TIMESTAMP_STORAGE_TABLE_NAME;
32  
33  public class VoidLeaseManagementModule extends AbstractModule {
34      private static final Logger LOG = LoggerFactory.getLogger(VoidLeaseManagementModule.class);
35      private String keytab;
36      private String principal;
37      private String tableName = DEFAULT_TIMESTAMP_STORAGE_TABLE_NAME;
38  
39      @Override
40      protected void configure() {
41          LOG.info(this.toString());
42          bindConstant().annotatedWith(Names.named(HBaseTimestampStorageConfig.TIMESTAMP_STORAGE_TABLE_NAME_KEY)).to(tableName);
43          install(new HBaseConfigModule(principal, keytab));
44      }
45  
46      @Provides
47      @Singleton
48      LeaseManagement provideLeaseManager(TSOChannelHandler tsoChannelHandler, TSOStateManager stateManager)
49              throws LeaseManagementException {
50  
51          return new VoidLeaseManager(tsoChannelHandler, stateManager);
52  
53      }
54  
55      // ----------------------------------------------------------------------------------------------------------------
56      // WARNING: Do not remove getters/setters, needed by snake_yaml!
57      // ----------------------------------------------------------------------------------------------------------------
58  
59      public String getTableName() {
60          return tableName;
61      }
62  
63      public void setTableName(String tableName) {
64          this.tableName = tableName;
65      }
66  
67      public String getPrincipal() {
68          return principal;
69      }
70  
71      public void setPrincipal(String principal) {
72          this.principal = principal;
73      }
74  
75      public String getKeytab() {
76          return keytab;
77      }
78  
79      public void setKeytab(String keytab) {
80          this.keytab = keytab;
81      }
82  
83      @Override
84      public String toString() {
85          final StringBuilder sb = new StringBuilder("VoidLeaseManagementModule{");
86          sb.append("keytab='").append(keytab).append('\'');
87          sb.append(", principal='").append(principal).append('\'');
88          sb.append(", tableName='").append(tableName).append('\'');
89          sb.append('}');
90          return sb.toString();
91      }
92  }