Class: Experiment

Inherits:
Object
  • Object
show all
Defined in:
lib/tree_building/claudius.rb

Instance Method Summary collapse

Constructor Details

#initialize(name, &block) ⇒ Experiment



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/tree_building/claudius.rb', line 11

def initialize(name, &block)
    @child_node
    @current_node = nil
    @tmp_concurrently = false
    @tmp_safely = false
    @tmp_execution_place = 'localhost'
    @in_after_scope = false
    @in_before_scope = false
    @root = Node.new(nil, block)
    @current_node = @root
    @root.name = name
    instance_eval(&block) if block
end

Instance Method Details

#after(*args, &block) ⇒ Object



47
48
49
50
51
# File 'lib/tree_building/claudius.rb', line 47

def after(*args, &block)
    @in_after_scope = true
    yield
    @in_after_scope = false
end

#before(*args, &block) ⇒ Object



41
42
43
44
45
# File 'lib/tree_building/claudius.rb', line 41

def before(*args, &block)
    @in_before_scope = true
    yield
    @in_before_scope = false
end

#concurrent(*args, &block) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/tree_building/claudius.rb', line 33

def concurrent(*args, &block)
    @child_node = ConcurrentNode.new(@current_node, block)
    @current_node.node_list.push(@child_node)
    @current_node = @child_node
    block.call
    @current_node = @current_node.parent
end

#concurrentlyObject



25
26
27
# File 'lib/tree_building/claudius.rb', line 25

def concurrently
    @tmp_concurrently = true
end

#destroy_machinesObject



114
115
116
117
118
# File 'lib/tree_building/claudius.rb', line 114

def destroy_machines
    if $vms_manager
        $vms_manager.destroy_machines
    end
end

#execute(*args, &block) ⇒ Object



86
87
88
89
90
91
92
93
94
# File 'lib/tree_building/claudius.rb', line 86

def execute(*args, &block)
    @child_node = ExecutionNode.new(@current_node, block)
    @child_node.is_safely = @tmp_safely
    @child_node.is_concurrently = @tmp_concurrently
    @current_node.node_list.push(@child_node)
    @current_node = @child_node
    block.call
    @current_node = @current_node.parent
end

#export_tree(path = 'execution_tree') ⇒ Object



120
121
122
# File 'lib/tree_building/claudius.rb', line 120

def export_tree(path = 'execution_tree')
    @root.print_tree(path)
end

#foreach(parameters, *args, &block) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/tree_building/claudius.rb', line 53

def foreach(parameters, *args, &block)

    @current_node = ForeachNode.new(@current_node, block)

    @current_node.is_safely = @tmp_safely
    @tmp_safely = false

    @current_node.is_concurrently = @tmp_concurrently
    @tmp_concurrently = false

    @current_node.parent.node_list.push(@current_node)

    parameters.each do |parameter|
        @child_node = Node.new(@current_node, block)
        @child_node.name = "Parameter: #{parameter}"
        @current_node.node_list.push(@child_node)
        @current_node = @child_node
        block.call parameter
        @current_node = @current_node.parent
    end

    @current_node = @current_node.parent
end

#on(instance, *args, &block) ⇒ Object



77
78
79
80
81
82
83
84
# File 'lib/tree_building/claudius.rb', line 77

def on(instance, *args, &block)
    @child_node = OnNode.new(@current_node, instance, block)

    @current_node.node_list.push(@child_node)
    @current_node = @child_node
    block.call
    @current_node = @current_node.parent
end

#runObject



106
107
108
109
110
111
112
# File 'lib/tree_building/claudius.rb', line 106

def run
    begin
        @root.run(nil)
    rescue
        '{error : true}'
    end
end

#safelyObject



29
30
31
# File 'lib/tree_building/claudius.rb', line 29

def safely
    @tmp_safely = true
end

#ssh(command) ⇒ Object



96
97
98
99
100
101
102
103
104
# File 'lib/tree_building/claudius.rb', line 96

def ssh(command)
    if @in_before_scope
        @current_node.before_list.push(command)
    elsif @in_after_scope
        @current_node.after_list.push(command)
    else
        @current_node.commands.push(command)
    end
end