wise_omf 0.9
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 +7 -0
- data/lib/wise_omf/client.rb +211 -0
- data/lib/wise_omf/protobuf.rb +3 -0
- data/lib/wise_omf/server.rb +4 -0
- data/lib/wise_omf.rb +4 -0
- metadata +48 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2c646960c311267d13f375733a6e9eeb8445d892
|
4
|
+
data.tar.gz: 987108e23efaa45458ad3cafd5f908e63f24b192
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c877157e684d0d8603af76c98ff868f7eebefd34e033e39750c6005dd79dc5b15e3831bdea753728edfb6de4bb093b1ee0c9fd25f05c2da549384cd7b5021c8e
|
7
|
+
data.tar.gz: 3efdae6ecfc627219897d5f9210706ff0f2fb8485c59dc2d59da8b0eae424bc25c07a4a474ebcce8b19ca599cb3ef75fd5bc8a3d6b978780df39612951acf4b1
|
@@ -0,0 +1,211 @@
|
|
1
|
+
require 'lrucache'
|
2
|
+
require 'wise_omf/uid_helper'
|
3
|
+
require 'yaml'
|
4
|
+
module WiseOMF
|
5
|
+
module Client
|
6
|
+
class ExperimentHelper
|
7
|
+
@@random = Random.new
|
8
|
+
@@uid_cache = LRUCache.new(ttl: 30.minutes)
|
9
|
+
|
10
|
+
|
11
|
+
# Create an unique message id
|
12
|
+
# NOTE: Message ids are guaranteed to be unique within 30 minutes.
|
13
|
+
def self.messageUID
|
14
|
+
uid = -1
|
15
|
+
while true
|
16
|
+
uid = @@random.rand(2**32)
|
17
|
+
break if @@uid_cache.fetch(uid).nil?
|
18
|
+
end
|
19
|
+
@@uid_cache.store(uid, 1)
|
20
|
+
return uid
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
# The WiseGroup is the representation of an omf resource group
|
26
|
+
# which provides the ability to register callback for requests and configure messages.
|
27
|
+
# You should not create an instance of this group directly. This can cause unwanted side effects.
|
28
|
+
# The better way is to ask the ReservationManager (factory) for a group for a list of node urns.
|
29
|
+
class WiseGroup
|
30
|
+
# Message types to call callbacks for
|
31
|
+
@@default_message_types = [:response, :inform]
|
32
|
+
attr_accessor :name, :uid, :group, :default_callback
|
33
|
+
@callback_cache
|
34
|
+
@name
|
35
|
+
@uid
|
36
|
+
@group
|
37
|
+
@default_callback
|
38
|
+
|
39
|
+
def initialize(name, uid)
|
40
|
+
@callback_cache = LRUCache.new(ttl: 30.minutes)
|
41
|
+
@name = name
|
42
|
+
@uid = uid
|
43
|
+
group = OmfEc::Group.new(name)
|
44
|
+
OmfEc.experiment.add_group(group)
|
45
|
+
group.add_resource(uid)
|
46
|
+
@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"
|
57
|
+
end
|
58
|
+
|
59
|
+
def init_callback
|
60
|
+
|
61
|
+
while @group.topic.nil?
|
62
|
+
info "Delaying callback creation for 0.5 seconds"
|
63
|
+
sleep 0.5
|
64
|
+
end
|
65
|
+
info "Setting message callback for #{self.name}"
|
66
|
+
@group.topic.on_message(:inform_status) { |msg|
|
67
|
+
rid = msg.content.properties.requestId
|
68
|
+
if rid.nil? && @@default_message_types.include?(msg.content.type)
|
69
|
+
self.default_callback.call(msg) unless self.default_callback.nil?
|
70
|
+
else
|
71
|
+
callback = @callback_cache.fetch(rid)
|
72
|
+
unless callback.nil?
|
73
|
+
callback.call(msg.content.properties)
|
74
|
+
else
|
75
|
+
if @@default_message_types.include? msg.content.type
|
76
|
+
self.default_callback.call(msg) unless self.default_callback.nil?
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
}
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
def request(property, &block)
|
85
|
+
mid = WiseOMF::Client::ExperimentHelper.messageUID
|
86
|
+
unless block.nil?
|
87
|
+
@callback_cache.store(mid, block)
|
88
|
+
end
|
89
|
+
fail "Can't request topic here" if property.to_sym.eql? 'topic'.to_sym
|
90
|
+
@group.topic.configure({property => mid})
|
91
|
+
end
|
92
|
+
|
93
|
+
def configure(property, value, &block)
|
94
|
+
mid = WiseOMF::Client::ExperimentHelper.messageUID
|
95
|
+
unless block.nil?
|
96
|
+
@callback_cache.store(mid, block)
|
97
|
+
end
|
98
|
+
@group.topic.configure({property => {requestId: mid, value: value}})
|
99
|
+
end
|
100
|
+
|
101
|
+
def method_missing(name, *args, &block)
|
102
|
+
if name =~ /set_(.+)/
|
103
|
+
configure($1, args[0], &block)
|
104
|
+
else
|
105
|
+
request(name, &block)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def delete_callback(requestId)
|
110
|
+
@callback_cache.delete(requestId)
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
# The reservation manager handles the creation and storage of node groups and stores all relevant information
|
116
|
+
# for the current experiment.
|
117
|
+
# If you need to talk to a single node, call the ResverationManager.groupForNode(nodeUrn) method.
|
118
|
+
# If you want a custom subset of nodes, call the ReservationManager.groupForNodes(nodeUrnArray) method.
|
119
|
+
# For talking to all nodes, you can get the approprita group bei calling ReservationManager.allNodesGroup.
|
120
|
+
class ReservationManager
|
121
|
+
@@reservation
|
122
|
+
@@nodeUrns
|
123
|
+
@@nodeGroups
|
124
|
+
@@reservationGroup
|
125
|
+
|
126
|
+
# Initializes the reservation manager class and creates all needed wise groups
|
127
|
+
#
|
128
|
+
# TODO explain parameters here
|
129
|
+
def self.init(reservation, nodeUrns)
|
130
|
+
@@nodeGroups = {}
|
131
|
+
@@reservation = reservation
|
132
|
+
@@nodeUrns = nodeUrns
|
133
|
+
@@reservationGroup = WiseOMF::Client::WiseGroup.new('ReservationGroup', self.reservationID)
|
134
|
+
@@reservationGroup.init_callback
|
135
|
+
# Creating the all nodes group:
|
136
|
+
self.allNodesGroup
|
137
|
+
|
138
|
+
# Creating the single node groups:
|
139
|
+
@@nodeUrns.each { |node|
|
140
|
+
self.groupForNode(node)
|
141
|
+
}
|
142
|
+
|
143
|
+
end
|
144
|
+
|
145
|
+
def self.reservationGroup
|
146
|
+
@@reservationGroup
|
147
|
+
end
|
148
|
+
|
149
|
+
def self.createGroupForNodes(nodeUrns, name = nil, &block)
|
150
|
+
groupId = WiseOMFUtils::UIDHelper.node_group_uid(@@reservation, nodeUrns)
|
151
|
+
if @@nodeGroups[groupId].nil?
|
152
|
+
if name.nil?
|
153
|
+
group = WiseOMF::Client::WiseGroup.new(nodeUrns.to_s, groupId)
|
154
|
+
else
|
155
|
+
group = WiseOMF::Client::WiseGroup.new(name, groupId)
|
156
|
+
end
|
157
|
+
@@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
|
166
|
+
|
167
|
+
}
|
168
|
+
@@reservationGroup.group.topic.create(:wisebed_node, {uid: groupId, urns: nodeUrns, membership: group.group.address})
|
169
|
+
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
# Returns a group to use when interacting with an arbitrary subset of the all nodes set
|
174
|
+
#
|
175
|
+
# @param[Array, Set, #read] a list of nodes to get the group for.
|
176
|
+
def self.groupForNodes(nodeUrns)
|
177
|
+
groupId = WiseOMFUtils::UIDHelper.node_group_uid(@@reservation, nodeUrns)
|
178
|
+
@@nodeGroups[groupId]
|
179
|
+
end
|
180
|
+
|
181
|
+
# Returns a group to work with when interacting with all nodes of the reservation
|
182
|
+
def self.allNodesGroup
|
183
|
+
groupId = WiseOMFUtils::UIDHelper.node_group_uid(@@reservation, @@nodeUrns)
|
184
|
+
if @@nodeGroups[groupId].nil?
|
185
|
+
@@nodeGroups[groupId] = WiseOMF::Client::WiseGroup.new('AllNodes', groupId)
|
186
|
+
@@nodeGroups[groupId].init_callback
|
187
|
+
end
|
188
|
+
@@nodeGroups[groupId]
|
189
|
+
end
|
190
|
+
|
191
|
+
# Returns a WiseGroup to talk to. This group should be used for interacting with single nodes.
|
192
|
+
#
|
193
|
+
# @param[String, #read] the node urn
|
194
|
+
def self.groupForNode(nodeUrn)
|
195
|
+
groupId = WiseOMFUtils::UIDHelper.node_group_uid(@@reservation, [nodeUrn])
|
196
|
+
if @@nodeGroups[groupId].nil?
|
197
|
+
@@nodeGroups[groupId] = WiseOMF::Client::WiseGroup.new(nodeUrn, groupId)
|
198
|
+
@@nodeGroups[groupId].init_callback
|
199
|
+
end
|
200
|
+
@@nodeGroups[groupId]
|
201
|
+
end
|
202
|
+
|
203
|
+
# Getter for the reservation id of the current reservation
|
204
|
+
def self.reservationID
|
205
|
+
WiseOMFUtils::UIDHelper.reservation_uid(@@reservation)
|
206
|
+
end
|
207
|
+
|
208
|
+
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
data/lib/wise_omf.rb
ADDED
metadata
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wise_omf
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.9'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tobias Mende
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-11-19 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: This gem provides helpers for working with the testbed runtime via the
|
14
|
+
OMF (Orbit Measurement Framework)
|
15
|
+
email: me@tobsolution.de
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/wise_omf.rb
|
21
|
+
- lib/wise_omf/protobuf.rb
|
22
|
+
- lib/wise_omf/server.rb
|
23
|
+
- lib/wise_omf/client.rb
|
24
|
+
homepage: https://github.com/wisebed/wiseomf
|
25
|
+
licenses:
|
26
|
+
- MIT
|
27
|
+
metadata: {}
|
28
|
+
post_install_message:
|
29
|
+
rdoc_options: []
|
30
|
+
require_paths:
|
31
|
+
- lib
|
32
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - '>='
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
requirements: []
|
43
|
+
rubyforge_project:
|
44
|
+
rubygems_version: 2.0.6
|
45
|
+
signing_key:
|
46
|
+
specification_version: 4
|
47
|
+
summary: WiseOMF Utility Gem
|
48
|
+
test_files: []
|