use of gov.ca.cwds.rest.ElasticsearchConfiguration in project api-core by ca-cwds.
the class ElasticSearchLiveTestRunner method main.
/**
* Let 'er rip!
*
* @param args command line
* @throws Exception Exception rises to the top
*/
public static void main(String... args) throws Exception {
if (args.length < 2) {
throw new ApiException("Usage: java " + ElasticSearchLiveTestRunner.class.getName() + " <ES config file> <search terms>");
}
final String path = args[0];
final String searchFor = args[1];
final ConfigurationSourceProvider provider = new SubstitutingSourceProvider(new FileConfigurationSourceProvider(), new EnvironmentVariableSubstitutor(false));
ElasticsearchConfiguration config;
try (InputStream iss = provider.open(path)) {
config = YAML_MAPPER.readValue(iss, ElasticsearchConfiguration.class);
}
try (AutoCloseElasticsearchDao autoCloseDao = new AutoCloseElasticsearchDao(elasticsearchClient(config))) {
ElasticSearchLiveTestRunner job = new ElasticSearchLiveTestRunner(autoCloseDao, searchFor);
job.run();
}
}
use of gov.ca.cwds.rest.ElasticsearchConfiguration in project API by ca-cwds.
the class DataAccessModule method elasticsearchClient.
// @Singleton
@Provides
public synchronized Client elasticsearchClient(ApiConfiguration apiConfiguration) {
if (client == null) {
ElasticsearchConfiguration config = apiConfiguration.getElasticsearchConfiguration();
try {
// Settings settings = Settings.settingsBuilder()
// .put("cluster.name", config.getElasticsearchCluster()).build();
// client = TransportClient.builder().settings(settings).build().addTransportAddress(
// new InetSocketTransportAddress(InetAddress.getByName(config.getElasticsearchHost()),
// Integer.parseInt(config.getElasticsearchPort())));
TransportClient ret = new PreBuiltTransportClient(Settings.builder().put("cluster.name", config.getElasticsearchCluster()).build());
ret.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(config.getElasticsearchHost()), Integer.parseInt(config.getElasticsearchPort())));
client = ret;
} catch (Exception e) {
LOGGER.error("Error initializing Elasticsearch client: {}", e.getMessage(), e);
throw new ApiException("Error initializing Elasticsearch client: " + e.getMessage(), e);
}
}
return client;
}
Aggregations