use of org.opencastproject.assetmanager.api.Snapshot in project opencast by opencast.
the class AbstractAssetManager method takeSnapshot.
@Override
public Snapshot takeSnapshot(MediaPackage mediaPackage) {
final String mediaPackageId = mediaPackage.getIdentifier().toString();
AQueryBuilder queryBuilder = createQuery();
AResult result = queryBuilder.select(queryBuilder.snapshot()).where(queryBuilder.mediaPackageId(mediaPackageId).and(queryBuilder.version().isLatest())).run();
Opt<ARecord> record = result.getRecords().head();
if (record.isSome()) {
Opt<Snapshot> snapshot = record.get().getSnapshot();
if (snapshot.isSome()) {
return takeSnapshot(snapshot.get().getOwner(), mediaPackage);
}
}
return takeSnapshot(DEFAULT_OWNER, mediaPackage);
}
use of org.opencastproject.assetmanager.api.Snapshot in project opencast by opencast.
the class AssetManagerWithMessaging method takeSnapshot.
@Override
public Snapshot takeSnapshot(String owner, MediaPackage mp) {
final Snapshot snapshot = super.takeSnapshot(owner, mp);
notifyTakeSnapshot(snapshot);
return snapshot;
}
use of org.opencastproject.assetmanager.api.Snapshot in project opencast by opencast.
the class LiveScheduleServiceImplTest method testCreateLiveEvent.
@Test
public void testCreateLiveEvent() throws Exception {
URI mpURI = LiveScheduleServiceImplTest.class.getResource("/assetmanager-mp.xml").toURI();
MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().loadFromXml(mpURI.toURL().openStream());
setUpAssetManager(mp);
URI catalogURI = LiveScheduleServiceImplTest.class.getResource("/episode.xml").toURI();
DublinCoreCatalog episodeDC = DublinCores.read(catalogURI.toURL().openStream());
catalogURI = LiveScheduleServiceImplTest.class.getResource("/series.xml").toURI();
DublinCoreCatalog seriesDC = DublinCores.read(catalogURI.toURL().openStream());
EasyMock.expect(seriesService.getSeries(SERIES_ID)).andReturn(seriesDC).anyTimes();
Job job = createJob(1L, "anything", "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<catalog id=\"9ad6ebcb-b414-4b15-ab62-5e5ddede447e\" type=\"dublincore/episode\" xmlns=\"http://mediapackage.opencastproject.org\">" + "<mimetype>text/xml</mimetype>" + "<url>http://10.10.10.50/static/mh_default_org/engage-live/episode.xml</url></catalog>" + "###<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<catalog id=\"23113662-1a84-457a-85d5-0b3e32d2413a\" type=\"dublincore/series\" xmlns=\"http://mediapackage.opencastproject.org\">" + "<mimetype>text/xml</mimetype>" + "<url>http://10.10.10.50/static/mh_default_org/engage-live/series.xml</url></catalog>" + "###<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<attachment id=\"security-policy-episode\" type=\"security/xacml+episode\" xmlns=\"http://mediapackage.opencastproject.org\">" + "<mimetype>text/xml</mimetype>" + "<url>http://10.10.10.50/static/mh_default_org/engage-live/security_policy_episode.xml</url></attachment>");
EasyMock.expect(downloadDistributionService.distribute(EasyMock.anyString(), EasyMock.anyObject(MediaPackage.class), EasyMock.anyObject(Set.class), EasyMock.anyBoolean())).andReturn(job);
EasyMock.expect(serviceRegistry.getJob(1L)).andReturn(job).anyTimes();
Job jobPub = createJob(2L, "anything", "anything");
Capture<MediaPackage> capturedMp = Capture.newInstance();
EasyMock.expect(searchService.add(EasyMock.capture(capturedMp))).andReturn(jobPub);
EasyMock.expect(serviceRegistry.getJob(2L)).andReturn(job).anyTimes();
Capture<MediaPackage> capturedSnapshotMp = Capture.newInstance();
Version v = EasyMock.createNiceMock(Version.class);
Snapshot s = EasyMock.createNiceMock(Snapshot.class);
EasyMock.expect(s.getVersion()).andReturn(v);
EasyMock.replay(s, v);
EasyMock.expect(assetManager.takeSnapshot(EasyMock.capture(capturedSnapshotMp))).andReturn(s);
replayServices();
service.setDownloadDistributionService(downloadDistributionService);
service.createLiveEvent(MP_ID, episodeDC);
// Check published live media package
MediaPackage searchMp = capturedMp.getValue();
Assert.assertEquals(MP_ID, searchMp.getIdentifier().compact());
Assert.assertEquals(DURATION, searchMp.getDuration().longValue());
Assert.assertEquals(2, searchMp.getCatalogs().length);
assertExpectedLiveTracks(searchMp.getTracks(), DURATION, CAPTURE_AGENT_NAME, "_suffix", false);
// Check archived media package
MediaPackage archivedMp = capturedSnapshotMp.getValue();
Assert.assertEquals(MP_ID, archivedMp.getIdentifier().compact());
Assert.assertEquals(1, archivedMp.getPublications().length);
Assert.assertEquals(LiveScheduleService.CHANNEL_ID, archivedMp.getPublications()[0].getChannel());
// Check that version got into local cache
Assert.assertEquals(v, service.getSnapshotVersionCache().getIfPresent(MP_ID));
}
use of org.opencastproject.assetmanager.api.Snapshot in project opencast by opencast.
the class LiveScheduleServiceImplTest method setUpAssetManager.
private void setUpAssetManager(MediaPackage mp) {
version = EasyMock.createNiceMock(Version.class);
snapshot = EasyMock.createNiceMock(Snapshot.class);
EasyMock.expect(snapshot.getMediaPackage()).andReturn(mp).anyTimes();
EasyMock.expect(snapshot.getOrganizationId()).andReturn(org.getId()).anyTimes();
EasyMock.expect(snapshot.getVersion()).andReturn(version);
ARecord aRec = EasyMock.createNiceMock(ARecord.class);
EasyMock.expect(aRec.getSnapshot()).andReturn(Opt.some(snapshot)).anyTimes();
Stream<ARecord> recStream = Stream.mk(aRec);
Predicate p = EasyMock.createNiceMock(Predicate.class);
EasyMock.expect(p.and(p)).andReturn(p).anyTimes();
AResult r = EasyMock.createNiceMock(AResult.class);
EasyMock.expect(r.getSize()).andReturn(1L).anyTimes();
EasyMock.expect(r.getRecords()).andReturn(recStream).anyTimes();
Target t = EasyMock.createNiceMock(Target.class);
ASelectQuery selectQuery = EasyMock.createNiceMock(ASelectQuery.class);
EasyMock.expect(selectQuery.where(EasyMock.anyObject(Predicate.class))).andReturn(selectQuery).anyTimes();
EasyMock.expect(selectQuery.run()).andReturn(r).anyTimes();
AQueryBuilder query = EasyMock.createNiceMock(AQueryBuilder.class);
EasyMock.expect(query.snapshot()).andReturn(t).anyTimes();
EasyMock.expect(query.mediaPackageId(EasyMock.anyObject(String.class))).andReturn(p).anyTimes();
EasyMock.expect(query.select(EasyMock.anyObject(Target.class))).andReturn(selectQuery).anyTimes();
VersionField v = EasyMock.createNiceMock(VersionField.class);
EasyMock.expect(v.isLatest()).andReturn(p).anyTimes();
EasyMock.expect(query.version()).andReturn(v).anyTimes();
EasyMock.expect(assetManager.createQuery()).andReturn(query).anyTimes();
EasyMock.replay(snapshot, aRec, p, r, t, selectQuery, query, v);
}
use of org.opencastproject.assetmanager.api.Snapshot in project opencast by opencast.
the class LiveScheduleServiceImpl method updateLiveEvent.
boolean updateLiveEvent(MediaPackage previousMp, DublinCoreCatalog episodeDC) throws LiveScheduleException {
// Get latest mp from the asset manager
Snapshot snapshot = getSnapshot(previousMp.getIdentifier().toString());
// will be compared below.
if (snapshot.getVersion().equals(snapshotVersionCache.getIfPresent(previousMp.getIdentifier()))) {
logger.debug("Snapshot version {} was created by us so this change is ignored.", snapshot.getVersion());
return false;
}
// Temporary mp
MediaPackage tempMp = (MediaPackage) snapshot.getMediaPackage().clone();
// Set duration (used by live tracks)
setDuration(tempMp, episodeDC);
// Add live tracks to media package
addLiveTracks(tempMp, episodeDC.getFirst(DublinCore.PROPERTY_SPATIAL));
// If same mp, no need to do anything
if (isSameMediaPackage(previousMp, tempMp)) {
logger.debug("Live media package {} seems to be the same. Not updating.", previousMp);
return false;
}
logger.info("Updating live media package {}", previousMp);
// Add and distribute catalogs/acl, this creates a new mp
MediaPackage mp = addAndDistributeElements(snapshot);
// Add tracks from tempMp
for (Track t : tempMp.getTracks()) mp.add(t);
// Remove publication element that came with the snapshot mp
removeLivePublicationChannel(mp);
// Publish mp to engage search index
publish(mp);
// Publication channel already there so no need to add
// Don't leave garbage there!
retractPreviousElements(previousMp, mp);
return true;
}
Aggregations