Search in sources :

Example 1 with ExtensionMapping

use of org.apache.nifi.nar.ExtensionMapping in project nifi by apache.

the class DocGeneratorTest method testProcessorLoadsNarResources.

@Test
public void testProcessorLoadsNarResources() throws IOException, ClassNotFoundException {
    TemporaryFolder temporaryFolder = new TemporaryFolder();
    temporaryFolder.create();
    NiFiProperties properties = loadSpecifiedProperties("/conf/nifi.properties", NiFiProperties.COMPONENT_DOCS_DIRECTORY, temporaryFolder.getRoot().getAbsolutePath());
    final Bundle systemBundle = SystemBundle.create(properties);
    final ExtensionMapping mapping = NarUnpacker.unpackNars(properties, systemBundle);
    NarClassLoaders.getInstance().init(properties.getFrameworkWorkingDirectory(), properties.getExtensionsWorkingDirectory());
    ExtensionManager.discoverExtensions(systemBundle, NarClassLoaders.getInstance().getBundles());
    DocGenerator.generate(properties, mapping);
    final String extensionClassName = "org.apache.nifi.processors.WriteResourceToStream";
    final BundleCoordinate coordinate = mapping.getProcessorNames().get(extensionClassName).stream().findFirst().get();
    final String path = coordinate.getGroup() + "/" + coordinate.getId() + "/" + coordinate.getVersion() + "/" + extensionClassName;
    File processorDirectory = new File(temporaryFolder.getRoot(), path);
    File indexHtml = new File(processorDirectory, "index.html");
    Assert.assertTrue(indexHtml + " should have been generated", indexHtml.exists());
    String generatedHtml = FileUtils.readFileToString(indexHtml);
    Assert.assertNotNull(generatedHtml);
    Assert.assertTrue(generatedHtml.contains("This example processor loads a resource from the nar and writes it to the FlowFile content"));
    Assert.assertTrue(generatedHtml.contains("files that were successfully processed"));
    Assert.assertTrue(generatedHtml.contains("files that were not successfully processed"));
    Assert.assertTrue(generatedHtml.contains("resources"));
}
Also used : NiFiProperties(org.apache.nifi.util.NiFiProperties) ExtensionMapping(org.apache.nifi.nar.ExtensionMapping) Bundle(org.apache.nifi.bundle.Bundle) SystemBundle(org.apache.nifi.nar.SystemBundle) TemporaryFolder(org.junit.rules.TemporaryFolder) BundleCoordinate(org.apache.nifi.bundle.BundleCoordinate) File(java.io.File) Test(org.junit.Test)

Example 2 with ExtensionMapping

use of org.apache.nifi.nar.ExtensionMapping in project nifi by apache.

the class DocumentationController method doGet.

/**
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    final ExtensionMapping extensionMappings = (ExtensionMapping) servletContext.getAttribute("nifi-extension-mapping");
    final Collator collator = Collator.getInstance(Locale.US);
    // create the processors lookup
    final Map<String, String> processors = new TreeMap<>(collator);
    for (final String processorClass : extensionMappings.getProcessorNames().keySet()) {
        processors.put(StringUtils.substringAfterLast(processorClass, "."), processorClass);
    }
    // create the controller service lookup
    final Map<String, String> controllerServices = new TreeMap<>(collator);
    for (final String controllerServiceClass : extensionMappings.getControllerServiceNames().keySet()) {
        controllerServices.put(StringUtils.substringAfterLast(controllerServiceClass, "."), controllerServiceClass);
    }
    // create the reporting task lookup
    final Map<String, String> reportingTasks = new TreeMap<>(collator);
    for (final String reportingTaskClass : extensionMappings.getReportingTaskNames().keySet()) {
        reportingTasks.put(StringUtils.substringAfterLast(reportingTaskClass, "."), reportingTaskClass);
    }
    // make the available components available to the documentation jsp
    request.setAttribute("processors", processors);
    request.setAttribute("processorBundleLookup", extensionMappings.getProcessorNames());
    request.setAttribute("controllerServices", controllerServices);
    request.setAttribute("controllerServiceBundleLookup", extensionMappings.getControllerServiceNames());
    request.setAttribute("reportingTasks", reportingTasks);
    request.setAttribute("reportingTaskBundleLookup", extensionMappings.getReportingTaskNames());
    request.setAttribute("totalComponents", GENERAL_LINK_COUNT + extensionMappings.size() + DEVELOPER_LINK_COUNT);
    // forward appropriately
    request.getRequestDispatcher("/WEB-INF/jsp/documentation.jsp").forward(request, response);
}
Also used : ExtensionMapping(org.apache.nifi.nar.ExtensionMapping) TreeMap(java.util.TreeMap) Collator(java.text.Collator)

Aggregations

ExtensionMapping (org.apache.nifi.nar.ExtensionMapping)2 File (java.io.File)1 Collator (java.text.Collator)1 TreeMap (java.util.TreeMap)1 Bundle (org.apache.nifi.bundle.Bundle)1 BundleCoordinate (org.apache.nifi.bundle.BundleCoordinate)1 SystemBundle (org.apache.nifi.nar.SystemBundle)1 NiFiProperties (org.apache.nifi.util.NiFiProperties)1 Test (org.junit.Test)1 TemporaryFolder (org.junit.rules.TemporaryFolder)1