org.apache.nifi.nar.ExtensionManager Java Examples

The following examples show how to use org.apache.nifi.nar.ExtensionManager. 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: StandardXMLFlowConfigurationDAO.java    From nifi with Apache License 2.0 6 votes vote down vote up
public StandardXMLFlowConfigurationDAO(final Path flowXml, final StringEncryptor encryptor, final NiFiProperties nifiProperties,
                                       final ExtensionManager extensionManager) throws IOException {
    this.nifiProperties = nifiProperties;
    final File flowXmlFile = flowXml.toFile();
    if (!flowXmlFile.exists()) {
        // createDirectories would throw an exception if the directory exists but is a symbolic link
        if (Files.notExists(flowXml.getParent())) {
            Files.createDirectories(flowXml.getParent());
        }
        Files.createFile(flowXml);
        //TODO: find a better solution. With Windows 7 and Java 7, Files.isWritable(source.getParent()) returns false, even when it should be true.
    } else if (!flowXmlFile.canRead() || !flowXmlFile.canWrite()) {
        throw new IOException(flowXml + " exists but you have insufficient read/write privileges");
    }

    this.flowXmlPath = flowXml;
    this.encryptor = encryptor;
    this.extensionManager = extensionManager;

    this.archiveManager = new FlowConfigurationArchiveManager(flowXmlPath, nifiProperties);
}
 
Example #2
Source File: AbstractComponentNode.java    From nifi with Apache License 2.0 6 votes vote down vote up
public AbstractComponentNode(final String id,
                             final ValidationContextFactory validationContextFactory, final ControllerServiceProvider serviceProvider,
                             final String componentType, final String componentCanonicalClass, final ComponentVariableRegistry variableRegistry,
                             final ReloadComponent reloadComponent, final ExtensionManager extensionManager, final ValidationTrigger validationTrigger, final boolean isExtensionMissing) {
    this.id = id;
    this.validationContextFactory = validationContextFactory;
    this.serviceProvider = serviceProvider;
    this.name = new AtomicReference<>(componentType);
    this.componentType = componentType;
    this.componentCanonicalClass = componentCanonicalClass;
    this.reloadComponent = reloadComponent;
    this.variableRegistry = variableRegistry;
    this.validationTrigger = validationTrigger;
    this.extensionManager = extensionManager;
    this.isExtensionMissing = new AtomicBoolean(isExtensionMissing);
}
 
Example #3
Source File: AbstractComponentNode.java    From nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Determines if the given controller service node has the required API as an ancestor.
 *
 * @param controllerServiceImplBundle the bundle of a controller service being referenced by a processor
 * @param requiredApiCoordinate the controller service API required by the processor
 * @return true if the controller service node has the require API as an ancestor, false otherwise
 */
private boolean matchesApi(final ExtensionManager extensionManager, final Bundle controllerServiceImplBundle, final BundleCoordinate requiredApiCoordinate) {
    // start with the coordinate of the controller service for cases where the API and service are in the same bundle
    BundleCoordinate controllerServiceDependencyCoordinate = controllerServiceImplBundle.getBundleDetails().getCoordinate();

    boolean foundApiDependency = false;
    while (controllerServiceDependencyCoordinate != null) {
        // determine if the dependency coordinate matches the required API
        if (requiredApiCoordinate.equals(controllerServiceDependencyCoordinate)) {
            foundApiDependency = true;
            break;
        }

        // move to the next dependency in the chain, or stop if null
        final Bundle controllerServiceDependencyBundle = extensionManager.getBundle(controllerServiceDependencyCoordinate);
        if (controllerServiceDependencyBundle == null) {
            controllerServiceDependencyCoordinate = null;
        } else {
            controllerServiceDependencyCoordinate = controllerServiceDependencyBundle.getBundleDetails().getDependencyCoordinate();
        }
    }

    return foundApiDependency;
}
 
