Search in sources :

Example 1 with Feedback

use of io.seldon.protos.PredictionProtos.Feedback in project seldon-core by SeldonIO.

the class RestClientController method feedback.

@RequestMapping(value = "/api/v0.1/feedback", method = RequestMethod.POST, consumes = "application/json; charset=utf-8", produces = "application/json; charset=utf-8")
public ResponseEntity<String> feedback(RequestEntity<String> requestEntity) {
    Feedback feedback;
    try {
        Feedback.Builder builder = Feedback.newBuilder();
        ProtoBufUtils.updateMessageBuilderFromJson(builder, requestEntity.getBody());
        feedback = builder.build();
    } catch (InvalidProtocolBufferException e) {
        logger.error("Bad request", e);
        throw new APIException(ApiExceptionType.ENGINE_INVALID_JSON, requestEntity.getBody());
    }
    try {
        predictionService.sendFeedback(feedback);
        String json = "{}";
        return new ResponseEntity<String>(json, HttpStatus.OK);
    } catch (InterruptedException e) {
        throw new APIException(ApiExceptionType.ENGINE_INTERRUPTED, e.getMessage());
    } catch (ExecutionException e) {
        if (e.getCause().getClass() == APIException.class) {
            throw (APIException) e.getCause();
        } else {
            throw new APIException(ApiExceptionType.ENGINE_EXECUTION_FAILURE, e.getMessage());
        }
    } catch (InvalidProtocolBufferException e) {
        throw new APIException(ApiExceptionType.ENGINE_INVALID_JSON, "");
    }
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) APIException(io.seldon.engine.exception.APIException) Feedback(io.seldon.protos.PredictionProtos.Feedback) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ExecutionException(java.util.concurrent.ExecutionException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with Feedback

use of io.seldon.protos.PredictionProtos.Feedback in project seldon-core by SeldonIO.

the class RestClientController method feedback.

@RequestMapping(value = "/api/v0.1/feedback", method = RequestMethod.POST, consumes = "application/json; charset=utf-8", produces = "application/json; charset=utf-8")
@ResponseStatus(value = HttpStatus.OK)
public void feedback(RequestEntity<String> requestEntity, Principal principal) {
    String clientId = principal.getName();
    String json = requestEntity.getBody();
    Feedback feedback;
    try {
        Feedback.Builder builder = Feedback.newBuilder();
        ProtoBufUtils.updateMessageBuilderFromJson(builder, requestEntity.getBody());
        feedback = builder.build();
        Iterable<Tag> tags = asList(tagsProvider.principal(clientId), tagsProvider.projectName(clientId), tagsProvider.deploymentName(clientId), tagsProvider.deploymentVersion(clientId));
        Counter.builder("seldon_api_ingress_server_feedback_reward").tags(tags).register(Metrics.globalRegistry).increment(feedback.getReward());
        Counter.builder("seldon_api_ingress_server_feedback").tags(tags).register(Metrics.globalRegistry).increment();
    } catch (InvalidProtocolBufferException e) {
        logger.error("Bad request", e);
        throw new SeldonAPIException(ApiExceptionType.APIFE_INVALID_RESPONSE_JSON, requestEntity.getBody());
    }
    predictionService.sendFeedback(json, clientId);
}
Also used : SeldonAPIException(io.seldon.apife.exception.SeldonAPIException) Feedback(io.seldon.protos.PredictionProtos.Feedback) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) Tag(io.micrometer.core.instrument.Tag) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)2 Feedback (io.seldon.protos.PredictionProtos.Feedback)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 Tag (io.micrometer.core.instrument.Tag)1 SeldonAPIException (io.seldon.apife.exception.SeldonAPIException)1 APIException (io.seldon.engine.exception.APIException)1 ExecutionException (java.util.concurrent.ExecutionException)1 ResponseEntity (org.springframework.http.ResponseEntity)1 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)1