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