Search in sources :

Example 31 with BundleCoordinate

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

the class TestFlowController method testInstantiateSnippetWhenProcessorMissingBundle.

@Test(expected = IllegalArgumentException.class)
public void testInstantiateSnippetWhenProcessorMissingBundle() throws Exception {
    final String id = UUID.randomUUID().toString();
    final BundleCoordinate coordinate = systemBundle.getBundleDetails().getCoordinate();
    final ProcessorNode processorNode = controller.createProcessor(DummyProcessor.class.getName(), id, coordinate);
    // create a processor dto
    final ProcessorDTO processorDTO = new ProcessorDTO();
    // use a different id here
    processorDTO.setId(UUID.randomUUID().toString());
    processorDTO.setPosition(new PositionDTO(new Double(0), new Double(0)));
    processorDTO.setStyle(processorNode.getStyle());
    processorDTO.setParentGroupId("1234");
    processorDTO.setInputRequirement(processorNode.getInputRequirement().name());
    processorDTO.setPersistsState(processorNode.getProcessor().getClass().isAnnotationPresent(Stateful.class));
    processorDTO.setRestricted(processorNode.isRestricted());
    processorDTO.setExtensionMissing(processorNode.isExtensionMissing());
    processorDTO.setType(processorNode.getCanonicalClassName());
    // missing bundle
    processorDTO.setBundle(null);
    processorDTO.setName(processorNode.getName());
    processorDTO.setState(processorNode.getScheduledState().toString());
    processorDTO.setRelationships(new ArrayList<>());
    processorDTO.setDescription("description");
    processorDTO.setSupportsParallelProcessing(!processorNode.isTriggeredSerially());
    processorDTO.setSupportsEventDriven(processorNode.isEventDrivenSupported());
    processorDTO.setSupportsBatching(processorNode.isSessionBatchingSupported());
    ProcessorConfigDTO configDTO = new ProcessorConfigDTO();
    configDTO.setSchedulingPeriod(processorNode.getSchedulingPeriod());
    configDTO.setPenaltyDuration(processorNode.getPenalizationPeriod());
    configDTO.setYieldDuration(processorNode.getYieldPeriod());
    configDTO.setRunDurationMillis(processorNode.getRunDuration(TimeUnit.MILLISECONDS));
    configDTO.setConcurrentlySchedulableTaskCount(processorNode.getMaxConcurrentTasks());
    configDTO.setLossTolerant(processorNode.isLossTolerant());
    configDTO.setComments(processorNode.getComments());
    configDTO.setBulletinLevel(processorNode.getBulletinLevel().name());
    configDTO.setSchedulingStrategy(processorNode.getSchedulingStrategy().name());
    configDTO.setExecutionNode(processorNode.getExecutionNode().name());
    configDTO.setAnnotationData(processorNode.getAnnotationData());
    processorDTO.setConfig(configDTO);
    // create the snippet with the processor
    final FlowSnippetDTO flowSnippetDTO = new FlowSnippetDTO();
    flowSnippetDTO.setProcessors(Collections.singleton(processorDTO));
    // instantiate the snippet
    assertEquals(0, controller.getRootGroup().getProcessors().size());
    controller.instantiateSnippet(controller.getRootGroup(), flowSnippetDTO);
}
Also used : Stateful(org.apache.nifi.annotation.behavior.Stateful) ProcessorConfigDTO(org.apache.nifi.web.api.dto.ProcessorConfigDTO) FlowSnippetDTO(org.apache.nifi.web.api.dto.FlowSnippetDTO) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) DummyProcessor(org.apache.nifi.controller.service.mock.DummyProcessor) BundleCoordinate(org.apache.nifi.bundle.BundleCoordinate) PositionDTO(org.apache.nifi.web.api.dto.PositionDTO) Test(org.junit.Test)

Example 32 with BundleCoordinate

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

the class TestFlowController method testInstantiateSnippetWithControllerService.

