✨ 日志文件存储.
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package com.orion.ops.framework.common.file;
|
package com.orion.ops.framework.common.file;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文件客户端
|
* 文件客户端
|
||||||
@@ -65,8 +66,6 @@ public interface FileClient {
|
|||||||
*/
|
*/
|
||||||
String upload(String path, InputStream in, boolean autoClose, boolean overrideIfExist) throws Exception;
|
String upload(String path, InputStream in, boolean autoClose, boolean overrideIfExist) throws Exception;
|
||||||
|
|
||||||
// TODO getOutputStream
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检查文件是否存在
|
* 检查文件是否存在
|
||||||
*
|
*
|
||||||
@@ -102,4 +101,23 @@ public interface FileClient {
|
|||||||
*/
|
*/
|
||||||
InputStream getContentInputStream(String path) throws Exception;
|
InputStream getContentInputStream(String path) throws Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取文件输出流
|
||||||
|
*
|
||||||
|
* @param path path
|
||||||
|
* @return stream
|
||||||
|
* @throws Exception Exception
|
||||||
|
*/
|
||||||
|
OutputStream getContentOutputStream(String path) throws Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取文件输出流
|
||||||
|
*
|
||||||
|
* @param path path
|
||||||
|
* @param append append
|
||||||
|
* @return stream
|
||||||
|
* @throws Exception Exception
|
||||||
|
*/
|
||||||
|
OutputStream getContentOutputStream(String path, boolean append) throws Exception;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import com.orion.lang.utils.Exceptions;
|
|||||||
import com.orion.ops.framework.common.file.FileClient;
|
import com.orion.ops.framework.common.file.FileClient;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文件客户端工具
|
* 文件客户端工具
|
||||||
@@ -85,8 +86,6 @@ public class FileClientUtils {
|
|||||||
return delegate.upload(path, in, autoClose, overrideIfExist);
|
return delegate.upload(path, in, autoClose, overrideIfExist);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO getOutputStream
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检查文件是否存在
|
* 检查文件是否存在
|
||||||
*
|
*
|
||||||
@@ -130,6 +129,29 @@ public class FileClientUtils {
|
|||||||
return delegate.getContentInputStream(path);
|
return delegate.getContentInputStream(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取文件输出流
|
||||||
|
*
|
||||||
|
* @param path path
|
||||||
|
* @return stream
|
||||||
|
* @throws Exception Exception
|
||||||
|
*/
|
||||||
|
public static OutputStream getContentOutputStream(String path) throws Exception {
|
||||||
|
return delegate.getContentOutputStream(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取文件输出流
|
||||||
|
*
|
||||||
|
* @param path path
|
||||||
|
* @param append append
|
||||||
|
* @return stream
|
||||||
|
* @throws Exception Exception
|
||||||
|
*/
|
||||||
|
public static OutputStream getContentOutputStream(String path, boolean append) throws Exception {
|
||||||
|
return delegate.getContentOutputStream(path, append);
|
||||||
|
}
|
||||||
|
|
||||||
public static void setDelegate(FileClient delegate) {
|
public static void setDelegate(FileClient delegate) {
|
||||||
if (FileClientUtils.delegate != null) {
|
if (FileClientUtils.delegate != null) {
|
||||||
// unmodified
|
// unmodified
|
||||||
|
|||||||
@@ -48,4 +48,13 @@ public class OrionStorageAutoConfiguration {
|
|||||||
return new LocalFileClient(config.getLocal());
|
return new LocalFileClient(config.getLocal());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return 日志文件客户端
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnProperty(value = "orion.storage.logs.enabled", havingValue = "true")
|
||||||
|
public FileClient logsFileClient() {
|
||||||
|
return new LocalFileClient(config.getLogs());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,4 +20,9 @@ public class StorageConfig {
|
|||||||
*/
|
*/
|
||||||
private LocalFileClientConfig local;
|
private LocalFileClientConfig local;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日志文件客户端 配置
|
||||||
|
*/
|
||||||
|
private LocalFileClientConfig logs;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import com.orion.ops.framework.common.file.FileClient;
|
|||||||
import com.orion.ops.framework.common.utils.FileClientUtils;
|
import com.orion.ops.framework.common.utils.FileClientUtils;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -57,14 +58,14 @@ public abstract class AbstractFileClient<Config extends FileClientConfig> implem
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[] getContent(String path) throws Exception {
|
public byte[] getContent(String path) throws Exception {
|
||||||
try (InputStream in = this.doDownload(path)) {
|
try (InputStream in = this.getContentInputStream(path)) {
|
||||||
return Streams.toByteArray(in);
|
return Streams.toByteArray(in);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InputStream getContentInputStream(String path) throws Exception {
|
public OutputStream getContentOutputStream(String path) throws Exception {
|
||||||
return this.doDownload(path);
|
return this.getContentOutputStream(path, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -79,15 +80,6 @@ public abstract class AbstractFileClient<Config extends FileClientConfig> implem
|
|||||||
*/
|
*/
|
||||||
protected abstract String doUpload(String path, InputStream in, boolean autoClose, boolean overrideIfExist) throws Exception;
|
protected abstract String doUpload(String path, InputStream in, boolean autoClose, boolean overrideIfExist) throws Exception;
|
||||||
|
|
||||||
/**
|
|
||||||
* 执行下载操作
|
|
||||||
*
|
|
||||||
* @param path path
|
|
||||||
* @return stream
|
|
||||||
* @throws Exception Exception
|
|
||||||
*/
|
|
||||||
protected abstract InputStream doDownload(String path) throws Exception;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取返回路径 用于客户端返回
|
* 获取返回路径 用于客户端返回
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -31,11 +31,15 @@ public class FileClientConfig {
|
|||||||
/**
|
/**
|
||||||
* 是否拼接时间作为文件夹
|
* 是否拼接时间作为文件夹
|
||||||
*/
|
*/
|
||||||
protected boolean dateDirectory = true;
|
protected boolean dateDirectory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 时间文件夹格式
|
* 时间文件夹格式
|
||||||
*/
|
*/
|
||||||
protected String datePattern = Dates.YMD;
|
protected String datePattern;
|
||||||
|
|
||||||
|
public FileClientConfig() {
|
||||||
|
this.datePattern = Dates.YMD;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import com.orion.lang.utils.Exceptions;
|
|||||||
import com.orion.ops.framework.common.file.FileClient;
|
import com.orion.ops.framework.common.file.FileClient;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 默认文件客户端
|
* 默认文件客户端
|
||||||
@@ -61,6 +62,16 @@ public class PrimaryFileClient implements FileClient {
|
|||||||
return delegate.getContentInputStream(path);
|
return delegate.getContentInputStream(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OutputStream getContentOutputStream(String path) throws Exception {
|
||||||
|
return delegate.getContentOutputStream(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OutputStream getContentOutputStream(String path, boolean append) throws Exception {
|
||||||
|
return delegate.getContentOutputStream(path, append);
|
||||||
|
}
|
||||||
|
|
||||||
public static void setDelegate(FileClient delegate) {
|
public static void setDelegate(FileClient delegate) {
|
||||||
if (PrimaryFileClient.delegate != null) {
|
if (PrimaryFileClient.delegate != null) {
|
||||||
// unmodified
|
// unmodified
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import com.orion.ops.framework.common.constant.Const;
|
|||||||
import com.orion.ops.framework.storage.core.client.AbstractFileClient;
|
import com.orion.ops.framework.storage.core.client.AbstractFileClient;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 本地文件客户端
|
* 本地文件客户端
|
||||||
@@ -20,6 +21,16 @@ public class LocalFileClient extends AbstractFileClient<LocalFileClientConfig> {
|
|||||||
super(config);
|
super(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InputStream getContentInputStream(String path) throws Exception {
|
||||||
|
return Files1.openInputStreamFast(this.getAbsolutePath(path));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OutputStream getContentOutputStream(String path, boolean append) throws Exception {
|
||||||
|
return Files1.openOutputStreamFast(this.getAbsolutePath(path), append);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String doUpload(String path, InputStream in, boolean autoClose, boolean overrideIfExist) {
|
protected String doUpload(String path, InputStream in, boolean autoClose, boolean overrideIfExist) {
|
||||||
// 获取返回文件路径
|
// 获取返回文件路径
|
||||||
@@ -35,11 +46,6 @@ public class LocalFileClient extends AbstractFileClient<LocalFileClientConfig> {
|
|||||||
return returnPath;
|
return returnPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected InputStream doDownload(String path) throws Exception {
|
|
||||||
return Files1.openInputStreamFast(this.getAbsolutePath(path));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isExists(String path) {
|
public boolean isExists(String path) {
|
||||||
return Files1.isFile(this.getAbsolutePath(path));
|
return Files1.isFile(this.getAbsolutePath(path));
|
||||||
|
|||||||
@@ -20,13 +20,18 @@ public class LocalFileClientConfig extends FileClientConfig {
|
|||||||
* <p>
|
* <p>
|
||||||
* 无需 / 结尾
|
* 无需 / 结尾
|
||||||
*/
|
*/
|
||||||
private String storagePath = "";
|
private String storagePath;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 基础路径
|
* 基础路径
|
||||||
* <p>
|
* <p>
|
||||||
* 无需 / 结尾
|
* 无需 / 结尾
|
||||||
*/
|
*/
|
||||||
private String basePath = "";
|
private String basePath;
|
||||||
|
|
||||||
|
public LocalFileClientConfig() {
|
||||||
|
this.storagePath = "";
|
||||||
|
this.basePath = "";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,11 @@
|
|||||||
"name": "orion.storage.local",
|
"name": "orion.storage.local",
|
||||||
"type": "com.orion.ops.framework.storage.core.client.local.LocalFileClientConfig",
|
"type": "com.orion.ops.framework.storage.core.client.local.LocalFileClientConfig",
|
||||||
"sourceType": "com.orion.ops.framework.storage.core.client.local.LocalFileClientConfig"
|
"sourceType": "com.orion.ops.framework.storage.core.client.local.LocalFileClientConfig"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "orion.storage.logs",
|
||||||
|
"type": "com.orion.ops.framework.storage.core.client.local.LocalFileClientConfig",
|
||||||
|
"sourceType": "com.orion.ops.framework.storage.core.client.local.LocalFileClientConfig"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"properties": [
|
"properties": [
|
||||||
@@ -34,7 +39,7 @@
|
|||||||
"name": "orion.storage.local.date-directory",
|
"name": "orion.storage.local.date-directory",
|
||||||
"type": "java.lang.Boolean",
|
"type": "java.lang.Boolean",
|
||||||
"description": "是否拼接时间作为文件夹.",
|
"description": "是否拼接时间作为文件夹.",
|
||||||
"defaultValue": true
|
"defaultValue": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "orion.storage.local.date-pattern",
|
"name": "orion.storage.local.date-pattern",
|
||||||
@@ -51,6 +56,40 @@
|
|||||||
"name": "orion.storage.local.base-path",
|
"name": "orion.storage.local.base-path",
|
||||||
"type": "java.lang.String",
|
"type": "java.lang.String",
|
||||||
"description": "基础路径."
|
"description": "基础路径."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "orion.storage.logs.enabled",
|
||||||
|
"type": "java.lang.Boolean",
|
||||||
|
"description": "是否启用.",
|
||||||
|
"defaultValue": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "orion.storage.logs.timestamp-prefix",
|
||||||
|
"type": "java.lang.Boolean",
|
||||||
|
"description": "是否使用时间戳作为文件名称前缀.",
|
||||||
|
"defaultValue": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "orion.storage.logs.date-directory",
|
||||||
|
"type": "java.lang.Boolean",
|
||||||
|
"description": "是否拼接时间作为文件夹.",
|
||||||
|
"defaultValue": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "orion.storage.logs.date-pattern",
|
||||||
|
"type": "java.lang.Boolean",
|
||||||
|
"description": "时间文件夹格式.",
|
||||||
|
"defaultValue": "yyyy-MM-dd"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "orion.storage.logs.storage-path",
|
||||||
|
"type": "java.lang.String",
|
||||||
|
"description": "存储路径."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "orion.storage.logs.base-path",
|
||||||
|
"type": "java.lang.String",
|
||||||
|
"description": "基础路径."
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -186,8 +186,16 @@ orion:
|
|||||||
primary: true
|
primary: true
|
||||||
enabled: true
|
enabled: true
|
||||||
timestamp-prefix: false
|
timestamp-prefix: false
|
||||||
|
date-directory: false
|
||||||
storage-path: ${user.home}
|
storage-path: ${user.home}
|
||||||
base-path: /orion/storage/orion-ops-pro
|
base-path: /orion/orion-ops-pro/storage
|
||||||
|
# 日志文件存储
|
||||||
|
logs:
|
||||||
|
enabled: true
|
||||||
|
timestamp-prefix: false
|
||||||
|
date-directory: false
|
||||||
|
storage-path: ${user.home}
|
||||||
|
base-path: /orion/orion-ops-pro/logs
|
||||||
security:
|
security:
|
||||||
password-encoder-length: 4
|
password-encoder-length: 4
|
||||||
# 匿名接口
|
# 匿名接口
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ public class ExecRequest extends PageRequest {
|
|||||||
@Schema(description = "执行模板id")
|
@Schema(description = "执行模板id")
|
||||||
private Long templateId;
|
private Long templateId;
|
||||||
|
|
||||||
@NotBlank
|
|
||||||
@Size(max = 128)
|
@Size(max = 128)
|
||||||
@Schema(description = "执行描述")
|
@Schema(description = "执行描述")
|
||||||
private String desc;
|
private String desc;
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import com.orion.lang.utils.json.matcher.NoMatchStrategy;
|
|||||||
import com.orion.lang.utils.json.matcher.ReplacementFormatter;
|
import com.orion.lang.utils.json.matcher.ReplacementFormatter;
|
||||||
import com.orion.lang.utils.json.matcher.ReplacementFormatters;
|
import com.orion.lang.utils.json.matcher.ReplacementFormatters;
|
||||||
import com.orion.lang.utils.time.Dates;
|
import com.orion.lang.utils.time.Dates;
|
||||||
|
import com.orion.ops.framework.common.constant.Const;
|
||||||
import com.orion.ops.framework.common.constant.ErrorMessage;
|
import com.orion.ops.framework.common.constant.ErrorMessage;
|
||||||
import com.orion.ops.framework.common.security.LoginUser;
|
import com.orion.ops.framework.common.security.LoginUser;
|
||||||
import com.orion.ops.framework.common.utils.Valid;
|
import com.orion.ops.framework.common.utils.Valid;
|
||||||
@@ -81,7 +82,7 @@ public class ExecServiceImpl implements ExecService {
|
|||||||
ExecLogDO execLog = ExecLogDO.builder()
|
ExecLogDO execLog = ExecLogDO.builder()
|
||||||
.userId(userId)
|
.userId(userId)
|
||||||
.source(ExecSourceEnum.BATCH.name())
|
.source(ExecSourceEnum.BATCH.name())
|
||||||
.desc(request.getDesc())
|
.desc(Strings.ifBlank(request.getDesc(), Strings.retain(command, 60) + Const.OMIT))
|
||||||
.command(command)
|
.command(command)
|
||||||
.status(ExecStatusEnum.COMPLETED.name())
|
.status(ExecStatusEnum.COMPLETED.name())
|
||||||
.build();
|
.build();
|
||||||
@@ -124,7 +125,7 @@ public class ExecServiceImpl implements ExecService {
|
|||||||
* @return logPath
|
* @return logPath
|
||||||
*/
|
*/
|
||||||
private String buildLogPath(Long logId, Long hostId) {
|
private String buildLogPath(Long logId, Long hostId) {
|
||||||
return "/logs/exec/" + logId + "/" + hostId + ".log";
|
return "/exec/" + logId + "/" + hostId + ".log";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -28,9 +28,6 @@ export const builtinsParams: Array<TemplateParam> = [
|
|||||||
}, {
|
}, {
|
||||||
name: 'execId',
|
name: 'execId',
|
||||||
desc: '执行记录id'
|
desc: '执行记录id'
|
||||||
}, {
|
|
||||||
name: 'execHostId',
|
|
||||||
desc: '执行主机记录id'
|
|
||||||
}, {
|
}, {
|
||||||
name: 'uuid',
|
name: 'uuid',
|
||||||
desc: '生成任务维度 uuid'
|
desc: '生成任务维度 uuid'
|
||||||
|
|||||||
Reference in New Issue
Block a user