示例#1
0
  private void runTestOnTable(HTable table)
      throws IOException, InterruptedException, ClassNotFoundException {
    Job job = null;
    try {
      LOG.info("Before map/reduce startup");
      job = new Job(table.getConfiguration(), "process column contents");
      job.setNumReduceTasks(1);
      Scan scan = new Scan();
      scan.addFamily(INPUT_FAMILY);
      TableMapReduceUtil.initTableMapperJob(
          Bytes.toString(table.getTableName()),
          scan,
          ProcessContentsMapper.class,
          ImmutableBytesWritable.class,
          Put.class,
          job);
      TableMapReduceUtil.initTableReducerJob(
          Bytes.toString(table.getTableName()), IdentityTableReducer.class, job);
      FileOutputFormat.setOutputPath(job, new Path("test"));
      LOG.info("Started " + Bytes.toString(table.getTableName()));
      assertTrue(job.waitForCompletion(true));
      LOG.info("After map/reduce completion");

      // verify map-reduce results
      verify(Bytes.toString(table.getTableName()));
    } finally {
      table.close();
      if (job != null) {
        FileUtil.fullyDelete(new File(job.getConfiguration().get("hadoop.tmp.dir")));
      }
    }
  }
示例#2
0
  private boolean check() throws DataExchangeException, IOException {
    if (!admin.isMasterRunning()) {
      throw new IllegalStateException("HBase master is not running!");
    }
    if (!admin.tableExists(htable.getTableName())) {
      throw new IllegalStateException(
          "HBase table " + Bytes.toString(htable.getTableName()) + " is not existed!");
    }
    if (!admin.isTableAvailable(htable.getTableName())) {
      throw new IllegalStateException(
          "HBase table " + Bytes.toString(htable.getTableName()) + " is not available!");
    }
    if (!admin.isTableEnabled(htable.getTableName())) {
      throw new IllegalStateException(
          "HBase table " + Bytes.toString(htable.getTableName()) + " is disable!");
    }

    return true;
  }