cpee 1.4.31 → 1.4.32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/cockpit/css/ui.css +25 -6
  3. data/cockpit/css/wfadaptor.css +20 -10
  4. data/cockpit/graph.html +7 -2
  5. data/cockpit/index.html +2 -3
  6. data/cockpit/js/details.js +3 -0
  7. data/cockpit/js/instance.js +70 -20
  8. data/cockpit/js/ui.js +32 -5
  9. data/cockpit/js/wfadaptor.js +70 -42
  10. data/cockpit/themes/compact/theme.js +55 -46
  11. data/cockpit/themes/default/symbols/otherwise.svg +2 -1
  12. data/cockpit/themes/{promise/symbols/choose.svg → default/symbols/parallel_branch_compact.svg} +2 -2
  13. data/cockpit/themes/default/theme.js +39 -44
  14. data/cockpit/themes/extended/theme.js +252 -60
  15. data/cockpit/themes/{lego → packed}/theme.js +492 -105
  16. data/cockpit/track.html +39 -32
  17. data/cpee.gemspec +1 -1
  18. data/lib/cpee/controller.rb +2 -0
  19. data/lib/cpee/instantiation.rb +22 -5
  20. data/lib/cpee/value_helper.rb +1 -1
  21. data/lib/instantiation.xml +3 -0
  22. data/log/elasticsearch_logging.rb +189 -50
  23. data/server/handlerwrappers/default.rb +3 -3
  24. data/server/server.pid +1 -0
  25. metadata +5 -53
  26. data/cockpit/themes/lego/rngs/alternative.rng +0 -5
  27. data/cockpit/themes/lego/rngs/call.rng +0 -41
  28. data/cockpit/themes/lego/rngs/choose.rng +0 -8
  29. data/cockpit/themes/lego/rngs/critical.rng +0 -5
  30. data/cockpit/themes/lego/rngs/loop.rng +0 -11
  31. data/cockpit/themes/lego/rngs/manipulate.rng +0 -6
  32. data/cockpit/themes/lego/rngs/parallel.rng +0 -5
  33. data/cockpit/themes/lego/rngs/parallel_branch.rng +0 -8
  34. data/cockpit/themes/lego/symbols/alternative.svg +0 -4
  35. data/cockpit/themes/lego/symbols/call.svg +0 -4
  36. data/cockpit/themes/lego/symbols/callmanipulate.svg +0 -6
  37. data/cockpit/themes/lego/symbols/callori.svg +0 -4
  38. data/cockpit/themes/lego/symbols/choose.svg +0 -4
  39. data/cockpit/themes/lego/symbols/choose_exclusive.svg +0 -5
  40. data/cockpit/themes/lego/symbols/choose_inclusive.svg +0 -4
  41. data/cockpit/themes/lego/symbols/critical.svg +0 -4
  42. data/cockpit/themes/lego/symbols/escape.svg +0 -5
  43. data/cockpit/themes/lego/symbols/lego.svg +0 -72
  44. data/cockpit/themes/lego/symbols/loop.svg +0 -5
  45. data/cockpit/themes/lego/symbols/manipulate.svg +0 -4
  46. data/cockpit/themes/lego/symbols/otherwise.svg +0 -4
  47. data/cockpit/themes/lego/symbols/parallel.svg +0 -6
  48. data/cockpit/themes/lego/symbols/parallel_branch.svg +0 -4
  49. data/cockpit/themes/lego/symbols/scripts.svg +0 -4
  50. data/cockpit/themes/lego/symbols/start.svg +0 -3
  51. data/cockpit/themes/promise/rngs/alternative.rng +0 -5
  52. data/cockpit/themes/promise/rngs/call.rng +0 -41
  53. data/cockpit/themes/promise/rngs/choose.rng +0 -8
  54. data/cockpit/themes/promise/rngs/critical.rng +0 -5
  55. data/cockpit/themes/promise/rngs/loop.rng +0 -11
  56. data/cockpit/themes/promise/rngs/manipulate.rng +0 -6
  57. data/cockpit/themes/promise/rngs/parallel.rng +0 -5
  58. data/cockpit/themes/promise/rngs/parallel_branch.rng +0 -8
  59. data/cockpit/themes/promise/symbols/alternative.svg +0 -4
  60. data/cockpit/themes/promise/symbols/call.svg +0 -4
  61. data/cockpit/themes/promise/symbols/callmanipulate.svg +0 -6
  62. data/cockpit/themes/promise/symbols/choose_exclusive.svg +0 -5
  63. data/cockpit/themes/promise/symbols/choose_inclusive.svg +0 -4
  64. data/cockpit/themes/promise/symbols/critical.svg +0 -4
  65. data/cockpit/themes/promise/symbols/escape.svg +0 -5
  66. data/cockpit/themes/promise/symbols/loop.svg +0 -5
  67. data/cockpit/themes/promise/symbols/manipulate.svg +0 -4
  68. data/cockpit/themes/promise/symbols/otherwise.svg +0 -4
  69. data/cockpit/themes/promise/symbols/parallel.svg +0 -6
  70. data/cockpit/themes/promise/symbols/parallel_branch.svg +0 -4
  71. data/cockpit/themes/promise/symbols/preminder.svg +0 -6
  72. data/cockpit/themes/promise/symbols/scripts.svg +0 -4
  73. data/cockpit/themes/promise/symbols/start.svg +0 -3
  74. data/cockpit/themes/promise/theme.js +0 -801
