All Products
Search
Document Center

CDN

Last Updated: Jul 11, 2019

Initialize a client

Initialize a client before using the SDK. For more information, see initVodClient.

Preload content to cache nodes

For more information about the request and response parameters, see PreloadVodObjectCaches.

import com.aliyuncs.vod.model.v20170321.PreloadVodObjectCachesRequest;
import com.aliyuncs.vod.model.v20170321.PreloadVodObjectCachesResponse;

    /**
     * Method for preloading content to cache nodes
     * @param client The client that sends a request.
     * @return PreloadVodObjectCachesResponse
     * @throws Exception
     */
    public static PreloadVodObjectCachesResponse preloadVodObjectCaches(DefaultAcsClient client) throws Exception {
        PreloadVodObjectCachesRequest request = new PreloadVodObjectCachesRequest();
        // Sets the URL of the content to be preloaded.
        request.setObjectPath("http://test.com/fd.mp4");
        return client.getAcsResponse(request);
    }

    /**
     * Call example
     * @param argv
     */
    public static void main(String[] argv) {
        try {
            DefaultAcsClient client = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
            PreloadVodObjectCachesResponse response = preloadVodObjectCaches(client);
            // The ID of the preload task.
            System.out.println("PreloadTaskId = " + response.getPreloadTaskId());
            // The GUID generated by Alibaba Cloud for the request.
            System.out.println("RequestId = " + response.getRequestId());
        } catch (Exception e) {
            System.out.println("ErrorMessage = " + e.getMessage());
        }
    }

Refresh the cached content on nodes

For more information about the request and response parameters, see RefreshVodObjectCaches.

import com.aliyuncs.vod.model.v20170321.RefreshVodObjectCachesRequest;
import com.aliyuncs.vod.model.v20170321.RefreshVodObjectCachesResponse;

    /**
     * Method for refreshing the cached content on nodes
     * @param client The client that sends a request.
     * @return RefreshVodObjectCachesResponse
     * @throws Exception
     */
    public static RefreshVodObjectCachesResponse refreshVodObjectCaches(DefaultAcsClient client) throws Exception {
        RefreshVodObjectCachesRequest request = new RefreshVodObjectCachesRequest();
        // Sets the URL of the content to be refreshed.
        request.setObjectPath("http://test.com/fd.mp4");
        // Sets the type of the content to be refreshed.
        request.setObjectType("File");
        return client.getAcsResponse(request);
    }

    /**
     * Call example
     * @param argv
     */
    public static void main(String[] argv) {
        try {
            DefaultAcsClient client = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
            RefreshVodObjectCachesResponse response = refreshVodObjectCaches(client);
            // The ID of the refresh task.
            System.out.println("PreloadTaskId = " + response.getRefreshTaskId());
            // The GUID generated by Alibaba Cloud for the request.
            System.out.println("RequestId = " + response.getRequestId());
        } catch (Exception e) {
            System.out.println("ErrorMessage = " + e.getMessage());
        }
    }

Query the status of refresh and preload tasks

For more information about the request and response parameters, see DescribeVodRefreshTasks.

