cpee-logging-xes-yaml 1.3.4 → 1.3.5

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: aab20ce260e56f4571add36cef8c7fe6f638fad4a723d28f8a13e6e93e99a32c
4
- data.tar.gz: 122128fd3e956198fc7096409ff1f64bf47d0e17f5f2e72dd2f4cf3d138ea173
3
+ metadata.gz: ddf89052e93d9c38c178377595703e815e14bc16a05b2c57cbf9ff73f65f12ad
4
+ data.tar.gz: c1fc949892594dd764c55338ddbe9d0eb74aa84a49799503c4a2cc5764f0f2c5
5
5
  SHA512:
6
- metadata.gz: f36ec97639c73e0735250eee61c39febc1b43e2bab34912780be9a393ccedc45ef3cffdcfd97cd432145a73fcb0935e10dfc405bdd9500117de9afb53522b9de
7
- data.tar.gz: 242461d18564a0c2fb9b2b5992e45a99e7506e79aab3eaa08be4c4a1bc4846733b39bc49b7b6e5c7714f719e74ce6afd6fa8225a91642be3188f61c597dfa4f2
6
+ metadata.gz: afa34dc21a86f7112a81958620b49d9dfb0457dbaba778d876b4cb24a9e8f31685168111e610848a73c5d26ca4efe38b1c509d2fd4065acec49ea8c6daec64e3
7
+ data.tar.gz: 1da376713380410325754f2dd18e8d70653ce0f0026b56c347ae1062ca8aeba7e7660568031df9fe0efa150a51239e98ce739329adafcf52fd7fd27fbff7fcfa
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "cpee-logging-xes-yaml"
3
- s.version = "1.3.4"
3
+ s.version = "1.3.5"
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)"
@@ -25,6 +25,8 @@ require 'typhoeus'
25
25
  require 'stringio'
26
26
  require 'typhoeus'
27
27
  require 'date'
28
+ require 'msgpack'
29
+ require 'csv'
28
30
 
29
31
  def wrap(s, width=78, indent=19, extra_indent=2)
30
32
  lines = []
@@ -46,7 +48,7 @@ def wrap(s, width=78, indent=19, extra_indent=2)
46
48
  return lines.join "\n"
47
49
  end
48
50
 
49
- def follow(fname,io,copy,deep=0)
51
+ def follow(fname,io,copy,deep=0,index=nil)
50
52
  tname = if fname =~ /\.xes\.shift\.yaml/
51
53
  File.basename(fname,'.xes.shift.yaml')
52
54
  elsif fname =~ /\.xes\.yaml/
@@ -58,7 +60,7 @@ def follow(fname,io,copy,deep=0)
58
60
  end
59
61
  YAML.load_stream(io) do |e|
60
62
  if name = e.dig('log','trace','cpee:name')
61
- puts " " * deep + name + " (#{tname}) - #{e.dig('log','trace','concept:name')}"
63
+ index.write " " * deep + name + " (#{tname}) - #{e.dig('log','trace','concept:name')}\n"
62
64
  end
63
65
  if e.dig('event','cpee:lifecycle:transition') == 'task/instantiation'
64
66
  base = e.dig('event','raw')
@@ -68,13 +70,14 @@ def follow(fname,io,copy,deep=0)
68
70
  end
69
71
  uuid = base.dig('CPEE-INSTANCE-UUID') rescue nil
70
72
  if uuid
71
- react File.dirname(fname) + "/#{uuid}.xes.yaml",copy,deep + 2
73
+ react File.dirname(fname) + "/#{uuid}.xes.yaml", copy, deep + 2, index
72
74
  end
73
75
  end
74
76
  end
75
77
  end
76
78
 
77
- def react(name,copy=false,deep=0)
79
+ def react(name,copy=false,deep=0,index=nil)
80
+ index ||= File.open('index.txt','w')
78
81
  if name.nil?
79
82
  help
80
83
  elsif name =~ /^https?:\/\//
