Search in sources :

Example 6 with ComponentLifeCycleException

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

the class FlowController method createReportingTask.

public ReportingTaskNode createReportingTask(final String type, final String id, final BundleCoordinate bundleCoordinate, final Set<URL> additionalUrls, final boolean firstTimeAdded, final boolean register) throws ReportingTaskInstantiationException {
    if (type == null || id == null || bundleCoordinate == null) {
        throw new NullPointerException();
    }
    LoggableComponent<ReportingTask> task = null;
    boolean creationSuccessful = true;
    try {
        task = instantiateReportingTask(type, id, bundleCoordinate, additionalUrls);
    } catch (final Exception e) {
        LOG.error("Could not create Reporting Task of type " + type + " for ID " + id + "; creating \"Ghost\" implementation", e);
        final GhostReportingTask ghostTask = new GhostReportingTask();
        ghostTask.setIdentifier(id);
        ghostTask.setCanonicalClassName(type);
        task = new LoggableComponent<>(ghostTask, bundleCoordinate, null);
        creationSuccessful = false;
    }
    final ComponentVariableRegistry componentVarRegistry = new StandardComponentVariableRegistry(this.variableRegistry);
    final ValidationContextFactory validationContextFactory = new StandardValidationContextFactory(controllerServiceProvider, componentVarRegistry);
    final ReportingTaskNode taskNode;
    if (creationSuccessful) {
        taskNode = new StandardReportingTaskNode(task, id, this, processScheduler, validationContextFactory, componentVarRegistry, this);
    } else {
        final String simpleClassName = type.contains(".") ? StringUtils.substringAfterLast(type, ".") : type;
        final String componentType = "(Missing) " + simpleClassName;
        taskNode = new StandardReportingTaskNode(task, id, this, processScheduler, validationContextFactory, componentType, type, componentVarRegistry, this, true);
    }
    taskNode.setName(taskNode.getReportingTask().getClass().getSimpleName());
    if (firstTimeAdded) {
        final ReportingInitializationContext config = new StandardReportingInitializationContext(id, taskNode.getName(), SchedulingStrategy.TIMER_DRIVEN, "1 min", taskNode.getLogger(), this, nifiProperties, this);
        try {
            taskNode.getReportingTask().initialize(config);
        } catch (final InitializationException ie) {
            throw new ReportingTaskInstantiationException("Failed to initialize reporting task of type " + type, ie);
        }
        try (final NarCloseable x = NarCloseable.withComponentNarLoader(taskNode.getReportingTask().getClass(), taskNode.getReportingTask().getIdentifier())) {
            ReflectionUtils.invokeMethodsWithAnnotation(OnAdded.class, taskNode.getReportingTask());
            ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnConfigurationRestored.class, taskNode.getReportingTask());
        } catch (final Exception e) {
            throw new ComponentLifeCycleException("Failed to invoke On-Added Lifecycle methods of " + taskNode.getReportingTask(), e);
        }
    }
    if (register) {
        reportingTasks.put(id, taskNode);
        // Register log observer to provide bulletins when reporting task logs anything at WARN level or above
        final LogRepository logRepository = LogRepositoryFactory.getRepository(id);
        logRepository.addObserver(StandardProcessorNode.BULLETIN_OBSERVER_ID, LogLevel.WARN, new ReportingTaskLogObserver(getBulletinRepository(), taskNode));
    }
    return taskNode;
}
Also used : NarCloseable(org.apache.nifi.nar.NarCloseable) StandardComponentVariableRegistry(org.apache.nifi.registry.variable.StandardComponentVariableRegistry) LogRepository(org.apache.nifi.logging.LogRepository) StandardValidationContextFactory(org.apache.nifi.processor.StandardValidationContextFactory) StandardReportingInitializationContext(org.apache.nifi.controller.reporting.StandardReportingInitializationContext) InitializationException(org.apache.nifi.reporting.InitializationException) ComponentLifeCycleException(org.apache.nifi.controller.exception.ComponentLifeCycleException) StandardValidationContextFactory(org.apache.nifi.processor.StandardValidationContextFactory) ConfigException(org.apache.zookeeper.server.quorum.QuorumPeerConfig.ConfigException) IOException(java.io.IOException) ProcessorInstantiationException(org.apache.nifi.controller.exception.ProcessorInstantiationException) ComponentLifeCycleException(org.apache.nifi.controller.exception.ComponentLifeCycleException) UnknownServiceAddressException(org.apache.nifi.cluster.protocol.UnknownServiceAddressException) FlowSerializationException(org.apache.nifi.controller.serialization.FlowSerializationException) ResourceNotFoundException(org.apache.nifi.web.ResourceNotFoundException) InitializationException(org.apache.nifi.reporting.InitializationException) ReportingTaskInstantiationException(org.apache.nifi.controller.reporting.ReportingTaskInstantiationException) CommunicationsException(org.apache.nifi.controller.exception.CommunicationsException) FlowSynchronizationException(org.apache.nifi.controller.serialization.FlowSynchronizationException) ControllerServiceInstantiationException(org.apache.nifi.controller.exception.ControllerServiceInstantiationException) GhostReportingTask(org.apache.nifi.reporting.GhostReportingTask) ReportingTaskInstantiationException(org.apache.nifi.controller.reporting.ReportingTaskInstantiationException) ReportingInitializationContext(org.apache.nifi.reporting.ReportingInitializationContext) StandardReportingInitializationContext(org.apache.nifi.controller.reporting.StandardReportingInitializationContext) StandardReportingTaskNode(org.apache.nifi.controller.reporting.StandardReportingTaskNode) StandardReportingTaskNode(org.apache.nifi.controller.reporting.StandardReportingTaskNode) StandardComponentVariableRegistry(org.apache.nifi.registry.variable.StandardComponentVariableRegistry) ComponentVariableRegistry(org.apache.nifi.registry.ComponentVariableRegistry) ReportingTaskLogObserver(org.apache.nifi.logging.ReportingTaskLogObserver) ReportingTask(org.apache.nifi.reporting.ReportingTask) GhostReportingTask(org.apache.nifi.reporting.GhostReportingTask)

