org.apache.nifi.remote.RemoteGroupPort Java Examples

The following examples show how to use org.apache.nifi.remote.RemoteGroupPort. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestRemoteProcessGroupAuditor.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testConfigurePortCompression() throws Throwable {

    final RemoteGroupPort existingRPGPort = defaultRemoteGroupPort();
    when(existingRPGPort.getName()).thenReturn("input-port-1");

    final RemoteProcessGroupPortDTO inputRPGPortDTO = defaultRemoteProcessGroupPortDTO();
    inputRPGPortDTO.setUseCompression(true);

    final Collection<Action> actions = updateProcessGroupInputPortConfiguration(inputRPGPortDTO, existingRPGPort);

    assertEquals(1, actions.size());
    final Action action = actions.iterator().next();
    assertEquals(Operation.Configure, action.getOperation());
    assertConfigureDetails(action.getActionDetails(), "input-port-1.Compressed", "false", "true");

}
 
Example #2
Source File: StandardRemoteProcessGroupDAO.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public RemoteGroupPort updateRemoteProcessGroupOutputPort(String remoteProcessGroupId, RemoteProcessGroupPortDTO remoteProcessGroupPortDto) {
    final RemoteProcessGroup remoteProcessGroup = locateRemoteProcessGroup(remoteProcessGroupId);
    final RemoteGroupPort port = remoteProcessGroup.getOutputPort(remoteProcessGroupPortDto.getId());

    if (port == null) {
        throw new ResourceNotFoundException(
                String.format("Unable to find remote process group output port with id '%s'.", remoteProcessGroupId));
    }

    // verify the update
    verifyUpdatePort(port, remoteProcessGroupPortDto);

    // perform the update
    updatePort(port, remoteProcessGroupPortDto, remoteProcessGroup);
    remoteProcessGroup.getProcessGroup().onComponentModified();

    return port;
}
 
Example #3
Source File: StandardRemoteProcessGroupDAO.java    From nifi with Apache License 2.0 6 votes vote down vote up
/**
 *
 * @param port Port instance to be updated.
 * @param remoteProcessGroupPortDto DTO containing updated remote process group port settings.
 * @param remoteProcessGroup If remoteProcessGroupPortDto has updated isTransmitting input,
 *                           this method will start or stop the port in this remoteProcessGroup as necessary.
 */
private void updatePort(RemoteGroupPort port, RemoteProcessGroupPortDTO remoteProcessGroupPortDto, RemoteProcessGroup remoteProcessGroup) {
    if (isNotNull(remoteProcessGroupPortDto.getConcurrentlySchedulableTaskCount())) {
        port.setMaxConcurrentTasks(remoteProcessGroupPortDto.getConcurrentlySchedulableTaskCount());
    }
    if (isNotNull(remoteProcessGroupPortDto.getUseCompression())) {
        port.setUseCompression(remoteProcessGroupPortDto.getUseCompression());
    }

    final BatchSettingsDTO batchSettingsDTO = remoteProcessGroupPortDto.getBatchSettings();
    if (isNotNull(batchSettingsDTO)) {
        port.setBatchCount(batchSettingsDTO.getCount());
        port.setBatchSize(batchSettingsDTO.getSize());
        port.setBatchDuration(batchSettingsDTO.getDuration());
    }

    final Boolean isTransmitting = remoteProcessGroupPortDto.isTransmitting();
    if (isNotNull(isTransmitting)) {
        // start or stop as necessary
        if (!port.isRunning() && isTransmitting) {
            remoteProcessGroup.startTransmitting(port);
        } else if (port.isRunning() && !isTransmitting) {
            remoteProcessGroup.stopTransmitting(port);
        }
    }
}
 
