类org.apache.hadoop.hbase.client.Admin源码实例Demo

下面列出了怎么用org.apache.hadoop.hbase.client.Admin的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: hbase   文件: TestBulkLoadReplication.java
private static void startThirdCluster() throws Exception {
  LOG.info("Setup Zk to same one from UTIL1 and UTIL2");
  UTIL3.setZkCluster(UTIL1.getZkCluster());
  UTIL3.startMiniCluster(NUM_SLAVES1);

  TableDescriptor table = TableDescriptorBuilder.newBuilder(tableName)
    .setColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(famName)
      .setMobEnabled(true)
      .setMobThreshold(4000)
      .setScope(HConstants.REPLICATION_SCOPE_GLOBAL).build())
    .setColumnFamily(ColumnFamilyDescriptorBuilder.of(noRepfamName)).build();

  Connection connection3 = ConnectionFactory.createConnection(CONF3);
  try (Admin admin3 = connection3.getAdmin()) {
    admin3.createTable(table, HBaseTestingUtility.KEYS_FOR_HBA_CREATE_TABLE);
  }
  UTIL3.waitUntilAllRegionsAssigned(tableName);
  htable3 = connection3.getTable(tableName);
}
 
源代码2 项目: hbase   文件: TestCloneSnapshotProcedure.java
private SnapshotProtos.SnapshotDescription getSnapshot() throws Exception {
  if (snapshot == null) {
    final TableName snapshotTableName = TableName.valueOf("testCloneSnapshot");
    long tid = System.currentTimeMillis();
    final String snapshotName = "snapshot-" + tid;

    Admin admin = UTIL.getAdmin();
    // create Table
    SnapshotTestingUtils.createTable(UTIL, snapshotTableName, getNumReplicas(), CF);
    // Load data
    SnapshotTestingUtils.loadData(UTIL, snapshotTableName, 500, CF);
    admin.disableTable(snapshotTableName);
    // take a snapshot
    admin.snapshot(snapshotName, snapshotTableName);
    admin.enableTable(snapshotTableName);

    List<SnapshotDescription> snapshotList = admin.listSnapshots();
    snapshot = ProtobufUtil.createHBaseProtosSnapshotDesc(snapshotList.get(0));
  }
  return snapshot;
}
 
源代码3 项目: phoenix   文件: SetPropertyIT.java
@Test
public void testSetHTableProperties() throws Exception {
    Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
    String ddl = "CREATE TABLE " + dataTableFullName + " (\n"
            +"ID1 VARCHAR(15) NOT NULL,\n"
            +"ID2 VARCHAR(15) NOT NULL,\n"
            +"CREATED_DATE DATE,\n"
            +"CREATION_TIME BIGINT,\n"
            +"LAST_USED DATE,\n"
            +"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) " + generateDDLOptions("SALT_BUCKETS = 8");
    Connection conn1 = DriverManager.getConnection(getUrl(), props);
    conn1.createStatement().execute(ddl);
    ddl = "ALTER TABLE " + dataTableFullName + " SET COMPACTION_ENABLED=FALSE";
    conn1.createStatement().execute(ddl);
    try (Admin admin = conn1.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
        TableDescriptor tableDesc = admin.getDescriptor(TableName.valueOf(dataTableFullName));
        assertEquals(1, tableDesc.getColumnFamilies().length);
        assertEquals("0", tableDesc.getColumnFamilies()[0].getNameAsString());
        assertEquals(Boolean.toString(false), tableDesc.getValue(TableDescriptorBuilder.COMPACTION_ENABLED));
    }
}
 
