/*******************************************************************************
* 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
{
///
/// Creates a replication task using the specified parameters.
///
[Cmdlet("New", "DMSReplicationTask", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)]
[OutputType("Amazon.DatabaseMigrationService.Model.ReplicationTask")]
[AWSCmdlet("Calls the AWS Database Migration Service CreateReplicationTask API operation.", Operation = new[] {"CreateReplicationTask"}, SelectReturnType = typeof(Amazon.DatabaseMigrationService.Model.CreateReplicationTaskResponse))]
[AWSCmdletOutput("Amazon.DatabaseMigrationService.Model.ReplicationTask or Amazon.DatabaseMigrationService.Model.CreateReplicationTaskResponse",
"This cmdlet returns an Amazon.DatabaseMigrationService.Model.ReplicationTask object.",
"The service call response (type Amazon.DatabaseMigrationService.Model.CreateReplicationTaskResponse) can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack."
)]
public partial class NewDMSReplicationTaskCmdlet : 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
///
///
#if !MODULAR
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
#else
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true, Mandatory = true)]
[System.Management.Automation.AllowNull]
#endif
[Amazon.PowerShell.Common.AWSRequiredParameter]
[AWSConstantClassSource("Amazon.DatabaseMigrationService.MigrationTypeValue")]
public Amazon.DatabaseMigrationService.MigrationTypeValue MigrationType { get; set; }
#endregion
#region Parameter ReplicationInstanceArn
///
///
/// The Amazon Resource Name (ARN) of a replication instance.
///
///
#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 ReplicationInstanceArn { get; set; }
#endregion
#region Parameter ReplicationTaskIdentifier
///
///
/// An identifier for the replication task.Constraints:- Must contain 1-255 alphanumeric characters or hyphens.
- First character must be a letter.
- Cannot end with a hyphen or contain two consecutive hyphens.
///
///
#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 ReplicationTaskIdentifier { get; set; }
#endregion
#region Parameter ReplicationTaskSetting
///
///
/// Overall settings for the task, in JSON format. For more information, see Specifying
/// Task Settings for Database Migration Service Tasks in the Database Migration
/// Service User Guide.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("ReplicationTaskSettings")]
public System.String ReplicationTaskSetting { get; set; }
#endregion
#region Parameter ResourceIdentifier
///
///
/// A friendly name for the resource identifier at the end of the EndpointArn
/// response parameter that is returned in the created Endpoint
object. The
/// value for this parameter can have up to 31 characters. It can contain only ASCII letters,
/// digits, and hyphen ('-'). Also, it can't end with a hyphen or contain two consecutive
/// hyphens, and can only begin with a letter, such as Example-App-ARN1
.
/// For example, this value might result in the EndpointArn
value arn:aws:dms:eu-west-1:012345678901:rep:Example-App-ARN1
.
/// If you don't specify a ResourceIdentifier
value, DMS generates a default
/// identifier value for the end of EndpointArn
.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String ResourceIdentifier { get; set; }
#endregion
#region Parameter SourceEndpointArn
///
///
/// An Amazon Resource Name (ARN) that uniquely identifies the source endpoint.
///
///
#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 SourceEndpointArn { get; set; }
#endregion
#region Parameter TableMapping
///
///
/// The table mappings for the task, in JSON format. For more information, see Using
/// Table Mapping to Specify Task Settings in the Database Migration Service User
/// Guide.
///
///
#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]
[Alias("TableMappings")]
public System.String TableMapping { get; set; }
#endregion
#region Parameter Tag
///
///
/// One or more tags to be assigned to the replication task.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("Tags")]
public Amazon.DatabaseMigrationService.Model.Tag[] Tag { get; set; }
#endregion
#region Parameter TargetEndpointArn
///
///
/// An Amazon Resource Name (ARN) that uniquely identifies the target endpoint.
///
///
#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 TargetEndpointArn { 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.CreateReplicationTaskResponse).
/// Specifying the name of a property of type Amazon.DatabaseMigrationService.Model.CreateReplicationTaskResponse 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 ReplicationInstanceArn parameter.
/// The -PassThru parameter is deprecated, use -Select '^ReplicationInstanceArn' instead. This parameter will be removed in a future version.
///
[System.Obsolete("The -PassThru parameter is deprecated, use -Select '^ReplicationInstanceArn' 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.ReplicationInstanceArn), MyInvocation.BoundParameters);
if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "New-DMSReplicationTask (CreateReplicationTask)"))
{
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.ReplicationInstanceArn;
}
#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;
#if MODULAR
if (this.MigrationType == null && ParameterWasBound(nameof(this.MigrationType)))
{
WriteWarning("You are passing $null as a value for parameter MigrationType 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.ReplicationInstanceArn = this.ReplicationInstanceArn;
#if MODULAR
if (this.ReplicationInstanceArn == null && ParameterWasBound(nameof(this.ReplicationInstanceArn)))
{
WriteWarning("You are passing $null as a value for parameter ReplicationInstanceArn 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;
#if MODULAR
if (this.ReplicationTaskIdentifier == null && ParameterWasBound(nameof(this.ReplicationTaskIdentifier)))
{
WriteWarning("You are passing $null as a value for parameter ReplicationTaskIdentifier 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.ReplicationTaskSetting = this.ReplicationTaskSetting;
context.ResourceIdentifier = this.ResourceIdentifier;
context.SourceEndpointArn = this.SourceEndpointArn;
#if MODULAR
if (this.SourceEndpointArn == null && ParameterWasBound(nameof(this.SourceEndpointArn)))
{
WriteWarning("You are passing $null as a value for parameter SourceEndpointArn 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.TableMapping = this.TableMapping;
#if MODULAR
if (this.TableMapping == null && ParameterWasBound(nameof(this.TableMapping)))
{
WriteWarning("You are passing $null as a value for parameter TableMapping 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
if (this.Tag != null)
{
context.Tag = new List(this.Tag);
}
context.TargetEndpointArn = this.TargetEndpointArn;
#if MODULAR
if (this.TargetEndpointArn == null && ParameterWasBound(nameof(this.TargetEndpointArn)))
{
WriteWarning("You are passing $null as a value for parameter TargetEndpointArn 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.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.CreateReplicationTaskRequest();
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.ReplicationInstanceArn != null)
{
request.ReplicationInstanceArn = cmdletContext.ReplicationInstanceArn;
}
if (cmdletContext.ReplicationTaskIdentifier != null)
{
request.ReplicationTaskIdentifier = cmdletContext.ReplicationTaskIdentifier;
}
if (cmdletContext.ReplicationTaskSetting != null)
{
request.ReplicationTaskSettings = cmdletContext.ReplicationTaskSetting;
}
if (cmdletContext.ResourceIdentifier != null)
{
request.ResourceIdentifier = cmdletContext.ResourceIdentifier;
}
if (cmdletContext.SourceEndpointArn != null)
{
request.SourceEndpointArn = cmdletContext.SourceEndpointArn;
}
if (cmdletContext.TableMapping != null)
{
request.TableMappings = cmdletContext.TableMapping;
}
if (cmdletContext.Tag != null)
{
request.Tags = cmdletContext.Tag;
}
if (cmdletContext.TargetEndpointArn != null)
{
request.TargetEndpointArn = cmdletContext.TargetEndpointArn;
}
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.CreateReplicationTaskResponse CallAWSServiceOperation(IAmazonDatabaseMigrationService client, Amazon.DatabaseMigrationService.Model.CreateReplicationTaskRequest request)
{
Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "AWS Database Migration Service", "CreateReplicationTask");
try
{
#if DESKTOP
return client.CreateReplicationTask(request);
#elif CORECLR
return client.CreateReplicationTaskAsync(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 ReplicationInstanceArn { get; set; }
public System.String ReplicationTaskIdentifier { get; set; }
public System.String ReplicationTaskSetting { get; set; }
public System.String ResourceIdentifier { get; set; }
public System.String SourceEndpointArn { get; set; }
public System.String TableMapping { get; set; }
public List Tag { get; set; }
public System.String TargetEndpointArn { get; set; }
public System.String TaskData { get; set; }
public System.Func Select { get; set; } =
(response, cmdlet) => response.ReplicationTask;
}
}
}