Class: Node

Inherits:
Object
  • Object
show all
Defined in:
lib/node_layout.rb

Direct Known Subclasses

AdvancedNode, SimpleNode

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, cloud, roles = []) ⇒ Node

Returns a new instance of Node.



556
557
558
559
560
561
562
563
564
# File 'lib/node_layout.rb', line 556

def initialize id, cloud, roles=[]
  # For Xen/KVM id is the public ip address
  # For clouds, id is node-X since the ip is not known
  @id = id
  @cloud = cloud
  @roles = roles.map { |r| r.to_sym }

  expand_roles
end

Instance Attribute Details

#cloudObject

Returns the value of attribute cloud.



554
555
556
# File 'lib/node_layout.rb', line 554

def cloud
  @cloud
end

#idObject

Returns the value of attribute id.



554
555
556
# File 'lib/node_layout.rb', line 554

def id
  @id
end

#rolesObject

Returns the value of attribute roles.



554
555
556
# File 'lib/node_layout.rb', line 554

def roles
  @roles
end

Instance Method Details

#add_db_role(db_type, is_master) ⇒ Object



566
567
568
569
570
571
572
573
# File 'lib/node_layout.rb', line 566

def add_db_role db_type, is_master
  if is_master
    add_role :db_master
    add_role :zookeeper
  else
    add_role :db_slave
  end
end

#add_rabbitmq_role(is_master) ⇒ Object



575
576
577
578
579
580
581
# File 'lib/node_layout.rb', line 575

def add_rabbitmq_role is_master
  if is_master
    add_role :rabbitmq_master
  else
    add_role :rabbitmq_slave
  end
end

#add_role(role) ⇒ Object



583
584
585
586
# File 'lib/node_layout.rb', line 583

def add_role role
  @roles << role.to_sym
  expand_roles
end

#errorsObject



599
600
601
# File 'lib/node_layout.rb', line 599

def errors
  @roles.map { |r| "Invalid role: #{r}" if !VALID_ROLES.include?(r) }.compact
end

#expand_rolesObject



603
604
605
606
607
# File 'lib/node_layout.rb', line 603

def expand_roles
  error_msg = "Expand roles should never be called on a node type." + \
    " All nodes should be either a SimpleNode or AdvancedNode"
  raise RuntimeError error_msg
end

#valid?Boolean

Returns:

  • (Boolean)


595
596
597
# File 'lib/node_layout.rb', line 595

def valid?
  self.errors.empty?
end