diff --git a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/instance/impl/InstanceServiceImpl.java b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/instance/impl/InstanceServiceImpl.java index 502aaf8..7d46a8a 100644 --- a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/instance/impl/InstanceServiceImpl.java +++ b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/instance/impl/InstanceServiceImpl.java @@ -207,6 +207,11 @@ public class InstanceServiceImpl implements InstanceService { String table = CmdbUtils.CMDB_INSTANCE + moduleCode.toLowerCase(); String valueTable = CmdbUtils.CMDB_INSTANCE_VALUE + moduleCode.toLowerCase(); boolean hasAdminRole = checkAdminRole(userId); + log.info("pager:{}",JSON.toJSONString(pager)); + log.info("table:{}",JSON.toJSONString(table)); + log.info("valueTable:{}",JSON.toJSONString(valueTable)); + log.info("userId:{}",JSON.toJSONString(userId)); + log.info("hasAdminRole:{}",JSON.toJSONString(hasAdminRole)); int total = instanceRepository.count(pager.getParams(), table, valueTable, userId, hasAdminRole); list = this.instanceRepository.list(pager, table, valueTable, userId, hasAdminRole); convertInstanceValue(list, moduleId, userId, hasAdminRole); diff --git a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/impl/ModuleServiceImpl.java b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/impl/ModuleServiceImpl.java index 2df4d5a..7e3c9b7 100644 --- a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/impl/ModuleServiceImpl.java +++ b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/impl/ModuleServiceImpl.java @@ -10,6 +10,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -430,17 +431,20 @@ public class ModuleServiceImpl implements ModuleService { List nameList = Arrays.asList("网络设备", "物理服务器", "安全设备"); //查询根节点 List rootGroups = moduleGroupRepository.queryRootInName(nameList); - log.info("moduleGroups:{}", JSON.toJSONString(rootGroups)); + log.info("rootGroups:{}", JSON.toJSONString(rootGroups)); + log.info("context:{}", JSON.toJSONString(context)); - //查询出所有根节点下的子节点 + //用countDownLatch是为了加快速度 + CountDownLatch countDownLatch = new CountDownLatch(rootGroups.size()); + + Map resultMap = new HashMap<>(); + + for (ModuleGroup rootGroup : rootGroups) { + //获取每个模型的所有实例总数 + getInstaceCount(rootGroup,resultMap,countDownLatch); + } + countDownLatch.await(); - List rootGroupIds = rootGroups.stream().map(ModuleGroup::getId).collect(Collectors.toList()); - // 获取模型分组所有数据 - List moduleGroups = moduleGroupRepository.all(); - // 获取根节点的子节点集合 - List children = moduleGroups.stream().filter(item -> rootGroupIds.contains(item.getParentId())) - .collect(Collectors.toList()); - log.info("children:{}", JSON.toJSONString(children)); //查询云主机总数 Pager pager = new Pager(); @@ -458,7 +462,6 @@ public class ModuleServiceImpl implements ModuleService { return new GeneralResult(false,"查询失败"); } - Map resultMap = new HashMap<>(); resultMap.put("vm",result.getData().getInteger("total")); return new GeneralResult<>(true, resultMap,"查询成功"); @@ -468,6 +471,29 @@ public class ModuleServiceImpl implements ModuleService { } } + private void getInstaceCount(ModuleGroup rootGroup, Map resultMap, CountDownLatch countDownLatch) { + new Thread(new Runnable() { + @Override + public void run() { + //获取当前ModuleGroup下所有的modle + Pager pager = new Pager(); + GeneralResult> modelList = getModelList(pager); + if (modelList.isFailed()) { + log.info("modelList:{}", JSON.toJSONString(modelList)); + countDownLatch.countDown(); + return; + } + for (CiModule model : modelList.getData().getRows()) { + //获取每个模型下所有的实例总数 + String table = CmdbUtils.CMDB_INSTANCE + model.getCode().toLowerCase(); + String valueTable = CmdbUtils.CMDB_INSTANCE_VALUE + model.getCode().toLowerCase(); + } + resultMap.put("",""); + countDownLatch.countDown(); + } + }).start(); + } + private GeneralResult baseModifyProperty(Long moduleId, List groups, List properties, Long userId) throws Exception { CiModule module = moduleRepository.query(moduleId);