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

The following examples show how to use org.apache.nifi.registry.flow.VersionedComponent. 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: RegistryService.java    From nifi-registry with Apache License 2.0 6 votes vote down vote up
/**
 * Group the differences in the comparison by component
 * @param flowDifferences The differences to group together by component
 * @return A set of componentDifferenceGroups where each entry contains a set of differences specific to that group
 */
private Set<ComponentDifferenceGroup> getStringComponentDifferenceGroupMap(Set<FlowDifference> flowDifferences) {
    Map<String, ComponentDifferenceGroup> differenceGroups = new HashMap<>();
    for (FlowDifference diff : flowDifferences) {
        ComponentDifferenceGroup group;
        // A component may only exist on only one version for new/removed components
        VersionedComponent component = ObjectUtils.firstNonNull(diff.getComponentA(), diff.getComponentB());
        if(differenceGroups.containsKey(component.getIdentifier())){
            group = differenceGroups.get(component.getIdentifier());
        }else{
            group = FlowMappings.map(component);
            differenceGroups.put(component.getIdentifier(), group);
        }
        group.getDifferences().add(FlowMappings.map(diff));
    }
    return differenceGroups.values().stream().collect(Collectors.toSet());
}
 
Example #2
Source File: FlowDifferenceFilters.java    From nifi with Apache License 2.0 6 votes vote down vote up
public static boolean isNewPropertyWithDefaultValue(final FlowDifference fd, final FlowManager flowManager) {
    if (fd.getDifferenceType() != DifferenceType.PROPERTY_ADDED) {
        return false;
    }

    final VersionedComponent componentB = fd.getComponentB();

    if (componentB instanceof InstantiatedVersionedProcessor) {
        final InstantiatedVersionedProcessor instantiatedProcessor = (InstantiatedVersionedProcessor) componentB;
        final ProcessorNode processorNode = flowManager.getProcessorNode(instantiatedProcessor.getInstanceId());
        return isNewPropertyWithDefaultValue(fd, processorNode);
    } else if (componentB instanceof InstantiatedVersionedControllerService) {
        final InstantiatedVersionedControllerService instantiatedControllerService = (InstantiatedVersionedControllerService) componentB;
        final ControllerServiceNode controllerService = flowManager.getControllerServiceNode(instantiatedControllerService.getInstanceId());
        return isNewPropertyWithDefaultValue(fd, controllerService);
    }

    return false;
}
 
Example #3
Source File: IntegrationTestUtils.java    From nifi-registry with Apache License 2.0 6 votes vote down vote up
private static void assertVersionedProcessGroupsEqual(VersionedProcessGroup expected, VersionedProcessGroup actual) {
    assertNotNull(actual);

    assertEquals(((VersionedComponent)expected), ((VersionedComponent)actual));

    // Poor man's set equality assertion as we are only checking the base type and not doing a recursive check
    // TODO, this would be a stronger assertion by replacing this with a true VersionedProcessGroup.equals() method that does a deep equality check
    assertSetsEqual(expected.getProcessGroups(), actual.getProcessGroups());
    assertSetsEqual(expected.getRemoteProcessGroups(), actual.getRemoteProcessGroups());
    assertSetsEqual(expected.getProcessors(), actual.getProcessors());
    assertSetsEqual(expected.getInputPorts(), actual.getInputPorts());
    assertSetsEqual(expected.getOutputPorts(), actual.getOutputPorts());
    assertSetsEqual(expected.getConnections(), actual.getConnections());
    assertSetsEqual(expected.getLabels(), actual.getLabels());
    assertSetsEqual(expected.getFunnels(), actual.getFunnels());
    assertSetsEqual(expected.getControllerServices(), actual.getControllerServices());
}
 
