Skip to content

Commit

Permalink
accept exec variable for maven plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
jetoile committed Apr 3, 2016
1 parent bdb80f8 commit de22c70
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ To use it, add into the pom project stuff like that:
</executions>
<configuration>
<hadoopUnitPath>/home/khanh/tools/hadoop-unit-standalone</hadoopUnitPath>
<exec>./hadoop-unit-standalone</exec>
<values>
<value>ZOOKEEPER</value>
<value>HDFS</value>
Expand All @@ -398,6 +399,7 @@ To use it, add into the pom project stuff like that:
</executions>
<configuration>
<hadoopUnitPath>/home/khanh/tools/hadoop-unit-standalone</hadoopUnitPath>
<exec>./hadoop-unit-standalone</exec>
<outputFile>/tmp/toto.txt</outputFile>
</configuration>
Expand All @@ -416,6 +418,8 @@ Values can be:
hadoopUnitPath is not mandatory but system enviroment variable HADOOP_UNIT_HOME must be defined.
exec variable is optional.
If both are set, HADOOP_UNIT_HOME override hadoopUnitPath.
Warning: This plugin will modify hadoop.properties and delete hadoop unit logs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.commons.lang.StringUtils;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.BuildPluginManager;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;

import java.io.*;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
Expand All @@ -32,6 +32,9 @@ public class HadoopBootstrapRemoteStarter extends AbstractMojo {
@Parameter(property = "outputFile")
protected String outputFile;

@Parameter(property = "exec")
protected String exec;

@Component
private MavenProject project;

Expand All @@ -42,7 +45,6 @@ public class HadoopBootstrapRemoteStarter extends AbstractMojo {
private BuildPluginManager pluginManager;



@Override
public void execute() throws MojoExecutionException, MojoFailureException {
HadoopBootstrapRemoteUtils utils = new HadoopBootstrapRemoteUtils(project, session, pluginManager);
Expand All @@ -58,8 +60,8 @@ public void execute() throws MojoExecutionException, MojoFailureException {
Path hadoopLogFilePath = Paths.get(hadoopUnitPath, "wrapper.log");
deleteLogFile(hadoopLogFilePath);

getLog().info("is going to start hadoop unit");
utils.operateRemoteHadoopUnit(hadoopUnitPath, outputFile, "start");
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");
Expand Down Expand Up @@ -88,7 +90,6 @@ private void editHadoopUnitConfFile() {
}



private void deleteLogFile(Path hadoopLogFilePath) {
getLog().info("is going to delete log file");
if (hadoopLogFilePath.toFile().exists() && hadoopLogFilePath.toFile().canWrite()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public class HadoopBootstrapRemoteStopper extends AbstractMojo {
@Parameter(property = "outputFile")
protected String outputFile;

@Parameter(property = "exec")
protected String exec;

@Component
private MavenProject project;

Expand All @@ -47,8 +50,8 @@ public void execute() throws MojoExecutionException, MojoFailureException {

utils.getHadoopUnitPath(hadoopUnitPath, getLog());

getLog().info("is going to stop hadoop unit");
utils.operateRemoteHadoopUnit(hadoopUnitPath, outputFile, "stop");
getLog().info("is going to stop hadoop unit with executable " + ((exec == null) ? "./hadoop-unit-standalone" : exec));
utils.operateRemoteHadoopUnit(hadoopUnitPath, outputFile, "stop", exec);
Path hadoopLogFilePath = Paths.get(hadoopUnitPath, "wrapper.log");

getLog().info("is going tail log file");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ public HadoopBootstrapRemoteUtils(MavenProject project, MavenSession session, Bu
this.pluginManager = pluginManager;
}

public void operateRemoteHadoopUnit(String hadoopUnitPath, String outputFile, String op) throws MojoExecutionException {
public void operateRemoteHadoopUnit(String hadoopUnitPath, String outputFile, String op, String exec) throws MojoExecutionException {
if (exec == null) {
exec = "./hadoop-unit-standalone";
}
executeMojo(
plugin(
groupId("org.codehaus.mojo"),
Expand All @@ -38,7 +41,7 @@ public void operateRemoteHadoopUnit(String hadoopUnitPath, String outputFile, St
goal("exec"),
configuration(
element(name("workingDirectory"), hadoopUnitPath + "/bin"),
element(name("executable"), "./hadoop-unit-standalone"),
element(name("executable"), exec),
element(name("commandlineArgs"), op),
element(name("outputFile"), outputFile)
),
Expand Down

0 comments on commit de22c70

Please sign in to comment.