Example #4
Source File: StandardStateManagerProvider.java    From nifi with Apache License 2.0 6 votes vote down vote up
public static synchronized StateManagerProvider create(final NiFiProperties properties, final VariableRegistry variableRegistry, final ExtensionManager extensionManager,
                                                       final ParameterLookup parameterLookup) throws ConfigParseException, IOException {
    if (provider != null) {
        return provider;
    }

    final StateProvider localProvider = createLocalStateProvider(properties,variableRegistry, extensionManager, parameterLookup);

    final StateProvider clusterProvider;
    if (properties.isNode()) {
        clusterProvider = createClusteredStateProvider(properties,variableRegistry, extensionManager, parameterLookup);
    } else {
        clusterProvider = null;
    }

    provider = new StandardStateManagerProvider(localProvider, clusterProvider);
    return provider;
}
 
Example #5
Source File: EventDrivenSchedulingAgent.java    From nifi with Apache License 2.0 6 votes vote down vote up
public EventDrivenSchedulingAgent(final FlowEngine flowEngine, final ControllerServiceProvider serviceProvider, final StateManagerProvider stateManagerProvider,
                                  final EventDrivenWorkerQueue workerQueue, final RepositoryContextFactory contextFactory, final int maxThreadCount,
                                  final StringEncryptor encryptor, final ExtensionManager extensionManager) {
    super(flowEngine);
    this.serviceProvider = serviceProvider;
    this.stateManagerProvider = stateManagerProvider;
    this.workerQueue = workerQueue;
    this.contextFactory = contextFactory;
    this.maxThreadCount = new AtomicInteger(maxThreadCount);
    this.encryptor = encryptor;
    this.extensionManager = extensionManager;

    for (int i = 0; i < maxThreadCount; i++) {
        final Runnable eventDrivenTask = new EventDrivenTask(workerQueue, activeThreadCount);
        flowEngine.scheduleWithFixedDelay(eventDrivenTask, 0L, 1L, TimeUnit.NANOSECONDS);
    }
}
 
Example #6
Source File: StandardStateManagerProvider.java    From nifi with Apache License 2.0 6 votes vote down vote up
private static StateProvider instantiateStateProvider(final ExtensionManager extensionManager, final String type) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
    final ClassLoader ctxClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        final List<Bundle> bundles = extensionManager.getBundles(type);
        if (bundles.size() == 0) {
            throw new IllegalStateException(String.format("The specified class '%s' is not known to this nifi.", type));
        }
        if (bundles.size() > 1) {
            throw new IllegalStateException(String.format("Multiple bundles found for the specified class '%s', only one is allowed.", type));
        }

        final Bundle bundle = bundles.get(0);
        final ClassLoader detectedClassLoaderForType = bundle.getClassLoader();
        final Class<?> rawClass = Class.forName(type, true, detectedClassLoaderForType);

        Thread.currentThread().setContextClassLoader(detectedClassLoaderForType);
        final Class<? extends StateProvider> mgrClass = rawClass.asSubclass(StateProvider.class);
        return withNarClassLoader(mgrClass.newInstance());
    } finally {
        if (ctxClassLoader != null) {
            Thread.currentThread().setContextClassLoader(ctxClassLoader);
        }
    }
}
 
Example #7
Source File: BundleUtils.java    From nifi with Apache License 2.0 6 votes vote down vote up
private static BundleCoordinate findCompatibleBundle(final ExtensionManager extensionManager, final String type,
                                                     final BundleDTO bundleDTO, final boolean allowCompatibleBundle) {
    final BundleCoordinate coordinate = new BundleCoordinate(bundleDTO.getGroup(), bundleDTO.getArtifact(), bundleDTO.getVersion());
    final Bundle bundle = extensionManager.getBundle(coordinate);

    if (bundle == null) {
        if (allowCompatibleBundle) {
            return findBundleForType(extensionManager, type, coordinate);
        } else {
            throw new IllegalStateException(String.format("%s from %s is not known to this NiFi instance.", type, coordinate));
        }
    } else {
        final List<BundleCoordinate> bundlesForType = extensionManager.getBundles(type).stream().map(b -> b.getBundleDetails().getCoordinate()).collect(Collectors.toList());
        if (bundlesForType.contains(coordinate)) {
            return coordinate;
        } else {
            throw new IllegalStateException(String.format("Found bundle %s but does not support %s", coordinate, type));
        }
    }
}
 
