@@ -500,7 +500,7 @@ private async Task<IEnumerable<TemplateResource>> GetRelatedTemplateResourcesAsy
500
500
List < TemplateResource > templateResources = new List < TemplateResource > ( ) ;
501
501
string apimname = exc . sourceApimName , resourceGroup = exc . resourceGroup , fileFolder = exc . fileFolder , policyXMLBaseUrl = exc . policyXMLBaseUrl , policyXMLSasToken = exc . policyXMLSasToken ;
502
502
503
- #region Schemas
503
+ #region Schemas
504
504
// add schema resources to api template
505
505
List < TemplateResource > schemaResources = await GenerateSchemasARMTemplate ( apimname , apiName , resourceGroup , fileFolder ) ;
506
506
templateResources . AddRange ( schemaResources ) ;
@@ -509,9 +509,30 @@ private async Task<IEnumerable<TemplateResource>> GetRelatedTemplateResourcesAsy
509
509
#region Operations
510
510
// pull api operations for service
511
511
string [ ] operationNames = await GetAllOperationNames ( apimname , resourceGroup , apiName ) ;
512
+ int numBatches = 0 ;
513
+
514
+ // create empty array for the batch operation owners
515
+ List < string > batchOwners = new List < string > ( ) ;
516
+
517
+ // if a batch size is specified
518
+ if ( exc . operationBatchSize > 0 ) {
519
+ // store the number of batches required based on exc.operationBatchSize
520
+ numBatches = ( int ) Math . Ceiling ( ( double ) operationNames . Length / ( double ) exc . operationBatchSize ) ;
521
+ //Console.WriteLine ("Number of batches: {0}", numBatches);
522
+ }
523
+
512
524
513
525
foreach ( string operationName in operationNames )
514
526
{
527
+ int opIndex = Array . IndexOf ( operationNames , operationName ) ;
528
+
529
+ //add batch owners into array
530
+ // ensure each owner is linked to the one before
531
+ if ( exc . operationBatchSize > 0 && opIndex < numBatches ) {
532
+ batchOwners . Add ( operationName ) ;
533
+ //Console.WriteLine("Adding operation {0} to owner list", operationName);
534
+ }
535
+
515
536
string operationDetails = await GetAPIOperationDetailsAsync ( apimname , resourceGroup , apiName , operationName ) ;
516
537
517
538
Console . WriteLine ( "'{0}' Operation found" , operationName ) ;
@@ -540,6 +561,24 @@ private async Task<IEnumerable<TemplateResource>> GetRelatedTemplateResourcesAsy
540
561
}
541
562
}
542
563
564
+ // add to batch if flagged
565
+ string batchdependsOn ;
566
+
567
+ if ( exc . operationBatchSize > 0 && opIndex > 0 ) {
568
+ if ( opIndex >= 1 && opIndex <= numBatches - 1 ) {
569
+ // chain the owners to each other
570
+ batchdependsOn = $ "[resourceId('Microsoft.ApiManagement/service/apis/operations', parameters('{ ParameterNames . ApimServiceName } '), '{ apiName } ', '{ batchOwners [ opIndex - 1 ] } ')]";
571
+ //Console.WriteLine("Owner chaining: this request {0} to previous {1}", operationName, batchOwners[opIndex-1]);
572
+ } else {
573
+ // chain the operation to respective owner
574
+ int ownerIndex = ( int ) Math . Floor ( ( opIndex - numBatches ) / ( ( double ) exc . operationBatchSize - 1 ) ) ;
575
+ batchdependsOn = $ "[resourceId('Microsoft.ApiManagement/service/apis/operations', parameters('{ ParameterNames . ApimServiceName } '), '{ apiName } ', '{ batchOwners [ ownerIndex ] } ')]";
576
+ //Console.WriteLine("Operation {0} chained to owner {1}", operationName, batchOwners[ownerIndex]);
577
+ }
578
+
579
+ operationDependsOn . Add ( batchdependsOn ) ;
580
+ }
581
+
543
582
operationResource . dependsOn = operationDependsOn . ToArray ( ) ;
544
583
templateResources . Add ( operationResource ) ;
545
584
@@ -638,8 +677,8 @@ private async Task<IEnumerable<TemplateResource>> GetRelatedTemplateResourcesAsy
638
677
catch ( Exception ) { }
639
678
#endregion
640
679
641
- #region API Tags
642
- // add tags associated with the api to template
680
+ #region API Tags
681
+ // add tags associated with the api to template
643
682
try
644
683
{
645
684
// pull tags associated with the api
@@ -661,10 +700,11 @@ private async Task<IEnumerable<TemplateResource>> GetRelatedTemplateResourcesAsy
661
700
}
662
701
}
663
702
catch ( Exception ) { }
664
- #endregion
703
+ #endregion
665
704
666
- #region API Products
705
+
667
706
// add product api associations to template
707
+ #region API Products
668
708
try
669
709
{
670
710
// pull product api associations
@@ -708,8 +748,8 @@ private async Task<IEnumerable<TemplateResource>> GetRelatedTemplateResourcesAsy
708
748
diagnosticResource . scale = null ;
709
749
diagnosticResource . dependsOn = new string [ ] { $ "[resourceId('Microsoft.ApiManagement/service/apis', parameters('{ ParameterNames . ApimServiceName } '), '{ apiName } ')]" } ;
710
750
711
- if ( exc . paramApiLoggerId )
712
- {
751
+ if ( exc . paramApiLoggerId ) {
752
+
713
753
diagnosticResource . properties . loggerId = $ "[parameters('{ ParameterNames . ApiLoggerId } ').{ ExtractorUtils . GenValidParamName ( apiName , ParameterPrefix . Api ) } .{ ExtractorUtils . GenValidParamName ( diagnosticName , ParameterPrefix . Diagnostic ) } ]";
714
754
}
715
755
@@ -720,6 +760,7 @@ private async Task<IEnumerable<TemplateResource>> GetRelatedTemplateResourcesAsy
720
760
}
721
761
722
762
templateResources . Add ( diagnosticResource ) ;
763
+
723
764
}
724
765
#endregion
725
766
0 commit comments