use of org.apache.nifi.remote.RootGroupPort in project nifi by apache.
the class DtoFactory method createPortDto.
/**
* Creates a PortDTO from the specified Port.
*
* @param port port
* @return dto
*/
public PortDTO createPortDto(final Port port) {
if (port == null) {
return null;
}
final PortDTO dto = new PortDTO();
dto.setId(port.getIdentifier());
dto.setPosition(createPositionDto(port.getPosition()));
dto.setName(port.getName());
dto.setComments(port.getComments());
dto.setConcurrentlySchedulableTaskCount(port.getMaxConcurrentTasks());
dto.setParentGroupId(port.getProcessGroup().getIdentifier());
dto.setState(port.getScheduledState().toString());
dto.setType(port.getConnectableType().name());
dto.setVersionedComponentId(port.getVersionedComponentId().orElse(null));
// if this port is on the root group, determine if its actually connected to another nifi
if (port instanceof RootGroupPort) {
final RootGroupPort rootGroupPort = (RootGroupPort) port;
dto.setTransmitting(rootGroupPort.isTransmitting());
dto.setGroupAccessControl(rootGroupPort.getGroupAccessControl());
dto.setUserAccessControl(rootGroupPort.getUserAccessControl());
}
final Collection<ValidationResult> validationErrors = port.getValidationErrors();
if (validationErrors != null && !validationErrors.isEmpty()) {
final List<String> errors = new ArrayList<>();
for (final ValidationResult validationResult : validationErrors) {
errors.add(validationResult.toString());
}
dto.setValidationErrors(errors);
}
return dto;
}
use of org.apache.nifi.remote.RootGroupPort in project nifi by apache.
the class TestDataTransferResource method testReceiveZeroFlowFiles.
@Test
public void testReceiveZeroFlowFiles() throws Exception {
final HttpServletRequest req = createCommonHttpServletRequest();
final DataTransferResource resource = getDataTransferResource();
final HttpFlowFileServerProtocol serverProtocol = resource.getHttpFlowFileServerProtocol(null);
final RootGroupPort port = mock(RootGroupPort.class);
doReturn(port).when(serverProtocol).getPort();
doAnswer(invocation -> 0).when(port).receiveFlowFiles(any(Peer.class), any());
final ServletContext context = null;
final InputStream inputStream = null;
final HttpRemoteSiteListener transactionManager = HttpRemoteSiteListener.getInstance(NiFiProperties.createBasicNiFiProperties(null, null));
final String transactionId = transactionManager.createTransaction();
final Response response = resource.receiveFlowFiles("port-id", transactionId, req, context, inputStream);
transactionManager.cancelTransaction(transactionId);
assertEquals(400, response.getStatus());
}
use of org.apache.nifi.remote.RootGroupPort in project nifi by apache.
the class TestDataTransferResource method testReceiveFlowFiles.
@Test
public void testReceiveFlowFiles() throws Exception {
final HttpServletRequest req = createCommonHttpServletRequest();
final DataTransferResource resource = getDataTransferResource();
final HttpFlowFileServerProtocol serverProtocol = resource.getHttpFlowFileServerProtocol(null);
final RootGroupPort port = mock(RootGroupPort.class);
doReturn(port).when(serverProtocol).getPort();
doAnswer(invocation -> {
Peer peer = (Peer) invocation.getArguments()[0];
((HttpServerCommunicationsSession) peer.getCommunicationsSession()).setChecksum("server-checksum");
return 7;
}).when(port).receiveFlowFiles(any(Peer.class), any());
final ServletContext context = null;
final InputStream inputStream = null;
final HttpRemoteSiteListener transactionManager = HttpRemoteSiteListener.getInstance(NiFiProperties.createBasicNiFiProperties(null, null));
final String transactionId = transactionManager.createTransaction();
final Response response = resource.receiveFlowFiles("port-id", transactionId, req, context, inputStream);
transactionManager.cancelTransaction(transactionId);
final Object entity = response.getEntity();
assertEquals(202, response.getStatus());
assertEquals("server-checksum", entity);
}
use of org.apache.nifi.remote.RootGroupPort in project nifi by apache.
the class ControllerSearchService method search.
private ComponentSearchResultDTO search(final String searchStr, final Port port) {
final List<String> matches = new ArrayList<>();
addIfAppropriate(searchStr, port.getIdentifier(), "Id", matches);
addIfAppropriate(searchStr, port.getVersionedComponentId().orElse(null), "Version Control ID", matches);
addIfAppropriate(searchStr, port.getName(), "Name", matches);
addIfAppropriate(searchStr, port.getComments(), "Comments", matches);
// consider scheduled state
if (ScheduledState.DISABLED.equals(port.getScheduledState())) {
if (StringUtils.containsIgnoreCase("disabled", searchStr)) {
matches.add("Run status: Disabled");
}
} else {
if (StringUtils.containsIgnoreCase("invalid", searchStr) && !port.isValid()) {
matches.add("Run status: Invalid");
} else if (ScheduledState.RUNNING.equals(port.getScheduledState()) && StringUtils.containsIgnoreCase("running", searchStr)) {
matches.add("Run status: Running");
} else if (ScheduledState.STOPPED.equals(port.getScheduledState()) && StringUtils.containsIgnoreCase("stopped", searchStr)) {
matches.add("Run status: Stopped");
}
}
if (port instanceof RootGroupPort) {
final RootGroupPort rootGroupPort = (RootGroupPort) port;
// user access controls
for (final String userAccessControl : rootGroupPort.getUserAccessControl()) {
addIfAppropriate(searchStr, userAccessControl, "User access control", matches);
}
// group access controls
for (final String groupAccessControl : rootGroupPort.getGroupAccessControl()) {
addIfAppropriate(searchStr, groupAccessControl, "Group access control", matches);
}
}
if (matches.isEmpty()) {
return null;
}
final ComponentSearchResultDTO dto = new ComponentSearchResultDTO();
dto.setId(port.getIdentifier());
dto.setName(port.getName());
dto.setMatches(matches);
return dto;
}
use of org.apache.nifi.remote.RootGroupPort 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