cpee-logging-xes-yaml 1.3.3 → 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: 5d0f1a3d5cdf89d14a2c7ff96d36f0d331496ca095d4c395c49c770e827ed279
4
- data.tar.gz: 67c87266391555e7dd326420e341549314d3b111b036637c965e42300972489d
3
+ metadata.gz: ddf89052e93d9c38c178377595703e815e14bc16a05b2c57cbf9ff73f65f12ad
4
+ data.tar.gz: c1fc949892594dd764c55338ddbe9d0eb74aa84a49799503c4a2cc5764f0f2c5
5
5
  SHA512:
6
- metadata.gz: 97bdab2b3cfaafb419e5dd20a87eab3ec096a08a15c22fac43f1a7209e3a440bb31246007c85f38dc51ed60ed28115d651191c4de24aae6d8480341e7d286cc1
7
- data.tar.gz: 434309fe76ed0653a8af989e4fd074c21d2164f37518d4808c54fe8bb77bd8c86b2bf1f6aa39fa556070a68d32a13b4262052a7caa2089237e84b14d7394f88b
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.3"
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)"
@@ -16,7 +16,6 @@
16
16
  # CPEE-LOGGING-XES-YAML (file LICENSE in the main directory). If not, see
17
17
  # <http://www.gnu.org/licenses/>.
18
18
 
19
- curpath = __dir__
20
19
  require 'rubygems'
21
20
  require 'optparse'
22
21
  require 'fileutils'
@@ -26,17 +25,21 @@ require 'typhoeus'
26
25
  require 'stringio'
27
26
  require 'typhoeus'
28
27
  require 'date'
28
+ require 'msgpack'
29
+ require 'csv'
29
30
 
30
- def wrap(s, width=78, indent=19, extra_indent=4)
31
+ def wrap(s, width=78, indent=19, extra_indent=2)
31
32
  lines = []
32
- line, s = s[0..indent-2], s[indent..-1]
33
- s.split(/\n/).each do |ss|
34
- ss.split(/[ \t]+/).each do |word|
33
+ line, s = s[0..indent-1], s[indent..-1]
34
+ s.split(/\n/).each_with_index do |ss,i|
35
+ ss.split(/[ \t]+/).each_with_index do |word,j|
35
36
  if line.size + word.size >= width
36
37
  lines << line
37
- line = (" " * (indent + extra_indent)) + word
38
+ line = (" " * (indent)) + word
38
39
  else
39
- line << " " << word
40
+ line << " " if i > 0 || j != 0
41
+ line << (" " * (extra_indent)) if i > 0 && j == 0
42
+ line << word
40
43
  end
41
44
  end
42
45
  lines << line if line
@@ -45,7 +48,7 @@ def wrap(s, width=78, indent=19, extra_indent=4)
45
48
  return lines.join "\n"
46
49
  end
47
50
 
48
- def follow(fname,io,copy,deep=0)
51
+ def follow(fname,io,copy,deep=0,index=nil)
49
52
  tname = if fname =~ /\.xes\.shift\.yaml/
50
53
  File.basename(fname,'.xes.shift.yaml')
51
54
  elsif fname =~ /\.xes\.yaml/
@@ -57,7 +60,7 @@ def follow(fname,io,copy,deep=0)
57
60
  end
58
61
  YAML.load_stream(io) do |e|
59
62
  if name = e.dig('log','trace','cpee:name')
60
- puts " " * deep + name + " (#{tname}) - #{e.dig('log','trace','concept:name')}"
63
+ index.write " " * deep + name + " (#{tname}) - #{e.dig('log','trace','concept:name')}\n"
61
64
  end
62
65
  if e.dig('event','cpee:lifecycle:transition') == 'task/instantiation'
63
66
  base = e.dig('event','raw')
@@ -67,13 +70,14 @@ def follow(fname,io,copy,deep=0)
67
70
  end
68
71
  uuid = base.dig('CPEE-INSTANCE-UUID') rescue nil
69
72
  if uuid
70
- react File.dirname(fname) + "/#{uuid}.xes.yaml",copy,deep + 2
73
+ react File.dirname(fname) + "/#{uuid}.xes.yaml", copy, deep + 2, index
71
74
  end
72
75
  end
73
76
  end
74
77
  end
75
78
 
76
- def react(name,copy=false,deep=0)
79
+ def react(name,copy=false,deep=0,index=nil)
80
+ index ||= File.open('index.txt','w')
77
81
  if name.nil?
78
82
  help
79
83
  elsif name =~ /^https?:\/\//
@@ -82,59 +86,72 @@ def react(name,copy=false,deep=0)
82
86
  file = Tempfile.new('sic')
83
87
  file.write(res.body)
84
88
  file.rewind
85
- follow name, file, copy, deep
89
+ follow name, file, copy, deep, index
86
90
  file.close
87
91
  file.unlink
88
92
  end
89
93
  elsif File.exist? name
90
- follow name, File.open(name), copy, deep
94
+ follow name, File.open(name), copy, deep, index
91
95
  else
92
96
  help
93
97
  end
94
98
  end
95
99
 
96
100
  def extract(path)
101
+ unlink = false
97
102
  if path =~ /^http.*/
