cpee-logging-xes-yaml 1.3.2 → 1.3.4

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: 99c79d272d96fc0194b782ae5f93492b7a50f5daac07cb60da447d2be314cbc8
4
- data.tar.gz: ceb9ac1ca98aa9bae3fc4fb15c3e617ec306fa00bc62e8f627888169ee8ca703
3
+ metadata.gz: aab20ce260e56f4571add36cef8c7fe6f638fad4a723d28f8a13e6e93e99a32c
4
+ data.tar.gz: 122128fd3e956198fc7096409ff1f64bf47d0e17f5f2e72dd2f4cf3d138ea173
5
5
  SHA512:
6
- metadata.gz: fe2f39dad68c6a86308811d25df6a1e41e9133984c1c67c6512240128abce5fa57727f915615cbe2fae21ef61bead8ab20b36e5c8bbab43181d7a9a38d116459
7
- data.tar.gz: 94fa1197bc3e2b820464c947204aaa3ec376c13d90a87f3f371c11c39548aee98c4ec6fc71de28969ef319e07df780eb024db674e5777e33796cfc8a62b9dc51
6
+ metadata.gz: f36ec97639c73e0735250eee61c39febc1b43e2bab34912780be9a393ccedc45ef3cffdcfd97cd432145a73fcb0935e10dfc405bdd9500117de9afb53522b9de
7
+ data.tar.gz: 242461d18564a0c2fb9b2b5992e45a99e7506e79aab3eaa08be4c4a1bc4846733b39bc49b7b6e5c7714f719e74ce6afd6fa8225a91642be3188f61c597dfa4f2
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "cpee-logging-xes-yaml"
3
- s.version = "1.3.2"
3
+ s.version = "1.3.4"
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)"
@@ -18,10 +18,9 @@ require 'weel'
18
18
  require 'digest/sha1'
19
19
 
20
20
  class StreamPoint
21
- attr_accessor :value, :timestamp, :source, :meta
22
- attr_reader :id
21
+ attr_accessor :value, :timestamp, :source, :meta, :id
23
22
 
24
- def initialize(id)
23
+ def initialize(id=nil)
25
24
  @id = id
26
25
  @value = nil
27
26
  @timestamp = Time.now
@@ -101,6 +100,7 @@ module CPEE
101
100
  tp = nil
102
101
  if val.is_a? StreamPoint
103
102
  tp = val
103
+ tp.id = tid if tp.id.nil?
104
104
  tp.source = tso if tp.source.nil?
105
105
  else
106
106
  tp = StreamPoint.new(tid)
@@ -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'
@@ -24,17 +23,21 @@ require 'xml/smart'
24
23
  require 'yaml'
25
24
  require 'typhoeus'
26
25
  require 'stringio'
26
+ require 'typhoeus'
27
+ require 'date'
27
28
 
28
- def wrap(s, width=78, indent=18, extra_indent=4)
29
+ def wrap(s, width=78, indent=19, extra_indent=2)
29
30
  lines = []
30
- line, s = s[0..indent-2], s[indent..-1]
31
- s.split(/\n/).each do |ss|
32
- ss.split(/[ \t]+/).each do |word|
31
+ line, s = s[0..indent-1], s[indent..-1]
32
+ s.split(/\n/).each_with_index do |ss,i|
33
+ ss.split(/[ \t]+/).each_with_index do |word,j|
33
34
  if line.size + word.size >= width
34
35
  lines << line
35
- line = (" " * (indent + extra_indent)) + word
36
+ line = (" " * (indent)) + word
36
37
  else
37
- line << " " << word
38
+ line << " " if i > 0 || j != 0
39
+ line << (" " * (extra_indent)) if i > 0 && j == 0
40
+ line << word
38
41
  end
39
42
  end
40
43
  lines << line if line
@@ -91,20 +94,72 @@ def react(name,copy=false,deep=0)
91
94
  end
92
95
  end
93
96
 
97
+ def extract(path)
98
+ if path =~ /^http.*/
99
+ response = Typhoeus.get(path)
100
+ if response.success?
101
+ text = response.response_body
102
+ end
103
+ else
104
+ text = File.read(path)
105
+ end
106
+ yaml = Psych.load_stream(text)
107
+ changes = []
108
+
109
+ info = yaml.shift()
110
+ 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'))
113
+ changes.push(el)
114
+ end
115
+ end
116
+ #puts "found #{changes.size()} changes"
117
+
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')}
120
+
121
+ de = ep = desc = nil
122
+ counter = 0
123
+ changes.each() do |change|
124
+ if(change.dig('event','cpee:lifecycle:transition') == 'dataelements/change') then
125
+ de = change.dig('event','data')
126
+ end
127
+ if(change.dig('event','cpee:lifecycle:transition') == 'endpoints/change') then
128
+ ep = change.dig('event','data')
129
+ end
130
+ if(change.dig('event','cpee:lifecycle:transition') == 'description/change') then
131
+ desc = change.dig('event','cpee:description')
132
+ end
133
+ if(change.dig('event','cpee:lifecycle:transition') == 'description/change' || change.dig('event','cpee:lifecycle:transition') == 'endpoints/change') then
134
+ yield uuid, de, ep, desc, counter if block_given?
135
+ counter += 1
136
+ end
137
+ end
138
+
139
+ [de, ep, desc]
140
+ end
141
+
94
142
  exname = File.basename($0)
