Class: OsCtld::Commands::Container::LocalTransfer::State

Inherits:
Base
  • Object
show all
Defined in:
lib/osctld/commands/container/local_transfer/state.rb

Direct Known Subclasses

CopyState, MoveState

Instance Attribute Summary

Attributes inherited from Base

#client, #client_handler, #id, #opts

Instance Method Summary collapse

Methods inherited from Base

#build_dataset_map, #cleanup_target_container!, #clear_failed_state_snapshot, #complete_target!, #destroy_local_transfer_snapshots, #ensure_target_staged_or_complete!, #find, #force_writeout, #operation, #require_local_transfer_log!, #snapshot_datasets, #snapshot_name, #start_target!, #target_ct, #target_pool, #transfer_dataset, #validate_dataset_layout!

Methods inherited from Logged

#base_execute, #find

Methods inherited from Base

#base_execute, #call_cmd, #call_cmd!, #error, #error!, handle, #handled, #indirect?, #initialize, #manipulate, #manipulation_holder, #ok, #progress, #request_stop, run, run!

Constructor Details

This class inherits a constructor from OsCtld::Commands::Base

Instance Method Details

#after_state_snapshot(_ct, _running, _stopped) ⇒ Object (protected)



70
# File 'lib/osctld/commands/container/local_transfer/state.rb', line 70

def after_state_snapshot(_ct, _running, _stopped); end

#after_target_complete(_log, _running) ⇒ Object (protected)



72
# File 'lib/osctld/commands/container/local_transfer/state.rb', line 72

def after_target_complete(_log, _running); end

#execute(ct) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/osctld/commands/container/local_transfer/state.rb', line 5

def execute(ct)
  manipulate(ct) do
    log = prepare_state!(ct)
    running = log.state_running
    stopped = stop_source_for_state?(running)

    if stopped
      call_cmd!(Commands::Container::Stop, id: ct.id, pool: ct.pool.name)
      force_writeout(ct)
    end

    clear_failed_state_snapshot(ct, log)

    snap = snapshot_name(:state)
    snapshot_datasets(log, snap)

    ct.exclusively do
      ct.local_transfer_log.state_snapshot = snap
      ct.save_config
    end

    after_state_snapshot(ct, running, stopped)

    log.opts.datasets.each do |pair|
      transfer_dataset(pair, snap, from_snapshot: log.snapshots.last)
    end

    complete_target!(log)
    after_target_complete(log, running)

    ct.exclusively do
      ct.local_transfer_log.state = :transfer
      ct.save_config
    end
  end

  ok
end

#prepare_state!(ct) ⇒ Object (protected)



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/osctld/commands/container/local_transfer/state.rb', line 46

def prepare_state!(ct)
  log = ct.exclusively do
    ret = require_local_transfer_log!(ct)
    unless %i[base incremental].include?(ret.state) && ret.can_local_continue?(:transfer)
      error!('invalid local transfer sequence')
    end

    if ret.state_running.nil?
      ret.state_running = ct.state == :running
      ct.save_config
    end

    ret
  end

  ensure_target_staged_or_complete!(log)
  validate_dataset_layout!(ct)
  log
end

#stop_source_for_state?(_running) ⇒ Boolean (protected)

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


66
67
68
# File 'lib/osctld/commands/container/local_transfer/state.rb', line 66

def stop_source_for_state?(_running)
  raise NotImplementedError
end