Example #8
Source File: ComponentDAO.java    From nifi with Apache License 2.0 6 votes vote down vote up
protected void verifyCreate(final ExtensionManager extensionManager, final String type, final BundleDTO bundle) {
    final List<Bundle> bundles = extensionManager.getBundles(type);

    if (bundle != null) {
        final BundleCoordinate coordinate = new BundleCoordinate(bundle.getGroup(), bundle.getArtifact(), bundle.getVersion());
        if (bundles.stream().filter(b -> b.getBundleDetails().getCoordinate().equals(coordinate)).count() == 0) {
            throw new IllegalStateException(String.format("%s is not known to this NiFi instance.", coordinate.toString()));
        }
    } else {
        if (bundles.isEmpty()) {
            throw new IllegalStateException(String.format("%s is not known to this NiFi instance.", type));
        } else if (bundles.size() > 1) {
            throw new IllegalStateException(String.format("Multiple versions of %s exist. Please specify the desired bundle.", type));
        }
    }
}
 
Example #9
Source File: StandardReportingTaskDAO.java    From nifi with Apache License 2.0 6 votes vote down vote up
@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 ExtensionManager extensionManager = reportingTaskProvider.getExtensionManager();
        final BundleCoordinate bundleCoordinate = BundleUtils.getBundle(extensionManager, reportingTaskDTO.getType(), reportingTaskDTO.getBundle());
        final ReportingTaskNode reportingTask = reportingTaskProvider.createReportingTask(
                reportingTaskDTO.getType(), reportingTaskDTO.getId(), bundleCoordinate, 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);
    }
}
 
Example #10
Source File: StandardControllerServiceProvider.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public void removeControllerService(final ControllerServiceNode serviceNode) {
    requireNonNull(serviceNode);
    serviceCache.remove(serviceNode.getIdentifier());

    final ProcessGroup group = serviceNode.getProcessGroup();
    if (group == null) {
        flowManager.removeRootControllerService(serviceNode);
        return;
    }

    group.removeControllerService(serviceNode);
    LogRepositoryFactory.removeRepository(serviceNode.getIdentifier());
    final ExtensionManager extensionManager = flowController.getExtensionManager();
    extensionManager.removeInstanceClassLoader(serviceNode.getIdentifier());
    serviceCache.remove(serviceNode.getIdentifier());
}
 
Example #11
Source File: StandardProcessorDAO.java    From nifi with Apache License 2.0 6 votes vote down vote up
private void updateBundle(ProcessorNode processor, ProcessorDTO processorDTO) {
    final BundleDTO bundleDTO = processorDTO.getBundle();
    if (bundleDTO != null) {
        final ExtensionManager extensionManager = flowController.getExtensionManager();
        final BundleCoordinate incomingCoordinate = BundleUtils.getBundle(extensionManager, processor.getCanonicalClassName(), bundleDTO);
        final BundleCoordinate existingCoordinate = processor.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(processor.getCanonicalClassName(), incomingCoordinate);
                final Set<URL> additionalUrls = processor.getAdditionalClasspathResources(tempComponent.getPropertyDescriptors());
                flowController.getReloadComponent().reload(processor, processor.getCanonicalClassName(), incomingCoordinate, additionalUrls);
            } catch (ProcessorInstantiationException e) {
                throw new NiFiCoreException(String.format("Unable to update processor %s from %s to %s due to: %s",
                        processorDTO.getId(), processor.getBundleCoordinate().getCoordinate(), incomingCoordinate.getCoordinate(), e.getMessage()), e);
            }
        }
    }
}
 
Example #12
Source File: AbstractControllerSearchIntegrationTest.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() {
    resetResults();
    processGroups = new HashSet<>();
    parameterContexts = new HashSet<>();

    final FlowManager flowManager = Mockito.mock(FlowManager.class);
    final ParameterContextManager parameterContextManager = Mockito.mock(ParameterContextManager.class);

    Mockito.when(flowController.getFlowManager()).thenReturn(flowManager);
    Mockito.when(flowManager.getParameterContextManager()).thenReturn(parameterContextManager);
    Mockito.when(parameterContextManager.getParameterContexts()).thenReturn(parameterContexts);

    ExtensionManager extensionManager = Mockito.mock(ExtensionManager.class);
    Mockito.when(flowController.getExtensionManager()).thenReturn(extensionManager);
}
 
