arunsrajan commented on code in PR #26010: URL: https://github.com/apache/camel/pull/26010#discussion_r3913334538
########## components/camel-alibaba/camel-alibaba-eventbridge/src/main/java/org/apache/camel/component/alibaba/eventbridge/EventSourceCache.java: ########## @@ -0,0 +1,362 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.alibaba.eventbridge; + +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; + +import com.aliyun.eventbridge.EventBridgeClient; +import com.aliyun.eventbridge.models.EventBusEntry; +import com.aliyun.eventbridge.models.EventRuleDTO; +import com.aliyun.eventbridge.models.ListEventBusesRequest; +import com.aliyun.eventbridge.models.ListEventBusesResponse; +import com.aliyun.eventbridge.models.ListRulesRequest; +import com.aliyun.eventbridge.models.ListRulesResponse; +import com.google.gson.Gson; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import org.apache.camel.component.alibaba.eventbridge.models.AllowedEventBus; +import org.apache.camel.component.alibaba.eventbridge.models.AllowedEventSource; +import org.apache.camel.util.ObjectHelper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * TTL-based in-memory cache for verified Alibaba Cloud EventBridge bus, event source, and source-scoped event type + * definitions. + * <p> + * Implements a two-phase validated cache workflow: + * <ol> + * <li>Fetch and validate configured event sources and event types against Alibaba Cloud API ({@code listEventBuses} and + * {@code listRules}).</li> + * <li><b>Only after validation passes</b>, populate the cache with the verified {@link BusMetadata} for fast runtime + * comparison.</li> + * </ol> + */ +final class EventSourceCache { + + private static final Logger LOG = LoggerFactory.getLogger(EventSourceCache.class); + private static final Gson GSON = new Gson(); + private static final int PAGE_LIMIT = 100; + + /** + * Java 16 record holding cached bus metadata including mapped event sources and their permitted event types. + */ + public record BusMetadata(boolean exists, Map<String, Set<String>> sourceToTypesMap) { + public BusMetadata { + if (sourceToTypesMap == null) { + sourceToTypesMap = Collections.emptyMap(); + } else { + Map<String, Set<String>> unmodifiable = new HashMap<>(); + for (Map.Entry<String, Set<String>> entry : sourceToTypesMap.entrySet()) { + unmodifiable.put(entry.getKey(), Collections.unmodifiableSet(new HashSet<>(entry.getValue()))); + } + sourceToTypesMap = Collections.unmodifiableMap(unmodifiable); + } + } Review Comment: Addressed. When cloud validation is enabled (`validateEventSource=true` or `validateEventType=true`), rule metadata verification is mandatory and missing rules fail closed. We have also updated `alibaba-eventbridge-component.adoc` and the Camel catalog documentation mirror to explicitly describe the fail-closed cloud validation and caching lifecycle. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
