Java Code Examples for org.apache.nifi.controller.ScheduledState#valueOf()

The following examples show how to use org.apache.nifi.controller.ScheduledState#valueOf() . 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: StandardRemoteProcessGroup.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Converts a set of ports into a set of remote process group ports.
 *
 * @param ports to convert
 * @return descriptors of ports
 */
private Set<RemoteProcessGroupPortDescriptor> convertRemotePort(final Set<PortDTO> ports) {
    Set<RemoteProcessGroupPortDescriptor> remotePorts = null;
    if (ports != null) {
        remotePorts = new LinkedHashSet<>(ports.size());
        for (final PortDTO port : ports) {
            final StandardRemoteProcessGroupPortDescriptor descriptor = new StandardRemoteProcessGroupPortDescriptor();
            final ScheduledState scheduledState = ScheduledState.valueOf(port.getState());
            descriptor.setId(port.getId());
            descriptor.setName(port.getName());
            descriptor.setComments(port.getComments());
            descriptor.setTargetRunning(ScheduledState.RUNNING.equals(scheduledState));
            remotePorts.add(descriptor);
        }
    }
    return remotePorts;
}
 
Example 2
Source File: StandardRemoteProcessGroup.java    From nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Converts a set of ports into a set of remote process group ports.
 *
 * @param ports to convert
 * @return descriptors of ports
 */
private Set<RemoteProcessGroupPortDescriptor> convertRemotePort(final Set<PortDTO> ports) {
    Set<RemoteProcessGroupPortDescriptor> remotePorts = null;
    if (ports != null) {
        remotePorts = new LinkedHashSet<>(ports.size());
        for (final PortDTO port : ports) {
            final StandardRemoteProcessGroupPortDescriptor descriptor = new StandardRemoteProcessGroupPortDescriptor();
            final ScheduledState scheduledState = ScheduledState.valueOf(port.getState());
            descriptor.setId(generatePortId(port.getId()));
            descriptor.setTargetId(port.getId());
            descriptor.setName(port.getName());
            descriptor.setComments(port.getComments());
            descriptor.setTargetRunning(ScheduledState.RUNNING.equals(scheduledState));
            remotePorts.add(descriptor);
        }
    }
    return remotePorts;
}
 
Example 3
Source File: StandardReportingTaskDAO.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
@Override
public ReportingTaskNode updateReportingTask(final ReportingTaskDTO reportingTaskDTO) {
    // get the reporting task
    final ReportingTaskNode reportingTask = locateReportingTask(reportingTaskDTO.getId());

    // ensure we can perform the update
    verifyUpdate(reportingTask, reportingTaskDTO);

    // perform the update
    configureReportingTask(reportingTask, reportingTaskDTO);

    // configure scheduled state
    // see if an update is necessary
    if (isNotNull(reportingTaskDTO.getState())) {
        final ScheduledState purposedScheduledState = ScheduledState.valueOf(reportingTaskDTO.getState());

        // only attempt an action if it is changing
        if (!purposedScheduledState.equals(reportingTask.getScheduledState())) {
            try {
                // perform the appropriate action
                switch (purposedScheduledState) {
                    case RUNNING:
                        reportingTaskProvider.startReportingTask(reportingTask);
                        break;
                    case STOPPED:
                        switch (reportingTask.getScheduledState()) {
                            case RUNNING:
                                reportingTaskProvider.stopReportingTask(reportingTask);
                                break;
                            case DISABLED:
                                reportingTaskProvider.enableReportingTask(reportingTask);
                                break;
                        }
                        break;
                    case DISABLED:
                        reportingTaskProvider.disableReportingTask(reportingTask);
                        break;
                }
            } catch (IllegalStateException | ComponentLifeCycleException ise) {
                throw new NiFiCoreException(ise.getMessage(), ise);
            } catch (RejectedExecutionException ree) {
                throw new NiFiCoreException("Unable to schedule all tasks for the specified reporting task.", ree);
            } catch (NullPointerException npe) {
                throw new NiFiCoreException("Unable to update reporting task run state.", npe);
            } catch (Exception e) {
                throw new NiFiCoreException("Unable to update reporting task run state: " + e, e);
            }
        }
    }

    return reportingTask;
}
 
