@Test public void formatWorker() throws Exception { final int storageLevels = 3; final String perms = "rwx------"; String workerDataFolder; final File[] dirs = new File[] { mTemporaryFolder.newFolder("level0"), mTemporaryFolder.newFolder("level1"), mTemporaryFolder.newFolder("level2") }; for (File dir : dirs) { workerDataFolder = CommonUtils.getWorkerDataDirectory(dir.getPath(), ServerConfiguration.global()); FileUtils.createDir(PathUtils.concatPath(workerDataFolder, "subdir")); FileUtils.createFile(PathUtils.concatPath(workerDataFolder, "file")); } try (Closeable r = new ConfigurationRule(new HashMap<PropertyKey, String>() { { put(PropertyKey.WORKER_TIERED_STORE_LEVEL0_DIRS_PATH, dirs[0].getPath()); put(PropertyKey.WORKER_TIERED_STORE_LEVEL1_DIRS_PATH, dirs[1].getPath()); put(PropertyKey.WORKER_TIERED_STORE_LEVEL2_DIRS_PATH, dirs[2].getPath()); put(PropertyKey.WORKER_TIERED_STORE_LEVELS, String.valueOf(storageLevels)); put(PropertyKey.WORKER_DATA_FOLDER_PERMISSIONS, perms); } }, ServerConfiguration.global()).toResource()) { Format.format(Format.Mode.WORKER, ServerConfiguration.global()); for (File dir : dirs) { workerDataFolder = CommonUtils.getWorkerDataDirectory(dir.getPath(), ServerConfiguration.global()); assertTrue(FileUtils.exists(dir.getPath())); assertTrue(FileUtils.exists(workerDataFolder)); assertEquals(PosixFilePermissions.fromString(perms), Files.getPosixFilePermissions(Paths .get(workerDataFolder))); try (DirectoryStream<Path> directoryStream = Files .newDirectoryStream(Paths.get(workerDataFolder))) { for (Path child : directoryStream) { fail("No sub dirs or files are expected in " + child.toString()); } } } } }
public static void format(Mode mode, AlluxioConfiguration alluxioConf) throws IOException { switch (mode) { case MASTER: URI journalLocation = JournalUtils.getJournalLocation(); LOG.info("Formatting master journal: {}", journalLocation); JournalSystem journalSystem = new JournalSystem.Builder() .setLocation(journalLocation).build(CommonUtils.ProcessType.MASTER); for (String masterServiceName : ServiceUtils.getMasterServiceNames()) { journalSystem.createJournal(new NoopMaster(masterServiceName)); } journalSystem.format(); break; case WORKER: String workerDataFolder = ServerConfiguration.get(PropertyKey.WORKER_DATA_FOLDER); LOG.info("Formatting worker data folder: {}", workerDataFolder); int storageLevels = ServerConfiguration.getInt(PropertyKey.WORKER_TIERED_STORE_LEVELS); for (int level = 0; level < storageLevels; level++) { PropertyKey tierLevelDirPath = PropertyKey.Template.WORKER_TIERED_STORE_LEVEL_DIRS_PATH.format(level); String[] dirPaths = ServerConfiguration.get(tierLevelDirPath).split(","); String name = "Data path for tier " + level; for (String dirPath : dirPaths) { String dirWorkerDataFolder = CommonUtils.getWorkerDataDirectory(dirPath, alluxioConf); LOG.info("Formatting {}:{}", name, dirWorkerDataFolder); formatWorkerDataFolder(dirWorkerDataFolder); } } break; default: throw new RuntimeException(String.format("Unrecognized format mode: %s", mode)); } }
Format { public static void format(Mode mode, AlluxioConfiguration alluxioConf) throws IOException { switch (mode) { case MASTER: URI journalLocation = JournalUtils.getJournalLocation(); LOG.info("Formatting master journal: {}", journalLocation); JournalSystem journalSystem = new JournalSystem.Builder() .setLocation(journalLocation).build(CommonUtils.ProcessType.MASTER); for (String masterServiceName : ServiceUtils.getMasterServiceNames()) { journalSystem.createJournal(new NoopMaster(masterServiceName)); } journalSystem.format(); break; case WORKER: String workerDataFolder = ServerConfiguration.get(PropertyKey.WORKER_DATA_FOLDER); LOG.info("Formatting worker data folder: {}", workerDataFolder); int storageLevels = ServerConfiguration.getInt(PropertyKey.WORKER_TIERED_STORE_LEVELS); for (int level = 0; level < storageLevels; level++) { PropertyKey tierLevelDirPath = PropertyKey.Template.WORKER_TIERED_STORE_LEVEL_DIRS_PATH.format(level); String[] dirPaths = ServerConfiguration.get(tierLevelDirPath).split(","); String name = "Data path for tier " + level; for (String dirPath : dirPaths) { String dirWorkerDataFolder = CommonUtils.getWorkerDataDirectory(dirPath, alluxioConf); LOG.info("Formatting {}:{}", name, dirWorkerDataFolder); formatWorkerDataFolder(dirWorkerDataFolder); } } break; default: throw new RuntimeException(String.format("Unrecognized format mode: %s", mode)); } } }
Format { public static void format(Mode mode, AlluxioConfiguration alluxioConf) throws IOException { switch (mode) { case MASTER: URI journalLocation = JournalUtils.getJournalLocation(); LOG.info("Formatting master journal: {}", journalLocation); JournalSystem journalSystem = new JournalSystem.Builder() .setLocation(journalLocation).build(CommonUtils.ProcessType.MASTER); for (String masterServiceName : ServiceUtils.getMasterServiceNames()) { journalSystem.createJournal(new NoopMaster(masterServiceName)); } journalSystem.format(); break; case WORKER: String workerDataFolder = ServerConfiguration.get(PropertyKey.WORKER_DATA_FOLDER); LOG.info("Formatting worker data folder: {}", workerDataFolder); int storageLevels = ServerConfiguration.getInt(PropertyKey.WORKER_TIERED_STORE_LEVELS); for (int level = 0; level < storageLevels; level++) { PropertyKey tierLevelDirPath = PropertyKey.Template.WORKER_TIERED_STORE_LEVEL_DIRS_PATH.format(level); String[] dirPaths = ServerConfiguration.get(tierLevelDirPath).split(","); String name = "Data path for tier " + level; for (String dirPath : dirPaths) { String dirWorkerDataFolder = CommonUtils.getWorkerDataDirectory(dirPath, alluxioConf); LOG.info("Formatting {}:{}", name, dirWorkerDataFolder); formatWorkerDataFolder(dirWorkerDataFolder); } } break; default: throw new RuntimeException(String.format("Unrecognized format mode: %s", mode)); } } private  Format(); }
Format { public static void format(Mode mode, AlluxioConfiguration alluxioConf) throws IOException { switch (mode) { case MASTER: URI journalLocation = JournalUtils.getJournalLocation(); LOG.info("Formatting master journal: {}", journalLocation); JournalSystem journalSystem = new JournalSystem.Builder() .setLocation(journalLocation).build(CommonUtils.ProcessType.MASTER); for (String masterServiceName : ServiceUtils.getMasterServiceNames()) { journalSystem.createJournal(new NoopMaster(masterServiceName)); } journalSystem.format(); break; case WORKER: String workerDataFolder = ServerConfiguration.get(PropertyKey.WORKER_DATA_FOLDER); LOG.info("Formatting worker data folder: {}", workerDataFolder); int storageLevels = ServerConfiguration.getInt(PropertyKey.WORKER_TIERED_STORE_LEVELS); for (int level = 0; level < storageLevels; level++) { PropertyKey tierLevelDirPath = PropertyKey.Template.WORKER_TIERED_STORE_LEVEL_DIRS_PATH.format(level); String[] dirPaths = ServerConfiguration.get(tierLevelDirPath).split(","); String name = "Data path for tier " + level; for (String dirPath : dirPaths) { String dirWorkerDataFolder = CommonUtils.getWorkerDataDirectory(dirPath, alluxioConf); LOG.info("Formatting {}:{}", name, dirWorkerDataFolder); formatWorkerDataFolder(dirWorkerDataFolder); } } break; default: throw new RuntimeException(String.format("Unrecognized format mode: %s", mode)); } } private  Format(); static void main(String[] args); static void format(Mode mode, AlluxioConfiguration alluxioConf); }
Format { public static void format(Mode mode, AlluxioConfiguration alluxioConf) throws IOException { switch (mode) { case MASTER: URI journalLocation = JournalUtils.getJournalLocation(); LOG.info("Formatting master journal: {}", journalLocation); JournalSystem journalSystem = new JournalSystem.Builder() .setLocation(journalLocation).build(CommonUtils.ProcessType.MASTER); for (String masterServiceName : ServiceUtils.getMasterServiceNames()) { journalSystem.createJournal(new NoopMaster(masterServiceName)); } journalSystem.format(); break; case WORKER: String workerDataFolder = ServerConfiguration.get(PropertyKey.WORKER_DATA_FOLDER); LOG.info("Formatting worker data folder: {}", workerDataFolder); int storageLevels = ServerConfiguration.getInt(PropertyKey.WORKER_TIERED_STORE_LEVELS); for (int level = 0; level < storageLevels; level++) { PropertyKey tierLevelDirPath = PropertyKey.Template.WORKER_TIERED_STORE_LEVEL_DIRS_PATH.format(level); String[] dirPaths = ServerConfiguration.get(tierLevelDirPath).split(","); String name = "Data path for tier " + level; for (String dirPath : dirPaths) { String dirWorkerDataFolder = CommonUtils.getWorkerDataDirectory(dirPath, alluxioConf); LOG.info("Formatting {}:{}", name, dirWorkerDataFolder); formatWorkerDataFolder(dirWorkerDataFolder); } } break; default: throw new RuntimeException(String.format("Unrecognized format mode: %s", mode)); } } private  Format(); static void main(String[] args); static void format(Mode mode, AlluxioConfiguration alluxioConf);  }