Class: Ufo::CLI::Ps
Direct Known Subclasses
Errors
Defined Under Namespace
Classes: Errors, Task
Instance Attribute Summary
Attributes inherited from Base
#task_definition
Instance Method Summary
collapse
#autoscaling, #autoscaling_enabled?
#acm, #applicationautoscaling, #aws_options, #cloudformation, #cloudwatchlogs, #ec2, #ecr, #ecs, #elb, #find_stack, #ssm_client, #stack_resources, #status, #task_definition_arns
Methods inherited from Base
#initialize
#sure?
#pretty_home, #pretty_path, #pretty_time
#logger
#build, #deploy, #info, #ps
#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)) } 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.no_service_message
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?
resource_id = "service/#{@cluster}/#{service.service_name}"
resp = applicationautoscaling.describe_scalable_targets(
service_namespace: "ecs",
resource_ids: [resource_id],
)
resp.scalable_targets.first 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 o[:format] ||= format
presenter = CliFormat::Presenter.new(o)
= show_notes ? Task. : Task.[0..-2]
presenter. =
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" 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
message = "Running: #{service.running_count} Desired: #{service.desired_count}"
if scalable_target
message += " Min: #{scalable_target.min_capacity} Max: #{scalable_target.max_capacity}"
end
message
end
|