查询实例总数
parent
1f83038120
commit
a816dffe8c
|
@ -70,6 +70,7 @@ import com.megatron.framework.lock.AutoCloseLock;
|
|||
import com.megatron.framework.lock.LockFactory;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
|
||||
/**
|
||||
* @author 胡立伟
|
||||
|
@ -437,44 +438,44 @@ public class ModuleServiceImpl implements ModuleService {
|
|||
//用countDownLatch是为了加快速度
|
||||
CountDownLatch countDownLatch = new CountDownLatch(rootGroups.size());
|
||||
|
||||
Map<String,Object> resultMap = new HashMap<>();
|
||||
Map<String, Object> resultMap = new HashMap<>();
|
||||
|
||||
for (ModuleGroup rootGroup : rootGroups) {
|
||||
//获取每个模型的所有实例总数
|
||||
getInstaceCount(rootGroup,resultMap,countDownLatch);
|
||||
getInstaceCount(rootGroup, resultMap, countDownLatch, context.getTarget());
|
||||
}
|
||||
countDownLatch.await();
|
||||
|
||||
|
||||
//查询云主机总数
|
||||
Pager pager = new Pager();
|
||||
pager.setPage(1);
|
||||
pager.setRows(Integer.MAX_VALUE);
|
||||
List<Param> paramList = new ArrayList<>();
|
||||
Param param = new Param();
|
||||
param.setParam(MapTools.simpleMap("isTemplate",false));
|
||||
param.setParam(MapTools.simpleMap("isTemplate", false));
|
||||
param.setSign(Sign.EQ);
|
||||
paramList.add(param);
|
||||
pager.setParams(paramList);
|
||||
GeneralResult<JSONObject> result = cmpInternalService.list(pager.toMap());
|
||||
if(result.isFailed()){
|
||||
if (result.isFailed()) {
|
||||
log.info("list:{}", JSON.toJSONString(result));
|
||||
return new GeneralResult(false,"查询失败");
|
||||
return new GeneralResult(false, "查询失败");
|
||||
}
|
||||
|
||||
resultMap.put("vm",result.getData().getInteger("total"));
|
||||
resultMap.put("vm", result.getData().getInteger("total"));
|
||||
|
||||
return new GeneralResult<>(true, resultMap,"查询成功");
|
||||
return new GeneralResult<>(true, resultMap, "查询成功");
|
||||
} catch (Exception e) {
|
||||
log.info("查询失败", e);
|
||||
return new GeneralResult<>(false, "查询失败");
|
||||
}
|
||||
}
|
||||
|
||||
private void getInstaceCount(ModuleGroup rootGroup, Map<String, Object> resultMap, CountDownLatch countDownLatch) {
|
||||
private void getInstaceCount(ModuleGroup rootGroup, Map<String, Object> resultMap, CountDownLatch countDownLatch, Long userId) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
//获取当前ModuleGroup下所有的modle
|
||||
Pager pager = new Pager();
|
||||
GeneralResult<GridBean<CiModule>> modelList = getModelList(pager);
|
||||
|
@ -483,12 +484,22 @@ public class ModuleServiceImpl implements ModuleService {
|
|||
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<Param> paramList = new ArrayList<>();
|
||||
Param param = new Param();
|
||||
param.setParam(MapTools.simpleMap("moduleId", model.getId()));
|
||||
boolean adminRole = instanceService.checkAdminRole(userId);
|
||||
int count = instanceRepository.count((List<Param>) param, table, valueTable, userId, adminRole);
|
||||
total+=count;
|
||||
}
|
||||
resultMap.put(rootGroup.getCode(), total);
|
||||
} catch (Exception e) {
|
||||
log.info("查询失败", e);
|
||||
}
|
||||
resultMap.put("","");
|
||||
countDownLatch.countDown();
|
||||
}
|
||||
}).start();
|
||||
|
|
Loading…
Reference in New Issue