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, "");
}
}
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);
}
Aggregations