Search in sources :

Example 6 with ValidationException

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

the class StandardConnectionDAO method createConnection.

@Override
public Connection createConnection(final String groupId, final ConnectionDTO connectionDTO) {
    final ProcessGroup group = locateProcessGroup(flowController, groupId);
    if (isNotNull(connectionDTO.getParentGroupId()) && !flowController.areGroupsSame(connectionDTO.getParentGroupId(), groupId)) {
        throw new IllegalStateException("Cannot specify a different Parent Group ID than the Group to which the Connection is being added");
    }
    // get the source and destination connectables
    final ConnectableDTO sourceConnectableDTO = connectionDTO.getSource();
    final ConnectableDTO destinationConnectableDTO = connectionDTO.getDestination();
    // ensure both are specified
    if (sourceConnectableDTO == null || destinationConnectableDTO == null) {
        throw new IllegalArgumentException("Both source and destinations must be specified.");
    }
    // if the source/destination connectable's group id has not been set, its inferred to be the current group
    if (sourceConnectableDTO.getGroupId() == null) {
        sourceConnectableDTO.setGroupId(groupId);
    }
    if (destinationConnectableDTO.getGroupId() == null) {
        destinationConnectableDTO.setGroupId(groupId);
    }
    // validate the proposed configuration
    final List<String> validationErrors = validateProposedConfiguration(groupId, connectionDTO);
    // ensure there was no validation errors
    if (!validationErrors.isEmpty()) {
        throw new ValidationException(validationErrors);
    }
    // find the source
    final Connectable source;
    if (ConnectableType.REMOTE_OUTPUT_PORT.name().equals(sourceConnectableDTO.getType())) {
        final ProcessGroup sourceParentGroup = locateProcessGroup(flowController, groupId);
        final RemoteProcessGroup remoteProcessGroup = sourceParentGroup.getRemoteProcessGroup(sourceConnectableDTO.getGroupId());
        source = remoteProcessGroup.getOutputPort(sourceConnectableDTO.getId());
    } else {
        final ProcessGroup sourceGroup = locateProcessGroup(flowController, sourceConnectableDTO.getGroupId());
        source = sourceGroup.getConnectable(sourceConnectableDTO.getId());
    }
    // find the destination
    final Connectable destination;
    if (ConnectableType.REMOTE_INPUT_PORT.name().equals(destinationConnectableDTO.getType())) {
        final ProcessGroup destinationParentGroup = locateProcessGroup(flowController, groupId);
        final RemoteProcessGroup remoteProcessGroup = destinationParentGroup.getRemoteProcessGroup(destinationConnectableDTO.getGroupId());
        destination = remoteProcessGroup.getInputPort(destinationConnectableDTO.getId());
    } else {
        final ProcessGroup destinationGroup = locateProcessGroup(flowController, destinationConnectableDTO.getGroupId());
        destination = destinationGroup.getConnectable(destinationConnectableDTO.getId());
    }
    // determine the relationships
    final Set<String> relationships = new HashSet<>();
    if (isNotNull(connectionDTO.getSelectedRelationships())) {
        relationships.addAll(connectionDTO.getSelectedRelationships());
    }
    // create the connection
    final Connection connection = flowController.createConnection(connectionDTO.getId(), connectionDTO.getName(), source, destination, relationships);
    // configure the connection
    configureConnection(connection, connectionDTO);
    // add the connection to the group
    group.addConnection(connection);
    return connection;
}
Also used : RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) ValidationException(org.apache.nifi.controller.exception.ValidationException) Connectable(org.apache.nifi.connectable.Connectable) ProcessGroup(org.apache.nifi.groups.ProcessGroup) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) Connection(org.apache.nifi.connectable.Connection) ConnectableDTO(org.apache.nifi.web.api.dto.ConnectableDTO) HashSet(java.util.HashSet)

Example 7 with ValidationException

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

the class StandardOutputPortDAO method verifyUpdate.

private void verifyUpdate(final Port outputPort, 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(outputPort.getScheduledState())) {
            // perform the appropriate action
            switch(purposedScheduledState) {
                case RUNNING:
                    outputPort.verifyCanStart();
                    break;
                case STOPPED:
                    switch(outputPort.getScheduledState()) {
                        case RUNNING:
                            outputPort.verifyCanStop();
                            break;
                        case DISABLED:
                            outputPort.verifyCanEnable();
                            break;
                    }
                    break;
                case DISABLED:
                    outputPort.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
        outputPort.verifyCanUpdate();
    }
}
Also used : ValidationException(org.apache.nifi.controller.exception.ValidationException) ScheduledState(org.apache.nifi.controller.ScheduledState)

Example 8 with ValidationException

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

the class StandardReportingTaskDAO method verifyUpdate.

private void verifyUpdate(final ReportingTaskNode reportingTask, final ReportingTaskDTO reportingTaskDTO) {
    // ensure the state, if specified, is valid
    if (isNotNull(reportingTaskDTO.getState())) {
        try {
            final ScheduledState purposedScheduledState = ScheduledState.valueOf(reportingTaskDTO.getState());
            // only attempt an action if it is changing
            if (!purposedScheduledState.equals(reportingTask.getScheduledState())) {
                // perform the appropriate action
                switch(purposedScheduledState) {
                    case RUNNING:
                        reportingTask.verifyCanStart();
                        break;
                    case STOPPED:
                        switch(reportingTask.getScheduledState()) {
                            case RUNNING:
                                reportingTask.verifyCanStop();
                                break;
                            case DISABLED:
                                reportingTask.verifyCanEnable();
                                break;
                        }
                        break;
                    case DISABLED:
                        reportingTask.verifyCanDisable();
                        break;
                }
            }
        } catch (IllegalArgumentException iae) {
            throw new IllegalArgumentException(String.format("The specified reporting task state (%s) is not valid. Valid options are 'RUNNING', 'STOPPED', and 'DISABLED'.", reportingTaskDTO.getState()));
        }
    }
    boolean modificationRequest = false;
    if (isAnyNotNull(reportingTaskDTO.getName(), reportingTaskDTO.getSchedulingStrategy(), reportingTaskDTO.getSchedulingPeriod(), reportingTaskDTO.getAnnotationData(), reportingTaskDTO.getProperties(), reportingTaskDTO.getBundle())) {
        modificationRequest = true;
        // validate the request
        final List<String> requestValidation = validateProposedConfiguration(reportingTask, reportingTaskDTO);
        // ensure there was no validation errors
        if (!requestValidation.isEmpty()) {
            throw new ValidationException(requestValidation);
        }
    }
    final BundleDTO bundleDTO = reportingTaskDTO.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(reportingTask.getCanonicalClassName(), bundleDTO);
        // ensure we are only changing to a bundle with the same group and id, but different version
        reportingTask.verifyCanUpdateBundle(bundleCoordinate);
    }
    if (modificationRequest) {
        reportingTask.verifyCanUpdate();
    }
}
Also used : 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)

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