@Test public void testEcActionForFile() throws Exception { String srcPath = "/ec/test_file"; createTestFile(srcPath, 100000000); dfsClient.setStoragePolicy(srcPath, "COLD"); HdfsFileStatus srcFileStatus = dfsClient.getFileInfo(srcPath); assertEquals(null, srcFileStatus.getErasureCodingPolicy()); ErasureCodingAction ecAction = new ErasureCodingAction(); ecAction.setContext(smartContext); String ecTmpPath = "/ssm/ec_tmp/tmp_file"; Map<String, String> args = new HashMap<>(); args.put(HdfsAction.FILE_PATH, srcPath); args.put(ErasureCodingBase.EC_TMP, ecTmpPath); args.put(ErasureCodingAction.EC_POLICY_NAME, ecPolicy.getName()); ecAction.init(args); ecAction.run(); assertTrue(ecAction.getExpectedAfterRun()); HdfsFileStatus fileStatus = dfsClient.getFileInfo(srcPath); assertEquals(ecPolicy, fileStatus.getErasureCodingPolicy()); assertEquals(srcFileStatus.getLen(), fileStatus.getLen()); assertEquals(srcFileStatus.getModificationTime(), fileStatus.getModificationTime()); assertEquals(srcFileStatus.getAccessTime(), fileStatus.getAccessTime()); assertEquals(srcFileStatus.getOwner(), fileStatus.getOwner()); assertEquals(srcFileStatus.getGroup(), fileStatus.getGroup()); assertEquals(srcFileStatus.getPermission(), fileStatus.getPermission()); if (srcFileStatus.getStoragePolicy() != 0) { assertEquals(srcFileStatus.getStoragePolicy(), fileStatus.getStoragePolicy()); } }
@Override public void init(Map<String, String> args) { super.init(args); this.conf = getContext().getConf(); this.srcPath = args.get(FILE_PATH); if (args.containsKey(EC_TMP)) { this.ecTmpPath = args.get(EC_TMP); } if (args.containsKey(EC_POLICY_NAME) && !args.get(EC_POLICY_NAME).isEmpty()) { this.ecPolicyName = args.get(EC_POLICY_NAME); } else { String defaultEcPolicy = conf.getTrimmed(DFSConfigKeys.DFS_NAMENODE_EC_SYSTEM_DEFAULT_POLICY, DFSConfigKeys.DFS_NAMENODE_EC_SYSTEM_DEFAULT_POLICY_DEFAULT); this.ecPolicyName = defaultEcPolicy; } if (args.containsKey(BUF_SIZE) && !args.get(BUF_SIZE).isEmpty()) { this.bufferSize = (int) StringUtil.parseToByte(args.get(BUF_SIZE)); } this.progress = 0.0F; }
ErasureCodingAction extends ErasureCodingBase { @Override public void init(Map<String, String> args) { super.init(args); this.conf = getContext().getConf(); this.srcPath = args.get(FILE_PATH); if (args.containsKey(EC_TMP)) { this.ecTmpPath = args.get(EC_TMP); } if (args.containsKey(EC_POLICY_NAME) && !args.get(EC_POLICY_NAME).isEmpty()) { this.ecPolicyName = args.get(EC_POLICY_NAME); } else { String defaultEcPolicy = conf.getTrimmed(DFSConfigKeys.DFS_NAMENODE_EC_SYSTEM_DEFAULT_POLICY, DFSConfigKeys.DFS_NAMENODE_EC_SYSTEM_DEFAULT_POLICY_DEFAULT); this.ecPolicyName = defaultEcPolicy; } if (args.containsKey(BUF_SIZE) && !args.get(BUF_SIZE).isEmpty()) { this.bufferSize = (int) StringUtil.parseToByte(args.get(BUF_SIZE)); } this.progress = 0.0F; } }
ErasureCodingAction extends ErasureCodingBase { @Override public void init(Map<String, String> args) { super.init(args); this.conf = getContext().getConf(); this.srcPath = args.get(FILE_PATH); if (args.containsKey(EC_TMP)) { this.ecTmpPath = args.get(EC_TMP); } if (args.containsKey(EC_POLICY_NAME) && !args.get(EC_POLICY_NAME).isEmpty()) { this.ecPolicyName = args.get(EC_POLICY_NAME); } else { String defaultEcPolicy = conf.getTrimmed(DFSConfigKeys.DFS_NAMENODE_EC_SYSTEM_DEFAULT_POLICY, DFSConfigKeys.DFS_NAMENODE_EC_SYSTEM_DEFAULT_POLICY_DEFAULT); this.ecPolicyName = defaultEcPolicy; } if (args.containsKey(BUF_SIZE) && !args.get(BUF_SIZE).isEmpty()) { this.bufferSize = (int) StringUtil.parseToByte(args.get(BUF_SIZE)); } this.progress = 0.0F; }  }
ErasureCodingAction extends ErasureCodingBase { @Override public void init(Map<String, String> args) { super.init(args); this.conf = getContext().getConf(); this.srcPath = args.get(FILE_PATH); if (args.containsKey(EC_TMP)) { this.ecTmpPath = args.get(EC_TMP); } if (args.containsKey(EC_POLICY_NAME) && !args.get(EC_POLICY_NAME).isEmpty()) { this.ecPolicyName = args.get(EC_POLICY_NAME); } else { String defaultEcPolicy = conf.getTrimmed(DFSConfigKeys.DFS_NAMENODE_EC_SYSTEM_DEFAULT_POLICY, DFSConfigKeys.DFS_NAMENODE_EC_SYSTEM_DEFAULT_POLICY_DEFAULT); this.ecPolicyName = defaultEcPolicy; } if (args.containsKey(BUF_SIZE) && !args.get(BUF_SIZE).isEmpty()) { this.bufferSize = (int) StringUtil.parseToByte(args.get(BUF_SIZE)); } this.progress = 0.0F; }  @Override void init(Map<String, String> args); void validateEcPolicy(String ecPolicyName); @Override float getProgress(); }
ErasureCodingAction extends ErasureCodingBase { @Override public void init(Map<String, String> args) { super.init(args); this.conf = getContext().getConf(); this.srcPath = args.get(FILE_PATH); if (args.containsKey(EC_TMP)) { this.ecTmpPath = args.get(EC_TMP); } if (args.containsKey(EC_POLICY_NAME) && !args.get(EC_POLICY_NAME).isEmpty()) { this.ecPolicyName = args.get(EC_POLICY_NAME); } else { String defaultEcPolicy = conf.getTrimmed(DFSConfigKeys.DFS_NAMENODE_EC_SYSTEM_DEFAULT_POLICY, DFSConfigKeys.DFS_NAMENODE_EC_SYSTEM_DEFAULT_POLICY_DEFAULT); this.ecPolicyName = defaultEcPolicy; } if (args.containsKey(BUF_SIZE) && !args.get(BUF_SIZE).isEmpty()) { this.bufferSize = (int) StringUtil.parseToByte(args.get(BUF_SIZE)); } this.progress = 0.0F; }  @Override void init(Map<String, String> args); void validateEcPolicy(String ecPolicyName); @Override float getProgress(); static final String EC_POLICY_NAME; }