private void deleteLogFile(Path hadoopLogFilePath) { getLog().info("is going to delete log file"); if (hadoopLogFilePath.toFile().exists() && hadoopLogFilePath.toFile().canWrite()) { if (!hadoopLogFilePath.toFile().delete()) { getLog().warn("unable to delete log file"); } getLog().info("delete log file done"); } }
@Override public void execute() throws MojoExecutionException, MojoFailureException { if (skipTests) { getLog().info("Hadoop Unit's start goal is skipped"); } else { HadoopBootstrapRemoteUtils utils = new HadoopBootstrapRemoteUtils(project, session, pluginManager); hadoopUnitPath = utils.getHadoopUnitPath(hadoopUnitPath, getLog()); //change hadoop.properties getLog().info("is going to modifying hadoop.properties"); editHadoopUnitConfFile(); getLog().info("modifying hadoop.properties done"); //clean log file Path hadoopLogFilePath = Paths.get(hadoopUnitPath, "wrapper.log"); deleteLogFile(hadoopLogFilePath); getLog().info("is going to start hadoop unit with executable " + ((exec == null) ? "./hadoop-unit-standalone" : exec)); utils.operateRemoteHadoopUnit(hadoopUnitPath, outputFile, "start", exec); //listen to log file and wait getLog().info("is going tail log file"); utils.tailLogFileUntilFind(hadoopLogFilePath, "/_/ /_/ \\__,_/ \\__,_/ \\____/\\____/_ .___/ \\____/ /_/ /_//_/ \\__/", getLog()); getLog().info("hadoop unit started"); } }
private void editHadoopUnitConfFile() { Path hadoopPropertiesPath = Paths.get(hadoopUnitPath, "conf", "hadoop.properties"); Path hadoopPropertiesBackupPath = Paths.get(hadoopUnitPath, "conf", "hadoop.properties.old"); if (hadoopPropertiesBackupPath.toFile().exists() && hadoopPropertiesBackupPath.toFile().canWrite()) { hadoopPropertiesBackupPath.toFile().delete(); } hadoopPropertiesPath.toFile().renameTo(hadoopPropertiesBackupPath.toFile()); PropertiesConfiguration configuration = new PropertiesConfiguration(); values.forEach(v -> configuration.addProperty(v.toLowerCase(), "true")); try { configuration.save(new FileWriter(hadoopPropertiesPath.toFile())); } catch (ConfigurationException | IOException e) { getLog().error("unable to find or modifying hadoop.properties. Check user rights", e); } }