Search in sources :

Example 36 with BundleCoordinate

use of org.apache.nifi.bundle.BundleCoordinate 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)

Example 37 with BundleCoordinate

use of org.apache.nifi.bundle.BundleCoordinate in project nifi by apache.

the class TestStandardProcessorNode method testStart.

@Test(timeout = 10000)
public void testStart() throws InterruptedException {
    final ProcessorThatThrowsExceptionOnScheduled processor = new ProcessorThatThrowsExceptionOnScheduled();
    final String uuid = UUID.randomUUID().toString();
    ProcessorInitializationContext initContext = new StandardProcessorInitializationContext(uuid, null, null, null, null);
    processor.initialize(initContext);
    final ReloadComponent reloadComponent = Mockito.mock(ReloadComponent.class);
    final BundleCoordinate coordinate = Mockito.mock(BundleCoordinate.class);
    final LoggableComponent<Processor> loggableComponent = new LoggableComponent<>(processor, coordinate, null);
    final StandardProcessorNode procNode = new StandardProcessorNode(loggableComponent, uuid, createValidationContextFactory(), null, null, NiFiProperties.createBasicNiFiProperties(null, null), new StandardComponentVariableRegistry(VariableRegistry.EMPTY_REGISTRY), reloadComponent);
    final ScheduledExecutorService taskScheduler = new FlowEngine(1, "TestClasspathResources", true);
    final StandardProcessContext processContext = new StandardProcessContext(procNode, null, null, null, () -> false);
    final SchedulingAgentCallback schedulingAgentCallback = new SchedulingAgentCallback() {

        @Override
        public void onTaskComplete() {
        }

        @Override
        public Future<?> scheduleTask(final Callable<?> task) {
            return taskScheduler.submit(task);
        }

        @Override
        public void trigger() {
            Assert.fail("Should not have completed");
        }
    };
    procNode.start(taskScheduler, 20000L, processContext, schedulingAgentCallback, true);
    Thread.sleep(1000L);
    assertEquals(1, processor.onScheduledCount);
    assertEquals(1, processor.onUnscheduledCount);
    assertEquals(1, processor.onStoppedCount);
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) 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) FlowEngine(org.apache.nifi.engine.FlowEngine) StandardProcessorInitializationContext(org.apache.nifi.processor.StandardProcessorInitializationContext) BundleCoordinate(org.apache.nifi.bundle.BundleCoordinate) ProcessorInitializationContext(org.apache.nifi.processor.ProcessorInitializationContext) StandardProcessorInitializationContext(org.apache.nifi.processor.StandardProcessorInitializationContext) Callable(java.util.concurrent.Callable) StandardProcessContext(org.apache.nifi.processor.StandardProcessContext) Test(org.junit.Test)

Example 38 with BundleCoordinate

use of org.apache.nifi.bundle.BundleCoordinate in project nifi by apache.

the class TestStandardProcessorNode method testVerifyCanUpdateBundle.

@Test
public void testVerifyCanUpdateBundle() {
    final ReloadComponent reloadComponent = new MockReloadComponent();
    final ModifiesClasspathNoAnnotationProcessor processor = new ModifiesClasspathNoAnnotationProcessor();
    final StandardProcessorNode procNode = createProcessorNode(processor, reloadComponent);
    final BundleCoordinate existingCoordinate = procNode.getBundleCoordinate();
    // should be allowed to update when the bundle is the same
    procNode.verifyCanUpdateBundle(existingCoordinate);
    // should be allowed to update when the group and id are the same but version is different
    final BundleCoordinate diffVersion = new BundleCoordinate(existingCoordinate.getGroup(), existingCoordinate.getId(), "v2");
    assertTrue(!existingCoordinate.getVersion().equals(diffVersion.getVersion()));
    procNode.verifyCanUpdateBundle(diffVersion);
    // should not be allowed to update when the bundle id is different
    final BundleCoordinate diffId = new BundleCoordinate(existingCoordinate.getGroup(), "different-id", existingCoordinate.getVersion());
    assertTrue(!existingCoordinate.getId().equals(diffId.getId()));
    try {
        procNode.verifyCanUpdateBundle(diffId);
        Assert.fail("Should have thrown exception");
    } catch (Exception e) {
    }
    // should not be allowed to update when the bundle group is different
    final BundleCoordinate diffGroup = new BundleCoordinate("different-group", existingCoordinate.getId(), existingCoordinate.getVersion());
    assertTrue(!existingCoordinate.getGroup().equals(diffGroup.getGroup()));
    try {
        procNode.verifyCanUpdateBundle(diffGroup);
        Assert.fail("Should have thrown exception");
    } catch (Exception e) {
    }
}
Also used : ModifiesClasspathNoAnnotationProcessor(org.apache.nifi.test.processors.ModifiesClasspathNoAnnotationProcessor) BundleCoordinate(org.apache.nifi.bundle.BundleCoordinate) ProcessorInstantiationException(org.apache.nifi.controller.exception.ProcessorInstantiationException) ReportingTaskInstantiationException(org.apache.nifi.controller.reporting.ReportingTaskInstantiationException) ProcessException(org.apache.nifi.processor.exception.ProcessException) MalformedURLException(java.net.MalformedURLException) ControllerServiceInstantiationException(org.apache.nifi.controller.exception.ControllerServiceInstantiationException) Test(org.junit.Test)

