aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Azure/Tango.AzureUtils
diff options
context:
space:
mode:
authorRoy Ben Shabat <Roy.mail.net@gmail.com>2020-02-07 04:26:56 +0200
committerRoy Ben Shabat <Roy.mail.net@gmail.com>2020-02-07 04:26:56 +0200
commitaf1c7bd1b6122c1387fe6e2749f9847f4be84b16 (patch)
tree434b68cf03755d17f5a3ae81f346aee66cd427d9 /Software/Visual_Studio/Azure/Tango.AzureUtils
parentd6223286f10478ba2607852a287fa39151e0fcaf (diff)
downloadTango-af1c7bd1b6122c1387fe6e2749f9847f4be84b16.tar.gz
Tango-af1c7bd1b6122c1387fe6e2749f9847f4be84b16.zip
Working on azure utils...
Diffstat (limited to 'Software/Visual_Studio/Azure/Tango.AzureUtils')
-rw-r--r--Software/Visual_Studio/Azure/Tango.AzureUtils/AzureUtilsComponentBase.cs4
-rw-r--r--Software/Visual_Studio/Azure/Tango.AzureUtils/Deployment/DeploymentManager.cs17
-rw-r--r--Software/Visual_Studio/Azure/Tango.AzureUtils/Environment/CreateEnvironmentConfiguration.cs2
-rw-r--r--Software/Visual_Studio/Azure/Tango.AzureUtils/Environment/EnvironmentManager.cs65
-rw-r--r--Software/Visual_Studio/Azure/Tango.AzureUtils/ExtensionMethods.cs13
-rw-r--r--Software/Visual_Studio/Azure/Tango.AzureUtils/Storage/StorageManager.cs3
6 files changed, 89 insertions, 15 deletions
diff --git a/Software/Visual_Studio/Azure/Tango.AzureUtils/AzureUtilsComponentBase.cs b/Software/Visual_Studio/Azure/Tango.AzureUtils/AzureUtilsComponentBase.cs
index 840f7bb58..813a99011 100644
--- a/Software/Visual_Studio/Azure/Tango.AzureUtils/AzureUtilsComponentBase.cs
+++ b/Software/Visual_Studio/Azure/Tango.AzureUtils/AzureUtilsComponentBase.cs
@@ -45,7 +45,7 @@ namespace Tango.AzureUtils
Progress?.Invoke(this, e);
}
- protected async Task<bool> RequestConfirmation(String message, bool throwIfCancel = true)
+ protected async Task<bool> RequestConfirmation(String message)
{
LogManager.Log($"Confirmation Required: {message}");
@@ -66,7 +66,7 @@ namespace Tango.AzureUtils
}
else
{
- return true;
+ throw new OperationCanceledException($"Confirmation required no event handler found. ({message})");
}
}
diff --git a/Software/Visual_Studio/Azure/Tango.AzureUtils/Deployment/DeploymentManager.cs b/Software/Visual_Studio/Azure/Tango.AzureUtils/Deployment/DeploymentManager.cs
index 5f1eb28fd..2cdfce4b0 100644
--- a/Software/Visual_Studio/Azure/Tango.AzureUtils/Deployment/DeploymentManager.cs
+++ b/Software/Visual_Studio/Azure/Tango.AzureUtils/Deployment/DeploymentManager.cs
@@ -58,14 +58,21 @@ namespace Tango.AzureUtils.Deployment
dictionary.Add(nameof(MachineServiceSettings.MACHINE_STUDIO_VERSIONS_CONTAINER), targetSettings.MACHINE_STUDIO_VERSIONS_CONTAINER);
dictionary.Add(nameof(MachineServiceSettings.TANGO_VERSIONS_CONTAINER), targetSettings.TANGO_VERSIONS_CONTAINER);
- var slot = await app.DeploymentSlots
+ var definition = app.DeploymentSlots
.Define(targetSettings.SLOT_NAME)
.WithBrandNewConfiguration()
- .WithWebAppAlwaysOn(true)
- .WithWebSocketsEnabled(true)
+ .WithHttpsOnly(sourceSlot.HttpsOnly)
+ .WithWebAppAlwaysOn(sourceSlot.AlwaysOn)
+ .WithWebSocketsEnabled(sourceSlot.WebSocketsEnabled)
.WithStickyAppSettings(dictionary)
- .WithStickyConnectionString(targetSettings.DB_CATALOG, $"Server=tcp:twine.database.windows.net,1433;Initial Catalog={targetSettings.DB_CATALOG};Persist Security Info=False;User ID=BackupUser;Password=Aa123456;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;", Microsoft.Azure.Management.AppService.Fluent.Models.ConnectionStringType.SQLAzure)
- .CreateAsync();
+ .WithStickyConnectionString(targetSettings.DB_CATALOG, $"Server=tcp:twine.database.windows.net,1433;Initial Catalog={targetSettings.DB_CATALOG};Persist Security Info=False;User ID=BackupUser;Password=Aa123456;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;", Microsoft.Azure.Management.AppService.Fluent.Models.ConnectionStringType.SQLAzure);
+
+ if (sourceSlot.RemoteDebuggingEnabled)
+ {
+ definition = definition.WithRemoteDebuggingEnabled(sourceSlot.RemoteDebuggingVersion);
+ }
+
+ var slot = await definition.CreateAsync();
return slot;
}
diff --git a/Software/Visual_Studio/Azure/Tango.AzureUtils/Environment/CreateEnvironmentConfiguration.cs b/Software/Visual_Studio/Azure/Tango.AzureUtils/Environment/CreateEnvironmentConfiguration.cs
index bf1c2cb31..e8162e4c0 100644
--- a/Software/Visual_Studio/Azure/Tango.AzureUtils/Environment/CreateEnvironmentConfiguration.cs
+++ b/Software/Visual_Studio/Azure/Tango.AzureUtils/Environment/CreateEnvironmentConfiguration.cs
@@ -24,5 +24,7 @@ namespace Tango.AzureUtils.Environment
public bool CopyStorageBlobs { get; set; } = true;
public bool CopyMachineServiceFiles { get; set; } = true;
public bool IgnoreExistingSlot { get; set; } = false;
+ public bool ConfigureMachineServiceLogging { get; set; } = true;
+ public bool ConfigureCloudBackup { get; set; } = true;
}
}
diff --git a/Software/Visual_Studio/Azure/Tango.AzureUtils/Environment/EnvironmentManager.cs b/Software/Visual_Studio/Azure/Tango.AzureUtils/Environment/EnvironmentManager.cs
index f30a51671..7f6c093d4 100644
--- a/Software/Visual_Studio/Azure/Tango.AzureUtils/Environment/EnvironmentManager.cs
+++ b/Software/Visual_Studio/Azure/Tango.AzureUtils/Environment/EnvironmentManager.cs
@@ -5,7 +5,9 @@ using System.Text;
using System.Threading.Tasks;
using Microsoft.Azure;
using Microsoft.Azure.Management.AppService.Fluent;
+using Microsoft.Azure.Management.AppService.Fluent.Models;
using Microsoft.Azure.Management.Fluent;
+using Microsoft.Azure.Management.Monitor.Fluent;
using Microsoft.Azure.Management.RecoveryServices.Backup;
using Microsoft.Azure.Management.Sql.Fluent.Models;
using Microsoft.WindowsAzure.Storage;
@@ -56,10 +58,10 @@ namespace Tango.AzureUtils.Environment
}
//Add Environment Group
- await _adManager.Authenticate(config.Email, config.Password);
-
if (config.CreateEnvironmentGroup)
{
+ await _adManager.Authenticate(config.Email, config.Password);
+
if (!await _adManager.IsGroupExists(targetSettings.ENVIRONMENT_GROUP))
{
await _adManager.AddGroup(targetSettings.ENVIRONMENT_GROUP);
@@ -83,7 +85,7 @@ namespace Tango.AzureUtils.Environment
{
if (slot == null)
{
- slot = await _deploymentManager.CreateDeploymentSlot(app, sourceSlot, targetSettings.SLOT_NAME);
+ slot = await _deploymentManager.CreateDeploymentSlot(app, sourceSlot, name);
}
else
{
@@ -148,16 +150,13 @@ namespace Tango.AzureUtils.Environment
OnProgress(AzureUtilsStage.Environment, $"Waiting for database static collections synchronization...");
}
-
- //Add Storage Containers
await _storageManager.Connect(sourceSettings.STORAGE_ACCOUNT);
+ //Add Storage Containers
if (config.CreateStorageContainers)
{
await _storageManager.CreateContainer(targetSettings.MACHINE_STUDIO_VERSIONS_CONTAINER);
await _storageManager.CreateContainer(targetSettings.TANGO_VERSIONS_CONTAINER);
- await _storageManager.CreateContainer(targetSettings.MACHINE_SERVICE_BACKUPS_CONTAINER);
- await _storageManager.CreateContainer(targetSettings.MACHINE_SERVICE_LOGS_CONTAINER);
}
if (config.CopyStorageBlobs)
@@ -191,6 +190,58 @@ namespace Tango.AzureUtils.Environment
await _ftpManager.CopyAppFiles(sourceSlot, slot);
}
+ //Configure Diagnostics logging.
+ if (config.ConfigureMachineServiceLogging)
+ {
+ OnProgress(AzureUtilsStage.Environment, "Configuring diagnostics logging...");
+
+ var diagnosticsContainer = await _storageManager.CreateContainer(targetSettings.MACHINE_SERVICE_LOGS_CONTAINER);
+ String diagnosticsContainerSasUrl = diagnosticsContainer.GetSharedAccessUrl();
+
+ await Azure.WebApps.Inner.UpdateDiagnosticLogsConfigSlotAsync(app.ResourceGroupName, app.Name, new Microsoft.Azure.Management.AppService.Fluent.Models.SiteLogsConfigInner()
+ {
+ ApplicationLogs = new Microsoft.Azure.Management.AppService.Fluent.Models.ApplicationLogsConfig()
+ {
+ AzureBlobStorage = new Microsoft.Azure.Management.AppService.Fluent.Models.AzureBlobStorageApplicationLogsConfig()
+ {
+ Level = sourceSlot.DiagnosticLogsConfig.ApplicationLoggingStorageBlobLogLevel,
+ RetentionInDays = sourceSlot.DiagnosticLogsConfig.ApplicationLoggingStorageBlobRetentionDays,
+ SasUrl = diagnosticsContainerSasUrl,
+ }
+ },
+ DetailedErrorMessages = new Microsoft.Azure.Management.AppService.Fluent.Models.EnabledConfig(true),
+ }, slot.Name);
+ }
+
+ //Configure Cloud Backup.
+ if (config.ConfigureCloudBackup)
+ {
+ OnProgress(AzureUtilsStage.Environment, "Configuring cloud backup...");
+
+ var sourceConfig = await Azure.WebApps.Inner.GetBackupConfigurationSlotAsync(app.ResourceGroupName, app.Name, sourceSlot.Name);
+
+ var backupContainer = await _storageManager.CreateContainer(targetSettings.MACHINE_SERVICE_BACKUPS_CONTAINER);
+
+ var connectionStrings = await slot.GetConnectionStringsAsync();
+ var databaseConnectionString = connectionStrings.SingleOrDefault(x => x.Value.Name == targetSettings.DB_CATALOG);
+
+ await Azure.WebApps.Inner.UpdateBackupConfigurationSlotAsync(app.ResourceGroupName, app.Name, new Microsoft.Azure.Management.AppService.Fluent.Models.BackupRequestInner()
+ {
+ BackupSchedule = sourceConfig.BackupSchedule,
+ Enabled = sourceConfig.Enabled,
+ StorageAccountUrl = backupContainer.GetSharedAccessUrl(),
+ Databases = new List<DatabaseBackupSetting>()
+ {
+ new DatabaseBackupSetting()
+ {
+ DatabaseType = DatabaseType.SqlAzure,
+ ConnectionStringName = targetSettings.DB_CATALOG,
+ ConnectionString = databaseConnectionString.Value.Value,
+ }
+ }
+ }, slot.Name);
+ }
+
//Restart slot.
OnProgress(AzureUtilsStage.Environment, "Restarting deployment slot...");
await slot.RestartAsync();
diff --git a/Software/Visual_Studio/Azure/Tango.AzureUtils/ExtensionMethods.cs b/Software/Visual_Studio/Azure/Tango.AzureUtils/ExtensionMethods.cs
index 66d3f167a..e521ce410 100644
--- a/Software/Visual_Studio/Azure/Tango.AzureUtils/ExtensionMethods.cs
+++ b/Software/Visual_Studio/Azure/Tango.AzureUtils/ExtensionMethods.cs
@@ -1,4 +1,5 @@
using Microsoft.Azure.Management.AppService.Fluent;
+using Microsoft.WindowsAzure.Storage.Blob;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -47,4 +48,16 @@ public static class ExtensionMethods
return dataSource;
}
+
+ public static String GetSharedAccessUrl(this CloudBlobContainer container)
+ {
+ String sas = container.GetSharedAccessSignature(new Microsoft.WindowsAzure.Storage.Blob.SharedAccessBlobPolicy()
+ {
+ Permissions = SharedAccessBlobPermissions.Read | SharedAccessBlobPermissions.Write | SharedAccessBlobPermissions.List | SharedAccessBlobPermissions.Delete | SharedAccessBlobPermissions.Add,
+ });
+
+ sas = new Uri(container.Uri + sas).ToString();
+
+ return sas;
+ }
}
diff --git a/Software/Visual_Studio/Azure/Tango.AzureUtils/Storage/StorageManager.cs b/Software/Visual_Studio/Azure/Tango.AzureUtils/Storage/StorageManager.cs
index 910f4b84f..8b3aeca2b 100644
--- a/Software/Visual_Studio/Azure/Tango.AzureUtils/Storage/StorageManager.cs
+++ b/Software/Visual_Studio/Azure/Tango.AzureUtils/Storage/StorageManager.cs
@@ -47,11 +47,12 @@ namespace Tango.AzureUtils.Storage
return targetBlob;
}
- public async Task CreateContainer(String name)
+ public async Task<CloudBlobContainer> CreateContainer(String name)
{
OnProgress(AzureUtilsStage.Storage, $"Creating storage container '{name}'...");
var container = _client.GetContainerReference(name);
await container.CreateIfNotExistsAsync();
+ return container;
}
public async Task UpgradePPCStorage(IWebAppBase sourceApp, IWebAppBase targetApp)