nutella_framework 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ac187479daa0e0d14c536168f984cd938ab4186b
4
- data.tar.gz: cb4b9e47db857035b8d19cfa3a1fbf112760cd50
3
+ metadata.gz: 42a3d1f40115ef7fd3fb351ce9ae42589b26b5cf
4
+ data.tar.gz: dfe33a197e9196709b3e61654a50c81320c95548
5
5
  SHA512:
6
- metadata.gz: d5432a739db7b22af3e5a5ff212c226a5e5b8054355521e21593404fd4b72f4c99a001fcdc2c965e34abbf56e6f9454384e0b685e522055272ea57737bc8a2e9
7
- data.tar.gz: db9906aa9ae78f264f3a72e93b15b1321f054ea77fd77e801691f8c2a4dfdfe38ccf0de0f531cbf69dea9a42a75e2fe5542e5b13328a80a441143f2b62be08a1
6
+ metadata.gz: aa57378efdaf2c2cceef0f72bb7440026fde992795e3bad03d58c8a7e162b6b78b3ce5e527ccdd5620f54ed52550c2dc5a3babb11ed89cb93400e655e9f0395d
7
+ data.tar.gz: 5ac1bbc05b8207ea94707b70105e55fea8ea08dffd7b41697cfea6510c53dde3a1896a817a1002fe4aad7e4f20f514fb2cafda180ceb596437db6178187c2340
data/Gemfile CHANGED
@@ -7,7 +7,7 @@ gem 'sinatra', '~>1.4.5', '>=1.4.5'
7
7
  gem 'thin', '~>1.6.3', '>=1.6.3'
8
8
  gem 'nokogiri', '~>1.6.3', '>=1.6.3'
9
9
  gem 'slop', '~>4.0.0', '>=4.0.0'
10
- gem 'nutella_lib','~>0.4.3', '>=0.4.3'
10
+ gem 'nutella_lib','~>0.4.5', '>=0.4.5'
11
11
 
12
12
 
13
13
  group :development do
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.2
1
+ 0.4.3
@@ -0,0 +1,25 @@
1
+ require_relative '../../lib/config/runlist'
2
+ require_relative '../../lib/config/config'
3
+ require_relative '../../nutella_lib/framework_core'
4
+
5
+ # Framework bots can access all the parameters they need directly
6
+ # from the configuration file and the runlist,
7
+ # to which they have full access to.
8
+
9
+ # Access the config file like so:
10
+ # Nutella.config['broker']
11
+
12
+ # Access the runs list like so:
13
+ # Nutella.runlist.all_runs
14
+
15
+
16
+ # Initialize this bot as framework component
17
+ nutella.f.init(Nutella.config['broker'], 'example_framework_bot')
18
+
19
+
20
+ # Your code goes here! Go crazy!
21
+
22
+
23
+ # Does your bot die? If all your bot is doing is waiting for message on the network
24
+ # and responding to them, the main thread will terminate unless you call...
25
+ # nutella.f.net.listen
@@ -0,0 +1,6 @@
1
+ #!/bin/sh
2
+
3
+ BASEDIR=$(dirname $0)
4
+
5
+ ruby $BASEDIR/example_framework_bot.rb > /dev/null 2>&1 &
6
+ echo $! > $BASEDIR/.pid
@@ -8,11 +8,11 @@
8
8
  </head>
9
9
  <body>
10
10
  <h1>Example framework interface</h1>
11
- <p>This is an example of a framework interface. It really doesn't belong here but for now this
12
- is ok. Once we'll have real framework interfaces this is going to be be moved to a template.
13
- </p>
14
- <p>And just to make sure we are loading not just the index, here is a picture of dandelions</p>
11
+ <p>This is an example of a framework interface. Use this template to write your own framework interface.</p>
12
+ <p>And just to make sure we are not just loading the index.html file, here is a picture of dandelions</p>
15
13
  <img src="dandelion-flowers-card.jpg" width="500">
16
14
 
