Search in sources :

Example 1 with ReportingTaskInstantiationException

use of org.apache.nifi.controller.reporting.ReportingTaskInstantiationException in project nifi by apache.

the class StandardReportingTaskDAO method createReportingTask.

@Override
public ReportingTaskNode createReportingTask(final ReportingTaskDTO reportingTaskDTO) {
    // ensure the type is specified
    if (reportingTaskDTO.getType() == null) {
        throw new IllegalArgumentException("The reporting task type must be specified.");
    }
    try {
        // create the reporting task
        final ReportingTaskNode reportingTask = reportingTaskProvider.createReportingTask(reportingTaskDTO.getType(), reportingTaskDTO.getId(), BundleUtils.getBundle(reportingTaskDTO.getType(), reportingTaskDTO.getBundle()), true);
        // ensure we can perform the update
        verifyUpdate(reportingTask, reportingTaskDTO);
        // perform the update
        configureReportingTask(reportingTask, reportingTaskDTO);
        return reportingTask;
    } catch (ReportingTaskInstantiationException rtie) {
        throw new NiFiCoreException(rtie.getMessage(), rtie);
    }
}
Also used : NiFiCoreException(org.apache.nifi.web.NiFiCoreException) ReportingTaskInstantiationException(org.apache.nifi.controller.reporting.ReportingTaskInstantiationException) ReportingTaskNode(org.apache.nifi.controller.ReportingTaskNode)

Example 2 with ReportingTaskInstantiationException

use of org.apache.nifi.controller.reporting.ReportingTaskInstantiationException in project nifi by apache.

the class FlowController method instantiateReportingTask.

private LoggableComponent<ReportingTask> instantiateReportingTask(final String type, final String id, final BundleCoordinate bundleCoordinate, final Set<URL> additionalUrls) throws ReportingTaskInstantiationException {
    final ClassLoader ctxClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        final Bundle reportingTaskBundle = ExtensionManager.getBundle(bundleCoordinate);
        if (reportingTaskBundle == null) {
            throw new IllegalStateException("Unable to find bundle for coordinate " + bundleCoordinate.getCoordinate());
        }
        final ClassLoader detectedClassLoader = ExtensionManager.createInstanceClassLoader(type, id, reportingTaskBundle, additionalUrls);
        final Class<?> rawClass = Class.forName(type, false, detectedClassLoader);
        Thread.currentThread().setContextClassLoader(detectedClassLoader);
        final Class<? extends ReportingTask> reportingTaskClass = rawClass.asSubclass(ReportingTask.class);
        final Object reportingTaskObj = reportingTaskClass.newInstance();
        final ReportingTask reportingTask = reportingTaskClass.cast(reportingTaskObj);
        final ComponentLog componentLog = new SimpleProcessLogger(id, reportingTask);
        final TerminationAwareLogger terminationAwareLogger = new TerminationAwareLogger(componentLog);
        return new LoggableComponent<>(reportingTask, bundleCoordinate, terminationAwareLogger);
    } catch (final Exception e) {
        throw new ReportingTaskInstantiationException(type, e);
    } finally {
        if (ctxClassLoader != null) {
            Thread.currentThread().setContextClassLoader(ctxClassLoader);
        }
    }
}
Also used : Bundle(org.apache.nifi.bundle.Bundle) ComponentLog(org.apache.nifi.logging.ComponentLog) 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) ReportingTaskInstantiationException(org.apache.nifi.controller.reporting.ReportingTaskInstantiationException) NarThreadContextClassLoader(org.apache.nifi.nar.NarThreadContextClassLoader) SimpleProcessLogger(org.apache.nifi.processor.SimpleProcessLogger) ReportingTask(org.apache.nifi.reporting.ReportingTask) GhostReportingTask(org.apache.nifi.reporting.GhostReportingTask)

Example 3 with ReportingTaskInstantiationException

use of org.apache.nifi.controller.reporting.ReportingTaskInstantiationException in project nifi by apache.

the class StandardFlowSynchronizer method getOrCreateReportingTask.

