/*******************************************************************************
* 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.EMRServerless;
using Amazon.EMRServerless.Model;
namespace Amazon.PowerShell.Cmdlets.EMRServerless
{
///
/// Creates an application.
///
[Cmdlet("New", "EMRServerlessApplication", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)]
[OutputType("Amazon.EMRServerless.Model.CreateApplicationResponse")]
[AWSCmdlet("Calls the EMR Serverless CreateApplication API operation.", Operation = new[] {"CreateApplication"}, SelectReturnType = typeof(Amazon.EMRServerless.Model.CreateApplicationResponse))]
[AWSCmdletOutput("Amazon.EMRServerless.Model.CreateApplicationResponse",
"This cmdlet returns an Amazon.EMRServerless.Model.CreateApplicationResponse object containing multiple properties. The object can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack."
)]
public partial class NewEMRServerlessApplicationCmdlet : AmazonEMRServerlessClientCmdlet, IExecutor
{
#region Parameter Architecture
///
///
/// The CPU architecture of an application.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[AWSConstantClassSource("Amazon.EMRServerless.Architecture")]
public Amazon.EMRServerless.Architecture Architecture { get; set; }
#endregion
#region Parameter MaximumCapacity_Cpu
///
///
/// The maximum allowed CPU for an application.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String MaximumCapacity_Cpu { get; set; }
#endregion
#region Parameter MaximumCapacity_Disk
///
///
/// The maximum allowed disk for an application.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String MaximumCapacity_Disk { get; set; }
#endregion
#region Parameter AutoStartConfiguration_Enabled
///
///
/// Enables the application to automatically start on job submission. Defaults to true.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.Boolean? AutoStartConfiguration_Enabled { get; set; }
#endregion
#region Parameter AutoStopConfiguration_Enabled
///
///
/// Enables the application to automatically stop after a certain amount of time being
/// idle. Defaults to true.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.Boolean? AutoStopConfiguration_Enabled { get; set; }
#endregion
#region Parameter AutoStopConfiguration_IdleTimeoutMinute
///
///
/// The amount of idle time in minutes after which your application will automatically
/// stop. Defaults to 15 minutes.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("AutoStopConfiguration_IdleTimeoutMinutes")]
public System.Int32? AutoStopConfiguration_IdleTimeoutMinute { get; set; }
#endregion
#region Parameter ImageConfiguration_ImageUri
///
///
/// The URI of an image in the Amazon ECR registry. This field is required when you create
/// a new application. If you leave this field blank in an update, Amazon EMR will remove
/// the image configuration.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String ImageConfiguration_ImageUri { get; set; }
#endregion
#region Parameter InitialCapacity
///
///
/// The capacity to initialize when the application is created.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.Collections.Hashtable InitialCapacity { get; set; }
#endregion
#region Parameter MaximumCapacity_Memory
///
///
/// The maximum allowed resources for an application.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String MaximumCapacity_Memory { get; set; }
#endregion
#region Parameter Name
///
///
/// The name of the application.
///
///
[System.Management.Automation.Parameter(Position = 0, ValueFromPipelineByPropertyName = true, ValueFromPipeline = true)]
public System.String Name { get; set; }
#endregion
#region Parameter ReleaseLabel
///
///
/// The Amazon EMR release associated with the application.
///
///
#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 ReleaseLabel { get; set; }
#endregion
#region Parameter NetworkConfiguration_SecurityGroupId
///
///
/// The array of security group Ids for customer VPC connectivity.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("NetworkConfiguration_SecurityGroupIds")]
public System.String[] NetworkConfiguration_SecurityGroupId { get; set; }
#endregion
#region Parameter NetworkConfiguration_SubnetId
///
///
/// The array of subnet Ids for customer VPC connectivity.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("NetworkConfiguration_SubnetIds")]
public System.String[] NetworkConfiguration_SubnetId { get; set; }
#endregion
#region Parameter Tag
///
///
/// The tags assigned to the application.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("Tags")]
public System.Collections.Hashtable Tag { get; set; }
#endregion
#region Parameter Type
///
///
/// The type of application you want to start, such as Spark or Hive.
///
///
#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 Type { get; set; }
#endregion
#region Parameter WorkerTypeSpecification
///
///
/// The key-value pairs that specify worker type to WorkerTypeSpecificationInput
.
/// This parameter must contain all valid worker types for a Spark or Hive application.
/// Valid worker types include Driver
and Executor
for Spark
/// applications and HiveDriver
and TezTask
for Hive applications.
/// You can either set image details in this parameter for each worker type, or in imageConfiguration
/// for all worker types.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("WorkerTypeSpecifications")]
public System.Collections.Hashtable WorkerTypeSpecification { get; set; }
#endregion
#region Parameter ClientToken
///
///
/// The client idempotency token of the application to create. Its value must be unique
/// for each request.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String ClientToken { get; set; }
#endregion
#region Parameter Select
///
/// Use the -Select parameter to control the cmdlet output. The default value is '*'.
/// Specifying -Select '*' will result in the cmdlet returning the whole service response (Amazon.EMRServerless.Model.CreateApplicationResponse).
/// Specifying the name of a property of type Amazon.EMRServerless.Model.CreateApplicationResponse 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; } = "*";
#endregion
#region Parameter PassThru
///
/// Changes the cmdlet behavior to return the value passed to the Name parameter.
/// The -PassThru parameter is deprecated, use -Select '^Name' instead. This parameter will be removed in a future version.
///
[System.Obsolete("The -PassThru parameter is deprecated, use -Select '^Name' 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.Name), MyInvocation.BoundParameters);
if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "New-EMRServerlessApplication (CreateApplication)"))
{
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.Name;
}
#pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute
context.Architecture = this.Architecture;
context.AutoStartConfiguration_Enabled = this.AutoStartConfiguration_Enabled;
context.AutoStopConfiguration_Enabled = this.AutoStopConfiguration_Enabled;
context.AutoStopConfiguration_IdleTimeoutMinute = this.AutoStopConfiguration_IdleTimeoutMinute;
context.ClientToken = this.ClientToken;
context.ImageConfiguration_ImageUri = this.ImageConfiguration_ImageUri;
if (this.InitialCapacity != null)
{
context.InitialCapacity = new Dictionary(StringComparer.Ordinal);
foreach (var hashKey in this.InitialCapacity.Keys)
{
context.InitialCapacity.Add((String)hashKey, (InitialCapacityConfig)(this.InitialCapacity[hashKey]));
}
}
context.MaximumCapacity_Cpu = this.MaximumCapacity_Cpu;
context.MaximumCapacity_Disk = this.MaximumCapacity_Disk;
context.MaximumCapacity_Memory = this.MaximumCapacity_Memory;
context.Name = this.Name;
if (this.NetworkConfiguration_SecurityGroupId != null)
{
context.NetworkConfiguration_SecurityGroupId = new List(this.NetworkConfiguration_SecurityGroupId);
}
if (this.NetworkConfiguration_SubnetId != null)
{
context.NetworkConfiguration_SubnetId = new List(this.NetworkConfiguration_SubnetId);
}
context.ReleaseLabel = this.ReleaseLabel;
#if MODULAR
if (this.ReleaseLabel == null && ParameterWasBound(nameof(this.ReleaseLabel)))
{
WriteWarning("You are passing $null as a value for parameter ReleaseLabel 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 Dictionary(StringComparer.Ordinal);
foreach (var hashKey in this.Tag.Keys)
{
context.Tag.Add((String)hashKey, (String)(this.Tag[hashKey]));
}
}
context.Type = this.Type;
#if MODULAR
if (this.Type == null && ParameterWasBound(nameof(this.Type)))
{
WriteWarning("You are passing $null as a value for parameter Type 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.WorkerTypeSpecification != null)
{
context.WorkerTypeSpecification = new Dictionary(StringComparer.Ordinal);
foreach (var hashKey in this.WorkerTypeSpecification.Keys)
{
context.WorkerTypeSpecification.Add((String)hashKey, (WorkerTypeSpecificationInput)(this.WorkerTypeSpecification[hashKey]));
}
}
// 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.EMRServerless.Model.CreateApplicationRequest();
if (cmdletContext.Architecture != null)
{
request.Architecture = cmdletContext.Architecture;
}
// populate AutoStartConfiguration
var requestAutoStartConfigurationIsNull = true;
request.AutoStartConfiguration = new Amazon.EMRServerless.Model.AutoStartConfig();
System.Boolean? requestAutoStartConfiguration_autoStartConfiguration_Enabled = null;
if (cmdletContext.AutoStartConfiguration_Enabled != null)
{
requestAutoStartConfiguration_autoStartConfiguration_Enabled = cmdletContext.AutoStartConfiguration_Enabled.Value;
}
if (requestAutoStartConfiguration_autoStartConfiguration_Enabled != null)
{
request.AutoStartConfiguration.Enabled = requestAutoStartConfiguration_autoStartConfiguration_Enabled.Value;
requestAutoStartConfigurationIsNull = false;
}
// determine if request.AutoStartConfiguration should be set to null
if (requestAutoStartConfigurationIsNull)
{
request.AutoStartConfiguration = null;
}
// populate AutoStopConfiguration
var requestAutoStopConfigurationIsNull = true;
request.AutoStopConfiguration = new Amazon.EMRServerless.Model.AutoStopConfig();
System.Boolean? requestAutoStopConfiguration_autoStopConfiguration_Enabled = null;
if (cmdletContext.AutoStopConfiguration_Enabled != null)
{
requestAutoStopConfiguration_autoStopConfiguration_Enabled = cmdletContext.AutoStopConfiguration_Enabled.Value;
}
if (requestAutoStopConfiguration_autoStopConfiguration_Enabled != null)
{
request.AutoStopConfiguration.Enabled = requestAutoStopConfiguration_autoStopConfiguration_Enabled.Value;
requestAutoStopConfigurationIsNull = false;
}
System.Int32? requestAutoStopConfiguration_autoStopConfiguration_IdleTimeoutMinute = null;
if (cmdletContext.AutoStopConfiguration_IdleTimeoutMinute != null)
{
requestAutoStopConfiguration_autoStopConfiguration_IdleTimeoutMinute = cmdletContext.AutoStopConfiguration_IdleTimeoutMinute.Value;
}
if (requestAutoStopConfiguration_autoStopConfiguration_IdleTimeoutMinute != null)
{
request.AutoStopConfiguration.IdleTimeoutMinutes = requestAutoStopConfiguration_autoStopConfiguration_IdleTimeoutMinute.Value;
requestAutoStopConfigurationIsNull = false;
}
// determine if request.AutoStopConfiguration should be set to null
if (requestAutoStopConfigurationIsNull)
{
request.AutoStopConfiguration = null;
}
if (cmdletContext.ClientToken != null)
{
request.ClientToken = cmdletContext.ClientToken;
}
// populate ImageConfiguration
var requestImageConfigurationIsNull = true;
request.ImageConfiguration = new Amazon.EMRServerless.Model.ImageConfigurationInput();
System.String requestImageConfiguration_imageConfiguration_ImageUri = null;
if (cmdletContext.ImageConfiguration_ImageUri != null)
{
requestImageConfiguration_imageConfiguration_ImageUri = cmdletContext.ImageConfiguration_ImageUri;
}
if (requestImageConfiguration_imageConfiguration_ImageUri != null)
{
request.ImageConfiguration.ImageUri = requestImageConfiguration_imageConfiguration_ImageUri;
requestImageConfigurationIsNull = false;
}
// determine if request.ImageConfiguration should be set to null
if (requestImageConfigurationIsNull)
{
request.ImageConfiguration = null;
}
if (cmdletContext.InitialCapacity != null)
{
request.InitialCapacity = cmdletContext.InitialCapacity;
}
// populate MaximumCapacity
var requestMaximumCapacityIsNull = true;
request.MaximumCapacity = new Amazon.EMRServerless.Model.MaximumAllowedResources();
System.String requestMaximumCapacity_maximumCapacity_Cpu = null;
if (cmdletContext.MaximumCapacity_Cpu != null)
{
requestMaximumCapacity_maximumCapacity_Cpu = cmdletContext.MaximumCapacity_Cpu;
}
if (requestMaximumCapacity_maximumCapacity_Cpu != null)
{
request.MaximumCapacity.Cpu = requestMaximumCapacity_maximumCapacity_Cpu;
requestMaximumCapacityIsNull = false;
}
System.String requestMaximumCapacity_maximumCapacity_Disk = null;
if (cmdletContext.MaximumCapacity_Disk != null)
{
requestMaximumCapacity_maximumCapacity_Disk = cmdletContext.MaximumCapacity_Disk;
}
if (requestMaximumCapacity_maximumCapacity_Disk != null)
{
request.MaximumCapacity.Disk = requestMaximumCapacity_maximumCapacity_Disk;
requestMaximumCapacityIsNull = false;
}
System.String requestMaximumCapacity_maximumCapacity_Memory = null;
if (cmdletContext.MaximumCapacity_Memory != null)
{
requestMaximumCapacity_maximumCapacity_Memory = cmdletContext.MaximumCapacity_Memory;
}
if (requestMaximumCapacity_maximumCapacity_Memory != null)
{
request.MaximumCapacity.Memory = requestMaximumCapacity_maximumCapacity_Memory;
requestMaximumCapacityIsNull = false;
}
// determine if request.MaximumCapacity should be set to null
if (requestMaximumCapacityIsNull)
{
request.MaximumCapacity = null;
}
if (cmdletContext.Name != null)
{
request.Name = cmdletContext.Name;
}
// populate NetworkConfiguration
var requestNetworkConfigurationIsNull = true;
request.NetworkConfiguration = new Amazon.EMRServerless.Model.NetworkConfiguration();
List requestNetworkConfiguration_networkConfiguration_SecurityGroupId = null;
if (cmdletContext.NetworkConfiguration_SecurityGroupId != null)
{
requestNetworkConfiguration_networkConfiguration_SecurityGroupId = cmdletContext.NetworkConfiguration_SecurityGroupId;
}
if (requestNetworkConfiguration_networkConfiguration_SecurityGroupId != null)
{
request.NetworkConfiguration.SecurityGroupIds = requestNetworkConfiguration_networkConfiguration_SecurityGroupId;
requestNetworkConfigurationIsNull = false;
}
List requestNetworkConfiguration_networkConfiguration_SubnetId = null;
if (cmdletContext.NetworkConfiguration_SubnetId != null)
{
requestNetworkConfiguration_networkConfiguration_SubnetId = cmdletContext.NetworkConfiguration_SubnetId;
}
if (requestNetworkConfiguration_networkConfiguration_SubnetId != null)
{
request.NetworkConfiguration.SubnetIds = requestNetworkConfiguration_networkConfiguration_SubnetId;
requestNetworkConfigurationIsNull = false;
}
// determine if request.NetworkConfiguration should be set to null
if (requestNetworkConfigurationIsNull)
{
request.NetworkConfiguration = null;
}
if (cmdletContext.ReleaseLabel != null)
{
request.ReleaseLabel = cmdletContext.ReleaseLabel;
}
if (cmdletContext.Tag != null)
{
request.Tags = cmdletContext.Tag;
}
if (cmdletContext.Type != null)
{
request.Type = cmdletContext.Type;
}
if (cmdletContext.WorkerTypeSpecification != null)
{
request.WorkerTypeSpecifications = cmdletContext.WorkerTypeSpecification;
}
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.EMRServerless.Model.CreateApplicationResponse CallAWSServiceOperation(IAmazonEMRServerless client, Amazon.EMRServerless.Model.CreateApplicationRequest request)
{
Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "EMR Serverless", "CreateApplication");
try
{
#if DESKTOP
return client.CreateApplication(request);
#elif CORECLR
return client.CreateApplicationAsync(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 Amazon.EMRServerless.Architecture Architecture { get; set; }
public System.Boolean? AutoStartConfiguration_Enabled { get; set; }
public System.Boolean? AutoStopConfiguration_Enabled { get; set; }
public System.Int32? AutoStopConfiguration_IdleTimeoutMinute { get; set; }
public System.String ClientToken { get; set; }
public System.String ImageConfiguration_ImageUri { get; set; }
public Dictionary InitialCapacity { get; set; }
public System.String MaximumCapacity_Cpu { get; set; }
public System.String MaximumCapacity_Disk { get; set; }
public System.String MaximumCapacity_Memory { get; set; }
public System.String Name { get; set; }
public List NetworkConfiguration_SecurityGroupId { get; set; }
public List NetworkConfiguration_SubnetId { get; set; }
public System.String ReleaseLabel { get; set; }
public Dictionary Tag { get; set; }
public System.String Type { get; set; }
public Dictionary WorkerTypeSpecification { get; set; }
public System.Func Select { get; set; } =
(response, cmdlet) => response;
}
}
}