15
+ WE NEED TO COMPLETE THIS TEMPLATE BUT IN ORDER FOR THAT TO HAPPEN, I NEED JAVASCRIPT APIs!!!
16
+
17
17
  </body>
18
18
  </html>
@@ -0,0 +1,42 @@
1
+ # Logger bot
2
+ # ----------
3
+ #
4
+ # This bot is in charge of recording all the messages that are sent by
5
+ # all components in all runs. It records all info sent to channels:
6
+ # - `/nutella/logging`
7
+ # - `/nutella/apps/<app_id>/logging`
8
+ # - `/nutella/apps/<app_id>/runs/<run_id>/logging`
9
+ # All logs are appended to a MongoDB collection called `logs`, inside the
10
+ # `nutella` database.
11
+ #
12
+ # -----------------------------------------------------------------------------
13
+
14
+ require_relative '../../lib/config/runlist'
15
+ require_relative '../../lib/config/config'
16
+ require_relative '../../nutella_lib/framework_core'
17
+
18
+ require_relative 'utils'
19
+
20
+ # Initialize this bot as framework component
21
+ nutella.f.init(Nutella.config['broker'], 'example_framework_bot')
22
+
23
+ # Get a mongo persisted collection
24
+ db = nutella.f.persist.get_mongo_collection_store 'logs'
25
+
26
+
27
+ # Listen for run-level log messages
28
+ nutella.f.net.subscribe_to_all_runs('logging', lambda do |payload, app_id, run_id, from|
29
+ db.push assemble_log(payload, from)
30
+ end)
31
+ # Listen for app-level log messages
32
+ nutella.f.net.subscribe_to_all_apps('logging', lambda do |payload, app_id, from|
33
+ db.push assemble_log(payload, from)
34
+ end)
35
+ # Listen for framework-level log messages
36
+ nutella.f.net.subscribe('logging', lambda do |payload, from|
37
+ db.push assemble_log(payload, from)
38
+ end)
39
+
40
+
41
+ # Listen and process messages as they come
42
+ nutella.f.net.listen
@@ -0,0 +1,5 @@
1
+ #!/bin/sh
2
+
3
+ BASEDIR=$(dirname $0)
4
+ ruby $BASEDIR/logging_bot.rb > /dev/null 2>&1 &
5
+ echo $! > $BASEDIR/.pid
@@ -0,0 +1,8 @@
1
+ # Utility functions for logging bot
2
+
3
+ def assemble_log(payload, from)
4
+ h = Hash.new
5
+ h.merge! payload
6
+ h['from'] = from
7
+ h
8
+ end
@@ -1,50 +1,35 @@
1
+ require_relative '../../lib/config/runlist'
2
+ require_relative '../../lib/config/config'
1
3
  require_relative '../../nutella_lib/framework_core'
2
4
 
3
- # Define a couple of utility functions to better deal with the runs list
4
- def all_apps( runlist_file )
5
- runlist_h = JSON.parse(IO.read(runlist_file))
6
- runlist_h.keys
7
- end
8
-
9
- def runs_for_app( runlist_file, app_id )
10
- runlist_h = JSON.parse(IO.read(runlist_file))
11
- # If there is no app with this id, then return false and do nothing
12
- return [] if runlist_h[app_id].nil?
13
- runs = runlist_h[app_id]['runs']
14
- runs.nil? ? [] : runs
15
- end
5
+ # Framework bots can access all the parameters they need directly
6
+ # from the configuration file and the runlist,
7
+ # to which they have full access to.
16
8
 
9
+ # Access the config file like so:
10
+ # Nutella.config['broker']
17
11
 
18
- # Parse configuration file and runlist from the command line
19
- config_file = ARGV[0]
20
- runlist_file = ARGV[1]
12
+ # Access the runs list like so:
13
+ # Nutella.runlist.all_runs
21
14
 
22
- # Try to parse both config file and runlist and terminate if we can't
23
- begin
24
- config_h = JSON.parse(IO.read(config_file))
25
- runlist_h = JSON.parse(IO.read(runlist_file))
26
- rescue
27
- # something went wrong
28
- abort 'Impossible to parse configuration and/or runlist files!'
29
- end
30
15
 