import com.aliyuncs.vod.model.v20170321.DescribeVodRefreshTasksRequest;
import com.aliyuncs.vod.model.v20170321.DescribeVodRefreshTasksResponse;

    /**
     * Method for querying the status of refresh and preload tasks
     * @param client The client that sends a request.
     * @return DescribeVodRefreshTasksResponse
     * @throws Exception
     */
    public static DescribeVodRefreshTasksResponse describeVodRefreshTasks(DefaultAcsClient client) throws Exception {
        DescribeVodRefreshTasksRequest request = new DescribeVodRefreshTasksRequest();
        // Specifies the domain name to be queried.
        request.setDomainName("test.com");
        // Sets the task type.
        request.setObjectType("file");
        return client.getAcsResponse(request);
    }

    /**
     * Call example
     * @param argv
     */
    public static void main(String[] argv) {
        try {
            DefaultAcsClient client = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
            DescribeVodRefreshTasksResponse response = describeVodRefreshTasks(client);
            // The number of data records per page.
            System.out.println("PageSize = " + response.getPageSize());
            // The page number.
            System.out.println("PageNumber = " + response.getPageNumber());
            // The total number of data records.
            System.out.println("TotalCount = " + response.getTotalCount());
            // The GUID generated by Alibaba Cloud for the request.
            System.out.println("RequestId = " + response.getRequestId());
            if (response.getTasks() ! = null && response.getTasks().size() > 0) {
                for (DescribeVodRefreshTasksResponse.Task task : response.getTasks()) {
                    System.out.println("-----------------------------");
                    // The task ID.
                    System.out.println("TaskId = " + task.getTaskId());
                    // The URL of the content to be refreshed or preloaded.
                    System.out.println("ObjectPath = " + task.getObjectPath());
                    // The task status.
                    System.out.println("Status = " + task.getStatus());
                    // The task progress, in percentage.
                    System.out.println("Process = " + task.getProcess());
                    // The task type.
                    System.out.println("ObjectType = " + task.getObjectType());
                    // The creation time of the task, in UTC.
                    System.out.println("CreationTime = " + task.getCreationTime());
                    // The error message returned when the refresh or preload task failed.
                    System.out.println("Description = " + task.getDescription());
                }
            }
        } catch (Exception e) {
            System.out.println("ErrorMessage = " + e.getMessage());
        }
    }

Query the maximum number and remaining number of requests to refresh and preload content on the current day

For more information about the request and response parameters, see DescribeVodRefreshQuota.

import com.aliyuncs.vod.model.v20170321.DescribeVodRefreshQuotaRequest;
import com.aliyuncs.vod.model.v20170321.DescribeVodRefreshQuotaResponse;

    /**
     * Method for querying the maximum number and remaining number of requests to refresh and preload content on the current day
     * @param client The client that sends a request.
     * @return DescribeVodRefreshQuotaResponse
     * @throws Exception
     */
    public static DescribeVodRefreshQuotaResponse describeVodRefreshQuota(DefaultAcsClient client) throws Exception {
        DescribeVodRefreshQuotaRequest request = new DescribeVodRefreshQuotaRequest();
        return client.getAcsResponse(request);
    }

    /**
     * Call example
     * @param argv
     */
    public static void main(String[] argv) {
        try {
            DefaultAcsClient client = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
            DescribeVodRefreshQuotaResponse response = describeVodRefreshQuota(client);
            // The maximum number of requests to refresh URLs on the current day.
            System.out.println("UrlQuota = " + response.getUrlQuota());
            // The maximum number of requests to refresh directories on the current day.
            System.out.println("DirQuota = " + response.getDirQuota());
            // The remaining number of requests to refresh URLs on the current day.
            System.out.println("UrlRemain = " + response.getUrlRemain());
            // The remaining number of requests to refresh directories on the current day.
            System.out.println("DirRemain = " + response.getDirRemain());
            // The maximum number of requests to preload content on the current day.
            System.out.println("PreloadQuota = " + response.getPreloadQuota());
            // The remaining number of requests to preload content on the current day.
            System.out.println("PreloadRemain = " + response.getPreloadRemain());
            // The GUID generated by Alibaba Cloud for the request.
            System.out.println("RequestId = " + response.getRequestId());
        } catch (Exception e) {
            System.out.println("ErrorMessage = " + e.getMessage());
        }
    }

Obtain the network traffic monitoring data for accelerating domain names

For more information about the request and response parameters, see DescribeVodDomainTrafficData.

import com.aliyuncs.vod.model.v20170321.DescribeVodDomainTrafficDataRequest;
import com.aliyuncs.vod.model.v20170321.DescribeVodDomainTrafficDataResponse;

/**
 * Method for obtaining the network traffic monitoring data for accelerating domain names
 */
