/*******************************************************************************
* 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.ComputeOptimizer;
using Amazon.ComputeOptimizer.Model;
namespace Amazon.PowerShell.Cmdlets.CO
{
///
/// Exports optimization recommendations for Amazon ECS services on Fargate.
///
///
///
/// Recommendations are exported in a CSV file, and its metadata in a JSON file, to an
/// existing Amazon Simple Storage Service (Amazon S3) bucket that you specify. For more
/// information, see Exporting
/// Recommendations in the Compute Optimizer User Guide.
///
/// You can only have one Amazon ECS service export job in progress per Amazon Web Services
/// Region.
///
///
[Cmdlet("Export", "COECSServiceRecommendation", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)]
[OutputType("Amazon.ComputeOptimizer.Model.ExportECSServiceRecommendationsResponse")]
[AWSCmdlet("Calls the AWS Compute Optimizer ExportECSServiceRecommendations API operation.", Operation = new[] {"ExportECSServiceRecommendations"}, SelectReturnType = typeof(Amazon.ComputeOptimizer.Model.ExportECSServiceRecommendationsResponse))]
[AWSCmdletOutput("Amazon.ComputeOptimizer.Model.ExportECSServiceRecommendationsResponse",
"This cmdlet returns an Amazon.ComputeOptimizer.Model.ExportECSServiceRecommendationsResponse object containing multiple properties. The object can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack."
)]
public partial class ExportCOECSServiceRecommendationCmdlet : AmazonComputeOptimizerClientCmdlet, IExecutor
{
#region Parameter AccountId
///
///
/// The Amazon Web Services account IDs for the export Amazon ECS service recommendations.
/// If your account is the management account or the delegated administrator of an organization,
/// use this parameter to specify the member account you want to export recommendations
/// to.This parameter can't be specified together with the include member accounts parameter.
/// The parameters are mutually exclusive.If this parameter or the include member accounts parameter is omitted, the recommendations
/// for member accounts aren't included in the export.You can specify multiple account IDs per request.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("AccountIds")]
public System.String[] AccountId { get; set; }
#endregion
#region Parameter S3DestinationConfig_Bucket
///
///
/// The name of the Amazon S3 bucket to use as the destination for an export job.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String S3DestinationConfig_Bucket { get; set; }
#endregion
#region Parameter FieldsToExport
///
///
/// The recommendations data to include in the export file. For more information about
/// the fields that can be exported, see Exported
/// files in the Compute Optimizer User Guide.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String[] FieldsToExport { get; set; }
#endregion
#region Parameter FileFormat
///
///
/// The format of the export file. The CSV file is the only export file format currently supported.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[AWSConstantClassSource("Amazon.ComputeOptimizer.FileFormat")]
public Amazon.ComputeOptimizer.FileFormat FileFormat { get; set; }
#endregion
#region Parameter Filter
///
///
/// An array of objects to specify a filter that exports a more specific set of Amazon
/// ECS service recommendations.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("Filters")]
public Amazon.ComputeOptimizer.Model.ECSServiceRecommendationFilter[] Filter { get; set; }
#endregion
#region Parameter IncludeMemberAccount
///
///
/// If your account is the management account or the delegated administrator of an organization,
/// this parameter indicates whether to include recommendations for resources in all member
/// accounts of the organization.The member accounts must also be opted in to Compute Optimizer, and trusted access
/// for Compute Optimizer must be enabled in the organization account. For more information,
/// see Compute
/// Optimizer and Amazon Web Services Organizations trusted access in the Compute
/// Optimizer User Guide.If this parameter is omitted, recommendations for member accounts of the organization
/// aren't included in the export file.If this parameter or the account ID parameter is omitted, recommendations for member
/// accounts aren't included in the export.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("IncludeMemberAccounts")]
public System.Boolean? IncludeMemberAccount { get; set; }
#endregion
#region Parameter S3DestinationConfig_KeyPrefix
///
///
/// The Amazon S3 bucket prefix for an export job.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String S3DestinationConfig_KeyPrefix { 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.ComputeOptimizer.Model.ExportECSServiceRecommendationsResponse).
/// Specifying the name of a property of type Amazon.ComputeOptimizer.Model.ExportECSServiceRecommendationsResponse 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 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 = string.Empty;
if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "Export-COECSServiceRecommendation (ExportECSServiceRecommendations)"))
{
return;
}
var context = new CmdletContext();
// allow for manipulation of parameters prior to loading into context
PreExecutionContextLoad(context);
if (ParameterWasBound(nameof(this.Select)))
{
context.Select = CreateSelectDelegate(Select) ??
throw new System.ArgumentException("Invalid value for -Select parameter.", nameof(this.Select));
}
if (this.AccountId != null)
{
context.AccountId = new List(this.AccountId);
}
if (this.FieldsToExport != null)
{
context.FieldsToExport = new List(this.FieldsToExport);
}
context.FileFormat = this.FileFormat;
if (this.Filter != null)
{
context.Filter = new List(this.Filter);
}
context.IncludeMemberAccount = this.IncludeMemberAccount;
context.S3DestinationConfig_Bucket = this.S3DestinationConfig_Bucket;
context.S3DestinationConfig_KeyPrefix = this.S3DestinationConfig_KeyPrefix;
// 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.ComputeOptimizer.Model.ExportECSServiceRecommendationsRequest();
if (cmdletContext.AccountId != null)
{
request.AccountIds = cmdletContext.AccountId;
}
if (cmdletContext.FieldsToExport != null)
{
request.FieldsToExport = cmdletContext.FieldsToExport;
}
if (cmdletContext.FileFormat != null)
{
request.FileFormat = cmdletContext.FileFormat;
}
if (cmdletContext.Filter != null)
{
request.Filters = cmdletContext.Filter;
}
if (cmdletContext.IncludeMemberAccount != null)
{
request.IncludeMemberAccounts = cmdletContext.IncludeMemberAccount.Value;
}
// populate S3DestinationConfig
var requestS3DestinationConfigIsNull = true;
request.S3DestinationConfig = new Amazon.ComputeOptimizer.Model.S3DestinationConfig();
System.String requestS3DestinationConfig_s3DestinationConfig_Bucket = null;
if (cmdletContext.S3DestinationConfig_Bucket != null)
{
requestS3DestinationConfig_s3DestinationConfig_Bucket = cmdletContext.S3DestinationConfig_Bucket;
}
if (requestS3DestinationConfig_s3DestinationConfig_Bucket != null)
{
request.S3DestinationConfig.Bucket = requestS3DestinationConfig_s3DestinationConfig_Bucket;
requestS3DestinationConfigIsNull = false;
}
System.String requestS3DestinationConfig_s3DestinationConfig_KeyPrefix = null;
if (cmdletContext.S3DestinationConfig_KeyPrefix != null)
{
requestS3DestinationConfig_s3DestinationConfig_KeyPrefix = cmdletContext.S3DestinationConfig_KeyPrefix;
}
if (requestS3DestinationConfig_s3DestinationConfig_KeyPrefix != null)
{
request.S3DestinationConfig.KeyPrefix = requestS3DestinationConfig_s3DestinationConfig_KeyPrefix;
requestS3DestinationConfigIsNull = false;
}
// determine if request.S3DestinationConfig should be set to null
if (requestS3DestinationConfigIsNull)
{
request.S3DestinationConfig = null;
}
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.ComputeOptimizer.Model.ExportECSServiceRecommendationsResponse CallAWSServiceOperation(IAmazonComputeOptimizer client, Amazon.ComputeOptimizer.Model.ExportECSServiceRecommendationsRequest request)
{
Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "AWS Compute Optimizer", "ExportECSServiceRecommendations");
try
{
#if DESKTOP
return client.ExportECSServiceRecommendations(request);
#elif CORECLR
return client.ExportECSServiceRecommendationsAsync(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 List AccountId { get; set; }
public List FieldsToExport { get; set; }
public Amazon.ComputeOptimizer.FileFormat FileFormat { get; set; }
public List Filter { get; set; }
public System.Boolean? IncludeMemberAccount { get; set; }
public System.String S3DestinationConfig_Bucket { get; set; }
public System.String S3DestinationConfig_KeyPrefix { get; set; }
public System.Func Select { get; set; } =
(response, cmdlet) => response;
}
}
}