...
|
...
|
@@ -12,6 +12,7 @@ import com.yoho.ops.cmdb.models.Host; |
|
|
import com.yoho.ops.cmdb.qcloud.constant.QcloudConstant;
|
|
|
import com.yoho.ops.cmdb.qcloud.model.QcloudAutoScalingGroup;
|
|
|
import com.yoho.ops.cmdb.qcloud.model.QcloudInstanceSet;
|
|
|
import com.yoho.ops.cmdb.qcloud.model.QcloudResponse;
|
|
|
import com.yoho.ops.cmdb.qcloud.model.QcloudScalingInstancesSet;
|
|
|
import com.yoho.ops.cmdb.qcloud.util.QcloudSdkUtil;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
...
|
...
|
@@ -134,17 +135,6 @@ public class QcloudClientFactory { |
|
|
if(joQcloudScalingInstancesData != null&&joQcloudScalingInstancesData.get("scalingInstancesSet")!=null){
|
|
|
scalingInstancesSets=JSON.parseArray(joQcloudScalingInstancesData.getString("scalingInstancesSet"), QcloudScalingInstancesSet.class);
|
|
|
}
|
|
|
/* if(scalingInstancesSets!=null&&scalingInstancesSets.size()>0){
|
|
|
List<String> scalingInstanceIDs=new ArrayList<String>();
|
|
|
scalingInstancesSets.forEach(scalingInstancesSet->{
|
|
|
//System.out.println(scalingInstancesSet.getInstanceId());
|
|
|
scalingInstanceIDs.add(scalingInstancesSet.getInstanceId());
|
|
|
});
|
|
|
List<QcloudInstanceSet> instanceList=this.getInstancesSet(scalingInstanceIDs);
|
|
|
instanceList.forEach(inst->{
|
|
|
// System.out.println(inst.getUnInstanceId());
|
|
|
});
|
|
|
}*/
|
|
|
}catch (Exception e){
|
|
|
logger.error(" - QcloudClientFactory - getScalingInstancesSet- error", e);
|
|
|
}
|
...
|
...
|
@@ -153,23 +143,6 @@ public class QcloudClientFactory { |
|
|
|
|
|
/**
|
|
|
* 接口:DescribeInstances
|
|
|
* @param instanceId 实例ID
|
|
|
* @return
|
|
|
*/
|
|
|
/*private List<QcloudInstanceSet> getInstancesSet(String instanceId){
|
|
|
List<QcloudInstanceSet> instanceSets = null;
|
|
|
if(StringUtils.isBlank(instanceId)){
|
|
|
return null;
|
|
|
}
|
|
|
List<String> instanceIds = new ArrayList<>();
|
|
|
instanceIds.add(instanceId);
|
|
|
instanceSets = getInstancesSet(instanceIds);
|
|
|
|
|
|
return instanceSets;
|
|
|
}
|
|
|
*/
|
|
|
/**
|
|
|
* 接口:DescribeInstances
|
|
|
* @param scalingInstanceIds 实例ID集合
|
|
|
* @return
|
|
|
*/
|
...
|
...
|
@@ -199,5 +172,66 @@ public class QcloudClientFactory { |
|
|
}
|
|
|
|
|
|
|
|
|
public List<Host> getAllInstancesSet(){
|
|
|
List<Host> allHost=new ArrayList<Host>();
|
|
|
//List<QcloudInstanceSet> instanceSets_all = new ArrayList<QcloudInstanceSet>();
|
|
|
Set<String> instanceIDs=new HashSet<String>();
|
|
|
try{
|
|
|
// 第一步,先获取第一页的数据
|
|
|
int Limit=20;
|
|
|
int pageNumber=0;
|
|
|
//int Offset=0;
|
|
|
TreeMap<String, Object> params = new TreeMap<>();
|
|
|
params.put("Offset", pageNumber*Limit);
|
|
|
params.put("Limit",100);
|
|
|
logger.info("--------------getAllInstancesSet - start");
|
|
|
String rootJson = QcloudSdkUtil.getCommonData(new Cvm(), "GET", QcloudConstant.QCLOUD_API_INSTANCE_FUN, params, true);
|
|
|
if(StringUtils.isBlank(rootJson)){
|
|
|
return null;
|
|
|
}
|
|
|
QcloudResponse rootObj = JSON.parseObject(rootJson, QcloudResponse.class);
|
|
|
int total=rootObj.getTotalCount();
|
|
|
if(rootObj != null&&rootObj.getInstanceSet()!=null){
|
|
|
rootObj.getInstanceSet().forEach(inst->{
|
|
|
if(!instanceIDs.contains(inst.getUnInstanceId())){
|
|
|
instanceIDs.add(inst.getUnInstanceId());
|
|
|
Host host=new Host(DataCenter.qcloud,inst.getUnInstanceId(), inst.getLanIp(), inst.getInstanceName());
|
|
|
allHost.add(host);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
//第二步,分页获取
|
|
|
if(total>Limit){
|
|
|
pageNumber=1;
|
|
|
int pageCount=(int)Math.ceil(total/(double)Limit) ;
|
|
|
for(;pageNumber<pageCount;pageNumber++){
|
|
|
|
|
|
params.put("Offset", pageNumber*Limit);
|
|
|
|
|
|
rootJson = QcloudSdkUtil.getCommonData(new Cvm(), "GET", QcloudConstant.QCLOUD_API_INSTANCE_FUN, params, true);
|
|
|
if(StringUtils.isBlank(rootJson)){
|
|
|
continue;
|
|
|
}
|
|
|
rootObj = JSON.parseObject(rootJson, QcloudResponse.class);
|
|
|
if(rootObj != null&&rootObj.getInstanceSet()!=null){
|
|
|
rootObj.getInstanceSet().forEach(inst -> {
|
|
|
if(!instanceIDs.contains(inst.getUnInstanceId())){
|
|
|
instanceIDs.add(inst.getUnInstanceId());
|
|
|
Host host=new Host(DataCenter.qcloud,inst.getUnInstanceId(), inst.getLanIp(), inst.getInstanceName());
|
|
|
allHost.add(host);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}catch (Exception e){
|
|
|
logger.error(" - QcloudToolServiceImpl - getScalingInstancesSet- error", e);
|
|
|
}
|
|
|
|
|
|
return allHost;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} |
...
|
...
|
|