org.apache.nifi.registry.flow.VersionedFlowSnapshot Java Examples

The following examples show how to use org.apache.nifi.registry.flow.VersionedFlowSnapshot. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FlowsIT.java    From nifi-registry with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetFlowVersionsEmpty() throws Exception {

    // Given: a Bucket "2" containing a flow "3" with no snapshots (see FlowsIT.sql)
    final String bucketId = "2";
    final String flowId = "3";

    // When: the /buckets/{id}/flows/{id}/versions endpoint is queried

    final VersionedFlowSnapshot[] flowSnapshots = client
            .target(createURL("buckets/{bucketId}/flows/{flowId}/versions"))
            .resolveTemplate("bucketId", bucketId)
            .resolveTemplate("flowId", flowId)
            .request()
            .get(VersionedFlowSnapshot[].class);

    // Then: an empty array is returned

    assertNotNull(flowSnapshots);
    assertEquals(0, flowSnapshots.length);
}
 
Example #2
Source File: JerseyFlowSnapshotClient.java    From nifi-registry with Apache License 2.0 6 votes vote down vote up
@Override
public VersionedFlowSnapshot getLatest(final String bucketId, final String flowId)
        throws NiFiRegistryException, IOException {
    if (StringUtils.isBlank(bucketId)) {
        throw new IllegalArgumentException("Bucket Identifier cannot be blank");
    }

    if (StringUtils.isBlank(flowId)) {
        throw new IllegalArgumentException("Flow Identifier cannot be blank");
    }

    return executeAction("Error retrieving latest snapshot", () -> {
        final WebTarget target = bucketFlowSnapshotTarget
                .path("/latest")
                .resolveTemplate("bucketId", bucketId)
                .resolveTemplate("flowId", flowId);

        return getRequestBuilder(target).get(VersionedFlowSnapshot.class);
    });
}
 
Example #3
Source File: StandardServiceFacade.java    From nifi-registry with Apache License 2.0 6 votes vote down vote up
private void populateLinksAndPermissions(final VersionedFlowSnapshot snapshot) {
    if (snapshot == null) {
        return;
    }

    if (snapshot.getSnapshotMetadata() != null) {
        linkService.populateLinks(snapshot.getSnapshotMetadata());
    }

    if (snapshot.getFlow() != null) {
        linkService.populateLinks(snapshot.getFlow());
    }

    if (snapshot.getBucket() != null) {
        permissionsService.populateBucketPermissions(snapshot.getBucket());
        linkService.populateLinks(snapshot.getBucket());
    }
}
 
Example #4
Source File: TestProcessGroupResource.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testExportProcessGroup() {
    final String groupId = UUID.randomUUID().toString();
    final VersionedFlowSnapshot versionedFlowSnapshot = mock(VersionedFlowSnapshot.class);

    when(serviceFacade.getCurrentFlowSnapshotByGroupId(groupId)).thenReturn(versionedFlowSnapshot);

    final String flowName = "flowname";
    final VersionedProcessGroup versionedProcessGroup = mock(VersionedProcessGroup.class);
    when(versionedFlowSnapshot.getFlowContents()).thenReturn(versionedProcessGroup);
    when(versionedProcessGroup.getName()).thenReturn(flowName);

    final Response response = processGroupResource.exportProcessGroup(groupId);

    final VersionedFlowSnapshot resultEntity = (VersionedFlowSnapshot)response.getEntity();

    assertEquals(200, response.getStatus());
    assertEquals(versionedFlowSnapshot, resultEntity);
}
 
Example #5
Source File: BucketFlowResource.java    From nifi-registry with Apache License 2.0 6 votes vote down vote up
private static void setSnaphotMetadataIfMissing(
        @NotNull String bucketIdParam,
        @NotNull String flowIdParam,
        @NotNull VersionedFlowSnapshot flowSnapshot) {

    VersionedFlowSnapshotMetadata metadata = flowSnapshot.getSnapshotMetadata();
    if (metadata == null) {
        metadata = new VersionedFlowSnapshotMetadata();
    }

    if (metadata.getBucketIdentifier() == null) {
        metadata.setBucketIdentifier(bucketIdParam);
    }

    if (metadata.getFlowIdentifier() == null) {
        metadata.setFlowIdentifier(flowIdParam);
    }

    flowSnapshot.setSnapshotMetadata(metadata);
}
 
