全部产品
云市场

点播CDN

更新时间:2019-01-31 17:54:31

初始化客户端

使用前请先初始化客户端,参考 initVodClient 接口。

预热缓存

接口参数和返回字段请参考 PreloadVodObjectCaches

  1. import com.aliyuncs.vod.model.v20170321.PreloadVodObjectCachesRequest;
  2. import com.aliyuncs.vod.model.v20170321.PreloadVodObjectCachesResponse;
  3. /**
  4. * 预热缓存
  5. * @param client 发送请求客户端
  6. * @return PreloadVodObjectCachesResponse
  7. * @throws Exception
  8. */
  9. public static PreloadVodObjectCachesResponse preloadVodObjectCaches(DefaultAcsClient client) throws Exception {
  10. PreloadVodObjectCachesRequest request = new PreloadVodObjectCachesRequest();
  11. // 需要预热的文件路径
  12. request.setObjectPath("http://test.com/fd.mp4");
  13. return client.getAcsResponse(request);
  14. }
  15. /**
  16. * 请求示例
  17. * @param argv
  18. */
  19. public static void main(String[] argv) {
  20. try {
  21. DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  22. PreloadVodObjectCachesResponse response = preloadVodObjectCaches(client);
  23. // 预热返回的任务ID
  24. System.out.println("PreloadTaskId = " + response.getPreloadTaskId());
  25. // 请求ID
  26. System.out.println("RequestId = " + response.getRequestId());
  27. } catch (Exception e) {
  28. System.out.println("ErrorMessage = " + e.getMessage());
  29. }
  30. }

刷新缓存

接口参数和返回字段请参考 RefreshVodObjectCaches

  1. import com.aliyuncs.vod.model.v20170321.RefreshVodObjectCachesRequest;
  2. import com.aliyuncs.vod.model.v20170321.RefreshVodObjectCachesResponse;
  3. /**
  4. * 刷新缓存
  5. * @param client 发送请求客户端
  6. * @return RefreshVodObjectCachesResponse
  7. * @throws Exception
  8. */
  9. public static RefreshVodObjectCachesResponse refreshVodObjectCaches(DefaultAcsClient client) throws Exception {
  10. RefreshVodObjectCachesRequest request = new RefreshVodObjectCachesRequest();
  11. // 需要刷新的文件或者目录路径
  12. request.setObjectPath("http://test.com/fd.mp4");
  13. // 刷新的类型
  14. request.setObjectType("File");
  15. return client.getAcsResponse(request);
  16. }
  17. /**
  18. * 请求示例
  19. * @param argv
  20. */
  21. public static void main(String[] argv) {
  22. try {
  23. DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  24. RefreshVodObjectCachesResponse response = refreshVodObjectCaches(client);
  25. // 刷新返回的任务ID
  26. System.out.println("PreloadTaskId = " + response.getRefreshTaskId());
  27. // 请求ID
  28. System.out.println("RequestId = " + response.getRequestId());
  29. } catch (Exception e) {
  30. System.out.println("ErrorMessage = " + e.getMessage());
  31. }
  32. }

查询刷新和预热状态

