云监控-计算资源-云主机列表添加根据数据中心查询虚拟机列表
parent
b2e59808e3
commit
0e02e7ecbb
|
@ -45,6 +45,20 @@ public class VmController {
|
|||
return vmService.list(pager, context, request);
|
||||
}
|
||||
|
||||
/**
|
||||
* 云主机列表By数据中心
|
||||
*
|
||||
* @param pager 分页
|
||||
* @param context 当前用户上下文
|
||||
* @param request HttpServletRequest
|
||||
* @return 云主机列表
|
||||
*/
|
||||
@GetMapping("/listByDataCenter")
|
||||
@Operation(summary = "云主机列表")
|
||||
public GeneralResult listByDataCenter(Pager pager, @Value(Common.REQ_CONTEXT) RequestContext context, HttpServletRequest request) {
|
||||
return vmService.listByDataCenter(pager, context, request);
|
||||
}
|
||||
|
||||
/**
|
||||
* 云主机资源概览
|
||||
*
|
||||
|
|
|
@ -36,4 +36,5 @@ public interface VmService {
|
|||
|
||||
GeneralResult listManagerCce(Pager pager, RequestContext context, HttpServletRequest request);
|
||||
|
||||
GeneralResult listByDataCenter(Pager pager, RequestContext context, HttpServletRequest request);
|
||||
}
|
|
@ -62,6 +62,27 @@ public class VmServiceImpl implements VmService {
|
|||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GeneralResult<?> listByDataCenter(Pager pager, RequestContext context, HttpServletRequest request) {
|
||||
GeneralResult<?> result = cmpCloudServerService.listByDataCenter(pager, request.getHeader(Common.TOKEN));
|
||||
if (result.isFailed()) {
|
||||
return result;
|
||||
}
|
||||
JSONObject data = (JSONObject) result.getData();
|
||||
List<CloudServerModel> list = data.getJSONArray(Common.ROWS).toJavaList(CloudServerModel.class);
|
||||
if (list.isEmpty()) {
|
||||
return result;
|
||||
}
|
||||
// 默认全部开启
|
||||
for (CloudServerModel cloudServerModel : list) {
|
||||
cloudServerModel.setAlarmEnable(true);
|
||||
}
|
||||
Map<String, VmAdapter> adapters = applicationContext.getBeansOfType(VmAdapter.class);
|
||||
adapters.forEach((s, vmAdapter) -> vmAdapter.list(list, context));
|
||||
data.put(Common.ROWS, list);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GeneralResult vmOverview(Long id) {
|
||||
GeneralResult<CloudServer> cloudServer = cmpCloudServerService.detail(id);
|
||||
|
|
|
@ -74,6 +74,25 @@ public class CmpCloudServerService {
|
|||
|
||||
return remoteService.invoke();
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表查询
|
||||
*
|
||||
* @param pager 分页
|
||||
* @param token 如果为null,则使用internal_token内部调用查询
|
||||
* @return 云主机列表
|
||||
*/
|
||||
public GeneralResult<?> listByDataCenter(Pager pager, String token) {
|
||||
Map<String, Object> headers = new HashMap<>(2);
|
||||
if (token == null) {
|
||||
headers.put(BocloudToken.INTERNAL_TOKEN, currentService.getToken());
|
||||
} else {
|
||||
headers.put(Common.TOKEN, token);
|
||||
}
|
||||
RemoteService remoteService = serviceFactory.build(SERVICE, "/v1/vms/vmsOfDataCenter", HttpMethod.GET, headers, pager.toMap(false));
|
||||
|
||||
return remoteService.invoke();
|
||||
}
|
||||
/**
|
||||
* 列表查询
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue