Java Code Examples for org.apache.hadoop.hbase.protobuf.generated.HBaseProtos#SnapshotDescription

The following examples show how to use org.apache.hadoop.hbase.protobuf.generated.HBaseProtos#SnapshotDescription . These examples are extracted from open source projects. 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 Project: presto-hbase-connector   File: Utils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * get region infos
 *
 * @param zookeeperQuorum     zookeeper quorum
 * @param zookeeperClientPort zookeeper client port
 * @param hBaseRootDir        HBase root dir
 * @param snapshotName        snapshot name
 * @return region info list
 * @throws IOException IOException
 */
public static List<HRegionInfo> getRegionInfos(String zookeeperQuorum, String zookeeperClientPort,
                                               String hBaseRootDir, String snapshotName) throws IOException {
    try {
        Configuration conf = Utils.getHadoopConf(zookeeperQuorum, zookeeperClientPort);
        Path root = new Path(hBaseRootDir);
        FileSystem fs = FileSystem.get(conf);
        Path snapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(snapshotName, root);
        HBaseProtos.SnapshotDescription snapshotDesc = SnapshotDescriptionUtils.readSnapshotInfo(fs, snapshotDir);
        SnapshotManifest manifest = SnapshotManifest.open(conf, fs, snapshotDir, snapshotDesc);
        return Utils.getRegionInfosFromManifest(manifest);
    } catch (IOException ex) {
        logger.error("get region info error: " + ex.getMessage(), ex);
        throw ex;
    }
}
 
Example 2
Source Project: hbase-tools   File: SnapshotOptionTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testClearWatchLeak() throws Exception {
    List<HBaseProtos.SnapshotDescription> snapshotDescriptions;
    String[] argsParam;
    SnapshotArgs args;
    Snapshot app;

    // with option
    argsParam = new String[]{"localhost", ".*", "--test", "--clear-watch-leak"};
    args = new SnapshotArgs(argsParam);
    app = new Snapshot(admin, args);

    // create snapshot
    app.run();
    snapshotDescriptions = listSnapshots(tableName + ".*");
    assertEquals(1, snapshotDescriptions.size());
}
 
Example 3
Source Project: hbase-tools   File: SnapshotTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testNamespace() throws Exception {
    List<HBaseProtos.SnapshotDescription> snapshotDescriptions;
    String[] argsParam;
    SnapshotArgs args;
    Snapshot app;
    String fullTableName = null;

    try {
        // create table with namespace
        fullTableName = TEST_NAMESPACE + ":" + TestBase.tableName;
        createTable(fullTableName);

        // table with namespace
        argsParam = new String[]{"localhost", fullTableName};
        args = new SnapshotArgs(argsParam);
        app = new Snapshot(admin, args);

        // create snapshot
        app.run();
        snapshotDescriptions = admin.listSnapshots(app.getPrefix(fullTableName) + ".*");
        assertEquals(1, snapshotDescriptions.size());
    } finally {
        dropTable(fullTableName);
    }
}
 
Example 4
Source Project: hbase-tools   File: SnapshotOptionTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testExclude() throws Exception {
    List<HBaseProtos.SnapshotDescription> snapshotDescriptions;
    String[] argsParam;
    SnapshotArgs args;
    Snapshot app;

    // create table
    String tableName2 = createAdditionalTable(tableName + "2");

    // with table list
    argsParam = new String[]{"localhost", ".*", "--exclude=" + tableName, "--test"};
    args = new SnapshotArgs(argsParam);
    app = new Snapshot(admin, args);

    // create snapshot
    app.run();
    snapshotDescriptions = listSnapshots(tableName + ".*");
    assertEquals(1, snapshotDescriptions.size());
    assertEquals(tableName2, snapshotDescriptions.get(0).getTable());
}
 
Example 5
Source Project: hbase-tools   File: SnapshotOptionTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testClearWatchLeak() throws Exception {
    List<HBaseProtos.SnapshotDescription> snapshotDescriptions;
    String[] argsParam;
    SnapshotArgs args;
    Snapshot app;

    // with option
    argsParam = new String[]{"localhost", ".*", "--test", "--clear-watch-leak"};
    args = new SnapshotArgs(argsParam);
    app = new Snapshot(admin, args);

    // create snapshot
    app.run();
    snapshotDescriptions = listSnapshots(tableName + ".*");
    assertEquals(1, snapshotDescriptions.size());
}
 
