From 02078ced39e08bdd6a1f41820db697eca3d56a81 Mon Sep 17 00:00:00 2001 From: star <15031259256@163.com> Date: Fri, 19 Jan 2024 16:12:09 +0800 Subject: [PATCH] fix(controller): support multiple value (#3131) --- client/starwhale/base/client/models/models.py | 2 +- console/src/api/server/data-contracts.ts | 2 +- .../starwhale/mlops/domain/job/spec/StepSpec.java | 2 +- .../SwCliModelHandlerContainerSpecification.java | 13 +++++++++---- ...SwCliModelHandlerContainerSpecificationTest.java | 11 +++++++---- 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/client/starwhale/base/client/models/models.py b/client/starwhale/base/client/models/models.py index 2955efed39..981c4d34ee 100644 --- a/client/starwhale/base/client/models/models.py +++ b/client/starwhale/base/client/models/models.py @@ -1392,7 +1392,7 @@ class OptionField(SwBaseModel): type: OptionType required: bool multiple: bool - value: Optional[str] = None + value: Optional[Dict[str, Any]] = None help: Optional[str] = None hidden: bool default: Optional[str] = None diff --git a/console/src/api/server/data-contracts.ts b/console/src/api/server/data-contracts.ts index 34fc1a3ad3..7f10b44ab1 100644 --- a/console/src/api/server/data-contracts.ts +++ b/console/src/api/server/data-contracts.ts @@ -1267,7 +1267,7 @@ export interface IOptionField { type: IOptionType required: boolean multiple: boolean - value?: string + value?: object help?: string hidden: boolean default?: string diff --git a/server/controller/src/main/java/ai/starwhale/mlops/domain/job/spec/StepSpec.java b/server/controller/src/main/java/ai/starwhale/mlops/domain/job/spec/StepSpec.java index d748166ed8..1db5dd16a0 100644 --- a/server/controller/src/main/java/ai/starwhale/mlops/domain/job/spec/StepSpec.java +++ b/server/controller/src/main/java/ai/starwhale/mlops/domain/job/spec/StepSpec.java @@ -143,7 +143,7 @@ public static class OptionField { /** * used for server side only */ - private String value; + private Object value; private String help; diff --git a/server/controller/src/main/java/ai/starwhale/mlops/schedule/impl/container/impl/SwCliModelHandlerContainerSpecification.java b/server/controller/src/main/java/ai/starwhale/mlops/schedule/impl/container/impl/SwCliModelHandlerContainerSpecification.java index e0f6bca23f..6ad50b2c90 100644 --- a/server/controller/src/main/java/ai/starwhale/mlops/schedule/impl/container/impl/SwCliModelHandlerContainerSpecification.java +++ b/server/controller/src/main/java/ai/starwhale/mlops/schedule/impl/container/impl/SwCliModelHandlerContainerSpecification.java @@ -28,6 +28,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.stream.Collectors; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; @@ -86,14 +87,18 @@ public Map getContainerEnvs() { cmdArgs.append( stepSpec.getArguments().values().stream() .flatMap(options -> options.values().stream()) - .filter(optionField -> StringUtils.hasText(optionField.getValue())) + .filter(optionField -> Objects.nonNull(optionField.getValue())) .map(optionField -> { if (optionField.isFlag()) { - return Boolean.parseBoolean(optionField.getValue()) + return (boolean) optionField.getValue() ? "--" + optionField.getName() : ""; - } else { - return "--" + optionField.getName() + " " + optionField.getValue(); + } else if (optionField.isMultiple() + && optionField.getValue() instanceof List) { + return ((List) optionField.getValue()).stream() + .map(value -> "--" + optionField.getName() + " " + value) + .collect(Collectors.joining(" ")); } + return "--" + optionField.getName() + " " + optionField.getValue(); }).collect(Collectors.joining(" ")) ); } diff --git a/server/controller/src/test/java/ai/starwhale/mlops/schedule/impl/contianer/SwCliModelHandlerContainerSpecificationTest.java b/server/controller/src/test/java/ai/starwhale/mlops/schedule/impl/contianer/SwCliModelHandlerContainerSpecificationTest.java index 5b2a9b6f91..b4a65775fe 100644 --- a/server/controller/src/test/java/ai/starwhale/mlops/schedule/impl/contianer/SwCliModelHandlerContainerSpecificationTest.java +++ b/server/controller/src/test/java/ai/starwhale/mlops/schedule/impl/contianer/SwCliModelHandlerContainerSpecificationTest.java @@ -96,7 +96,7 @@ public class SwCliModelHandlerContainerSpecificationTest { put("SW_RUN_HANDLER", null); put("SW_DEV_TOKEN", null); put("SW_DEV_PORT", "8000"); - put("SW_TASK_EXTRA_CMD_ARGS", "--is_eval --reshape 32 --a 11"); + put("SW_TASK_EXTRA_CMD_ARGS", "--is_eval --reshape 32 --patch 1 --patch 2 --a 11"); put("SW_CONDA_CONFIG", "channels:\n" + " - defaults\n" + "show_channel_urls: true\n" @@ -139,7 +139,7 @@ public class SwCliModelHandlerContainerSpecificationTest { put("SW_PYPI_RETRIES", "1"); put("SW_PYPI_TIMEOUT", "2"); put("SW_RUN_HANDLER", null); - put("SW_TASK_EXTRA_CMD_ARGS", "--is_eval --reshape 32 --a 11"); + put("SW_TASK_EXTRA_CMD_ARGS", "--is_eval --reshape 32 --patch 1 --patch 2 --a 11"); put("SW_CONDA_CONFIG", "channels:\n" + " - defaults\n" + "show_channel_urls: true\n" @@ -284,13 +284,16 @@ private Task mockTask(boolean devMode) throws JsonProcessingException { + " opts:\n" + " - --reshape\n" + " required: false\n" - + " patch:\n" // this will not be used + + " patch:\n" + " default: 16\n" + " help: batch size\n" + " hidden: false\n" + " is_flag: false\n" - + " multiple: false\n" + + " multiple: true\n" + " name: patch\n" + + " value:\n" + + " - 1\n" + + " - 2\n" + " opts:\n" + " - --patch\n" + " required: false",