Search in sources :

Example 1 with ValidationException

use of org.apache.nifi.controller.exception.ValidationException in project nifi by apache.

the class StandardControllerServiceDAO method verifyUpdate.

private void verifyUpdate(final ControllerServiceNode controllerService, final ControllerServiceDTO controllerServiceDTO) {
    // validate the new controller service state if appropriate
    if (isNotNull(controllerServiceDTO.getState())) {
        try {
            // attempt to parse the service state
            final ControllerServiceState purposedControllerServiceState = ControllerServiceState.valueOf(controllerServiceDTO.getState());
            // ensure the state is valid
            if (ControllerServiceState.ENABLING.equals(purposedControllerServiceState) || ControllerServiceState.DISABLING.equals(purposedControllerServiceState)) {
                throw new IllegalArgumentException();
            }
            // only attempt an action if it is changing
            if (!purposedControllerServiceState.equals(controllerService.getState())) {
                if (ControllerServiceState.ENABLED.equals(purposedControllerServiceState)) {
                    controllerService.verifyCanEnable();
                } else if (ControllerServiceState.DISABLED.equals(purposedControllerServiceState)) {
                    controllerService.verifyCanDisable();
                }
            }
        } catch (final IllegalArgumentException iae) {
            throw new IllegalArgumentException("Controller Service state: Value must be one of [ENABLED, DISABLED]");
        }
    }
    boolean modificationRequest = false;
    if (isAnyNotNull(controllerServiceDTO.getName(), controllerServiceDTO.getAnnotationData(), controllerServiceDTO.getComments(), controllerServiceDTO.getProperties(), controllerServiceDTO.getBundle())) {
        modificationRequest = true;
        // validate the request
        final List<String> requestValidation = validateProposedConfiguration(controllerService, controllerServiceDTO);
        // ensure there was no validation errors
        if (!requestValidation.isEmpty()) {
            throw new ValidationException(requestValidation);
        }
    }
    final BundleDTO bundleDTO = controllerServiceDTO.getBundle();
    if (bundleDTO != null) {
        // ensures all nodes in a cluster have the bundle, throws exception if bundle not found for the given type
        final BundleCoordinate bundleCoordinate = BundleUtils.getBundle(controllerService.getCanonicalClassName(), bundleDTO);
        // ensure we are only changing to a bundle with the same group and id, but different version
        controllerService.verifyCanUpdateBundle(bundleCoordinate);
    }
    if (modificationRequest) {
        controllerService.verifyCanUpdate();
    }
}
Also used : ControllerServiceState(org.apache.nifi.controller.service.ControllerServiceState) ValidationException(org.apache.nifi.controller.exception.ValidationException) BundleDTO(org.apache.nifi.web.api.dto.BundleDTO) BundleCoordinate(org.apache.nifi.bundle.BundleCoordinate)

Example 2 with ValidationException

use of org.apache.nifi.controller.exception.ValidationException in project nifi by apache.

the class StandardInputPortDAO method verifyUpdate.

private void verifyUpdate(final Port inputPort, final PortDTO portDTO) {
    if (isNotNull(portDTO.getState())) {
        final ScheduledState purposedScheduledState = ScheduledState.valueOf(portDTO.getState());
        // only attempt an action if it is changing
        if (!purposedScheduledState.equals(inputPort.getScheduledState())) {
            // perform the appropriate action
            switch(purposedScheduledState) {
                case RUNNING:
                    inputPort.verifyCanStart();
                    break;
                case STOPPED:
                    switch(inputPort.getScheduledState()) {
                        case RUNNING:
                            inputPort.verifyCanStop();
                            break;
                        case DISABLED:
                            inputPort.verifyCanEnable();
                            break;
                    }
                    break;
                case DISABLED:
                    inputPort.verifyCanDisable();
                    break;
            }
        }
    }
    // see what's be modified
    if (isAnyNotNull(portDTO.getUserAccessControl(), portDTO.getGroupAccessControl(), portDTO.getConcurrentlySchedulableTaskCount(), portDTO.getName(), portDTO.getComments())) {
        // validate the request
        final List<String> requestValidation = validateProposedConfiguration(portDTO);
        // ensure there was no validation errors
        if (!requestValidation.isEmpty()) {
            throw new ValidationException(requestValidation);
        }
        // ensure the port can be updated
        inputPort.verifyCanUpdate();
    }
}
Also used : ValidationException(org.apache.nifi.controller.exception.ValidationException) ScheduledState(org.apache.nifi.controller.ScheduledState)

Example 3 with ValidationException

use of org.apache.nifi.controller.exception.ValidationException in project nifi by apache.

the class StandardProcessorDAO method verifyUpdate.

