Search in sources :

Example 11 with Position

use of org.apache.nifi.connectable.Position in project nifi by apache.

the class StandardProcessGroup method updateRemoteProcessGroup.

private void updateRemoteProcessGroup(final RemoteProcessGroup rpg, final VersionedRemoteProcessGroup proposed, final String componentIdSeed) {
    rpg.setComments(proposed.getComments());
    rpg.setCommunicationsTimeout(proposed.getCommunicationsTimeout());
    rpg.setInputPorts(proposed.getInputPorts() == null ? Collections.emptySet() : proposed.getInputPorts().stream().map(port -> createPortDescriptor(port, componentIdSeed, rpg.getIdentifier())).collect(Collectors.toSet()), false);
    rpg.setName(proposed.getName());
    rpg.setNetworkInterface(proposed.getLocalNetworkInterface());
    rpg.setOutputPorts(proposed.getOutputPorts() == null ? Collections.emptySet() : proposed.getOutputPorts().stream().map(port -> createPortDescriptor(port, componentIdSeed, rpg.getIdentifier())).collect(Collectors.toSet()), false);
    rpg.setPosition(new Position(proposed.getPosition().getX(), proposed.getPosition().getY()));
    rpg.setProxyHost(proposed.getProxyHost());
    rpg.setProxyPort(proposed.getProxyPort());
    rpg.setProxyUser(proposed.getProxyUser());
    rpg.setTransportProtocol(SiteToSiteTransportProtocol.valueOf(proposed.getTransportProtocol()));
    rpg.setYieldDuration(proposed.getYieldDuration());
}
Also used : OnRemoved(org.apache.nifi.annotation.lifecycle.OnRemoved) ConfigurationContext(org.apache.nifi.controller.ConfigurationContext) Size(org.apache.nifi.connectable.Size) FlowComparison(org.apache.nifi.registry.flow.diff.FlowComparison) StringUtils(org.apache.commons.lang3.StringUtils) ReflectionUtils(org.apache.nifi.util.ReflectionUtils) PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) SecureRandom(java.security.SecureRandom) NiFiRegistryException(org.apache.nifi.registry.client.NiFiRegistryException) ComponentType(org.apache.nifi.registry.flow.ComponentType) VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup) SnippetUtils(org.apache.nifi.util.SnippetUtils) Map(java.util.Map) HashCodeBuilder(org.apache.commons.lang3.builder.HashCodeBuilder) RootGroupPort(org.apache.nifi.remote.RootGroupPort) Connectable(org.apache.nifi.connectable.Connectable) Connection(org.apache.nifi.connectable.Connection) Bundle(org.apache.nifi.registry.flow.Bundle) FlowFilePrioritizer(org.apache.nifi.flowfile.FlowFilePrioritizer) FlowDifferenceFilters(org.apache.nifi.util.FlowDifferenceFilters) VersionedFlowStatus(org.apache.nifi.registry.flow.VersionedFlowStatus) Set(java.util.Set) VersionedFlowCoordinates(org.apache.nifi.registry.flow.VersionedFlowCoordinates) VersionedRemoteGroupPort(org.apache.nifi.registry.flow.VersionedRemoteGroupPort) FlowController(org.apache.nifi.controller.FlowController) StandardCharsets(java.nio.charset.StandardCharsets) StateManagerProvider(org.apache.nifi.components.state.StateManagerProvider) Position(org.apache.nifi.connectable.Position) ScheduledState(org.apache.nifi.controller.ScheduledState) ControllerService(org.apache.nifi.controller.ControllerService) ExtensionManager(org.apache.nifi.nar.ExtensionManager) StandardVersionControlInformation(org.apache.nifi.registry.flow.StandardVersionControlInformation) Resource(org.apache.nifi.authorization.Resource) FlowComparator(org.apache.nifi.registry.flow.diff.FlowComparator) StaticDifferenceDescriptor(org.apache.nifi.registry.flow.diff.StaticDifferenceDescriptor) StandardComparableDataFlow(org.apache.nifi.registry.flow.diff.StandardComparableDataFlow) SiteToSiteTransportProtocol(org.apache.nifi.remote.protocol.SiteToSiteTransportProtocol) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ArrayList(java.util.ArrayList) Relationship(org.apache.nifi.processor.Relationship) ControllerServiceReference(org.apache.nifi.controller.service.ControllerServiceReference) ControllerServiceProvider(org.apache.nifi.controller.service.ControllerServiceProvider) VersionedLabel(org.apache.nifi.registry.flow.VersionedLabel) LinkedHashSet(java.util.LinkedHashSet) VersionedFlowState(org.apache.nifi.registry.flow.VersionedFlowState) EvolvingDifferenceDescriptor(org.apache.nifi.registry.flow.diff.EvolvingDifferenceDescriptor) ConfiguredComponent(org.apache.nifi.controller.ConfiguredComponent) Positionable(org.apache.nifi.connectable.Positionable) ExecutionNode(org.apache.nifi.scheduling.ExecutionNode) IOException(java.io.IOException) VersionedFlowSnapshot(org.apache.nifi.registry.flow.VersionedFlowSnapshot) NiFiRegistryFlowMapper(org.apache.nifi.registry.flow.mapping.NiFiRegistryFlowMapper) Lock(java.util.concurrent.locks.Lock) NiFiProperties(org.apache.nifi.util.NiFiProperties) VariableImpact(org.apache.nifi.attribute.expression.language.VariableImpact) FlowFileQueue(org.apache.nifi.controller.queue.FlowFileQueue) ProcessorInstantiationException(org.apache.nifi.controller.exception.ProcessorInstantiationException) BundleCoordinate(org.apache.nifi.bundle.BundleCoordinate) URL(java.net.URL) ConnectableType(org.apache.nifi.connectable.ConnectableType) ConnectableComponent(org.apache.nifi.registry.flow.ConnectableComponent) VariableDescriptor(org.apache.nifi.registry.VariableDescriptor) LoggerFactory(org.slf4j.LoggerFactory) Port(org.apache.nifi.connectable.Port) StandardFlowComparator(org.apache.nifi.registry.flow.diff.StandardFlowComparator) Query(org.apache.nifi.attribute.expression.language.Query) ResourceType(org.apache.nifi.authorization.resource.ResourceType) TemplateDTO(org.apache.nifi.web.api.dto.TemplateDTO) SchedulingStrategy(org.apache.nifi.scheduling.SchedulingStrategy) VersionedPort(org.apache.nifi.registry.flow.VersionedPort) VersionedRemoteProcessGroup(org.apache.nifi.registry.flow.VersionedRemoteProcessGroup) StandardProcessScheduler(org.apache.nifi.controller.scheduling.StandardProcessScheduler) VersionedComponent(org.apache.nifi.registry.flow.VersionedComponent) DifferenceType(org.apache.nifi.registry.flow.diff.DifferenceType) VersionedConnection(org.apache.nifi.registry.flow.VersionedConnection) Template(org.apache.nifi.controller.Template) Label(org.apache.nifi.controller.label.Label) FlowRegistryClient(org.apache.nifi.registry.flow.FlowRegistryClient) OnShutdown(org.apache.nifi.annotation.lifecycle.OnShutdown) MutableVariableRegistry(org.apache.nifi.registry.variable.MutableVariableRegistry) Authorizable(org.apache.nifi.authorization.resource.Authorizable) UUID(java.util.UUID) ComponentLifeCycleException(org.apache.nifi.controller.exception.ComponentLifeCycleException) Snippet(org.apache.nifi.controller.Snippet) Collectors(java.util.stream.Collectors) ResourceFactory(org.apache.nifi.authorization.resource.ResourceFactory) Objects(java.util.Objects) List(java.util.List) BatchSize(org.apache.nifi.registry.flow.BatchSize) VersionedFunnel(org.apache.nifi.registry.flow.VersionedFunnel) ToStringBuilder(org.apache.commons.lang3.builder.ToStringBuilder) VersionControlInformation(org.apache.nifi.registry.flow.VersionControlInformation) Optional(java.util.Optional) LocalPort(org.apache.nifi.connectable.LocalPort) StandardProcessContext(org.apache.nifi.processor.StandardProcessContext) ProcessorNode(org.apache.nifi.controller.ProcessorNode) Revision(org.apache.nifi.web.Revision) Funnel(org.apache.nifi.connectable.Funnel) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) ToStringStyle(org.apache.commons.lang3.builder.ToStringStyle) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) FlowRegistry(org.apache.nifi.registry.flow.FlowRegistry) HashSet(java.util.HashSet) StringEncryptor(org.apache.nifi.encrypt.StringEncryptor) ComparableDataFlow(org.apache.nifi.registry.flow.diff.ComparableDataFlow) Objects.requireNonNull(java.util.Objects.requireNonNull) StandardConfigurationContext(org.apache.nifi.controller.service.StandardConfigurationContext) NarCloseable(org.apache.nifi.nar.NarCloseable) LogLevel(org.apache.nifi.logging.LogLevel) VersionedProcessor(org.apache.nifi.registry.flow.VersionedProcessor) Logger(org.slf4j.Logger) StateManager(org.apache.nifi.components.state.StateManager) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort) StandardRemoteProcessGroupPortDescriptor(org.apache.nifi.remote.StandardRemoteProcessGroupPortDescriptor) VersionedFlow(org.apache.nifi.registry.flow.VersionedFlow) VersionedControllerService(org.apache.nifi.registry.flow.VersionedControllerService) TimeUnit(java.util.concurrent.TimeUnit) ComponentVariableRegistry(org.apache.nifi.registry.ComponentVariableRegistry) FlowDifference(org.apache.nifi.registry.flow.diff.FlowDifference) VersionedPropertyDescriptor(org.apache.nifi.registry.flow.VersionedPropertyDescriptor) Collections(java.util.Collections) LogRepositoryFactory(org.apache.nifi.logging.LogRepositoryFactory) Position(org.apache.nifi.connectable.Position)

