dtk-action-agent 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 21e7fee109731e73725a259437c2d996742eef6e
4
+ data.tar.gz: ca71e73fdb44d748c8f4e14ce40bcb45b44b4984
5
+ SHA512:
6
+ metadata.gz: 433e0f1761c0de50613a8a9f6e543b8857b7c15ec4316fb821eb02546efbf3822b3cf094d966d6f9cc82a656fef60d8e3e4807e362568d38900edbbf2d3ba569
7
+ data.tar.gz: e9e1eb5dba5b37b41c33736a04a5e8383ef3ce0f15e94cae6dcecf2e8616e9255ec062c8dc5a557fa5ce1eeec406db98b0eaabeb41dbf285630eaa4908765dbc
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'json'
4
+ require File.expand_path('../../lib/arbiter', __FILE__)
5
+
6
+ unless ARGV[0]
7
+ error_msg = {
8
+ :error => 'You need to provide JSON with argument to method call'
9
+ }
10
+ print error_msg.to_json
11
+ else
12
+ content = JSON.parse(ARGV[0])
13
+ arbiter = DTK::Agent::Arbiter.new(content)
14
+ arbiter.run()
15
+
16
+ results = arbiter.results()
17
+ # we print results in json so that they can be serialized in another
18
+ print results.to_json
19
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/dtk-action-agent/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Rich PELAVIN"]
6
+ gem.email = ["rich@reactor8.com"]
7
+ gem.description = %q{The DTK Action Agent is designed to run commands on remote machine.}
8
+ gem.summary = %q{DTK Action Agent}
9
+ gem.homepage = ""
10
+ gem.licenses = ["GPL-3.0"]
11
+
12
+ gem.files = %w(Gemfile dtk-action-agent.gemspec)
13
+ gem.files += Dir.glob("bin/**/*")
14
+ gem.files += Dir.glob("lib/**/*")
15
+
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.name = "dtk-action-agent"
18
+ gem.require_paths = ["lib"]
19
+ gem.version = "#{DTK::ActionAgent::VERSION}.#{ARGV[3]}".chomp(".")
20
+
21
+ gem.add_dependency 'posix-spawn','0.3.8'
22
+ gem.add_dependency 'awesome_print', '1.1.0'
23
+ gem.add_dependency 'json', '1.8.2'
24
+
25
+ end
data/lib/arbiter.rb ADDED
@@ -0,0 +1,54 @@
1
+ require 'ap'
2
+ require 'posix-spawn'
3
+
4
+ module DTK
5
+ module Agent
6
+ class Arbiter
7
+
8
+ attr_reader :process_pool
9
+
10
+ def initialize(consumer_hash)
11
+ @received_message = consumer_hash
12
+ @process_pool = []
13
+ end
14
+
15
+ def run
16
+ (@received_message['commands']||[]).each do |message|
17
+ @process_pool << POSIX::Spawn::Child.new(message)
18
+ end
19
+
20
+ loop do
21
+ sleep(1)
22
+ @process_pool.each do |process|
23
+ unless process.status.exited?
24
+ next
25
+ end
26
+ end
27
+ break
28
+ end
29
+ end
30
+
31
+ def results
32
+ @process_pool.collect do |process|
33
+ {
34
+ :status => process.status.exitstatus,
35
+ :stdout => process.out,
36
+ :stderr => process.err
37
+ }
38
+ end
39
+ end
40
+
41
+ def print_results
42
+ @process_pool.each do |process|
43
+ ap process.status
44
+ ap "STDOUT"
45
+ print process.out
46
+ ap "STDERR"
47
+ print process.err
48
+ ap "-----------------------------------"
49
+ end
50
+ end
51
+
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,5 @@
1
+ module DTK
2
+ module ActionAgent
3
+ VERSION="0.0.1"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dtk-action-agent
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Rich PELAVIN
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: posix-spawn
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.3.8
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.3.8
27
+ - !ruby/object:Gem::Dependency
28
+ name: awesome_print
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 1.1.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 1.1.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 1.8.2
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 1.8.2
55
+ description: The DTK Action Agent is designed to run commands on remote machine.
56
+ email:
57
+ - rich@reactor8.com
58
+ executables:
59
+ - dtk-action-agent
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - Gemfile
64
+ - bin/dtk-action-agent
65
+ - dtk-action-agent.gemspec
66
+ - lib/arbiter.rb
67
+ - lib/dtk-action-agent/version.rb
68
+ homepage: ''
69
+ licenses:
70
+ - GPL-3.0
71
+ metadata: {}
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubyforge_project:
88
+ rubygems_version: 2.2.2
89
+ signing_key:
90
+ specification_version: 4
91
+ summary: DTK Action Agent
92
+ test_files: []