Skip to content

Commit 818d39c

Browse files
author
dragonfly91
committed
Merge branch 'dev1' of https://github.com/MabOneSdk/azure-powershell into dev1
2 parents 2a144d2 + 35142c3 commit 818d39c

File tree

6 files changed

+45
-59
lines changed

6 files changed

+45
-59
lines changed

src/ResourceManager/RecoveryServices.Backup/Cmdlets/ProtectionPolicy/SetAzureRmRecoveryServicesPolicy.cs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,29 @@ public override void ExecuteCmdlet()
6969
}, HydraAdapter);
7070

7171
IPsBackupProvider psBackupProvider = providerManager.GetProviderInstance(Policy.WorkloadType,
72-
Policy.BackupManagementType);
73-
// now convert hydraPolicy to PSObject
74-
WriteObject(psBackupProvider.ModifyPolicy());
72+
Policy.BackupManagementType);
73+
ProtectionPolicyResponse policyResponse = psBackupProvider.ModifyPolicy();
74+
75+
if(policyResponse.StatusCode == System.Net.HttpStatusCode.Accepted)
76+
{
77+
// Track OperationStatus URL for operation completion
78+
BackUpOperationStatusResponse operationResponse = WaitForOperationCompletionUsingStatusLink(
79+
policyResponse.AzureAsyncOperation,
80+
HydraAdapter.GetProtectionPolicyOperationStatusByURL);
81+
82+
if(operationResponse.OperationStatus.Status == OperationStatusValues.Failed.ToString())
83+
{
84+
// if operation failed, then trace warning/error
85+
}
86+
87+
// get list of jobIds and return jobResponses
88+
WriteObject(GetJobObject(((OperationStatusJobsExtendedInfo)operationResponse.OperationStatus.Properties).JobIds));
89+
}
90+
else
91+
{
92+
// Hydra will return OK if NO datasources are associated with this policy
93+
// just trace and return
94+
}
7595
});
7696
}
7797
}

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.HydraAdapter/BMSAPIs/PolicyAPIs.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ public ProtectionPolicyListResponse ListProtectionPolicy(
5757
BmsAdapter.CmdletCancellationToken).Result;
5858
}
5959

60-
// TBD for other operations
60+
public BackUpOperationStatusResponse GetProtectionPolicyOperationStatusByURL(string url)
61+
{
62+
return BmsAdapter.Client.ProtectionPolicy.GetOperationStatusByURLAsync(
63+
url,
64+
BmsAdapter.GetCustomRequestHeaders(),
65+
BmsAdapter.CmdletCancellationToken).Result;
66+
}
6167
}
6268
}

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Providers/IPsBackupProvider.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,11 @@ public interface IPsBackupProvider
4242

4343
ProtectionPolicyResponse CreatePolicy();
4444

45-
List<AzureRmRecoveryServicesJobBase> ModifyPolicy();
46-
47-
ProtectionPolicyResponse GetPolicy();
45+
ProtectionPolicyResponse ModifyPolicy();
4846

4947
AzureRmRecoveryServicesSchedulePolicyBase GetDefaultSchedulePolicyObject();
5048

51-
AzureRmRecoveryServicesRetentionPolicyBase GetDefaultRetentionPolicyObject();
52-
void DeletePolicy();
49+
AzureRmRecoveryServicesRetentionPolicyBase GetDefaultRetentionPolicyObject();
5350

5451
List<AzureRmRecoveryServicesContainerBase> ListProtectionContainers();
5552

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Providers/Providers/AzureSqlPsBackupProvider.cs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,26 +69,16 @@ public Management.RecoveryServices.Backup.Models.ProtectionPolicyResponse Create
6969
throw new NotImplementedException();
7070
}
7171

72-
public List<AzureRmRecoveryServicesJobBase> ModifyPolicy()
72+
public Management.RecoveryServices.Backup.Models.ProtectionPolicyResponse ModifyPolicy()
7373
{
7474
throw new NotImplementedException();
7575
}
7676

7777
public List<Models.AzureRmRecoveryServicesContainerBase> ListProtectionContainers()
7878
{
7979
throw new NotImplementedException();
80-
}
81-
82-
public Management.RecoveryServices.Backup.Models.ProtectionPolicyResponse GetPolicy()
83-
{
84-
throw new NotImplementedException();
85-
}
86-
87-
public void DeletePolicy()
88-
{
89-
throw new NotImplementedException();
90-
}
91-
80+
}
81+
9282
public AzureRmRecoveryServicesSchedulePolicyBase GetDefaultSchedulePolicyObject()
9383
{
9484
throw new NotImplementedException();

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Providers/Providers/IaasVmPsBackupProvider.cs

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ public ProtectionPolicyResponse CreatePolicy()
238238
hydraRequest);
239239
}
240240

