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;
}
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);
}
Aggregations