Example #4
Source File: StandardRemoteProcessGroupDAO.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public RemoteGroupPort updateRemoteProcessGroupInputPort(String remoteProcessGroupId, RemoteProcessGroupPortDTO remoteProcessGroupPortDto) {
    final RemoteProcessGroup remoteProcessGroup = locateRemoteProcessGroup(remoteProcessGroupId);
    final RemoteGroupPort port = remoteProcessGroup.getInputPort(remoteProcessGroupPortDto.getId());

    if (port == null) {
        throw new ResourceNotFoundException(
                String.format("Unable to find remote process group input port with id '%s'.", remoteProcessGroupPortDto.getId()));
    }

    // verify the update
    verifyUpdatePort(port, remoteProcessGroupPortDto);

    // perform the update
    updatePort(port, remoteProcessGroupPortDto, remoteProcessGroup);

    remoteProcessGroup.getProcessGroup().onComponentModified();
    return port;
}
 
Example #5
Source File: StandardRemoteProcessGroupDAO.java    From nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Verified the specified remote port can be updated, if necessary.
 */
private void verifyUpdatePort(RemoteGroupPort port, RemoteProcessGroupPortDTO remoteProcessGroupPortDto) {
    // see if the remote process group can start/stop transmitting
    if (isNotNull(remoteProcessGroupPortDto.isTransmitting())) {
        if (!port.isRunning() && remoteProcessGroupPortDto.isTransmitting()) {
            port.verifyCanStart();
        } else if (port.isRunning() && !remoteProcessGroupPortDto.isTransmitting()) {
            port.verifyCanStop();
        }
    }

    // validate the proposed configuration
    final List<String> requestValidation = validateProposedRemoteProcessGroupPortConfiguration(port, remoteProcessGroupPortDto);
    // ensure there was no validation errors
    if (!requestValidation.isEmpty()) {
        throw new ValidationException(requestValidation);
    }


    // verify update when appropriate
    if (isAnyNotNull(remoteProcessGroupPortDto.getConcurrentlySchedulableTaskCount(),
            remoteProcessGroupPortDto.getUseCompression(),
            remoteProcessGroupPortDto.getBatchSettings())) {
        port.verifyCanUpdate();
    }
}
 
Example #6
Source File: StandardRemoteProcessGroupDAO.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Verified the specified remote port can be updated, if necessary.
 */
private void verifyUpdatePort(RemoteGroupPort port, RemoteProcessGroupPortDTO remoteProcessGroupPortDto) {
    // see if the remote process group can start/stop transmitting
    if (isNotNull(remoteProcessGroupPortDto.isTransmitting())) {
        if (!port.isRunning() && remoteProcessGroupPortDto.isTransmitting()) {
            port.verifyCanStart();
        } else if (port.isRunning() && !remoteProcessGroupPortDto.isTransmitting()) {
            port.verifyCanStop();
        }
    }

    // validate the proposed configuration
    final List<String> requestValidation = validateProposedRemoteProcessGroupPortConfiguration(port, remoteProcessGroupPortDto);
    // ensure there was no validation errors
    if (!requestValidation.isEmpty()) {
        throw new ValidationException(requestValidation);
    }


    // verify update when appropriate
    if (isAnyNotNull(remoteProcessGroupPortDto.getConcurrentlySchedulableTaskCount(), remoteProcessGroupPortDto.getUseCompression())) {
        port.verifyCanUpdate();
    }
}
 
Example #7
Source File: TestRemoteProcessGroupAuditor.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testEnablePort() throws Throwable {

    final RemoteGroupPort existingRPGPort = defaultRemoteGroupPort();
    when(existingRPGPort.getName()).thenReturn("input-port-1");
    when(existingRPGPort.isRunning()).thenReturn(false);

    final RemoteProcessGroupPortDTO inputRPGPortDTO = defaultRemoteProcessGroupPortDTO();
    inputRPGPortDTO.setTransmitting(true);

    final Collection<Action> actions = updateProcessGroupInputPortConfiguration(inputRPGPortDTO, existingRPGPort);

    assertEquals(1, actions.size());
    final Action action = actions.iterator().next();
    assertEquals(Operation.Configure, action.getOperation());
    assertConfigureDetails(action.getActionDetails(), "input-port-1.Transmission", "disabled", "enabled");

}
 