Example 7 with ComponentLifeCycleException

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

the class StandardProcessorDAO method updateProcessor.

@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;
}
Also used : NiFiCoreException(org.apache.nifi.web.NiFiCoreException) ProcessorNode(org.apache.nifi.controller.ProcessorNode) ScheduledState(org.apache.nifi.controller.ScheduledState) ProcessGroup(org.apache.nifi.groups.ProcessGroup) ComponentLifeCycleException(org.apache.nifi.controller.exception.ComponentLifeCycleException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ProcessorInstantiationException(org.apache.nifi.controller.exception.ProcessorInstantiationException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ResourceNotFoundException(org.apache.nifi.web.ResourceNotFoundException) ParseException(java.text.ParseException) ComponentLifeCycleException(org.apache.nifi.controller.exception.ComponentLifeCycleException) NiFiCoreException(org.apache.nifi.web.NiFiCoreException) ValidationException(org.apache.nifi.controller.exception.ValidationException)

Aggregations

ComponentLifeCycleException (org.apache.nifi.controller.exception.ComponentLifeCycleException)7 ProcessorInstantiationException (org.apache.nifi.controller.exception.ProcessorInstantiationException)5 NarCloseable (org.apache.nifi.nar.NarCloseable)4 ResourceNotFoundException (org.apache.nifi.web.ResourceNotFoundException)4 IOException (java.io.IOException)3 ControllerServiceInstantiationException (org.apache.nifi.controller.exception.ControllerServiceInstantiationException)3 ReportingTaskInstantiationException (org.apache.nifi.controller.reporting.ReportingTaskInstantiationException)3 StandardValidationContextFactory (org.apache.nifi.processor.StandardValidationContextFactory)3 ComponentVariableRegistry (org.apache.nifi.registry.ComponentVariableRegistry)3 StandardComponentVariableRegistry (org.apache.nifi.registry.variable.StandardComponentVariableRegistry)3 ParseException (java.text.ParseException)2 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)2 UnknownServiceAddressException (org.apache.nifi.cluster.protocol.UnknownServiceAddressException)2 ProcessorNode (org.apache.nifi.controller.ProcessorNode)2 ScheduledState (org.apache.nifi.controller.ScheduledState)2 CommunicationsException (org.apache.nifi.controller.exception.CommunicationsException)2 ValidationException (org.apache.nifi.controller.exception.ValidationException)2 FlowSerializationException (org.apache.nifi.controller.serialization.FlowSerializationException)2 FlowSynchronizationException (org.apache.nifi.controller.serialization.FlowSynchronizationException)2 ProcessGroup (org.apache.nifi.groups.ProcessGroup)2