use of com.github.alexcojocaru.mojo.elasticsearch.v2.client.ElasticsearchClient in project elasticsearch-maven-plugin by alexcojocaru.
the class BootstrapClusterStep method execute.
@Override
public void execute(ClusterConfiguration config) {
if (StringUtils.isBlank(config.getPathInitScript())) {
// nothing to do; return
return;
}
String filePath = config.getPathInitScript();
validateFile(filePath);
// we'll run all commands against the first node in the cluster
ElasticsearchClient client = new ElasticsearchClient.Builder().withInstanceConfiguration(config.getInstanceConfigurationList().get(0)).withHostname("localhost").build();
Stream<String> stream = null;
try {
stream = Files.lines(Paths.get(filePath));
stream.forEach(command -> executeInitCommand(client, config.getLog(), command));
} catch (IOException e) {
throw new ElasticsearchSetupException("Cannot read the init script file", e);
} finally {
if (stream != null) {
stream.close();
}
}
}
use of com.github.alexcojocaru.mojo.elasticsearch.v2.client.ElasticsearchClient 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.ElasticsearchClient in project elasticsearch-maven-plugin by alexcojocaru.
the class WaitToStartInstanceStep method execute.
@Override
public void execute(InstanceConfiguration config) {
int timeout = config.getStartupTimeout();
try (ElasticsearchClient client = new ElasticsearchClient.Builder().withInstanceConfiguration(config).withHostname("localhost").build()) {
Monitor monitor = new Monitor(client, config.getClusterConfiguration().getLog());
monitor.waitToStartInstance(config.getBaseDir(), config.getClusterConfiguration().getClusterName(), timeout);
}
}
use of com.github.alexcojocaru.mojo.elasticsearch.v2.client.ElasticsearchClient 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.ElasticsearchClient in project elasticsearch-maven-plugin by alexcojocaru.
the class WaitToStartClusterStep method execute.
@Override
public void execute(ClusterConfiguration config) {
try (ElasticsearchClient client = new ElasticsearchClient.Builder().withInstanceConfiguration(config.getInstanceConfigurationList().get(0)).withHostname("localhost").build()) {
Monitor monitor = new Monitor(client, config.getLog());
monitor.waitToStartCluster(config.getClusterName(), config.getInstanceConfigurationList().size(), config.getStartupTimeout());
}
}
Aggregations