@@ -306,7 +306,8 @@ static async Task AlterConsumerGroupOffsetsAsync(string bootstrapServers, string
306306
307307 var group = commandArgs [ 0 ] ;
308308 var tpoes = new List < TopicPartitionOffset > ( ) ;
309- for ( int i = 1 ; i + 2 < commandArgs . Length ; i += 3 ) {
309+ for ( int i = 1 ; i + 2 < commandArgs . Length ; i += 3 )
310+ {
310311 try
311312 {
312313 var topic = commandArgs [ i ] ;
@@ -330,7 +331,8 @@ static async Task AlterConsumerGroupOffsetsAsync(string bootstrapServers, string
330331 {
331332 var results = await adminClient . AlterConsumerGroupOffsetsAsync ( input ) ;
332333 Console . WriteLine ( "Successfully altered offsets:" ) ;
333- foreach ( var groupResult in results ) {
334+ foreach ( var groupResult in results )
335+ {
334336 Console . WriteLine ( groupResult ) ;
335337 }
336338
@@ -363,7 +365,8 @@ static async Task ListConsumerGroupOffsetsAsync(string bootstrapServers, string[
363365
364366 var group = commandArgs [ 0 ] ;
365367 var tpes = new List < TopicPartition > ( ) ;
366- for ( int i = 1 ; i + 1 < commandArgs . Length ; i += 2 ) {
368+ for ( int i = 1 ; i + 1 < commandArgs . Length ; i += 2 )
369+ {
367370 try
368371 {
369372 var topic = commandArgs [ i ] ;
@@ -391,7 +394,8 @@ static async Task ListConsumerGroupOffsetsAsync(string bootstrapServers, string[
391394 {
392395 var result = await adminClient . ListConsumerGroupOffsetsAsync ( input ) ;
393396 Console . WriteLine ( "Successfully listed offsets:" ) ;
394- foreach ( var groupResult in result ) {
397+ foreach ( var groupResult in result )
398+ {
395399 Console . WriteLine ( groupResult ) ;
396400 }
397401 }
@@ -412,7 +416,8 @@ static async Task ListConsumerGroupOffsetsAsync(string bootstrapServers, string[
412416 }
413417 }
414418
415- static async Task ListConsumerGroupsAsync ( string bootstrapServers , string [ ] commandArgs ) {
419+ static async Task ListConsumerGroupsAsync ( string bootstrapServers , string [ ] commandArgs )
420+ {
416421 var timeout = TimeSpan . FromSeconds ( 30 ) ;
417422 var statesList = new List < ConsumerGroupState > ( ) ;
418423 try
@@ -423,7 +428,8 @@ static async Task ListConsumerGroupsAsync(string bootstrapServers, string[] comm
423428 }
424429 if ( commandArgs . Length > 1 )
425430 {
426- for ( int i = 1 ; i < commandArgs . Length ; i ++ ) {
431+ for ( int i = 1 ; i < commandArgs . Length ; i ++ )
432+ {
427433 statesList . Add ( Enum . Parse < ConsumerGroupState > ( commandArgs [ i ] ) ) ;
428434 }
429435 }
@@ -458,7 +464,8 @@ static async Task ListConsumerGroupsAsync(string bootstrapServers, string[] comm
458464 }
459465
460466
461- static async Task DescribeConsumerGroupsAsync ( string bootstrapServers , string [ ] commandArgs ) {
467+ static async Task DescribeConsumerGroupsAsync ( string bootstrapServers , string [ ] commandArgs )
468+ {
462469 if ( commandArgs . Length < 1 )
463470 {
464471 Console . WriteLine ( "usage: .. <bootstrapServers> describe-consumer-groups <group1> [<group2 ... <groupN>]" ) ;
@@ -501,6 +508,96 @@ static async Task DescribeConsumerGroupsAsync(string bootstrapServers, string[]
501508 }
502509 }
503510 }
511+
512+ static async Task IncrementalAlterConfigsAsync ( string bootstrapServers , string [ ] commandArgs )
513+ {
514+ var timeout = TimeSpan . FromSeconds ( 30 ) ;
515+ var configResourceList = new Dictionary < ConfigResource , List < ConfigEntry > > ( ) ;
516+ try
517+ {
518+ if ( commandArgs . Length > 0 )
519+ {
520+ timeout = TimeSpan . FromSeconds ( Int32 . Parse ( commandArgs [ 0 ] ) ) ;
521+ }
522+ if ( ( ( commandArgs . Length - 1 ) % 3 ) != 0 )
523+ {
524+ throw new ArgumentException ( "invalid arguments length" ) ;
525+ }
526+
527+ for ( int i = 1 ; i < commandArgs . Length ; i += 3 )
528+ {
529+ var resourceType = Enum . Parse < ResourceType > ( commandArgs [ i ] ) ;
530+ var resourceName = commandArgs [ i + 1 ] ;
531+ var configs = commandArgs [ i + 2 ] ;
532+ var configList = new List < ConfigEntry > ( ) ;
533+ foreach ( var config in configs . Split ( ";" ) )
534+ {
535+ var nameOpValue = config . Split ( "=" ) ;
536+ if ( nameOpValue . Length != 2 )
537+ {
538+ throw new ArgumentException ( $ "invalid alteration name \" { config } \" ") ;
539+ }
540+
541+ var name = nameOpValue [ 0 ] ;
542+ var opValue = nameOpValue [ 1 ] . Split ( ":" ) ;
543+ if ( opValue . Length != 2 )
544+ {
545+ throw new ArgumentException ( $ "invalid alteration value \" { nameOpValue [ 1 ] } \" ") ;
546+ }
547+
548+ var op = Enum . Parse < AlterConfigOpType > ( opValue [ 0 ] ) ;
549+ var value = opValue [ 1 ] ;
550+ configList . Add ( new ConfigEntry
551+ {
552+ Name = name ,
553+ Value = value ,
554+ IncrementalOperation = op
555+ } ) ;
556+ }
557+ var resource = new ConfigResource
558+ {
559+ Name = resourceName ,
560+ Type = resourceType
561+ } ;
562+ configResourceList [ resource ] = configList ;
563+ }
564+ }
565+ catch ( Exception e ) when (
566+ e is ArgumentException ||
567+ e is FormatException
568+ )
569+ {
570+ Console . WriteLine ( $ "error: { e . Message } ") ;
571+ Console . WriteLine ( "usage: .. <bootstrapServers> incremental-alter-configs [<timeout_seconds> <resource-type1> <resource-name1> <config-name1=op-type1:config-value1;config-name1=op-type1:config-value1> ...]" ) ;
572+ Environment . ExitCode = 1 ;
573+ return ;
574+ }
575+
576+ using ( var adminClient = new AdminClientBuilder ( new AdminClientConfig { BootstrapServers = bootstrapServers } ) . Build ( ) )
577+ {
578+ try
579+ {
580+ var alterResultList = await adminClient . IncrementalAlterConfigsAsync ( configResourceList , new IncrementalAlterConfigsOptions ( ) { RequestTimeout = timeout } ) ;
581+ foreach ( var alterResult in alterResultList )
582+ {
583+ Console . WriteLine ( $ "Resource { alterResult . ConfigResource } altered correctly") ;
584+ }
585+ }
586+ catch ( IncrementalAlterConfigsException e )
587+ {
588+ foreach ( var alterResult in e . Results )
589+ {
590+ Console . WriteLine ( $ "Resource { alterResult . ConfigResource } had error: { alterResult . Error } ") ;
591+ }
592+ Environment . ExitCode = 1 ;
593+ }
594+ catch ( Exception e )
595+ {
596+ Console . WriteLine ( $ "An error occurred altering configs incrementally: { e . Message } ") ;
597+ Environment . ExitCode = 1 ;
598+ }
599+ }
600+ }
504601
505602 public static async Task Main ( string [ ] args )
506603 {
@@ -511,7 +608,8 @@ public static async Task Main(string[] args)
511608 "list-groups" , "metadata" , "library-version" , "create-topic" , "create-acls" ,
512609 "describe-acls" , "delete-acls" ,
513610 "list-consumer-groups" , "describe-consumer-groups" ,
514- "list-consumer-group-offsets" , "alter-consumer-group-offsets"
611+ "list-consumer-group-offsets" , "alter-consumer-group-offsets" ,
612+ "incremental-alter-configs"
515613 } ) +
516614 " .." ) ;
517615 Environment . ExitCode = 1 ;
@@ -557,6 +655,9 @@ public static async Task Main(string[] args)
557655 case "describe-consumer-groups" :
558656 await DescribeConsumerGroupsAsync ( bootstrapServers , commandArgs ) ;
559657 break ;
658+ case "incremental-alter-configs" :
659+ await IncrementalAlterConfigsAsync ( bootstrapServers , commandArgs ) ;
660+ break ;
560661 default :
561662 Console . WriteLine ( $ "unknown command: { command } ") ;
562663 break ;
0 commit comments