Example 6
Source Project: hbase-tools   File: SnapshotOptionTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testClearWatchLeak() throws Exception {
    List<HBaseProtos.SnapshotDescription> snapshotDescriptions;
    String[] argsParam;
    SnapshotArgs args;
    Snapshot app;

    // with option
    argsParam = new String[]{"localhost", ".*", "--test", "--clear-watch-leak"};
    args = new SnapshotArgs(argsParam);
    app = new Snapshot(admin, args);

    // create snapshot
    app.run();
    snapshotDescriptions = listSnapshots(tableName + ".*");
    assertEquals(1, snapshotDescriptions.size());
}
 
Example 7
Source Project: hbase-tools   File: SnapshotTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testDuplicatedName() throws Exception {
    List<HBaseProtos.SnapshotDescription> snapshotDescriptions;
    String[] argsParam;
    SnapshotArgs args;
    Snapshot app;

    argsParam = new String[]{"localhost", ".*", "--test"};
    args = new SnapshotArgs(argsParam);
    app = new Snapshot(admin, args);

    String snapshotName = app.getPrefix(tableName) + "test";
    // create snapshot first
    app.snapshot(null, tableName, snapshotName);
    snapshotDescriptions = listSnapshots(tableName + ".*");
    assertEquals(1, snapshotDescriptions.size());

    // create snapshot again
    app.snapshot(null, tableName, snapshotName);
    snapshotDescriptions = listSnapshots(tableName + ".*");
    assertEquals(1, snapshotDescriptions.size());
}
 
Example 8
Source Project: hbase-tools   File: SnapshotOptionTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testExcludeRegexList() throws Exception {
    List<HBaseProtos.SnapshotDescription> snapshotDescriptions;
    String[] argsParam;
    SnapshotArgs args;
    Snapshot app;

    // create table
    String tableName2 = createAdditionalTable(tableName + "2");
    createAdditionalTable(tableName + "21");

    // with table list
    argsParam = new String[]{"localhost", ".*", "--exclude=" + tableName2 + ".*", "--test"};
    args = new SnapshotArgs(argsParam);
    app = new Snapshot(admin, args);

    // create snapshot
    app.run();
    snapshotDescriptions = listSnapshots(tableName + ".*");
    assertEquals(1, snapshotDescriptions.size());
    assertEquals(tableName, snapshotDescriptions.get(0).getTable());
}
 
Example 9
Source Project: hbase-tools   File: SnapshotOptionTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testExclude() throws Exception {
    List<HBaseProtos.SnapshotDescription> snapshotDescriptions;
    String[] argsParam;
    SnapshotArgs args;
    Snapshot app;

    // create table
    String tableName2 = createAdditionalTable(tableName + "2");

    // with table list
    argsParam = new String[]{"localhost", ".*", "--exclude=" + tableName, "--test"};
    args = new SnapshotArgs(argsParam);
    app = new Snapshot(admin, args);

    // create snapshot
    app.run();
    snapshotDescriptions = listSnapshots(tableName + ".*");
    assertEquals(1, snapshotDescriptions.size());
    assertEquals(tableName2, snapshotDescriptions.get(0).getTable());
}
 
Example 10
Source Project: hbase-tools   File: SnapshotTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testNamespace() throws Exception {
    List<HBaseProtos.SnapshotDescription> snapshotDescriptions;
    String[] argsParam;
    SnapshotArgs args;
    Snapshot app;
    String fullTableName = null;

    try {
        // create table with namespace
        fullTableName = TEST_NAMESPACE + ":" + TestBase.tableName;
        createTable(fullTableName);

        // table with namespace
        argsParam = new String[]{"localhost", fullTableName};
        args = new SnapshotArgs(argsParam);
        app = new Snapshot(admin, args);

        // create snapshot
        app.run();
        snapshotDescriptions = admin.listSnapshots(app.getPrefix(fullTableName) + ".*");
        assertEquals(1, snapshotDescriptions.size());
    } finally {
        dropTable(fullTableName);
    }
}
 