Example #6
Source File: JerseyFlowSnapshotClient.java    From nifi-registry with Apache License 2.0 6 votes vote down vote up
@Override
public VersionedFlowSnapshot get(final String bucketId, final String flowId, final int version)
        throws NiFiRegistryException, IOException {
    if (StringUtils.isBlank(bucketId)) {
        throw new IllegalArgumentException("Bucket Identifier cannot be blank");
    }

    if (StringUtils.isBlank(flowId)) {
        throw new IllegalArgumentException("Flow Identifier cannot be blank");
    }

    if (version < 1) {
        throw new IllegalArgumentException("Version must be greater than 1");
    }

    return executeAction("Error retrieving flow snapshot", () -> {
        final WebTarget target = bucketFlowSnapshotTarget
                .path("/{version}")
                .resolveTemplate("bucketId", bucketId)
                .resolveTemplate("flowId", flowId)
                .resolveTemplate("version", version);

        return getRequestBuilder(target).get(VersionedFlowSnapshot.class);
    });
}
 
Example #7
Source File: TestRegistryService.java    From nifi-registry with Apache License 2.0 6 votes vote down vote up
private VersionedFlowSnapshot createSnapshot() {
    final VersionedFlowSnapshotMetadata snapshotMetadata = new VersionedFlowSnapshotMetadata();
    snapshotMetadata.setFlowIdentifier("flow1");
    snapshotMetadata.setVersion(1);
    snapshotMetadata.setComments("This is the first snapshot");
    snapshotMetadata.setBucketIdentifier("b1");
    snapshotMetadata.setAuthor("user1");

    final VersionedProcessGroup processGroup = new VersionedProcessGroup();
    processGroup.setIdentifier("pg1");
    processGroup.setName("My Process Group");

    final VersionedFlowSnapshot snapshot = new VersionedFlowSnapshot();
    snapshot.setSnapshotMetadata(snapshotMetadata);
    snapshot.setFlowContents(processGroup);

    return snapshot;
}
 
Example #8
Source File: TestFlowContentSerializer.java    From nifi-registry with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeserializeVer3() throws IOException {
    final String file = "/serialization/ver3.snapshot";
    try (final InputStream is = this.getClass().getResourceAsStream(file)) {
        final Integer version = serializer.readDataModelVersion(is);
        assertNotNull(version);
        assertEquals(3, version.intValue());
        assertFalse(serializer.isProcessGroupVersion(version));

        final FlowContent flowContent = serializer.deserializeFlowContent(version, is);
        assertNotNull(flowContent);

        final VersionedFlowSnapshot flowSnapshot = flowContent.getFlowSnapshot();
        assertNotNull(flowSnapshot);

        final VersionedProcessGroup processGroup = flowSnapshot.getFlowContents();
        assertNotNull(processGroup);
        assertNotNull(processGroup.getProcessors());
        assertEquals(1, processGroup.getProcessors().size());
    }
}
 
Example #9
Source File: StandardProcessGroupDAO.java    From nifi with Apache License 2.0 6 votes vote down vote up
@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().forEach(RemoteProcessGroup::initialize);

    // process group being updated may not be versioned
    if (versionControlInformation != null) {
        final StandardVersionControlInformation svci = StandardVersionControlInformation.Builder.fromDto(versionControlInformation)
                .flowSnapshot(proposedSnapshot.getFlowContents())
                .build();
        group.setVersionControlInformation(svci, Collections.emptyMap());
    }

    group.onComponentModified();

    return group;
}
 
