Search in sources :

Example 11 with Document

use of org.apache.metron.indexing.dao.update.Document in project metron by apache.

the class ElasticsearchMetaAlertIntegrationTest method shouldThrowExceptionOnMetaAlertUpdate.

@Test
public void shouldThrowExceptionOnMetaAlertUpdate() throws Exception {
    Document metaAlert = new Document(new HashMap<>(), "meta_alert", METAALERT_TYPE, 0L);
    try {
        // Verify a meta alert cannot be updated in the meta alert dao
        metaDao.update(metaAlert, Optional.empty());
        Assert.fail("Direct meta alert update should throw an exception");
    } catch (UnsupportedOperationException uoe) {
        Assert.assertEquals("Meta alerts cannot be directly updated", uoe.getMessage());
    }
}
Also used : Document(org.apache.metron.indexing.dao.update.Document) Test(org.junit.Test)

Example 12 with Document

use of org.apache.metron.indexing.dao.update.Document in project metron by apache.

the class HBaseDao method getAllLatest.

@Override
public Iterable<Document> getAllLatest(List<GetRequest> getRequests) throws IOException {
    List<Get> gets = new ArrayList<>();
    for (GetRequest getRequest : getRequests) {
        gets.add(buildGet(getRequest));
    }
    Result[] results = getTableInterface().get(gets);
    List<Document> allLatest = new ArrayList<>();
    for (Result result : results) {
        Document d = getDocumentFromResult(result);
        if (d != null) {
            allLatest.add(d);
        }
    }
    return allLatest;
}
Also used : Get(org.apache.hadoop.hbase.client.Get) GetRequest(org.apache.metron.indexing.dao.search.GetRequest) ArrayList(java.util.ArrayList) Document(org.apache.metron.indexing.dao.update.Document) Result(org.apache.hadoop.hbase.client.Result)

Example 13 with Document

use of org.apache.metron.indexing.dao.update.Document in project metron by apache.

the class HBaseDao method batchUpdate.

@Override
public void batchUpdate(Map<Document, Optional<String>> updates) throws IOException {
    List<Put> puts = new ArrayList<>();
    for (Map.Entry<Document, Optional<String>> updateEntry : updates.entrySet()) {
        Document update = updateEntry.getKey();
        Put put = buildPut(update);
        puts.add(put);
    }
    getTableInterface().put(puts);
}
Also used : Optional(java.util.Optional) ArrayList(java.util.ArrayList) Document(org.apache.metron.indexing.dao.update.Document) Map(java.util.Map) NavigableMap(java.util.NavigableMap) Put(org.apache.hadoop.hbase.client.Put)

Example 14 with Document

use of org.apache.metron.indexing.dao.update.Document in project metron by apache.

the class IndexDao method patch.

/**
 * Update a document in an index given a JSON Patch (see RFC 6902 at https://tools.ietf.org/html/rfc6902)
 * @param request The patch request
 * @param timestamp Optionally a timestamp to set. If not specified then current time is used.
 * @throws OriginalNotFoundException If the original is not found, then it cannot be patched.
 * @throws IOException
 */
default void patch(PatchRequest request, Optional<Long> timestamp) throws OriginalNotFoundException, IOException {
    Document d = getPatchedDocument(request, timestamp);
    update(d, Optional.ofNullable(request.getIndex()));
}
Also used : Document(org.apache.metron.indexing.dao.update.Document)

Example 15 with Document

use of org.apache.metron.indexing.dao.update.Document in project metron by apache.

the class MultiIndexDao method getLatest.

@Override
public Document getLatest(final String guid, String sensorType) throws IOException {
    Document ret = null;
    List<DocumentContainer> output = indices.parallelStream().map(dao -> {
        try {
            return new DocumentContainer(dao.getLatest(guid, sensorType));
        } catch (Throwable e) {
            return new DocumentContainer(e);
        }
    }).collect(Collectors.toList());
    List<String> error = new ArrayList<>();
    for (DocumentContainer dc : output) {
        if (dc.getException().isPresent()) {
            Throwable e = dc.getException().get();
            error.add(e.getMessage() + "\n" + ExceptionUtils.getStackTrace(e));
        } else {
            if (dc.getDocument().isPresent()) {
                Document d = dc.getDocument().get();
                if (ret == null || ret.getTimestamp() < d.getTimestamp()) {
                    ret = d;
                }
            }
        }
    }
    if (error.size() > 0) {
        throw new IOException(Joiner.on("\n").join(error));
    }
    return ret;
}
Also used : InvalidSearchException(org.apache.metron.indexing.dao.search.InvalidSearchException) Document(org.apache.metron.indexing.dao.update.Document) Iterables(com.google.common.collect.Iterables) FieldType(org.apache.metron.indexing.dao.search.FieldType) GroupRequest(org.apache.metron.indexing.dao.search.GroupRequest) IOException(java.io.IOException) GetRequest(org.apache.metron.indexing.dao.search.GetRequest) SearchRequest(org.apache.metron.indexing.dao.search.SearchRequest) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) GroupResponse(org.apache.metron.indexing.dao.search.GroupResponse) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) Optional(java.util.Optional) Collections(java.util.Collections) Joiner(com.google.common.base.Joiner) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils) SearchResponse(org.apache.metron.indexing.dao.search.SearchResponse) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Document(org.apache.metron.indexing.dao.update.Document)

Aggregations

Document (org.apache.metron.indexing.dao.update.Document)31 ArrayList (java.util.ArrayList)13 GetRequest (org.apache.metron.indexing.dao.search.GetRequest)12 Map (java.util.Map)11 HashMap (java.util.HashMap)10 Test (org.junit.Test)10 IOException (java.io.IOException)9 List (java.util.List)6 Optional (java.util.Optional)6 Collectors (java.util.stream.Collectors)5 AccessConfig (org.apache.metron.indexing.dao.AccessConfig)5 IndexDao (org.apache.metron.indexing.dao.IndexDao)5 MetaAlertCreateResponse (org.apache.metron.indexing.dao.metaalert.MetaAlertCreateResponse)4 FieldType (org.apache.metron.indexing.dao.search.FieldType)4 GroupRequest (org.apache.metron.indexing.dao.search.GroupRequest)4 SearchRequest (org.apache.metron.indexing.dao.search.SearchRequest)4 java.util (java.util)3 Constants (org.apache.metron.common.Constants)3 MockHBaseTableProvider (org.apache.metron.hbase.mock.MockHBaseTableProvider)3 MetaAlertCreateRequest (org.apache.metron.indexing.dao.metaalert.MetaAlertCreateRequest)3