wise_omf 0.9 → 0.9.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2c646960c311267d13f375733a6e9eeb8445d892
4
- data.tar.gz: 987108e23efaa45458ad3cafd5f908e63f24b192
3
+ metadata.gz: 1c8e0758c700cc9980a2cd20165c0133a7538bbc
4
+ data.tar.gz: e6c00e7941afd772c5c7e6c9a147026e1b9f7951
5
5
  SHA512:
6
- metadata.gz: c877157e684d0d8603af76c98ff868f7eebefd34e033e39750c6005dd79dc5b15e3831bdea753728edfb6de4bb093b1ee0c9fd25f05c2da549384cd7b5021c8e
7
- data.tar.gz: 3efdae6ecfc627219897d5f9210706ff0f2fb8485c59dc2d59da8b0eae424bc25c07a4a474ebcce8b19ca599cb3ef75fd5bc8a3d6b978780df39612951acf4b1
6
+ metadata.gz: 5817c0124d767d1a89fc9e7c96377700e123e95207720f9f3910ed7291e7bfa0afd2e540a5f4eef292ad566f71418e490409ded3c20f28b4227d1c8ef08690da
7
+ data.tar.gz: 5b3a7c196405a0e32845f9da57836cf0016f8c024cbf7ee27b81ad6af25329d0fe85a996b2b6789c6018ee0a4342c343fa465aacd4c528ad06d8210048b2bd95
@@ -1,8 +1,11 @@
1
1
  require 'lrucache'
2
2
  require 'wise_omf/uid_helper'
3
3
  require 'yaml'
4
+ require 'omf_common'
4
5
  module WiseOMF
5
6
  module Client
7
+
8
+ # The ExperimentHelper offers helper methods for the experiment.
6
9
  class ExperimentHelper
7
10
  @@random = Random.new
8
11
  @@uid_cache = LRUCache.new(ttl: 30.minutes)
@@ -10,6 +13,9 @@ module WiseOMF
10
13
 
11
14
  # Create an unique message id
12
15
  # NOTE: Message ids are guaranteed to be unique within 30 minutes.
16
+ #
17
+ # @return [Integer] an integer which can be used as messageUID.
18
+ # This integer is guaranteed to be unique within 30 minutes.
13
19
  def self.messageUID
14
20
  uid = -1
15
21
  while true
@@ -36,6 +42,17 @@ module WiseOMF
36
42
  @group
37
43
  @default_callback
38
44
 
45
+
46
+ # Creates a new WiseGroup which handles an OmfEc::Group for the given name And connects the resource with the given uid.
47
+ # Speaking in OMF, the resource represented by the given uid becomes a member of the newly created Group.
48
+ # The WiseGroup encapsulates the OMF group and handles the proper registration of callbacks for configure and request messages.
49
+ #
50
+ # However, you are free to use the OmfEc::Group directly, but it's highly recommended to use a WiseGroup as helper.
51
+ #
52
+ # @param name [String] the name for the OmfEc::Group.
53
+ # @param uid [String] the uid of the resource represented by this group.
54
+ #
55
+ # @see OmfEc::Group
39
56
  def initialize(name, uid)
40
57
  @callback_cache = LRUCache.new(ttl: 30.minutes)
41
58
  @name = name
@@ -44,26 +61,24 @@ module WiseOMF
44
61
  OmfEc.experiment.add_group(group)
45
62
  group.add_resource(uid)
46
63
  @group = group
47
-
48
- #@group = OmfEc::Group.new(uid, {unique: false}) { |g|
49
- # info "Created Group #{name}: #{g.to_yaml}"
50
- #
51
- # #yield self unless block.nil?
52
- #
53
- #}
54
- #OmfEc.experiment.add_group(@group)
55
- #@group.add_resource(name)
56
- warn "Finished init"
64
+ info "Finished intialization of WiseGroup (#{name})"
57
65
  end
58
66
 
59
- def init_callback
60
-
61
- while @group.topic.nil?
62
- info "Delaying callback creation for 0.5 seconds"
63
- sleep 0.5
67
+ # This method initializes the callback handler on the group topic.
68
+ # The topic might be nil direct after the intialization.
69
+ #
70
+ # @param block a block that should be called after initializing the topic callback
71
+ def init_callback(&block)
72
+ if @group.topic.nil?
73
+ info "Delaying callback creation for 1 seconds"
74
+ OmfCommon.el.after(1) {
75
+ info "Firing"
76
+ init_callback(&block)
77
+ }
78
+ return
64
79
  end
