Search in sources :

Example 16 with ElasticsearchCommand

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

the class BootstrapClusterStepTest method testExecuteInitCommandPut.

@Test
public void testExecuteInitCommandPut() throws ElasticsearchClientException {
    ElasticsearchCommand command = mock(ElasticsearchCommand.class);
    when(command.getRequestMethod()).thenReturn(RequestMethod.PUT);
    when(command.getJson()).thenReturn("json");
    when(command.getRelativeUrl()).thenReturn("index/type/id");
    step.executeInitCommand(client, log, command);
    verify(client).put("/index/type/id", "json");
}
Also used : ElasticsearchCommand(com.github.alexcojocaru.mojo.elasticsearch.v2.client.ElasticsearchCommand) Test(org.junit.Test)

Example 17 with ElasticsearchCommand

use of com.github.alexcojocaru.mojo.elasticsearch.v2.client.ElasticsearchCommand 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 18 with ElasticsearchCommand

use of com.github.alexcojocaru.mojo.elasticsearch.v2.client.ElasticsearchCommand 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)

Aggregations

ElasticsearchCommand (com.github.alexcojocaru.mojo.elasticsearch.v2.client.ElasticsearchCommand)17 Test (org.junit.Test)12 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)8 ElasticsearchSetupException (com.github.alexcojocaru.mojo.elasticsearch.v2.ElasticsearchSetupException)7 HashMap (java.util.HashMap)4 ElasticsearchClientException (com.github.alexcojocaru.mojo.elasticsearch.v2.client.ElasticsearchClientException)3 Map (java.util.Map)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 IOException (java.io.IOException)2 List (java.util.List)2 ArgumentMatchers.anyMap (org.mockito.ArgumentMatchers.anyMap)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ClusterConfiguration (com.github.alexcojocaru.mojo.elasticsearch.v2.ClusterConfiguration)1 InstanceConfiguration (com.github.alexcojocaru.mojo.elasticsearch.v2.InstanceConfiguration)1 ElasticsearchClient (com.github.alexcojocaru.mojo.elasticsearch.v2.client.ElasticsearchClient)1 RequestMethod (com.github.alexcojocaru.mojo.elasticsearch.v2.client.ElasticsearchCommand.RequestMethod)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1