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());
}
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);
}
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) {
}
}
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);
}
}
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;
}
Aggregations