cpee-logging-xes-yaml 1.0.6 → 1.1.0

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
  SHA256:
3
- metadata.gz: 0ba8710880804c7803eea8c127abb88ad8a6ec3d7189b2731127b620c7eaf7fa
4
- data.tar.gz: acc8a90a7c55119ba9ab9f2e81e170658e39b35aa9e456fc66b69060d43f107d
3
+ metadata.gz: 8a56a402debfb1779e310bbe0128f64814a51dc3a9af96c8e2d15935bfa07364
4
+ data.tar.gz: 5c3fcf8d82de2daacfd7c932dd2326bf274a3b0aff205f44d52a7bae0b1e7431
5
5
  SHA512:
6
- metadata.gz: 3aca1dfc7ea1fb6cf504d9ca6692da23e017f598b9fed424cfe8caa5e25ebbb7c70bd1e32ab339d704e53d77f187a19050e18df26c4eb8dbb27e267d3d807c1d
7
- data.tar.gz: 68529513a92e2e3abb3c494ccbaa4965d7230c15fce74e1567f68a45f81c9122fd8730ffed3088d65a52f8f206aa5b2fd58926d985aa72ae79c305f483e0561f
6
+ metadata.gz: de9cfc04b3337a8e42bf5396cd5905151973932a4655d18c695193d0b74a8d5045f45e0c49bfdd59b48df62a327d3340a29ca34504df51a8e19e014e4a56a7d1
7
+ data.tar.gz: 212c23ea84f1186db0c59249d82ca8471f366d040f68c5711c32629c00763cc871216cf7380e67b3a4f1f38f7b24dc2770e9f83b7f5146e72d9032a567b8f6ae
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "cpee-logging-xes-yaml"
3
- s.version = "1.0.6"
3
+ s.version = "1.1.0"
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.license = "LGPL-3.0"
6
6
  s.summary = "Logging for the cloud process execution engine (cpee.org)"
@@ -21,65 +21,14 @@ require 'yaml'
21
21
  require 'riddl/server'
22
22
  require 'time'
23
23
 
24
+ require_relative 'tools'
25
+
24
26
  module CPEE
25
27
  module Logging
26
28
 
27
29
  SERVER = File.expand_path(File.join(__dir__,'logging.xml'))
28
30
 
29
- class Handler < Riddl::Implementation #{{{
30
- def doc(topic,event_name,log_dir,template,payload)
31
- notification = JSON.parse(payload)
32
- instance = notification['instance-uuid']
33
- return unless instance
34
-
35
- instancenr = notification['instance']
36
- content = notification['content']
37
- activity = content['activity']
38
- parameters = content['parameters']
39
- receiving = content['received']
40
-
41
- log = YAML::load(File.read(template))
42
- log["log"]["trace"]["concept:name"] ||= instancenr
43
- log["log"]["trace"]["cpee:name"] ||= notification['instance-name'] if notification['instance-name']
44
- log["log"]["trace"]["cpee:instance"] ||= instance
45
- File.open(File.join(log_dir,instance+'.xes.yaml'),'w'){|f| f.puts log.to_yaml} unless File.exists? File.join(log_dir,instance+'.xes.yaml')
46
- event = {}
47
- event["concept:instance"] = instancenr
48
- event["concept:name"] = content["label"] if content["label"]
49
- if content["endpoint"]
50
- event["concept:endpoint"] = content["endpoint"]
51
- end
52
- event["id:id"] = (activity.nil? || activity == "") ? 'external' : activity
53
- event["cpee:activity"] = event["id:id"]
54
- event["cpee:activity_uuid"] = content['activity-uuid'] if content['activity-uuid']
55
- event["cpee:instance"] = instance
56
- case event_name
57
- when 'receiving', 'change', 'instantiation'
58
- event["lifecycle:transition"] = "unknown"
59
- when 'done'
60
- event["lifecycle:transition"] = "complete"
61
- else
62
- event["lifecycle:transition"] = "start"
63
- end
64
- event["cpee:lifecycle:transition"] = "#{topic}/#{event_name}"
65
- event["cpee:state"] = content['state'] if content['state']
66
- event["cpee:description"] = content['dslx'] if content['dslx']
67
- unless parameters["arguments"]&.nil?
68
- event["data"] = parameters["arguments"]
69
- end
70
- if content['changed']&.any?
71
- event["data"] = content['values']
72
- end
73
- if receiving && !receiving.empty?
74
- event["raw"] = receiving
75
- end
76
- event["time:timestamp"]= event['cpee:timestamp'] || Time.now.strftime("%Y-%m-%dT%H:%M:%S.%L%:z")
77
- File.open(File.join(log_dir,instance+'.xes.yaml'),'a') do |f|
78
- f << {'event' => event}.to_yaml
79
- end
80
- nil
81
- end
82
-
31
+ class Handler < Riddl::Implementation
83
32
  def response