Example 12 with Position

use of org.apache.nifi.connectable.Position in project nifi by apache.

the class StandardProcessGroup method updateProcessGroup.

private void updateProcessGroup(final ProcessGroup group, final VersionedProcessGroup proposed, final String componentIdSeed, final Set<String> updatedVersionedComponentIds, final boolean updatePosition, final boolean updateName, final boolean updateDescendantVersionedGroups, final Set<String> variablesToSkip) throws ProcessorInstantiationException {
    group.setComments(proposed.getComments());
    if (updateName) {
        group.setName(proposed.getName());
    }
    if (updatePosition && proposed.getPosition() != null) {
        group.setPosition(new Position(proposed.getPosition().getX(), proposed.getPosition().getY()));
    }
    // Determine which variables have been added/removed and add/remove them from this group's variable registry.
    // We don't worry about if a variable value has changed, because variables are designed to be 'environment specific.'
    // As a result, once imported, we won't update variables to match the remote flow, but we will add any missing variables
    // and remove any variables that are no longer part of the remote flow.
    final Set<String> existingVariableNames = group.getVariableRegistry().getVariableMap().keySet().stream().map(VariableDescriptor::getName).collect(Collectors.toSet());
    final Map<String, String> updatedVariableMap = new HashMap<>();
    // If any new variables exist in the proposed flow, add those to the variable registry.
    for (final Map.Entry<String, String> entry : proposed.getVariables().entrySet()) {
        if (!existingVariableNames.contains(entry.getKey()) && !variablesToSkip.contains(entry.getKey())) {
            updatedVariableMap.put(entry.getKey(), entry.getValue());
        }
    }
    group.setVariables(updatedVariableMap);
    final VersionedFlowCoordinates remoteCoordinates = proposed.getVersionedFlowCoordinates();
    if (remoteCoordinates == null) {
        group.disconnectVersionControl(false);
    } else {
        final String registryId = flowController.getFlowRegistryClient().getFlowRegistryId(remoteCoordinates.getRegistryUrl());
        final String bucketId = remoteCoordinates.getBucketId();
        final String flowId = remoteCoordinates.getFlowId();
        final int version = remoteCoordinates.getVersion();
        final FlowRegistry flowRegistry = flowController.getFlowRegistryClient().getFlowRegistry(registryId);
        final String registryName = flowRegistry == null ? registryId : flowRegistry.getName();
        final VersionedFlowState flowState = remoteCoordinates.getLatest() ? VersionedFlowState.UP_TO_DATE : VersionedFlowState.STALE;
        final VersionControlInformation vci = new StandardVersionControlInformation.Builder().registryId(registryId).registryName(registryName).bucketId(bucketId).bucketName(bucketId).flowId(flowId).flowName(flowId).version(version).flowSnapshot(proposed).status(new StandardVersionedFlowStatus(flowState, flowState.getDescription())).build();
        group.setVersionControlInformation(vci, Collections.emptyMap());
    }
    // Controller Services
    // Controller Services have to be handled a bit differently than other components. This is because Processors and Controller
    // Services may reference other Controller Services. Since we may be adding Service A, which depends on Service B, before adding
    // Service B, we need to ensure that we create all Controller Services first and then call updateControllerService for each
    // Controller Service. This way, we ensure that all services have been created before setting the properties. This allows us to
    // properly obtain the correct mapping of Controller Service VersionedComponentID to Controller Service instance id.
    final Map<String, ControllerServiceNode> servicesByVersionedId = group.getControllerServices(false).stream().collect(Collectors.toMap(component -> component.getVersionedComponentId().orElse(component.getIdentifier()), Function.identity()));
    final Set<String> controllerServicesRemoved = new HashSet<>(servicesByVersionedId.keySet());
    final Map<ControllerServiceNode, VersionedControllerService> services = new HashMap<>();
    // Add any Controller Service that does not yet exist.
    for (final VersionedControllerService proposedService : proposed.getControllerServices()) {
        ControllerServiceNode service = servicesByVersionedId.get(proposedService.getIdentifier());
        if (service == null) {
            service = addControllerService(group, proposedService, componentIdSeed);
            LOG.info("Added {} to {}", service, this);
        }
        services.put(service, proposedService);
    }
    // Update all of the Controller Services to match the VersionedControllerService
    for (final Map.Entry<ControllerServiceNode, VersionedControllerService> entry : services.entrySet()) {
        final ControllerServiceNode service = entry.getKey();
        final VersionedControllerService proposedService = entry.getValue();
        if (updatedVersionedComponentIds.contains(proposedService.getIdentifier())) {
            updateControllerService(service, proposedService);
            LOG.info("Updated {}", service);
        }
        controllerServicesRemoved.remove(proposedService.getIdentifier());
    }
    // Child groups
    final Map<String, ProcessGroup> childGroupsByVersionedId = group.getProcessGroups().stream().collect(Collectors.toMap(component -> component.getVersionedComponentId().orElse(component.getIdentifier()), Function.identity()));
    final Set<String> childGroupsRemoved = new HashSet<>(childGroupsByVersionedId.keySet());
    for (final VersionedProcessGroup proposedChildGroup : proposed.getProcessGroups()) {
        final ProcessGroup childGroup = childGroupsByVersionedId.get(proposedChildGroup.getIdentifier());
        final VersionedFlowCoordinates childCoordinates = proposedChildGroup.getVersionedFlowCoordinates();
        if (childGroup == null) {
            final ProcessGroup added = addProcessGroup(group, proposedChildGroup, componentIdSeed, variablesToSkip);
            flowController.onProcessGroupAdded(added);
            added.findAllRemoteProcessGroups().stream().forEach(RemoteProcessGroup::initialize);
            LOG.info("Added {} to {}", added, this);
        } else if (childCoordinates == null || updateDescendantVersionedGroups) {
            updateProcessGroup(childGroup, proposedChildGroup, componentIdSeed, updatedVersionedComponentIds, true, true, updateDescendantVersionedGroups, variablesToSkip);
            LOG.info("Updated {}", childGroup);
        }
        childGroupsRemoved.remove(proposedChildGroup.getIdentifier());
    }
    // Funnels
    final Map<String, Funnel> funnelsByVersionedId = group.getFunnels().stream().collect(Collectors.toMap(component -> component.getVersionedComponentId().orElse(component.getIdentifier()), Function.identity()));
    final Set<String> funnelsRemoved = new HashSet<>(funnelsByVersionedId.keySet());
    for (final VersionedFunnel proposedFunnel : proposed.getFunnels()) {
        final Funnel funnel = funnelsByVersionedId.get(proposedFunnel.getIdentifier());
        if (funnel == null) {
            final Funnel added = addFunnel(group, proposedFunnel, componentIdSeed);
            flowController.onFunnelAdded(added);
            LOG.info("Added {} to {}", added, this);
        } else if (updatedVersionedComponentIds.contains(proposedFunnel.getIdentifier())) {
            updateFunnel(funnel, proposedFunnel);
            LOG.info("Updated {}", funnel);
        } else {
            funnel.setPosition(new Position(proposedFunnel.getPosition().getX(), proposedFunnel.getPosition().getY()));
        }
        funnelsRemoved.remove(proposedFunnel.getIdentifier());
    }
    // Input Ports
    final Map<String, Port> inputPortsByVersionedId = group.getInputPorts().stream().collect(Collectors.toMap(component -> component.getVersionedComponentId().orElse(component.getIdentifier()), Function.identity()));
    final Set<String> inputPortsRemoved = new HashSet<>(inputPortsByVersionedId.keySet());
    for (final VersionedPort proposedPort : proposed.getInputPorts()) {
        final Port port = inputPortsByVersionedId.get(proposedPort.getIdentifier());
        if (port == null) {
            final Port added = addInputPort(group, proposedPort, componentIdSeed);
            flowController.onInputPortAdded(added);
            LOG.info("Added {} to {}", added, this);
        } else if (updatedVersionedComponentIds.contains(proposedPort.getIdentifier())) {
            updatePort(port, proposedPort);
            LOG.info("Updated {}", port);
        } else {
            port.setPosition(new Position(proposedPort.getPosition().getX(), proposedPort.getPosition().getY()));
        }
        inputPortsRemoved.remove(proposedPort.getIdentifier());
    }
    // Output Ports
    final Map<String, Port> outputPortsByVersionedId = group.getOutputPorts().stream().collect(Collectors.toMap(component -> component.getVersionedComponentId().orElse(component.getIdentifier()), Function.identity()));
    final Set<String> outputPortsRemoved = new HashSet<>(outputPortsByVersionedId.keySet());
    for (final VersionedPort proposedPort : proposed.getOutputPorts()) {
        final Port port = outputPortsByVersionedId.get(proposedPort.getIdentifier());
        if (port == null) {
            final Port added = addOutputPort(group, proposedPort, componentIdSeed);
            flowController.onOutputPortAdded(added);
            LOG.info("Added {} to {}", added, this);
        } else if (updatedVersionedComponentIds.contains(proposedPort.getIdentifier())) {
            updatePort(port, proposedPort);
            LOG.info("Updated {}", port);
        } else {
            port.setPosition(new Position(proposedPort.getPosition().getX(), proposedPort.getPosition().getY()));
        }
        outputPortsRemoved.remove(proposedPort.getIdentifier());
    }
    // Labels
    final Map<String, Label> labelsByVersionedId = group.getLabels().stream().collect(Collectors.toMap(component -> component.getVersionedComponentId().orElse(component.getIdentifier()), Function.identity()));
    final Set<String> labelsRemoved = new HashSet<>(labelsByVersionedId.keySet());
    for (final VersionedLabel proposedLabel : proposed.getLabels()) {
        final Label label = labelsByVersionedId.get(proposedLabel.getIdentifier());
        if (label == null) {
            final Label added = addLabel(group, proposedLabel, componentIdSeed);
            LOG.info("Added {} to {}", added, this);
        } else if (updatedVersionedComponentIds.contains(proposedLabel.getIdentifier())) {
            updateLabel(label, proposedLabel);
            LOG.info("Updated {}", label);
        } else {
            label.setPosition(new Position(proposedLabel.getPosition().getX(), proposedLabel.getPosition().getY()));
        }
        labelsRemoved.remove(proposedLabel.getIdentifier());
    }
    // Processors
    final Map<String, ProcessorNode> processorsByVersionedId = group.getProcessors().stream().collect(Collectors.toMap(component -> component.getVersionedComponentId().orElse(component.getIdentifier()), Function.identity()));
    final Set<String> processorsRemoved = new HashSet<>(processorsByVersionedId.keySet());
    final Map<ProcessorNode, Set<Relationship>> autoTerminatedRelationships = new HashMap<>();
    for (final VersionedProcessor proposedProcessor : proposed.getProcessors()) {
        final ProcessorNode processor = processorsByVersionedId.get(proposedProcessor.getIdentifier());
        if (processor == null) {
            final ProcessorNode added = addProcessor(group, proposedProcessor, componentIdSeed);
            flowController.onProcessorAdded(added);
            final Set<Relationship> proposedAutoTerminated = proposedProcessor.getAutoTerminatedRelationships() == null ? Collections.emptySet() : proposedProcessor.getAutoTerminatedRelationships().stream().map(relName -> added.getRelationship(relName)).collect(Collectors.toSet());
            autoTerminatedRelationships.put(added, proposedAutoTerminated);
            LOG.info("Added {} to {}", added, this);
        } else if (updatedVersionedComponentIds.contains(proposedProcessor.getIdentifier())) {
            updateProcessor(processor, proposedProcessor);
            final Set<Relationship> proposedAutoTerminated = proposedProcessor.getAutoTerminatedRelationships() == null ? Collections.emptySet() : proposedProcessor.getAutoTerminatedRelationships().stream().map(relName -> processor.getRelationship(relName)).collect(Collectors.toSet());
            if (!processor.getAutoTerminatedRelationships().equals(proposedAutoTerminated)) {
                autoTerminatedRelationships.put(processor, proposedAutoTerminated);
            }
            LOG.info("Updated {}", processor);
        } else {
            processor.setPosition(new Position(proposedProcessor.getPosition().getX(), proposedProcessor.getPosition().getY()));
        }
        processorsRemoved.remove(proposedProcessor.getIdentifier());
    }
    // Remote Groups
    final Map<String, RemoteProcessGroup> rpgsByVersionedId = group.getRemoteProcessGroups().stream().collect(Collectors.toMap(component -> component.getVersionedComponentId().orElse(component.getIdentifier()), Function.identity()));
    final Set<String> rpgsRemoved = new HashSet<>(rpgsByVersionedId.keySet());
    for (final VersionedRemoteProcessGroup proposedRpg : proposed.getRemoteProcessGroups()) {
        final RemoteProcessGroup rpg = rpgsByVersionedId.get(proposedRpg.getIdentifier());
        if (rpg == null) {
            final RemoteProcessGroup added = addRemoteProcessGroup(group, proposedRpg, componentIdSeed);
            LOG.info("Added {} to {}", added, this);
        } else if (updatedVersionedComponentIds.contains(proposedRpg.getIdentifier())) {
            updateRemoteProcessGroup(rpg, proposedRpg, componentIdSeed);
            LOG.info("Updated {}", rpg);
        } else {
            rpg.setPosition(new Position(proposedRpg.getPosition().getX(), proposedRpg.getPosition().getY()));
        }
        rpgsRemoved.remove(proposedRpg.getIdentifier());
    }
    // Connections
    final Map<String, Connection> connectionsByVersionedId = group.getConnections().stream().collect(Collectors.toMap(component -> component.getVersionedComponentId().orElse(component.getIdentifier()), Function.identity()));
    final Set<String> connectionsRemoved = new HashSet<>(connectionsByVersionedId.keySet());
    for (final VersionedConnection proposedConnection : proposed.getConnections()) {
        final Connection connection = connectionsByVersionedId.get(proposedConnection.getIdentifier());
        if (connection == null) {
            final Connection added = addConnection(group, proposedConnection, componentIdSeed);
            flowController.onConnectionAdded(added);
            LOG.info("Added {} to {}", added, this);
        } else if (isUpdateable(connection)) {
            // If the connection needs to be updated, then the source and destination will already have
            // been stopped (else, the validation above would fail). So if the source or the destination is running,
            // then we know that we don't need to update the connection.
            updateConnection(connection, proposedConnection);
            LOG.info("Updated {}", connection);
        }
        connectionsRemoved.remove(proposedConnection.getIdentifier());
    }
    // to remove a component if it has a connection going to it!
    for (final String removedVersionedId : connectionsRemoved) {
        final Connection connection = connectionsByVersionedId.get(removedVersionedId);
        LOG.info("Removing {} from {}", connection, group);
        group.removeConnection(connection);
        flowController.onConnectionRemoved(connection);
    }
    // Once the appropriate connections have been removed, we may now update Processors' auto-terminated relationships.
    // We cannot do this above, in the 'updateProcessor' call because if a connection is removed and changed to auto-terminated,
    // then updating this in the updateProcessor call above would attempt to set the Relationship to being auto-terminated while a
    // Connection for that relationship exists. This will throw an Exception.
    autoTerminatedRelationships.forEach((proc, rels) -> proc.setAutoTerminatedRelationships(rels));
    // Remove all controller services no longer in use
    for (final String removedVersionedId : controllerServicesRemoved) {
        final ControllerServiceNode service = servicesByVersionedId.get(removedVersionedId);
        LOG.info("Removing {} from {}", service, group);
        // Must remove Controller Service through Flow Controller in order to remove from cache
        flowController.removeControllerService(service);
    }
    for (final String removedVersionedId : funnelsRemoved) {
        final Funnel funnel = funnelsByVersionedId.get(removedVersionedId);
        LOG.info("Removing {} from {}", funnel, group);
        group.removeFunnel(funnel);
    }
    for (final String removedVersionedId : inputPortsRemoved) {
        final Port port = inputPortsByVersionedId.get(removedVersionedId);
        LOG.info("Removing {} from {}", port, group);
        group.removeInputPort(port);
    }
    for (final String removedVersionedId : outputPortsRemoved) {
        final Port port = outputPortsByVersionedId.get(removedVersionedId);
        LOG.info("Removing {} from {}", port, group);
        group.removeOutputPort(port);
    }
    for (final String removedVersionedId : labelsRemoved) {
        final Label label = labelsByVersionedId.get(removedVersionedId);
        LOG.info("Removing {} from {}", label, group);
        group.removeLabel(label);
    }
    for (final String removedVersionedId : processorsRemoved) {
        final ProcessorNode processor = processorsByVersionedId.get(removedVersionedId);
        LOG.info("Removing {} from {}", processor, group);
        group.removeProcessor(processor);
    }
    for (final String removedVersionedId : rpgsRemoved) {
        final RemoteProcessGroup rpg = rpgsByVersionedId.get(removedVersionedId);
        LOG.info("Removing {} from {}", rpg, group);
        group.removeRemoteProcessGroup(rpg);
    }
    for (final String removedVersionedId : childGroupsRemoved) {
        final ProcessGroup childGroup = childGroupsByVersionedId.get(removedVersionedId);
        LOG.info("Removing {} from {}", childGroup, group);
        group.removeProcessGroup(childGroup);
    }
}
Also used : OnRemoved(org.apache.nifi.annotation.lifecycle.OnRemoved) ConfigurationContext(org.apache.nifi.controller.ConfigurationContext) Size(org.apache.nifi.connectable.Size) FlowComparison(org.apache.nifi.registry.flow.diff.FlowComparison) StringUtils(org.apache.commons.lang3.StringUtils) ReflectionUtils(org.apache.nifi.util.ReflectionUtils) PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) SecureRandom(java.security.SecureRandom) NiFiRegistryException(org.apache.nifi.registry.client.NiFiRegistryException) ComponentType(org.apache.nifi.registry.flow.ComponentType) VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup) SnippetUtils(org.apache.nifi.util.SnippetUtils) Map(java.util.Map) HashCodeBuilder(org.apache.commons.lang3.builder.HashCodeBuilder) RootGroupPort(org.apache.nifi.remote.RootGroupPort) Connectable(org.apache.nifi.connectable.Connectable) Connection(org.apache.nifi.connectable.Connection) Bundle(org.apache.nifi.registry.flow.Bundle) FlowFilePrioritizer(org.apache.nifi.flowfile.FlowFilePrioritizer) FlowDifferenceFilters(org.apache.nifi.util.FlowDifferenceFilters) VersionedFlowStatus(org.apache.nifi.registry.flow.VersionedFlowStatus) Set(java.util.Set) VersionedFlowCoordinates(org.apache.nifi.registry.flow.VersionedFlowCoordinates) VersionedRemoteGroupPort(org.apache.nifi.registry.flow.VersionedRemoteGroupPort) FlowController(org.apache.nifi.controller.FlowController) StandardCharsets(java.nio.charset.StandardCharsets) StateManagerProvider(org.apache.nifi.components.state.StateManagerProvider) Position(org.apache.nifi.connectable.Position) ScheduledState(org.apache.nifi.controller.ScheduledState) ControllerService(org.apache.nifi.controller.ControllerService) ExtensionManager(org.apache.nifi.nar.ExtensionManager) StandardVersionControlInformation(org.apache.nifi.registry.flow.StandardVersionControlInformation) Resource(org.apache.nifi.authorization.Resource) FlowComparator(org.apache.nifi.registry.flow.diff.FlowComparator) StaticDifferenceDescriptor(org.apache.nifi.registry.flow.diff.StaticDifferenceDescriptor) StandardComparableDataFlow(org.apache.nifi.registry.flow.diff.StandardComparableDataFlow) SiteToSiteTransportProtocol(org.apache.nifi.remote.protocol.SiteToSiteTransportProtocol) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ArrayList(java.util.ArrayList) Relationship(org.apache.nifi.processor.Relationship) ControllerServiceReference(org.apache.nifi.controller.service.ControllerServiceReference) ControllerServiceProvider(org.apache.nifi.controller.service.ControllerServiceProvider) VersionedLabel(org.apache.nifi.registry.flow.VersionedLabel) LinkedHashSet(java.util.LinkedHashSet) VersionedFlowState(org.apache.nifi.registry.flow.VersionedFlowState) EvolvingDifferenceDescriptor(org.apache.nifi.registry.flow.diff.EvolvingDifferenceDescriptor) ConfiguredComponent(org.apache.nifi.controller.ConfiguredComponent) Positionable(org.apache.nifi.connectable.Positionable) ExecutionNode(org.apache.nifi.scheduling.ExecutionNode) IOException(java.io.IOException) VersionedFlowSnapshot(org.apache.nifi.registry.flow.VersionedFlowSnapshot) NiFiRegistryFlowMapper(org.apache.nifi.registry.flow.mapping.NiFiRegistryFlowMapper) Lock(java.util.concurrent.locks.Lock) NiFiProperties(org.apache.nifi.util.NiFiProperties) VariableImpact(org.apache.nifi.attribute.expression.language.VariableImpact) FlowFileQueue(org.apache.nifi.controller.queue.FlowFileQueue) ProcessorInstantiationException(org.apache.nifi.controller.exception.ProcessorInstantiationException) BundleCoordinate(org.apache.nifi.bundle.BundleCoordinate) URL(java.net.URL) ConnectableType(org.apache.nifi.connectable.ConnectableType) ConnectableComponent(org.apache.nifi.registry.flow.ConnectableComponent) VariableDescriptor(org.apache.nifi.registry.VariableDescriptor) LoggerFactory(org.slf4j.LoggerFactory) Port(org.apache.nifi.connectable.Port) StandardFlowComparator(org.apache.nifi.registry.flow.diff.StandardFlowComparator) Query(org.apache.nifi.attribute.expression.language.Query) ResourceType(org.apache.nifi.authorization.resource.ResourceType) TemplateDTO(org.apache.nifi.web.api.dto.TemplateDTO) SchedulingStrategy(org.apache.nifi.scheduling.SchedulingStrategy) VersionedPort(org.apache.nifi.registry.flow.VersionedPort) VersionedRemoteProcessGroup(org.apache.nifi.registry.flow.VersionedRemoteProcessGroup) StandardProcessScheduler(org.apache.nifi.controller.scheduling.StandardProcessScheduler) VersionedComponent(org.apache.nifi.registry.flow.VersionedComponent) DifferenceType(org.apache.nifi.registry.flow.diff.DifferenceType) VersionedConnection(org.apache.nifi.registry.flow.VersionedConnection) Template(org.apache.nifi.controller.Template) Label(org.apache.nifi.controller.label.Label) FlowRegistryClient(org.apache.nifi.registry.flow.FlowRegistryClient) OnShutdown(org.apache.nifi.annotation.lifecycle.OnShutdown) MutableVariableRegistry(org.apache.nifi.registry.variable.MutableVariableRegistry) Authorizable(org.apache.nifi.authorization.resource.Authorizable) UUID(java.util.UUID) ComponentLifeCycleException(org.apache.nifi.controller.exception.ComponentLifeCycleException) Snippet(org.apache.nifi.controller.Snippet) Collectors(java.util.stream.Collectors) ResourceFactory(org.apache.nifi.authorization.resource.ResourceFactory) Objects(java.util.Objects) List(java.util.List) BatchSize(org.apache.nifi.registry.flow.BatchSize) VersionedFunnel(org.apache.nifi.registry.flow.VersionedFunnel) ToStringBuilder(org.apache.commons.lang3.builder.ToStringBuilder) VersionControlInformation(org.apache.nifi.registry.flow.VersionControlInformation) Optional(java.util.Optional) LocalPort(org.apache.nifi.connectable.LocalPort) StandardProcessContext(org.apache.nifi.processor.StandardProcessContext) ProcessorNode(org.apache.nifi.controller.ProcessorNode) Revision(org.apache.nifi.web.Revision) Funnel(org.apache.nifi.connectable.Funnel) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) ToStringStyle(org.apache.commons.lang3.builder.ToStringStyle) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) FlowRegistry(org.apache.nifi.registry.flow.FlowRegistry) HashSet(java.util.HashSet) StringEncryptor(org.apache.nifi.encrypt.StringEncryptor) ComparableDataFlow(org.apache.nifi.registry.flow.diff.ComparableDataFlow) Objects.requireNonNull(java.util.Objects.requireNonNull) StandardConfigurationContext(org.apache.nifi.controller.service.StandardConfigurationContext) NarCloseable(org.apache.nifi.nar.NarCloseable) LogLevel(org.apache.nifi.logging.LogLevel) VersionedProcessor(org.apache.nifi.registry.flow.VersionedProcessor) Logger(org.slf4j.Logger) StateManager(org.apache.nifi.components.state.StateManager) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort) StandardRemoteProcessGroupPortDescriptor(org.apache.nifi.remote.StandardRemoteProcessGroupPortDescriptor) VersionedFlow(org.apache.nifi.registry.flow.VersionedFlow) VersionedControllerService(org.apache.nifi.registry.flow.VersionedControllerService) TimeUnit(java.util.concurrent.TimeUnit) ComponentVariableRegistry(org.apache.nifi.registry.ComponentVariableRegistry) FlowDifference(org.apache.nifi.registry.flow.diff.FlowDifference) VersionedPropertyDescriptor(org.apache.nifi.registry.flow.VersionedPropertyDescriptor) Collections(java.util.Collections) LogRepositoryFactory(org.apache.nifi.logging.LogRepositoryFactory) VersionedFunnel(org.apache.nifi.registry.flow.VersionedFunnel) Funnel(org.apache.nifi.connectable.Funnel) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet) HashMap(java.util.HashMap) FlowRegistry(org.apache.nifi.registry.flow.FlowRegistry) HashCodeBuilder(org.apache.commons.lang3.builder.HashCodeBuilder) ToStringBuilder(org.apache.commons.lang3.builder.ToStringBuilder) RootGroupPort(org.apache.nifi.remote.RootGroupPort) VersionedRemoteGroupPort(org.apache.nifi.registry.flow.VersionedRemoteGroupPort) Port(org.apache.nifi.connectable.Port) VersionedPort(org.apache.nifi.registry.flow.VersionedPort) LocalPort(org.apache.nifi.connectable.LocalPort) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort) VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup) VersionedLabel(org.apache.nifi.registry.flow.VersionedLabel) Label(org.apache.nifi.controller.label.Label) ProcessorNode(org.apache.nifi.controller.ProcessorNode) VersionedFlowState(org.apache.nifi.registry.flow.VersionedFlowState) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet) VersionedRemoteProcessGroup(org.apache.nifi.registry.flow.VersionedRemoteProcessGroup) Position(org.apache.nifi.connectable.Position) Connection(org.apache.nifi.connectable.Connection) VersionedConnection(org.apache.nifi.registry.flow.VersionedConnection) VersionedPort(org.apache.nifi.registry.flow.VersionedPort) VersionedControllerService(org.apache.nifi.registry.flow.VersionedControllerService) VersionedFunnel(org.apache.nifi.registry.flow.VersionedFunnel) VersionedFlowCoordinates(org.apache.nifi.registry.flow.VersionedFlowCoordinates) VersionedLabel(org.apache.nifi.registry.flow.VersionedLabel) StandardVersionControlInformation(org.apache.nifi.registry.flow.StandardVersionControlInformation) VersionControlInformation(org.apache.nifi.registry.flow.VersionControlInformation) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) VersionedRemoteProcessGroup(org.apache.nifi.registry.flow.VersionedRemoteProcessGroup) Relationship(org.apache.nifi.processor.Relationship) VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup) VersionedRemoteProcessGroup(org.apache.nifi.registry.flow.VersionedRemoteProcessGroup) VersionedConnection(org.apache.nifi.registry.flow.VersionedConnection) Map(java.util.Map) HashMap(java.util.HashMap) VersionedProcessor(org.apache.nifi.registry.flow.VersionedProcessor)

