Skip to content

Commit 7bfeaea

Browse files
committed
Enable Protection Validation and TBDs implementation Part 2
1 parent 58c02d4 commit 7bfeaea

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/ResourceManager/RecoveryServices.Backup/Cmdlets/Item/EnableAzureRmRecoveryServicesProtection.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,35 @@ public override void ExecuteCmdlet()
8383
// -- TBD to move it to common helper and remove hard-coded vaules
8484

8585
var response = HydraAdapter.GetProtectedItemOperationStatusByURL(jobResponse.AzureAsyncOperation);
86-
while (response.OperationStatus.Status == "InProgress")
86+
while (response.OperationStatus.Status == HydraModel.OperationStatusValues.InProgress)
8787
{
8888
response = HydraAdapter.GetProtectedItemOperationStatusByURL(jobResponse.AzureAsyncOperation);
8989
System.Threading.Thread.Sleep(TimeSpan.FromSeconds(5));
9090
}
9191

92-
if(response.OperationStatus.Status == "Completed")
92+
if (response.OperationStatus.Status == HydraModel.OperationStatusValues.Succeeded)
9393
{
9494
var jobStatusResponse = (HydraModel.OperationStatusJobExtendedInfo)response.OperationStatus.Properties;
9595
string jobId = jobStatusResponse.JobId;
9696
var job = HydraAdapter.GetJob(jobId);
9797
WriteObject(JobConversions.GetPSJob(job));
9898
}
99+
else if(response.OperationStatus.Status == HydraModel.OperationStatusValues.Failed)
100+
{
101+
var jobStatusResponse = (HydraModel.OperationStatusJobExtendedInfo)response.OperationStatus.Properties;
102+
if(jobStatusResponse != null || !string.IsNullOrEmpty(jobStatusResponse.JobId))
103+
{
104+
string jobId = jobStatusResponse.JobId;
105+
var job = HydraAdapter.GetJob(jobId);
106+
WriteObject(JobConversions.GetPSJob(job));
107+
}
108+
109+
var errorMessage(string.Format("Operation failed with error code and error message",
110+
response.OperationStatus.OperationStatusError,
111+
response.OperationStatus.OperationStatusError));
112+
113+
throw new Exception(errorMessage);
114+
}
99115
});
100116
}
101117
}

0 commit comments

Comments
 (0)