org.apache.nifi.reporting.ReportingTask Java Examples

The following examples show how to use org.apache.nifi.reporting.ReportingTask. 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: StandardExtensionDiscoveringManager.java    From nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Loads extensions from the specified bundle.
 *
 * @param bundle from which to load extensions
 */
@SuppressWarnings("unchecked")
private void loadExtensions(final Bundle bundle) {
    for (final Map.Entry<Class, Set<Class>> entry : definitionMap.entrySet()) {
        final boolean isControllerService = ControllerService.class.equals(entry.getKey());
        final boolean isProcessor = Processor.class.equals(entry.getKey());
        final boolean isReportingTask = ReportingTask.class.equals(entry.getKey());

        final ServiceLoader<?> serviceLoader = ServiceLoader.load(entry.getKey(), bundle.getClassLoader());
        for (final Object o : serviceLoader) {
            try {
                loadExtension(o, entry.getKey(), bundle);
            } catch (Exception e) {
                logger.warn("Failed to register extension {} due to: {}" , new Object[]{o.getClass().getCanonicalName(), e.getMessage()});
                if (logger.isDebugEnabled()) {
                    logger.debug("", e);
                }
            }
        }

        classLoaderBundleLookup.put(bundle.getClassLoader(), bundle);
    }
}
 
Example #2
Source File: DocGenerator.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Generates documentation into the work/docs dir specified by
 * NiFiProperties.
 *
 * @param properties to lookup nifi properties
 */
public static void generate(final NiFiProperties properties) {
    @SuppressWarnings("rawtypes")
    final Set<Class> extensionClasses = new HashSet<>();
    extensionClasses.addAll(ExtensionManager.getExtensions(Processor.class));
    extensionClasses.addAll(ExtensionManager.getExtensions(ControllerService.class));
    extensionClasses.addAll(ExtensionManager.getExtensions(ReportingTask.class));

    final File explodedNiFiDocsDir = properties.getComponentDocumentationWorkingDirectory();

    logger.debug("Generating documentation for: " + extensionClasses.size() + " components in: "
            + explodedNiFiDocsDir);

    for (final Class<?> extensionClass : extensionClasses) {
        if (ConfigurableComponent.class.isAssignableFrom(extensionClass)) {
            final Class<? extends ConfigurableComponent> componentClass = extensionClass.asSubclass(ConfigurableComponent.class);
            try {
                logger.debug("Documenting: " + componentClass);
                document(explodedNiFiDocsDir, componentClass);
            } catch (Exception e) {
                logger.warn("Unable to document: " + componentClass, e);
            }
        }
    }
}
 
Example #3
Source File: StandardExtensionDiscoveringManager.java    From nifi with Apache License 2.0 6 votes vote down vote up
public StandardExtensionDiscoveringManager() {
    definitionMap.put(Processor.class, new HashSet<>());
    definitionMap.put(FlowFilePrioritizer.class, new HashSet<>());
    definitionMap.put(ReportingTask.class, new HashSet<>());
    definitionMap.put(ControllerService.class, new HashSet<>());
    definitionMap.put(Authorizer.class, new HashSet<>());
    definitionMap.put(UserGroupProvider.class, new HashSet<>());
    definitionMap.put(AccessPolicyProvider.class, new HashSet<>());
    definitionMap.put(LoginIdentityProvider.class, new HashSet<>());
    definitionMap.put(ProvenanceRepository.class, new HashSet<>());
    definitionMap.put(ComponentStatusRepository.class, new HashSet<>());
    definitionMap.put(FlowFileRepository.class, new HashSet<>());
    definitionMap.put(FlowFileSwapManager.class, new HashSet<>());
    definitionMap.put(ContentRepository.class, new HashSet<>());
    definitionMap.put(StateProvider.class, new HashSet<>());
    definitionMap.put(StatusAnalyticsModel.class, new HashSet<>());
}
 