241-
public List<AzureRmRecoveryServicesJobBase> ModifyPolicy()
241+
public ProtectionPolicyResponse ModifyPolicy()
242242
{
243243
AzureRmRecoveryServicesRetentionPolicyBase retentionPolicy = (AzureRmRecoveryServicesRetentionPolicyBase)
244244
ProviderData.ProviderParameters[PolicyParams.RetentionPolicy];
@@ -293,24 +293,8 @@ public List<AzureRmRecoveryServicesJobBase> ModifyPolicy()
293293
}
294294
};
295295

296-
ProtectionPolicyResponse response = HydraAdapter.CreateOrUpdateProtectionPolicy(
297-
policy.Name,
298-
hydraRequest);
299-
300-
List<AzureRmRecoveryServicesJobBase> jobsList = new List<AzureRmRecoveryServicesJobBase>();
301-
302-
if (/*response.StatusCode == System.Net.HttpStatusCode.Accepted*/ true)
303-
{
304-
// poll for AsyncHeader and get the jobsList
305-
// TBD
306-
}
307-
else
308-
{
309-
// no datasources attached to policy
310-
// hence no jobs and no action.
311-
}
312-
313-
return jobsList;
296+
return HydraAdapter.CreateOrUpdateProtectionPolicy(policy.Name,
297+
hydraRequest);
314298
}
315299

316300
public List<AzureRmRecoveryServicesContainerBase> ListProtectionContainers()
@@ -406,18 +390,7 @@ public List<AzureRmRecoveryServicesItemBase> ListProtectedItems()
406390
}
407391

408392
return itemModels;
409-
}
410-
411-
public ProtectionPolicyResponse GetPolicy()
412-
{
413-
throw new NotImplementedException();
414-
}
415-
416-
public void DeletePolicy()
417-
{
418-
throw new NotImplementedException();
419-
}
420-
393+
}
421394

422395
public AzureRmRecoveryServicesSchedulePolicyBase GetDefaultSchedulePolicyObject()
423396
{

src/ResourceManager/RecoveryServices.Backup/RecoveryServicesBackupCmdletBase.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets
3838
/// </summary>
3939
public abstract class RecoveryServicesBackupCmdletBase : AzureRMCmdlet
4040
{
41-
public delegate BackUpOperationStatusResponse GetOpResponse(string url);
42-
4341
// in seconds
4442
private int _defaultSleepForOperationTracking = 15;
4543

@@ -134,7 +132,7 @@ public AzureRmRecoveryServicesJobBase GetJobObject(string jobId)
134132
return JobConversions.GetPSJob(HydraAdapter.GetJob(jobId));
135133
}
136134

137-
public List<AzureRmRecoveryServicesJobBase> GetJobObject(List<string> jobIds)
135+
public List<AzureRmRecoveryServicesJobBase> GetJobObject(IList<string> jobIds)
138136
{
139137
List<AzureRmRecoveryServicesJobBase> result = new List<AzureRmRecoveryServicesJobBase>();
140138
foreach (string jobId in jobIds)
@@ -144,17 +142,19 @@ public List<AzureRmRecoveryServicesJobBase> GetJobObject(List<string> jobIds)
144142
return result;
145143
}
146144

147-
public BackUpOperationStatusResponse WaitForOperation(string url, GetOpResponse hydraFunc)
145+
public BackUpOperationStatusResponse WaitForOperationCompletionUsingStatusLink(
146+
string statusUrlLink,
147+
Func<string, BackUpOperationStatusResponse> hydraFunc)
148148
{
149149
// using this directly because it doesn't matter which function we use.
150150
// return type is same and currently we are using it in only two places.
151151
// protected item and policy.
152-
BackUpOperationStatusResponse response = hydraFunc(url);
152+
BackUpOperationStatusResponse response = hydraFunc(statusUrlLink);
153153

154154
while (response.OperationStatus.Status == OperationStatusValues.InProgress.ToString())
155155
{
156156
Thread.Sleep(_defaultSleepForOperationTracking * 1000);
157-
response = HydraAdapter.GetProtectedItemOperationStatusByURL(url);
157+
response = hydraFunc(statusUrlLink);
158158
}
159159

160160
return response;

0 commit comments

Comments
 (0)