@@ -59,45 +59,52 @@
59
59
  <link rel="stylesheet" href="css/track.css" type="text/css"/>
60
60
  </head>
61
61
  <body data-base-port="8298" data-res-port="9303" data-theme-base="themes" is="x-ui">
62
+ <div class='hidden' id='relaxngworker'></div>
62
63
  <div id="trackfull">
63
64
  <div id='graphcolumn'>
64
65
  <div id="usage">
65
66
  <span id="title"></span> | <span id='state'>
66
67
  <span id="state_text"></span>
67
- <span> ⇒ </span>
68
- <button name="state_start" title='start'>
69
- <svg viewBox="0 -1.5 7 12" width="10" height="16">
70
- <path
71
- style="fill:#000000;fill-rule:evenodd;stroke:#000000;stroke-width:0;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
72
- d="M 1.1000001e-6,1.0403124e-6 5.0000006e-7,10.583335 6.6145841,5.2916677 Z"/>
73
- </svg>
74
- </button>
75
- <button name="state_stop" title='stop'>
76
- <svg viewBox="0 -1.5 7 12" width="10" height="16">
77
- <path
78
- style="fill:#000000;fill-rule:evenodd;stroke:#000000;stroke-width:0;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
79
- d="m 3.9687505,1.3375769 1e-6,7.9374995 2.645832,1e-6 V 1.3375772 Z m -3.96875,0 v 7.9375005 h 2.645833 V 1.3375769 Z"/>
80
- </svg>
81
- </button>
82
- <span> / </span>
83
- <button name="state_sim" title='simulate'>
84
- <svg viewBox="0 -1.5 7 12" width="10" height="16">
85
- <path
86
- style="fill:#000000;fill-rule:evenodd;stroke:#000000;stroke-width:0;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
87
- d="M 0,7.0741552 1.598154,6.8788136 q 0.144277,1.0115903 0.58266,1.4859901 0.443932,0.474402 1.193067,0.474402 0.793528,0 1.193066,-0.418589 0.405089,-0.4255654 0.405089,-0.990661 0,-0.362777 -0.172025,-0.6139303 Q 4.633538,6.5578953 4.211802,6.3695302 3.923247,6.2439536 2.896654,5.9230353 1.575957,5.5114228 1.04324,4.911445 0.294105,4.0672905 0.294105,2.8533821 q 0,-0.7813662 0.349596,-1.4580852 Q 0.998846,0.7116014 1.659195,0.3558006 2.325092,0 3.262898,0 4.794462,0 5.565794,0.8441546 6.342674,1.6883092 6.381518,3.0975591 L 4.73897,3.1882531 Q 4.633538,2.3999106 4.283941,2.0580629 3.939894,1.7092386 3.246251,1.7092386 q -0.71584,0 -1.120927,0.3697537 -0.260811,0.2372006 -0.260811,0.6348602 0,0.3627771 0.244164,0.6209071 0.31075,0.3278947 1.509366,0.6836954 1.198616,0.3558008 1.770178,0.7395073 0.577111,0.3767302 0.898962,1.0394962 0.327399,0.6557896 0.327399,1.6255215 0,0.8790367 -0.388439,1.6464517 -0.388442,0.767412 -1.098732,1.1441413 -0.710291,0.369755 -1.770178,0.369755 -1.542663,0 -2.369485,-0.8929903 Q 0.160924,8.7903717 0,7.0741552 Z"/>
88
- </svg>
89
- </button>
90
- <span> / </span>
91
- <button name="state_abandon" title='abandon'>
92
- <svg viewBox="0 -1.5 7 12" width="10" height="16">
93
- <path
94
- style="fill:#000000;fill-rule:evenodd;stroke:#000000;stroke-width:0;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
95
- d="m 5e-7,1.3229172 h 2.645833 V 5.0000007e-7 h 1.322917 V 1.3229172 h 2.645833 V 2.6458339 H 5e-7 Z m 2.645833,2.6458332 v 3.96875 l 1.322917,10e-8 v -3.96875 z M 5e-7,10.583333 l 6.614584,1e-6 -1e-6,-6.6145835 h -1.322916 v 5.2916667 h -3.96875 V 3.9687505 H 5e-7 Z"/>
96
- </svg>
97
- </button>
68
+ <span id="state_any">
69
+ <span> </span>
70
+ <button name="state_start" title='start'>
71
+ <svg viewBox="0 -1.5 7 12" width="10" height="16">
72
+ <path
73
+ style="fill:#000000;fill-rule:evenodd;stroke:#000000;stroke-width:0;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
74
+ d="M 1.1000001e-6,1.0403124e-6 5.0000006e-7,10.583335 6.6145841,5.2916677 Z"/>
75
+ </svg>
76
+ </button>
77
+ <button name="state_stop" title='stop'>
78
+ <svg viewBox="0 -1.5 7 12" width="10" height="16">
79
+ <path
80
+ style="fill:#000000;fill-rule:evenodd;stroke:#000000;stroke-width:0;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
81
+ d="m 3.9687505,1.3375769 1e-6,7.9374995 2.645832,1e-6 V 1.3375772 Z m -3.96875,0 v 7.9375005 h 2.645833 V 1.3375769 Z"/>
82
+ </svg>
83
+ </button>
84
+ <span id="state_extended">
85
+ <span> / </span>
86
+ <button name="state_sim" title='simulate'>
87
+ <svg viewBox="0 -1.5 7 12" width="10" height="16">
88
+ <path
89
+ style="fill:#000000;fill-rule:evenodd;stroke:#000000;stroke-width:0;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
90
+ d="M 0,7.0741552 1.598154,6.8788136 q 0.144277,1.0115903 0.58266,1.4859901 0.443932,0.474402 1.193067,0.474402 0.793528,0 1.193066,-0.418589 0.405089,-0.4255654 0.405089,-0.990661 0,-0.362777 -0.172025,-0.6139303 Q 4.633538,6.5578953 4.211802,6.3695302 3.923247,6.2439536 2.896654,5.9230353 1.575957,5.5114228 1.04324,4.911445 0.294105,4.0672905 0.294105,2.8533821 q 0,-0.7813662 0.349596,-1.4580852 Q 0.998846,0.7116014 1.659195,0.3558006 2.325092,0 3.262898,0 4.794462,0 5.565794,0.8441546 6.342674,1.6883092 6.381518,3.0975591 L 4.73897,3.1882531 Q 4.633538,2.3999106 4.283941,2.0580629 3.939894,1.7092386 3.246251,1.7092386 q -0.71584,0 -1.120927,0.3697537 -0.260811,0.2372006 -0.260811,0.6348602 0,0.3627771 0.244164,0.6209071 0.31075,0.3278947 1.509366,0.6836954 1.198616,0.3558008 1.770178,0.7395073 0.577111,0.3767302 0.898962,1.0394962 0.327399,0.6557896 0.327399,1.6255215 0,0.8790367 -0.388439,1.6464517 -0.388442,0.767412 -1.098732,1.1441413 -0.710291,0.369755 -1.770178,0.369755 -1.542663,0 -2.369485,-0.8929903 Q 0.160924,8.7903717 0,7.0741552 Z"/>
91
+ </svg>
92
+ </button>
93
+ <span> / </span>
94
+ <button name="state_abandon" title='abandon'>
95
+ <svg viewBox="0 -1.5 7 12" width="10" height="16">
96
+ <path
97
+ style="fill:#000000;fill-rule:evenodd;stroke:#000000;stroke-width:0;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
98
+ d="m 5e-7,1.3229172 h 2.645833 V 5.0000007e-7 h 1.322917 V 1.3229172 h 2.645833 V 2.6458339 H 5e-7 Z m 2.645833,2.6458332 v 3.96875 l 1.322917,10e-8 v -3.96875 z M 5e-7,10.583333 l 6.614584,1e-6 -1e-6,-6.6145835 h -1.322916 v 5.2916667 h -3.96875 V 3.9687505 H 5e-7 Z"/>
99
+ </svg>
100
+ </button>
101
+ </span>
102
+ </span>
98
103
  </span>