Example 4
Source File: StandardReportingTaskDAO.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
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())) {
        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);
        }
    }

    if (modificationRequest) {
        reportingTask.verifyCanUpdate();
    }
}
 
Example 5
Source File: StandardProcessorDAO.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
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())) {
        modificationRequest = true;
    }

    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();
    }
}
 
Example 6
Source File: StandardProcessorDAO.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
@Override
public ProcessorNode updateProcessor(ProcessorDTO processorDTO) {
    ProcessorNode processor = locateProcessor(processorDTO.getId());
    ProcessGroup parentGroup = processor.getProcessGroup();

    // ensure we can perform the update
    verifyUpdate(processor, processorDTO);

    // configure the processor
    configureProcessor(processor, processorDTO);

    // see if an update is necessary
    if (isNotNull(processorDTO.getState())) {
        final ScheduledState purposedScheduledState = ScheduledState.valueOf(processorDTO.getState());

        // only attempt an action if it is changing
        if (!purposedScheduledState.equals(processor.getScheduledState())) {
            try {
                // perform the appropriate action
                switch (purposedScheduledState) {
                    case RUNNING:
                        parentGroup.startProcessor(processor);
                        break;
                    case STOPPED:
                        switch (processor.getScheduledState()) {
                            case RUNNING:
                                parentGroup.stopProcessor(processor);
                                break;
                            case DISABLED:
                                parentGroup.enableProcessor(processor);
                                break;
                        }
                        break;
                    case DISABLED:
                        parentGroup.disableProcessor(processor);
                        break;
                }
            } catch (IllegalStateException | ComponentLifeCycleException ise) {
                throw new NiFiCoreException(ise.getMessage(), ise);
            } catch (RejectedExecutionException ree) {
                throw new NiFiCoreException("Unable to schedule all tasks for the specified processor.", ree);
            } catch (NullPointerException npe) {
                throw new NiFiCoreException("Unable to update processor run state.", npe);
            } catch (Exception e) {
                throw new NiFiCoreException("Unable to update processor run state: " + e, e);
            }
        }
    }

    return processor;
}
 
Example 7
Source File: StandardOutputPortDAO.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
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();
    }
}
 
Example 8
Source File: StandardOutputPortDAO.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
@Override
public Port updatePort(PortDTO portDTO) {
    Port outputPort = locatePort(portDTO.getId());

    // ensure we can do this update
    verifyUpdate(outputPort, portDTO);

    // handle state transition
    if (portDTO.getState() != null) {
        final ScheduledState purposedScheduledState = ScheduledState.valueOf(portDTO.getState());

        // only attempt an action if it is changing
        if (!purposedScheduledState.equals(outputPort.getScheduledState())) {
            try {
                // perform the appropriate action
                switch (purposedScheduledState) {
                    case RUNNING:
                        outputPort.getProcessGroup().startOutputPort(outputPort);
                        break;
                    case STOPPED:
                        switch (outputPort.getScheduledState()) {
                            case RUNNING:
                                outputPort.getProcessGroup().stopOutputPort(outputPort);
                                break;
                            case DISABLED:
                                outputPort.getProcessGroup().enableOutputPort(outputPort);
                                break;
                        }
                        break;
                    case DISABLED:
                        outputPort.getProcessGroup().disableOutputPort(outputPort);
                        break;
                }
            } catch (IllegalStateException ise) {
                throw new NiFiCoreException(ise.getMessage(), ise);
            }
        }
    }

    if (outputPort instanceof RootGroupPort) {
        final RootGroupPort rootPort = (RootGroupPort) outputPort;
        if (isNotNull(portDTO.getGroupAccessControl())) {
            rootPort.setGroupAccessControl(portDTO.getGroupAccessControl());
        }
        if (isNotNull(portDTO.getUserAccessControl())) {
            rootPort.setUserAccessControl(portDTO.getUserAccessControl());
        }
    }

    // perform the configuration
    final String name = portDTO.getName();
    final String comments = portDTO.getComments();
    final Integer concurrentTasks = portDTO.getConcurrentlySchedulableTaskCount();
    if (isNotNull(portDTO.getPosition())) {
        outputPort.setPosition(new Position(portDTO.getPosition().getX(), portDTO.getPosition().getY()));
    }
    if (isNotNull(name)) {
        outputPort.setName(name);
    }
    if (isNotNull(comments)) {
        outputPort.setComments(comments);
    }
    if (isNotNull(concurrentTasks)) {
        outputPort.setMaxConcurrentTasks(concurrentTasks);
    }

    return outputPort;
}
 