84
33
  topic = @p[1].value
85
34
  event_name = @p[2].value
@@ -87,11 +36,11 @@ module CPEE
87
36
  template = @a[1]
88
37
  notification = @p[3].value.read
89
38
  EM.defer do
90
- doc topic, event_name, log_dir, template, notification
39
+ CPEE::Logging::doc topic, event_name, log_dir, template, notification
91
40
  end
92
41
  nil
93
42
  end
94
- end #}}}
43
+ end
95
44
 
96
45
  def self::implementation(opts)
97
46
  opts[:log_dir] ||= File.join(__dir__,'logs')
@@ -0,0 +1,184 @@
1
+ require 'weel'
2
+
3
+ class StreamPoint
4
+ attr_accessor :value, :timestamp, :source, :meta
5
+
6
+ def initialize
7
+ @value = nil
8
+ @timestamp = Time.now
9
+ @source = nil
10
+ @meta = nil
11
+ end
12
+
13
+ def to_h(id)
14
+ tp = { 'stream:point' => { } }
15
+ tp['stream:point']['stream:id'] = id
16
+ tp['stream:point']['stream:value'] = @value
17
+ tp['stream:point']['stream:timestamp'] = @timestamp
18
+ tp['stream:point']['stream:source'] = @source unless @source.nil?
19
+ tp['stream:point']['stream:meta'] = @meta unless @meta.nil?
20
+ tp
21
+ end
22
+ end
23
+
24
+ module CPEE
25
+ module Logging
26
+
27
+ def self::extract_probes(where,xml)
28
+ XML::Smart::string(xml) do |doc|
29
+ doc.register_namespace 'd', 'http://cpee.org/ns/description/1.0'
30
+ doc.find('//d:call').each do |c|
31
+ c.find('d:annotations/d:_context_data_analysis/d:probes').each do |p|
32
+ File.write(where + '_' + c.attributes['id'] + '.probe', p.dump)
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ def self::extract_sensor(rs,code,result)
39
+ result.map! do |res|
40
+ if res['mimetype'].nil?
41
+ res['value']
42
+ elsif res['mimetype'] == 'application/json'
43
+ JSON::parse(res['data'])
44
+ elsif res['mimetype'] == 'application/xml' || res['mimetype'] == 'text/xml'
45
+ XML::Smart::string(res['data']) rescue nil
46
+ elsif res.mimetype == 'text/yaml'
47
+ YAML::load(res['data']) rescue nil
48
+ elsif result[0].mimetype == 'text/plain'
49
+ t = res['data']
50
+ if t.start_with?("<?xml version=")
51
+ t = XML::Smart::string(t)
52
+ else
53
+ t = t.to_f if t == t.to_f.to_s
54
+ t = t.to_i if t == t.to_i.to_s
55
+ end
56
+ t
57
+ elsif res.mimetype == 'text/html'
58
+ t = res['data']
59
+ t = t.to_f if t == t.to_f.to_s
60
+ t = t.to_i if t == t.to_i.to_s
61
+ t
62
+ else
63
+ res['data']
64
+ end
65
+ end
66
+ result = result[0] if result.length == 1
67
+ rs.instance_eval(code)
68
+ end
69
+
70
+ def self::persist_values(where,values)
71
+ unless File.exists?(where)
72
+ File.write(where,'{}')
73
+ end
74
+ f = File.open(where,'r+')
75
+ f.flock(File::LOCK_EX)
76
+ json = JSON::load(f).merge(values)
77
+ f.rewind
78
+ f.truncate(0)
79
+ f.write(JSON.generate(json))
80
+ f.close
81
+ end
82
+
83
+ def self::doc(topic,event_name,log_dir,template,payload)
84
+ notification = JSON.parse(payload)
85
+ instance = notification['instance-uuid']
86
+ return unless instance
87
+
88
+ instancenr = notification['instance']
89
+ content = notification['content']
90
+ activity = content['activity']
91
+ parameters = content['parameters']
92
+ receiving = content['received']
93
+
94
+ if content['dslx']
95
+ CPEE::Logging::extract_probes(File.join(log_dir,instance),content['dslx'])
96
+ end
97
+
98
+ if topic == 'dataelements' && event_name == 'change'
99
+ if content['changed']&.any?
100
+ CPEE::Logging::persist_values(File.join(log_dir,instance + '.data.json'),content['values'])
101
+ end
102
+ end
103
+
104
+ log = YAML::load(File.read(template))
105
+ log["log"]["trace"]["concept:name"] ||= instancenr
106
+ log["log"]["trace"]["cpee:name"] ||= notification['instance-name'] if notification['instance-name']
107
+ log["log"]["trace"]["cpee:instance"] ||= instance
108
+ File.open(File.join(log_dir,instance+'.xes.yaml'),'w'){|f| f.puts log.to_yaml} unless File.exists? File.join(log_dir,instance+'.xes.yaml')
109
+ event = {}
110
+ event["concept:instance"] = instancenr
111
+ event["concept:name"] = content["label"] if content["label"]
112
+ if content["endpoint"]
113
+ event["concept:endpoint"] = content["endpoint"]
114
+ end
115
+ event["id:id"] = (activity.nil? || activity == "") ? 'external' : activity
116
+ event["cpee:activity"] = event["id:id"]
117
+ event["cpee:activity_uuid"] = content['activity-uuid'] if content['activity-uuid']
118
+ event["cpee:instance"] = instance
119
+ case event_name
120
+ when 'receiving', 'change', 'instantiation'
121
+ event["lifecycle:transition"] = "unknown"
122
+ when 'done'
123
+ event["lifecycle:transition"] = "complete"
124
+ else
125
+ event["lifecycle:transition"] = "start"
126
+ end
127
+ event["cpee:lifecycle:transition"] = "#{topic}/#{event_name}"
128
+ event["cpee:state"] = content['state'] if content['state']
129
+ event["cpee:description"] = content['dslx'] if content['dslx']
130
+ unless parameters["arguments"]&.nil?
131
+ event["data"] = parameters["arguments"]
132
+ end if parameters
133
+ if content['changed']&.any?
134
+ event["data"] = content['values']
135
+ end
136
+ if receiving && !receiving.empty?
137
+ fname = File.join(log_dir,instance + '_' + event["id:id"] + '.probe')
138
+ dname = File.join(log_dir,instance + '.data.json')
139
+
140
+ if File.exists?(fname)
141
+ te = event.dup
142
+ te['stream:sensorstream'] = []
143
+
144
+ rs = WEEL::ReadStructure.new(File.exists?(dname) ? JSON::load(File::open(dname)) : {},{},{})
145
+ XML::Smart::open_unprotected(fname) do |doc|
146
+ doc.register_namespace 'd', 'http://cpee.org/ns/description/1.0'
147
+ doc.find('//d:probe').each do |p|
148
+ tid = p.find('string(d:id)')
149
+ tso = p.find('string(d:source)')
150
+ if p.find('d:extractor_type[.="extrinsic"]')
151
+ val = CPEE::Logging::extract_sensor(rs,p.find('string(d:extractor_code)'),receiving) rescue nil
152
+ if val.is_a? Array
153
+ val.each do |e|
154
+ if e.is_a? StreamPoint
155
+ e.source ||= tso
156
+ te['stream:sensorstream'] << e.to_h(tid)
157
+ end
158
+ end
159
+ else
160
+ tp = StreamPoint.new
161
+ tp.source = tso
162
+ tp.value = val
163
+ te['stream:sensorstream'] << tp.to_h(tid)
164
+ end
165
+ end
166
+ end
167
+ end
168
+ te["cpee:lifecycle:transition"] = "sensor/stream"
169
+ File.open(File.join(log_dir,instance+'.xes.yaml'),'a') do |f|
170
+ f << {'event' => te}.to_yaml
171
+ end
172
+ end
173
+
174
+ event["raw"] = receiving
175
+ end
176
+ event["time:timestamp"]= event['cpee:timestamp'] || Time.now.strftime("%Y-%m-%dT%H:%M:%S.%L%:z")
177
+ File.open(File.join(log_dir,instance+'.xes.yaml'),'a') do |f|
178
+ f << {'event' => event}.to_yaml
179
+ end
180
+ end
181
+
182
+ end
183
+ end
184
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cpee-logging-xes-yaml
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juergen eTM Mangler
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: tools
11
11
  cert_chain: []
12
- date: 2022-10-10 00:00:00.000000000 Z
12
+ date: 2022-10-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: riddl
@@ -75,6 +75,7 @@ files:
75
75
  - lib/cpee-logging-xes-yaml/logging.rb
76
76
  - lib/cpee-logging-xes-yaml/logging.xml
77
77
  - lib/cpee-logging-xes-yaml/template.xes_yaml
78
+ - lib/cpee-logging-xes-yaml/tools.rb
78
79
  - server/log
79
80
  - tools/cpee-logging-xes-yaml
80
81
  homepage: http://cpee.org/