接口参数和返回字段请参考 DescribeVodRefreshTasks

  1. import com.aliyuncs.vod.model.v20170321.DescribeVodRefreshTasksRequest;
  2. import com.aliyuncs.vod.model.v20170321.DescribeVodRefreshTasksResponse;
  3. /**
  4. * 查询刷新和预热状态
  5. * @param client 发送请求客户端
  6. * @return DescribeVodRefreshTasksResponse
  7. * @throws Exception
  8. */
  9. public static DescribeVodRefreshTasksResponse describeVodRefreshTasks(DefaultAcsClient client) throws Exception {
  10. DescribeVodRefreshTasksRequest request = new DescribeVodRefreshTasksRequest();
  11. // 需要查询的域名
  12. request.setDomainName("test.com");
  13. // 任务类型
  14. request.setObjectType("file");
  15. return client.getAcsResponse(request);
  16. }
  17. /**
  18. * 请求示例
  19. * @param argv
  20. */
  21. public static void main(String[] argv) {
  22. try {
  23. DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  24. DescribeVodRefreshTasksResponse response = describeVodRefreshTasks(client);
  25. // 整页大小
  26. System.out.println("PageSize = " + response.getPageSize());
  27. // 页码
  28. System.out.println("PageNumber = " + response.getPageNumber());
  29. // 总条数
  30. System.out.println("TotalCount = " + response.getTotalCount());
  31. // 请求ID
  32. System.out.println("RequestId = " + response.getRequestId());
  33. if (response.getTasks() != null && response.getTasks().size() > 0) {
  34. for (DescribeVodRefreshTasksResponse.Task task : response.getTasks()) {
  35. System.out.println("-----------------------------");
  36. // 任务ID
  37. System.out.println("TaskId = " + task.getTaskId());
  38. // 刷新对象路径
  39. System.out.println("ObjectPath = " + task.getObjectPath());
  40. // 状态
  41. System.out.println("Status = " + task.getStatus());
  42. // 进度百分比
  43. System.out.println("Process = " + task.getProcess());
  44. // 任务类型
  45. System.out.println("ObjectType = " + task.getObjectType());
  46. // 任务对象创建时间,使用UTC时间。
  47. System.out.println("CreationTime = " + task.getCreationTime());
  48. // 刷新预热失败返回的错误描述。
  49. System.out.println("Description = " + task.getDescription());
  50. }
  51. }
  52. } catch (Exception e) {
  53. System.out.println("ErrorMessage = " + e.getMessage());
  54. }
  55. }

查询刷新预热次数限制和余量

接口参数和返回字段请参考 DescribeVodRefreshQuota

  1. import com.aliyuncs.vod.model.v20170321.DescribeVodRefreshQuotaRequest;
  2. import com.aliyuncs.vod.model.v20170321.DescribeVodRefreshQuotaResponse;
  3. /**
  4. * 查询刷新预热次数限制和余量
  5. * @param client 发送请求客户端
  6. * @return DescribeVodRefreshQuotaResponse
  7. * @throws Exception
  8. */
  9. public static DescribeVodRefreshQuotaResponse describeVodRefreshQuota(DefaultAcsClient client) throws Exception {
  10. DescribeVodRefreshQuotaRequest request = new DescribeVodRefreshQuotaRequest();
  11. return client.getAcsResponse(request);
  12. }
  13. /**
  14. * 请求示例
  15. * @param argv
  16. */
  17. public static void main(String[] argv) {
  18. try {
  19. DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  20. DescribeVodRefreshQuotaResponse response = describeVodRefreshQuota(client);
  21. // 当日URL刷新数量上限
  22. System.out.println("UrlQuota = " + response.getUrlQuota());
  23. // 当日目录刷新数量上限
  24. System.out.println("DirQuota = " + response.getDirQuota());
  25. // 当日剩余URL刷新数量
  26. System.out.println("UrlRemain = " + response.getUrlRemain());
  27. // 当日剩余目录刷新数量
  28. System.out.println("DirRemain = " + response.getDirRemain());
  29. // 当天预热数量上限
  30. System.out.println("PreloadQuota = " + response.getPreloadQuota());
  31. // 当天剩余预热数量
  32. System.out.println("PreloadRemain = " + response.getPreloadRemain());
  33. // 请求ID
  34. System.out.println("RequestId = " + response.getRequestId());
  35. } catch (Exception e) {
  36. System.out.println("ErrorMessage = " + e.getMessage());
  37. }
  38. }

查询流量数据