99
104
  </div>
100
- <svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:x="http://www.w3.org/1999/xlink" id='graphcanvas' width='1' height='1'></svg>
105
+ <div id='graphgrid'>
106
+ <svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:x="http://www.w3.org/1999/xlink" id='graphcanvas' width='1' height='1'></svg>
107
+ </div>
101
108
  </div>
102
109
  <div id='trackcolumn'>
103
110
  </div>
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "cpee"
3
- s.version = "1.4.31"
3
+ s.version = "1.4.32"
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.license = "LGPL-3.0"
6
6
  s.summary = "Preliminary release of cloud process execution engine (cpee). If you just need workflow execution, without a rest/xmpp service exposing it, then use WEEL"
@@ -378,6 +378,8 @@ module CPEE
378
378
  sim
379
379
  when 'ready'
380
380
  @instance.state_signal
381
+ when 'abandoned'
382
+ @instance.abandon
381
383
  end
382
384
  else
383
385
  if node = @properties.data.find("/p:properties/p:state").first
@@ -119,17 +119,30 @@ module CPEE
119
119
  end #}}}
120
120
  private :handle_starting
121
121
  def handle_data(cpee,instance,data) #{{{
122
- if data
123
- srv = Riddl::Client.new(cpee, cpee + "?riddl-description")
122
+ if data && !data.empty?
124
123
  content = XML::Smart.string('<content/>')
