Search in sources :

Example 1 with ListLiveChannelsRequest

use of com.aliyun.oss.model.ListLiveChannelsRequest in project aliyun-oss-java-sdk by aliyun.

the class LiveChannelOperation method listLiveChannels.

/**
 * List all live channels.
 */
public List<LiveChannel> listLiveChannels(String bucketName) throws OSSException, ClientException {
    LiveChannelListing liveChannelListing = listLiveChannels(new ListLiveChannelsRequest(bucketName));
    List<LiveChannel> liveChannels = liveChannelListing.getLiveChannels();
    while (liveChannelListing.isTruncated()) {
        liveChannelListing = listLiveChannels(new ListLiveChannelsRequest(bucketName, liveChannelListing.getNextMarker(), null));
        liveChannels.addAll(liveChannelListing.getLiveChannels());
    }
    return liveChannels;
}
Also used : ListLiveChannelsRequest(com.aliyun.oss.model.ListLiveChannelsRequest) LiveChannelListing(com.aliyun.oss.model.LiveChannelListing) LiveChannel(com.aliyun.oss.model.LiveChannel)

Example 2 with ListLiveChannelsRequest

use of com.aliyun.oss.model.ListLiveChannelsRequest in project aliyun-oss-java-sdk by aliyun.

the class RtmpTest method testListLiveChannel.

