Search in sources :

Example 56 with GetResponse

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.get.GetResponse in project arctic-sea by 52North.

the class ElasticsearchAdminHandler method addUuidToMetadataIfNeeded.

@SuppressWarnings("unchecked")
private void addUuidToMetadataIfNeeded(String uuid) throws ElasticsearchException {
    GetResponse resp = client.prepareGet(settings.getIndexId(), MetadataDataMapping.METADATA_TYPE_NAME, MetadataDataMapping.METADATA_ROW_ID).setOperationThreaded(false).get();
    Object retValues = resp.getSourceAsMap().get(MetadataDataMapping.METADATA_UUIDS_FIELD.getName());
    List<String> values;
    if (retValues instanceof String) {
        values = new LinkedList<>();
        values.add((String) retValues);
    } else if (retValues instanceof List<?>) {
        values = (List<String>) retValues;
    } else {
        throw new ConfigurationError("Invalid %s field type %s should have String or java.util.Collection<String>", MetadataDataMapping.METADATA_UUIDS_FIELD, retValues.getClass());
    }
    // add new uuid if needed
    if (!values.stream().anyMatch(m -> m.equals(uuid))) {
        Map<String, Object> uuids = new HashMap<>();
        values.add(uuid);
        uuids.put(MetadataDataMapping.METADATA_UUIDS_FIELD.getName(), values);
        uuids.put(MetadataDataMapping.METADATA_UPDATE_TIME_FIELD.getName(), Calendar.getInstance(DateTimeZone.UTC.toTimeZone()));
        client.prepareUpdate(settings.getIndexId(), MetadataDataMapping.METADATA_TYPE_NAME, "1").setDoc(uuids).get();
        logger.info("UUID {} is added to the {} type", uuid, MetadataDataMapping.METADATA_TYPE_NAME);
    }
}
Also used : ConfigurationError(org.n52.faroe.ConfigurationError) ElasticsearchException(org.elasticsearch.ElasticsearchException) GetResponse(org.elasticsearch.action.get.GetResponse) DateTimeZone(org.joda.time.DateTimeZone) ConfigurationError(org.n52.faroe.ConfigurationError) KibanaImporter(org.n52.iceland.statistics.api.utils.KibanaImporter) NodeBuilder(org.elasticsearch.node.NodeBuilder) TransportClient(org.elasticsearch.client.transport.TransportClient) LoggerFactory(org.slf4j.LoggerFactory) MetadataDataMapping(org.n52.iceland.statistics.api.mappings.MetadataDataMapping) HashMap(java.util.HashMap) InetAddress(java.net.InetAddress) Inject(javax.inject.Inject) Calendar(java.util.Calendar) Settings(org.elasticsearch.common.settings.Settings) Map(java.util.Map) EmbeddedElasticsearch(org.n52.iceland.statistics.impl.server.EmbeddedElasticsearch) Node(org.elasticsearch.node.Node) ElasticsearchSettings(org.n52.iceland.statistics.api.ElasticsearchSettings) ElasticsearchSettingsKeys(org.n52.iceland.statistics.api.ElasticsearchSettingsKeys) LinkedList(java.util.LinkedList) JsonParseException(com.fasterxml.jackson.core.JsonParseException) Logger(org.slf4j.Logger) InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress) Client(org.elasticsearch.client.Client) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) UnknownHostException(java.net.UnknownHostException) StandardCharsets(java.nio.charset.StandardCharsets) CreateIndexResponse(org.elasticsearch.action.admin.indices.create.CreateIndexResponse) IndicesAdminClient(org.elasticsearch.client.IndicesAdminClient) Objects(java.util.Objects) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) ServletContext(javax.servlet.ServletContext) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) IAdminDataHandler(org.n52.iceland.statistics.api.interfaces.datahandler.IAdminDataHandler) DefaultElasticsearchSchemas(org.n52.iceland.statistics.impl.schemabuilders.DefaultElasticsearchSchemas) Joiner(com.google.common.base.Joiner) HashMap(java.util.HashMap) LinkedList(java.util.LinkedList) List(java.util.List) GetResponse(org.elasticsearch.action.get.GetResponse)

Example 57 with GetResponse

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.get.GetResponse in project arctic-sea by 52North.

the class ElasticsearchAdminHandlerIT method createNewDatabase.

@Test
public void createNewDatabase() throws InterruptedException {
    adminHandler.createSchema();
    IndicesAdminClient indices = getEmbeddedClient().admin().indices();
    IndicesExistsResponse index = indices.prepareExists(clientSettings.getIndexId()).get();
    Assert.assertTrue(index.isExists());
    GetResponse resp = getEmbeddedClient().prepareGet(clientSettings.getIndexId(), MetadataDataMapping.METADATA_TYPE_NAME, MetadataDataMapping.METADATA_ROW_ID).setOperationThreaded(false).get();
    Assert.assertEquals(1, resp.getSourceAsMap().get(MetadataDataMapping.METADATA_VERSION_FIELD.getName()));
}
Also used : IndicesExistsResponse(org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse) IndicesAdminClient(org.elasticsearch.client.IndicesAdminClient) GetResponse(org.elasticsearch.action.get.GetResponse) ElasticsearchAwareTest(org.n52.iceland.statistics.basetests.ElasticsearchAwareTest) Test(org.junit.Test)

