Class: EcsCmd::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/ecs_cmd/service.rb

Instance Method Summary collapse

Constructor Details

#initialize(cluster, name, region) ⇒ Service

Returns a new instance of Service.



6
7
8
9
10
# File 'lib/ecs_cmd/service.rb', line 6

def initialize(cluster, name, region)
  @client = Aws::ECS::Client.new(region: region)
  @service_stats = @client.describe_services(cluster: cluster, services: [name])[0]
  raise 'service does not appear to exist' if @service_stats.empty?
end

Instance Method Details

#arnObject



12
13
14
# File 'lib/ecs_cmd/service.rb', line 12

def arn
  @service_stats[0]['service_arn']
end

#deployment_configurationObject



37
38
39
# File 'lib/ecs_cmd/service.rb', line 37

def deployment_configuration
  @service_stats[0]['deployment_configuration']
end

#deploymentsObject



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

def deployments
  t = []
  @service_stats[0]['deployments'].each do |e|
    t << ['id', e['id']]
    t << ['status', e['status']]
    t << ['task definition', e['task_definition']]
    t << ['desired count', e['desired_count']]
    t << ['pending count', e['pending_count']]
    t << ['running count', e['running_count']]
    t << ['created at', e['created_at']]
    t << ['updated at', e['updated_at']]
    t << ["\n"]
  end
  table = Terminal::Table.new headings: ['DEPLOYMENTS'], rows: t
  table
end

#desired_countObject



41
42
43
# File 'lib/ecs_cmd/service.rb', line 41

def desired_count
  @service_stats[0]['desired_count']
end

#eventsObject



61
62
63
64
65
# File 'lib/ecs_cmd/service.rb', line 61

def events
  @service_stats[0]['events'].each do |e|
    puts "#{e['created_at']}: #{e['message']}"
  end
end

#health_check_grace_periodObject



57
58
59
# File 'lib/ecs_cmd/service.rb', line 57

def health_check_grace_period
  @service_stats[0]['health_check_grace_period_seconds']
end

#list_serviceObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/ecs_cmd/service.rb', line 71

def list_service
  row1 = []
  row1 << [name, status, running_count, desired_count, pending_count,
           deployment_configuration['maximum_percent'], deployment_configuration['minimum_healthy_percent']]
  table1 = Terminal::Table.new headings: ['NAME', 'STATUS', 'RUNNING COUNT',
                                          'DESIRED COUNT', 'PENDING COUNT',
                                          'MAX HEALTHY', 'MIN HEALTHY'], rows: row1
  row2 = []
  row2 << [task_definition]
  table2 = Terminal::Table.new headings: ['TASK DEFINITION'], rows: row2
  puts table1
  puts table2
  puts deployments
end

#nameObject



67
68
69
# File 'lib/ecs_cmd/service.rb', line 67

def name
  @service_stats[0]['service_name']
end

#pending_countObject



49
50
51
# File 'lib/ecs_cmd/service.rb', line 49

def pending_count
  @service_stats[0]['pending_count']
end

#running_countObject



45
46
47
# File 'lib/ecs_cmd/service.rb', line 45

def running_count
  @service_stats[0]['running_count']
end

#statusObject



16
17
18
# File 'lib/ecs_cmd/service.rb', line 16

def status
  @service_stats[0]['status']
end

#task_definitionObject



53
54
55
# File 'lib/ecs_cmd/service.rb', line 53

def task_definition
  @service_stats[0]['task_definition']
end