31
16
  # Initialize this bot as framework component
32
- nutella.f.init(config_h['broker'], 'app_runs_list_bot')
17
+ nutella.f.init(Nutella.config['broker'], 'app_runs_list_bot')
33
18
 
34
19
 
35
20
  # Listen for runs_list requests (done by app components when they connect)
36
21
  nutella.f.net.handle_requests_on_all_apps('app_runs_list', lambda do |req, app_id, from|
37
- runs_for_app(runlist_file, app_id)
22
+ Nutella.runlist.runs_for_app app_id
38
23
  end)
39
24
 
40
25
 
41
26
  # Whenever the runs list is updated, fire an updated runlist to all the apps
42
- p = JSON.parse(IO.read(runlist_file))
27
+ p = Nutella.runlist.all_runs
43
28
  while sleep .5
44
- n = JSON.parse IO.read runlist_file
29
+ n = Nutella.runlist.all_runs
45
30
  if p!=n
46
31
  all_apps.each do |app_id, _|
47
- nutella.f.net.publish_to_app(app_id, 'app_runs_list', runs_for_app(app_id, runlist_h))
32
+ nutella.f.net.publish_to_app(app_id, 'app_runs_list', Nutella.runlist.runs_for_app(app_id))
48
33
  end
49
34
  p = n
50
35
  end
@@ -1,8 +1,5 @@
1
1
  #!/bin/sh
2
2
 
3
3
  BASEDIR=$(dirname $0)
4
-
5
- # Pass the configuration file and the runlist
6
-
7
- ruby $BASEDIR/app_runs_list_bot.rb $1 $2 > /dev/null 2>&1 &
4
+ ruby $BASEDIR/app_runs_list_bot.rb > /dev/null 2>&1 &
8
5
  echo $! > $BASEDIR/.pid
@@ -2,11 +2,11 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: nutella_framework 0.4.2 ruby lib
5
+ # stub: nutella_framework 0.4.3 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "nutella_framework"
9
- s.version = "0.4.2"
9
+ s.version = "0.4.3"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
@@ -30,8 +30,13 @@ Gem::Specification.new do |s|
30
30
  "bin/nutella",
31
31
  "data/index.html",
32
32
  "data/startup",
33
- "framework_components/example_framework_interface/dandelion-flowers-card.jpg",
34
- "framework_components/example_framework_interface/index.html",
33
+ "example_framework_components/example_framework_bot/example_framework_bot.rb",
34
+ "example_framework_components/example_framework_bot/startup",
35
+ "framework_components/example_framework_web_interface/dandelion-flowers-card.jpg",
36
+ "framework_components/example_framework_web_interface/index.html",
37
+ "framework_components/logging_bot/logging_bot.rb",
38
+ "framework_components/logging_bot/startup",
39
+ "framework_components/logging_bot/utils.rb",
35
40
  "framework_components/main_interface/main_interface_bot.rb",
36
41
  "framework_components/main_interface/public/index.html",
37
42
  "framework_components/main_interface/startup",
@@ -67,8 +72,9 @@ Gem::Specification.new do |s|
67
72
  "lib/tmux/tmux.rb",
68
73
  "nutella_framework.gemspec",
69
74
  "nutella_lib/framework_core.rb",
75
+ "nutella_lib/framework_log.rb",
70
76
  "nutella_lib/framework_net.rb",
71
- "nutella_lib/framework_persistence.rb",
77
+ "nutella_lib/framework_persist.rb",
72
78
  "test/commands/test_cmd_cli_params_parsing.rb",
73
79
  "test/commands/test_command_template.rb",
74
80
  "test/config/test_current_app_utils.rb",
@@ -94,7 +100,7 @@ Gem::Specification.new do |s|
94
100
  s.add_runtime_dependency(%q<thin>, [">= 1.6.3", "~> 1.6.3"])
95
101
  s.add_runtime_dependency(%q<nokogiri>, [">= 1.6.3", "~> 1.6.3"])