Example #4
Source File: StandardFlowComparator.java    From nifi-registry with Apache License 2.0 6 votes vote down vote up
private boolean compareComponents(final VersionedComponent componentA, final VersionedComponent componentB, final Set<FlowDifference> differences,
    final boolean compareName, final boolean comparePos, final boolean compareComments) {
    if (componentA == null) {
        differences.add(difference(DifferenceType.COMPONENT_ADDED, componentA, componentB, componentA, componentB));
        return true;
    }

    if (componentB == null) {
        differences.add(difference(DifferenceType.COMPONENT_REMOVED, componentA, componentB, componentA, componentB));
        return true;
    }

    if (compareComments) {
        addIfDifferent(differences, DifferenceType.COMMENTS_CHANGED, componentA, componentB, VersionedComponent::getComments, false);
    }

    if (compareName) {
        addIfDifferent(differences, DifferenceType.NAME_CHANGED, componentA, componentB, VersionedComponent::getName);
    }

    if (comparePos) {
        addIfDifferent(differences, DifferenceType.POSITION_CHANGED, componentA, componentB, VersionedComponent::getPosition);
    }

    return false;
}
 
Example #5
Source File: FlowMappings.java    From nifi-registry with Apache License 2.0 5 votes vote down vote up
public static ComponentDifferenceGroup map(VersionedComponent versionedComponent){
    ComponentDifferenceGroup grouping = new ComponentDifferenceGroup();
    grouping.setComponentId(versionedComponent.getIdentifier());
    grouping.setComponentName(versionedComponent.getName());
    grouping.setProcessGroupId(versionedComponent.getGroupIdentifier());
    grouping.setComponentType(versionedComponent.getComponentType().getTypeName());
    return grouping;
}
 
Example #6
Source File: FlowDifferenceFilters.java    From nifi with Apache License 2.0 5 votes vote down vote up
public static boolean isIgnorableVersionedFlowCoordinateChange(final FlowDifference fd) {
    if (fd.getDifferenceType() == DifferenceType.VERSIONED_FLOW_COORDINATES_CHANGED) {
        final VersionedComponent componentA = fd.getComponentA();
        final VersionedComponent componentB = fd.getComponentB();

        if (componentA instanceof VersionedProcessGroup && componentB instanceof VersionedProcessGroup) {
            final VersionedProcessGroup versionedProcessGroupA = (VersionedProcessGroup) componentA;
            final VersionedProcessGroup versionedProcessGroupB = (VersionedProcessGroup) componentB;

            final VersionedFlowCoordinates coordinatesA = versionedProcessGroupA.getVersionedFlowCoordinates();
            final VersionedFlowCoordinates coordinatesB = versionedProcessGroupB.getVersionedFlowCoordinates();

            if (coordinatesA != null && coordinatesB != null) {
                String registryUrlA = coordinatesA.getRegistryUrl();
                String registryUrlB = coordinatesB.getRegistryUrl();

                if (registryUrlA != null && registryUrlB != null && !registryUrlA.equals(registryUrlB)) {
                    if (registryUrlA.endsWith("/")) {
                        registryUrlA = registryUrlA.substring(0, registryUrlA.length() - 1);
                    }

                    if (registryUrlB.endsWith("/")) {
                        registryUrlB = registryUrlB.substring(0, registryUrlB.length() - 1);
                    }

                    if (registryUrlA.equals(registryUrlB)) {
                        return true;
                    }
                }
            }
        }
    }

    return false;
}
 
Example #7
Source File: FlowDifferenceFilters.java    From nifi with Apache License 2.0 5 votes vote down vote up
public static boolean isAddedOrRemovedRemotePort(final FlowDifference fd) {
    if (fd.getDifferenceType() == DifferenceType.COMPONENT_ADDED || fd.getDifferenceType() == DifferenceType.COMPONENT_REMOVED) {
        VersionedComponent component = fd.getComponentA();
        if (component == null || fd.getComponentB() instanceof InstantiatedVersionedComponent) {
            component = fd.getComponentB();
        }

        if (component.getComponentType() == ComponentType.REMOTE_INPUT_PORT
                || component.getComponentType() == ComponentType.REMOTE_OUTPUT_PORT) {
            return true;
        }
    }

    return false;
}
 
Example #8
Source File: FlowDifferenceFilters.java    From nifi with Apache License 2.0 5 votes vote down vote up
public static boolean isPublicPortNameChange(final FlowDifference fd) {
    final VersionedComponent versionedComponent = fd.getComponentA();
    if (fd.getDifferenceType() == DifferenceType.NAME_CHANGED && versionedComponent instanceof VersionedPort) {
        final VersionedPort versionedPort = (VersionedPort) versionedComponent;
        if (versionedPort.isAllowRemoteAccess()) {
            return true;
        }
    }

    return false;
}
 
