use of org.apache.nifi.groups.ProcessGroup in project nifi by apache.
the class TestProcessorLifecycle method validateProcessorUnscheduledAndStoppedWhenStopIsCalledBeforeProcessorFullyStarted.
/**
* Validates that processor can be stopped before start sequence finished.
*/
@Test
public void validateProcessorUnscheduledAndStoppedWhenStopIsCalledBeforeProcessorFullyStarted() throws Exception {
final FlowControllerAndSystemBundle fcsb = this.buildFlowControllerForTest();
fc = fcsb.getFlowController();
ProcessGroup testGroup = fc.createProcessGroup(UUID.randomUUID().toString());
this.setControllerRootGroup(fc, testGroup);
ProcessorNode testProcNode = fc.createProcessor(TestProcessor.class.getName(), UUID.randomUUID().toString(), fcsb.getSystemBundle().getBundleDetails().getCoordinate());
testProcNode.setProperties(properties);
TestProcessor testProcessor = (TestProcessor) testProcNode.getProcessor();
// sets the scenario for the processor to run
int delay = 200;
this.longRunningOnSchedule(testProcessor, delay);
ProcessScheduler ps = fc.getProcessScheduler();
ps.startProcessor(testProcNode, true);
assertCondition(() -> ScheduledState.RUNNING == testProcNode.getScheduledState(), 5000L);
ps.stopProcessor(testProcNode);
assertCondition(() -> ScheduledState.STOPPED == testProcNode.getScheduledState(), 5000L);
assertCondition(() -> testProcessor.operationNames.size() == 3, 8000L);
assertEquals("@OnScheduled", testProcessor.operationNames.get(0));
assertEquals("@OnUnscheduled", testProcessor.operationNames.get(1));
assertEquals("@OnStopped", testProcessor.operationNames.get(2));
}
use of org.apache.nifi.groups.ProcessGroup in project nifi by apache.
the class TestProcessorLifecycle method validateStartFailsOnInvalidProcessorWithDisabledService.
/**
* Validate that processor will not be validated on failing
* ControllerService validation (not enabled).
*/
@Test(expected = IllegalStateException.class)
public void validateStartFailsOnInvalidProcessorWithDisabledService() throws Exception {
final FlowControllerAndSystemBundle fcsb = this.buildFlowControllerForTest();
fc = fcsb.getFlowController();
ProcessGroup testGroup = fc.createProcessGroup(UUID.randomUUID().toString());
this.setControllerRootGroup(fc, testGroup);
ControllerServiceNode testServiceNode = fc.createControllerService(TestService.class.getName(), "serv", fcsb.getSystemBundle().getBundleDetails().getCoordinate(), null, true);
ProcessorNode testProcNode = fc.createProcessor(TestProcessor.class.getName(), UUID.randomUUID().toString(), fcsb.getSystemBundle().getBundleDetails().getCoordinate());
properties.put("S", testServiceNode.getIdentifier());
testProcNode.setProperties(properties);
TestProcessor testProcessor = (TestProcessor) testProcNode.getProcessor();
testProcessor.withService = true;
ProcessScheduler ps = fc.getProcessScheduler();
ps.startProcessor(testProcNode, true);
fail();
}
use of org.apache.nifi.groups.ProcessGroup in project nifi by apache.
the class TestProcessorLifecycle method validateProcessorDeletion.
/**
* Test deletion of processor when connected to another
*
* @throws Exception exception
*/
@Test
public void validateProcessorDeletion() throws Exception {
final FlowControllerAndSystemBundle fcsb = this.buildFlowControllerForTest();
fc = fcsb.getFlowController();
ProcessGroup testGroup = fc.createProcessGroup(UUID.randomUUID().toString());
this.setControllerRootGroup(fc, testGroup);
ProcessorNode testProcNodeA = fc.createProcessor(TestProcessor.class.getName(), UUID.randomUUID().toString(), fcsb.getSystemBundle().getBundleDetails().getCoordinate());
testProcNodeA.setProperties(properties);
testGroup.addProcessor(testProcNodeA);
ProcessorNode testProcNodeB = fc.createProcessor(TestProcessor.class.getName(), UUID.randomUUID().toString(), fcsb.getSystemBundle().getBundleDetails().getCoordinate());
testProcNodeB.setProperties(properties);
testGroup.addProcessor(testProcNodeB);
Collection<String> relationNames = new ArrayList<>();
relationNames.add("relation");
Connection connection = fc.createConnection(UUID.randomUUID().toString(), Connection.class.getName(), testProcNodeA, testProcNodeB, relationNames);
testGroup.addConnection(connection);
ProcessScheduler ps = fc.getProcessScheduler();
ps.startProcessor(testProcNodeA, true);
ps.startProcessor(testProcNodeB, true);
try {
testGroup.removeProcessor(testProcNodeA);
fail();
} catch (Exception e) {
// should throw exception because processor running
}
try {
testGroup.removeProcessor(testProcNodeB);
fail();
} catch (Exception e) {
// should throw exception because processor running
}
ps.stopProcessor(testProcNodeB);
Thread.sleep(100);
try {
testGroup.removeProcessor(testProcNodeA);
fail();
} catch (Exception e) {
// should throw exception because destination processor running
}
try {
testGroup.removeProcessor(testProcNodeB);
fail();
} catch (Exception e) {
// should throw exception because source processor running
}
ps.stopProcessor(testProcNodeA);
Thread.sleep(100);
testGroup.removeProcessor(testProcNodeA);
testGroup.removeProcessor(testProcNodeB);
testGroup.shutdown();
}
use of org.apache.nifi.groups.ProcessGroup in project nifi by apache.
the class TestStandardControllerServiceProvider method testOrderingOfServices.
@Test
public void testOrderingOfServices() {
final ProcessGroup procGroup = new MockProcessGroup(controller);
final FlowController controller = Mockito.mock(FlowController.class);
Mockito.when(controller.getGroup(Mockito.anyString())).thenReturn(procGroup);
final StandardControllerServiceProvider provider = new StandardControllerServiceProvider(controller, null, null, stateManagerProvider, variableRegistry, niFiProperties);
final ControllerServiceNode serviceNode1 = provider.createControllerService(ServiceA.class.getName(), "1", systemBundle.getBundleDetails().getCoordinate(), null, false);
final ControllerServiceNode serviceNode2 = provider.createControllerService(ServiceB.class.getName(), "2", systemBundle.getBundleDetails().getCoordinate(), null, false);
setProperty(serviceNode1, ServiceA.OTHER_SERVICE.getName(), "2");
final Map<String, ControllerServiceNode> nodeMap = new LinkedHashMap<>();
nodeMap.put("1", serviceNode1);
nodeMap.put("2", serviceNode2);
List<List<ControllerServiceNode>> branches = StandardControllerServiceProvider.determineEnablingOrder(nodeMap);
assertEquals(2, branches.size());
List<ControllerServiceNode> ordered = branches.get(0);
assertEquals(2, ordered.size());
assertTrue(ordered.get(0) == serviceNode2);
assertTrue(ordered.get(1) == serviceNode1);
assertEquals(1, branches.get(1).size());
assertTrue(branches.get(1).get(0) == serviceNode2);
nodeMap.clear();
nodeMap.put("2", serviceNode2);
nodeMap.put("1", serviceNode1);
branches = StandardControllerServiceProvider.determineEnablingOrder(nodeMap);
assertEquals(2, branches.size());
ordered = branches.get(1);
assertEquals(2, ordered.size());
assertTrue(ordered.get(0) == serviceNode2);
assertTrue(ordered.get(1) == serviceNode1);
assertEquals(1, branches.get(0).size());
assertTrue(branches.get(0).get(0) == serviceNode2);
// add circular dependency on self.
nodeMap.clear();
setProperty(serviceNode1, ServiceA.OTHER_SERVICE_2.getName(), "1");
nodeMap.put("1", serviceNode1);
nodeMap.put("2", serviceNode2);
branches = StandardControllerServiceProvider.determineEnablingOrder(nodeMap);
assertEquals(2, branches.size());
ordered = branches.get(0);
assertEquals(2, ordered.size());
assertTrue(ordered.get(0) == serviceNode2);
assertTrue(ordered.get(1) == serviceNode1);
nodeMap.clear();
nodeMap.put("2", serviceNode2);
nodeMap.put("1", serviceNode1);
branches = StandardControllerServiceProvider.determineEnablingOrder(nodeMap);
assertEquals(2, branches.size());
ordered = branches.get(1);
assertEquals(2, ordered.size());
assertTrue(ordered.get(0) == serviceNode2);
assertTrue(ordered.get(1) == serviceNode1);
// add circular dependency once removed. In this case, we won't actually be able to enable these because of the
// circular dependency because they will never be valid because they will always depend on a disabled service.
// But we want to ensure that the method returns successfully without throwing a StackOverflowException or anything
// like that.
nodeMap.clear();
final ControllerServiceNode serviceNode3 = provider.createControllerService(ServiceA.class.getName(), "3", systemBundle.getBundleDetails().getCoordinate(), null, false);
setProperty(serviceNode1, ServiceA.OTHER_SERVICE.getName(), "3");
setProperty(serviceNode3, ServiceA.OTHER_SERVICE.getName(), "1");
nodeMap.put("1", serviceNode1);
nodeMap.put("3", serviceNode3);
branches = StandardControllerServiceProvider.determineEnablingOrder(nodeMap);
assertEquals(2, branches.size());
ordered = branches.get(0);
assertEquals(2, ordered.size());
assertTrue(ordered.get(0) == serviceNode3);
assertTrue(ordered.get(1) == serviceNode1);
nodeMap.clear();
nodeMap.put("3", serviceNode3);
nodeMap.put("1", serviceNode1);
branches = StandardControllerServiceProvider.determineEnablingOrder(nodeMap);
assertEquals(2, branches.size());
ordered = branches.get(1);
assertEquals(2, ordered.size());
assertTrue(ordered.get(0) == serviceNode3);
assertTrue(ordered.get(1) == serviceNode1);
// Add multiple completely disparate branches.
nodeMap.clear();
setProperty(serviceNode1, ServiceA.OTHER_SERVICE.getName(), "2");
final ControllerServiceNode serviceNode4 = provider.createControllerService(ServiceB.class.getName(), "4", systemBundle.getBundleDetails().getCoordinate(), null, false);
final ControllerServiceNode serviceNode5 = provider.createControllerService(ServiceB.class.getName(), "5", systemBundle.getBundleDetails().getCoordinate(), null, false);
setProperty(serviceNode3, ServiceA.OTHER_SERVICE.getName(), "4");
nodeMap.put("1", serviceNode1);
nodeMap.put("2", serviceNode2);
nodeMap.put("3", serviceNode3);
nodeMap.put("4", serviceNode4);
nodeMap.put("5", serviceNode5);
branches = StandardControllerServiceProvider.determineEnablingOrder(nodeMap);
assertEquals(5, branches.size());
ordered = branches.get(0);
assertEquals(2, ordered.size());
assertTrue(ordered.get(0) == serviceNode2);
assertTrue(ordered.get(1) == serviceNode1);
assertEquals(1, branches.get(1).size());
assertTrue(branches.get(1).get(0) == serviceNode2);
ordered = branches.get(2);
assertEquals(2, ordered.size());
assertTrue(ordered.get(0) == serviceNode4);
assertTrue(ordered.get(1) == serviceNode3);
assertEquals(1, branches.get(3).size());
assertTrue(branches.get(3).get(0) == serviceNode4);
assertEquals(1, branches.get(4).size());
assertTrue(branches.get(4).get(0) == serviceNode5);
// create 2 branches both dependent on the same service
nodeMap.clear();
setProperty(serviceNode1, ServiceA.OTHER_SERVICE.getName(), "2");
setProperty(serviceNode3, ServiceA.OTHER_SERVICE.getName(), "2");
nodeMap.put("1", serviceNode1);
nodeMap.put("2", serviceNode2);
nodeMap.put("3", serviceNode3);
branches = StandardControllerServiceProvider.determineEnablingOrder(nodeMap);
assertEquals(3, branches.size());
ordered = branches.get(0);
assertEquals(2, ordered.size());
assertTrue(ordered.get(0) == serviceNode2);
assertTrue(ordered.get(1) == serviceNode1);
ordered = branches.get(1);
assertEquals(1, ordered.size());
assertTrue(ordered.get(0) == serviceNode2);
ordered = branches.get(2);
assertEquals(2, ordered.size());
assertTrue(ordered.get(0) == serviceNode2);
assertTrue(ordered.get(1) == serviceNode3);
}
use of org.apache.nifi.groups.ProcessGroup in project nifi by apache.
the class TestHttpFlowFileServerProtocol method testPortNotInValidState.
@Test
public void testPortNotInValidState() throws Exception {
final HttpFlowFileServerProtocol serverProtocol = getDefaultHttpFlowFileServerProtocol();
final Peer peer = getDefaultPeer();
((HttpServerCommunicationsSession) peer.getCommunicationsSession()).putHandshakeParam(HandshakeProperty.PORT_IDENTIFIER, "port-identifier");
final ProcessGroup processGroup = mock(ProcessGroup.class);
final RootGroupPort port = mock(RootGroupPort.class);
final PortAuthorizationResult authResult = mock(PortAuthorizationResult.class);
doReturn(true).when(processGroup).isRootGroup();
doReturn(port).when(processGroup).getOutputPort("port-identifier");
doReturn(authResult).when(port).checkUserAuthorization(any(String.class));
doReturn(true).when(authResult).isAuthorized();
serverProtocol.setRootProcessGroup(processGroup);
try {
serverProtocol.handshake(peer);
fail();
} catch (final HandshakeException e) {
assertEquals(ResponseCode.PORT_NOT_IN_VALID_STATE, e.getResponseCode());
}
assertFalse(serverProtocol.isHandshakeSuccessful());
}
Aggregations