com.github.alexcojocaru.mojo.elasticsearch.v2.StopMojo Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of elasticsearch-maven-plugin Show documentation
Show all versions of elasticsearch-maven-plugin Show documentation
A Maven plugin to run a single node Elasticsearch cluster during the integration test phase of a build
package com.github.alexcojocaru.mojo.elasticsearch.v2;
import org.apache.commons.exec.CommandLine;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import com.github.alexcojocaru.mojo.elasticsearch.v2.util.ProcessUtil;
/**
* The main plugin mojo to stop a forked ES instances.
*
* @author Alex Cojocaru
*/
@Mojo(name = "stop", defaultPhase = LifecyclePhase.POST_INTEGRATION_TEST)
public class StopMojo
extends AbstractElasticsearchBaseMojo
{
@Override
public void execute() throws MojoExecutionException, MojoFailureException
{
if (skip)
{
getLog().info("Skipping plugin execution");
return;
}
ClusterConfiguration clusterConfig = buildClusterConfiguration();
for (InstanceConfiguration config : clusterConfig.getInstanceConfigurationList())
{
try
{
getLog().info(String.format("Stopping Elasticsearch [%s]", config));
String baseDir = config.getBaseDir();
ProcessUtil.executeScript(config, getShutdownScriptCommand(baseDir));
getLog().info(String.format("Elasticsearch [%d] stopped", config.getId()));
}
catch (Exception e)
{
getLog().error("Exception while stopping Elasticsearch", e);
}
}
}
protected CommandLine getShutdownScriptCommand(String basePath)
{
String pid = ProcessUtil.getElasticsearchPid(basePath);
return ProcessUtil.buildKillCommandLine(pid);
}
}