Search in sources :

Example 1 with SystemBundle

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

the class ITAccessTokenEndpoint method setup.

@BeforeClass
public static void setup() throws Exception {
    // configure the location of the nifi properties
    File nifiPropertiesFile = new File("src/test/resources/access-control/nifi.properties");
    System.setProperty(NiFiProperties.PROPERTIES_FILE_PATH, nifiPropertiesFile.getAbsolutePath());
    NiFiProperties props = NiFiProperties.createBasicNiFiProperties(null, null);
    flowXmlPath = props.getProperty(NiFiProperties.FLOW_CONFIGURATION_FILE);
    // delete the database directory to avoid issues with re-registration in testRequestAccessUsingToken
    FileUtils.deleteDirectory(props.getDatabaseRepositoryPath().toFile());
    // load extensions
    final Bundle systemBundle = SystemBundle.create(props);
    NarClassLoaders.getInstance().init(props.getFrameworkWorkingDirectory(), props.getExtensionsWorkingDirectory());
    ExtensionManager.discoverExtensions(systemBundle, NarClassLoaders.getInstance().getBundles());
    // start the server
    SERVER = new NiFiTestServer("src/main/webapp", CONTEXT_PATH, props);
    SERVER.startServer();
    SERVER.loadFlow();
    // get the base url
    BASE_URL = SERVER.getBaseUrl() + CONTEXT_PATH;
    // create the user
    final Client client = WebUtils.createClient(null, createTrustContext(props));
    TOKEN_USER = new NiFiTestUser(client, null);
}
Also used : NiFiProperties(org.apache.nifi.util.NiFiProperties) Bundle(org.apache.nifi.bundle.Bundle) SystemBundle(org.apache.nifi.nar.SystemBundle) NiFiTestServer(org.apache.nifi.integration.util.NiFiTestServer) Client(javax.ws.rs.client.Client) File(java.io.File) NiFiTestUser(org.apache.nifi.integration.util.NiFiTestUser) BeforeClass(org.junit.BeforeClass)

Example 2 with SystemBundle

use of org.apache.nifi.nar.SystemBundle 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 3 with SystemBundle

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

the class TestStandardProcessorNode method createProcessorNode.

private StandardProcessorNode createProcessorNode(final Processor processor, final ReloadComponent reloadComponent) {
    final String uuid = UUID.randomUUID().toString();
    final ValidationContextFactory validationContextFactory = createValidationContextFactory();
    final NiFiProperties niFiProperties = NiFiProperties.createBasicNiFiProperties("src/test/resources/conf/nifi.properties", null);
    final ProcessScheduler processScheduler = Mockito.mock(ProcessScheduler.class);
    final TerminationAwareLogger componentLog = Mockito.mock(TerminationAwareLogger.class);
    final Bundle systemBundle = SystemBundle.create(niFiProperties);
    ExtensionManager.discoverExtensions(systemBundle, Collections.emptySet());
    ExtensionManager.createInstanceClassLoader(processor.getClass().getName(), uuid, systemBundle, null);
    ProcessorInitializationContext initContext = new StandardProcessorInitializationContext(uuid, componentLog, null, null, null);
    processor.initialize(initContext);
    final LoggableComponent<Processor> loggableComponent = new LoggableComponent<>(processor, systemBundle.getBundleDetails().getCoordinate(), componentLog);
    return new StandardProcessorNode(loggableComponent, uuid, validationContextFactory, processScheduler, null, niFiProperties, new StandardComponentVariableRegistry(variableRegistry), reloadComponent);
}
Also used : NiFiProperties(org.apache.nifi.util.NiFiProperties) ModifiesClasspathNoAnnotationProcessor(org.apache.nifi.test.processors.ModifiesClasspathNoAnnotationProcessor) Processor(org.apache.nifi.processor.Processor) ModifiesClasspathProcessor(org.apache.nifi.test.processors.ModifiesClasspathProcessor) AbstractProcessor(org.apache.nifi.processor.AbstractProcessor) StandardComponentVariableRegistry(org.apache.nifi.registry.variable.StandardComponentVariableRegistry) Bundle(org.apache.nifi.bundle.Bundle) SystemBundle(org.apache.nifi.nar.SystemBundle) StandardProcessorInitializationContext(org.apache.nifi.processor.StandardProcessorInitializationContext) ProcessorInitializationContext(org.apache.nifi.processor.ProcessorInitializationContext) StandardProcessorInitializationContext(org.apache.nifi.processor.StandardProcessorInitializationContext)