Example #4
Source File: TestSimpleProcessLogger.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Before
public void before() {
    task = mock(ReportingTask.class);
    when(task.getIdentifier()).thenReturn("foo");
    when(task.toString()).thenReturn("MyTask");
    componentLog = new SimpleProcessLogger(task.getIdentifier(), task);
    try {
        Field loggerField = componentLog.getClass().getDeclaredField("logger");
        loggerField.setAccessible(true);
        logger = mock(Logger.class);

        when(logger.isDebugEnabled()).thenReturn(true);
        when(logger.isInfoEnabled()).thenReturn(true);
        when(logger.isWarnEnabled()).thenReturn(true);
        when(logger.isErrorEnabled()).thenReturn(true);
        when(logger.isTraceEnabled()).thenReturn(true);

        loggerField.set(componentLog, logger);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
 
Example #5
Source File: FlowController.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
private void notifyComponentsConfigurationRestored() {
    for (final ProcessorNode procNode : getGroup(getRootGroupId()).findAllProcessors()) {
        final Processor processor = procNode.getProcessor();
        try (final NarCloseable nc = NarCloseable.withComponentNarLoader(processor.getClass(), processor.getIdentifier())) {
            ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnConfigurationRestored.class, processor);
        }
    }

    for (final ControllerServiceNode serviceNode : getAllControllerServices()) {
        final ControllerService service = serviceNode.getControllerServiceImplementation();

        try (final NarCloseable nc = NarCloseable.withComponentNarLoader(service.getClass(), service.getIdentifier())) {
            ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnConfigurationRestored.class, service);
        }
    }

    for (final ReportingTaskNode taskNode : getAllReportingTasks()) {
        final ReportingTask task = taskNode.getReportingTask();

        try (final NarCloseable nc = NarCloseable.withComponentNarLoader(task.getClass(), task.getIdentifier())) {
            ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnConfigurationRestored.class, task);
        }
    }
}
 
Example #6
Source File: StandardReportingContext.java    From nifi with Apache License 2.0 6 votes vote down vote up
public StandardReportingContext(final FlowController flowController, final BulletinRepository bulletinRepository,
                                final Map<PropertyDescriptor, String> properties, final ReportingTask reportingTask,
                                final VariableRegistry variableRegistry, final ParameterLookup parameterLookup) {
    this.flowController = flowController;
    this.eventAccess = flowController.getEventAccess();
    this.bulletinRepository = bulletinRepository;
    this.properties = Collections.unmodifiableMap(properties);
    this.serviceProvider = flowController.getControllerServiceProvider();
    this.reportingTask = reportingTask;
    this.variableRegistry = variableRegistry;
    this.parameterLookup = parameterLookup;
    this.analyticsEnabled = flowController.getStatusAnalyticsEngine() != null;
    preparedQueries = new HashMap<>();

    for (final Map.Entry<PropertyDescriptor, String> entry : properties.entrySet()) {
        final PropertyDescriptor desc = entry.getKey();
        String value = entry.getValue();
        if (value == null) {
            value = desc.getDefaultValue();
        }

        final PreparedQuery pq = Query.prepare(value);
        preparedQueries.put(desc, pq);
    }
}
 
