Search in sources :

Example 21 with Position

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

the class PositionScaler method scale.

/**
 * Scales the {@link Position} of the given {@link Positionable} by the provided factor.  This method
 * replaces the {@link Position} in the {@link Positionable} with a new scaled {@link Position}.
 *
 * @param positionable containing a {@link Position} to scale
 * @param factorX      used to scale a {@link Positionable}'s X-coordinate position
 * @param factorY      used to scale a {@link Positionable}'s Y-coordinate position
 */
public static void scale(Positionable positionable, double factorX, double factorY) {
    final Position startingPosition = positionable.getPosition();
    final Position scaledPosition = scalePosition(startingPosition, factorX, factorY);
    positionable.setPosition(scaledPosition);
}
Also used : Position(org.apache.nifi.connectable.Position)

Example 22 with Position

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

the class DtoFactory method createConnectionDto.

/**
 * Creates a ConnectionDTO from the specified Connection.
 *
 * @param connection connection
 * @return dto
 */
public ConnectionDTO createConnectionDto(final Connection connection) {
    if (connection == null) {
        return null;
    }
    final ConnectionDTO dto = new ConnectionDTO();
    dto.setId(connection.getIdentifier());
    dto.setParentGroupId(connection.getProcessGroup().getIdentifier());
    final List<PositionDTO> bendPoints = new ArrayList<>();
    for (final Position bendPoint : connection.getBendPoints()) {
        bendPoints.add(createPositionDto(bendPoint));
    }
    dto.setBends(bendPoints);
    dto.setName(connection.getName());
    dto.setLabelIndex(connection.getLabelIndex());
    dto.setzIndex(connection.getZIndex());
    dto.setSource(createConnectableDto(connection.getSource()));
    dto.setDestination(createConnectableDto(connection.getDestination()));
    dto.setVersionedComponentId(connection.getVersionedComponentId().orElse(null));
    dto.setBackPressureObjectThreshold(connection.getFlowFileQueue().getBackPressureObjectThreshold());
    dto.setBackPressureDataSizeThreshold(connection.getFlowFileQueue().getBackPressureDataSizeThreshold());
    dto.setFlowFileExpiration(connection.getFlowFileQueue().getFlowFileExpiration());
    dto.setPrioritizers(new ArrayList<String>());
    for (final FlowFilePrioritizer comparator : connection.getFlowFileQueue().getPriorities()) {
        dto.getPrioritizers().add(comparator.getClass().getCanonicalName());
    }
    // For ports, we do not want to populate the relationships.
    for (final Relationship selectedRelationship : connection.getRelationships()) {
        if (!Relationship.ANONYMOUS.equals(selectedRelationship)) {
            if (dto.getSelectedRelationships() == null) {
                dto.setSelectedRelationships(new TreeSet<String>(Collator.getInstance(Locale.US)));
            }
            dto.getSelectedRelationships().add(selectedRelationship.getName());
        }
    }
    // For ports, we do not want to populate the relationships.
    for (final Relationship availableRelationship : connection.getSource().getRelationships()) {
        if (!Relationship.ANONYMOUS.equals(availableRelationship)) {
            if (dto.getAvailableRelationships() == null) {
                dto.setAvailableRelationships(new TreeSet<String>(Collator.getInstance(Locale.US)));
            }
            dto.getAvailableRelationships().add(availableRelationship.getName());
        }
    }
    return dto;
}
Also used : Position(org.apache.nifi.connectable.Position) Relationship(org.apache.nifi.processor.Relationship) ArrayList(java.util.ArrayList) FlowFilePrioritizer(org.apache.nifi.flowfile.FlowFilePrioritizer)

Example 23 with Position

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

the class StandardConnectionDAO method configureConnection.

/**
 * Configures the specified connection using the specified dto.
 */
private void configureConnection(Connection connection, ConnectionDTO connectionDTO) {
    // validate flow file comparators/prioritizers
    List<FlowFilePrioritizer> newPrioritizers = null;
    final List<String> prioritizers = connectionDTO.getPrioritizers();
    if (isNotNull(prioritizers)) {
        final List<String> newPrioritizersClasses = new ArrayList<>(prioritizers);
        newPrioritizers = new ArrayList<>();
        for (final String className : newPrioritizersClasses) {
            try {
                newPrioritizers.add(flowController.createPrioritizer(className));
            } catch (final ClassNotFoundException | InstantiationException | IllegalAccessException e) {
                throw new IllegalArgumentException("Unable to set prioritizer " + className + ": " + e);
            }
        }
    }
    // update connection queue
    if (isNotNull(connectionDTO.getFlowFileExpiration())) {
        connection.getFlowFileQueue().setFlowFileExpiration(connectionDTO.getFlowFileExpiration());
    }
    if (isNotNull(connectionDTO.getBackPressureObjectThreshold())) {
        connection.getFlowFileQueue().setBackPressureObjectThreshold(connectionDTO.getBackPressureObjectThreshold());
    }
    if (isNotNull(connectionDTO.getBackPressureDataSizeThreshold())) {
        connection.getFlowFileQueue().setBackPressureDataSizeThreshold(connectionDTO.getBackPressureDataSizeThreshold());
    }
    if (isNotNull(newPrioritizers)) {
        connection.getFlowFileQueue().setPriorities(newPrioritizers);
    }
    // update the connection state
    if (isNotNull(connectionDTO.getBends())) {
        final List<Position> bendPoints = new ArrayList<>();
        for (final PositionDTO bend : connectionDTO.getBends()) {
            if (bend != null) {
                bendPoints.add(new Position(bend.getX(), bend.getY()));
            }
        }
        connection.setBendPoints(bendPoints);
    }
    if (isNotNull(connectionDTO.getName())) {
        connection.setName(connectionDTO.getName());
    }
    if (isNotNull(connectionDTO.getLabelIndex())) {
        connection.setLabelIndex(connectionDTO.getLabelIndex());
    }
    if (isNotNull(connectionDTO.getzIndex())) {
        connection.setZIndex(connectionDTO.getzIndex());
    }
}
Also used : Position(org.apache.nifi.connectable.Position) ArrayList(java.util.ArrayList) PositionDTO(org.apache.nifi.web.api.dto.PositionDTO) FlowFilePrioritizer(org.apache.nifi.flowfile.FlowFilePrioritizer)

