當前位置: 首頁>>代碼示例>>Java>>正文


Java HConnection類代碼示例

本文整理匯總了Java中org.apache.hadoop.hbase.client.HConnection的典型用法代碼示例。如果您正苦於以下問題:Java HConnection類的具體用法?Java HConnection怎麽用?Java HConnection使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


HConnection類屬於org.apache.hadoop.hbase.client包,在下文中一共展示了HConnection類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getRegionServerWriter

import org.apache.hadoop.hbase.client.HConnection; //導入依賴的package包/類
/**
 * Get a writer and path for a log starting at the given entry. This function is threadsafe so
 * long as multiple threads are always acting on different regions.
 * @return null if this region shouldn't output any logs
 */
private RegionServerWriter getRegionServerWriter(String loc) throws IOException {
  RegionServerWriter ret = writers.get(loc);
  if (ret != null) {
    return ret;
  }

  TableName tableName = getTableFromLocationStr(loc);
  if(tableName == null){
    throw new IOException("Invalid location string:" + loc + " found. Replay aborted.");
  }

  HConnection hconn = getConnectionByTableName(tableName);
  synchronized (writers) {
    ret = writers.get(loc);
    if (ret == null) {
      ret = new RegionServerWriter(conf, tableName, hconn);
      writers.put(loc, ret);
    }
  }
  return ret;
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:27,代碼來源:WALSplitter.java

示例2: loadDisabledTables

import org.apache.hadoop.hbase.client.HConnection; //導入依賴的package包/類
/**
 * Load the list of disabled tables in ZK into local set.
 * @throws ZooKeeperConnectionException
 * @throws IOException
 */
private void loadDisabledTables()
throws ZooKeeperConnectionException, IOException {
  HConnectionManager.execute(new HConnectable<Void>(getConf()) {
    @Override
    public Void connect(HConnection connection) throws IOException {
      ZooKeeperWatcher zkw = createZooKeeperWatcher();
      try {
        for (TableName tableName :
            ZKTableStateClientSideReader.getDisabledOrDisablingTables(zkw)) {
          disabledTables.add(tableName);
        }
      } catch (KeeperException ke) {
        throw new IOException(ke);
      } catch (InterruptedException e) {
        throw new InterruptedIOException();
      } finally {
        zkw.close();
      }
      return null;
    }
  });
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:28,代碼來源:HBaseFsck.java

示例3: verifyMetaRowsAreUpdated

import org.apache.hadoop.hbase.client.HConnection; //導入依賴的package包/類
/**
 * Verify that every hbase:meta row is updated
 */
void verifyMetaRowsAreUpdated(HConnection hConnection)
    throws IOException {
  List<Result> results = MetaTableAccessor.fullScan(hConnection);
  assertTrue(results.size() >= REGION_COUNT);

  for (Result result : results) {
    byte[] hriBytes = result.getValue(HConstants.CATALOG_FAMILY,
        HConstants.REGIONINFO_QUALIFIER);
    assertTrue(hriBytes != null && hriBytes.length > 0);
    assertTrue(MetaMigrationConvertingToPB.isMigrated(hriBytes));

    byte[] splitA = result.getValue(HConstants.CATALOG_FAMILY,
        HConstants.SPLITA_QUALIFIER);
    if (splitA != null && splitA.length > 0) {
      assertTrue(MetaMigrationConvertingToPB.isMigrated(splitA));
    }

    byte[] splitB = result.getValue(HConstants.CATALOG_FAMILY,
        HConstants.SPLITB_QUALIFIER);
    if (splitB != null && splitB.length > 0) {
      assertTrue(MetaMigrationConvertingToPB.isMigrated(splitB));
    }
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:28,代碼來源:TestMetaMigrationConvertingToPB.java

示例4: getMockedConnection

import org.apache.hadoop.hbase.client.HConnection; //導入依賴的package包/類
@SuppressWarnings("deprecation")
private HConnection getMockedConnection(final Configuration conf)
throws IOException, ServiceException {
  HConnection c = Mockito.mock(HConnection.class);
  Mockito.when(c.getConfiguration()).thenReturn(conf);
  Mockito.doNothing().when(c).close();
  // Make it so we return a particular location when asked.
  final HRegionLocation loc = new HRegionLocation(HRegionInfo.FIRST_META_REGIONINFO,
      ServerName.valueOf("example.org", 1234, 0));
  Mockito.when(c.getRegionLocation((TableName) Mockito.any(),
      (byte[]) Mockito.any(), Mockito.anyBoolean())).
    thenReturn(loc);
  Mockito.when(c.locateRegion((TableName) Mockito.any(), (byte[]) Mockito.any())).
    thenReturn(loc);
  ClientProtos.ClientService.BlockingInterface hri =
    Mockito.mock(ClientProtos.ClientService.BlockingInterface.class);
  Mockito.when(hri.bulkLoadHFile((RpcController)Mockito.any(), (BulkLoadHFileRequest)Mockito.any())).
    thenThrow(new ServiceException(new IOException("injecting bulk load error")));
  Mockito.when(c.getClient(Mockito.any(ServerName.class))).
    thenReturn(hri);
  return c;
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:23,代碼來源:TestLoadIncrementalHFilesSplitRecovery.java

示例5: getDeployedHRIs

import org.apache.hadoop.hbase.client.HConnection; //導入依賴的package包/類
/**
 * Get region info from local cluster.
 */
Map<ServerName, List<String>> getDeployedHRIs(final HBaseAdmin admin) throws IOException {
  ClusterStatus status = admin.getClusterStatus();
  Collection<ServerName> regionServers = status.getServers();
  Map<ServerName, List<String>> mm =
      new HashMap<ServerName, List<String>>();
  for (ServerName hsi : regionServers) {
    AdminProtos.AdminService.BlockingInterface server = ((HConnection) connection).getAdmin(hsi);

    // list all online regions from this region server
    List<HRegionInfo> regions = ProtobufUtil.getOnlineRegions(server);
    List<String> regionNames = new ArrayList<String>();
    for (HRegionInfo hri : regions) {
      regionNames.add(hri.getRegionNameAsString());
    }
    mm.put(hsi, regionNames);
  }
  return mm;
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:22,代碼來源:TestHBaseFsck.java

示例6: populateUserProfileData

import org.apache.hadoop.hbase.client.HConnection; //導入依賴的package包/類
private static void populateUserProfileData(HConnection connection) throws Exception {
  UserProfile up1 = new UserProfile();
  up1.userId = "101";
  up1.lastUpdatedTimeStamp = System.currentTimeMillis() - 1000;
  up1.historicAvg90PercentSingleDaySpend = 90.0;
  up1.historicAvgSingleDaySpend = 50.0;
  up1.todayMaxSpend = 0.0;
  up1.todayNumOfPurchases = 0l;
  HBaseUtils.populateUserProfile(connection, up1);

  up1.userId = "102";
  up1.lastUpdatedTimeStamp = System.currentTimeMillis() - 1000;
  up1.historicAvg90PercentSingleDaySpend = 90.0;
  up1.historicAvgSingleDaySpend = 50.0;
  up1.todayMaxSpend = 0.0;
  up1.todayNumOfPurchases = 0l;
  HBaseUtils.populateUserProfile(connection, up1);

  up1.userId = "103";
  up1.lastUpdatedTimeStamp = System.currentTimeMillis() - 1000;
  up1.historicAvg90PercentSingleDaySpend = 90.0;
  up1.historicAvgSingleDaySpend = 50.0;
  up1.todayMaxSpend = 0.0;
  up1.todayNumOfPurchases = 0l;
  HBaseUtils.populateUserProfile(connection, up1);
}
 
開發者ID:amitchmca,項目名稱:hadooparchitecturebook,代碼行數:27,代碼來源:RunLocalTest.java

示例7: getServerHoldingRegion

import org.apache.hadoop.hbase.client.HConnection; //導入依賴的package包/類
@Override
public ServerName getServerHoldingRegion(byte[] regionName) throws IOException {
  HConnection connection = admin.getConnection();
  HRegionLocation regionLoc = connection.locateRegion(regionName);
  if (regionLoc == null) {
    LOG.warn("Cannot find region server holding region " + Bytes.toString(regionName)
        + " for table " + HRegionInfo.getTableName(regionName) + ", start key [" +
        Bytes.toString(HRegionInfo.getStartKey(regionName)) + "]");
    return null;
  }

  AdminProtos.AdminService.BlockingInterface client =
    connection.getAdmin(regionLoc.getServerName());
  ServerInfo info = ProtobufUtil.getServerInfo(client);
  return ProtobufUtil.toServerName(info.getServerName());
}
 
開發者ID:tenggyut,項目名稱:HIndex,代碼行數:17,代碼來源:DistributedHBaseCluster.java

示例8: testVerifyRootRegionLocationFails

import org.apache.hadoop.hbase.client.HConnection; //導入依賴的package包/類
/**
 * Test get of root region fails properly if nothing to connect to.
 * @throws IOException
 * @throws InterruptedException
 * @throws KeeperException
 */
@Test
public void testVerifyRootRegionLocationFails()
throws IOException, InterruptedException, KeeperException {
  HConnection connection = Mockito.mock(HConnection.class);
  ConnectException connectException =
    new ConnectException("Connection refused");
  final HRegionInterface implementation =
    Mockito.mock(HRegionInterface.class);
  Mockito.when(implementation.getRegionInfo((byte [])Mockito.any())).
    thenThrow(connectException);
  Mockito.when(connection.getHRegionConnection(Mockito.anyString(),
    Mockito.anyInt(), Mockito.anyBoolean())).
    thenReturn(implementation);
  final CatalogTracker ct = constructAndStartCatalogTracker(connection);
  RootLocationEditor.setRootLocation(this.watcher,
    new ServerName("example.com", 1234, System.currentTimeMillis()));
  Assert.assertFalse(ct.verifyRootRegionLocation(100));
}
 
開發者ID:fengchen8086,項目名稱:LCIndex-HBase-0.94.16,代碼行數:25,代碼來源:TestCatalogTracker.java

示例9: testNoTimeoutWaitForRoot

import org.apache.hadoop.hbase.client.HConnection; //導入依賴的package包/類
/**
 * Test waiting on root w/ no timeout specified.
 * @throws IOException
 * @throws InterruptedException
 * @throws KeeperException
 */
@Test public void testNoTimeoutWaitForRoot()
throws IOException, InterruptedException, KeeperException {
  HConnection connection = Mockito.mock(HConnection.class);
  final CatalogTracker ct = constructAndStartCatalogTracker(connection);
  ServerName hsa = ct.getRootLocation();
  Assert.assertNull(hsa);

  // Now test waiting on root location getting set.
  Thread t = new WaitOnMetaThread(ct);
  startWaitAliveThenWaitItLives(t, 1000);
  // Set a root location.
  hsa = setRootLocation();
  // Join the thread... should exit shortly.
  t.join();
  // Now root is available.
  Assert.assertTrue(ct.getRootLocation().equals(hsa));
}
 
開發者ID:fengchen8086,項目名稱:LCIndex-HBase-0.94.16,代碼行數:24,代碼來源:TestCatalogTracker.java

示例10: mockConnection

import org.apache.hadoop.hbase.client.HConnection; //導入依賴的package包/類
/**
 * @param implementation An {@link HRegionInterface} instance; you'll likely
 * want to pass a mocked HRS; can be null.
 * @return Mock up a connection that returns a {@link org.apache.hadoop.conf.Configuration} when
 * {@link HConnection#getConfiguration()} is called, a 'location' when
 * {@link HConnection#getRegionLocation(byte[], byte[], boolean)} is called,
 * and that returns the passed {@link HRegionInterface} instance when
 * {@link HConnection#getHRegionConnection(String, int)}
 * is called (Be sure call
 * {@link HConnectionManager#deleteConnection(org.apache.hadoop.conf.Configuration)}
 * when done with this mocked Connection.
 * @throws IOException
 */
private HConnection mockConnection(final HRegionInterface implementation)
throws IOException {
  HConnection connection =
    HConnectionTestingUtility.getMockedConnection(UTIL.getConfiguration());
  Mockito.doNothing().when(connection).close();
  // Make it so we return any old location when asked.
  final HRegionLocation anyLocation =
    new HRegionLocation(HRegionInfo.FIRST_META_REGIONINFO, SN.getHostname(),
      SN.getPort());
  Mockito.when(connection.getRegionLocation((byte[]) Mockito.any(),
      (byte[]) Mockito.any(), Mockito.anyBoolean())).
    thenReturn(anyLocation);
  Mockito.when(connection.locateRegion((byte[]) Mockito.any(),
      (byte[]) Mockito.any())).
    thenReturn(anyLocation);
  if (implementation != null) {
    // If a call to getHRegionConnection, return this implementation.
    Mockito.when(connection.getHRegionConnection(Mockito.anyString(), Mockito.anyInt())).
      thenReturn(implementation);
  }
  return connection;
}
 
開發者ID:fengchen8086,項目名稱:LCIndex-HBase-0.94.16,代碼行數:36,代碼來源:TestCatalogTracker.java

示例11: testVerifyMetaRegionLocationFails

import org.apache.hadoop.hbase.client.HConnection; //導入依賴的package包/類
/**
 * Test get of meta region fails properly if nothing to connect to.
 * @throws IOException
 * @throws InterruptedException
 * @throws KeeperException
 * @throws ServiceException
 */
@Test
public void testVerifyMetaRegionLocationFails()
throws IOException, InterruptedException, KeeperException, ServiceException {
  HConnection connection = Mockito.mock(HConnection.class);
  ServiceException connectException =
    new ServiceException(new ConnectException("Connection refused"));
  final AdminProtos.AdminService.BlockingInterface implementation =
    Mockito.mock(AdminProtos.AdminService.BlockingInterface.class);
  Mockito.when(implementation.getRegionInfo((RpcController)Mockito.any(),
    (GetRegionInfoRequest)Mockito.any())).thenThrow(connectException);
  Mockito.when(connection.getAdmin(Mockito.any(ServerName.class), Mockito.anyBoolean())).
    thenReturn(implementation);
  final CatalogTracker ct = constructAndStartCatalogTracker(connection);

  MetaRegionTracker.setMetaLocation(this.watcher,
      ServerName.valueOf("example.com", 1234, System.currentTimeMillis()));
  Assert.assertFalse(ct.verifyMetaRegionLocation(100));
}
 
開發者ID:tenggyut,項目名稱:HIndex,代碼行數:26,代碼來源:TestCatalogTracker.java

示例12: getMockedConnection

import org.apache.hadoop.hbase.client.HConnection; //導入依賴的package包/類
private HConnection getMockedConnection(final Configuration conf)
throws IOException {
  HConnection c = Mockito.mock(HConnection.class);
  Mockito.when(c.getConfiguration()).thenReturn(conf);
  Mockito.doNothing().when(c).close();
  // Make it so we return a particular location when asked.
  final HRegionLocation loc = new HRegionLocation(HRegionInfo.FIRST_META_REGIONINFO,
      "example.org", 1234);
  Mockito.when(c.getRegionLocation((byte[]) Mockito.any(),
      (byte[]) Mockito.any(), Mockito.anyBoolean())).
    thenReturn(loc);
  Mockito.when(c.locateRegion((byte[]) Mockito.any(), (byte[]) Mockito.any())).
    thenReturn(loc);
  HRegionInterface hri = Mockito.mock(HRegionInterface.class);
  Mockito.when(hri.bulkLoadHFiles(Mockito.anyList(), (byte [])Mockito.any(),
    Mockito.anyBoolean())).thenThrow(new IOException("injecting bulk load error"));
  Mockito.when(c.getHRegionConnection(Mockito.anyString(), Mockito.anyInt())).
    thenReturn(hri);
  return c;
}
 
開發者ID:fengchen8086,項目名稱:LCIndex-HBase-0.94.16,代碼行數:21,代碼來源:TestLoadIncrementalHFilesSplitRecovery.java

示例13: getDeployedHRIs

import org.apache.hadoop.hbase.client.HConnection; //導入依賴的package包/類
/**
 * Get region info from local cluster.
 */
Map<ServerName, List<String>> getDeployedHRIs(HBaseAdmin admin)
  throws IOException {
  ClusterStatus status = admin.getMaster().getClusterStatus();
  Collection<ServerName> regionServers = status.getServers();
  Map<ServerName, List<String>> mm =
      new HashMap<ServerName, List<String>>();
  HConnection connection = admin.getConnection();
  for (ServerName hsi : regionServers) {
    HRegionInterface server =
      connection.getHRegionConnection(hsi.getHostname(), hsi.getPort());

    // list all online regions from this region server
    List<HRegionInfo> regions = server.getOnlineRegions();
    List<String> regionNames = new ArrayList<String>();
    for (HRegionInfo hri : regions) {
      regionNames.add(hri.getRegionNameAsString());
    }
    mm.put(hsi, regionNames);
  }
  return mm;
}
 
開發者ID:fengchen8086,項目名稱:LCIndex-HBase-0.94.16,代碼行數:25,代碼來源:TestHBaseFsck.java

示例14: getDeployedHRIs

import org.apache.hadoop.hbase.client.HConnection; //導入依賴的package包/類
/**
 * Get region info from local cluster.
 */
Map<ServerName, List<String>> getDeployedHRIs(
    final HBaseAdmin admin) throws IOException {
  ClusterStatus status = admin.getClusterStatus();
  Collection<ServerName> regionServers = status.getServers();
  Map<ServerName, List<String>> mm =
      new HashMap<ServerName, List<String>>();
  HConnection connection = admin.getConnection();
  for (ServerName hsi : regionServers) {
    AdminProtos.AdminService.BlockingInterface server = connection.getAdmin(hsi);

    // list all online regions from this region server
    List<HRegionInfo> regions = ProtobufUtil.getOnlineRegions(server);
    List<String> regionNames = new ArrayList<String>();
    for (HRegionInfo hri : regions) {
      regionNames.add(hri.getRegionNameAsString());
    }
    mm.put(hsi, regionNames);
  }
  return mm;
}
 
開發者ID:tenggyut,項目名稱:HIndex,代碼行數:24,代碼來源:TestHBaseFsck.java

示例15: getCurrentConnection

import org.apache.hadoop.hbase.client.HConnection; //導入依賴的package包/類
/**
 * Get the cached connection for the current user.
 * If none or timed out, create a new one.
 */
ConnectionInfo getCurrentConnection() throws IOException {
  String userName = getEffectiveUser();
  ConnectionInfo connInfo = connections.get(userName);
  if (connInfo == null || !connInfo.updateAccessTime()) {
    Lock lock = locker.acquireLock(userName);
    try {
      connInfo = connections.get(userName);
      if (connInfo == null) {
        UserGroupInformation ugi = realUser;
        if (!userName.equals(realUserName)) {
          ugi = UserGroupInformation.createProxyUser(userName, realUser);
        }
        User user = userProvider.create(ugi);
        HConnection conn = HConnectionManager.createConnection(conf, user);
        connInfo = new ConnectionInfo(conn, userName);
        connections.put(userName, connInfo);
      }
    } finally {
      lock.unlock();
    }
  }
  return connInfo;
}
 
開發者ID:grokcoder,項目名稱:pbase,代碼行數:28,代碼來源:ConnectionCache.java


注:本文中的org.apache.hadoop.hbase.client.HConnection類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。