@Override public void verifyRevision(final Revision revision, final NiFiUser user) { final Revision curRevision = revisionManager.getRevision(revision.getComponentId()); if (revision.equals(curRevision)) { return; } throw new InvalidRevisionException(revision + " is not the most up-to-date revision. This component appears to have been modified"); }
@Override public <T> RevisionUpdate<T> updateRevision(final RevisionClaim originalClaim, final NiFiUser user, final UpdateRevisionTask<T> task) throws ExpiredRevisionClaimException { Objects.requireNonNull(user); logger.debug("Attempting to update revision using {}", originalClaim); final List<Revision> revisionList = new ArrayList<>(originalClaim.getRevisions()); revisionList.sort(new RevisionComparator()); for (final Revision revision : revisionList) { final Revision currentRevision = getRevision(revision.getComponentId()); final boolean verified = revision.equals(currentRevision); if (!verified) { // Throw an Exception indicating that we failed to obtain the locks throw new InvalidRevisionException("Invalid Revision was given for component with ID '" + revision.getComponentId() + "'"); } } // We successfully verified all revisions. logger.debug("Successfully verified Revision Claim for all revisions"); // Perform the update final RevisionUpdate<T> updatedComponent = task.update(); // If the update succeeded then put the updated revisions into the revisionMap // If an exception is thrown during the update we don't want to update revision so it is ok to bounce out of this method if (updatedComponent != null) { for (final Revision updatedRevision : updatedComponent.getUpdatedRevisions()) { revisionMap.put(updatedRevision.getComponentId(), updatedRevision); } } return updatedComponent; }
throw new InvalidRevisionException("Failed to update component " + authorizable, erce);
/** * Checks the specified response and drains the stream appropriately. */ private void checkResponse(final NodeResponse nodeResponse, final String id) { if (nodeResponse.hasThrowable()) { ClientResponseUtils.drainClientResponse(nodeResponse.getClientResponse()); throw new ClusterRequestException(nodeResponse.getThrowable()); } else if (nodeResponse.getClientResponse().getStatus() == Response.Status.CONFLICT.getStatusCode()) { ClientResponseUtils.drainClientResponse(nodeResponse.getClientResponse()); throw new InvalidRevisionException(String.format("NiFi is unable to process the request at this time.")); } else if (nodeResponse.getClientResponse().getStatus() == Response.Status.NOT_FOUND.getStatusCode()) { ClientResponseUtils.drainClientResponse(nodeResponse.getClientResponse()); throw new ResourceNotFoundException("Unable to find component with id: " + id); } else if (nodeResponse.getClientResponse().getStatus() != Response.Status.OK.getStatusCode()) { ClientResponseUtils.drainClientResponse(nodeResponse.getClientResponse()); throw new ClusterRequestException("Method resulted in an unsuccessful HTTP response code: " + nodeResponse.getClientResponse().getStatus()); } }
@Override public SnippetEntity updateSnippet(final Set<Revision> revisions, final SnippetDTO snippetDto) { final NiFiUser user = NiFiUserUtils.getNiFiUser(); final RevisionClaim revisionClaim = new StandardRevisionClaim(revisions); final RevisionUpdate<SnippetDTO> snapshot; try { snapshot = revisionManager.updateRevision(revisionClaim, user, new UpdateRevisionTask<SnippetDTO>() { @Override public RevisionUpdate<SnippetDTO> update() { // get the updated component final Snippet snippet = snippetDAO.updateSnippetComponents(snippetDto); // drop the snippet snippetDAO.dropSnippet(snippet.getId()); // save updated controller controllerFacade.save(); // increment the revisions final Set<Revision> updatedRevisions = revisions.stream().map(revision -> { final Revision currentRevision = revisionManager.getRevision(revision.getComponentId()); return currentRevision.incrementRevision(revision.getClientId()); }).collect(Collectors.toSet()); final SnippetDTO dto = dtoFactory.createSnippetDto(snippet); return new StandardRevisionUpdate<>(dto, null, updatedRevisions); } }); } catch (final ExpiredRevisionClaimException e) { throw new InvalidRevisionException("Failed to update Snippet", e); } return entityFactory.createSnippetEntity(snapshot.getComponent()); }