百度MapReduce BMR

    InstanceGroup(实例组)

    查询实例组列表

    如下代码可根据集群ID获取其实例组信息:

    public void listInstanceGroups(BmrClient client, String clusterId) {
        try {
            // 方法 1. 罗列指定集群ID相关的实例组
            ListInstanceGroupsResponse response1 = client.listInstanceGroups(clusterId);
            // 方法 2. 自定义ListInstanceGroupsRequest对象的查询请求 
            ListInstanceGroupsResponse response2 = client.listInstanceGroups(new ListInstanceGroupsRequest().withClusterId(clusterId));
            for (InstanceGroup instanceGroup: response2.getInstanceGroups()) {
                System.out.println(instanceGroup.getId() + "," +  instanceGroup.getType()
                        + "," + instanceGroup.getInstanceType() + "," + instanceGroup.getRequestedInstanceCount()
                        + "," + instanceGroup.getRootDiskSizeInGB() + "," + instanceGroup.getRootDiskMediumType());
                for (CdsItem cdsItem: instanceGroup.getCds()){
                    System.out.println("cdsItem " + cdsItem.getSizeInGB() + “,” + cdsItem.getMediumType());
                }
            }
        } catch (BceServiceException e){
            System.out.println("List instance group failed: " + e.getErrorMessage());
        }
    }

    请求返回的ListInstanceGroupsResponse对象包含了相关的实例组对象数组List, 获取实例组对象数组的方法为response.getInstanceGroups()。实例组对象InstanceGroup的属性包括了实例组类型、实例数、系统盘容量大小等配置信息,每个属性均有对应的getter访问器方法。其中系统盘存储介质类型支持ssd(SSD云磁盘)、premium_ssd(高性能云磁盘)两种。

    public class InstanceGroup {
        private String id;                                     //实例组ID
        private String instanceType;                           //实例组套餐类型
        private String name;                                   //实例组名称
        private String type;                                   //实例组类型
        private int requestedInstanceCount;                    //请求的实例个数
        private int rootDiskSizeInGB;                          //系统盘容量大小
        private String rootDiskMediumType;                     //系统盘存储介质类型 
        private List<CdsItem> cds;                             //云磁盘信息列表
    }

    云盘对象CdsItem的属性包括云盘容量大小和云盘存储介质,每个属性均有对应的getter访问器方法,其中云存储介质支持premium_ssd(SSD云磁盘),ssd(高性能云磁盘)两种类型。

    public class CdsItem {
        private int sizeInGB;                                 //云磁盘容量大小
        private String mediumType;                            //云磁盘存储介质 
    }

    修改实例组配置

    BMR支持对CORE、TASK节点进行配置变更,示例代码如下:

    public void modifyInstanceGroups(BmrClient bmrClient, String clusterId, String coreGroupId, String taskGroupId) {
        // 可省略无须修改的实例组
        List<ModifyInstanceGroupConfig> instanceGroups = new ArrayList<ModifyInstanceGroupConfig>();
        // core group
        ModifyInstanceGroupConfig coreGroup = new ModifyInstanceGroupConfig();
        coreGroup.setId(coreGroupId);
        coreGroup.setInstanceCount(4);
        instanceGroups.add(coreGroup);
        // task group
        ModifyInstanceGroupConfig taskGroup = new ModifyInstanceGroupConfig();
        taskGroup.setId(taskGroupId);
        taskGroup.setInstanceCount(2);
        instanceGroups.add(taskGroup);
    
        String clientToken = UUID.randomUUID().toString();
        try {
            bmrClient.modifyInstanceGroups(
                    new ModifyInstanceGroupRequest()
                            .withClusterId(clusterId)
                            .withInstanceGroups(instanceGroups)
                            .withClientToken(clientToken)
            );
        } catch (BceServiceException e) {
            System.out.println("Modify instance groups failed: " + e.getErrorMessage());
        }
    }
    上一篇
    Instance(实例)
    下一篇
    Cluster(集群)