public static DescribeVodDomainTrafficDataResponse describeVodDomainTrafficData(DefaultAcsClient client) throws Exception {
        DescribeVodDomainTrafficDataRequest request = new DescribeVodDomainTrafficDataRequest();
        // Specifies the domain name to be queried.
        request.setDomainName("example.test.com");
        // Sets the start time of queried data, in UTC.
        request.setStartTime("2019-01-15T15:59:59Z");
        // Sets the end time of queried data, in UTC.
        request.setEndTime("2019-01-20T15:59:58Z");

        // Obtains a response.
        return client.getAcsResponse(request);
}

/**
 * Call example
 * @param args
 */
public static void main(String[] args) throws Exception {
        // Initializes the client.
        DefaultAcsClient client = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");

        try {
            // Obtains a response.
            DescribeVodDomainTrafficDataResponse response = describeVodDomainTrafficData(client);

            // The GUID generated by Alibaba Cloud for the request.
            System.out.println("RequestId:" + response.getRequestId());
            // The accelerating domain name.
            System.out.println("DomainName:" + response.getDomainName());
            // The start time of queried data.
            System.out.println("StartTime:" + response.getStartTime());
            // The end time of queried data.
            System.out.println("EndTime:" + response.getEndTime());
            // The time interval of queried data.
            System.out.println("DataInterval:" + response.getDataInterval());
            // The network traffic data that is collected during each interval.
            if (response.getTrafficDataPerInterval() ! = null && response.getTrafficDataPerInterval().size() ! = 0) {
                List<DescribeVodDomainTrafficDataResponse.DataModule> dataModules = response.getTrafficDataPerInterval(); 
                for(int i=0; i<dataModules.size(); i++) { 
                    System.out.println("==========================" );
                    System.out.println("TimeStamp:" + dataModules.get(i).getTimeStamp());
                    System.out.println("Value:" + dataModules.get(i).getValue());
                    System.out.println("DomesticValue:" + dataModules.get(i).getDomesticValue());
                    System.out.println("OverseasValue:" + dataModules.get(i).getOverseasValue());
                }

            }
        } catch (Exception e) {
            System.out.println("ErrorMessage:" + e.getLocalizedMessage());
        }
}

Obtain the network bandwidth monitoring data for accelerating domain names

For more information about the request and response parameters, see DescribeVodDomainBpsData.

import com.aliyuncs.vod.model.v20170321.DescribeVodDomainBpsDataRequest;
import com.aliyuncs.vod.model.v20170321.DescribeVodDomainBpsDataResponse;
import java.util.List;

/**
 * Method for obtaining the network bandwidth monitoring data for accelerating domain names
 */
public static DescribeVodDomainBpsDataResponse describeVodDomainBpsData(DefaultAcsClient client) throws Exception {
        DescribeVodDomainBpsDataRequest request = new DescribeVodDomainBpsDataRequest();
        // Specifies the domain name to be queried.
        request.setDomainName("example.test.com");
        // Sets the start time of queried data, in UTC.
        request.setStartTime("2019-01-15T15:59:59Z");
        // Sets the end time of queried data, in UTC.
        request.setEndTime("2019-01-20T15:59:58Z");

        // Obtains a response.
        return client.getAcsResponse(request);
}

/**
 * Call example
 * @param args
 */
public static void main(String[] args) throws Exception {
        // Initializes the client.
        DefaultAcsClient client = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
        try {
            // Obtains a response.
            DescribeVodDomainBpsDataResponse response = describeVodDomainBpsData(client);

            // The GUID generated by Alibaba Cloud for the request.
            System.out.println("RequestId:" + response.getRequestId());
            // The accelerating domain name.
            System.out.println("DomainName:" + response.getDomainName());
            // The start time of queried data.
            System.out.println("StartTime:" + response.getStartTime());
            // The end time of queried data.
            System.out.println("EndTime:" + response.getEndTime());
            // The time interval of queried data.
            System.out.println("DataInterval:" + response.getDataInterval());
            // The network bandwidth data that is collected during each interval.
            if (response.getBpsDataPerInterval() ! = null && response.getBpsDataPerInterval().size() ! = 0) {
                List<DescribeVodDomainBpsDataResponse.DataModule> dataModules = response.getBpsDataPerInterval(); 
                for(int i=0; i<dataModules.size(); i++) {
                    System.out.println("==========================" );
                    System.out.println("TimeStamp:" + dataModules.get(i).getTimeStamp());
                    System.out.println("Value:" + dataModules.get(i).getValue());
                    System.out.println("DomesticValue:" + dataModules.get(i).getDomesticValue());
                    System.out.println("OverseasValue:" + dataModules.get(i).getOverseasValue());
                }

            }
        } catch (Exception e) {
            System.out.println("ErrorMessage:" + e.getLocalizedMessage());
        }
}

