
org.frameworkset.nosql.hbase.HbaseConfigurationFactoryBean Maven / Gradle / Ivy
Show all versions of bboss-datatran-hbase Show documentation
/**
* Copyright 2008 biaoping.yin
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.frameworkset.nosql.hbase;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import java.util.Iterator;
import java.util.Map;
/**
* Factory for creating HBase specific configuration. By default cleans up any connection associated with the current configuration.
*
* @author Costin Leau
*/
public class HbaseConfigurationFactoryBean{
private Configuration configuration;
private Configuration hadoopConfig;
private Map properties;
/**
* Sets the Hadoop configuration to use.
*
* @param configuration The configuration to set.
*/
public void setConfiguration(Configuration configuration) {
this.hadoopConfig = configuration;
}
/**
* Sets the configuration properties.
*
* @param properties The properties to set.
*/
public void setProperties(Map properties) {
this.properties = properties;
}
public void afterPropertiesSet() {
configuration = (hadoopConfig != null ? HBaseConfiguration.create(hadoopConfig) : HBaseConfiguration.create());
addProperties(configuration, properties);
// //刷新kgt
// try {
//
// /* configuration.set("hadoop.security.authentication", "Kerberos");
// configuration.set("keytab.file", "/app/apm/consumer/config/user.keytab");
// configuration.set("kerberos.principal", "[email protected]");*/
//
// String user = configuration.get("kerberos.principal");
// String path = configuration.get("keytab.file");
// long interval = Long.parseLong(configuration.get("kerberos.refresh.interval"));
// System.out.println("333333333>>> user:"+ user+",path:"+path+",interval:"+interval);
// UserGroupInformation.setConfiguration(configuration);
//
// UserGroupInformation.loginUserFromKeytab(user, path);
//
// HbaseKerberosLogin login = new HbaseKerberosLogin();
// login.autoRefreshThreadForKbTgt(interval);
// }catch(Exception e){
// System.out.println("刷新tgt失败");
// e.printStackTrace();
// }
}
/**
* Adds the specified properties to the given {@link Configuration} object.
*
* @param configuration configuration to manipulate. Should not be null.
* @param properties properties to add to the configuration. May be null.
*/
private void addProperties(Configuration configuration, Map properties) {
// Assert.notNull(configuration, "A non-null configuration is required");
if (properties != null && properties.size() > 0) {
Iterator> props = properties.entrySet().iterator();
while (props.hasNext()) {
Map.Entry entry = props.next();
String key = entry.getKey();
configuration.set(key, entry.getValue());
}
}
}
public Configuration getConfiguration() {
return configuration;
}
}