Example #10
Source File: ImportFlowIT.java    From nifi with Apache License 2.0 6 votes vote down vote up
private Set<FlowDifference> getLocalModifications(final ProcessGroup processGroup, final VersionedFlowSnapshot versionedFlowSnapshot) {
    final NiFiRegistryFlowMapper mapper = new NiFiRegistryFlowMapper(getFlowController().getExtensionManager());
    final VersionedProcessGroup localGroup = mapper.mapProcessGroup(processGroup, getFlowController().getControllerServiceProvider(), getFlowController().getFlowRegistryClient(), true);
    final VersionedProcessGroup registryGroup = versionedFlowSnapshot.getFlowContents();

    final ComparableDataFlow localFlow = new StandardComparableDataFlow("Local Flow", localGroup);
    final ComparableDataFlow registryFlow = new StandardComparableDataFlow("Versioned Flow", registryGroup);

    final Set<String> ancestorServiceIds = processGroup.getAncestorServiceIds();
    final FlowComparator flowComparator = new StandardFlowComparator(registryFlow, localFlow, ancestorServiceIds, new ConciseEvolvingDifferenceDescriptor());
    final FlowComparison flowComparison = flowComparator.compare();
    final Set<FlowDifference> differences = flowComparison.getDifferences().stream()
        .filter(difference -> difference.getDifferenceType() != DifferenceType.BUNDLE_CHANGED)
        .filter(FlowDifferenceFilters.FILTER_ADDED_REMOVED_REMOTE_PORTS)
        .filter(FlowDifferenceFilters.FILTER_PUBLIC_PORT_NAME_CHANGES)
        .filter(FlowDifferenceFilters.FILTER_IGNORABLE_VERSIONED_FLOW_COORDINATE_CHANGES)
        .collect(Collectors.toCollection(HashSet::new));

    return differences;
}
 
Example #11
Source File: TestRestAPI.java    From nifi-registry with Apache License 2.0 5 votes vote down vote up
private static VersionedFlowSnapshot createSnapshot(Client client, VersionedFlow flow, int num) {
    final VersionedFlowSnapshotMetadata snapshotMetadata1 = new VersionedFlowSnapshotMetadata();
    snapshotMetadata1.setBucketIdentifier(flow.getBucketIdentifier());
    snapshotMetadata1.setFlowIdentifier(flow.getIdentifier());
    snapshotMetadata1.setVersion(num);
    snapshotMetadata1.setComments("This is snapshot #" + num);

    final VersionedProcessGroup snapshotContents1 = new VersionedProcessGroup();
    snapshotContents1.setIdentifier("pg1");
    snapshotContents1.setName("Process Group 1");

    final VersionedFlowSnapshot snapshot1 = new VersionedFlowSnapshot();
    snapshot1.setSnapshotMetadata(snapshotMetadata1);
    snapshot1.setFlowContents(snapshotContents1);

    final VersionedFlowSnapshot createdSnapshot = client.target(REGISTRY_API_BUCKETS_URL)
            .path("{bucketId}/flows/{flowId}/versions")
            .resolveTemplate("bucketId", flow.getBucketIdentifier())
            .resolveTemplate("flowId", flow.getIdentifier())
            .request()
            .post(
                    Entity.entity(snapshot1, MediaType.APPLICATION_JSON_TYPE),
                    VersionedFlowSnapshot.class
            );

    return createdSnapshot;
}
 
Example #12
Source File: StandardServiceFacade.java    From nifi-registry with Apache License 2.0 5 votes vote down vote up
private void authorizeBucketAccess(final RequestAction action, final VersionedFlowSnapshot flowSnapshot) {
    // this should never happen, but if somehow the back-end didn't populate the bucket id let's make sure the flow snapshot isn't returned
    if (flowSnapshot == null || flowSnapshot.getSnapshotMetadata() == null) {
        throw new IllegalStateException("Unable to authorize access because bucket identifier is null or blank");
    }

    authorizeBucketAccess(action, flowSnapshot.getSnapshotMetadata().getBucketIdentifier());
}
 