96
102
  s.add_runtime_dependency(%q<slop>, [">= 4.0.0", "~> 4.0.0"])
97
- s.add_runtime_dependency(%q<nutella_lib>, [">= 0.4.3", "~> 0.4.3"])
103
+ s.add_runtime_dependency(%q<nutella_lib>, [">= 0.4.5", "~> 0.4.5"])
98
104
  s.add_development_dependency(%q<shoulda>, [">= 3", "~> 3"])
99
105
  s.add_development_dependency(%q<yard>, [">= 0.8.7", "~> 0.8"])
100
106
  s.add_development_dependency(%q<rdoc>, [">= 4.0", "~> 4.0"])
@@ -109,7 +115,7 @@ Gem::Specification.new do |s|
109
115
  s.add_dependency(%q<thin>, [">= 1.6.3", "~> 1.6.3"])
110
116
  s.add_dependency(%q<nokogiri>, [">= 1.6.3", "~> 1.6.3"])
111
117
  s.add_dependency(%q<slop>, [">= 4.0.0", "~> 4.0.0"])
112
- s.add_dependency(%q<nutella_lib>, [">= 0.4.3", "~> 0.4.3"])
118
+ s.add_dependency(%q<nutella_lib>, [">= 0.4.5", "~> 0.4.5"])
113
119
  s.add_dependency(%q<shoulda>, [">= 3", "~> 3"])
114
120
  s.add_dependency(%q<yard>, [">= 0.8.7", "~> 0.8"])
115
121
  s.add_dependency(%q<rdoc>, [">= 4.0", "~> 4.0"])
@@ -125,7 +131,7 @@ Gem::Specification.new do |s|
125
131
  s.add_dependency(%q<thin>, [">= 1.6.3", "~> 1.6.3"])
126
132
  s.add_dependency(%q<nokogiri>, [">= 1.6.3", "~> 1.6.3"])
127
133
  s.add_dependency(%q<slop>, [">= 4.0.0", "~> 4.0.0"])
128
- s.add_dependency(%q<nutella_lib>, [">= 0.4.3", "~> 0.4.3"])
134
+ s.add_dependency(%q<nutella_lib>, [">= 0.4.5", "~> 0.4.5"])
129
135
  s.add_dependency(%q<shoulda>, [">= 3", "~> 3"])
130
136
  s.add_dependency(%q<yard>, [">= 0.8.7", "~> 0.8"])
131
137
  s.add_dependency(%q<rdoc>, [">= 4.0", "~> 4.0"])
@@ -3,6 +3,8 @@ require 'config/runlist'
3
3
 
4
4
  # APIs sub-modules
5
5
  require_relative 'framework_net'
6
+ require_relative 'framework_log'
7
+ require_relative 'framework_persist'
6
8
 
7
9
 
8
10
  module Nutella
@@ -13,7 +15,6 @@ module Nutella
13
15
  end
14
16
 
15
17
 
16
-
17
18
  # Framework-level APIs sub-module
18
19
  module Framework
19
20
 
@@ -25,6 +26,7 @@ module Nutella
25
26
  Nutella.run_id = nil
26
27
  Nutella.component_id = component_id
27
28
  Nutella.resource_id = nil
29
+ Nutella.mongo_host = broker_hostname
28
30
  Nutella.mqtt = SimpleMQTTClient.new broker_hostname
29
31
  end
30
32
 
@@ -36,19 +38,6 @@ module Nutella
36
38
 
37
39
  # Utility functions
38
40
 
39
-
40
- # Parse command line arguments for framework level components
41
- #
42
- # @param [Array] args command line arguments array
43
- # @return [String] broker
44
- def self.parse_args(args)
45
- if args.length < 1
46
- STDERR.puts 'Couldn\'t read broker address from the command line, impossible to initialize component!'
47
- return
48
- end
49
- return args[0]
50
- end
51
-
52
41
  # Extracts the component name from the folder where the code for this component is located
53
42
  #
54
43
  # @return [String] the component name
