Module: BlackStack::Workmesh
- Defined in:
- lib/workmesh.rb
Defined Under Namespace
Classes: Node, Protocol, Service
Constant Summary collapse
- @@roundrobin =
hash with the round-robin positions per service.
{}
- @@nodes =
infrastructure configuration
[]
- @@services =
[]
- @@log_filename =
logger configuration
nil
- @@logger =
BlackStack::DummyLogger.new(nil)
- @@connection_string =
Connection string to the database. Example: mysql2://user:password@localhost:3306/database
nil
Class Method Summary collapse
-
.add_node(h) ⇒ Object
add_node add a node to the infrastructure.
-
.add_service(h) ⇒ Object
add_service add a service to the infrastructure.
-
.assign(o, service_name, h = {}) ⇒ Object
assign object to a node.
-
.assigned_node(o, service_name) ⇒ Object
return the assigned node to an object, for a specific service.
-
.connection_string ⇒ Object
return connection string to the database.
-
.log_filename ⇒ Object
return the log filename.
-
.logger ⇒ Object
return the logger.
- .node(name) ⇒ Object
- .nodes ⇒ Object
-
.roundrobin(o, service_name) ⇒ Object
assign object to a node using a round-robin algorithm this method is used when the service assignation is :roundrobin this method is for internal use only, and it should not be called directly.
- .service(name) ⇒ Object
- .services ⇒ Object
-
.set_connection_string(s) ⇒ Object
define the connectionstring to the database.
-
.set_log_filename(s) ⇒ Object
define a filename for the log file.
- .set_logger(l) ⇒ Object
Class Method Details
.add_node(h) ⇒ Object
add_node add a node to the infrastructure
300 301 302 303 304 |
# File 'lib/workmesh.rb', line 300 def self.add_node(h) @@nodes << BlackStack::Workmesh::Node.new(h) # add to deployer BlackStack::Deployer.add_node(h) #if @@integrate_with_blackstack_deployer end |
.add_service(h) ⇒ Object
add_service add a service to the infrastructure
316 317 318 |
# File 'lib/workmesh.rb', line 316 def self.add_service(h) @@services << BlackStack::Workmesh::Service.new(h) end |
.assign(o, service_name, h = {}) ⇒ Object
assign object to a node
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 |
# File 'lib/workmesh.rb', line 368 def self.assign(o, service_name, h = {}) # getting the service s = @@services.select { |s| s.name.to_s == service_name.to_s }.first # validate: the service exists raise "The service #{service_name} does not exists" if s.nil? # validate: the object o is an instance of the Sequel Class mapping the table :entity_table raise "The object o is not an instance of :entity_table (#{s.entity_table.to_s})" unless o.is_a?(Sequel::Model) && o.class.table_name.to_s == s.entity_table.to_s # reassign if h[:reassign] == true o[s.entity_field_assignation] = nil o.save end # validate: the object o has not been assigned yet raise "The object o has been already assigned to a node. Use the :reassign parameter for reassignation." unless o[s.entity_field_assignation].nil? # decide the assignation method if s.assignation == :entityweight raise 'The assignation method :entityweight is not implemented yet.' elsif s.assignation == :roundrobin return BlackStack::Workmesh.roundrobin(o, service_name) elsif s.assignation == :entitynumber raise 'The assignation method :entitynumber is not implemented yet.' else raise "The assignation method #{s.assignation} is unknown." end end |
.assigned_node(o, service_name) ⇒ Object
return the assigned node to an object, for a specific service. if the object has not a node assigned, then return nil.
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 |
# File 'lib/workmesh.rb', line 350 def self.assigned_node(o, service_name) # getting the service s = @@services.select { |s| s.name.to_s == service_name.to_s }.first # validate: the service exists raise "The service #{service_name} does not exists" if s.nil? # validate: the object o is an instance of the Sequel Class mapping the table :entity_table raise "The object o is not an instance of :entity_table (#{s.entity_table.to_s})" unless o.is_a?(Sequel::Model) && o.class.table_name.to_s == s.entity_table.to_s # if the object has not a node assigned, then return nil. return nil if o[s.entity_field_assignation].nil? # find the node ret = @@nodes.select { |n| n.name.to_s == o[s.entity_field_assignation].to_s }.first # validate: the node exists raise "The node #{o[s.entity_field_assignation]} does not exists in configuration file" if ret.nil? # return ret end |
.connection_string ⇒ Object
return connection string to the database. Example: mysql2://user:password@localhost:3306/database
294 295 296 |
# File 'lib/workmesh.rb', line 294 def self.connection_string() @@connection_string end |
.log_filename ⇒ Object
return the log filename.
284 285 286 |
# File 'lib/workmesh.rb', line 284 def self.log_filename() @@log_filename end |
.logger ⇒ Object
return the logger.
275 276 277 |
# File 'lib/workmesh.rb', line 275 def self.logger() @@logger end |
.node(name) ⇒ Object
310 311 312 |
# File 'lib/workmesh.rb', line 310 def self.node(name) @@nodes.select { |n| n.name.to_s == name.to_s }.first end |
.nodes ⇒ Object
306 307 308 |
# File 'lib/workmesh.rb', line 306 def self.nodes @@nodes end |
.roundrobin(o, service_name) ⇒ Object
assign object to a node using a round-robin algorithm this method is used when the service assignation is :roundrobin this method is for internal use only, and it should not be called directly.
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 |
# File 'lib/workmesh.rb', line 331 def self.roundrobin(o, service_name) @@roundrobin[service_name] = 0 if @@roundrobin[service_name].nil? # getting the service s = @@services.select { |s| s.name.to_s == service_name.to_s }.first # getting all the nodes assigned to the service nodes = @@nodes.select { |n| n.workmesh_service.to_s == service_name.to_s }.sort_by { |n| n.name.to_s } # increase i @@roundrobin[service_name] += 1 @@roundrobin[service_name] = 0 if @@roundrobin[service_name] >= nodes.length # assign the object to the node n = nodes[@@roundrobin[service_name]] o[s.entity_field_assignation] = n.name o.save # return n end |
.service(name) ⇒ Object
324 325 326 |
# File 'lib/workmesh.rb', line 324 def self.service(name) @@services.select { |s| s.name.to_s == name.to_s }.first end |
.services ⇒ Object
320 321 322 |
# File 'lib/workmesh.rb', line 320 def self.services @@services end |
.set_connection_string(s) ⇒ Object
define the connectionstring to the database.
289 290 291 |
# File 'lib/workmesh.rb', line 289 def self.set_connection_string(s) @@connection_string = s end |
.set_log_filename(s) ⇒ Object
define a filename for the log file.
269 270 271 272 |
# File 'lib/workmesh.rb', line 269 def self.set_log_filename(s) @@log_filename = s @@logger = BlackStack::LocalLogger.new(s) end |
.set_logger(l) ⇒ Object
279 280 281 |
# File 'lib/workmesh.rb', line 279 def self.set_logger(l) @@logger = l end |