Class: OsCtld::SendReceive::Log

Inherits:
Object
  • Object
show all
Defined in:
lib/osctld/send_receive/log.rb

Overview

This class serves as a scratchpad for container send/receive

Both the source and the destination nodes have an instance of this class per container. This class determines whether the next step of the send can proceed, stores names of snapshots created during the send and other settings.

Defined Under Namespace

Classes: Options

Constant Summary collapse

STATES =
%i(stage base incremental transfer cleanup)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Log

Returns a new instance of Log.

Parameters:

  • opts (Hash)

    options

Options Hash (opts):

  • role (Symbol)

    `:source`, `:destination`

  • token (String)
  • state (Symbol)
  • snapshots (Array<String>)
  • opts (Options, Hash)


87
88
89
90
91
92
93
# File 'lib/osctld/send_receive/log.rb', line 87

def initialize(opts)
  @role = opts[:role]
  @token = opts[:token]
  @state = opts[:state] || :stage
  @snapshots = opts[:snapshots] || []
  @opts = opts[:opts].is_a?(Options) ? opts[:opts] : Options.new(opts[:opts] || {})
end

Instance Attribute Details

#optsObject (readonly)

Returns the value of attribute opts.



69
70
71
# File 'lib/osctld/send_receive/log.rb', line 69

def opts
  @opts
end

#roleObject (readonly)

Returns the value of attribute role.



69
70
71
# File 'lib/osctld/send_receive/log.rb', line 69

def role
  @role
end

#snapshotsObject (readonly)

Returns the value of attribute snapshots.



69
70
71
# File 'lib/osctld/send_receive/log.rb', line 69

def snapshots
  @snapshots
end

#stateObject

Returns the value of attribute state.



69
70
71
# File 'lib/osctld/send_receive/log.rb', line 69

def state
  @state
end

#tokenObject (readonly)

Returns the value of attribute token.



69
70
71
# File 'lib/osctld/send_receive/log.rb', line 69

def token
  @token
end

Class Method Details

.load(cfg) ⇒ Object



71
72
73
74
75
76
77
78
79
# File 'lib/osctld/send_receive/log.rb', line 71

def self.load(cfg)
  new(
    role: cfg['role'].to_sym,
    token: cfg['token'],
    state: cfg['state'].to_sym,
    snapshots: cfg['snapshots'],
    opts: Options.load(cfg['opts']),
  )
end

Instance Method Details

#can_receive_cancel?Boolean

Returns:

  • (Boolean)


138
139
140
# File 'lib/osctld/send_receive/log.rb', line 138

def can_receive_cancel?
  %i(stage base incremental).include?(state)
end

#can_receive_continue?(next_state) ⇒ Boolean

Returns:

  • (Boolean)


124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/osctld/send_receive/log.rb', line 124

def can_receive_continue?(next_state)
  syncs = %i(base incremental)
  cur_i = STATES.index(state)
  next_i = STATES.index(next_state)

  if !next_i
    false
  elsif syncs.include?(state) && syncs.include?(next_state)
    true
  else
    next_i > cur_i
  end
end

#can_send_cancel?(force) ⇒ Boolean

Returns:

  • (Boolean)


118
119
120
121
122
# File 'lib/osctld/send_receive/log.rb', line 118

def can_send_cancel?(force)
  cancellable = %i(stage base incremental)
  cancellable << :transfer if force
  cancellable.include?(state)
end

#can_send_continue?(next_state) ⇒ Boolean

Returns:

  • (Boolean)


105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/osctld/send_receive/log.rb', line 105

def can_send_continue?(next_state)
  cur_i = STATES.index(state)
  next_i = STATES.index(next_state)

  if !next_i
    false
  elsif state == :incremental && next_state == :incremental
    true
  else
    next_i > cur_i
  end
end

#closeObject



147
148
149
# File 'lib/osctld/send_receive/log.rb', line 147

def close
  SendReceive::Tokens.free(token)
end

#dumpObject



95
96
97
98
99
100
101
102
103
# File 'lib/osctld/send_receive/log.rb', line 95

def dump
  {
    'role' => role.to_s,
    'token' => token,
    'state' => state.to_s,
    'snapshots' => snapshots,
    'opts' => opts.dump,
  }
end