125
124
  JSON::parse(data).each do |k,v|
126
125
  content.root.add(k,v)
127
126
  end
127
+ srv = Riddl::Client.new(cpee, cpee + "?riddl-description")
128
128
  res = srv.resource("/#{instance}/properties/values/dataelements/")
129
129
  status, response = res.patch [
130
130
  Riddl::Parameter::Complex.new('content','text/xml',content.to_s)
131
131
  ]
132
- end # rescue nil
132
+ end rescue nil
133
+ end #}}}
134
+ def handle_endpoints(cpee,instance,data) #{{{
135
+ if data && !data.empty?
136
+ content = XML::Smart.string('<content/>')
137
+ JSON::parse(data).each do |k,v|
138
+ content.root.add(k,v)
139
+ end
140
+ srv = Riddl::Client.new(cpee, cpee + "?riddl-description")
141
+ res = srv.resource("/#{instance}/properties/values/endpoints/")
142
+ status, response = res.patch [
143
+ Riddl::Parameter::Complex.new('content','text/xml',content.to_s)
144
+ ]
145
+ end rescue nil
133
146
  end #}}}
134
147
  end #}}}
135
148
 
@@ -140,7 +153,8 @@ module CPEE
140
153
  cpee = @h['X_CPEE'] || @a[0]
