aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Azure/Tango.AzureUtils
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2020-02-04 16:32:43 +0200
committerRoy Ben-Shabat <Roy@Twine-s.com>2020-02-04 16:32:43 +0200
commit5bf3a7b36b3ccc7942f4e8e3fa227a38c04a8451 (patch)
tree03019be5bddc677ddb440fa00affc9b7c24aa1ce /Software/Visual_Studio/Azure/Tango.AzureUtils
parentc6a0f97efd7fc804e761086db3179443d1414df7 (diff)
downloadTango-5bf3a7b36b3ccc7942f4e8e3fa227a38c04a8451.tar.gz
Tango-5bf3a7b36b3ccc7942f4e8e3fa227a38c04a8451.zip
Working on azure utils.
Diffstat (limited to 'Software/Visual_Studio/Azure/Tango.AzureUtils')
-rw-r--r--Software/Visual_Studio/Azure/Tango.AzureUtils/AzureUtilsAuthenticationFactory.cs37
-rw-r--r--Software/Visual_Studio/Azure/Tango.AzureUtils/AzureUtilsComponentBase.cs34
-rw-r--r--Software/Visual_Studio/Azure/Tango.AzureUtils/AzureUtilsProgressEventArgs.cs (renamed from Software/Visual_Studio/Azure/Tango.AzureUtils/Deployment/DeploymentProgressEventArgs.cs)6
-rw-r--r--Software/Visual_Studio/Azure/Tango.AzureUtils/AzureUtilsStage.cs (renamed from Software/Visual_Studio/Azure/Tango.AzureUtils/Deployment/DeploymentStage.cs)8
-rw-r--r--Software/Visual_Studio/Azure/Tango.AzureUtils/Deployment/DeploymentManager.cs107
-rw-r--r--Software/Visual_Studio/Azure/Tango.AzureUtils/Deployment/ExtensionMethods.cs1
-rw-r--r--Software/Visual_Studio/Azure/Tango.AzureUtils/Deployment/MachineServiceSettings.cs1
-rw-r--r--Software/Visual_Studio/Azure/Tango.AzureUtils/Deployment/UpgradeConfiguration.cs26
-rw-r--r--Software/Visual_Studio/Azure/Tango.AzureUtils/Tango.AzureUtils.csproj6
9 files changed, 152 insertions, 74 deletions
diff --git a/Software/Visual_Studio/Azure/Tango.AzureUtils/AzureUtilsAuthenticationFactory.cs b/Software/Visual_Studio/Azure/Tango.AzureUtils/AzureUtilsAuthenticationFactory.cs
new file mode 100644
index 000000000..4e37be13f
--- /dev/null
+++ b/Software/Visual_Studio/Azure/Tango.AzureUtils/AzureUtilsAuthenticationFactory.cs
@@ -0,0 +1,37 @@
+using Microsoft.Azure.Management.Fluent;
+using Microsoft.Azure.Management.ResourceManager.Fluent;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tango.AzureUtils
+{
+ public class AzureUtilsAuthenticationFactory
+ {
+ private static IAzure _azure;
+
+ public static Task<IAzure> AuthenticateOrGetAsync(AzureUtilsCredentials creds)
+ {
+ if (_azure == null)
+ {
+ return Task.Factory.StartNew<IAzure>(() =>
+ {
+ var credentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal(
+ creds.ClientID,
+ creds.ClientSecret,
+ creds.TenantID,
+ AzureEnvironment.AzureGlobalCloud);
+
+ _azure = Azure.Authenticate(credentials).WithSubscription(creds.SubscriptionID);
+ return _azure;
+ });
+ }
+ else
+ {
+ return Task.FromResult(_azure);
+ }
+ }
+ }
+}
diff --git a/Software/Visual_Studio/Azure/Tango.AzureUtils/AzureUtilsComponentBase.cs b/Software/Visual_Studio/Azure/Tango.AzureUtils/AzureUtilsComponentBase.cs
new file mode 100644
index 000000000..507c9adbc
--- /dev/null
+++ b/Software/Visual_Studio/Azure/Tango.AzureUtils/AzureUtilsComponentBase.cs
@@ -0,0 +1,34 @@
+using Microsoft.Azure.Management.Fluent;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.Core;
+
+namespace Tango.AzureUtils
+{
+ public abstract class AzureUtilsComponentBase : ExtendedObject
+ {
+ protected IAzure Azure { get; private set; }
+
+ public event EventHandler<AzureUtilsProgressEventArgs> Progress;
+
+ public AzureUtilsComponentBase(IAzure azure)
+ {
+ Azure = azure;
+ }
+
+ protected virtual void OnProgress(AzureUtilsStage stage, String message = null, double progress = 0, double maximum = 100, bool indeterminate = true)
+ {
+ Progress?.Invoke(this, new AzureUtilsProgressEventArgs()
+ {
+ Stage = stage,
+ Message = message,
+ Progress = progress,
+ Maximum = maximum,
+ IsIndeterminate = indeterminate,
+ });
+ }
+ }
+}
diff --git a/Software/Visual_Studio/Azure/Tango.AzureUtils/Deployment/DeploymentProgressEventArgs.cs b/Software/Visual_Studio/Azure/Tango.AzureUtils/AzureUtilsProgressEventArgs.cs
index 5fe166464..554ae8e3d 100644
--- a/Software/Visual_Studio/Azure/Tango.AzureUtils/Deployment/DeploymentProgressEventArgs.cs
+++ b/Software/Visual_Studio/Azure/Tango.AzureUtils/AzureUtilsProgressEventArgs.cs
@@ -4,11 +4,11 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
-namespace Tango.AzureUtils.Deployment
+namespace Tango.AzureUtils
{
- public class DeploymentProgressEventArgs : EventArgs
+ public class AzureUtilsProgressEventArgs : EventArgs
{
- public DeploymentStage Stage { get; set; }
+ public AzureUtilsStage Stage { get; set; }
public double Progress { get; set; }
public double Maximum { get; set; }
public bool IsIndeterminate { get; set; }
diff --git a/Software/Visual_Studio/Azure/Tango.AzureUtils/Deployment/DeploymentStage.cs b/Software/Visual_Studio/Azure/Tango.AzureUtils/AzureUtilsStage.cs
index 531a1ed8c..f7e0c1cd4 100644
--- a/Software/Visual_Studio/Azure/Tango.AzureUtils/Deployment/DeploymentStage.cs
+++ b/Software/Visual_Studio/Azure/Tango.AzureUtils/AzureUtilsStage.cs
@@ -4,12 +4,16 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
-namespace Tango.AzureUtils.Deployment
+namespace Tango.AzureUtils
{
- public enum DeploymentStage
+ public enum AzureUtilsStage
{
Ready,
Initializing,
+ Error,
+
+ //Deployment
+ Validating,
DownloadingFTP,
UploadingFTP,
}
diff --git a/Software/Visual_Studio/Azure/Tango.AzureUtils/Deployment/DeploymentManager.cs b/Software/Visual_Studio/Azure/Tango.AzureUtils/Deployment/DeploymentManager.cs
index 8a3b6ad7b..782466c37 100644
--- a/Software/Visual_Studio/Azure/Tango.AzureUtils/Deployment/DeploymentManager.cs
+++ b/Software/Visual_Studio/Azure/Tango.AzureUtils/Deployment/DeploymentManager.cs
@@ -20,24 +20,18 @@ using Tango.BL;
using Tango.BL.Entities;
using Tango.Core;
using Tango.Core.Helpers;
+using Microsoft.Azure.Management.AppService.Fluent.DeploymentSlot.Definition;
+using Microsoft.Azure.Management.AppService.Fluent.WebAppBase.Definition;
namespace Tango.AzureUtils.Deployment
{
- public class DeploymentManager : ExtendedObject
+ public class DeploymentManager : AzureUtilsComponentBase
{
- private AzureUtilsCredentials _credentials;
- private IAzure _azure;
private IProgress<FtpProgress> _ftpDownloadProgress;
private IProgress<FtpProgress> _ftpUploadProgress;
//TODO: Embedded TFP injection to current package!
- #region Events
-
- public event EventHandler<DeploymentProgressEventArgs> DeploymentProgress;
-
- #endregion
-
#region Properties
private UpgradeConfiguration _upgradeConfiguration;
@@ -51,59 +45,28 @@ namespace Tango.AzureUtils.Deployment
#region Constructors
- public DeploymentManager(AzureUtilsCredentials credentials)
+ public DeploymentManager(IAzure azure) : base(azure)
{
UpgradeConfiguration = new UpgradeConfiguration();
- _credentials = credentials;
-
_ftpDownloadProgress = new Progress<FtpProgress>((p) =>
{
- OnProgress(DeploymentStage.DownloadingFTP, $"Downloading {p.RemotePath}...", p.Progress, 100, false);
+ OnProgress(AzureUtilsStage.DownloadingFTP, $"Downloading {p.RemotePath}...", p.Progress, 100, false);
});
_ftpUploadProgress = new Progress<FtpProgress>((p) =>
{
- OnProgress(DeploymentStage.UploadingFTP, $"Uploading {p.LocalPath}...", p.Progress, 100, false);
+ OnProgress(AzureUtilsStage.UploadingFTP, $"Uploading {p.LocalPath}...", p.Progress, 100, false);
});
}
#endregion
- #region Authenticate
-
- private IAzure GetOrCreateAzure()
- {
- if (_azure == null)
- {
- var credentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal(
- _credentials.ClientID,
- _credentials.ClientSecret,
- _credentials.TenantID,
- AzureEnvironment.AzureGlobalCloud);
-
- _azure = Azure.Authenticate(credentials).WithSubscription(_credentials.SubscriptionID);
- }
-
- return _azure;
- }
-
- #endregion
-
#region Helpers
public async Task<List<IWebApp>> GetAllWebAppsAsync()
{
- return (await GetOrCreateAzure().WebApps.ListAsync()).ToList();
- }
-
- #endregion
-
- #region Init
-
- public void Init()
- {
- GetOrCreateAzure();
+ return (await Azure.WebApps.ListAsync()).ToList();
}
#endregion
@@ -260,7 +223,7 @@ namespace Tango.AzureUtils.Deployment
}
catch (Exception ex)
{
- throw new ArgumentException("Could not fetch machine service settings. Please check that all settings are available.");
+ throw new ArgumentException("Could not fetch machine service settings. Please check that all settings are available.", ex);
}
try
@@ -276,7 +239,7 @@ namespace Tango.AzureUtils.Deployment
}
catch (Exception ex)
{
- throw new InvalidDataException("Could not retrieve latest Machine Studio version from database.", ex);
+ throw new InvalidDataException($"Could not retrieve '{app.Name}' latest Machine Studio version from database.", ex);
}
}
@@ -306,7 +269,7 @@ namespace Tango.AzureUtils.Deployment
}
catch (Exception ex)
{
- throw new InvalidDataException("Could not retrieve latest PPC version from database.", ex);
+ throw new InvalidDataException($"Could not retrieve '{app.Name}' latest PPC version from database.", ex);
}
}
@@ -399,10 +362,44 @@ namespace Tango.AzureUtils.Deployment
#endregion
+ #region Deployment Slots
+
+ public async Task<IDeploymentSlot> AddDeploymentSlot(IWebApp app, IDeploymentSlot existingSlot, String name, MachineServiceSettings settings)
+ {
+ var slot = app.DeploymentSlots.Define(name);
+ IWithCreate<IDeploymentSlot> toCreate = null;
+
+ if (existingSlot != null)
+ {
+ toCreate = slot.WithConfigurationFromDeploymentSlot(existingSlot);
+ }
+ else
+ {
+ toCreate = slot.WithBrandNewConfiguration();
+ }
+
+ var dictionary = new Dictionary<string, string>();
+ dictionary.Add(nameof(MachineServiceSettings.DB_ADDRESS), settings.DB_ADDRESS);
+ dictionary.Add(nameof(MachineServiceSettings.DB_ADDRESS), settings.DB_ADDRESS);
+ dictionary.Add(nameof(MachineServiceSettings.DB_CATALOG), settings.DB_CATALOG);
+ dictionary.Add(nameof(MachineServiceSettings.DB_USER_NAME), settings.DB_USER_NAME);
+
+ var result = await toCreate.CreateAsync();
+
+ return result;
+ }
+
+ #endregion
+
#region Validation
public async Task ValidateUpgrade(IWebAppBase sourceApp, IWebAppBase targetApp)
{
+ if (sourceApp == targetApp)
+ {
+ throw new InvalidOperationException("Invalid upgrade configuration. source app and target app are identical.");
+ }
+
if (UpgradeConfiguration.UpgradeMachineStudio)
{
await ValidateMachineStudioUpgrade(sourceApp, targetApp);
@@ -497,21 +494,5 @@ namespace Tango.AzureUtils.Deployment
}
#endregion
-
- #region Virtual Methods
-
- protected virtual void OnProgress(DeploymentStage stage, String message = null, double progress = 0, double maximum = 100, bool indeterminate = true)
- {
- DeploymentProgress?.Invoke(this, new DeploymentProgressEventArgs()
- {
- Stage = stage,
- Message = message,
- Progress = progress,
- Maximum = maximum,
- IsIndeterminate = indeterminate,
- });
- }
-
- #endregion
}
}
diff --git a/Software/Visual_Studio/Azure/Tango.AzureUtils/Deployment/ExtensionMethods.cs b/Software/Visual_Studio/Azure/Tango.AzureUtils/Deployment/ExtensionMethods.cs
index b9437e49e..938717b43 100644
--- a/Software/Visual_Studio/Azure/Tango.AzureUtils/Deployment/ExtensionMethods.cs
+++ b/Software/Visual_Studio/Azure/Tango.AzureUtils/Deployment/ExtensionMethods.cs
@@ -22,6 +22,7 @@ public static class ExtensionMethods
settings.STORAGE_ACCOUNT = s[nameof(MachineServiceSettings.STORAGE_ACCOUNT)].Value;
settings.MACHINE_STUDIO_VERSIONS_CONTAINER = s[nameof(MachineServiceSettings.MACHINE_STUDIO_VERSIONS_CONTAINER)].Value;
settings.TANGO_VERSIONS_CONTAINER = s[nameof(MachineServiceSettings.TANGO_VERSIONS_CONTAINER)].Value;
+ settings.ENVIRONMENT_GROUP = s[nameof(MachineServiceSettings.ENVIRONMENT_GROUP)].Value;
return settings;
}
diff --git a/Software/Visual_Studio/Azure/Tango.AzureUtils/Deployment/MachineServiceSettings.cs b/Software/Visual_Studio/Azure/Tango.AzureUtils/Deployment/MachineServiceSettings.cs
index 66e374ba8..7becb86df 100644
--- a/Software/Visual_Studio/Azure/Tango.AzureUtils/Deployment/MachineServiceSettings.cs
+++ b/Software/Visual_Studio/Azure/Tango.AzureUtils/Deployment/MachineServiceSettings.cs
@@ -15,5 +15,6 @@ namespace Tango.AzureUtils.Deployment
public String STORAGE_ACCOUNT { get; set; }
public String TANGO_VERSIONS_CONTAINER { get; set; }
public String MACHINE_STUDIO_VERSIONS_CONTAINER { get; set; }
+ public String ENVIRONMENT_GROUP { get; set; }
}
}
diff --git a/Software/Visual_Studio/Azure/Tango.AzureUtils/Deployment/UpgradeConfiguration.cs b/Software/Visual_Studio/Azure/Tango.AzureUtils/Deployment/UpgradeConfiguration.cs
index 233034d0d..ab1099617 100644
--- a/Software/Visual_Studio/Azure/Tango.AzureUtils/Deployment/UpgradeConfiguration.cs
+++ b/Software/Visual_Studio/Azure/Tango.AzureUtils/Deployment/UpgradeConfiguration.cs
@@ -3,13 +3,31 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using Tango.Core;
namespace Tango.AzureUtils.Deployment
{
- public class UpgradeConfiguration
+ public class UpgradeConfiguration : ExtendedObject
{
- public bool UpgradeMachineService { get; set; }
- public bool UpgradeMachineStudio { get; set; }
- public bool UpgradePPC { get; set; }
+ private bool _UpgradeMachineService;
+ public bool UpgradeMachineService
+ {
+ get { return _UpgradeMachineService; }
+ set { _UpgradeMachineService = value; RaisePropertyChangedAuto(); }
+ }
+
+ private bool _UpgradeMachineStudio;
+ public bool UpgradeMachineStudio
+ {
+ get { return _UpgradeMachineStudio; }
+ set { _UpgradeMachineStudio = value; RaisePropertyChangedAuto(); }
+ }
+
+ private bool _UpgradePPC;
+ public bool UpgradePPC
+ {
+ get { return _UpgradePPC; }
+ set { _UpgradePPC = value; RaisePropertyChangedAuto(); }
+ }
}
}
diff --git a/Software/Visual_Studio/Azure/Tango.AzureUtils/Tango.AzureUtils.csproj b/Software/Visual_Studio/Azure/Tango.AzureUtils/Tango.AzureUtils.csproj
index d3dc6a69f..cc9417c18 100644
--- a/Software/Visual_Studio/Azure/Tango.AzureUtils/Tango.AzureUtils.csproj
+++ b/Software/Visual_Studio/Azure/Tango.AzureUtils/Tango.AzureUtils.csproj
@@ -183,10 +183,12 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
+ <Compile Include="AzureUtilsAuthenticationFactory.cs" />
+ <Compile Include="AzureUtilsComponentBase.cs" />
<Compile Include="AzureUtilsCredentials.cs" />
<Compile Include="Deployment\DeploymentManager.cs" />
- <Compile Include="Deployment\DeploymentProgressEventArgs.cs" />
- <Compile Include="Deployment\DeploymentStage.cs" />
+ <Compile Include="AzureUtilsProgressEventArgs.cs" />
+ <Compile Include="AzureUtilsStage.cs" />
<Compile Include="Deployment\ExtensionMethods.cs" />
<Compile Include="Deployment\MachineServiceSettings.cs" />
<Compile Include="Deployment\UpgradeConfiguration.cs" />