/*******************************************************************************
* 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.ForecastService;
using Amazon.ForecastService.Model;
namespace Amazon.PowerShell.Cmdlets.FRC
{
///
/// Creates an Amazon Forecast dataset. The information about the dataset that you provide
/// helps Forecast understand how to consume the data for model training. This includes
/// the following:
///
/// DataFrequency
- How frequently your historical time-series
/// data is collected.
/// Domain
and DatasetType
- Each dataset
/// has an associated dataset domain and a type within the domain. Amazon Forecast provides
/// a list of predefined domains and types within each domain. For each unique dataset
/// domain and type within the domain, Amazon Forecast requires your data to include a
/// minimum set of predefined fields.
/// Schema
- A schema specifies the fields in the dataset, including
/// the field name and data type.
///
/// After creating a dataset, you import your training data into it and add the dataset
/// to a dataset group. You use the dataset group to create a predictor. For more information,
/// see Importing
/// datasets.
///
/// To get a list of all your datasets, use the ListDatasets
/// operation.
///
/// For example Forecast datasets, see the Amazon
/// Forecast Sample GitHub repository.
///
/// The Status
of a dataset must be ACTIVE
before you can import
/// training data. Use the DescribeDataset
/// operation to get the status.
///
///
[Cmdlet("New", "FRCDataset", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)]
[OutputType("System.String")]
[AWSCmdlet("Calls the Amazon Forecast Service CreateDataset API operation.", Operation = new[] {"CreateDataset"}, SelectReturnType = typeof(Amazon.ForecastService.Model.CreateDatasetResponse))]
[AWSCmdletOutput("System.String or Amazon.ForecastService.Model.CreateDatasetResponse",
"This cmdlet returns a System.String object.",
"The service call response (type Amazon.ForecastService.Model.CreateDatasetResponse) can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack."
)]
public partial class NewFRCDatasetCmdlet : AmazonForecastServiceClientCmdlet, IExecutor
{
protected override bool IsSensitiveRequest { get; set; } = true;
#region Parameter Schema_Attribute
///
///
/// An array of attributes specifying the name and type of each field in a dataset.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("Schema_Attributes")]
public Amazon.ForecastService.Model.SchemaAttribute[] Schema_Attribute { get; set; }
#endregion
#region Parameter DataFrequency
///
///
/// The frequency of data collection. This parameter is required for RELATED_TIME_SERIES
/// datasets.Valid intervals are an integer followed by Y (Year), M (Month), W (Week), D (Day),
/// H (Hour), and min (Minute). For example, "1D" indicates every day and "15min" indicates
/// every 15 minutes. You cannot specify a value that would overlap with the next larger
/// frequency. That means, for example, you cannot specify a frequency of 60 minutes,
/// because that is equivalent to 1 hour. The valid values for each frequency are the
/// following:- Minute - 1-59
- Hour - 1-23
- Day - 1-6
- Week - 1-4
- Month - 1-11
- Year - 1
Thus, if you want every other week forecasts, specify "2W". Or, if you want quarterly
/// forecasts, you specify "3M".
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String DataFrequency { get; set; }
#endregion
#region Parameter DatasetName
///
///
/// A name for the dataset.
///
///
#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 DatasetName { get; set; }
#endregion
#region Parameter DatasetType
///
///
/// The dataset type. Valid values depend on the chosen Domain
.
///
///
#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.ForecastService.DatasetType")]
public Amazon.ForecastService.DatasetType DatasetType { get; set; }
#endregion
#region Parameter Domain
///
///
/// The domain associated with the dataset. When you add a dataset to a dataset group,
/// this value and the value specified for the Domain
parameter of the CreateDatasetGroup
/// operation must match.The Domain
and DatasetType
that you choose determine the
/// fields that must be present in the training data that you import to the dataset. For
/// example, if you choose the RETAIL
domain and TARGET_TIME_SERIES
/// as the DatasetType
, Amazon Forecast requires item_id
, timestamp
,
/// and demand
fields to be present in your data. For more information, see
/// Importing
/// datasets.
///
///
#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.ForecastService.Domain")]
public Amazon.ForecastService.Domain Domain { get; set; }
#endregion
#region Parameter EncryptionConfig_KMSKeyArn
///
///
/// The Amazon Resource Name (ARN) of the KMS key.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String EncryptionConfig_KMSKeyArn { get; set; }
#endregion
#region Parameter EncryptionConfig_RoleArn
///
///
/// The ARN of the IAM role that Amazon Forecast can assume to access the KMS key.Passing a role across Amazon Web Services accounts is not allowed. If you pass a role
/// that isn't in your account, you get an InvalidInputException
error.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String EncryptionConfig_RoleArn { get; set; }
#endregion
#region Parameter Tag
///
///
/// The optional metadata that you apply to the dataset to help you categorize and organize
/// them. Each tag consists of a key and an optional value, both of which you define.The following basic restrictions apply to tags:- Maximum number of tags per resource - 50.
- For each resource, each tag key must be unique, and each tag key can have only one
/// value.
- Maximum key length - 128 Unicode characters in UTF-8.
- Maximum value length - 256 Unicode characters in UTF-8.
- If your tagging schema is used across multiple services and resources, remember that
/// other services may have restrictions on allowed characters. Generally allowed characters
/// are: letters, numbers, and spaces representable in UTF-8, and the following characters:
/// + - = . _ : / @.
- Tag keys and values are case sensitive.
- Do not use
aws:
, AWS:
, or any upper or lowercase combination
/// of such as a prefix for keys as it is reserved for Amazon Web Services use. You cannot
/// edit or delete tag keys with this prefix. Values can have this prefix. If a tag value
/// has aws
as its prefix but the key does not, then Forecast considers it
/// to be a user tag and will count against the limit of 50 tags. Tags with only the key
/// prefix of aws
do not count against your tags per resource limit.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("Tags")]
public Amazon.ForecastService.Model.Tag[] Tag { get; set; }
#endregion
#region Parameter Select
///
/// Use the -Select parameter to control the cmdlet output. The default value is 'DatasetArn'.
/// Specifying -Select '*' will result in the cmdlet returning the whole service response (Amazon.ForecastService.Model.CreateDatasetResponse).
/// Specifying the name of a property of type Amazon.ForecastService.Model.CreateDatasetResponse 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; } = "DatasetArn";
#endregion
#region Parameter PassThru
///
/// Changes the cmdlet behavior to return the value passed to the DatasetName parameter.
/// The -PassThru parameter is deprecated, use -Select '^DatasetName' instead. This parameter will be removed in a future version.
///
[System.Obsolete("The -PassThru parameter is deprecated, use -Select '^DatasetName' 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.DatasetName), MyInvocation.BoundParameters);
if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "New-FRCDataset (CreateDataset)"))
{
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.DatasetName;
}
#pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute
context.DataFrequency = this.DataFrequency;
context.DatasetName = this.DatasetName;
#if MODULAR
if (this.DatasetName == null && ParameterWasBound(nameof(this.DatasetName)))
{
WriteWarning("You are passing $null as a value for parameter DatasetName 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.DatasetType = this.DatasetType;
#if MODULAR
if (this.DatasetType == null && ParameterWasBound(nameof(this.DatasetType)))
{
WriteWarning("You are passing $null as a value for parameter DatasetType 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.Domain = this.Domain;
#if MODULAR
if (this.Domain == null && ParameterWasBound(nameof(this.Domain)))
{
WriteWarning("You are passing $null as a value for parameter Domain 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.EncryptionConfig_KMSKeyArn = this.EncryptionConfig_KMSKeyArn;
context.EncryptionConfig_RoleArn = this.EncryptionConfig_RoleArn;
if (this.Schema_Attribute != null)
{
context.Schema_Attribute = new List(this.Schema_Attribute);
}
if (this.Tag != null)
{
context.Tag = new List(this.Tag);
}
// 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.ForecastService.Model.CreateDatasetRequest();
if (cmdletContext.DataFrequency != null)
{
request.DataFrequency = cmdletContext.DataFrequency;
}
if (cmdletContext.DatasetName != null)
{
request.DatasetName = cmdletContext.DatasetName;
}
if (cmdletContext.DatasetType != null)
{
request.DatasetType = cmdletContext.DatasetType;
}
if (cmdletContext.Domain != null)
{
request.Domain = cmdletContext.Domain;
}
// populate EncryptionConfig
var requestEncryptionConfigIsNull = true;
request.EncryptionConfig = new Amazon.ForecastService.Model.EncryptionConfig();
System.String requestEncryptionConfig_encryptionConfig_KMSKeyArn = null;
if (cmdletContext.EncryptionConfig_KMSKeyArn != null)
{
requestEncryptionConfig_encryptionConfig_KMSKeyArn = cmdletContext.EncryptionConfig_KMSKeyArn;
}
if (requestEncryptionConfig_encryptionConfig_KMSKeyArn != null)
{
request.EncryptionConfig.KMSKeyArn = requestEncryptionConfig_encryptionConfig_KMSKeyArn;
requestEncryptionConfigIsNull = false;
}
System.String requestEncryptionConfig_encryptionConfig_RoleArn = null;
if (cmdletContext.EncryptionConfig_RoleArn != null)
{
requestEncryptionConfig_encryptionConfig_RoleArn = cmdletContext.EncryptionConfig_RoleArn;
}
if (requestEncryptionConfig_encryptionConfig_RoleArn != null)
{
request.EncryptionConfig.RoleArn = requestEncryptionConfig_encryptionConfig_RoleArn;
requestEncryptionConfigIsNull = false;
}
// determine if request.EncryptionConfig should be set to null
if (requestEncryptionConfigIsNull)
{
request.EncryptionConfig = null;
}
// populate Schema
var requestSchemaIsNull = true;
request.Schema = new Amazon.ForecastService.Model.Schema();
List requestSchema_schema_Attribute = null;
if (cmdletContext.Schema_Attribute != null)
{
requestSchema_schema_Attribute = cmdletContext.Schema_Attribute;
}
if (requestSchema_schema_Attribute != null)
{
request.Schema.Attributes = requestSchema_schema_Attribute;
requestSchemaIsNull = false;
}
// determine if request.Schema should be set to null
if (requestSchemaIsNull)
{
request.Schema = null;
}
if (cmdletContext.Tag != null)
{
request.Tags = cmdletContext.Tag;
}
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.ForecastService.Model.CreateDatasetResponse CallAWSServiceOperation(IAmazonForecastService client, Amazon.ForecastService.Model.CreateDatasetRequest request)
{
Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon Forecast Service", "CreateDataset");
try
{
#if DESKTOP
return client.CreateDataset(request);
#elif CORECLR
return client.CreateDatasetAsync(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 DataFrequency { get; set; }
public System.String DatasetName { get; set; }
public Amazon.ForecastService.DatasetType DatasetType { get; set; }
public Amazon.ForecastService.Domain Domain { get; set; }
public System.String EncryptionConfig_KMSKeyArn { get; set; }
public System.String EncryptionConfig_RoleArn { get; set; }
public List Schema_Attribute { get; set; }
public List Tag { get; set; }
public System.Func Select { get; set; } =
(response, cmdlet) => response.DatasetArn;
}
}
}