141
154
  selfurl = @a[1]
142
155
  cblist = @a[2]
143
- status, res = Riddl::Client.new(@p[2].value).get
156
+
157
+ status, res = Riddl::Client.new(@p[2].value.gsub(/ /,'%20')).get
144
158
  tdoc = if status >= 200 && status < 300
145
159
  res[0].value.read
146
160
  else
@@ -150,7 +164,10 @@ module CPEE
150
164
  if (instance, uuid = load_testset(tdoc,cpee,@p[0].value)).first == -1
151
165
  @status = 500
152
166
  else
153
- handle_data cpee, instance, @p[3]&.value
167
+ handle_data cpee, instance, @p[3]&.value if @p[3]&.name == 'init'
168
+ handle_endpoints cpee, instance, @p[3]&.value if @p[3]&.name == 'endpoints'
169
+ handle_endpoints cpee, instance, @p[4]&.value if @p[4]&.name == 'endpoints'
170
+
154
171
  handle_waiting cpee, instance, uuid, @p[1].value, selfurl, cblist
155
172
  handle_starting cpee, instance, @p[1].value
156
173
 
@@ -34,7 +34,7 @@ module CPEE
34
34
  def self::parse_extended(value)
35
35
  if [String].include? value.class
36
36
  self::parse(value)
37
- elsif [Array, NilClass, Integer, Float, TrueClass, FalseClass, Date].inclu
37
+ elsif [Array, NilClass, Integer, Float, TrueClass, FalseClass, Date].include? value.class
38
38
  value
39
39
  elsif value.respond_to?(:to_s)
40
40
  value.to_s
@@ -30,6 +30,9 @@
30
30
  <optional>
31
31
  <parameter name="init" type="string"/>
32
32
  </optional>
33
+ <optional>
34
+ <parameter name="endpoints" type="string"/>
35
+ </optional>
33
36
  </message>
34
37
  <message name="instance">
35
38
  <parameter name="behavior" type="string">
@@ -9,8 +9,16 @@ require 'faraday'
9
9
  require 'elasticsearch'
10
10
 
11
11
  class Logging < Riddl::Implementation
12
-
13
- def doc(topic,event_name,esc,template,instancenr,notification)
12
+ def doc(topic, event_name, esc, template, instancenr, notification)
13
+ # DEBUG: del pp
14
+ pp "---"
15
+ pp "---"
16
+ pp "#{topic}/#{event_name}"
17
+ pp instancenr
18
+ pp "---"
19
+ pp notification.to_yaml
20
+ pp "---"
21
+ pp "---"
14
22
  uuid = notification['instance_uuid']
15
23
  return unless uuid
16
24
 
@@ -26,7 +34,6 @@ class Logging < Riddl::Implementation
26
34
  "properties" => {
27
35
  "group" => {
28
36
  "type" => "keyword"
29
-
30
37
  },
31
38
  "name" => {
32
39
  "type" => "keyword"
@@ -36,6 +43,7 @@ class Logging < Riddl::Implementation
36
43
  }
37
44
  }
38
45
  end #}}}
46
+
39
47
  unless esc.indices.exists? index: 'instances' #{{{
40
48
  esc.indices.create index: 'instances', body: {
41
49
  "mappings" => {
@@ -62,6 +70,7 @@ class Logging < Riddl::Implementation
62
70
  }
63
71
  }
64
72
  end #}}}
73
+
65
74
  unless esc.indices.exists? index: 'spawned' #{{{
