Search in sources :

Example 1 with IFileTransferProcessor

use of com.orion.ops.handler.sftp.IFileTransferProcessor in project orion-ops by lijiahangmax.

the class SftpServiceImpl method transferReTransfer.

/**
 * 重新传输
 */
private void transferReTransfer(String fileToken, boolean isUpload) {
    // 获取请求文件
    FileTransferLogDO transferLog = this.getTransferLogByToken(fileToken);
    Valid.notNull(transferLog, MessageConst.UNSELECTED_TRANSFER_LOG);
    Long machineId = transferLog.getMachineId();
    // 暂停
    IFileTransferProcessor processor = transferProcessorManager.getProcessor(transferLog.getFileToken());
    if (processor != null) {
        processor.stop();
    }
    if (isUpload) {
        // 删除远程文件
        SftpExecutor executor = sftpBasicExecutorHolder.getBasicExecutor(machineId);
        SftpFile file = executor.getFile(transferLog.getRemoteFile());
        if (file != null) {
            executor.rmFile(transferLog.getRemoteFile());
        }
    } else {
        // 删除本地文件
        String loacalPath = Files1.getPath(SystemEnvAttr.SWAP_PATH.getValue(), transferLog.getLocalFile());
        Files1.delete(loacalPath);
    }
    // 修改进度
    FileTransferLogDO update = new FileTransferLogDO();
    update.setId(transferLog.getId());
    update.setTransferStatus(SftpTransferStatus.WAIT.getStatus());
    update.setNowProgress(0D);
    update.setCurrentSize(0L);
    fileTransferLogDAO.updateById(update);
    // 通知进度
    FileTransferNotifyDTO.FileTransferNotifyProgress progress = FileTransferNotifyDTO.progress(Strings.EMPTY, Files1.getSize(transferLog.getFileSize()), "0");
    transferProcessorManager.notifySessionProgressEvent(transferLog.getUserId(), machineId, transferLog.getFileToken(), progress);
    // 通知状态
    transferProcessorManager.notifySessionStatusEvent(transferLog.getUserId(), machineId, transferLog.getFileToken(), SftpTransferStatus.WAIT.getStatus());
    // 提交下载
    IFileTransferProcessor.of(FileTransferHint.transfer(transferLog)).exec();
}
Also used : SftpFile(com.orion.remote.channel.sftp.SftpFile) SftpExecutor(com.orion.remote.channel.sftp.SftpExecutor) FileTransferLogDO(com.orion.ops.entity.domain.FileTransferLogDO) FileTransferNotifyDTO(com.orion.ops.entity.dto.FileTransferNotifyDTO) IFileTransferProcessor(com.orion.ops.handler.sftp.IFileTransferProcessor)

Example 2 with IFileTransferProcessor

use of com.orion.ops.handler.sftp.IFileTransferProcessor in project orion-ops by lijiahangmax.

the class SftpServiceImpl method transferRemove.

@Override
public void transferRemove(String fileToken) {
    // 获取请求文件
    FileTransferLogDO transferLog = this.getTransferLogByToken(fileToken);
    Valid.notNull(transferLog, MessageConst.UNSELECTED_TRANSFER_LOG);
    // 如果是进行中则需要取消任务
    if (SftpTransferStatus.RUNNABLE.getStatus().equals(transferLog.getTransferStatus())) {
        IFileTransferProcessor processor = transferProcessorManager.getProcessor(fileToken);
        if (processor != null) {
            processor.stop();
        }
    }
    // 逻辑删除
    fileTransferLogDAO.deleteById(transferLog.getId());
}
Also used : FileTransferLogDO(com.orion.ops.entity.domain.FileTransferLogDO) IFileTransferProcessor(com.orion.ops.handler.sftp.IFileTransferProcessor)

Example 3 with IFileTransferProcessor

use of com.orion.ops.handler.sftp.IFileTransferProcessor in project orion-ops by lijiahangmax.

the class SftpServiceImpl method transferPause.

@Override
public void transferPause(String fileToken) {
    // 获取请求文件
    FileTransferLogDO transferLog = this.getTransferLogByToken(fileToken);
    Valid.notNull(transferLog, MessageConst.UNSELECTED_TRANSFER_LOG);
    // 判断状态是否为进行中
    Integer status = transferLog.getTransferStatus();
    Valid.isTrue(SftpTransferStatus.WAIT.getStatus().equals(status) || SftpTransferStatus.RUNNABLE.getStatus().equals(status), MessageConst.ILLEGAL_STATUS);
    // 获取执行器
    IFileTransferProcessor processor = transferProcessorManager.getProcessor(fileToken);
    if (processor != null) {
        // 执行器不为空则终止
        processor.stop();
    } else {
        Integer changeStatus;
        if (SftpTransferType.PACKAGE.getType().equals(transferLog.getTransferType())) {
            changeStatus = SftpTransferStatus.CANCEL.getStatus();
        } else {
            changeStatus = SftpTransferStatus.PAUSE.getStatus();
        }
        // 修改状态
        FileTransferLogDO update = new FileTransferLogDO();
        update.setId(transferLog.getId());
        update.setTransferStatus(changeStatus);
        fileTransferLogDAO.updateById(update);
        // 通知状态
        transferProcessorManager.notifySessionStatusEvent(transferLog.getUserId(), transferLog.getMachineId(), transferLog.getFileToken(), changeStatus);
    }
}
Also used : FileTransferLogDO(com.orion.ops.entity.domain.FileTransferLogDO) IFileTransferProcessor(com.orion.ops.handler.sftp.IFileTransferProcessor)

Example 4 with IFileTransferProcessor

use of com.orion.ops.handler.sftp.IFileTransferProcessor in project orion-ops by lijiahangmax.

the class SftpServiceImpl method transferPauseAll.

@Override
public void transferPauseAll(String sessionToken) {
    // 获取token信息
    Long machineId = this.getMachineId(sessionToken);
    LambdaQueryWrapper<FileTransferLogDO> wrapper = new LambdaQueryWrapper<FileTransferLogDO>().eq(FileTransferLogDO::getUserId, Currents.getUserId()).eq(FileTransferLogDO::getMachineId, machineId).in(FileTransferLogDO::getTransferStatus, SftpTransferStatus.WAIT.getStatus(), SftpTransferStatus.RUNNABLE.getStatus()).in(FileTransferLogDO::getTransferType, SftpTransferType.UPLOAD.getType(), SftpTransferType.DOWNLOAD.getType());
    List<FileTransferLogDO> transferLogs = fileTransferLogDAO.selectList(wrapper);
    for (FileTransferLogDO transferLog : transferLogs) {
        // 修改状态为暂停
        FileTransferLogDO update = new FileTransferLogDO();
        update.setId(transferLog.getId());
        update.setTransferStatus(SftpTransferStatus.PAUSE.getStatus());
        fileTransferLogDAO.updateById(update);
        // 通知状态
        transferProcessorManager.notifySessionStatusEvent(transferLog.getUserId(), machineId, transferLog.getFileToken(), SftpTransferStatus.PAUSE.getStatus());
    }
    // 获取执行器暂停
    for (FileTransferLogDO transferLog : transferLogs) {
        IFileTransferProcessor processor = transferProcessorManager.getProcessor(transferLog.getFileToken());
        if (processor != null) {
            processor.stop();
        }
    }
}
Also used : FileTransferLogDO(com.orion.ops.entity.domain.FileTransferLogDO) IFileTransferProcessor(com.orion.ops.handler.sftp.IFileTransferProcessor) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)

Aggregations

FileTransferLogDO (com.orion.ops.entity.domain.FileTransferLogDO)4 IFileTransferProcessor (com.orion.ops.handler.sftp.IFileTransferProcessor)4 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)1 FileTransferNotifyDTO (com.orion.ops.entity.dto.FileTransferNotifyDTO)1 SftpExecutor (com.orion.remote.channel.sftp.SftpExecutor)1 SftpFile (com.orion.remote.channel.sftp.SftpFile)1