Example #9
Source File: StandardFlowDifference.java    From nifi-registry with Apache License 2.0 5 votes vote down vote up
public StandardFlowDifference(final DifferenceType type, final VersionedComponent componentA, final VersionedComponent componentB, final String fieldName,
        final Object valueA, final Object valueB, final String description) {
    this.type = type;
    this.componentA = componentA;
    this.componentB = componentB;
    this.fieldName = Optional.ofNullable(fieldName);
    this.valueA = valueA;
    this.valueB = valueB;
    this.description = description;
}
 
Example #10
Source File: StandardFlowComparator.java    From nifi-registry with Apache License 2.0 5 votes vote down vote up
private <T extends VersionedComponent> void addIfDifferent(final Set<FlowDifference> differences, final DifferenceType type, final T componentA, final T componentB,
    final Function<T, Object> transform, final boolean differentiateNullAndEmptyString, final Object defaultValue) {

    Object valueA = transform.apply(componentA);
    if (valueA == null) {
        valueA = defaultValue;
    }

    Object valueB = transform.apply(componentB);
    if (valueB == null) {
        valueB = defaultValue;
    }

    if (Objects.equals(valueA, valueB)) {
        return;
    }

    // We don't want to disambiguate between an empty collection and null.
    if ((valueA == null || valueA instanceof Collection) && (valueB == null || valueB instanceof Collection) && isEmpty((Collection<?>) valueA) && isEmpty((Collection<?>) valueB)) {
        return;
    }

    if (!differentiateNullAndEmptyString && isEmptyString(valueA) && isEmptyString(valueB)) {
        return;
    }

    differences.add(difference(type, componentA, componentB, valueA, valueB));
}
 
Example #11
Source File: FlowMappings.java    From nifi-registry with Apache License 2.0 5 votes vote down vote up
private static String getValueDescription(Object valueA){
    if(valueA instanceof VersionedComponent){
        return ((VersionedComponent) valueA).getIdentifier();
    }
    if(valueA!= null){
        return valueA.toString();
    }
    return null;
}
 
Example #12
Source File: IntegrationTestUtils.java    From nifi-registry with Apache License 2.0 5 votes vote down vote up
private static void assertSetsEqual(Set<? extends VersionedComponent> expected, Set<? extends VersionedComponent> actual) {
    if (expected != null) {
        assertNotNull(actual);
        assertEquals(expected.size(), actual.size());
        assertTrue(actual.containsAll(expected));
    }
}
 
Example #13
Source File: StandardFlowComparator.java    From nifi-registry with Apache License 2.0 4 votes vote down vote up
private FlowDifference difference(final DifferenceType type, final VersionedComponent componentA, final VersionedComponent componentB,
        final Object valueA, final Object valueB) {

    final String description = differenceDescriptor.describeDifference(type, flowA.getName(), flowB.getName(), componentA, componentB, null, valueA, valueB);
    return new StandardFlowDifference(type, componentA, componentB, valueA, valueB, description);
}
 
Example #14
Source File: StandardFlowComparator.java    From nifi-registry with Apache License 2.0 4 votes vote down vote up
private boolean compareComponents(final VersionedComponent componentA, final VersionedComponent componentB, final Set<FlowDifference> differences) {
    return compareComponents(componentA, componentB, differences, true, true, true);
}
 
Example #15
Source File: StandardFlowComparator.java    From nifi-registry with Apache License 2.0 4 votes vote down vote up
private <T extends VersionedComponent> Map<String, T> byId(final Set<T> components) {
    return components.stream().collect(Collectors.toMap(VersionedComponent::getIdentifier, Function.identity()));
}
 
Example #16
Source File: StandardFlowDifference.java    From nifi-registry with Apache License 2.0 4 votes vote down vote up
@Override
public VersionedComponent getComponentB() {
    return componentB;
}
 