66
75
  esc.indices.create index: 'spawned', body: {
67
76
  "mappings" => {
@@ -76,12 +85,13 @@ class Logging < Riddl::Implementation
76
85
  "date": {
77
86
  "type": "date",
78
87
  "format": "date_time_no_millis"
79
- },
88
+ }
80
89
  }
81
90
  }
82
91
  }
83
92
  }
84
93
  end #}}}
94
+
85
95
  unless esc.indices.exists? index: 'sensors' #{{{
86
96
  esc.indices.create index: 'sensors', body: {
87
97
  "mappings" => {
@@ -107,6 +117,7 @@ class Logging < Riddl::Implementation
107
117
  }
108
118
  }
109
119
  end #}}}
120
+
110
121
  unless esc.indices.exists? index: 'values' #{{{
111
122
  esc.indices.create index: 'values', body: {
112
123
  "mappings" => {
@@ -144,6 +155,33 @@ class Logging < Riddl::Implementation
144
155
  }
145
156
  end #}}}
146
157
 
158
+ unless esc.indices.exists? index: 'test_values' #{{{
159
+ esc.indices.create index: 'test_values', body: {
160
+ "mappings" => {
161
+ "entry" => {
162
+ "properties" => {
163
+ "uuid" => {
164
+ "type" => "keyword"
165
+ },
166
+ "sensor" => {
167
+ "type" => "keyword"
168
+ },
169
+ "task" => {
170
+ "type" => "keyword"
171
+ },
172
+ "timestamp": {
173
+ "type": "date",
174
+ "format": "date_time"
175
+ },
176
+ "value" => {
177
+ "type" => "object"
178
+ }
179
+ }
180
+ }
181
+ }
182
+ }
183
+ end #}}}
184
+
147
185
  uuid = notification.dig('instance_uuid')
148
186
 
149
187
  if notification.dig('attributes','artefacts') #{{{
@@ -160,58 +198,159 @@ class Logging < Riddl::Implementation
160
198
  'date': Time.now.iso8601,
161
199
  'info': notification.dig('attributes','info')
162
200
  }
163
-
164
201
  end
165
202
  end #}}}
166
203
 
167
- pp notification
204
+ # DEBUG:
205
+ # pp notification
168
206
  case "#{topic}/#{event_name}"