源代码4 项目: presto-hbase-connector   文件: HBaseTables.java
Set<String> getSchemaNames() {
    NamespaceDescriptor[] namespaceDescriptors = new NamespaceDescriptor[0];
    Admin admin = null;
    try {
        admin = hbaseClientManager.getAdmin();
        namespaceDescriptors = admin.listNamespaceDescriptors();
    } catch (IOException e) {
        logger.error(e, e.getMessage());
    } finally {
        if (admin != null) {
            hbaseClientManager.close(admin);
        }
    }

    HashSet<String> set = new HashSet<>();
    NamespaceDescriptor[] temp = namespaceDescriptors;
    int namespaceDescriptorLength = namespaceDescriptors.length;

    for (int i = 0; i < namespaceDescriptorLength; ++i) {
        NamespaceDescriptor namespaceDescriptor = temp[i];
        set.add(namespaceDescriptor.getName());
    }

    return set;
}
 
源代码5 项目: spliceengine   文件: CheckTableIT.java
public static void deleteFirstIndexRegion(SpliceWatcher spliceWatcher, Connection connection, String schemaName, String tableName, String indexName) throws Exception {
    SConfiguration config = HConfiguration.getConfiguration();
    HBaseTestingUtility testingUtility = new HBaseTestingUtility((Configuration) config.getConfigSource().unwrapDelegate());
    Admin admin = testingUtility.getAdmin();

    // Delete 2nd region of index
    long   conglomerateId = TableSplit.getConglomerateId(connection, schemaName, tableName, indexName);
    TableName iName = TableName.valueOf(config.getNamespace(),Long.toString(conglomerateId));
    List<RegionInfo> partitions = admin.getRegions(iName);
    for (RegionInfo partition : partitions) {
        byte[] startKey = partition.getStartKey();
        if (startKey.length == 0) {
            String encodedRegionName = partition.getEncodedName();
            spliceWatcher.execute(String.format("call syscs_util.delete_region('%s', '%s', '%s', '%s', false)",
                    schemaName, tableName, indexName, encodedRegionName));
            break;
        }
    }
}
 
源代码6 项目: ranger   文件: HBaseRangerAuthorizationTest.java
@Test
public void testReadTablesAsProcessOwner() throws Exception {
    final Configuration conf = HBaseConfiguration.create();
    conf.set("hbase.zookeeper.quorum", "localhost");
    conf.set("hbase.zookeeper.property.clientPort", "" + port);
    conf.set("zookeeper.znode.parent", "/hbase-unsecure");
    
    Connection conn = ConnectionFactory.createConnection(conf);
    Admin admin = conn.getAdmin();

    HTableDescriptor[] tableDescriptors = admin.listTables();
    for (HTableDescriptor desc : tableDescriptors) {
        LOG.info("Found table:[" + desc.getTableName().getNameAsString() + "]");
    }
    Assert.assertEquals(3, tableDescriptors.length);

    conn.close();
}
 
源代码7 项目: hbase   文件: TestAccessController2.java
@Test
public void testCreateTableWithGroupPermissions() throws Exception {
  grantGlobal(TEST_UTIL, TESTGROUP_1_NAME, Action.CREATE);
  try {
    AccessTestAction createAction = new AccessTestAction() {
      @Override
      public Object run() throws Exception {
        TableDescriptorBuilder.ModifyableTableDescriptor tableDescriptor =
          new TableDescriptorBuilder.ModifyableTableDescriptor(testTable.getTableName());
        tableDescriptor.setColumnFamily(
          new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(TEST_FAMILY));
        try (Connection connection =
            ConnectionFactory.createConnection(TEST_UTIL.getConfiguration())) {
          try (Admin admin = connection.getAdmin()) {
            admin.createTable(tableDescriptor);
          }
        }
        return null;
      }
    };
    verifyAllowed(createAction, TESTGROUP1_USER1);
    verifyDenied(createAction, TESTGROUP2_USER1);
  } finally {
    revokeGlobal(TEST_UTIL, TESTGROUP_1_NAME, Action.CREATE);
  }
}
 
