/* * Copyright 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. */ using System; using System.Collections.Generic; using System.Text; namespace Amazon.ElasticMapReduce.Model { /// /// Class that provides helper methods for constructing predefined bootstrap actions. /// /// /// /// IAmazonElasticMapReduce emr = TestUtil.EMRClient; /// /// BootstrapActions bootstrapActions = new BootstrapActions(); /// /// var daemons = bootstrapActions.NewConfigureDaemons(); /// daemons.AddHeapSize(Daemon.JobTracker, 2048); /// /// RunJobFlowRequest request = new RunJobFlowRequest /// { /// Name = "Job Flow With Bootstrap Actions", /// BootstrapActions = new List<BootstrapActionConfig> /// { /// bootstrapActions.NewRunIf("instance.isMaster=true", daemons.Build()) /// }, /// LogUri = "s3://log-bucket/", /// Instances = new JobFlowInstancesConfig /// { /// Ec2KeyName = "keypair", /// HadoopVersion = "0.20", /// InstanceCount = 5, /// KeepJobFlowAliveWhenNoSteps = true, /// MasterInstanceType = "m1.small", /// SlaveInstanceType = "m1.small" /// } /// }; /// /// RunJobFlowResponse response = emr.RunJobFlow(request); /// /// public class BootstrapActions { readonly string bucket; /// /// Creates a new default BootstrapActions for us in us-east-1. /// public BootstrapActions() : this("us-east-1.elasticmapreduce") {} /// /// Creates a new BootstrapActions. /// /// the bucket from which to download the bootstrap actions. public BootstrapActions(string bucket) { this.bucket = bucket; } /// /// Create a new run-if bootstrap action which lets you conditionally run bootstrap actions. /// /// The condition to evaluate, if true the bootstrap action executes. /// The bootstrap action to execute in case of successful evaluation. /// A BootstrapActionConfig to be provided when running a job flow. public BootstrapActionConfig NewRunIf(string condition, BootstrapActionConfig config) { List args = config.ScriptBootstrapAction.Args; args.Add(condition); args.Add(config.ScriptBootstrapAction.Path); return new BootstrapActionConfig { Name = "Run If, " + config.Name, ScriptBootstrapAction = new ScriptBootstrapActionConfig { Path = "s3://" + bucket + "/bootstrap-actions/run-if", Args = args } }; } /// /// Create a new bootstrap action which lets you configure Hadoop's XML files. /// public ConfigureHadoop NewConfigureHadoop() { return new ConfigureHadoop(this.bucket); } /// /// Create a new bootstrap action which lets you configure Hadoop's daemons. The options /// are written to the hadoop-user-env.sh file. /// public ConfigureDaemons NewConfigureDaemons() { return new ConfigureDaemons(this.bucket); } } }