Class: Ufo::Ps
Defined Under Namespace
Classes: Task
Instance Method Summary collapse
-
#display_scale_help ⇒ Object
If the running count less than the desired account yet, check the events and show a message with helpful debugging information.
- #display_target_group_help ⇒ Object
- #display_tasks(tasks) ⇒ Object
- #run ⇒ Object
- #statuses ⇒ Object
- #summary ⇒ Object
- #task_arns ⇒ Object
Methods inherited from Base
#full_service, #info, #initialize, #no_service_message, #switch_current
Methods included from Stack::Helper
#adjust_stack_name, #cfn, #find_stack, #status
Methods included from Util
#default_cluster, #display_params, #execute, #pretty_time, #settings, #task_definition_arns, #user_params
Methods included from AwsService
#cloudformation, #cloudwatchlogs, #ec2, #ecr, #ecs, #elb
Constructor Details
This class inherits a constructor from Ufo::Base
Instance Method Details
#display_scale_help ⇒ Object
If the running count less than the desired account yet, check the events and show a message with helpful debugging information.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/ufo/ps.rb', line 68 def display_scale_help return if service.running_count >= service.desired_count events = service["events"][0..3] # only check most recent 4 messages error_event = events.find do |e| e. =~ /was unable to place a task/ end return unless error_event puts "There is an issue scaling the #{@service.color(:green)} service to #{service.desired_count}. Here's the error:" puts error_event..color(:red) if service.launch_type == "EC2" puts "If AutoScaling is set up for the container instances, it can take a little time to add additional instances. You'll see this message until the capacity is added." end end |
#display_target_group_help ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/ufo/ps.rb', line 47 def display_target_group_help events = service["events"][0..4] return if events[0]. =~ /has reached a steady state/ # The error currently happens to be the 5th element. # # Example: # "(service XXX) (instance i-XXX) (port 32875) is unhealthy in (target-group arn:aws:elasticloadbalancing:us-east-1:111111111111:targetgroup/devel-Targe-1111111111111/1111111111111111) due to (reason Health checks failed with these codes: [400])">] error_event = events.find do |e| e. =~ /is unhealthy in/ && e. =~ /targetgroup/ end return unless error_event puts "There are targets in the target group reporting unhealthy. This can cause containers to cycle. Here's the error:" puts error_event..color(:red) puts "Check out the ECS console events tab for more info." end |
#display_tasks(tasks) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/ufo/ps.rb', line 84 def display_tasks(tasks) table = Text::Table.new Task.extra_columns = @options[:extra] table.head = Task.header tasks = tasks.sort_by { |t| t["task_arn"] } tasks.each do |t| task = Task.new(t) table.rows << task.to_a unless task.hide? end puts table end |
#run ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/ufo/ps.rb', line 7 def run unless service puts return end summary if task_arns.empty? puts "There are 0 running tasks." return end all_task_arns = task_arns.each_slice(100).map do |arns| resp = ecs.describe_tasks(tasks: arns, cluster: @cluster) resp["tasks"] end.flatten display_tasks(all_task_arns) display_scale_help display_target_group_help end |
#statuses ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/ufo/ps.rb', line 96 def statuses status = @options[:status].upcase valid_statuses = %w[RUNNING PENDING STOPPED] all_statuses = valid_statuses + ["ALL"] unless all_statuses.include?(status) puts "Invalid status filter provided. Please provided one of the following:" puts all_statuses.map(&:downcase).join(", ") exit 1 end status == "ALL" ? valid_statuses : [status] end |
#summary ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/ufo/ps.rb', line 30 def summary return unless @options[:summary] puts "=> Service: #{full_service}" puts " Service name: #{service.service_name}" puts " Status: #{service.status}" puts " Running count: #{service.running_count}" puts " Desired count: #{service.desired_count}" puts " Launch type: #{service.launch_type}" puts " Task definition: #{service.task_definition.split('/').last}" elb = info.load_balancer(service) if elb puts " Elb: #{elb.dns_name}" puts " Elb type: #{elb.type}" end puts " Route53: #{info.route53_dns}" if info.route53_dns end |
#task_arns ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/ufo/ps.rb', line 109 def task_arns threads, results = [], {} statuses.each do |status| threads << Thread.new do = { service_name: service.service_name, cluster: @cluster, desired_status: status, } # Limit display of too many stopped tasks [:max_results] = 20 if status == "STOPPED" resp = ecs.list_tasks() results[status] = resp.task_arns end end threads.map(&:join) results.values.flatten.uniq end |