Search in sources :

Example 11 with VersionedProcessGroup

use of org.apache.nifi.registry.flow.VersionedProcessGroup in project nifi-minifi by apache.

the class NiFiRegConfigSchemaFunction method apply.

@Override
public ConfigSchema apply(final VersionedFlowSnapshot versionedFlowSnapshot) {
    Map<String, Object> map = new HashMap<>();
    map.put(CommonPropertyKeys.FLOW_CONTROLLER_PROPS_KEY, flowControllerSchemaFunction.apply(versionedFlowSnapshot).toMap());
    VersionedProcessGroup versionedProcessGroup = versionedFlowSnapshot.getFlowContents();
    addVersionedProcessGroup(map, versionedProcessGroup);
    return new ConfigSchema(map);
}
Also used : HashMap(java.util.HashMap) VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup) ConfigSchema(org.apache.nifi.minifi.commons.schema.ConfigSchema)

Example 12 with VersionedProcessGroup

use of org.apache.nifi.registry.flow.VersionedProcessGroup in project nifi-minifi by apache.

the class VersionedProcessGroupEnricher method enrich.

public void enrich(final VersionedProcessGroup versionedProcessGroup) {
    List<VersionedProcessGroup> allVersionedProcessGroups = getAllVersionedProcessGroups(versionedProcessGroup);
    Set<VersionedRemoteProcessGroup> remoteProcessGroups = getAll(allVersionedProcessGroups, VersionedProcessGroup::getRemoteProcessGroups).collect(Collectors.toSet());
    Map<String, String> connectableNameMap = getAll(allVersionedProcessGroups, VersionedProcessGroup::getProcessors).collect(Collectors.toMap(VersionedComponent::getIdentifier, VersionedComponent::getName));
    Map<String, String> rpgIdToTargetIdMap = new HashMap<>();
    for (VersionedRemoteProcessGroup remoteProcessGroup : remoteProcessGroups) {
        final Set<VersionedRemoteGroupPort> rpgInputPorts = nullToEmpty(remoteProcessGroup.getInputPorts());
        final Set<VersionedRemoteGroupPort> rpgOutputPorts = nullToEmpty(remoteProcessGroup.getOutputPorts());
        // Map all port DTOs to their respective targetIds
        rpgIdToTargetIdMap.putAll(Stream.concat(rpgInputPorts.stream(), rpgOutputPorts.stream()).collect(Collectors.toMap(VersionedRemoteGroupPort::getIdentifier, VersionedRemoteGroupPort::getTargetId)));
        addConnectables(connectableNameMap, rpgInputPorts, VersionedRemoteGroupPort::getIdentifier, VersionedRemoteGroupPort::getIdentifier);
        addConnectables(connectableNameMap, rpgOutputPorts, VersionedRemoteGroupPort::getIdentifier, VersionedRemoteGroupPort::getIdentifier);
    }
    addConnectables(connectableNameMap, getAll(allVersionedProcessGroups, VersionedProcessGroup::getInputPorts).collect(Collectors.toList()), VersionedPort::getIdentifier, VersionedPort::getName);
    addConnectables(connectableNameMap, getAll(allVersionedProcessGroups, VersionedProcessGroup::getOutputPorts).collect(Collectors.toList()), VersionedPort::getIdentifier, VersionedPort::getName);
    final Set<VersionedConnection> connections = getAll(allVersionedProcessGroups, VersionedProcessGroup::getConnections).collect(Collectors.toSet());
    // Enrich connection endpoints using known names and overriding with targetIds for remote ports
    for (VersionedConnection connection : connections) {
        setName(connectableNameMap, connection.getSource(), rpgIdToTargetIdMap);
        setName(connectableNameMap, connection.getDestination(), rpgIdToTargetIdMap);
    }
    // Override any ids that are for Remote Ports to use their target Ids where available
    connections.stream().flatMap(connectionDTO -> Stream.of(connectionDTO.getSource(), connectionDTO.getDestination())).filter(connectable -> (connectable.getType() == ConnectableComponentType.REMOTE_OUTPUT_PORT || connectable.getType() == ConnectableComponentType.REMOTE_INPUT_PORT)).forEach(connectable -> connectable.setId(Optional.ofNullable(rpgIdToTargetIdMap.get(connectable.getId())).orElse(connectable.getId())));
    // Establish unique names for connections
    for (VersionedConnection connection : connections) {
        if (StringUtil.isNullOrEmpty(connection.getName())) {
            StringBuilder name = new StringBuilder();
            ConnectableComponent connectionSource = connection.getSource();
            name.append(determineValueForConnectable(connectionSource, rpgIdToTargetIdMap));
            name.append("/");
            if (connection.getSelectedRelationships() != null && connection.getSelectedRelationships().size() > 0) {
                name.append(connection.getSelectedRelationships().iterator().next());
            }
            name.append("/");
            ConnectableComponent connectionDestination = connection.getDestination();
            name.append(determineValueForConnectable(connectionDestination, rpgIdToTargetIdMap));
            connection.setName(name.toString());
        }
    }
    nullToEmpty(versionedProcessGroup.getProcessGroups()).stream().forEach(pg -> enrich(pg));
}
Also used : ConnectableComponent(org.apache.nifi.registry.flow.ConnectableComponent) Collection(java.util.Collection) Set(java.util.Set) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) VersionedRemoteGroupPort(org.apache.nifi.registry.flow.VersionedRemoteGroupPort) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) StringUtil(org.apache.nifi.minifi.commons.schema.common.StringUtil) VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup) Map(java.util.Map) VersionedPort(org.apache.nifi.registry.flow.VersionedPort) VersionedRemoteProcessGroup(org.apache.nifi.registry.flow.VersionedRemoteProcessGroup) Optional(java.util.Optional) CollectionUtil.nullToEmpty(org.apache.nifi.minifi.commons.schema.common.CollectionUtil.nullToEmpty) VersionedComponent(org.apache.nifi.registry.flow.VersionedComponent) VersionedConnection(org.apache.nifi.registry.flow.VersionedConnection) ConnectableComponentType(org.apache.nifi.registry.flow.ConnectableComponentType) HashMap(java.util.HashMap) VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup) VersionedRemoteGroupPort(org.apache.nifi.registry.flow.VersionedRemoteGroupPort) VersionedPort(org.apache.nifi.registry.flow.VersionedPort) ConnectableComponent(org.apache.nifi.registry.flow.ConnectableComponent) VersionedRemoteProcessGroup(org.apache.nifi.registry.flow.VersionedRemoteProcessGroup) VersionedConnection(org.apache.nifi.registry.flow.VersionedConnection)

