private static void verifyNoDuplicateVersionControlInfoDtos(final ProcessGroup group, final Collection<VersionControlInformationDTO> snippetVcis) { final VersionControlInformation vci = group.getVersionControlInformation(); if (vci != null) { for (final VersionControlInformationDTO snippetVci : snippetVcis) { if (vci.getBucketIdentifier().equals(snippetVci.getBucketId()) && vci.getFlowIdentifier().equals(snippetVci.getFlowId())) { throw new IllegalArgumentException("Cannot place the given Process Group into the desired destination because the destination group or one of its ancestor groups is " + "under Version Control and one of the selected Process Groups is also under Version Control with the same Flow. A Process Group that is under Version Control " + "cannot contain a child Process Group that points to the same Versioned Flow."); } } } final ProcessGroup parent = group.getParent(); if (parent != null) { verifyNoDuplicateVersionControlInfoDtos(parent, snippetVcis); } }
@Override public VersionedFlowSnapshot getVersionedFlowSnapshot(final VersionControlInformationDTO versionControlInfo, final boolean fetchRemoteFlows) { final FlowRegistry flowRegistry = flowRegistryClient.getFlowRegistry(versionControlInfo.getRegistryId()); if (flowRegistry == null) { throw new ResourceNotFoundException("Could not find any Flow Registry registered with identifier " + versionControlInfo.getRegistryId()); } final VersionedFlowSnapshot snapshot; try { snapshot = flowRegistry.getFlowContents(versionControlInfo.getBucketId(), versionControlInfo.getFlowId(), versionControlInfo.getVersion(), fetchRemoteFlows, NiFiUserUtils.getNiFiUser()); } catch (final NiFiRegistryException | IOException e) { logger.error(e.getMessage(), e); throw new IllegalArgumentException("The Flow Registry with ID " + versionControlInfo.getRegistryId() + " reports that no Flow exists with Bucket " + versionControlInfo.getBucketId() + ", Flow " + versionControlInfo.getFlowId() + ", Version " + versionControlInfo.getVersion()); } return snapshot; }
serviceFacade.deleteVersionedFlow(vci.getRegistryId(), vci.getBucketId(), vci.getFlowId()); } catch (final Exception e) { logger.error("Created Versioned Flow with ID {} in bucket with ID {} but failed to replicate the Version Control Information to cluster. " + "Attempted to delete the newly created (empty) flow from the Flow Registry but failed", vci.getFlowId(), vci.getBucketId(), e); serviceFacade.deleteVersionedFlow(vci.getRegistryId(), vci.getBucketId(), vci.getFlowId()); } catch (final Exception e) { logger.error("Created Versioned Flow with ID {} in bucket with ID {} but failed to replicate the Version Control Information to cluster. " + "Attempted to delete the newly created (empty) flow from the Flow Registry but failed", vci.getFlowId(), vci.getBucketId(), e);
throw new IllegalArgumentException("Version Control Information must supply Process Group ID"); if (versionControlInfo.getBucketId() == null) { throw new IllegalArgumentException("Version Control Information must supply Bucket ID");
private void verifyImportProcessGroup(final VersionControlInformationDTO vciDto, final VersionedProcessGroup contents, final ProcessGroup group) { if (group == null) { return; } final VersionControlInformation vci = group.getVersionControlInformation(); if (vci != null) { // Note that we do not compare the Registry ID here because there could be two registry clients // that point to the same server (one could point to localhost while another points to 127.0.0.1, for instance).. if (Objects.equals(vciDto.getBucketId(), vci.getBucketIdentifier()) && Objects.equals(vciDto.getFlowId(), vci.getFlowIdentifier())) { throw new IllegalStateException("Cannot import the specified Versioned Flow into the Process Group because doing so would cause a recursive dataflow. " + "If Process Group A contains Process Group B, then Process Group B is not allowed to contain the flow identified by Process Group A."); } } final Set<VersionedProcessGroup> childGroups = contents.getProcessGroups(); if (childGroups != null) { for (final VersionedProcessGroup childGroup : childGroups) { final VersionedFlowCoordinates childCoordinates = childGroup.getVersionedFlowCoordinates(); if (childCoordinates != null) { final VersionControlInformationDTO childVci = new VersionControlInformationDTO(); childVci.setBucketId(childCoordinates.getBucketId()); childVci.setFlowId(childCoordinates.getFlowId()); verifyImportProcessGroup(childVci, childGroup, group); } } } verifyImportProcessGroup(vciDto, contents, group.getParent()); }
throw new IllegalArgumentException("The Process Group ID in the request body does not match the Process Group ID of the requested resource."); if (requestVersionControlInfoDto.getBucketId() == null) { throw new IllegalArgumentException("The Bucket ID must be supplied."); if (!currentVersion.getBucketId().equals(versionControlInformationDTO.getBucketId())) { throw new IllegalArgumentException("The Version Control Information provided does not match the flow that the Process Group is currently synchronized with.");
private int getLatestVersion(final NiFiClient client, final VersionControlInformationDTO existingVersionControlDTO) throws NiFiClientException, IOException { final FlowClient flowClient = client.getFlowClient(); final String registryId = existingVersionControlDTO.getRegistryId(); final String bucketId = existingVersionControlDTO.getBucketId(); final String flowId = existingVersionControlDTO.getFlowId(); final VersionedFlowSnapshotMetadataSetEntity versions = flowClient.getVersions(registryId, bucketId, flowId); if (versions.getVersionedFlowSnapshotMetadataSet() == null || versions.getVersionedFlowSnapshotMetadataSet().isEmpty()) { throw new NiFiClientException("No versions available"); } int latestVersion = 1; for (VersionedFlowSnapshotMetadataEntity version : versions.getVersionedFlowSnapshotMetadataSet()) { if (version.getVersionedFlowSnapshotMetadata().getVersion() > latestVersion) { latestVersion = version.getVersionedFlowSnapshotMetadata().getVersion(); } } return latestVersion; }
@Override public VersionedFlowSnapshotMetadataSetResult doExecute(final NiFiClient client, final Properties properties) throws NiFiClientException, IOException, MissingOptionException { final String pgId = getRequiredArg(properties, CommandOption.PG_ID); final VersionsClient versionsClient = client.getVersionsClient(); final VersionControlInformationEntity existingVersionControlInfo = versionsClient.getVersionControlInfo(pgId); final VersionControlInformationDTO existingVersionControlDTO = existingVersionControlInfo.getVersionControlInformation(); if (existingVersionControlDTO == null) { throw new NiFiClientException("Process group is not under version control"); } final String registryId = existingVersionControlDTO.getRegistryId(); final String bucketId = existingVersionControlDTO.getBucketId(); final String flowId = existingVersionControlDTO.getFlowId(); final FlowClient flowClient = client.getFlowClient(); final VersionedFlowSnapshotMetadataSetEntity versions = flowClient.getVersions(registryId, bucketId, flowId); if (versions.getVersionedFlowSnapshotMetadataSet() == null || versions.getVersionedFlowSnapshotMetadataSet().isEmpty()) { throw new NiFiClientException("No versions available"); } return new VersionedFlowSnapshotMetadataSetResult(getResultType(properties), versions); }
throw new IllegalArgumentException("The Process Group ID in the request body does not match the Process Group ID of the requested resource."); if (requestVersionControlInfoDto.getBucketId() == null) { throw new IllegalArgumentException("The Bucket ID must be supplied.");
public static Builder fromDto(VersionControlInformationDTO dto) { Builder builder = new Builder(); builder.registryId(dto.getRegistryId()) .registryName(dto.getRegistryName()) .bucketId(dto.getBucketId()) .bucketName(dto.getBucketName()) .flowId(dto.getFlowId()) .flowName(dto.getFlowName()) .flowDescription(dto.getFlowDescription()) .status(new VersionedFlowStatus() { @Override public VersionedFlowState getState() { return VersionedFlowState.valueOf(dto.getState()); } @Override public String getStateExplanation() { return dto.getStateExplanation(); } }) .version(dto.getVersion()); return builder; }
public VersionControlInformationDTO copy(final VersionControlInformationDTO original) { if (original == null) { return null; } final VersionControlInformationDTO copy = new VersionControlInformationDTO(); copy.setRegistryId(original.getRegistryId()); copy.setRegistryName(original.getRegistryName()); copy.setBucketId(original.getBucketId()); copy.setBucketName(original.getBucketName()); copy.setFlowId(original.getFlowId()); copy.setFlowName(original.getFlowName()); copy.setFlowDescription(original.getFlowDescription()); copy.setVersion(original.getVersion()); copy.setState(original.getState()); copy.setStateExplanation(original.getStateExplanation()); return copy; }