Search in sources :

Example 81 with InvalidProtocolBufferException

use of com.google.protobuf.InvalidProtocolBufferException in project grpc-java by grpc.

the class RbacFilter method parseFilterConfig.

@Override
public ConfigOrError<RbacConfig> parseFilterConfig(Message rawProtoMessage) {
    RBAC rbacProto;
    if (!(rawProtoMessage instanceof Any)) {
        return ConfigOrError.fromError("Invalid config type: " + rawProtoMessage.getClass());
    }
    Any anyMessage = (Any) rawProtoMessage;
    try {
        rbacProto = anyMessage.unpack(RBAC.class);
    } catch (InvalidProtocolBufferException e) {
        return ConfigOrError.fromError("Invalid proto: " + e);
    }
    return parseRbacConfig(rbacProto);
}
Also used : RBAC(io.envoyproxy.envoy.extensions.filters.http.rbac.v3.RBAC) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) Any(com.google.protobuf.Any)

Example 82 with InvalidProtocolBufferException

use of com.google.protobuf.InvalidProtocolBufferException in project druid by druid-io.

the class ProtobufReader method parseInputRows.

@Override
protected List<InputRow> parseInputRows(DynamicMessage intermediateRow) throws ParseException, JsonProcessingException {
    Map<String, Object> record;
    if (flattenSpec == null || JSONPathSpec.DEFAULT.equals(flattenSpec)) {
        try {
            record = CollectionUtils.mapKeys(intermediateRow.getAllFields(), k -> k.getJsonName());
        } catch (Exception ex) {
            throw new ParseException(null, ex, "Protobuf message could not be parsed");
        }
    } else {
        try {
            String json = JsonFormat.printer().print(intermediateRow);
            record = recordFlattener.flatten(OBJECT_MAPPER.readValue(json, JsonNode.class));
        } catch (InvalidProtocolBufferException e) {
            throw new ParseException(null, e, "Protobuf message could not be parsed");
        }
    }
    return Collections.singletonList(MapInputRowParser.parse(inputRowSchema, record));
}
Also used : DynamicMessage(com.google.protobuf.DynamicMessage) ParseException(org.apache.druid.java.util.common.parsers.ParseException) ObjectFlattener(org.apache.druid.java.util.common.parsers.ObjectFlattener) CollectionUtils(org.apache.druid.utils.CollectionUtils) InputRowSchema(org.apache.druid.data.input.InputRowSchema) Iterators(com.google.common.collect.Iterators) ByteBuffer(java.nio.ByteBuffer) JSONPathSpec(org.apache.druid.java.util.common.parsers.JSONPathSpec) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) CloseableIterator(org.apache.druid.java.util.common.parsers.CloseableIterator) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) MapInputRowParser(org.apache.druid.data.input.impl.MapInputRowParser) JSONFlattenerMaker(org.apache.druid.java.util.common.parsers.JSONFlattenerMaker) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) IOUtils(org.apache.commons.io.IOUtils) InputRow(org.apache.druid.data.input.InputRow) List(java.util.List) IntermediateRowParsingReader(org.apache.druid.data.input.IntermediateRowParsingReader) CloseableIterators(org.apache.druid.java.util.common.CloseableIterators) JsonFormat(com.google.protobuf.util.JsonFormat) ObjectFlatteners(org.apache.druid.java.util.common.parsers.ObjectFlatteners) InputEntity(org.apache.druid.data.input.InputEntity) Collections(java.util.Collections) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ParseException(org.apache.druid.java.util.common.parsers.ParseException) ParseException(org.apache.druid.java.util.common.parsers.ParseException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException)

Example 83 with InvalidProtocolBufferException

use of com.google.protobuf.InvalidProtocolBufferException in project heron by twitter.

the class PhysicalPlanProvider method ParseResponseToPhysicalPlan.

protected PhysicalPlan ParseResponseToPhysicalPlan(byte[] responseData) {
    // byte to base64 string
    String encodedString = new String(responseData);
    LOG.fine("tmanager returns physical plan in base64 str: " + encodedString);
    // base64 string to proto bytes
    byte[] decodedBytes = Base64.getDecoder().decode(encodedString);
    // construct proto obj from bytes
    PhysicalPlan pp = null;
    try {
        pp = PhysicalPlan.parseFrom(decodedBytes);
    } catch (InvalidProtocolBufferException e) {
        throw new InvalidStateException(topologyName, "Failed to fetch the physical plan");
    }
    return pp;
}
Also used : PhysicalPlan(org.apache.heron.proto.system.PhysicalPlans.PhysicalPlan) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException)

Example 84 with InvalidProtocolBufferException

use of com.google.protobuf.InvalidProtocolBufferException in project heron by twitter.

the class LocalFileSystemStorage method restoreCheckpoint.

@Override
public Checkpoint restoreCheckpoint(CheckpointInfo info) throws StatefulStorageException {
    String path = getCheckpointPath(info.getCheckpointId(), info.getComponent(), info.getInstanceId());
    byte[] res = FileUtils.readFromFile(path);
    if (res.length != 0) {
        // Try to parse the protobuf
        CheckpointManager.InstanceStateCheckpoint state;
        try {
            state = CheckpointManager.InstanceStateCheckpoint.parseFrom(res);
        } catch (InvalidProtocolBufferException e) {
            throw new StatefulStorageException("Failed to parse the data", e);
        }
        return new Checkpoint(state);
    } else {
        throw new StatefulStorageException("Failed to parse the data");
    }
}
Also used : StatefulStorageException(org.apache.heron.spi.statefulstorage.StatefulStorageException) Checkpoint(org.apache.heron.spi.statefulstorage.Checkpoint) CheckpointManager(org.apache.heron.proto.ckptmgr.CheckpointManager) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException)

Example 85 with InvalidProtocolBufferException

use of com.google.protobuf.InvalidProtocolBufferException in project heron by twitter.

the class MetricsCacheMetricsProvider method getMetricsFromMetricsCache.

@VisibleForTesting
TopologyManager.MetricResponse getMetricsFromMetricsCache(String metric, String component, Instant start, Duration duration) {
    LOG.log(Level.FINE, "MetricsCache Query request metric name : {0}", metric);
    TopologyManager.MetricRequest request = TopologyManager.MetricRequest.newBuilder().setComponentName(component).setExplicitInterval(MetricInterval.newBuilder().setStart(start.minus(duration).getEpochSecond()).setEnd(start.getEpochSecond()).build()).addMetric(metric).build();
    LOG.log(Level.FINE, "MetricsCache Query request: \n{0}", request);
    HttpURLConnection connection = NetworkUtils.getHttpConnection(getCacheLocation());
    try {
        boolean result = NetworkUtils.sendHttpPostRequest(connection, "X", request.toByteArray());
        if (!result) {
            LOG.warning("Failed to get response from metrics cache. Resetting connection...");
            resetCacheLocation();
            return null;
        }
        byte[] responseData = NetworkUtils.readHttpResponse(connection);
        try {
            TopologyManager.MetricResponse response = TopologyManager.MetricResponse.parseFrom(responseData);
            LOG.log(Level.FINE, "MetricsCache Query response: \n{0}", response);
            return response;
        } catch (InvalidProtocolBufferException e) {
            LOG.log(Level.SEVERE, "protobuf cannot parse the reply from MetricsCache ", e);
            return null;
        }
    } finally {
        if (connection != null) {
            connection.disconnect();
        }
    }
}
Also used : TopologyManager(org.apache.heron.proto.tmanager.TopologyManager) HttpURLConnection(java.net.HttpURLConnection) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

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