Module: Smash::CloudPowers::Node

Includes:
Auth, Helper, SelfAwareness, Zenv
Included in:
Smash::CloudPowers
Defined in:
lib/cloud_powers/node.rb

Instance Method Summary collapse

Methods included from Zenv

#env_vars, #file_tree_search, #i_vars, #project_root, #project_root=, #system_vars, #zfind

Methods included from Helper

#attr_map!, #available_resources, #called_from, #create_logger, #deep_modify_keys_with, #format_error_message, #log_file, #logger, #modify_keys_with, #smart_retry, #task_path, #task_require_path, #to_camel, #to_hyph, #to_i_var, #to_pascal, #to_ruby_file_name, #to_snake, #update_message_body, #valid_json?, #valid_url?

Methods included from SelfAwareness

#boot_time, #die!, #get_awareness!, #instance_id, #instance_url, #metadata_request, #run_time, #send_frequent_status_updates, #status, #task_name, #time_is_up?

Methods included from Synapse::Pipe

#create_stream, #flow_from_pipe, #flow_to_pipe, #from_pipe, #message_body_collection, #pipe_message_body, #pipe_to, #stream_config, #stream_exists?, #stream_status

Methods included from AwsResources

#ec2, #image, #kinesis, #region, #s3, #sns, #sqs

Methods included from Auth

creds, region

Methods included from Synapse::Queue

#board_name, #build_queue, #create_queue!, #delete_queue_message, #get_queue_message_count, #pluck_queue_message, #poll, #queue_exists?, #queue_poller, #queue_search, #send_queue_message

Instance Method Details

#node_config(opts = {}) ⇒ Object

These are sensible defaults that can be overriden by providing a Hash as a param.

Parameters

  • opts Hash (optional) the opts Hash should have values that should be used instead of the default configuration.


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/cloud_powers/node.rb', line 20

def node_config(opts = {})
  {
    dry_run:                  zfind(:testing) || false,
    image_id:                 image('crawlbotprod').image_id, # image(:neuron).image_id
    instance_type:            't2.nano',
    min_count:                opts[:max_count] || 0,
    max_count:                0,
    key_name:                 'crawlBot',
    security_groups:          ['webCrawler'],
    security_group_ids:       ['sg-940edcf2'],
    placement:                { availability_zone: 'us-west-2c' },
    disable_api_termination:  'false',
    instance_initiated_shutdown_behavior:   'terminate'
  }.merge(opts)
end

#spin_up_neurons(opts = {}) ⇒ Object

Uses Aws::EC2#run_instances() to create nodes (Neurons or Cerebrums), at a rate of 0..(n <= 100) at a time, until the required number of instances has been started. The #instance_config() method is used to create instance configuration for the #run_instances method by using the opts hash that was provided as a parameter.

Parameters

  • opts Hash (optional) an optional instance configuration hash can be passed, which will override the values in the default configuration returned by #instance_config()


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/cloud_powers/node.rb', line 46

def spin_up_neurons(opts = {})
  ids = nil
  begin
    response = ec2.run_instances(node_config(opts))
    ids = response.instances.map(&:instance_id)

    ec2.wait_until(:instance_running, instance_ids: ids) do
      logger.info "waiting for #{ids.count} Neurons to start..."
    end

    # tag(ids, { key: 'task', value: to_camel(self.class.to_s) })
  rescue Aws::EC2::Errors::DryRunOperation => e
    ids = (1..(opts[:max_count] || 0)).to_a.map { |n| n.to_s }
    logger.info "waiting for #{ids.count} Neurons to start..."
  end

  ids
end