Example 9
Source File: FlowFromDOMFactory.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
private static ScheduledState getScheduledState(final Element element) {
    return ScheduledState.valueOf(getString(element, "scheduledState"));
}
 
Example 10
Source File: StandardInputPortDAO.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
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();
    }
}
 
Example 11
Source File: AbstractPortDAO.java    From nifi with Apache License 2.0 4 votes vote down vote up
protected void verifyUpdate(final Port port, 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(port.getScheduledState())) {
            // perform the appropriate action
            switch (purposedScheduledState) {
                case RUNNING:
                    port.verifyCanStart();
                    break;
                case STOPPED:
                    switch (port.getScheduledState()) {
                        case RUNNING:
                            port.verifyCanStop();
                            break;
                        case DISABLED:
                            port.verifyCanEnable();
                            break;
                    }
                    break;
                case DISABLED:
                    port.verifyCanDisable();
                    break;
            }
        }
    }

    // see what's be modified
    if (isAnyNotNull(portDTO.getUserAccessControl(),
        portDTO.getGroupAccessControl(),
        portDTO.getConcurrentlySchedulableTaskCount(),
        portDTO.getName(),
        portDTO.getComments(),
        portDTO.getAllowRemoteAccess())) {

        // validate the request
        final List<String> requestValidation = validateProposedConfiguration(port, portDTO);

        // ensure there was no validation errors
        if (!requestValidation.isEmpty()) {
            throw new ValidationException(requestValidation);
        }

        // ensure the port can be updated
        port.verifyCanUpdate();
    }

}
 
Example 12
Source File: AbstractPortDAO.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Override
public Port updatePort(PortDTO portDTO) {
    final Port port = locatePort(portDTO.getId());
    final ProcessGroup processGroup = port.getProcessGroup();

    // ensure we can do this update
    verifyUpdate(port, portDTO);

    // handle state transition
    if (isNotNull(portDTO.getState())) {
        final ScheduledState proposedScheduledState = ScheduledState.valueOf(portDTO.getState());

        // only attempt an action if it is changing
        if (!proposedScheduledState.equals(port.getScheduledState())) {
            try {
                handleStateTransition(port, proposedScheduledState);
            } catch (IllegalStateException ise) {
                throw new NiFiCoreException(ise.getMessage(), ise);
            }
        }
    }

    if (port instanceof PublicPort) {
        final PublicPort publicPort = (PublicPort) port;
        if (isNotNull(portDTO.getGroupAccessControl())) {
            publicPort.setGroupAccessControl(portDTO.getGroupAccessControl());
        }
        if (isNotNull(portDTO.getUserAccessControl())) {
            publicPort.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())) {
        port.setPosition(new Position(portDTO.getPosition().getX(), portDTO.getPosition().getY()));
    }
    if (isNotNull(name)) {
        port.setName(name);
    }
    if (isNotNull(comments)) {
        port.setComments(comments);
    }
    if (isNotNull(concurrentTasks)) {
        port.setMaxConcurrentTasks(concurrentTasks);
    }

    processGroup.onComponentModified();
    return port;
}
 