Example #17
Source File: StandardFlowDifference.java    From nifi-registry with Apache License 2.0 4 votes vote down vote up
@Override
public VersionedComponent getComponentA() {
    return componentA;
}
 
Example #18
Source File: StandardFlowComparator.java    From nifi-registry with Apache License 2.0 4 votes vote down vote up
private <T extends VersionedComponent> void addIfDifferent(final Set<FlowDifference> differences, final DifferenceType type, final T componentA, final T componentB,
    final Function<T, Object> transform) {

    addIfDifferent(differences, type, componentA, componentB, transform, true);
}
 
Example #19
Source File: StandardFlowDifference.java    From nifi-registry with Apache License 2.0 4 votes vote down vote up
public StandardFlowDifference(final DifferenceType type, final VersionedComponent componentA, final VersionedComponent componentB, final Object valueA, final Object valueB,
        final String description) {
    this(type, componentA, componentB, null, valueA, valueB, description);
}
 
Example #20
Source File: EvolvingDifferenceDescriptor.java    From nifi-registry with Apache License 2.0 4 votes vote down vote up
@Override
public String describeDifference(final DifferenceType type, final String flowAName, final String flowBName, final VersionedComponent componentA,
    final VersionedComponent componentB, final String fieldName, final Object valueA, final Object valueB) {

    final String description;
    switch (type) {
        case COMPONENT_ADDED:
            description = String.format("%s with ID %s was added to flow", componentB.getComponentType().getTypeName(), componentB.getIdentifier());
            break;
        case COMPONENT_REMOVED:
            description = String.format("%s with ID %s was removed from flow", componentA.getComponentType().getTypeName(), componentA.getIdentifier());
            break;
        case SCHEDULED_STATE_CHANGED:
            if (ScheduledState.DISABLED.equals(valueA)) {
                description = String.format("%s was enabled", componentA.getComponentType().getTypeName());
            } else {
                description = String.format("%s was disabled", componentA.getComponentType().getTypeName());
            }
            break;
        case PROPERTY_ADDED:
            description = String.format("Property '%s' was added to %s with ID %s", fieldName, componentB.getComponentType().getTypeName(), componentB.getIdentifier());
            break;
        case PROPERTY_REMOVED:
            description = String.format("Property '%s' was removed from %s with ID %s", fieldName, componentA.getComponentType().getTypeName(), componentA.getIdentifier());
            break;
        case PROPERTY_PARAMETERIZED:
            description = String.format("Property '%s' was parameterized", fieldName);
            break;
        case PROPERTY_PARAMETERIZATION_REMOVED:
            description = String.format("Property '%s' is no longer a parameter reference", fieldName);
            break;
        case VARIABLE_ADDED:
            description = String.format("Variable '%s' was added to Process Group with ID %s", fieldName, componentB.getIdentifier());
            break;
        case VARIABLE_REMOVED:
            description = String.format("Variable '%s' was removed from Process Group with ID %s", fieldName, componentA.getIdentifier());
            break;
        default:
            description = String.format("%s for %s with ID %s from '%s' to '%s'",
                type.getDescription(), componentA.getComponentType().getTypeName(), componentA.getIdentifier(), valueA, valueB);
            break;
    }

    return description;
}
 
