Search in sources :

Example 1 with CacheFileAction

use of org.smartdata.hdfs.action.CacheFileAction in project SSM by Intel-bigdata.

the class TestCmdlet method runHelper.

private Cmdlet runHelper() throws IOException {
    SmartAction[] actions = new SmartAction[4];
    // New action
    // actions[0] = new AllSsdFileAction();
    // actions[0].setDfsClient(client);
    // actions[0].setContext(new SmartContext(smartConf));
    // actions[0].getDNStorageReports(new String[]{"/testMoveFile/file1"});
    // actions[1] = new MoveFileAction();
    // actions[1].setDfsClient(client);
    // actions[1].setContext(new SmartContext(smartConf));
    // actions[1].getDNStorageReports(new String[]{"/testMoveFile/file2", "COLD"});
    actions[2] = new CacheFileAction();
    ((HdfsAction) actions[2]).setDfsClient(dfsClient);
    actions[2].setContext(smartContext);
    Map<String, String> args = new HashMap();
    args.put(CacheFileAction.FILE_PATH, "/testCacheFile");
    actions[2].init(args);
    // New Cmdlet
    Cmdlet cmd = new Cmdlet(Arrays.asList(actions));
    cmd.setId(1);
    cmd.setRuleId(1);
    cmd.setState(CmdletState.PENDING);
    return cmd;
}
Also used : CacheFileAction(org.smartdata.hdfs.action.CacheFileAction) HdfsAction(org.smartdata.hdfs.action.HdfsAction) HashMap(java.util.HashMap) SmartAction(org.smartdata.action.SmartAction)

Example 2 with CacheFileAction

use of org.smartdata.hdfs.action.CacheFileAction in project SSM by Intel-bigdata.

the class TestCachedListFetcher method testFetcher.

@Test
public void testFetcher() throws Exception {
    String pathPrefix = "/fileTest/cache/";
    String[] fids = { "5", "7", "9", "10" };
    Path dir = new Path(pathPrefix);
    dfs.mkdirs(dir);
    dfs.setStoragePolicy(dir, "HOT");
    List<FileInfo> fileInfos = new ArrayList<>();
    for (int i = 0; i < fids.length; i++) {
        CacheFileAction cacheAction = new CacheFileAction();
        String path = pathPrefix + fids[i];
        FSDataOutputStream out = dfs.create(new Path(path));
        out.writeChars("testUncache");
        out.close();
        // Create cache pool
        CacheScheduler.createCachePool(dfsClient);
        fileInfos.add(createFileStatus(pathPrefix + fids[i]));
        cacheAction.setContext(smartContext);
        cacheAction.setDfsClient(dfsClient);
        Map<String, String> args = new HashMap();
        args.put(CacheFileAction.FILE_PATH, path);
        cacheAction.init(args);
        cacheAction.run();
    // System.out.println(cacheAction.isCached(path));
    }
    metaStore.insertFiles(fileInfos.toArray(new FileInfo[fileInfos.size()]));
    List<FileInfo> ret = metaStore.getFile();
    Assert.assertTrue(ret.size() == fids.length);
    cachedListFetcher.start();
    Thread.sleep(1000);
    List<CachedFileStatus> cachedFileStatuses = cachedListFetcher.getCachedList();
    Assert.assertTrue(cachedFileStatuses.size() == fids.length);
    int unCachedSize = 2;
    for (int i = 0; i < unCachedSize; i++) {
        UncacheFileAction uncacheFileAction = new UncacheFileAction();
        String path = pathPrefix + fids[i];
        fileInfos.add(createFileStatus("fileTest/cache/" + fids[i]));
        uncacheFileAction.setContext(smartContext);
        uncacheFileAction.setDfsClient(dfsClient);
        Map<String, String> args = new HashMap();
        args.put(UncacheFileAction.FILE_PATH, path);
        uncacheFileAction.init(args);
        uncacheFileAction.run();
    }
    // System.out.println(uncacheFileAction .isCached(path));
    Thread.sleep(2000);
    cachedFileStatuses = cachedListFetcher.getCachedList();
    Assert.assertTrue(cachedFileStatuses.size() == fids.length - unCachedSize);
}
Also used : Path(org.apache.hadoop.fs.Path) CacheFileAction(org.smartdata.hdfs.action.CacheFileAction) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) UncacheFileAction(org.smartdata.hdfs.action.UncacheFileAction) FileInfo(org.smartdata.model.FileInfo) CachedFileStatus(org.smartdata.model.CachedFileStatus) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)2 CacheFileAction (org.smartdata.hdfs.action.CacheFileAction)2 ArrayList (java.util.ArrayList)1 FSDataOutputStream (org.apache.hadoop.fs.FSDataOutputStream)1 Path (org.apache.hadoop.fs.Path)1 Test (org.junit.Test)1 SmartAction (org.smartdata.action.SmartAction)1 HdfsAction (org.smartdata.hdfs.action.HdfsAction)1 UncacheFileAction (org.smartdata.hdfs.action.UncacheFileAction)1 CachedFileStatus (org.smartdata.model.CachedFileStatus)1 FileInfo (org.smartdata.model.FileInfo)1