@Test
public void testListLiveChannel() {
    final String liveChannelPrefix = "normal-list-live-channel";
    try {
        // create live channels
        for (int i = 0; i < 10; i++) {
            CreateLiveChannelRequest createLiveChannelRequest = new CreateLiveChannelRequest(bucketName, liveChannelPrefix + i);
            ossClient.createLiveChannel(createLiveChannelRequest);
        }
        // default
        ListLiveChannelsRequest listLiveChannelsRequest = new ListLiveChannelsRequest(bucketName);
        LiveChannelListing liveChannelListing = ossClient.listLiveChannels(listLiveChannelsRequest);
        Assert.assertTrue(liveChannelListing.getLiveChannels().size() >= 10);
        Assert.assertNull(liveChannelListing.getPrefix());
        Assert.assertNull(liveChannelListing.getMarker());
        Assert.assertNull(liveChannelListing.getNextMarker());
        Assert.assertEquals(liveChannelListing.getMaxKeys(), 100);
        Assert.assertFalse(liveChannelListing.isTruncated());
        // prefix
        listLiveChannelsRequest = new ListLiveChannelsRequest(bucketName);
        listLiveChannelsRequest.setPrefix(liveChannelPrefix);
        liveChannelListing = ossClient.listLiveChannels(listLiveChannelsRequest);
        Assert.assertTrue(liveChannelListing.getLiveChannels().size() == 10);
        Assert.assertEquals(liveChannelListing.getPrefix(), liveChannelPrefix);
        Assert.assertNull(liveChannelListing.getMarker());
        Assert.assertNull(liveChannelListing.getNextMarker());
        Assert.assertEquals(liveChannelListing.getMaxKeys(), 100);
        Assert.assertFalse(liveChannelListing.isTruncated());
        for (LiveChannel liveChannel : liveChannelListing.getLiveChannels()) {
            Assert.assertTrue(liveChannel.getName().startsWith(liveChannelPrefix));
            Assert.assertEquals(liveChannel.getDescription(), "");
            Assert.assertEquals(liveChannel.getStatus(), LiveChannelStatus.Enabled);
            Assert.assertTrue(dateAfterValidator(liveChannel.getLastModified()));
            Assert.assertEquals(liveChannel.getPublishUrls().size(), 1);
            Assert.assertTrue(liveChannel.getPublishUrls().get(0).startsWith("rtmp://"));
            Assert.assertTrue(liveChannel.getPublishUrls().get(0).indexOf("live/" + liveChannelPrefix) > -1);
            Assert.assertEquals(liveChannel.getPlayUrls().size(), 1);
            Assert.assertTrue(liveChannel.getPlayUrls().get(0).startsWith("http://"));
            Assert.assertTrue(liveChannel.getPlayUrls().get(0).endsWith("/playlist.m3u8"));
        }
        // marker
        listLiveChannelsRequest = new ListLiveChannelsRequest(bucketName);
        listLiveChannelsRequest.setPrefix(liveChannelPrefix);
        listLiveChannelsRequest.setMarker(liveChannelPrefix + 5);
        liveChannelListing = ossClient.listLiveChannels(listLiveChannelsRequest);
        Assert.assertTrue(liveChannelListing.getLiveChannels().size() == 4);
        Assert.assertEquals(liveChannelListing.getPrefix(), liveChannelPrefix);
        Assert.assertEquals(liveChannelListing.getMarker(), liveChannelPrefix + 5);
        Assert.assertNull(liveChannelListing.getNextMarker());
        Assert.assertEquals(liveChannelListing.getMaxKeys(), 100);
        Assert.assertFalse(liveChannelListing.isTruncated());
        for (LiveChannel liveChannel : liveChannelListing.getLiveChannels()) {
            Assert.assertTrue(liveChannel.getName().startsWith(liveChannelPrefix));
            Assert.assertEquals(liveChannel.getDescription(), "");
            Assert.assertEquals(liveChannel.getStatus(), LiveChannelStatus.Enabled);
            Assert.assertTrue(dateAfterValidator(liveChannel.getLastModified()));
            Assert.assertEquals(liveChannel.getPublishUrls().size(), 1);
            Assert.assertTrue(liveChannel.getPublishUrls().get(0).startsWith("rtmp://"));
            Assert.assertTrue(liveChannel.getPublishUrls().get(0).indexOf("live/" + liveChannelPrefix) > -1);
            Assert.assertEquals(liveChannel.getPlayUrls().size(), 1);
            Assert.assertTrue(liveChannel.getPlayUrls().get(0).startsWith("http://"));
            Assert.assertTrue(liveChannel.getPlayUrls().get(0).endsWith("/playlist.m3u8"));
        }
        // marker
        listLiveChannelsRequest = new ListLiveChannelsRequest(bucketName);
        listLiveChannelsRequest.setPrefix(liveChannelPrefix);
        listLiveChannelsRequest.setMaxKeys(5);
        liveChannelListing = ossClient.listLiveChannels(listLiveChannelsRequest);
        Assert.assertTrue(liveChannelListing.getLiveChannels().size() == 5);
        Assert.assertEquals(liveChannelListing.getPrefix(), liveChannelPrefix);
        Assert.assertNull(liveChannelListing.getMarker());
        Assert.assertNotNull(liveChannelListing.getNextMarker());
        Assert.assertEquals(liveChannelListing.getMaxKeys(), 5);
        Assert.assertTrue(liveChannelListing.isTruncated());
        for (LiveChannel liveChannel : liveChannelListing.getLiveChannels()) {
            Assert.assertTrue(liveChannel.getName().startsWith(liveChannelPrefix));
            Assert.assertEquals(liveChannel.getDescription(), "");
            Assert.assertEquals(liveChannel.getStatus(), LiveChannelStatus.Enabled);
            Assert.assertTrue(dateAfterValidator(liveChannel.getLastModified()));
            Assert.assertEquals(liveChannel.getPublishUrls().size(), 1);
            Assert.assertTrue(liveChannel.getPublishUrls().get(0).startsWith("rtmp://"));
            Assert.assertTrue(liveChannel.getPublishUrls().get(0).indexOf("live/" + liveChannelPrefix) > -1);
            Assert.assertEquals(liveChannel.getPlayUrls().size(), 1);
            Assert.assertTrue(liveChannel.getPlayUrls().get(0).startsWith("http://"));
            Assert.assertTrue(liveChannel.getPlayUrls().get(0).endsWith("/playlist.m3u8"));
        }
        // page
        listLiveChannelsRequest = new ListLiveChannelsRequest(bucketName);
        listLiveChannelsRequest.setPrefix(liveChannelPrefix);
        listLiveChannelsRequest.setMaxKeys(5);
        do {
            liveChannelListing = ossClient.listLiveChannels(listLiveChannelsRequest);
            Assert.assertTrue(liveChannelListing.getLiveChannels().size() == 5);
            for (LiveChannel liveChannel : liveChannelListing.getLiveChannels()) {
                Assert.assertTrue(liveChannel.getName().startsWith(liveChannelPrefix));
            }
            listLiveChannelsRequest.setMarker(liveChannelListing.getNextMarker());
        } while (liveChannelListing.isTruncated());
        // list all
        List<LiveChannel> liveChannels = ossClient.listLiveChannels(bucketName);
        Assert.assertTrue(liveChannels.size() >= 10);
        // delete live channels
        for (int i = 0; i < 10; i++) {
            ossClient.deleteLiveChannel(bucketName, liveChannelPrefix + i);
        }
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    }
}
Also used : CreateLiveChannelRequest(com.aliyun.oss.model.CreateLiveChannelRequest) ListLiveChannelsRequest(com.aliyun.oss.model.ListLiveChannelsRequest) LiveChannelListing(com.aliyun.oss.model.LiveChannelListing) LiveChannel(com.aliyun.oss.model.LiveChannel) OSSException(com.aliyun.oss.OSSException) ParseException(java.text.ParseException) Test(org.junit.Test)

Aggregations

ListLiveChannelsRequest (com.aliyun.oss.model.ListLiveChannelsRequest)2 LiveChannel (com.aliyun.oss.model.LiveChannel)2 LiveChannelListing (com.aliyun.oss.model.LiveChannelListing)2 OSSException (com.aliyun.oss.OSSException)1 CreateLiveChannelRequest (com.aliyun.oss.model.CreateLiveChannelRequest)1 ParseException (java.text.ParseException)1 Test (org.junit.Test)1