private void verifyUpdate(ProcessorNode processor, ProcessorDTO processorDTO) {
    // ensure the state, if specified, is valid
    if (isNotNull(processorDTO.getState())) {
        try {
            final ScheduledState purposedScheduledState = ScheduledState.valueOf(processorDTO.getState());
            // only attempt an action if it is changing
            if (!purposedScheduledState.equals(processor.getScheduledState())) {
                // perform the appropriate action
                switch(purposedScheduledState) {
                    case RUNNING:
                        processor.verifyCanStart();
                        break;
                    case STOPPED:
                        switch(processor.getScheduledState()) {
                            case RUNNING:
                                processor.verifyCanStop();
                                break;
                            case DISABLED:
                                processor.verifyCanEnable();
                                break;
                        }
                        break;
                    case DISABLED:
                        processor.verifyCanDisable();
                        break;
                }
            }
        } catch (IllegalArgumentException iae) {
            throw new IllegalArgumentException(String.format("The specified processor state (%s) is not valid. Valid options are 'RUNNING', 'STOPPED', and 'DISABLED'.", processorDTO.getState()));
        }
    }
    boolean modificationRequest = false;
    if (isAnyNotNull(processorDTO.getName(), processorDTO.getBundle())) {
        modificationRequest = true;
    }
    final BundleDTO bundleDTO = processorDTO.getBundle();
    if (bundleDTO != null) {
        // ensures all nodes in a cluster have the bundle, throws exception if bundle not found for the given type
        final BundleCoordinate bundleCoordinate = BundleUtils.getBundle(processor.getCanonicalClassName(), bundleDTO);
        // ensure we are only changing to a bundle with the same group and id, but different version
        processor.verifyCanUpdateBundle(bundleCoordinate);
    }
    final ProcessorConfigDTO configDTO = processorDTO.getConfig();
    if (configDTO != null) {
        if (isAnyNotNull(configDTO.getAnnotationData(), configDTO.getAutoTerminatedRelationships(), configDTO.getBulletinLevel(), configDTO.getComments(), configDTO.getConcurrentlySchedulableTaskCount(), configDTO.getPenaltyDuration(), configDTO.getProperties(), configDTO.getSchedulingPeriod(), configDTO.getSchedulingStrategy(), configDTO.getExecutionNode(), configDTO.getYieldDuration())) {
            modificationRequest = true;
        }
        // validate the request
        final List<String> requestValidation = validateProposedConfiguration(processor, configDTO);
        // ensure there was no validation errors
        if (!requestValidation.isEmpty()) {
            throw new ValidationException(requestValidation);
        }
    }
    if (modificationRequest) {
        processor.verifyCanUpdate();
    }
}
Also used : ProcessorConfigDTO(org.apache.nifi.web.api.dto.ProcessorConfigDTO) ValidationException(org.apache.nifi.controller.exception.ValidationException) ScheduledState(org.apache.nifi.controller.ScheduledState) BundleDTO(org.apache.nifi.web.api.dto.BundleDTO) BundleCoordinate(org.apache.nifi.bundle.BundleCoordinate)

Example 4 with ValidationException

use of org.apache.nifi.controller.exception.ValidationException in project nifi by apache.

the class StandardConnectionDAO method verifyUpdate.

private void verifyUpdate(final Connection connection, final ConnectionDTO connectionDTO) {
    // determine what the request is attempting
    if (isAnyNotNull(connectionDTO.getBackPressureDataSizeThreshold(), connectionDTO.getBackPressureObjectThreshold(), connectionDTO.getDestination(), connectionDTO.getFlowFileExpiration(), connectionDTO.getName(), connectionDTO.getPosition(), connectionDTO.getPrioritizers(), connectionDTO.getSelectedRelationships())) {
        // validate the incoming request
        final List<String> validationErrors = validateProposedConfiguration(connection.getProcessGroup().getIdentifier(), connectionDTO);
        // ensure there was no validation errors
        if (!validationErrors.isEmpty()) {
            throw new ValidationException(validationErrors);
        }
        // If destination is changing, ensure that current destination is not running. This check is done here, rather than
        // in the Connection object itself because the Connection object itself does not know which updates are to occur and
        // we don't want to prevent updating things like the connection name or backpressure just because the destination is running
        final Connectable destination = connection.getDestination();
        if (destination != null && destination.isRunning() && destination.getConnectableType() != ConnectableType.FUNNEL && destination.getConnectableType() != ConnectableType.INPUT_PORT) {
            throw new ValidationException(Collections.singletonList("Cannot change the destination of connection because the current destination is running"));
        }
        // verify that this connection supports modification
        connection.verifyCanUpdate();
    }
}
Also used : ValidationException(org.apache.nifi.controller.exception.ValidationException) Connectable(org.apache.nifi.connectable.Connectable)

Example 5 with ValidationException

use of org.apache.nifi.controller.exception.ValidationException in project nifi by apache.

the class StandardConnectionDAO method verifyCreate.