Example #13
Source File: ImportFlowIT.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testParameterContextCreatedOnImportWithSensitivePropertyReference() {
    // Create a processor with a sensitive property
    final ProcessorNode processor = createProcessorNode(UsernamePasswordProcessor.class);
    processor.setProperties(Collections.singletonMap(UsernamePasswordProcessor.PASSWORD.getName(), "#{secret-param}"));

    // Create a VersionedFlowSnapshot that contains the processor
    final Parameter parameter = new Parameter(new ParameterDescriptor.Builder().name("secret-param").sensitive(true).build(), null);
    final VersionedFlowSnapshot versionedFlowWithParameterReference = createFlowSnapshot(Collections.emptyList(), Collections.singletonList(processor), Collections.singleton(parameter));

    // Create child group
    final ProcessGroup innerGroup = getFlowController().getFlowManager().createProcessGroup("inner-group-id");
    innerGroup.setName("Inner Group");
    getRootGroup().addProcessGroup(innerGroup);

    innerGroup.updateFlow(versionedFlowWithParameterReference, null, true, true, true);

    final ParameterContext parameterContext = innerGroup.getParameterContext();
    assertNotNull(parameterContext);

    final Collection<Parameter> parameters = parameterContext.getParameters().values();
    assertEquals(1, parameters.size());

    final Parameter firstParameter = parameters.iterator().next();
    assertEquals("secret-param", firstParameter.getDescriptor().getName());
    assertTrue(firstParameter.getDescriptor().isSensitive());
    assertNull(firstParameter.getValue());
}
 
Example #14
Source File: ExportFlowVersion.java    From nifi with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #15
Source File: ConfigMain.java    From nifi-minifi with Apache License 2.0 5 votes vote down vote up
public static ConfigSchema transformVersionedFlowSnapshotToSchema(InputStream source) throws IOException {
    try {
        final ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
        objectMapper.setAnnotationIntrospector(new JaxbAnnotationIntrospector(objectMapper.getTypeFactory()));
        objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

        final VersionedFlowSnapshot versionedFlowSnapshot = objectMapper.readValue(source, VersionedFlowSnapshot.class);
        return transformVersionedFlowSnapshotToSchema(versionedFlowSnapshot);
    } finally {
        source.close();
    }
}
 
Example #16
Source File: ImportFlowIT.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testParameterCreatedWithNullValueOnImportWithSensitivePropertyReference() {
    // Create a processor with a sensitive property
    final ProcessorNode processor = createProcessorNode(UsernamePasswordProcessor.class);
    processor.setProperties(Collections.singletonMap(UsernamePasswordProcessor.PASSWORD.getName(), "#{secret-param}"));

    // Create a VersionedFlowSnapshot that contains the processor
    final Parameter parameter = new Parameter(new ParameterDescriptor.Builder().name("secret-param").sensitive(true).build(), null);
    final VersionedFlowSnapshot versionedFlowWithParameterReference = createFlowSnapshot(Collections.emptyList(), Collections.singletonList(processor), Collections.singleton(parameter));

    // Create child group
    final ProcessGroup innerGroup = getFlowController().getFlowManager().createProcessGroup("inner-group-id");
    innerGroup.setName("Inner Group");
    getRootGroup().addProcessGroup(innerGroup);

    final ParameterReferenceManager parameterReferenceManager = new StandardParameterReferenceManager(getFlowController().getFlowManager());
    final ParameterContext parameterContext = new StandardParameterContext("param-context-id", "parameter-context", parameterReferenceManager, null);
    innerGroup.setParameterContext(parameterContext);

    assertTrue(parameterContext.getParameters().isEmpty());

    innerGroup.updateFlow(versionedFlowWithParameterReference, null, true, true, true);

    final Collection<Parameter> parameters = parameterContext.getParameters().values();
    assertEquals(1, parameters.size());

    final Parameter firstParameter = parameters.iterator().next();
    assertEquals("secret-param", firstParameter.getDescriptor().getName());
    assertTrue(firstParameter.getDescriptor().isSensitive());
    assertNull(firstParameter.getValue());
}
 
