use of org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.InvalidProtocolBufferException in project grpc-java by grpc.
the class RouteLookupServiceClusterSpecifierPlugin method parsePlugin.
@Override
@SuppressWarnings("unchecked")
public ConfigOrError<RlsPluginConfig> parsePlugin(Message rawProtoMessage) {
if (!(rawProtoMessage instanceof Any)) {
return ConfigOrError.fromError("Invalid config type: " + rawProtoMessage.getClass());
}
try {
Any anyMessage = (Any) rawProtoMessage;
Class<? extends Message> protoClass;
try {
protoClass = (Class<? extends Message>) Class.forName("io.grpc.lookup.v1.RouteLookupClusterSpecifier");
} catch (ClassNotFoundException e) {
return ConfigOrError.fromError("Dependency for 'io.grpc:grpc-rls' is missing: " + e);
}
Message configProto;
try {
configProto = anyMessage.unpack(protoClass);
} catch (InvalidProtocolBufferException e) {
return ConfigOrError.fromError("Invalid proto: " + e);
}
String jsonString = MessagePrinter.print(configProto);
try {
Map<String, ?> jsonMap = (Map<String, ?>) JsonParser.parse(jsonString);
Map<String, ?> config = JsonUtil.getObject(jsonMap, "routeLookupConfig");
return ConfigOrError.fromConfig(RlsPluginConfig.create(config));
} catch (IOException e) {
return ConfigOrError.fromError("Unable to parse RouteLookupClusterSpecifier: " + jsonString);
}
} catch (RuntimeException e) {
return ConfigOrError.fromError("Error parsing RouteLookupConfig: " + e);
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.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 org.apache.beam.vendor.grpc.v1p43p2.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 org.apache.beam.vendor.grpc.v1p43p2.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 org.apache.beam.vendor.grpc.v1p43p2.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");
}
}
Aggregations