use of com.orion.ops.entity.domain.FileTransferLogDO in project orion-ops by lijiahangmax.
the class PackageFileProcessor method run.
@Override
public void run() {
// 判断是否可以传输
FileTransferLogDO fileTransferLog = fileTransferLogDAO.selectById(packageFile.getId());
if (fileTransferLog == null || !SftpTransferStatus.WAIT.getStatus().equals(fileTransferLog.getTransferStatus())) {
return;
}
transferProcessorManager.addProcessor(fileToken, this);
try {
// 通知状态runnable
this.updateStatus(SftpTransferStatus.RUNNABLE);
// 初始化压缩器
this.compressor = CompressTypeEnum.ZIP.compressor().get();
compressor.setAbsoluteCompressPath(compressPath);
compressor.compressNotify(this::notifyProgress);
// 添加压缩文件
this.initCompressFiles();
// 添加压缩清单
this.initCompressFileRaw();
// 二次检查状态 防止在添加文件过程中取消或者删除
fileTransferLog = fileTransferLogDAO.selectById(packageFile.getId());
if (fileTransferLog == null || !SftpTransferStatus.RUNNABLE.getStatus().equals(fileTransferLog.getTransferStatus())) {
return;
}
// 开始压缩
this.compressor.compress();
// 传输完成通知
this.updateStatus(SftpTransferStatus.FINISH);
} catch (Exception e) {
log.error("sftp压缩文件-出现异常 fileToken: {}, e: {}, message: {}", fileToken, e.getClass().getName(), e.getMessage());
// 程序错误并非传输错误修改状态
if (!userCancel) {
log.error("sftp传输文件-运行异常 fileToken: {}", fileToken, e);
this.updateStatus(SftpTransferStatus.ERROR);
}
e.printStackTrace();
} finally {
this.done = true;
transferProcessorManager.removeProcessor(fileToken);
}
}
use of com.orion.ops.entity.domain.FileTransferLogDO in project orion-ops by lijiahangmax.
the class PackageFileProcessor method initCompressFiles.
/**
* 初始化压缩文件
*/
private void initCompressFiles() {
this.nameMapping = Maps.newLinkedMap();
for (int i = 0; i < fileList.size(); i++) {
FileTransferLogDO fileLog = fileList.get(i);
String remoteFile = fileLog.getRemoteFile();
String localFilePath = Files1.getPath(SystemEnvAttr.SWAP_PATH.getValue(), fileLog.getLocalFile());
if (!Files1.isFile(new File(localFilePath))) {
continue;
}
// 添加mapping
String remoteFileName;
if (nameMapping.containsKey(remoteFile)) {
remoteFileName = remoteFile + "_" + (i + 1);
} else {
remoteFileName = remoteFile;
}
nameMapping.put(remoteFileName, fileLog);
compressor.addFile(remoteFileName, localFilePath);
}
}
use of com.orion.ops.entity.domain.FileTransferLogDO in project orion-ops by lijiahangmax.
the class PackageFileProcessor method updateStatus.
/**
* 通知状态
*
* @param status status
*/
private void updateStatus(SftpTransferStatus status) {
FileTransferLogDO update = new FileTransferLogDO();
update.setId(packageFile.getId());
update.setTransferStatus(status.getStatus());
if (SftpTransferStatus.FINISH.equals(status)) {
// 设置压缩文件实际大小
File compressFile = new File(compressPath);
if (Files1.isFile(compressFile)) {
update.setFileSize(compressFile.length());
update.setCurrentSize(compressFile.length());
} else {
update.setCurrentSize(packageFile.getFileSize());
}
update.setNowProgress(100D);
}
int effect = fileTransferLogDAO.updateById(update);
log.info("sftp传输压缩-更新状态 fileToken: {}, status: {}, effect: {}", fileToken, status, effect);
if (SftpTransferStatus.FINISH.equals(status)) {
// 通知进度
FileTransferNotifyDTO.FileTransferNotifyProgress notifyProgress = FileTransferNotifyDTO.progress(Strings.EMPTY, Files1.getSize(totalSize), "100");
transferProcessorManager.notifySessionProgressEvent(userId, machineId, fileToken, notifyProgress);
}
// 通知状态
transferProcessorManager.notifySessionStatusEvent(userId, machineId, fileToken, status.getStatus());
}
use of com.orion.ops.entity.domain.FileTransferLogDO in project orion-ops by lijiahangmax.
the class PackageFileProcessor method notifyProgress.
/**
* 通知进度
*
* @param name name
*/
private void notifyProgress(String name) {
if (done) {
return;
}
FileTransferLogDO compressedFile = nameMapping.get(name);
if (compressedFile == null) {
return;
}
// 计算进度
long curr = currentSize.addAndGet(compressedFile.getFileSize());
double progress = this.getProgress();
String progressRate = Numbers.setScale(progress, 2);
// 更新进度
FileTransferLogDO update = new FileTransferLogDO();
update.setId(packageFile.getId());
update.setCurrentSize(curr);
update.setNowProgress(progress);
fileTransferLogDAO.updateById(update);
// 通知进度
FileTransferNotifyDTO.FileTransferNotifyProgress notifyProgress = FileTransferNotifyDTO.progress(Strings.EMPTY, Files1.getSize(curr), progressRate);
transferProcessorManager.notifySessionProgressEvent(userId, machineId, fileToken, notifyProgress);
}
use of com.orion.ops.entity.domain.FileTransferLogDO in project orion-ops by lijiahangmax.
the class FileTransferProcessor method transferDoneCallback.
/**
* 传输完成回调
*
* @param pro progress
*/
protected void transferDoneCallback(ByteTransferProgress pro) {
try {
FileTransferLogDO update = new FileTransferLogDO();
update.setId(record.getId());
if (progress.isError()) {
// 非用户取消更新状态
if (!userCancel) {
this.updateStatusAndNotify(SftpTransferStatus.ERROR.getStatus());
}
} else {
String transferCurrent = Files1.getSize(progress.getCurrent());
String transferRate = Files1.getSize(progress.getNowRate());
// notify progress
this.notifyProgress(transferRate, transferCurrent, "100");
// notify status
this.updateStatusAndNotify(SftpTransferStatus.FINISH.getStatus(), 100D, progress.getEnd());
}
} catch (Exception e) {
log.error("sftp-传输完成回调异常 fileToken: {}, digest: {}", fileToken, Exceptions.getDigest(e));
e.printStackTrace();
}
}
Aggregations