Example 13 with Position

use of org.apache.nifi.connectable.Position in project nifi by apache.

the class StandardFlowSynchronizer method updateProcessGroup.

private ProcessGroup updateProcessGroup(final FlowController controller, final ProcessGroup parentGroup, final Element processGroupElement, final StringEncryptor encryptor, final FlowEncodingVersion encodingVersion) throws ProcessorInstantiationException {
    // get the parent group ID
    final String parentId = (parentGroup == null) ? null : parentGroup.getIdentifier();
    // get the process group
    final ProcessGroupDTO processGroupDto = FlowFromDOMFactory.getProcessGroup(parentId, processGroupElement, encryptor, encodingVersion);
    // update the process group
    if (parentId == null) {
        /*
             * Labels are not included in the "inherit flow" algorithm, so we cannot
             * blindly update them because they may not exist in the current flow.
             * Therefore, we first remove all labels, and then let the updating
             * process add labels defined in the new flow.
             */
        final ProcessGroup root = controller.getGroup(controller.getRootGroupId());
        for (final Label label : root.findAllLabels()) {
            label.getProcessGroup().removeLabel(label);
        }
    }
    // update the process group
    controller.updateProcessGroup(processGroupDto);
    // get the real process group and ID
    final ProcessGroup processGroup = controller.getGroup(processGroupDto.getId());
    // determine the scheduled state of all of the Controller Service
    final List<Element> controllerServiceNodeList = getChildrenByTagName(processGroupElement, "controllerService");
    final Set<ControllerServiceNode> toDisable = new HashSet<>();
    final Set<ControllerServiceNode> toEnable = new HashSet<>();
    for (final Element serviceElement : controllerServiceNodeList) {
        final ControllerServiceDTO dto = FlowFromDOMFactory.getControllerService(serviceElement, encryptor);
        final ControllerServiceNode serviceNode = processGroup.getControllerService(dto.getId());
        // Check if the controller service is in the correct state. We consider it the correct state if
        // we are in a transitional state and heading in the right direction or already in the correct state.
        // E.g., it is the correct state if it should be 'DISABLED' and it is either DISABLED or DISABLING.
        final ControllerServiceState serviceState = getFinalTransitionState(serviceNode.getState());
        final ControllerServiceState clusterState = getFinalTransitionState(ControllerServiceState.valueOf(dto.getState()));
        if (serviceState != clusterState) {
            switch(clusterState) {
                case DISABLED:
                    toDisable.add(serviceNode);
                    break;
                case ENABLED:
                    toEnable.add(serviceNode);
                    break;
            }
        }
    }
    controller.disableControllerServicesAsync(toDisable);
    controller.enableControllerServices(toEnable);
    // processors & ports cannot be updated - they must be the same. Except for the scheduled state.
    final List<Element> processorNodeList = getChildrenByTagName(processGroupElement, "processor");
    for (final Element processorElement : processorNodeList) {
        final ProcessorDTO dto = FlowFromDOMFactory.getProcessor(processorElement, encryptor);
        final ProcessorNode procNode = processGroup.getProcessor(dto.getId());
        updateNonFingerprintedProcessorSettings(procNode, dto);
        if (!procNode.getScheduledState().name().equals(dto.getState())) {
            try {
                switch(ScheduledState.valueOf(dto.getState())) {
                    case DISABLED:
                        // switch processor do disabled. This means we have to stop it (if it's already stopped, this method does nothing),
                        // and then we have to disable it.
                        controller.stopProcessor(procNode.getProcessGroupIdentifier(), procNode.getIdentifier());
                        procNode.getProcessGroup().disableProcessor(procNode);
                        break;
                    case RUNNING:
                        // we want to run now. Make sure processor is not disabled and then start it.
                        procNode.getProcessGroup().enableProcessor(procNode);
                        controller.startProcessor(procNode.getProcessGroupIdentifier(), procNode.getIdentifier(), false);
                        break;
                    case STOPPED:
                        if (procNode.getScheduledState() == ScheduledState.DISABLED) {
                            procNode.getProcessGroup().enableProcessor(procNode);
                        } else if (procNode.getScheduledState() == ScheduledState.RUNNING) {
                            controller.stopProcessor(procNode.getProcessGroupIdentifier(), procNode.getIdentifier());
                        }
                        break;
                }
            } catch (final IllegalStateException ise) {
                logger.error("Failed to change Scheduled State of {} from {} to {} due to {}", procNode, procNode.getScheduledState().name(), dto.getState(), ise.toString());
                logger.error("", ise);
                // create bulletin for the Processor Node
                controller.getBulletinRepository().addBulletin(BulletinFactory.createBulletin(procNode, "Node Reconnection", Severity.ERROR.name(), "Failed to change Scheduled State of " + procNode + " from " + procNode.getScheduledState().name() + " to " + dto.getState() + " due to " + ise.toString()));
                // create bulletin at Controller level.
                controller.getBulletinRepository().addBulletin(BulletinFactory.createBulletin("Node Reconnection", Severity.ERROR.name(), "Failed to change Scheduled State of " + procNode + " from " + procNode.getScheduledState().name() + " to " + dto.getState() + " due to " + ise.toString()));
            }
        }
    }
    final List<Element> inputPortList = getChildrenByTagName(processGroupElement, "inputPort");
    for (final Element portElement : inputPortList) {
        final PortDTO dto = FlowFromDOMFactory.getPort(portElement);
        final Port port = processGroup.getInputPort(dto.getId());
        if (!port.getScheduledState().name().equals(dto.getState())) {
            switch(ScheduledState.valueOf(dto.getState())) {
                case DISABLED:
                    // switch processor do disabled. This means we have to stop it (if it's already stopped, this method does nothing),
                    // and then we have to disable it.
                    controller.stopConnectable(port);
                    port.getProcessGroup().disableInputPort(port);
                    break;
                case RUNNING:
                    // we want to run now. Make sure processor is not disabled and then start it.
                    port.getProcessGroup().enableInputPort(port);
                    controller.startConnectable(port);
                    break;
                case STOPPED:
                    if (port.getScheduledState() == ScheduledState.DISABLED) {
                        port.getProcessGroup().enableInputPort(port);
                    } else if (port.getScheduledState() == ScheduledState.RUNNING) {
                        controller.stopConnectable(port);
                    }
                    break;
            }
        }
    }
    final List<Element> outputPortList = getChildrenByTagName(processGroupElement, "outputPort");
    for (final Element portElement : outputPortList) {
        final PortDTO dto = FlowFromDOMFactory.getPort(portElement);
        final Port port = processGroup.getOutputPort(dto.getId());
        if (!port.getScheduledState().name().equals(dto.getState())) {
            switch(ScheduledState.valueOf(dto.getState())) {
                case DISABLED:
                    // switch processor do disabled. This means we have to stop it (if it's already stopped, this method does nothing),
                    // and then we have to disable it.
                    controller.stopConnectable(port);
                    port.getProcessGroup().disableOutputPort(port);
                    break;
                case RUNNING:
                    // we want to run now. Make sure processor is not disabled and then start it.
                    port.getProcessGroup().enableOutputPort(port);
                    controller.startConnectable(port);
                    break;
                case STOPPED:
                    if (port.getScheduledState() == ScheduledState.DISABLED) {
                        port.getProcessGroup().enableOutputPort(port);
                    } else if (port.getScheduledState() == ScheduledState.RUNNING) {
                        controller.stopConnectable(port);
                    }
                    break;
            }
        }
    }
    // Update scheduled state of Remote Group Ports
    final List<Element> remoteProcessGroupList = getChildrenByTagName(processGroupElement, "remoteProcessGroup");
    for (final Element remoteGroupElement : remoteProcessGroupList) {
        final RemoteProcessGroupDTO remoteGroupDto = FlowFromDOMFactory.getRemoteProcessGroup(remoteGroupElement, encryptor);
        final RemoteProcessGroup rpg = processGroup.getRemoteProcessGroup(remoteGroupDto.getId());
        // input ports
        final List<Element> inputPortElements = getChildrenByTagName(remoteGroupElement, "inputPort");
        for (final Element inputPortElement : inputPortElements) {
            final RemoteProcessGroupPortDescriptor portDescriptor = FlowFromDOMFactory.getRemoteProcessGroupPort(inputPortElement);
            final String inputPortId = portDescriptor.getId();
            final RemoteGroupPort inputPort = rpg.getInputPort(inputPortId);
            if (inputPort == null) {
                continue;
            }
            if (portDescriptor.isTransmitting()) {
                if (inputPort.getScheduledState() != ScheduledState.RUNNING && inputPort.getScheduledState() != ScheduledState.STARTING) {
                    rpg.startTransmitting(inputPort);
                }
            } else if (inputPort.getScheduledState() != ScheduledState.STOPPED && inputPort.getScheduledState() != ScheduledState.STOPPING) {
                rpg.stopTransmitting(inputPort);
            }
        }
        // output ports
        final List<Element> outputPortElements = getChildrenByTagName(remoteGroupElement, "outputPort");
        for (final Element outputPortElement : outputPortElements) {
            final RemoteProcessGroupPortDescriptor portDescriptor = FlowFromDOMFactory.getRemoteProcessGroupPort(outputPortElement);
            final String outputPortId = portDescriptor.getId();
            final RemoteGroupPort outputPort = rpg.getOutputPort(outputPortId);
            if (outputPort == null) {
                continue;
            }
            if (portDescriptor.isTransmitting()) {
                if (outputPort.getScheduledState() != ScheduledState.RUNNING && outputPort.getScheduledState() != ScheduledState.STARTING) {
                    rpg.startTransmitting(outputPort);
                }
            } else if (outputPort.getScheduledState() != ScheduledState.STOPPED && outputPort.getScheduledState() != ScheduledState.STOPPING) {
                rpg.stopTransmitting(outputPort);
            }
        }
    }
    // add labels
    final List<Element> labelNodeList = getChildrenByTagName(processGroupElement, "label");
    for (final Element labelElement : labelNodeList) {
        final LabelDTO labelDTO = FlowFromDOMFactory.getLabel(labelElement);
        final Label label = controller.createLabel(labelDTO.getId(), labelDTO.getLabel());
        label.setStyle(labelDTO.getStyle());
        label.setPosition(new Position(labelDTO.getPosition().getX(), labelDTO.getPosition().getY()));
        label.setVersionedComponentId(labelDTO.getVersionedComponentId());
        if (labelDTO.getWidth() != null && labelDTO.getHeight() != null) {
            label.setSize(new Size(labelDTO.getWidth(), labelDTO.getHeight()));
        }
        processGroup.addLabel(label);
    }
    // update nested process groups (recursively)
    final List<Element> nestedProcessGroupNodeList = getChildrenByTagName(processGroupElement, "processGroup");
    for (final Element nestedProcessGroupElement : nestedProcessGroupNodeList) {
        updateProcessGroup(controller, processGroup, nestedProcessGroupElement, encryptor, encodingVersion);
    }
    // update connections
    final List<Element> connectionNodeList = getChildrenByTagName(processGroupElement, "connection");
    for (final Element connectionElement : connectionNodeList) {
        final ConnectionDTO dto = FlowFromDOMFactory.getConnection(connectionElement);
        final Connection connection = processGroup.getConnection(dto.getId());
        connection.setName(dto.getName());
        connection.setProcessGroup(processGroup);
        if (dto.getLabelIndex() != null) {
            connection.setLabelIndex(dto.getLabelIndex());
        }
        if (dto.getzIndex() != null) {
            connection.setZIndex(dto.getzIndex());
        }
        final List<Position> bendPoints = new ArrayList<>();
        for (final PositionDTO bend : dto.getBends()) {
            bendPoints.add(new Position(bend.getX(), bend.getY()));
        }
        connection.setBendPoints(bendPoints);
        List<FlowFilePrioritizer> newPrioritizers = null;
        final List<String> prioritizers = dto.getPrioritizers();
        if (prioritizers != null) {
            final List<String> newPrioritizersClasses = new ArrayList<>(prioritizers);
            newPrioritizers = new ArrayList<>();
            for (final String className : newPrioritizersClasses) {
                try {
                    newPrioritizers.add(controller.createPrioritizer(className));
                } catch (final ClassNotFoundException | InstantiationException | IllegalAccessException e) {
                    throw new IllegalArgumentException("Unable to set prioritizer " + className + ": " + e);
                }
            }
        }
        if (newPrioritizers != null) {
            connection.getFlowFileQueue().setPriorities(newPrioritizers);
        }
        if (dto.getBackPressureObjectThreshold() != null) {
            connection.getFlowFileQueue().setBackPressureObjectThreshold(dto.getBackPressureObjectThreshold());
        }
        if (dto.getBackPressureDataSizeThreshold() != null && !dto.getBackPressureDataSizeThreshold().trim().isEmpty()) {
            connection.getFlowFileQueue().setBackPressureDataSizeThreshold(dto.getBackPressureDataSizeThreshold());
        }
        if (dto.getFlowFileExpiration() != null) {
            connection.getFlowFileQueue().setFlowFileExpiration(dto.getFlowFileExpiration());
        }
    }
    // Replace the templates with those from the proposed flow
    final List<Element> templateNodeList = getChildrenByTagName(processGroupElement, "template");
    for (final Element templateElement : templateNodeList) {
        final TemplateDTO templateDto = TemplateUtils.parseDto(templateElement);
        final Template template = new Template(templateDto);
        // This just makes sure that they do.
        if (processGroup.getTemplate(template.getIdentifier()) != null) {
            processGroup.removeTemplate(template);
        }
        processGroup.addTemplate(template);
    }
    return processGroup;
}
Also used : ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) ControllerServiceState(org.apache.nifi.controller.service.ControllerServiceState) Size(org.apache.nifi.connectable.Size) ConnectionDTO(org.apache.nifi.web.api.dto.ConnectionDTO) TemplateDTO(org.apache.nifi.web.api.dto.TemplateDTO) Element(org.w3c.dom.Element) RootGroupPort(org.apache.nifi.remote.RootGroupPort) Port(org.apache.nifi.connectable.Port) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort) Label(org.apache.nifi.controller.label.Label) ArrayList(java.util.ArrayList) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) RemoteProcessGroupDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO) FlowFilePrioritizer(org.apache.nifi.flowfile.FlowFilePrioritizer) HashSet(java.util.HashSet) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort) Position(org.apache.nifi.connectable.Position) PortDTO(org.apache.nifi.web.api.dto.PortDTO) Connection(org.apache.nifi.connectable.Connection) RemoteProcessGroupDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO) PositionDTO(org.apache.nifi.web.api.dto.PositionDTO) RemoteProcessGroupPortDescriptor(org.apache.nifi.groups.RemoteProcessGroupPortDescriptor) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) ProcessGroup(org.apache.nifi.groups.ProcessGroup) LabelDTO(org.apache.nifi.web.api.dto.LabelDTO) ProcessorInstantiationException(org.apache.nifi.controller.exception.ProcessorInstantiationException) ReportingTaskInstantiationException(org.apache.nifi.controller.reporting.ReportingTaskInstantiationException)

