use of com.orion.lang.wrapper.DataGrid in project orion-ops by lijiahangmax.
the class TerminalSessionManager method getOnlineTerminal.
/**
* session 列表
*
* @param request request
* @return dataGrid
*/
public DataGrid<MachineTerminalManagerVO> getOnlineTerminal(MachineTerminalManagerRequest request) {
List<MachineTerminalManagerVO> sessionList = sessionHolder.values().stream().filter(s -> Optional.ofNullable(request.getToken()).filter(Strings::isNotBlank).map(t -> s.getToken().contains(t)).orElse(true)).filter(s -> Optional.ofNullable(request.getMachineName()).filter(Strings::isNotBlank).map(t -> s.getHint().getMachineName().toLowerCase().contains(t.toLowerCase())).orElse(true)).filter(s -> Optional.ofNullable(request.getMachineTag()).filter(Strings::isNotBlank).map(t -> s.getHint().getMachineTag().contains(t)).orElse(true)).filter(s -> Optional.ofNullable(request.getMachineHost()).filter(Strings::isNotBlank).map(t -> s.getHint().getMachineHost().contains(t)).orElse(true)).filter(s -> Optional.ofNullable(request.getUserId()).map(t -> s.getHint().getUserId().equals(t)).orElse(true)).filter(s -> Optional.ofNullable(request.getUsername()).map(t -> s.getHint().getUsername().toLowerCase().contains(t.toLowerCase())).orElse(true)).filter(s -> Optional.ofNullable(request.getMachineId()).map(t -> s.getHint().getMachineId().equals(t)).orElse(true)).filter(s -> {
if (request.getConnectedTimeStart() == null || request.getConnectedTimeEnd() == null) {
return true;
}
return DateRanges.inRange(request.getConnectedTimeStart(), request.getConnectedTimeEnd(), s.getHint().getConnectedTime());
}).map(s -> {
MachineTerminalManagerVO vo = Converts.to(s.getHint(), MachineTerminalManagerVO.class);
vo.setToken(s.getToken());
return vo;
}).sorted(Comparator.comparing(MachineTerminalManagerVO::getConnectedTime).reversed()).collect(Collectors.toList());
List<MachineTerminalManagerVO> page = Lists.newLimitList(sessionList).limit(request.getLimit()).page(request.getPage());
return DataGrid.of(page, sessionList.size());
}
use of com.orion.lang.wrapper.DataGrid in project orion-ops by lijiahangmax.
the class MachineKeyServiceImpl method listKeys.
@Override
public DataGrid<MachineSecretKeyVO> listKeys(MachineKeyRequest request) {
final int page = request.getPage();
final int limit = request.getLimit();
final boolean checkStatus = request.getMountStatus() != null;
if (checkStatus) {
request.setPage(Const.N_1);
request.setLimit(Const.N_100000);
}
LambdaQueryWrapper<MachineSecretKeyDO> wrapper = new LambdaQueryWrapper<MachineSecretKeyDO>().like(Strings.isNotBlank(request.getName()), MachineSecretKeyDO::getKeyName, request.getName()).like(Strings.isNotBlank(request.getDescription()), MachineSecretKeyDO::getDescription, request.getDescription()).orderByDesc(MachineSecretKeyDO::getCreateTime);
DataGrid<MachineSecretKeyVO> dataGrid = DataQuery.of(machineSecretKeyDAO).page(request).wrapper(wrapper).dataGrid(MachineSecretKeyVO.class);
if (!dataGrid.isEmpty()) {
List<String> loadKeys = SessionHolder.getLoadKeys();
for (MachineSecretKeyVO row : dataGrid.getRows()) {
String path = row.getPath();
boolean isFile = Files1.isFile(new File(MachineKeyService.getKeyPath(path)));
if (isFile) {
boolean match = loadKeys.stream().anyMatch(key -> key.endsWith(path));
if (match) {
row.setMountStatus(MountKeyStatus.MOUNTED.getStatus());
} else {
row.setMountStatus(MountKeyStatus.DUMPED.getStatus());
}
} else {
row.setMountStatus(MountKeyStatus.NOT_FOUND.getStatus());
}
}
}
if (!checkStatus) {
return dataGrid;
} else {
// 手动过滤
List<MachineSecretKeyVO> totalRows = dataGrid.stream().filter(row -> request.getMountStatus().equals(row.getMountStatus())).collect(Collectors.toList());
List<MachineSecretKeyVO> rows = new LimitList<>(totalRows, limit).page(page);
// 封装返回
DataGrid<MachineSecretKeyVO> newDataGrid = DataGrid.of(rows, totalRows.size());
newDataGrid.setPage(page);
newDataGrid.setLimit(limit);
return newDataGrid;
}
}
Aggregations