aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Azure/Tango.AzureUtils
diff options
context:
space:
mode:
authorRoy Ben Shabat <Roy.mail.net@gmail.com>2020-02-14 12:13:10 +0200
committerRoy Ben Shabat <Roy.mail.net@gmail.com>2020-02-14 12:13:10 +0200
commit6e6126cca201dae1f3a9499bb0d950fb9d797a8f (patch)
treec1cc50ee03b24a21ae4f620bc805076dfba948a8 /Software/Visual_Studio/Azure/Tango.AzureUtils
parent678b22afc27e53811f978103b7ea41609ff68606 (diff)
downloadTango-6e6126cca201dae1f3a9499bb0d950fb9d797a8f.tar.gz
Tango-6e6126cca201dae1f3a9499bb0d950fb9d797a8f.zip
Implemented version rollback on AzureUtils.
Changed GetLatestVersion on machine service to respond to any version difference instead of smaller version.
Diffstat (limited to 'Software/Visual_Studio/Azure/Tango.AzureUtils')
-rw-r--r--Software/Visual_Studio/Azure/Tango.AzureUtils/Database/DatabaseManager.cs30
-rw-r--r--Software/Visual_Studio/Azure/Tango.AzureUtils/Environment/EnvironmentManager.cs56
-rw-r--r--Software/Visual_Studio/Azure/Tango.AzureUtils/Environment/RollbackEnvironmentConfiguration.cs15
-rw-r--r--Software/Visual_Studio/Azure/Tango.AzureUtils/Storage/StorageManager.cs34
-rw-r--r--Software/Visual_Studio/Azure/Tango.AzureUtils/Tango.AzureUtils.csproj1
5 files changed, 136 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Azure/Tango.AzureUtils/Database/DatabaseManager.cs b/Software/Visual_Studio/Azure/Tango.AzureUtils/Database/DatabaseManager.cs
index 0c2e56edf..cb1a608a8 100644
--- a/Software/Visual_Studio/Azure/Tango.AzureUtils/Database/DatabaseManager.cs
+++ b/Software/Visual_Studio/Azure/Tango.AzureUtils/Database/DatabaseManager.cs
@@ -231,6 +231,36 @@ namespace Tango.AzureUtils.Database
}
}
+ public async Task DowngradeMachineStudioVersion(IWebAppBase app)
+ {
+ var latestMachineStudioVersion = await GetLatestMachineStudioVersion(app);
+ var dataSource = (await app.GetMachineServiceSettingsAsync()).ToDataSource();
+
+ OnProgress(AzureUtilsStage.Database, $"Removing machine studio database entry for version '{latestMachineStudioVersion.Version}'...");
+
+ using (var db = ObservablesContext.CreateDefault(dataSource))
+ {
+ var latest = await db.MachineStudioVersions.SingleOrDefaultAsync(x => x.Guid == latestMachineStudioVersion.Guid);
+ db.MachineStudioVersions.Remove(latest);
+ await db.SaveChangesAsync();
+ }
+ }
+
+ public async Task DowngradePPCVersion(IWebAppBase app)
+ {
+ var latestPPCVersion = await GetLatestPPCVersion(app);
+ var dataSource = (await app.GetMachineServiceSettingsAsync()).ToDataSource();
+
+ OnProgress(AzureUtilsStage.Database, $"Removing PPC database entry for version '{latestPPCVersion.Version}'...");
+
+ using (var db = ObservablesContext.CreateDefault(dataSource))
+ {
+ var latest = await db.TangoVersions.SingleOrDefaultAsync(x => x.Guid == latestPPCVersion.Guid);
+ db.TangoVersions.Remove(latest);
+ await db.SaveChangesAsync();
+ }
+ }
+
public async Task<MachineStudioVersion> GetLatestMachineStudioVersion(IWebAppBase app)
{
OnProgress(AzureUtilsStage.Database, $"Getting latest machine studio version on '{app.Name}'...");
diff --git a/Software/Visual_Studio/Azure/Tango.AzureUtils/Environment/EnvironmentManager.cs b/Software/Visual_Studio/Azure/Tango.AzureUtils/Environment/EnvironmentManager.cs
index 83b0c29ee..53665a73d 100644
--- a/Software/Visual_Studio/Azure/Tango.AzureUtils/Environment/EnvironmentManager.cs
+++ b/Software/Visual_Studio/Azure/Tango.AzureUtils/Environment/EnvironmentManager.cs
@@ -453,5 +453,61 @@ namespace Tango.AzureUtils.Environment
}
#endregion
+
+ #region Rollback
+
+ public async Task RollbackEnvironment(IWebAppBase app, RollbackEnvironmentConfiguration config)
+ {
+ OnProgress(AzureUtilsStage.Environment, $"Retrieving settings for '{app.Name}'...");
+
+ var settings = await app.GetMachineServiceSettingsAsync();
+ await _storageManager.Connect(settings.STORAGE_ACCOUNT);
+
+ if (config.RollbackMachineStudio)
+ {
+ try
+ {
+ await _storageManager.DowngradeMachineStudioStorage(app);
+ }
+ catch (Exception ex)
+ {
+ await RequestConfirmation($"Error occurred while trying to remove machine studio storage blobs.\n{ex.FlattenMessage()}\nDo you wish to continue?");
+ }
+
+ try
+ {
+ await _databaseManager.DowngradeMachineStudioVersion(app);
+ }
+ catch (Exception ex)
+ {
+ await RequestConfirmation($"Error occurred while trying to remove machine studio database version.\n{ex.FlattenMessage()}\nDo you wish to continue?");
+ }
+ }
+
+ if (config.RollbackPPC)
+ {
+ try
+ {
+ await _storageManager.DowngradePPCStorage(app);
+ }
+ catch (Exception ex)
+ {
+ await RequestConfirmation($"Error occurred while trying to remove PPC storage blobs.\n{ex.FlattenMessage()}\nDo you wish to continue?");
+ }
+
+ try
+ {
+ await _databaseManager.DowngradePPCVersion(app);
+ }
+ catch (Exception ex)
+ {
+ await RequestConfirmation($"Error occurred while trying to remove PPC database version.\n{ex.FlattenMessage()}\nDo you wish to continue?");
+ }
+ }
+
+ OnCompleted("Environment rollback completed successfully.");
+ }
+
+ #endregion
}
}
diff --git a/Software/Visual_Studio/Azure/Tango.AzureUtils/Environment/RollbackEnvironmentConfiguration.cs b/Software/Visual_Studio/Azure/Tango.AzureUtils/Environment/RollbackEnvironmentConfiguration.cs
new file mode 100644
index 000000000..da0f68aac
--- /dev/null
+++ b/Software/Visual_Studio/Azure/Tango.AzureUtils/Environment/RollbackEnvironmentConfiguration.cs
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tango.AzureUtils.Environment
+{
+ public class RollbackEnvironmentConfiguration
+ {
+ public bool RollbackMachineStudio { get; set; }
+
+ public bool RollbackPPC { get; set; }
+ }
+}
diff --git a/Software/Visual_Studio/Azure/Tango.AzureUtils/Storage/StorageManager.cs b/Software/Visual_Studio/Azure/Tango.AzureUtils/Storage/StorageManager.cs
index 3551bf4f4..77a0aaf6d 100644
--- a/Software/Visual_Studio/Azure/Tango.AzureUtils/Storage/StorageManager.cs
+++ b/Software/Visual_Studio/Azure/Tango.AzureUtils/Storage/StorageManager.cs
@@ -68,6 +68,14 @@ namespace Tango.AzureUtils.Storage
await container.DeleteAsync();
}
+ public async Task RemoveBlob(String containerName, String blobName)
+ {
+ OnProgress(AzureUtilsStage.Storage, $"Removing blob '{blobName}'...");
+ var container = _client.GetContainerReference(containerName);
+ var blob = container.GetBlockBlobReference(blobName);
+ await blob.DeleteAsync();
+ }
+
public async Task UpgradePPCStorage(IWebAppBase sourceApp, IWebAppBase targetApp)
{
OnProgress(AzureUtilsStage.Storage, $"Retrieving source and target settings...");
@@ -134,6 +142,32 @@ namespace Tango.AzureUtils.Storage
});
}
+ public async Task DowngradeMachineStudioStorage(IWebAppBase app)
+ {
+ OnProgress(AzureUtilsStage.Storage, $"Retrieving settings...");
+
+ var latestMachineStudioVersion = await _databaseManager.GetLatestMachineStudioVersion(app);
+ var settings = await app.GetMachineServiceSettingsAsync();
+
+ await RemoveBlob(settings.MACHINE_STUDIO_VERSIONS_CONTAINER, latestMachineStudioVersion.BlobName);
+ await RemoveBlob(settings.MACHINE_STUDIO_VERSIONS_CONTAINER, latestMachineStudioVersion.InstallerBlobName);
+
+ OnCompleted("Latest Machine Studio storage blobs removed.");
+ }
+
+ public async Task DowngradePPCStorage(IWebAppBase app)
+ {
+ OnProgress(AzureUtilsStage.Storage, $"Retrieving settings...");
+
+ var latestPPCVersion = await _databaseManager.GetLatestPPCVersion(app);
+ var settings = await app.GetMachineServiceSettingsAsync();
+
+ await RemoveBlob(settings.TANGO_VERSIONS_CONTAINER, latestPPCVersion.BlobName);
+ await RemoveBlob(settings.TANGO_VERSIONS_CONTAINER, latestPPCVersion.InstallerBlobName);
+
+ OnCompleted("Latest PPC storage blobs removed.");
+ }
+
public async Task ValidatePPCStorageUpgrade(IWebAppBase sourceApp, IWebAppBase targetApp)
{
OnProgress(AzureUtilsStage.Validating, "Validating PPC database upgrade...");
diff --git a/Software/Visual_Studio/Azure/Tango.AzureUtils/Tango.AzureUtils.csproj b/Software/Visual_Studio/Azure/Tango.AzureUtils/Tango.AzureUtils.csproj
index 4a8daf233..896c34635 100644
--- a/Software/Visual_Studio/Azure/Tango.AzureUtils/Tango.AzureUtils.csproj
+++ b/Software/Visual_Studio/Azure/Tango.AzureUtils/Tango.AzureUtils.csproj
@@ -241,6 +241,7 @@
<Compile Include="AzureUtilsProgressEventArgs.cs" />
<Compile Include="AzureUtilsStage.cs" />
<Compile Include="Environment\CreateEnvironmentConfiguration.cs" />
+ <Compile Include="Environment\RollbackEnvironmentConfiguration.cs" />
<Compile Include="Environment\RemoveEnvironmentConfiguration.cs" />
<Compile Include="Environment\EnvironmentSettings.cs" />
<Compile Include="Environment\UpgradeEnvironmentConfiguration.cs" />