@@ -83,59 +86,72 @@ def react(name,copy=false,deep=0)
83
86
  file = Tempfile.new('sic')
84
87
  file.write(res.body)
85
88
  file.rewind
86
- follow name, file, copy, deep
89
+ follow name, file, copy, deep, index
87
90
  file.close
88
91
  file.unlink
89
92
  end
90
93
  elsif File.exist? name
91
- follow name, File.open(name), copy, deep
94
+ follow name, File.open(name), copy, deep, index
92
95
  else
93
96
  help
94
97
  end
95
98
  end
96
99
 
97
100
  def extract(path)
101
+ unlink = false
98
102
  if path =~ /^http.*/
99
- response = Typhoeus.get(path)
100
- if response.success?
101
- text = response.response_body
103
+ unlink = true
104
+ text = Tempfile.new('extract-model-download')
105
+ request = Typhoeus::Request.new("www.example.com/huge.iso")
106
+ request.on_headers do |response|
107
+ if response.code != 200
108
+ raise "Request failed"
109
+ end
110
+ end
111
+ request.on_body do |chunk|
112
+ text.write(chunk)
113
+ end
114
+ request.on_complete do |response|
115
+ text.rewind
102
116
  end
117
+ request.run
103
118
  else
104
- text = File.read(path)
119
+ text = File.open(path)
105
120
  end
106
121
  yaml = Psych.load_stream(text)
107
122
  changes = []
108
123
 
109
- info = yaml.shift()
124
+ info = yaml.shift
110
125
  uuid = info.dig('log','trace','cpee:instance')
111
- yaml.each() do |el|
112
- if(el['event']['id:id'] == 'external' && (el.dig('event','cpee:lifecycle:transition') == 'endpoints/change' || el.dig('event','cpee:lifecycle:transition') == 'dataelements/change'|| el.dig('event','cpee:lifecycle:transition') == 'description/change'))
126
+ yaml.each do |el|
127
+ if el['event']['id:id'] == 'external' && (el.dig('event','cpee:lifecycle:transition') == 'endpoints/change' || el.dig('event','cpee:lifecycle:transition') == 'dataelements/change'|| el.dig('event','cpee:lifecycle:transition') == 'description/change')
113
128
  changes.push(el)
114
129
  end
115
130
  end
116
- #puts "found #{changes.size()} changes"
117
131
 
118
- changes.sort!() {|a,b| DateTime.strptime(a.dig('event','time:timestamp'),'%Y-%m-%dT%H:%M:%S.%L%:z') <=> DateTime.strptime(b.dig('event','time:timestamp'),'%Y-%m-%dT%H:%M:%S.%L%:z')}
119
- #p changes.map() {|el| el.dig('event','time:timestamp')}
132
+ changes.sort! { |a,b| DateTime.strptime(a.dig('event','time:timestamp'),'%Y-%m-%dT%H:%M:%S.%L%:z') <=> DateTime.strptime(b.dig('event','time:timestamp'),'%Y-%m-%dT%H:%M:%S.%L%:z') }
120
133
 
121
134
  de = ep = desc = nil
122
135
  counter = 0
123
- changes.each() do |change|
124
- if(change.dig('event','cpee:lifecycle:transition') == 'dataelements/change') then
136
+ changes.each do |change|
137
+ if change.dig('event','cpee:lifecycle:transition') == 'dataelements/change'
125
138
  de = change.dig('event','data')
126
139
  end
127
- if(change.dig('event','cpee:lifecycle:transition') == 'endpoints/change') then
140
+ if change.dig('event','cpee:lifecycle:transition') == 'endpoints/change'
128
141
  ep = change.dig('event','data')
129
142
  end
130
- if(change.dig('event','cpee:lifecycle:transition') == 'description/change') then
143
+ if change.dig('event','cpee:lifecycle:transition') == 'description/change'
131
144
  desc = change.dig('event','cpee:description')
132
145
  end
