From 69cece8355800f18117e0c942e574a0fbac7fb6d Mon Sep 17 00:00:00 2001 From: jackjii79 Date: Mon, 11 Mar 2024 16:27:33 -0700 Subject: [PATCH 1/5] debug --- common/transform/build.gradle | 14 +++--- .../common/transform/RequestChecker.java | 6 ++- .../transform/SampleRequestBuilder.java | 25 ++++------- .../transform/ScoreRequestTransformer.java | 44 ++++++++----------- gradle/mixins/checkstyle.gradle | 3 +- local-rest-scorer/build.gradle | 3 -- .../rest/controller/ModelsApiController.java | 1 + 7 files changed, 42 insertions(+), 54 deletions(-) diff --git a/common/transform/build.gradle b/common/transform/build.gradle index 1434aec7..e6b63fea 100644 --- a/common/transform/build.gradle +++ b/common/transform/build.gradle @@ -6,7 +6,6 @@ apply from: project(":").file('gradle/java.gradle') dependencies { implementation project(':common:rest-java-model') - implementation group: 'io.swagger.core.v3', name: 'swagger-annotations' implementation group: 'ai.h2o', name: 'mojo2-runtime-api' implementation group: 'ai.h2o', name: 'mojo2-runtime-impl' implementation group: 'com.google.guava', name: 'guava' @@ -28,13 +27,14 @@ dependencies { testImplementation group: 'org.junit-pioneer', name: 'junit-pioneer', version: jupiterPioneerVersion } -bootJar { - enabled=false -} - test { useJUnitPlatform() +} + +bootJar { + enabled = false +} - jvmArgs '--add-opens=java.base/java.util=ALL-UNNAMED' - jvmArgs '--add-opens=java.base/java.lang=ALL-UNNAMED' +jar { + enabled = true } diff --git a/common/transform/src/main/java/ai/h2o/mojos/deploy/common/transform/RequestChecker.java b/common/transform/src/main/java/ai/h2o/mojos/deploy/common/transform/RequestChecker.java index 00044180..05de1fd1 100644 --- a/common/transform/src/main/java/ai/h2o/mojos/deploy/common/transform/RequestChecker.java +++ b/common/transform/src/main/java/ai/h2o/mojos/deploy/common/transform/RequestChecker.java @@ -6,7 +6,9 @@ import ai.h2o.mojos.runtime.frame.MojoFrameMeta; import java.util.List; -/** Checks that the request is of the correct form matching the corresponding mojo pipeline. */ +/** + * Checks that the request is of the correct form matching the corresponding mojo pipeline. + */ public class RequestChecker { private final SampleRequestBuilder sampleRequestBuilder; @@ -44,7 +46,7 @@ private String getProblemMessageOrNull(ScoreRequest scoreRequest, MojoFrameMeta if (!fields.containsAll(expectedFields)) { return String.format( "Input fields don't contain all the Mojo fields, expected %s actual %s", - expectedFields.toString(), fields.toString()); + expectedFields, fields); } int i = 0; for (List row : scoreRequest.getRows()) { diff --git a/common/transform/src/main/java/ai/h2o/mojos/deploy/common/transform/SampleRequestBuilder.java b/common/transform/src/main/java/ai/h2o/mojos/deploy/common/transform/SampleRequestBuilder.java index 9aae8647..57cc5693 100644 --- a/common/transform/src/main/java/ai/h2o/mojos/deploy/common/transform/SampleRequestBuilder.java +++ b/common/transform/src/main/java/ai/h2o/mojos/deploy/common/transform/SampleRequestBuilder.java @@ -14,7 +14,9 @@ * request to further play with and fill with actual meaningful data. */ public class SampleRequestBuilder { - /** Builds a valid {@link ScoreRequest} based on the given mojo input {@link MojoFrameMeta}. */ + /** + * Builds a valid {@link ScoreRequest} based on the given mojo input {@link MojoFrameMeta}. + */ public ScoreRequest build(MojoFrameMeta inputMeta) { ScoreRequest request = new ScoreRequest(); final List fields = @@ -31,20 +33,11 @@ public ScoreRequest build(MojoFrameMeta inputMeta) { } private static String getExampleValue(MojoColumn.Type type) { - switch (type) { - case Bool: - return "true"; - case Int32: - case Int64: - case Float32: - case Float64: - return "0"; - case Str: - return "text"; - case Time64: - return "2018-01-01"; - default: - return ""; - } + return switch (type) { + case Bool -> "true"; + case Int32, Int64, Float32, Float64 -> "0"; + case Str -> "text"; + case Time64 -> "2018-01-01"; + }; } } diff --git a/common/transform/src/main/java/ai/h2o/mojos/deploy/common/transform/ScoreRequestTransformer.java b/common/transform/src/main/java/ai/h2o/mojos/deploy/common/transform/ScoreRequestTransformer.java index a530d993..c3cc35ed 100644 --- a/common/transform/src/main/java/ai/h2o/mojos/deploy/common/transform/ScoreRequestTransformer.java +++ b/common/transform/src/main/java/ai/h2o/mojos/deploy/common/transform/ScoreRequestTransformer.java @@ -34,31 +34,25 @@ private List> transformRow( List fields, List> rows, Map dataFields) { return rows.stream() .map( - row -> { - List transformData = - IntStream.range(0, row.size()) - .mapToObj( - fieldIdx -> { - String colName = fields.get(fieldIdx); - String origin = row.get(fieldIdx); - if (dataFields.containsKey(colName)) { - String sanitizeValue = - Utils.sanitizeBoolean( - origin, dataFields.get(colName).getDataType()); - if (!sanitizeValue.equals(origin)) { - logger.debug("Value '{}' parsed as '{}'", origin, sanitizeValue); - } - return sanitizeValue; - } else { - logger.debug("Column '{}' can not be found in Input schema", colName); - return origin; - } - }) - .collect(Collectors.toList()); - List transformedRow = new ArrayList<>(); - transformedRow.addAll(transformData); - return transformedRow; - }) + row -> IntStream.range(0, row.size()) + .mapToObj( + fieldIdx -> { + String colName = fields.get(fieldIdx); + String origin = row.get(fieldIdx); + if (dataFields.containsKey(colName)) { + String sanitizeValue = + Utils.sanitizeBoolean( + origin, dataFields.get(colName).getDataType()); + if (!sanitizeValue.equals(origin)) { + logger.debug("Value '{}' parsed as '{}'", origin, sanitizeValue); + } + return sanitizeValue; + } else { + logger.debug("Column '{}' can not be found in Input schema", colName); + return origin; + } + }) + .toList()) .collect(Collectors.toList()); } } diff --git a/gradle/mixins/checkstyle.gradle b/gradle/mixins/checkstyle.gradle index 90622b52..5793e29b 100644 --- a/gradle/mixins/checkstyle.gradle +++ b/gradle/mixins/checkstyle.gradle @@ -1,5 +1,5 @@ // Defines shared Gradle project Checkstyle analyzer configuration. - +/* apply plugin: 'checkstyle' checkstyle { @@ -7,3 +7,4 @@ checkstyle { configFile = project(":").file("config/checkstyle/google_style.xml") configProperties = ["suppressionFile": project(":").file("config/checkstyle/suppressions.xml")] } +*/ \ No newline at end of file diff --git a/local-rest-scorer/build.gradle b/local-rest-scorer/build.gradle index bf22837f..e4838cbc 100644 --- a/local-rest-scorer/build.gradle +++ b/local-rest-scorer/build.gradle @@ -32,9 +32,6 @@ dependencies { test { useJUnitPlatform() - - jvmArgs '--add-opens=java.base/java.util=ALL-UNNAMED' - jvmArgs '--add-opens=java.base/java.lang=ALL-UNNAMED' } bootRun { diff --git a/local-rest-scorer/src/main/java/ai/h2o/mojos/deploy/local/rest/controller/ModelsApiController.java b/local-rest-scorer/src/main/java/ai/h2o/mojos/deploy/local/rest/controller/ModelsApiController.java index 10d28128..51cff6ac 100644 --- a/local-rest-scorer/src/main/java/ai/h2o/mojos/deploy/local/rest/controller/ModelsApiController.java +++ b/local-rest-scorer/src/main/java/ai/h2o/mojos/deploy/local/rest/controller/ModelsApiController.java @@ -84,6 +84,7 @@ public ResponseEntity getScore(ScoreRequest request) { try { log.info("Got scoring request"); ScoreResponse scoreResponse = scorer.score(request); + log.info("finish scoring request"); scoreResponse.id(getScorerModelId()); return ResponseEntity.ok(scoreResponse); } catch (IllegalArgumentException e) { From 77f7162e6d516acdf603e27220441492ec0d789e Mon Sep 17 00:00:00 2001 From: jackjii79 Date: Mon, 11 Mar 2024 16:40:14 -0700 Subject: [PATCH 2/5] upgrade sprintboot --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index e1e2ecc6..af850ba1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -37,7 +37,7 @@ jakartaServletVersion = 6.0.0 tomcatVersion = 9.0.75 # External plugins: -springBootPluginVersion = 3.2.0 +springBootPluginVersion = 3.2.1 swaggerGradlePluginVersion = 2.19.2 errorpronePluginVersion = 3.1.0 jibPluginVersion = 3.4.0 From d897a95b8422e72d0ff7fbc2bfe0d29c13acd82d Mon Sep 17 00:00:00 2001 From: jackjii79 Date: Mon, 11 Mar 2024 19:03:29 -0700 Subject: [PATCH 3/5] save --- .../transform/ScoreRequestTransformer.java | 41 ++++++++----------- gradle.properties | 4 +- local-rest-scorer/build.gradle | 1 - 3 files changed, 20 insertions(+), 26 deletions(-) diff --git a/common/transform/src/main/java/ai/h2o/mojos/deploy/common/transform/ScoreRequestTransformer.java b/common/transform/src/main/java/ai/h2o/mojos/deploy/common/transform/ScoreRequestTransformer.java index c3cc35ed..e3cb187b 100644 --- a/common/transform/src/main/java/ai/h2o/mojos/deploy/common/transform/ScoreRequestTransformer.java +++ b/common/transform/src/main/java/ai/h2o/mojos/deploy/common/transform/ScoreRequestTransformer.java @@ -3,7 +3,6 @@ import ai.h2o.mojos.deploy.common.rest.model.DataField; import ai.h2o.mojos.deploy.common.rest.model.ScoreRequest; import com.google.common.collect.ImmutableMap; -import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.function.BiConsumer; @@ -32,27 +31,23 @@ public void accept(ScoreRequest scoreRequest, List dataFields) { private List> transformRow( List fields, List> rows, Map dataFields) { - return rows.stream() - .map( - row -> IntStream.range(0, row.size()) - .mapToObj( - fieldIdx -> { - String colName = fields.get(fieldIdx); - String origin = row.get(fieldIdx); - if (dataFields.containsKey(colName)) { - String sanitizeValue = - Utils.sanitizeBoolean( - origin, dataFields.get(colName).getDataType()); - if (!sanitizeValue.equals(origin)) { - logger.debug("Value '{}' parsed as '{}'", origin, sanitizeValue); - } - return sanitizeValue; - } else { - logger.debug("Column '{}' can not be found in Input schema", colName); - return origin; - } - }) - .toList()) - .collect(Collectors.toList()); + return rows.stream().map(row -> IntStream.range(0, row.size()).mapToObj( + fieldIdx -> { + String colName = fields.get(fieldIdx); + String origin = row.get(fieldIdx); + if (dataFields.containsKey(colName)) { + String sanitizeValue = Utils.sanitizeBoolean( + origin, dataFields.get(colName).getDataType() + ); + if (!sanitizeValue.equals(origin)) { + logger.debug("Value '{}' parsed as '{}'", origin, sanitizeValue); + } + return sanitizeValue; + } else { + logger.warn("Column '{}' can not be found in Input schema", colName); + return origin; + } + } + ).collect(Collectors.toList())).collect(Collectors.toList()); } } diff --git a/gradle.properties b/gradle.properties index af850ba1..a9098e60 100644 --- a/gradle.properties +++ b/gradle.properties @@ -34,10 +34,10 @@ sparklingWaterVersion = 3.30.1.3-1-3.0 configVersion = 1.3.4 openApiJacksonNullableVersion = 0.2.6 jakartaServletVersion = 6.0.0 -tomcatVersion = 9.0.75 +tomcatVersion = 9.0.63 # External plugins: -springBootPluginVersion = 3.2.1 +springBootPluginVersion = 3.0.13 swaggerGradlePluginVersion = 2.19.2 errorpronePluginVersion = 3.1.0 jibPluginVersion = 3.4.0 diff --git a/local-rest-scorer/build.gradle b/local-rest-scorer/build.gradle index e4838cbc..a6a35151 100644 --- a/local-rest-scorer/build.gradle +++ b/local-rest-scorer/build.gradle @@ -5,7 +5,6 @@ plugins { apply from: project(":").file('gradle/java.gradle') dependencies { - runtimeOnly group: 'org.springframework.boot', name: 'spring-boot-properties-migrator' implementation project(':common:rest-spring-api') implementation project(':common:transform') implementation group: 'ai.h2o', name: 'h2o-genmodel' From c69fd56ede73682e5aa146a838c724628fc0dab5 Mon Sep 17 00:00:00 2001 From: jackjii79 Date: Tue, 12 Mar 2024 09:46:20 -0700 Subject: [PATCH 4/5] save --- build.gradle | 4 ++-- common/rest-java-model/build.gradle | 8 ++++++- common/rest-spring-api/build.gradle | 3 ++- common/transform/build.gradle | 14 +++++++----- ...oFrameToContributionResponseConverter.java | 4 ++-- .../MojoFrameToScoreResponseConverter.java | 22 +++++++++---------- .../common/transform/RequestChecker.java | 3 ++- .../transform/SampleRequestBuilder.java | 21 +++++++++++++----- .../ScoreRequestToMojoFrameConverter.java | 3 ++- .../transform/ScoreRequestTransformer.java | 8 ++++--- .../mojos/deploy/common/transform/Utils.java | 3 ++- .../common/transform/MojoScorerTest.java | 4 ++-- .../ScoreRequestTransformerTest.java | 18 +++++++-------- gradle.properties | 10 ++++----- gradle/java_no_style.gradle | 4 ++-- gradle/mixins/checkstyle.gradle | 2 -- gradle/wrapper/gradle-wrapper.properties | 2 +- local-rest-scorer/build.gradle | 3 +++ settings.gradle | 22 +++++++++---------- 19 files changed, 92 insertions(+), 66 deletions(-) diff --git a/build.gradle b/build.gradle index b1170a66..1726fe29 100644 --- a/build.gradle +++ b/build.gradle @@ -47,8 +47,8 @@ subprojects { // } // task distributionZip(type: Zip) { - archiveName "${project.name}-${project.version}.zip" - destinationDir(file(buildDir)) + getArchiveFileName().set("${project.name}-${project.version}.zip") + getDestinationDirectory().set(file(buildDir)) } task printVersion { diff --git a/common/rest-java-model/build.gradle b/common/rest-java-model/build.gradle index 60135688..66f0e7f6 100644 --- a/common/rest-java-model/build.gradle +++ b/common/rest-java-model/build.gradle @@ -23,6 +23,7 @@ openApiGenerate { invokerPackage = "ai.h2o.mojos.deploy.common.rest" inputSpec = "$rootDir/common/swagger/v1openapi3/swagger.json" outputDir = "$buildDir/gen" + generateAliasAsModel = true globalProperties.set([ "skipFormModel": "false", ]) @@ -31,6 +32,7 @@ openApiGenerate { "interfaceOnly": "true", "basePackage": "ai.h2o.mojos.deploy.common.rest", "modelPackage": "ai.h2o.mojos.deploy.common.rest.model", + "apiPackage": "ai.h2o.mojos.deploy.common.rest.api", ]) } @@ -38,11 +40,15 @@ bootJar { enabled=false } +jar { + enabled=true +} + compileJava.dependsOn tasks.openApiValidate, tasks.openApiGenerate sourceSets { main { java { - srcDir("$buildDir/gen/src/main/java") + srcDir("${buildDir}/gen/src/main/java") } } } diff --git a/common/rest-spring-api/build.gradle b/common/rest-spring-api/build.gradle index 7bb85789..9c628913 100644 --- a/common/rest-spring-api/build.gradle +++ b/common/rest-spring-api/build.gradle @@ -20,6 +20,7 @@ openApiGenerate { generatorName = 'spring' inputSpec = "$rootDir/common/swagger/v1openapi3/swagger.json" outputDir = "$buildDir/gen" + generateAliasAsModel = true globalProperties.set([ "skipFormModel": "false", ]) @@ -46,7 +47,7 @@ compileJava.dependsOn tasks.openApiValidate, tasks.openApiGenerate sourceSets { main { java { - srcDir("$buildDir/gen/src/main/java") + srcDir("${buildDir}/gen/src/main/java") } } } diff --git a/common/transform/build.gradle b/common/transform/build.gradle index e6b63fea..405a6053 100644 --- a/common/transform/build.gradle +++ b/common/transform/build.gradle @@ -5,7 +5,8 @@ plugins { apply from: project(":").file('gradle/java.gradle') dependencies { - implementation project(':common:rest-java-model') + implementation project(':common:rest-spring-api') + implementation group: 'io.swagger.core.v3', name: 'swagger-annotations' implementation group: 'ai.h2o', name: 'mojo2-runtime-api' implementation group: 'ai.h2o', name: 'mojo2-runtime-impl' implementation group: 'com.google.guava', name: 'guava' @@ -27,10 +28,6 @@ dependencies { testImplementation group: 'org.junit-pioneer', name: 'junit-pioneer', version: jupiterPioneerVersion } -test { - useJUnitPlatform() -} - bootJar { enabled = false } @@ -38,3 +35,10 @@ bootJar { jar { enabled = true } + +test { + useJUnitPlatform() + + jvmArgs '--add-opens=java.base/java.util=ALL-UNNAMED' + jvmArgs '--add-opens=java.base/java.lang=ALL-UNNAMED' +} diff --git a/common/transform/src/main/java/ai/h2o/mojos/deploy/common/transform/MojoFrameToContributionResponseConverter.java b/common/transform/src/main/java/ai/h2o/mojos/deploy/common/transform/MojoFrameToContributionResponseConverter.java index fef44d63..74f9b7d5 100644 --- a/common/transform/src/main/java/ai/h2o/mojos/deploy/common/transform/MojoFrameToContributionResponseConverter.java +++ b/common/transform/src/main/java/ai/h2o/mojos/deploy/common/transform/MojoFrameToContributionResponseConverter.java @@ -19,8 +19,8 @@ public class MojoFrameToContributionResponseConverter { * ContributionResponse}. */ public ContributionResponse contributionResponseWithNoOutputGroup(MojoFrame shapleyMojoFrame) { - List> outputRows = - Stream.generate(ArrayList::new) + List outputRows = + Stream.generate(Row::new) .limit(shapleyMojoFrame.getNrows()) .collect(Collectors.toList()); Utils.copyResultFields(shapleyMojoFrame, outputRows); diff --git a/common/transform/src/main/java/ai/h2o/mojos/deploy/common/transform/MojoFrameToScoreResponseConverter.java b/common/transform/src/main/java/ai/h2o/mojos/deploy/common/transform/MojoFrameToScoreResponseConverter.java index 59a6a60c..51afd2d7 100644 --- a/common/transform/src/main/java/ai/h2o/mojos/deploy/common/transform/MojoFrameToScoreResponseConverter.java +++ b/common/transform/src/main/java/ai/h2o/mojos/deploy/common/transform/MojoFrameToScoreResponseConverter.java @@ -37,7 +37,7 @@ public class MojoFrameToScoreResponseConverter // Note: assumption is that pipeline supports Prediction interval. // However for some h2o3 model, even classification model may still set // this to be true. - private Boolean supportPredictionInterval; + private final Boolean supportPredictionInterval; public MojoFrameToScoreResponseConverter(boolean supportPredictionInterval) { this.supportPredictionInterval = supportPredictionInterval; @@ -57,8 +57,8 @@ public MojoFrameToScoreResponseConverter() { @Override public ScoreResponse apply(MojoFrame mojoFrame, ScoreRequest scoreRequest) { Set includedFields = getSetOfIncludedFields(scoreRequest); - List> outputRows = - Stream.generate(ArrayList::new) + List outputRows = + Stream.generate(Row::new) .limit(mojoFrame.getNrows()) .collect(Collectors.toList()); copyFilteredInputFields(scoreRequest, includedFields, outputRows); @@ -81,7 +81,7 @@ public ScoreResponse apply(MojoFrame mojoFrame, ScoreRequest scoreRequest) { * response frame, only one column rows will be populated into the outputRows to ensure backward * compatible. */ - private void fillOutputRows(MojoFrame mojoFrame, List> outputRows) { + private void fillOutputRows(MojoFrame mojoFrame, List outputRows) { List> targetRows = getTargetRows(mojoFrame); for (int rowIdx = 0; rowIdx < mojoFrame.getNrows(); rowIdx++) { outputRows.get(rowIdx).addAll(targetRows.get(rowIdx)); @@ -182,9 +182,9 @@ private List getTargetFieldIndices(MojoFrame mojoFrame) { * Extract prediction interval columns rows from MOJO response frame. Note: Assumption is * prediction interval should already be enabled and response frame has expected structure. */ - private List> getPredictionIntervalRows(MojoFrame mojoFrame, int targetIdx) { - List> predictionIntervalRows = - Stream.generate(ArrayList::new) + private List getPredictionIntervalRows(MojoFrame mojoFrame, int targetIdx) { + List predictionIntervalRows = + Stream.generate(Row::new) .limit(mojoFrame.getNrows()) .collect(Collectors.toList()); for (int row = 0; row < mojoFrame.getNrows(); row++) { @@ -234,15 +234,15 @@ private int getTargetColIdx(List mojoColumns) { } private static void copyFilteredInputFields( - ScoreRequest scoreRequest, Set includedFields, List> outputRows) { + ScoreRequest scoreRequest, Set includedFields, List outputRows) { if (includedFields.isEmpty()) { return; } boolean generateRowIds = shouldGenerateRowIds(scoreRequest, includedFields); - List> inputRows = scoreRequest.getRows(); + List inputRows = scoreRequest.getRows(); for (int row = 0; row < outputRows.size(); row++) { - List inputRow = inputRows.get(row); - List outputRow = outputRows.get(row); + Row inputRow = inputRows.get(row); + Row outputRow = outputRows.get(row); List inputFields = scoreRequest.getFields(); for (int col = 0; col < inputFields.size(); col++) { if (includedFields.contains(inputFields.get(col))) { diff --git a/common/transform/src/main/java/ai/h2o/mojos/deploy/common/transform/RequestChecker.java b/common/transform/src/main/java/ai/h2o/mojos/deploy/common/transform/RequestChecker.java index 05de1fd1..350465fd 100644 --- a/common/transform/src/main/java/ai/h2o/mojos/deploy/common/transform/RequestChecker.java +++ b/common/transform/src/main/java/ai/h2o/mojos/deploy/common/transform/RequestChecker.java @@ -2,6 +2,7 @@ import static java.util.Arrays.asList; +import ai.h2o.mojos.deploy.common.rest.model.Row; import ai.h2o.mojos.deploy.common.rest.model.ScoreRequest; import ai.h2o.mojos.runtime.frame.MojoFrameMeta; import java.util.List; @@ -38,7 +39,7 @@ private String getProblemMessageOrNull(ScoreRequest scoreRequest, MojoFrameMeta if (fields == null || fields.isEmpty()) { return "List of input fields cannot be empty"; } - List> rows = scoreRequest.getRows(); + List rows = scoreRequest.getRows(); if (rows == null || rows.isEmpty()) { return "List of input data rows cannot be empty"; } diff --git a/common/transform/src/main/java/ai/h2o/mojos/deploy/common/transform/SampleRequestBuilder.java b/common/transform/src/main/java/ai/h2o/mojos/deploy/common/transform/SampleRequestBuilder.java index 57cc5693..35c8963d 100644 --- a/common/transform/src/main/java/ai/h2o/mojos/deploy/common/transform/SampleRequestBuilder.java +++ b/common/transform/src/main/java/ai/h2o/mojos/deploy/common/transform/SampleRequestBuilder.java @@ -33,11 +33,20 @@ public ScoreRequest build(MojoFrameMeta inputMeta) { } private static String getExampleValue(MojoColumn.Type type) { - return switch (type) { - case Bool -> "true"; - case Int32, Int64, Float32, Float64 -> "0"; - case Str -> "text"; - case Time64 -> "2018-01-01"; - }; + switch (type) { + case Bool: + return "true"; + case Int32: + case Int64: + case Float32: + case Float64: + return "0"; + case Str: + return "text"; + case Time64: + return "2018-01-01"; + default: + return ""; + } } } diff --git a/common/transform/src/main/java/ai/h2o/mojos/deploy/common/transform/ScoreRequestToMojoFrameConverter.java b/common/transform/src/main/java/ai/h2o/mojos/deploy/common/transform/ScoreRequestToMojoFrameConverter.java index 362b9fdc..de2253b6 100644 --- a/common/transform/src/main/java/ai/h2o/mojos/deploy/common/transform/ScoreRequestToMojoFrameConverter.java +++ b/common/transform/src/main/java/ai/h2o/mojos/deploy/common/transform/ScoreRequestToMojoFrameConverter.java @@ -1,5 +1,6 @@ package ai.h2o.mojos.deploy.common.transform; +import ai.h2o.mojos.deploy.common.rest.model.Row; import ai.h2o.mojos.deploy.common.rest.model.ScoreRequest; import ai.h2o.mojos.runtime.frame.MojoFrame; import ai.h2o.mojos.runtime.frame.MojoFrameBuilder; @@ -17,7 +18,7 @@ public MojoFrame apply(ScoreRequest scoreRequest, MojoFrameBuilder frameBuilder) List fields = scoreRequest.getFields(); if (scoreRequest.getRows() != null) { - for (List row : scoreRequest.getRows()) { + for (Row row : scoreRequest.getRows()) { MojoRowBuilder rowBuilder = frameBuilder.getMojoRowBuilder(); for (int i = 0; i < row.size(); i++) { rowBuilder.setValue(fields.get(i), row.get(i)); diff --git a/common/transform/src/main/java/ai/h2o/mojos/deploy/common/transform/ScoreRequestTransformer.java b/common/transform/src/main/java/ai/h2o/mojos/deploy/common/transform/ScoreRequestTransformer.java index e3cb187b..ea8e4faa 100644 --- a/common/transform/src/main/java/ai/h2o/mojos/deploy/common/transform/ScoreRequestTransformer.java +++ b/common/transform/src/main/java/ai/h2o/mojos/deploy/common/transform/ScoreRequestTransformer.java @@ -1,8 +1,10 @@ package ai.h2o.mojos.deploy.common.transform; import ai.h2o.mojos.deploy.common.rest.model.DataField; +import ai.h2o.mojos.deploy.common.rest.model.Row; import ai.h2o.mojos.deploy.common.rest.model.ScoreRequest; import com.google.common.collect.ImmutableMap; +import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.function.BiConsumer; @@ -29,8 +31,8 @@ public void accept(ScoreRequest scoreRequest, List dataFields) { transformRow(scoreRequest.getFields(), scoreRequest.getRows(), dataFieldMap)); } - private List> transformRow( - List fields, List> rows, Map dataFields) { + private List transformRow( + List fields, List rows, Map dataFields) { return rows.stream().map(row -> IntStream.range(0, row.size()).mapToObj( fieldIdx -> { String colName = fields.get(fieldIdx); @@ -48,6 +50,6 @@ private List> transformRow( return origin; } } - ).collect(Collectors.toList())).collect(Collectors.toList()); + ).collect(Collectors.toCollection(Row::new))).collect(Collectors.toList()); } } diff --git a/common/transform/src/main/java/ai/h2o/mojos/deploy/common/transform/Utils.java b/common/transform/src/main/java/ai/h2o/mojos/deploy/common/transform/Utils.java index cf8a55eb..6ea5e0d7 100644 --- a/common/transform/src/main/java/ai/h2o/mojos/deploy/common/transform/Utils.java +++ b/common/transform/src/main/java/ai/h2o/mojos/deploy/common/transform/Utils.java @@ -1,6 +1,7 @@ package ai.h2o.mojos.deploy.common.transform; import ai.h2o.mojos.deploy.common.rest.model.DataField; +import ai.h2o.mojos.deploy.common.rest.model.Row; import ai.h2o.mojos.runtime.frame.MojoFrame; import java.util.List; @@ -10,7 +11,7 @@ public class Utils { * * @param mojoFrame {@link MojoFrame} */ - public static void copyResultFields(MojoFrame mojoFrame, List> outputRows) { + public static void copyResultFields(MojoFrame mojoFrame, List outputRows) { String[][] outputColumns = new String[mojoFrame.getNcols()][]; for (int col = 0; col < mojoFrame.getNcols(); col++) { outputColumns[col] = mojoFrame.getColumn(col).getDataAsStrings(); diff --git a/common/transform/src/test/java/ai/h2o/mojos/deploy/common/transform/MojoScorerTest.java b/common/transform/src/test/java/ai/h2o/mojos/deploy/common/transform/MojoScorerTest.java index b1de0e40..5896de01 100644 --- a/common/transform/src/test/java/ai/h2o/mojos/deploy/common/transform/MojoScorerTest.java +++ b/common/transform/src/test/java/ai/h2o/mojos/deploy/common/transform/MojoScorerTest.java @@ -474,8 +474,8 @@ private MojoFrame generateDummyTransformedMojoFrame() { private ScoreResponse generateDummyResponse() { ScoreResponse response = new ScoreResponse(); - List> outputRows = - Stream.generate(ArrayList::new).limit(4).collect(Collectors.toList()); + List outputRows = + Stream.generate(Row::new).limit(4).collect(Collectors.toList()); response.setScore(outputRows); response.setFields(Arrays.asList("field1")); return response; diff --git a/common/transform/src/test/java/ai/h2o/mojos/deploy/common/transform/ScoreRequestTransformerTest.java b/common/transform/src/test/java/ai/h2o/mojos/deploy/common/transform/ScoreRequestTransformerTest.java index 8807ff4e..770c43eb 100644 --- a/common/transform/src/test/java/ai/h2o/mojos/deploy/common/transform/ScoreRequestTransformerTest.java +++ b/common/transform/src/test/java/ai/h2o/mojos/deploy/common/transform/ScoreRequestTransformerTest.java @@ -38,16 +38,16 @@ void transform_BooleanLiteral_Transformed() { // Given ScoreRequest scoreRequest = new ScoreRequest(); scoreRequest.setFields(Collections.singletonList("test")); - List> rows = + List rows = new ArrayList<>( Arrays.asList( - new ArrayList<>(), - new ArrayList<>(), - new ArrayList<>(), - new ArrayList<>(), - new ArrayList<>(), - new ArrayList<>(), - new ArrayList<>())); + new Row(), + new Row(), + new Row(), + new Row(), + new Row(), + new Row(), + new Row())); rows.get(0).addAll(Collections.singletonList("true")); rows.get(1).addAll(Collections.singletonList("False")); rows.get(2).addAll(Collections.singletonList("TrUE")); @@ -85,7 +85,7 @@ void transform_NonBooleanLiteral_Unchanged() { // Given ScoreRequest scoreRequest = new ScoreRequest(); scoreRequest.setFields(Collections.singletonList("test")); - List> rows = new ArrayList<>(Arrays.asList(new Row(), new Row())); + List rows = new ArrayList<>(Arrays.asList(new Row(), new Row())); rows.get(0).addAll(Collections.singletonList("unchangedFeature1")); rows.get(1).addAll(Collections.singletonList("unchangedFeature2")); scoreRequest.setRows(rows); diff --git a/gradle.properties b/gradle.properties index a9098e60..487edcb4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -34,14 +34,14 @@ sparklingWaterVersion = 3.30.1.3-1-3.0 configVersion = 1.3.4 openApiJacksonNullableVersion = 0.2.6 jakartaServletVersion = 6.0.0 -tomcatVersion = 9.0.63 +tomcatVersion = 9.0.75 # External plugins: -springBootPluginVersion = 3.0.13 +springBootPluginVersion = 3.2.3 swaggerGradlePluginVersion = 2.19.2 errorpronePluginVersion = 3.1.0 jibPluginVersion = 3.4.0 -openApiGeneratorGradlePluginVersion = 7.0.1 +openApiGeneratorGradlePluginVersion = 7.2.0 # External tools: checkStyleVersion = 8.21 @@ -52,8 +52,8 @@ errorproneVersion = 2.23.0 # Docker settings dockerRepositoryPrefix = harbor.h2o.ai/opsh2oai/h2oai/ dockerIncludePython = true -# Digest of eclipse-temurin:17.0.9_9-jdk-alpine -javaBaseImage = eclipse-temurin@sha256:24643c2dd329ef482ecd042b59cbfb7fe13716342e22674a0abd763559c8a1dd +# Digest of eclipse-temurin:21.0.2_13-jdk-alpine +javaBaseImage = eclipse-temurin@sha256:82698e23d15ada036bc176f6fb210401e0679cd0a4b1e71d05e7329982d6062c # Increase timeouts to avoid read error from OSS Nexus # See: diff --git a/gradle/java_no_style.gradle b/gradle/java_no_style.gradle index 8fa91f0f..97ea94bb 100644 --- a/gradle/java_no_style.gradle +++ b/gradle/java_no_style.gradle @@ -5,5 +5,5 @@ apply plugin: 'java' apply from: project(":").file('gradle/mixins/dependencies.gradle') -sourceCompatibility = JavaVersion.VERSION_17 -targetCompatibility = JavaVersion.VERSION_17 +sourceCompatibility = "21" +targetCompatibility = "21" diff --git a/gradle/mixins/checkstyle.gradle b/gradle/mixins/checkstyle.gradle index 5793e29b..78c41b3d 100644 --- a/gradle/mixins/checkstyle.gradle +++ b/gradle/mixins/checkstyle.gradle @@ -1,5 +1,4 @@ // Defines shared Gradle project Checkstyle analyzer configuration. -/* apply plugin: 'checkstyle' checkstyle { @@ -7,4 +6,3 @@ checkstyle { configFile = project(":").file("config/checkstyle/google_style.xml") configProperties = ["suppressionFile": project(":").file("config/checkstyle/suppressions.xml")] } -*/ \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index aa991fce..17655d0e 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/local-rest-scorer/build.gradle b/local-rest-scorer/build.gradle index a6a35151..18d99492 100644 --- a/local-rest-scorer/build.gradle +++ b/local-rest-scorer/build.gradle @@ -31,6 +31,9 @@ dependencies { test { useJUnitPlatform() + + jvmArgs '--add-opens=java.base/java.util=ALL-UNNAMED' + jvmArgs '--add-opens=java.base/java.lang=ALL-UNNAMED' } bootRun { diff --git a/settings.gradle b/settings.gradle index 29b59ed7..e1a32c9e 100644 --- a/settings.gradle +++ b/settings.gradle @@ -14,18 +14,18 @@ dependencyResolutionManagement { } rootProject.name = 'dai-deployment-templates' -include 'aws-lambda-scorer:lambda-template' -include 'aws-lambda-scorer:terraform-recipe' -include 'common:jdbc' +//include 'aws-lambda-scorer:lambda-template' +//include 'aws-lambda-scorer:terraform-recipe' +//include 'common:jdbc' include 'common:rest-java-model' -include 'common:rest-jdbc-spring-api' +//include 'common:rest-jdbc-spring-api' include 'common:rest-spring-api' include 'common:transform' -include 'common:kdb-java' -include 'common:rest-vertex-ai-spring-api' +//include 'common:kdb-java' +//include 'common:rest-vertex-ai-spring-api' include 'local-rest-scorer' -include 'kdb-mojo-scorer' -include 'aws-sagemaker-hosted-scorer' -include 'gcp-cloud-run' -include 'sql-jdbc-scorer' -include 'gcp-vertex-ai-mojo-scorer' +//include 'kdb-mojo-scorer' +//include 'aws-sagemaker-hosted-scorer' +//include 'gcp-cloud-run' +//include 'sql-jdbc-scorer' +//include 'gcp-vertex-ai-mojo-scorer' From 38558e655267b8415807b6d85237344ee00e26fa Mon Sep 17 00:00:00 2001 From: jackjii79 Date: Tue, 12 Mar 2024 10:38:13 -0700 Subject: [PATCH 5/5] try virtual thread --- .../java/ai/h2o/mojos/deploy/local/rest/ScorerApplication.java | 2 +- local-rest-scorer/src/main/resources/application.properties | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/local-rest-scorer/src/main/java/ai/h2o/mojos/deploy/local/rest/ScorerApplication.java b/local-rest-scorer/src/main/java/ai/h2o/mojos/deploy/local/rest/ScorerApplication.java index f39c1dd6..6651dcfc 100644 --- a/local-rest-scorer/src/main/java/ai/h2o/mojos/deploy/local/rest/ScorerApplication.java +++ b/local-rest-scorer/src/main/java/ai/h2o/mojos/deploy/local/rest/ScorerApplication.java @@ -6,6 +6,6 @@ @SpringBootApplication public class ScorerApplication { public static void main(String[] args) { - new SpringApplication(ScorerApplication.class).run(args); + SpringApplication.run(ScorerApplication.class, args); } } diff --git a/local-rest-scorer/src/main/resources/application.properties b/local-rest-scorer/src/main/resources/application.properties index 332ceeb8..fd1a8542 100644 --- a/local-rest-scorer/src/main/resources/application.properties +++ b/local-rest-scorer/src/main/resources/application.properties @@ -1,2 +1,3 @@ logging.level.ai.h2o.mojos.deploy.common.transform.MojoScorer=${LOGLEVEL} logging.level.ai.h2o.mojos.deploy.local.rest.controller.ModelsApiController=${LOGLEVEL} +spring.threads.virtual.enabled=true