diff --git a/orion-ops-framework/orion-ops-framework-common/src/main/java/com/orion/ops/framework/common/file/FileClient.java b/orion-ops-framework/orion-ops-framework-common/src/main/java/com/orion/ops/framework/common/file/FileClient.java index 0da9c6bc..eba307e6 100644 --- a/orion-ops-framework/orion-ops-framework-common/src/main/java/com/orion/ops/framework/common/file/FileClient.java +++ b/orion-ops-framework/orion-ops-framework-common/src/main/java/com/orion/ops/framework/common/file/FileClient.java @@ -1,6 +1,7 @@ package com.orion.ops.framework.common.file; 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; - // TODO getOutputStream - /** * 检查文件是否存在 * @@ -102,4 +101,23 @@ public interface FileClient { */ 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; + } diff --git a/orion-ops-framework/orion-ops-framework-common/src/main/java/com/orion/ops/framework/common/utils/FileClientUtils.java b/orion-ops-framework/orion-ops-framework-common/src/main/java/com/orion/ops/framework/common/utils/FileClientUtils.java index 8dec81bd..94200f4a 100644 --- a/orion-ops-framework/orion-ops-framework-common/src/main/java/com/orion/ops/framework/common/utils/FileClientUtils.java +++ b/orion-ops-framework/orion-ops-framework-common/src/main/java/com/orion/ops/framework/common/utils/FileClientUtils.java @@ -4,6 +4,7 @@ import com.orion.lang.utils.Exceptions; import com.orion.ops.framework.common.file.FileClient; import java.io.InputStream; +import java.io.OutputStream; /** * 文件客户端工具 @@ -85,8 +86,6 @@ public class FileClientUtils { return delegate.upload(path, in, autoClose, overrideIfExist); } - // TODO getOutputStream - /** * 检查文件是否存在 * @@ -130,6 +129,29 @@ public class FileClientUtils { 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) { if (FileClientUtils.delegate != null) { // unmodified diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-storage/src/main/java/com/orion/ops/framework/storage/config/OrionStorageAutoConfiguration.java b/orion-ops-framework/orion-ops-spring-boot-starter-storage/src/main/java/com/orion/ops/framework/storage/config/OrionStorageAutoConfiguration.java index cd0d21d7..84f2daad 100644 --- a/orion-ops-framework/orion-ops-spring-boot-starter-storage/src/main/java/com/orion/ops/framework/storage/config/OrionStorageAutoConfiguration.java +++ b/orion-ops-framework/orion-ops-spring-boot-starter-storage/src/main/java/com/orion/ops/framework/storage/config/OrionStorageAutoConfiguration.java @@ -48,4 +48,13 @@ public class OrionStorageAutoConfiguration { return new LocalFileClient(config.getLocal()); } + /** + * @return 日志文件客户端 + */ + @Bean + @ConditionalOnProperty(value = "orion.storage.logs.enabled", havingValue = "true") + public FileClient logsFileClient() { + return new LocalFileClient(config.getLogs()); + } + } diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-storage/src/main/java/com/orion/ops/framework/storage/config/StorageConfig.java b/orion-ops-framework/orion-ops-spring-boot-starter-storage/src/main/java/com/orion/ops/framework/storage/config/StorageConfig.java index b3c52bb1..9195c6df 100644 --- a/orion-ops-framework/orion-ops-spring-boot-starter-storage/src/main/java/com/orion/ops/framework/storage/config/StorageConfig.java +++ b/orion-ops-framework/orion-ops-spring-boot-starter-storage/src/main/java/com/orion/ops/framework/storage/config/StorageConfig.java @@ -20,4 +20,9 @@ public class StorageConfig { */ private LocalFileClientConfig local; + /** + * 日志文件客户端 配置 + */ + private LocalFileClientConfig logs; + } diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-storage/src/main/java/com/orion/ops/framework/storage/core/client/AbstractFileClient.java b/orion-ops-framework/orion-ops-spring-boot-starter-storage/src/main/java/com/orion/ops/framework/storage/core/client/AbstractFileClient.java index 89719b23..52655262 100644 --- a/orion-ops-framework/orion-ops-spring-boot-starter-storage/src/main/java/com/orion/ops/framework/storage/core/client/AbstractFileClient.java +++ b/orion-ops-framework/orion-ops-spring-boot-starter-storage/src/main/java/com/orion/ops/framework/storage/core/client/AbstractFileClient.java @@ -8,6 +8,7 @@ import com.orion.ops.framework.common.file.FileClient; import com.orion.ops.framework.common.utils.FileClientUtils; import java.io.InputStream; +import java.io.OutputStream; import java.util.Date; /** @@ -57,14 +58,14 @@ public abstract class AbstractFileClient implem @Override public byte[] getContent(String path) throws Exception { - try (InputStream in = this.doDownload(path)) { + try (InputStream in = this.getContentInputStream(path)) { return Streams.toByteArray(in); } } @Override - public InputStream getContentInputStream(String path) throws Exception { - return this.doDownload(path); + public OutputStream getContentOutputStream(String path) throws Exception { + return this.getContentOutputStream(path, false); } /** @@ -79,15 +80,6 @@ public abstract class AbstractFileClient implem */ 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; - /** * 获取返回路径 用于客户端返回 * diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-storage/src/main/java/com/orion/ops/framework/storage/core/client/FileClientConfig.java b/orion-ops-framework/orion-ops-spring-boot-starter-storage/src/main/java/com/orion/ops/framework/storage/core/client/FileClientConfig.java index 2fb18959..cd13f9a6 100644 --- a/orion-ops-framework/orion-ops-spring-boot-starter-storage/src/main/java/com/orion/ops/framework/storage/core/client/FileClientConfig.java +++ b/orion-ops-framework/orion-ops-spring-boot-starter-storage/src/main/java/com/orion/ops/framework/storage/core/client/FileClientConfig.java @@ -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; + } } diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-storage/src/main/java/com/orion/ops/framework/storage/core/client/PrimaryFileClient.java b/orion-ops-framework/orion-ops-spring-boot-starter-storage/src/main/java/com/orion/ops/framework/storage/core/client/PrimaryFileClient.java index ec9fbac9..9fff4243 100644 --- a/orion-ops-framework/orion-ops-spring-boot-starter-storage/src/main/java/com/orion/ops/framework/storage/core/client/PrimaryFileClient.java +++ b/orion-ops-framework/orion-ops-spring-boot-starter-storage/src/main/java/com/orion/ops/framework/storage/core/client/PrimaryFileClient.java @@ -4,6 +4,7 @@ import com.orion.lang.utils.Exceptions; import com.orion.ops.framework.common.file.FileClient; import java.io.InputStream; +import java.io.OutputStream; /** * 默认文件客户端 @@ -61,6 +62,16 @@ public class PrimaryFileClient implements FileClient { 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) { if (PrimaryFileClient.delegate != null) { // unmodified diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-storage/src/main/java/com/orion/ops/framework/storage/core/client/local/LocalFileClient.java b/orion-ops-framework/orion-ops-spring-boot-starter-storage/src/main/java/com/orion/ops/framework/storage/core/client/local/LocalFileClient.java index 654b0fbd..409ff5c8 100644 --- a/orion-ops-framework/orion-ops-spring-boot-starter-storage/src/main/java/com/orion/ops/framework/storage/core/client/local/LocalFileClient.java +++ b/orion-ops-framework/orion-ops-spring-boot-starter-storage/src/main/java/com/orion/ops/framework/storage/core/client/local/LocalFileClient.java @@ -6,6 +6,7 @@ import com.orion.ops.framework.common.constant.Const; import com.orion.ops.framework.storage.core.client.AbstractFileClient; import java.io.InputStream; +import java.io.OutputStream; /** * 本地文件客户端 @@ -20,6 +21,16 @@ public class LocalFileClient extends AbstractFileClient { 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 protected String doUpload(String path, InputStream in, boolean autoClose, boolean overrideIfExist) { // 获取返回文件路径 @@ -35,11 +46,6 @@ public class LocalFileClient extends AbstractFileClient { return returnPath; } - @Override - protected InputStream doDownload(String path) throws Exception { - return Files1.openInputStreamFast(this.getAbsolutePath(path)); - } - @Override public boolean isExists(String path) { return Files1.isFile(this.getAbsolutePath(path)); diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-storage/src/main/java/com/orion/ops/framework/storage/core/client/local/LocalFileClientConfig.java b/orion-ops-framework/orion-ops-spring-boot-starter-storage/src/main/java/com/orion/ops/framework/storage/core/client/local/LocalFileClientConfig.java index 874b3045..781a7791 100644 --- a/orion-ops-framework/orion-ops-spring-boot-starter-storage/src/main/java/com/orion/ops/framework/storage/core/client/local/LocalFileClientConfig.java +++ b/orion-ops-framework/orion-ops-spring-boot-starter-storage/src/main/java/com/orion/ops/framework/storage/core/client/local/LocalFileClientConfig.java @@ -20,13 +20,18 @@ public class LocalFileClientConfig extends FileClientConfig { *

