|
25 | 25 | import com.launchdarkly.sdk.server.integrations.HooksConfigurationBuilder; |
26 | 26 | import com.launchdarkly.sdk.server.integrations.ServiceEndpointsBuilder; |
27 | 27 | import com.launchdarkly.sdk.server.integrations.StreamingDataSourceBuilder; |
| 28 | +import com.launchdarkly.sdk.server.integrations.DataSystemBuilder; |
| 29 | +import com.launchdarkly.sdk.server.DataSystemComponents; |
| 30 | +import com.launchdarkly.sdk.server.integrations.FDv2PollingInitializerBuilder; |
| 31 | +import com.launchdarkly.sdk.server.integrations.FDv2PollingSynchronizerBuilder; |
| 32 | +import com.launchdarkly.sdk.server.integrations.FDv2StreamingSynchronizerBuilder; |
28 | 33 | import com.launchdarkly.sdk.server.interfaces.BigSegmentStoreStatusProvider; |
| 34 | +import com.launchdarkly.sdk.server.subsystems.DataSourceBuilder; |
| 35 | +import com.launchdarkly.sdk.server.datasources.Initializer; |
| 36 | +import com.launchdarkly.sdk.server.datasources.Synchronizer; |
| 37 | +import com.launchdarkly.sdk.server.subsystems.DataSystemConfiguration; |
29 | 38 |
|
30 | 39 | import org.jetbrains.annotations.NotNull; |
31 | 40 | import org.slf4j.Logger; |
|
55 | 64 | import sdktest.Representations.HookConfig; |
56 | 65 | import sdktest.Representations.SdkConfigHookParams; |
57 | 66 | import sdktest.Representations.SdkConfigParams; |
| 67 | +import sdktest.Representations.SdkConfigDataSystemParams; |
| 68 | +import sdktest.Representations.SdkConfigDataInitializerParams; |
| 69 | +import sdktest.Representations.SdkConfigSynchronizersParams; |
| 70 | +import sdktest.Representations.SdkConfigSynchronizerParams; |
| 71 | +import sdktest.Representations.SdkConfigPollingParams; |
| 72 | +import sdktest.Representations.SdkConfigStreamingParams; |
58 | 73 | import sdktest.Representations.SecureModeHashParams; |
59 | 74 | import sdktest.Representations.SecureModeHashResponse; |
60 | 75 |
|
@@ -465,6 +480,125 @@ private LDConfig buildSdkConfig(SdkConfigParams params, String tag) { |
465 | 480 | builder.hooks(Components.hooks().setHooks(hookList)); |
466 | 481 | } |
467 | 482 |
|
| 483 | + if (params.dataSystem != null) { |
| 484 | + DataSystemBuilder dataSystemBuilder = Components.dataSystem().custom(); |
| 485 | + |
| 486 | + // TODO: enable this code in the future and determine which dependencies on persistent stores need to be added to contract test build process |
| 487 | + // Configure persistent store if provided |
| 488 | + // if (params.dataSystem.store != null && params.dataSystem.store.persistentDataStore != null) { |
| 489 | + // var storeConfig = params.dataSystem.store.persistentDataStore; |
| 490 | + // var storeType = storeConfig.store.type.toLowerCase(); |
| 491 | + // ComponentConfigurer<DataStore> persistentStore = null; |
| 492 | + // |
| 493 | + // switch (storeType) { |
| 494 | + // case "redis": |
| 495 | + // // Redis store configuration |
| 496 | + // break; |
| 497 | + // case "dynamodb": |
| 498 | + // // DynamoDB store configuration |
| 499 | + // break; |
| 500 | + // case "consul": |
| 501 | + // // Consul store configuration |
| 502 | + // break; |
| 503 | + // } |
| 504 | + // |
| 505 | + // if (persistentStore != null) { |
| 506 | + // // Configure cache |
| 507 | + // var cacheMode = storeConfig.cache != null ? storeConfig.cache.mode.toLowerCase() : null; |
| 508 | + // // ... cache configuration ... |
| 509 | + // |
| 510 | + // // Determine store mode |
| 511 | + // var storeMode = params.dataSystem.storeMode == 0 |
| 512 | + // ? DataSystemConfiguration.DataStoreMode.READ_ONLY |
| 513 | + // : DataSystemConfiguration.DataStoreMode.READ_WRITE; |
| 514 | + // |
| 515 | + // dataSystemBuilder.persistentStore(persistentStore, storeMode); |
| 516 | + // } |
| 517 | + // } |
| 518 | + |
| 519 | + // Configure initializers |
| 520 | + if (params.dataSystem.initializers != null && params.dataSystem.initializers.length > 0) { |
| 521 | + List<DataSourceBuilder<Initializer>> initializers = new ArrayList<>(); |
| 522 | + for (SdkConfigDataInitializerParams initializer : params.dataSystem.initializers) { |
| 523 | + if (initializer.polling != null) { |
| 524 | + FDv2PollingInitializerBuilder pollingBuilder = DataSystemComponents.pollingInitializer(); |
| 525 | + if (initializer.polling.baseUri != null) { |
| 526 | + ServiceEndpointsBuilder endpointOverride = Components.serviceEndpoints().polling(initializer.polling.baseUri); |
| 527 | + pollingBuilder.serviceEndpointsOverride(endpointOverride); |
| 528 | + } |
| 529 | + // Note: pollInterval is not available for initializers, only for synchronizers |
| 530 | + if (params.dataSystem.payloadFilter != null && !params.dataSystem.payloadFilter.isEmpty()) { |
| 531 | + pollingBuilder.payloadFilter(params.dataSystem.payloadFilter); |
| 532 | + } |
| 533 | + initializers.add(pollingBuilder); |
| 534 | + } |
| 535 | + } |
| 536 | + if (!initializers.isEmpty()) { |
| 537 | + dataSystemBuilder.initializers(initializers.toArray(new DataSourceBuilder[0])); |
| 538 | + } |
| 539 | + } |
| 540 | + |
| 541 | + // Configure synchronizers |
| 542 | + if (params.dataSystem.synchronizers != null) { |
| 543 | + List<DataSourceBuilder<Synchronizer>> synchronizers = new ArrayList<>(); |
| 544 | + |
| 545 | + // Primary synchronizer |
| 546 | + if (params.dataSystem.synchronizers.primary != null) { |
| 547 | + DataSourceBuilder<Synchronizer> primary = createSynchronizer(params.dataSystem.synchronizers.primary, params.dataSystem.payloadFilter); |
| 548 | + if (primary != null) { |
| 549 | + synchronizers.add(primary); |
| 550 | + } |
| 551 | + } |
| 552 | + |
| 553 | + // Secondary synchronizer (optional) |
| 554 | + if (params.dataSystem.synchronizers.secondary != null) { |
| 555 | + DataSourceBuilder<Synchronizer> secondary = createSynchronizer(params.dataSystem.synchronizers.secondary, params.dataSystem.payloadFilter); |
| 556 | + if (secondary != null) { |
| 557 | + synchronizers.add(secondary); |
| 558 | + } |
| 559 | + } |
| 560 | + |
| 561 | + if (!synchronizers.isEmpty()) { |
| 562 | + dataSystemBuilder.synchronizers(synchronizers.toArray(new DataSourceBuilder[0])); |
| 563 | + } |
| 564 | + } |
| 565 | + |
| 566 | + builder.dataSystem(dataSystemBuilder); |
| 567 | + } |
| 568 | + |
468 | 569 | return builder.build(); |
469 | 570 | } |
| 571 | + |
| 572 | + private DataSourceBuilder<Synchronizer> createSynchronizer( |
| 573 | + SdkConfigSynchronizerParams synchronizer, |
| 574 | + String payloadFilter) { |
| 575 | + if (synchronizer.polling != null) { |
| 576 | + FDv2PollingSynchronizerBuilder pollingBuilder = DataSystemComponents.pollingSynchronizer(); |
| 577 | + if (synchronizer.polling.baseUri != null) { |
| 578 | + ServiceEndpointsBuilder endpointOverride = Components.serviceEndpoints().polling(synchronizer.polling.baseUri); |
| 579 | + pollingBuilder.serviceEndpointsOverride(endpointOverride); |
| 580 | + } |
| 581 | + if (synchronizer.polling.pollIntervalMs != null) { |
| 582 | + pollingBuilder.pollInterval(Duration.ofMillis(synchronizer.polling.pollIntervalMs)); |
| 583 | + } |
| 584 | + if (payloadFilter != null && !payloadFilter.isEmpty()) { |
| 585 | + pollingBuilder.payloadFilter(payloadFilter); |
| 586 | + } |
| 587 | + return pollingBuilder; |
| 588 | + } else if (synchronizer.streaming != null) { |
| 589 | + FDv2StreamingSynchronizerBuilder streamingBuilder = DataSystemComponents.streamingSynchronizer(); |
| 590 | + if (synchronizer.streaming.baseUri != null) { |
| 591 | + ServiceEndpointsBuilder endpointOverride = Components.serviceEndpoints().streaming(synchronizer.streaming.baseUri); |
| 592 | + streamingBuilder.serviceEndpointsOverride(endpointOverride); |
| 593 | + } |
| 594 | + if (synchronizer.streaming.initialRetryDelayMs != null) { |
| 595 | + streamingBuilder.initialReconnectDelay(Duration.ofMillis(synchronizer.streaming.initialRetryDelayMs)); |
| 596 | + } |
| 597 | + if (payloadFilter != null && !payloadFilter.isEmpty()) { |
| 598 | + streamingBuilder.payloadFilter(payloadFilter); |
| 599 | + } |
| 600 | + return streamingBuilder; |
| 601 | + } |
| 602 | + return null; |
| 603 | + } |
470 | 604 | } |
0 commit comments