Example #7
Source File: TestSimpleProcessLogger.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Before
public void before() {
    task = mock(ReportingTask.class);
    when(task.getIdentifier()).thenReturn("foo");
    when(task.toString()).thenReturn("MyTask");
    componentLog = new SimpleProcessLogger(task.getIdentifier(), task);
    try {
        Field loggerField = componentLog.getClass().getDeclaredField("logger");
        loggerField.setAccessible(true);
        logger = mock(Logger.class);

        when(logger.isDebugEnabled()).thenReturn(true);
        when(logger.isInfoEnabled()).thenReturn(true);
        when(logger.isWarnEnabled()).thenReturn(true);
        when(logger.isErrorEnabled()).thenReturn(true);
        when(logger.isTraceEnabled()).thenReturn(true);

        loggerField.set(componentLog, logger);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
 
Example #8
Source File: FingerprintFactory.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
private void addReportingTaskFingerprint(final StringBuilder builder, final ReportingTaskDTO dto, final FlowController controller) {
    builder.append(dto.getId());
    builder.append(dto.getType());
    builder.append(dto.getName());
    builder.append(dto.getComments());
    builder.append(dto.getSchedulingPeriod());
    builder.append(dto.getSchedulingStrategy());
    builder.append(dto.getAnnotationData());

    // create an instance of the ReportingTask so that we know the default property values
    ReportingTask reportingTask = null;
    try {
        if (controller != null) {
            reportingTask = controller.createReportingTask(dto.getType(), UUID.randomUUID().toString(), false, false).getReportingTask();
        }
    } catch (Exception e) {
        logger.warn("Unable to create ReportingTask of type {} due to {}; its default properties will be fingerprinted instead of being ignored.", dto.getType(), e.toString());
        if (logger.isDebugEnabled()) {
            logger.warn("", e);
        }
    }

    addPropertiesFingerprint(builder, reportingTask, dto.getProperties());
}
 
Example #9
Source File: FlowController.java    From nifi with Apache License 2.0 6 votes vote down vote up
private void notifyComponentsConfigurationRestored() {
    for (final ProcessorNode procNode : flowManager.getRootGroup().findAllProcessors()) {
        final Processor processor = procNode.getProcessor();
        try (final NarCloseable nc = NarCloseable.withComponentNarLoader(extensionManager, processor.getClass(), processor.getIdentifier())) {
            ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnConfigurationRestored.class, processor);
        }
    }

    for (final ControllerServiceNode serviceNode : flowManager.getAllControllerServices()) {
        final ControllerService service = serviceNode.getControllerServiceImplementation();

        try (final NarCloseable nc = NarCloseable.withComponentNarLoader(extensionManager, service.getClass(), service.getIdentifier())) {
            ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnConfigurationRestored.class, service);
        }
    }

    for (final ReportingTaskNode taskNode : getAllReportingTasks()) {
        final ReportingTask task = taskNode.getReportingTask();

        try (final NarCloseable nc = NarCloseable.withComponentNarLoader(extensionManager, task.getClass(), task.getIdentifier())) {
            ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnConfigurationRestored.class, task);
        }
    }
}
 
Example #10
Source File: StandardReportingContext.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
public StandardReportingContext(final FlowController flowController, final BulletinRepository bulletinRepository,
                                final Map<PropertyDescriptor, String> properties, final ControllerServiceProvider serviceProvider, final ReportingTask reportingTask,
                                final VariableRegistry variableRegistry) {
    this.flowController = flowController;
    this.eventAccess = flowController;
    this.bulletinRepository = bulletinRepository;
    this.properties = Collections.unmodifiableMap(properties);
    this.serviceProvider = serviceProvider;
    this.reportingTask = reportingTask;
    this.variableRegistry = variableRegistry;
    preparedQueries = new HashMap<>();
    for (final Map.Entry<PropertyDescriptor, String> entry : properties.entrySet()) {
        final PropertyDescriptor desc = entry.getKey();
        String value = entry.getValue();
        if (value == null) {
            value = desc.getDefaultValue();
        }

        final PreparedQuery pq = Query.prepare(value);
        preparedQueries.put(desc, pq);
    }
}
 