源代码8 项目: geowave   文件: HBaseOperations.java
@Override
public void deleteAll() throws IOException {
  try (Admin admin = conn.getAdmin()) {
    final TableName[] tableNamesArr = admin.listTableNames();
    for (final TableName tableName : tableNamesArr) {
      if ((tableNamespace == null) || tableName.getNameAsString().startsWith(tableNamespace)) {
        synchronized (ADMIN_MUTEX) {
          if (admin.tableExists(tableName)) {
            disableTable(admin, tableName);
            admin.deleteTable(tableName);
          }
        }
      }
    }
    synchronized (this) {
      iteratorsAttached = false;
    }
    cfCache.clear();
    partitionCache.clear();
    coprocessorCache.clear();
    DataAdapterAndIndexCache.getInstance(
        RowMergingAdapterOptionProvider.ROW_MERGING_ADAPTER_CACHE_ID,
        tableNamespace,
        HBaseStoreFactoryFamily.TYPE).deleteAll();
  }
}
 
源代码9 项目: hbase   文件: TestMasterQuotasObserver.java
@Test
public void testTableRPCQuotaRemoved() throws Exception {
  final Connection conn = TEST_UTIL.getConnection();
  final Admin admin = conn.getAdmin();
  final TableName tn = TableName.valueOf(testName.getMethodName());
  // Drop the table if it somehow exists
  if (admin.tableExists(tn)) {
    dropTable(admin, tn);
  }

  createTable(admin, tn);
  assertEquals(0, getThrottleQuotas());

  // Set RPC quota
  QuotaSettings settings =
      QuotaSettingsFactory.throttleTable(tn, ThrottleType.REQUEST_SIZE, 2L, TimeUnit.HOURS);
  admin.setQuota(settings);

  assertEquals(1, getThrottleQuotas());

  // Delete the table and observe the RPC quota being automatically deleted as well
  dropTable(admin, tn);
  assertEquals(0, getThrottleQuotas());
}
 
源代码10 项目: hbase   文件: TestDelegationTokenWithEncryption.java
@Test
public void testPutGetWithDelegationToken() throws Exception {
  TableName tableName = getTestTableName();
  byte[] family = Bytes.toBytes("f");
  byte[] qualifier = Bytes.toBytes("q");
  byte[] row = Bytes.toBytes("row");
  byte[] value = Bytes.toBytes("data");
  try (Connection conn = ConnectionFactory.createConnection(TEST_UTIL.getConfiguration())) {
    Admin admin = conn.getAdmin();
    TableDescriptorBuilder.ModifyableTableDescriptor tableDescriptor =
      new TableDescriptorBuilder.ModifyableTableDescriptor(tableName);
    tableDescriptor.setColumnFamily(
      new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(family));
    admin.createTable(tableDescriptor);
    try (Table table = conn.getTable(tableName)) {
      table.put(new Put(row).addColumn(family, qualifier, value));
      Result result = table.get(new Get(row));
      assertArrayEquals(value, result.getValue(family, qualifier));
    }
  }
}
 
源代码11 项目: hbase   文件: TestRegionOpen.java
@Test
public void testPriorityRegionIsOpenedWithSeparateThreadPool() throws Exception {
  final TableName tableName = TableName.valueOf(TestRegionOpen.class.getSimpleName());
  ThreadPoolExecutor exec = getRS().getExecutorService()
      .getExecutorThreadPool(ExecutorType.RS_OPEN_PRIORITY_REGION);
  long completed = exec.getCompletedTaskCount();

  TableDescriptorBuilder.ModifyableTableDescriptor tableDescriptor =
    new TableDescriptorBuilder.ModifyableTableDescriptor(tableName);
  tableDescriptor.setPriority(HConstants.HIGH_QOS);
  tableDescriptor.setColumnFamily(
    new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(
      HConstants.CATALOG_FAMILY));
  try (Connection connection = ConnectionFactory.createConnection(HTU.getConfiguration());
      Admin admin = connection.getAdmin()) {
    admin.createTable(tableDescriptor);
  }

  assertEquals(completed + 1, exec.getCompletedTaskCount());
}
 
