Java Code Examples for org.apache.hadoop.hbase.client.HConnectionManager#createConnection()
The following examples show how to use
org.apache.hadoop.hbase.client.HConnectionManager#createConnection() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Merge.java From hbase-tools with Apache License 2.0 | 6 votes |
public Merge(HBaseAdmin admin, Args args) throws IOException { if (args.getOptionSet().nonOptionArguments().size() < 2 || args.getOptionSet().nonOptionArguments().size() > 3) { // todo refactoring throw new RuntimeException(Args.INVALID_ARGUMENTS); } this.admin = admin; this.args = args; if (args.has(Args.OPTION_TEST)) this.test = true; actionParam = (String) args.getOptionSet().nonOptionArguments().get(2); this.connection = HConnectionManager.createConnection(admin.getConfiguration()); tableNameSet = Util.parseTableSet(admin, args); if (args.has(Args.OPTION_PHOENIX)) this.isPhoenixSaltingTable = true; }
Example 2
Source File: HBaseConfigurationUtil.java From opensoc-streaming with Apache License 2.0 | 6 votes |
/** * Creates the cluster conncetion. * * @throws IOException * Signals that an I/O exception has occurred. */ private static void createClusterConncetion() throws IOException { try { if (connectionAvailable()) { return; } clusterConnection = HConnectionManager.createConnection(read()); addShutdownHook(); System.out.println("Created HConnection and added shutDownHook"); } catch (IOException e) { LOGGER .error( "Exception occurred while creating HConnection using HConnectionManager", e); throw e; } }
Example 3
Source File: CIFHbaseAdapter.java From opensoc-streaming with Apache License 2.0 | 6 votes |
@Override public boolean initializeAdapter() { // Initialize HBase Table Configuration conf = null; conf = HBaseConfiguration.create(); conf.set("hbase.zookeeper.quorum", _quorum); conf.set("hbase.zookeeper.property.clientPort", _port); try { LOGGER.debug("=======Connecting to HBASE==========="); LOGGER.debug("=======ZOOKEEPER = " + conf.get("hbase.zookeeper.quorum")); HConnection connection = HConnectionManager.createConnection(conf); table = connection.getTable(_tableName); return true; } catch (IOException e) { // TODO Auto-generated catch block LOGGER.debug("=======Unable to Connect to HBASE==========="); e.printStackTrace(); } return false; }
Example 4
Source File: HBaseConnection.java From Kylin with Apache License 2.0 | 6 votes |
public static HConnection get(String url) { // find configuration Configuration conf = ConfigCache.get(url); if (conf == null) { conf = HadoopUtil.newHBaseConfiguration(url); ConfigCache.put(url, conf); } HConnection connection = ConnPool.get(url); try { // I don't use DCL since recreate a connection is not a big issue. if (connection == null) { connection = HConnectionManager.createConnection(conf); ConnPool.put(url, connection); } } catch (Throwable t) { throw new StorageException("Error when open connection " + url, t); } return connection; }
Example 5
Source File: DataJanitorStateTest.java From phoenix-tephra with Apache License 2.0 | 6 votes |
@Before public void beforeTest() throws Exception { pruneStateTable = TableName.valueOf(conf.get(TxConstants.TransactionPruning.PRUNE_STATE_TABLE, TxConstants.TransactionPruning.DEFAULT_PRUNE_STATE_TABLE)); HTable table = createTable(pruneStateTable.getName(), new byte[][]{DataJanitorState.FAMILY}, false, // Prune state table is a non-transactional table, hence no transaction co-processor Collections.<String>emptyList()); table.close(); connection = HConnectionManager.createConnection(conf); dataJanitorState = new DataJanitorState(new DataJanitorState.TableSupplier() { @Override public HTableInterface get() throws IOException { return connection.getTable(pruneStateTable); } }); }
Example 6
Source File: HBaseTransactionPruningPlugin.java From phoenix-tephra with Apache License 2.0 | 6 votes |
@Override public void initialize(Configuration conf) throws IOException { this.conf = conf; this.hBaseAdmin = new HBaseAdmin(conf); this.connection = HConnectionManager.createConnection(conf); final TableName stateTable = TableName.valueOf(conf.get(TxConstants.TransactionPruning.PRUNE_STATE_TABLE, TxConstants.TransactionPruning.DEFAULT_PRUNE_STATE_TABLE)); LOG.info("Initializing plugin with state table {}:{}", stateTable.getNamespaceAsString(), stateTable.getNameAsString()); createPruneTable(stateTable); this.dataJanitorState = new DataJanitorState(new DataJanitorState.TableSupplier() { @Override public HTableInterface get() throws IOException { return connection.getTable(stateTable); } }); }
Example 7
Source File: HBaseConfigurationUtil.java From opensoc-streaming with Apache License 2.0 | 6 votes |
/** * Creates the cluster conncetion. * * @throws IOException * Signals that an I/O exception has occurred. */ private static void createClusterConncetion() throws IOException { try { if (connectionAvailable()) { return; } clusterConnection = HConnectionManager.createConnection(read()); addShutdownHook(); System.out.println("Created HConnection and added shutDownHook"); } catch (IOException e) { LOGGER .error( "Exception occurred while creating HConnection using HConnectionManager", e); throw e; } }
Example 8
Source File: HBaseTransactionPruningPlugin.java From phoenix-tephra with Apache License 2.0 | 6 votes |
@Override public void initialize(Configuration conf) throws IOException { this.conf = conf; this.hBaseAdmin = new HBaseAdmin(conf); this.connection = HConnectionManager.createConnection(conf); final TableName stateTable = TableName.valueOf(conf.get(TxConstants.TransactionPruning.PRUNE_STATE_TABLE, TxConstants.TransactionPruning.DEFAULT_PRUNE_STATE_TABLE)); LOG.info("Initializing plugin with state table {}:{}", stateTable.getNamespaceAsString(), stateTable.getNameAsString()); createPruneTable(stateTable); this.dataJanitorState = new DataJanitorState(new DataJanitorState.TableSupplier() { @Override public HTableInterface get() throws IOException { return connection.getTable(stateTable); } }); }
Example 9
Source File: HBaseAction.java From DDMQ with Apache License 2.0 | 6 votes |
public HBaseAction(ConsumerGroupConfig consumerGroupConfig) { group = consumerGroupConfig.getGroup(); for (String topic : consumerGroupConfig.getTopicMap().keySet()) { UpstreamTopic upstreamTopic = consumerGroupConfig.getTopicMap().get(topic); if (upstreamTopic.getHbaseconfiguration() != null) { // create hbase connection. Configuration configuration = HBaseConfiguration.create(); configuration.set(HbaseConst.ZK_QUORUM, upstreamTopic.getHbaseconfiguration().getHbaseZK()); configuration.set(HbaseConst.ZK_CLIENT_PORT, upstreamTopic.getHbaseconfiguration().getHbasePort()); configuration.set(HbaseConst.CLIENT_BUFFER, upstreamTopic.getHbaseconfiguration().getHbaseBuffer()); configuration.set(HbaseConst.USER_NAME, upstreamTopic.getHbaseconfiguration().getUser()); configuration.set(HbaseConst.PASSWORD, upstreamTopic.getHbaseconfiguration().getPassword()); try { HBaseConnection HBaseConnection = new HBaseConnection(HConnectionManager.createConnection(configuration)); connectionMap.put(topic, HBaseConnection); } catch (IOException e) { LogUtils.logErrorInfo("HBASE_error", "failed to create hbase connection, ", e); } } } }
Example 10
Source File: HBaseClientManager.java From bigdata-tutorial with Apache License 2.0 | 5 votes |
public synchronized HConnection getConn() { if (null == conn) { try { this.conn = HConnectionManager.createConnection(config); } catch (Exception ex) { LOGGER.error("create conn err:", ex); } } return conn; }
Example 11
Source File: TestHBaseDAO.java From DistributedCrawler with Apache License 2.0 | 5 votes |
@Test public void testPut() throws IOException { Configuration configuration = HBaseConfiguration.create(); HConnection connection = HConnectionManager.createConnection(configuration); HTableInterface table = connection.getTable("page"); // use the table as needed, for a single operation and a single thread Put put = new Put("2".getBytes()); put.add("content".getBytes(), null, "我吃包子".getBytes()); put.add("title".getBytes(), null, "吃包子".getBytes()); put.add("url".getBytes(), null, "http://www.sina.com.cn".getBytes()); table.put(put); table.close(); connection.close(); }
Example 12
Source File: InvalidListPruneTest.java From phoenix-tephra with Apache License 2.0 | 5 votes |
@BeforeClass public static void startMiniCluster() throws Exception { // Setup the configuration to start HBase cluster with the invalid list pruning enabled conf = HBaseConfiguration.create(); conf.setBoolean(TxConstants.TransactionPruning.PRUNE_ENABLE, true); // Flush prune data to table quickly, so that tests don't need have to wait long to see updates conf.setLong(TxConstants.TransactionPruning.PRUNE_FLUSH_INTERVAL, 0L); AbstractHBaseTableTest.startMiniCluster(); TransactionStateStorage txStateStorage = new InMemoryTransactionStateStorage(); TransactionManager txManager = new TransactionManager(conf, txStateStorage, new TxMetricsCollector()); txManager.startAndWait(); // Do some transactional data operations txDataTable1 = TableName.valueOf("invalidListPruneTestTable1"); HTable hTable = createTable(txDataTable1.getName(), new byte[][]{family}, false, Collections.singletonList(TestTransactionProcessor.class.getName())); try (TransactionAwareHTable txTable = new TransactionAwareHTable(hTable, TxConstants.ConflictDetection.ROW)) { TransactionContext txContext = new TransactionContext(new InMemoryTxSystemClient(txManager), txTable); txContext.start(); for (int i = 0; i < MAX_ROWS; ++i) { txTable.put(new Put(Bytes.toBytes(i)).add(family, qualifier, Bytes.toBytes(i))); } txContext.finish(); } testUtil.flush(txDataTable1); txManager.stopAndWait(); pruneStateTable = TableName.valueOf(conf.get(TxConstants.TransactionPruning.PRUNE_STATE_TABLE, TxConstants.TransactionPruning.DEFAULT_PRUNE_STATE_TABLE)); connection = HConnectionManager.createConnection(conf); dataJanitorState = new DataJanitorState(new DataJanitorState.TableSupplier() { @Override public HTableInterface get() throws IOException { return connection.getTable(pruneStateTable); } }); }
Example 13
Source File: WhoisHBaseAdapter.java From opensoc-streaming with Apache License 2.0 | 5 votes |
public boolean initializeAdapter() { Configuration conf = null; conf = HBaseConfiguration.create(); conf.set("hbase.zookeeper.quorum", _quorum); conf.set("hbase.zookeeper.property.clientPort", _port); conf.set("zookeeper.session.timeout", "20"); conf.set("hbase.rpc.timeout", "20"); conf.set("zookeeper.recovery.retry", "1"); conf.set("zookeeper.recovery.retry.intervalmill", "1"); try { LOG.trace("[OpenSOC] Connecting to HBase"); LOG.trace("[OpenSOC] ZOOKEEPER = " + conf.get("hbase.zookeeper.quorum")); LOG.trace("[OpenSOC] CONNECTING TO HBASE WITH: " + conf); HConnection connection = HConnectionManager.createConnection(conf); LOG.trace("[OpenSOC] CONNECTED TO HBASE"); table = connection.getTable(_table_name); LOG.trace("--------CONNECTED TO TABLE: " + table); JSONObject tester = enrich("cisco.com"); if (tester.keySet().size() == 0) throw new IOException( "Either HBASE is misconfigured or whois table is missing"); return true; } catch (IOException e) { e.printStackTrace(); } return false; }
Example 14
Source File: HBaseTablespace.java From tajo with Apache License 2.0 | 5 votes |
public HConnection getConnection() throws IOException { synchronized(connMap) { HConnectionKey key = new HConnectionKey(hbaseConf); HConnection conn = connMap.get(key); if (conn == null) { conn = HConnectionManager.createConnection(hbaseConf); connMap.put(key, conn); } return conn; } }
Example 15
Source File: HConnectionController.java From recsys-offline with Apache License 2.0 | 5 votes |
public HConnection getHConnection() { HConnection con = null; try { if (null == con || con.isClosed()) { con = HConnectionManager.createConnection(config); } } catch (IOException e) { logger.error("Cannot get HBase connection.", e.getCause()); } return con; }
Example 16
Source File: HBaseSimpleDemo.java From bigdata-tutorial with Apache License 2.0 | 5 votes |
public HConnection openConn() { if (null == hconn) { try { this.hconn = HConnectionManager.createConnection(config); } catch (Exception ex) { ex.printStackTrace(); } } return hconn; }
Example 17
Source File: HConnectionFactory.java From phoenix with Apache License 2.0 | 4 votes |
@Override public HConnection createConnection(Configuration conf) throws IOException { return HConnectionManager.createConnection(conf); }
Example 18
Source File: HBaseCompat0_98.java From incubator-atlas with Apache License 2.0 | 4 votes |
@Override public ConnectionMask createConnection(Configuration conf) throws IOException { return new HConnection0_98(HConnectionManager.createConnection(conf)); }
Example 19
Source File: TestBase.java From hbase-tools with Apache License 2.0 | 4 votes |
@BeforeClass public static void setUpOnce() throws Exception { miniCluster = System.getProperty("cluster.type").equals("mini"); securedCluster = System.getProperty("cluster.secured").equals("true"); System.out.println("realCluster - " + !miniCluster); System.out.println("securedCluster - " + securedCluster); Util.setLoggingThreshold("ERROR"); if (miniCluster) { if (hbase == null) { conf = HBaseConfiguration.create(new Configuration(true)); conf.setInt("hbase.master.info.port", -1); conf.set("zookeeper.session.timeout", "3600000"); conf.set("dfs.client.socket-timeout", "3600000"); hbase = new HBaseTestingUtility(conf); if (securedCluster) { enableSecurity(conf); verifyConfiguration(conf); hbase.startMiniCluster(RS_COUNT); hbase.waitTableEnabled(AccessControlLists.ACL_TABLE_NAME.getName(), 10000); } else { hbase.startMiniCluster(RS_COUNT); } updateTestZkQuorum(); admin = new HBaseAdminWrapper(conf); } } else { if (admin == null) { final String argsFileName = securedCluster ? "../../testClusterRealSecured.args" : "../../testClusterRealNonSecured.args"; if (!Util.isFile(argsFileName)) { throw new IllegalStateException("You have to define args file " + argsFileName + " for tests."); } String[] testArgs = {argsFileName}; Args args = new TestArgs(testArgs); admin = HBaseClient.getAdmin(args); conf = admin.getConfiguration(); RS_COUNT = getServerNameList().size(); } } previousBalancerRunning = admin.setBalancerRunning(false, true); hConnection = HConnectionManager.createConnection(conf); createNamespace(admin, TEST_NAMESPACE); USER_RW = User.createUserForTesting(conf, "rwuser", new String[0]); }
Example 20
Source File: TestBase.java From hbase-tools with Apache License 2.0 | 4 votes |
@BeforeClass public static void setUpOnce() throws Exception { miniCluster = System.getProperty("cluster.type").equals("mini"); securedCluster = System.getProperty("cluster.secured").equals("true"); System.out.println("realCluster - " + !miniCluster); System.out.println("securedCluster - " + securedCluster); Util.setLoggingThreshold("ERROR"); if (miniCluster) { if (hbase == null) { conf = HBaseConfiguration.create(new Configuration(true)); conf.setInt("hbase.master.info.port", -1); conf.set("zookeeper.session.timeout", "3600000"); conf.set("dfs.client.socket-timeout", "3600000"); hbase = new HBaseTestingUtility(conf); if (securedCluster) { enableSecurity(conf); verifyConfiguration(conf); hbase.startMiniCluster(RS_COUNT); hbase.waitTableEnabled(AccessControlLists.ACL_TABLE_NAME.getName(), 10000); } else { hbase.startMiniCluster(RS_COUNT); } updateTestZkQuorum(); admin = new HBaseAdminWrapper(conf); } } else { if (admin == null) { final String argsFileName = securedCluster ? "../../testClusterRealSecured.args" : "../../testClusterRealNonSecured.args"; if (!Util.isFile(argsFileName)) { throw new IllegalStateException("You have to define args file " + argsFileName + " for tests."); } String[] testArgs = {argsFileName}; Args args = new TestArgs(testArgs); admin = HBaseClient.getAdmin(args); conf = admin.getConfiguration(); RS_COUNT = getServerNameList().size(); } } previousBalancerRunning = admin.setBalancerRunning(false, true); hConnection = HConnectionManager.createConnection(conf); createNamespace(admin, TEST_NAMESPACE); USER_RW = User.createUserForTesting(conf, "rwuser", new String[0]); }