Skip to content

Commit d9b86fc

Browse files
committed
Shifting to central exception handling for SiteRecovery cmdlets
After this instead of overriding ExecuteCmdlet, ExecuteSiteRecoveryCmdlet needs to be overriden. Exceptions will then be automatically taken care of.
1 parent 382d7df commit d9b86fc

File tree

40 files changed

+611
-755
lines changed

40 files changed

+611
-755
lines changed

src/ResourceManager/SiteRecovery/Commands.SiteRecovery/Common/SiteRecoveryCmdletBase.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,22 @@ internal PSRecoveryServicesClient RecoveryServicesClient
6262
}
6363

6464
/// <summary>
65-
/// Overrides base implementation of Process record.
65+
/// Virtual method to be implemented by Site Recovery cmdlets.
6666
/// </summary>
67-
protected override void ProcessRecord()
67+
public virtual void ExecuteSiteRecoveryCmdlet()
68+
{
69+
// Do Nothing
70+
}
71+
72+
/// <summary>
73+
///
74+
/// </summary>
75+
public override void ExecuteCmdlet()
6876
{
6977
try
7078
{
71-
base.ProcessRecord();
79+
base.ExecuteCmdlet();
80+
ExecuteSiteRecoveryCmdlet();
7281
}
7382
catch (Exception ex)
7483
{

src/ResourceManager/SiteRecovery/Commands.SiteRecovery/Job/GetAzureSiteRecoveryJob.cs

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -86,30 +86,24 @@ public class GetAzureSiteRecoveryJob : SiteRecoveryCmdletBase
8686
/// <summary>
8787
/// ProcessRecord of the command.
8888
/// </summary>
89-
public override void ExecuteCmdlet()
89+
public override void ExecuteSiteRecoveryCmdlet()
9090
{
91-
try
91+
base.ExecuteSiteRecoveryCmdlet();
92+
switch (this.ParameterSetName)
9293
{
93-
switch (this.ParameterSetName)
94-
{
95-
case ASRParameterSets.ByObject:
96-
this.Name = this.Job.Name;
97-
this.GetByName();
98-
break;
99-
100-
case ASRParameterSets.ByName:
101-
this.GetByName();
102-
break;
103-
104-
case ASRParameterSets.ByParam:
105-
default:
106-
this.GetByParam();
107-
break;
108-
}
109-
}
110-
catch (Exception exception)
111-
{
112-
this.HandleException(exception);
94+
case ASRParameterSets.ByObject:
95+
this.Name = this.Job.Name;
96+
this.GetByName();
97+
break;
98+
99+
case ASRParameterSets.ByName:
100+
this.GetByName();
101+
break;
102+
103+
case ASRParameterSets.ByParam:
104+
default:
105+
this.GetByParam();
106+
break;
113107
}
114108
}
115109

src/ResourceManager/SiteRecovery/Commands.SiteRecovery/Job/RestartAzureSiteRecoveryJob.cs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,25 +44,20 @@ public class RestartAzureSiteRecoveryJob : SiteRecoveryCmdletBase
4444
/// <summary>
4545
/// ProcessRecord of the command.
4646
/// </summary>
47-
public override void ExecuteCmdlet()
47+
public override void ExecuteSiteRecoveryCmdlet()
4848
{
49-
try
50-
{
51-
switch (this.ParameterSetName)
52-
{
53-
case ASRParameterSets.ByObject:
54-
this.Name = this.Job.Name;
55-
this.RestartByName();
56-
break;
49+
base.ExecuteSiteRecoveryCmdlet();
5750

58-
case ASRParameterSets.ByName:
59-
this.RestartByName();
60-
break;
61-
}
62-
}
63-
catch (Exception exception)
51+
switch (this.ParameterSetName)
6452
{
65-
this.HandleException(exception);
53+
case ASRParameterSets.ByObject:
54+
this.Name = this.Job.Name;
55+
this.RestartByName();
56+
break;
57+
58+
case ASRParameterSets.ByName:
59+
this.RestartByName();
60+
break;
6661
}
6762
}
6863

src/ResourceManager/SiteRecovery/Commands.SiteRecovery/Job/ResumeAzureSiteRecoveryJob.cs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,25 +51,20 @@ public class ResumeAzureSiteRecoveryJob : SiteRecoveryCmdletBase
5151
/// <summary>
5252
/// ProcessRecord of the command.
5353
/// </summary>
54-
public override void ExecuteCmdlet()
54+
public override void ExecuteSiteRecoveryCmdlet()
5555
{
56-
try
57-
{
58-
switch (this.ParameterSetName)
59-
{
60-
case ASRParameterSets.ByObject:
61-
this.Name = this.Job.Name;
62-
this.ResumesByName();
63-
break;
56+
base.ExecuteSiteRecoveryCmdlet();
6457

65-
case ASRParameterSets.ByName:
66-
this.ResumesByName();
67-
break;
68-
}
69-
}
70-
catch (Exception exception)
58+
switch (this.ParameterSetName)
7159
{
72-
this.HandleException(exception);
60+
case ASRParameterSets.ByObject:
61+
this.Name = this.Job.Name;
62+
this.ResumesByName();
63+
break;
64+
65+
case ASRParameterSets.ByName:
66+
this.ResumesByName();
67+
break;
7368
}
7469
}
7570

src/ResourceManager/SiteRecovery/Commands.SiteRecovery/Job/StopAzureSiteRecoveryJob.cs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,25 +44,20 @@ public class StopAzureSiteRecoveryJob : SiteRecoveryCmdletBase
4444
/// <summary>
4545
/// ProcessRecord of the command.
4646
/// </summary>
47-
public override void ExecuteCmdlet()
47+
public override void ExecuteSiteRecoveryCmdlet()
4848
{
49-
try
50-
{
51-
switch (this.ParameterSetName)
52-
{
53-
case ASRParameterSets.ByObject:
54-
this.Name = this.Job.Name;
55-
this.StopByName();
56-
break;
49+
base.ExecuteSiteRecoveryCmdlet();
5750

58-
case ASRParameterSets.ByName:
59-
this.StopByName();
60-
break;
61-
}
62-
}
63-
catch (Exception exception)
51+
switch (this.ParameterSetName)
6452
{
65-
this.HandleException(exception);
53+
case ASRParameterSets.ByObject:
54+
this.Name = this.Job.Name;
55+
this.StopByName();
56+
break;
57+
58+
case ASRParameterSets.ByName:
59+
this.StopByName();
60+
break;
6661
}
6762
}
6863

src/ResourceManager/SiteRecovery/Commands.SiteRecovery/Network/GetAzureRMSiteRecoveryNetwork.cs

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -55,29 +55,24 @@ public class GetAzureRMSiteRecoveryNetwork : SiteRecoveryCmdletBase
5555
/// <summary>
5656
/// ProcessRecord of the command.
5757
/// </summary>
58-
public override void ExecuteCmdlet()
58+
public override void ExecuteSiteRecoveryCmdlet()
5959
{
60-
try
61-
{
62-
switch (this.ParameterSetName)
63-
{
64-
case ASRParameterSets.ByServerObject:
65-
this.GetByServer();
66-
break;
67-
case ASRParameterSets.ByName:
68-
this.GetByName();
69-
break;
70-
case ASRParameterSets.ByFriendlyName:
71-
this.GetByFriendlyName();
72-
break;
73-
case ASRParameterSets.Default:
74-
this.GetAllNetworks();
75-
break;
76-
}
77-
}
78-
catch (Exception exception)
60+
base.ExecuteSiteRecoveryCmdlet();
61+
62+
switch (this.ParameterSetName)
7963
{
80-
this.HandleException(exception);
64+
case ASRParameterSets.ByServerObject:
65+
this.GetByServer();
66+
break;
67+
case ASRParameterSets.ByName:
68+
this.GetByName();
69+
break;
70+
case ASRParameterSets.ByFriendlyName:
71+
this.GetByFriendlyName();
72+
break;
73+
case ASRParameterSets.Default:
74+
this.GetAllNetworks();
75+
break;
8176
}
8277
}
8378

src/ResourceManager/SiteRecovery/Commands.SiteRecovery/Network/GetAzureRMSiteRecoveryNetworkMapping.cs

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -61,30 +61,25 @@ public class GetAzureRMSiteRecoveryNetworkMapping : SiteRecoveryCmdletBase
6161
/// <summary>
6262
/// ProcessRecord of the command.
6363
/// </summary>
64-
public override void ExecuteCmdlet()
64+
public override void ExecuteSiteRecoveryCmdlet()
6565
{
66-
try
67-
{
68-
networkMappingsListResponse =
66+
base.ExecuteSiteRecoveryCmdlet();
67+
68+
networkMappingsListResponse =
6969
RecoveryServicesClient
7070
.GetAzureSiteRecoveryNetworkMappings();
7171

72-
switch (this.ParameterSetName)
73-
{
74-
case ASRParameterSets.EnterpriseToEnterprise:
75-
this.FilterE2EMappings();
76-
break;
77-
case ASRParameterSets.EnterpriseToAzure:
78-
this.FilterE2AMappings();
79-
break;
80-
case ASRParameterSets.Default:
81-
WriteNetworkMappings(networkMappingsListResponse.NetworkMappingsList);
82-
break;
83-
}
84-
}
85-
catch (Exception exception)
72+
switch (this.ParameterSetName)
8673
{
87-
this.HandleException(exception);
74+
case ASRParameterSets.EnterpriseToEnterprise:
75+
this.FilterE2EMappings();
76+
break;
77+
case ASRParameterSets.EnterpriseToAzure:
78+
this.FilterE2AMappings();
79+
break;
80+
case ASRParameterSets.Default:
81+
WriteNetworkMappings(networkMappingsListResponse.NetworkMappingsList);
82+
break;
8883
}
8984
}
9085

src/ResourceManager/SiteRecovery/Commands.SiteRecovery/Network/NewAzureRMSiteRecoveryNetworkMapping.cs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,23 +55,18 @@ public class NewAzureRMSiteRecoveryNetworkMapping : SiteRecoveryCmdletBase
5555
/// <summary>
5656
/// ProcessRecord of the command.
5757
/// </summary>
58-
public override void ExecuteCmdlet()
58+
public override void ExecuteSiteRecoveryCmdlet()
5959
{
60-
try
61-
{
62-
switch (this.ParameterSetName)
63-
{
64-
case ASRParameterSets.EnterpriseToEnterprise:
65-
this.EnterpriseToEnterpriseNetworkMapping();
66-
break;
67-
case ASRParameterSets.EnterpriseToAzure:
68-
this.EnterpriseToAzureNetworkMapping();
69-
break;
70-
}
71-
}
72-
catch (Exception exception)
60+
base.ExecuteSiteRecoveryCmdlet();
61+
62+
switch (this.ParameterSetName)
7363
{
74-
this.HandleException(exception);
64+
case ASRParameterSets.EnterpriseToEnterprise:
65+
this.EnterpriseToEnterpriseNetworkMapping();
66+
break;
67+
case ASRParameterSets.EnterpriseToAzure:
68+
this.EnterpriseToAzureNetworkMapping();
69+
break;
7570
}
7671
}
7772

src/ResourceManager/SiteRecovery/Commands.SiteRecovery/Network/RemoveAzureRMSiteRecoveryNetworkMapping.cs

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,27 +39,22 @@ public class RemoveAzureRMSiteRecoveryNetworkMapping : SiteRecoveryCmdletBase
3939
/// <summary>
4040
/// ProcessRecord of the command.
4141
/// </summary>
42-
public override void ExecuteCmdlet()
42+
public override void ExecuteSiteRecoveryCmdlet()
4343
{
44-
try
45-
{
46-
LongRunningOperationResponse response =
47-
RecoveryServicesClient
48-
.RemoveAzureSiteRecoveryNetworkMapping(
49-
Utilities.GetValueFromArmId(this.NetworkMapping.ID, ARMResourceTypeConstants.ReplicationFabrics),
50-
Utilities.GetValueFromArmId(this.NetworkMapping.ID, "replicationNetworks"),
51-
Utilities.GetValueFromArmId(this.NetworkMapping.ID, "replicationNetworkMappings"));
44+
base.ExecuteSiteRecoveryCmdlet();
5245

53-
JobResponse jobResponse =
54-
RecoveryServicesClient
55-
.GetAzureSiteRecoveryJobDetails(PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location));
46+
LongRunningOperationResponse response =
47+
RecoveryServicesClient
48+
.RemoveAzureSiteRecoveryNetworkMapping(
49+
Utilities.GetValueFromArmId(this.NetworkMapping.ID, ARMResourceTypeConstants.ReplicationFabrics),
50+
Utilities.GetValueFromArmId(this.NetworkMapping.ID, "replicationNetworks"),
51+
Utilities.GetValueFromArmId(this.NetworkMapping.ID, "replicationNetworkMappings"));
5652

57-
WriteObject(new ASRJob(jobResponse.Job));
58-
}
59-
catch (Exception exception)
60-
{
61-
this.HandleException(exception);
62-
}
53+
JobResponse jobResponse =
54+
RecoveryServicesClient
55+
.GetAzureSiteRecoveryJobDetails(PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location));
56+
57+
WriteObject(new ASRJob(jobResponse.Job));
6358
}
6459
}
6560
}