private ReportingTaskNode getOrCreateReportingTask(final FlowController controller, final ReportingTaskDTO dto, final boolean controllerInitialized, final boolean existingFlowEmpty) throws ReportingTaskInstantiationException {
    // create a new reporting task node when the controller is not initialized or the flow is empty
    if (!controllerInitialized || existingFlowEmpty) {
        BundleCoordinate coordinate;
        try {
            coordinate = BundleUtils.getCompatibleBundle(dto.getType(), dto.getBundle());
        } catch (final IllegalStateException e) {
            final BundleDTO bundleDTO = dto.getBundle();
            if (bundleDTO == null) {
                coordinate = BundleCoordinate.UNKNOWN_COORDINATE;
            } else {
                coordinate = new BundleCoordinate(bundleDTO.getGroup(), bundleDTO.getArtifact(), bundleDTO.getVersion());
            }
        }
        final ReportingTaskNode reportingTask = controller.createReportingTask(dto.getType(), dto.getId(), coordinate, false);
        reportingTask.setName(dto.getName());
        reportingTask.setComments(dto.getComments());
        reportingTask.setSchedulingPeriod(dto.getSchedulingPeriod());
        reportingTask.setSchedulingStrategy(SchedulingStrategy.valueOf(dto.getSchedulingStrategy()));
        reportingTask.setAnnotationData(dto.getAnnotationData());
        reportingTask.setProperties(dto.getProperties());
        final ComponentLog componentLog = new SimpleProcessLogger(dto.getId(), reportingTask.getReportingTask());
        final ReportingInitializationContext config = new StandardReportingInitializationContext(dto.getId(), dto.getName(), SchedulingStrategy.valueOf(dto.getSchedulingStrategy()), dto.getSchedulingPeriod(), componentLog, controller, nifiProperties, controller);
        try {
            reportingTask.getReportingTask().initialize(config);
        } catch (final InitializationException ie) {
            throw new ReportingTaskInstantiationException("Failed to initialize reporting task of type " + dto.getType(), ie);
        }
        return reportingTask;
    } else {
        // otherwise return the existing reporting task node
        return controller.getReportingTaskNode(dto.getId());
    }
}
Also used : ReportingTaskInstantiationException(org.apache.nifi.controller.reporting.ReportingTaskInstantiationException) ReportingInitializationContext(org.apache.nifi.reporting.ReportingInitializationContext) StandardReportingInitializationContext(org.apache.nifi.controller.reporting.StandardReportingInitializationContext) SimpleProcessLogger(org.apache.nifi.processor.SimpleProcessLogger) BundleDTO(org.apache.nifi.web.api.dto.BundleDTO) StandardReportingInitializationContext(org.apache.nifi.controller.reporting.StandardReportingInitializationContext) InitializationException(org.apache.nifi.reporting.InitializationException) BundleCoordinate(org.apache.nifi.bundle.BundleCoordinate) ComponentLog(org.apache.nifi.logging.ComponentLog)

Example 4 with ReportingTaskInstantiationException

use of org.apache.nifi.controller.reporting.ReportingTaskInstantiationException 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 5 with ReportingTaskInstantiationException

use of org.apache.nifi.controller.reporting.ReportingTaskInstantiationException in project nifi by apache.

the class StandardReportingTaskDAO method updateBundle.

private void updateBundle(ReportingTaskNode reportingTask, ReportingTaskDTO reportingTaskDTO) {
    final BundleDTO bundleDTO = reportingTaskDTO.getBundle();
    if (bundleDTO != null) {
        final BundleCoordinate incomingCoordinate = BundleUtils.getBundle(reportingTask.getCanonicalClassName(), bundleDTO);
        final BundleCoordinate existingCoordinate = reportingTask.getBundleCoordinate();
        if (!existingCoordinate.getCoordinate().equals(incomingCoordinate.getCoordinate())) {
            try {
                // we need to use the property descriptors from the temp component here in case we are changing from a ghost component to a real component
                final ConfigurableComponent tempComponent = ExtensionManager.getTempComponent(reportingTask.getCanonicalClassName(), incomingCoordinate);
                final Set<URL> additionalUrls = reportingTask.getAdditionalClasspathResources(tempComponent.getPropertyDescriptors());
                reloadComponent.reload(reportingTask, reportingTask.getCanonicalClassName(), incomingCoordinate, additionalUrls);
            } catch (ReportingTaskInstantiationException e) {
                throw new NiFiCoreException(String.format("Unable to update reporting task %s from %s to %s due to: %s", reportingTaskDTO.getId(), reportingTask.getBundleCoordinate().getCoordinate(), incomingCoordinate.getCoordinate(), e.getMessage()), e);
            }
        }
    }
}
Also used : NiFiCoreException(org.apache.nifi.web.NiFiCoreException) ReportingTaskInstantiationException(org.apache.nifi.controller.reporting.ReportingTaskInstantiationException) ConfigurableComponent(org.apache.nifi.components.ConfigurableComponent) BundleDTO(org.apache.nifi.web.api.dto.BundleDTO) BundleCoordinate(org.apache.nifi.bundle.BundleCoordinate) URL(java.net.URL)

Aggregations

ReportingTaskInstantiationException (org.apache.nifi.controller.reporting.ReportingTaskInstantiationException)5 InitializationException (org.apache.nifi.reporting.InitializationException)3 IOException (java.io.IOException)2 BundleCoordinate (org.apache.nifi.bundle.BundleCoordinate)2 UnknownServiceAddressException (org.apache.nifi.cluster.protocol.UnknownServiceAddressException)2 CommunicationsException (org.apache.nifi.controller.exception.CommunicationsException)2 ComponentLifeCycleException (org.apache.nifi.controller.exception.ComponentLifeCycleException)2 ControllerServiceInstantiationException (org.apache.nifi.controller.exception.ControllerServiceInstantiationException)2 ProcessorInstantiationException (org.apache.nifi.controller.exception.ProcessorInstantiationException)2 StandardReportingInitializationContext (org.apache.nifi.controller.reporting.StandardReportingInitializationContext)2 FlowSerializationException (org.apache.nifi.controller.serialization.FlowSerializationException)2 FlowSynchronizationException (org.apache.nifi.controller.serialization.FlowSynchronizationException)2 ComponentLog (org.apache.nifi.logging.ComponentLog)2 SimpleProcessLogger (org.apache.nifi.processor.SimpleProcessLogger)2 GhostReportingTask (org.apache.nifi.reporting.GhostReportingTask)2 ReportingInitializationContext (org.apache.nifi.reporting.ReportingInitializationContext)2 ReportingTask (org.apache.nifi.reporting.ReportingTask)2 NiFiCoreException (org.apache.nifi.web.NiFiCoreException)2 ResourceNotFoundException (org.apache.nifi.web.ResourceNotFoundException)2 BundleDTO (org.apache.nifi.web.api.dto.BundleDTO)2