Example 11
Source Project: hbase-tools   File: SnapshotTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testAllTables() throws Exception {
    List<HBaseProtos.SnapshotDescription> snapshotDescriptions;

    // create tables
    createAdditionalTable(tableName + "2");
    createAdditionalTable(tableName + "3");

    // all tables, keep unlimited
    String[] argsParam = {"localhost", ".*", "--test"};
    SnapshotArgs args = new SnapshotArgs(argsParam);
    Snapshot app = new Snapshot(admin, args);

    // create snapshot 1
    app.run();
    snapshotDescriptions = listSnapshots(tableName + ".*");
    assertEquals(3, snapshotDescriptions.size());

    // create snapshot 2
    Thread.sleep(1000);
    app.run();
    snapshotDescriptions = listSnapshots(tableName + ".*");
    assertEquals(6, snapshotDescriptions.size());

    // create snapshot 3
    Thread.sleep(1000);
    app.run();
    snapshotDescriptions = listSnapshots(tableName + ".*");
    assertEquals(9, snapshotDescriptions.size());

    // create snapshot 3
    Thread.sleep(1000);
    app.run();
    snapshotDescriptions = listSnapshots(tableName + ".*");
    assertEquals(12, snapshotDescriptions.size());
}
 
Example 12
@Test
public void testRegexList() throws Exception {
    // create tables
    String tableName2 = createAdditionalTable(tableName + "2");
    String tableName3 = createAdditionalTable(tableName + "3");

    List<HBaseProtos.SnapshotDescription> snapshotDescriptions;

    // all tables, keep unlimited
    String[] argsParam = {"localhost", tableName + ".*," + tableName2 + ".*," + tableName3 + ".*"};
    SnapshotArgs args = new SnapshotArgs(argsParam);
    Snapshot app = new Snapshot(admin, args);

    // create snapshot 1
    app.run();
    snapshotDescriptions = listSnapshots(tableName + ".*");
    assertEquals(3, snapshotDescriptions.size());

    // create snapshot 2
    Thread.sleep(1000);
    app.run();
    snapshotDescriptions = listSnapshots(tableName + ".*");
    assertEquals(6, snapshotDescriptions.size());

    // create snapshot 3
    Thread.sleep(1000);
    app.run();
    snapshotDescriptions = listSnapshots(tableName + ".*");
    assertEquals(9, snapshotDescriptions.size());

    // create snapshot 3
    Thread.sleep(1000);
    app.run();
    snapshotDescriptions = listSnapshots(tableName + ".*");
    assertEquals(12, snapshotDescriptions.size());
}
 
Example 13
@Test
public void testList() throws Exception {
    List<HBaseProtos.SnapshotDescription> snapshotDescriptions;
    String[] argsParam;
    SnapshotArgs args;
    Snapshot app;

    // create table
    String tableName2 = createAdditionalTable(tableName + "2");

    // with table list
    argsParam = new String[]{"localhost", tableName + "," + tableName2};
    args = new SnapshotArgs(argsParam);
    app = new Snapshot(admin, args);

    // create snapshot
    app.run();
    snapshotDescriptions = listSnapshots(tableName + ".*");
    assertEquals(2, snapshotDescriptions.size());

    // with table list contains blank
    argsParam = new String[]{"localhost", tableName + " , " + tableName2};
    args = new SnapshotArgs(argsParam);
    app = new Snapshot(admin, args);

    // create snapshot
    Thread.sleep(1000);
    app.run();
    snapshotDescriptions = listSnapshots(tableName + ".*");
    assertEquals(4, snapshotDescriptions.size());
}
 
Example 14
@Test
public void testList() throws Exception {
    List<HBaseProtos.SnapshotDescription> snapshotDescriptions;
    String[] argsParam;
    SnapshotArgs args;
    Snapshot app;

    // create table
    String tableName2 = createAdditionalTable(tableName + "2");

    // with table list
    argsParam = new String[]{"localhost", tableName + "," + tableName2};
    args = new SnapshotArgs(argsParam);
    app = new Snapshot(admin, args);

    // create snapshot
    app.run();
    snapshotDescriptions = listSnapshots(tableName + ".*");
    assertEquals(2, snapshotDescriptions.size());

    // with table list contains blank
    argsParam = new String[]{"localhost", tableName + " , " + tableName2};
    args = new SnapshotArgs(argsParam);
    app = new Snapshot(admin, args);

    // create snapshot
    Thread.sleep(1000);
    app.run();
    snapshotDescriptions = listSnapshots(tableName + ".*");
    assertEquals(4, snapshotDescriptions.size());
}
 
