Search in sources :

Example 1 with MachineKeyRequest

use of com.orion.ops.entity.request.MachineKeyRequest 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;
    }
}
Also used : EventKeys(com.orion.ops.consts.event.EventKeys) ValueMix(com.orion.ops.utils.ValueMix) MachineSecretKeyVO(com.orion.ops.entity.vo.MachineSecretKeyVO) Date(java.util.Date) MessageConst(com.orion.ops.consts.MessageConst) EventParamsHolder(com.orion.ops.consts.event.EventParamsHolder) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) FileWriters(com.orion.utils.io.FileWriters) ObjectIds(com.orion.id.ObjectIds) MachineSecretKeyDO(com.orion.ops.entity.domain.MachineSecretKeyDO) LimitList(com.orion.lang.collect.LimitList) MachineSecretKeyDAO(com.orion.ops.dao.MachineSecretKeyDAO) PathBuilders(com.orion.ops.utils.PathBuilders) Service(org.springframework.stereotype.Service) MachineKeyRequest(com.orion.ops.entity.request.MachineKeyRequest) Map(java.util.Map) Maps(com.orion.utils.collect.Maps) Const(com.orion.ops.consts.Const) MountKeyStatus(com.orion.ops.consts.machine.MountKeyStatus) DataGrid(com.orion.lang.wrapper.DataGrid) MachineKeyService(com.orion.ops.service.api.MachineKeyService) Resource(javax.annotation.Resource) Valid(com.orion.ops.utils.Valid) Collectors(java.util.stream.Collectors) File(java.io.File) Files1(com.orion.utils.io.Files1) DataQuery(com.orion.ops.utils.DataQuery) Converts(com.orion.utils.convert.Converts) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Base64s(com.orion.utils.codec.Base64s) SessionHolder(com.orion.remote.channel.SessionHolder) Strings(com.orion.utils.Strings) Transactional(org.springframework.transaction.annotation.Transactional) MachineSecretKeyVO(com.orion.ops.entity.vo.MachineSecretKeyVO) MachineSecretKeyDO(com.orion.ops.entity.domain.MachineSecretKeyDO) File(java.io.File)

Aggregations

LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)1 ObjectIds (com.orion.id.ObjectIds)1 LimitList (com.orion.lang.collect.LimitList)1 DataGrid (com.orion.lang.wrapper.DataGrid)1 Const (com.orion.ops.consts.Const)1 MessageConst (com.orion.ops.consts.MessageConst)1 EventKeys (com.orion.ops.consts.event.EventKeys)1 EventParamsHolder (com.orion.ops.consts.event.EventParamsHolder)1 MountKeyStatus (com.orion.ops.consts.machine.MountKeyStatus)1 MachineSecretKeyDAO (com.orion.ops.dao.MachineSecretKeyDAO)1 MachineSecretKeyDO (com.orion.ops.entity.domain.MachineSecretKeyDO)1 MachineKeyRequest (com.orion.ops.entity.request.MachineKeyRequest)1 MachineSecretKeyVO (com.orion.ops.entity.vo.MachineSecretKeyVO)1 MachineKeyService (com.orion.ops.service.api.MachineKeyService)1 DataQuery (com.orion.ops.utils.DataQuery)1 PathBuilders (com.orion.ops.utils.PathBuilders)1 Valid (com.orion.ops.utils.Valid)1 ValueMix (com.orion.ops.utils.ValueMix)1 SessionHolder (com.orion.remote.channel.SessionHolder)1 Strings (com.orion.utils.Strings)1