/******************************************************************************* * Copyright 2012-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"). You may not use * this file except in compliance with the License. A copy of the License is located at * * http://aws.amazon.com/apache2.0 * * or in the "license" file accompanying this file. * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR * CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. * ***************************************************************************** * * AWS Tools for Windows (TM) PowerShell (TM) * */ using System; using System.Collections.Generic; using System.Linq; using System.Management.Automation; using System.Text; using Amazon.PowerShell.Common; using Amazon.Runtime; using Amazon.CloudWatch; using Amazon.CloudWatch.Model; namespace Amazon.PowerShell.Cmdlets.CW { /// /// Deletes the specified anomaly detection model from your account. For more information /// about how to delete an anomaly detection model, see Deleting /// an anomaly detection model in the CloudWatch User Guide. /// [Cmdlet("Remove", "CWAnomalyDetector", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.High)] [OutputType("None")] [AWSCmdlet("Calls the Amazon CloudWatch DeleteAnomalyDetector API operation.", Operation = new[] {"DeleteAnomalyDetector"}, SelectReturnType = typeof(Amazon.CloudWatch.Model.DeleteAnomalyDetectorResponse))] [AWSCmdletOutput("None or Amazon.CloudWatch.Model.DeleteAnomalyDetectorResponse", "This cmdlet does not generate any output." + "The service response (type Amazon.CloudWatch.Model.DeleteAnomalyDetectorResponse) can be referenced from properties attached to the cmdlet entry in the $AWSHistory stack." )] public partial class RemoveCWAnomalyDetectorCmdlet : AmazonCloudWatchClientCmdlet, IExecutor { #region Parameter SingleMetricAnomalyDetector_Dimension /// /// /// The metric dimensions to create the anomaly detection model for. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [Alias("SingleMetricAnomalyDetector_Dimensions")] public Amazon.CloudWatch.Model.Dimension[] SingleMetricAnomalyDetector_Dimension { get; set; } #endregion #region Parameter MetricMathAnomalyDetector_MetricDataQuery /// /// /// An array of metric data query structures that enables you to create an anomaly detector /// based on the result of a metric math expression. Each item in MetricDataQueries /// gets a metric or performs a math expression. One item in MetricDataQueries /// is the expression that provides the time series that the anomaly detector uses as /// input. Designate the expression by setting ReturnData to true /// for this object in the array. For all other expressions and metrics, set ReturnData /// to false. The designated expression must return a single time series. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [Alias("MetricMathAnomalyDetector_MetricDataQueries")] public Amazon.CloudWatch.Model.MetricDataQuery[] MetricMathAnomalyDetector_MetricDataQuery { get; set; } #endregion #region Parameter SingleMetricAnomalyDetector_MetricName /// /// /// The name of the metric to create the anomaly detection model for. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String SingleMetricAnomalyDetector_MetricName { get; set; } #endregion #region Parameter SingleMetricAnomalyDetector_Namespace /// /// /// The namespace of the metric to create the anomaly detection model for. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String SingleMetricAnomalyDetector_Namespace { get; set; } #endregion #region Parameter SingleMetricAnomalyDetector_Stat /// /// /// The statistic to use for the metric and anomaly detection model. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String SingleMetricAnomalyDetector_Stat { get; set; } #endregion #region Parameter Dimension /// /// /// The metric dimensions associated with the anomaly detection model to delete. /// /// This parameter is deprecated. /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [System.ObsoleteAttribute("Use SingleMetricAnomalyDetector.")] [Alias("Dimensions")] public Amazon.CloudWatch.Model.Dimension[] Dimension { get; set; } #endregion #region Parameter MetricName /// /// /// The metric name associated with the anomaly detection model to delete. /// /// This parameter is deprecated. /// [System.Management.Automation.Parameter(Position = 0, ValueFromPipelineByPropertyName = true, ValueFromPipeline = true)] [System.ObsoleteAttribute("Use SingleMetricAnomalyDetector.")] public System.String MetricName { get; set; } #endregion #region Parameter Namespace /// /// /// The namespace associated with the anomaly detection model to delete. /// /// This parameter is deprecated. /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [System.ObsoleteAttribute("Use SingleMetricAnomalyDetector.")] public System.String Namespace { get; set; } #endregion #region Parameter Stat /// /// /// The statistic associated with the anomaly detection model to delete. /// /// This parameter is deprecated. /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [System.ObsoleteAttribute("Use SingleMetricAnomalyDetector.")] public System.String Stat { get; set; } #endregion #region Parameter Select /// /// Use the -Select parameter to control the cmdlet output. The cmdlet doesn't have a return value by default. /// Specifying -Select '*' will result in the cmdlet returning the whole service response (Amazon.CloudWatch.Model.DeleteAnomalyDetectorResponse). /// Specifying -Select '^ParameterName' will result in the cmdlet returning the selected cmdlet parameter value. /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public string Select { get; set; } = "*"; #endregion #region Parameter PassThru /// /// Changes the cmdlet behavior to return the value passed to the MetricName parameter. /// The -PassThru parameter is deprecated, use -Select '^MetricName' instead. This parameter will be removed in a future version. /// [System.Obsolete("The -PassThru parameter is deprecated, use -Select '^MetricName' instead. This parameter will be removed in a future version.")] [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public SwitchParameter PassThru { get; set; } #endregion #region Parameter Force /// /// This parameter overrides confirmation prompts to force /// the cmdlet to continue its operation. This parameter should always /// be used with caution. /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public SwitchParameter Force { get; set; } #endregion protected override void ProcessRecord() { this._AWSSignerType = "v4"; base.ProcessRecord(); var resourceIdentifiersText = FormatParameterValuesForConfirmationMsg(nameof(this.MetricName), MyInvocation.BoundParameters); if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "Remove-CWAnomalyDetector (DeleteAnomalyDetector)")) { return; } var context = new CmdletContext(); // allow for manipulation of parameters prior to loading into context PreExecutionContextLoad(context); #pragma warning disable CS0618, CS0612 //A class member was marked with the Obsolete attribute if (ParameterWasBound(nameof(this.Select))) { context.Select = CreateSelectDelegate(Select) ?? throw new System.ArgumentException("Invalid value for -Select parameter.", nameof(this.Select)); if (this.PassThru.IsPresent) { throw new System.ArgumentException("-PassThru cannot be used when -Select is specified.", nameof(this.Select)); } } else if (this.PassThru.IsPresent) { context.Select = (response, cmdlet) => this.MetricName; } #pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute #pragma warning disable CS0618, CS0612 //A class member was marked with the Obsolete attribute if (this.Dimension != null) { context.Dimension = new List(this.Dimension); } #pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute if (this.MetricMathAnomalyDetector_MetricDataQuery != null) { context.MetricMathAnomalyDetector_MetricDataQuery = new List(this.MetricMathAnomalyDetector_MetricDataQuery); } #pragma warning disable CS0618, CS0612 //A class member was marked with the Obsolete attribute context.MetricName = this.MetricName; #pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute #pragma warning disable CS0618, CS0612 //A class member was marked with the Obsolete attribute context.Namespace = this.Namespace; #pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute if (this.SingleMetricAnomalyDetector_Dimension != null) { context.SingleMetricAnomalyDetector_Dimension = new List(this.SingleMetricAnomalyDetector_Dimension); } context.SingleMetricAnomalyDetector_MetricName = this.SingleMetricAnomalyDetector_MetricName; context.SingleMetricAnomalyDetector_Namespace = this.SingleMetricAnomalyDetector_Namespace; context.SingleMetricAnomalyDetector_Stat = this.SingleMetricAnomalyDetector_Stat; #pragma warning disable CS0618, CS0612 //A class member was marked with the Obsolete attribute context.Stat = this.Stat; #pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute // allow further manipulation of loaded context prior to processing PostExecutionContextLoad(context); var output = Execute(context) as CmdletOutput; ProcessOutput(output); } #region IExecutor Members public object Execute(ExecutorContext context) { var cmdletContext = context as CmdletContext; // create request var request = new Amazon.CloudWatch.Model.DeleteAnomalyDetectorRequest(); #pragma warning disable CS0618, CS0612 //A class member was marked with the Obsolete attribute if (cmdletContext.Dimension != null) { request.Dimensions = cmdletContext.Dimension; } #pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute // populate MetricMathAnomalyDetector var requestMetricMathAnomalyDetectorIsNull = true; request.MetricMathAnomalyDetector = new Amazon.CloudWatch.Model.MetricMathAnomalyDetector(); List requestMetricMathAnomalyDetector_metricMathAnomalyDetector_MetricDataQuery = null; if (cmdletContext.MetricMathAnomalyDetector_MetricDataQuery != null) { requestMetricMathAnomalyDetector_metricMathAnomalyDetector_MetricDataQuery = cmdletContext.MetricMathAnomalyDetector_MetricDataQuery; } if (requestMetricMathAnomalyDetector_metricMathAnomalyDetector_MetricDataQuery != null) { request.MetricMathAnomalyDetector.MetricDataQueries = requestMetricMathAnomalyDetector_metricMathAnomalyDetector_MetricDataQuery; requestMetricMathAnomalyDetectorIsNull = false; } // determine if request.MetricMathAnomalyDetector should be set to null if (requestMetricMathAnomalyDetectorIsNull) { request.MetricMathAnomalyDetector = null; } #pragma warning disable CS0618, CS0612 //A class member was marked with the Obsolete attribute if (cmdletContext.MetricName != null) { request.MetricName = cmdletContext.MetricName; } #pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute #pragma warning disable CS0618, CS0612 //A class member was marked with the Obsolete attribute if (cmdletContext.Namespace != null) { request.Namespace = cmdletContext.Namespace; } #pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute // populate SingleMetricAnomalyDetector var requestSingleMetricAnomalyDetectorIsNull = true; request.SingleMetricAnomalyDetector = new Amazon.CloudWatch.Model.SingleMetricAnomalyDetector(); List requestSingleMetricAnomalyDetector_singleMetricAnomalyDetector_Dimension = null; if (cmdletContext.SingleMetricAnomalyDetector_Dimension != null) { requestSingleMetricAnomalyDetector_singleMetricAnomalyDetector_Dimension = cmdletContext.SingleMetricAnomalyDetector_Dimension; } if (requestSingleMetricAnomalyDetector_singleMetricAnomalyDetector_Dimension != null) { request.SingleMetricAnomalyDetector.Dimensions = requestSingleMetricAnomalyDetector_singleMetricAnomalyDetector_Dimension; requestSingleMetricAnomalyDetectorIsNull = false; } System.String requestSingleMetricAnomalyDetector_singleMetricAnomalyDetector_MetricName = null; if (cmdletContext.SingleMetricAnomalyDetector_MetricName != null) { requestSingleMetricAnomalyDetector_singleMetricAnomalyDetector_MetricName = cmdletContext.SingleMetricAnomalyDetector_MetricName; } if (requestSingleMetricAnomalyDetector_singleMetricAnomalyDetector_MetricName != null) { request.SingleMetricAnomalyDetector.MetricName = requestSingleMetricAnomalyDetector_singleMetricAnomalyDetector_MetricName; requestSingleMetricAnomalyDetectorIsNull = false; } System.String requestSingleMetricAnomalyDetector_singleMetricAnomalyDetector_Namespace = null; if (cmdletContext.SingleMetricAnomalyDetector_Namespace != null) { requestSingleMetricAnomalyDetector_singleMetricAnomalyDetector_Namespace = cmdletContext.SingleMetricAnomalyDetector_Namespace; } if (requestSingleMetricAnomalyDetector_singleMetricAnomalyDetector_Namespace != null) { request.SingleMetricAnomalyDetector.Namespace = requestSingleMetricAnomalyDetector_singleMetricAnomalyDetector_Namespace; requestSingleMetricAnomalyDetectorIsNull = false; } System.String requestSingleMetricAnomalyDetector_singleMetricAnomalyDetector_Stat = null; if (cmdletContext.SingleMetricAnomalyDetector_Stat != null) { requestSingleMetricAnomalyDetector_singleMetricAnomalyDetector_Stat = cmdletContext.SingleMetricAnomalyDetector_Stat; } if (requestSingleMetricAnomalyDetector_singleMetricAnomalyDetector_Stat != null) { request.SingleMetricAnomalyDetector.Stat = requestSingleMetricAnomalyDetector_singleMetricAnomalyDetector_Stat; requestSingleMetricAnomalyDetectorIsNull = false; } // determine if request.SingleMetricAnomalyDetector should be set to null if (requestSingleMetricAnomalyDetectorIsNull) { request.SingleMetricAnomalyDetector = null; } #pragma warning disable CS0618, CS0612 //A class member was marked with the Obsolete attribute if (cmdletContext.Stat != null) { request.Stat = cmdletContext.Stat; } #pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute CmdletOutput output; // issue call var client = Client ?? CreateClient(_CurrentCredentials, _RegionEndpoint); try { var response = CallAWSServiceOperation(client, request); object pipelineOutput = null; pipelineOutput = cmdletContext.Select(response, this); output = new CmdletOutput { PipelineOutput = pipelineOutput, ServiceResponse = response }; } catch (Exception e) { output = new CmdletOutput { ErrorResponse = e }; } return output; } public ExecutorContext CreateContext() { return new CmdletContext(); } #endregion #region AWS Service Operation Call private Amazon.CloudWatch.Model.DeleteAnomalyDetectorResponse CallAWSServiceOperation(IAmazonCloudWatch client, Amazon.CloudWatch.Model.DeleteAnomalyDetectorRequest request) { Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon CloudWatch", "DeleteAnomalyDetector"); try { #if DESKTOP return client.DeleteAnomalyDetector(request); #elif CORECLR return client.DeleteAnomalyDetectorAsync(request).GetAwaiter().GetResult(); #else #error "Unknown build edition" #endif } catch (AmazonServiceException exc) { var webException = exc.InnerException as System.Net.WebException; if (webException != null) { throw new Exception(Utils.Common.FormatNameResolutionFailureMessage(client.Config, webException.Message), webException); } throw; } } #endregion internal partial class CmdletContext : ExecutorContext { [System.ObsoleteAttribute] public List Dimension { get; set; } public List MetricMathAnomalyDetector_MetricDataQuery { get; set; } [System.ObsoleteAttribute] public System.String MetricName { get; set; } [System.ObsoleteAttribute] public System.String Namespace { get; set; } public List SingleMetricAnomalyDetector_Dimension { get; set; } public System.String SingleMetricAnomalyDetector_MetricName { get; set; } public System.String SingleMetricAnomalyDetector_Namespace { get; set; } public System.String SingleMetricAnomalyDetector_Stat { get; set; } [System.ObsoleteAttribute] public System.String Stat { get; set; } public System.Func Select { get; set; } = (response, cmdlet) => null; } } }