加速域名管理
更新时间:2023-05-16
新建加速域名
如下代码可以新建一个加速域名:
public void testCreateDomain(CdnClient client) {
String domainName = "my.test.com";
ArrayList<OriginPeer> origin = new ArrayList<OriginPeer>();
origin.add(new OriginPeer().withPeer("1.2.3.4")); // 添加源站 1.2.3.4
origin.add(new OriginPeer().withPeer("2.3.4.5")); // 添加源站 2.3.4.5
CreateDomainRequest request = new CreateDomainRequest()
.withDomain(domainName)
.withOrigin(origin);
CreateDomainResponse response = client.createDomain(request);
System.out.println(response.getCname()); // 创建成功,获取对应的CNAME
}
注意:由于加速域名在所有区域中是唯一的,所以需要保证domain不与其他所有区域上的加速域名名称相同
启用加速域名接口
public void enableDomain(CdnClient client){
String domain="my.test.com";
cdnClient.enableDomain(domain);
}
停用加速域名接口
public void disableDomain(CdnClient client){
String domain="my.test.com";
cdnClient.disableDomain(domain);
}
删除加速域名
如下代码可以删除一个加速域名:
public void deleteDomain (CdnClient client) {
String domain="my.test.com";
client.deleteDomain(domainName);
}
查看加速域名列表
如下代码可以列出用户所有的域名:
public void listDomains (CdnClient client) {
// 获取用户的加速域名列表
List<Domain> domains = client.listDomains().getDomains();
// 遍历加速域名
for (Domain domain : domains) {
System.out.println(domain.getName());
}
}
注意:仅获取域名基础信息
查询用户下所有域名
public void listUserDomains() throws Exception {
String status = "RUNNING";
// 用法1
List<UserDomain> domains = cdnClient.getUserDomains(status).getDomains();
for (UserDomain entry : domains) {
System.out.println(entry.getDomain() + " -- " + entry.getStatus());
}
// 用法2
GetUserDomainsRequest request = new GetUserDomainsRequest();
request.setStatus(status);
request.setRule("");
List<UserDomain> domains = cdnClient.getUserDomains(request).getDomains();
for (UserDomain entry : domains) {
System.out.println(entry.getDomain() + " -- " + entry.getStatus());
}
}
查询域名是否可添加
public void checkDomainValid(){
String domain = "my.test.com";
CheckDomainValidResponse response = cdnClient.checkDomainValid(domain);
System.out.println(response.isValid());
}
查询域名是否备案
public void getIcpStatus() {
String domain = "my.test.com";
GetIcpResponse response = cdnClient.getIcpStatus(domain);
System.out.println(response);
}
单域名配置复制任务提交接口
public void copyDomainConfig() throws Exception {
String originDomain = "my.test.com";
List<String> domains = new ArrayList<String>() {
{
add("my.test2.com");
add("my.test3.com");
add("my.test4.com");
}
};
List<String> configNames = new ArrayList<String>() {
{
add("originConfig");
add("compress");
add("setHttpHeader");
}
};
CopyDomainTaskResponse copyDomainConfigResponse = cdnClient.copyDomainConfig(originDomain, domains, configNames);
System.out.println(copyDomainConfigResponse);
}
查询复制任务状态接口
public void getCopyDomainStatus() throws Exception {
String taskId = "0e5461ac524658668503cfc32230fed9";
CopyDomainTaskStatusResponse copyDomainConfigResponse = cdnClient.getCopyDomainStatus(taskId);
System.out.println(copyDomainConfigResponse.getStatus());
}
查询域名可复制配置项接口
public void getDomainConfigKeys() throws Exception {
String domain = "my.test.com";
DomainConfigKeysResponse domainConfig = cdnClient.getDomainConfigKeys(domain);
System.out.println(domainConfig.getConfigs());
}