Example 24 with Position

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

the class StandardFunnelDAO method createFunnel.

@Override
public Funnel createFunnel(String groupId, FunnelDTO funnelDTO) {
    if (funnelDTO.getParentGroupId() != null && !flowController.areGroupsSame(groupId, funnelDTO.getParentGroupId())) {
        throw new IllegalArgumentException("Cannot specify a different Parent Group ID than the Group to which the Funnel is being added.");
    }
    // get the desired group
    ProcessGroup group = locateProcessGroup(flowController, groupId);
    // create the funnel
    Funnel funnel = flowController.createFunnel(funnelDTO.getId());
    if (funnelDTO.getPosition() != null) {
        funnel.setPosition(new Position(funnelDTO.getPosition().getX(), funnelDTO.getPosition().getY()));
    }
    // add the funnel
    group.addFunnel(funnel);
    group.startFunnel(funnel);
    return funnel;
}
Also used : Funnel(org.apache.nifi.connectable.Funnel) Position(org.apache.nifi.connectable.Position) ProcessGroup(org.apache.nifi.groups.ProcessGroup)

Example 25 with Position

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

the class StandardInputPortDAO method updatePort.

@Override
public Port updatePort(PortDTO portDTO) {
    Port inputPort = locatePort(portDTO.getId());
    // ensure we can do this update
    verifyUpdate(inputPort, portDTO);
    // handle state transition
    if (isNotNull(portDTO.getState())) {
        final ScheduledState purposedScheduledState = ScheduledState.valueOf(portDTO.getState());
        // only attempt an action if it is changing
        if (!purposedScheduledState.equals(inputPort.getScheduledState())) {
            try {
                // perform the appropriate action
                switch(purposedScheduledState) {
                    case RUNNING:
                        inputPort.getProcessGroup().startInputPort(inputPort);
                        break;
                    case STOPPED:
                        switch(inputPort.getScheduledState()) {
                            case RUNNING:
                                inputPort.getProcessGroup().stopInputPort(inputPort);
                                break;
                            case DISABLED:
                                inputPort.getProcessGroup().enableInputPort(inputPort);
                                break;
                        }
                        break;
                    case DISABLED:
                        inputPort.getProcessGroup().disableInputPort(inputPort);
                        break;
                }
            } catch (IllegalStateException ise) {
                throw new NiFiCoreException(ise.getMessage(), ise);
            }
        }
    }
    if (inputPort instanceof RootGroupPort) {
        final RootGroupPort rootPort = (RootGroupPort) inputPort;
        if (isNotNull(portDTO.getGroupAccessControl())) {
            rootPort.setGroupAccessControl(portDTO.getGroupAccessControl());
        }
        if (isNotNull(portDTO.getUserAccessControl())) {
            rootPort.setUserAccessControl(portDTO.getUserAccessControl());
        }
    }
    // update the port
    final String name = portDTO.getName();
    final String comments = portDTO.getComments();
    final Integer concurrentTasks = portDTO.getConcurrentlySchedulableTaskCount();
    if (isNotNull(portDTO.getPosition())) {
        inputPort.setPosition(new Position(portDTO.getPosition().getX(), portDTO.getPosition().getY()));
    }
    if (isNotNull(name)) {
        inputPort.setName(name);
    }
    if (isNotNull(comments)) {
        inputPort.setComments(comments);
    }
    if (isNotNull(concurrentTasks)) {
        inputPort.setMaxConcurrentTasks(concurrentTasks);
    }
    inputPort.getProcessGroup().onComponentModified();
    return inputPort;
}
Also used : NiFiCoreException(org.apache.nifi.web.NiFiCoreException) ScheduledState(org.apache.nifi.controller.ScheduledState) RootGroupPort(org.apache.nifi.remote.RootGroupPort) Position(org.apache.nifi.connectable.Position) Port(org.apache.nifi.connectable.Port) RootGroupPort(org.apache.nifi.remote.RootGroupPort)

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