Skip to content

[Release-1.2.2] Clean the cmdlets code, add a deprecation warning to some of the cmdlets, add some verbose messages #1884

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Feb 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
using System.Threading.Tasks;
using Hyak.Common;
using Microsoft.Azure.Commands.Insights.Autoscale;
using Microsoft.Azure.Commands.Insights.OutputClasses;
using Microsoft.Azure.Management.Insights;
using Microsoft.Azure.Management.Insights.Models;
using Microsoft.WindowsAzure.Commands.ScenarioTest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void GetAutoscaleHistoryCommandParametersProcessing()
Test.Utilities.ExecuteVerifications(
cmdlet: cmdlet,
insinsightsEventOperationsMockightsClientMock: this.insightsEventOperationsMock,
requiredFieldName: "eventSource",
requiredFieldName: "category",
requiredFieldValue: GetAutoscaleHistoryCommand.AutoscaleEventSourceName,
filter: ref this.filter,
selected: ref this.selected,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Azure.Commands.Insights.Alerts;
using Microsoft.Azure.Commands.Insights.Diagnostics;
using Microsoft.Azure.Management.Insights;
using Microsoft.Azure.Management.Insights.Models;
Expand All @@ -35,7 +34,6 @@ public class GetDiagnosticSettingCommandTests
private readonly Mock<IServiceDiagnosticSettingsOperations> insightsDiagnosticsOperationsMock;
private Mock<ICommandRuntime> commandRuntimeMock;
private ServiceDiagnosticSettingsGetResponse response;
private RuleCreateOrUpdateParameters createOrUpdatePrms;
private const string resourceId = "/subscriptions/123/resourcegroups/rg/providers/rp/resource/myresource";
private string calledResourceId;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,13 @@

using System;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Azure.Commands.Insights.Alerts;
using Microsoft.Azure.Commands.Insights.Diagnostics;
using Microsoft.Azure.Management.Insights;
using Microsoft.Azure.Management.Insights.Models;
using Microsoft.WindowsAzure.Commands.ScenarioTest;
using Moq;
using Xunit;

namespace Microsoft.Azure.Commands.Insights.Test.Diagnostics
{
Expand All @@ -36,7 +31,6 @@ public class SetDiagnosticSettingCommandTests
private readonly Mock<IServiceDiagnosticSettingsOperations> insightsDiagnosticsOperationsMock;
private Mock<ICommandRuntime> commandRuntimeMock;
private ServiceDiagnosticSettingsGetResponse response;
private RuleCreateOrUpdateParameters createOrUpdatePrms;
private const string resourceId = "/subscriptions/123/resourcegroups/rg/providers/rp/resource/myresource";
private const string storageAccountId = "/subscriptions/123/resourcegroups/rg/providers/microsoft.storage/accounts/myaccount";
private string calledResourceId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using System;
using System.Management.Automation;
using System.Threading;
using System.Threading.Tasks;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public static void VerifyConditionInFilter(string filter, string field, string v
if (!string.IsNullOrWhiteSpace(field))
{
var condition = string.Format("and {0} eq '{1}'", field, value);
Assert.True(filter.Contains(condition), "Filter does not contain required condition");
Assert.True(filter.Contains(condition), string.Format("Filter: {0} does not contain required condition: {1}", filter, condition));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<package id="System.Spatial" version="5.6.4" targetFramework="net45" />
<package id="WindowsAzure.Storage" version="6.0.0" targetFramework="net45" />
<package id="xunit" version="2.1.0" targetFramework="net45" />
<package id="xunit.abstractions" version="2.0.0" targetFramework="net45" />
<package id="xunit.abstractions" version="2.0.0" targetFramework="net45" />
<package id="xunit.assert" version="2.1.0" targetFramework="net45" />
<package id="xunit.core" version="2.1.0" targetFramework="net45" />
<package id="xunit.extensibility.core" version="2.1.0" targetFramework="net45" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ private ManagementEventRuleCondition CreateEventRuleCondition()

private void VerifyRuleTypeToParametersConsistency()
{
WriteVerboseWithTimestamp(string.Format("VerifyRuleTypeToParametersConsistency: input type:{0}", this.RuleType));
AlertRuleTypes type = AlertRuleTypes.Event;

// NOTE: the parameters EventName and MetricName cannot appear both at same time (see the parameters declaration), but they can be both absent simultaneously (i.e. Webtest data source type)
Expand Down Expand Up @@ -209,12 +210,15 @@ private RuleCondition CreateRuleCondition()
switch (this.RuleType)
{
case AlertRuleTypes.Event:
WriteVerboseWithTimestamp(string.Format("CreateRuleCondition: Creating event rule condition (event-based rule)"));
condition = this.CreateEventRuleCondition();
break;
case AlertRuleTypes.Metric:
WriteVerboseWithTimestamp(string.Format("CreateRuleCondition: Creating threshold rule condition (metric-based rule"));
condition = this.CreateThresholdRuleCondition();
break;
case AlertRuleTypes.Webtest:
WriteVerboseWithTimestamp(string.Format("CreateRuleCondition: Creating location threshold rule condition (webtest rule)"));
condition = new LocationThresholdRuleCondition()
{
DataSource = new RuleMetricDataSource(),
Expand All @@ -234,6 +238,8 @@ protected override RuleCreateOrUpdateParameters CreateSdkCallParameters()
this.VerifyRuleTypeToParametersConsistency();

RuleCondition condition = this.CreateRuleCondition();

WriteVerboseWithTimestamp(string.Format("CreateSdkCallParameters: Creating rule object"));
return new RuleCreateOrUpdateParameters()
{
Location = this.Location,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,10 @@ public abstract class AddAlertRuleCommandBase : ManagementCmdletBase
/// </summary>
protected override void ProcessRecordInternal()
{
WriteWarning("This cmdlet is being modified to enable better experience and may contain breaking changes in a future release.");

RuleCreateOrUpdateParameters parameters = this.CreateSdkCallParameters();

var result = this.InsightsManagementClient.AlertOperations.CreateOrUpdateRuleAsync(resourceGroupName: this.ResourceGroup, parameters: parameters).Result;
WriteObject(result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ protected override bool KeepTheRecord(EventData record)
/// <returns>Modified query filter including the condition for eventSource</returns>
protected override string ProcessParticularParameters(string currentQueryFilter)
{
WriteWarning("This cmdlet is being modified to enable better experience and may contain breaking changes in a future release.");

// Make sure only events for alerts come back
return this.AddConditionIfPResent(currentQueryFilter, "eventSource", AlertsEventSourceName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ public class GetAlertRuleCommand : ManagementCmdletBase
/// </summary>
protected override void ProcessRecordInternal()
{
WriteWarning("This cmdlet is being modified to enable better experience and may contain breaking changes in a future release.");

if (string.IsNullOrWhiteSpace(this.Name))
{
// Retrieve all the AlertRules for a ResourceGroup
Expand All @@ -83,6 +85,7 @@ protected override void ProcessRecordInternal()
{
// Retrieve a single AlertRule determined by the ResourceGroup and the rule name
RuleGetResponse result = this.InsightsManagementClient.AlertOperations.GetRuleAsync(resourceGroupName: this.ResourceGroup, ruleName: this.Name).Result;

var finalResult = new List<PSManagementItemDescriptor> { this.DetailedOutput.IsPresent ? (PSManagementItemDescriptor)new PSAlertRule(result) : new PSAlertRuleNoDetails(result) };
WriteObject(sendToPipeline: finalResult);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Management.Automation;
using Microsoft.Azure.Management.Insights;
Expand Down Expand Up @@ -50,6 +49,8 @@ public class RemoveAlertRuleCommand : ManagementCmdletBase
/// </summary>
protected override void ProcessRecordInternal()
{
WriteWarning("This cmdlet is being modified to enable better experience and may contain breaking changes in a future release.");

AzureOperationResponse result = this.InsightsManagementClient.AlertOperations.DeleteRuleAsync(resourceGroupName: this.ResourceGroup, ruleName: this.Name).Result;
WriteObject(result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
using System.Linq;
using System.Management.Automation;
using Hyak.Common;
using Microsoft.Azure.Commands.Insights.OutputClasses;
using Microsoft.Azure.Commands.Insights.Properties;
using Microsoft.Azure.Management.Insights;
using Microsoft.Azure.Management.Insights.Models;
Expand Down Expand Up @@ -94,7 +93,10 @@ public class AddAutoscaleSettingCommand : ManagementCmdletBase
/// </summary>
protected override void ProcessRecordInternal()
{
WriteWarning("This cmdlet is being modified to enable better experience and may contain breaking changes in a future release.");

AutoscaleSettingCreateOrUpdateParameters parameters = this.CreateSdkCallParameters();

var result = this.InsightsManagementClient.AutoscaleOperations.CreateOrUpdateSettingAsync(resourceGroupName: this.ResourceGroup, autoscaleSettingName: this.Name, parameters: parameters).Result;

WriteObject(result);
Expand All @@ -106,6 +108,7 @@ private AutoscaleSettingCreateOrUpdateParameters CreateSdkCallParameters()

if (this.SettingSpec != null)
{

// Receiving a single parameter with the whole spec for an autoscale setting
var property = this.SettingSpec.Properties;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ protected override bool KeepTheRecord(EventData record)
/// <returns>Modified query filter including the condition for eventSource</returns>
protected override string ProcessParticularParameters(string currentQueryFilter)
{
WriteWarning("This cmdlet is being modified to enable better experience and may contain breaking changes in a future release.");

return this.AddConditionIfPResent(currentQueryFilter, "category", AutoscaleEventSourceName);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
Expand Down Expand Up @@ -59,6 +58,8 @@ public class GetAutoscaleSettingCommand : ManagementCmdletBase
/// </summary>
protected override void ProcessRecordInternal()
{
WriteWarning("This cmdlet is being modified to enable better experience and may contain breaking changes in a future release.");

if (string.IsNullOrWhiteSpace(this.Name))
{
// Retrieve all the Autoscale settings for a resource group
Expand All @@ -71,6 +72,7 @@ protected override void ProcessRecordInternal()
{
// Retrieve a single Autoscale setting determined by the resource group and the rule name
AutoscaleSettingGetResponse result = this.InsightsManagementClient.AutoscaleOperations.GetSettingAsync(resourceGroupName: this.ResourceGroup, autoscaleSettingName: this.Name).Result;

WriteObject(sendToPipeline: this.DetailedOutput.IsPresent ? new PSAutoscaleSetting(result) : result.ToAutoscaleSettingGetResponse());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ public class NewAutoscaleProfileCommand : AzureRMCmdlet
/// </summary>
public override void ExecuteCmdlet()
{
WriteWarning("This cmdlet is being modified to enable better experience and may contain breaking changes in a future release.");

AutoscaleProfile profile = this.CreateSettingProfile();
WriteObject(profile);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,10 @@
// ----------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Management.Automation;
using Microsoft.Azure.Commands.Insights.Properties;
using Microsoft.Azure.Commands.ResourceManager.Common;
using Microsoft.Azure.Management.Insights.Models;
using Microsoft.WindowsAzure.Commands.Utilities.Common;

namespace Microsoft.Azure.Commands.Insights.Autoscale
{
Expand Down Expand Up @@ -116,6 +113,8 @@ public class NewAutoscaleRuleCommand : AzureRMCmdlet
/// </summary>
public override void ExecuteCmdlet()
{
WriteWarning("This cmdlet is being modified to enable better experience and may contain breaking changes in a future release.");

ScaleRule rule = this.CreateSettingRule();
WriteObject(rule);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Management.Automation;
using Microsoft.Azure.Management.Insights;

Expand Down Expand Up @@ -50,6 +48,8 @@ public class RemoveAutoscaleSettingCommand : ManagementCmdletBase
/// </summary>
protected override void ProcessRecordInternal()
{
WriteWarning("This cmdlet is being modified to enable better experience and may contain breaking changes in a future release.");

AzureOperationResponse result = this.InsightsManagementClient.AutoscaleOperations.DeleteSettingAsync(resourceGroupName: this.ResourceGroup, autoscaleSettingName: this.Name).Result;
WriteObject(result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms, Version=2.18.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.2.18.206251556\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms.dll</HintPath>
<Private>True</Private>
</Reference>
</Reference>
<Reference Include="Microsoft.Rest.ClientRuntime, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.Rest.ClientRuntime.2.0.1\lib\net45\Microsoft.Rest.ClientRuntime.dll</HintPath>
<Private>True</Private>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Management.Automation;
using System.Threading;
using Microsoft.Azure.Commands.Insights.OutputClasses;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// ----------------------------------------------------------------------------------

using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

using System;
using Microsoft.Azure.Commands.ResourceManager.Common;
using Microsoft.WindowsAzure.Commands.Utilities.Common;

namespace Microsoft.Azure.Commands.Insights
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace Microsoft.Azure.Commands.Insights
/// <summary>
/// Base class for the Azure Insights SDK Cmdlets based on the InsightsManagementClient
/// </summary>
public abstract class ManagementCmdletBase : InsightsCmdletBase, IDisposable
public abstract class ManagementCmdletBase : InsightsCmdletBase
{
#region General declarations

Expand All @@ -35,11 +35,11 @@ public abstract class ManagementCmdletBase : InsightsCmdletBase, IDisposable
/// </summary>
public IInsightsManagementClient InsightsManagementClient
{
get
{
// The premise is that a command to establish a context (like Add-AzureRmAccount) has
// been called before this command in order to have a correct CurrentContext
get {
if (this.insightsManagementClient == null)
{
// The premise is that a command to establish a context (like Add-AzureRmAccount) has been called before this command in order to have a correct CurrentContext
this.insightsManagementClient = AzureSession.ClientFactory.CreateClient<InsightsManagementClient>(DefaultProfile.Context, AzureEnvironment.Endpoint.ResourceManager);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
using Microsoft.Azure.Commands.Insights.OutputClasses;
using Microsoft.Azure.Commands.ResourceManager.Common;
using Microsoft.Azure.Insights.Models;
using Microsoft.WindowsAzure.Commands.Utilities.Common;

namespace Microsoft.Azure.Commands.Insights.Metrics
{
Expand Down Expand Up @@ -77,6 +76,8 @@ public PSMetricTabularResult[] ProcessParameter()
/// </summary>
public override void ExecuteCmdlet()
{
WriteWarning("This cmdlet is being modified to enable better experience and may contain breaking changes in a future release.");

WriteObject(this.ProcessParameter());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using System;
using System.Linq;
using System.Management.Automation;
using System.Text;
Expand Down Expand Up @@ -71,12 +70,15 @@ protected string ProcessParameters()
/// </summary>
protected override void ProcessRecordInternal()
{
WriteWarning("This cmdlet is being modified to enable better experience and may contain breaking changes in a future release.");

string queryFilter = this.ProcessParameters();
bool fullDetails = this.DetailedOutput.IsPresent;

// Call the proper API methods to return a list of raw records.
// If fullDetails is present full details of the records are displayed, otherwise only a summary of the records is displayed
MetricDefinitionListResponse response = this.InsightsClient.MetricDefinitionOperations.GetMetricDefinitionsAsync(resourceUri: this.ResourceId, filterString: queryFilter, cancellationToken: CancellationToken.None).Result;

var records = response.MetricDefinitionCollection.Value.Select(e => fullDetails ? (MetricDefinition)new PSMetricDefinition(e) : new PSMetricDefinitionNoDetails(e)).ToArray();

WriteObject(sendToPipeline: records);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,15 @@ protected string ProcessParameters()
/// </summary>
protected override void ProcessRecordInternal()
{
WriteWarning("This cmdlet is being modified to enable better experience and may contain breaking changes in a future release.");

string queryFilter = this.ProcessParameters();
bool fullDetails = this.DetailedOutput.IsPresent;

// Call the proper API methods to return a list of raw records.
// If fullDetails is present full details of the records displayed, otherwise only a summary of the values is displayed
MetricListResponse response = this.InsightsClient.MetricOperations.GetMetricsAsync(resourceUri: this.ResourceId, filterString: queryFilter, cancellationToken: CancellationToken.None).Result;

var records = response.MetricCollection.Value.Select(e => fullDetails ? (Metric)new PSMetric(e) : new PSMetricNoDetails(e)).ToArray();

WriteObject(sendToPipeline: records);
Expand Down
Loading