Example 14 with Position

use of org.apache.nifi.connectable.Position in project nifi by apache.

the class StandardFlowSynchronizer method addProcessGroup.

private ProcessGroup addProcessGroup(final FlowController controller, final ProcessGroup parentGroup, final Element processGroupElement, final StringEncryptor encryptor, final FlowEncodingVersion encodingVersion) throws ProcessorInstantiationException {
    // get the parent group ID
    final String parentId = (parentGroup == null) ? null : parentGroup.getIdentifier();
    // add the process group
    final ProcessGroupDTO processGroupDTO = FlowFromDOMFactory.getProcessGroup(parentId, processGroupElement, encryptor, encodingVersion);
    final ProcessGroup processGroup = controller.createProcessGroup(processGroupDTO.getId());
    processGroup.setComments(processGroupDTO.getComments());
    processGroup.setVersionedComponentId(processGroupDTO.getVersionedComponentId());
    processGroup.setPosition(toPosition(processGroupDTO.getPosition()));
    processGroup.setName(processGroupDTO.getName());
    processGroup.setParent(parentGroup);
    if (parentGroup == null) {
        controller.setRootGroup(processGroup);
    } else {
        parentGroup.addProcessGroup(processGroup);
    }
    // Set the variables for the variable registry
    final Map<String, String> variables = new HashMap<>();
    final List<Element> variableElements = getChildrenByTagName(processGroupElement, "variable");
    for (final Element variableElement : variableElements) {
        final String variableName = variableElement.getAttribute("name");
        final String variableValue = variableElement.getAttribute("value");
        if (variableName == null || variableValue == null) {
            continue;
        }
        variables.put(variableName, variableValue);
    }
    processGroup.setVariables(variables);
    final VersionControlInformationDTO versionControlInfoDto = processGroupDTO.getVersionControlInformation();
    if (versionControlInfoDto != null) {
        final FlowRegistry flowRegistry = controller.getFlowRegistryClient().getFlowRegistry(versionControlInfoDto.getRegistryId());
        final String registryName = flowRegistry == null ? versionControlInfoDto.getRegistryId() : flowRegistry.getName();
        versionControlInfoDto.setState(VersionedFlowState.SYNC_FAILURE.name());
        versionControlInfoDto.setStateExplanation("Process Group has not yet been synchronized with the Flow Registry");
        final StandardVersionControlInformation versionControlInformation = StandardVersionControlInformation.Builder.fromDto(versionControlInfoDto).registryName(registryName).build();
        // pass empty map for the version control mapping because the VersionedComponentId has already been set on the components
        processGroup.setVersionControlInformation(versionControlInformation, Collections.emptyMap());
    }
    // Add Controller Services
    final List<Element> serviceNodeList = getChildrenByTagName(processGroupElement, "controllerService");
    if (!serviceNodeList.isEmpty()) {
        final Map<ControllerServiceNode, Element> controllerServices = ControllerServiceLoader.loadControllerServices(serviceNodeList, controller, processGroup, encryptor);
        ControllerServiceLoader.enableControllerServices(controllerServices, controller, encryptor, autoResumeState);
    }
    // add processors
    final List<Element> processorNodeList = getChildrenByTagName(processGroupElement, "processor");
    for (final Element processorElement : processorNodeList) {
        final ProcessorDTO processorDTO = FlowFromDOMFactory.getProcessor(processorElement, encryptor);
        BundleCoordinate coordinate;
        try {
            coordinate = BundleUtils.getCompatibleBundle(processorDTO.getType(), processorDTO.getBundle());
        } catch (final IllegalStateException e) {
            final BundleDTO bundleDTO = processorDTO.getBundle();
            if (bundleDTO == null) {
                coordinate = BundleCoordinate.UNKNOWN_COORDINATE;
            } else {
                coordinate = new BundleCoordinate(bundleDTO.getGroup(), bundleDTO.getArtifact(), bundleDTO.getVersion());
            }
        }
        final ProcessorNode procNode = controller.createProcessor(processorDTO.getType(), processorDTO.getId(), coordinate, false);
        procNode.setVersionedComponentId(processorDTO.getVersionedComponentId());
        processGroup.addProcessor(procNode);
        updateProcessor(procNode, processorDTO, processGroup, controller);
    }
    // add input ports
    final List<Element> inputPortNodeList = getChildrenByTagName(processGroupElement, "inputPort");
    for (final Element inputPortElement : inputPortNodeList) {
        final PortDTO portDTO = FlowFromDOMFactory.getPort(inputPortElement);
        final Port port;
        if (processGroup.isRootGroup()) {
            port = controller.createRemoteInputPort(portDTO.getId(), portDTO.getName());
        } else {
            port = controller.createLocalInputPort(portDTO.getId(), portDTO.getName());
        }
        port.setVersionedComponentId(portDTO.getVersionedComponentId());
        port.setPosition(toPosition(portDTO.getPosition()));
        port.setComments(portDTO.getComments());
        port.setProcessGroup(processGroup);
        final Set<String> userControls = portDTO.getUserAccessControl();
        if (userControls != null && !userControls.isEmpty()) {
            if (!(port instanceof RootGroupPort)) {
                throw new IllegalStateException("Attempting to add User Access Controls to " + port.getIdentifier() + ", but it is not a RootGroupPort");
            }
            ((RootGroupPort) port).setUserAccessControl(userControls);
        }
        final Set<String> groupControls = portDTO.getGroupAccessControl();
        if (groupControls != null && !groupControls.isEmpty()) {
            if (!(port instanceof RootGroupPort)) {
                throw new IllegalStateException("Attempting to add Group Access Controls to " + port.getIdentifier() + ", but it is not a RootGroupPort");
            }
            ((RootGroupPort) port).setGroupAccessControl(groupControls);
        }
        processGroup.addInputPort(port);
        if (portDTO.getConcurrentlySchedulableTaskCount() != null) {
            port.setMaxConcurrentTasks(portDTO.getConcurrentlySchedulableTaskCount());
        }
        final ScheduledState scheduledState = ScheduledState.valueOf(portDTO.getState());
        if (ScheduledState.RUNNING.equals(scheduledState)) {
            controller.startConnectable(port);
        } else if (ScheduledState.DISABLED.equals(scheduledState)) {
            processGroup.disableInputPort(port);
        }
    }
    // add output ports
    final List<Element> outputPortNodeList = getChildrenByTagName(processGroupElement, "outputPort");
    for (final Element outputPortElement : outputPortNodeList) {
        final PortDTO portDTO = FlowFromDOMFactory.getPort(outputPortElement);
        final Port port;
        if (processGroup.isRootGroup()) {
            port = controller.createRemoteOutputPort(portDTO.getId(), portDTO.getName());
        } else {
            port = controller.createLocalOutputPort(portDTO.getId(), portDTO.getName());
        }
        port.setVersionedComponentId(portDTO.getVersionedComponentId());
        port.setPosition(toPosition(portDTO.getPosition()));
        port.setComments(portDTO.getComments());
        port.setProcessGroup(processGroup);
        final Set<String> userControls = portDTO.getUserAccessControl();
        if (userControls != null && !userControls.isEmpty()) {
            if (!(port instanceof RootGroupPort)) {
                throw new IllegalStateException("Attempting to add User Access Controls to " + port.getIdentifier() + ", but it is not a RootGroupPort");
            }
            ((RootGroupPort) port).setUserAccessControl(userControls);
        }
        final Set<String> groupControls = portDTO.getGroupAccessControl();
        if (groupControls != null && !groupControls.isEmpty()) {
            if (!(port instanceof RootGroupPort)) {
                throw new IllegalStateException("Attempting to add Group Access Controls to " + port.getIdentifier() + ", but it is not a RootGroupPort");
            }
            ((RootGroupPort) port).setGroupAccessControl(groupControls);
        }
        processGroup.addOutputPort(port);
        if (portDTO.getConcurrentlySchedulableTaskCount() != null) {
            port.setMaxConcurrentTasks(portDTO.getConcurrentlySchedulableTaskCount());
        }
        final ScheduledState scheduledState = ScheduledState.valueOf(portDTO.getState());
        if (ScheduledState.RUNNING.equals(scheduledState)) {
            controller.startConnectable(port);
        } else if (ScheduledState.DISABLED.equals(scheduledState)) {
            processGroup.disableOutputPort(port);
        }
    }
    // add funnels
    final List<Element> funnelNodeList = getChildrenByTagName(processGroupElement, "funnel");
    for (final Element funnelElement : funnelNodeList) {
        final FunnelDTO funnelDTO = FlowFromDOMFactory.getFunnel(funnelElement);
        final Funnel funnel = controller.createFunnel(funnelDTO.getId());
        funnel.setVersionedComponentId(funnelDTO.getVersionedComponentId());
        funnel.setPosition(toPosition(funnelDTO.getPosition()));
        // Since this is called during startup, we want to add the funnel without enabling it
        // and then tell the controller to enable it. This way, if the controller is not fully
        // initialized, the starting of the funnel is delayed until the controller is ready.
        processGroup.addFunnel(funnel, false);
        controller.startConnectable(funnel);
    }
    // add labels
    final List<Element> labelNodeList = getChildrenByTagName(processGroupElement, "label");
    for (final Element labelElement : labelNodeList) {
        final LabelDTO labelDTO = FlowFromDOMFactory.getLabel(labelElement);
        final Label label = controller.createLabel(labelDTO.getId(), labelDTO.getLabel());
        label.setVersionedComponentId(labelDTO.getVersionedComponentId());
        label.setStyle(labelDTO.getStyle());
        label.setPosition(toPosition(labelDTO.getPosition()));
        label.setSize(new Size(labelDTO.getWidth(), labelDTO.getHeight()));
        processGroup.addLabel(label);
    }
    // add nested process groups (recursively)
    final List<Element> nestedProcessGroupNodeList = getChildrenByTagName(processGroupElement, "processGroup");
    for (final Element nestedProcessGroupElement : nestedProcessGroupNodeList) {
        addProcessGroup(controller, processGroup, nestedProcessGroupElement, encryptor, encodingVersion);
    }
    // add remote process group
    final List<Element> remoteProcessGroupNodeList = getChildrenByTagName(processGroupElement, "remoteProcessGroup");
    for (final Element remoteProcessGroupElement : remoteProcessGroupNodeList) {
        final RemoteProcessGroupDTO remoteGroupDto = FlowFromDOMFactory.getRemoteProcessGroup(remoteProcessGroupElement, encryptor);
        final RemoteProcessGroup remoteGroup = controller.createRemoteProcessGroup(remoteGroupDto.getId(), remoteGroupDto.getTargetUris());
        remoteGroup.setVersionedComponentId(remoteGroupDto.getVersionedComponentId());
        remoteGroup.setComments(remoteGroupDto.getComments());
        remoteGroup.setPosition(toPosition(remoteGroupDto.getPosition()));
        final String name = remoteGroupDto.getName();
        if (name != null && !name.trim().isEmpty()) {
            remoteGroup.setName(name);
        }
        remoteGroup.setProcessGroup(processGroup);
        remoteGroup.setCommunicationsTimeout(remoteGroupDto.getCommunicationsTimeout());
        if (remoteGroupDto.getYieldDuration() != null) {
            remoteGroup.setYieldDuration(remoteGroupDto.getYieldDuration());
        }
        final String transportProtocol = remoteGroupDto.getTransportProtocol();
        if (transportProtocol != null && !transportProtocol.trim().isEmpty()) {
            remoteGroup.setTransportProtocol(SiteToSiteTransportProtocol.valueOf(transportProtocol.toUpperCase()));
        }
        if (remoteGroupDto.getProxyHost() != null) {
            remoteGroup.setProxyHost(remoteGroupDto.getProxyHost());
        }
        if (remoteGroupDto.getProxyPort() != null) {
            remoteGroup.setProxyPort(remoteGroupDto.getProxyPort());
        }
        if (remoteGroupDto.getProxyUser() != null) {
            remoteGroup.setProxyUser(remoteGroupDto.getProxyUser());
        }
        if (remoteGroupDto.getProxyPassword() != null) {
            remoteGroup.setProxyPassword(remoteGroupDto.getProxyPassword());
        }
        if (StringUtils.isBlank(remoteGroupDto.getLocalNetworkInterface())) {
            remoteGroup.setNetworkInterface(null);
        } else {
            remoteGroup.setNetworkInterface(remoteGroupDto.getLocalNetworkInterface());
        }
        final Set<RemoteProcessGroupPortDescriptor> inputPorts = new HashSet<>();
        for (final Element portElement : getChildrenByTagName(remoteProcessGroupElement, "inputPort")) {
            inputPorts.add(FlowFromDOMFactory.getRemoteProcessGroupPort(portElement));
        }
        remoteGroup.setInputPorts(inputPorts, false);
        final Set<RemoteProcessGroupPortDescriptor> outputPorts = new HashSet<>();
        for (final Element portElement : getChildrenByTagName(remoteProcessGroupElement, "outputPort")) {
            outputPorts.add(FlowFromDOMFactory.getRemoteProcessGroupPort(portElement));
        }
        remoteGroup.setOutputPorts(outputPorts, false);
        processGroup.addRemoteProcessGroup(remoteGroup);
        for (final RemoteProcessGroupPortDescriptor remoteGroupPortDTO : outputPorts) {
            final RemoteGroupPort port = remoteGroup.getOutputPort(remoteGroupPortDTO.getId());
            if (Boolean.TRUE.equals(remoteGroupPortDTO.isTransmitting())) {
                controller.startTransmitting(port);
            }
        }
        for (final RemoteProcessGroupPortDescriptor remoteGroupPortDTO : inputPorts) {
            final RemoteGroupPort port = remoteGroup.getInputPort(remoteGroupPortDTO.getId());
            if (Boolean.TRUE.equals(remoteGroupPortDTO.isTransmitting())) {
                controller.startTransmitting(port);
            }
        }
    }
    // add connections
    final List<Element> connectionNodeList = getChildrenByTagName(processGroupElement, "connection");
    for (final Element connectionElement : connectionNodeList) {
        final ConnectionDTO dto = FlowFromDOMFactory.getConnection(connectionElement);
        final Connectable source;
        final ConnectableDTO sourceDto = dto.getSource();
        if (ConnectableType.REMOTE_OUTPUT_PORT.name().equals(sourceDto.getType())) {
            final RemoteProcessGroup remoteGroup = processGroup.getRemoteProcessGroup(sourceDto.getGroupId());
            source = remoteGroup.getOutputPort(sourceDto.getId());
        } else {
            final ProcessGroup sourceGroup = controller.getGroup(sourceDto.getGroupId());
            if (sourceGroup == null) {
                throw new RuntimeException("Found Invalid ProcessGroup ID for Source: " + dto.getSource().getGroupId());
            }
            source = sourceGroup.getConnectable(sourceDto.getId());
        }
        if (source == null) {
            throw new RuntimeException("Found Invalid Connectable ID for Source: " + dto.getSource().getId());
        }
        final Connectable destination;
        final ConnectableDTO destinationDto = dto.getDestination();
        if (ConnectableType.REMOTE_INPUT_PORT.name().equals(destinationDto.getType())) {
            final RemoteProcessGroup remoteGroup = processGroup.getRemoteProcessGroup(destinationDto.getGroupId());
            destination = remoteGroup.getInputPort(destinationDto.getId());
        } else {
            final ProcessGroup destinationGroup = controller.getGroup(destinationDto.getGroupId());
            if (destinationGroup == null) {
                throw new RuntimeException("Found Invalid ProcessGroup ID for Destination: " + dto.getDestination().getGroupId());
            }
            destination = destinationGroup.getConnectable(destinationDto.getId());
        }
        if (destination == null) {
            throw new RuntimeException("Found Invalid Connectable ID for Destination: " + dto.getDestination().getId());
        }
        final Connection connection = controller.createConnection(dto.getId(), dto.getName(), source, destination, dto.getSelectedRelationships());
        connection.setVersionedComponentId(dto.getVersionedComponentId());
        connection.setProcessGroup(processGroup);
        final List<Position> bendPoints = new ArrayList<>();
        for (final PositionDTO bend : dto.getBends()) {
            bendPoints.add(new Position(bend.getX(), bend.getY()));
        }
        connection.setBendPoints(bendPoints);
        final Long zIndex = dto.getzIndex();
        if (zIndex != null) {
            connection.setZIndex(zIndex);
        }
        if (dto.getLabelIndex() != null) {
            connection.setLabelIndex(dto.getLabelIndex());
        }
        List<FlowFilePrioritizer> newPrioritizers = null;
        final List<String> prioritizers = dto.getPrioritizers();
        if (prioritizers != null) {
            final List<String> newPrioritizersClasses = new ArrayList<>(prioritizers);
            newPrioritizers = new ArrayList<>();
            for (final String className : newPrioritizersClasses) {
                try {
                    newPrioritizers.add(controller.createPrioritizer(className));
                } catch (final ClassNotFoundException | InstantiationException | IllegalAccessException e) {
                    throw new IllegalArgumentException("Unable to set prioritizer " + className + ": " + e);
                }
            }
        }
        if (newPrioritizers != null) {
            connection.getFlowFileQueue().setPriorities(newPrioritizers);
        }
        if (dto.getBackPressureObjectThreshold() != null) {
            connection.getFlowFileQueue().setBackPressureObjectThreshold(dto.getBackPressureObjectThreshold());
        }
        if (dto.getBackPressureDataSizeThreshold() != null) {
            connection.getFlowFileQueue().setBackPressureDataSizeThreshold(dto.getBackPressureDataSizeThreshold());
        }
        if (dto.getFlowFileExpiration() != null) {
            connection.getFlowFileQueue().setFlowFileExpiration(dto.getFlowFileExpiration());
        }
        processGroup.addConnection(connection);
    }
    final List<Element> templateNodeList = getChildrenByTagName(processGroupElement, "template");
    for (final Element templateNode : templateNodeList) {
        final TemplateDTO templateDTO = TemplateUtils.parseDto(templateNode);
        final Template template = new Template(templateDTO);
        processGroup.addTemplate(template);
    }
    return processGroup;
}
Also used : HashMap(java.util.HashMap) Size(org.apache.nifi.connectable.Size) ConnectionDTO(org.apache.nifi.web.api.dto.ConnectionDTO) TemplateDTO(org.apache.nifi.web.api.dto.TemplateDTO) RootGroupPort(org.apache.nifi.remote.RootGroupPort) Port(org.apache.nifi.connectable.Port) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort) Label(org.apache.nifi.controller.label.Label) ArrayList(java.util.ArrayList) BundleCoordinate(org.apache.nifi.bundle.BundleCoordinate) Connectable(org.apache.nifi.connectable.Connectable) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) RemoteProcessGroupDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO) BundleDTO(org.apache.nifi.web.api.dto.BundleDTO) ConnectableDTO(org.apache.nifi.web.api.dto.ConnectableDTO) HashSet(java.util.HashSet) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) Position(org.apache.nifi.connectable.Position) PortDTO(org.apache.nifi.web.api.dto.PortDTO) RemoteProcessGroupDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO) FunnelDTO(org.apache.nifi.web.api.dto.FunnelDTO) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) ProcessGroup(org.apache.nifi.groups.ProcessGroup) Funnel(org.apache.nifi.connectable.Funnel) StandardVersionControlInformation(org.apache.nifi.registry.flow.StandardVersionControlInformation) RootGroupPort(org.apache.nifi.remote.RootGroupPort) Element(org.w3c.dom.Element) FlowRegistry(org.apache.nifi.registry.flow.FlowRegistry) VersionControlInformationDTO(org.apache.nifi.web.api.dto.VersionControlInformationDTO) FlowFilePrioritizer(org.apache.nifi.flowfile.FlowFilePrioritizer) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort) Connection(org.apache.nifi.connectable.Connection) PositionDTO(org.apache.nifi.web.api.dto.PositionDTO) RemoteProcessGroupPortDescriptor(org.apache.nifi.groups.RemoteProcessGroupPortDescriptor) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) LabelDTO(org.apache.nifi.web.api.dto.LabelDTO) ProcessorInstantiationException(org.apache.nifi.controller.exception.ProcessorInstantiationException) ReportingTaskInstantiationException(org.apache.nifi.controller.reporting.ReportingTaskInstantiationException)

