use of org.apache.nifi.controller.service.StandardControllerServiceProvider in project nifi by apache.
the class TestStandardProcessScheduler method validateDisablingOfTheFailedService.
@Test
public void validateDisablingOfTheFailedService() throws Exception {
final StandardProcessScheduler scheduler = createScheduler();
final StandardControllerServiceProvider provider = new StandardControllerServiceProvider(controller, scheduler, null, stateMgrProvider, variableRegistry, nifiProperties);
final ControllerServiceNode serviceNode = provider.createControllerService(FailingService.class.getName(), "1", systemBundle.getBundleDetails().getCoordinate(), null, false);
scheduler.enableControllerService(serviceNode);
Thread.sleep(1000);
scheduler.shutdown();
/*
* Because it was never disabled it will remain active since its
* enabling is being retried. This may actually be a bug in the
* scheduler since it probably has to shut down all components (disable
* services, shut down processors etc) before shutting down itself
*/
assertTrue(serviceNode.isActive());
assertTrue(serviceNode.getState() == ControllerServiceState.ENABLING);
}
use of org.apache.nifi.controller.service.StandardControllerServiceProvider in project nifi by apache.
the class TestStandardProcessScheduler method validateDisabledServiceCantBeDisabled.
/**
* Validates the atomic nature of ControllerServiceNode.disable(..) method
* which must never trigger @OnDisabled, regardless of how many threads may
* have a reference to the underlying ProcessScheduler and
* ControllerServiceNode.
*/
@Test
public void validateDisabledServiceCantBeDisabled() throws Exception {
final StandardProcessScheduler scheduler = createScheduler();
final StandardControllerServiceProvider provider = new StandardControllerServiceProvider(controller, scheduler, null, stateMgrProvider, variableRegistry, nifiProperties);
final ControllerServiceNode serviceNode = provider.createControllerService(SimpleTestService.class.getName(), "1", systemBundle.getBundleDetails().getCoordinate(), null, false);
final SimpleTestService ts = (SimpleTestService) serviceNode.getControllerServiceImplementation();
final ExecutorService executor = Executors.newCachedThreadPool();
final AtomicBoolean asyncFailed = new AtomicBoolean();
for (int i = 0; i < 1000; i++) {
executor.execute(new Runnable() {
@Override
public void run() {
try {
scheduler.disableControllerService(serviceNode);
assertFalse(serviceNode.isActive());
} catch (final Exception e) {
e.printStackTrace();
asyncFailed.set(true);
}
}
});
}
// need to sleep a while since we are emulating async invocations on
// method that is also internally async
Thread.sleep(500);
executor.shutdown();
assertFalse(asyncFailed.get());
assertEquals(0, ts.disableInvocationCount());
}
use of org.apache.nifi.controller.service.StandardControllerServiceProvider in project nifi by apache.
the class TestStandardProcessScheduler method testDisableControllerServiceWithProcessorTryingToStartUsingIt.
@Test(timeout = 60000)
public void testDisableControllerServiceWithProcessorTryingToStartUsingIt() throws InterruptedException {
final String uuid = UUID.randomUUID().toString();
final Processor proc = new ServiceReferencingProcessor();
proc.initialize(new StandardProcessorInitializationContext(uuid, null, null, null, null));
final ReloadComponent reloadComponent = Mockito.mock(ReloadComponent.class);
final StandardControllerServiceProvider serviceProvider = new StandardControllerServiceProvider(controller, scheduler, null, Mockito.mock(StateManagerProvider.class), variableRegistry, nifiProperties);
final ControllerServiceNode service = serviceProvider.createControllerService(NoStartServiceImpl.class.getName(), "service", systemBundle.getBundleDetails().getCoordinate(), null, true);
rootGroup.addControllerService(service);
final LoggableComponent<Processor> loggableComponent = new LoggableComponent<>(proc, systemBundle.getBundleDetails().getCoordinate(), null);
final ProcessorNode procNode = new StandardProcessorNode(loggableComponent, uuid, new StandardValidationContextFactory(serviceProvider, variableRegistry), scheduler, serviceProvider, nifiProperties, new StandardComponentVariableRegistry(VariableRegistry.EMPTY_REGISTRY), reloadComponent);
rootGroup.addProcessor(procNode);
Map<String, String> procProps = new HashMap<>();
procProps.put(ServiceReferencingProcessor.SERVICE_DESC.getName(), service.getIdentifier());
procNode.setProperties(procProps);
scheduler.enableControllerService(service);
scheduler.startProcessor(procNode, true);
Thread.sleep(25L);
scheduler.stopProcessor(procNode);
assertTrue(service.isActive());
assertTrue(service.getState() == ControllerServiceState.ENABLING);
scheduler.disableControllerService(service);
assertTrue(service.getState() == ControllerServiceState.DISABLING);
assertFalse(service.isActive());
while (service.getState() != ControllerServiceState.DISABLED) {
Thread.sleep(5L);
}
assertTrue(service.getState() == ControllerServiceState.DISABLED);
}
use of org.apache.nifi.controller.service.StandardControllerServiceProvider in project nifi by apache.
the class TestStandardProcessScheduler method validateNeverEnablingServiceCanStillBeDisabled.
/**
* Validates that service that is infinitely blocking in @OnEnabled can
* still have DISABLE operation initiated. The service itself will be set to
* DISABLING state at which point UI and all will know that such service can
* not be transitioned any more into any other state until it finishes
* enabling (which will never happen in our case thus should be addressed by
* user). However, regardless of user's mistake NiFi will remain
* functioning.
*/
@Test
public void validateNeverEnablingServiceCanStillBeDisabled() throws Exception {
final StandardProcessScheduler scheduler = createScheduler();
final StandardControllerServiceProvider provider = new StandardControllerServiceProvider(controller, scheduler, null, stateMgrProvider, variableRegistry, nifiProperties);
final ControllerServiceNode serviceNode = provider.createControllerService(LongEnablingService.class.getName(), "1", systemBundle.getBundleDetails().getCoordinate(), null, false);
final LongEnablingService ts = (LongEnablingService) serviceNode.getControllerServiceImplementation();
ts.setLimit(Long.MAX_VALUE);
scheduler.enableControllerService(serviceNode);
Thread.sleep(100);
assertTrue(serviceNode.isActive());
assertEquals(1, ts.enableInvocationCount());
Thread.sleep(1000);
scheduler.disableControllerService(serviceNode);
assertFalse(serviceNode.isActive());
assertEquals(ControllerServiceState.DISABLING, serviceNode.getState());
assertEquals(0, ts.disableInvocationCount());
}
use of org.apache.nifi.controller.service.StandardControllerServiceProvider in project nifi by apache.
the class StandardProcessSchedulerIT method validateLongEnablingServiceCanStillBeDisabled.
/**
* Validates that the service that is currently in ENABLING state can be
* disabled and that its @OnDisabled operation will be invoked as soon as
*
* @OnEnable finishes.
*/
@Test
public void validateLongEnablingServiceCanStillBeDisabled() throws Exception {
final StandardProcessScheduler scheduler = new StandardProcessScheduler(new FlowEngine(1, "Unit Test", true), null, null, stateMgrProvider, nifiProperties);
final StandardControllerServiceProvider provider = new StandardControllerServiceProvider(controller, scheduler, null, stateMgrProvider, variableRegistry, nifiProperties);
final ControllerServiceNode serviceNode = provider.createControllerService(LongEnablingService.class.getName(), "1", systemBundle.getBundleDetails().getCoordinate(), null, false);
final LongEnablingService ts = (LongEnablingService) serviceNode.getControllerServiceImplementation();
ts.setLimit(3000);
scheduler.enableControllerService(serviceNode);
Thread.sleep(2000);
assertTrue(serviceNode.isActive());
assertEquals(1, ts.enableInvocationCount());
Thread.sleep(500);
scheduler.disableControllerService(serviceNode);
assertFalse(serviceNode.isActive());
assertEquals(ControllerServiceState.DISABLING, serviceNode.getState());
assertEquals(0, ts.disableInvocationCount());
// wait a bit. . . Enabling will finish and @OnDisabled will be invoked
// automatically
Thread.sleep(4000);
assertEquals(ControllerServiceState.DISABLED, serviceNode.getState());
assertEquals(1, ts.disableInvocationCount());
}
Aggregations