Example #11
Source File: TestNarLoader.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testNarLoaderWhenAllAvailable() throws IOException {
    // Copy all NARs from src/test/resources/extensions to target/extensions
    final File extensionsDir = new File(EXTENSIONS_DIR);
    final Path narAutoLoadDir = Paths.get(NAR_AUTOLOAD_DIR);
    for (final File extensionFile : extensionsDir.listFiles()) {
        Files.copy(extensionFile.toPath(), narAutoLoadDir.resolve(extensionFile.getName()), StandardCopyOption.REPLACE_EXISTING);
    }

    final List<File> narFiles = Arrays.asList(narAutoLoadDir.toFile().listFiles());
    assertEquals(3, narFiles.size());

    final NarLoadResult narLoadResult = narLoader.load(narFiles);
    assertNotNull(narLoadResult);
    assertEquals(3, narLoadResult.getLoadedBundles().size());
    assertEquals(0, narLoadResult.getSkippedBundles().size());

    assertEquals(5, narClassLoaders.getBundles().size());
    assertEquals(1, extensionManager.getExtensions(Processor.class).size());
    assertEquals(1, extensionManager.getExtensions(ControllerService.class).size());
    assertEquals(0, extensionManager.getExtensions(ReportingTask.class).size());
}
 
Example #12
Source File: ExtensionBuilder.java    From nifi with Apache License 2.0 6 votes vote down vote up
private ReportingTaskNode createReportingTaskNode(final LoggableComponent<ReportingTask> reportingTask, final boolean creationSuccessful) {
    final ComponentVariableRegistry componentVarRegistry = new StandardComponentVariableRegistry(this.variableRegistry);
    final ValidationContextFactory validationContextFactory = new StandardValidationContextFactory(serviceProvider, componentVarRegistry);
    final ReportingTaskNode taskNode;
    if (creationSuccessful) {
        taskNode = new StandardReportingTaskNode(reportingTask, identifier, flowController, processScheduler,
                validationContextFactory, componentVarRegistry, reloadComponent, extensionManager, validationTrigger);
        taskNode.setName(taskNode.getReportingTask().getClass().getSimpleName());
    } else {
        final String simpleClassName = type.contains(".") ? StringUtils.substringAfterLast(type, ".") : type;
        final String componentType = "(Missing) " + simpleClassName;

        taskNode = new StandardReportingTaskNode(reportingTask, identifier, flowController, processScheduler, validationContextFactory,
                componentType, type, componentVarRegistry, reloadComponent, extensionManager, validationTrigger, true);
        taskNode.setName(componentType);
    }

    return taskNode;
}
 
Example #13
Source File: AbstractDocumentationWriter.java    From nifi with Apache License 2.0 5 votes vote down vote up
protected ExtensionType getExtensionType(final ConfigurableComponent component) {
    if (component instanceof Processor) {
        return ExtensionType.PROCESSOR;
    }
    if (component instanceof ControllerService) {
        return ExtensionType.CONTROLLER_SERVICE;
    }
    if (component instanceof ReportingTask) {
        return ExtensionType.REPORTING_TASK;
    }
    throw new AssertionError("Encountered unknown Configurable Component Type for " + component);
}
 
Example #14
Source File: AbstractReportingTaskNode.java    From nifi with Apache License 2.0 5 votes vote down vote up
public AbstractReportingTaskNode(final LoggableComponent<ReportingTask> reportingTask, final String id,
                                 final ControllerServiceProvider controllerServiceProvider, final ProcessScheduler processScheduler,
                                 final ValidationContextFactory validationContextFactory, final ComponentVariableRegistry variableRegistry,
                                 final ReloadComponent reloadComponent, final ExtensionManager extensionManager, final ValidationTrigger validationTrigger) {

    this(reportingTask, id, controllerServiceProvider, processScheduler, validationContextFactory,
            reportingTask.getComponent().getClass().getSimpleName(), reportingTask.getComponent().getClass().getCanonicalName(),
            variableRegistry, reloadComponent, extensionManager, validationTrigger, false);
}
 
Example #15
Source File: DocGenerator.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the DocumentationWriter for the type of component. Currently
 * Processor, ControllerService, and ReportingTask are supported.
 *
 * @param componentClass the class that requires a DocumentationWriter
 * @return a DocumentationWriter capable of generating documentation for
 * that specific type of class
 */
