Skip to content

Commit ec548d3

Browse files
author
Samuel Anudeep
committed
Merge pull request #212 from MabOneSdk/dev1
FI from dev1 to release
2 parents 9a969bf + e814ee3 commit ec548d3

File tree

97 files changed

+7886
-917
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+7886
-917
lines changed

src/ResourceManager/RecoveryServices.Backup/AzureRM.RecoveryServices.Backup.psd1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ ScriptsToProcess = @()
5757
TypesToProcess = @()
5858

5959
# Format files (.ps1xml) to be loaded when importing this module
60-
FormatsToProcess = @()
60+
FormatsToProcess = @(
61+
'.\Microsoft.Azure.Commands.RecoveryServices.Backup.format.ps1xml'
62+
)
6163

6264
# Modules to import as nested modules of the module specified in ModuleToProcess
6365
NestedModules = @(

src/ResourceManager/RecoveryServices.Backup/CmdletParameterHelpMessages.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,19 @@ internal static class Job
5656
public const string JobFilter = "Job whose latest object has to be fetched.";
5757
public const string WaitJobOrListFilter = "Job or List of jobs until end of which the cmdlet should wait.";
5858
public const string WaitJobTimeoutFilter = "Maximum time to wait before aborting wait in seconds.";
59+
public const string StopJobJobIdFilter = "Id of Job to be stopped.";
60+
public const string StopJobJobFilter = "Job to be stopped.";
61+
}
62+
63+
internal static class Item
64+
{
65+
public const string AzureVMName = "Azure VM Name.";
66+
public const string AzureVMServiceName = "Cloud Service Name for Azure Classic Compute VM.";
67+
public const string AzureVMResourceGroupName = "Resource Group Name for Azure Compute VM .";
68+
public const string ProtectedItem = "Filter value for status of job.";
69+
public const string ProtectionStatus = "Protection status of Item";
70+
public const string Status = "Status of the data source";
71+
public const string Container = "Container where the item resides";
5972
}
6073
}
6174
}