接口参数和返回字段请参考 DescribeVodDomainTrafficData

  1. import com.aliyuncs.vod.model.v20170321.DescribeVodDomainTrafficDataRequest;
  2. import com.aliyuncs.vod.model.v20170321.DescribeVodDomainTrafficDataResponse;
  3. /**
  4. * 查询流量数据
  5. */
  6. public static DescribeVodDomainTrafficDataResponse describeVodDomainTrafficData(DefaultAcsClient client) throws Exception {
  7. DescribeVodDomainTrafficDataRequest request = new DescribeVodDomainTrafficDataRequest();
  8. // 设置域名
  9. request.setDomainName("example.test.com");
  10. // 设置开始时间,请使用UTC格式
  11. request.setStartTime("2019-01-15T15:59:59Z");
  12. // 设置结束时间,请使用UTC格式
  13. request.setEndTime("2019-01-20T15:59:58Z");
  14. // 返回结果
  15. return client.getAcsResponse(request);
  16. }
  17. /**
  18. * 以下为调用示例
  19. * @param args
  20. */
  21. public static void main(String[] args) throws Exception {
  22. // 初始化客户端
  23. DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  24. try {
  25. // 获取结果
  26. DescribeVodDomainTrafficDataResponse response = describeVodDomainTrafficData(client);
  27. // 打印请求ID
  28. System.out.println("ResquestId:" + response.getRequestId());
  29. // 打印域名
  30. System.out.println("DomainName:" + response.getDomainName());
  31. // 打印开始时间
  32. System.out.println("StartTime:" + response.getStartTime());
  33. // 打印结束时间
  34. System.out.println("EndTime:" + response.getEndTime());
  35. // 打印时间间隔
  36. System.out.println("DataInterval:" + response.getDataInterval());
  37. // 打印流量数据
  38. if (response.getTrafficDataPerInterval() != null && response.getTrafficDataPerInterval().size() != 0) {
  39. List<DescribeVodDomainTrafficDataResponse.DataModule> dataModules = response.getTrafficDataPerInterval();
  40. for(int i=0; i<dataModules.size(); i++) {
  41. System.out.println("==========================" );
  42. System.out.println("TimeStamp:" + dataModules.get(i).getTimeStamp());
  43. System.out.println("Value:" + dataModules.get(i).getValue());
  44. System.out.println("DomesticValue:" + dataModules.get(i).getDomesticValue());
  45. System.out.println("OverseasValue:" + dataModules.get(i).getOverseasValue());
  46. }
  47. }
  48. } catch (Exception e) {
  49. System.out.println("ErrorMessage:" + e.getLocalizedMessage());
  50. }
  51. }

查询网络带宽

接口参数和返回字段请参考 DescribeVodDomainBpsData

  1. import com.aliyuncs.vod.model.v20170321.DescribeVodDomainBpsDataRequest;
  2. import com.aliyuncs.vod.model.v20170321.DescribeVodDomainBpsDataResponse;
  3. import java.util.List;
  4. /**
  5. * 查询网络带宽
  6. */
  7. public static DescribeVodDomainBpsDataResponse describeVodDomainBpsData(DefaultAcsClient client) throws Exception {
  8. DescribeVodDomainBpsDataRequest request = new DescribeVodDomainBpsDataRequest();
  9. // 设置域名
  10. request.setDomainName("example.test.com");
  11. // 设置开始时间,请使用UTC格式
  12. request.setStartTime("2019-01-15T15:59:59Z");
  13. // 设置结束时间,请使用UTC格式
  14. request.setEndTime("2019-01-20T15:59:58Z");
  15. // 返回结果
  16. return client.getAcsResponse(request);
  17. }
  18. /**
  19. * 以下为调用示例
  20. * @param args
  21. */
  22. public static void main(String[] args) throws Exception {
  23. // 初始化客户端
  24. DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  25. try {
  26. // 获取结果
  27. DescribeVodDomainBpsDataResponse response = describeVodDomainBpsData(client);
  28. // 打印请求ID
  29. System.out.println("ResquestId:" + response.getRequestId());
  30. // 打印域名
  31. System.out.println("DomainName:" + response.getDomainName());
  32. // 打印开始时间
  33. System.out.println("StartTime:" + response.getStartTime());
  34. // 打印结束时间
  35. System.out.println("EndTime:" + response.getEndTime());
  36. // 打印时间间隔
  37. System.out.println("DataInterval:" + response.getDataInterval());
  38. // 打印带宽数据
  39. if (response.getBpsDataPerInterval() != null && response.getBpsDataPerInterval().size() != 0) {
  40. List<DescribeVodDomainBpsDataResponse.DataModule> dataModules = response.getBpsDataPerInterval();
  41. for(int i=0; i<dataModules.size(); i++) {
  42. System.out.println("==========================" );
  43. System.out.println("TimeStamp:" + dataModules.get(i).getTimeStamp());
  44. System.out.println("Value:" + dataModules.get(i).getValue());
  45. System.out.println("DomesticValue:" + dataModules.get(i).getDomesticValue());
  46. System.out.println("OverseasValue:" + dataModules.get(i).getOverseasValue());
  47. }
  48. }
  49. } catch (Exception e) {
  50. System.out.println("ErrorMessage:" + e.getLocalizedMessage());
  51. }
  52. }

