Search in sources :

Example 6 with InstanceConfiguration

use of com.github.alexcojocaru.mojo.elasticsearch.v2.InstanceConfiguration in project elasticsearch-maven-plugin by alexcojocaru.

the class RemoveExistingDataStepTest method testRemoveExistingData.

@Test
public void testRemoveExistingData() {
    InstanceConfiguration instanceConfig = mock(InstanceConfiguration.class);
    when(instanceConfig.getBaseDir()).thenReturn(".");
    ClusterConfiguration clusterConfig = new ClusterConfiguration.Builder().withKeepExistingData(false).build();
    when(instanceConfig.getClusterConfiguration()).thenReturn(clusterConfig);
    new RemoveExistingDataStep().execute(instanceConfig);
    // a bit convoluted, but this check that getBaseDir()
    // was called in order to build the data and logs directories.
    Mockito.verify(instanceConfig).getBaseDir();
}
Also used : InstanceConfiguration(com.github.alexcojocaru.mojo.elasticsearch.v2.InstanceConfiguration) ClusterConfiguration(com.github.alexcojocaru.mojo.elasticsearch.v2.ClusterConfiguration) Test(org.junit.Test)

Example 7 with InstanceConfiguration

use of com.github.alexcojocaru.mojo.elasticsearch.v2.InstanceConfiguration in project elasticsearch-maven-plugin by alexcojocaru.

the class RemoveExistingDataStepTest method testKeepExistingData.

@Test
public void testKeepExistingData() {
    InstanceConfiguration instanceConfig = mock(InstanceConfiguration.class);
    ClusterConfiguration clusterConfig = new ClusterConfiguration.Builder().withKeepExistingData(true).build();
    when(instanceConfig.getClusterConfiguration()).thenReturn(clusterConfig);
    new RemoveExistingDataStep().execute(instanceConfig);
    // a bit convoluted, but this check that getBaseDir()
    // was never called in order to build the data and logs directories.
    Mockito.verify(instanceConfig, never()).getBaseDir();
}
Also used : InstanceConfiguration(com.github.alexcojocaru.mojo.elasticsearch.v2.InstanceConfiguration) ClusterConfiguration(com.github.alexcojocaru.mojo.elasticsearch.v2.ClusterConfiguration) Test(org.junit.Test)

Example 8 with InstanceConfiguration

use of com.github.alexcojocaru.mojo.elasticsearch.v2.InstanceConfiguration in project elasticsearch-maven-plugin by alexcojocaru.

the class ResolveElasticsearchStep method execute.

@Override
public void execute(InstanceConfiguration config) {
    File unpackDirectory = null;
    try {
        File artifact = new ElasticsearchArtifactResolver(config.getClusterConfiguration()).resolve();
        unpackDirectory = unpackToElasticsearchDirectory(artifact, config);
        setupElasticsearchConf(config);
    } catch (ArtifactException | IOException e) {
        throw new RuntimeException(e);
    } finally {
        cleanUp(unpackDirectory, config.getClusterConfiguration());
    }
}
Also used : ElasticsearchArtifactResolver(com.github.alexcojocaru.mojo.elasticsearch.v2.step.resolveartifact.ElasticsearchArtifactResolver) ArtifactException(com.github.alexcojocaru.mojo.elasticsearch.v2.configuration.ArtifactException) IOException(java.io.IOException) File(java.io.File)

Example 9 with InstanceConfiguration

use of com.github.alexcojocaru.mojo.elasticsearch.v2.InstanceConfiguration in project elasticsearch-maven-plugin by alexcojocaru.

the class InstallPluginsStep method execute.

