Search in sources :

Example 61 with InvalidProtocolBufferException

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);
    }
}
Also used : InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) IntOrString(io.kubernetes.client.proto.IntStr.IntOrString)

Example 62 with InvalidProtocolBufferException

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;
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) SeldonMessage(io.seldon.protos.PredictionProtos.SeldonMessage) SeldonAPIException(io.seldon.apife.exception.SeldonAPIException) HttpStatus(org.springframework.http.HttpStatus) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 63 with InvalidProtocolBufferException

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 {
    }
}
Also used : CustomObjectsApi(io.kubernetes.client.apis.CustomObjectsApi) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) IOException(java.io.IOException) ApiClient(io.kubernetes.client.ApiClient) SeldonDeployment(io.seldon.protos.DeploymentProtos.SeldonDeployment) ApiException(io.kubernetes.client.ApiException)

Example 64 with InvalidProtocolBufferException

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;
    }
}
Also used : CustomObjectsApi(io.kubernetes.client.apis.CustomObjectsApi) GsonBuilder(com.google.gson.GsonBuilder) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) Gson(com.google.gson.Gson) IOException(java.io.IOException) ApiClient(io.kubernetes.client.ApiClient) ApiException(io.kubernetes.client.ApiException)

Example 65 with InvalidProtocolBufferException

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

Aggregations

InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)260 ServerRequest (com.pokegoapi.main.ServerRequest)46 ByteString (com.google.protobuf.ByteString)42 IOException (java.io.IOException)41 RequestFailedException (com.pokegoapi.exceptions.request.RequestFailedException)39 InvalidProtocolBufferException (org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.InvalidProtocolBufferException)22 HashMap (java.util.HashMap)21 ArrayList (java.util.ArrayList)19 List (java.util.List)18 Map (java.util.Map)17 Any (com.google.protobuf.Any)16 RunnerApi (org.apache.beam.model.pipeline.v1.RunnerApi)15 HashSet (java.util.HashSet)11 Key (org.apache.accumulo.core.data.Key)10 Value (org.apache.accumulo.core.data.Value)10 Status (org.apache.accumulo.server.replication.proto.Replication.Status)10 Text (org.apache.hadoop.io.Text)10 JsonToken (com.fasterxml.jackson.core.JsonToken)9 ByteString (org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.ByteString)9 ContractExeException (org.tron.core.exception.ContractExeException)9