Search in sources :

Example 11 with ElasticsearchSetupException

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

the class BootstrapClusterStep method parseJson.

protected void parseJson(ElasticsearchClient client, Log log, Path path) {
    try {
        String json = new String(Files.readAllBytes(path));
        List<Map<String, Object>> commands = new ObjectMapper().readValue(json, new TypeReference<List<Map<String, Object>>>() {
        });
        commands.forEach(command -> {
            log.debug(String.format("Parsing command: %s", command));
            ElasticsearchCommand esCommand = parseMapCommand(command);
            executeInitCommand(client, log, esCommand);
        });
    } catch (IOException e) {
        throw new ElasticsearchSetupException("Cannot read the init json file", e);
    }
}
Also used : ElasticsearchCommand(com.github.alexcojocaru.mojo.elasticsearch.v2.client.ElasticsearchCommand) ElasticsearchSetupException(com.github.alexcojocaru.mojo.elasticsearch.v2.ElasticsearchSetupException) List(java.util.List) IOException(java.io.IOException) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 12 with ElasticsearchSetupException

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

the class BootstrapClusterStep method parseScript.

protected void parseScript(ElasticsearchClient client, Log log, Path path) {
    try (Stream<String> stream = Files.lines(path)) {
        stream.forEach(command -> {
            log.debug(String.format("Parsing command: %s", command));
            ElasticsearchCommand esCommand = parseStringCommand(command);
            if (esCommand.isSkip() == false) {
                executeInitCommand(client, log, esCommand);
            }
        });
    } catch (IOException e) {
        throw new ElasticsearchSetupException("Cannot read the init script file", e);
    }
}
Also used : ElasticsearchCommand(com.github.alexcojocaru.mojo.elasticsearch.v2.client.ElasticsearchCommand) ElasticsearchSetupException(com.github.alexcojocaru.mojo.elasticsearch.v2.ElasticsearchSetupException) IOException(java.io.IOException)

Example 13 with ElasticsearchSetupException

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

the class ValidateBaseDirectoryStep method execute.

@Override
public void execute(ClusterConfiguration config) {
    String baseDir = config.getInstanceConfigurationList().get(0).getBaseDir();
    try {
        Validate.notBlank(baseDir);
        // this should catch erroneous paths
        new File(baseDir).getCanonicalPath();
    } catch (Exception e) {
        throw new ElasticsearchSetupException(String.format("The value of the 'baseDir' parameter ('%1$s') is not a valid file path.", baseDir));
    }
}
Also used : ElasticsearchSetupException(com.github.alexcojocaru.mojo.elasticsearch.v2.ElasticsearchSetupException) File(java.io.File) ElasticsearchSetupException(com.github.alexcojocaru.mojo.elasticsearch.v2.ElasticsearchSetupException)

Aggregations

ElasticsearchSetupException (com.github.alexcojocaru.mojo.elasticsearch.v2.ElasticsearchSetupException)13 IOException (java.io.IOException)8 ElasticsearchCommand (com.github.alexcojocaru.mojo.elasticsearch.v2.client.ElasticsearchCommand)5 File (java.io.File)5 List (java.util.List)3 Log (org.apache.maven.plugin.logging.Log)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ElasticsearchClientException (com.github.alexcojocaru.mojo.elasticsearch.v2.client.ElasticsearchClientException)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ArrayList (java.util.ArrayList)2 DefaultExecutor (org.apache.commons.exec.DefaultExecutor)2 PumpStreamHandler (org.apache.commons.exec.PumpStreamHandler)2 TeeOutputStream (org.apache.commons.io.output.TeeOutputStream)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ElasticsearchClient (com.github.alexcojocaru.mojo.elasticsearch.v2.client.ElasticsearchClient)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Map (java.util.Map)1 CommandLine (org.apache.commons.exec.CommandLine)1