Example #17
Source File: RegistryService.java    From nifi-registry with Apache License 2.0 5 votes vote down vote up
public VersionedFlowSnapshot getFlowSnapshot(final String bucketIdentifier, final String flowIdentifier, final Integer version) {
    if (StringUtils.isBlank(bucketIdentifier)) {
        throw new IllegalArgumentException("Bucket identifier cannot be null or blank");
    }

    if (StringUtils.isBlank(flowIdentifier)) {
        throw new IllegalArgumentException("Flow identifier cannot be null or blank");
    }

    if (version == null) {
        throw new IllegalArgumentException("Version cannot be null or blank");
    }

    final BucketEntity existingBucket = metadataService.getBucketById(bucketIdentifier);
    if (existingBucket == null) {
        LOGGER.warn("The specified bucket id [{}] does not exist.", bucketIdentifier);
        throw new ResourceNotFoundException("The specified bucket ID does not exist in this registry.");
    }

    // we need to populate the version count here so we have to do this retrieval instead of snapshotEntity.getFlow()
    final FlowEntity flowEntityWithCount = metadataService.getFlowByIdWithSnapshotCounts(flowIdentifier);
    if (flowEntityWithCount == null) {
        LOGGER.warn("The specified flow id [{}] does not exist.", flowIdentifier);
        throw new ResourceNotFoundException("The specified flow ID does not exist in this bucket.");
    }

    if (!existingBucket.getId().equals(flowEntityWithCount.getBucketId())) {
        throw new IllegalStateException("The requested flow is not located in the given bucket");
    }

    return getVersionedFlowSnapshot(existingBucket, flowEntityWithCount, version);
}
 
Example #18
Source File: TestRegistryService.java    From nifi-registry with Apache License 2.0 5 votes vote down vote up
@Test(expected = IllegalStateException.class)
public void testCreateFirstSnapshotWithBadVersion() {
    final VersionedFlowSnapshot snapshot = createSnapshot();

    final BucketEntity existingBucket = new BucketEntity();
    existingBucket.setId("b1");
    existingBucket.setName("My Bucket");
    existingBucket.setDescription("This is my bucket");
    existingBucket.setCreated(new Date());

    when(metadataService.getBucketById(existingBucket.getId())).thenReturn(existingBucket);

    // return a flow with the existing snapshot when getFlowById is called
    final FlowEntity existingFlow = new FlowEntity();
    existingFlow.setId("flow1");
    existingFlow.setName("My Flow");
    existingFlow.setDescription("This is my flow.");
    existingFlow.setCreated(new Date());
    existingFlow.setModified(new Date());
    existingFlow.setBucketId(existingBucket.getId());

    when(metadataService.getFlowById(existingFlow.getId())).thenReturn(existingFlow);

    // set the first version to something other than 1
    snapshot.getSnapshotMetadata().setVersion(100);
    registryService.createFlowSnapshot(snapshot);
}
 
Example #19
Source File: TestRegistryService.java    From nifi-registry with Apache License 2.0 5 votes vote down vote up
@Test(expected = ResourceNotFoundException.class)
public void testCreateSnapshotBucketDoesNotExist() {
    when(metadataService.getBucketById(any(String.class))).thenReturn(null);

    final VersionedFlowSnapshot snapshot = createSnapshot();
    registryService.createFlowSnapshot(snapshot);
}
 
