lib/elasticity/job_flow.rb in elasticity-6.0.5 vs lib/elasticity/job_flow.rb in elasticity-6.0.6
- old
+ new
@@ -15,31 +15,33 @@
attr_accessor :log_uri
attr_accessor :tags
attr_accessor :master_instance_type
attr_accessor :slave_instance_type
attr_accessor :ami_version
+ attr_accessor :release_label
attr_accessor :keep_job_flow_alive_when_no_steps
attr_accessor :ec2_subnet_id
attr_accessor :placement
attr_accessor :region
attr_accessor :visible_to_all_users
attr_accessor :enable_debugging
attr_accessor :job_flow_role
attr_accessor :service_role
attr_accessor :jobflow_id
+ attr_accessor :aws_applications
def initialize
@action_on_failure = 'TERMINATE_JOB_FLOW'
@name = 'Elasticity Job Flow'
- @ami_version = 'latest'
@keep_job_flow_alive_when_no_steps = false
self.placement = 'us-east-1a'
@enable_debugging = false
@visible_to_all_users = false
@bootstrap_actions = []
+ @aws_applications = []
@jobflow_steps = []
@installed_steps = []
@instance_groups = {}
set_master_instance_group(Elasticity::InstanceGroup.new)
@@ -104,10 +106,17 @@
raise JobFlowRunningError, 'To modify bootstrap actions, please create a new job flow.'
end
@bootstrap_actions << bootstrap_action
end
+ def add_application(application)
+ raise JobFlowRunningError, 'To add applications, please create a new job flow.' if is_jobflow_running?
+ application = Application.new(name: application) if application.is_a?(String)
+ fail "application is not an Elasticity::Application" unless application.is_a?(Application)
+ @aws_applications << application
+ end
+
def set_master_instance_group(instance_group)
instance_group.role = 'MASTER'
@instance_groups[:master] = instance_group
end
@@ -182,21 +191,35 @@
!@jobflow_id.nil?
end
def jobflow_config
config = jobflow_preamble
+ validate_and_apply_ami_or_release_version(config)
steps = jobflow_steps
steps.insert(0, Elasticity::SetupHadoopDebuggingStep.new.to_aws_step(self)) if @enable_debugging
config[:steps] = steps
config[:log_uri] = @log_uri if @log_uri
config[:tags] = jobflow_tags if @tags
config[:job_flow_role] = @job_flow_role if @job_flow_role
config[:service_role] = @service_role if @service_role
- config[:bootstrap_actions] = @bootstrap_actions.map{|a| a.to_aws_bootstrap_action} unless @bootstrap_actions.empty?
+ config[:bootstrap_actions] = @bootstrap_actions.map(&:to_aws_bootstrap_action) unless @bootstrap_actions.empty?
+ config[:applications] = @aws_applications.map(&:to_hash) if valid_aws_applications?
config
end
+ def valid_aws_applications?
+ !@aws_applications.empty?
+ end
+
+ def validate_and_apply_ami_or_release_version(config)
+ fail "Please use an EMR release_label not ami_version" if !@aws_applications.empty? && !@ami_version.nil?
+ fail "Please set the EMR release_label" if !@aws_applications.empty? && @release_label.nil?
+ config[:ami_version] = 'latest' if @ami_version.nil? && release_label.nil?
+ config[:ami_version] = @ami_version unless @ami_version.nil?
+ config[:release_label] = @release_label unless @release_label.nil?
+ end
+
def jobflow_tags
@tags.map do |key, value|
{
key: key.to_s,
value: value
@@ -205,10 +228,9 @@
end
def jobflow_preamble
preamble = {
:name => @name,
- :ami_version => @ami_version,
:visible_to_all_users => @visible_to_all_users,
:instances => {
:keep_job_flow_alive_when_no_steps => @keep_job_flow_alive_when_no_steps,
:instance_groups => jobflow_instance_groups,
:placement => {