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; }
@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; }
private static VersionControlInformationDTO getVersionControlInformation(final Element versionControlInfoElement) { if (versionControlInfoElement == null) { return null; } final VersionControlInformationDTO dto = new VersionControlInformationDTO(); dto.setRegistryId(getString(versionControlInfoElement, "registryId")); dto.setBucketId(getString(versionControlInfoElement, "bucketId")); dto.setBucketName(getString(versionControlInfoElement, "bucketName")); dto.setFlowId(getString(versionControlInfoElement, "flowId")); dto.setFlowName(getString(versionControlInfoElement, "flowName")); dto.setFlowDescription(getString(versionControlInfoElement, "flowDescription")); dto.setVersion(getInt(versionControlInfoElement, "version")); return dto; }
public VersionControlInformationDTO createVersionControlInformationDto(final ProcessGroup group) { if (group == null) { return null; } final VersionControlInformation versionControlInfo = group.getVersionControlInformation(); if (versionControlInfo == null) { return null; } final VersionControlInformationDTO dto = new VersionControlInformationDTO(); dto.setGroupId(group.getIdentifier()); dto.setRegistryId(versionControlInfo.getRegistryIdentifier()); dto.setRegistryName(versionControlInfo.getRegistryName()); dto.setBucketId(versionControlInfo.getBucketIdentifier()); dto.setBucketName(versionControlInfo.getBucketName()); dto.setFlowId(versionControlInfo.getFlowIdentifier()); dto.setFlowName(versionControlInfo.getFlowName()); dto.setFlowDescription(versionControlInfo.getFlowDescription()); dto.setVersion(versionControlInfo.getVersion()); final VersionedFlowStatus status = versionControlInfo.getStatus(); final VersionedFlowState state = status.getState(); dto.setState(state == null ? null : state.name()); dto.setStateExplanation(status.getStateExplanation()); return dto; }
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; }
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()); }
final VersionControlInformationDTO versionControlInfo = new VersionControlInformationDTO(); versionControlInfo.setRegistryId(registryId); versionControlInfo.setBucketId(bucketId); versionControlInfo.setFlowId(flowId); versionControlInfo.setVersion(flowVersion);
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);
public static void updateFlowState(final VersionControlInformationDTO clientDto, final VersionControlInformationDTO dto) { final VersionedFlowState clientState = VersionedFlowState.valueOf(clientDto.getState()); if (clientState == VersionedFlowState.SYNC_FAILURE) { return; final VersionedFlowState dtoState = VersionedFlowState.valueOf(dto.getState()); if (dtoState == VersionedFlowState.SYNC_FAILURE) { clientDto.setState(dto.getState()); clientDto.setStateExplanation(dto.getStateExplanation()); return; clientDto.setState(flowState.name()); clientDto.setStateExplanation(flowState.getDescription());
final VersionedFlow flow = flowSnapshot.getFlow(); versionControlInfo.setBucketName(bucket.getName()); versionControlInfo.setFlowName(flow.getName()); versionControlInfo.setFlowDescription(flow.getDescription()); versionControlInfo.setRegistryName(serviceFacade.getFlowRegistryName(versionControlInfo.getRegistryId())); final VersionedFlowState flowState = flowSnapshot.isLatest() ? VersionedFlowState.UP_TO_DATE : VersionedFlowState.STALE; versionControlInfo.setState(flowState.name());
@Override protected void writeSimpleResult(final PrintStream output) { final VersionControlInformationDTO dto = versionControlInformationEntity.getVersionControlInformation(); if (dto == null) { return; } final Table table = new Table.Builder() .column("Registry", 20, 30, true) .column("Bucket", 20, 30, true) .column("Flow", 20, 30, true) .column("Ver", 3, 3, false) .build(); table.addRow( dto.getRegistryName(), dto.getBucketName(), dto.getFlowName(), String.valueOf(dto.getVersion()) ); final TableWriter tableWriter = new DynamicTableWriter(); tableWriter.write(table, output); }
final FlowRegistry flowRegistry = controller.getFlowRegistryClient().getFlowRegistry(versionControlInfoDto.getRegistryId()); final String registryName = flowRegistry == null ? versionControlInfoDto.getRegistryId() : flowRegistry.getName(); versionControlInfoDto.setState(VersionedFlowState.SYNC_FAILURE.name()); versionControlInfoDto.setStateExplanation("Process Group has not yet been synchronized with the Flow Registry"); final StandardVersionControlInformation versionControlInformation = StandardVersionControlInformation.Builder.fromDto(versionControlInfoDto) .registryName(registryName)
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); } }
newVersion = getLatestVersion(client, existingVersionControlDTO); if (newVersion.intValue() == existingVersionControlDTO.getVersion().intValue()) { throw new NiFiClientException("Process group already at latest version"); existingVersionControlDTO.setVersion(newVersion);
@Override public VersionedFlowState getState() { return VersionedFlowState.valueOf(dto.getState()); }
@Override public String getStateExplanation() { return dto.getStateExplanation(); } })
@Override public ProcessGroup updateVersionControlInformation(final VersionControlInformationDTO versionControlInformation, final Map<String, String> versionedComponentMapping) { final String groupId = versionControlInformation.getGroupId(); final ProcessGroup group = locateProcessGroup(flowController, groupId); final String registryId = versionControlInformation.getRegistryId(); final FlowRegistry flowRegistry = flowController.getFlowRegistryClient().getFlowRegistry(registryId); final String registryName = flowRegistry == null ? registryId : flowRegistry.getName(); final NiFiRegistryFlowMapper mapper = new NiFiRegistryFlowMapper(flowController.getExtensionManager()); final VersionedProcessGroup flowSnapshot = mapper.mapProcessGroup(group, flowController.getControllerServiceProvider(), flowController.getFlowRegistryClient(), false); final StandardVersionControlInformation vci = StandardVersionControlInformation.Builder.fromDto(versionControlInformation) .registryName(registryName) .flowSnapshot(flowSnapshot) .build(); group.setVersionControlInformation(vci, versionedComponentMapping); group.onComponentModified(); return group; }
final VersionControlInformationDTO versionControlInfoDto = new VersionControlInformationDTO(); versionControlInfoDto.setBucketId(snapshotMetadata.getBucketIdentifier()); versionControlInfoDto.setBucketName(bucket.getName()); versionControlInfoDto.setFlowId(snapshotMetadata.getFlowIdentifier()); versionControlInfoDto.setFlowName(flow.getName()); versionControlInfoDto.setFlowDescription(flow.getDescription()); versionControlInfoDto.setGroupId(groupId); versionControlInfoDto.setVersion(snapshotMetadata.getVersion()); versionControlInfoDto.setRegistryId(entity.getRegistryId()); versionControlInfoDto.setRegistryName(serviceFacade.getFlowRegistryName(entity.getRegistryId())); versionControlInfoDto.setState(flowState.name());
throw new IllegalArgumentException("Version Control Information must be supplied"); if (versionControlInfo.getGroupId() == null) { 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"); if (versionControlInfo.getFlowId() == null) { throw new IllegalArgumentException("Version Control Information must supply Flow ID"); if (versionControlInfo.getRegistryId() == null) { throw new IllegalArgumentException("Version Control Information must supply Registry ID"); if (versionControlInfo.getVersion() == null) { throw new IllegalArgumentException("Version Control Information must supply Version"); final String groupId = requestEntity.getVersionControlInformation().getGroupId();
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; }