private static DocumentationWriter getDocumentWriter(final ExtensionManager extensionManager,
                                                              final Class<? extends ConfigurableComponent> componentClass) {
    if (Processor.class.isAssignableFrom(componentClass)) {
        return new HtmlProcessorDocumentationWriter(extensionManager);
    } else if (ControllerService.class.isAssignableFrom(componentClass)) {
        return new HtmlDocumentationWriter(extensionManager);
    } else if (ReportingTask.class.isAssignableFrom(componentClass)) {
        return new HtmlDocumentationWriter(extensionManager);
    }

    return null;
}
 
Example #16
Source File: DocGenerator.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Generates documentation into the work/docs dir specified by
 * NiFiProperties.
 *
 * @param properties to lookup nifi properties
 * @param extensionMapping extension mapping
 */
public static void generate(final NiFiProperties properties, final ExtensionManager extensionManager, final ExtensionMapping extensionMapping) {
    final File explodedNiFiDocsDir = properties.getComponentDocumentationWorkingDirectory();

    logger.debug("Generating documentation for: " + extensionMapping.size() + " components in: " + explodedNiFiDocsDir);

    documentConfigurableComponent(extensionManager.getExtensions(Processor.class), explodedNiFiDocsDir, extensionManager);
    documentConfigurableComponent(extensionManager.getExtensions(ControllerService.class), explodedNiFiDocsDir, extensionManager);
    documentConfigurableComponent(extensionManager.getExtensions(ReportingTask.class), explodedNiFiDocsDir, extensionManager);
}
 
Example #17
Source File: StandardReportingTaskNode.java    From nifi with Apache License 2.0 5 votes vote down vote up
public StandardReportingTaskNode(final LoggableComponent<ReportingTask> reportingTask, final String id, final FlowController controller,
                                 final ProcessScheduler processScheduler, final ValidationContextFactory validationContextFactory,
                                 final String componentType, final String canonicalClassName, final ComponentVariableRegistry variableRegistry,
                                 final ReloadComponent reloadComponent, final ExtensionManager extensionManager, final ValidationTrigger validationTrigger, final boolean isExtensionMissing) {
    super(reportingTask, id, controller.getControllerServiceProvider(), processScheduler, validationContextFactory, componentType, canonicalClassName,
        variableRegistry, reloadComponent, extensionManager, validationTrigger, isExtensionMissing);
    this.flowController = controller;
}
 
Example #18
Source File: ConfigurableComponentInitializerFactory.java    From nifi-minifi with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a ConfigurableComponentInitializer for the type of component.
 * Currently Processor, ControllerService and ReportingTask are supported.
 *
 * @param componentClass the class that requires a ConfigurableComponentInitializer
 * @return a ConfigurableComponentInitializer capable of initializing that specific type of class
 */
public static ConfigurableComponentInitializer createComponentInitializer(final Class<? extends ConfigurableComponent> componentClass) {
    if (Processor.class.isAssignableFrom(componentClass)) {
        return new ProcessorInitializer();
    } else if (ControllerService.class.isAssignableFrom(componentClass)) {
        return new ControllerServiceInitializer();
    } else if (ReportingTask.class.isAssignableFrom(componentClass)) {
        return new ReportingTaskingInitializer();
    }

    return null;
}
 
Example #19
Source File: ReportingTaskingInitializer.java    From nifi-minifi with Apache License 2.0 5 votes vote down vote up
@Override
public void teardown(ConfigurableComponent component) {
    ReportingTask reportingTask = (ReportingTask) component;
    try (NarCloseable narCloseable = NarCloseable.withComponentNarLoader(component.getClass(), component.getIdentifier())) {

        final MockConfigurationContext context = new MockConfigurationContext();
        ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnShutdown.class, reportingTask, new MockComponentLogger(), context);
    } finally {
        ExtensionManager.removeInstanceClassLoader(component.getIdentifier());
    }
}
 
