|
17 | 17 | package org.fireflyframework.data.config; |
18 | 18 |
|
19 | 19 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 20 | +import io.micrometer.core.instrument.MeterRegistry; |
| 21 | +import io.micrometer.observation.ObservationRegistry; |
20 | 22 | import org.fireflyframework.cache.core.CacheAdapter; |
21 | 23 | import org.fireflyframework.data.cache.EnrichmentCacheKeyGenerator; |
22 | 24 | import org.fireflyframework.data.cache.EnrichmentCacheService; |
23 | 25 | import org.fireflyframework.data.cache.OperationCacheService; |
| 26 | +import org.fireflyframework.data.event.EnrichmentEventPublisher; |
| 27 | +import org.fireflyframework.data.event.JobEventPublisher; |
| 28 | +import org.fireflyframework.data.event.OperationEventPublisher; |
| 29 | +import org.fireflyframework.data.health.JobOrchestratorHealthIndicator; |
| 30 | +import org.fireflyframework.data.mapper.JobResultMapper; |
| 31 | +import org.fireflyframework.data.mapper.JobResultMapperRegistry; |
| 32 | +import org.fireflyframework.data.observability.JobMetricsService; |
| 33 | +import org.fireflyframework.data.observability.JobTracingService; |
| 34 | +import org.fireflyframework.data.operation.schema.JsonSchemaGenerator; |
| 35 | +import org.fireflyframework.data.orchestration.port.JobOrchestrator; |
24 | 36 | import org.fireflyframework.data.service.DataEnricher; |
25 | 37 | import org.fireflyframework.data.service.DataEnricherRegistry; |
| 38 | +import org.fireflyframework.data.service.DataJobDiscoveryService; |
26 | 39 | import lombok.extern.slf4j.Slf4j; |
27 | 40 | import org.springframework.boot.autoconfigure.AutoConfiguration; |
28 | 41 | import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; |
| 42 | +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; |
29 | 43 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
30 | 44 | import org.springframework.boot.context.properties.EnableConfigurationProperties; |
| 45 | +import org.springframework.context.ApplicationContext; |
| 46 | +import org.springframework.context.ApplicationEventPublisher; |
31 | 47 | import org.springframework.context.annotation.Bean; |
32 | | -import org.springframework.context.annotation.ComponentScan; |
33 | 48 |
|
34 | 49 | import java.util.List; |
| 50 | +import java.util.Optional; |
35 | 51 |
|
36 | 52 | /** |
37 | 53 | * Auto-configuration for data enrichment components. |
|
42 | 58 | * <li>Data enricher registry for discovering enrichers</li> |
43 | 59 | * <li>Enrichment cache service (when cache is enabled and CacheAdapter is available)</li> |
44 | 60 | * <li>Cache key generator for tenant-isolated caching</li> |
| 61 | + * <li>Job metrics and tracing services</li> |
| 62 | + * <li>Event publishers for enrichment, operation, and job events</li> |
| 63 | + * <li>Job result mapper registry</li> |
| 64 | + * <li>Job orchestrator health indicator</li> |
| 65 | + * <li>Data job discovery service</li> |
| 66 | + * <li>JSON schema generator</li> |
45 | 67 | * </ul> |
46 | 68 | * |
47 | | - * <p>Note: EnrichmentEventPublisher is auto-discovered via @Service annotation |
48 | | - * and is conditionally created based on firefly.data.enrichment.publish-events property.</p> |
49 | | - * |
50 | 69 | * <p>The configuration is activated when:</p> |
51 | 70 | * <ul> |
52 | 71 | * <li>The property {@code firefly.data.enrichment.enabled} is true (default)</li> |
|
76 | 95 | havingValue = "true", |
77 | 96 | matchIfMissing = true |
78 | 97 | ) |
79 | | -@ComponentScan(basePackages = "org.fireflyframework.data") |
80 | 98 | public class DataEnrichmentAutoConfiguration { |
81 | | - |
| 99 | + |
82 | 100 | public DataEnrichmentAutoConfiguration() { |
83 | 101 | log.info("Initializing Data Enrichment Auto-Configuration"); |
84 | 102 | } |
85 | | - |
| 103 | + |
86 | 104 | /** |
87 | 105 | * Creates the data enricher registry bean. |
88 | 106 | * |
@@ -166,4 +184,133 @@ public OperationCacheService operationCacheService( |
166 | 184 | log.info("Creating OperationCacheService bean with cache type: {}", cacheManager.getCacheType()); |
167 | 185 | return new OperationCacheService(cacheManager, objectMapper, properties); |
168 | 186 | } |
| 187 | + |
| 188 | + /** |
| 189 | + * Creates the job metrics service bean. |
| 190 | + * |
| 191 | + * <p>This service records job-related metrics using Micrometer.</p> |
| 192 | + */ |
| 193 | + @Bean |
| 194 | + @ConditionalOnMissingBean |
| 195 | + public JobMetricsService jobMetricsService(MeterRegistry meterRegistry, |
| 196 | + JobOrchestrationProperties properties) { |
| 197 | + log.info("Creating JobMetricsService bean"); |
| 198 | + return new JobMetricsService(meterRegistry, properties); |
| 199 | + } |
| 200 | + |
| 201 | + /** |
| 202 | + * Creates the job tracing service bean. |
| 203 | + * |
| 204 | + * <p>This service adds distributed tracing to job operations.</p> |
| 205 | + */ |
| 206 | + @Bean |
| 207 | + @ConditionalOnMissingBean |
| 208 | + public JobTracingService jobTracingService(ObservationRegistry observationRegistry, |
| 209 | + JobOrchestrationProperties properties) { |
| 210 | + log.info("Creating JobTracingService bean"); |
| 211 | + return new JobTracingService(observationRegistry, properties); |
| 212 | + } |
| 213 | + |
| 214 | + /** |
| 215 | + * Creates the JSON schema generator bean. |
| 216 | + * |
| 217 | + * <p>This component generates JSON Schemas and example objects from Java classes.</p> |
| 218 | + */ |
| 219 | + @Bean |
| 220 | + @ConditionalOnMissingBean |
| 221 | + public JsonSchemaGenerator jsonSchemaGenerator(ObjectMapper objectMapper) { |
| 222 | + log.info("Creating JsonSchemaGenerator bean"); |
| 223 | + return new JsonSchemaGenerator(objectMapper); |
| 224 | + } |
| 225 | + |
| 226 | + /** |
| 227 | + * Creates the job event publisher bean. |
| 228 | + * |
| 229 | + * <p>This service publishes job lifecycle events through Spring's event mechanism.</p> |
| 230 | + */ |
| 231 | + @Bean |
| 232 | + @ConditionalOnMissingBean |
| 233 | + public JobEventPublisher jobEventPublisher(ApplicationEventPublisher eventPublisher, |
| 234 | + JobOrchestrationProperties properties) { |
| 235 | + log.info("Creating JobEventPublisher bean"); |
| 236 | + return new JobEventPublisher(eventPublisher, properties); |
| 237 | + } |
| 238 | + |
| 239 | + /** |
| 240 | + * Creates the enrichment event publisher bean. |
| 241 | + * |
| 242 | + * <p>This service publishes enrichment lifecycle events through Spring's event mechanism. |
| 243 | + * It is only created when {@code firefly.data.enrichment.publish-events} is true (default).</p> |
| 244 | + */ |
| 245 | + @Bean |
| 246 | + @ConditionalOnMissingBean |
| 247 | + @ConditionalOnProperty( |
| 248 | + prefix = "firefly.data.enrichment", |
| 249 | + name = "publish-events", |
| 250 | + havingValue = "true", |
| 251 | + matchIfMissing = true |
| 252 | + ) |
| 253 | + public EnrichmentEventPublisher enrichmentEventPublisher(ApplicationEventPublisher eventPublisher) { |
| 254 | + log.info("Creating EnrichmentEventPublisher bean"); |
| 255 | + return new EnrichmentEventPublisher(eventPublisher); |
| 256 | + } |
| 257 | + |
| 258 | + /** |
| 259 | + * Creates the operation event publisher bean. |
| 260 | + * |
| 261 | + * <p>This service publishes provider operation lifecycle events through Spring's event mechanism. |
| 262 | + * It is only created when {@code firefly.data.enrichment.operations.publish-events} is true (default).</p> |
| 263 | + */ |
| 264 | + @Bean |
| 265 | + @ConditionalOnMissingBean |
| 266 | + @ConditionalOnProperty( |
| 267 | + prefix = "firefly.data.enrichment.operations", |
| 268 | + name = "publish-events", |
| 269 | + havingValue = "true", |
| 270 | + matchIfMissing = true |
| 271 | + ) |
| 272 | + public OperationEventPublisher operationEventPublisher(ApplicationEventPublisher eventPublisher) { |
| 273 | + log.info("Creating OperationEventPublisher bean"); |
| 274 | + return new OperationEventPublisher(eventPublisher); |
| 275 | + } |
| 276 | + |
| 277 | + /** |
| 278 | + * Creates the data job discovery service bean. |
| 279 | + * |
| 280 | + * <p>This service discovers and logs all registered DataJobs at application startup. |
| 281 | + * It uses {@code @EventListener} to react to {@code ApplicationReadyEvent}.</p> |
| 282 | + */ |
| 283 | + @Bean |
| 284 | + @ConditionalOnMissingBean |
| 285 | + public DataJobDiscoveryService dataJobDiscoveryService(ApplicationContext applicationContext) { |
| 286 | + log.info("Creating DataJobDiscoveryService bean"); |
| 287 | + return new DataJobDiscoveryService(applicationContext); |
| 288 | + } |
| 289 | + |
| 290 | + /** |
| 291 | + * Creates the job result mapper registry bean. |
| 292 | + * |
| 293 | + * <p>This registry automatically discovers all {@link JobResultMapper} beans and makes them |
| 294 | + * available for the RESULT stage transformation.</p> |
| 295 | + */ |
| 296 | + @Bean |
| 297 | + @ConditionalOnMissingBean |
| 298 | + public JobResultMapperRegistry jobResultMapperRegistry(List<JobResultMapper<?, ?>> mappers) { |
| 299 | + log.info("Creating JobResultMapperRegistry bean with {} mapper(s)", mappers.size()); |
| 300 | + return new JobResultMapperRegistry(mappers); |
| 301 | + } |
| 302 | + |
| 303 | + /** |
| 304 | + * Creates the job orchestrator health indicator bean. |
| 305 | + * |
| 306 | + * <p>This health indicator reports the status of the job orchestrator.</p> |
| 307 | + */ |
| 308 | + @Bean |
| 309 | + @ConditionalOnMissingBean |
| 310 | + public JobOrchestratorHealthIndicator jobOrchestratorHealthIndicator( |
| 311 | + Optional<JobOrchestrator> orchestrator, |
| 312 | + JobOrchestrationProperties properties) { |
| 313 | + log.info("Creating JobOrchestratorHealthIndicator bean"); |
| 314 | + return new JobOrchestratorHealthIndicator(orchestrator, properties); |
| 315 | + } |
169 | 316 | } |
0 commit comments