95
143
 
96
144
  ARGV.options { |opt|
97
145
  opt.summary_indent = ' ' * 2
98
- opt.summary_width = 15
146
+ opt.summary_width = 16
99
147
  opt.banner = "Usage:\n#{opt.summary_indent}#{exname} new [DIR] | view [URI] | copy [URI]\n"
100
148
  opt.on("Options:")
101
149
  opt.on("--help", "-h", "This text") { puts opt; exit }
102
150
  opt.on("")
103
- opt.on(wrap("new [DIR] scaffolds a sample logging service. Add a handler to a cpee instance to experience the pleasure.",78,18,0))
151
+ opt.on(wrap("\"#{exname}\" will be call \"c\" in the examples for each command."))
152
+ exname = 'c'
104
153
  opt.on("")
105
- opt.on(wrap("view [DIR] view the dependencies between processes and subprocesses.\nWorks 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"))
154
+ opt.on(wrap("new [DIR] scaffolds a sample logging service. Add a handler to a cpee instance to experience the pleasure."))
106
155
  opt.on("")
107
- opt.on(wrap("copy [DIR] copy dependent processes and subprocesses to the current\ndirectory. 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"))
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"))
157
+ 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"))
159
+ opt.on("")
160
+ 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
+ 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"))
108
163
  opt.parse!
109
164
  }
110
165
  if (ARGV.length != 2)
@@ -112,20 +167,66 @@ if (ARGV.length != 2)
112
167
  exit
113
168
  else
114
169
  command = ARGV[0]
115
- dir = ARGV[1]
170
+ path = ARGV[1]
116
171
  end
117
172
 
118
173
  if command == 'new'
119
- if !File.exist?(dir)
120
- FileUtils.cp_r(File.join(curpath,'..','server'),dir)
121
- FileUtils.mkdir(File.join(dir,'logs')) rescue nil
174
+ if !File.exist?(path)
175
+ FileUtils.cp_r(File.join(__dir__,'..','server'),path)
176
+ FileUtils.mkdir(File.join(path,'logs')) rescue nil
122
177
  else
123
178
  puts 'Directory already exists.'
124
179
  end
125
180
  elsif command == 'view'
126
- react dir, false
181
+ react path, false
127
182
  elsif command == 'copy'
128
- react dir, true
183
+ react path, true
184
+ elsif command == 'extract-all'
185
+ extract(path) do |uuid, de, ep, desc, version|
186
+ xml = XML::Smart.string('<testset xmlns="http://cpee.org/ns/properties/2.0"><executionhandler>ruby</executionhandler></testset>')
187
+ dataelements = xml.root().add('dataelements')
188
+ endpoints = xml.root().add('endpoints')
189
+ description = xml.root().add('description').add(XML::Smart.string('<description xmlns="http://cpee.org/ns/description/1.0"/>').root())
190
+ unless de.nil?
191
+ de.each do |d|
192
+ dataelements.add(d['name'],d['value'])
193
+ end
194
+ end
195
+ unless ep.nil?
196
+ ep.each do |e|
197
+ endpoints.add(e['name'],e['value'])
198
+ end
199
+ end
200
+ unless desc.nil?
201
+ description.replace_by(XML::Smart.string(desc).root())
202
+ end
203
+ dirname = File.join(uuid)
204
+ filename = File.join(dirname,"#{uuid}_#{version}.xml")
205
+ Dir.mkdir(dirname) unless Dir.exist?(dirname)
206
+ File.write(filename, xml.to_s())
207
+ end
208
+ elsif command == 'extract-last'
209
+ de, ep, desc = extract(path)
210
+
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'])
218
+ end
219
+ end
220
+ unless ep.nil?
221
+ ep.each do |e|
222
+ endpoints.add(e['name'],e['value'])
223
+ end
224
+ end
225
+ unless desc.nil?
226
+ description.replace_by(XML::Smart.string(desc).root())
227
+ end
228
+
229
+ puts xml.to_s
129
230
  else
130
231
  puts ARGV.options
131
232
  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.2
4
+ version: 1.3.4
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: 2023-04-21 00:00:00.000000000 Z
12
+ date: 2024-01-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: riddl
@@ -98,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
98
  - !ruby/object:Gem::Version
99
99
  version: '0'
100
100
  requirements: []
101
- rubygems_version: 3.3.26
101
+ rubygems_version: 3.4.10
102
102
  signing_key:
103
103
  specification_version: 4
104
104
  summary: Logging for the cloud process execution engine (cpee.org)