Example #13
Source File: ExtensionDiscovery.java    From nifi with Apache License 2.0 6 votes vote down vote up
public static ExtensionManager discover(final File narWorkingDirectory, final ClassLoader systemClassLoader) throws IOException {
    NarClassLoaders narClassLoaders = NarClassLoadersHolder.getInstance();

    final long discoveryStart = System.nanoTime();
    try {
        narClassLoaders.init(systemClassLoader, null, narWorkingDirectory);
    } catch (final ClassNotFoundException cnfe) {
        throw new IOException("Could not initialize Class Loaders", cnfe);
    }

    final Set<Bundle> narBundles = narClassLoaders.getBundles();

    final StandardExtensionDiscoveringManager extensionManager = new StandardExtensionDiscoveringManager();
    extensionManager.discoverExtensions(narBundles);
    extensionManager.logClassLoaderMapping();

    final long discoveryMillis = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - discoveryStart);
    logger.info("Successfully discovered extensions in {} milliseconds", discoveryMillis);

    return extensionManager;
}
 
Example #14
Source File: HtmlDocumentationWriter.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Uses the {@link ExtensionManager} to discover any {@link ControllerService} implementations that implement a specific
 * ControllerService API.
 *
 * @param parent the controller service API
 * @return a list of controller services that implement the controller service API
 */
private List<Class<? extends ControllerService>> lookupControllerServiceImpls(
        final Class<? extends ControllerService> parent) {

    final List<Class<? extends ControllerService>> implementations = new ArrayList<>();

    // first get all ControllerService implementations
    final Set<Class> controllerServices = ExtensionManager.getExtensions(ControllerService.class);

    // then iterate over all controller services looking for any that is a child of the parent
    // ControllerService API that was passed in as a parameter
    for (final Class<? extends ControllerService> controllerServiceClass : controllerServices) {
        if (parent.isAssignableFrom(controllerServiceClass)) {
            implementations.add(controllerServiceClass);
        }
    }

    return implementations;
}
 
Example #15
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 #16
Source File: FlowController.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("rawtypes")
public List<String> getComponentTypes() {
    final Set<Class> procClasses = ExtensionManager.getExtensions(Processor.class);
    final List<String> componentTypes = new ArrayList<>(procClasses.size() + 2);
    componentTypes.add(ProvenanceEventRecord.REMOTE_INPUT_PORT_TYPE);
    componentTypes.add(ProvenanceEventRecord.REMOTE_OUTPUT_PORT_TYPE);
    procClasses.stream()
        .map(procClass -> procClass.getSimpleName())
        .forEach(componentType -> componentTypes.add(componentType));
    return componentTypes;
}
 
Example #17
Source File: FlowController.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
private Processor instantiateProcessor(final String type, final String identifier) throws ProcessorInstantiationException {
    Processor processor;

    final ClassLoader ctxClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        final ClassLoader detectedClassLoaderForType = ExtensionManager.getClassLoader(type, identifier);
        final Class<?> rawClass;
        if (detectedClassLoaderForType == null) {
            // try to find from the current class loader
            rawClass = Class.forName(type);
        } else {
            // try to find from the registered classloader for that type
            rawClass = Class.forName(type, true, ExtensionManager.getClassLoader(type, identifier));
        }

        Thread.currentThread().setContextClassLoader(detectedClassLoaderForType);
        final Class<? extends Processor> processorClass = rawClass.asSubclass(Processor.class);
        processor = processorClass.newInstance();
        final ComponentLog componentLogger = new SimpleProcessLogger(identifier, processor);
        final ProcessorInitializationContext ctx = new StandardProcessorInitializationContext(identifier, componentLogger, this, this, nifiProperties);
        processor.initialize(ctx);

        LogRepositoryFactory.getRepository(identifier).setLogger(componentLogger);
        return processor;
    } catch (final Throwable t) {
        throw new ProcessorInstantiationException(type, t);
    } finally {
        if (ctxClassLoader != null) {
            Thread.currentThread().setContextClassLoader(ctxClassLoader);
        }
    }
}
 
