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());
}
}
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;
}
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);
}
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()));
}
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;
}
Aggregations