Example 15 with Position

use of org.apache.nifi.connectable.Position in project nifi by apache.

the class StandardFlowSerializer method addConnection.

private void addConnection(final Element parentElement, final Connection connection) {
    final Document doc = parentElement.getOwnerDocument();
    final Element element = doc.createElement("connection");
    parentElement.appendChild(element);
    addTextElement(element, "id", connection.getIdentifier());
    addTextElement(element, "versionedComponentId", connection.getVersionedComponentId());
    addTextElement(element, "name", connection.getName());
    final Element bendPointsElement = doc.createElement("bendPoints");
    element.appendChild(bendPointsElement);
    for (final Position bendPoint : connection.getBendPoints()) {
        addPosition(bendPointsElement, bendPoint, "bendPoint");
    }
    addTextElement(element, "labelIndex", connection.getLabelIndex());
    addTextElement(element, "zIndex", connection.getZIndex());
    final String sourceId = connection.getSource().getIdentifier();
    final ConnectableType sourceType = connection.getSource().getConnectableType();
    final String sourceGroupId;
    if (sourceType == ConnectableType.REMOTE_OUTPUT_PORT) {
        sourceGroupId = ((RemoteGroupPort) connection.getSource()).getRemoteProcessGroup().getIdentifier();
    } else {
        sourceGroupId = connection.getSource().getProcessGroup().getIdentifier();
    }
    final ConnectableType destinationType = connection.getDestination().getConnectableType();
    final String destinationId = connection.getDestination().getIdentifier();
    final String destinationGroupId;
    if (destinationType == ConnectableType.REMOTE_INPUT_PORT) {
        destinationGroupId = ((RemoteGroupPort) connection.getDestination()).getRemoteProcessGroup().getIdentifier();
    } else {
        destinationGroupId = connection.getDestination().getProcessGroup().getIdentifier();
    }
    addTextElement(element, "sourceId", sourceId);
    addTextElement(element, "sourceGroupId", sourceGroupId);
    addTextElement(element, "sourceType", sourceType.toString());
    addTextElement(element, "destinationId", destinationId);
    addTextElement(element, "destinationGroupId", destinationGroupId);
    addTextElement(element, "destinationType", destinationType.toString());
    for (final Relationship relationship : connection.getRelationships()) {
        addTextElement(element, "relationship", relationship.getName());
    }
    addTextElement(element, "maxWorkQueueSize", connection.getFlowFileQueue().getBackPressureObjectThreshold());
    addTextElement(element, "maxWorkQueueDataSize", connection.getFlowFileQueue().getBackPressureDataSizeThreshold());
    addTextElement(element, "flowFileExpiration", connection.getFlowFileQueue().getFlowFileExpiration());
    for (final FlowFilePrioritizer comparator : connection.getFlowFileQueue().getPriorities()) {
        final String className = comparator.getClass().getCanonicalName();
        addTextElement(element, "queuePrioritizerClass", className);
    }
    parentElement.appendChild(element);
}
Also used : Position(org.apache.nifi.connectable.Position) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort) Element(org.w3c.dom.Element) Relationship(org.apache.nifi.processor.Relationship) ConnectableType(org.apache.nifi.connectable.ConnectableType) FlowFilePrioritizer(org.apache.nifi.flowfile.FlowFilePrioritizer) Document(org.w3c.dom.Document)