Example 13 with VersionedProcessGroup

use of org.apache.nifi.registry.flow.VersionedProcessGroup in project nifi-registry by apache.

the class StandardFlowComparator method compare.

@Override
public FlowComparison compare() {
    final VersionedProcessGroup groupA = flowA.getContents();
    final VersionedProcessGroup groupB = flowB.getContents();
    final Set<FlowDifference> differences = compare(groupA, groupB);
    return new StandardFlowComparison(flowA, flowB, differences);
}
Also used : VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup)

Example 14 with VersionedProcessGroup

use of org.apache.nifi.registry.flow.VersionedProcessGroup in project nifi-registry by apache.

the class TestRegistryService method testGetDiffReturnsRemovedComponentChanges.

// -----------------Test Flow Diff Service Method---------------------
@Test
public void testGetDiffReturnsRemovedComponentChanges() {
    when(flowPersistenceProvider.getFlowContent(anyString(), anyString(), anyInt())).thenReturn(new byte[10], new byte[10]);
    final VersionedProcessGroup pgA = createVersionedProcessGroupA();
    final VersionedProcessGroup pgB = createVersionedProcessGroupB();
    when(snapshotSerializer.deserialize(any())).thenReturn(pgA, pgB);
    final VersionedFlowDifference diff = registryService.getFlowDiff("bucketIdentifier", "flowIdentifier", 1, 2);
    assertNotNull(diff);
    Optional<ComponentDifferenceGroup> removedComponent = diff.getComponentDifferenceGroups().stream().filter(p -> p.getComponentId().equals("ID-pg1")).findFirst();
    assertTrue(removedComponent.isPresent());
    assertTrue(removedComponent.get().getDifferences().iterator().next().getDifferenceType().equals("COMPONENT_REMOVED"));
}
Also used : Arrays(java.util.Arrays) SortedSet(java.util.SortedSet) Date(java.util.Date) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) FlowEntity(org.apache.nifi.registry.db.entity.FlowEntity) VersionedFlowSnapshotMetadata(org.apache.nifi.registry.flow.VersionedFlowSnapshotMetadata) VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup) Mockito.doAnswer(org.mockito.Mockito.doAnswer) FlowSnapshotEntity(org.apache.nifi.registry.db.entity.FlowSnapshotEntity) Validator(javax.validation.Validator) Set(java.util.Set) Serializer(org.apache.nifi.registry.serialization.Serializer) BucketEntity(org.apache.nifi.registry.db.entity.BucketEntity) List(java.util.List) VersionedFlowDifference(org.apache.nifi.registry.diff.VersionedFlowDifference) Optional(java.util.Optional) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Bucket(org.apache.nifi.registry.bucket.Bucket) ValidatorFactory(javax.validation.ValidatorFactory) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Answer(org.mockito.stubbing.Answer) ComponentDifference(org.apache.nifi.registry.diff.ComponentDifference) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ResourceNotFoundException(org.apache.nifi.registry.exception.ResourceNotFoundException) Validation(javax.validation.Validation) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) Before(org.junit.Before) OutputStream(java.io.OutputStream) VersionedProcessor(org.apache.nifi.registry.flow.VersionedProcessor) ComponentDifferenceGroup(org.apache.nifi.registry.diff.ComponentDifferenceGroup) VersionedProcessGroupSerializer(org.apache.nifi.registry.serialization.VersionedProcessGroupSerializer) Assert.assertNotNull(org.junit.Assert.assertNotNull) FlowPersistenceProvider(org.apache.nifi.registry.flow.FlowPersistenceProvider) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) VersionedFlowSnapshot(org.apache.nifi.registry.flow.VersionedFlowSnapshot) VersionedFlow(org.apache.nifi.registry.flow.VersionedFlow) Mockito.verify(org.mockito.Mockito.verify) ConstraintViolationException(javax.validation.ConstraintViolationException) Assert(org.junit.Assert) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) InputStream(java.io.InputStream) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) VersionedFlowDifference(org.apache.nifi.registry.diff.VersionedFlowDifference) VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup) ComponentDifferenceGroup(org.apache.nifi.registry.diff.ComponentDifferenceGroup) Test(org.junit.Test)

