@Override public void reset(final Collection<Revision> revisions) { synchronized (this) { // avoid allowing two threads to reset versions concurrently revisionMap.clear(); for (final Revision revision : revisions) { revisionMap.put(revision.getComponentId(), revision); } } }
@Override public boolean equals(final Object obj) { if (obj == null) { return false; } if (obj == this) { return true; } if ((obj instanceof Revision) == false) { return false; } Revision thatRevision = (Revision) obj; // ensure that component ID's are the same (including null) if (thatRevision.getComponentId() == null && getComponentId() != null) { return false; } if (thatRevision.getComponentId() != null && getComponentId() == null) { return false; } if (thatRevision.getComponentId() != null && !thatRevision.getComponentId().equals(getComponentId())) { return false; } if (this.version != null && this.version.equals(thatRevision.version)) { return true; } else { return clientId != null && !clientId.trim().isEmpty() && clientId.equals(thatRevision.getClientId()); } }
private Map<String, Revision> getRevisions(final String groupId, final Set<String> componentIds) { final Set<Revision> processorRevisions = serviceFacade.getRevisionsFromGroup(groupId, group -> componentIds); return processorRevisions.stream().collect(Collectors.toMap(revision -> revision.getComponentId(), Function.identity())); }
private Map<String, Revision> getRevisions(final String groupId, final Set<String> componentIds) { final Set<Revision> processorRevisions = serviceFacade.getRevisionsFromGroup(groupId, group -> componentIds); return processorRevisions.stream().collect(Collectors.toMap(revision -> revision.getComponentId(), Function.identity())); }
@Override public int compare(final Revision o1, final Revision o2) { final int componentComparison = o1.getComponentId().compareTo(o2.getComponentId()); if (componentComparison != 0) { return componentComparison; } final int clientComparison = o1.getClientId().compareTo(o2.getClientId()); if (clientComparison != 0) { return clientComparison; } return o1.getVersion().compareTo(o2.getVersion()); }
@Override public <T> T deleteRevision(final RevisionClaim claim, final NiFiUser user, final DeleteRevisionTask<T> task) throws ExpiredRevisionClaimException { Objects.requireNonNull(user); logger.debug("Attempting to delete revision using {}", claim); final List<Revision> revisionList = new ArrayList<>(claim.getRevisions()); revisionList.sort(new RevisionComparator()); // Verify the provided revisions. String failedId = null; for (final Revision revision : revisionList) { final Revision curRevision = getRevision(revision.getComponentId()); if (!curRevision.equals(revision)) { throw new ExpiredRevisionClaimException("Invalid Revision was given for component with ID '" + failedId + "'"); } } // Perform the action provided final T taskResult = task.performTask(); for (final Revision revision : revisionList) { revisionMap.remove(revision.getComponentId()); } return taskResult; }
@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; }
@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 RevisionUpdate<ScheduleComponentsEntity> update() { // schedule the components processGroupDAO.enableComponents(processGroupId, state, componentRevisions.keySet()); // update the revisions final Map<String, Revision> updatedRevisions = new HashMap<>(); for (final Revision revision : componentRevisions.values()) { final Revision currentRevision = revisionManager.getRevision(revision.getComponentId()); updatedRevisions.put(revision.getComponentId(), currentRevision.incrementRevision(revision.getClientId())); } // save controllerFacade.save(); // gather details for response final ScheduleComponentsEntity entity = new ScheduleComponentsEntity(); entity.setId(processGroupId); entity.setState(state.name()); return new StandardRevisionUpdate<>(entity, null, new HashSet<>(updatedRevisions.values())); } });
@Override public RevisionUpdate<ScheduleComponentsEntity> update() { // schedule the components processGroupDAO.scheduleComponents(processGroupId, state, componentRevisions.keySet()); // update the revisions final Map<String, Revision> updatedRevisions = new HashMap<>(); for (final Revision revision : componentRevisions.values()) { final Revision currentRevision = revisionManager.getRevision(revision.getComponentId()); updatedRevisions.put(revision.getComponentId(), currentRevision.incrementRevision(revision.getClientId())); } // save controllerFacade.save(); // gather details for response final ScheduleComponentsEntity entity = new ScheduleComponentsEntity(); entity.setId(processGroupId); entity.setState(state.name()); return new StandardRevisionUpdate<>(entity, null, new HashSet<>(updatedRevisions.values())); } });
@Override public RevisionUpdate<ActivateControllerServicesEntity> update() { // schedule the components processGroupDAO.activateControllerServices(processGroupId, state, serviceRevisions.keySet()); // update the revisions final Map<String, Revision> updatedRevisions = new HashMap<>(); for (final Revision revision : serviceRevisions.values()) { final Revision currentRevision = revisionManager.getRevision(revision.getComponentId()); updatedRevisions.put(revision.getComponentId(), currentRevision.incrementRevision(revision.getClientId())); } // save controllerFacade.save(); // gather details for response final ActivateControllerServicesEntity entity = new ActivateControllerServicesEntity(); entity.setId(processGroupId); entity.setState(state.name()); return new StandardRevisionUpdate<>(entity, null, new HashSet<>(updatedRevisions.values())); } });
@Override public RevisionUpdate<D> update() { // get the updated component final C component = daoUpdate.get(); // save updated controller controllerFacade.save(); final D dto = dtoCreation.apply(component); final Revision updatedRevision = revisionManager.getRevision(revision.getComponentId()).incrementRevision(revision.getClientId()); final FlowModification lastModification = new FlowModification(updatedRevision, user.getIdentity()); return new StandardRevisionUpdate<>(dto, lastModification); } });
@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); } });
() -> serviceFacade.verifyDeleteSnippet(snippetId, requestRevisions.stream().map(rev -> rev.getComponentId()).collect(Collectors.toSet())), (revisions, entity) -> {
@Override public RevisionUpdate<ProcessGroupDTO> update() { // update the Process Group processGroupDAO.updateProcessGroupFlow(groupId, proposedFlowSnapshot, versionControlInfo, componentIdSeed, verifyNotModified, updateSettings, updateDescendantVersionedFlows); // update the revisions final Set<Revision> updatedRevisions = revisions.stream() .map(rev -> revisionManager.getRevision(rev.getComponentId()).incrementRevision(revision.getClientId())) .collect(Collectors.toSet()); // save controllerFacade.save(); // gather details for response final ProcessGroupDTO dto = dtoFactory.createProcessGroupDto(processGroup); final Revision updatedRevision = revisionManager.getRevision(groupId).incrementRevision(revision.getClientId()); final FlowModification lastModification = new FlowModification(updatedRevision, user.getIdentity()); return new StandardRevisionUpdate<>(dto, lastModification, updatedRevisions); } });
public static ComponentRevision fromRevision(final Revision revision) { final ComponentRevision componentRevision = new ComponentRevision(); componentRevision.setVersion(revision.getVersion()); componentRevision.setClientId(revision.getClientId()); componentRevision.setComponentId(revision.getComponentId()); return componentRevision; }
dto.setClientId(revision.getClientId()); dto.setVersion(revision.getVersion()); componentsToSchedule.put(revision.getComponentId(), dto); });
authorizeSnippet(snippet, authorizer, lookup, RequestAction.WRITE, false, false); }, () -> serviceFacade.verifyUpdateSnippet(requestSnippetDTO, requestRevisions.stream().map(rev -> rev.getComponentId()).collect(Collectors.toSet())), (revisions, snippetEntity) -> {
dto.setClientId(revision.getClientId()); dto.setVersion(revision.getVersion()); componentsToSchedule.put(revision.getComponentId(), dto); });
@Override public RegistryClientEntity updateRegistryClient(Revision revision, RegistryDTO registryDTO) { final RevisionClaim revisionClaim = new StandardRevisionClaim(revision); final NiFiUser user = NiFiUserUtils.getNiFiUser(); final FlowRegistry registry = registryDAO.getFlowRegistry(registryDTO.getId()); final RevisionUpdate<FlowRegistry> revisionUpdate = revisionManager.updateRevision(revisionClaim, user, () -> { final boolean duplicateName = registryDAO.getFlowRegistries().stream() .anyMatch(reg -> reg.getName().equals(registryDTO.getName()) && !reg.getIdentifier().equals(registryDTO.getId())); if (duplicateName) { throw new IllegalStateException("Cannot update Flow Registry because a Flow Registry already exists with the name " + registryDTO.getName()); } registry.setDescription(registryDTO.getDescription()); registry.setName(registryDTO.getName()); registry.setURL(registryDTO.getUri()); controllerFacade.save(); final Revision updatedRevision = revisionManager.getRevision(revision.getComponentId()).incrementRevision(revision.getClientId()); final FlowModification lastModification = new FlowModification(updatedRevision, user.getIdentity()); return new StandardRevisionUpdate<>(registry, lastModification); }); final FlowRegistry updatedReg = revisionUpdate.getComponent(); return createRegistryClientEntity(updatedReg); }