Example 39 with BundleCoordinate

use of org.apache.nifi.bundle.BundleCoordinate in project nifi by apache.

the class StandardProcessGroup method updateProcessor.

private void updateProcessor(final ProcessorNode processor, final VersionedProcessor proposed) throws ProcessorInstantiationException {
    processor.setAnnotationData(proposed.getAnnotationData());
    processor.setBulletinLevel(LogLevel.valueOf(proposed.getBulletinLevel()));
    processor.setComments(proposed.getComments());
    processor.setName(proposed.getName());
    processor.setPenalizationPeriod(proposed.getPenaltyDuration());
    final Map<String, String> properties = populatePropertiesMap(processor.getProperties(), proposed.getProperties(), proposed.getPropertyDescriptors(), processor.getProcessGroup());
    processor.setProperties(properties, true);
    processor.setRunDuration(proposed.getRunDurationMillis(), TimeUnit.MILLISECONDS);
    processor.setSchedulingStrategy(SchedulingStrategy.valueOf(proposed.getSchedulingStrategy()));
    processor.setScheduldingPeriod(proposed.getSchedulingPeriod());
    processor.setMaxConcurrentTasks(proposed.getConcurrentlySchedulableTaskCount());
    processor.setExecutionNode(ExecutionNode.valueOf(proposed.getExecutionNode()));
    processor.setStyle(proposed.getStyle());
    processor.setYieldPeriod(proposed.getYieldDuration());
    processor.setPosition(new Position(proposed.getPosition().getX(), proposed.getPosition().getY()));
    if (!isEqual(processor.getBundleCoordinate(), proposed.getBundle())) {
        final BundleCoordinate newBundleCoordinate = toCoordinate(proposed.getBundle());
        final List<PropertyDescriptor> descriptors = new ArrayList<>(processor.getProperties().keySet());
        final Set<URL> additionalUrls = processor.getAdditionalClasspathResources(descriptors);
        flowController.reload(processor, proposed.getType(), newBundleCoordinate, additionalUrls);
    }
}
Also used : PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) VersionedPropertyDescriptor(org.apache.nifi.registry.flow.VersionedPropertyDescriptor) Position(org.apache.nifi.connectable.Position) ArrayList(java.util.ArrayList) BundleCoordinate(org.apache.nifi.bundle.BundleCoordinate) URL(java.net.URL)

Example 40 with BundleCoordinate

use of org.apache.nifi.bundle.BundleCoordinate in project nifi by apache.

the class NiFiRegistryFlowMapper method mapControllerServiceApis.

private List<ControllerServiceAPI> mapControllerServiceApis(final ControllerServiceNode service) {
    final Class<?> serviceClass = service.getControllerServiceImplementation().getClass();
    final Set<Class<?>> serviceApiClasses = new HashSet<>();
    // get all of it's interfaces to determine the controller service api's it implements
    final List<Class<?>> interfaces = ClassUtils.getAllInterfaces(serviceClass);
    for (final Class<?> i : interfaces) {
        // add all controller services that's not ControllerService itself
        if (ControllerService.class.isAssignableFrom(i) && !ControllerService.class.equals(i)) {
            serviceApiClasses.add(i);
        }
    }
    final List<ControllerServiceAPI> serviceApis = new ArrayList<>();
    for (final Class<?> serviceApiClass : serviceApiClasses) {
        final BundleCoordinate bundleCoordinate = ExtensionManager.getBundle(serviceApiClass.getClassLoader()).getBundleDetails().getCoordinate();
        final ControllerServiceAPI serviceApi = new ControllerServiceAPI();
        serviceApi.setType(serviceApiClass.getName());
        serviceApi.setBundle(mapBundle(bundleCoordinate));
        serviceApis.add(serviceApi);
    }
    return serviceApis;
}
Also used : ControllerServiceAPI(org.apache.nifi.registry.flow.ControllerServiceAPI) ArrayList(java.util.ArrayList) ControllerService(org.apache.nifi.controller.ControllerService) VersionedControllerService(org.apache.nifi.registry.flow.VersionedControllerService) BundleCoordinate(org.apache.nifi.bundle.BundleCoordinate) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

BundleCoordinate (org.apache.nifi.bundle.BundleCoordinate)65 Bundle (org.apache.nifi.bundle.Bundle)23 LinkedHashSet (java.util.LinkedHashSet)18 ArrayList (java.util.ArrayList)16 BundleDTO (org.apache.nifi.web.api.dto.BundleDTO)16 HashMap (java.util.HashMap)14 Test (org.junit.Test)14 URL (java.net.URL)13 HashSet (java.util.HashSet)13 File (java.io.File)12 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)12 ControllerServiceNode (org.apache.nifi.controller.service.ControllerServiceNode)12 ConfigurableComponent (org.apache.nifi.components.ConfigurableComponent)10 List (java.util.List)8 Map (java.util.Map)8 Set (java.util.Set)8 Position (org.apache.nifi.connectable.Position)7 IOException (java.io.IOException)6 Collectors (java.util.stream.Collectors)6 Collections (java.util.Collections)5