Class: ForemanDlm::Dlmlock

Inherits:
ApplicationRecord
  • Object
show all
Includes:
Authorizable
Defined in:
app/models/foreman_dlm/dlmlock.rb,
app/models/foreman_dlm/dlmlock/update.rb

Direct Known Subclasses

Update

Defined Under Namespace

Classes: Update

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#oldObject

Returns the value of attribute old.



47
48
49
# File 'app/models/foreman_dlm/dlmlock.rb', line 47

def old
  @old
end

Class Method Details

.dlm_stale_timeObject



11
12
13
# File 'app/models/foreman_dlm/dlmlock.rb', line 11

def self.dlm_stale_time
  (Setting[:dlm_stale_time] || 4).hours
end

.humanize_class_nameObject



7
8
9
# File 'app/models/foreman_dlm/dlmlock.rb', line 7

def self.humanize_class_name
  N_('Distributed Lock')
end

Instance Method Details

#acquire!(host) ⇒ Object



49
50
51
52
53
54
55
# File 'app/models/foreman_dlm/dlmlock.rb', line 49

def acquire!(host)
  return false unless host.can_acquire_update_locks?

  result = atomic_update(nil, host)
  ForemanDlm::RefreshDlmlockStatus.set(wait: self.class.dlm_stale_time).perform_later([host.id]) if result
  result
end

#disable!Object



65
66
67
# File 'app/models/foreman_dlm/dlmlock.rb', line 65

def disable!
  update(enabled: false)
end

#disabled?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'app/models/foreman_dlm/dlmlock.rb', line 74

def disabled?
  !enabled?
end

#enable!Object



61
62
63
# File 'app/models/foreman_dlm/dlmlock.rb', line 61

def enable!
  update(enabled: true)
end

#humanized_typeObject



83
84
85
# File 'app/models/foreman_dlm/dlmlock.rb', line 83

def humanized_type
  _('Generic Lock')
end

#locked?Boolean Also known as: taken?

Returns:

  • (Boolean)


78
79
80
# File 'app/models/foreman_dlm/dlmlock.rb', line 78

def locked?
  host.present?
end

#locked_by?(host) ⇒ Boolean Also known as: acquired_by?

Returns:

  • (Boolean)


69
70
71
# File 'app/models/foreman_dlm/dlmlock.rb', line 69

def locked_by?(host)
  self.host == host
end

#log_enable_or_disable_eventObject



27
28
29
30
# File 'app/models/foreman_dlm/dlmlock.rb', line 27

def log_enable_or_disable_event
  event_type = enabled ? :enable : :disable
  log_event(host, event_type)
end

#log_release_and_acquire_eventsObject



32
33
34
35
36
37
# File 'app/models/foreman_dlm/dlmlock.rb', line 32

def log_release_and_acquire_events
  old_host_id = saved_changes[:host_id].first
  old_host = Host.find_by(id: old_host_id) if old_host_id
  log_event(old_host, :release) if old_host
  log_event(host, :acquire) if host
end

#release!(host) ⇒ Object



57
58
59
# File 'app/models/foreman_dlm/dlmlock.rb', line 57

def release!(host)
  atomic_update(host, nil)
end