@Test public void test_predicate() throws IOException { SegmentPredicate predicate = new SegmentPredicate(); predicate.setConfig("test config"); Map<String, Object> configMap = new HashMap<>(); configMap.put("path", fileName); configMap.put("root.path", rootPath); predicate.setConfigMap(configMap); FileExistPredicator predicator = new FileExistPredicator(predicate); assertTrue(predicator.predicate()); configMap.put("path", "fileName"); predicate.setConfigMap(configMap); assertFalse(predicator.predicate()); }
@Override public boolean predicate() throws IOException { Map<String, Object> config = predicate.getConfigMap(); String[] paths = null; String rootPath = null; if (config != null && !StringUtils.isEmpty((String) config.get(PREDICT_PATH))) { paths = ((String) config.get(PREDICT_PATH)) .split(PATH_CONNECTOR_CHARACTER); rootPath = (String) config.get(PREDICT_ROOT_PATH); } if (ArrayUtils.isEmpty(paths) || StringUtils.isEmpty(rootPath)) { LOGGER.error("Predicate path is null.Please check predicates " + "config root.path and path."); throw new NullPointerException(); } for (String path : paths) { String hdfsPath = rootPath + path; LOGGER.info("Predicate path: {}", hdfsPath); if (!FSUtil.isFileExist(hdfsPath)) { LOGGER.info("Predicate path: " + hdfsPath + " doesn't exist."); return false; } LOGGER.info("Predicate path: " + hdfsPath + " exists."); } return true; }
FileExistPredicator implements Predicator { @Override public boolean predicate() throws IOException { Map<String, Object> config = predicate.getConfigMap(); String[] paths = null; String rootPath = null; if (config != null && !StringUtils.isEmpty((String) config.get(PREDICT_PATH))) { paths = ((String) config.get(PREDICT_PATH)) .split(PATH_CONNECTOR_CHARACTER); rootPath = (String) config.get(PREDICT_ROOT_PATH); } if (ArrayUtils.isEmpty(paths) || StringUtils.isEmpty(rootPath)) { LOGGER.error("Predicate path is null.Please check predicates " + "config root.path and path."); throw new NullPointerException(); } for (String path : paths) { String hdfsPath = rootPath + path; LOGGER.info("Predicate path: {}", hdfsPath); if (!FSUtil.isFileExist(hdfsPath)) { LOGGER.info("Predicate path: " + hdfsPath + " doesn't exist."); return false; } LOGGER.info("Predicate path: " + hdfsPath + " exists."); } return true; } }
FileExistPredicator implements Predicator { @Override public boolean predicate() throws IOException { Map<String, Object> config = predicate.getConfigMap(); String[] paths = null; String rootPath = null; if (config != null && !StringUtils.isEmpty((String) config.get(PREDICT_PATH))) { paths = ((String) config.get(PREDICT_PATH)) .split(PATH_CONNECTOR_CHARACTER); rootPath = (String) config.get(PREDICT_ROOT_PATH); } if (ArrayUtils.isEmpty(paths) || StringUtils.isEmpty(rootPath)) { LOGGER.error("Predicate path is null.Please check predicates " + "config root.path and path."); throw new NullPointerException(); } for (String path : paths) { String hdfsPath = rootPath + path; LOGGER.info("Predicate path: {}", hdfsPath); if (!FSUtil.isFileExist(hdfsPath)) { LOGGER.info("Predicate path: " + hdfsPath + " doesn't exist."); return false; } LOGGER.info("Predicate path: " + hdfsPath + " exists."); } return true; } FileExistPredicator(SegmentPredicate predicate); }
FileExistPredicator implements Predicator { @Override public boolean predicate() throws IOException { Map<String, Object> config = predicate.getConfigMap(); String[] paths = null; String rootPath = null; if (config != null && !StringUtils.isEmpty((String) config.get(PREDICT_PATH))) { paths = ((String) config.get(PREDICT_PATH)) .split(PATH_CONNECTOR_CHARACTER); rootPath = (String) config.get(PREDICT_ROOT_PATH); } if (ArrayUtils.isEmpty(paths) || StringUtils.isEmpty(rootPath)) { LOGGER.error("Predicate path is null.Please check predicates " + "config root.path and path."); throw new NullPointerException(); } for (String path : paths) { String hdfsPath = rootPath + path; LOGGER.info("Predicate path: {}", hdfsPath); if (!FSUtil.isFileExist(hdfsPath)) { LOGGER.info("Predicate path: " + hdfsPath + " doesn't exist."); return false; } LOGGER.info("Predicate path: " + hdfsPath + " exists."); } return true; } FileExistPredicator(SegmentPredicate predicate); @Override boolean predicate(); }
FileExistPredicator implements Predicator { @Override public boolean predicate() throws IOException { Map<String, Object> config = predicate.getConfigMap(); String[] paths = null; String rootPath = null; if (config != null && !StringUtils.isEmpty((String) config.get(PREDICT_PATH))) { paths = ((String) config.get(PREDICT_PATH)) .split(PATH_CONNECTOR_CHARACTER); rootPath = (String) config.get(PREDICT_ROOT_PATH); } if (ArrayUtils.isEmpty(paths) || StringUtils.isEmpty(rootPath)) { LOGGER.error("Predicate path is null.Please check predicates " + "config root.path and path."); throw new NullPointerException(); } for (String path : paths) { String hdfsPath = rootPath + path; LOGGER.info("Predicate path: {}", hdfsPath); if (!FSUtil.isFileExist(hdfsPath)) { LOGGER.info("Predicate path: " + hdfsPath + " doesn't exist."); return false; } LOGGER.info("Predicate path: " + hdfsPath + " exists."); } return true; } FileExistPredicator(SegmentPredicate predicate); @Override boolean predicate();  }