Github user nickwallen commented on a diff in the pull request:
https://github.com/apache/metron/pull/1190#discussion_r217439809
--- Diff:
metron-platform/metron-indexing/src/main/java/org/apache/metron/indexing/dao/MultiIndexDao.java
---
@@ -101,48 +103,59 @@ public void batchUpdate(Map<Document,
Optional<String>> updates) throws IOExcept
}
@Override
- public void addCommentToAlert(CommentAddRemoveRequest request) throws
IOException {
+ public Document addCommentToAlert(CommentAddRemoveRequest request)
throws IOException {
Document latest = getLatest(request.getGuid(),
request.getSensorType());
- addCommentToAlert(request, latest);
+ return addCommentToAlert(request, latest);
}
-
+ /**
+ * Adds comments to an alert. Updates are written to each Dao in
parallel with the assumption that all updates
+ * are identical. The first update to be applied is returned as the
current version of the alert with comments added.
+ * @param request Request to add comments
+ * @param latest The latest version of the alert the comments will be
added to.
+ * @return The complete alert document with comments added.
+ * @throws IOException
+ */
@Override
- public void addCommentToAlert(CommentAddRemoveRequest request, Document
latest) throws IOException {
- List<String> exceptions =
- indices.parallelStream().map(dao -> {
- try {
- dao.addCommentToAlert(request, latest);
- return null;
- } catch (Throwable e) {
- return dao.getClass() + ": " + e.getMessage() + "\n" +
ExceptionUtils.getStackTrace(e);
- }
- }).filter(Objects::nonNull).collect(Collectors.toList());
- if (exceptions.size() > 0) {
- throw new IOException(Joiner.on("\n").join(exceptions));
- }
+ public Document addCommentToAlert(CommentAddRemoveRequest request,
Document latest) throws IOException {
+ List<DocumentContainer> output =
+ indices.parallelStream().map(dao -> {
+ try {
+ return new
DocumentContainer(dao.addCommentToAlert(request, latest));
+ } catch (Throwable e) {
+ return new DocumentContainer(e);
+ }
+ }).collect(Collectors.toList());
--- End diff --
Nice! I like your approach.
---