use of com.google.protobuf.InvalidProtocolBufferException in project seldon-core by SeldonIO.
the class SeldonDeploymentOperatorImpl method getEngineEnvVarJson.
private static String getEngineEnvVarJson(Message protoMessage) throws SeldonDeploymentException {
String retVal;
try {
retVal = ProtoBufUtils.toJson(protoMessage, true, false);
retVal = new String(Base64.getEncoder().encode(retVal.getBytes()));
return retVal;
} catch (InvalidProtocolBufferException e) {
throw new SeldonDeploymentException("Failed to parse protobuf", e);
}
}
use of com.google.protobuf.InvalidProtocolBufferException in project seldon-core by SeldonIO.
the class RestClientController method prediction.
@RequestMapping(value = "/api/v0.1/predictions", method = RequestMethod.POST, consumes = "application/json; charset=utf-8", produces = "application/json; charset=utf-8")
public ResponseEntity<String> prediction(RequestEntity<String> requestEntity, Principal principal) {
String clientId = principal.getName();
String json = requestEntity.getBody();
logger.info(String.format("[%s] [%s] [%s] [%s]", "POST", requestEntity.getUrl().getPath(), clientId, json));
SeldonMessage request;
try {
SeldonMessage.Builder builder = SeldonMessage.newBuilder();
ProtoBufUtils.updateMessageBuilderFromJson(builder, requestEntity.getBody());
request = builder.build();
} catch (InvalidProtocolBufferException e) {
logger.error("Bad request", e);
throw new SeldonAPIException(ApiExceptionType.APIFE_INVALID_JSON, requestEntity.getBody());
}
HttpStatus httpStatus = HttpStatus.OK;
// At present passes JSON string. Could use gRPC?
String ret = predictionService.predict(json, clientId);
SeldonMessage response;
try {
SeldonMessage.Builder builder = SeldonMessage.newBuilder();
ProtoBufUtils.updateMessageBuilderFromJson(builder, ret);
response = builder.build();
} catch (InvalidProtocolBufferException e) {
logger.error("Bad response", e);
throw new SeldonAPIException(ApiExceptionType.APIFE_INVALID_RESPONSE_JSON, requestEntity.getBody());
}
kafkaProducer.send(clientId, RequestResponse.newBuilder().setRequest(request).setResponse(response).build());
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setContentType(MediaType.APPLICATION_JSON);
ResponseEntity<String> responseEntity = new ResponseEntity<String>(ret, responseHeaders, httpStatus);
return responseEntity;
}
use of com.google.protobuf.InvalidProtocolBufferException in project seldon-core by SeldonIO.
the class KubeCRDHandlerImpl method updateSeldonDeployment.
@Override
public void updateSeldonDeployment(SeldonDeployment mldep) {
try {
// Need to remove resourceVersion from the representation used for last-applied-configuration otherwise you will errors subsequently using kubectl
SeldonDeployment mlDepTmp = SeldonDeployment.newBuilder(mldep).setMetadata(ObjectMeta.newBuilder(mldep.getMetadata()).clearResourceVersion().removeAnnotations("kubectl.kubernetes.io/last-applied-configuration").build()).build();
// Create string representation of JSON to add as annotation to allow declarative "kubectl apply" commands to work otherwise a replace
// would remove the last-applied-configuration that kubectl adds.
String json = SeldonDeploymentUtils.toJson(mlDepTmp, true);
// Create final version of deployment with annotation
SeldonDeployment mlDeployment = SeldonDeployment.newBuilder(mldep).setMetadata(ObjectMeta.newBuilder(mldep.getMetadata()).putAnnotations("kubectl.kubernetes.io/last-applied-configuration", json + "\n")).build();
json = SeldonDeploymentUtils.toJson(mlDeployment, false);
logger.debug("Updating seldondeployment " + mlDeployment.getMetadata().getName());
ApiClient client = Config.defaultClient();
CustomObjectsApi api = new CustomObjectsApi(client);
api.replaceNamespacedCustomObject(GROUP, VERSION, namespace, KIND_PLURAL, mlDeployment.getMetadata().getName(), json.getBytes());
} catch (InvalidProtocolBufferException e) {
logger.error("Failed to update deployment in kubernetes ", e);
} catch (ApiException e) {
logger.error("Failed to update deployment in kubernetes ", e);
} catch (IOException e) {
logger.error("Failed to get client ", e);
} finally {
}
}
use of com.google.protobuf.InvalidProtocolBufferException in project seldon-core by SeldonIO.
the class KubeCRDHandlerImpl method getSeldonDeployment.
@Override
public SeldonDeployment getSeldonDeployment(String name) {
try {
ApiClient client = Config.defaultClient();
CustomObjectsApi api = new CustomObjectsApi(client);
Object resp = api.getNamespacedCustomObject(GROUP, VERSION, namespace, KIND_PLURAL, name);
Gson gson = new GsonBuilder().create();
String json = gson.toJson(resp);
try {
return SeldonDeploymentUtils.jsonToSeldonDeployment(json);
} catch (InvalidProtocolBufferException e) {
logger.error("Failed to parse " + json, e);
return null;
}
} catch (ApiException e) {
return null;
} catch (IOException e) {
logger.error("Failed to get client", e);
return null;
}
}
use of com.google.protobuf.InvalidProtocolBufferException 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, "");
}
}
Aggregations