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);
}
}
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);
}
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);
}
}
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);
}
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");
}
Aggregations