debian-mirror-gitlab/app/models/clusters/concerns/application_status.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

128 lines
4 KiB
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
module Clusters
module Concerns
module ApplicationStatus
extend ActiveSupport::Concern
included do
2019-07-07 11:18:12 +05:30
scope :available, -> do
where(
status: [
2021-04-29 21:17:54 +05:30
self.state_machines[:status].states[:externally_installed].value,
2019-07-07 11:18:12 +05:30
self.state_machines[:status].states[:installed].value,
self.state_machines[:status].states[:updated].value
]
)
end
2018-05-09 12:01:36 +05:30
2018-03-17 18:26:18 +05:30
state_machine :status, initial: :not_installable do
state :not_installable, value: -2
state :errored, value: -1
state :installable, value: 0
state :scheduled, value: 1
state :installing, value: 2
state :installed, value: 3
2018-12-05 23:21:45 +05:30
state :updating, value: 4
state :updated, value: 5
state :update_errored, value: 6
2019-07-31 22:56:46 +05:30
state :uninstalling, value: 7
state :uninstall_errored, value: 8
2020-05-24 23:13:21 +05:30
state :uninstalled, value: 10
2021-04-29 21:17:54 +05:30
state :externally_installed, value: 11
2018-03-17 18:26:18 +05:30
2019-12-21 20:55:43 +05:30
# Used for applications that are pre-installed by the cluster,
# e.g. Knative in GCP Cloud Run enabled clusters
# Because we cannot upgrade or uninstall Knative in these clusters,
# we define only one simple state transition to enter the `pre_installed` state,
# and no exit transitions.
state :pre_installed, value: 9
2020-05-24 23:13:21 +05:30
event :make_externally_installed do
2021-04-29 21:17:54 +05:30
transition any => :externally_installed
2020-05-24 23:13:21 +05:30
end
event :make_externally_uninstalled do
transition any => :uninstalled
end
2018-03-17 18:26:18 +05:30
event :make_scheduled do
2019-07-31 22:56:46 +05:30
transition [:installable, :errored, :installed, :updated, :update_errored, :uninstall_errored] => :scheduled
2018-03-17 18:26:18 +05:30
end
event :make_installing do
transition [:scheduled] => :installing
end
event :make_installed do
transition [:installing] => :installed
2019-03-02 22:35:43 +05:30
transition [:updating] => :updated
2018-03-17 18:26:18 +05:30
end
2019-12-21 20:55:43 +05:30
event :make_pre_installed do
transition any => :pre_installed
end
2018-03-17 18:26:18 +05:30
event :make_errored do
2019-07-31 22:56:46 +05:30
transition any - [:updating, :uninstalling] => :errored
2019-03-02 22:35:43 +05:30
transition [:updating] => :update_errored
2019-07-31 22:56:46 +05:30
transition [:uninstalling] => :uninstall_errored
2018-03-17 18:26:18 +05:30
end
2018-12-05 23:21:45 +05:30
event :make_updating do
2019-03-02 22:35:43 +05:30
transition [:installed, :updated, :update_errored, :scheduled] => :updating
2018-12-05 23:21:45 +05:30
end
event :make_update_errored do
transition any => :update_errored
end
2019-07-31 22:56:46 +05:30
event :make_uninstalling do
transition [:scheduled] => :uninstalling
end
2021-04-29 21:17:54 +05:30
before_transition any => [:scheduled, :installed, :uninstalled, :externally_installed] do |application, _|
2019-09-30 21:07:59 +05:30
application.status_reason = nil
2018-03-17 18:26:18 +05:30
end
2019-09-30 21:07:59 +05:30
before_transition any => [:errored] do |application, transition|
2018-03-17 18:26:18 +05:30
status_reason = transition.args.first
2019-09-30 21:07:59 +05:30
application.status_reason = status_reason if status_reason
2018-03-17 18:26:18 +05:30
end
2018-12-05 23:21:45 +05:30
2019-09-30 21:07:59 +05:30
before_transition any => [:updating] do |application, _|
application.status_reason = nil
2018-12-05 23:21:45 +05:30
end
2019-09-30 21:07:59 +05:30
before_transition any => [:update_errored, :uninstall_errored] do |application, transition|
2018-12-05 23:21:45 +05:30
status_reason = transition.args.first
2019-09-30 21:07:59 +05:30
application.status_reason = status_reason if status_reason
2018-12-05 23:21:45 +05:30
end
2019-02-15 15:39:39 +05:30
2019-09-30 21:07:59 +05:30
after_transition any => [:uninstalling], :use_transactions => false do |application, _|
application.prepare_uninstall
2019-02-15 15:39:39 +05:30
end
2018-03-17 18:26:18 +05:30
end
end
2018-12-13 13:39:08 +05:30
2019-12-21 20:55:43 +05:30
def status_states
self.class.state_machines[:status].states.each_with_object({}) do |state, states|
states[state.name] = state.value
end
end
2019-03-02 22:35:43 +05:30
def updateable?
installed? || updated? || update_errored?
end
2018-12-13 13:39:08 +05:30
def available?
2021-04-29 21:17:54 +05:30
pre_installed? || installed? || externally_installed? || updated?
2018-12-13 13:39:08 +05:30
end
2019-03-02 22:35:43 +05:30
def update_in_progress?
updating?
end
2018-03-17 18:26:18 +05:30
end
end
end