metadata.setFlowIdentifier(flowId); metadata.setVersion(version); metadata.setComments(deserializedSnapshot.getSnapshotMetadata().getComments()); final VersionedFlowSnapshot snapshot = new VersionedFlowSnapshot(); snapshot.setSnapshotMetadata(metadata); snapshot.setFlowContents(deserializedSnapshot.getFlowContents()); final VersionedFlowSnapshotMetadata createdMetadata = createdSnapshot.getSnapshotMetadata();
logger.info("Updating Process Group with ID {} to version {} of the Versioned Flow", groupId, flowSnapshot.getSnapshotMetadata().getVersion()); final Bucket bucket = flowSnapshot.getBucket(); final VersionedFlow flow = flowSnapshot.getFlow(); final VersionedFlowSnapshotMetadata metadata = flowSnapshot.getSnapshotMetadata(); final VersionControlInformationDTO vci = new VersionControlInformationDTO(); vci.setBucketId(metadata.getBucketIdentifier()); vci.setRegistryName(serviceFacade.getFlowRegistryName(requestVci.getRegistryId())); vci.setVersion(metadata.getVersion()); vci.setState(flowSnapshot.isLatest() ? VersionedFlowState.UP_TO_DATE.name() : VersionedFlowState.STALE.name());
final Integer srcSnapshotFlowVersion = srcSnapshot.getSnapshotMetadata().getVersion(); destMetadata.setFlowIdentifier(destFlowId); destMetadata.setVersion(destFlowVersion); destMetadata.setComments(srcSnapshot.getSnapshotMetadata().getComments()); srcSnapshot.setFlow(null); srcSnapshot.setBucket(null); srcSnapshot.setSnapshotMetadata(destMetadata);
@Override public VersionedFlowSnapshotResult doExecute(final NiFiRegistryClient client, final Properties properties) throws ParseException, IOException, NiFiRegistryException { final String flowId = getRequiredArg(properties, CommandOption.FLOW_ID); final Integer version = getIntArg(properties, CommandOption.FLOW_VERSION); // if no version was provided then export the latest, otherwise use specific version final VersionedFlowSnapshot versionedFlowSnapshot; if (version == null) { versionedFlowSnapshot = client.getFlowSnapshotClient().getLatest(flowId); } else { versionedFlowSnapshot = client.getFlowSnapshotClient().get(flowId, version); } versionedFlowSnapshot.setFlow(null); versionedFlowSnapshot.setBucket(null); versionedFlowSnapshot.getSnapshotMetadata().setBucketIdentifier(null); versionedFlowSnapshot.getSnapshotMetadata().setFlowIdentifier(null); versionedFlowSnapshot.getSnapshotMetadata().setLink(null); // currently export doesn't use the ResultWriter concept, it always writes JSON // destination will be a file if outputFile is specified, otherwise it will be the output stream of the CLI final String outputFile; if (properties.containsKey(CommandOption.OUTPUT_FILE.getLongName())) { outputFile = properties.getProperty(CommandOption.OUTPUT_FILE.getLongName()); } else { outputFile = null; } return new VersionedFlowSnapshotResult(versionedFlowSnapshot, outputFile); }
@Override public VersionedFlowSnapshot registerVersionedFlowSnapshot(final VersionedFlow flow, final VersionedProcessGroup snapshot, final String comments, final int expectedVersion, final NiFiUser user) throws IOException, NiFiRegistryException { final FlowSnapshotClient snapshotClient = getFlowSnapshotClient(user); final VersionedFlowSnapshot versionedFlowSnapshot = new VersionedFlowSnapshot(); versionedFlowSnapshot.setFlowContents(snapshot); final VersionedFlowSnapshotMetadata metadata = new VersionedFlowSnapshotMetadata(); metadata.setBucketIdentifier(flow.getBucketIdentifier()); metadata.setFlowIdentifier(flow.getIdentifier()); metadata.setAuthor(getIdentity(user)); metadata.setTimestamp(System.currentTimeMillis()); metadata.setVersion(expectedVersion); metadata.setComments(comments); versionedFlowSnapshot.setSnapshotMetadata(metadata); return snapshotClient.create(versionedFlowSnapshot); }
@Override public ProcessGroup updateProcessGroupFlow(final String groupId, final VersionedFlowSnapshot proposedSnapshot, final VersionControlInformationDTO versionControlInformation, final String componentIdSeed, final boolean verifyNotModified, final boolean updateSettings, final boolean updateDescendantVersionedFlows) { final ProcessGroup group = locateProcessGroup(flowController, groupId); group.updateFlow(proposedSnapshot, componentIdSeed, verifyNotModified, updateSettings, updateDescendantVersionedFlows); group.findAllRemoteProcessGroups().stream().forEach(RemoteProcessGroup::initialize); final StandardVersionControlInformation svci = StandardVersionControlInformation.Builder.fromDto(versionControlInformation) .flowSnapshot(proposedSnapshot.getFlowContents()) .build(); group.setVersionControlInformation(svci, Collections.emptyMap()); group.onComponentModified(); return group; }
if (flowSnapshot.getSnapshotMetadata() != null) { flowSnapshot.getSnapshotMetadata().setTimestamp(System.currentTimeMillis()); flowSnapshot.setFlow(null); flowSnapshot.setBucket(null); final VersionedFlowSnapshotMetadata snapshotMetadata = flowSnapshot.getSnapshotMetadata(); processGroupSerializer.serialize(flowSnapshot.getFlowContents(), out); flowSnapshot.setBucket(bucket); flowSnapshot.setFlow(updatedVersionedFlow); return flowSnapshot; } finally {
private VersionedFlowSnapshot getVersionedFlowSnapshot(final BucketEntity bucketEntity, final FlowEntity flowEntity, final Integer version) { // ensure the snapshot exists final FlowSnapshotEntity snapshotEntity = metadataService.getFlowSnapshot(flowEntity.getId(), version); if (snapshotEntity == null) { LOGGER.warn("The specified flow snapshot id [{}] does not exist for version [{}].", flowEntity.getId(), version); throw new ResourceNotFoundException("The specified versioned flow snapshot does not exist for this flow."); } // get the serialized bytes of the snapshot final byte[] serializedSnapshot = flowPersistenceProvider.getFlowContent(bucketEntity.getId(), flowEntity.getId(), version); if (serializedSnapshot == null || serializedSnapshot.length == 0) { throw new IllegalStateException("No serialized content found for snapshot with flow identifier " + flowEntity.getId() + " and version " + version); } // deserialize the contents final InputStream input = new ByteArrayInputStream(serializedSnapshot); final VersionedProcessGroup flowContents = processGroupSerializer.deserialize(input); // map entities to data model final Bucket bucket = DataModelMapper.map(bucketEntity); final VersionedFlow versionedFlow = DataModelMapper.map(bucketEntity, flowEntity); final VersionedFlowSnapshotMetadata snapshotMetadata = DataModelMapper.map(bucketEntity, snapshotEntity); // create the snapshot to return final VersionedFlowSnapshot snapshot = new VersionedFlowSnapshot(); snapshot.setFlowContents(flowContents); snapshot.setSnapshotMetadata(snapshotMetadata); snapshot.setFlow(versionedFlow); snapshot.setBucket(bucket); return snapshot; }
final VersionControlInformation versionControlInfo = getVersionControlInformation(); if (versionControlInfo != null) { if (!versionControlInfo.getFlowIdentifier().equals(updatedFlow.getSnapshotMetadata().getFlowIdentifier())) { throw new IllegalStateException(this + " is under version control but the given flow does not match the flow that this Process Group is synchronized with"); final VersionedProcessGroup flowContents = updatedFlow.getFlowContents(); if (verifyConnectionRemoval) { findAllProcessGroups(updatedFlow.getFlowContents(), proposedProcessGroups); findAllProcessors(updatedFlow.getFlowContents(), proposedProcessors); findAllControllerServices(updatedFlow.getFlowContents(), proposedServices); findAllConnections(updatedFlow.getFlowContents(), proposedConnections);
final Bucket bucket = flowSnapshot.getBucket(); final VersionedFlow flow = flowSnapshot.getFlow(); final VersionedFlowState flowState = flowSnapshot.isLatest() ? VersionedFlowState.UP_TO_DATE : VersionedFlowState.STALE; versionControlInfo.setState(flowState.name()); serviceFacade.discoverCompatibleBundles(flowSnapshot.getFlowContents()); serviceFacade.verifyImportProcessGroup(versionControlInfo, flowSnapshot.getFlowContents(), groupId); if (versionedFlowSnapshot != null) { final Set<ConfigurableComponent> restrictedComponents = FlowRegistryUtils.getRestrictedComponents( versionedFlowSnapshot.getFlowContents(), serviceFacade); restrictedComponents.forEach(restrictedComponent -> { final ComponentAuthorizable restrictedComponentAuthorizable = lookup.getConfigurableComponent(restrictedComponent); final VersionedFlowSnapshot versionedFlowSnapshot = requestProcessGroupEntity.getVersionedFlowSnapshot(); if (versionedFlowSnapshot != null) { serviceFacade.verifyComponentTypes(versionedFlowSnapshot.getFlowContents()); if (flowSnapshot != null && StringUtils.isNotBlank(flowSnapshot.getFlowContents().getName()) && StringUtils.isBlank(processGroup.getName())) { processGroup.setName(flowSnapshot.getFlowContents().getName()); flowSnapshot.getFlowContents().setPosition(null); entity = serviceFacade.updateProcessGroupContents(newGroupRevision, newGroupId, versionControlInfo, flowSnapshot, getIdGenerationSeed().orElse(null), false, true, true);
final VersionedFlowSnapshotMetadata requestSnapshotMetadata = requestFlowSnapshot.getSnapshotMetadata(); if (requestSnapshotMetadata == null) { throw new IllegalArgumentException("Snapshot Metadata must be supplied."); (rev, entity) -> { final VersionedFlowSnapshot flowSnapshot = entity.getVersionedFlowSnapshot(); final VersionedFlowSnapshotMetadata snapshotMetadata = flowSnapshot.getSnapshotMetadata(); final Bucket bucket = flowSnapshot.getBucket(); final VersionedFlow flow = flowSnapshot.getFlow();
@Override public FlowControllerSchema apply(final VersionedFlowSnapshot versionedFlowSnapshot) { // If the VersionedFlowSnapshot came directly from NiFi Registry without modification, as would be the // case with C2 server, then we should have a non-null VersionedFlow, but if we're using a snapshot that // was export from another tool like the CLI, the flow may be null'd out, so fall back to root group. String name; String description; if (versionedFlowSnapshot.getFlow() == null) { name = versionedFlowSnapshot.getFlowContents().getName(); description = versionedFlowSnapshot.getFlowContents().getComments(); } else { name = versionedFlowSnapshot.getFlow().getName(); description = versionedFlowSnapshot.getFlow().getDescription(); } Map<String, Object> map = new HashMap<>(); map.put(CommonPropertyKeys.NAME_KEY, name); map.put(CommonPropertyKeys.COMMENT_KEY, description); return new FlowControllerSchema(map); } }
final VersionedProcessGroup contents = snapshot.getFlowContents(); group.setRemoteProcessGroups(contents.getRemoteProcessGroups()); group.setVariables(contents.getVariables()); coordinates.setLatest(snapshot.isLatest());
/** * 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 VersionedFlowSnapshot getFlowContents(final String bucketId, final String flowId, final int version, final boolean fetchRemoteFlows, final NiFiUser user) throws IOException, NiFiRegistryException { final FlowSnapshotClient snapshotClient = getFlowSnapshotClient(user); final VersionedFlowSnapshot flowSnapshot = snapshotClient.get(bucketId, flowId, version); if (fetchRemoteFlows) { final VersionedProcessGroup contents = flowSnapshot.getFlowContents(); for (final VersionedProcessGroup child : contents.getProcessGroups()) { populateVersionedContentsRecursively(child, user); } } return flowSnapshot; }
final Bucket bucket = registeredSnapshot.getBucket(); final VersionedFlow flow = registeredSnapshot.getFlow(); vci.setRegistryId(registryId); vci.setRegistryName(getFlowRegistryName(registryId)); vci.setVersion(registeredSnapshot.getSnapshotMetadata().getVersion()); vci.setState(VersionedFlowState.UP_TO_DATE.name());
@Override public FlowControllerSchema apply(final VersionedFlowSnapshot versionedFlowSnapshot) { // If the VersionedFlowSnapshot came directly from NiFi Registry without modification, as would be the // case with C2 server, then we should have a non-null VersionedFlow, but if we're using a snapshot that // was export from another tool like the CLI, the flow may be null'd out, so fall back to root group. String name; String description; if (versionedFlowSnapshot.getFlow() == null) { name = versionedFlowSnapshot.getFlowContents().getName(); description = versionedFlowSnapshot.getFlowContents().getComments(); } else { name = versionedFlowSnapshot.getFlow().getName(); description = versionedFlowSnapshot.getFlow().getDescription(); } Map<String, Object> map = new HashMap<>(); map.put(CommonPropertyKeys.NAME_KEY, name); map.put(CommonPropertyKeys.COMMENT_KEY, description); return new FlowControllerSchema(map); } }
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(); }
final ComparableDataFlow remoteFlow = new StandardComparableDataFlow("Remote Flow", proposedSnapshot.getFlowContents()); updateProcessGroup(this, proposedSnapshot.getFlowContents(), componentIdSeed, updatedVersionedComponentIds, false, updateSettings, updateDescendantVersionedFlows, knownVariables); } catch (final Throwable t) {
srcFlowSnapshot.setFlow(null); srcFlowSnapshot.setBucket(null); destMetadata.setFlowIdentifier(destFlowId); destMetadata.setVersion(srcVersion); destMetadata.setComments(srcFlowSnapshot.getSnapshotMetadata().getComments()); srcFlowSnapshot.setSnapshotMetadata(destMetadata); client.getFlowSnapshotClient().create(srcFlowSnapshot);