Search in sources :

Example 6 with SftpExecutor

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

the class SftpServiceImpl method changeGroup.

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

Example 7 with SftpExecutor

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

the class SftpServiceImpl method chown.

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

Example 8 with SftpExecutor

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

the class SftpServiceImpl method remove.

@Override
public void remove(FileRemoveRequest request) {
    SftpExecutor executor = sftpBasicExecutorHolder.getBasicExecutor(request.getSessionToken());
    List<String> paths = request.getPaths();
    synchronized (executor) {
        paths.stream().map(Files1::getPath).forEach(executor::rm);
    }
    // 设置日志参数
    EventParamsHolder.addParams(request);
    EventParamsHolder.addParam(EventKeys.COUNT, paths.size());
}
Also used : SftpExecutor(com.orion.remote.channel.sftp.SftpExecutor)

Example 9 with SftpExecutor

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

the class SftpServiceImpl method mkdir.

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

Example 10 with SftpExecutor

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

the class SftpServiceImpl method download.

@Override
public void download(FileDownloadRequest request) {
    // 获取token信息
    Long machineId = this.getMachineId(request.getSessionToken());
    SftpExecutor executor = sftpBasicExecutorHolder.getBasicExecutor(request.getSessionToken());
    UserDTO user = Currents.getUser();
    Long userId = user.getId();
    // 定义文件转换器
    Function<SftpFile, FileTransferLogDO> convert = file -> {
        // 本地保存路径
        String fileToken = ObjectIds.next();
        // 设置传输信息
        FileTransferLogDO download = new FileTransferLogDO();
        download.setUserId(userId);
        download.setUserName(user.getUsername());
        download.setFileToken(fileToken);
        download.setTransferType(SftpTransferType.DOWNLOAD.getType());
        download.setMachineId(machineId);
        download.setRemoteFile(file.getPath());
        download.setLocalFile(PathBuilders.getSftpDownloadFilePath(fileToken));
        download.setCurrentSize(0L);
        download.setFileSize(file.getSize());
        download.setNowProgress(0D);
        download.setTransferStatus(SftpTransferStatus.WAIT.getStatus());
        return download;
    };
    // 初始化下载信息
    List<FileTransferLogDO> downloadFiles = Lists.newList();
    List<String> paths = request.getPaths();
    for (String path : paths) {
        SftpFile file = executor.getFile(path);
        Valid.notNull(file, Strings.format(MessageConst.FILE_NOT_FOUND, path));
        // 如果是文件夹则递归所有文件
        if (file.isDirectory()) {
            List<SftpFile> childFiles = executor.listFiles(path, true, false);
            childFiles.forEach(f -> downloadFiles.add(convert.apply(f)));
        } else {
            downloadFiles.add(convert.apply(file));
        }
    }
    for (FileTransferLogDO downloadFile : downloadFiles) {
        fileTransferLogDAO.insert(downloadFile);
        // 通知添加
        transferProcessorManager.notifySessionAddEvent(userId, machineId, downloadFile.getFileToken(), downloadFile);
    }
    // 提交下载任务
    for (FileTransferLogDO downloadFile : downloadFiles) {
        IFileTransferProcessor.of(FileTransferHint.transfer(downloadFile)).exec();
    }
    // 设置日志参数
    EventParamsHolder.addParam(EventKeys.MACHINE_ID, machineId);
    EventParamsHolder.addParam(EventKeys.PATHS, paths);
    EventParamsHolder.addParam(EventKeys.COUNT, downloadFiles.size());
}
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) SftpExecutor(com.orion.remote.channel.sftp.SftpExecutor) FileTransferLogDO(com.orion.ops.entity.domain.FileTransferLogDO) UserDTO(com.orion.ops.entity.dto.UserDTO)

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