IterationsHandler { public IterativeAlgorithmState handleNewIterativeAlgorithmRequest( AdpDBManager adpDBManager, String algorithmKey, AlgorithmProperties algorithmProperties, ContainerProxy[] usedContainerProxies) { AdpDBClient adpDBClient; try { String database = HBPConstants.DEMO_DB_WORKING_DIRECTORY + algorithmKey; AdpDBClientProperties clientProperties = new AdpDBClientProperties(database, "", "", false, false, -1, 10); clientProperties.setContainerProxies(usedContainerProxies); adpDBClient = AdpDBClientFactory.createDBClient(adpDBManager, clientProperties); } catch (RemoteException e) { String errMsg = "Failed to initialize " + AdpDBClient.class.getSimpleName() + " for algorithm: " + algorithmKey; log.error(errMsg); throw new IterationsFatalException(errMsg, e); } log.debug("Created " + AdpDBClient.class.getSimpleName() + " for iterative algorithm: " + algorithmKey + "."); IterativeAlgorithmState iterativeAlgorithmState = new IterativeAlgorithmState(algorithmKey, algorithmProperties, adpDBClient); log.debug("Created " + IterativeAlgorithmState.class.getSimpleName() + " for: " + iterativeAlgorithmState.toString() + "."); String[] dflScripts = new String[ IterativeAlgorithmState.IterativeAlgorithmPhasesModel.values().length]; for (IterativeAlgorithmState.IterativeAlgorithmPhasesModel phase : IterativeAlgorithmState.IterativeAlgorithmPhasesModel.values()) { try { if (algorithmProperties.getType() == AlgorithmProperties.AlgorithmType.python_iterative) { dflScripts[phase.ordinal()] = Composer.composePythonIterativeAlgorithmsDFLScript( algorithmKey, algorithmProperties, phase); } else if (algorithmProperties.getType() == AlgorithmProperties.AlgorithmType.iterative) { dflScripts[phase.ordinal()] = Composer.composeIterativeAlgorithmsDFLScript( algorithmKey, algorithmProperties, phase); } else { throw new IterationsFatalException("Algorithm type should be iterative or python_iterative."); } } catch (ComposerException e) { throw new IterationsFatalException("Composer failure to generate DFL script for phase: " + phase.name() + ".", e); } } iterativeAlgorithmState.setDflScripts(dflScripts); for (String dflScript : dflScripts) { log.debug("Iterative algorithm dfl Scripts Generated: \n" + dflScript); } try { for (IterativeAlgorithmState.IterativeAlgorithmPhasesModel phase : IterativeAlgorithmState.IterativeAlgorithmPhasesModel.values()) { String demoCurrentAlgorithmDir = DEMO_ALGORITHMS_WORKING_DIRECTORY + "/" + algorithmKey; Composer.persistDFLScriptToAlgorithmsDemoDirectory( demoCurrentAlgorithmDir, dflScripts[phase.ordinal()], phase); } } catch (IOException e) { log.error("Failed to persist DFL scripts for algorithm [" + algorithmKey + "]"); } iterationsStateManager.submitIterativeAlgorithm(algorithmKey, iterativeAlgorithmState); iterativeAlgorithmState.lock(); iterationsScheduler.scheduleNewAlgorithm(algorithmKey); log.debug(iterativeAlgorithmState.toString() + " was submitted."); return iterativeAlgorithmState; } private  IterationsHandler(); static IterationsHandler getInstance(); IterativeAlgorithmState handleNewIterativeAlgorithmRequest(
            AdpDBManager adpDBManager, String algorithmKey,
            AlgorithmProperties algorithmProperties, ContainerProxy[] usedContainerProxies); void removeIterativeAlgorithmStateInstanceFromISM(String algorithmKey);  }
@Test public void ensureIterativeAlgorithmIsSubmittedToStateManager() throws IOException { String algorithmKey = IterationsTestGenericUtils.generateAlgorithmKey(algorithmProperties); final IterativeAlgorithmState ias = handler.handleNewIterativeAlgorithmRequest( AdpDBManagerLocator.getDBManager(), algorithmKey, algorithmProperties, ArtRegistryLocator.getArtRegistryProxy().getContainers()); final Map<String, IterativeAlgorithmState> iterativeAlgorithmMapping = Whitebox.getInternalState(stateManager, "iterativeAlgorithmMapping"); TestCase.assertFalse(iterativeAlgorithmMapping.isEmpty()); FileUtils.deleteDirectory(new File( HBPConstants.DEMO_ALGORITHMS_WORKING_DIRECTORY + "/" + ias.getAlgorithmKey())); }