源代码12 项目: phoenix   文件: FlappingAlterTableIT.java
@Test
public void testNewColumnFamilyInheritsTTLOfEmptyCF() throws Exception {
    Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
    String ddl = "CREATE TABLE " + dataTableFullName + " (\n"
            +"ID1 VARCHAR(15) NOT NULL,\n"
            +"ID2 VARCHAR(15) NOT NULL,\n"
            +"CREATED_DATE DATE,\n"
            +"CREATION_TIME BIGINT,\n"
            +"LAST_USED DATE,\n"
            +"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) TTL = 1000";
    Connection conn1 = DriverManager.getConnection(getUrl(), props);
    conn1.createStatement().execute(ddl);
    ddl = "ALTER TABLE " + dataTableFullName + " ADD CF.STRING VARCHAR";
    conn1.createStatement().execute(ddl);
    try (Admin admin = conn1.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
        TableDescriptor tableDesc = admin.getDescriptor(TableName.valueOf(dataTableFullName));
        ColumnFamilyDescriptor[] columnFamilies = tableDesc.getColumnFamilies();
        assertEquals(2, columnFamilies.length);
        assertEquals("0", columnFamilies[0].getNameAsString());
        assertEquals(1000, columnFamilies[0].getTimeToLive());
        assertEquals("CF", columnFamilies[1].getNameAsString());
        assertEquals(1000, columnFamilies[1].getTimeToLive());
    }
}
 
源代码13 项目: hbase   文件: TestClusterScopeQuotaThrottle.java
@Test
public void testUserClusterScopeQuota() throws Exception {
  final Admin admin = TEST_UTIL.getAdmin();
  final String userName = User.getCurrent().getShortName();

  // Add 6req/min limit for read request in cluster scope
  admin.setQuota(QuotaSettingsFactory.throttleUser(userName, ThrottleType.READ_NUMBER, 6,
    TimeUnit.MINUTES, QuotaScope.CLUSTER));
  // Add 6req/min limit for write request in machine scope
  admin.setQuota(
    QuotaSettingsFactory.throttleUser(userName, ThrottleType.WRITE_NUMBER, 6, TimeUnit.MINUTES));
  triggerUserCacheRefresh(TEST_UTIL, false, TABLE_NAMES);
  // should execute at max 6 read requests and at max 3 write write requests
  assertEquals(6, doPuts(10, FAMILY, QUALIFIER, tables[0]));
  assertEquals(3, doGets(10, tables[0]));
  // Remove all the limits
  admin.setQuota(QuotaSettingsFactory.unthrottleUser(userName));
  triggerUserCacheRefresh(TEST_UTIL, true, TABLE_NAMES);
}
 
源代码14 项目: phoenix   文件: SetPropertyIT.java
@Test
public void testSetPropertyAndAddColumnForDefaultColumnFamily() throws Exception {
    Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
    Connection conn = DriverManager.getConnection(getUrl(), props);
    conn.setAutoCommit(false);
    String ddl = "CREATE TABLE " + dataTableFullName +
            "  (a_string varchar not null, col1 integer" +
            "  CONSTRAINT pk PRIMARY KEY (a_string)) " + tableDDLOptions;
    try {
        conn.createStatement().execute(ddl);
        conn.createStatement().execute("ALTER TABLE " + dataTableFullName + " ADD col2 integer IN_MEMORY=true");
        try (Admin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
            ColumnFamilyDescriptor[] columnFamilies = admin.getDescriptor(TableName.valueOf(dataTableFullName))
                    .getColumnFamilies();
            assertEquals(1, columnFamilies.length);
            assertEquals("0", columnFamilies[0].getNameAsString());
            assertTrue(columnFamilies[0].isInMemory());
        }
    } finally {
        conn.close();
    }
}
 