Download raw CDN access logs for a specified domain name

For more information about the request and response parameters, see DescribeVodDomainLog.

import com.aliyuncs.vod.model.v20170321.DescribeVodDomainLogRequest;
import com.aliyuncs.vod.model.v20170321.DescribeVodDomainLogResponse;
import java.util.List;

/**
 * Method for downloading raw CDN access logs for a specified domain name
 */
public static DescribeVodDomainLogResponse describeVodDomainLog(DefaultAcsClient client) throws Exception {
        DescribeVodDomainLogRequest request = new DescribeVodDomainLogRequest();
        // Specifies the domain name to be queried.
        request.setDomainName("zhptest.alicdn.com");
        // Sets the start time of queried logs, in UTC.
        request.setStartTime("2019-01-15T15:59:59Z");
        // Sets the end time of queried logs, in UTC.
        request.setEndTime("2019-01-20T15:59:58Z");
        // Sets the number of data records per page.
        //request.setPageSize(300L);
        // Sets the page number.
        //request.setPageNumber(1L);

        // Obtains a response.
        return client.getAcsResponse(request);
}

/**
 * Call example
 * @param args
 */
public static void main(String[] args) throws Exception {
        // Initializes the client.
        DefaultAcsClient client = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
        try {
            // Obtains a response.
            DescribeVodDomainLogResponse response = describeVodDomainLog(client);

            // The GUID generated by Alibaba Cloud for the request.
            System.out.println("RequestId:" + response.getRequestId());

            // The details about CDN logs.
            if (response.getDomainLogDetails() ! = null && response.getDomainLogDetails().size() ! = 0) {
                List<DescribeVodDomainLogResponse.DomainLogDetail> domainLogDetails = response.getDomainLogDetails(); 
                for(int i=0; i<domainLogDetails.size(); i++) { 
                    System.out.println("==========================" );
                    System.out.println("DomainName:" + domainLogDetails.get(i).getDomainName());
                    System.out.println("LogCount:" + domainLogDetails.get(i).getLogCount());

                    System.out.println("=== PageInfoDetail Data ===" );
                    System.out.println("PageNumber:" + domainLogDetails.get(i).getPageInfos().getPageNumber());
                    System.out.println("PageSize:" + domainLogDetails.get(i).getPageInfos().getPageSize());
                    System.out.println("Total:" + domainLogDetails.get(i).getPageInfos().getTotal());

                    System.out.println("=== LogInfoDetail Data ===" );
                    List<DescribeVodDomainLogResponse.DomainLogDetail.LogInfoDetail> logInfos = domainLogDetails.get(i).getLogInfos(); 
                    if (logInfos ! = null && logInfos.size() ! = 0) {
                        for (int k=0; k<logInfos.size(); k++) { 
                            System.out.println("LogName:" + logInfos.get(k).getLogName());
                            System.out.println("LogPath:" + logInfos.get(k).getLogPath());
                            System.out.println("LogSize:" + logInfos.get(k).getLogSize());
                            System.out.println("StartTime:" + logInfos.get(k).getStartTime());
                            System.out.println("EndTime:" + logInfos.get(k).getEndTime());
                        }
                    }
                }

            }
        } catch (Exception e) {
            System.out.println("ErrorMessage:" + e.getLocalizedMessage());
        }
}