Search in sources :

Example 1 with ElasticsearchConfiguration

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();
    }
}
Also used : SubstitutingSourceProvider(io.dropwizard.configuration.SubstitutingSourceProvider) ConfigurationSourceProvider(io.dropwizard.configuration.ConfigurationSourceProvider) FileConfigurationSourceProvider(io.dropwizard.configuration.FileConfigurationSourceProvider) InputStream(java.io.InputStream) EnvironmentVariableSubstitutor(io.dropwizard.configuration.EnvironmentVariableSubstitutor) ElasticsearchConfiguration(gov.ca.cwds.rest.ElasticsearchConfiguration) ApiException(gov.ca.cwds.rest.api.ApiException) FileConfigurationSourceProvider(io.dropwizard.configuration.FileConfigurationSourceProvider)

Example 2 with ElasticsearchConfiguration

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;
}
Also used : TransportClient(org.elasticsearch.client.transport.TransportClient) PreBuiltTransportClient(org.elasticsearch.transport.client.PreBuiltTransportClient) PreBuiltTransportClient(org.elasticsearch.transport.client.PreBuiltTransportClient) ElasticsearchConfiguration(gov.ca.cwds.rest.ElasticsearchConfiguration) InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress) ApiException(gov.ca.cwds.rest.api.ApiException) ApiException(gov.ca.cwds.rest.api.ApiException) Provides(com.google.inject.Provides)

Aggregations

ElasticsearchConfiguration (gov.ca.cwds.rest.ElasticsearchConfiguration)2 ApiException (gov.ca.cwds.rest.api.ApiException)2 Provides (com.google.inject.Provides)1 ConfigurationSourceProvider (io.dropwizard.configuration.ConfigurationSourceProvider)1 EnvironmentVariableSubstitutor (io.dropwizard.configuration.EnvironmentVariableSubstitutor)1 FileConfigurationSourceProvider (io.dropwizard.configuration.FileConfigurationSourceProvider)1 SubstitutingSourceProvider (io.dropwizard.configuration.SubstitutingSourceProvider)1 InputStream (java.io.InputStream)1 TransportClient (org.elasticsearch.client.transport.TransportClient)1 InetSocketTransportAddress (org.elasticsearch.common.transport.InetSocketTransportAddress)1 PreBuiltTransportClient (org.elasticsearch.transport.client.PreBuiltTransportClient)1