Skip to content
This repository was archived by the owner on Aug 4, 2022. It is now read-only.

Commit 2bfe5a7

Browse files
Automate pipeline management (#147)
* Extract business logic from UI menus to Actions. Correcting name spaces to match folder structure * Fix naming issues * Enable draining and starting the pipelines from the command line * Create Action for running initialization steps Separate the logic of creating and running steps from the EnableScaleUnitFeature menu, making it simpler and more decoupled. * Move deployer to Utilities folder Use StepGenerator in Deployer * Fix import path * Use GetScaleUnitId in menus Also change access modifiers for IAction
1 parent 0884f7e commit 2bfe5a7

47 files changed

Lines changed: 690 additions & 374 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using ScaleUnitManagement.DatabaseManager;
4+
5+
namespace CLI.Actions
6+
{
7+
internal class CleanUpStorageAccountAction : ContextualAction
8+
{
9+
public CleanUpStorageAccountAction(string scaleUnitId) : base(scaleUnitId)
10+
{
11+
}
12+
13+
protected override async Task ExecuteInScaleUnitContext()
14+
{
15+
try
16+
{
17+
var storageAccountManager = new StorageAccountManager();
18+
await storageAccountManager.CleanStorageAccount();
19+
Console.WriteLine("Done");
20+
}
21+
catch (Exception ex)
22+
{
23+
Console.WriteLine($"An exception occured while cleaning up storage: \n{ex}");
24+
}
25+
}
26+
}
27+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System.Threading.Tasks;
2+
using ScaleUnitManagement.Utilities;
3+
using ScaleUnitManagement.WorkloadSetupOrchestrator;
4+
5+
namespace CLI.Actions
6+
{
7+
internal class ConfigureEnvironmentAction : ContextualAction
8+
{
9+
public ConfigureEnvironmentAction(string scaleUnitId) : base(scaleUnitId)
10+
{
11+
}
12+
13+
protected override async Task ExecuteInScaleUnitContext()
14+
{
15+
if (ScaleUnitContext.GetScaleUnitId() == "@@")
16+
await new HubConfigurationManager().Configure();
17+
else
18+
await new ScaleUnitConfigurationManager().Configure();
19+
}
20+
}
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using ScaleUnitManagement.WorkloadSetupOrchestrator;
4+
5+
namespace CLI.Actions
6+
{
7+
internal class DeleteWorkloadsAction : ContextualAction
8+
{
9+
public DeleteWorkloadsAction(string scaleUnitId) : base(scaleUnitId)
10+
{
11+
}
12+
13+
protected override async Task ExecuteInScaleUnitContext()
14+
{
15+
var workloadDeleter = new WorkloadDeleter();
16+
await workloadDeleter.DeleteWorkloadsFromScaleUnit();
17+
18+
Console.WriteLine("Done.");
19+
}
20+
}
21+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using ScaleUnitManagement.ScaleUnitFeatureManager.Common;
4+
using ScaleUnitManagement.Utilities;
5+
6+
namespace CLI.Actions
7+
{
8+
internal class DisableScaleUnitFeatureAction : ContextualAction
9+
{
10+
public DisableScaleUnitFeatureAction(string scaleUnitId) : base(scaleUnitId)
11+
{
12+
}
13+
14+
protected override Task ExecuteInScaleUnitContext()
15+
{
16+
try
17+
{
18+
new StopServices().Run();
19+
using (var webConfig = new WebConfig())
20+
{
21+
SharedWebConfig.Configure(webConfig, isScaleUnitFeatureEnabled: false);
22+
}
23+
new RunDBSync().Run(isScaleUnitFeatureEnabled: false);
24+
new StartServices().Run();
25+
}
26+
catch (Exception ex)
27+
{
28+
Console.Error.WriteLine($"An error occured while trying to disable scale unit feature:\n{ex}");
29+
}
30+
return Task.CompletedTask;
31+
}
32+
}
33+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System.Threading.Tasks;
2+
using ScaleUnitManagement.WorkloadSetupOrchestrator;
3+
4+
namespace CLI.Actions
5+
{
6+
internal class DrainPipelinesAction : ContextualAction
7+
{
8+
public DrainPipelinesAction(string scaleUnitId) : base(scaleUnitId)
9+
{
10+
}
11+
12+
protected override async Task ExecuteInScaleUnitContext()
13+
{
14+
var pipelineManager = new PipelineManager();
15+
await pipelineManager.DrainWorkloadDataPipelines();
16+
}
17+
}
18+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using ScaleUnitManagement.DatabaseManager;
4+
5+
namespace CLI.Actions
6+
{
7+
internal class ImportWorkloadBlobAction : ContextualAction
8+
{
9+
private readonly string sasToken;
10+
11+
public ImportWorkloadBlobAction(string scaleUnitId, string sasToken) : base(scaleUnitId)
12+
{
13+
this.sasToken = sasToken;
14+
}
15+
16+
protected override async Task ExecuteInScaleUnitContext()
17+
{
18+
var storageAccountManager = new StorageAccountManager();
19+
try
20+
{
21+
await storageAccountManager.ImportWorkloadsBlob(sasToken);
22+
Console.WriteLine("Done");
23+
}
24+
catch (Exception ex)
25+
{
26+
Console.WriteLine($"An exception occured while importing blobs: {ex.Message}");
27+
}
28+
}
29+
}
30+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System.Threading.Tasks;
2+
using ScaleUnitManagement.Utilities;
3+
using ScaleUnitManagement.WorkloadSetupOrchestrator;
4+
5+
namespace CLI.Actions
6+
{
7+
internal class InstallWorkloadsAction : ContextualAction
8+
{
9+
public InstallWorkloadsAction(string scaleUnitId) : base(scaleUnitId)
10+
{
11+
}
12+
13+
protected override async Task ExecuteInScaleUnitContext()
14+
{
15+
if (ScaleUnitContext.GetScaleUnitId() == "@@")
16+
await new HubWorkloadInstaller().Install();
17+
else
18+
await new ScaleUnitWorkloadInstaller().Install();
19+
}
20+
}
21+
}

src/CLI/Menus/WorkloadMovementOptions/MoveWorkloads.cs renamed to src/CLI/Actions/MoveAllWorkloadsAction.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1+
using System;
2+
using System.Collections.Generic;
13
using System.Threading.Tasks;
24
using ScaleUnitManagement.Utilities;
35
using ScaleUnitManagement.WorkloadSetupOrchestrator;
4-
using System;
56

6-
namespace CLI.WorkloadMovementOptions
7+
namespace CLI.Actions
78
{
8-
internal class MoveWorkloads
9+
internal class MoveAllWorkloadsAction : IAction
910
{
10-
public async Task MoveAllWorkloads(int input, string selectionHistory)
11+
public async Task Execute()
1112
{
1213
try
1314
{
1415
Console.WriteLine("Moving all workloads to the hub");
15-
System.Collections.Generic.List<ScaleUnitInstance> scaleUnitInstances = Config.ScaleUnitInstances();
16+
List<ScaleUnitInstance> scaleUnitInstances = Config.ScaleUnitInstances();
1617

1718
foreach (ScaleUnitInstance scaleUnit in scaleUnitInstances)
1819
{
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using ScaleUnitManagement.WorkloadSetupOrchestrator;
4+
5+
namespace CLI.Actions
6+
{
7+
internal class PerformEmergencyTransitionToHubAction : ContextualAction
8+
{
9+
public PerformEmergencyTransitionToHubAction(string scaleUnitId) : base(scaleUnitId)
10+
{
11+
}
12+
13+
protected override async Task ExecuteInScaleUnitContext()
14+
{
15+
try
16+
{
17+
var workloadMover = new WorkloadMover();
18+
await workloadMover.EmergencyTransitionToHub();
19+
Console.WriteLine("Done");
20+
}
21+
catch (Exception ex)
22+
{
23+
Console.Error.WriteLine($"An error occured while trying to run emergency transition to hub:\n{ex}");
24+
}
25+
}
26+
}
27+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System.Threading.Tasks;
2+
using ScaleUnitManagement.WorkloadSetupOrchestrator;
3+
4+
namespace CLI.Actions
5+
{
6+
internal class StartPipelinesAction : ContextualAction
7+
{
8+
public StartPipelinesAction(string scaleUnitId) : base(scaleUnitId)
9+
{
10+
}
11+
12+
protected override async Task ExecuteInScaleUnitContext()
13+
{
14+
var pipelineManager = new PipelineManager();
15+
await pipelineManager.StartWorkloadDataPipelines();
16+
}
17+
}
18+
}

0 commit comments

Comments
 (0)