This topic describes how to use Alibaba Cloud SDK for Java to call DescribeDisks to obtain disk information.

Prerequisites

Before you begin, make sure that you have completed the following:
  • To use Alibaba Cloud SDK for Java, you must have an Alibaba Cloud account and an AccessKey pair. You can create and view your AccessKey pair on the AccessKey Management page in the Alibaba Cloud Console.
  • You have installed Alibaba Cloud SDK for Java. For SDK version details, visit Alibaba Cloud SDK.
    <dependencies>
        <! -- https://mvnrepository.com/artifact/com.aliyun/aliyun-java-sdk-core -->
        <dependency>
            <groupId>com.aliyun</groupId>
            <artifactId>aliyun-java-sdk-core</artifactId>
            <version>4.4.3</version>
        </dependency>
        <! -- https://mvnrepository.com/artifact/com.aliyun/aliyun-java-sdk-ecs-->
        <dependency>
            <groupId>com.aliyun</groupId>
            <artifactId>aliyun-java-sdk-ecs</artifactId>
            <version>4.17.4</version>
        </dependency>
    </dependencies>

Sample code

This topic uses the following sample code as an example:
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.FormatType;
import com.aliyuncs.ecs.model.v20140526.*;
 public class DescribeDisks {


        private static final String ACCESS_KEY = "<your-access-key>";
        private static final String ACCESS_SECRET = "<your-access-key_Secret>";
        private static IAcsClient client = null;

        static {
            // Create a profile
            IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", ACCESS_KEY, ACCESS_SECRET);
            // Create an Acs client
            client = new DefaultAcsClient(profile);
        }

        public static FormatType describeDisks(FormatType formatType) {
            // Create a request
            DescribeDisksRequest request = new DescribeDisksRequest();
            request.setAcceptFormat(formatType);
            request.setInstanceId("<instance-ID");
                    request.setRegionId("regionID");
            try {
                // Obtain returned content
                return client.doAction(request).getHttpContentType();
                // Obtain returned object
                //return client.getAcsResponse(request);
            } catch (ServerException e) {
                e.printStackTrace();
                return null;
            } catch (ClientException e) {
                e.printStackTrace();
                return null;
            }
        }

        public static void main(String[] args) {
            System.out.println(describeDisks(FormatType.JSON));
        }

     }