Example #8
Source File: TestRemoteProcessGroupAuditor.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testEnablePort() throws Throwable {

    final RemoteGroupPort existingRPGPort = defaultRemoteGroupPort();
    when(existingRPGPort.getName()).thenReturn("input-port-1");
    when(existingRPGPort.isRunning()).thenReturn(false);

    final RemoteProcessGroupPortDTO inputRPGPortDTO = defaultRemoteProcessGroupPortDTO();
    inputRPGPortDTO.setTransmitting(true);

    final Collection<Action> actions = updateProcessGroupInputPortConfiguration(inputRPGPortDTO, existingRPGPort);

    assertEquals(1, actions.size());
    final Action action = actions.iterator().next();
    assertEquals(Operation.Configure, action.getOperation());
    assertConfigureDetails(action.getActionDetails(), "input-port-1.Transmission", "disabled", "enabled");

}
 
Example #9
Source File: TestRemoteProcessGroupAuditor.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testDisablePort() throws Throwable {

    final RemoteGroupPort existingRPGPort = defaultRemoteGroupPort();
    when(existingRPGPort.getName()).thenReturn("input-port-1");
    when(existingRPGPort.isRunning()).thenReturn(true);

    final RemoteProcessGroupPortDTO inputRPGPortDTO = defaultRemoteProcessGroupPortDTO();
    inputRPGPortDTO.setTransmitting(false);

    final Collection<Action> actions = updateProcessGroupInputPortConfiguration(inputRPGPortDTO, existingRPGPort);

    assertEquals(1, actions.size());
    final Action action = actions.iterator().next();
    assertEquals(Operation.Configure, action.getOperation());
    assertConfigureDetails(action.getActionDetails(), "input-port-1.Transmission", "enabled", "disabled");

}
 
Example #10
Source File: TestRemoteProcessGroupAuditor.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testConfigurePortConcurrency() throws Throwable {

    final RemoteGroupPort existingRPGPort = defaultRemoteGroupPort();
    when(existingRPGPort.getName()).thenReturn("input-port-1");

    final RemoteProcessGroupPortDTO inputRPGPortDTO = defaultRemoteProcessGroupPortDTO();
    inputRPGPortDTO.setConcurrentlySchedulableTaskCount(2);

    final Collection<Action> actions = updateProcessGroupInputPortConfiguration(inputRPGPortDTO, existingRPGPort);

    assertEquals(1, actions.size());
    final Action action = actions.iterator().next();
    assertEquals(Operation.Configure, action.getOperation());
    assertConfigureDetails(action.getActionDetails(), "input-port-1.Concurrent Tasks", "1", "2");

}
 
Example #11
Source File: TestRemoteProcessGroupAuditor.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testConfigurePortConcurrency() throws Throwable {

    final RemoteGroupPort existingRPGPort = defaultRemoteGroupPort();
    when(existingRPGPort.getName()).thenReturn("input-port-1");

    final RemoteProcessGroupPortDTO inputRPGPortDTO = defaultRemoteProcessGroupPortDTO();
    inputRPGPortDTO.setConcurrentlySchedulableTaskCount(2);

    final Collection<Action> actions = updateProcessGroupInputPortConfiguration(inputRPGPortDTO, existingRPGPort);

    assertEquals(1, actions.size());
    final Action action = actions.iterator().next();
    assertEquals(Operation.Configure, action.getOperation());
    assertConfigureDetails(action.getActionDetails(), "input-port-1.Concurrent Tasks", "1", "2");

}
 
