omf_common 6.0.0.pre.6 → 6.0.0.pre.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,61 @@
1
+ default namespace = "http://schema.mytestbed.net/6.0/protocol"
2
+
3
+ start = (create | configure | request | release | inform)
4
+
5
+ anything = ( text | element * { (attribute type { text })?, (text | anything) * })
6
+
7
+ create = element create {
8
+ attribute msg_id { text },
9
+ element context_id { text },
10
+ element property {
11
+ attribute key { text },
12
+ (attribute type { text })?,
13
+ anything *
14
+ } *
15
+ }
16
+
17
+ configure = element configure {
18
+ attribute msg_id { text },
19
+ element context_id { text },
20
+ element property {
21
+ attribute key { text },
22
+ (attribute type { text })?,
23
+ anything *
24
+ } *
25
+ }
26
+
27
+ request = element request {
28
+ attribute msg_id { text },
29
+ element context_id { text },
30
+ element publish_to { text }?,
31
+ element property {
32
+ (attribute key { text }),
33
+ (attribute type { text })?,
34
+ anything *
35
+ }*
36
+ }
37
+
38
+ release = element release {
39
+ attribute msg_id { text },
40
+ element context_id { text },
41
+ element resource_id { text },
42
+ element property {
43
+ (attribute key { text }),
44
+ (attribute type { text })?,
45
+ anything *
46
+ }*
47
+ }
48
+
49
+ inform = element inform {
50
+ attribute msg_id { text },
51
+ element context_id { text },
52
+ element inform_type { "CREATED" | "FAILED" | "STATUS" | "RELEASED" | "ERROR" | "WARN"},
53
+ element resource_id { text }?,
54
+ element resource_address { text }?,
55
+ element reason { text }?,
56
+ element property {
57
+ attribute key { text },
58
+ (attribute type { text })?,
59
+ anything *
60
+ } *
61
+ }
@@ -0,0 +1,157 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <grammar ns="http://schema.mytestbed.net/6.0/protocol" xmlns="http://relaxng.org/ns/structure/1.0">
3
+ <start>
4
+ <choice>
5
+ <ref name="create"/>
6
+ <ref name="configure"/>
7
+ <ref name="request"/>
8
+ <ref name="release"/>
9
+ <ref name="inform"/>
10
+ </choice>
11
+ </start>
12
+ <define name="anything">
13
+ <choice>
14
+ <text/>
15
+ <element>
16
+ <anyName/>
17
+ <optional>
18
+ <attribute name="type"/>
19
+ </optional>
20
+ <zeroOrMore>
21
+ <choice>
22
+ <text/>
23
+ <ref name="anything"/>
24
+ </choice>
25
+ </zeroOrMore>
26
+ </element>
27
+ </choice>
28
+ </define>
29
+ <define name="create">
30
+ <element name="create">
31
+ <attribute name="msg_id"/>
32
+ <element name="context_id">
33
+ <text/>
34
+ </element>
35
+ <zeroOrMore>
36
+ <element name="property">
37
+ <attribute name="key"/>
38
+ <optional>
39
+ <attribute name="type"/>
40
+ </optional>
41
+ <zeroOrMore>
42
+ <ref name="anything"/>
43
+ </zeroOrMore>
44
+ </element>
45
+ </zeroOrMore>
46
+ </element>
47
+ </define>
48
+ <define name="configure">
49
+ <element name="configure">
50
+ <attribute name="msg_id"/>
51
+ <element name="context_id">
52
+ <text/>
53
+ </element>
54
+ <zeroOrMore>
55
+ <element name="property">
56
+ <attribute name="key"/>
57
+ <optional>
58
+ <attribute name="type"/>
59
+ </optional>
60
+ <zeroOrMore>
61
+ <ref name="anything"/>
62
+ </zeroOrMore>
63
+ </element>
64
+ </zeroOrMore>
65
+ </element>
66
+ </define>
67
+ <define name="request">
68
+ <element name="request">
69
+ <attribute name="msg_id"/>
70
+ <element name="context_id">
71
+ <text/>
72
+ </element>
73
+ <optional>
74
+ <element name="publish_to">
75
+ <text/>
76
+ </element>
77
+ </optional>
78
+ <zeroOrMore>
79
+ <element name="property">
80
+ <attribute name="key"/>
81
+ <optional>
82
+ <attribute name="type"/>
83
+ </optional>
84
+ <zeroOrMore>
85
+ <ref name="anything"/>
86
+ </zeroOrMore>
87
+ </element>
88
+ </zeroOrMore>
89
+ </element>
90
+ </define>
91
+ <define name="release">
92
+ <element name="release">
93
+ <attribute name="msg_id"/>
94
+ <element name="context_id">
95
+ <text/>
96
+ </element>
97
+ <element name="resource_id">
98
+ <text/>
99
+ </element>
100
+ <zeroOrMore>
101
+ <element name="property">
102
+ <attribute name="key"/>
103
+ <optional>
104
+ <attribute name="type"/>
105
+ </optional>
106
+ <zeroOrMore>
107
+ <ref name="anything"/>
108
+ </zeroOrMore>
109
+ </element>
110
+ </zeroOrMore>
111
+ </element>
112
+ </define>
113
+ <define name="inform">
114
+ <element name="inform">
115
+ <attribute name="msg_id"/>
116
+ <element name="context_id">
117
+ <text/>
118
+ </element>
119
+ <element name="inform_type">
120
+ <choice>
121
+ <value>CREATED</value>
122
+ <value>FAILED</value>
123
+ <value>STATUS</value>
124
+ <value>RELEASED</value>
125
+ <value>ERROR</value>
126
+ <value>WARN</value>
127
+ </choice>
128
+ </element>
129
+ <optional>
130
+ <element name="resource_id">
131
+ <text/>
132
+ </element>
133
+ </optional>
134
+ <optional>
135
+ <element name="resource_address">
136
+ <text/>
137
+ </element>
138
+ </optional>
139
+ <optional>
140
+ <element name="reason">
141
+ <text/>
142
+ </element>
143
+ </optional>
144
+ <zeroOrMore>
145
+ <element name="property">
146
+ <attribute name="key"/>
147
+ <optional>
148
+ <attribute name="type"/>
149
+ </optional>
150
+ <zeroOrMore>
151
+ <ref name="anything"/>
152
+ </zeroOrMore>
153
+ </element>
154
+ </zeroOrMore>
155
+ </element>
156
+ </define>
157
+ </grammar>
@@ -0,0 +1,34 @@
1
+ module OmfCommon
2
+ class Topic
3
+ attr_accessor :id, :comm
4
+
5
+ def initialize(id, comm)
6
+ self.id ||= id
7
+ self.comm ||= comm
8
+ end
9
+
10
+ def subscribe(&block)
11
+ comm.subscribe(id, &block)
12
+ end
13
+
14
+ def on_message(message_guard_proc = nil, &message_block)
15
+ event_block = proc do |event|
16
+ message_block.call(Message.parse(event.items.first.payload))
17
+ end
18
+ guard_block = proc do |event|
19
+ (event.items?) && (!event.delayed?) &&
20
+ event.items.first.payload &&
21
+ (omf_message = Message.parse(event.items.first.payload)) &&
22
+ event.node == self.id &&
23
+ (valid_guard?(message_guard_proc) ? message_guard_proc.call(omf_message) : true)
24
+ end
25
+ comm.topic_event(guard_block, &event_block)
26
+ end
27
+
28
+ private
29
+
30
+ def valid_guard?(guard_proc)
31
+ guard_proc && guard_proc.class == Proc
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,20 @@
1
+ module OmfCommon
2
+ class TopicMessage
3
+ attr_accessor :body, :comm
4
+
5
+ def initialize(body, comm)
6
+ self.body ||= body
7
+ self.comm ||= comm
8
+ end
9
+
10
+ def publish(topic_id, &block)
11
+ comm.publish(topic_id, body.dup, &block)
12
+ end
13
+
14
+ %w(created status failed released).each do |inform_type|
15
+ define_method("on_inform_#{inform_type}") do |*args, &message_block|
16
+ comm.send("on_#{inform_type}_message", body, &message_block)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -1,4 +1,4 @@
1
1
  module OmfCommon