源代码15 项目: hbase   文件: SnapshotScannerHDFSAclController.java
@Override
public void postStartMaster(ObserverContext<MasterCoprocessorEnvironment> c) throws IOException {
  if (!initialized) {
    return;
  }
  try (Admin admin = c.getEnvironment().getConnection().getAdmin()) {
    if (admin.tableExists(PermissionStorage.ACL_TABLE_NAME)) {
      // Check if acl table has 'm' CF, if not, add 'm' CF
      TableDescriptor tableDescriptor = admin.getDescriptor(PermissionStorage.ACL_TABLE_NAME);
      boolean containHdfsAclFamily = Arrays.stream(tableDescriptor.getColumnFamilies()).anyMatch(
        family -> Bytes.equals(family.getName(), SnapshotScannerHDFSAclStorage.HDFS_ACL_FAMILY));
      if (!containHdfsAclFamily) {
        TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableDescriptor)
            .setColumnFamily(ColumnFamilyDescriptorBuilder
                .newBuilder(SnapshotScannerHDFSAclStorage.HDFS_ACL_FAMILY).build());
        admin.modifyTable(builder.build());
      }
      aclTableInitialized = true;
    } else {
      throw new TableNotFoundException("Table " + PermissionStorage.ACL_TABLE_NAME
          + " is not created yet. Please check if " + getClass().getName()
          + " is configured after " + AccessController.class.getName());
    }
  }
}
 
源代码16 项目: nifi   文件: HBase_2_ClientService.java
/**
 * As of Apache NiFi 1.5.0, due to changes made to
 * {@link SecurityUtil#loginKerberos(Configuration, String, String)}, which is used by this
 * class to authenticate a principal with Kerberos, HBase controller services no longer
 * attempt relogins explicitly.  For more information, please read the documentation for
 * {@link SecurityUtil#loginKerberos(Configuration, String, String)}.
 * <p/>
 * In previous versions of NiFi, a {@link org.apache.nifi.hadoop.KerberosTicketRenewer} was started
 * when the HBase controller service was enabled.  The use of a separate thread to explicitly relogin could cause
 * race conditions with the implicit relogin attempts made by hadoop/HBase code on a thread that references the same
 * {@link UserGroupInformation} instance.  One of these threads could leave the
 * {@link javax.security.auth.Subject} in {@link UserGroupInformation} to be cleared or in an unexpected state
 * while the other thread is attempting to use the {@link javax.security.auth.Subject}, resulting in failed
 * authentication attempts that would leave the HBase controller service in an unrecoverable state.
 *
 * @see SecurityUtil#loginKerberos(Configuration, String, String)
 */
@OnEnabled
public void onEnabled(final ConfigurationContext context) throws InitializationException, IOException, InterruptedException {
    this.connection = createConnection(context);

    // connection check
    if (this.connection != null) {
        final Admin admin = this.connection.getAdmin();
        if (admin != null) {
            admin.listTableNames();

            final ClusterStatus clusterStatus = admin.getClusterStatus();
            if (clusterStatus != null) {
                final ServerName master = clusterStatus.getMaster();
                if (master != null) {
                    masterAddress = master.getHostAndPort();
                } else {
                    masterAddress = null;
                }
            }
        }
    }
}
 
源代码17 项目: hbase   文件: CanaryTool.java
private static List<Future<Void>> sniff(final Admin admin, final Sink sink,
    TableDescriptor tableDesc, ExecutorService executor, TaskType taskType,
    boolean rawScanEnabled, LongAdder rwLatency, boolean readAllCF) throws Exception {
  LOG.debug("Reading list of regions for table {}", tableDesc.getTableName());
  try (Table table = admin.getConnection().getTable(tableDesc.getTableName())) {
    List<RegionTask> tasks = new ArrayList<>();
    try (RegionLocator regionLocator =
             admin.getConnection().getRegionLocator(tableDesc.getTableName())) {
      for (HRegionLocation location: regionLocator.getAllRegionLocations()) {
        if (location == null) {
          LOG.warn("Null location");
          continue;
        }
        ServerName rs = location.getServerName();
        RegionInfo region = location.getRegion();
        tasks.add(new RegionTask(admin.getConnection(), region, rs, (RegionStdOutSink)sink,
            taskType, rawScanEnabled, rwLatency, readAllCF));
        Map<String, List<RegionTaskResult>> regionMap = ((RegionStdOutSink) sink).getRegionMap();
        regionMap.put(region.getRegionNameAsString(), new ArrayList<RegionTaskResult>());
      }
      return executor.invokeAll(tasks);
    }
  } catch (TableNotFoundException e) {
    return Collections.EMPTY_LIST;
  }
}
 
