Search in sources :

Example 1 with ElasticsearchParameters

use of org.apache.gora.elasticsearch.utils.ElasticsearchParameters in project gora by apache.

the class ElasticsearchStore method initialize.

@Override
public void initialize(Class<K> keyClass, Class<T> persistentClass, Properties properties) throws GoraException {
    try {
        LOG.debug("Initializing Elasticsearch store");
        ElasticsearchParameters parameters = ElasticsearchParameters.load(properties, getConf());
        super.initialize(keyClass, persistentClass, properties);
        ElasticsearchMappingBuilder<K, T> builder = new ElasticsearchMappingBuilder<>(this);
        InputStream mappingStream;
        if (properties.containsKey(XML_MAPPING_DEFINITION)) {
            if (LOG.isTraceEnabled()) {
                LOG.trace("{} = {}", XML_MAPPING_DEFINITION, properties.getProperty(XML_MAPPING_DEFINITION));
            }
            mappingStream = org.apache.commons.io.IOUtils.toInputStream(properties.getProperty(XML_MAPPING_DEFINITION), (Charset) null);
        } else {
            mappingStream = getClass().getClassLoader().getResourceAsStream(properties.getProperty(PARSE_MAPPING_FILE_KEY, DEFAULT_MAPPING_FILE));
        }
        String xsdValidation = properties.getProperty(XSD_VALIDATION, "false");
        builder.readMappingFile(mappingStream, Boolean.parseBoolean(xsdValidation));
        elasticsearchMapping = builder.getElasticsearchMapping();
        client = createClient(parameters);
        LOG.info("Elasticsearch store was successfully initialized.");
    } catch (Exception ex) {
        LOG.error("Error while initializing Elasticsearch store", ex);
        throw new GoraException(ex);
    }
}
Also used : GoraException(org.apache.gora.util.GoraException) InputStream(java.io.InputStream) Charset(java.nio.charset.Charset) ElasticsearchParameters(org.apache.gora.elasticsearch.utils.ElasticsearchParameters) ElasticsearchMappingBuilder(org.apache.gora.elasticsearch.mapping.ElasticsearchMappingBuilder) GoraException(org.apache.gora.util.GoraException) IOException(java.io.IOException)

Example 2 with ElasticsearchParameters

use of org.apache.gora.elasticsearch.utils.ElasticsearchParameters in project gora by apache.

the class TestElasticsearchStore method testLoadElasticsearchParameters.

@Test
public void testLoadElasticsearchParameters() throws IOException {
    log.info("test method: testLoadElasticsearchParameters");
    Properties properties = DataStoreFactory.createProps();
    ElasticsearchParameters parameters = ElasticsearchParameters.load(properties, testDriver.getConfiguration());
    Assert.assertEquals("localhost", parameters.getHost());
    Assert.assertEquals(AuthenticationType.BASIC, parameters.getAuthenticationType());
    Assert.assertEquals("elastic", parameters.getUsername());
    Assert.assertEquals("password", parameters.getPassword());
}
Also used : Properties(java.util.Properties) ElasticsearchParameters(org.apache.gora.elasticsearch.utils.ElasticsearchParameters) Test(org.junit.Test)

Example 3 with ElasticsearchParameters

use of org.apache.gora.elasticsearch.utils.ElasticsearchParameters in project gora by apache.

the class ElasticsearchStoreMetadataAnalyzer method initialize.

@Override
public void initialize() throws GoraException {
    ElasticsearchParameters parameters = ElasticsearchParameters.load(properties, getConf());
    elasticsearchClient = ElasticsearchStore.createClient(parameters);
}
Also used : ElasticsearchParameters(org.apache.gora.elasticsearch.utils.ElasticsearchParameters)

Aggregations

ElasticsearchParameters (org.apache.gora.elasticsearch.utils.ElasticsearchParameters)3 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Charset (java.nio.charset.Charset)1 Properties (java.util.Properties)1 ElasticsearchMappingBuilder (org.apache.gora.elasticsearch.mapping.ElasticsearchMappingBuilder)1 GoraException (org.apache.gora.util.GoraException)1 Test (org.junit.Test)1