Example 15
Source Project: hbase-tools   File: TestBase.java    License: Apache License 2.0 5 votes vote down vote up
protected void deleteSnapshots(String tableName) throws Exception {
    for (HBaseProtos.SnapshotDescription snapshotDescription : admin.listSnapshots(".*" + tableName + ".*")) {
        if (snapshotDescription.getTable().equals(tableName) || snapshotDescription.getTable().equals(TEST_NAMESPACE + ":" + tableName)) {
            admin.deleteSnapshots(snapshotDescription.getName());
        }
    }
}
 
Example 16
Source Project: hbase-tools   File: SnapshotOptionTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testOverride() throws Exception {
    List<HBaseProtos.SnapshotDescription> snapshotDescriptions;
    String[] argsParam;
    SnapshotArgs args;
    Snapshot app;

    // create table
    String tableName2 = createAdditionalTable(tableName + "2");

    // with table list
    argsParam = new String[]{"localhost", ".*", "--override=" + tableName + "/1/true", "--keep=2", "--test"};
    args = new SnapshotArgs(argsParam);
    app = new Snapshot(admin, args);

    // create snapshot 1
    app.run();
    snapshotDescriptions = listSnapshots(tableName + ".*");
    assertEquals(2, snapshotDescriptions.size());
    assertEquals(tableName2, snapshotDescriptions.get(0).getTable());
    assertEquals(HBaseProtos.SnapshotDescription.Type.FLUSH, snapshotDescriptions.get(0).getType());
    assertEquals(tableName, snapshotDescriptions.get(1).getTable());
    assertEquals(HBaseProtos.SnapshotDescription.Type.SKIPFLUSH, snapshotDescriptions.get(1).getType());

    // create snapshot 2
    Thread.sleep(1000);
    app.run();
    snapshotDescriptions = listSnapshots(tableName + ".*");
    assertEquals(3, snapshotDescriptions.size());
    assertEquals(tableName2, snapshotDescriptions.get(0).getTable());
    assertEquals(HBaseProtos.SnapshotDescription.Type.FLUSH, snapshotDescriptions.get(0).getType());
    assertEquals(tableName2, snapshotDescriptions.get(1).getTable());
    assertEquals(HBaseProtos.SnapshotDescription.Type.FLUSH, snapshotDescriptions.get(1).getType());
    assertEquals(tableName, snapshotDescriptions.get(2).getTable());
    assertEquals(HBaseProtos.SnapshotDescription.Type.SKIPFLUSH, snapshotDescriptions.get(2).getType());
}
 
Example 17
Source Project: hbase-tools   File: SnapshotOptionTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testSkipFlush() throws Exception {
    List<HBaseProtos.SnapshotDescription> snapshotDescriptions;
    String[] argsParam;
    SnapshotArgs args;
    Snapshot app;

    // skip flush
    argsParam = new String[]{"localhost", ".*", "--skip-flush=true", "--test"};
    args = new SnapshotArgs(argsParam);
    app = new Snapshot(admin, args);

    // create snapshot
    app.run();
    snapshotDescriptions = listSnapshots(tableName + ".*");
    assertEquals(1, snapshotDescriptions.size());
    assertEquals(HBaseProtos.SnapshotDescription.Type.SKIPFLUSH, snapshotDescriptions.get(0).getType());

    // do not skip flush
    argsParam = new String[]{"localhost", ".*", "--test"};
    args = new SnapshotArgs(argsParam);
    app = new Snapshot(admin, args);

    // create snapshot
    Thread.sleep(1000);
    app.run();
    snapshotDescriptions = listSnapshots(tableName + ".*");
    assertEquals(2, snapshotDescriptions.size());
    assertEquals(HBaseProtos.SnapshotDescription.Type.FLUSH, snapshotDescriptions.get(1).getType());
}
 
