Skip to content

Commit

Permalink
IKASAN-2044 - allow stopped flows to remain stopped when deactivate/a…
Browse files Browse the repository at this point in the history
…ctivate is called.
  • Loading branch information
mitcje authored and mick-stewart73 committed Jan 21, 2022
1 parent 5e6d01e commit 9405f1c
Show file tree
Hide file tree
Showing 2 changed files with 175 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ public class ModuleActivatorDefaultImpl implements ModuleActivator<Flow>
/** internal list of modules activated */
private List<Module> activatedModuleNames = new ArrayList<Module>();

/** keep a handle to the state (running or stopped) of each flow when deactivated for reference on activation */
List<String> flowsInStoppedState = new ArrayList<String>();

/**
* Constructor
* @param configurationService
Expand Down Expand Up @@ -171,7 +174,15 @@ public void activate(Module<Flow> module)
{
try
{
flow.start();
if( this.flowsInStoppedState.contains( flow.getName()) )
{
logger.info("Module [" + module.getName() + "] Flow [" + flow.getName()
+ "] was previously stopped. Leaving flow in a stopped state.");
}
else
{
flow.start();
}
}
catch(RuntimeException e)
{
Expand Down Expand Up @@ -222,6 +233,12 @@ public void deactivate(Module<Flow> module)
// stop flows
for(Flow flow:module.getFlows())
{
// get a handle to the flows currently stopped
if(!flow.isRunning())
{
this.flowsInStoppedState.add(flow.getName());
}

// stop flow and associated components
flow.stop();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ public void test_successful_activate_existing_startupControl()
exactly(1).of(flowStartupControl).getStartupType();
will(returnValue(StartupType.AUTOMATIC));

exactly(1).of(flow1).getName();
will(returnValue("flowname1"));

oneOf(flow1).start();

exactly(2).of(dashboardRestService).publish(module);
Expand Down Expand Up @@ -236,6 +239,9 @@ public void test_successful_activate_no_existing_startupControl()
oneOf(flowStartupControl).getStartupType();
will(returnValue(StartupType.AUTOMATIC));

exactly(1).of(flow1).getName();
will(returnValue("flowname1"));

oneOf(flow1).start();

exactly(2).of(dashboardRestService).publish(module);
Expand Down Expand Up @@ -286,6 +292,9 @@ public void test_successful_activate_no_existing_startupControl_not_configured_r
oneOf(flowStartupControl).getStartupType();
will(returnValue(StartupType.AUTOMATIC));

exactly(1).of(flow1).getName();
will(returnValue("flowname1"));

oneOf(flow1).start();

exactly(2).of(dashboardRestService).publish(module);
Expand All @@ -296,6 +305,154 @@ public void test_successful_activate_no_existing_startupControl_not_configured_r
mockery.assertIsSatisfied();
}

@Test
public void test_successful_deactivate_activate_with_stopped_flow()
{
List flowsEmpty = new ArrayList();

final List flowsPopulated = new ArrayList();
flowsPopulated.add(flow1);

final List startupControls = new ArrayList();

moduleActivator =
new ExtendedModuleActivator(false, configurationService, startupControlDao, dashboardRestService, dashboardRestService);

String moduleName = "moduleName";

mockery.checking(new Expectations()
{
{
//
// deactivate

// stop flows
exactly(1).of(module).getFlows();
will(returnValue(flowsPopulated));

exactly(1).of(flow1).isRunning();
will(returnValue(false));

exactly(1).of(flow1).getName();
will(returnValue("flowname1"));

oneOf(flow1).stop();

//
// activate

exactly(1).of(startupControlDao).getStartupControls(moduleName);
will(returnValue(startupControls));

oneOf(module).getName();
will(returnValue(moduleName));

// start flows
exactly(1).of(module).getFlows();
will(returnValue(flowsPopulated));

exactly(1).of(module).getName();
will(returnValue(moduleName));

exactly(2).of(flow1).getName();
will(returnValue("flowname1"));

oneOf(startupControlDao).getStartupControl(moduleName, "flowname1");
will(returnValue(flowStartupControl));

oneOf(flowStartupControl).getStartupType();
will(returnValue(StartupType.AUTOMATIC));

exactly(1).of(flow1).getName();
will(returnValue("flowname1"));

exactly(1).of(module).getName();
will(returnValue(moduleName));

exactly(1).of(flow1).getName();
will(returnValue("flowname1"));

exactly(2).of(dashboardRestService).publish(module);

}
});

moduleActivator.deactivate(module);
moduleActivator.activate(module);
Assert.assertTrue("module isActivated should return true", moduleActivator.isActivated(module) );
mockery.assertIsSatisfied();
}

@Test
public void test_successful_deactivate_activate_with_running_flow()
{
List flowsEmpty = new ArrayList();

final List flowsPopulated = new ArrayList();
flowsPopulated.add(flow1);

final List startupControls = new ArrayList();

moduleActivator =
new ExtendedModuleActivator(false, configurationService, startupControlDao, dashboardRestService, dashboardRestService);

String moduleName = "moduleName";

mockery.checking(new Expectations()
{
{
//
// deactivate

// stop flows
exactly(1).of(module).getFlows();
will(returnValue(flowsPopulated));

exactly(1).of(flow1).isRunning();
will(returnValue(true));

oneOf(flow1).stop();

//
// activate

exactly(1).of(startupControlDao).getStartupControls(moduleName);
will(returnValue(startupControls));

oneOf(module).getName();
will(returnValue(moduleName));

// start flows
exactly(1).of(module).getFlows();
will(returnValue(flowsPopulated));

exactly(1).of(module).getName();
will(returnValue(moduleName));

exactly(2).of(flow1).getName();
will(returnValue("flowname1"));

oneOf(startupControlDao).getStartupControl(moduleName, "flowname1");
will(returnValue(flowStartupControl));

oneOf(flowStartupControl).getStartupType();
will(returnValue(StartupType.AUTOMATIC));

exactly(1).of(flow1).getName();
will(returnValue("flowname1"));

exactly(1).of(flow1).start();

exactly(2).of(dashboardRestService).publish(module);

}
});

moduleActivator.deactivate(module);
moduleActivator.activate(module);
Assert.assertTrue("module isActivated should return true", moduleActivator.isActivated(module) );
mockery.assertIsSatisfied();
}

private class ExtendedModuleActivator extends ModuleActivatorDefaultImpl
{
Expand Down

0 comments on commit 9405f1c

Please sign in to comment.