@Override
public void verifyCreate(String groupId, ConnectionDTO connectionDTO) {
    // validate the incoming request
    final List<String> validationErrors = validateProposedConfiguration(groupId, connectionDTO);
    // ensure there was no validation errors
    if (!validationErrors.isEmpty()) {
        throw new ValidationException(validationErrors);
    }
    // Ensure that both the source and the destination for the connection exist.
    // In the case that the source or destination is a port in a Remote Process Group,
    // this is necessary because the ports can change in the background. It may still be
    // possible for a port to disappear between the 'verify' stage and the creation stage,
    // but this prevents the case where some nodes already know about the port while other
    // nodes in the cluster do not. This is a more common case, as users may try to connect
    // to the port as soon as the port is created.
    final ConnectableDTO sourceDto = connectionDTO.getSource();
    if (sourceDto == null || sourceDto.getId() == null) {
        throw new IllegalArgumentException("Cannot create connection without specifying source");
    }
    final ConnectableDTO destinationDto = connectionDTO.getDestination();
    if (destinationDto == null || destinationDto.getId() == null) {
        throw new IllegalArgumentException("Cannot create connection without specifying destination");
    }
    if (ConnectableType.REMOTE_OUTPUT_PORT.name().equals(sourceDto.getType())) {
        final ProcessGroup sourceParentGroup = locateProcessGroup(flowController, groupId);
        final RemoteProcessGroup remoteProcessGroup = sourceParentGroup.getRemoteProcessGroup(sourceDto.getGroupId());
        if (remoteProcessGroup == null) {
            throw new IllegalArgumentException("Unable to find the specified remote process group.");
        }
        final RemoteGroupPort sourceConnectable = remoteProcessGroup.getOutputPort(sourceDto.getId());
        if (sourceConnectable == null) {
            throw new IllegalArgumentException("The specified source for the connection does not exist");
        } else if (!sourceConnectable.getTargetExists()) {
            throw new IllegalArgumentException("The specified remote output port does not exist.");
        }
    } else {
        final ProcessGroup sourceGroup = locateProcessGroup(flowController, sourceDto.getGroupId());
        final Connectable sourceConnectable = sourceGroup.getConnectable(sourceDto.getId());
        if (sourceConnectable == null) {
            throw new IllegalArgumentException("The specified source for the connection does not exist");
        }
    }
    if (ConnectableType.REMOTE_INPUT_PORT.name().equals(destinationDto.getType())) {
        final ProcessGroup destinationParentGroup = locateProcessGroup(flowController, groupId);
        final RemoteProcessGroup remoteProcessGroup = destinationParentGroup.getRemoteProcessGroup(destinationDto.getGroupId());
        if (remoteProcessGroup == null) {
            throw new IllegalArgumentException("Unable to find the specified remote process group.");
        }
        final RemoteGroupPort destinationConnectable = remoteProcessGroup.getInputPort(destinationDto.getId());
        if (destinationConnectable == null) {
            throw new IllegalArgumentException("The specified destination for the connection does not exist");
        } else if (!destinationConnectable.getTargetExists()) {
            throw new IllegalArgumentException("The specified remote input port does not exist.");
        }
    } else {
        final ProcessGroup destinationGroup = locateProcessGroup(flowController, destinationDto.getGroupId());
        final Connectable destinationConnectable = destinationGroup.getConnectable(destinationDto.getId());
        if (destinationConnectable == null) {
            throw new IllegalArgumentException("The specified destination for the connection does not exist");
        }
    }
}
Also used : RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) ValidationException(org.apache.nifi.controller.exception.ValidationException) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort) Connectable(org.apache.nifi.connectable.Connectable) ProcessGroup(org.apache.nifi.groups.ProcessGroup) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) ConnectableDTO(org.apache.nifi.web.api.dto.ConnectableDTO)

Aggregations

ValidationException (org.apache.nifi.controller.exception.ValidationException)8 ScheduledState (org.apache.nifi.controller.ScheduledState)4 BundleCoordinate (org.apache.nifi.bundle.BundleCoordinate)3 Connectable (org.apache.nifi.connectable.Connectable)3 BundleDTO (org.apache.nifi.web.api.dto.BundleDTO)3 ProcessGroup (org.apache.nifi.groups.ProcessGroup)2 RemoteProcessGroup (org.apache.nifi.groups.RemoteProcessGroup)2 ConnectableDTO (org.apache.nifi.web.api.dto.ConnectableDTO)2 HashSet (java.util.HashSet)1 Connection (org.apache.nifi.connectable.Connection)1 ControllerServiceState (org.apache.nifi.controller.service.ControllerServiceState)1 RemoteGroupPort (org.apache.nifi.remote.RemoteGroupPort)1 ProcessorConfigDTO (org.apache.nifi.web.api.dto.ProcessorConfigDTO)1