@@ -306,7 +306,8 @@ static async Task AlterConsumerGroupOffsetsAsync(string bootstrapServers, string
306
306
307
307
var group = commandArgs [ 0 ] ;
308
308
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
+ {
310
311
try
311
312
{
312
313
var topic = commandArgs [ i ] ;
@@ -330,7 +331,8 @@ static async Task AlterConsumerGroupOffsetsAsync(string bootstrapServers, string
330
331
{
331
332
var results = await adminClient . AlterConsumerGroupOffsetsAsync ( input ) ;
332
333
Console . WriteLine ( "Successfully altered offsets:" ) ;
333
- foreach ( var groupResult in results ) {
334
+ foreach ( var groupResult in results )
335
+ {
334
336
Console . WriteLine ( groupResult ) ;
335
337
}
336
338
@@ -363,7 +365,8 @@ static async Task ListConsumerGroupOffsetsAsync(string bootstrapServers, string[
363
365
364
366
var group = commandArgs [ 0 ] ;
365
367
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
+ {
367
370
try
368
371
{
369
372
var topic = commandArgs [ i ] ;
@@ -391,7 +394,8 @@ static async Task ListConsumerGroupOffsetsAsync(string bootstrapServers, string[
391
394
{
392
395
var result = await adminClient . ListConsumerGroupOffsetsAsync ( input ) ;
393
396
Console . WriteLine ( "Successfully listed offsets:" ) ;
394
- foreach ( var groupResult in result ) {
397
+ foreach ( var groupResult in result )
398
+ {
395
399
Console . WriteLine ( groupResult ) ;
396
400
}
397
401
}
@@ -412,7 +416,8 @@ static async Task ListConsumerGroupOffsetsAsync(string bootstrapServers, string[
412
416
}
413
417
}
414
418
415
- static async Task ListConsumerGroupsAsync ( string bootstrapServers , string [ ] commandArgs ) {
419
+ static async Task ListConsumerGroupsAsync ( string bootstrapServers , string [ ] commandArgs )
420
+ {
416
421
var timeout = TimeSpan . FromSeconds ( 30 ) ;
417
422
var statesList = new List < ConsumerGroupState > ( ) ;
418
423
try
@@ -423,7 +428,8 @@ static async Task ListConsumerGroupsAsync(string bootstrapServers, string[] comm
423
428
}
424
429
if ( commandArgs . Length > 1 )
425
430
{
426
- for ( int i = 1 ; i < commandArgs . Length ; i ++ ) {
431
+ for ( int i = 1 ; i < commandArgs . Length ; i ++ )
432
+ {
427
433
statesList . Add ( Enum . Parse < ConsumerGroupState > ( commandArgs [ i ] ) ) ;
428
434
}
429
435
}
@@ -458,7 +464,8 @@ static async Task ListConsumerGroupsAsync(string bootstrapServers, string[] comm
458
464
}
459
465
460
466
461
- static async Task DescribeConsumerGroupsAsync ( string bootstrapServers , string [ ] commandArgs ) {
467
+ static async Task DescribeConsumerGroupsAsync ( string bootstrapServers , string [ ] commandArgs )
468
+ {
462
469
if ( commandArgs . Length < 1 )
463
470
{
464
471
Console . WriteLine ( "usage: .. <bootstrapServers> describe-consumer-groups <group1> [<group2 ... <groupN>]" ) ;
@@ -501,6 +508,96 @@ static async Task DescribeConsumerGroupsAsync(string bootstrapServers, string[]
501
508
}
502
509
}
503
510
}
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
+ }
504
601
505
602
public static async Task Main ( string [ ] args )
506
603
{
@@ -511,7 +608,8 @@ public static async Task Main(string[] args)
511
608
"list-groups" , "metadata" , "library-version" , "create-topic" , "create-acls" ,
512
609
"describe-acls" , "delete-acls" ,
513
610
"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"
515
613
} ) +
516
614
" .." ) ;
517
615
Environment . ExitCode = 1 ;
@@ -557,6 +655,9 @@ public static async Task Main(string[] args)
557
655
case "describe-consumer-groups" :
558
656
await DescribeConsumerGroupsAsync ( bootstrapServers , commandArgs ) ;
559
657
break ;
658
+ case "incremental-alter-configs" :
659
+ await IncrementalAlterConfigsAsync ( bootstrapServers , commandArgs ) ;
660
+ break ;
560
661
default :
561
662
Console . WriteLine ( $ "unknown command: { command } ") ;
562
663
break ;
0 commit comments