Example #20
Source File: AbstractReportingTaskNode.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
public AbstractReportingTaskNode(final ReportingTask reportingTask, final String id,
                                 final ControllerServiceProvider controllerServiceProvider, final ProcessScheduler processScheduler,
                                 final ValidationContextFactory validationContextFactory, final VariableRegistry variableRegistry,
                                 final ComponentLog logger) {

    this(reportingTask, id, controllerServiceProvider, processScheduler, validationContextFactory,
        reportingTask.getClass().getSimpleName(), reportingTask.getClass().getCanonicalName(),variableRegistry, logger);
}
 
Example #21
Source File: ReportingTaskingInitializer.java    From nifi-minifi with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(ConfigurableComponent component) throws InitializationException {
    ReportingTask reportingTask = (ReportingTask) component;
    ReportingInitializationContext context = new MockReportingInitializationContext();
    try (NarCloseable narCloseable = NarCloseable.withComponentNarLoader(component.getClass(), context.getIdentifier())) {
        reportingTask.initialize(context);
    }
}
 
Example #22
Source File: AbstractReportingTaskNode.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public void setReportingTask(final LoggableComponent<ReportingTask> reportingTask) {
    if (isRunning()) {
        throw new IllegalStateException("Cannot modify Reporting Task configuration while Reporting Task is running");
    }
    this.reportingTaskRef.set(new ReportingTaskDetails(reportingTask));
}
 
Example #23
Source File: StandardReportingTaskNode.java    From nifi with Apache License 2.0 5 votes vote down vote up
public StandardReportingTaskNode(final LoggableComponent<ReportingTask> reportingTask, final String id, final FlowController controller,
                                 final ProcessScheduler processScheduler, final ValidationContextFactory validationContextFactory,
                                 final ComponentVariableRegistry variableRegistry, final ReloadComponent reloadComponent, final ExtensionManager extensionManager,
                                 final ValidationTrigger validationTrigger) {
    super(reportingTask, id, controller.getControllerServiceProvider(), processScheduler, validationContextFactory, variableRegistry, reloadComponent, extensionManager, validationTrigger);
    this.flowController = controller;
}
 
Example #24
Source File: ReportingTaskingInitializer.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(ConfigurableComponent component) throws InitializationException {
    ReportingTask reportingTask = (ReportingTask) component;
    ReportingInitializationContext context = new MockReportingInitializationContext();
    try (NarCloseable narCloseable = NarCloseable.withComponentNarLoader(component.getClass(), context.getIdentifier())) {
        reportingTask.initialize(context);
    }
}
 
Example #25
Source File: ExtensionBuilder.java    From nifi with Apache License 2.0 5 votes vote down vote up
private LoggableComponent<ReportingTask> createLoggableReportingTask() throws ReportingTaskInstantiationException {
    try {
        final LoggableComponent<ReportingTask> taskComponent = createLoggableComponent(ReportingTask.class);

        final String taskName = taskComponent.getComponent().getClass().getSimpleName();
        final ReportingInitializationContext config = new StandardReportingInitializationContext(identifier, taskName,
                SchedulingStrategy.TIMER_DRIVEN, "1 min", taskComponent.getLogger(), serviceProvider, kerberosConfig, nodeTypeProvider);

        taskComponent.getComponent().initialize(config);

        return taskComponent;
    } catch (final Exception e) {
        throw new ReportingTaskInstantiationException(type, e);
    }
}
 
Example #26
Source File: DirectInjectionExtensionManager.java    From nifi with Apache License 2.0 5 votes vote down vote up
public void injectExtension(final Object extension) {
    final Class<?> extensionType;
    if (extension instanceof Processor) {
        extensionType = Processor.class;
    } else if (extension instanceof ControllerService) {
        extensionType = ControllerService.class;
    } else if (extension instanceof ReportingTask) {
        extensionType = ReportingTask.class;
    } else {
        throw new IllegalArgumentException("Given extension is not a Processor, Controller Service, or Reporting Task");
    }

    super.loadExtension(extension, extensionType, INTEGRATION_TEST_BUNDLE);
}
 
