Skip to content
This repository has been archived by the owner on Nov 29, 2024. It is now read-only.

Commit

Permalink
add media score endpoint with exp controller
Browse files Browse the repository at this point in the history
  • Loading branch information
jih147 committed Jun 13, 2023
1 parent e1aeafb commit c0c691c
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 39 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
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());
}
@Override
public void addFormatters(FormatterRegistry registry) {
registry.addConverter(new MultipartConverter());
registry.addConverter(new ScoreMediaRequestConverter());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
Expand Down Expand Up @@ -157,13 +156,6 @@ public ResponseEntity<ScoreRequest> getSampleRequest() {
return ResponseEntity.ok(sampleRequestBuilder.build(scorer.getPipeline().getInputMeta()));
}

@Override
public ResponseEntity<ScoreResponse> getScoreMedia(
ScoreMediaRequest scoreMediaRequest, List<Resource> files) {
log.info("Received score media request");
return ResponseEntity.status(HttpStatus.NOT_IMPLEMENTED).build();
}

private String getScorerModelId() {
try {
String res = System.getenv(MODEL_ID);
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ScoreResponse> getMediaScore(
ScoreMediaRequest request, List<Resource> files) {
log.info("Got score media request");
throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED,
"score media files is not implemented");
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package ai.h2o.mojos.deploy.local.rest.Converter;
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<MultipartFile, Resource> {

@Override
public Resource convert(MultipartFile source) {
return source.getResource();
}
@Override
public Resource convert(MultipartFile source) {
return source.getResource();
}
}
Original file line number Diff line number Diff line change
@@ -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<String, ScoreMediaRequest> {

@Override
public ScoreMediaRequest convert(String input) {
return new Gson().fromJson(input, ScoreMediaRequest.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -193,16 +194,17 @@ void verifyScore_Fails_ReturnsException() {
@Test
void verifyScoreMedia_ReturnsUnimplemented() {
// Given
MojoScorer scorer = mock(MojoScorer.class);
ScoreMediaRequest request = mock(ScoreMediaRequest.class);
List<Resource> files = new ArrayList<>();
ModelsApiControllerV1Exp controller = new ModelsApiController(scorer, sampleRequestBuilder);

// When
ResponseEntity<ScoreResponse> response =
controller.getScoreMedia(request, files);
ModelsMediaController controller = new ModelsMediaController();

// Then
assertEquals(response.getStatusCode(), HttpStatus.NOT_IMPLEMENTED);
// 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());
}
}
}

0 comments on commit c0c691c

Please sign in to comment.