xpflow 0.1b

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. data/bin/xpflow +96 -0
  2. data/lib/colorado.rb +198 -0
  3. data/lib/json/add/core.rb +243 -0
  4. data/lib/json/add/rails.rb +8 -0
  5. data/lib/json/common.rb +423 -0
  6. data/lib/json/editor.rb +1369 -0
  7. data/lib/json/ext.rb +28 -0
  8. data/lib/json/pure/generator.rb +442 -0
  9. data/lib/json/pure/parser.rb +320 -0
  10. data/lib/json/pure.rb +15 -0
  11. data/lib/json/version.rb +8 -0
  12. data/lib/json.rb +62 -0
  13. data/lib/mime/types.rb +881 -0
  14. data/lib/mime-types.rb +3 -0
  15. data/lib/restclient/abstract_response.rb +106 -0
  16. data/lib/restclient/exceptions.rb +193 -0
  17. data/lib/restclient/net_http_ext.rb +55 -0
  18. data/lib/restclient/payload.rb +235 -0
  19. data/lib/restclient/raw_response.rb +34 -0
  20. data/lib/restclient/request.rb +316 -0
  21. data/lib/restclient/resource.rb +169 -0
  22. data/lib/restclient/response.rb +24 -0
  23. data/lib/restclient.rb +174 -0
  24. data/lib/xpflow/bash.rb +341 -0
  25. data/lib/xpflow/bundle.rb +113 -0
  26. data/lib/xpflow/cmdline.rb +249 -0
  27. data/lib/xpflow/collection.rb +122 -0
  28. data/lib/xpflow/concurrency.rb +79 -0
  29. data/lib/xpflow/data.rb +393 -0
  30. data/lib/xpflow/dsl.rb +816 -0
  31. data/lib/xpflow/engine.rb +574 -0
  32. data/lib/xpflow/ensemble.rb +135 -0
  33. data/lib/xpflow/events.rb +56 -0
  34. data/lib/xpflow/experiment.rb +65 -0
  35. data/lib/xpflow/exts/facter.rb +30 -0
  36. data/lib/xpflow/exts/g5k.rb +931 -0
  37. data/lib/xpflow/exts/g5k_use.rb +50 -0
  38. data/lib/xpflow/exts/gui.rb +140 -0
  39. data/lib/xpflow/exts/model.rb +155 -0
  40. data/lib/xpflow/graph.rb +1603 -0
  41. data/lib/xpflow/graph_xpflow.rb +251 -0
  42. data/lib/xpflow/import.rb +196 -0
  43. data/lib/xpflow/library.rb +349 -0
  44. data/lib/xpflow/logging.rb +153 -0
  45. data/lib/xpflow/manager.rb +147 -0
  46. data/lib/xpflow/nodes.rb +1250 -0
  47. data/lib/xpflow/runs.rb +773 -0
  48. data/lib/xpflow/runtime.rb +125 -0
  49. data/lib/xpflow/scope.rb +168 -0
  50. data/lib/xpflow/ssh.rb +186 -0
  51. data/lib/xpflow/stat.rb +50 -0
  52. data/lib/xpflow/stdlib.rb +381 -0
  53. data/lib/xpflow/structs.rb +369 -0
  54. data/lib/xpflow/taktuk.rb +193 -0
  55. data/lib/xpflow/templates/ssh-config.basic +14 -0
  56. data/lib/xpflow/templates/ssh-config.inria +18 -0
  57. data/lib/xpflow/templates/ssh-config.proxy +13 -0
  58. data/lib/xpflow/templates/taktuk +6590 -0
  59. data/lib/xpflow/templates/utils/batch +4 -0
  60. data/lib/xpflow/templates/utils/bootstrap +12 -0
  61. data/lib/xpflow/templates/utils/hostname +3 -0
  62. data/lib/xpflow/templates/utils/ping +3 -0
  63. data/lib/xpflow/templates/utils/rsync +12 -0
  64. data/lib/xpflow/templates/utils/scp +17 -0
  65. data/lib/xpflow/templates/utils/scp_many +8 -0
  66. data/lib/xpflow/templates/utils/ssh +3 -0
  67. data/lib/xpflow/templates/utils/ssh-interactive +4 -0
  68. data/lib/xpflow/templates/utils/taktuk +19 -0
  69. data/lib/xpflow/threads.rb +187 -0
  70. data/lib/xpflow/utils.rb +569 -0
  71. data/lib/xpflow/visual.rb +230 -0
  72. data/lib/xpflow/with_g5k.rb +7 -0
  73. data/lib/xpflow.rb +349 -0
  74. metadata +135 -0
