/*******************************************************************************
* 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.Personalize;
using Amazon.Personalize.Model;
namespace Amazon.PowerShell.Cmdlets.PERS
{
///
/// Amazon.Personalize.IAmazonPersonalize.CreateRecommender
///
[Cmdlet("New", "PERSRecommender", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)]
[OutputType("System.String")]
[AWSCmdlet("Calls the AWS Personalize CreateRecommender API operation.", Operation = new[] {"CreateRecommender"}, SelectReturnType = typeof(Amazon.Personalize.Model.CreateRecommenderResponse))]
[AWSCmdletOutput("System.String or Amazon.Personalize.Model.CreateRecommenderResponse",
"This cmdlet returns a System.String object.",
"The service call response (type Amazon.Personalize.Model.CreateRecommenderResponse) can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack."
)]
public partial class NewPERSRecommenderCmdlet : AmazonPersonalizeClientCmdlet, IExecutor
{
#region Parameter DatasetGroupArn
///
///
/// The Amazon Resource Name (ARN) of the destination domain dataset group for the recommender.
///
///
#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 DatasetGroupArn { get; set; }
#endregion
#region Parameter TrainingDataConfig_ExcludedDatasetColumn
///
///
/// Specifies the columns to exclude from training. Each key is a dataset type, and each
/// value is a list of columns. Exclude columns to control what data Amazon Personalize
/// uses to generate recommendations. For example, you might have a column that you want
/// to use only to filter recommendations. You can exclude this column from training and
/// Amazon Personalize considers it only when filtering.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("RecommenderConfig_TrainingDataConfig_ExcludedDatasetColumns")]
public System.Collections.Hashtable TrainingDataConfig_ExcludedDatasetColumn { get; set; }
#endregion
#region Parameter RecommenderConfig_ItemExplorationConfig
///
///
/// Specifies the exploration configuration hyperparameters, including explorationWeight
/// and explorationItemAgeCutOff
, you want to use to configure the amount
/// of item exploration Amazon Personalize uses when recommending items. Provide itemExplorationConfig
/// data only if your recommenders generate personalized recommendations for a user (not
/// popular items or similar items).
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.Collections.Hashtable RecommenderConfig_ItemExplorationConfig { get; set; }
#endregion
#region Parameter RecommenderConfig_MinRecommendationRequestsPerSecond
///
///
/// Specifies the requested minimum provisioned recommendation requests per second that
/// Amazon Personalize will support. A high minRecommendationRequestsPerSecond
/// will increase your bill. We recommend starting with 1 for minRecommendationRequestsPerSecond
/// (the default). Track your usage using Amazon CloudWatch metrics, and increase the
/// minRecommendationRequestsPerSecond
as necessary.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.Int32? RecommenderConfig_MinRecommendationRequestsPerSecond { get; set; }
#endregion
#region Parameter Name
///
///
/// The name of the recommender.
///
///
#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 Name { get; set; }
#endregion
#region Parameter RecipeArn
///
///
/// The Amazon Resource Name (ARN) of the recipe that the recommender will use. For a
/// recommender, a recipe is a Domain dataset group use case. Only Domain dataset group
/// use cases can be used to create a recommender. For information about use cases see
/// Choosing
/// recommender use cases.
///
///
#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 RecipeArn { get; set; }
#endregion
#region Parameter Tag
///
///
/// A list of tags
/// to apply to the recommender.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("Tags")]
public Amazon.Personalize.Model.Tag[] Tag { get; set; }
#endregion
#region Parameter Select
///
/// Use the -Select parameter to control the cmdlet output. The default value is 'RecommenderArn'.
/// Specifying -Select '*' will result in the cmdlet returning the whole service response (Amazon.Personalize.Model.CreateRecommenderResponse).
/// Specifying the name of a property of type Amazon.Personalize.Model.CreateRecommenderResponse 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; } = "RecommenderArn";
#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-PERSRecommender (CreateRecommender)"))
{
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.DatasetGroupArn = this.DatasetGroupArn;
#if MODULAR
if (this.DatasetGroupArn == null && ParameterWasBound(nameof(this.DatasetGroupArn)))
{
WriteWarning("You are passing $null as a value for parameter DatasetGroupArn 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.Name = this.Name;
#if MODULAR
if (this.Name == null && ParameterWasBound(nameof(this.Name)))
{
WriteWarning("You are passing $null as a value for parameter Name 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.RecipeArn = this.RecipeArn;
#if MODULAR
if (this.RecipeArn == null && ParameterWasBound(nameof(this.RecipeArn)))
{
WriteWarning("You are passing $null as a value for parameter RecipeArn 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.RecommenderConfig_ItemExplorationConfig != null)
{
context.RecommenderConfig_ItemExplorationConfig = new Dictionary(StringComparer.Ordinal);
foreach (var hashKey in this.RecommenderConfig_ItemExplorationConfig.Keys)
{
context.RecommenderConfig_ItemExplorationConfig.Add((String)hashKey, (String)(this.RecommenderConfig_ItemExplorationConfig[hashKey]));
}
}
context.RecommenderConfig_MinRecommendationRequestsPerSecond = this.RecommenderConfig_MinRecommendationRequestsPerSecond;
if (this.TrainingDataConfig_ExcludedDatasetColumn != null)
{
context.TrainingDataConfig_ExcludedDatasetColumn = new Dictionary>(StringComparer.Ordinal);
foreach (var hashKey in this.TrainingDataConfig_ExcludedDatasetColumn.Keys)
{
object hashValue = this.TrainingDataConfig_ExcludedDatasetColumn[hashKey];
if (hashValue == null)
{
context.TrainingDataConfig_ExcludedDatasetColumn.Add((String)hashKey, null);
continue;
}
var enumerable = SafeEnumerable(hashValue);
var valueSet = new List();
foreach (var s in enumerable)
{
valueSet.Add((System.String)s);
}
context.TrainingDataConfig_ExcludedDatasetColumn.Add((String)hashKey, valueSet);
}
}
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.Personalize.Model.CreateRecommenderRequest();
if (cmdletContext.DatasetGroupArn != null)
{
request.DatasetGroupArn = cmdletContext.DatasetGroupArn;
}
if (cmdletContext.Name != null)
{
request.Name = cmdletContext.Name;
}
if (cmdletContext.RecipeArn != null)
{
request.RecipeArn = cmdletContext.RecipeArn;
}
// populate RecommenderConfig
var requestRecommenderConfigIsNull = true;
request.RecommenderConfig = new Amazon.Personalize.Model.RecommenderConfig();
Dictionary requestRecommenderConfig_recommenderConfig_ItemExplorationConfig = null;
if (cmdletContext.RecommenderConfig_ItemExplorationConfig != null)
{
requestRecommenderConfig_recommenderConfig_ItemExplorationConfig = cmdletContext.RecommenderConfig_ItemExplorationConfig;
}
if (requestRecommenderConfig_recommenderConfig_ItemExplorationConfig != null)
{
request.RecommenderConfig.ItemExplorationConfig = requestRecommenderConfig_recommenderConfig_ItemExplorationConfig;
requestRecommenderConfigIsNull = false;
}
System.Int32? requestRecommenderConfig_recommenderConfig_MinRecommendationRequestsPerSecond = null;
if (cmdletContext.RecommenderConfig_MinRecommendationRequestsPerSecond != null)
{
requestRecommenderConfig_recommenderConfig_MinRecommendationRequestsPerSecond = cmdletContext.RecommenderConfig_MinRecommendationRequestsPerSecond.Value;
}
if (requestRecommenderConfig_recommenderConfig_MinRecommendationRequestsPerSecond != null)
{
request.RecommenderConfig.MinRecommendationRequestsPerSecond = requestRecommenderConfig_recommenderConfig_MinRecommendationRequestsPerSecond.Value;
requestRecommenderConfigIsNull = false;
}
Amazon.Personalize.Model.TrainingDataConfig requestRecommenderConfig_recommenderConfig_TrainingDataConfig = null;
// populate TrainingDataConfig
var requestRecommenderConfig_recommenderConfig_TrainingDataConfigIsNull = true;
requestRecommenderConfig_recommenderConfig_TrainingDataConfig = new Amazon.Personalize.Model.TrainingDataConfig();
Dictionary> requestRecommenderConfig_recommenderConfig_TrainingDataConfig_trainingDataConfig_ExcludedDatasetColumn = null;
if (cmdletContext.TrainingDataConfig_ExcludedDatasetColumn != null)
{
requestRecommenderConfig_recommenderConfig_TrainingDataConfig_trainingDataConfig_ExcludedDatasetColumn = cmdletContext.TrainingDataConfig_ExcludedDatasetColumn;
}
if (requestRecommenderConfig_recommenderConfig_TrainingDataConfig_trainingDataConfig_ExcludedDatasetColumn != null)
{
requestRecommenderConfig_recommenderConfig_TrainingDataConfig.ExcludedDatasetColumns = requestRecommenderConfig_recommenderConfig_TrainingDataConfig_trainingDataConfig_ExcludedDatasetColumn;
requestRecommenderConfig_recommenderConfig_TrainingDataConfigIsNull = false;
}
// determine if requestRecommenderConfig_recommenderConfig_TrainingDataConfig should be set to null
if (requestRecommenderConfig_recommenderConfig_TrainingDataConfigIsNull)
{
requestRecommenderConfig_recommenderConfig_TrainingDataConfig = null;
}
if (requestRecommenderConfig_recommenderConfig_TrainingDataConfig != null)
{
request.RecommenderConfig.TrainingDataConfig = requestRecommenderConfig_recommenderConfig_TrainingDataConfig;
requestRecommenderConfigIsNull = false;
}
// determine if request.RecommenderConfig should be set to null
if (requestRecommenderConfigIsNull)
{
request.RecommenderConfig = 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.Personalize.Model.CreateRecommenderResponse CallAWSServiceOperation(IAmazonPersonalize client, Amazon.Personalize.Model.CreateRecommenderRequest request)
{
Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "AWS Personalize", "CreateRecommender");
try
{
#if DESKTOP
return client.CreateRecommender(request);
#elif CORECLR
return client.CreateRecommenderAsync(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 DatasetGroupArn { get; set; }
public System.String Name { get; set; }
public System.String RecipeArn { get; set; }
public Dictionary RecommenderConfig_ItemExplorationConfig { get; set; }
public System.Int32? RecommenderConfig_MinRecommendationRequestsPerSecond { get; set; }
public Dictionary> TrainingDataConfig_ExcludedDatasetColumn { get; set; }
public List Tag { get; set; }
public System.Func Select { get; set; } =
(response, cmdlet) => response.RecommenderArn;
}
}
}