133
- if(change.dig('event','cpee:lifecycle:transition') == 'description/change' || change.dig('event','cpee:lifecycle:transition') == 'endpoints/change') then
146
+ if change.dig('event','cpee:lifecycle:transition') == 'description/change' || change.dig('event','cpee:lifecycle:transition') == 'endpoints/change'
134
147
  yield uuid, de, ep, desc, counter if block_given?
135
148
  counter += 1
136
149
  end
137
150
  end
138
151
 
152
+ text.close
153
+ text.unlink if unlink
154
+
139
155
  [de, ep, desc]
140
156
  end
141
157
 
@@ -153,21 +169,26 @@ ARGV.options { |opt|
153
169
  opt.on("")
154
170
  opt.on(wrap("new [DIR] scaffolds a sample logging service. Add a handler to a cpee instance to experience the pleasure."))
155
171
  opt.on("")
156
- opt.on(wrap("view [DIR] view the dependencies between processes and subprocesses. Works for local and remote logs. Examples:\n#{exname} view https://cpee.org/log/123.xes.yaml\n#{exname} view https://cpee.org/log/a.xes.yaml > index.txt\n#{exname} view ~/log/logs/456.xes.yaml"))
172
+ opt.on(wrap("view [LOG] view the dependencies between processes and subprocesses. Works for local and remote logs. Examples:\n#{exname} view https://cpee.org/log/123.xes.yaml\n#{exname} view https://cpee.org/log/a.xes.yaml > index.txt\n#{exname} view ~/log/logs/456.xes.yaml"))
157
173
  opt.on("")
158
- opt.on(wrap("copy [DIR] copy dependent processes and subprocesses to the current directory. Works for local and remote logs. Examples: \n#{exname} copy https://cpee.org/log/123.xes.yaml\n#{exname} copy ~/log/logs/456.xes.yaml"))
174
+ opt.on(wrap("copy [LOG] copy dependent processes and subprocesses to the current directory. Works for local and remote logs. Examples: \n#{exname} copy https://cpee.org/log/123.xes.yaml\n#{exname} copy ~/log/logs/456.xes.yaml"))
159
175
  opt.on("")
160
176
  opt.on(wrap("extract-all [LOG] extract cpee testset from cpee xes-yaml log. Works for local and remote logs. Write logs to files in folder named like the instance uuid contained in the log. Examples: \n#{exname} extract https://cpee.org/log/123.xes.yaml\n#{exname} extract ~/log/logs/456.xes.yaml"))
161
177
  opt.on("")
162
- opt.on(wrap("extract-last [LOG] extract cpee testset from cpee xes-yaml log. Works for local and remote logs. Write last revision of the model to stdout. Examples:\n#{exname} extract https://cpee.org/log/123.xes.yaml\n#{exname} extract ~/log/logs/456.xes.yaml"))
178
+ opt.on(wrap("extract-last [LOG] extract cpee testset from cpee xes-yaml log. Works for local and remote logs. Write last revision of the model to stdout. When called with out [LOG], models for all log files in the current directory are extracted. Examples:\n#{exname} extract https://cpee.org/log/123.xes.yaml\n#{exname} extract ~/log/logs/456.xes.yaml"))
179
+ opt.on("")
180
+ opt.on(wrap("index [LOG] creates an index for a log file, for more efficient parsing. When called without [LOG], indexes all log files in the current directory. Examples:\n#{exname} index https://cpee.org/log/123.xes.yaml\n#{exname} index ~/log/logs/456.xes.yaml"))
163
181
  opt.parse!
164
182
  }
165
- if (ARGV.length != 2)
183
+
184
+ if (ARGV.length < 1 || ARGV.length > 2)
166
185
  puts ARGV.options
167
186
  exit
168
- else
187
+ elsif ARGV.length == 2
169
188
  command = ARGV[0]
170
189
  path = ARGV[1]
190
+ elsif ARGV.length == 1 && %w{index extract-last}.include?(ARGV[0])
191
+ command = ARGV[0]
171
192
  end
172
193
 
173
194
  if command == 'new'
@@ -206,27 +227,79 @@ elsif command == 'extract-all'
206
227
  File.write(filename, xml.to_s())
