/******************************************************************************* * 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.DatabaseMigrationService; using Amazon.DatabaseMigrationService.Model; namespace Amazon.PowerShell.Cmdlets.DMS { /// /// Modifies the specified replication task. /// /// /// /// You can't modify the task endpoints. The task must be stopped before you can modify /// it. /// /// For more information about DMS tasks, see Working /// with Migration Tasks in the Database Migration Service User Guide. /// /// [Cmdlet("Edit", "DMSReplicationTask", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)] [OutputType("Amazon.DatabaseMigrationService.Model.ReplicationTask")] [AWSCmdlet("Calls the AWS Database Migration Service ModifyReplicationTask API operation.", Operation = new[] {"ModifyReplicationTask"}, SelectReturnType = typeof(Amazon.DatabaseMigrationService.Model.ModifyReplicationTaskResponse))] [AWSCmdletOutput("Amazon.DatabaseMigrationService.Model.ReplicationTask or Amazon.DatabaseMigrationService.Model.ModifyReplicationTaskResponse", "This cmdlet returns an Amazon.DatabaseMigrationService.Model.ReplicationTask object.", "The service call response (type Amazon.DatabaseMigrationService.Model.ModifyReplicationTaskResponse) can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack." )] public partial class EditDMSReplicationTaskCmdlet : AmazonDatabaseMigrationServiceClientCmdlet, IExecutor { #region Parameter CdcStartPosition /// /// /// Indicates when you want a change data capture (CDC) operation to start. Use either /// CdcStartPosition or CdcStartTime to specify when you want a CDC operation to start. /// Specifying both values results in an error. The value can be in date, checkpoint, or LSN/SCN format.Date Example: --cdc-start-position “2018-03-08T12:12:12”Checkpoint Example: --cdc-start-position "checkpoint:V1#27#mysql-bin-changelog.157832:1975:-1:2002:677883278264080:mysql-bin-changelog.157832:1876#0#0#*#0#93"LSN Example: --cdc-start-position “mysql-bin-changelog.000024:373”When you use this task setting with a source PostgreSQL database, a logical replication /// slot should already be created and associated with the source endpoint. You can verify /// this by setting the slotName extra connection attribute to the name of /// this logical replication slot. For more information, see Extra /// Connection Attributes When Using PostgreSQL as a Source for DMS. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String CdcStartPosition { get; set; } #endregion #region Parameter CdcStartTime /// /// /// Indicates the start time for a change data capture (CDC) operation. Use either CdcStartTime /// or CdcStartPosition to specify when you want a CDC operation to start. Specifying /// both values results in an error.Timestamp Example: --cdc-start-time “2018-03-08T12:12:12” /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.DateTime? CdcStartTime { get; set; } #endregion #region Parameter CdcStopPosition /// /// /// Indicates when you want a change data capture (CDC) operation to stop. The value can /// be either server time or commit time.Server time example: --cdc-stop-position “server_time:2018-02-09T12:12:12”Commit time example: --cdc-stop-position “commit_time: 2018-02-09T12:12:12“ /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String CdcStopPosition { get; set; } #endregion #region Parameter MigrationType /// /// /// The migration type. Valid values: full-load | cdc | full-load-and-cdc /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [AWSConstantClassSource("Amazon.DatabaseMigrationService.MigrationTypeValue")] public Amazon.DatabaseMigrationService.MigrationTypeValue MigrationType { get; set; } #endregion #region Parameter ReplicationTaskArn /// /// /// The Amazon Resource Name (ARN) of the replication task. /// /// #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 ReplicationTaskArn { get; set; } #endregion #region Parameter ReplicationTaskIdentifier /// /// /// The replication task identifier.Constraints: /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String ReplicationTaskIdentifier { get; set; } #endregion #region Parameter ReplicationTaskSetting /// /// /// JSON file that contains settings for the task, such as task metadata settings. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [Alias("ReplicationTaskSettings")] public System.String ReplicationTaskSetting { get; set; } #endregion #region Parameter TableMapping /// /// /// When using the CLI or boto3, provide the path of the JSON file that contains the table /// mappings. Precede the path with file://. For example, --table-mappings /// file://mappingfile.json. When working with the DMS API, provide the JSON as /// the parameter value. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [Alias("TableMappings")] public System.String TableMapping { get; set; } #endregion #region Parameter TaskData /// /// /// Supplemental information that the task requires to migrate the data for certain source /// and target endpoints. For more information, see Specifying /// Supplemental Data for Task Settings in the Database Migration Service User /// Guide. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String TaskData { get; set; } #endregion #region Parameter Select /// /// Use the -Select parameter to control the cmdlet output. The default value is 'ReplicationTask'. /// Specifying -Select '*' will result in the cmdlet returning the whole service response (Amazon.DatabaseMigrationService.Model.ModifyReplicationTaskResponse). /// Specifying the name of a property of type Amazon.DatabaseMigrationService.Model.ModifyReplicationTaskResponse 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; } = "ReplicationTask"; #endregion #region Parameter PassThru /// /// Changes the cmdlet behavior to return the value passed to the ReplicationTaskArn parameter. /// The -PassThru parameter is deprecated, use -Select '^ReplicationTaskArn' instead. This parameter will be removed in a future version. /// [System.Obsolete("The -PassThru parameter is deprecated, use -Select '^ReplicationTaskArn' 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.ReplicationTaskArn), MyInvocation.BoundParameters); if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "Edit-DMSReplicationTask (ModifyReplicationTask)")) { 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.ReplicationTaskArn; } #pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute context.CdcStartPosition = this.CdcStartPosition; context.CdcStartTime = this.CdcStartTime; context.CdcStopPosition = this.CdcStopPosition; context.MigrationType = this.MigrationType; context.ReplicationTaskArn = this.ReplicationTaskArn; #if MODULAR if (this.ReplicationTaskArn == null && ParameterWasBound(nameof(this.ReplicationTaskArn))) { WriteWarning("You are passing $null as a value for parameter ReplicationTaskArn 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.ReplicationTaskIdentifier = this.ReplicationTaskIdentifier; context.ReplicationTaskSetting = this.ReplicationTaskSetting; context.TableMapping = this.TableMapping; context.TaskData = this.TaskData; // 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.DatabaseMigrationService.Model.ModifyReplicationTaskRequest(); if (cmdletContext.CdcStartPosition != null) { request.CdcStartPosition = cmdletContext.CdcStartPosition; } if (cmdletContext.CdcStartTime != null) { request.CdcStartTime = cmdletContext.CdcStartTime.Value; } if (cmdletContext.CdcStopPosition != null) { request.CdcStopPosition = cmdletContext.CdcStopPosition; } if (cmdletContext.MigrationType != null) { request.MigrationType = cmdletContext.MigrationType; } if (cmdletContext.ReplicationTaskArn != null) { request.ReplicationTaskArn = cmdletContext.ReplicationTaskArn; } if (cmdletContext.ReplicationTaskIdentifier != null) { request.ReplicationTaskIdentifier = cmdletContext.ReplicationTaskIdentifier; } if (cmdletContext.ReplicationTaskSetting != null) { request.ReplicationTaskSettings = cmdletContext.ReplicationTaskSetting; } if (cmdletContext.TableMapping != null) { request.TableMappings = cmdletContext.TableMapping; } if (cmdletContext.TaskData != null) { request.TaskData = cmdletContext.TaskData; } 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.DatabaseMigrationService.Model.ModifyReplicationTaskResponse CallAWSServiceOperation(IAmazonDatabaseMigrationService client, Amazon.DatabaseMigrationService.Model.ModifyReplicationTaskRequest request) { Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "AWS Database Migration Service", "ModifyReplicationTask"); try { #if DESKTOP return client.ModifyReplicationTask(request); #elif CORECLR return client.ModifyReplicationTaskAsync(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 CdcStartPosition { get; set; } public System.DateTime? CdcStartTime { get; set; } public System.String CdcStopPosition { get; set; } public Amazon.DatabaseMigrationService.MigrationTypeValue MigrationType { get; set; } public System.String ReplicationTaskArn { get; set; } public System.String ReplicationTaskIdentifier { get; set; } public System.String ReplicationTaskSetting { get; set; } public System.String TableMapping { get; set; } public System.String TaskData { get; set; } public System.Func Select { get; set; } = (response, cmdlet) => response.ReplicationTask; } } }