use of org.apache.nifi.connectable.Port in project nifi by apache.
the class StandardInputPortDAO method verifyUpdate.
@Override
public void verifyUpdate(PortDTO portDTO) {
final Port inputPort = locatePort(portDTO.getId());
verifyUpdate(inputPort, portDTO);
}
use of org.apache.nifi.connectable.Port in project nifi by apache.
the class StandardOutputPortDAO method locatePort.
private Port locatePort(final String portId) {
final ProcessGroup rootGroup = flowController.getGroup(flowController.getRootGroupId());
final Port port = rootGroup.findOutputPort(portId);
if (port == null) {
throw new ResourceNotFoundException(String.format("Unable to find port with id '%s'.", portId));
} else {
return port;
}
}
use of org.apache.nifi.connectable.Port in project nifi by apache.
the class StandardOutputPortDAO method updatePort.
@Override
public Port updatePort(PortDTO portDTO) {
Port outputPort = locatePort(portDTO.getId());
// ensure we can do this update
verifyUpdate(outputPort, portDTO);
// handle state transition
if (portDTO.getState() != null) {
final ScheduledState purposedScheduledState = ScheduledState.valueOf(portDTO.getState());
// only attempt an action if it is changing
if (!purposedScheduledState.equals(outputPort.getScheduledState())) {
try {
// perform the appropriate action
switch(purposedScheduledState) {
case RUNNING:
outputPort.getProcessGroup().startOutputPort(outputPort);
break;
case STOPPED:
switch(outputPort.getScheduledState()) {
case RUNNING:
outputPort.getProcessGroup().stopOutputPort(outputPort);
break;
case DISABLED:
outputPort.getProcessGroup().enableOutputPort(outputPort);
break;
}
break;
case DISABLED:
outputPort.getProcessGroup().disableOutputPort(outputPort);
break;
}
} catch (IllegalStateException ise) {
throw new NiFiCoreException(ise.getMessage(), ise);
}
}
}
if (outputPort instanceof RootGroupPort) {
final RootGroupPort rootPort = (RootGroupPort) outputPort;
if (isNotNull(portDTO.getGroupAccessControl())) {
rootPort.setGroupAccessControl(portDTO.getGroupAccessControl());
}
if (isNotNull(portDTO.getUserAccessControl())) {
rootPort.setUserAccessControl(portDTO.getUserAccessControl());
}
}
// perform the configuration
final String name = portDTO.getName();
final String comments = portDTO.getComments();
final Integer concurrentTasks = portDTO.getConcurrentlySchedulableTaskCount();
if (isNotNull(portDTO.getPosition())) {
outputPort.setPosition(new Position(portDTO.getPosition().getX(), portDTO.getPosition().getY()));
}
if (isNotNull(name)) {
outputPort.setName(name);
}
if (isNotNull(comments)) {
outputPort.setComments(comments);
}
if (isNotNull(concurrentTasks)) {
outputPort.setMaxConcurrentTasks(concurrentTasks);
}
outputPort.getProcessGroup().onComponentModified();
return outputPort;
}
use of org.apache.nifi.connectable.Port in project nifi by apache.
the class StandardOutputPortDAO method verifyDelete.
@Override
public void verifyDelete(final String portId) {
final Port outputPort = locatePort(portId);
outputPort.verifyCanDelete();
}
use of org.apache.nifi.connectable.Port in project nifi by apache.
the class StandardOutputPortDAO method createPort.
@Override
public Port createPort(String groupId, PortDTO portDTO) {
if (isNotNull(portDTO.getParentGroupId()) && !flowController.areGroupsSame(groupId, portDTO.getParentGroupId())) {
throw new IllegalArgumentException("Cannot specify a different Parent Group ID than the Group to which the OutputPort is being added.");
}
// ensure the name has been specified
if (portDTO.getName() == null) {
throw new IllegalArgumentException("Port name must be specified.");
}
// get the desired group
ProcessGroup group = locateProcessGroup(flowController, groupId);
// determine if this is the root group
Port port;
if (group.getParent() == null) {
port = flowController.createRemoteOutputPort(portDTO.getId(), portDTO.getName());
} else {
port = flowController.createLocalOutputPort(portDTO.getId(), portDTO.getName());
}
// ensure we can perform the update before we add the processor to the flow
verifyUpdate(port, portDTO);
// configure
if (portDTO.getPosition() != null) {
port.setPosition(new Position(portDTO.getPosition().getX(), portDTO.getPosition().getY()));
}
port.setComments(portDTO.getComments());
// add the port
group.addOutputPort(port);
return port;
}
Aggregations