src/ResourceManager/SiteRecovery/Commands.SiteRecovery/Policy/GetAzureSiteRecoveryPolicy.cs

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,26 +47,21 @@ public class GetAzureSiteRecoveryPolicy : SiteRecoveryCmdletBase
4747
/// <summary>
4848
/// ProcessRecord of the command.
4949
/// </summary>
50-
public override void ExecuteCmdlet()
50+
public override void ExecuteSiteRecoveryCmdlet()
5151
{
52-
try
53-
{
54-
switch (this.ParameterSetName)
55-
{
56-
case ASRParameterSets.ByFriendlyName:
57-
this.GetByFriendlyName();
58-
break;
59-
case ASRParameterSets.ByName:
60-
this.GetByName();
61-
break;
62-
case ASRParameterSets.Default:
63-
this.GetAll();
64-
break;
65-
}
66-
}
67-
catch (Exception exception)
52+
base.ExecuteSiteRecoveryCmdlet();
53+
54+
switch (this.ParameterSetName)
6855
{
69-
this.HandleException(exception);
56+
case ASRParameterSets.ByFriendlyName:
57+
this.GetByFriendlyName();
58+
break;
59+
case ASRParameterSets.ByName:
60+
this.GetByName();
61+
break;
62+
case ASRParameterSets.Default:
63+
this.GetAll();
64+
break;
7065
}
7166
}
7267

0 commit comments

Comments
 (0)