@Test
public void testInstantiateSnippetWithControllerService() throws ProcessorInstantiationException {
    final String id = UUID.randomUUID().toString();
    final BundleCoordinate coordinate = systemBundle.getBundleDetails().getCoordinate();
    final ControllerServiceNode controllerServiceNode = controller.createControllerService(ServiceA.class.getName(), id, coordinate, null, true);
    // create the controller service dto
    final ControllerServiceDTO csDto = new ControllerServiceDTO();
    // use a different id
    csDto.setId(UUID.randomUUID().toString());
    csDto.setParentGroupId(controllerServiceNode.getProcessGroup() == null ? null : controllerServiceNode.getProcessGroup().getIdentifier());
    csDto.setName(controllerServiceNode.getName());
    csDto.setType(controllerServiceNode.getCanonicalClassName());
    csDto.setBundle(new BundleDTO(coordinate.getGroup(), coordinate.getId(), coordinate.getVersion()));
    csDto.setState(controllerServiceNode.getState().name());
    csDto.setAnnotationData(controllerServiceNode.getAnnotationData());
    csDto.setComments(controllerServiceNode.getComments());
    csDto.setPersistsState(controllerServiceNode.getControllerServiceImplementation().getClass().isAnnotationPresent(Stateful.class));
    csDto.setRestricted(controllerServiceNode.isRestricted());
    csDto.setExtensionMissing(controllerServiceNode.isExtensionMissing());
    csDto.setDescriptors(new LinkedHashMap<>());
    csDto.setProperties(new LinkedHashMap<>());
    // create the snippet with the controller service
    final FlowSnippetDTO flowSnippetDTO = new FlowSnippetDTO();
    flowSnippetDTO.setControllerServices(Collections.singleton(csDto));
    // instantiate the snippet
    assertEquals(0, controller.getRootGroup().getControllerServices(false).size());
    controller.instantiateSnippet(controller.getRootGroup(), flowSnippetDTO);
    assertEquals(1, controller.getRootGroup().getControllerServices(false).size());
}
Also used : Stateful(org.apache.nifi.annotation.behavior.Stateful) ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) FlowSnippetDTO(org.apache.nifi.web.api.dto.FlowSnippetDTO) ServiceA(org.apache.nifi.controller.service.mock.ServiceA) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) BundleDTO(org.apache.nifi.web.api.dto.BundleDTO) BundleCoordinate(org.apache.nifi.bundle.BundleCoordinate) Test(org.junit.Test)

Example 33 with BundleCoordinate

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

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

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

the class TestFlowController method testInstantiateSnippetWhenControllerServiceMissingBundle.

@Test(expected = IllegalArgumentException.class)
public void testInstantiateSnippetWhenControllerServiceMissingBundle() throws ProcessorInstantiationException {
    final String id = UUID.randomUUID().toString();
    final BundleCoordinate coordinate = systemBundle.getBundleDetails().getCoordinate();
    final ControllerServiceNode controllerServiceNode = controller.createControllerService(ServiceA.class.getName(), id, coordinate, null, true);
    // create the controller service dto
    final ControllerServiceDTO csDto = new ControllerServiceDTO();
    // use a different id
    csDto.setId(UUID.randomUUID().toString());
    csDto.setParentGroupId(controllerServiceNode.getProcessGroup() == null ? null : controllerServiceNode.getProcessGroup().getIdentifier());
    csDto.setName(controllerServiceNode.getName());
    csDto.setType(controllerServiceNode.getCanonicalClassName());
    // missing bundle
    csDto.setBundle(null);
    csDto.setState(controllerServiceNode.getState().name());
    csDto.setAnnotationData(controllerServiceNode.getAnnotationData());
    csDto.setComments(controllerServiceNode.getComments());
    csDto.setPersistsState(controllerServiceNode.getControllerServiceImplementation().getClass().isAnnotationPresent(Stateful.class));
    csDto.setRestricted(controllerServiceNode.isRestricted());
    csDto.setExtensionMissing(controllerServiceNode.isExtensionMissing());
    csDto.setDescriptors(new LinkedHashMap<>());
    csDto.setProperties(new LinkedHashMap<>());
    // create the snippet with the controller service
    final FlowSnippetDTO flowSnippetDTO = new FlowSnippetDTO();
    flowSnippetDTO.setControllerServices(Collections.singleton(csDto));
    // instantiate the snippet
    assertEquals(0, controller.getRootGroup().getControllerServices(false).size());
    controller.instantiateSnippet(controller.getRootGroup(), flowSnippetDTO);
}
Also used : Stateful(org.apache.nifi.annotation.behavior.Stateful) ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) FlowSnippetDTO(org.apache.nifi.web.api.dto.FlowSnippetDTO) ServiceA(org.apache.nifi.controller.service.mock.ServiceA) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) BundleCoordinate(org.apache.nifi.bundle.BundleCoordinate) Test(org.junit.Test)

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