Example 18
@Test
public void testRegexList() throws Exception {
    // create tables
    String tableName2 = createAdditionalTable(tableName + "2");
    String tableName3 = createAdditionalTable(tableName + "3");

    List<HBaseProtos.SnapshotDescription> snapshotDescriptions;

    // all tables, keep unlimited
    String[] argsParam = {"localhost", tableName + ".*," + tableName2 + ".*," + tableName3 + ".*"};
    SnapshotArgs args = new SnapshotArgs(argsParam);
    Snapshot app = new Snapshot(admin, args);

    // create snapshot 1
    app.run();
    snapshotDescriptions = listSnapshots(tableName + ".*");
    assertEquals(3, snapshotDescriptions.size());

    // create snapshot 2
    Thread.sleep(1000);
    app.run();
    snapshotDescriptions = listSnapshots(tableName + ".*");
    assertEquals(6, snapshotDescriptions.size());

    // create snapshot 3
    Thread.sleep(1000);
    app.run();
    snapshotDescriptions = listSnapshots(tableName + ".*");
    assertEquals(9, snapshotDescriptions.size());

    // create snapshot 3
    Thread.sleep(1000);
    app.run();
    snapshotDescriptions = listSnapshots(tableName + ".*");
    assertEquals(12, snapshotDescriptions.size());
}
 
Example 19
Source Project: hbase-tools   File: SnapshotOptionTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void testDeleteSnapshotsForNotExistingTables() throws Exception {
    List<HBaseProtos.SnapshotDescription> snapshotDescriptions;
    String[] argsParam;
    SnapshotArgs args;
    Snapshot app;

    // create table
    String tableName2 = createAdditionalTable(tableName + "2");

    // create snapshot for 2 tables and keep 1
    argsParam = new String[]{"localhost", ".*", "--keep=1", "--test", "--delete-snapshot-for-not-existing-table"};
    args = new SnapshotArgs(argsParam);
    app = new Snapshot(admin, args);

    // create snapshot first
    app.run();
    snapshotDescriptions = listSnapshots(tableName + ".*");
    assertEquals(2, snapshotDescriptions.size());
    assertEquals(tableName2, snapshotDescriptions.get(0).getTable());
    assertEquals(tableName, snapshotDescriptions.get(1).getTable());

    // create snapshot once more
    Thread.sleep(1000);
    app.run();
    snapshotDescriptions = listSnapshots(tableName + ".*");
    assertEquals(2, snapshotDescriptions.size());
    assertEquals(tableName2, snapshotDescriptions.get(0).getTable());
    assertEquals(tableName, snapshotDescriptions.get(1).getTable());

    // create snapshot does not follow hbase-snapshot naming rule
    String shouldNotBeDeleted = tableName2 + "-snapshot-test";
    admin.snapshot(shouldNotBeDeleted, tableName2);

    // drop one table
    dropTable(tableName2);

    // create snapshot for only one table and snapshot for dropped table should not be deleted yet
    argsParam = new String[]{"localhost", ".*", "--keep=1", "--test"};
    args = new SnapshotArgs(argsParam);
    app = new Snapshot(admin, args);
    Thread.sleep(1000);
    app.run();
    snapshotDescriptions = listSnapshots(tableName + ".*");
    assertEquals(3, snapshotDescriptions.size());
    assertEquals(tableName2, snapshotDescriptions.get(0).getTable());
    assertEquals(tableName2, snapshotDescriptions.get(1).getTable());
    assertEquals(tableName, snapshotDescriptions.get(2).getTable());

    // create snapshot for only one table and delete snapshot for dropped table
    argsParam = new String[]{"localhost", ".*", "--keep=1", "--test", "--delete-snapshot-for-not-existing-table"};
    args = new SnapshotArgs(argsParam);
    app = new Snapshot(admin, args);
    Thread.sleep(1000);
    app.run();
    snapshotDescriptions = listSnapshots(tableName + ".*");
    assertEquals(2, snapshotDescriptions.size());
    assertEquals(tableName2, snapshotDescriptions.get(0).getTable());
    assertEquals(shouldNotBeDeleted, snapshotDescriptions.get(0).getName());
    assertEquals(tableName, snapshotDescriptions.get(1).getTable());
}
 
Example 20
Source Project: hbase-tools   File: TestBase.java    License: Apache License 2.0 4 votes vote down vote up
protected List<HBaseProtos.SnapshotDescription> listSnapshots(String tableName) throws IOException {
    return admin.listSnapshots(tableName);
}