Example #12
Source File: DtoFactory.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
public RemoteProcessGroupPortDTO createRemoteProcessGroupPortDto(final RemoteGroupPort port) {
    if (port == null) {
        return null;
    }

    final RemoteProcessGroupPortDTO dto = new RemoteProcessGroupPortDTO();
    dto.setId(port.getIdentifier());
    dto.setName(port.getName());
    dto.setComments(port.getComments());
    dto.setTransmitting(port.isRunning());
    dto.setTargetRunning(port.isTargetRunning());
    dto.setConcurrentlySchedulableTaskCount(port.getMaxConcurrentTasks());
    dto.setUseCompression(port.isUseCompression());
    dto.setExists(port.getTargetExists());

    // determine if this port is currently connected to another component locally
    if (ConnectableType.REMOTE_OUTPUT_PORT.equals(port.getConnectableType())) {
        dto.setConnected(!port.getConnections().isEmpty());
    } else {
        dto.setConnected(port.hasIncomingConnection());
    }

    return dto;
}
 
Example #13
Source File: TestRemoteProcessGroupAuditor.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testConfigurePortCompression() throws Throwable {

    final RemoteGroupPort existingRPGPort = defaultRemoteGroupPort();
    when(existingRPGPort.getName()).thenReturn("input-port-1");

    final RemoteProcessGroupPortDTO inputRPGPortDTO = defaultRemoteProcessGroupPortDTO();
    inputRPGPortDTO.setUseCompression(true);

    final Collection<Action> actions = updateProcessGroupInputPortConfiguration(inputRPGPortDTO, existingRPGPort);

    assertEquals(1, actions.size());
    final Action action = actions.iterator().next();
    assertEquals(Operation.Configure, action.getOperation());
    assertConfigureDetails(action.getActionDetails(), "input-port-1.Compressed", "false", "true");

}
 
Example #14
Source File: StandardProcessGroup.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
private static RemoteGroupPort findRemoteGroupPort(final String identifier, final ProcessGroup group) {
    for (final RemoteProcessGroup remoteGroup : group.getRemoteProcessGroups()) {
        final RemoteGroupPort remoteInPort = remoteGroup.getInputPort(identifier);
        if (remoteInPort != null) {
            return remoteInPort;
        }

        final RemoteGroupPort remoteOutPort = remoteGroup.getOutputPort(identifier);
        if (remoteOutPort != null) {
            return remoteOutPort;
        }
    }

    for (final ProcessGroup childGroup : group.getProcessGroups()) {
        final RemoteGroupPort childGroupRemoteGroupPort = findRemoteGroupPort(identifier, childGroup);
        if (childGroupRemoteGroupPort != null) {
            return childGroupRemoteGroupPort;
        }
    }

    return null;
}
 
Example #15
Source File: RelationshipAuditor.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Determines the type of component the specified connectable is.
 */
private Component determineConnectableType(Connectable connectable) {
    String sourceId = connectable.getIdentifier();
    Component componentType = Component.Controller;
    if (connectable instanceof ProcessorNode) {
        componentType = Component.Processor;
    } else if (connectable instanceof RemoteGroupPort) {
        final RemoteGroupPort remoteGroupPort = (RemoteGroupPort) connectable;
        if (TransferDirection.RECEIVE.equals(remoteGroupPort.getTransferDirection())) {
            if (remoteGroupPort.getRemoteProcessGroup() == null) {
                componentType = Component.InputPort;
            } else {
                componentType = Component.OutputPort;
            }
        } else {
            if (remoteGroupPort.getRemoteProcessGroup() == null) {
                componentType = Component.OutputPort;
            } else {
                componentType = Component.InputPort;
            }
        }
    } else if (connectable instanceof Port) {
        ProcessGroup processGroup = connectable.getProcessGroup();
        if (processGroup.getInputPort(sourceId) != null) {
            componentType = Component.InputPort;
        } else if (processGroup.getOutputPort(sourceId) != null) {
            componentType = Component.OutputPort;
        }
    } else if (connectable instanceof Funnel) {
        componentType = Component.Funnel;
    }
    return componentType;
}
 
