Search in sources :

Example 1 with InstanceClassLoader

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

the class TestFlowController method testReloadControllerServiceWithAdditionalResources.

@Test
public void testReloadControllerServiceWithAdditionalResources() throws MalformedURLException {
    final URL resource1 = new File("src/test/resources/TestClasspathResources/resource1.txt").toURI().toURL();
    final URL resource2 = new File("src/test/resources/TestClasspathResources/resource2.txt").toURI().toURL();
    final URL resource3 = new File("src/test/resources/TestClasspathResources/resource3.txt").toURI().toURL();
    final Set<URL> additionalUrls = new LinkedHashSet<>(Arrays.asList(resource1, resource2, resource3));
    final String id = "ServiceA" + System.currentTimeMillis();
    final BundleCoordinate coordinate = systemBundle.getBundleDetails().getCoordinate();
    final ControllerServiceNode controllerServiceNode = controller.createControllerService(ServiceA.class.getName(), id, coordinate, null, true);
    final String originalName = controllerServiceNode.getName();
    // the instance class loader shouldn't have any of the resources yet
    InstanceClassLoader instanceClassLoader = ExtensionManager.getInstanceClassLoader(id);
    assertNotNull(instanceClassLoader);
    assertFalse(containsResource(instanceClassLoader.getURLs(), resource1));
    assertFalse(containsResource(instanceClassLoader.getURLs(), resource2));
    assertFalse(containsResource(instanceClassLoader.getURLs(), resource3));
    assertTrue(instanceClassLoader.getAdditionalResourceUrls().isEmpty());
    controller.reload(controllerServiceNode, ServiceB.class.getName(), coordinate, additionalUrls);
    // the instance class loader shouldn't have any of the resources yet
    instanceClassLoader = ExtensionManager.getInstanceClassLoader(id);
    assertNotNull(instanceClassLoader);
    assertTrue(containsResource(instanceClassLoader.getURLs(), resource1));
    assertTrue(containsResource(instanceClassLoader.getURLs(), resource2));
    assertTrue(containsResource(instanceClassLoader.getURLs(), resource3));
    assertEquals(3, instanceClassLoader.getAdditionalResourceUrls().size());
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ServiceB(org.apache.nifi.controller.service.mock.ServiceB) ServiceA(org.apache.nifi.controller.service.mock.ServiceA) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) InstanceClassLoader(org.apache.nifi.nar.InstanceClassLoader) File(java.io.File) BundleCoordinate(org.apache.nifi.bundle.BundleCoordinate) URL(java.net.URL) Test(org.junit.Test)

Example 2 with InstanceClassLoader

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

the class TestFlowController method testReloadProcessorWithAdditionalResources.

@Test
public void testReloadProcessorWithAdditionalResources() throws ProcessorInstantiationException, MalformedURLException {
    final URL resource1 = new File("src/test/resources/TestClasspathResources/resource1.txt").toURI().toURL();
    final URL resource2 = new File("src/test/resources/TestClasspathResources/resource2.txt").toURI().toURL();
    final URL resource3 = new File("src/test/resources/TestClasspathResources/resource3.txt").toURI().toURL();
    final Set<URL> additionalUrls = new LinkedHashSet<>(Arrays.asList(resource1, resource2, resource3));
    final String id = "1234-ScheduledProcessor" + System.currentTimeMillis();
    final BundleCoordinate coordinate = systemBundle.getBundleDetails().getCoordinate();
    final ProcessorNode processorNode = controller.createProcessor(DummyScheduledProcessor.class.getName(), id, coordinate);
    final String originalName = processorNode.getName();
    // the instance class loader shouldn't have any of the resources yet
    InstanceClassLoader instanceClassLoader = ExtensionManager.getInstanceClassLoader(id);
    assertNotNull(instanceClassLoader);
    assertFalse(containsResource(instanceClassLoader.getURLs(), resource1));
    assertFalse(containsResource(instanceClassLoader.getURLs(), resource2));
    assertFalse(containsResource(instanceClassLoader.getURLs(), resource3));
    assertTrue(instanceClassLoader.getAdditionalResourceUrls().isEmpty());
    // now change the type of the processor from DummyScheduledProcessor to DummySettingsProcessor
    controller.reload(processorNode, DummySettingsProcessor.class.getName(), coordinate, additionalUrls);
    // the instance class loader shouldn't have any of the resources yet
    instanceClassLoader = ExtensionManager.getInstanceClassLoader(id);
    assertNotNull(instanceClassLoader);
    assertTrue(containsResource(instanceClassLoader.getURLs(), resource1));
    assertTrue(containsResource(instanceClassLoader.getURLs(), resource2));
    assertTrue(containsResource(instanceClassLoader.getURLs(), resource3));
    assertEquals(3, instanceClassLoader.getAdditionalResourceUrls().size());
}
Also used : LinkedHashSet(java.util.LinkedHashSet) InstanceClassLoader(org.apache.nifi.nar.InstanceClassLoader) File(java.io.File) BundleCoordinate(org.apache.nifi.bundle.BundleCoordinate) URL(java.net.URL) Test(org.junit.Test)

