/******************************************************************************* * 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.RDS; using Amazon.RDS.Model; namespace Amazon.PowerShell.Cmdlets.RDS { /// /// Initiates the failover process for an Aurora global database (GlobalCluster). /// /// /// /// A failover for an Aurora global database promotes one of secondary read-only DB clusters /// to be the primary DB cluster and demotes the primary DB cluster to being a secondary /// (read-only) DB cluster. In other words, the role of the current primary DB cluster /// and the selected (target) DB cluster are switched. The selected secondary DB cluster /// assumes full read/write capabilities for the Aurora global database. /// /// For more information about failing over an Amazon Aurora global database, see Managed /// planned failover for Amazon Aurora global databases in the Amazon Aurora User /// Guide. /// /// This action applies to GlobalCluster (Aurora global databases) only. Use this /// action only on healthy Aurora global databases with running Aurora DB clusters and /// no Region-wide outages, to test disaster recovery scenarios or to reconfigure your /// Aurora global database topology. /// /// [Cmdlet("Start", "RDSFailoverGlobalCluster", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)] [OutputType("Amazon.RDS.Model.GlobalCluster")] [AWSCmdlet("Calls the Amazon Relational Database Service FailoverGlobalCluster API operation.", Operation = new[] {"FailoverGlobalCluster"}, SelectReturnType = typeof(Amazon.RDS.Model.FailoverGlobalClusterResponse))] [AWSCmdletOutput("Amazon.RDS.Model.GlobalCluster or Amazon.RDS.Model.FailoverGlobalClusterResponse", "This cmdlet returns an Amazon.RDS.Model.GlobalCluster object.", "The service call response (type Amazon.RDS.Model.FailoverGlobalClusterResponse) can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack." )] public partial class StartRDSFailoverGlobalClusterCmdlet : AmazonRDSClientCmdlet, IExecutor { #region Parameter GlobalClusterIdentifier /// /// /// Identifier of the Aurora global database (GlobalCluster) that should be failed /// over. The identifier is the unique key assigned by the user when the Aurora global /// database was created. In other words, it's the name of the Aurora global database /// that you want to fail over.Constraints: /// /// #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 GlobalClusterIdentifier { get; set; } #endregion #region Parameter TargetDbClusterIdentifier /// /// /// Identifier of the secondary Aurora DB cluster that you want to promote to primary /// for the Aurora global database (GlobalCluster.) Use the Amazon Resource Name /// (ARN) for the identifier so that Aurora can locate the cluster in its Amazon Web Services /// Region. /// /// #if !MODULAR [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] #else [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true, Mandatory = true)] [System.Management.Automation.AllowEmptyString] [System.Management.Automation.AllowNull] #endif [Amazon.PowerShell.Common.AWSRequiredParameter] public System.String TargetDbClusterIdentifier { get; set; } #endregion #region Parameter Select /// /// Use the -Select parameter to control the cmdlet output. The default value is 'GlobalCluster'. /// Specifying -Select '*' will result in the cmdlet returning the whole service response (Amazon.RDS.Model.FailoverGlobalClusterResponse). /// Specifying the name of a property of type Amazon.RDS.Model.FailoverGlobalClusterResponse 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; } = "GlobalCluster"; #endregion #region Parameter PassThru /// /// Changes the cmdlet behavior to return the value passed to the GlobalClusterIdentifier parameter. /// The -PassThru parameter is deprecated, use -Select '^GlobalClusterIdentifier' instead. This parameter will be removed in a future version. /// [System.Obsolete("The -PassThru parameter is deprecated, use -Select '^GlobalClusterIdentifier' 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.GlobalClusterIdentifier), MyInvocation.BoundParameters); if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "Start-RDSFailoverGlobalCluster (FailoverGlobalCluster)")) { 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.GlobalClusterIdentifier; } #pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute context.GlobalClusterIdentifier = this.GlobalClusterIdentifier; #if MODULAR if (this.GlobalClusterIdentifier == null && ParameterWasBound(nameof(this.GlobalClusterIdentifier))) { WriteWarning("You are passing $null as a value for parameter GlobalClusterIdentifier 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.TargetDbClusterIdentifier = this.TargetDbClusterIdentifier; #if MODULAR if (this.TargetDbClusterIdentifier == null && ParameterWasBound(nameof(this.TargetDbClusterIdentifier))) { WriteWarning("You are passing $null as a value for parameter TargetDbClusterIdentifier 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 // 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.RDS.Model.FailoverGlobalClusterRequest(); if (cmdletContext.GlobalClusterIdentifier != null) { request.GlobalClusterIdentifier = cmdletContext.GlobalClusterIdentifier; } if (cmdletContext.TargetDbClusterIdentifier != null) { request.TargetDbClusterIdentifier = cmdletContext.TargetDbClusterIdentifier; } 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.RDS.Model.FailoverGlobalClusterResponse CallAWSServiceOperation(IAmazonRDS client, Amazon.RDS.Model.FailoverGlobalClusterRequest request) { Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon Relational Database Service", "FailoverGlobalCluster"); try { #if DESKTOP return client.FailoverGlobalCluster(request); #elif CORECLR return client.FailoverGlobalClusterAsync(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 GlobalClusterIdentifier { get; set; } public System.String TargetDbClusterIdentifier { get; set; } public System.Func Select { get; set; } = (response, cmdlet) => response.GlobalCluster; } } }