@@ -0,0 +1,4 @@
1
+ #!/bin/bash -eu
2
+ # Runs SSH so that it will hold connection for the given amount of seconds.
3
+
4
+ exec <%= path %>/ssh -f sleep ${1}
@@ -0,0 +1,12 @@
1
+ #!/bin/bash -eu
2
+ #
3
+ # We boostrap here and return YAML
4
+ #
5
+ # The needed variables are:
6
+ # - tmpdir - tmpdir created on a remote site
7
+ #
8
+
9
+ tmpdir=$(<%= path %>/ssh "mktemp -d")
10
+
11
+ echo "---"
12
+ echo ":tmpdir: ${tmpdir}"
@@ -0,0 +1,3 @@
1
+ #!/bin/bash -eu
2
+
3
+ exec <%= path %>/ssh hostname
@@ -0,0 +1,3 @@
1
+ #!/bin/bash
2
+
3
+ exec <%= path %>/ssh true
@@ -0,0 +1,12 @@
1
+ #!/bin/bash -eux
2
+
3
+ if [ $# -ne 2 ]; then
4
+ echo "Give src dir and dst dir."
5
+ exit 1
6
+ fi
7
+
8
+ src="$1"
9
+ dst="$2"
10
+
11
+ cmd="scp -S <%= path %>/ssh $src :$dst"
12
+ exec "$cmd"
@@ -0,0 +1,17 @@
1
+ #!/bin/bash -eu
2
+
3
+ if [ $# -ne 2 ]; then
4
+ echo "Give src dir and dst dir."
5
+ exit 1
6
+ fi
7
+
8
+ src="$1"
9
+ dst="$2"
10
+
11
+ switch=""
12
+
13
+ if [ -d "$src" ]; then
14
+ switch="-r"
15
+ fi
16
+
17
+ exec scp -F <%= path %>/ssh-config ${switch} ${src} this:${dst}
@@ -0,0 +1,8 @@
1
+ #!/bin/bash
2
+
3
+ set -eux
4
+
5
+ dest_dir=${1}
6
+ shift
7
+
8
+ exec scp -F <%= path %>/ssh-config -- "$@" this:${dest_dir}
@@ -0,0 +1,3 @@
1
+ #!/bin/bash -eu
2
+
3
+ exec ssh -F <%= path %>/ssh-config this "$@"
@@ -0,0 +1,4 @@
1
+ #!/bin/bash -eu
2
+ #
3
+
4
+ exec <%= path %>/ssh -t
@@ -0,0 +1,19 @@
1
+ #!/bin/bash -eu
2
+ #
3
+ # this assumes that taktuk is installed on nodes
4
+
5
+ if [ $# -eq 0 ]; then
6
+ echo "No file given."
7
+ exit 1
8
+ fi
9
+
10
+ list_local=${1}
11
+ shift
12
+
13
+ tmpdir=$(<%= path %>/ssh mktemp -d)
14
+ list_remote=${tmpdir}/hostfile
15
+
16
+ # <%= path %>/batch 3 # pipe connection for 3 seconds
17
+ <%= path %>/scp ${list_local} ${list_remote}
18
+ <%= path %>/ssh taktuk -f ${list_remote} "$@"
19
+ # <%= path %>/ssh rm -rf ${tmpdir}
@@ -0,0 +1,187 @@
1
+
2
+ require 'thread'
3
+
4
+ module XPFlow
5
+
6
+ $xpflow_global_mutex = Mutex.new
7
+
8
+ def self.global_synchronize(&block)
9
+ return $xpflow_global_mutex.synchronize(&block)
10
+ end
11
+
12
+ $xpflow_global_counters = {}
13
+
14
+ def self.global_counter(label = :global)
15
+ value = global_synchronize do
16
+ h = $xpflow_global_counters
17
+ if h.key?(label)
18
+ h[label] += 1
19
+ else
20
+ h[label] = 0
21
+ end
22
+ h[label]
23
+ end
24
+ return value
25
+ end
26
+
27
+ # Implements a pool of threads.
28
+ # The threads can execute blocks of code
29
+
30
+ class ThreadPool
31
+
32
+ def initialize(size)
33
+ @size = size
34
+ @queue = Queue.new
35
+ @threads = size.times.map do
36
+ Thread.new do
37
+ worker
38
+ end
39
+ end
40
+ end
41
+
42
+ def worker
43
+ while true
44
+ el = @queue.pop
45
+ break if el.nil?
46
+ block, args = el
47
+ block.call(*args)
48
+ end
49
+ end
50
+
51
+ def execute(*args, &block)
52
+ @queue.push([ block, args ])
53
+ end
54
+
55
+ def join(yes_or_no = true)
56
+ @size.times { @queue.push(nil) }
57
+ @threads.each { |t| t.join } if yes_or_no
58
+ end
59
+ end
60
+
61
+ class OrderedArray
62
+
63
+ def initialize
64
+ @queue = []
65
+ @lock = Mutex.new
66
+ @cond = ConditionVariable.new
67
+ end
68
+
69
+ def give(i, x)
70
+ @lock.synchronize do
71
+ @queue.push([i, x])
72
+ @cond.broadcast
73
+ end
74
+ end
75
+
76
+ def take(n)
77
+ @lock.synchronize do
78
+ while @queue.length < n
79
+ @cond.wait(@lock)
80
+ end
81
+ arr = @queue.sort { |x, y| x.first <=> y.first }.map { |i, x| x }
82
+ arr
83
+ end
84
+ end
85
+
86
+ end
87
+
88
+ # Let's one thread wait for a value
89
+ # Do not call 'take' multiple times.
90
+
91
+ class Meeting
92
+
93
+ def initialize(run)
94
+ @lock = Mutex.new
95
+ @cond = ConditionVariable.new
96
+ @queue = []
97
+ @run = run
98
+ end
99
+
100
+ def give(x)
101
+ @lock.synchronize do
102
+ @queue.push(x)
103
+ @cond.broadcast
104
+ end
105
+ end
106
+
107
+ def _take(n)
108
+ flatten = (n < 0)
109
+ n = n.abs
110
+ @lock.synchronize do
111
+ while @queue.length < n
112
+ @cond.wait(@lock)
113
+ end
114
+ arr = @queue.shift(n)
115
+ arr = arr.first if flatten
116
+ arr
117
+ end
118
+ end
119
+
120
+ def take(n)
121
+ begin
122
+ return _take(n)
123
+ rescue Interrupt => e
124
+ raise RunMsgError.new(@run, "Thread rendez-vous has been interrupted.")
125
+ end
126
+ end
127
+
128
+ end
129
+
130
+ # Collects exceptions (using 'push' method)
131
+ # and rethrows them collectively as RunError.
132
+
133
+ class ExceptionBag
134
+
135
+ def initialize
136
+ @lock = Mutex.new
137
+ @bag = []
138
+ end
139
+
140
+ def push(x)
141
+ @lock.synchronize do
142
+ @bag.push(x)
143
+ end
144
+ end
145
+
146
+ def raise_if_needed(run)
147
+ @lock.synchronize do
148
+ copy = @bag.map.to_a
149
+ raise RunError.new(run, copy) if copy.length > 0
150
+ end
151
+ end
152
+
153
+ end
154
+
155
+ class Threads
156
+
157
+ def self.defaults
158
+ return { :join => true }
159
+ end
160
+
161
+ def self.merge_opts(x, y)
162
+ return x.merge(y) { |k, old, new|
163
+ (new.nil? ? old : new)
164
+ }
165
+ end
166
+
167
+ def self.run(run, list, opts = {}, &block)
168
+ opts = merge_opts(defaults(), opts)
169
+ bag = ExceptionBag.new
170
+ size = [ list.length, opts[:pool] ].min
171
+ pool = ThreadPool.new(size)
172
+ list.each_with_index do |el, i|
173
+ pool.execute(el, i) do |x, it|
174
+ begin
175
+ block.call(x, it)
176
+ rescue RunError => e
177
+ bag.push(e)
178
+ end
179
+ end
180
+ end
181
+ pool.join(opts[:join])
182
+ bag.raise_if_needed(run)
183
+ end
184
+
185
+ end
186
+
187
+ end