Aggregations

Position (org.apache.nifi.connectable.Position)28 Port (org.apache.nifi.connectable.Port)10 ProcessGroup (org.apache.nifi.groups.ProcessGroup)10 RootGroupPort (org.apache.nifi.remote.RootGroupPort)10 ArrayList (java.util.ArrayList)9 Size (org.apache.nifi.connectable.Size)9 FlowFilePrioritizer (org.apache.nifi.flowfile.FlowFilePrioritizer)9 RemoteProcessGroup (org.apache.nifi.groups.RemoteProcessGroup)9 HashSet (java.util.HashSet)7 Funnel (org.apache.nifi.connectable.Funnel)7 Label (org.apache.nifi.controller.label.Label)7 Relationship (org.apache.nifi.processor.Relationship)7 RemoteGroupPort (org.apache.nifi.remote.RemoteGroupPort)7 BundleCoordinate (org.apache.nifi.bundle.BundleCoordinate)6 Connection (org.apache.nifi.connectable.Connection)5 ProcessorInstantiationException (org.apache.nifi.controller.exception.ProcessorInstantiationException)5 ControllerServiceNode (org.apache.nifi.controller.service.ControllerServiceNode)5 VersionedProcessGroup (org.apache.nifi.registry.flow.VersionedProcessGroup)5 Element (org.w3c.dom.Element)5 URL (java.net.URL)4