From 96450b9d0ab2a7290221f0e07aea5fda8a83efaf Mon Sep 17 00:00:00 2001 From: Nikhil Kulkarni Date: Tue, 8 Aug 2023 16:05:58 -0700 Subject: [PATCH] Update snakeyaml version to v2 (#2523) * Update snakeyaml version * User LoaderOptions in snakeyaml2 * Run target formatJava --- .../java/org/pytorch/serve/archive/utils/ArchiveUtils.java | 3 ++- frontend/gradle.properties | 2 +- .../serve/metrics/configuration/MetricConfiguration.java | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/frontend/archive/src/main/java/org/pytorch/serve/archive/utils/ArchiveUtils.java b/frontend/archive/src/main/java/org/pytorch/serve/archive/utils/ArchiveUtils.java index ff24e483e3..370763a6ae 100644 --- a/frontend/archive/src/main/java/org/pytorch/serve/archive/utils/ArchiveUtils.java +++ b/frontend/archive/src/main/java/org/pytorch/serve/archive/utils/ArchiveUtils.java @@ -21,6 +21,7 @@ import org.pytorch.serve.archive.DownloadArchiveException; import org.pytorch.serve.archive.model.InvalidModelException; import org.pytorch.serve.archive.s3.HttpUtils; +import org.yaml.snakeyaml.LoaderOptions; import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.constructor.Constructor; import org.yaml.snakeyaml.error.YAMLException; @@ -47,7 +48,7 @@ public static T readFile(File file, Class type) public static T readYamlFile(File file, Class type) throws InvalidModelException, IOException { - Yaml yaml = new Yaml(new Constructor(type)); + Yaml yaml = new Yaml(new Constructor(type, new LoaderOptions())); try (Reader r = new InputStreamReader( Files.newInputStream(file.toPath()), StandardCharsets.UTF_8)) { diff --git a/frontend/gradle.properties b/frontend/gradle.properties index 2590230cc1..c9f7d91936 100644 --- a/frontend/gradle.properties +++ b/frontend/gradle.properties @@ -8,7 +8,7 @@ slf4j_api_version=1.7.32 slf4j_log4j_version=2.17.1 testng_version=7.1.0 torchserve_sdk_version=0.0.5 -snakeyaml_version=1.31 +snakeyaml_version=2.1 grpc_version=1.50.0 protoc_version=3.18.0 lmax_disruptor_version=3.4.4 diff --git a/frontend/server/src/main/java/org/pytorch/serve/metrics/configuration/MetricConfiguration.java b/frontend/server/src/main/java/org/pytorch/serve/metrics/configuration/MetricConfiguration.java index cb41a0d907..12f4c8bd72 100644 --- a/frontend/server/src/main/java/org/pytorch/serve/metrics/configuration/MetricConfiguration.java +++ b/frontend/server/src/main/java/org/pytorch/serve/metrics/configuration/MetricConfiguration.java @@ -6,6 +6,7 @@ import java.util.List; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.yaml.snakeyaml.LoaderOptions; import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.composer.ComposerException; import org.yaml.snakeyaml.constructor.Constructor; @@ -64,7 +65,7 @@ public void validate() { public static MetricConfiguration loadConfiguration(String configFilePath) throws FileNotFoundException, ComposerException, RuntimeException { - Constructor constructor = new Constructor(MetricConfiguration.class); + Constructor constructor = new Constructor(MetricConfiguration.class, new LoaderOptions()); Yaml yaml = new Yaml(constructor); FileInputStream inputStream = new FileInputStream(new File(configFilePath)); MetricConfiguration config = yaml.load(inputStream);