Search in sources :

Example 16 with RootGroupPort

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;
}
Also used : RootGroupPort(org.apache.nifi.remote.RootGroupPort) ArrayList(java.util.ArrayList) ValidationResult(org.apache.nifi.components.ValidationResult)

Example 17 with RootGroupPort

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());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(javax.ws.rs.core.Response) RootGroupPort(org.apache.nifi.remote.RootGroupPort) InputStream(java.io.InputStream) Peer(org.apache.nifi.remote.Peer) HttpRemoteSiteListener(org.apache.nifi.remote.HttpRemoteSiteListener) HttpFlowFileServerProtocol(org.apache.nifi.remote.protocol.http.HttpFlowFileServerProtocol) ServletContext(javax.servlet.ServletContext) Test(org.junit.Test)

Example 18 with RootGroupPort

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);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(javax.ws.rs.core.Response) HttpServerCommunicationsSession(org.apache.nifi.remote.io.http.HttpServerCommunicationsSession) RootGroupPort(org.apache.nifi.remote.RootGroupPort) InputStream(java.io.InputStream) Peer(org.apache.nifi.remote.Peer) HttpRemoteSiteListener(org.apache.nifi.remote.HttpRemoteSiteListener) HttpFlowFileServerProtocol(org.apache.nifi.remote.protocol.http.HttpFlowFileServerProtocol) ServletContext(javax.servlet.ServletContext) Test(org.junit.Test)

Example 19 with RootGroupPort

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;
}
Also used : RootGroupPort(org.apache.nifi.remote.RootGroupPort) ArrayList(java.util.ArrayList) ComponentSearchResultDTO(org.apache.nifi.web.api.dto.search.ComponentSearchResultDTO)

Example 20 with RootGroupPort

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;
}
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

RootGroupPort (org.apache.nifi.remote.RootGroupPort)21 Port (org.apache.nifi.connectable.Port)13 ProcessGroup (org.apache.nifi.groups.ProcessGroup)11 RemoteProcessGroup (org.apache.nifi.groups.RemoteProcessGroup)8 ArrayList (java.util.ArrayList)7 HashSet (java.util.HashSet)7 Connection (org.apache.nifi.connectable.Connection)7 RemoteGroupPort (org.apache.nifi.remote.RemoteGroupPort)7 PortAuthorizationResult (org.apache.nifi.remote.PortAuthorizationResult)6 NiFiUser (org.apache.nifi.authorization.user.NiFiUser)5 VersionedProcessGroup (org.apache.nifi.registry.flow.VersionedProcessGroup)5 Peer (org.apache.nifi.remote.Peer)5 Connectable (org.apache.nifi.connectable.Connectable)4 Funnel (org.apache.nifi.connectable.Funnel)4 Position (org.apache.nifi.connectable.Position)4 HttpServerCommunicationsSession (org.apache.nifi.remote.io.http.HttpServerCommunicationsSession)4 BundleCoordinate (org.apache.nifi.bundle.BundleCoordinate)3 ScheduledState (org.apache.nifi.controller.ScheduledState)3 Label (org.apache.nifi.controller.label.Label)3 ControllerServiceNode (org.apache.nifi.controller.service.ControllerServiceNode)3