src/ResourceManager/RecoveryServices.Backup/Cmdlets/Container/GetAzureRmRecoveryServicesContainer.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
1616
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ProviderModel;
1717
using Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers;
18-
using Microsoft.Azure.Management.RecoveryServices.Backup.Models;
1918
using System;
2019
using System.Collections.Generic;
2120
using System.Linq;
@@ -29,7 +28,7 @@ namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets
2928
/// Get list of containers
3029
/// </summary>
3130
[Cmdlet(VerbsCommon.Get, "AzureRmRecoveryServicesContainer"), OutputType(typeof(List<AzureRmRecoveryServicesContainerBase>), typeof(AzureRmRecoveryServicesContainerBase))]
32-
public class GetAzureRmRecoveryServicesContainer : RecoveryServicesBackupVaultCmdletBase
31+
public class GetAzureRmRecoveryServicesContainer : RecoveryServicesBackupCmdletBase
3332
{
3433
[Parameter(Mandatory = true, HelpMessage = ParamHelpMsg.Container.ContainerType)]
3534
[ValidateNotNullOrEmpty]
@@ -55,7 +54,6 @@ public override void ExecuteCmdlet()
5554

5655
PsBackupProviderManager providerManager = new PsBackupProviderManager(new Dictionary<System.Enum, object>()
5756
{
58-
{ContainerParams.Vault, Vault},
5957
{ContainerParams.ContainerType, ContainerType},
6058
{ContainerParams.Name, Name},
6159
{ContainerParams.ResourceGroupName, ResourceGroupName},
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System;
16+
using System.Linq;
17+
using System.Text;
18+
using System.Threading.Tasks;
19+
using System.Collections.Generic;
20+
using System.Management.Automation;
21+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
22+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ProviderModel;
23+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers;
24+
25+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets
26+
{
27+
/// <summary>
28+
/// Enable Azure Backup protection
29+
/// </summary>
30+
[Cmdlet(VerbsLifecycle.Enable, "AzureRmRecoveryServicesProtection", DefaultParameterSetName = ModifyProtectionParameterSet), OutputType(typeof(AzureRmRecoveryServicesJobBase))]
31+
public class EnableAzureRmRecoveryServicesProtection : RecoveryServicesBackupCmdletBase
32+
{
33+
internal const string AzureVMClassicComputeParameterSet = "AzureVMClassicCompute";
34+
internal const string AzureVMComputeParameterSet = "AzureVMCompute";
35+
internal const string ModifyProtectionParameterSet = "ModifyProtection";
36+
37+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = AzureVMClassicComputeParameterSet, HelpMessage = ParamHelpMsg.Item.AzureVMName)]
38+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = AzureVMComputeParameterSet, HelpMessage = ParamHelpMsg.Item.AzureVMName)]
39+
public string Name { get; set; }
40+
41+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = AzureVMClassicComputeParameterSet, HelpMessage = ParamHelpMsg.Item.AzureVMServiceName)]
42+
public string ServiceName { get; set; }
43+
44+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = AzureVMComputeParameterSet, HelpMessage = ParamHelpMsg.Item.AzureVMResourceGroupName)]
45+
public string ResourceGroupName { get; set; }
46+
47+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = AzureVMClassicComputeParameterSet, HelpMessage = ParamHelpMsg.Common.WorkloadType)]
48+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = AzureVMComputeParameterSet, HelpMessage = ParamHelpMsg.Common.WorkloadType)]
49+
public WorkloadType WorkLoadType { get; set; }
50+
51+
[Parameter(Mandatory = true, HelpMessage = ParamHelpMsg.Policy.ProtectionPolicy)]
52+
[ValidateNotNullOrEmpty]
53+
public AzureRmRecoveryServicesPolicyBase Policy { get; set; }
54+
55+
[Parameter(Mandatory = false, HelpMessage = ParamHelpMsg.Item.ProtectedItem, ValueFromPipeline = true)]
56+
[ValidateNotNullOrEmpty]
57+
public AzureRmRecoveryServicesItemBase Item { get; set; }
58+
59+
public override void ExecuteCmdlet()
60+
{
61+
ExecutionBlock(() =>
62+
{
63+
base.ExecuteCmdlet();
64+
65+
PsBackupProviderManager providerManager = new PsBackupProviderManager(new Dictionary<System.Enum, object>()
66+
{
67+
{ItemParams.AzureVMName, Name},
68+
{ItemParams.AzureVMCloudServiceName, ServiceName},
69+
{ItemParams.AzureVMResourceGroupName, ResourceGroupName},
70+
{ItemParams.WorkloadType, WorkLoadType},
71+
{ItemParams.Policy, Policy},
72+
{ItemParams.Item, Item},
73+
{ItemParams.ParameterSetName, this.ParameterSetName},
74+
}, HydraAdapter);
75+
76+
IPsBackupProvider psBackupProvider = (Item != null) ? providerManager.GetProviderInstance(WorkLoadType, Item.BackupManagementType)
77+
: providerManager.GetProviderInstance(WorkLoadType);
78+
79+
var jobResponse = psBackupProvider.EnableProtection();
80+
81+
// Track Response and display job details
82+
// -- TBD to move it to common helper and remove hard-coded vaules
83+
84+
var response = HydraAdapter.GetProtectedItemOperationStatusByURL(jobResponse.AzureAsyncOperation);
85+
while (response.OperationStatus.Status == "InProgress")
86+
{
87+
response = HydraAdapter.GetProtectedItemOperationStatusByURL(jobResponse.AzureAsyncOperation);
88+
System.Threading.Thread.Sleep(TimeSpan.FromSeconds(5));
89+
}
90+
91+
if(response.OperationStatus.Status == "Completed")
92+
{
93+
// TBD -- Hydra change to add jobId in OperationStatusExtendedInfo
94+
string jobId = ""; //response.OperationStatus.Properties.jobId;
95+
var job = HydraAdapter.GetJob(jobId);
96+
//WriteObject(ConversionHelpers.GetJobModel(job));
97+
}
98+
});
99+
}
100+
}
101+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
16+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ProviderModel;
17+
using System;
18+
using System.Collections.Generic;
19+
using System.Linq;
20+
using System.Management.Automation;
21+
using System.Text;
22+
using System.Threading.Tasks;
23+
24+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets
25+
{
26+
/// <summary>
27+
/// Get list of items
28+
/// </summary>
29+
[Cmdlet(VerbsCommon.Get, "AzureRmRecoveryServicesItem"), OutputType(typeof(List<AzureRmRecoveryServicesItemBase>), typeof(AzureRmRecoveryServicesItemBase))]
30+
public class GetAzureRmRecoveryServicesItem : RecoveryServicesBackupCmdletBase
31+
{
32+
[Parameter(Mandatory = true, HelpMessage = ParamHelpMsg.Item.Container)]
33+
[ValidateNotNullOrEmpty]
34+
public AzureRmRecoveryServicesContainerBase Container { get; set; }
35+
36+
[Parameter(Mandatory = false, HelpMessage = ParamHelpMsg.Item.AzureVMName)]
37+
[ValidateNotNullOrEmpty]
38+
public string Name { get; set; }
39+
40+
[Parameter(Mandatory = false, HelpMessage = ParamHelpMsg.Item.ProtectionStatus)]
41+
[ValidateNotNullOrEmpty]
42+
public ItemProtectionStatus ProtectionStatus { get; set; }
43+
44+
[Parameter(Mandatory = false, HelpMessage = ParamHelpMsg.Item.Status)]
45+
[ValidateNotNullOrEmpty]
46+
public ItemStatus Status { get; set; }
47+
48+
[Parameter(Mandatory = true, HelpMessage = ParamHelpMsg.Common.WorkloadType)]
49+
[ValidateNotNullOrEmpty]
50+
public WorkloadType WorkloadType { get; set; }
51+
52+
public override void ExecuteCmdlet()
53+
{
54+
ExecutionBlock(() =>
55+
{
56+
base.ExecuteCmdlet();
57+
58+
PsBackupProviderManager providerManager = new PsBackupProviderManager(new Dictionary<System.Enum, object>()
59+
{
60+
{ItemParams.Container, Container},
61+
{ItemParams.AzureVMName, Name},
62+
{ItemParams.ProtectionStatus, ProtectionStatus},
63+
{ItemParams.Status, Status},
64+
{ItemParams.WorkloadType, WorkloadType},
65+
}, HydraAdapter);
66+
67+
IPsBackupProvider psBackupProvider = providerManager.GetProviderInstance(WorkloadType,
68+
(Container as AzureRmRecoveryServicesBackupManagementContext).BackupManagementType);
69+
var itemModels = psBackupProvider.ListProtectedItems();
70+
71+
if (itemModels.Count == 1)
72+
{
73+
WriteObject(itemModels.First());
74+
}
75+
else
76+
{
77+
WriteObject(itemModels);
78+
}
79+
});
80+
}
81+
}
82+
}

