excadg 0.2.2 → 0.2.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c18dc7316830116ac440841ff222fcd662b50307167b27962ea99003678f1bdf
4
- data.tar.gz: 6719109dd9d4fa114c5265da537bc104d12b1ee1c5e7b72ff0bd68f1525fa2cd
3
+ metadata.gz: 5bccdde832f42e296103812d1a60fa0adf8534d102c697d08b97697d5524dd37
4
+ data.tar.gz: a1da774573729eac556f4dfa3ff2c46bb21f1029db30cebeb172e00c9f3f9460
5
5
  SHA512:
6
- metadata.gz: 7d39543a7ebeea6c23ac1dd2d2f8bee42c7cff9a65028c1029996248cbf9a6bb2f7a79793dd5f3533c981d9e7c3ea01ab4358c2d3321e88768b05e87f14c49d4
7
- data.tar.gz: 2a558a66f53d2dc2da7a0af4df066f1122c96997bcf654f088426e88cd2691e79ca329d34a36029596761b78f13f5711934f138e44156f2d4782a5604fccc80e
6
+ metadata.gz: 29923112c768f2bb6a3ca99109c5d2a7bd48b6b0b45b9df7c9715ab29f557414fce338da3dd7ff6cbda5922d10bfd04d57316204c2279b8f402dba08687306f3
7
+ data.tar.gz: 496d09bc1390c268800976e6aa238f153671c9548d40be92e82e6d12b5a949537070317b65973ddbbfe62e6783b9643cf19280ea72a333ff577e0e6dc89cd67f
data/README.md CHANGED
@@ -9,7 +9,10 @@ Another feature is that the graph is dynamic and any vertex could produce anothe
9
9
  ## Tool
10
10
 
11
11
  There is a tool script in `bin` folder called `excadg`. Run `./bin/excadg --help` for available options.
12
- It allows to make and run basic payload graphs specified by a YAML config. See [config/](config/) folder for sample configs.
12
+ It allows to run basic payload graphs specified by a YAML config. See [config/](config/) folder for sample configs.
13
+
14
+ Another tool is `bin/adgen`, it has `--help` as well. It's suitable to generate relatively complex random graphs.
15
+ Try `./bin/adgen --range 1:5 --file mygraph.yaml --count 30` then `./bin/excadg --graph mygraph.yaml -l mygraph.log -d mygraph.yaml --gdump mygraph.jpg`.
13
16
 
14
17
  ## Framework
15
18
 
