/******************************************************************************* * 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.MemoryDB; using Amazon.MemoryDB.Model; namespace Amazon.PowerShell.Cmdlets.MDB { /// /// Modifies the settings for a cluster. You can use this operation to change one or more /// cluster configuration settings by specifying the settings and the new values. /// [Cmdlet("Update", "MDBCluster", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)] [OutputType("Amazon.MemoryDB.Model.Cluster")] [AWSCmdlet("Calls the Amazon MemoryDB UpdateCluster API operation.", Operation = new[] {"UpdateCluster"}, SelectReturnType = typeof(Amazon.MemoryDB.Model.UpdateClusterResponse))] [AWSCmdletOutput("Amazon.MemoryDB.Model.Cluster or Amazon.MemoryDB.Model.UpdateClusterResponse", "This cmdlet returns an Amazon.MemoryDB.Model.Cluster object.", "The service call response (type Amazon.MemoryDB.Model.UpdateClusterResponse) can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack." )] public partial class UpdateMDBClusterCmdlet : AmazonMemoryDBClientCmdlet, IExecutor { #region Parameter ACLName /// /// /// The Access Control List that is associated with the cluster /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String ACLName { get; set; } #endregion #region Parameter ClusterName /// /// /// The name of the cluster to update /// /// #if !MODULAR [System.Management.Automation.Parameter(Position = 0, ValueFromPipelineByPropertyName = true, ValueFromPipeline = true)] #else [System.Management.Automation.Parameter(Position = 0, ValueFromPipelineByPropertyName = true, ValueFromPipeline = true, Mandatory = true)] [System.Management.Automation.AllowEmptyString] [System.Management.Automation.AllowNull] #endif [Amazon.PowerShell.Common.AWSRequiredParameter] public System.String ClusterName { get; set; } #endregion #region Parameter Description /// /// /// The description of the cluster to update /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String Description { get; set; } #endregion #region Parameter EngineVersion /// /// /// The upgraded version of the engine to be run on the nodes. You can upgrade to a newer /// engine version, but you cannot downgrade to an earlier engine version. If you want /// to use an earlier engine version, you must delete the existing cluster and create /// it anew with the earlier engine version. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String EngineVersion { get; set; } #endregion #region Parameter MaintenanceWindow /// /// /// Specifies the weekly time range during which maintenance on the cluster is performed. /// It is specified as a range in the format ddd:hh24:mi-ddd:hh24:mi (24H Clock UTC). /// The minimum maintenance window is a 60 minute period.Valid values for ddd are:Example: sun:23:00-mon:01:30 /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String MaintenanceWindow { get; set; } #endregion #region Parameter NodeType /// /// /// A valid node type that you want to scale this cluster up or down to. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String NodeType { get; set; } #endregion #region Parameter ParameterGroupName /// /// /// The name of the parameter group to update /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String ParameterGroupName { get; set; } #endregion #region Parameter ReplicaConfiguration_ReplicaCount /// /// /// The number of replicas to scale up or down to /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.Int32? ReplicaConfiguration_ReplicaCount { get; set; } #endregion #region Parameter SecurityGroupId /// /// /// The SecurityGroupIds to update /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [Alias("SecurityGroupIds")] public System.String[] SecurityGroupId { get; set; } #endregion #region Parameter ShardConfiguration_ShardCount /// /// /// The number of shards in the cluster /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.Int32? ShardConfiguration_ShardCount { get; set; } #endregion #region Parameter SnapshotRetentionLimit /// /// /// The number of days for which MemoryDB retains automatic cluster snapshots before deleting /// them. For example, if you set SnapshotRetentionLimit to 5, a snapshot that was taken /// today is retained for 5 days before being deleted. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.Int32? SnapshotRetentionLimit { get; set; } #endregion #region Parameter SnapshotWindow /// /// /// The daily time range (in UTC) during which MemoryDB begins taking a daily snapshot /// of your cluster. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String SnapshotWindow { get; set; } #endregion #region Parameter SnsTopicArn /// /// /// The SNS topic ARN to update /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String SnsTopicArn { get; set; } #endregion #region Parameter SnsTopicStatus /// /// /// The status of the Amazon SNS notification topic. Notifications are sent only if the /// status is active. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String SnsTopicStatus { get; set; } #endregion #region Parameter Select /// /// Use the -Select parameter to control the cmdlet output. The default value is 'Cluster'. /// Specifying -Select '*' will result in the cmdlet returning the whole service response (Amazon.MemoryDB.Model.UpdateClusterResponse). /// Specifying the name of a property of type Amazon.MemoryDB.Model.UpdateClusterResponse will result in that property being returned. /// 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; } = "Cluster"; #endregion #region Parameter PassThru /// /// Changes the cmdlet behavior to return the value passed to the ClusterName parameter. /// The -PassThru parameter is deprecated, use -Select '^ClusterName' instead. This parameter will be removed in a future version. /// [System.Obsolete("The -PassThru parameter is deprecated, use -Select '^ClusterName' 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.ClusterName), MyInvocation.BoundParameters); if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "Update-MDBCluster (UpdateCluster)")) { 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.ClusterName; } #pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute context.ACLName = this.ACLName; context.ClusterName = this.ClusterName; #if MODULAR if (this.ClusterName == null && ParameterWasBound(nameof(this.ClusterName))) { WriteWarning("You are passing $null as a value for parameter ClusterName which is marked as required. In case you believe this parameter was incorrectly marked as required, report this by opening an issue at https://github.com/aws/aws-tools-for-powershell/issues."); } #endif context.Description = this.Description; context.EngineVersion = this.EngineVersion; context.MaintenanceWindow = this.MaintenanceWindow; context.NodeType = this.NodeType; context.ParameterGroupName = this.ParameterGroupName; context.ReplicaConfiguration_ReplicaCount = this.ReplicaConfiguration_ReplicaCount; if (this.SecurityGroupId != null) { context.SecurityGroupId = new List(this.SecurityGroupId); } context.ShardConfiguration_ShardCount = this.ShardConfiguration_ShardCount; context.SnapshotRetentionLimit = this.SnapshotRetentionLimit; context.SnapshotWindow = this.SnapshotWindow; context.SnsTopicArn = this.SnsTopicArn; context.SnsTopicStatus = this.SnsTopicStatus; // 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.MemoryDB.Model.UpdateClusterRequest(); if (cmdletContext.ACLName != null) { request.ACLName = cmdletContext.ACLName; } if (cmdletContext.ClusterName != null) { request.ClusterName = cmdletContext.ClusterName; } if (cmdletContext.Description != null) { request.Description = cmdletContext.Description; } if (cmdletContext.EngineVersion != null) { request.EngineVersion = cmdletContext.EngineVersion; } if (cmdletContext.MaintenanceWindow != null) { request.MaintenanceWindow = cmdletContext.MaintenanceWindow; } if (cmdletContext.NodeType != null) { request.NodeType = cmdletContext.NodeType; } if (cmdletContext.ParameterGroupName != null) { request.ParameterGroupName = cmdletContext.ParameterGroupName; } // populate ReplicaConfiguration var requestReplicaConfigurationIsNull = true; request.ReplicaConfiguration = new Amazon.MemoryDB.Model.ReplicaConfigurationRequest(); System.Int32? requestReplicaConfiguration_replicaConfiguration_ReplicaCount = null; if (cmdletContext.ReplicaConfiguration_ReplicaCount != null) { requestReplicaConfiguration_replicaConfiguration_ReplicaCount = cmdletContext.ReplicaConfiguration_ReplicaCount.Value; } if (requestReplicaConfiguration_replicaConfiguration_ReplicaCount != null) { request.ReplicaConfiguration.ReplicaCount = requestReplicaConfiguration_replicaConfiguration_ReplicaCount.Value; requestReplicaConfigurationIsNull = false; } // determine if request.ReplicaConfiguration should be set to null if (requestReplicaConfigurationIsNull) { request.ReplicaConfiguration = null; } if (cmdletContext.SecurityGroupId != null) { request.SecurityGroupIds = cmdletContext.SecurityGroupId; } // populate ShardConfiguration var requestShardConfigurationIsNull = true; request.ShardConfiguration = new Amazon.MemoryDB.Model.ShardConfigurationRequest(); System.Int32? requestShardConfiguration_shardConfiguration_ShardCount = null; if (cmdletContext.ShardConfiguration_ShardCount != null) { requestShardConfiguration_shardConfiguration_ShardCount = cmdletContext.ShardConfiguration_ShardCount.Value; } if (requestShardConfiguration_shardConfiguration_ShardCount != null) { request.ShardConfiguration.ShardCount = requestShardConfiguration_shardConfiguration_ShardCount.Value; requestShardConfigurationIsNull = false; } // determine if request.ShardConfiguration should be set to null if (requestShardConfigurationIsNull) { request.ShardConfiguration = null; } if (cmdletContext.SnapshotRetentionLimit != null) { request.SnapshotRetentionLimit = cmdletContext.SnapshotRetentionLimit.Value; } if (cmdletContext.SnapshotWindow != null) { request.SnapshotWindow = cmdletContext.SnapshotWindow; } if (cmdletContext.SnsTopicArn != null) { request.SnsTopicArn = cmdletContext.SnsTopicArn; } if (cmdletContext.SnsTopicStatus != null) { request.SnsTopicStatus = cmdletContext.SnsTopicStatus; } 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.MemoryDB.Model.UpdateClusterResponse CallAWSServiceOperation(IAmazonMemoryDB client, Amazon.MemoryDB.Model.UpdateClusterRequest request) { Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon MemoryDB", "UpdateCluster"); try { #if DESKTOP return client.UpdateCluster(request); #elif CORECLR return client.UpdateClusterAsync(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 { public System.String ACLName { get; set; } public System.String ClusterName { get; set; } public System.String Description { get; set; } public System.String EngineVersion { get; set; } public System.String MaintenanceWindow { get; set; } public System.String NodeType { get; set; } public System.String ParameterGroupName { get; set; } public System.Int32? ReplicaConfiguration_ReplicaCount { get; set; } public List SecurityGroupId { get; set; } public System.Int32? ShardConfiguration_ShardCount { get; set; } public System.Int32? SnapshotRetentionLimit { get; set; } public System.String SnapshotWindow { get; set; } public System.String SnsTopicArn { get; set; } public System.String SnsTopicStatus { get; set; } public System.Func Select { get; set; } = (response, cmdlet) => response.Cluster; } } }