本文介绍通过SMC Java SDK调用ModifySourceServerAttribute修改迁移源的名称和描述。

背景信息

您可以调用ModifySourceServerAttribute接口修改迁移源的名称和描述,详情请参见ModifySourceServerAttribute

代码示例

以下代码适用于修改迁移源的名称和描述:

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.smc.model.v20190601.ModifySourceServerAttributeRequest;
import com.aliyuncs.smc.model.v20190601.ModifySourceServerAttributeResponse;
import com.google.gson.Gson;

public class ModifySourceServerAttribute {
    public static void main(String[] args) {
        //初始化AcsClient实例,设置地域ID及您的AccessKey信息
        DefaultProfile profile = DefaultProfile.getProfile("<region-Id>", "<accessKeyId>", "<accessSecret>");
        IAcsClient client = new DefaultAcsClient(profile);

        //创建API请求,并设置参数
        ModifySourceServerAttributeRequest request = new ModifySourceServerAttributeRequest();
        //迁移源ID
        request.setSourceId("s-bp152mkfswviw7sd****");
        //迁移源名称
        request.setName("MySourceServer");
        //迁移源描述
        request.setDescription("This is a source server.");

        //发送请求获取返回值或处理异常
        try {
            ModifySourceServerAttributeResponse response = client.getAcsResponse(request);
            System.out.println(new Gson().toJson(response));
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
    } 
}

执行结果

{    
    "RequestId": "78A76F74-CA05-4B34-83D2-60F30311B5AD"
}