Example #20
Source File: TestVersionsResource.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testExportFlowVersion() {
    final String groupId = UUID.randomUUID().toString();
    final VersionedFlowSnapshot versionedFlowSnapshot = mock(VersionedFlowSnapshot.class);

    when(serviceFacade.getVersionedFlowSnapshotByGroupId(groupId)).thenReturn(versionedFlowSnapshot);

    final String flowName = "flowname";
    final int flowVersion = 1;
    final VersionedProcessGroup versionedProcessGroup = mock(VersionedProcessGroup.class);
    final VersionedFlowSnapshotMetadata snapshotMetadata = mock(VersionedFlowSnapshotMetadata.class);
    when(versionedFlowSnapshot.getFlowContents()).thenReturn(versionedProcessGroup);
    when(versionedProcessGroup.getName()).thenReturn(flowName);
    when(versionedFlowSnapshot.getSnapshotMetadata()).thenReturn(snapshotMetadata);
    when(snapshotMetadata.getVersion()).thenReturn(flowVersion);

    final VersionedProcessGroup innerVersionedProcessGroup = mock(VersionedProcessGroup.class);
    final VersionedProcessGroup innerInnerVersionedProcessGroup = mock(VersionedProcessGroup.class);
    when(versionedProcessGroup.getProcessGroups()).thenReturn(Sets.newHashSet(innerVersionedProcessGroup));
    when(innerVersionedProcessGroup.getProcessGroups()).thenReturn(Sets.newHashSet(innerInnerVersionedProcessGroup));

    final Response response = versionsResource.exportFlowVersion(groupId);

    final VersionedFlowSnapshot resultEntity = (VersionedFlowSnapshot)response.getEntity();

    assertEquals(200, response.getStatus());
    assertEquals(versionedFlowSnapshot, resultEntity);

    verify(versionedFlowSnapshot).setFlow(null);
    verify(versionedFlowSnapshot).setBucket(null);
    verify(versionedFlowSnapshot).setSnapshotMetadata(null);
    verify(versionedProcessGroup).setVersionedFlowCoordinates(null);
    verify(innerVersionedProcessGroup).setVersionedFlowCoordinates(null);
    verify(innerInnerVersionedProcessGroup).setVersionedFlowCoordinates(null);
}
 
Example #21
Source File: RegistryUtil.java    From nifi with Apache License 2.0 5 votes vote down vote up
private void populateVersionedContentsRecursively(final VersionedProcessGroup group, final NiFiUser user) throws NiFiRegistryException, IOException {
    if (group == null) {
        return;
    }

    final VersionedFlowCoordinates coordinates = group.getVersionedFlowCoordinates();
    if (coordinates != null) {
        final String registryUrl = coordinates.getRegistryUrl();
        final String bucketId = coordinates.getBucketId();
        final String flowId = coordinates.getFlowId();
        final int version = coordinates.getVersion();

        final RegistryUtil subFlowUtil = new RegistryUtil(registryUrl, sslContext);
        final VersionedFlowSnapshot snapshot = subFlowUtil.getFlowByID(bucketId, flowId, version);
        final VersionedProcessGroup contents = snapshot.getFlowContents();

        group.setComments(contents.getComments());
        group.setConnections(contents.getConnections());
        group.setControllerServices(contents.getControllerServices());
        group.setFunnels(contents.getFunnels());
        group.setInputPorts(contents.getInputPorts());
        group.setLabels(contents.getLabels());
        group.setOutputPorts(contents.getOutputPorts());
        group.setProcessGroups(contents.getProcessGroups());
        group.setProcessors(contents.getProcessors());
        group.setRemoteProcessGroups(contents.getRemoteProcessGroups());
        group.setVariables(contents.getVariables());
        coordinates.setLatest(snapshot.isLatest());
    }

    for (final VersionedProcessGroup child : group.getProcessGroups()) {
        populateVersionedContentsRecursively(child, user);
    }
}
 
Example #22
Source File: StandardServiceFacade.java    From nifi-registry with Apache License 2.0 5 votes vote down vote up
@Override
public VersionedFlowSnapshot getLatestFlowSnapshot(final String flowIdentifier) {
    final VersionedFlowSnapshotMetadata latestMetadata = registryService.getLatestFlowSnapshotMetadata(flowIdentifier);
    authorizeBucketAccess(RequestAction.READ, latestMetadata);

    final String bucketIdentifier = latestMetadata.getBucketIdentifier();
    final Integer latestVersion = latestMetadata.getVersion();

    final VersionedFlowSnapshot lastSnapshot = registryService.getFlowSnapshot(bucketIdentifier, flowIdentifier, latestVersion);
    populateLinksAndPermissions(lastSnapshot);
    return lastSnapshot;
}
 