65
- info "Setting message callback for #{self.name}"
66
- @group.topic.on_message(:inform_status) { |msg|
80
+ info "Setting message callback for WiseGroup (#{self.name})"
81
+ @group.topic.on_message(:wise_group_callback_handler) { |msg|
67
82
  rid = msg.content.properties.requestId
68
83
  if rid.nil? && @@default_message_types.include?(msg.content.type)
69
84
  self.default_callback.call(msg) unless self.default_callback.nil?
@@ -78,9 +93,15 @@ module WiseOMF
78
93
  end
79
94
  end
80
95
  }
96
+ info "Callback: #{block}"
97
+ block.call(self) if block
81
98
 
82
99
  end
83
100
 
101
+ # Send a request message for the given property and callback
102
+ #
103
+ # @param property [String] the property to request
104
+ # @param &block the callback to be called for responses to this request
84
105
  def request(property, &block)
85
106
  mid = WiseOMF::Client::ExperimentHelper.messageUID
86
107
  unless block.nil?
@@ -90,6 +111,10 @@ module WiseOMF
90
111
  @group.topic.configure({property => mid})
91
112
  end
92
113
 
114
+ # Send a configure message for the given property and callback
115
+ #
116
+ # @param property [String] the property to configure
117
+ # @param &block the callback to be called for responses to this configuration attempt
93
118
  def configure(property, value, &block)
94
119
  mid = WiseOMF::Client::ExperimentHelper.messageUID
95
120
  unless block.nil?
@@ -98,6 +123,11 @@ module WiseOMF
98
123
  @group.topic.configure({property => {requestId: mid, value: value}})
99
124
  end
100
125
 
126
+ # This method translates calls to configure_xxx and request_xxx into proper FRCP messages (like in the OMF)
127
+ #
128
+ # @param name [String] the name of the method
129
+ # @param *args [Array] an array of arguments (empty for request_xxx, containing one argument for configure_xxx)
130
+ # @param &block a block which should be set as callback for the request/ configure message
101
131
  def method_missing(name, *args, &block)
102
132
  if name =~ /set_(.+)/
103
133
  configure($1, args[0], &block)
@@ -106,14 +136,23 @@ module WiseOMF
106
136
  end
107
137
  end
108
138
 
139
+ # Method for deleting a callback from the callback cache.
140
+ # After deleting the callback, it will not be called for messages arriving with the given requestId
141
+ #
142
+ # @param requestId [Integer] the requestId to delete the callback for
109
143
  def delete_callback(requestId)
110
144
  @callback_cache.delete(requestId)
111
145
  end
112
146
 
147
+ # Terminates this group (unsubscribes topic...)
148
+ def done
149
+ self.group.topic.unsubscribe(:wise_group_callback_handler)
150
+ end
151
+
113
152
  end
114
153
 
115
154
  # The reservation manager handles the creation and storage of node groups and stores all relevant information
116
- # for the current experiment.
155
+ # for the current experiment. The manager is designed as factory, so that it only exists once in the experiment.
117
156
  # If you need to talk to a single node, call the ResverationManager.groupForNode(nodeUrn) method.
118
157
  # If you want a custom subset of nodes, call the ReservationManager.groupForNodes(nodeUrnArray) method.
119
158
  # For talking to all nodes, you can get the approprita group bei calling ReservationManager.allNodesGroup.
@@ -123,9 +162,19 @@ module WiseOMF
123
162
  @@nodeGroups
124
163
  @@reservationGroup
125
164
 
126
- # Initializes the reservation manager class and creates all needed wise groups
165
+ # Initializes the reservation manager class and creates the following WiseGroups:
166
+ # - The allNodesGroup (containing all nodes of this reservation)
167
+ # - One node group for each single node
168
+ # - One group for the reservation itself
127
169
  #
128
- # TODO explain parameters here
170
+ # @param reservation [Hash] a hash explaining by the following YAML example:
171
+ # ---
172
+ # :secretReservationKeys:
173
+ # - :nodeUrnPrefix: "urn:wisebed:uzl1:"
174
+ # :key: "7601BE4781736B57BC6185D1AAF33A9F"
175
+ # - :nodeUrnPrefix: "..."
176
+ # :key: "..."
177
+ # @param nodeUrns [Set, Array] a set of node urns beeing part of this reservation.
129
178
  def self.init(reservation, nodeUrns)
130
179
  @@nodeGroups = {}
131
180
  @@reservation = reservation
@@ -155,30 +204,37 @@ module WiseOMF
155
204
  group = WiseOMF::Client::WiseGroup.new(name, groupId)
156
205
  end
157
206
  @@nodeGroups[groupId] = group
158
- group.init_callback
159
- group.group.topic.on_message(:wait_for_membership) { |msg|
160
- if msg.properties.membership && msg.properties.membership.include?(group.group.address)
161
- info "New group setup finished"
162
- group.group.topic.on_message(:wait_for_membership) {}
163
- #group.init_callback
164
- block.call(group) if block
165
- end
207
+ info 'Creating new group'
208
+ group.init_callback {
209
+ info 'Topic initialized'
210
+ group.group.topic.on_message(:wait_for_membership) { |msg|
211
+ info "Wait for Membership: #{msg.to_yaml}"
212
+ if msg.properties.membership && msg.properties.membership.include?(group.group.address)
213
+ info 'New group setup finished'
214
+ group.group.topic.unsubscribe(:wait_for_membership)
215
+ block.call(group) if block
216
+ end
166
217
 
218
+ }
219
+ @@reservationGroup.group.topic.create(:wisebed_node, {uid: groupId, urns: nodeUrns, membership: group.group.address})
167
220
  }
168
- @@reservationGroup.group.topic.create(:wisebed_node, {uid: groupId, urns: nodeUrns, membership: group.group.address})
221
+
169
222
 
170
223
  end
171
224
  end
172
225
 
173
226
  # Returns a group to use when interacting with an arbitrary subset of the all nodes set
174
227
  #
175
- # @param[Array, Set, #read] a list of nodes to get the group for.
228
+ # @param nodeUrns [Array, Set, #read] a list of nodes to get the group for.
229
+ # @return [WiseOMF::Client::WiseGroup] the WiseGroup for the node urns if one was found, nil otherwise
176
230
  def self.groupForNodes(nodeUrns)
177
231
  groupId = WiseOMFUtils::UIDHelper.node_group_uid(@@reservation, nodeUrns)
178
232
  @@nodeGroups[groupId]
179
233
  end
180
234
 
181
235
  # Returns a group to work with when interacting with all nodes of the reservation
236
+ #
237
+ # @return [WiseOMF::Client::WiseGroup] the group containing the resource representing all nodes in the reservation
182
238
  def self.allNodesGroup
183
239
  groupId = WiseOMFUtils::UIDHelper.node_group_uid(@@reservation, @@nodeUrns)
184
240
  if @@nodeGroups[groupId].nil?
@@ -191,6 +247,7 @@ module WiseOMF
191
247
  # Returns a WiseGroup to talk to. This group should be used for interacting with single nodes.
192
248
  #
193
249
  # @param[String, #read] the node urn
250
+ # @return[WiseOMF::Client::WiseGroup] the group for a single resource
194
251
  def self.groupForNode(nodeUrn)
195
252
  groupId = WiseOMFUtils::UIDHelper.node_group_uid(@@reservation, [nodeUrn])
196
253
  if @@nodeGroups[groupId].nil?
@@ -201,10 +258,19 @@ module WiseOMF
201
258
  end
202
259
 
203
260
  # Getter for the reservation id of the current reservation
261
+ # @return[String] the reservation id for this reservation
204
262
  def self.reservationID
205
263
  WiseOMFUtils::UIDHelper.reservation_uid(@@reservation)
206
264
  end
207
265
 
266
+ # Finalizes all node groups and the reservation group.
267
+ # Call this method at the end of your experiment just before calling OmfEc::Experiment.done
268
+ def self.done
269
+ info 'Cleaning Reservation Resources'
270
+ @@nodeGroups.each_value { |group| group.done }
271
+ @@reservationGroup.done
272
+ end
273
+
208
274
 
209
275
  end
210
276
  end
data/lib/wise_omf.rb CHANGED
@@ -1,4 +1,8 @@
1
1
  require 'wise_omf/client'
2
2
  require 'wise_omf/protobuf'
3
+
4
+ # The main file of the WiseOMF gem.
5
+ # This class just requires the Client Modul which should be used on client side
6
+ # @see WiseOMF::Client
3
7
  class WiseOmf
4
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wise_omf
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.9'
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Mende
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-19 00:00:00.000000000 Z
11
+ date: 2013-11-20 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: This gem provides helpers for working with the testbed runtime via the
14
14
  OMF (Orbit Measurement Framework)
@@ -46,3 +46,4 @@ signing_key:
46
46
  specification_version: 4
47
47
  summary: WiseOMF Utility Gem
48
48
  test_files: []
49
+ has_rdoc: