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();
}
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());
}
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);
}
}
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();
}
}
}
Aggregations