Search in sources :

Example 11 with SftpExecutor

use of com.orion.remote.channel.sftp.SftpExecutor in project orion-ops by lijiahangmax.

the class SftpServiceImpl method truncate.

@Override
public void truncate(FileTruncateRequest request) {
    String path = Files1.getPath(request.getPath());
    SftpExecutor executor = sftpBasicExecutorHolder.getBasicExecutor(request.getSessionToken());
    synchronized (executor) {
        executor.truncate(path);
    }
    // 设置日志参数
    EventParamsHolder.addParams(request);
}
Also used : SftpExecutor(com.orion.remote.channel.sftp.SftpExecutor)

Example 12 with SftpExecutor

use of com.orion.remote.channel.sftp.SftpExecutor in project orion-ops by lijiahangmax.

the class SftpServiceImpl method list.

private FileListVO list(String path, Boolean all, SftpExecutor executor) {
    synchronized (executor) {
        List<SftpFile> fileList;
        if (all == null || !all) {
            // 不查询隐藏文件
            fileList = executor.listFilesFilter(path, f -> !f.getName().startsWith("."), false, true);
        } else {
            // 查询隐藏文件
            fileList = executor.ll(path);
        }
        // 返回
        FileListVO fileListVO = new FileListVO();
        List<FileDetailVO> files = Converts.toList(fileList, FileDetailVO.class);
        fileListVO.setPath(path);
        fileListVO.setFiles(files);
        return fileListVO;
    }
}
Also used : SftpFile(com.orion.remote.channel.sftp.SftpFile) EventKeys(com.orion.ops.consts.event.EventKeys) IFileTransferProcessor(com.orion.ops.handler.sftp.IFileTransferProcessor) MessageConst(com.orion.ops.consts.MessageConst) EventParamsHolder(com.orion.ops.consts.event.EventParamsHolder) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) ObjectIds(com.orion.id.ObjectIds) Function(java.util.function.Function) TransferProcessorManager(com.orion.ops.handler.sftp.TransferProcessorManager) FileTransferHint(com.orion.ops.handler.sftp.hint.FileTransferHint) PathBuilders(com.orion.ops.utils.PathBuilders) FileTransferLogVO(com.orion.ops.entity.vo.FileTransferLogVO) SftpBasicExecutorHolder(com.orion.ops.handler.sftp.SftpBasicExecutorHolder) Service(org.springframework.stereotype.Service) Arrays1(com.orion.utils.Arrays1) RedisTemplate(org.springframework.data.redis.core.RedisTemplate) FileOpenVO(com.orion.ops.entity.vo.sftp.FileOpenVO) KeyConst(com.orion.ops.consts.KeyConst) Const(com.orion.ops.consts.Const) SftpFile(com.orion.remote.channel.sftp.SftpFile) FileDetailVO(com.orion.ops.entity.vo.sftp.FileDetailVO) SftpTransferType(com.orion.ops.consts.sftp.SftpTransferType) SftpTransferStatus(com.orion.ops.consts.sftp.SftpTransferStatus) com.orion.ops.entity.request.sftp(com.orion.ops.entity.request.sftp) UUIds(com.orion.id.UUIds) Resource(javax.annotation.Resource) SftpService(com.orion.ops.service.api.SftpService) Valid(com.orion.ops.utils.Valid) Collectors(java.util.stream.Collectors) UserDTO(com.orion.ops.entity.dto.UserDTO) Files1(com.orion.utils.io.Files1) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) Converts(com.orion.utils.convert.Converts) List(java.util.List) SftpPackageType(com.orion.ops.consts.sftp.SftpPackageType) SystemEnvAttr(com.orion.ops.consts.system.SystemEnvAttr) FileTransferLogDAO(com.orion.ops.dao.FileTransferLogDAO) FileListVO(com.orion.ops.entity.vo.sftp.FileListVO) FileTransferLogDO(com.orion.ops.entity.domain.FileTransferLogDO) Lists(com.orion.utils.collect.Lists) MachineInfoService(com.orion.ops.service.api.MachineInfoService) Currents(com.orion.ops.utils.Currents) FileTransferNotifyDTO(com.orion.ops.entity.dto.FileTransferNotifyDTO) SftpExecutor(com.orion.remote.channel.sftp.SftpExecutor) Strings(com.orion.utils.Strings) FileListVO(com.orion.ops.entity.vo.sftp.FileListVO) FileDetailVO(com.orion.ops.entity.vo.sftp.FileDetailVO)

Example 13 with SftpExecutor

use of com.orion.remote.channel.sftp.SftpExecutor in project orion-ops by lijiahangmax.

the class SftpServiceImpl method open.

