Github user markap14 commented on a diff in the pull request: https://github.com/apache/nifi/pull/461#discussion_r64249465 --- Diff: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiServiceFacade.java --- @@ -568,164 +699,50 @@ public void verifyDeleteReportingTask(String reportingTaskId) { @Override - public void verifyUpdateSnippet(SnippetDTO snippetDto) { + public void verifyUpdateSnippet(SnippetDTO snippetDto, final Set<String> affectedComponentIds) { try { // if snippet does not exist, then the update request is likely creating it // so we don't verify since it will fail if (snippetDAO.hasSnippet(snippetDto.getId())) { snippetDAO.verifyUpdate(snippetDto); } } catch (final Exception e) { - revisionManager.cancelClaim(snippetDto.getId()); + affectedComponentIds.forEach(id -> revisionManager.cancelClaim(snippetDto.getId())); throw e; } } - private Set<Revision> getRevisionsForGroup(final String groupId) { - final Set<Revision> revisions = new HashSet<>(); - - revisions.add(revisionManager.getRevision(groupId)); - final ProcessGroup processGroup = processGroupDAO.getProcessGroup(groupId); - if (processGroup == null) { - throw new IllegalArgumentException("Snippet contains a reference to Process Group with ID " + groupId + " but no Process Group exists with that ID"); - } - - processGroup.getConnections().stream().map(c -> c.getIdentifier()).map(id -> revisionManager.getRevision(id)).forEach(rev -> revisions.add(rev)); - processGroup.getFunnels().stream().map(c -> c.getIdentifier()).map(id -> revisionManager.getRevision(id)).forEach(rev -> revisions.add(rev)); - processGroup.getInputPorts().stream().map(c -> c.getIdentifier()).map(id -> revisionManager.getRevision(id)).forEach(rev -> revisions.add(rev)); - processGroup.getOutputPorts().stream().map(c -> c.getIdentifier()).map(id -> revisionManager.getRevision(id)).forEach(rev -> revisions.add(rev)); - processGroup.getLabels().stream().map(c -> c.getIdentifier()).map(id -> revisionManager.getRevision(id)).forEach(rev -> revisions.add(rev)); - processGroup.getProcessors().stream().map(c -> c.getIdentifier()).map(id -> revisionManager.getRevision(id)).forEach(rev -> revisions.add(rev)); - processGroup.getRemoteProcessGroups().stream().map(c -> c.getIdentifier()).map(id -> revisionManager.getRevision(id)).forEach(rev -> revisions.add(rev)); - processGroup.getProcessGroups().stream().map(c -> c.getIdentifier()).forEach(id -> revisions.addAll(getRevisionsForGroup(id))); - - return revisions; - } - - private Set<Revision> getRevisionsForSnippet(final SnippetDTO snippetDto) { - final Set<Revision> requiredRevisions = new HashSet<>(); - requiredRevisions.add(revisionManager.getRevision(snippetDto.getId())); - snippetDto.getConnections().entrySet().stream() - .map(entry -> new Revision(entry.getValue().getVersion(), entry.getValue().getClientId(), entry.getKey())) - .forEach(rev -> requiredRevisions.add(rev)); - - snippetDto.getFunnels().entrySet().stream() - .map(entry -> new Revision(entry.getValue().getVersion(), entry.getValue().getClientId(), entry.getKey())) - .forEach(rev -> requiredRevisions.add(rev)); - - snippetDto.getInputPorts().entrySet().stream() - .map(entry -> new Revision(entry.getValue().getVersion(), entry.getValue().getClientId(), entry.getKey())) - .forEach(rev -> requiredRevisions.add(rev)); - - snippetDto.getOutputPorts().entrySet().stream() - .map(entry -> new Revision(entry.getValue().getVersion(), entry.getValue().getClientId(), entry.getKey())) - .forEach(rev -> requiredRevisions.add(rev)); - - snippetDto.getLabels().entrySet().stream() - .map(entry -> new Revision(entry.getValue().getVersion(), entry.getValue().getClientId(), entry.getKey())) - .forEach(rev -> requiredRevisions.add(rev)); - - snippetDto.getProcessors().entrySet().stream() - .map(entry -> new Revision(entry.getValue().getVersion(), entry.getValue().getClientId(), entry.getKey())) - .forEach(rev -> requiredRevisions.add(rev)); - - snippetDto.getRemoteProcessGroups().entrySet().stream() - .map(entry -> new Revision(entry.getValue().getVersion(), entry.getValue().getClientId(), entry.getKey())) - .forEach(rev -> requiredRevisions.add(rev)); - - for (final String groupId : snippetDto.getProcessGroups().keySet()) { - requiredRevisions.addAll(getRevisionsForGroup(groupId)); - } - - return requiredRevisions; - } - - private ProcessGroup getGroup(final String groupId) { - return revisionManager.get(groupId, rev -> processGroupDAO.getProcessGroup(groupId)); - } - @Override - public UpdateResult<SnippetEntity> updateSnippet(final Revision revision, final SnippetDTO snippetDto) { - // if label does not exist, then create new label - if (snippetDAO.hasSnippet(snippetDto.getId()) == false) { - return new UpdateResult<>(createSnippet(snippetDto), true); - } - - final Set<Revision> requiredRevisions = getRevisionsForSnippet(snippetDto); - - // if the parent group is specified in the request, ensure write access to it as it could be moving the components in the snippet - final String requestProcessGroupIdentifier = snippetDto.getParentGroupId(); - if (requestProcessGroupIdentifier != null) { - final ProcessGroup requestProcessGroup = processGroupDAO.getProcessGroup(requestProcessGroupIdentifier); - requestProcessGroup.authorize(authorizer, RequestAction.WRITE); - } - + public SnippetEntity updateSnippet(final Set<Revision> revisions, final SnippetDTO snippetDto) { --- End diff -- This name is a bit confusing, as it is not actually updating a snippet but rather updating the components referenced by the snippet. Perhaps we should rename it "updateSnippetComponents"?
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---