源代码18 项目: phoenix   文件: SetPropertyIT.java
@Test
public void testSetHColumnProperties() throws Exception {
    Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
    String ddl = "CREATE TABLE " + dataTableFullName + " (\n"
            +"ID1 VARCHAR(15) NOT NULL,\n"
            +"ID2 VARCHAR(15) NOT NULL,\n"
            +"CREATED_DATE DATE,\n"
            +"CREATION_TIME BIGINT,\n"
            +"LAST_USED DATE,\n"
            +"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) " + generateDDLOptions("SALT_BUCKETS = 8");
    Connection conn1 = DriverManager.getConnection(getUrl(), props);
    conn1.createStatement().execute(ddl);
    ddl = "ALTER TABLE " + dataTableFullName + " SET REPLICATION_SCOPE=1";
    conn1.createStatement().execute(ddl);
    try (Admin admin = conn1.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
        ColumnFamilyDescriptor[] columnFamilies = admin.getDescriptor(TableName.valueOf(dataTableFullName))
                .getColumnFamilies();
        assertEquals(1, columnFamilies.length);
        assertEquals("0", columnFamilies[0].getNameAsString());
        assertEquals(1, columnFamilies[0].getScope());
    }
}
 
@Test
public void testMasterObserverToModifyTableSchema() throws IOException {
  TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(TABLENAME);
  for (int i = 1; i <= 3; i++) {
    builder.setColumnFamily(
        ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("cf" + i)).setMaxVersions(i)
            .build());
  }
  try (Admin admin = UTIL.getAdmin()) {
    admin.createTable(builder.build());
    assertOneVersion(admin.getDescriptor(TABLENAME));

    builder.modifyColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("cf1"))
        .setMaxVersions(Integer.MAX_VALUE).build());
    admin.modifyTable(builder.build());
    assertOneVersion(admin.getDescriptor(TABLENAME));
  }
}
 
源代码20 项目: hbase   文件: RegionSplitter.java
static void createPresplitTable(TableName tableName, SplitAlgorithm splitAlgo,
        String[] columnFamilies, Configuration conf)
throws IOException, InterruptedException {
  final int splitCount = conf.getInt("split.count", 0);
  Preconditions.checkArgument(splitCount > 1, "Split count must be > 1");

  Preconditions.checkArgument(columnFamilies.length > 0,
      "Must specify at least one column family. ");
  LOG.debug("Creating table " + tableName + " with " + columnFamilies.length
      + " column families.  Presplitting to " + splitCount + " regions");

  TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableName);
  for (String cf : columnFamilies) {
    builder.setColumnFamily(ColumnFamilyDescriptorBuilder.of(cf));
  }
  try (Connection connection = ConnectionFactory.createConnection(conf)) {
    Admin admin = connection.getAdmin();
    try {
      Preconditions.checkArgument(!admin.tableExists(tableName),
        "Table already exists: " + tableName);
      admin.createTable(builder.build(), splitAlgo.split(splitCount));
    } finally {
      admin.close();
    }
    LOG.debug("Table created!  Waiting for regions to show online in META...");
    if (!conf.getBoolean("split.verify", true)) {
      // NOTE: createTable is synchronous on the table, but not on the regions
      int onlineRegions = 0;
      while (onlineRegions < splitCount) {
        onlineRegions = MetaTableAccessor.getRegionCount(connection, tableName);
        LOG.debug(onlineRegions + " of " + splitCount + " regions online...");
        if (onlineRegions < splitCount) {
          Thread.sleep(10 * 1000); // sleep
        }
      }
    }
    LOG.debug("Finished creating table with " + splitCount + " regions");
  }
}
 