Example #23
Source File: RegistryUtil.java    From nifi with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #24
Source File: ImportFlowIT.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testChangeVersionFromParamReferenceToAnotherParamReferenceIsLocalModification() {
    // Create a processor with a sensitive property and create a versioned flow for it.
    final ProcessorNode initialProcessor = createProcessorNode(UsernamePasswordProcessor.class);
    final Map<String, String> initialProperties = new HashMap<>();
    initialProperties.put(UsernamePasswordProcessor.USERNAME.getName(), "user");
    initialProperties.put(UsernamePasswordProcessor.PASSWORD.getName(), "#{secret-param}");
    initialProcessor.setProperties(initialProperties);

    final VersionedFlowSnapshot initialVersionSnapshot = createFlowSnapshot(Collections.emptyList(), Collections.singletonList(initialProcessor), null);

    // Update processor to have a different explicit value for both sensitive and non-sensitive properties and create a versioned flow for it.
    final Map<String, String> updatedProperties = new HashMap<>();
    updatedProperties.put(UsernamePasswordProcessor.USERNAME.getName(), "user");
    updatedProperties.put(UsernamePasswordProcessor.PASSWORD.getName(), "#{other-param}");
    initialProcessor.setProperties(updatedProperties);

    final VersionedFlowSnapshot updatedVersionSnapshot = createFlowSnapshot(Collections.emptyList(), Collections.singletonList(initialProcessor), null);

    // Create child group and update to the first version of the flow, with parameter ref
    final ProcessGroup innerGroup = getFlowController().getFlowManager().createProcessGroup("inner-group-id");
    innerGroup.setName("Inner Group");
    getRootGroup().addProcessGroup(innerGroup);

    // Import the flow into our newly created group
    innerGroup.updateFlow(initialVersionSnapshot, null, true, true, true);

    final Set<FlowDifference> localModifications = getLocalModifications(innerGroup, updatedVersionSnapshot);
    assertEquals(1, localModifications.size());
    assertEquals(DifferenceType.PROPERTY_CHANGED, localModifications.iterator().next().getDifferenceType());
}
 
Example #25
Source File: BucketFlowResource.java    From nifi-registry with Apache License 2.0 5 votes vote down vote up
@GET
@Path("{flowId}/versions/{versionNumber: \\d+}")
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(
        value = "Get bucket flow version",
        notes = "Gets the given version of a flow, including the metadata and content for the version.",
        response = VersionedFlowSnapshot.class,
        extensions = {
                @Extension(name = "access-policy", properties = {
                        @ExtensionProperty(name = "action", value = "read"),
                        @ExtensionProperty(name = "resource", value = "/buckets/{bucketId}") })
        }
)
@ApiResponses({
        @ApiResponse(code = 400, message = HttpStatusMessages.MESSAGE_400),
        @ApiResponse(code = 401, message = HttpStatusMessages.MESSAGE_401),
        @ApiResponse(code = 403, message = HttpStatusMessages.MESSAGE_403),
        @ApiResponse(code = 404, message = HttpStatusMessages.MESSAGE_404),
        @ApiResponse(code = 409, message = HttpStatusMessages.MESSAGE_409) })
public Response getFlowVersion(
        @PathParam("bucketId")
        @ApiParam("The bucket identifier")
            final String bucketId,
        @PathParam("flowId")
        @ApiParam("The flow identifier")
            final String flowId,
        @PathParam("versionNumber")
        @ApiParam("The version number")
            final Integer versionNumber) {

    final VersionedFlowSnapshot snapshot = serviceFacade.getFlowSnapshot(bucketId, flowId, versionNumber);
    return Response.status(Response.Status.OK).entity(snapshot).build();
}
 