207
228
  end
208
229
  elsif command == 'extract-last'
209
- de, ep, desc = extract(path)
230
+ path = if path
231
+ [path]
232
+ else
233
+ Dir.glob('*.xes.yaml')
234
+ end
210
235
 
211
- xml = XML::Smart.string('<testset xmlns="http://cpee.org/ns/properties/2.0"><executionhandler>ruby</executionhandler></testset>')
212
- dataelements = xml.root().add('dataelements')
213
- endpoints = xml.root().add('endpoints')
214
- description = xml.root().add('description').add(XML::Smart.string('<description xmlns="http://cpee.org/ns/description/1.0"/>').root())
215
- unless de.nil?
216
- de.each do |d|
217
- dataelements.add(d['name'],d['value'])
236
+ path.each do |f|
237
+ de, ep, desc = extract(f)
238
+
239
+ xml = XML::Smart.string('<testset xmlns="http://cpee.org/ns/properties/2.0"><executionhandler>ruby</executionhandler></testset>')
240
+ dataelements = xml.root().add('dataelements')
241
+ endpoints = xml.root().add('endpoints')
242
+ description = xml.root().add('description').add(XML::Smart.string('<description xmlns="http://cpee.org/ns/description/1.0"/>').root())
243
+ unless de.nil?
244
+ de.each do |d|
245
+ dataelements.add(d['name'],d['value'])
246
+ end
218
247
  end
219
- end
220
- unless ep.nil?
221
- ep.each do |e|
222
- endpoints.add(e['name'],e['value'])
248
+ unless ep.nil?
249
+ ep.each do |e|
250
+ endpoints.add(e['name'],e['value'])
251
+ end
223
252
  end
253
+ unless desc.nil?
254
+ description.replace_by(XML::Smart.string(desc).root())
255
+ end
256
+
257
+ File.write(f + '.model', xml.to_s)
224
258
  end
225
- unless desc.nil?
226
- description.replace_by(XML::Smart.string(desc).root())
259
+ elsif command == 'index'
260
+ path = if path
261
+ [path]
262
+ else
263
+ Dir.glob('*.xes.yaml')
227
264
  end
228
265
 
229
- puts xml.to_s
266
+ path.each do |f|
267
+ index = []
268
+ io = File.open(f)
269
+ while not io.eof?
270
+ start = io.pos
271
+ docs = io.readline("---\n",chomp: true)
272
+ doc = YAML::load(docs, permitted_classes: [Time])
273
+ if doc
274
+ transition = doc.dig('event','cpee:lifecycle:transition')
275
+ if transition =~ /^(activity\/calling|activity\/receiving|task\/instantiation)/
276
+ endpoint = doc.dig('event','concept:endpoint')
277
+ uuid = doc.dig('event','cpee:activity_uuid')
278
+ transition = case transition
279
+ when 'activity/calling'
280
+ 'c'
281
+ when 'activity/receiving'
282
+ 'r'
283
+ when 'task/instantiation'
284
+ 'i'
285
+ end
286
+ index << { :e => endpoint.to_s, :u => uuid.to_s, :t => transition.to_s, :s => start.to_i, :l => docs.length.to_i }
287
+ end
288
+ end
289
+ end
290
+ io.close
291
+ CSV.open(f + '.index.csv', 'w') do |csv|
292
+ index.each do |e|
293
+ csv << e.values
294
+ end
295
+ end
296
+
297
+ nindex = index.group_by{ |a| a[:u] }.collect do |k,v|
298
+ [v[0][:e], v.collect{ |a| [ a[:t], {:s => a[:s], :l => a[:l]} ] } ]
299
+ end
300
+
301
+ File.write(f + '.index', MessagePack.pack(nindex))
302
+ end
230
303
  else
231
304
  puts ARGV.options
232
305
  end
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.3.4
4
+ version: 1.3.5
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: 2024-01-17 00:00:00.000000000 Z
12
+ date: 2024-01-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: riddl