Example 58 with GetResponse

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.get.GetResponse in project arctic-sea by 52North.

the class ElasticsearchAdminHandlerIT method addnewUuidOnConnect.

@SuppressWarnings("unchecked")
@Test
public void addnewUuidOnConnect() {
    adminHandler.createSchema();
    clientSettings.setUuid("lofasz janos");
    adminHandler.createSchema();
    GetResponse resp = getEmbeddedClient().prepareGet(clientSettings.getIndexId(), MetadataDataMapping.METADATA_TYPE_NAME, MetadataDataMapping.METADATA_ROW_ID).setOperationThreaded(false).get();
    Map<String, Object> map = resp.getSourceAsMap();
    Assert.assertNotNull(map.get(MetadataDataMapping.METADATA_CREATION_TIME_FIELD.getName()));
    Assert.assertNotNull(map.get(MetadataDataMapping.METADATA_UUIDS_FIELD.getName()));
    Assert.assertNotNull(map.get(MetadataDataMapping.METADATA_UPDATE_TIME_FIELD.getName()));
    List<String> object = (List<String>) map.get(MetadataDataMapping.METADATA_UUIDS_FIELD.getName());
    Assert.assertEquals(2, object.size());
    Assert.assertThat(object, CoreMatchers.hasItem("lofasz janos"));
}
Also used : List(java.util.List) GetResponse(org.elasticsearch.action.get.GetResponse) ElasticsearchAwareTest(org.n52.iceland.statistics.basetests.ElasticsearchAwareTest) Test(org.junit.Test)

Example 59 with GetResponse

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.get.GetResponse in project alien4cloud by alien4cloud.

the class EsDaoCrudTest method assertDocumentExisit.

private void assertDocumentExisit(String indexName, String typeName, String id, boolean expected) {
    GetResponse response = getDocument(indexName, typeName, id);
    assertEquals(expected, response.isExists());
    assertEquals(expected, !response.isSourceEmpty());
}
Also used : GetResponse(org.elasticsearch.action.get.GetResponse)

Example 60 with GetResponse

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.get.GetResponse in project alien4cloud by alien4cloud.

the class EsDaoCrudTest method saveToscaComponentTest.

@Test
public void saveToscaComponentTest() throws IndexingServiceException, IOException {
    dao.save(indexedNodeTypeTest);
    String typeName1 = indexedNodeTypeTest.getClass().getSimpleName().toLowerCase();
    assertDocumentExisit(ElasticSearchDAO.TOSCA_ELEMENT_INDEX, typeName1, indexedNodeTypeTest.getId(), true);
    GetResponse resp = getDocument(ElasticSearchDAO.TOSCA_ELEMENT_INDEX, typeName1, indexedNodeTypeTest.getId());
    log.info(resp.getSourceAsString());
    NodeType nt = jsonMapper.readValue(resp.getSourceAsString(), NodeType.class);
    assertBeanEqualsToOriginal(nt);
    refresh();
}
Also used : NodeType(org.alien4cloud.tosca.model.types.NodeType) GetResponse(org.elasticsearch.action.get.GetResponse) Test(org.junit.Test)

Aggregations

GetResponse (org.elasticsearch.action.get.GetResponse)167 Test (org.junit.Test)50 GetRequest (org.elasticsearch.action.get.GetRequest)28 Map (java.util.Map)27 MultiGetResponse (org.elasticsearch.action.get.MultiGetResponse)26 ArrayList (java.util.ArrayList)23 HashMap (java.util.HashMap)21 Date (java.util.Date)18 ESSyncConfig (com.alibaba.otter.canal.client.adapter.es.core.config.ESSyncConfig)17 Dml (com.alibaba.otter.canal.client.adapter.support.Dml)17 LinkedHashMap (java.util.LinkedHashMap)17 IOException (java.io.IOException)16 DataSource (javax.sql.DataSource)14 GetRequestBuilder (org.elasticsearch.action.get.GetRequestBuilder)14 SearchResponse (org.elasticsearch.action.search.SearchResponse)14 DeleteResponse (org.elasticsearch.action.delete.DeleteResponse)12 ElasticsearchException (org.elasticsearch.ElasticsearchException)10 Settings (org.elasticsearch.common.settings.Settings)10 Alias (org.elasticsearch.action.admin.indices.alias.Alias)7 IndexResponse (org.elasticsearch.action.index.IndexResponse)7