From c437ebe2f3a377f4a6c7c251320c54c32b8c1581 Mon Sep 17 00:00:00 2001 From: Siddharth Singh Date: Thu, 29 Nov 2018 13:51:20 +0530 Subject: [PATCH] commit --- .../ServiceClientHelpers.cs | 5 +- .../CommonModels/Enums.cs | 12 +- .../CommonModels/Utils.cs | 25 +++- ...s.RecoveryServices.Backup.Providers.csproj | 93 ++++++++++++ .../AzureWorkloadPsBackupProvider.cs | 138 ++++++++++++++++++ .../PsBackupProviderManager.cs | 15 +- 6 files changed, 279 insertions(+), 9 deletions(-) create mode 100644 src/RecoveryServices/RecoveryServices.Backup.Providers/Commands.RecoveryServices.Backup.Providers.csproj create mode 100644 src/RecoveryServices/RecoveryServices.Backup.Providers/Providers/AzureWorkloadPsBackupProvider.cs diff --git a/src/RecoveryServices/RecoveryServices.Backup.Helpers/ServiceClientHelpers.cs b/src/RecoveryServices/RecoveryServices.Backup.Helpers/ServiceClientHelpers.cs index 07acea7e5bbf..b6ab24a37197 100644 --- a/src/RecoveryServices/RecoveryServices.Backup.Helpers/ServiceClientHelpers.cs +++ b/src/RecoveryServices/RecoveryServices.Backup.Helpers/ServiceClientHelpers.cs @@ -76,6 +76,9 @@ public static string GetServiceClientProviderType(CmdletModel.WorkloadType workl case CmdletModel.WorkloadType.AzureFiles: providerType = ServiceClientModel.BackupManagementType.AzureStorage.ToString(); break; + case CmdletModel.WorkloadType.MSSQL: + providerType = ServiceClientModel.BackupManagementType.AzureWorkload.ToString(); + break; default: break; } @@ -353,4 +356,4 @@ public static string GetServiceClientWorkloadType(CmdletModel.WorkloadType workl return serviceClientWorkloadType; } } -} +} \ No newline at end of file diff --git a/src/RecoveryServices/RecoveryServices.Backup.Models/CommonModels/Enums.cs b/src/RecoveryServices/RecoveryServices.Backup.Models/CommonModels/Enums.cs index 1ac388827f41..1b3551a3a303 100644 --- a/src/RecoveryServices/RecoveryServices.Backup.Models/CommonModels/Enums.cs +++ b/src/RecoveryServices/RecoveryServices.Backup.Models/CommonModels/Enums.cs @@ -37,7 +37,12 @@ public enum ContainerType /// /// Represents any Azure Storage containers. /// - AzureStorage + AzureStorage, + + /// + /// Represents any Azure Workload containers. + /// + AzureWorkload } /// @@ -70,6 +75,7 @@ public enum BackupManagementType /// Represents Azure File Storage. https://docs.microsoft.com/en-in/azure/storage/files/storage-files-introduction /// AzureStorage, + AzureWorkload, } /// @@ -103,6 +109,7 @@ public enum WorkloadType /// Represents Azure File https://docs.microsoft.com/en-in/azure/storage/files/storage-files-introduction /// AzureFiles, + MSSQL, } /// @@ -134,6 +141,7 @@ public enum PsBackupProviderTypes /// Represents the Azure File provider for powershell cmdlets. /// AzureFiles, + AzureWorkload, } /// @@ -334,4 +342,4 @@ public enum SourceFileType File, Directory } -} +} \ No newline at end of file diff --git a/src/RecoveryServices/RecoveryServices.Backup.Models/CommonModels/Utils.cs b/src/RecoveryServices/RecoveryServices.Backup.Models/CommonModels/Utils.cs index 526188855a4f..019db748a1a5 100644 --- a/src/RecoveryServices/RecoveryServices.Backup.Models/CommonModels/Utils.cs +++ b/src/RecoveryServices/RecoveryServices.Backup.Models/CommonModels/Utils.cs @@ -218,6 +218,8 @@ public static BackupManagementType GetPsBackupManagementType(string backupManage return BackupManagementType.AzureSQL; case ServiceClientModel.BackupManagementType.AzureStorage: return BackupManagementType.AzureStorage; + case ServiceClientModel.BackupManagementType.AzureWorkload: + return BackupManagementType.AzureWorkload; default: throw new Exception("Unsupported BackupManagmentType: " + backupManagementType); } @@ -248,6 +250,11 @@ public static ContainerType GetPsContainerType(string containerType) { return ContainerType.AzureStorage; } + else if (containerType == + ServiceClientModel.BackupManagementType.AzureWorkload) + { + return ContainerType.AzureWorkload; + } else { throw new Exception("Unsupported ContainerType: " + containerType); @@ -265,14 +272,18 @@ public static WorkloadType GetPsWorkloadType(string workloadType) { return WorkloadType.AzureVM; } - if (workloadType == ServiceClientModel.WorkloadType.AzureSqlDb.ToString()) + else if (workloadType == ServiceClientModel.WorkloadType.AzureSqlDb.ToString()) { return WorkloadType.AzureSQLDatabase; } - if (workloadType == ServiceClientModel.WorkloadType.AzureFileShare) + else if (workloadType == ServiceClientModel.WorkloadType.AzureFileShare) { return WorkloadType.AzureFiles; } + else if (workloadType == ServiceClientModel.WorkloadType.SQLDataBase) + { + return WorkloadType.MSSQL; + } else { throw new Exception("Unsupported WorkloadType: " + workloadType); @@ -290,14 +301,18 @@ public static string GetServiceClientWorkloadType(string workloadType) { return ServiceClientModel.WorkloadType.VM; } - if (workloadType == WorkloadType.AzureSQLDatabase.ToString()) + else if (workloadType == WorkloadType.AzureSQLDatabase.ToString()) { return ServiceClientModel.WorkloadType.AzureSqlDb; } - if (workloadType == WorkloadType.AzureFiles.ToString()) + else if (workloadType == WorkloadType.AzureFiles.ToString()) { return ServiceClientModel.WorkloadType.AzureFileShare; } + else if (workloadType == WorkloadType.MSSQL.ToString()) + { + return ServiceClientModel.WorkloadType.SQLDataBase; + } else { throw new Exception("Unsupported WorkloadType: " + workloadType); @@ -343,4 +358,4 @@ public static string GetWorkloadTypeFromArmType(string armType) throw new Exception("Unsupported ArmType: " + armType); } } -} +} \ No newline at end of file diff --git a/src/RecoveryServices/RecoveryServices.Backup.Providers/Commands.RecoveryServices.Backup.Providers.csproj b/src/RecoveryServices/RecoveryServices.Backup.Providers/Commands.RecoveryServices.Backup.Providers.csproj new file mode 100644 index 000000000000..a7c0bb54ea7e --- /dev/null +++ b/src/RecoveryServices/RecoveryServices.Backup.Providers/Commands.RecoveryServices.Backup.Providers.csproj @@ -0,0 +1,93 @@ + + + + + + Debug + AnyCPU + {02234E90-BCDE-4B20-B1F5-01B1005821DB} + Library + Properties + Microsoft.Azure.Commands.RecoveryServices.Backup.Providers + Microsoft.Azure.Commands.RecoveryServices.Backup.Providers + v4.5.2 + 512 + ..\ + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + prompt + 4 + TRACE;SIGN + true + MSSharedLibKey.snk + true + false + + + + False + ..\..\..\packages\Microsoft.Azure.Management.RecoveryServices.Backup.3.0.1-preview\lib\net452\Microsoft.Azure.Management.RecoveryServices.Backup.dll + + + + + + + + + + + + + + + + + + + + + + + + + + + {142d7b0b-388a-4ceb-a228-7f6d423c5c2e} + Commands.Profile + + + {0e1d3f36-e6c8-4764-8c7d-6f9ee537490c} + Commands.RecoveryServices.Backup.Helpers + + + {5e675749-6139-464a-904c-59c0ffdfec82} + Commands.RecoveryServices.Backup.Logger + + + {30b92759-50b3-494e-b9f0-ec9a2ce9d57b} + Commands.RecoveryServices.Backup.Models + + + {b758fec1-35c1-4f93-a954-66dd33f6e0ec} + Commands.RecoveryServices.Backup.ServiceClientAdapter + + + + + + + + \ No newline at end of file diff --git a/src/RecoveryServices/RecoveryServices.Backup.Providers/Providers/AzureWorkloadPsBackupProvider.cs b/src/RecoveryServices/RecoveryServices.Backup.Providers/Providers/AzureWorkloadPsBackupProvider.cs new file mode 100644 index 000000000000..8a2dbc27f142 --- /dev/null +++ b/src/RecoveryServices/RecoveryServices.Backup.Providers/Providers/AzureWorkloadPsBackupProvider.cs @@ -0,0 +1,138 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models; +using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ServiceClientAdapterNS; +using Microsoft.Azure.Management.RecoveryServices.Backup.Models; +using System; +using System.Collections.Generic; +using CmdletModel = Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models; +using RestAzureNS = Microsoft.Rest.Azure; +using Microsoft.Azure.Commands.RecoveryServices.Backup.Properties; +using ServiceClientModel = Microsoft.Azure.Management.RecoveryServices.Backup.Models; +using Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers; + +namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ProviderModel +{ + /// + /// This class implements methods for azure DB Workload backup provider + /// + public class AzureWorkloadPsBackupProvider : IPsBackupProvider + { + private const int defaultOperationStatusRetryTimeInMilliSec = 5 * 1000; // 5 sec + private const string separator = ";"; + private const CmdletModel.RetentionDurationType defaultFileRetentionType = + CmdletModel.RetentionDurationType.Days; + private const int defaultFileRetentionCount = 30; + Dictionary ProviderData { get; set; } + ServiceClientAdapter ServiceClientAdapter { get; set; } + AzureWorkloadProviderHelper AzureWorkloadProviderHelper { get; set; } + /// + /// Initializes the provider with the data recieved from the cmdlet layer + /// + /// Data from the cmdlet layer intended for the provider + /// Service client adapter for communicating with the backend service + public void Initialize(Dictionary providerData, ServiceClientAdapter serviceClientAdapter) + { + ProviderData = providerData; + ServiceClientAdapter = serviceClientAdapter; + AzureWorkloadProviderHelper = new AzureWorkloadProviderHelper(ServiceClientAdapter); + } + + public ResourceBackupStatus CheckBackupStatus() + { + throw new NotImplementedException(); + } + + public ProtectionPolicyResource CreatePolicy() + { + throw new NotImplementedException(); + } + + public RestAzureNS.AzureOperationResponse DisableProtection() + { + throw new NotImplementedException(); + } + + public RestAzureNS.AzureOperationResponse EnableProtection() + { + throw new NotImplementedException(); + } + + public RetentionPolicyBase GetDefaultRetentionPolicyObject() + { + throw new NotImplementedException(); + } + + public SchedulePolicyBase GetDefaultSchedulePolicyObject() + { + throw new NotImplementedException(); + } + + public ProtectedItemResource GetProtectedItem() + { + throw new NotImplementedException(); + } + + public RecoveryPointBase GetRecoveryPointDetails() + { + throw new NotImplementedException(); + } + + public List ListBackupManagementServers() + { + throw new NotImplementedException(); + } + + public List ListProtectedItems() + { + throw new NotImplementedException(); + } + + public List ListProtectionContainers() + { + throw new NotImplementedException(); + } + + public List ListRecoveryPoints() + { + throw new NotImplementedException(); + } + + public RestAzureNS.AzureOperationResponse ModifyPolicy() + { + throw new NotImplementedException(); + } + + public RPMountScriptDetails ProvisionItemLevelRecoveryAccess() + { + throw new NotImplementedException(); + } + + public void RevokeItemLevelRecoveryAccess() + { + throw new NotImplementedException(); + } + + public RestAzureNS.AzureOperationResponse TriggerBackup() + { + throw new NotImplementedException(); + } + + public RestAzureNS.AzureOperationResponse TriggerRestore() + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/src/RecoveryServices/RecoveryServices.Backup.Providers/PsBackupProviderManager.cs b/src/RecoveryServices/RecoveryServices.Backup.Providers/PsBackupProviderManager.cs index 3495a997a853..d241d3e99a05 100644 --- a/src/RecoveryServices/RecoveryServices.Backup.Providers/PsBackupProviderManager.cs +++ b/src/RecoveryServices/RecoveryServices.Backup.Providers/PsBackupProviderManager.cs @@ -215,6 +215,16 @@ public IPsBackupProvider GetProviderInstance( } psProviderType = PsBackupProviderTypes.AzureFiles; break; + case WorkloadType.MSSQL: + if (backupManagementType.HasValue && + backupManagementType != BackupManagementType.AzureWorkload) + { + throw new ArgumentException( + string.Format(Resources.BackupManagementTypeNotExpectedForWorkloadType, + workloadType.ToString())); + } + psProviderType = PsBackupProviderTypes.AzureWorkload; + break; default: throw new ArgumentException( string.Format(Resources.UnsupportedWorkloadTypeException, @@ -248,6 +258,9 @@ public IPsBackupProvider GetProviderInstance(PsBackupProviderTypes providerType) case PsBackupProviderTypes.AzureFiles: psBackupProvider = new AzureFilesPsBackupProvider(); break; + case PsBackupProviderTypes.AzureWorkload: + psBackupProvider = new AzureWorkloadPsBackupProvider(); + break; default: break; } @@ -277,4 +290,4 @@ public IPsBackupProvider GetProviderInstance(string resourceType) } } } -} +} \ No newline at end of file