protected List<Integer> getVersions(final NiFiRegistryClient client, final String flowId) throws NiFiRegistryException, IOException { final FlowSnapshotClient srcSnapshotClient = client.getFlowSnapshotClient(); final List<VersionedFlowSnapshotMetadata> srcVersionMetadata = srcSnapshotClient.getSnapshotMetadata(flowId); return srcVersionMetadata.stream().map(s -> s.getVersion()).collect(Collectors.toList()); }
@Override public Set<VersionedFlowSnapshotMetadata> getFlowVersionsForUser(String registryId, String bucketId, String flowId, NiFiUser user) { try { final FlowRegistry flowRegistry = flowRegistryClient.getFlowRegistry(registryId); if (flowRegistry == null) { throw new IllegalArgumentException("The specified registry id is unknown to this NiFi."); } final Set<VersionedFlowSnapshotMetadata> flowVersions = flowRegistry.getFlowVersions(bucketId, flowId, user); final Set<VersionedFlowSnapshotMetadata> sortedFlowVersions = new TreeSet<>((f1, f2) -> Integer.compare(f1.getVersion(), f2.getVersion())); sortedFlowVersions.addAll(flowVersions); return sortedFlowVersions; } catch (final IOException | NiFiRegistryException ioe) { throw new NiFiCoreException("Unable to obtain listing of versions for bucket with ID " + bucketId + " and flow with ID " + flowId + ": " + ioe, ioe); } }
@Override protected void writeSimpleResult(final PrintStream output) { if (versions == null || versions.isEmpty()) { return; } // date length, with locale specifics final String datePattern = "%1$ta, %<tb %<td %<tY %<tR %<tZ"; final int dateLength = String.format(datePattern, new Date()).length(); final Table table = new Table.Builder() .column("Ver", 3, 3, false) .column("Date", dateLength, dateLength, false) .column("Author", 20, 200, true) .column("Message", 8, 40, true) .build(); versions.forEach(vfs -> { table.addRow( String.valueOf(vfs.getVersion()), String.format(datePattern, new Date(vfs.getTimestamp())), vfs.getAuthor(), vfs.getComments() ); }); final TableWriter tableWriter = new DynamicTableWriter(); tableWriter.write(table, output); } }
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; }
try { final VersionedFlowSnapshotMetadata latestMetadata = snapshotClient.getLatestMetadata(flowId); version = latestMetadata.getVersion() + 1; } catch (NiFiRegistryException e) { final VersionedFlowSnapshotMetadata createdMetadata = createdSnapshot.getSnapshotMetadata(); return new StringResult(String.valueOf(createdMetadata.getVersion()), getContext().isInteractive());
logger.info("Updating Process Group with ID {} to version {} of the Versioned Flow", groupId, flowSnapshot.getSnapshotMetadata().getVersion()); vci.setRegistryId(requestVci.getRegistryId()); vci.setRegistryName(serviceFacade.getFlowRegistryName(requestVci.getRegistryId())); vci.setVersion(metadata.getVersion()); vci.setState(flowSnapshot.isLatest() ? VersionedFlowState.UP_TO_DATE.name() : VersionedFlowState.STALE.name());
versionControlInfoDto.setFlowDescription(flow.getDescription()); versionControlInfoDto.setGroupId(groupId); versionControlInfoDto.setVersion(snapshotMetadata.getVersion()); versionControlInfoDto.setRegistryId(entity.getRegistryId()); versionControlInfoDto.setRegistryName(serviceFacade.getFlowRegistryName(entity.getRegistryId())); final VersionedFlowState flowState = snapshotMetadata.getVersion() == flow.getVersionCount() ? VersionedFlowState.UP_TO_DATE : VersionedFlowState.STALE; versionControlInfoDto.setState(flowState.name());
final Integer srcSnapshotFlowVersion = srcSnapshot.getSnapshotMetadata().getVersion();
vci.setRegistryId(registryId); vci.setRegistryName(getFlowRegistryName(registryId)); vci.setVersion(registeredSnapshot.getSnapshotMetadata().getVersion()); vci.setState(VersionedFlowState.UP_TO_DATE.name());
/** * This is a convenience method that will return true when flow is populated and when the flow's versionCount * is equal to the version of this snapshot. * * @return true if flow is populated and if this snapshot is the latest version for the flow at the time of retrieval */ @XmlTransient public boolean isLatest() { return flow != null && snapshotMetadata != null && flow.getVersionCount() == getSnapshotMetadata().getVersion(); }
@Override public String toString() { final String flowName = (flow == null ? "null" : flow.getName()); return "VersionedFlowSnapshot[flowId=" + snapshotMetadata.getFlowIdentifier() + ", flowName=" + flowName + ", version=" + snapshotMetadata.getVersion() + ", comments=" + snapshotMetadata.getComments() + "]"; } }
final VersionedFlowSnapshotMetadata lastSnapshot = sortedSnapshots.last(); if (snapshotMetadata.getVersion() <= lastSnapshot.getVersion()) { throw new IllegalStateException("A Versioned flow snapshot with the same version already exists: " + snapshotMetadata.getVersion()); if (snapshotMetadata.getVersion() > (lastSnapshot.getVersion() + 1)) { throw new IllegalStateException("Version must be a one-up number, last version was " + lastSnapshot.getVersion() + " and version for this snapshot was " + snapshotMetadata.getVersion()); } else if (snapshotMetadata.getVersion() != 1) { throw new IllegalStateException("Version of first snapshot must be 1");
public static FlowSnapshotEntity map(final VersionedFlowSnapshotMetadata versionedFlowSnapshot) { final FlowSnapshotEntity flowSnapshotEntity = new FlowSnapshotEntity(); flowSnapshotEntity.setFlowId(versionedFlowSnapshot.getFlowIdentifier()); flowSnapshotEntity.setVersion(versionedFlowSnapshot.getVersion()); flowSnapshotEntity.setComments(versionedFlowSnapshot.getComments()); flowSnapshotEntity.setCreated(new Date(versionedFlowSnapshot.getTimestamp())); flowSnapshotEntity.setCreatedBy(versionedFlowSnapshot.getAuthor()); return flowSnapshotEntity; }
public static Event flowVersionCreated(final VersionedFlowSnapshot versionedFlowSnapshot) { final String versionComments = versionedFlowSnapshot.getSnapshotMetadata().getComments() == null ? "" : versionedFlowSnapshot.getSnapshotMetadata().getComments(); return new StandardEvent.Builder() .eventType(EventType.CREATE_FLOW_VERSION) .addField(EventFieldName.BUCKET_ID, versionedFlowSnapshot.getSnapshotMetadata().getBucketIdentifier()) .addField(EventFieldName.FLOW_ID, versionedFlowSnapshot.getSnapshotMetadata().getFlowIdentifier()) .addField(EventFieldName.VERSION, String.valueOf(versionedFlowSnapshot.getSnapshotMetadata().getVersion())) .addField(EventFieldName.USER, versionedFlowSnapshot.getSnapshotMetadata().getAuthor()) .addField(EventFieldName.COMMENT, versionComments) .build(); }
public Builder(final Bucket bucket, final VersionedFlow versionedFlow, final VersionedFlowSnapshotMetadata snapshotMetadata) { bucketId(bucket.getIdentifier()); bucketName(bucket.getName()); flowId(snapshotMetadata.getFlowIdentifier()); flowName(versionedFlow.getName()); version(snapshotMetadata.getVersion()); comments(snapshotMetadata.getComments()); author(snapshotMetadata.getAuthor()); snapshotTimestamp(snapshotMetadata.getTimestamp()); }