Example #18
Source File: FlowController.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
public FlowFilePrioritizer createPrioritizer(final String type) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
    FlowFilePrioritizer prioritizer;

    final ClassLoader ctxClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        final ClassLoader detectedClassLoaderForType = ExtensionManager.getClassLoader(type);
        final Class<?> rawClass;
        if (detectedClassLoaderForType == null) {
            // try to find from the current class loader
            rawClass = Class.forName(type);
        } else {
            // try to find from the registered classloader for that type
            rawClass = Class.forName(type, true, ExtensionManager.getClassLoader(type));
        }

        Thread.currentThread().setContextClassLoader(detectedClassLoaderForType);
        final Class<? extends FlowFilePrioritizer> prioritizerClass = rawClass.asSubclass(FlowFilePrioritizer.class);
        final Object processorObj = prioritizerClass.newInstance();
        prioritizer = prioritizerClass.cast(processorObj);

        return prioritizer;
    } finally {
        if (ctxClassLoader != null) {
            Thread.currentThread().setContextClassLoader(ctxClassLoader);
        }
    }
}
 
Example #19
Source File: StatusAnalyticsModelMapFactory.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Create a connection model instance  using configurations set in NiFi properties
 * @param extensionManager Extension Manager object for instantiating classes
 * @param nifiProperties NiFi Properties object
 * @return statusAnalyticsModel
 */
