/** Delete and recreate the data directory. */ private void setUpDataDir() { // Create primary data dir if it does not exist File dataDir = new File(hdfsFrameworkConfig.getDataDir()); FileUtils.createDir(dataDir); // Create secondary data dir if it does not exist File secondaryDataDir = new File(hdfsFrameworkConfig.getSecondaryDataDir()); FileUtils.createDir(secondaryDataDir); }
/** Create Symbolic Link for the HDFS binary. */ private void createSymbolicLink() { log.info("Creating a symbolic link for HDFS binary"); try { // Find Hdfs binary in sandbox File sandboxHdfsBinary = new File(System.getProperty("user.dir")); Path sandboxHdfsBinaryPath = Paths.get(sandboxHdfsBinary.getAbsolutePath()); // Create mesosphere opt dir (parent dir of the symbolic link) if it does not exist File frameworkMountDir = new File(hdfsFrameworkConfig.getFrameworkMountPath()); FileUtils.createDir(frameworkMountDir); // Delete and recreate directory for symbolic link every time String hdfsBinaryPath = hdfsFrameworkConfig.getFrameworkMountPath() + "/" + HDFSConstants.HDFS_BINARY_DIR; File hdfsBinaryDir = new File(hdfsBinaryPath); // Try to delete the symbolic link in case a dangling link is present try { ProcessBuilder processBuilder = new ProcessBuilder("unlink", hdfsBinaryPath); Process process = processBuilder.start(); redirectProcess(process); int exitCode = process.waitFor(); if (exitCode != 0) { log.info("Unable to unlink old sym link. Link may not exist. Exit code: " + exitCode); } } catch (IOException e) { log.fatal("Could not unlink " + hdfsBinaryPath, e); throw e; } // Delete the file if it exists if (hdfsBinaryDir.exists() && !FileUtils.deleteDirectory(hdfsBinaryDir)) { String msg = "Unable to delete file: " + hdfsBinaryDir; log.error(msg); throw new ExecutorException(msg); } // Create symbolic link Path hdfsLinkDirPath = Paths.get(hdfsBinaryPath); Files.createSymbolicLink(hdfsLinkDirPath, sandboxHdfsBinaryPath); log.info("The linked HDFS binary path is: " + sandboxHdfsBinaryPath); log.info("The symbolic link path is: " + hdfsLinkDirPath); // Adding binary to the PATH environment variable addBinaryToPath(hdfsBinaryPath); } catch (IOException | InterruptedException e) { String msg = "Error creating the symbolic link to hdfs binary"; shutdownExecutor(1, msg, e); } }