/** * Returns a new {@link SnapshotResources} instance. * * @param resources the resources in this collection * @param version the version associated with the resources in this collection * @param <T> the type of resources in this collection */ public static <T extends Message> SnapshotResources<T> create(Iterable<T> resources, String version) { return new AutoValue_SnapshotResources<>( StreamSupport.stream(resources.spliterator(), false) .collect( Collector.of( ImmutableMap.Builder<String, T>::new, (b, e) -> b.put(Resources.getResourceName(e), e), (b1, b2) -> b1.putAll(b2.build()), ImmutableMap.Builder::build)), version); }
HttpConnectionManager.Builder config = HttpConnectionManager.newBuilder(); structAsMessage(filter.getConfig(), config); LOGGER.error( "Failed to convert HTTP connection manager config struct into protobuf message for listener {}", getResourceName(l), e);
/** * Asserts that all dependent resources are included in the snapshot. All EDS resources are listed by name in CDS * resources, and all RDS resources are listed by name in LDS resources. * * <p>Note that clusters and listeners are requested without name references, so Envoy will accept the snapshot list * of clusters as-is, even if it does not match all references found in xDS. * * @throws SnapshotConsistencyException if the snapshot is not consistent */ public void ensureConsistent() throws SnapshotConsistencyException { Set<String> clusterEndpointRefs = Resources.getResourceReferences(clusters().resources().values()); ensureAllResourceNamesExist(CLUSTER_TYPE_URL, ENDPOINT_TYPE_URL, clusterEndpointRefs, endpoints().resources()); Set<String> listenerRouteRefs = Resources.getResourceReferences(listeners().resources().values()); ensureAllResourceNamesExist(LISTENER_TYPE_URL, ROUTE_TYPE_URL, listenerRouteRefs, routes().resources()); }
/** * Returns the name of the given resource message. * * @param anyResource the resource message * @throws RuntimeException if the passed Any doesn't correspond to an xDS resource */ public static String getResourceName(Any anyResource) { Class<? extends Message> clazz = RESOURCE_TYPE_BY_URL.get(anyResource.getTypeUrl()); Preconditions.checkNotNull(clazz, "cannot unpack non-xDS message type"); try { return getResourceName(anyResource.unpack(clazz)); } catch (InvalidProtocolBufferException e) { throw new RuntimeException(e); } }