Example #21
Source File: StaticDifferenceDescriptor.java    From nifi-registry with Apache License 2.0 4 votes vote down vote up
@Override
public String describeDifference(final DifferenceType type, final String flowAName, final String flowBName, final VersionedComponent componentA,
    final VersionedComponent componentB, final String fieldName, final Object valueA, final Object valueB) {

    final String description;
    switch (type) {
        case COMPONENT_ADDED:
            description = String.format("%s with ID %s exists in %s but not in %s",
                componentB.getComponentType().getTypeName(), componentB.getIdentifier(), flowBName, flowAName);
            break;
        case COMPONENT_REMOVED:
            description = String.format("%s with ID %s exists in %s but not in %s",
                componentA.getComponentType().getTypeName(), componentA.getIdentifier(), flowAName, flowBName);
            break;
        case PROPERTY_ADDED:
            description = String.format("Property '%s' exists for %s with ID %s in %s but not in %s",
                fieldName, componentB.getComponentType().getTypeName(), componentB.getIdentifier(), flowBName, flowAName);
            break;
        case PROPERTY_REMOVED:
            description = String.format("Property '%s' exists for %s with ID %s in %s but not in %s",
                fieldName, componentA.getComponentType().getTypeName(), componentA.getIdentifier(), flowAName, flowBName);
            break;
        case PROPERTY_PARAMETERIZED:
            description = String.format("Property '%s' is a parameter reference in %s but not in %s", fieldName, flowAName, flowBName);
            break;
        case PROPERTY_PARAMETERIZATION_REMOVED:
            description = String.format("Property '%s' is a parameter reference in %s but not in %s", fieldName, flowBName, flowAName);
            break;
        case SCHEDULED_STATE_CHANGED:
            if (ScheduledState.DISABLED.equals(valueA)) {
                description = String.format("%s is disabled in %s but enabled in %s", componentA.getComponentType().getTypeName(), flowAName, flowBName);
            } else {
                description = String.format("%s is enabled in %s but disabled in %s", componentA.getComponentType().getTypeName(), flowAName, flowBName);
            }
            break;
        case VARIABLE_ADDED:
            description = String.format("Variable '%s' exists for Process Group with ID %s in %s but not in %s",
                fieldName, componentB.getIdentifier(), flowBName, flowAName);
            break;
        case VARIABLE_REMOVED:
            description = String.format("Variable '%s' exists for Process Group with ID %s in %s but not in %s",
                fieldName, componentA.getIdentifier(), flowAName, flowBName);
            break;
        case VERSIONED_FLOW_COORDINATES_CHANGED:
            if (valueA instanceof VersionedFlowCoordinates && valueB instanceof VersionedFlowCoordinates) {
                final VersionedFlowCoordinates coordinatesA = (VersionedFlowCoordinates) valueA;
                final VersionedFlowCoordinates coordinatesB = (VersionedFlowCoordinates) valueB;

                // If the two vary only by version, then use a more concise message. If anything else is different, then use a fully explanation.
                if (Objects.equals(coordinatesA.getRegistryUrl(), coordinatesB.getRegistryUrl()) && Objects.equals(coordinatesA.getBucketId(), coordinatesB.getBucketId())
                        && Objects.equals(coordinatesA.getFlowId(), coordinatesB.getFlowId()) && coordinatesA.getVersion() != coordinatesB.getVersion()) {

                    description = String.format("Flow Version is %s in %s but %s in %s", coordinatesA.getVersion(), flowAName, coordinatesB.getVersion(), flowBName);
                    break;
                }
            }

            description = String.format("%s for %s with ID %s; flow '%s' has value %s; flow '%s' has value %s",
                type.getDescription(), componentA.getComponentType().getTypeName(), componentA.getIdentifier(),
                flowAName, valueA, flowBName, valueB);
            break;
        default:
            description = String.format("%s for %s with ID %s; flow '%s' has value %s; flow '%s' has value %s",
                type.getDescription(), componentA.getComponentType().getTypeName(), componentA.getIdentifier(),
                flowAName, valueA, flowBName, valueB);
            break;
    }

    return description;
}
 
