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 3bd45c6..9ea1105 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 @@ -435,16 +435,12 @@ public class ModuleServiceImpl implements ModuleService { 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, context.getTarget()); + getInstaceCount(rootGroup, resultMap, context.getTarget()); } - countDownLatch.await(); //查询云主机总数 Pager pager = new Pager(); @@ -471,42 +467,32 @@ public class ModuleServiceImpl implements ModuleService { } } - private void getInstaceCount(ModuleGroup rootGroup, Map resultMap, CountDownLatch countDownLatch, Long userId) { - new Thread(new Runnable() { - @Override - public void run() { - try { - log.info("rootGroup:{}",JSON.toJSONString(rootGroup)); - //获取当前ModuleGroup下所有的modle - Pager pager = new Pager(); - GeneralResult> modelList = getModelList(pager); - if (modelList.isFailed()) { - log.info("modelList:{}", JSON.toJSONString(modelList)); - countDownLatch.countDown(); - return; - } - Integer total = 0; - for (CiModule model : modelList.getData().getRows()) { - //获取每个模型下所有的实例总数 - String table = CmdbUtils.CMDB_INSTANCE + model.getCode().toLowerCase(); - String valueTable = CmdbUtils.CMDB_INSTANCE_VALUE + model.getCode().toLowerCase(); - List paramList = new ArrayList<>(); - Param param = new Param(); - param.setParam(MapTools.simpleMap("moduleId", model.getId())); - param.setSign(Sign.EQ); - paramList.add(param); - boolean adminRole = instanceService.checkAdminRole(userId); - int count = instanceRepository.count(paramList, table, valueTable, userId, adminRole); - log.info("count:{}",count); - total+=count; - } - resultMap.put(rootGroup.getCode(), total); - } catch (Exception e) { - log.info("查询失败", e); - } - countDownLatch.countDown(); - } - }).start(); + private void getInstaceCount(ModuleGroup rootGroup, Map resultMap, Long userId) throws Exception { + log.info("rootGroup:{}", JSON.toJSONString(rootGroup)); + //获取当前ModuleGroup下所有的modle + Pager pager = new Pager(); + GeneralResult> modelList = getModelList(pager); + if (modelList.isFailed()) { + log.info("modelList:{}", JSON.toJSONString(modelList)); + throw new Exception("查询实例失败"); + return; + } + Integer total = 0; + for (CiModule model : modelList.getData().getRows()) { + //获取每个模型下所有的实例总数 + String table = CmdbUtils.CMDB_INSTANCE + model.getCode().toLowerCase(); + String valueTable = CmdbUtils.CMDB_INSTANCE_VALUE + model.getCode().toLowerCase(); + List paramList = new ArrayList<>(); + Param param = new Param(); + param.setParam(MapTools.simpleMap("moduleId", model.getId())); + param.setSign(Sign.EQ); + paramList.add(param); + boolean adminRole = instanceService.checkAdminRole(userId); + int count = instanceRepository.count(paramList, table, valueTable, userId, adminRole); + log.info("count:{}", count); + total += count; + } + resultMap.put(rootGroup.getCode(), total); } private GeneralResult baseModifyProperty(Long moduleId, List groups, List properties,