diff --git a/aws-sagemaker-hosted-scorer-cpp/requirements.txt b/aws-sagemaker-hosted-scorer-cpp/requirements.txt index 71b74844..b1ca6c2d 100644 --- a/aws-sagemaker-hosted-scorer-cpp/requirements.txt +++ b/aws-sagemaker-hosted-scorer-cpp/requirements.txt @@ -16,4 +16,4 @@ pytz==2022.1 six==1.16.0 Werkzeug==2.1.2 zipp==3.8.0 -https://s3.amazonaws.com/artifacts.h2o.ai/releases/ai/h2o/daimojo/2.7.9/x86_64-centos7/daimojo-2.7.9-cp38-cp38-linux_x86_64.whl +https://s3.amazonaws.com/artifacts.h2o.ai/releases/ai/h2o/daimojo/2.8.1/x86_64-centos7/daimojo-2.8.1-cp38-cp38-linux_x86_64.whl diff --git a/aws-sagemaker-hosted-scorer-cpp/requirements_gpu.txt b/aws-sagemaker-hosted-scorer-cpp/requirements_gpu.txt index 341d1967..a7e90abf 100644 --- a/aws-sagemaker-hosted-scorer-cpp/requirements_gpu.txt +++ b/aws-sagemaker-hosted-scorer-cpp/requirements_gpu.txt @@ -16,4 +16,4 @@ pytz==2022.1 six==1.16.0 Werkzeug==2.1.2 zipp==3.8.0 -https://s3.amazonaws.com/artifacts.h2o.ai/releases/ai/h2o/daimojo/2.7.9/x86_64-centos7/daimojo-2.7.9%2Bcu111-cp38-cp38-linux_x86_64.whl \ No newline at end of file +https://s3.amazonaws.com/artifacts.h2o.ai/releases/ai/h2o/daimojo/2.8.1/x86_64-centos7/daimojo-2.8.1%2Bcu117-cp38-cp38-linux_x86_64.whl \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index eb26c18a..1b00d803 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,7 +5,7 @@ version = 1.1.21-SNAPSHOT # Internal dependencies: h2oVersion = 3.40.0.3 -mojoRuntimeVersion = 2.7.12.2 +mojoRuntimeVersion = 2.8.2 # External dependencies: awsLambdaCoreVersion = 1.2.0 diff --git a/local-rest-scorer/src/main/java/ai/h2o/mojos/deploy/local/rest/config/WebConfig.java b/local-rest-scorer/src/main/java/ai/h2o/mojos/deploy/local/rest/config/WebConfig.java new file mode 100644 index 00000000..4f959c99 --- /dev/null +++ b/local-rest-scorer/src/main/java/ai/h2o/mojos/deploy/local/rest/config/WebConfig.java @@ -0,0 +1,17 @@ +package ai.h2o.mojos.deploy.local.rest.config; + +import ai.h2o.mojos.deploy.local.rest.converter.MultipartConverter; +import ai.h2o.mojos.deploy.local.rest.converter.ScoreMediaRequestConverter; +import org.springframework.context.annotation.Configuration; +import org.springframework.format.FormatterRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +@Configuration +public class WebConfig implements WebMvcConfigurer { + + @Override + public void addFormatters(FormatterRegistry registry) { + registry.addConverter(new MultipartConverter()); + registry.addConverter(new ScoreMediaRequestConverter()); + } +} diff --git a/local-rest-scorer/src/main/java/ai/h2o/mojos/deploy/local/rest/controller/ModelsMediaController.java b/local-rest-scorer/src/main/java/ai/h2o/mojos/deploy/local/rest/controller/ModelsMediaController.java new file mode 100644 index 00000000..0cc7aa75 --- /dev/null +++ b/local-rest-scorer/src/main/java/ai/h2o/mojos/deploy/local/rest/controller/ModelsMediaController.java @@ -0,0 +1,26 @@ +package ai.h2o.mojos.deploy.local.rest.controller; + +import ai.h2o.mojos.deploy.common.rest.v1exp.api.ModelApi; +import ai.h2o.mojos.deploy.common.rest.v1exp.model.ScoreMediaRequest; +import ai.h2o.mojos.deploy.common.rest.v1exp.model.ScoreResponse; +import java.util.List; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.core.io.Resource; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.server.ResponseStatusException; + +@Controller +public class ModelsMediaController implements ModelApi { + private static final Logger log = LoggerFactory.getLogger(ModelsMediaController.class); + + @Override + public ResponseEntity getMediaScore( + ScoreMediaRequest request, List files) { + log.info("Got score media request"); + throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, + "score media files is not implemented"); + } +} diff --git a/local-rest-scorer/src/main/java/ai/h2o/mojos/deploy/local/rest/converter/MultipartConverter.java b/local-rest-scorer/src/main/java/ai/h2o/mojos/deploy/local/rest/converter/MultipartConverter.java new file mode 100644 index 00000000..b385dc7e --- /dev/null +++ b/local-rest-scorer/src/main/java/ai/h2o/mojos/deploy/local/rest/converter/MultipartConverter.java @@ -0,0 +1,13 @@ +package ai.h2o.mojos.deploy.local.rest.converter; + +import org.springframework.core.convert.converter.Converter; +import org.springframework.core.io.Resource; +import org.springframework.web.multipart.MultipartFile; + +public class MultipartConverter implements Converter { + + @Override + public Resource convert(MultipartFile source) { + return source.getResource(); + } +} diff --git a/local-rest-scorer/src/main/java/ai/h2o/mojos/deploy/local/rest/converter/ScoreMediaRequestConverter.java b/local-rest-scorer/src/main/java/ai/h2o/mojos/deploy/local/rest/converter/ScoreMediaRequestConverter.java new file mode 100644 index 00000000..b30f1181 --- /dev/null +++ b/local-rest-scorer/src/main/java/ai/h2o/mojos/deploy/local/rest/converter/ScoreMediaRequestConverter.java @@ -0,0 +1,13 @@ +package ai.h2o.mojos.deploy.local.rest.converter; + +import ai.h2o.mojos.deploy.common.rest.v1exp.model.ScoreMediaRequest; +import com.google.gson.Gson; +import org.springframework.core.convert.converter.Converter; + +public class ScoreMediaRequestConverter implements Converter { + + @Override + public ScoreMediaRequest convert(String input) { + return new Gson().fromJson(input, ScoreMediaRequest.class); + } +} diff --git a/local-rest-scorer/src/test/java/ai/h2o/mojos/deploy/local/rest/controller/ModelsApiControllerTest.java b/local-rest-scorer/src/test/java/ai/h2o/mojos/deploy/local/rest/controller/ModelsApiControllerTest.java index bae20b18..64f5a716 100644 --- a/local-rest-scorer/src/test/java/ai/h2o/mojos/deploy/local/rest/controller/ModelsApiControllerTest.java +++ b/local-rest-scorer/src/test/java/ai/h2o/mojos/deploy/local/rest/controller/ModelsApiControllerTest.java @@ -11,6 +11,7 @@ import ai.h2o.mojos.deploy.common.rest.model.Model; import ai.h2o.mojos.deploy.common.rest.model.ScoreRequest; import ai.h2o.mojos.deploy.common.rest.model.ScoreResponse; +import ai.h2o.mojos.deploy.common.rest.v1exp.model.ScoreMediaRequest; import ai.h2o.mojos.deploy.common.transform.MojoScorer; import ai.h2o.mojos.deploy.common.transform.SampleRequestBuilder; import ai.h2o.mojos.deploy.common.transform.ShapleyLoadOption; @@ -20,6 +21,7 @@ import java.io.File; import java.io.IOException; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -32,6 +34,7 @@ import org.mockito.MockedStatic; import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.core.io.Resource; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.server.ResponseStatusException; @@ -187,4 +190,21 @@ void verifyScore_Fails_ReturnsException() { assertEquals(HttpStatus.SERVICE_UNAVAILABLE, ((ResponseStatusException) ex).getStatus()); } } + + @Test + void verifyScoreMedia_ReturnsUnimplemented() { + // Given + ScoreMediaRequest request = mock(ScoreMediaRequest.class); + List files = new ArrayList<>(); + ModelsMediaController controller = new ModelsMediaController(); + + // When & Then + try { + controller.getMediaScore(request, files); + fail("exception is expected, but fail to raise"); + } catch (Exception ex) { + assertTrue(ex instanceof ResponseStatusException); + assertEquals(HttpStatus.NOT_IMPLEMENTED, ((ResponseStatusException) ex).getStatus()); + } + } }