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);
}
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;
}
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());
}
}
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;
}
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;
}
Aggregations