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].freeze

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)


101
102
103
104
105
106
107
# File 'lib/osctld/send_receive/log.rb', line 101

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.



83
84
85
# File 'lib/osctld/send_receive/log.rb', line 83

def opts
  @opts
end

#roleObject (readonly)

Returns the value of attribute role.



83
84
85
# File 'lib/osctld/send_receive/log.rb', line 83

def role
  @role
end

#snapshotsObject (readonly)

Returns the value of attribute snapshots.



83
84
85
# File 'lib/osctld/send_receive/log.rb', line 83

def snapshots
  @snapshots
end

#stateObject

Returns the value of attribute state.



83
84
85
# File 'lib/osctld/send_receive/log.rb', line 83

def state
  @state
end

#tokenObject (readonly)

Returns the value of attribute token.



83
84
85
# File 'lib/osctld/send_receive/log.rb', line 83

def token
  @token
end

Class Method Details

.load(cfg) ⇒ Object



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

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)


152
153
154
# File 'lib/osctld/send_receive/log.rb', line 152

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

#can_receive_continue?(next_state) ⇒ Boolean

Returns:

  • (Boolean)


138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/osctld/send_receive/log.rb', line 138

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)


132
133
134
135
136
# File 'lib/osctld/send_receive/log.rb', line 132

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)


119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/osctld/send_receive/log.rb', line 119

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



162
163
164
# File 'lib/osctld/send_receive/log.rb', line 162

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

#dumpObject



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

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