@@ -188,3 +191,6 @@ Logging is disabled by default, but it could be useful to debug tests. Add `ExcA
188
191
  - check for loops in the config
189
192
  - check for unreachable islands - graph connectivity
190
193
  - check that there are nodes to start from
194
+
195
+
196
+ - check MAX_CPU ...
data/bin/adgen ADDED
@@ -0,0 +1,81 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'logger'
4
+ require 'optparse'
5
+ require 'rgl/adjacency'
6
+ require 'rgl/dot'
7
+ require 'yaml'
8
+
9
+ log = Logger.new $stdout
10
+
11
+ options = {
12
+ count: 20,
13
+ delay: (1..5),
14
+ file: 'graph.yaml',
15
+ connectivity: 0.5
16
+ }
17
+
18
+ OptParse.new { |opts|
19
+ opts.banner = <<~EOD
20
+ sample config generator for excadg
21
+ makes a graph of randomly connected vertices
22
+ each vertex sleeps random # of seconds in range set
23
+ usage: #{$PROGRAM_NAME} [args]
24
+ EOD
25
+ opts.on('-c', '--count NUMBER', 'number of vertices to generate', "default: #{options[:count]}") { |o|
26
+ raise "Vertices count should be positive, got #{o.to_i}" unless o.to_i.positive?
27
+
28
+ options[:count] = o.to_i
29
+ }
30
+ opts.on('-f', '--file FILENAME', 'file name to dump config to', "default: #{options[:file]}") { |o|
31
+ options[:file] = o
32
+ }
33
+ opts.on('-r', '--range MIN:MAX', 'time range in seconds for vertives to sleep', "default: #{options[:delay]}") { |o|
34
+ min, max = o.split(':').collect(&:to_i)
35
+ raise "Min should be > 0, got #{min}" unless min.positive?
36
+ raise "Max should be >= #{min}, got #{max}" unless max >= min
37
+
38
+ options[:delay] = (min..max)
39
+ }
40
+ opts.on('--connectivity NUMBER',
41
+ 'graph connectivity, should be in (0...1)',
42
+ 'it sets a percentage of existing nodes are connected to new one',
43
+ 'the tool makes nodes iteratively, so there is a guarantee that result is a tree',
44
+ "default: #{options[:connectivity]}") { |o|
45
+ options[:connectivity] = o.to_f
46
+ raise 'Connectivity should be in 0...1' unless (0...1).include? options[:connectivity]
47
+ }
48
+ opts.on('--gdump FILENAME', 'dump initial execution graph to the file specified') { |o|
49
+ options[:gdump] = o
50
+ }
51
+ }.parse!
52
+
53
+ log.info 'generating graph'
54
+ graph = RGL::DirectedAdjacencyGraph.new
55
+ created_vertices = {}
56
+ options[:count].times { |i|
57
+ name = "v#{i}"
58
+ deps_count = rand(0..(created_vertices.size * options[:connectivity]))
59
+ deps = created_vertices.keys.sample(deps_count || 0)
60
+ created_vertices[name] = {
61
+ 'sleep' => rand(options[:delay]),
62
+ 'dependencies' => deps
63
+ }
64
+ deps.each { |dep|
65
+ graph.add_edge name, dep
66
+ }
67
+ print '.'
68
+ }
69
+ puts ''
70
+
71
+ log.info "saving graph to #{options[:file]}"
72
+ File.open(options[:file], 'w+') { |f|
73
+ f.write YAML.dump created_vertices
74
+ }
75
+
76
+ unless options[:gdump].nil?
77
+ log.info "dumping graph's image to #{options[:gdump]}"
78
+ graph.write_to_graphic_file(options[:gdump].split('.').last, options[:gdump].split('.')[...-1].join('.'))
79
+ end
80
+
81
+ log.info "graph config is saved to #{options[:file]}"
data/bin/excadg CHANGED
@@ -68,9 +68,9 @@ end
68
68
  raise "'#{options[:graph]}' config file is not readable" unless File.readable? options[:graph]
69
69
 
70
70
  ExcADG::Log.info 'reading config'
71
- config = YAML.safe_load_file options[:graph]
71
+ config = YAML.safe_load_file options[:graph], permitted_classes: [Symbol]
72
72
 
73
- runnable_vertices = config.select { |k, v| v&.dig('dependencies').nil? }.keys
73
+ runnable_vertices = config.select { |k, v| (v&.dig('dependencies') || []).empty? }.keys
74
74
  raise ArgumentError, 'at least one vertex should be ready to start' if runnable_vertices.empty?
75
75
 
76
76
  ExcADG::Log.info 'collect execution graph from config'
data/lib/excadg/broker.rb CHANGED
@@ -55,7 +55,7 @@ module ExcADG
55
55
  # @param period time between vertices state check
56
56
  def wait_all timeout: 60, period: 1
57
57
  Thread.new {
58
- Log.info "timeout is #{timeout} seconds"
58
+ Log.info "timeout is #{timeout || '∞'} seconds"
59
59
  Timeout.timeout(timeout) {
60
60
  loop {
61
61
  sleep period
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: excadg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - skorobogatydmitry
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-07-10 00:00:00.000000000 Z
11
+ date: 2024-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rgl
@@ -31,10 +31,12 @@ description: "\n\nThat's a library (framework) to execute a graph of dependent t
31
31
  email: skorobogaty.dmitry@gmail.com
32
32
  executables:
33
33
  - excadg
34
+ - adgen
34
35
  extensions: []
35
36
  extra_rdoc_files: []
36
37
  files:
37
38
  - README.md
39
+ - bin/adgen
38
40
  - bin/excadg
39
41
  - lib/excadg.rb
40
42
  - lib/excadg/assertions.rb