src/ResourceManager/RecoveryServices.Backup/Cmdlets/Jobs/GetAzureRmRecoveryServicesJob.cs

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using System.Management.Automation;
1818
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
1919
using Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers;
20+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Properties;
2021

2122
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets
2223
{
@@ -44,20 +45,18 @@ public class GetAzureRmRecoveryServicesJob : RecoveryServicesBackupCmdletBase
4445

4546
[Parameter(Mandatory = false, HelpMessage = ParamHelpMsg.Job.BackupManagementTypeFilter)]
4647
[ValidateNotNullOrEmpty]
47-
public BackupManagementType BackupManagementType { get; set; }
48+
public BackupManagementType? BackupManagementType { get; set; }
4849

4950
[Parameter(Mandatory = false, HelpMessage = ParamHelpMsg.Job.OperationFilter)]
5051
[ValidateNotNullOrEmpty]
51-
public JobOperation Operation { get; set; }
52+
public JobOperation? Operation { get; set; }
5253

5354
[Parameter(Mandatory = false, HelpMessage = ParamHelpMsg.Job.StatusFilter)]
5455
[ValidateNotNullOrEmpty]
55-
public JobStatus Status { get; set; }
56+
public JobStatus? Status { get; set; }
5657

5758
public override void ExecuteCmdlet()
5859
{
59-
ARSVault Vault = null;
60-
6160
ExecutionBlock(() =>
6261
{
6362
base.ExecuteCmdlet();
@@ -68,22 +67,29 @@ public override void ExecuteCmdlet()
6867

6968
if (From.HasValue)
7069
{
70+
WriteDebug("Entered From filter: " + From.Value);
7171
rangeStart = From.Value;
7272
}
7373

7474
if (To.HasValue)
7575
{
76+
WriteDebug("Entered To filter; " + To.Value);
7677
rangeEnd = To.Value;
7778
}
7879

80+
if (rangeStart.Kind != DateTimeKind.Utc || rangeEnd.Kind != DateTimeKind.Utc)
81+
{
82+
throw new Exception(Resources.JobTimeFiltersShouldBeSpecifiedInUtc);
83+
}
84+
7985
// validate filters
80-
if (rangeEnd >= rangeStart)
86+
if (rangeEnd <= rangeStart)
8187
{
82-
throw new Exception(CmdletWarningAndErrorMessages.Job.ToShouldBeLessThanFrom);
88+
throw new Exception(Resources.JobToShouldBeGreaterThanFrom);
8389
}
8490
else if (rangeEnd.Subtract(rangeStart) > TimeSpan.FromDays(30))
8591
{
86-
throw new Exception(CmdletWarningAndErrorMessages.Job.AllowedDateTimeRangeExceeded);
92+
throw new Exception(Resources.JobAllowedDateTimeRangeExceeded);
8793
}
8894

8995
// validate JobId and Job objects
@@ -92,36 +98,45 @@ public override void ExecuteCmdlet()
9298
// if JobId and Job are provided together and they don't match then throw exception
9399
if (Job != null && JobId != Job.InstanceId)
94100
{
95-
throw new Exception(CmdletWarningAndErrorMessages.Job.JobIdAndJobMismatch);
101+
throw new Exception(Resources.JobJobIdAndJobMismatch);
96102
}
97103
}
98104
else if (Job != null)
99105
{
100106
JobId = Job.InstanceId;
101107
}
102108

103-
// TODO: Initialize Vault object from base cmdlet once support is added
104109
List<AzureRmRecoveryServicesJobBase> result = new List<AzureRmRecoveryServicesJobBase>();
105110
int resultCount = 0;
106-
var adapterResponse = HydraAdapter.GetJobs(Vault.ResouceGroupName, Vault.Name, JobId, Status.ToString(), Operation.ToString(), rangeStart, rangeEnd,
107-
BackupManagementType.ToString());
111+
var adapterResponse = HydraAdapter.GetJobs(JobId,
112+
Status.HasValue ? Status.ToString() : null,
113+
Operation.HasValue ? Operation.ToString() : null,
114+
rangeStart,
115+
rangeEnd,
116+
BackupManagementType.HasValue ? Helpers.JobConversions.GetJobTypeForService(BackupManagementType.Value) : null);
108117
JobConversions.AddHydraJobsToPSList(adapterResponse, result, ref resultCount);
109118

110119
while (!string.IsNullOrEmpty(adapterResponse.ItemList.NextLink))
111120
{
112121
if (resultCount >= JobConstants.MaximumJobsToFetch)
113122
{
114123
// trace a warning that there are more jobs and user has to refine filters.
115-
WriteWarning(CmdletWarningAndErrorMessages.Job.RefineFilters);
124+
WriteWarning(Resources.JobRefineFilters);
116125
break;
117126
}
118127

119128
string skipToken;
120129
HydraHelpers.GetSkipTokenFromNextLink(adapterResponse.ItemList.NextLink, out skipToken);
121130
if (skipToken != null)
122131
{
123-
adapterResponse = HydraAdapter.GetJobs(Vault.ResouceGroupName, Vault.Name, JobId, Status.ToString(), Operation.ToString(),
124-
rangeStart, rangeEnd, BackupManagementType.ToString(), null, skipToken);
132+
adapterResponse = HydraAdapter.GetJobs(JobId,
133+
Status.HasValue ? Status.ToString() : null,
134+
Operation.HasValue ? Operation.ToString() : null,
135+
rangeStart,
136+
rangeEnd,
137+
BackupManagementType.HasValue ? Helpers.JobConversions.GetJobTypeForService(BackupManagementType.Value) : null,
138+
null,
139+
skipToken);
125140
JobConversions.AddHydraJobsToPSList(adapterResponse, result, ref resultCount);
126141
}
127142
else

src/ResourceManager/RecoveryServices.Backup/Cmdlets/Jobs/GetAzureRmRecoveryServicesJobDetails.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ public class GetAzureRmRecoveryServicesJobDetails : RecoveryServicesBackupCmdlet
3434

3535
public override void ExecuteCmdlet()
3636
{
37-
ARSVault Vault = null;
38-
3937
ExecutionBlock(() =>
4038
{
4139
base.ExecuteCmdlet();
@@ -45,8 +43,7 @@ public override void ExecuteCmdlet()
4543
JobId = Job.InstanceId;
4644
}
4745

48-
// Initialize vault object from base cmdlet
49-
var adapterResponse = HydraAdapter.GetJob(Vault.ResouceGroupName, Vault.Name, JobId);
46+
var adapterResponse = HydraAdapter.GetJob(JobId);
5047
WriteObject(JobConversions.GetPSJob(adapterResponse));
5148
});
5249
}

0 commit comments

Comments
 (0)