@Override
public FileOpenVO open(Long machineId) {
    // 获取当前用户
    Long userId = Currents.getUserId();
    // 生成token
    String sessionToken = this.generatorSessionToken(userId, machineId);
    SftpExecutor executor = sftpBasicExecutorHolder.getBasicExecutor(sessionToken);
    // 查询列表
    String path = executor.getHome();
    FileListVO list = this.list(path, false, executor);
    // 返回数据
    FileOpenVO openVO = new FileOpenVO();
    openVO.setSessionToken(sessionToken);
    openVO.setHome(path);
    openVO.setCharset(executor.getCharset());
    openVO.setPath(list.getPath());
    openVO.setFiles(list.getFiles());
    // 设置日志参数
    EventParamsHolder.addParam(EventKeys.MACHINE_NAME, machineInfoService.getMachineName(machineId));
    return openVO;
}
Also used : SftpExecutor(com.orion.remote.channel.sftp.SftpExecutor) FileListVO(com.orion.ops.entity.vo.sftp.FileListVO) FileOpenVO(com.orion.ops.entity.vo.sftp.FileOpenVO)

Example 14 with SftpExecutor

use of com.orion.remote.channel.sftp.SftpExecutor in project orion-ops by lijiahangmax.

the class SftpServiceImpl method chmod.

@Override
public String chmod(FileChmodRequest request) {
    String path = Files1.getPath(request.getPath());
    SftpExecutor executor = sftpBasicExecutorHolder.getBasicExecutor(request.getSessionToken());
    synchronized (executor) {
        executor.chmod(path, request.getPermission());
    }
    // 设置日志参数
    EventParamsHolder.addParams(request);
    // 返回权限
    return Files1.permission10toString(request.getPermission());
}
Also used : SftpExecutor(com.orion.remote.channel.sftp.SftpExecutor)

Example 15 with SftpExecutor

use of com.orion.remote.channel.sftp.SftpExecutor in project orion-ops by lijiahangmax.

the class SftpBasicExecutorHolder method invalidationUnusedExecutor.

/**
 * 无效化一段时间(5分钟)未使用的执行器
 */
@Scheduled(cron = "0 */1 * * * ?")
private void invalidationUnusedExecutor() {
    long curr = System.currentTimeMillis();
    // 查询需要淘汰的executor的key
    List<Long> expireKeys = basicExecutorHolder.keySet().stream().filter(key -> curr > executorUsing.get(key) + Const.MS_S_60 * 5).collect(Collectors.toList());
    // 移除
    expireKeys.forEach(key -> {
        SftpExecutor sftpExecutor = basicExecutorHolder.get(key);
        if (sftpExecutor == null) {
            return;
        }
        log.info("淘汰sftp执行器: {}", key);
        basicExecutorHolder.remove(key);
        sftpExecutor.disconnect();
    });
}
Also used : EventKeys(com.orion.ops.consts.event.EventKeys) Resource(javax.annotation.Resource) SftpService(com.orion.ops.service.api.SftpService) EventParamsHolder(com.orion.ops.consts.event.EventParamsHolder) Scheduled(org.springframework.scheduling.annotation.Scheduled) Collectors(java.util.stream.Collectors) SessionStore(com.orion.remote.channel.SessionStore) Slf4j(lombok.extern.slf4j.Slf4j) Component(org.springframework.stereotype.Component) List(java.util.List) MachineEnvService(com.orion.ops.service.api.MachineEnvService) Map(java.util.Map) MachineInfoService(com.orion.ops.service.api.MachineInfoService) Maps(com.orion.utils.collect.Maps) Const(com.orion.ops.consts.Const) SftpExecutor(com.orion.remote.channel.sftp.SftpExecutor) SftpExecutor(com.orion.remote.channel.sftp.SftpExecutor) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Aggregations

SftpExecutor (com.orion.remote.channel.sftp.SftpExecutor)15 FileListVO (com.orion.ops.entity.vo.sftp.FileListVO)4 SftpFile (com.orion.remote.channel.sftp.SftpFile)4 Const (com.orion.ops.consts.Const)3 EventKeys (com.orion.ops.consts.event.EventKeys)3 EventParamsHolder (com.orion.ops.consts.event.EventParamsHolder)3 FileTransferLogDO (com.orion.ops.entity.domain.FileTransferLogDO)3 FileTransferNotifyDTO (com.orion.ops.entity.dto.FileTransferNotifyDTO)3 FileDetailVO (com.orion.ops.entity.vo.sftp.FileDetailVO)3 FileOpenVO (com.orion.ops.entity.vo.sftp.FileOpenVO)3 IFileTransferProcessor (com.orion.ops.handler.sftp.IFileTransferProcessor)3 MachineInfoService (com.orion.ops.service.api.MachineInfoService)3 SftpService (com.orion.ops.service.api.SftpService)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 Resource (javax.annotation.Resource)3 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)2 ObjectIds (com.orion.id.ObjectIds)2 UUIds (com.orion.id.UUIds)2 KeyConst (com.orion.ops.consts.KeyConst)2