2
- VERSION = "6.0.0.pre.6"
2
+ VERSION = "6.0.0.pre.7"
3
3
  PROTOCOL_VERSION = "6.0"
4
4
  end
data/omf_common.gemspec CHANGED
@@ -19,7 +19,10 @@ Gem::Specification.new do |s|
19
19
  s.require_paths = ["lib"]
20
20
 
21
21
  # specify any dependencies here; for example:
22
- s.add_development_dependency "minitest", "~> 2.11.3"
22
+ s.add_development_dependency "minitest", "~> 3.2"
23
+ s.add_development_dependency "em-minitest-spec", "~> 1.1.1"
24
+ s.add_development_dependency "simplecov"
25
+ s.add_runtime_dependency "eventmachine", "~> 0.12.10"
23
26
  s.add_runtime_dependency "blather", "~> 0.8.0"
24
27
  s.add_runtime_dependency "logging", "~> 1.7.1"
25
28
  s.add_runtime_dependency "hashie", "~> 1.2.0"
@@ -0,0 +1,252 @@
1
+ def affiliations_xml
2
+ <<-NODE
3
+ <iq type='result'
4
+ from='pubsub.shakespeare.lit'
5
+ to='francisco@denmark.lit'
6
+ id='affil1'>
7
+ <pubsub xmlns='http://jabber.org/protocol/pubsub'>
8
+ <affiliations>
9
+ <affiliation node='node1' affiliation='owner'/>
10
+ <affiliation node='node2' affiliation='owner'/>
11
+ <affiliation node='node3' affiliation='publisher'/>
12
+ <affiliation node='node4' affiliation='outcast'/>
13
+ <affiliation node='node5' affiliation='member'/>
14
+ <affiliation node='node6' affiliation='none'/>
15
+ </affiliations>
16
+ </pubsub>
17
+ </iq>
18
+ NODE
19
+ end
20
+
21
+ def subscriptions_xml
22
+ <<-NODE
23
+ <iq type='result'
24
+ from='pubsub.shakespeare.lit'
25
+ to='francisco@denmark.lit'
26
+ id='affil1'>
27
+ <pubsub xmlns='http://jabber.org/protocol/pubsub'>
28
+ <subscriptions>
29
+ <subscription node='node1' jid='francisco@denmark.lit' subscription='subscribed' subid='fd8237yr872h3f289j2'/>
30
+ <subscription node='node2' jid='francisco@denmark.lit' subscription='subscribed' subid='h8394hf8923ju'/>
31
+ <subscription node='node3' jid='francisco@denmark.lit' subscription='unconfigured'/>
32
+ <subscription node='node4' jid='francisco@denmark.lit' subscription='pending'/>
33
+ <subscription node='node5' jid='francisco@denmark.lit' subscription='none'/>
34
+ </subscriptions>
35
+ </pubsub>
36
+ </iq>
37
+ NODE
38
+ end
39
+
40
+ def event_notification_xml
41
+ <<-NODE
42
+ <message from='pubsub.shakespeare.lit' to='francisco@denmark.lit' id='foo'>
43
+ <event xmlns='http://jabber.org/protocol/pubsub#event'>
44
+ <items node='princely_musings'>
45
+ <item id='ae890ac52d0df67ed7cfdf51b644e901'/>
46
+ </items>
47
+ </event>
48
+ </message>
49
+ NODE
50
+ end
51
+
52
+ def event_subids_xml
53
+ <<-NODE
54
+ <message from='pubsub.shakespeare.lit' to='francisco@denmark.lit' id='foo'>
55
+ <event xmlns='http://jabber.org/protocol/pubsub#event'>
56
+ <items node='princely_musings'>
57
+ <item id='ae890ac52d0df67ed7cfdf51b644e901'/>
58
+ </items>
59
+ </event>
60
+ <headers xmlns='http://jabber.org/protocol/shim'>
61
+ <header name='SubID'>123-abc</header>
62
+ <header name='SubID'>004-yyy</header>
63
+ </headers>
64
+ </message>
65
+ NODE
66
+ end
67
+
68
+ def unsubscribe_xml
69
+ <<-NODE
70
+ <iq type='error'
71
+ from='pubsub.shakespeare.lit'
72
+ to='francisco@denmark.lit/barracks'
73
+ id='unsub1'>
74
+ <pubsub xmlns='http://jabber.org/protocol/pubsub'>
75
+ <unsubscribe node='princely_musings' jid='francisco@denmark.lit'/>
76
+ </pubsub>
77
+ <error type='modify'>
78
+ <bad-request xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
79
+ <subid-required xmlns='http://jabber.org/protocol/pubsub#errors'/>
80
+ </error>
81
+ </iq>
82
+ NODE
83
+ end
84
+
85
+ def subscription_xml
86
+ <<-NODE
87
+ <iq type='result'
88
+ from='pubsub.shakespeare.lit'
89
+ to='francisco@denmark.lit/barracks'
90
+ id='sub1'>
91
+ <pubsub xmlns='http://jabber.org/protocol/pubsub'>
92
+ <subscription
93
+ node='princely_musings'
94
+ jid='francisco@denmark.lit'
95
+ subid='ba49252aaa4f5d320c24d3766f0bdcade78c78d3'
96
+ subscription='subscribed'/>
97
+ </pubsub>
98
+ </iq>
99
+ NODE
100
+ end
101
+
102
+ def subscribe_xml
103
+ <<-NODE
104
+ <iq type='set'
105
+ from='francisco@denmark.lit/barracks'
106
+ to='pubsub.shakespeare.lit'
107
+ id='sub1'>
108
+ <pubsub xmlns='http://jabber.org/protocol/pubsub'>
109
+ <subscribe
110
+ node='princely_musings'
111
+ jid='francisco@denmark.lit'/>
112
+ </pubsub>
113
+ </iq>
114
+ NODE
115
+ end
116
+
117
+ def publish_xml
118
+ <<-NODE
119
+ <iq type='result'
120
+ from='pubsub.shakespeare.lit'
121
+ to='hamlet@denmark.lit/blogbot'
122
+ id='publish1'>
123
+ <pubsub xmlns='http://jabber.org/protocol/pubsub'>
124
+ <publish node='princely_musings'>
125
+ <item id='ae890ac52d0df67ed7cfdf51b644e901'/>
126
+ </publish>
127
+ </pubsub>
128
+ </iq>
129
+ NODE
130
+ end
131
+
132
+ def created_xml
133
+ <<-NODE
134
+ <iq type='result'
135
+ from='pubsub.shakespeare.lit'
136
+ to='hamlet@denmark.lit/elsinore'
137
+ id='create2'>
138
+ <pubsub xmlns='http://jabber.org/protocol/pubsub'>
139
+ <create node='25e3d37dabbab9541f7523321421edc5bfeb2dae'/>
140
+ </pubsub>
141
+ </iq>
142
+ NODE
143
+ end
144
+
145
+ def published_xml
146
+ <<-NODE
147
+ <iq type='result'
148
+ from='pubsub.shakespeare.lit'
149
+ to='hamlet@denmark.lit/blogbot'
150
+ id='publish1'>
151
+ <pubsub xmlns='http://jabber.org/protocol/pubsub'>
152
+ <publish node='princely_musings'>
153
+ <item id='ae890ac52d0df67ed7cfdf51b644e901'/>
154
+ </publish>
155
+ </pubsub>
156
+ </iq>
157
+ NODE
158
+ end
159
+
160
+ def fabulous_xmpp_empty_success_xml
161
+ <<-NODE
162
+ <iq type='result'
163
+ from='pubsub.shakespeare.lit'
164
+ id='bob'/>
165
+ NODE
166
+ end
167
+
168
+ # OMF messages
169
+ def omf_created_xml
170
+ <<-NODE
171
+ <message from="pubsub.localhost" to="bravo@localhost" id="mclaren__bravo@localhost__FT6ea">
172
+ <event xmlns="http://jabber.org/protocol/pubsub#event">
173
+ <items node="mclaren">
174
+ <item id="4JMgcKzxFDLsP74">
175
+ <inform xmlns="http://schema.mytestbed.net/6.0/protocol" msg_id="a2b6aba9f11dc5bb88306a32d0720641f5020c1f">
176
+ <context_id>bf840fe9-c176-4fae-b7de-6fc27f183f76</context_id>
177
+ <inform_type>CREATED</inform_type>
178
+ <resource_id>444f17fb-546e-4685-a0d0-63e64fa046c8</resource_id>
179
+ <resource_address>444f17fb-546e-4685-a0d0-63e64fa046c8</resource_address>
180
+ </inform>
181
+ </item>
182
+ </items>
183
+ </event>
184
+ <headers xmlns="http://jabber.org/protocol/shim">
185
+ <header name="pubsub#subid">Mui0v6cdP9dj4Fo1wVj8KwD48WA606Q7oXWin5P1</header>
186
+ </headers>
187
+ </message>
188
+ NODE
189
+ end
190
+
191
+ def omf_status_xml
192
+ <<-NODE
193
+ <message from="pubsub.localhost" to="bravo@localhost" id="mclaren__bravo@localhost__FT6ea">
194
+ <event xmlns="http://jabber.org/protocol/pubsub#event">
195
+ <items node="mclaren">
196
+ <item id="4JMgcKzxFDLsP74">
197
+ <inform xmlns="http://schema.mytestbed.net/6.0/protocol" msg_id="a2b6aba9f11dc5bb88306a32d0720641f5020c1f">
198
+ <context_id>bf840fe9-c176-4fae-b7de-6fc27f183f76</context_id>
199
+ <inform_type>STATUS</inform_type>
200
+ <property key="bob">bob</property>
201
+ </inform>
202
+ </item>
203
+ </items>
204
+ </event>
205
+ <headers xmlns="http://jabber.org/protocol/shim">
206
+ <header name="pubsub#subid">Mui0v6cdP9dj4Fo1wVj8KwD48WA606Q7oXWin5P1</header>
207
+ </headers>
208
+ </message>
209
+ NODE
210
+ end
211
+
212
+ def omf_failed_xml
213
+ <<-NODE
214
+ <message from="pubsub.localhost" to="bravo@localhost" id="mclaren__bravo@localhost__FT6ea">
215
+ <event xmlns="http://jabber.org/protocol/pubsub#event">
216
+ <items node="mclaren">
217
+ <item id="4JMgcKzxFDLsP74">
218
+ <inform xmlns="http://schema.mytestbed.net/6.0/protocol" msg_id="a2b6aba9f11dc5bb88306a32d0720641f5020c1f">
219
+ <context_id>bf840fe9-c176-4fae-b7de-6fc27f183f76</context_id>
220
+ <inform_type>FAILED</inform_type>
221
+ <reason>No idea</reason>
222
+ </inform>
223
+ </item>
224
+ </items>
225
+ </event>
226
+ <headers xmlns="http://jabber.org/protocol/shim">
227
+ <header name="pubsub#subid">Mui0v6cdP9dj4Fo1wVj8KwD48WA606Q7oXWin5P1</header>
228
+ </headers>
229
+ </message>
230
+ NODE
231
+ end
232
+
233
+ def omf_released_xml
234
+ <<-NODE
235
+ <message from="pubsub.localhost" to="bravo@localhost" id="mclaren__bravo@localhost__FT6ea">
236
+ <event xmlns="http://jabber.org/protocol/pubsub#event">
237
+ <items node="mclaren">
238
+ <item id="4JMgcKzxFDLsP74">
239
+ <inform xmlns="http://schema.mytestbed.net/6.0/protocol" msg_id="a2b6aba9f11dc5bb88306a32d0720641f5020c1f">
240
+ <context_id>bf840fe9-c176-4fae-b7de-6fc27f183f76</context_id>
241
+ <inform_type>RELEASED</inform_type>
242
+ <resource_id>444f17fb-546e-4685-a0d0-63e64fa046c8</resource_id>
243
+ </inform>
244
+ </item>
245
+ </items>
246
+ </event>
247
+ <headers xmlns="http://jabber.org/protocol/shim">
248
+ <header name="pubsub#subid">Mui0v6cdP9dj4Fo1wVj8KwD48WA606Q7oXWin5P1</header>
249
+ </headers>
250
+ </message>
251
+ NODE
252
+ end