Example #16
Source File: FlowController.java    From nifi with Apache License 2.0 5 votes vote down vote up
public void stopTransmitting(final RemoteGroupPort remoteGroupPort) {
    writeLock.lock();
    try {
        if (initialized.get()) {
            remoteGroupPort.getRemoteProcessGroup().stopTransmitting(remoteGroupPort);
        } else {
            startRemoteGroupPortsAfterInitialization.remove(remoteGroupPort);
        }
    } finally {
        writeLock.unlock("stopTransmitting");
    }
}
 
Example #17
Source File: FlowController.java    From nifi with Apache License 2.0 5 votes vote down vote up
public void startTransmitting(final RemoteGroupPort remoteGroupPort) {
    writeLock.lock();
    try {
        if (initialized.get()) {
            remoteGroupPort.getRemoteProcessGroup().startTransmitting(remoteGroupPort);
        } else {
            startRemoteGroupPortsAfterInitialization.add(remoteGroupPort);
        }
    } finally {
        writeLock.unlock("startTransmitting");
    }
}
 
Example #18
Source File: NiFiRegistryFlowMapperTest.java    From nifi with Apache License 2.0 5 votes vote down vote up
private RemoteGroupPort prepareRemoteGroupPort(final RemoteProcessGroup remoteProcessGroup) {
    final RemoteGroupPort remoteGroupPort = mock(RemoteGroupPort.class);
    prepareComponentAuthorizable(remoteGroupPort, remoteProcessGroup.getIdentifier());
    when(remoteGroupPort.getName()).thenReturn("remotePort" + (counter++));
    when(remoteGroupPort.getRemoteProcessGroup()).thenReturn(remoteProcessGroup);
    return remoteGroupPort;
}
 
Example #19
Source File: NiFiRegistryFlowMapper.java    From nifi with Apache License 2.0 5 votes vote down vote up
public ConnectableComponent mapConnectable(final Connectable connectable) {
    final ConnectableComponent component = new InstantiatedConnectableComponent(connectable.getIdentifier(), connectable.getProcessGroupIdentifier());

    final String versionedId = getIdOrThrow(connectable.getVersionedComponentId(), connectable.getIdentifier(),
        () -> new IllegalArgumentException("Unable to map Connectable Component with identifier " + connectable.getIdentifier() + " to any version-controlled component"));
    component.setId(versionedId);

    component.setComments(connectable.getComments());

    final String groupId;
    if (connectable instanceof RemoteGroupPort) {
        final RemoteGroupPort port = (RemoteGroupPort) connectable;
        final RemoteProcessGroup rpg = port.getRemoteProcessGroup();
        final Optional<String> rpgVersionedId = rpg.getVersionedComponentId();
        groupId = getIdOrThrow(rpgVersionedId, rpg.getIdentifier(),
            () -> new IllegalArgumentException("Unable to find the Versioned Component ID for Remote Process Group that " + connectable + " belongs to"));

    } else {
        groupId = getIdOrThrow(connectable.getProcessGroup().getVersionedComponentId(), connectable.getProcessGroupIdentifier(),
            () -> new IllegalArgumentException("Unable to find the Versioned Component ID for the Process Group that " + connectable + " belongs to"));
    }

    component.setGroupId(groupId);

    component.setName(connectable.getName());
    component.setType(ConnectableComponentType.valueOf(connectable.getConnectableType().name()));
    return component;
}
 