Example #26
Source File: FlowResource.java    From nifi-registry with Apache License 2.0 5 votes vote down vote up
@GET
@Path("{flowId}/versions/latest")
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(
        value = "Get latest flow version",
        notes = "Gets the latest version of a flow, including metadata and flow content.",
        nickname = "globalGetLatestFlowVersion",
        response = VersionedFlowSnapshot.class,
        extensions = {
                @Extension(name = "access-policy", properties = {
                        @ExtensionProperty(name = "action", value = "read"),
                        @ExtensionProperty(name = "resource", value = "/buckets/{bucketId}") })
        }
)
@ApiResponses({
        @ApiResponse(code = 401, message = HttpStatusMessages.MESSAGE_401),
        @ApiResponse(code = 403, message = HttpStatusMessages.MESSAGE_403),
        @ApiResponse(code = 404, message = HttpStatusMessages.MESSAGE_404),
        @ApiResponse(code = 409, message = HttpStatusMessages.MESSAGE_409) })
public Response getLatestFlowVersion(
        @PathParam("flowId")
        @ApiParam("The flow identifier")
            final String flowId) {

    final VersionedFlowSnapshot lastSnapshot = serviceFacade.getLatestFlowSnapshot(flowId);
    return Response.status(Response.Status.OK).entity(lastSnapshot).build();
}
 
Example #27
Source File: StandardServiceFacade.java    From nifi-registry with Apache License 2.0 5 votes vote down vote up
@Override
public VersionedFlowSnapshot getLatestFlowSnapshot(final String bucketIdentifier, final String flowIdentifier) {
    authorizeBucketAccess(RequestAction.READ, bucketIdentifier);

    final VersionedFlowSnapshotMetadata latestMetadata = getLatestFlowSnapshotMetadata(bucketIdentifier, flowIdentifier);
    final VersionedFlowSnapshot lastSnapshot = getFlowSnapshot(bucketIdentifier, flowIdentifier, latestMetadata.getVersion());
    populateLinksAndPermissions(lastSnapshot);
    return lastSnapshot;
}
 
Example #28
Source File: StandardServiceFacade.java    From nifi-registry with Apache License 2.0 5 votes vote down vote up
@Override
public VersionedFlowSnapshot getFlowSnapshot(final String flowIdentifier, final Integer version) {
    final VersionedFlowSnapshotMetadata latestMetadata = registryService.getLatestFlowSnapshotMetadata(flowIdentifier);
    authorizeBucketAccess(RequestAction.READ, latestMetadata);

    final String bucketIdentifier = latestMetadata.getBucketIdentifier();
    final VersionedFlowSnapshot snapshot = registryService.getFlowSnapshot(bucketIdentifier, flowIdentifier, version);
    populateLinksAndPermissions(snapshot);
    return snapshot;
}
 
Example #29
Source File: StandardServiceFacade.java    From nifi-registry with Apache License 2.0 5 votes vote down vote up
@Override
public VersionedFlowSnapshot getFlowSnapshot(final String bucketIdentifier, final String flowIdentifier, final Integer version) {
    authorizeBucketAccess(RequestAction.READ, bucketIdentifier);

    final VersionedFlowSnapshot snapshot = registryService.getFlowSnapshot(bucketIdentifier, flowIdentifier, version);
    populateLinksAndPermissions(snapshot);
    return snapshot;
}
 
Example #30
Source File: DBFlowStorageIT.java    From nifi-registry with Apache License 2.0 5 votes vote down vote up
private VersionedFlowSnapshot createSnapshot(final Bucket bucket, final VersionedFlow flow, final int version, final String rootPgName) {
    final VersionedProcessGroup rootPg = new VersionedProcessGroup();
    rootPg.setName(rootPgName);

    final VersionedFlowSnapshotMetadata snapshotMetadata = new VersionedFlowSnapshotMetadata();
    snapshotMetadata.setBucketIdentifier(bucket.getIdentifier());
    snapshotMetadata.setFlowIdentifier(flow.getIdentifier());
    snapshotMetadata.setVersion(version);
    snapshotMetadata.setComments("comments");

    final VersionedFlowSnapshot snapshot = new VersionedFlowSnapshot();
    snapshot.setFlowContents(rootPg);
    snapshot.setSnapshotMetadata(snapshotMetadata);
    return snapshot;
}