41
41
import io .airbyte .config .SyncResourceRequirements ;
42
42
import io .airbyte .config .SyncResourceRequirementsKey ;
43
43
import io .airbyte .config .provider .ResourceRequirementsProvider ;
44
- import io .airbyte .featureflag .FieldSelectionWorkspaces .DestResourceOverrides ;
44
+ import io .airbyte .featureflag .DestResourceOverrides ;
45
+ import io .airbyte .featureflag .OrchestratorResourceOverrides ;
46
+ import io .airbyte .featureflag .SourceResourceOverrides ;
45
47
import io .airbyte .featureflag .TestClient ;
46
48
import io .airbyte .protocol .models .CatalogHelpers ;
47
49
import io .airbyte .protocol .models .ConfiguredAirbyteCatalog ;
@@ -92,6 +94,7 @@ class DefaultJobCreatorTest {
92
94
private static final StandardDestinationDefinition STANDARD_DESTINATION_DEFINITION ;
93
95
private static final ActorDefinitionVersion SOURCE_DEFINITION_VERSION ;
94
96
private static final ActorDefinitionVersion DESTINATION_DEFINITION_VERSION ;
97
+ private static final ConfiguredAirbyteCatalog CONFIGURED_AIRBYTE_CATALOG ;
95
98
private static final long JOB_ID = 12L ;
96
99
private static final UUID WORKSPACE_ID = UUID .randomUUID ();
97
100
@@ -151,7 +154,7 @@ class DefaultJobCreatorTest {
151
154
.withStream (CatalogHelpers .createAirbyteStream (STREAM3_NAME , NAMESPACE , Field .of (FIELD_NAME , JsonSchemaType .STRING )))
152
155
.withSyncMode (SyncMode .FULL_REFRESH )
153
156
.withDestinationSyncMode (DestinationSyncMode .OVERWRITE );
154
- final ConfiguredAirbyteCatalog catalog = new ConfiguredAirbyteCatalog ().withStreams (List .of (stream1 , stream2 , stream3 ));
157
+ CONFIGURED_AIRBYTE_CATALOG = new ConfiguredAirbyteCatalog ().withStreams (List .of (stream1 , stream2 , stream3 ));
155
158
156
159
STANDARD_SYNC = new StandardSync ()
157
160
.withConnectionId (connectionId )
@@ -160,7 +163,7 @@ class DefaultJobCreatorTest {
160
163
.withNamespaceFormat (null )
161
164
.withPrefix ("presto_to_hudi" )
162
165
.withStatus (StandardSync .Status .ACTIVE )
163
- .withCatalog (catalog )
166
+ .withCatalog (CONFIGURED_AIRBYTE_CATALOG )
164
167
.withSourceId (sourceId )
165
168
.withDestinationId (destinationId )
166
169
.withOperationIds (List .of (operationId ));
@@ -581,6 +584,146 @@ void testDestinationResourceReqsOverrides(final String cpuReqOverride,
581
584
assertEquals (expectedMemLimit , destConfigValues .getMemoryLimit ());
582
585
}
583
586
587
+ @ ParameterizedTest
588
+ @ MethodSource ("resourceOverrideMatrix" )
589
+ void testOrchestratorResourceReqsOverrides (final String cpuReqOverride ,
590
+ final String cpuLimitOverride ,
591
+ final String memReqOverride ,
592
+ final String memLimitOverride )
593
+ throws IOException {
594
+ final var overrides = new HashMap <>();
595
+ if (cpuReqOverride != null ) {
596
+ overrides .put ("cpu_request" , cpuReqOverride );
597
+ }
598
+ if (cpuLimitOverride != null ) {
599
+ overrides .put ("cpu_limit" , cpuLimitOverride );
600
+ }
601
+ if (memReqOverride != null ) {
602
+ overrides .put ("memory_request" , memReqOverride );
603
+ }
604
+ if (memLimitOverride != null ) {
605
+ overrides .put ("memory_limit" , memLimitOverride );
606
+ }
607
+
608
+ final ResourceRequirements originalReqs = new ResourceRequirements ()
609
+ .withCpuLimit ("0.8" )
610
+ .withCpuRequest ("0.8" )
611
+ .withMemoryLimit ("800Mi" )
612
+ .withMemoryRequest ("800Mi" );
613
+
614
+ final var jobCreator = new DefaultJobCreator (jobPersistence , resourceRequirementsProvider ,
615
+ new TestClient (Map .of (OrchestratorResourceOverrides .INSTANCE .getKey (), Jsons .serialize (overrides ))));
616
+
617
+ final var standardSync = new StandardSync ()
618
+ .withConnectionId (UUID .randomUUID ())
619
+ .withName ("presto to hudi" )
620
+ .withNamespaceDefinition (NamespaceDefinitionType .SOURCE )
621
+ .withNamespaceFormat (null )
622
+ .withPrefix ("presto_to_hudi" )
623
+ .withStatus (StandardSync .Status .ACTIVE )
624
+ .withCatalog (CONFIGURED_AIRBYTE_CATALOG )
625
+ .withSourceId (UUID .randomUUID ())
626
+ .withDestinationId (UUID .randomUUID ())
627
+ .withOperationIds (List .of (UUID .randomUUID ()))
628
+ .withResourceRequirements (originalReqs );
629
+
630
+ jobCreator .createSyncJob (
631
+ SOURCE_CONNECTION ,
632
+ DESTINATION_CONNECTION ,
633
+ standardSync ,
634
+ SOURCE_IMAGE_NAME ,
635
+ SOURCE_PROTOCOL_VERSION ,
636
+ DESTINATION_IMAGE_NAME ,
637
+ DESTINATION_PROTOCOL_VERSION ,
638
+ List .of (STANDARD_SYNC_OPERATION ),
639
+ null ,
640
+ new StandardSourceDefinition ().withResourceRequirements (new ActorDefinitionResourceRequirements ().withDefault (sourceResourceRequirements )),
641
+ new StandardDestinationDefinition ().withResourceRequirements (new ActorDefinitionResourceRequirements ().withDefault (destResourceRequirements )),
642
+ SOURCE_DEFINITION_VERSION ,
643
+ DESTINATION_DEFINITION_VERSION ,
644
+ WORKSPACE_ID );
645
+
646
+ final ArgumentCaptor <JobConfig > configCaptor = ArgumentCaptor .forClass (JobConfig .class );
647
+ verify (jobPersistence , times (1 )).enqueueJob (any (), configCaptor .capture ());
648
+ final var orchestratorConfigValues = configCaptor .getValue ().getSync ().getSyncResourceRequirements ().getOrchestrator ();
649
+
650
+ final var expectedCpuReq = StringUtils .isNotBlank (cpuReqOverride ) ? cpuReqOverride : originalReqs .getCpuRequest ();
651
+ assertEquals (expectedCpuReq , orchestratorConfigValues .getCpuRequest ());
652
+
653
+ final var expectedCpuLimit = StringUtils .isNotBlank (cpuLimitOverride ) ? cpuLimitOverride : originalReqs .getCpuLimit ();
654
+ assertEquals (expectedCpuLimit , orchestratorConfigValues .getCpuLimit ());
655
+
656
+ final var expectedMemReq = StringUtils .isNotBlank (memReqOverride ) ? memReqOverride : originalReqs .getMemoryRequest ();
657
+ assertEquals (expectedMemReq , orchestratorConfigValues .getMemoryRequest ());
658
+
659
+ final var expectedMemLimit = StringUtils .isNotBlank (memLimitOverride ) ? memLimitOverride : originalReqs .getMemoryLimit ();
660
+ assertEquals (expectedMemLimit , orchestratorConfigValues .getMemoryLimit ());
661
+ }
662
+
663
+ @ ParameterizedTest
664
+ @ MethodSource ("resourceOverrideMatrix" )
665
+ void testSourceResourceReqsOverrides (final String cpuReqOverride ,
666
+ final String cpuLimitOverride ,
667
+ final String memReqOverride ,
668
+ final String memLimitOverride )
669
+ throws IOException {
670
+ final var overrides = new HashMap <>();
671
+ if (cpuReqOverride != null ) {
672
+ overrides .put ("cpu_request" , cpuReqOverride );
673
+ }
674
+ if (cpuLimitOverride != null ) {
675
+ overrides .put ("cpu_limit" , cpuLimitOverride );
676
+ }
677
+ if (memReqOverride != null ) {
678
+ overrides .put ("memory_request" , memReqOverride );
679
+ }
680
+ if (memLimitOverride != null ) {
681
+ overrides .put ("memory_limit" , memLimitOverride );
682
+ }
683
+
684
+ final ResourceRequirements originalReqs = new ResourceRequirements ()
685
+ .withCpuLimit ("0.8" )
686
+ .withCpuRequest ("0.8" )
687
+ .withMemoryLimit ("800Mi" )
688
+ .withMemoryRequest ("800Mi" );
689
+
690
+ final var jobCreator = new DefaultJobCreator (jobPersistence , resourceRequirementsProvider ,
691
+ new TestClient (Map .of (SourceResourceOverrides .INSTANCE .getKey (), Jsons .serialize (overrides ))));
692
+
693
+ jobCreator .createSyncJob (
694
+ SOURCE_CONNECTION ,
695
+ DESTINATION_CONNECTION ,
696
+ STANDARD_SYNC ,
697
+ SOURCE_IMAGE_NAME ,
698
+ SOURCE_PROTOCOL_VERSION ,
699
+ DESTINATION_IMAGE_NAME ,
700
+ DESTINATION_PROTOCOL_VERSION ,
701
+ List .of (STANDARD_SYNC_OPERATION ),
702
+ null ,
703
+ new StandardSourceDefinition ().withResourceRequirements (new ActorDefinitionResourceRequirements ().withJobSpecific (List .of (
704
+ new JobTypeResourceLimit ().withJobType (JobType .SYNC ).withResourceRequirements (originalReqs )))),
705
+ new StandardDestinationDefinition ().withResourceRequirements (new ActorDefinitionResourceRequirements ().withDefault (destResourceRequirements )),
706
+ SOURCE_DEFINITION_VERSION ,
707
+ DESTINATION_DEFINITION_VERSION ,
708
+ WORKSPACE_ID );
709
+
710
+ final ArgumentCaptor <JobConfig > configCaptor = ArgumentCaptor .forClass (JobConfig .class );
711
+ verify (jobPersistence , times (1 )).enqueueJob (any (), configCaptor .capture ());
712
+ final var sourceConfigValues = configCaptor .getValue ().getSync ().getSyncResourceRequirements ().getSource ();
713
+
714
+ final var expectedCpuReq = StringUtils .isNotBlank (cpuReqOverride ) ? cpuReqOverride : originalReqs .getCpuRequest ();
715
+ assertEquals (expectedCpuReq , sourceConfigValues .getCpuRequest ());
716
+
717
+ final var expectedCpuLimit = StringUtils .isNotBlank (cpuLimitOverride ) ? cpuLimitOverride : originalReqs .getCpuLimit ();
718
+ assertEquals (expectedCpuLimit , sourceConfigValues .getCpuLimit ());
719
+
720
+ final var expectedMemReq = StringUtils .isNotBlank (memReqOverride ) ? memReqOverride : originalReqs .getMemoryRequest ();
721
+ assertEquals (expectedMemReq , sourceConfigValues .getMemoryRequest ());
722
+
723
+ final var expectedMemLimit = StringUtils .isNotBlank (memLimitOverride ) ? memLimitOverride : originalReqs .getMemoryLimit ();
724
+ assertEquals (expectedMemLimit , sourceConfigValues .getMemoryLimit ());
725
+ }
726
+
584
727
private static Stream <Arguments > resourceOverrideMatrix () {
585
728
return Stream .of (
586
729
Arguments .of ("0.7" , "0.4" , "1000Mi" , "2000Mi" ),
0 commit comments