* 无需 / 结尾 */ - private String storagePath = ""; + private String storagePath; /** * 基础路径 *

* 无需 / 结尾 */ - private String basePath = ""; + private String basePath; + + public LocalFileClientConfig() { + this.storagePath = ""; + this.basePath = ""; + } } diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-storage/src/main/resources/META-INF/spring-configuration-metadata.json b/orion-ops-framework/orion-ops-spring-boot-starter-storage/src/main/resources/META-INF/spring-configuration-metadata.json index e4799836..061a05ee 100644 --- a/orion-ops-framework/orion-ops-spring-boot-starter-storage/src/main/resources/META-INF/spring-configuration-metadata.json +++ b/orion-ops-framework/orion-ops-spring-boot-starter-storage/src/main/resources/META-INF/spring-configuration-metadata.json @@ -9,6 +9,11 @@ "name": "orion.storage.local", "type": "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": [ @@ -34,7 +39,7 @@ "name": "orion.storage.local.date-directory", "type": "java.lang.Boolean", "description": "是否拼接时间作为文件夹.", - "defaultValue": true + "defaultValue": false }, { "name": "orion.storage.local.date-pattern", @@ -51,6 +56,40 @@ "name": "orion.storage.local.base-path", "type": "java.lang.String", "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": "基础路径." } ] } \ No newline at end of file diff --git a/orion-ops-launch/src/main/resources/application.yaml b/orion-ops-launch/src/main/resources/application.yaml index 90153597..aa9139bc 100644 --- a/orion-ops-launch/src/main/resources/application.yaml +++ b/orion-ops-launch/src/main/resources/application.yaml @@ -186,8 +186,16 @@ orion: primary: true enabled: true timestamp-prefix: false + date-directory: false 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: password-encoder-length: 4 # 匿名接口 diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/request/exec/ExecRequest.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/request/exec/ExecRequest.java index 896ffda0..ad8d4f86 100644 --- a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/request/exec/ExecRequest.java +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/request/exec/ExecRequest.java @@ -27,7 +27,6 @@ public class ExecRequest extends PageRequest { @Schema(description = "执行模板id") private Long templateId; - @NotBlank @Size(max = 128) @Schema(description = "执行描述") private String desc; diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/impl/ExecServiceImpl.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/impl/ExecServiceImpl.java index bb397ca4..96ab07e1 100644 --- a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/impl/ExecServiceImpl.java +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/impl/ExecServiceImpl.java @@ -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.ReplacementFormatters; 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.security.LoginUser; import com.orion.ops.framework.common.utils.Valid; @@ -81,7 +82,7 @@ public class ExecServiceImpl implements ExecService { ExecLogDO execLog = ExecLogDO.builder() .userId(userId) .source(ExecSourceEnum.BATCH.name()) - .desc(request.getDesc()) + .desc(Strings.ifBlank(request.getDesc(), Strings.retain(command, 60) + Const.OMIT)) .command(command) .status(ExecStatusEnum.COMPLETED.name()) .build(); @@ -124,7 +125,7 @@ public class ExecServiceImpl implements ExecService { * @return logPath */ private String buildLogPath(Long logId, Long hostId) { - return "/logs/exec/" + logId + "/" + hostId + ".log"; + return "/exec/" + logId + "/" + hostId + ".log"; } /** diff --git a/orion-ops-ui/src/views/exec/exec-template/types/const.ts b/orion-ops-ui/src/views/exec/exec-template/types/const.ts index 2f8444e8..d0574ad9 100644 --- a/orion-ops-ui/src/views/exec/exec-template/types/const.ts +++ b/orion-ops-ui/src/views/exec/exec-template/types/const.ts @@ -28,9 +28,6 @@ export const builtinsParams: Array = [ }, { name: 'execId', desc: '执行记录id' - }, { - name: 'execHostId', - desc: '执行主机记录id' }, { name: 'uuid', desc: '生成任务维度 uuid'