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