@@ -0,0 +1,49 @@
1
+ require 'ansi'
2
+
3
+ module Nutella
4
+
5
+ module Framework
6
+
7
+ module Log
8
+
9
+ def self.debug(message, code=nil)
10
+ puts( ANSI.cyan + message + ANSI.reset )
11
+ Nutella.f.net.publish( 'logging', log_to_json(message, code, __method__) )
12
+ code
13
+ end
14
+
15
+ def self.info(message, code=nil)
16
+ puts( message )
17
+ Nutella.f.net.publish( 'logging', log_to_json(message, code, __method__) )
18
+ code
19
+ end
20
+
21
+ def self.success(message, code=nil)
22
+ puts( ANSI.green + message + ANSI.reset )
23
+ Nutella.f.net.publish( 'logging', log_to_json(message, code, __method__) )
24
+ code
25
+ end
26
+
27
+ def self.warn(message, code=nil)
28
+ puts( ANSI.yellow + message + ANSI.reset )
29
+ Nutella.f.net.publish( 'logging', log_to_json(message, code, __method__) )
30
+ code
31
+ end
32
+
33
+ def self.error(message, code=nil)
34
+ puts( ANSI.red + message + ANSI.reset )
35
+ Nutella.f.net.publish( 'logging', log_to_json(message, code, __method__) )
36
+ code
37
+ end
38
+
39
+ private
40
+
41
+ def self.log_to_json( message, code, level)
42
+ code.nil? ? {level: level, message: message} : {level: level, message: message, code: code}
43
+ end
44
+
45
+ end
46
+
47
+ end
48
+
49
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nutella_framework
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alessandro Gnoli
@@ -156,20 +156,20 @@ dependencies:
156
156
  requirements:
157
157
  - - ">="
158
158
  - !ruby/object:Gem::Version
159
- version: 0.4.3
159
+ version: 0.4.5
160
160
  - - "~>"
161
161
  - !ruby/object:Gem::Version
162
- version: 0.4.3
162
+ version: 0.4.5
163
163
  type: :runtime
164
164
  prerelease: false
165
165
  version_requirements: !ruby/object:Gem::Requirement
166
166
  requirements:
167
167
  - - ">="
168
168
  - !ruby/object:Gem::Version
169
- version: 0.4.3
169
+ version: 0.4.5
170
170
  - - "~>"
171
171
  - !ruby/object:Gem::Version
172
- version: 0.4.3
172
+ version: 0.4.5
173
173
  - !ruby/object:Gem::Dependency
174
174
  name: shoulda
175
175
  requirement: !ruby/object:Gem::Requirement
@@ -309,8 +309,13 @@ files:
309
309
  - bin/nutella
310
310
  - data/index.html
311
311
  - data/startup
312
- - framework_components/example_framework_interface/dandelion-flowers-card.jpg
313
- - framework_components/example_framework_interface/index.html
312
+ - example_framework_components/example_framework_bot/example_framework_bot.rb
313
+ - example_framework_components/example_framework_bot/startup
314
+ - framework_components/example_framework_web_interface/dandelion-flowers-card.jpg
315
+ - framework_components/example_framework_web_interface/index.html
316
+ - framework_components/logging_bot/logging_bot.rb
317
+ - framework_components/logging_bot/startup
318
+ - framework_components/logging_bot/utils.rb
314
319
  - framework_components/main_interface/main_interface_bot.rb
315
320
  - framework_components/main_interface/public/index.html
316
321
  - framework_components/main_interface/startup
@@ -346,8 +351,9 @@ files:
346
351
  - lib/tmux/tmux.rb
347
352
  - nutella_framework.gemspec
348
353
  - nutella_lib/framework_core.rb
354
+ - nutella_lib/framework_log.rb
349
355
  - nutella_lib/framework_net.rb
350
- - nutella_lib/framework_persistence.rb
356
+ - nutella_lib/framework_persist.rb
351
357
  - test/commands/test_cmd_cli_params_parsing.rb
352
358
  - test/commands/test_command_template.rb
353
359
  - test/config/test_current_app_utils.rb