/** * 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); }
/** * 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); } }
LOGGER.error( "Failed to convert HTTP connection manager config struct into protobuf message for listener {}", getResourceName(l), e);