Search in sources :

Example 1 with LiveChannel

use of com.aliyun.oss.model.LiveChannel 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 LiveChannel

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

the class TestBase method deleteBucketWithObjects.

protected static void deleteBucketWithObjects(OSSClient client, String bucketName) {
    if (!client.doesBucketExist(bucketName)) {
        return;
    }
    // delete objects
    List<String> allObjects = listAllObjects(client, bucketName);
    int total = allObjects.size();
    if (total > 0) {
        int opLoops = total / DELETE_OBJECTS_ONETIME_LIMIT;
        if (total % DELETE_OBJECTS_ONETIME_LIMIT != 0) {
            opLoops++;
        }
        List<String> objectsToDel = null;
        for (int i = 0; i < opLoops; i++) {
            int fromIndex = i * DELETE_OBJECTS_ONETIME_LIMIT;
            int len = 0;
            if (total <= DELETE_OBJECTS_ONETIME_LIMIT) {
                len = total;
            } else {
                len = (i + 1 == opLoops) ? (total - fromIndex) : DELETE_OBJECTS_ONETIME_LIMIT;
            }
            objectsToDel = allObjects.subList(fromIndex, fromIndex + len);
            DeleteObjectsRequest deleteObjectsRequest = new DeleteObjectsRequest(bucketName);
            deleteObjectsRequest.setEncodingType(DEFAULT_ENCODING_TYPE);
            deleteObjectsRequest.setKeys(objectsToDel);
            client.deleteObjects(deleteObjectsRequest);
        }
    }
    // delete live channels
    List<LiveChannel> channels = ossClient.listLiveChannels(bucketName);
    for (LiveChannel channel : channels) {
        ossClient.deleteLiveChannel(bucketName, channel.getName());
    }
    // delete bucket
    client.deleteBucket(bucketName);
}
Also used : LiveChannel(com.aliyun.oss.model.LiveChannel) DeleteObjectsRequest(com.aliyun.oss.model.DeleteObjectsRequest)

Example 3 with LiveChannel

use of com.aliyun.oss.model.LiveChannel 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)

Example 4 with LiveChannel

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

the class ResponseParsers method parseListLiveChannels.

/**
 * Unmarshall list live channels response body to live channel listing.
 */
@SuppressWarnings("unchecked")
public static LiveChannelListing parseListLiveChannels(InputStream responseBody) throws ResponseParseException {
    try {
        Element root = getXmlRootElement(responseBody);
        LiveChannelListing liveChannelListing = new LiveChannelListing();
        liveChannelListing.setTruncated(Boolean.valueOf(root.getChildText("IsTruncated")));
        if (root.getChild("Prefix") != null) {
            String prefix = root.getChildText("Prefix");
            liveChannelListing.setPrefix(isNullOrEmpty(prefix) ? null : prefix);
        }
        if (root.getChild("Marker") != null) {
            String marker = root.getChildText("Marker");
            liveChannelListing.setMarker(isNullOrEmpty(marker) ? null : marker);
        }
        if (root.getChild("MaxKeys") != null) {
            String maxKeys = root.getChildText("MaxKeys");
            liveChannelListing.setMaxKeys(Integer.valueOf(maxKeys));
        }
        if (root.getChild("NextMarker") != null) {
            String nextMarker = root.getChildText("NextMarker");
            liveChannelListing.setNextMarker(isNullOrEmpty(nextMarker) ? null : nextMarker);
        }
        List<Element> liveChannelElems = root.getChildren("LiveChannel");
        for (Element elem : liveChannelElems) {
            LiveChannel liveChannel = new LiveChannel();
            liveChannel.setName(elem.getChildText("Name"));
            liveChannel.setDescription(elem.getChildText("Description"));
            liveChannel.setStatus(LiveChannelStatus.parse(elem.getChildText("Status")));
            liveChannel.setLastModified(DateUtil.parseIso8601Date(elem.getChildText("LastModified")));
            List<String> publishUrls = new ArrayList<String>();
            List<Element> publishElems = elem.getChild("PublishUrls").getChildren("Url");
            for (Element urlElem : publishElems) {
                publishUrls.add(urlElem.getText());
            }
            liveChannel.setPublishUrls(publishUrls);
            List<String> playUrls = new ArrayList<String>();
            List<Element> playElems = elem.getChild("PlayUrls").getChildren("Url");
            for (Element urlElem : playElems) {
                playUrls.add(urlElem.getText());
            }
            liveChannel.setPlayUrls(playUrls);
            liveChannelListing.addLiveChannel(liveChannel);
        }
        return liveChannelListing;
    } catch (JDOMParseException e) {
        throw new ResponseParseException(e.getPartialDocument() + ": " + e.getMessage(), e);
    } catch (Exception e) {
        throw new ResponseParseException(e.getMessage(), e);
    }
}
Also used : JDOMParseException(org.jdom.input.JDOMParseException) Element(org.jdom.Element) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException) ArrayList(java.util.ArrayList) LiveChannelListing(com.aliyun.oss.model.LiveChannelListing) LiveChannel(com.aliyun.oss.model.LiveChannel) ParseException(java.text.ParseException) JDOMParseException(org.jdom.input.JDOMParseException) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException)

Aggregations

LiveChannel (com.aliyun.oss.model.LiveChannel)4 LiveChannelListing (com.aliyun.oss.model.LiveChannelListing)3 ListLiveChannelsRequest (com.aliyun.oss.model.ListLiveChannelsRequest)2 ParseException (java.text.ParseException)2 OSSException (com.aliyun.oss.OSSException)1 ResponseParseException (com.aliyun.oss.common.parser.ResponseParseException)1 CreateLiveChannelRequest (com.aliyun.oss.model.CreateLiveChannelRequest)1 DeleteObjectsRequest (com.aliyun.oss.model.DeleteObjectsRequest)1 ArrayList (java.util.ArrayList)1 Element (org.jdom.Element)1 JDOMParseException (org.jdom.input.JDOMParseException)1 Test (org.junit.Test)1