169
- when "dataelements/change", "endpoints/change"
170
- sensors = JSON.parse(notification.dig('attributes','sensors') || '[]')
171
- sensors.each do |s|
172
- sid = Digest::MD5.hexdigest(uuid + '_' + s['name'])
173
- esc.index index: 'sensors', type: 'entry', id: sid, body: {
174
- 'uuid': uuid,
175
- 'sensor': s['name'],
176
- 'visualizer_url': s['visualizer_url'],
177
- 'visualizer_params': [s['visualizer_params']]
178
- }
179
- esc.index index: 'values', type: 'entry', body: {
180
- 'uuid': uuid,
181
- 'sensor': s['name'],
182
- 'timestamp': notification.dig('timestamp'),
183
- 'value': s['value']
184
- }
185
- end
186
- when "activity/receiving"
187
- sensors = JSON.parse(notification.dig('sensors') || '[]')
188
- tdoc = notification.dig('received')
189
- sensors.each do |s|
190
- sid = Digest::MD5.hexdigest(uuid + '_' + s['name'])
191
- esc.index index: 'sensors', type: 'entry', id: sid, body: {
192
- 'uuid': uuid,
193
- 'sensor': s['name'],
194
- 'task': notification.dig('activity'),
195
- 'visualizer_url': s['visualizer_url'],
196
- 'visualizer_params': (s['visualizer_params'].nil? || s['visualizer_params'].empty? ? [] : [s['visualizer_params']])
197
- }
198
- status, result = Riddl::Client.new(s['extractor_url']).post [
199
- Riddl::Parameter::Simple.new('data',JSON.pretty_generate(tdoc)),
200
- Riddl::Parameter::Simple.new('what',s['extractor_arg'])
201
- ]
202
- if status >= 200 && status < 300
203
- ret = JSON::parse(result[0]&.value.read) rescue []
204
- ret.each do |v,t|
205
- esc.index index: 'values', type: 'entry', body: {
206
- 'uuid': uuid,
207
- 'sensor': s['name'],
208
- 'timestamp': t,
209
- 'value': v
210
- }
211
- end
212
- end
207
+ when "dataelements/change", "endpoints/change"
208
+ sensors = JSON.parse(notification.dig('attributes', 'sensors') || '[]')
209
+ sensors.each do |s|
210
+ sid = Digest::MD5.hexdigest(uuid + '_' + s['name'])
211
+ esc.index index: 'sensors', type: 'entry', id: sid, body: {
212
+ 'uuid': uuid,
213
+ 'sensor': s['name'],
214
+ 'visualizer_url': s['visualizer_url'],
215
+ 'visualizer_params': [s['visualizer_params']]
216
+ }
217
+ esc.index index: 'values', type: 'entry', body: {
218
+ 'uuid': uuid,
219
+ 'sensor': s['name'],
220
+ 'timestamp': notification.dig('timestamp'),
221
+ 'value': s['value']
222
+ }
223
+ end
224
+
225
+ when "activity/receiving"
226
+ sensors = JSON.parse(notification.dig('sensors') || '[]')
227
+ # tdoc = notification.dig('received')
228
+ tdoc = notification
229
+ # DEBUG:
230
+ # pp notification
231
+
232
+ sensors.each do |s|
233
+ sid = Digest::MD5.hexdigest(uuid + '_' + s['name'])
234
+ esc.index index: 'sensors', type: 'entry', id: sid, body: {
235
+ 'uuid': uuid,
236
+ 'sensor': s['name'],
237
+ 'task': notification.dig('activity'),
238
+ 'visualizer_url': s['visualizer_url'],
239
+ 'visualizer_params': (s['visualizer_params'].nil? || s['visualizer_params'].empty? ? [] : [s['visualizer_params']])
240
+ }
241
+ status, result = Riddl::Client.new(s['extractor_url']).post [
242
+ Riddl::Parameter::Simple.new('data', JSON.pretty_generate(tdoc)),
243
+ Riddl::Parameter::Simple.new('what', s['extractor_arg'])
244
+ ]
213
245
 
246
+ if status >= 200 && status < 300
247
+ # ret = JSON::parse(result[0]&.value.read) rescue []
248
+ ret = JSON.parse(result[0]&.value.read) rescue []
249
+ ret.each do |v, t|
250
+ esc.index index: 'values', type: 'entry', body: {
251
+ 'uuid': uuid,
252
+ 'sensor': s['name'],
253
+ # REVIEW: Why generate the timestamp in the PHP extractor?
254
+ # 'timestamp': "#{t}",
255
+ # 'timestamp': notification.dig('timestamp'),
256
+ 'timestamp': t,
257
+ 'value': v
258
+ }
259
+ end
214
260
  end