Example 15 with VersionedProcessGroup

use of org.apache.nifi.registry.flow.VersionedProcessGroup in project nifi-registry by apache.

the class TestRegistryService method testGetDiffReturnsChangesInChronologicalOrder.

@Test
public void testGetDiffReturnsChangesInChronologicalOrder() {
    when(flowPersistenceProvider.getFlowContent(anyString(), anyString(), anyInt())).thenReturn(new byte[10], new byte[10]);
    final VersionedProcessGroup pgA = createVersionedProcessGroupA();
    final VersionedProcessGroup pgB = createVersionedProcessGroupB();
    when(snapshotSerializer.deserialize(any())).thenReturn(pgA, pgB);
    // getFlowDiff orders the changes in ascending order of version number regardless of param order
    final VersionedFlowDifference diff = registryService.getFlowDiff("bucketIdentifier", "flowIdentifier", 2, 1);
    assertNotNull(diff);
    Optional<ComponentDifferenceGroup> nameChangedComponent = diff.getComponentDifferenceGroups().stream().filter(p -> p.getComponentId().equals("ProcessorFirstV1")).findFirst();
    assertTrue(nameChangedComponent.isPresent());
    ComponentDifference nameChangeDifference = nameChangedComponent.get().getDifferences().stream().filter(d -> d.getDifferenceType().equals("NAME_CHANGED")).findFirst().get();
    assertEquals("ProcessorFirstV1", nameChangeDifference.getValueA());
    assertEquals("ProcessorFirstV2", nameChangeDifference.getValueB());
}
Also used : Arrays(java.util.Arrays) SortedSet(java.util.SortedSet) Date(java.util.Date) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) FlowEntity(org.apache.nifi.registry.db.entity.FlowEntity) VersionedFlowSnapshotMetadata(org.apache.nifi.registry.flow.VersionedFlowSnapshotMetadata) VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup) Mockito.doAnswer(org.mockito.Mockito.doAnswer) FlowSnapshotEntity(org.apache.nifi.registry.db.entity.FlowSnapshotEntity) Validator(javax.validation.Validator) Set(java.util.Set) Serializer(org.apache.nifi.registry.serialization.Serializer) BucketEntity(org.apache.nifi.registry.db.entity.BucketEntity) List(java.util.List) VersionedFlowDifference(org.apache.nifi.registry.diff.VersionedFlowDifference) Optional(java.util.Optional) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Bucket(org.apache.nifi.registry.bucket.Bucket) ValidatorFactory(javax.validation.ValidatorFactory) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Answer(org.mockito.stubbing.Answer) ComponentDifference(org.apache.nifi.registry.diff.ComponentDifference) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ResourceNotFoundException(org.apache.nifi.registry.exception.ResourceNotFoundException) Validation(javax.validation.Validation) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) Before(org.junit.Before) OutputStream(java.io.OutputStream) VersionedProcessor(org.apache.nifi.registry.flow.VersionedProcessor) ComponentDifferenceGroup(org.apache.nifi.registry.diff.ComponentDifferenceGroup) VersionedProcessGroupSerializer(org.apache.nifi.registry.serialization.VersionedProcessGroupSerializer) Assert.assertNotNull(org.junit.Assert.assertNotNull) FlowPersistenceProvider(org.apache.nifi.registry.flow.FlowPersistenceProvider) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) VersionedFlowSnapshot(org.apache.nifi.registry.flow.VersionedFlowSnapshot) VersionedFlow(org.apache.nifi.registry.flow.VersionedFlow) Mockito.verify(org.mockito.Mockito.verify) ConstraintViolationException(javax.validation.ConstraintViolationException) Assert(org.junit.Assert) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) InputStream(java.io.InputStream) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ComponentDifference(org.apache.nifi.registry.diff.ComponentDifference) VersionedFlowDifference(org.apache.nifi.registry.diff.VersionedFlowDifference) VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup) ComponentDifferenceGroup(org.apache.nifi.registry.diff.ComponentDifferenceGroup) Test(org.junit.Test)