Example 3 with InstanceClassLoader

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

the class TestFlowController method testReloadReportingTaskWithAdditionalResources.

@Test
public void testReloadReportingTaskWithAdditionalResources() throws ReportingTaskInstantiationException, MalformedURLException {
    final URL resource1 = new File("src/test/resources/TestClasspathResources/resource1.txt").toURI().toURL();
    final URL resource2 = new File("src/test/resources/TestClasspathResources/resource2.txt").toURI().toURL();
    final URL resource3 = new File("src/test/resources/TestClasspathResources/resource3.txt").toURI().toURL();
    final Set<URL> additionalUrls = new LinkedHashSet<>(Arrays.asList(resource1, resource2, resource3));
    final String id = "ReportingTask" + System.currentTimeMillis();
    final BundleCoordinate coordinate = systemBundle.getBundleDetails().getCoordinate();
    final ReportingTaskNode node = controller.createReportingTask(DummyReportingTask.class.getName(), id, coordinate, true);
    // the instance class loader shouldn't have any of the resources yet
    InstanceClassLoader instanceClassLoader = ExtensionManager.getInstanceClassLoader(id);
    assertNotNull(instanceClassLoader);
    assertFalse(containsResource(instanceClassLoader.getURLs(), resource1));
    assertFalse(containsResource(instanceClassLoader.getURLs(), resource2));
    assertFalse(containsResource(instanceClassLoader.getURLs(), resource3));
    assertTrue(instanceClassLoader.getAdditionalResourceUrls().isEmpty());
    controller.reload(node, DummyScheduledReportingTask.class.getName(), coordinate, additionalUrls);
    // the instance class loader shouldn't have any of the resources yet
    instanceClassLoader = ExtensionManager.getInstanceClassLoader(id);
    assertNotNull(instanceClassLoader);
    assertTrue(containsResource(instanceClassLoader.getURLs(), resource1));
    assertTrue(containsResource(instanceClassLoader.getURLs(), resource2));
    assertTrue(containsResource(instanceClassLoader.getURLs(), resource3));
    assertEquals(3, instanceClassLoader.getAdditionalResourceUrls().size());
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DummyReportingTask(org.apache.nifi.controller.service.mock.DummyReportingTask) InstanceClassLoader(org.apache.nifi.nar.InstanceClassLoader) File(java.io.File) BundleCoordinate(org.apache.nifi.bundle.BundleCoordinate) URL(java.net.URL) Test(org.junit.Test)

Aggregations

File (java.io.File)3 URL (java.net.URL)3 LinkedHashSet (java.util.LinkedHashSet)3 BundleCoordinate (org.apache.nifi.bundle.BundleCoordinate)3 InstanceClassLoader (org.apache.nifi.nar.InstanceClassLoader)3 Test (org.junit.Test)3 ControllerServiceNode (org.apache.nifi.controller.service.ControllerServiceNode)1 DummyReportingTask (org.apache.nifi.controller.service.mock.DummyReportingTask)1 ServiceA (org.apache.nifi.controller.service.mock.ServiceA)1 ServiceB (org.apache.nifi.controller.service.mock.ServiceB)1