private StatusAnalyticsModel createModelInstance(ExtensionManager extensionManager, NiFiProperties nifiProperties) {
    final String implementationClassName = nifiProperties.getProperty(NiFiProperties.ANALYTICS_CONNECTION_MODEL_IMPLEMENTATION, NiFiProperties.DEFAULT_ANALYTICS_CONNECTION_MODEL_IMPLEMENTATION);
    if (implementationClassName == null) {
        throw new RuntimeException("Cannot create Analytics Model because the NiFi Properties is missing the following property: "
                + NiFiProperties.ANALYTICS_CONNECTION_MODEL_IMPLEMENTATION);
    }
    try {
        return NarThreadContextClassLoader.createInstance(extensionManager, implementationClassName, StatusAnalyticsModel.class, nifiProperties);
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example #20
Source File: AccessControlHelper.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
public AccessControlHelper(final String nifiPropertiesPath) throws Exception {
    // configure the location of the nifi properties
    File nifiPropertiesFile = new File(nifiPropertiesPath);
    System.setProperty(NiFiProperties.PROPERTIES_FILE_PATH, nifiPropertiesFile.getAbsolutePath());
    NiFiProperties props = NiFiProperties.createBasicNiFiProperties(null, null);
    flowXmlPath = props.getProperty(NiFiProperties.FLOW_CONFIGURATION_FILE);

    // load extensions
    NarClassLoaders.getInstance().init(props.getFrameworkWorkingDirectory(), props.getExtensionsWorkingDirectory());
    ExtensionManager.discoverExtensions(NarClassLoaders.getInstance().getExtensionClassLoaders());

    // start the server
    server = new NiFiTestServer("src/main/webapp", CONTEXT_PATH, props);
    server.startServer();
    server.loadFlow();

    // get the base url
    baseUrl = server.getBaseUrl() + CONTEXT_PATH;

    // create the users - user purposefully decoupled from clientId (same user different browsers tabs)
    readUser = new NiFiTestUser(server.getClient(), NiFiTestAuthorizer.READ_USER_DN);
    writeUser = new NiFiTestUser(server.getClient(), NiFiTestAuthorizer.WRITE_USER_DN);
    readWriteUser = new NiFiTestUser(server.getClient(), NiFiTestAuthorizer.READ_WRITE_USER_DN);
    noneUser = new NiFiTestUser(server.getClient(), NiFiTestAuthorizer.NONE_USER_DN);
    privilegedUser = new NiFiTestUser(server.getClient(), NiFiTestAuthorizer.PRIVILEGED_USER_DN);

    // populate the initial data flow
    NiFiWebApiTest.populateFlow(server.getClient(), baseUrl, readWriteUser, READ_WRITE_CLIENT_ID);
}
 
Example #21
Source File: TestAbstractComponentNode.java    From nifi with Apache License 2.0 5 votes vote down vote up
public ValidationControlledAbstractComponentNode(final long pauseMillis, final ValidationTrigger validationTrigger) {
    super("id", Mockito.mock(ValidationContextFactory.class), Mockito.mock(ControllerServiceProvider.class), "unit test component",
        ValidationControlledAbstractComponentNode.class.getCanonicalName(), Mockito.mock(ComponentVariableRegistry.class), Mockito.mock(ReloadComponent.class),
        Mockito.mock(ExtensionManager.class), validationTrigger, false);

    this.pauseMillis = pauseMillis;
}
 
Example #22
Source File: StandardProcessorNode.java    From nifi with Apache License 2.0 5 votes vote down vote up
public StandardProcessorNode(final LoggableComponent<Processor> processor, final String uuid,
                             final ValidationContextFactory validationContextFactory, final ProcessScheduler scheduler,
                             final ControllerServiceProvider controllerServiceProvider, final ComponentVariableRegistry variableRegistry,
                             final ReloadComponent reloadComponent, final ExtensionManager extensionManager, final ValidationTrigger validationTrigger) {

    this(processor, uuid, validationContextFactory, scheduler, controllerServiceProvider, processor.getComponent().getClass().getSimpleName(),
        processor.getComponent().getClass().getCanonicalName(), variableRegistry, reloadComponent, extensionManager, validationTrigger, false);
}
 
Example #23
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 #24
Source File: TestStandardControllerServiceInvocationHandler.java    From nifi with Apache License 2.0 5 votes vote down vote up
private BaseControllerService createProxyService() {
    final ExtensionManager extensionManager = Mockito.mock(ExtensionManager.class);
    final TestService testService = new TestService();
    testService.setLevel(1);

    final ControllerServiceNode serviceNode = Mockito.mock(ControllerServiceNode.class);
    Mockito.when(serviceNode.getState()).thenReturn(ControllerServiceState.ENABLED);

    final StandardControllerServiceInvocationHandler handler = new StandardControllerServiceInvocationHandler(extensionManager, testService);
    handler.setServiceNode(serviceNode);

    return (BaseControllerService) Proxy.newProxyInstance(getClass().getClassLoader(), new Class<?>[] {BaseControllerService.class}, handler);
}
 
Example #25
Source File: ControllerServiceInitializer.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
public void teardown(ConfigurableComponent component) {
    try (NarCloseable narCloseable = NarCloseable.withComponentNarLoader(component.getClass(), component.getIdentifier())) {
        ControllerService controllerService = (ControllerService) component;

        final ComponentLog logger = new MockComponentLogger();
        final MockConfigurationContext context = new MockConfigurationContext();
        ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnShutdown.class, controllerService, logger, context);
    } finally {
        ExtensionManager.removeInstanceClassLoaderIfExists(component.getIdentifier());
    }
}
 
Example #26
Source File: TestPopularVoteFlowElection.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testAutoGeneratedVsPopulatedFlowElection() throws IOException {
    final ExtensionManager extensionManager = new StandardExtensionDiscoveringManager();
    final FingerprintFactory fingerprintFactory = new FingerprintFactory(createEncryptorFromProperties(getNiFiProperties()), extensionManager);
    final PopularVoteFlowElection election = new PopularVoteFlowElection(1, TimeUnit.MINUTES, 4, fingerprintFactory);
    final byte[] emptyFlow = Files.readAllBytes(Paths.get("src/test/resources/conf/auto-generated-empty-flow.xml"));
    final byte[] nonEmptyFlow = Files.readAllBytes(Paths.get("src/test/resources/conf/reporting-task-flow.xml"));

    for (int i = 0; i < 4; i++) {
        assertFalse(election.isElectionComplete());
        assertNull(election.getElectedDataFlow());

        final DataFlow dataFlow;
        if (i % 2 == 0) {
            dataFlow = createDataFlow(emptyFlow);
        } else {
            dataFlow = createDataFlow(nonEmptyFlow);
        }

        final DataFlow electedDataFlow = election.castVote(dataFlow, createNodeId(i));

        if (i == 3) {
            assertNotNull(electedDataFlow);
            assertEquals(new String(nonEmptyFlow), new String(electedDataFlow.getFlow()));
        } else {
            assertNull(electedDataFlow);
        }
    }
}
 
Example #27
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 #28
Source File: BundleCompatibilityCheck.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public FlowInheritability checkInheritability(final DataFlow existingFlow, final DataFlow proposedFlow, final FlowController flowController) {
    final Document configuration = proposedFlow.getFlowDocument();

    if (configuration == null) {
        return FlowInheritability.inheritable();
    }

    final ExtensionManager extensionManager = flowController.getExtensionManager();
    final NodeList bundleNodes = configuration.getElementsByTagName("bundle");
    for (int i = 0; i < bundleNodes.getLength(); i++) {
        final Node bundleNode = bundleNodes.item(i);
        if (bundleNode instanceof Element) {
            final Element bundleElement = (Element) bundleNode;

            final Node componentNode = bundleElement.getParentNode();
            if (componentNode instanceof Element) {
                final Element componentElement = (Element) componentNode;
                if (!withinTemplate(componentElement)) {
                    final String componentType = DomUtils.getChildText(componentElement, "class");
                    final BundleDTO bundleDto = FlowFromDOMFactory.getBundle(bundleElement);

                    try {
                        BundleUtils.getBundle(extensionManager, componentType, bundleDto);
                    } catch (final IllegalStateException e) {
                        final String bundleDescription = bundleDto.getGroup() + ":" + bundleDto.getArtifact() + ":" + bundleDto.getVersion();
                        return FlowInheritability.notInheritable("Could not find Bundle " + bundleDescription + ": " + e.getMessage());
                    }
                }
            }
        }
    }

    return FlowInheritability.inheritable();
}
 
Example #29
Source File: ProcessorDocumentationWriterTest.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testNakedProcessor() throws IOException {
    ExtensionManager extensionManager = new StandardExtensionDiscoveringManager();

    NakedProcessor processor = new NakedProcessor();
    ProcessorInitializer initializer = new ProcessorInitializer(extensionManager);
    initializer.initialize(processor);

    DocumentationWriter writer = new HtmlProcessorDocumentationWriter(extensionManager);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    writer.write(processor, baos, false);
    initializer.teardown(processor);

    String results = new String(baos.toByteArray());
    XmlValidator.assertXmlValid(results);

    // no description
    assertContains(results, "No description provided.");

    // no tags
    assertContains(results, "No tags provided.");

    // properties
    assertContains(results, "This component has no required or optional properties.");

    // relationships
    assertContains(results, "This processor has no relationships.");

    // state management
    assertContains(results, "This component does not store state.");

    // state management
    assertContains(results, "This component is not restricted.");

    // input requirement
    assertNotContains(results, "Input requirement:");
}
 
Example #30
Source File: FlowController.java    From nifi with Apache License 2.0 5 votes vote down vote up
public static FlowController createStandaloneInstance(
        final FlowFileEventRepository flowFileEventRepo,
        final NiFiProperties properties,
        final Authorizer authorizer,
        final AuditService auditService,
        final StringEncryptor encryptor,
        final BulletinRepository bulletinRepo,
        final VariableRegistry variableRegistry,
        final FlowRegistryClient flowRegistryClient,
        final ExtensionManager extensionManager) {

    return new FlowController(
            flowFileEventRepo,
            properties,
            authorizer,
            auditService,
            encryptor,
            /* configuredForClustering */ false,
            /* NodeProtocolSender */ null,
            bulletinRepo,
            /* cluster coordinator */ null,
            /* heartbeat monitor */ null,
            /* leader election manager */ null,
            /* variable registry */ variableRegistry,
            flowRegistryClient,
            extensionManager);
}