use of org.opencastproject.job.api.JobBarrier.Result in project opencast by opencast.
the class ExecuteOnceWorkflowOperationHandlerTest method setUp.
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
// Mocking just about everything, just testing the mediapackage parse
String expectedTypeString = "catalog";
String catalogId = "catalog-id";
URI catUri = new URI("http://api.com/catalog");
catalog = CatalogImpl.newInstance();
catalog.addTag("engage-download");
catalog.setIdentifier(catalogId);
catalog.setURI(catUri);
WorkflowOperationInstance operation = EasyMock.createMock(WorkflowOperationInstance.class);
EasyMock.expect(operation.getId()).andReturn(123L).anyTimes();
EasyMock.expect(operation.getConfiguration(ExecuteOnceWorkflowOperationHandler.EXEC_PROPERTY)).andReturn(null).anyTimes();
EasyMock.expect(operation.getConfiguration(ExecuteOnceWorkflowOperationHandler.PARAMS_PROPERTY)).andReturn(null).anyTimes();
EasyMock.expect(operation.getConfiguration(ExecuteOnceWorkflowOperationHandler.LOAD_PROPERTY)).andReturn("123").anyTimes();
EasyMock.expect(operation.getConfiguration(ExecuteOnceWorkflowOperationHandler.TARGET_FLAVOR_PROPERTY)).andReturn(null).anyTimes();
EasyMock.expect(operation.getConfiguration(ExecuteOnceWorkflowOperationHandler.TARGET_TAGS_PROPERTY)).andReturn(null).anyTimes();
EasyMock.expect(operation.getConfiguration(ExecuteOnceWorkflowOperationHandler.OUTPUT_FILENAME_PROPERTY)).andReturn(null).anyTimes();
EasyMock.expect(operation.getConfiguration(ExecuteOnceWorkflowOperationHandler.SET_WF_PROPS_PROPERTY)).andReturn("false").anyTimes();
// these two need to supply a real string
EasyMock.expect(operation.getConfiguration(ExecuteOnceWorkflowOperationHandler.EXPECTED_TYPE_PROPERTY)).andReturn(expectedTypeString).anyTimes();
EasyMock.replay(operation);
Id mpId = EasyMock.createMock(Id.class);
MediaPackage mediaPackage = EasyMock.createMock(MediaPackage.class);
mediaPackage.add((MediaPackageElement) EasyMock.anyObject());
EasyMock.expect(mediaPackage.getIdentifier()).andReturn(mpId).anyTimes();
EasyMock.replay(mediaPackage);
workspaceService = EasyMock.createMock(Workspace.class);
EasyMock.expect(workspaceService.moveTo((URI) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject())).andReturn(catUri).anyTimes();
EasyMock.replay(workspaceService);
workflowInstance = EasyMock.createMock(WorkflowInstance.class);
EasyMock.expect(workflowInstance.getMediaPackage()).andReturn(mediaPackage).anyTimes();
EasyMock.expect(workflowInstance.getCurrentOperation()).andStubReturn(operation);
EasyMock.replay(workflowInstance);
// Override the waitForStatus method to not block the jobs
execOnceWOH = new ExecuteOnceWorkflowOperationHandler() {
@Override
protected Result waitForStatus(long timeout, Job... jobs) {
HashMap<Job, Status> map = Stream.mk(jobs).foldl(new HashMap<Job, Status>(), new Fn2<HashMap<Job, Status>, Job, HashMap<Job, Status>>() {
@Override
public HashMap<Job, Status> apply(HashMap<Job, Status> a, Job b) {
a.put(b, Status.FINISHED);
return a;
}
});
return new Result(map);
}
};
execOnceWOH.setWorkspace(workspaceService);
}
use of org.opencastproject.job.api.JobBarrier.Result in project opencast by opencast.
the class SeriesUpdatedEventHandler method updateEpisodeCatalog.
private boolean updateEpisodeCatalog(MediaPackage mp) throws DistributionException, MediaPackageException, NotFoundException, ServiceRegistryException, IllegalArgumentException, IOException {
// Update the episode catalog
for (Catalog episodeCatalog : mp.getCatalogs(MediaPackageElements.EPISODE)) {
DublinCoreCatalog episodeDublinCore = DublinCoreUtil.loadDublinCore(workspace, episodeCatalog);
episodeDublinCore.remove(DublinCore.PROPERTY_IS_PART_OF);
String filename = FilenameUtils.getName(episodeCatalog.getURI().toString());
URI uri = workspace.put(mp.getIdentifier().toString(), episodeCatalog.getIdentifier(), filename, dublinCoreService.serialize(episodeDublinCore));
episodeCatalog.setURI(uri);
// setting the URI to a new source so the checksum will most like be invalid
episodeCatalog.setChecksum(null);
// Distribute the updated episode dublincore
Job distributionJob = distributionService.distribute(CHANNEL_ID, mp, episodeCatalog.getIdentifier());
JobBarrier barrier = new JobBarrier(null, serviceRegistry, distributionJob);
Result jobResult = barrier.waitForJobs();
if (jobResult.getStatus().get(distributionJob).equals(FINISHED)) {
mp.remove(episodeCatalog);
mp.add(getFromXml(serviceRegistry.getJob(distributionJob.getId()).getPayload()));
} else {
logger.error("Unable to distribute episode catalog {}", episodeCatalog.getIdentifier());
return false;
}
}
return true;
}
Aggregations