Example #27
Source File: ConfigurableComponentInitializerFactory.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a ConfigurableComponentInitializer for the type of component.
 * Currently Processor, ControllerService and ReportingTask are supported.
 *
 * @param componentClass the class that requires a ConfigurableComponentInitializer
 * @return a ConfigurableComponentInitializer capable of initializing that specific type of class
 */
public static ConfigurableComponentInitializer createComponentInitializer(
        final ExtensionManager extensionManager, final Class<? extends ConfigurableComponent> componentClass) {
    if (Processor.class.isAssignableFrom(componentClass)) {
        return new ProcessorInitializer(extensionManager);
    } else if (ControllerService.class.isAssignableFrom(componentClass)) {
        return new ControllerServiceInitializer(extensionManager);
    } else if (ReportingTask.class.isAssignableFrom(componentClass)) {
        return new ReportingTaskingInitializer(extensionManager);
    }

    return null;
}
 
Example #28
Source File: ReportingTaskingInitializer.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(ConfigurableComponent component) throws InitializationException {
    ReportingTask reportingTask = (ReportingTask) component;
    ReportingInitializationContext context = new MockReportingInitializationContext();
    try (NarCloseable narCloseable = NarCloseable.withComponentNarLoader(extensionManager, component.getClass(), context.getIdentifier())) {
        reportingTask.initialize(context);
    }
}
 
Example #29
Source File: ReportingTaskingInitializer.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public void teardown(ConfigurableComponent component) {
    ReportingTask reportingTask = (ReportingTask) component;
    try (NarCloseable narCloseable = NarCloseable.withComponentNarLoader(extensionManager, component.getClass(), component.getIdentifier())) {

        final MockConfigurationContext context = new MockConfigurationContext();
        ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnShutdown.class, reportingTask, new MockComponentLogger(), context);
    } finally {
        extensionManager.removeInstanceClassLoader(component.getIdentifier());
    }
}
 
Example #30
Source File: StandardExtensionDiscoveringManager.java    From nifi with Apache License 2.0 5 votes vote down vote up
protected void loadExtension(final Object extension, final Class<?> extensionType, final Bundle bundle) {
    final boolean isControllerService = ControllerService.class.equals(extensionType);
    final boolean isProcessor = Processor.class.equals(extensionType);
    final boolean isReportingTask = ReportingTask.class.equals(extensionType);

    // create a cache of temp ConfigurableComponent instances, the initialize here has to happen before the checks below
    if ((isControllerService || isProcessor || isReportingTask) && extension instanceof ConfigurableComponent) {
        final ConfigurableComponent configurableComponent = (ConfigurableComponent) extension;
        initializeTempComponent(configurableComponent);

        final String cacheKey = getClassBundleKey(extension.getClass().getCanonicalName(), bundle.getBundleDetails().getCoordinate());
        tempComponentLookup.put(cacheKey, configurableComponent);
    }

    // only consider extensions discovered directly in this bundle
    boolean registerExtension = bundle.getClassLoader().equals(extension.getClass().getClassLoader());

    if (registerExtension) {
        final Class<?> extensionClass = extension.getClass();
        if (isControllerService && !checkControllerServiceEligibility(extensionClass)) {
            registerExtension = false;
            logger.error(String.format(
                "Skipping Controller Service %s because it is bundled with its supporting APIs and requires instance class loading.", extensionClass.getName()));
        }

        final boolean canReferenceControllerService = (isControllerService || isProcessor || isReportingTask) && extension instanceof ConfigurableComponent;
        if (canReferenceControllerService && !checkControllerServiceReferenceEligibility((ConfigurableComponent) extension, bundle.getClassLoader())) {
            registerExtension = false;
            logger.error(String.format(
                "Skipping component %s because it is bundled with its referenced Controller Service APIs and requires instance class loading.", extensionClass.getName()));
        }

        if (registerExtension) {
            registerExtensionClass(extensionType, extension.getClass(), bundle);
        }
    }
}