+++ /dev/null
-/* Copyright (c) 2009 Peter Troshin\r
- * Copyright (c) 2013 Alexander Sherstnev\r
- * \r
- * JAva Bioinformatics Analysis Web Services (JABAWS)\r
- * @version: 2.5 \r
- * \r
- * This library is free software; you can redistribute it and/or modify it under the terms of the\r
- * Apache License version 2 as published by the Apache Software Foundation\r
- * \r
- * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without\r
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache \r
- * License for more details.\r
- * \r
- * A copy of the license is in apache_license.txt. It is also available here:\r
- * @see: http://www.apache.org/licenses/LICENSE-2.0.txt\r
- * \r
- * Any republication or derived work distributed in source code form\r
- * must include this copyright and license notice.\r
- */\r
-\r
-package compbio.runner.msa;\r
-\r
-import static org.testng.Assert.assertEquals;\r
-import static org.testng.Assert.assertFalse;\r
-import static org.testng.Assert.assertNotNull;\r
-import static org.testng.Assert.assertTrue;\r
-import static org.testng.Assert.fail;\r
-\r
-import java.io.File;\r
-import java.io.FileInputStream;\r
-import java.io.FileNotFoundException;\r
-import java.io.IOException;\r
-import java.text.ParseException;\r
-import java.util.Collections;\r
-import java.util.List;\r
-\r
-import javax.xml.bind.JAXBException;\r
-\r
-import org.ggf.drmaa.DrmaaException;\r
-import org.ggf.drmaa.JobInfo;\r
-import org.testng.annotations.Test;\r
-\r
-import compbio.engine.AsyncExecutor;\r
-import compbio.engine.Configurator;\r
-import compbio.engine.FilePuller;\r
-import compbio.engine.SyncExecutor;\r
-import compbio.engine.client.EngineUtil;\r
-import compbio.engine.client.ConfExecutable;\r
-import compbio.engine.client.ConfiguredExecutable;\r
-import compbio.engine.client.Executable;\r
-import compbio.engine.client.Executable.ExecProvider;\r
-import compbio.engine.client.RunConfiguration;\r
-import compbio.engine.cluster.drmaa.ClusterEngineUtil;\r
-import compbio.engine.cluster.drmaa.ClusterRunner;\r
-import compbio.engine.cluster.drmaa.StatisticManager;\r
-import compbio.engine.conf.RunnerConfigMarshaller;\r
-import compbio.engine.local.AsyncLocalRunner;\r
-import compbio.engine.local.LocalExecutorService;\r
-import compbio.engine.local.LocalRunner;\r
-import compbio.metadata.AllTestSuit;\r
-import compbio.metadata.ChunkHolder;\r
-import compbio.metadata.JobExecutionException;\r
-import compbio.metadata.JobStatus;\r
-import compbio.metadata.JobSubmissionException;\r
-import compbio.metadata.LimitsManager;\r
-import compbio.metadata.ResultNotAvailableException;\r
-import compbio.metadata.RunnerConfig;\r
-import compbio.runner.OptionCombinator;\r
-import compbio.util.FileWatcher;\r
-import compbio.util.SysPrefs;\r
-\r
-public class ClustalOTester {\r
-\r
- static final String clustalConfigFile = AllTestSuit.TEST_DATA_PATH + "ClustaloParameters.xml";\r
- public static String test_outfile = "TO1381.clustalo.out";\r
- public static String cluster_test_outfile = "TO1381.clustalo.cluster.out";\r
-\r
- @Test(groups = {AllTestSuit.test_group_runner})\r
- public void RunLocally() {\r
- ClustalO clustal = new ClustalO();\r
- clustal.setInput(AllTestSuit.test_input).setOutput(test_outfile);\r
- try {\r
- // For local execution use relavive\r
- ConfiguredExecutable<ClustalO> confClustal = Configurator.configureExecutable(clustal, Executable.ExecProvider.Local);\r
- LocalRunner lr = new LocalRunner(confClustal);\r
- lr.executeJob();\r
- confClustal = (ConfiguredExecutable<ClustalO>) lr.waitForResult();\r
- assertNotNull(confClustal.getResults());\r
- } catch (JobSubmissionException e) {\r
- e.printStackTrace();\r
- fail(e.getLocalizedMessage());\r
- } catch (JobExecutionException e) {\r
- e.printStackTrace();\r
- fail(e.getLocalizedMessage());\r
- } catch (ResultNotAvailableException e) {\r
- e.printStackTrace();\r
- fail(e.getLocalizedMessage());\r
- }\r
- }\r
-\r
- @Test(groups = {AllTestSuit.test_group_runner})\r
- public void ConfigurationLoading() {\r
- try {\r
- RunnerConfig<ClustalO> clustalConfig = ConfExecutable.getRunnerOptions(ClustalO.class);\r
- assertNotNull(clustalConfig);\r
- assertTrue(clustalConfig.getArguments().size() > 0);\r
-\r
- LimitsManager<ClustalO> clustalLimits = ConfExecutable.getRunnerLimits(ClustalO.class);\r
- assertNotNull(clustalLimits);\r
- assertTrue(clustalLimits.getLimits().size() > 0);\r
- } catch (FileNotFoundException e) {\r
- e.printStackTrace();\r
- fail(e.getLocalizedMessage());\r
- } catch (IOException e) {\r
- e.printStackTrace();\r
- fail(e.getLocalizedMessage());\r
- }\r
- }\r
-\r
- @Test(groups = {AllTestSuit.test_group_runner})\r
- public void OptionsLocally() {\r
- try {\r
- RunnerConfigMarshaller<ClustalO> clustalmarsh = new RunnerConfigMarshaller<ClustalO>(RunnerConfig.class);\r
- RunnerConfig<ClustalO> clustalConfig = clustalmarsh.read(new FileInputStream(new File(clustalConfigFile)), RunnerConfig.class);\r
-\r
- OptionCombinator clustalOpc = new OptionCombinator(clustalConfig);\r
- List<String> options = clustalOpc.getOptionsAtRandom();\r
- for (int i = 0; i < options.size(); i++) {\r
- System.out.println("Using options: " + options);\r
- ClustalO clustal = new ClustalO();\r
- clustal.setInput(AllTestSuit.test_input);\r
- clustal.setOutput(test_outfile);\r
-\r
- // For local execution use relavive\r
- ConfiguredExecutable<ClustalO> confClustal = Configurator.configureExecutable(clustal, ExecProvider.Local);\r
-\r
- // Add options to the executable\r
- confClustal.addParameters(options);\r
-\r
- LocalRunner lr = new LocalRunner(confClustal);\r
- lr.executeJob();\r
- confClustal = (ConfiguredExecutable<ClustalO>) lr.waitForResult();\r
- assertNotNull(confClustal.getResults());\r
- Collections.shuffle(options);\r
- }\r
-\r
- } catch (JobSubmissionException e) {\r
- e.printStackTrace();\r
- fail(e.getLocalizedMessage());\r
- } catch (JobExecutionException e) {\r
- e.printStackTrace();\r
- fail(e.getLocalizedMessage());\r
- } catch (JAXBException e) {\r
- e.printStackTrace();\r
- fail(e.getLocalizedMessage());\r
- } catch (ResultNotAvailableException e) {\r
- e.printStackTrace();\r
- fail(e.getLocalizedMessage());\r
- } catch (FileNotFoundException e) {\r
- e.printStackTrace();\r
- fail(e.getLocalizedMessage());\r
- }\r
- }\r
-\r
- public static final void main(String[] args)\r
- throws JobSubmissionException, JobExecutionException, InterruptedException {\r
- ClustalO clustal = new ClustalO();\r
- clustal.setInput(AllTestSuit.test_input).setOutput(test_outfile);\r
- // For local execution use relavive\r
- ConfiguredExecutable<ClustalO> confClustal = Configurator.configureExecutable(clustal);\r
- AsyncExecutor lr = new AsyncLocalRunner();\r
- lr.submitJob(confClustal);\r
- Thread.sleep(3000);\r
- LocalExecutorService.shutDown();\r
- }\r
-\r
- @Test(groups = {AllTestSuit.test_group_runner})\r
- public void Persistance() {\r
- try {\r
- ClustalO clustal = new ClustalO();\r
- clustal.setError("errrr.txt");\r
- clustal.setInput(AllTestSuit.test_input);\r
- clustal.setOutput("outtt.txt");\r
- assertEquals(clustal.getInput(), AllTestSuit.test_input);\r
- assertEquals(clustal.getError(), "errrr.txt");\r
- assertEquals(clustal.getOutput(), "outtt.txt");\r
- ConfiguredExecutable<ClustalO> cClustal = Configurator.configureExecutable(clustal, Executable.ExecProvider.Local);\r
-\r
- SyncExecutor sexec = Configurator.getSyncEngine(cClustal);\r
- sexec.executeJob();\r
- cClustal = (ConfiguredExecutable<ClustalO>) sexec.waitForResult();\r
- assertNotNull(cClustal.getResults());\r
- // Save run configuration\r
- assertTrue(cClustal.saveRunConfiguration());\r
-\r
- // See if loaded configuration is the same as saved\r
- RunConfiguration loadedRun = RunConfiguration.load(new FileInputStream(new File(cClustal.getWorkDirectory(), RunConfiguration.rconfigFile)));\r
- assertTrue(((ConfExecutable<ClustalO>) cClustal)\r
- .getRunConfiguration().equals(loadedRun));\r
- // Load run configuration as ConfExecutable\r
- ConfiguredExecutable<ClustalO> resurrectedCclustal = (ConfiguredExecutable<ClustalO>) cClustal\r
- .loadRunConfiguration(new FileInputStream(new File(cClustal\r
- .getWorkDirectory(), RunConfiguration.rconfigFile)));\r
- assertNotNull(resurrectedCclustal);\r
- // See in details whether executables are the same\r
- assertEquals(resurrectedCclustal.getExecutable(), clustal);\r
-\r
- // Finally rerun the job in the new task directory\r
- ConfiguredExecutable<ClustalO> resclustal = Configurator\r
- .configureExecutable(resurrectedCclustal.getExecutable(),\r
- Executable.ExecProvider.Local);\r
-\r
- sexec = Configurator.getSyncEngine(resclustal, Executable.ExecProvider.Local);\r
- sexec.executeJob();\r
- cClustal = (ConfiguredExecutable<ClustalO>) sexec.waitForResult();\r
- assertNotNull(cClustal.getResults());\r
-\r
- } catch (JobSubmissionException e) {\r
- e.printStackTrace();\r
- fail(e.getMessage());\r
- } catch (JobExecutionException e) {\r
- e.printStackTrace();\r
- fail(e.getMessage());\r
- } catch (FileNotFoundException e) {\r
- e.printStackTrace();\r
- fail(e.getMessage());\r
- } catch (IOException e) {\r
- e.printStackTrace();\r
- fail(e.getMessage());\r
- } catch (ResultNotAvailableException e) {\r
- e.printStackTrace();\r
- fail(e.getMessage());\r
- }\r
- }\r
-\r
- @Test(groups = {AllTestSuit.test_group_runner})\r
- public void readStatistics()\r
- throws InterruptedException {\r
- try {\r
- ClustalO al = new ClustalO();\r
- al.setInput(AllTestSuit.test_input);\r
- al.setOutput(test_outfile);\r
- ConfiguredExecutable<ClustalO> confal = Configurator.configureExecutable(al, Executable.ExecProvider.Local);\r
-\r
- AsyncExecutor sexec = Configurator.getAsyncEngine(confal);\r
- String jobId = sexec.submitJob(confal);\r
- String file = EngineUtil.getFullPath(confal.getWorkDirectory(), ClustalW.getStatFile());\r
- FilePuller fw = FilePuller.newFilePuller(file, FileWatcher.MIN_CHUNK_SIZE_BYTES);\r
- int count = 0;\r
- long position = 0;\r
- fw.waitForFile(4);\r
- JobStatus status = sexec.getJobStatus(jobId);\r
- while (status != JobStatus.FINISHED || fw.hasMoreData()) {\r
- if (fw.hasMoreData()) {\r
- ChunkHolder ch = fw.pull(position);\r
- String chunk = ch.getChunk();\r
- position = ch.getNextPosition();\r
- }\r
- count++;\r
- if ((status == JobStatus.UNDEFINED || status == JobStatus.FAILED)) {\r
- fail("job " + jobId +" failed!");\r
- break;\r
- }\r
- Thread.sleep(200);\r
- status = sexec.getJobStatus(jobId);\r
- System.out.println("CLustalO: Job status = " + status + ", file status = " + fw.hasMoreData());\r
- }\r
- assertTrue(count > 1);\r
- ConfiguredExecutable<?> al2 = sexec.getResults(jobId);\r
- assertNotNull(al2.getResults());\r
- } catch (JobSubmissionException e) {\r
- e.printStackTrace();\r
- fail(e.getMessage());\r
- } catch (ResultNotAvailableException e) {\r
- e.printStackTrace();\r
- fail(e.getMessage());\r
- } catch (IOException e) {\r
- e.printStackTrace();\r
- fail(e.getMessage());\r
- }\r
- }\r
-\r
- @Test(groups = {AllTestSuit.test_group_cluster, AllTestSuit.test_group_runner})\r
- public void RunOnCluster() {\r
- ClustalO clustal = new ClustalO();\r
- assertFalse(SysPrefs.isWindows, "Cluster execution can only be in unix environment");\r
- clustal.setInput(AllTestSuit.test_input).setOutput(cluster_test_outfile);\r
- try {\r
- ConfiguredExecutable<ClustalO> confClustal = Configurator.configureExecutable(clustal);\r
- ClusterRunner runner = ClusterRunner.getInstance(confClustal);\r
- // ClusterSession csession = JobRunner.getSession();\r
- assertNotNull(runner);\r
- runner.executeJob();\r
- // assertNotNull("JobId is null", jobId1);\r
- JobStatus status = runner.getJobStatus();\r
- assertTrue(status == JobStatus.PENDING || status == JobStatus.RUNNING);\r
- JobInfo info = runner.getJobInfo();\r
- assertNotNull(info);\r
- StatisticManager sm = new StatisticManager(info);\r
- assertNotNull(sm);\r
- try {\r
- String exits = sm.getExitStatus();\r
- assertNotNull("Exit status is null", exits);\r
- // cut 4 trailing zeros from the number\r
- int exitsInt = ClusterEngineUtil.CLUSTER_STAT_IN_SEC.parse(exits).intValue();\r
- assertEquals(0, exitsInt);\r
- System.out.println(sm.getAllStats());\r
- } catch (ParseException e) {\r
- e.printStackTrace();\r
- fail("Parse Exception: " + e.getMessage());\r
- }\r
- // At present the task directory could not be completely removed\r
- // @see JobRunner.cleanup()\r
- assertFalse(runner.cleanup(), "Could not remove some files whilst cleaning up ");\r
- assertTrue(sm.hasExited());\r
- assertFalse(sm.wasAborted());\r
- assertFalse(sm.hasDump());\r
- assertFalse(sm.hasSignaled());\r
- } catch (JobSubmissionException e) {\r
- e.printStackTrace();\r
- fail("DrmaaException caught:" + e.getMessage());\r
- } catch (JobExecutionException e) {\r
- e.printStackTrace();\r
- fail("DrmaaException caught:" + e.getMessage());\r
- } catch (DrmaaException e) {\r
- e.printStackTrace();\r
- fail("DrmaaException caught:" + e.getMessage());\r
- }\r
- }\r
-\r
- @Test(groups = {AllTestSuit.test_group_cluster, AllTestSuit.test_group_runner})\r
- public void readStatisticsClusterExecution() {\r
- try {\r
- ClustalO clustal = new ClustalO().setInput(AllTestSuit.test_input).setOutput(test_outfile);\r
- ConfiguredExecutable<ClustalO> confClustal = Configurator.configureExecutable(clustal, Executable.ExecProvider.Cluster);\r
-\r
- AsyncExecutor sexec = Configurator.getAsyncEngine(confClustal);\r
- String jobId = sexec.submitJob(confClustal);\r
- String file = EngineUtil.getFullPath(confClustal.getWorkDirectory(), ClustalW.getStatFile());\r
- FilePuller fw = FilePuller.newFilePuller(file, FileWatcher.MIN_CHUNK_SIZE_BYTES);\r
- int count = 0;\r
- long position = 0;\r
- int maxloopcount = 108000; // max waiting time = 6h*60m*60s/0.2(one loop sleep)\r
- fw.waitForFile(200);\r
- /*\r
- * Under certain circumstances DRMAA could report the status wrongly\r
- * thus this loop never ends. maxloopcount ensures hard stop of the loop...\r
- */\r
- while (!( sexec.getJobStatus(jobId) == JobStatus.FINISHED || sexec.getJobStatus(jobId) == JobStatus.FAILED) \r
- || count < maxloopcount || fw.hasMoreData()) {\r
- ChunkHolder ch = fw.pull(position);\r
- String chunk = ch.getChunk();\r
- position = ch.getNextPosition();\r
- System.out.print(chunk);\r
- count++;\r
- Thread.sleep(200);\r
- if (sexec.getJobStatus(jobId) == JobStatus.UNDEFINED) {\r
- System.out.println("DRMAA reported wrong status for job + " + jobId + " continue anyway!");\r
- break;\r
- }\r
- }\r
- assertTrue(count > 1);\r
- ConfiguredExecutable<?> al = sexec.getResults(jobId);\r
- assertNotNull(al.getResults());\r
- } catch (JobSubmissionException e) {\r
- e.printStackTrace();\r
- fail(e.getMessage());\r
- } catch (ResultNotAvailableException e) {\r
- e.printStackTrace();\r
- fail(e.getMessage());\r
- } catch (IOException e) {\r
- e.printStackTrace();\r
- fail(e.getMessage());\r
- } catch (InterruptedException e) {\r
- e.printStackTrace();\r
- fail(e.getMessage());\r
- }\r
- }\r
-}\r