Search in sources :

Example 1 with ElasticsearchClientException

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

the class BootstrapClusterStep method executeInitCommand.

protected void executeInitCommand(ElasticsearchClient client, Log log, ElasticsearchCommand command) {
    String url = "/" + command.getRelativeUrl();
    String content = command.getJson();
    try {
        switch(command.getRequestMethod()) {
            case PUT:
                client.put(url, content);
                break;
            case POST:
                client.post(url, content, String.class);
                break;
            case DELETE:
                client.delete(url);
                break;
            default:
                throw new IllegalStateException(String.format("Unsupported request method: %s", command.getRequestMethod()));
        }
    } catch (ElasticsearchClientException e) {
        throw new ElasticsearchSetupException(String.format("Cannot execute command %s", command), e);
    }
}
Also used : ElasticsearchClientException(com.github.alexcojocaru.mojo.elasticsearch.v2.client.ElasticsearchClientException) ElasticsearchSetupException(com.github.alexcojocaru.mojo.elasticsearch.v2.ElasticsearchSetupException)

Example 2 with ElasticsearchClientException

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

the class BootstrapClusterStepTest method testExecuteInitCommandPost.

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

Example 3 with ElasticsearchClientException

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

the class BootstrapClusterStep method executeInitCommand.

private void executeInitCommand(ElasticsearchClient client, Log log, String command) {
    log.debug(String.format("Parsing command: %s", command));
    ElasticsearchCommand esCommand = parseStringCommand(command);
    if (esCommand.isSkip()) {
        return;
    }
    String url = "/" + esCommand.getRelativeUrl();
    String content = esCommand.getJson();
    try {
        switch(esCommand.getRequestMethod()) {
            case PUT:
                client.put(url, content);
                break;
            case POST:
                client.post(url, content, String.class);
                break;
            case DELETE:
                client.delete(url);
                break;
            default:
                throw new IllegalStateException(String.format("Unsupported request method: %s", esCommand.getRequestMethod()));
        }
    } catch (ElasticsearchClientException e) {
        throw new ElasticsearchSetupException(String.format("Cannot execute command %s", command), e);
    }
}
Also used : ElasticsearchCommand(com.github.alexcojocaru.mojo.elasticsearch.v2.client.ElasticsearchCommand) ElasticsearchClientException(com.github.alexcojocaru.mojo.elasticsearch.v2.client.ElasticsearchClientException) ElasticsearchSetupException(com.github.alexcojocaru.mojo.elasticsearch.v2.ElasticsearchSetupException)

Example 4 with ElasticsearchClientException

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

the class BootstrapClusterStepTest method testExecuteInitCommandWithException.

@Test(expected = ElasticsearchSetupException.class)
public void testExecuteInitCommandWithException() throws ElasticsearchClientException {
    ElasticsearchCommand command = mock(ElasticsearchCommand.class);
    when(command.getRequestMethod()).thenReturn(RequestMethod.DELETE);
    when(command.getRelativeUrl()).thenReturn("index/type/id");
    doThrow(ElasticsearchClientException.class).when(client).delete("/index/type/id");
    step.executeInitCommand(client, log, command);
}
Also used : ElasticsearchCommand(com.github.alexcojocaru.mojo.elasticsearch.v2.client.ElasticsearchCommand) Test(org.junit.Test)

Example 5 with ElasticsearchClientException

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

the class BootstrapClusterStepTest method testExecuteInitCommandDelete.

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

Aggregations

ElasticsearchCommand (com.github.alexcojocaru.mojo.elasticsearch.v2.client.ElasticsearchCommand)5 Test (org.junit.Test)4 ElasticsearchSetupException (com.github.alexcojocaru.mojo.elasticsearch.v2.ElasticsearchSetupException)2 ElasticsearchClientException (com.github.alexcojocaru.mojo.elasticsearch.v2.client.ElasticsearchClientException)2