源代码21 项目: spliceengine   文件: RangedClientPartition.java
@Override
public void flush() throws IOException {
    Connection connection = HBaseConnectionFactory.getInstance(HConfiguration.getConfiguration()).getConnection();
    byte[] encodedRegionName = regionInfo.getEncodedName().getBytes();
    try(Admin admin = connection.getAdmin()) {
        admin.flushRegion(encodedRegionName);
    }
}
 
源代码22 项目: hbase   文件: ConnectionCache.java
/**
 * Caller doesn't close the admin afterwards.
 * We need to manage it and close it properly.
 */
public Admin getAdmin() throws IOException {
  ConnectionInfo connInfo = getCurrentConnection();
  if (connInfo.admin == null) {
    Lock lock = locker.acquireLock(getEffectiveUser());
    try {
      if (connInfo.admin == null) {
        connInfo.admin = connInfo.connection.getAdmin();
      }
    } finally {
      lock.unlock();
    }
  }
  return connInfo.admin;
}
 
源代码23 项目: phoenix   文件: SetPropertyIT.java
@Test
public void testSetHColumnPropertyAndAddColumnForDefaultCFForTableWithOnlyPKCols() throws Exception {
    Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
    Connection conn = DriverManager.getConnection(getUrl(), props);
    conn.setAutoCommit(false);
    try {
        String ddl = "create table " + dataTableFullName + " ("
                + " id char(1) NOT NULL,"
                + " col1 integer NOT NULL,"
                + " col2 bigint NOT NULL,"
                + " CONSTRAINT NAME_PK PRIMARY KEY (id, col1, col2)"
                + " ) " + generateDDLOptions("TTL=86400, SALT_BUCKETS = 4, DEFAULT_COLUMN_FAMILY='XYZ'");
        conn.createStatement().execute(ddl);
        ddl = "ALTER TABLE " + dataTableFullName + " ADD COL3 INTEGER IN_MEMORY=true";
        conn.createStatement().execute(ddl);
        conn.commit();
        try (Admin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
            TableDescriptor tableDesc = admin.getDescriptor(TableName.valueOf(dataTableFullName));
            ColumnFamilyDescriptor[] columnFamilies = tableDesc.getColumnFamilies();
            assertEquals(1, columnFamilies.length);
            assertEquals(true, columnFamilies[0].isInMemory());
            assertEquals("XYZ", columnFamilies[0].getNameAsString());
        }
    } finally {
        conn.close();
    }
}
 
源代码24 项目: hbase   文件: CompactRandomRegionOfTableAction.java
@Override
public void perform() throws Exception {
  HBaseTestingUtility util = context.getHBaseIntegrationTestingUtility();
  Admin admin = util.getAdmin();
  boolean major = RandomUtils.nextInt(0, 100) < majorRatio;

  getLogger().info("Performing action: Compact random region of table "
    + tableName + ", major=" + major);
  List<RegionInfo> regions = admin.getRegions(tableName);
  if (regions == null || regions.isEmpty()) {
    getLogger().info("Table " + tableName + " doesn't have regions to compact");
    return;
  }

  RegionInfo region = PolicyBasedChaosMonkey.selectRandomItem(
    regions.toArray(new RegionInfo[0]));

  try {
    if (major) {
      getLogger().debug("Major compacting region " + region.getRegionNameAsString());
      admin.majorCompactRegion(region.getRegionName());
    } else {
      getLogger().debug("Compacting region " + region.getRegionNameAsString());
      admin.compactRegion(region.getRegionName());
    }
  } catch (Exception ex) {
    getLogger().warn("Compaction failed, might be caused by other chaos: " + ex.getMessage());
  }
  if (sleepTime > 0) {
    Thread.sleep(sleepTime);
  }
}
 