@Override
public void execute(InstanceConfiguration config) {
    if (config.getClusterConfiguration().getPlugins().size() > 0) {
        if (VersionUtil.isEqualOrGreater_6_4_0(config.getClusterConfiguration().getVersion())) {
            FilesystemUtil.setScriptPermission(config, "elasticsearch-cli");
        }
        FilesystemUtil.setScriptPermission(config, "elasticsearch-plugin");
    }
    Log log = config.getClusterConfiguration().getLog();
    for (PluginConfiguration plugin : config.getClusterConfiguration().getPlugins()) {
        log.info(String.format("Installing plugin '%s' with options '%s'", plugin.getUri(), plugin.getEsJavaOpts()));
        Map<String, String> environment = new HashMap<>(config.getEnvironmentVariables());
        if (StringUtils.isNotBlank(plugin.getEsJavaOpts())) {
            environment.put("ES_JAVA_OPTS", plugin.getEsJavaOpts());
        }
        CommandLine cmd = ProcessUtil.buildCommandLine("bin/elasticsearch-plugin").addArgument("install").addArgument("--batch").addArgument(plugin.getUri());
        ProcessUtil.executeScript(config, cmd, environment);
    }
}
Also used : CommandLine(org.apache.commons.exec.CommandLine) Log(org.apache.maven.plugin.logging.Log) HashMap(java.util.HashMap) PluginConfiguration(com.github.alexcojocaru.mojo.elasticsearch.v2.PluginConfiguration)

Example 10 with InstanceConfiguration

use of com.github.alexcojocaru.mojo.elasticsearch.v2.InstanceConfiguration in project elasticsearch-maven-plugin by alexcojocaru.

the class RunForkedMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    if (skip) {
        getLog().info("Skipping plugin execution");
        return;
    }
    ClusterConfiguration clusterConfig = buildClusterConfiguration();
    new PreStartClusterSequence().execute(clusterConfig);
    for (InstanceConfiguration config : clusterConfig.getInstanceConfigurationList()) {
        getLog().info(String.format("Using Elasticsearch [%d] configuration: %s", config.getId(), config));
        try {
            ForkedInstance instance = new ForkedInstance(config);
            instance.configureInstance();
            Thread thread = new Thread(instance);
            thread.start();
            new PostStartInstanceSequence().execute(config);
        } catch (Exception e) {
            throw new MojoExecutionException(e.getMessage(), e);
        }
    }
    new PostStartClusterSequence().execute(clusterConfig);
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) PostStartClusterSequence(com.github.alexcojocaru.mojo.elasticsearch.v2.step.PostStartClusterSequence) PreStartClusterSequence(com.github.alexcojocaru.mojo.elasticsearch.v2.step.PreStartClusterSequence) PostStartInstanceSequence(com.github.alexcojocaru.mojo.elasticsearch.v2.step.PostStartInstanceSequence) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Aggregations

File (java.io.File)5 IOException (java.io.IOException)5 ElasticsearchSetupException (com.github.alexcojocaru.mojo.elasticsearch.v2.ElasticsearchSetupException)4 Log (org.apache.maven.plugin.logging.Log)4 ClusterConfiguration (com.github.alexcojocaru.mojo.elasticsearch.v2.ClusterConfiguration)2 InstanceConfiguration (com.github.alexcojocaru.mojo.elasticsearch.v2.InstanceConfiguration)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 CommandLine (org.apache.commons.exec.CommandLine)2 DefaultExecutor (org.apache.commons.exec.DefaultExecutor)2 PumpStreamHandler (org.apache.commons.exec.PumpStreamHandler)2 TeeOutputStream (org.apache.commons.io.output.TeeOutputStream)2 Test (org.junit.Test)2 PluginConfiguration (com.github.alexcojocaru.mojo.elasticsearch.v2.PluginConfiguration)1 ElasticsearchClient (com.github.alexcojocaru.mojo.elasticsearch.v2.client.ElasticsearchClient)1 Monitor (com.github.alexcojocaru.mojo.elasticsearch.v2.client.Monitor)1 ArtifactException (com.github.alexcojocaru.mojo.elasticsearch.v2.configuration.ArtifactException)1 PostStartClusterSequence (com.github.alexcojocaru.mojo.elasticsearch.v2.step.PostStartClusterSequence)1 PostStartInstanceSequence (com.github.alexcojocaru.mojo.elasticsearch.v2.step.PostStartInstanceSequence)1