Aggregations

VersionedProcessGroup (org.apache.nifi.registry.flow.VersionedProcessGroup)36 VersionedFlowSnapshot (org.apache.nifi.registry.flow.VersionedFlowSnapshot)17 VersionedFlow (org.apache.nifi.registry.flow.VersionedFlow)13 VersionedFlowSnapshotMetadata (org.apache.nifi.registry.flow.VersionedFlowSnapshotMetadata)12 HashMap (java.util.HashMap)11 IOException (java.io.IOException)10 HashSet (java.util.HashSet)10 Set (java.util.Set)9 Bucket (org.apache.nifi.registry.bucket.Bucket)9 LinkedHashSet (java.util.LinkedHashSet)8 Collections (java.util.Collections)7 VersionedProcessor (org.apache.nifi.registry.flow.VersionedProcessor)7 ArrayList (java.util.ArrayList)6 Map (java.util.Map)6 Collectors (java.util.stream.Collectors)6 NiFiRegistryException (org.apache.nifi.registry.client.NiFiRegistryException)6 List (java.util.List)5 Optional (java.util.Optional)5 FlowRegistry (org.apache.nifi.registry.flow.FlowRegistry)5 StandardVersionControlInformation (org.apache.nifi.registry.flow.StandardVersionControlInformation)5