@Override
public Long call() throws Exception{
    SConfiguration configuration = HConfiguration.getConfiguration();
    Connection conn = HBaseConnectionFactory.getInstance(configuration).getConnection();
    Admin admin = conn.getAdmin();
    CoprocessorRpcChannel channel = admin.coprocessorService(serverName);
    SpliceRSRpcServices.BlockingInterface service = SpliceRSRpcServices.newBlockingStub(channel);
    SpliceMessage.SpliceOldestActiveTransactionRequest request = SpliceMessage.SpliceOldestActiveTransactionRequest.getDefaultInstance();
    SpliceMessage.SpliceOldestActiveTransactionResponse response = service.getOldestActiveTransaction(null, request);
    return response.getOldestActiveTransaction();
}
 
public void close(Admin admin) {
    try {
        admin.close();
    } catch (Exception ex) {
        log.error(ex, ex.getMessage());
    }
}
 
源代码27 项目: cloud-bigtable-examples   文件: CreateTable.java
private static boolean tableExists(TableName tableName, Admin admin)  {
  try {
    return admin.tableExists(tableName);
  } catch (Exception e) {
    LOG.error("Could not figure out if table " + tableName + " exists.", e);
    return false;
  } finally {
  }
}
 
private void creatTable(Admin admin, Configuration conf, TableName tableName, String[] family) throws IOException {
    HTableDescriptor desc = new HTableDescriptor(tableName);
    for (int i = 0; i < family.length; i++) {
        desc.addFamily(new HColumnDescriptor(family[i]));
    }
    if (admin.tableExists(tableName)) {
        throw new IOException("Table : " + tableName + " exists");
    } else {
        admin.createTable(desc);
        logger.info("create table Success!");
    }
}
 
源代码29 项目: phoenix   文件: SetPropertyIT.java
@Test
public void testSetPropertyAndAddColumnUsingDefaultColumnFamilySpecifier() throws Exception {
    Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
    Connection conn = DriverManager.getConnection(getUrl(), props);
    String ddl = "CREATE TABLE " + dataTableFullName
            +
            "  (a_string varchar not null, col1 integer, CF1.col2 integer" +
            "  CONSTRAINT pk PRIMARY KEY (a_string)) " + generateDDLOptions("DEFAULT_COLUMN_FAMILY = 'XYZ'");
    try {
        conn.createStatement().execute(ddl);
        conn.createStatement().execute(
                "ALTER TABLE " + dataTableFullName + " ADD col4 integer REPLICATION_SCOPE=1, XYZ.BLOCKSIZE=50000");
        conn.createStatement()
                .execute("ALTER TABLE " + dataTableFullName + " ADD XYZ.col5 integer IN_MEMORY=true ");
        try (Admin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
            ColumnFamilyDescriptor[] columnFamilies = admin.getDescriptor(TableName.valueOf(dataTableFullName))
                    .getColumnFamilies();
            assertEquals(2, columnFamilies.length);
            assertEquals("CF1", columnFamilies[0].getNameAsString());
            assertFalse(columnFamilies[0].isInMemory());
            assertEquals(1, columnFamilies[0].getScope());
            assertEquals(ColumnFamilyDescriptorBuilder.DEFAULT_BLOCKSIZE, columnFamilies[0].getBlocksize());
            assertEquals("XYZ", columnFamilies[1].getNameAsString());
            assertTrue(columnFamilies[1].isInMemory());
            assertEquals(1, columnFamilies[1].getScope());
            assertEquals(50000, columnFamilies[1].getBlocksize());
        }
    } finally {
        conn.close();
    }
}
 
源代码30 项目: datacollector   文件: BigtableTargetIT.java
private static void dropTable() {
  Connection conn = BigtableConfiguration.connect(projectID, instanceID);
  try {
    Admin admin = conn.getAdmin();
    admin.disableTable(TableName.valueOf(tableName));
    admin.deleteTable(TableName.valueOf(tableName));
  } catch (Exception ex) {
    LOG.info("dropTable(): exception {} ", ex.toString());
  }
}
 
 同包方法