use of org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.InvalidProtocolBufferException in project grpc-java by grpc.
the class ClientXdsClient method parseAggregateCluster.
private static StructOrError<CdsUpdate.Builder> parseAggregateCluster(Cluster cluster) {
String clusterName = cluster.getName();
CustomClusterType customType = cluster.getClusterType();
String typeName = customType.getName();
if (!typeName.equals(AGGREGATE_CLUSTER_TYPE_NAME)) {
return StructOrError.fromError("Cluster " + clusterName + ": unsupported custom cluster type: " + typeName);
}
io.envoyproxy.envoy.extensions.clusters.aggregate.v3.ClusterConfig clusterConfig;
try {
clusterConfig = unpackCompatibleType(customType.getTypedConfig(), io.envoyproxy.envoy.extensions.clusters.aggregate.v3.ClusterConfig.class, TYPE_URL_CLUSTER_CONFIG, TYPE_URL_CLUSTER_CONFIG_V2);
} catch (InvalidProtocolBufferException e) {
return StructOrError.fromError("Cluster " + clusterName + ": malformed ClusterConfig: " + e);
}
return StructOrError.fromStruct(CdsUpdate.forAggregate(clusterName, clusterConfig.getClustersList()));
}
use of org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.InvalidProtocolBufferException in project grpc-java by grpc.
the class ClientXdsClient method parseHttpFilter.
@VisibleForTesting
// Returns null if the filter is optional but not supported.
@Nullable
static StructOrError<FilterConfig> parseHttpFilter(io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.HttpFilter httpFilter, FilterRegistry filterRegistry, boolean isForClient) {
String filterName = httpFilter.getName();
boolean isOptional = httpFilter.getIsOptional();
if (!httpFilter.hasTypedConfig()) {
if (isOptional) {
return null;
} else {
return StructOrError.fromError("HttpFilter [" + filterName + "] is not optional and has no typed config");
}
}
Message rawConfig = httpFilter.getTypedConfig();
String typeUrl = httpFilter.getTypedConfig().getTypeUrl();
try {
if (typeUrl.equals(TYPE_URL_TYPED_STRUCT_UDPA)) {
TypedStruct typedStruct = httpFilter.getTypedConfig().unpack(TypedStruct.class);
typeUrl = typedStruct.getTypeUrl();
rawConfig = typedStruct.getValue();
} else if (typeUrl.equals(TYPE_URL_TYPED_STRUCT)) {
com.github.xds.type.v3.TypedStruct newTypedStruct = httpFilter.getTypedConfig().unpack(com.github.xds.type.v3.TypedStruct.class);
typeUrl = newTypedStruct.getTypeUrl();
rawConfig = newTypedStruct.getValue();
}
} catch (InvalidProtocolBufferException e) {
return StructOrError.fromError("HttpFilter [" + filterName + "] contains invalid proto: " + e);
}
Filter filter = filterRegistry.get(typeUrl);
if ((isForClient && !(filter instanceof ClientInterceptorBuilder)) || (!isForClient && !(filter instanceof ServerInterceptorBuilder))) {
if (isOptional) {
return null;
} else {
return StructOrError.fromError("HttpFilter [" + filterName + "](" + typeUrl + ") is required but unsupported for " + (isForClient ? "client" : "server"));
}
}
ConfigOrError<? extends FilterConfig> filterConfig = filter.parseFilterConfig(rawConfig);
if (filterConfig.errorDetail != null) {
return StructOrError.fromError("Invalid filter config for HttpFilter [" + filterName + "]: " + filterConfig.errorDetail);
}
return StructOrError.fromStruct(filterConfig.config);
}
use of org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.InvalidProtocolBufferException in project grpc-java by grpc.
the class ClientXdsClient method handleCdsResponse.
@Override
public void handleCdsResponse(ServerInfo serverInfo, String versionInfo, List<Any> resources, String nonce) {
syncContext.throwIfNotInThisSynchronizationContext();
Map<String, ParsedResource> parsedResources = new HashMap<>(resources.size());
Set<String> unpackedResources = new HashSet<>(resources.size());
Set<String> invalidResources = new HashSet<>();
List<String> errors = new ArrayList<>();
Set<String> retainedEdsResources = new HashSet<>();
for (int i = 0; i < resources.size(); i++) {
Any resource = resources.get(i);
// Unpack the Cluster.
Cluster cluster;
try {
cluster = unpackCompatibleType(resource, Cluster.class, ResourceType.CDS.typeUrl(), ResourceType.CDS.typeUrlV2());
} catch (InvalidProtocolBufferException e) {
errors.add("CDS response Resource index " + i + " - can't decode Cluster: " + e);
continue;
}
if (!isResourceNameValid(cluster.getName(), resource.getTypeUrl())) {
errors.add("Unsupported resource name: " + cluster.getName() + " for type: " + ResourceType.CDS);
continue;
}
String clusterName = canonifyResourceName(cluster.getName());
// unrequested resources.
if (!cdsResourceSubscribers.containsKey(clusterName)) {
continue;
}
unpackedResources.add(clusterName);
// Process Cluster into CdsUpdate.
CdsUpdate cdsUpdate;
try {
Set<String> certProviderInstances = null;
if (getBootstrapInfo() != null && getBootstrapInfo().certProviders() != null) {
certProviderInstances = getBootstrapInfo().certProviders().keySet();
}
cdsUpdate = processCluster(cluster, retainedEdsResources, certProviderInstances, serverInfo);
} catch (ResourceInvalidException e) {
errors.add("CDS response Cluster '" + clusterName + "' validation error: " + e.getMessage());
invalidResources.add(clusterName);
continue;
}
parsedResources.put(clusterName, new ParsedResource(cdsUpdate, resource));
}
logger.log(XdsLogLevel.INFO, "Received CDS Response version {0} nonce {1}. Parsed resources: {2}", versionInfo, nonce, unpackedResources);
handleResourceUpdate(serverInfo, ResourceType.CDS, parsedResources, invalidResources, retainedEdsResources, versionInfo, nonce, errors);
}
use of org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.InvalidProtocolBufferException in project grpc-java by grpc.
the class ClientXdsClient method parseOverrideFilterConfigs.
@VisibleForTesting
static StructOrError<Map<String, FilterConfig>> parseOverrideFilterConfigs(Map<String, Any> rawFilterConfigMap, FilterRegistry filterRegistry) {
Map<String, FilterConfig> overrideConfigs = new HashMap<>();
for (String name : rawFilterConfigMap.keySet()) {
Any anyConfig = rawFilterConfigMap.get(name);
String typeUrl = anyConfig.getTypeUrl();
boolean isOptional = false;
if (typeUrl.equals(TYPE_URL_FILTER_CONFIG)) {
io.envoyproxy.envoy.config.route.v3.FilterConfig filterConfig;
try {
filterConfig = anyConfig.unpack(io.envoyproxy.envoy.config.route.v3.FilterConfig.class);
} catch (InvalidProtocolBufferException e) {
return StructOrError.fromError("FilterConfig [" + name + "] contains invalid proto: " + e);
}
isOptional = filterConfig.getIsOptional();
anyConfig = filterConfig.getConfig();
typeUrl = anyConfig.getTypeUrl();
}
Message rawConfig = anyConfig;
try {
if (typeUrl.equals(TYPE_URL_TYPED_STRUCT_UDPA)) {
TypedStruct typedStruct = anyConfig.unpack(TypedStruct.class);
typeUrl = typedStruct.getTypeUrl();
rawConfig = typedStruct.getValue();
} else if (typeUrl.equals(TYPE_URL_TYPED_STRUCT)) {
com.github.xds.type.v3.TypedStruct newTypedStruct = anyConfig.unpack(com.github.xds.type.v3.TypedStruct.class);
typeUrl = newTypedStruct.getTypeUrl();
rawConfig = newTypedStruct.getValue();
}
} catch (InvalidProtocolBufferException e) {
return StructOrError.fromError("FilterConfig [" + name + "] contains invalid proto: " + e);
}
Filter filter = filterRegistry.get(typeUrl);
if (filter == null) {
if (isOptional) {
continue;
}
return StructOrError.fromError("HttpFilter [" + name + "](" + typeUrl + ") is required but unsupported");
}
ConfigOrError<? extends FilterConfig> filterConfig = filter.parseFilterConfigOverride(rawConfig);
if (filterConfig.errorDetail != null) {
return StructOrError.fromError("Invalid filter config for HttpFilter [" + name + "]: " + filterConfig.errorDetail);
}
overrideConfigs.put(name, filterConfig.config);
}
return StructOrError.fromStruct(overrideConfigs);
}
use of org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.InvalidProtocolBufferException in project grpc-java by grpc.
the class ProtoLiteUtilsTest method parseInvalid.
@Test
public void parseInvalid() throws Exception {
InputStream is = new ByteArrayInputStream(new byte[] { -127 });
try {
marshaller.parse(is);
fail("Expected exception");
} catch (StatusRuntimeException ex) {
assertEquals(Status.Code.INTERNAL, ex.getStatus().getCode());
assertNotNull(((InvalidProtocolBufferException) ex.getCause()).getUnfinishedMessage());
}
}
Aggregations