261
+ end
262
+
263
+ when "activity/calling"
264
+ sid = Digest::MD5.hexdigest(uuid + '_' + "start_task")
265
+ esc.index index: 'sensors', type: 'entry', id: sid, body: {
266
+ 'uuid': uuid,
267
+ 'sensor': "start_task",
268
+ 'task': "#{notification.dig('activity')}/#{notification.dig('label')}",
269
+ # 'visualizer_url': '',
270
+ # 'visualizer_params': ''
271
+ }
272
+ esc.index index: 'test_values', type: 'entry', body: {
273
+ 'uuid': uuid,
274
+ 'sensor': "start_task",
275
+ 'timestamp': notification.dig('timestamp'),
276
+ 'value': {
277
+ 'id': notification.dig('activity'),
278
+ 'name': notification.dig('label'),
279
+ 'uuid': uuid,
280
+ 'instance': instancenr
281
+ }
282
+ }
283
+
284
+ when "activity/done"
285
+ sid = Digest::MD5.hexdigest(uuid + '_' + "end_task")
286
+ esc.index index: 'sensors', type: 'entry', id: sid, body: {
287
+ 'uuid': uuid,
288
+ 'sensor': "end_task",
289
+ 'task': "#{notification.dig('activity')}/#{notification.dig('label')}",
290
+ # 'visualizer_url': '',
291
+ # 'visualizer_params': ''
292
+ }
293
+ esc.index index: 'test_values', type: 'entry', body: {
294
+ 'uuid': uuid,
295
+ 'sensor': "end_task",
296
+ 'timestamp': notification.dig('timestamp'),
297
+ 'value': {
298
+ 'id': notification.dig('activity'),
299
+ 'name': notification.dig('label'),
300
+ 'uuid': uuid,
301
+ 'instance': instancenr
302
+ }
303
+ }
304
+
305
+ when "task/instantiation"
306
+ sid = Digest::MD5.hexdigest(uuid + '_' + "sub_task")
307
+ esc.index index: 'sensors', type: 'entry', id: sid, body: {
308
+ 'uuid': uuid,
309
+ 'sensor': 'sub_task',
310
+ 'task': "#{notification.dig('activity')}/#{notification.dig('label')}"
311
+ # 'visualizer_url': '',
312
+ # 'visualizer_params': ''
313
+ }
314
+ esc.index index: 'test_values', type: 'entry', body: {
315
+ # 'uuid': notification.dig('received', 'CPEE-INSTANCE-UUID'),
316
+ 'uuid': uuid,
317
+ 'sensor': 'sub_task',
318
+ 'timestamp': notification.dig('timestamp'),
319
+ 'value': {
320
+ # 'child_uuid': notification.dig('received', 'data', 'CPEE-INSTANCE-UUID'),
321
+ # 'child_instance': notification.dig('received', 'data', 'CPEE-INSTANCE')
322
+ 'id': notification.dig('activity'),
323
+ 'name': notification.dig('label'),
324
+ 'uuid': uuid,
325
+ 'instance': instancenr,
326
+ 'child_uuid': notification.dig('received', 'CPEE-INSTANCE-UUID'),
327
+ 'child_instance': notification.dig('received', 'CPEE-INSTANCE')
328
+ }
329
+ }
330
+ sid = Digest::MD5.hexdigest(uuid + '_' + "sub_task")
331
+ esc.index index: 'sensors', type: 'entry', id: sid, body: {
332
+ 'uuid': notification.dig('received', 'CPEE-INSTANCE-UUID'),
333
+ 'sensor': 'sub_task',
334
+ 'task': "#{notification.dig('activity')}/#{notification.dig('label')}"
335
+ # 'visualizer_url': '',
336
+ # 'visualizer_params': ''
337
+ }
338
+ esc.index index: 'test_values', type: 'entry', body: {
339
+ # 'uuid': notification.dig('received', 'CPEE-INSTANCE-UUID'),
340
+ 'uuid': notification.dig('received', 'CPEE-INSTANCE-UUID'),
341
+ 'sensor': 'sub_task',
342
+ 'timestamp': notification.dig('timestamp'),
343
+ 'value': {
344
+ # 'child_uuid': notification.dig('received', 'data', 'CPEE-INSTANCE-UUID'),
345
+ # 'child_instance': notification.dig('received', 'data', 'CPEE-INSTANCE')
346
+ 'uuid': notification.dig('received', 'CPEE-INSTANCE-UUID'),
347
+ 'instance': notification.dig('received', 'CPEE-INSTANCE'),
348
+ 'parent_id': notification.dig('activity'),
349
+ 'parent_name': notification.dig('label'),
350
+ 'parent_uuid': uuid,
351
+ 'parent_instance': instancenr
352
+ }
353
+ }
215
354
  end
216
355
  nil
217
356
  end