Example 13
Source File: StandardReportingTaskDAO.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Override
public ReportingTaskNode updateReportingTask(final ReportingTaskDTO reportingTaskDTO) {
    // get the reporting task
    final ReportingTaskNode reportingTask = locateReportingTask(reportingTaskDTO.getId());

    // ensure we can perform the update
    verifyUpdate(reportingTask, reportingTaskDTO);

    // perform the update
    configureReportingTask(reportingTask, reportingTaskDTO);

    // attempt to change the underlying processor if an updated bundle is specified
    // updating the bundle must happen after configuring so that any additional classpath resources are set first
    updateBundle(reportingTask, reportingTaskDTO);

    // configure scheduled state
    // see if an update is necessary
    if (isNotNull(reportingTaskDTO.getState())) {
        final ScheduledState purposedScheduledState = ScheduledState.valueOf(reportingTaskDTO.getState());

        // only attempt an action if it is changing
        if (!purposedScheduledState.equals(reportingTask.getScheduledState())) {
            try {
                // perform the appropriate action
                switch (purposedScheduledState) {
                    case RUNNING:
                        reportingTaskProvider.startReportingTask(reportingTask);
                        break;
                    case STOPPED:
                        switch (reportingTask.getScheduledState()) {
                            case RUNNING:
                                reportingTaskProvider.stopReportingTask(reportingTask);
                                break;
                            case DISABLED:
                                reportingTaskProvider.enableReportingTask(reportingTask);
                                break;
                        }
                        break;
                    case DISABLED:
                        reportingTaskProvider.disableReportingTask(reportingTask);
                        break;
                }
            } catch (IllegalStateException | ComponentLifeCycleException ise) {
                throw new NiFiCoreException(ise.getMessage(), ise);
            } catch (RejectedExecutionException ree) {
                throw new NiFiCoreException("Unable to schedule all tasks for the specified reporting task.", ree);
            } catch (NullPointerException npe) {
                throw new NiFiCoreException("Unable to update reporting task run state.", npe);
            } catch (Exception e) {
                throw new NiFiCoreException("Unable to update reporting task run state: " + e, e);
            }
        }
    }

    return reportingTask;
}
 
Example 14
Source File: StandardReportingTaskDAO.java    From nifi with Apache License 2.0 4 votes vote down vote up
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(
                reportingTaskProvider.getExtensionManager(), 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();
    }
}
 
Example 15
Source File: StandardProcessorDAO.java    From nifi with Apache License 2.0 4 votes vote down vote up
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(flowController.getExtensionManager(), 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();
    }
}
 
Example 16
Source File: StandardProcessorDAO.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Override
public ProcessorNode updateProcessor(ProcessorDTO processorDTO) {
    ProcessorNode processor = locateProcessor(processorDTO.getId());
    ProcessGroup parentGroup = processor.getProcessGroup();

    // ensure we can perform the update
    verifyUpdate(processor, processorDTO);

    // configure the processor
    configureProcessor(processor, processorDTO);
    parentGroup.onComponentModified();

    // attempt to change the underlying processor if an updated bundle is specified
    // updating the bundle must happen after configuring so that any additional classpath resources are set first
    updateBundle(processor, processorDTO);

    // see if an update is necessary
    if (isNotNull(processorDTO.getState())) {
        final ScheduledState purposedScheduledState = ScheduledState.valueOf(processorDTO.getState());

        // only attempt an action if it is changing
        if (!purposedScheduledState.equals(processor.getScheduledState())) {
            try {
                // perform the appropriate action
                switch (purposedScheduledState) {
                    case RUNNING:
                        parentGroup.startProcessor(processor, true);
                        break;
                    case STOPPED:
                        switch (processor.getScheduledState()) {
                            case RUNNING:
                                parentGroup.stopProcessor(processor);
                                break;
                            case DISABLED:
                                parentGroup.enableProcessor(processor);
                                break;
                        }
                        break;
                    case DISABLED:
                        parentGroup.disableProcessor(processor);
                        break;
                }
            } catch (IllegalStateException | ComponentLifeCycleException ise) {
                throw new NiFiCoreException(ise.getMessage(), ise);
            } catch (RejectedExecutionException ree) {
                throw new NiFiCoreException("Unable to schedule all tasks for the specified processor.", ree);
            } catch (NullPointerException npe) {
                throw new NiFiCoreException("Unable to update processor run state.", npe);
            } catch (Exception e) {
                throw new NiFiCoreException("Unable to update processor run state: " + e, e);
            }
        }
    }

    return processor;
}
 
Example 17
Source File: FlowFromDOMFactory.java    From nifi with Apache License 2.0 4 votes vote down vote up
private static ScheduledState getScheduledState(final Element element) {
    return ScheduledState.valueOf(getString(element, "scheduledState"));
}
 
Example 18
Source File: StandardInputPortDAO.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
@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);
    }

    return inputPort;
}