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;
}
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);
}
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());
}
}
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);
}
}
Aggregations