云监控-计算资源-云主机列表添加根据数据中心查询虚拟机列表

develop
bayuzhen 2024-11-07 11:31:35 +08:00
parent b2e59808e3
commit 0e02e7ecbb
4 changed files with 55 additions and 0 deletions

View File

@ -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);
}
/**
*
*

View File

@ -36,4 +36,5 @@ public interface VmService {
GeneralResult listManagerCce(Pager pager, RequestContext context, HttpServletRequest request);
GeneralResult listByDataCenter(Pager pager, RequestContext context, HttpServletRequest request);
}

View File

@ -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);

View File

@ -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();
}
/**
*
*