98
- response = Typhoeus.get(path)
99
- if response.success?
100
- 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
101
116
  end
117
+ request.run
102
118
  else
103
- text = File.read(File.join(__dir__,path))
119
+ text = File.open(path)
104
120
  end
105
121
  yaml = Psych.load_stream(text)
106
122
  changes = []
107
123
 
108
- info = yaml.shift()
124
+ info = yaml.shift
109
125
  uuid = info.dig('log','trace','cpee:instance')
110
- yaml.each() do |el|
111
- 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')
112
128
  changes.push(el)
113
129
  end
114
130
  end
115
- #puts "found #{changes.size()} changes"
116
131
 
117
- 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')}
118
- #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') }
119
133
 
120
134
  de = ep = desc = nil
121
135
  counter = 0
122
- changes.each() do |change|
123
- 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'
124
138
  de = change.dig('event','data')
125
139
  end
126
- if(change.dig('event','cpee:lifecycle:transition') == 'endpoints/change') then
140
+ if change.dig('event','cpee:lifecycle:transition') == 'endpoints/change'
127
141
  ep = change.dig('event','data')
128
142
  end
129
- if(change.dig('event','cpee:lifecycle:transition') == 'description/change') then
143
+ if change.dig('event','cpee:lifecycle:transition') == 'description/change'
130
144
  desc = change.dig('event','cpee:description')
131
145
  end
132
- 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'
133
147
  yield uuid, de, ep, desc, counter if block_given?
134
148
  counter += 1
135
149
  end
136
150
  end
137
151
 
152
+ text.close
153
+ text.unlink if unlink
154
+
138
155
  [de, ep, desc]
139
156
  end
140
157
 
@@ -147,28 +164,36 @@ ARGV.options { |opt|
147
164
  opt.on("Options:")
148
165
  opt.on("--help", "-h", "This text") { puts opt; exit }
149
166
  opt.on("")
167
+ opt.on(wrap("\"#{exname}\" will be call \"c\" in the examples for each command."))
168
+ exname = 'c'
169
+ opt.on("")
150
170
  opt.on(wrap("new [DIR] scaffolds a sample logging service. Add a handler to a cpee instance to experience the pleasure."))
151
171
  opt.on("")
152
- 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"))
153
173
  opt.on("")
154
- 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"))
155
175
  opt.on("")
156
- 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"))
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"))
157
177
  opt.on("")
158
- 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"))
159
181
  opt.parse!
160
182
  }
161
- if (ARGV.length != 2)
183
+
184
+ if (ARGV.length < 1 || ARGV.length > 2)
162
185
  puts ARGV.options
163
186
  exit
164
- else
187
+ elsif ARGV.length == 2
165
188
  command = ARGV[0]
166
189
  path = ARGV[1]
190
+ elsif ARGV.length == 1 && %w{index extract-last}.include?(ARGV[0])
191
+ command = ARGV[0]
167
192
  end
168
193
 
169
194
  if command == 'new'
170
195
  if !File.exist?(path)
171
- FileUtils.cp_r(File.join(curpath,'..','server'),path)
196
+ FileUtils.cp_r(File.join(__dir__,'..','server'),path)
172
197
  FileUtils.mkdir(File.join(path,'logs')) rescue nil
173
198
  else
174
199
  puts 'Directory already exists.'
@@ -196,33 +221,85 @@ elsif command == 'extract-all'
196
221
  unless desc.nil?
197
222
  description.replace_by(XML::Smart.string(desc).root())
198
223
  end
199
- dirname = File.join(__dir__,uuid)
224
+ dirname = File.join(uuid)
200
225
  filename = File.join(dirname,"#{uuid}_#{version}.xml")
201
226
  Dir.mkdir(dirname) unless Dir.exist?(dirname)
202
227
  File.write(filename, xml.to_s())
203
228
  end
204
229
  elsif command == 'extract-last'
205
- de, ep, desc = extract(path)
230
+ path = if path
231
+ [path]
232
+ else
233
+ Dir.glob('*.xes.yaml')
234
+ end
235
+
236
+ path.each do |f|
237
+ de, ep, desc = extract(f)
206
238
 
207
- xml = XML::Smart.string('<testset xmlns="http://cpee.org/ns/properties/2.0"><executionhandler>ruby</executionhandler></testset>')
208
- dataelements = xml.root().add('dataelements')
209
- endpoints = xml.root().add('endpoints')
210
- description = xml.root().add('description').add(XML::Smart.string('<description xmlns="http://cpee.org/ns/description/1.0"/>').root())
211
- unless de.nil?
212
- de.each do |d|
213
- dataelements.add(d['name'],d['value'])
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
214
247
  end
215
- end
216
- unless ep.nil?
217
- ep.each do |e|
218
- endpoints.add(e['name'],e['value'])
248
+ unless ep.nil?
249
+ ep.each do |e|
250
+ endpoints.add(e['name'],e['value'])
251
+ end
219
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)
220
258
  end
221
- unless desc.nil?
222
- 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')
223
264
  end
224
265
 
225
- 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
226
303
  else
227
304
  puts ARGV.options
228
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.3
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-16 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