Skip to content

Commit 620346c

Browse files
authored
Implement apply() for cluster configuration changes (#110)
1 parent 4e13ed2 commit 620346c

8 files changed

Lines changed: 516 additions & 65 deletions

File tree

KustoSchemaTools.Tests/Changes/ClusterChangesTest.cs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ public ClusterChangesTests()
1818
public void GenerateChanges_WithIdenticalPolicies_ShouldDetectNoChanges()
1919
{
2020
// Arrange
21-
var oldCluster = CreateClusterWithPolicy(0.2, 1, 2, 3);
22-
var newCluster = CreateClusterWithPolicy(0.2, 1, 2, 3);
21+
var oldCluster = CreateClusterWithPolicy(0.2, 1, 2);
22+
var newCluster = CreateClusterWithPolicy(0.2, 1, 2);
2323

2424
// Act
2525
var changeSet = ClusterChanges.GenerateChanges(oldCluster, newCluster, _loggerMock.Object);
@@ -32,8 +32,8 @@ public void GenerateChanges_WithIdenticalPolicies_ShouldDetectNoChanges()
3232
public void GenerateChanges_WithSingleChange_ShouldDetectChangeAndCreateScript()
3333
{
3434
// Arrange
35-
var oldCluster = CreateClusterWithPolicy(0.2, 1, 2, 3);
36-
var newCluster = CreateClusterWithPolicy(0.2, 1, 2, 5);
35+
var oldCluster = CreateClusterWithPolicy(0.2, 1, 2);
36+
var newCluster = CreateClusterWithPolicy(0.2, 1, 5);
3737

3838
// Act
3939
var changeSet = ClusterChanges.GenerateChanges(oldCluster, newCluster, _loggerMock.Object);
@@ -93,8 +93,7 @@ public void GenerateChanges_WithNullNewCapacityPolicy_ShouldNotGenerateChanges()
9393
private Cluster CreateClusterWithPolicy(
9494
double? ingestionCapacityCoreUtilizationCoefficient = null,
9595
int? materializedViewsCapacityClusterMaximumConcurrentOperations = null,
96-
int? extentsRebuildClusterMaximumConcurrentOperations = null,
97-
int? extentsRebuildMaximumConcurrentOperationsPerNode = null
96+
int? materializedViewsCapacityClusterMinimumConcurrentOperations = null
9897
)
9998
{
10099
return new Cluster
@@ -104,11 +103,7 @@ private Cluster CreateClusterWithPolicy(
104103
MaterializedViewsCapacity = new MaterializedViewsCapacity
105104
{
106105
ClusterMaximumConcurrentOperations = materializedViewsCapacityClusterMaximumConcurrentOperations,
107-
ExtentsRebuildCapacity = (extentsRebuildClusterMaximumConcurrentOperations != null || extentsRebuildMaximumConcurrentOperationsPerNode != null) ? new ExtentsRebuildCapacity
108-
{
109-
ClusterMaximumConcurrentOperations = extentsRebuildClusterMaximumConcurrentOperations,
110-
MaximumConcurrentOperationsPerNode = extentsRebuildMaximumConcurrentOperationsPerNode
111-
} : null
106+
ClusterMinimumConcurrentOperations = materializedViewsCapacityClusterMinimumConcurrentOperations
112107
},
113108
IngestionCapacity = new IngestionCapacity
114109
{

KustoSchemaTools.Tests/KustoClusterOrchestratorTests.cs

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,6 @@
33
using KustoSchemaTools.Parser;
44
using Microsoft.Extensions.Logging;
55
using Moq;
6-
using System.Collections.Generic;
7-
using System.IO;
8-
using System.Threading.Tasks;
9-
using Xunit;
10-
using System.Data;
11-
using System;
12-
using System.Linq;
136
using Kusto.Data.Common;
147

158
namespace KustoSchemaTools.Tests
@@ -28,10 +21,9 @@ public KustoClusterOrchestratorTests()
2821
kustoClusterHandlerFactoryMock = new Mock<IKustoClusterHandlerFactory>();
2922
yamlClusterHandlerFactoryMock = new Mock<IYamlClusterHandlerFactory>();
3023

31-
// Create mock for KustoClusterHandler
32-
var kustoClientMock = new Mock<KustoClient>("test.eastus");
24+
var adminClientMock = new Mock<ICslAdminProvider>();
3325
var kustoLoggerMock = new Mock<ILogger<KustoClusterHandler>>();
34-
kustoHandlerMock = new Mock<KustoClusterHandler>(kustoClientMock.Object, kustoLoggerMock.Object, "test", "test.eastus");
26+
kustoHandlerMock = new Mock<KustoClusterHandler>(adminClientMock.Object, kustoLoggerMock.Object, "test", "test.eastus");
3527

3628
orchestrator = new KustoClusterOrchestrator(
3729
loggerMock.Object,
@@ -57,12 +49,10 @@ private Clusters CreateClustersWithCapacityPolicy(ClusterCapacityPolicy? capacit
5749

5850
private void SetupMockHandler(Cluster kustoCluster)
5951
{
60-
// Configure the handler factory to return our mock handler
6152
kustoClusterHandlerFactoryMock
6253
.Setup(f => f.Create("test", "test.eastus"))
6354
.Returns(kustoHandlerMock.Object);
6455

65-
// Set up the mock handler to return our test cluster
6656
kustoHandlerMock
6757
.Setup(h => h.LoadAsync())
6858
.ReturnsAsync(kustoCluster);
@@ -106,8 +96,7 @@ private Clusters CreateMultipleClusters()
10696

10797
private void SetupMultipleClusterMocks()
10898
{
109-
// Mock for cluster1
110-
var kustoHandler1Mock = new Mock<KustoClusterHandler>(new Mock<KustoClient>("cluster1.eastus").Object, new Mock<ILogger<KustoClusterHandler>>().Object, "cluster1", "cluster1.eastus");
99+
var kustoHandler1Mock = new Mock<KustoClusterHandler>(new Mock<ICslAdminProvider>().Object, new Mock<ILogger<KustoClusterHandler>>().Object, "cluster1", "cluster1.eastus");
111100
var kustoCluster1 = new Cluster
112101
{
113102
Name = "cluster1",
@@ -128,8 +117,7 @@ private void SetupMultipleClusterMocks()
128117
.Setup(h => h.LoadAsync())
129118
.ReturnsAsync(kustoCluster1);
130119

131-
// Mock for cluster2 - same as config, no changes
132-
var kustoHandler2Mock = new Mock<KustoClusterHandler>(new Mock<KustoClient>("cluster2.westus").Object, new Mock<ILogger<KustoClusterHandler>>().Object, "cluster2", "cluster2.westus");
120+
var kustoHandler2Mock = new Mock<KustoClusterHandler>(new Mock<ICslAdminProvider>().Object, new Mock<ILogger<KustoClusterHandler>>().Object, "cluster2", "cluster2.westus");
133121
var kustoCluster2 = new Cluster
134122
{
135123
Name = "cluster2",
@@ -404,7 +392,7 @@ public async Task GenerateChangesFromFileAsync_ValidYamlFile_ReturnsChanges()
404392
.Returns(new YamlClusterHandler(yamlFilePath));
405393

406394
// Set up mocks for the clusters defined in the YAML file
407-
var kustoHandler1Mock = new Mock<KustoClusterHandler>(new Mock<KustoClient>("test1.eastus").Object, new Mock<ILogger<KustoClusterHandler>>().Object, "test1", "test1.eastus");
395+
var kustoHandler1Mock = new Mock<KustoClusterHandler>(new Mock<ICslAdminProvider>().Object, new Mock<ILogger<KustoClusterHandler>>().Object, "test1", "test1.eastus");
408396
var kustoCluster1 = new Cluster
409397
{
410398
Name = "test1",
@@ -425,7 +413,7 @@ public async Task GenerateChangesFromFileAsync_ValidYamlFile_ReturnsChanges()
425413
.Setup(h => h.LoadAsync())
426414
.ReturnsAsync(kustoCluster1);
427415

428-
var kustoHandler2Mock = new Mock<KustoClusterHandler>(new Mock<KustoClient>("test2.eastus").Object, new Mock<ILogger<KustoClusterHandler>>().Object, "test2", "test2.eastus");
416+
var kustoHandler2Mock = new Mock<KustoClusterHandler>(new Mock<ICslAdminProvider>().Object, new Mock<ILogger<KustoClusterHandler>>().Object, "test2", "test2.eastus");
429417
var kustoCluster2 = new Cluster
430418
{
431419
Name = "test2",
@@ -568,8 +556,8 @@ public async Task GenerateChangesFromFileAsync_VerifyLoggingCalled()
568556
.Returns(new YamlClusterHandler(yamlFilePath));
569557

570558
// Set up a simple mock for the clusters
571-
var kustoHandler1Mock = new Mock<KustoClusterHandler>(new Mock<KustoClient>("test1.eastus").Object, new Mock<ILogger<KustoClusterHandler>>().Object, "test1", "test1.eastus");
572-
var kustoHandler2Mock = new Mock<KustoClusterHandler>(new Mock<KustoClient>("test2.eastus").Object, new Mock<ILogger<KustoClusterHandler>>().Object, "test2", "test2.eastus");
559+
var kustoHandler1Mock = new Mock<KustoClusterHandler>(new Mock<ICslAdminProvider>().Object, new Mock<ILogger<KustoClusterHandler>>().Object, "test1", "test1.eastus");
560+
var kustoHandler2Mock = new Mock<KustoClusterHandler>(new Mock<ICslAdminProvider>().Object, new Mock<ILogger<KustoClusterHandler>>().Object, "test2", "test2.eastus");
573561

574562
kustoClusterHandlerFactoryMock
575563
.Setup(f => f.Create("test1", "test1.eastus"))
@@ -639,7 +627,7 @@ public async Task GenerateChangesFromFileAsync_LoadAsyncThrowsException_Propagat
639627
.Setup(f => f.Create(yamlFilePath))
640628
.Returns(new YamlClusterHandler(yamlFilePath));
641629

642-
var kustoHandler1Mock = new Mock<KustoClusterHandler>(new Mock<KustoClient>("test1.eastus").Object, new Mock<ILogger<KustoClusterHandler>>().Object, "test1", "test1.eastus");
630+
var kustoHandler1Mock = new Mock<KustoClusterHandler>(new Mock<ICslAdminProvider>().Object, new Mock<ILogger<KustoClusterHandler>>().Object, "test1", "test1.eastus");
643631

644632
kustoClusterHandlerFactoryMock
645633
.Setup(f => f.Create("test1", "test1.eastus"))

0 commit comments

Comments
 (0)