[ 
https://issues.apache.org/jira/browse/METRON-1771?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16613687#comment-16613687
 ] 

ASF GitHub Bot commented on METRON-1771:
----------------------------------------

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.


> Update REST endpoints to support eventually consistent UI updates
> -----------------------------------------------------------------
>
>                 Key: METRON-1771
>                 URL: https://issues.apache.org/jira/browse/METRON-1771
>             Project: Metron
>          Issue Type: Improvement
>            Reporter: Ryan Merriman
>            Priority: Major
>
> Currently the REST endpoints that perform document updates either return 
> true/false or nothing.  This puts the responsibility of retrieving the 
> updated state of the object on the client in a separate call or 
> optimistically applying the changes and reverting when an update fails.  This 
> can be problematic if a client attempts to get the current state immediately 
> after an update and the change isn't visible yet in the back end.
> Ideally they should return the updated state of the object, eliminating the 
> need to look up the updated state in a separate call.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to