diff --git a/bocloud.cms.booter/src/main/java/com/bocloud/cms/booter/controller/VmController.java b/bocloud.cms.booter/src/main/java/com/bocloud/cms/booter/controller/VmController.java index 0922df8..4904acd 100644 --- a/bocloud.cms.booter/src/main/java/com/bocloud/cms/booter/controller/VmController.java +++ b/bocloud.cms.booter/src/main/java/com/bocloud/cms/booter/controller/VmController.java @@ -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); + } + /** * 云主机资源概览 * diff --git a/bocloud.cms.service/src/main/java/com/bocloud/cms/intf/VmService.java b/bocloud.cms.service/src/main/java/com/bocloud/cms/intf/VmService.java index a33db72..ef1b235 100644 --- a/bocloud.cms.service/src/main/java/com/bocloud/cms/intf/VmService.java +++ b/bocloud.cms.service/src/main/java/com/bocloud/cms/intf/VmService.java @@ -36,4 +36,5 @@ public interface VmService { GeneralResult listManagerCce(Pager pager, RequestContext context, HttpServletRequest request); + GeneralResult listByDataCenter(Pager pager, RequestContext context, HttpServletRequest request); } \ No newline at end of file diff --git a/bocloud.cms.service/src/main/java/com/bocloud/cms/service/VmServiceImpl.java b/bocloud.cms.service/src/main/java/com/bocloud/cms/service/VmServiceImpl.java index 20899a0..046d049 100644 --- a/bocloud.cms.service/src/main/java/com/bocloud/cms/service/VmServiceImpl.java +++ b/bocloud.cms.service/src/main/java/com/bocloud/cms/service/VmServiceImpl.java @@ -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 list = data.getJSONArray(Common.ROWS).toJavaList(CloudServerModel.class); + if (list.isEmpty()) { + return result; + } + // 默认全部开启 + for (CloudServerModel cloudServerModel : list) { + cloudServerModel.setAlarmEnable(true); + } + Map 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 = cmpCloudServerService.detail(id); diff --git a/bocloud.cms.service/src/main/java/com/bocloud/cms/service/internal/CmpCloudServerService.java b/bocloud.cms.service/src/main/java/com/bocloud/cms/service/internal/CmpCloudServerService.java index 7499643..e408e6d 100644 --- a/bocloud.cms.service/src/main/java/com/bocloud/cms/service/internal/CmpCloudServerService.java +++ b/bocloud.cms.service/src/main/java/com/bocloud/cms/service/internal/CmpCloudServerService.java @@ -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 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(); + } /** * 列表查询 *