Class: OpenStax::Aws::Stack::Status

Inherits:
Object
  • Object
show all
Defined in:
lib/openstax/aws/stack_status.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stack) ⇒ Status

Returns a new instance of Status.



4
5
6
# File 'lib/openstax/aws/stack_status.rb', line 4

def initialize(stack)
  @stack = stack
end

Class Method Details

.active_status_textsObject



81
82
83
# File 'lib/openstax/aws/stack_status.rb', line 81

def self.active_status_texts
  all_status_texts - %w(CREATE_FAILED DELETE_COMPLETE)
end

.all_status_textsObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/openstax/aws/stack_status.rb', line 54

def self.all_status_texts
  %w(
    CREATE_IN_PROGRESS
    CREATE_FAILED
    CREATE_COMPLETE
    ROLLBACK_IN_PROGRESS
    ROLLBACK_FAILED
    ROLLBACK_COMPLETE
    DELETE_IN_PROGRESS
    DELETE_FAILED
    DELETE_COMPLETE
    UPDATE_IN_PROGRESS
    UPDATE_COMPLETE_CLEANUP_IN_PROGRESS
    UPDATE_COMPLETE
    UPDATE_ROLLBACK_IN_PROGRESS
    UPDATE_ROLLBACK_FAILED
    UPDATE_ROLLBACK_COMPLETE_CLEANUP_IN_PROGRESS
    UPDATE_ROLLBACK_COMPLETE
    REVIEW_IN_PROGRESS
    IMPORT_IN_PROGRESS
    IMPORT_COMPLETE
    IMPORT_ROLLBACK_IN_PROGRESS
    IMPORT_ROLLBACK_FAILED
    IMPORT_ROLLBACK_COMPLETE
  )
end

.does_not_exist_status_textObject



50
51
52
# File 'lib/openstax/aws/stack_status.rb', line 50

def self.does_not_exist_status_text
  "DOES_NOT_EXIST"
end

.failure_status_textsObject



85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/openstax/aws/stack_status.rb', line 85

def self.failure_status_texts
  %w(
    UPDATE_ROLLBACK_COMPLETE
    ROLLBACK_COMPLETE
    ROLLBACK_IN_PROGRESS
    CREATE_FAILED
    ROLLBACK_FAILED
    DELETE_FAILED
    UPDATE_ROLLBACK_FAILED
    IMPORT_ROLLBACK_FAILED
  )
end

.success_status_textsObject



98
99
100
101
102
103
104
# File 'lib/openstax/aws/stack_status.rb', line 98

def self.success_status_texts
  %w(
    UPDATE_COMPLETE
    DELETE_COMPLETE
    CREATE_COMPLETE
  )
end

Instance Method Details

#creating?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/openstax/aws/stack_status.rb', line 38

def creating?
  "CREATE_IN_PROGRESS" == status_text
end

#deleting?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/openstax/aws/stack_status.rb', line 42

def deleting?
  "DELETE_IN_PROGRESS" == status_text
end

#exists?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/openstax/aws/stack_status.rb', line 46

def exists?
  self.class.does_not_exist_status_text != status_text
end

#failed?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/openstax/aws/stack_status.rb', line 21

def failed?
  self.class.failure_status_texts.include?(status_text)
end

#failed_events_since_last_user_eventObject



106
107
108
109
110
111
# File 'lib/openstax/aws/stack_status.rb', line 106

def failed_events_since_last_user_event
  @stack.events.each_with_object([]) do |event, array|
    array.push(event) if event.failed? && event.status_reason  #if nil, don't push
    return array if event.user_initiated?
  end
end

#status_textObject



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/openstax/aws/stack_status.rb', line 8

def status_text
  begin
    @stack.aws_stack.stack_status
  rescue Aws::CloudFormation::Errors::ValidationError => ee
    case ee.message
    when /Stack.*does not exist/
      self.class.does_not_exist_status_text
    else
      raise
    end
  end
end

#succeeded?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/openstax/aws/stack_status.rb', line 25

def succeeded?
  self.class.success_status_texts.include?(status_text)
end

#to_hObject



113
114
115
116
117
118
# File 'lib/openstax/aws/stack_status.rb', line 113

def to_h
  {
    status: status_text,
    failed_events_since_last_user_event: failed? ? failed_events_since_last_user_event : []
  }
end

#to_jsonObject



120
121
122
# File 'lib/openstax/aws/stack_status.rb', line 120

def to_json
  to_h.to_json
end

#updating?Boolean

Returns:

  • (Boolean)


29
30
31
32
33
34
35
36
# File 'lib/openstax/aws/stack_status.rb', line 29

def updating?
  %w(
    UPDATE_COMPLETE_CLEANUP_IN_PROGRESS
    UPDATE_IN_PROGRESS
    UPDATE_ROLLBACK_COMPLETE_CLEANUP_IN_PROGRESS
    UPDATE_ROLLBACK_IN_PROGRESS
  ).include?(status_text)
end