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)


92
93
94
95
96
97
98
# File 'lib/osctld/send_receive/log.rb', line 92

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.



74
75
76
# File 'lib/osctld/send_receive/log.rb', line 74

def opts
  @opts
end

#roleObject (readonly)

Returns the value of attribute role.



74
75
76
# File 'lib/osctld/send_receive/log.rb', line 74

def role
  @role
end

#snapshotsObject (readonly)

Returns the value of attribute snapshots.



74
75
76
# File 'lib/osctld/send_receive/log.rb', line 74

def snapshots
  @snapshots
end

#stateObject

Returns the value of attribute state.



74
75
76
# File 'lib/osctld/send_receive/log.rb', line 74

def state
  @state
end

#tokenObject (readonly)

Returns the value of attribute token.



74
75
76
# File 'lib/osctld/send_receive/log.rb', line 74

def token
  @token
end

Class Method Details

.load(cfg) ⇒ Object



76
77
78
79
80
81
82
83
84
# File 'lib/osctld/send_receive/log.rb', line 76

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)


143
144
145
# File 'lib/osctld/send_receive/log.rb', line 143

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

#can_receive_continue?(next_state) ⇒ Boolean

Returns:

  • (Boolean)


129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/osctld/send_receive/log.rb', line 129

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)


123
124
125
126
127
# File 'lib/osctld/send_receive/log.rb', line 123

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)


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

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



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

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

#dumpObject



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

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