Class: Ufo::CLI::Ps
- Includes:
- AwsServices, Ufo::Concerns::Autoscaling
- Defined in:
- lib/ufo/cli/ps.rb,
lib/ufo/cli/ps/task.rb,
lib/ufo/cli/ps/errors.rb
Direct Known Subclasses
Defined Under Namespace
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #convert_to_task_objects(task_arns) ⇒ Object
- #run ⇒ Object
- #scalable_target ⇒ Object
- #show_errors(tasks) ⇒ Object
-
#show_tasks(tasks_arns) ⇒ Object
Note: ufo stop also uses Ps#show_tasks.
- #summary ⇒ Object
- #tasks_counts ⇒ Object
Methods included from Ufo::Concerns::Autoscaling
#autoscaling, #autoscaling_enabled?
Methods included from AwsServices
#acm, #applicationautoscaling, #aws_options, #cfn, #cloudwatchlogs, #ec2, #ecr, #ecs, #elb, #s3, #ssm_client, #waf_client
Methods included from AwsServices::Concerns
#find_stack, #find_stack_resources, #stack_resources, #status, #task_definition_arns
Methods inherited from Base
Methods included from Utils::Sure
Methods included from Utils::Pretty
#pretty_home, #pretty_path, #pretty_time
Methods included from Utils::Logging
Methods included from Ufo::Concerns
Methods included from Ufo::Concerns::Names
Constructor Details
This class inherits a constructor from Ufo::CLI::Base
Instance Method Details
#convert_to_task_objects(task_arns) ⇒ Object
70 71 72 73 |
# File 'lib/ufo/cli/ps.rb', line 70 def convert_to_task_objects(task_arns) task_arns.sort_by! { |t| t["task_arn"] } task_arns.map { |t| Task.new(@options.merge(task: t)) } # will have Task objects after this point end |
#run ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ufo/cli/ps.rb', line 10 def run unless service stack = find_stack(@stack_name) if stack && stack.stack_status == "CREATE_IN_PROGRESS" logger.info "Stack is still creating. Try again after it completes." else logger.info info. end return end summary if task_arns.empty? logger.info "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 tasks = show_tasks(all_task_arns) show_errors(tasks) end |
#scalable_target ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/ufo/cli/ps.rb', line 58 def scalable_target return unless autoscaling_enabled? # Docs: https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/ApplicationAutoScaling/Client.html#describe_scalable_targets-instance_method # ECS service - The resource type is service and the unique identifier is the cluster name and service name. Example: service/default/sample-webapp. resource_id = "service/#{@cluster}/#{service.service_name}" resp = applicationautoscaling.describe_scalable_targets( service_namespace: "ecs", resource_ids: [resource_id], ) resp.scalable_targets.first # scalable_target end |
#show_errors(tasks) ⇒ Object
96 97 98 |
# File 'lib/ufo/cli/ps.rb', line 96 def show_errors(tasks) Errors.new(@options.merge(tasks: tasks)).show end |
#show_tasks(tasks_arns) ⇒ Object
Note: ufo stop also uses Ps#show_tasks. Thats why convert_to_task_objects within the method
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/ufo/cli/ps.rb', line 76 def show_tasks(tasks_arns) tasks = convert_to_task_objects(tasks_arns) tasks = tasks.reject(&:hide?) show_notes = show_notes(tasks) format = determine_format(tasks) o = @options.dup # Cant modify frozen Thor options o[:format] ||= format presenter = CliFormat::Presenter.new(o) header = show_notes ? Task.header : Task.header[0..-2] presenter.header = header tasks.each do |task| row = show_notes ? task.to_a : task.to_a[0..-2] presenter.rows << row end presenter.show tasks end |
#summary ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/ufo/cli/ps.rb', line 37 def summary return unless Ufo.config.ps.summary logger.info "Stack: #{@stack_name}" logger.info "Service: #{service.service_name}" logger.info "Status: #{service.status}" unless service.status == "ACTIVE" # not very useful when ACTIVE logger.info "Tasks: #{tasks_counts}" logger.info "Launch type: #{service.launch_type}" if service.launch_type elb = info.load_balancer(service) logger.info "#{elb.type.capitalize} ELB: #{elb.dns_name}" if elb logger.info "Url: #{info.url}" if info.url end |
#tasks_counts ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/ufo/cli/ps.rb', line 50 def tasks_counts = "Running: #{service.running_count} Desired: #{service.desired_count}" if scalable_target += " Min: #{scalable_target.min_capacity} Max: #{scalable_target.max_capacity}" end end |