|
12 | 12 | import org.labkey.api.data.SimpleFilter; |
13 | 13 | import org.labkey.api.data.TableInfo; |
14 | 14 | import org.labkey.api.data.TableSelector; |
| 15 | +import org.labkey.api.data.WorkbookContainerType; |
15 | 16 | import org.labkey.api.exp.api.ExpData; |
16 | 17 | import org.labkey.api.exp.api.ExpRun; |
17 | 18 | import org.labkey.api.exp.api.ExperimentService; |
18 | | -import org.labkey.api.exp.pipeline.XarGeneratorFactorySettings; |
| 19 | +import org.labkey.api.exp.pipeline.XarGeneratorId; |
19 | 20 | import org.labkey.api.module.Module; |
20 | 21 | import org.labkey.api.module.ModuleLoader; |
21 | 22 | import org.labkey.api.pipeline.AbstractTaskFactory; |
@@ -174,20 +175,24 @@ private static TaskId getTaskFactoryId(String location) |
174 | 175 | return new TaskId(XarTestTaskFactory.class, location); |
175 | 176 | } |
176 | 177 |
|
177 | | - public static TaskId registerTaskPipeline(String location) throws CloneNotSupportedException |
| 178 | + public static void registerTaskPipeline(String location) throws CloneNotSupportedException |
178 | 179 | { |
179 | 180 | //first register TaskFactory |
180 | 181 | TaskId taskFactoryId = getTaskFactoryId(location); |
181 | 182 | PipelineJobService.get().addTaskFactory(new XarTestTaskFactory(taskFactoryId, location)); |
182 | 183 |
|
183 | 184 | //then TaskPipeline |
184 | 185 | TaskId taskPipelineId = getTaskIdForEngine(location); |
| 186 | + TaskFactory<?> xarFact = PipelineJobService.get().getTaskFactory(new TaskId(XarGeneratorId.class)); |
| 187 | + if (xarFact == null) |
| 188 | + { |
| 189 | + throw new IllegalStateException("Unable to find TaskFactory for XarGeneratorId.class"); |
| 190 | + } |
| 191 | + |
185 | 192 | TaskPipelineSettings settings = new TaskPipelineSettings(taskPipelineId); |
186 | | - settings.setTaskProgressionSpec(new Object[]{taskFactoryId, getXarGenerator().getId()}); |
| 193 | + settings.setTaskProgressionSpec(new Object[]{taskFactoryId, xarFact.getId()}); |
187 | 194 | settings.setDeclaringModule(ModuleLoader.getInstance().getModule(ExperimentModule.class)); |
188 | 195 | PipelineJobService.get().addTaskPipeline(settings); |
189 | | - |
190 | | - return taskPipelineId; |
191 | 196 | } |
192 | 197 |
|
193 | 198 | @Override |
@@ -273,20 +278,6 @@ public boolean isJobComplete(PipelineJob job) |
273 | 278 | } |
274 | 279 | } |
275 | 280 |
|
276 | | - protected static XarGeneratorFactorySettings getXarGenerator() throws CloneNotSupportedException |
277 | | - { |
278 | | - XarGeneratorFactorySettings settings = new XarGeneratorFactorySettings("xarGeneratorJoin"); |
279 | | - settings.setJoin(true); |
280 | | - |
281 | | - TaskFactory<?> factory = PipelineJobService.get().getTaskFactory(settings.getCloneId()); |
282 | | - if (factory == null) |
283 | | - { |
284 | | - PipelineJobService.get().addTaskFactory(settings); |
285 | | - } |
286 | | - |
287 | | - return settings; |
288 | | - } |
289 | | - |
290 | 281 | @Override |
291 | 282 | public String getProtocolName() |
292 | 283 | { |
@@ -428,22 +419,76 @@ public void xarTest() throws Exception |
428 | 419 | Arrays.asList(new File("/arbitrary/path/outside/lkRoot/myFile.txt")), |
429 | 420 | Arrays.asList(new File("/another/arbitrary/path/outside/lkRoot/myFile.txt")) |
430 | 421 | ); |
| 422 | + |
| 423 | + Container project = ContainerManager.getForPath(PROJECT_NAME); |
| 424 | + PipeRoot projectRoot = PipelineService.get().getPipelineRootSetting(project); |
| 425 | + Assert.assertNotNull(PROJECT_NAME + " pipeline root is null", projectRoot); |
| 426 | + |
| 427 | + // We expect /Shared to be an allowable output location: |
| 428 | + PipeRoot sharedRoot = PipelineService.get().getPipelineRootSetting(ContainerManager.getSharedContainer()); |
| 429 | + Assert.assertNotNull("Shared pipeline root is null", sharedRoot); |
| 430 | + |
| 431 | + // A pipeline job submitted to a project/folder should be able to access files in /Shared |
| 432 | + doXarTest( |
| 433 | + "XarTestJob_UsingShared", |
| 434 | + Arrays.asList( |
| 435 | + FileUtil.appendPath(projectRoot.getRootFileLike(), org.labkey.api.util.Path.parse("myFileInJobFolder.txt")).toNioPathForWrite().toFile(), |
| 436 | + FileUtil.appendPath(sharedRoot.getRootFileLike(), org.labkey.api.util.Path.parse("myFileInSharedFolder.txt")).toNioPathForWrite().toFile() |
| 437 | + ), |
| 438 | + Arrays.asList( |
| 439 | + FileUtil.appendPath(projectRoot.getRootFileLike(), org.labkey.api.util.Path.parse("myOutputFileInJobFolder.txt")).toNioPathForWrite().toFile(), |
| 440 | + FileUtil.appendPath(sharedRoot.getRootFileLike(), org.labkey.api.util.Path.parse("myOutputFileInSharedFolder.txt")).toNioPathForWrite().toFile() |
| 441 | + ) |
| 442 | + ); |
| 443 | + |
| 444 | + // Now create workbooks in this folder: |
| 445 | + Container wb1 = ContainerManager.createContainer(project, null, "WB1", null, WorkbookContainerType.NAME, TestContext.get().getUser()); |
| 446 | + Container wb2 = ContainerManager.createContainer(project, null, "WB2", null, WorkbookContainerType.NAME, TestContext.get().getUser()); |
| 447 | + |
| 448 | + PipeRoot wb1Root = PipelineService.get().getPipelineRootSetting(wb1); |
| 449 | + Assert.assertNotNull("wb1Root is null", wb1Root); |
| 450 | + PipeRoot wb2Root = PipelineService.get().getPipelineRootSetting(wb2); |
| 451 | + Assert.assertNotNull("wb2Root is null", wb2Root); |
| 452 | + |
| 453 | + // A pipeline job submitted to a workbook should be able to reference files in /Shared, the parent folder, or sibling workbooks: |
| 454 | + doXarTest( |
| 455 | + "XarTestJob_AcrossWorkbooks", |
| 456 | + Arrays.asList( |
| 457 | + FileUtil.appendPath(projectRoot.getRootFileLike(), org.labkey.api.util.Path.parse("myFileInJobFolder.txt")).toNioPathForWrite().toFile(), |
| 458 | + FileUtil.appendPath(sharedRoot.getRootFileLike(), org.labkey.api.util.Path.parse("myFileInSharedFolder.txt")).toNioPathForWrite().toFile(), |
| 459 | + FileUtil.appendPath(wb1Root.getRootFileLike(), org.labkey.api.util.Path.parse("myFileInWB1Folder.txt")).toNioPathForWrite().toFile(), |
| 460 | + FileUtil.appendPath(wb2Root.getRootFileLike(), org.labkey.api.util.Path.parse("myFileInWB2Folder.txt")).toNioPathForWrite().toFile() |
| 461 | + ), |
| 462 | + Arrays.asList( |
| 463 | + FileUtil.appendPath(projectRoot.getRootFileLike(), org.labkey.api.util.Path.parse("myOutputFileInJobFolder.txt")).toNioPathForWrite().toFile(), |
| 464 | + FileUtil.appendPath(sharedRoot.getRootFileLike(), org.labkey.api.util.Path.parse("myOutputFileInSharedFolder.txt")).toNioPathForWrite().toFile(), |
| 465 | + FileUtil.appendPath(wb1Root.getRootFileLike(), org.labkey.api.util.Path.parse("myOutputFileInWB1Folder.txt")).toNioPathForWrite().toFile(), |
| 466 | + FileUtil.appendPath(wb2Root.getRootFileLike(), org.labkey.api.util.Path.parse("myOutputFileInWB2Folder.txt")).toNioPathForWrite().toFile() |
| 467 | + ), |
| 468 | + wb2 |
| 469 | + ); |
431 | 470 | } |
432 | 471 |
|
433 | 472 | @Test |
434 | 473 | public void xarTestRelativePaths() throws Exception |
435 | 474 | { |
436 | | - // NOTE: these will get converted to absolute paths by the pipeline code when they are saved: |
437 | | - doXarTest( |
438 | | - "XarTestJob_QuestionablePaths", |
439 | | - Arrays.asList(new File("../../../root/myFile.txt")), |
440 | | - Arrays.asList(new File("../../../users/root/anotherFile.txt")) |
441 | | - ); |
| 475 | + // NOTE: these will get converted to absolute paths by the pipeline code when they are saved, so this passes right now: |
| 476 | + //Assert.assertThrows("Maybe LabKey shouldn't allow this", Exception.class, () -> { |
| 477 | + doXarTest( |
| 478 | + "XarTestJob_QuestionablePaths", |
| 479 | + Arrays.asList(new File("../../../root/myFile.txt")), |
| 480 | + Arrays.asList(new File("../../../users/root/anotherFile.txt")) |
| 481 | + ); |
| 482 | + //}); |
442 | 483 | } |
443 | 484 |
|
444 | 485 | private void doXarTest(String jobName, List<File> inputFiles, List<File> outputFiles) throws Exception |
445 | 486 | { |
446 | | - Container c = ContainerManager.getForPath(PROJECT_NAME); |
| 487 | + doXarTest(jobName, inputFiles, outputFiles, ContainerManager.getForPath(PROJECT_NAME)); |
| 488 | + } |
| 489 | + |
| 490 | + private void doXarTest(String jobName, List<File> inputFiles, List<File> outputFiles, Container c) throws Exception |
| 491 | + { |
447 | 492 | PipelineJob job1 = XarTestPipelineJob.createJob(c, TestContext.get().getUser(), jobName, inputFiles, outputFiles); |
448 | 493 | PipelineService.get().queueJob(job1); |
449 | 494 | long start = System.currentTimeMillis(); |
|
0 commit comments