Example 4 with SystemBundle

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

the class TestProcessorLifecycle method buildFlowControllerForTest.

private FlowControllerAndSystemBundle buildFlowControllerForTest(final String propKey, final String propValue) throws Exception {
    final Map<String, String> addProps = new HashMap<>();
    addProps.put(NiFiProperties.ADMINISTRATIVE_YIELD_DURATION, "1 sec");
    addProps.put(NiFiProperties.STATE_MANAGEMENT_CONFIG_FILE, "target/test-classes/state-management.xml");
    addProps.put(NiFiProperties.STATE_MANAGEMENT_LOCAL_PROVIDER_ID, "local-provider");
    addProps.put(NiFiProperties.PROVENANCE_REPO_IMPLEMENTATION_CLASS, MockProvenanceRepository.class.getName());
    addProps.put("nifi.remote.input.socket.port", "");
    addProps.put("nifi.remote.input.secure", "");
    if (propKey != null && propValue != null) {
        addProps.put(propKey, propValue);
    }
    final NiFiProperties nifiProperties = NiFiProperties.createBasicNiFiProperties(propsFile, addProps);
    final Bundle systemBundle = SystemBundle.create(nifiProperties);
    ExtensionManager.discoverExtensions(systemBundle, Collections.emptySet());
    final FlowController flowController = FlowController.createStandaloneInstance(mock(FlowFileEventRepository.class), nifiProperties, mock(Authorizer.class), mock(AuditService.class), null, new VolatileBulletinRepository(), new FileBasedVariableRegistry(nifiProperties.getVariableRegistryPropertiesPaths()), mock(FlowRegistryClient.class));
    return new FlowControllerAndSystemBundle(flowController, systemBundle);
}
Also used : NiFiProperties(org.apache.nifi.util.NiFiProperties) VolatileBulletinRepository(org.apache.nifi.events.VolatileBulletinRepository) HashMap(java.util.HashMap) Bundle(org.apache.nifi.bundle.Bundle) SystemBundle(org.apache.nifi.nar.SystemBundle) FlowRegistryClient(org.apache.nifi.registry.flow.FlowRegistryClient) FlowFileEventRepository(org.apache.nifi.controller.repository.FlowFileEventRepository) Authorizer(org.apache.nifi.authorization.Authorizer) MockProvenanceRepository(org.apache.nifi.provenance.MockProvenanceRepository) FlowController(org.apache.nifi.controller.FlowController) AuditService(org.apache.nifi.admin.service.AuditService) FileBasedVariableRegistry(org.apache.nifi.registry.variable.FileBasedVariableRegistry)

Aggregations

Bundle (org.apache.nifi.bundle.Bundle)4 SystemBundle (org.apache.nifi.nar.SystemBundle)4 NiFiProperties (org.apache.nifi.util.NiFiProperties)4 File (java.io.File)2 HashMap (java.util.HashMap)1 Client (javax.ws.rs.client.Client)1 AuditService (org.apache.nifi.admin.service.AuditService)1 Authorizer (org.apache.nifi.authorization.Authorizer)1 BundleCoordinate (org.apache.nifi.bundle.BundleCoordinate)1 FlowController (org.apache.nifi.controller.FlowController)1 FlowFileEventRepository (org.apache.nifi.controller.repository.FlowFileEventRepository)1 VolatileBulletinRepository (org.apache.nifi.events.VolatileBulletinRepository)1 NiFiTestServer (org.apache.nifi.integration.util.NiFiTestServer)1 NiFiTestUser (org.apache.nifi.integration.util.NiFiTestUser)1 ExtensionMapping (org.apache.nifi.nar.ExtensionMapping)1 AbstractProcessor (org.apache.nifi.processor.AbstractProcessor)1 Processor (org.apache.nifi.processor.Processor)1 ProcessorInitializationContext (org.apache.nifi.processor.ProcessorInitializationContext)1 StandardProcessorInitializationContext (org.apache.nifi.processor.StandardProcessorInitializationContext)1 MockProvenanceRepository (org.apache.nifi.provenance.MockProvenanceRepository)1