Example #20
Source File: StandardFlowSerializer.java    From nifi with Apache License 2.0 5 votes vote down vote up
private void addRemoteGroupPort(final Element parentElement, final RemoteGroupPort port, final String elementName, final ScheduledStateLookup scheduledStateLookup) {
    final Document doc = parentElement.getOwnerDocument();
    final Element element = doc.createElement(elementName);
    parentElement.appendChild(element);
    addTextElement(element, "id", port.getIdentifier());
    addTextElement(element, "versionedComponentId", port.getVersionedComponentId());
    addTextElement(element, "name", port.getName());
    addPosition(element, port.getPosition());
    addTextElement(element, "comments", port.getComments());
    addTextElement(element, "scheduledState", scheduledStateLookup.getScheduledState(port).name());
    addTextElement(element, "targetId", port.getTargetIdentifier());
    addTextElement(element, "maxConcurrentTasks", port.getMaxConcurrentTasks());
    addTextElement(element, "useCompression", String.valueOf(port.isUseCompression()));
    final Integer batchCount = port.getBatchCount();
    if (batchCount != null && batchCount > 0) {
        addTextElement(element, "batchCount", batchCount);
    }
    final String batchSize = port.getBatchSize();
    if (batchSize != null && batchSize.length() > 0) {
        addTextElement(element, "batchSize", batchSize);
    }
    final String batchDuration = port.getBatchDuration();
    if (batchDuration != null && batchDuration.length() > 0) {
        addTextElement(element, "batchDuration", batchDuration);
    }

    parentElement.appendChild(element);
}
 
Example #21
Source File: StandardConnection.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public Authorizable getDestinationAuthorizable() {
    final Connectable destinationConnectable = getDestination();
    final Authorizable destinationAuthorizable;

    // if the destination is a remote group port, authorize according to the RPG
    if (destinationConnectable instanceof RemoteGroupPort) {
        destinationAuthorizable = ((RemoteGroupPort) destinationConnectable).getRemoteProcessGroup();
    } else {
        destinationAuthorizable = destinationConnectable;
    }

    return destinationAuthorizable;
}
 
Example #22
Source File: RemoteProcessGroupAuditor.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Audits the update of remote process group output port configuration.
 *
 * @param proceedingJoinPoint join point
 * @param remoteProcessGroupPortDto dto
 * @param remoteProcessGroupDAO dao
 * @return group
 * @throws Throwable ex
 */
@Around("within(org.apache.nifi.web.dao.RemoteProcessGroupDAO+) && "
        + "execution(org.apache.nifi.remote.RemoteGroupPort updateRemoteProcessGroupOutputPort(java.lang.String, org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO)) && "
        + "args(remoteProcessGroupId, remoteProcessGroupPortDto) && "
        + "target(remoteProcessGroupDAO)")
public RemoteGroupPort auditUpdateProcessGroupOutputPortConfiguration(
        ProceedingJoinPoint proceedingJoinPoint, String remoteProcessGroupId,
        RemoteProcessGroupPortDTO remoteProcessGroupPortDto, RemoteProcessGroupDAO remoteProcessGroupDAO) throws Throwable {

    final RemoteProcessGroup remoteProcessGroup = remoteProcessGroupDAO.getRemoteProcessGroup(remoteProcessGroupId);
    final RemoteGroupPort remoteProcessGroupPort = remoteProcessGroup.getOutputPort(remoteProcessGroupPortDto.getId());

    return auditUpdateProcessGroupPortConfiguration(proceedingJoinPoint, remoteProcessGroupPortDto, remoteProcessGroup, remoteProcessGroupPort);
}
 
Example #23
Source File: StandardConnection.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public Authorizable getSourceAuthorizable() {
    final Connectable sourceConnectable = getSource();
    final Authorizable sourceAuthorizable;

    // if the source is a remote group port, authorize according to the RPG
    if (sourceConnectable instanceof RemoteGroupPort) {
        sourceAuthorizable = ((RemoteGroupPort) sourceConnectable).getRemoteProcessGroup();
    } else {
        sourceAuthorizable = sourceConnectable;
    }

    return sourceAuthorizable;
}
 
Example #24
Source File: StandardRemoteProcessGroupDAO.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Validates the proposed configuration for the specified remote port.
 */