下载域名日志

接口参数和返回字段请参考 DescribeVodDomainLog

  1. import com.aliyuncs.vod.model.v20170321.DescribeVodDomainLogRequest;
  2. import com.aliyuncs.vod.model.v20170321.DescribeVodDomainLogResponse;
  3. import java.util.List;
  4. /**
  5. * 下载域名日志
  6. */
  7. public static DescribeVodDomainLogResponse describeVodDomainLog(DefaultAcsClient client) throws Exception {
  8. DescribeVodDomainLogRequest request = new DescribeVodDomainLogRequest();
  9. // 设置域名
  10. request.setDomainName("zhptest.alicdn.com");
  11. // 设置开始时间,请使用UTC格式
  12. request.setStartTime("2019-01-15T15:59:59Z");
  13. // 设置结束时间,请使用UTC格式
  14. request.setEndTime("2019-01-20T15:59:58Z");
  15. // 设置分页大小
  16. //request.setPageSize(300L);
  17. // 设置分页页号
  18. //request.setPageNumber(1L);
  19. // 返回结果
  20. return client.getAcsResponse(request);
  21. }
  22. /**
  23. * 以下为调用示例
  24. * @param args
  25. */
  26. public static void main(String[] args) throws Exception {
  27. // 初始化客户端
  28. DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  29. try {
  30. // 获取结果
  31. DescribeVodDomainLogResponse response = describeVodDomainLog(client);
  32. // 打印请求ID
  33. System.out.println("ResquestId:" + response.getRequestId());
  34. // 打印CDN日志详细数据
  35. if (response.getDomainLogDetails() != null && response.getDomainLogDetails().size() != 0) {
  36. List<DescribeVodDomainLogResponse.DomainLogDetail> domainLogDetails = response.getDomainLogDetails();
  37. for(int i=0; i<domainLogDetails.size(); i++) {
  38. System.out.println("==========================" );
  39. System.out.println("DomainName:" + domainLogDetails.get(i).getDomainName());
  40. System.out.println("LogCount:" + domainLogDetails.get(i).getLogCount());
  41. System.out.println("=== PageInfoDetail Data ===" );
  42. System.out.println("PageNumber:" + domainLogDetails.get(i).getPageInfos().getPageNumber());
  43. System.out.println("PageSize:" + domainLogDetails.get(i).getPageInfos().getPageSize());
  44. System.out.println("Total:" + domainLogDetails.get(i).getPageInfos().getTotal());
  45. System.out.println("=== LogInfoDetail Data ===" );
  46. List<DescribeVodDomainLogResponse.DomainLogDetail.LogInfoDetail> logInfos = domainLogDetails.get(i).getLogInfos();
  47. if (logInfos != null && logInfos.size() != 0) {
  48. for (int k=0; k<logInfos.size(); k++) {
  49. System.out.println("LogName:" + logInfos.get(k).getLogName());
  50. System.out.println("LogPath:" + logInfos.get(k).getLogPath());
  51. System.out.println("LogSize:" + logInfos.get(k).getLogSize());
  52. System.out.println("StartTime:" + logInfos.get(k).getStartTime());
  53. System.out.println("EndTime:" + logInfos.get(k).getEndTime());
  54. }
  55. }
  56. }
  57. }
  58. } catch (Exception e) {
  59. System.out.println("ErrorMessage:" + e.getLocalizedMessage());
  60. }
  61. }