Example #22
Source File: ConciseEvolvingDifferenceDescriptor.java    From nifi-registry with Apache License 2.0 4 votes vote down vote up
@Override
public String describeDifference(final DifferenceType type, final String flowAName, final String flowBName, final VersionedComponent componentA,
    final VersionedComponent componentB, final String fieldName, final Object valueA, final Object valueB) {

    final String description;
    switch (type) {
        case COMPONENT_ADDED:
            description = String.format("%s was added", componentB.getComponentType().getTypeName());
            break;
        case COMPONENT_REMOVED:
            description = String.format("%s was removed", componentA.getComponentType().getTypeName());
            break;
        case SCHEDULED_STATE_CHANGED:
            if (ScheduledState.DISABLED.equals(valueA)) {
                description = String.format("%s was enabled", componentA.getComponentType().getTypeName());
            } else {
                description = String.format("%s was disabled", componentA.getComponentType().getTypeName());
            }
            break;
        case PROPERTY_ADDED:
            description = String.format("Property '%s' was added", fieldName);
            break;
        case PROPERTY_REMOVED:
            description = String.format("Property '%s' was removed", fieldName);
            break;
        case PROPERTY_PARAMETERIZED:
            description = String.format("Property '%s' was parameterized", fieldName);
            break;
        case PROPERTY_PARAMETERIZATION_REMOVED:
            description = String.format("Property '%s' is no longer a parameter reference", fieldName);
            break;
        case VARIABLE_ADDED:
            description = String.format("Variable '%s' was added", fieldName);
            break;
        case VARIABLE_REMOVED:
            description = String.format("Variable '%s' was removed", fieldName);
            break;
        case POSITION_CHANGED:
            description = "Position was changed";
            break;
        case BENDPOINTS_CHANGED:
            description = "Connection Bendpoints changed";
            break;
        case VERSIONED_FLOW_COORDINATES_CHANGED:
            if (valueA instanceof VersionedFlowCoordinates && valueB instanceof VersionedFlowCoordinates) {
                final VersionedFlowCoordinates coordinatesA = (VersionedFlowCoordinates) valueA;
                final VersionedFlowCoordinates coordinatesB = (VersionedFlowCoordinates) valueB;

                // If the two vary only by version, then use a more concise message. If anything else is different, then use a fully explanation.
                if (Objects.equals(coordinatesA.getRegistryUrl(), coordinatesB.getRegistryUrl()) && Objects.equals(coordinatesA.getBucketId(), coordinatesB.getBucketId())
                        && Objects.equals(coordinatesA.getFlowId(), coordinatesB.getFlowId()) && coordinatesA.getVersion() != coordinatesB.getVersion()) {

                    description = String.format("Flow Version changed from %s to %s", coordinatesA.getVersion(), coordinatesB.getVersion());
                    break;
                }
            }

            description = String.format("From '%s' to '%s'", valueA, valueB);
            break;
        default:
            description = String.format("From '%s' to '%s'", valueA, valueB);
            break;
    }

    return description;
}
 
Example #23
Source File: StandardFlowComparator.java    From nifi-registry with Apache License 2.0 4 votes vote down vote up
private FlowDifference difference(final DifferenceType type, final VersionedComponent componentA, final VersionedComponent componentB, final String fieldName, final String prettyPrintFieldName,
                                  final Object valueA, final Object valueB) {

    final String description = differenceDescriptor.describeDifference(type, flowA.getName(), flowB.getName(), componentA, componentB, prettyPrintFieldName, valueA, valueB);
    return new StandardFlowDifference(type, componentA, componentB, fieldName, valueA, valueB, description);
}
 
Example #24
Source File: StandardFlowComparator.java    From nifi-registry with Apache License 2.0 4 votes vote down vote up
private <T extends VersionedComponent> void addIfDifferent(final Set<FlowDifference> differences, final DifferenceType type, final T componentA, final T componentB,
                                                           final Function<T, Object> transform, final boolean differentiateNullAndEmptyString) {
    addIfDifferent(differences, type, componentA, componentB, transform, differentiateNullAndEmptyString, null);
}
 
Example #25
Source File: DifferenceDescriptor.java    From nifi-registry with Apache License 2.0 2 votes vote down vote up
/**
 * Describes a difference between two flows
 *
 * @param type the difference
 * @param componentA the component in "Flow A"
 * @param componentB the component in "Flow B"
 * @param fieldName the name of the field that changed, or <code>null</code> if the field name does not apply for the difference type
 * @param valueA the value being compared from "Flow A"
 * @param valueB the value being compared from "Flow B"
 * @return a human-readable description of how the flows differ
 */
String describeDifference(DifferenceType type, String flowAName, String flowBName, VersionedComponent componentA, VersionedComponent componentB, String fieldName,
    Object valueA, Object valueB);
 
Example #26
Source File: FlowDifference.java    From nifi-registry with Apache License 2.0 votes vote down vote up
VersionedComponent getComponentB(); 
Example #27
Source File: FlowDifference.java    From nifi-registry with Apache License 2.0 votes vote down vote up
VersionedComponent getComponentA();