private List<String> validateProposedRemoteProcessGroupPortConfiguration(RemoteGroupPort remoteGroupPort, RemoteProcessGroupPortDTO remoteProcessGroupPortDTO) {
    final List<String> validationErrors = new ArrayList<>();

    // ensure the proposed port configuration is valid
    if (isNotNull(remoteProcessGroupPortDTO.getConcurrentlySchedulableTaskCount()) && remoteProcessGroupPortDTO.getConcurrentlySchedulableTaskCount() <= 0) {
        validationErrors.add(String.format("Concurrent tasks for port '%s' must be a positive integer.", remoteGroupPort.getName()));
    }

    final BatchSettingsDTO batchSettingsDTO = remoteProcessGroupPortDTO.getBatchSettings();
    if (batchSettingsDTO != null) {
        final Integer batchCount = batchSettingsDTO.getCount();
        if (isNotNull(batchCount) && batchCount < 0) {
            validationErrors.add(String.format("Batch count for port '%s' must be a positive integer.", remoteGroupPort.getName()));
        }

        final String batchSize = batchSettingsDTO.getSize();
        if (isNotNull(batchSize) && batchSize.length() > 0
                && !DataUnit.DATA_SIZE_PATTERN.matcher(batchSize.trim().toUpperCase()).matches()) {
            validationErrors.add(String.format("Batch size for port '%s' must be of format <Data Size> <Data Unit>" +
                    " where <Data Size> is a non-negative integer and <Data Unit> is a supported Data"
                    + " Unit, such as: B, KB, MB, GB, TB", remoteGroupPort.getName()));
        }

        final String batchDuration = batchSettingsDTO.getDuration();
        if (isNotNull(batchDuration) && batchDuration.length() > 0
                && !FormatUtils.TIME_DURATION_PATTERN.matcher(batchDuration.trim().toLowerCase()).matches()) {
            validationErrors.add(String.format("Batch duration for port '%s' must be of format <duration> <TimeUnit>" +
                    " where <duration> is a non-negative integer and TimeUnit is a supported Time Unit, such "
                    + "as: nanos, millis, secs, mins, hrs, days", remoteGroupPort.getName()));
        }
    }

    return validationErrors;
}
 
Example #25
Source File: StandardRemoteProcessGroupDAO.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public void verifyUpdateOutputPort(String remoteProcessGroupId, RemoteProcessGroupPortDTO remoteProcessGroupPortDto) {
    final RemoteProcessGroup remoteProcessGroup = locateRemoteProcessGroup(remoteProcessGroupId);
    final RemoteGroupPort port = remoteProcessGroup.getOutputPort(remoteProcessGroupPortDto.getId());

    if (port == null) {
        throw new ResourceNotFoundException(
                String.format("Unable to find remote process group output port with id '%s'.", remoteProcessGroupPortDto.getId()));
    }

    verifyUpdatePort(port, remoteProcessGroupPortDto);
}
 
Example #26
Source File: StandardRemoteProcessGroupDAO.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public void verifyUpdateInputPort(String remoteProcessGroupId, RemoteProcessGroupPortDTO remoteProcessGroupPortDto) {
    final RemoteProcessGroup remoteProcessGroup = locateRemoteProcessGroup(remoteProcessGroupId);
    final RemoteGroupPort port = remoteProcessGroup.getInputPort(remoteProcessGroupPortDto.getId());

    if (port == null) {
        throw new ResourceNotFoundException(
                String.format("Unable to find remote process group input port with id '%s'.", remoteProcessGroupPortDto.getId()));
    }

    verifyUpdatePort(port, remoteProcessGroupPortDto);
}
 
