Skip to content

Commit cb082aa

Browse files
authored
Fix Task registration and expand test cases (#7268)
1 parent 4aab49c commit cb082aa

1 file changed

Lines changed: 71 additions & 26 deletions

File tree

experiment/src/org/labkey/experiment/pipeline/XarTestPipelineJob.java

Lines changed: 71 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212
import org.labkey.api.data.SimpleFilter;
1313
import org.labkey.api.data.TableInfo;
1414
import org.labkey.api.data.TableSelector;
15+
import org.labkey.api.data.WorkbookContainerType;
1516
import org.labkey.api.exp.api.ExpData;
1617
import org.labkey.api.exp.api.ExpRun;
1718
import org.labkey.api.exp.api.ExperimentService;
18-
import org.labkey.api.exp.pipeline.XarGeneratorFactorySettings;
19+
import org.labkey.api.exp.pipeline.XarGeneratorId;
1920
import org.labkey.api.module.Module;
2021
import org.labkey.api.module.ModuleLoader;
2122
import org.labkey.api.pipeline.AbstractTaskFactory;
@@ -174,20 +175,24 @@ private static TaskId getTaskFactoryId(String location)
174175
return new TaskId(XarTestTaskFactory.class, location);
175176
}
176177

177-
public static TaskId registerTaskPipeline(String location) throws CloneNotSupportedException
178+
public static void registerTaskPipeline(String location) throws CloneNotSupportedException
178179
{
179180
//first register TaskFactory
180181
TaskId taskFactoryId = getTaskFactoryId(location);
181182
PipelineJobService.get().addTaskFactory(new XarTestTaskFactory(taskFactoryId, location));
182183

183184
//then TaskPipeline
184185
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+
185192
TaskPipelineSettings settings = new TaskPipelineSettings(taskPipelineId);
186-
settings.setTaskProgressionSpec(new Object[]{taskFactoryId, getXarGenerator().getId()});
193+
settings.setTaskProgressionSpec(new Object[]{taskFactoryId, xarFact.getId()});
187194
settings.setDeclaringModule(ModuleLoader.getInstance().getModule(ExperimentModule.class));
188195
PipelineJobService.get().addTaskPipeline(settings);
189-
190-
return taskPipelineId;
191196
}
192197

193198
@Override
@@ -273,20 +278,6 @@ public boolean isJobComplete(PipelineJob job)
273278
}
274279
}
275280

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-
290281
@Override
291282
public String getProtocolName()
292283
{
@@ -428,22 +419,76 @@ public void xarTest() throws Exception
428419
Arrays.asList(new File("/arbitrary/path/outside/lkRoot/myFile.txt")),
429420
Arrays.asList(new File("/another/arbitrary/path/outside/lkRoot/myFile.txt"))
430421
);
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+
);
431470
}
432471

433472
@Test
434473
public void xarTestRelativePaths() throws Exception
435474
{
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+
//});
442483
}
443484

444485
private void doXarTest(String jobName, List<File> inputFiles, List<File> outputFiles) throws Exception
445486
{
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+
{
447492
PipelineJob job1 = XarTestPipelineJob.createJob(c, TestContext.get().getUser(), jobName, inputFiles, outputFiles);
448493
PipelineService.get().queueJob(job1);
449494
long start = System.currentTimeMillis();

0 commit comments

Comments
 (0)