Example #27
Source File: StandardProcessGroupDAO.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public void verifyScheduleComponents(final String groupId, final ScheduledState state,final Set<String> componentIds) {
    final ProcessGroup group = locateProcessGroup(flowController, groupId);

    final Set<ProcessGroup> validGroups = new HashSet<>();
    validGroups.add(group);
    validGroups.addAll(group.findAllProcessGroups());

    for (final String componentId : componentIds) {
        final Connectable connectable = findConnectable(componentId, groupId, validGroups);
        if (connectable == null) {
            throw new ResourceNotFoundException("Unable to find component with id " + componentId);
        }

        if (connectable  instanceof RemoteGroupPort) {
            final RemoteGroupPort remotePort = (RemoteGroupPort) connectable;

            if (ScheduledState.RUNNING.equals(state)) {
                remotePort.verifyCanStart();
            } else {
                remotePort.verifyCanStop();
            }

            continue;
        }

        // verify as appropriate
        if (ScheduledState.RUNNING.equals(state)) {
            group.verifyCanStart(connectable);
        } else {
            group.verifyCanStop(connectable);
        }
    }
}
 
Example #28
Source File: StatusConfigReporterTest.java    From nifi-minifi with Apache License 2.0 5 votes vote down vote up
private void populateRemoteProcessGroup(boolean addBulletins, boolean addAuthIssues) {
    when(mockFlowController.getGroup(mockFlowController.getRootGroupId())).thenReturn(processGroup);

    RemoteProcessGroup remoteProcessGroup = mock(RemoteProcessGroup.class);
    when(processGroup.getRemoteProcessGroup(any())).thenReturn(remoteProcessGroup);

    RemoteGroupPort remoteGroupPort = mock(RemoteGroupPort.class);
    when(remoteGroupPort.getName()).thenReturn("inputPort");
    when(remoteGroupPort.getTargetExists()).thenReturn(true);
    when(remoteGroupPort.isTargetRunning()).thenReturn(false);

    when(remoteProcessGroup.getInputPorts()).thenReturn(Collections.singleton(remoteGroupPort));

    remoteGroupPort = mock(RemoteGroupPort.class);
    when(remoteGroupPort.getName()).thenReturn("outputPort");
    when(remoteGroupPort.getTargetExists()).thenReturn(true);
    when(remoteGroupPort.isTargetRunning()).thenReturn(false);

    when(remoteProcessGroup.getOutputPorts()).thenReturn(Collections.singleton(remoteGroupPort));

    RemoteProcessGroupStatus remoteProcessGroupStatus = new RemoteProcessGroupStatus();
    addRemoteProcessGroupStatus(remoteProcessGroupStatus);
    if (addBulletins) {
        addBulletins("Bulletin message", remoteProcessGroupStatus.getId());
    }
    when(rootGroupStatus.getRemoteProcessGroupStatus()).thenReturn(Collections.singletonList(remoteProcessGroupStatus));
}
 
Example #29
Source File: StatusRequestParser.java    From nifi-minifi with Apache License 2.0 5 votes vote down vote up
private static List<PortStatus> getPortStatusList(RemoteProcessGroupStatus inputRemoteProcessGroupStatus, FlowController flowController, String rootGroupId,
                                                  Function<RemoteProcessGroup, Set<RemoteGroupPort>> portFunction) {
    return portFunction.apply(flowController.getGroup(rootGroupId).getRemoteProcessGroup(inputRemoteProcessGroupStatus.getId())).stream().map(r -> {
        PortStatus portStatus = new PortStatus();

        portStatus.setName(r.getName());
        portStatus.setTargetExists(r.getTargetExists());
        portStatus.setTargetRunning(r.isTargetRunning());

        return portStatus;
    }).collect(Collectors.toList());
}
 
Example #30
Source File: FlowController.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
public Authorizable createRemoteDataAuthorizable(String remoteGroupPortId) {
    final DataAuthorizable authorizable;

    final RemoteGroupPort remoteGroupPort = getRootGroup().findRemoteGroupPort(remoteGroupPortId);
    if (remoteGroupPort == null) {
        throw new ResourceNotFoundException("The component that generated this event is no longer part of the data flow.");
    } else {
        // authorizable for remote group ports should be the remote process group
        authorizable = new DataAuthorizable(remoteGroupPort.getRemoteProcessGroup());
    }

    return authorizable;
}