Class: LS4::MembershipService

Inherits:
Service show all
Defined in:
lib/ls4/service/membership.rb

Instance Method Summary collapse

Methods inherited from Service

init

Methods included from EventBus::SingletonMixin

#ebus_bind!, #ebus_connect, extended

Methods included from EventBus::BusMixin

#ebus_all_slots, #ebus_disconnect!

Methods included from EventBus::DeclarerBase::Methods

#connect, #ebus_all_slots, #ebus_call_log, #ebus_call_slots, #ebus_signal_error, #ebus_signal_log, #ebus_signal_slots

Methods included from EventBus::DeclarerBase

#call_slot, #signal_slot

Constructor Details

#initializeMembershipService

Returns a new instance of MembershipService.



35
36
37
38
# File 'lib/ls4/service/membership.rb', line 35

def initialize
	@membership = Membership.new
	@fault_list = FaultList.new
end

Instance Method Details

#get_active_rsidsObject



62
63
64
# File 'lib/ls4/service/membership.rb', line 62

def get_active_rsids
	@membership.get_active_rsids
end

#get_all_nodesObject



58
59
60
# File 'lib/ls4/service/membership.rb', line 58

def get_all_nodes
	@membership.get_all_nodes
end

#get_node(nid) ⇒ Object



54
55
56
# File 'lib/ls4/service/membership.rb', line 54

def get_node(nid)
	@membership.get_node(nid)
end

#get_session_nid(nid) ⇒ Object



70
71
72
# File 'lib/ls4/service/membership.rb', line 70

def get_session_nid(nid)
	ProcessBus.get_session(get_node(nid).address)
end

#is_fault(nid) ⇒ Object



66
67
68
# File 'lib/ls4/service/membership.rb', line 66

def is_fault(nid)
	@fault_list.include?(nid)
end

#on_fault_list_changeObject



87
88
89
# File 'lib/ls4/service/membership.rb', line 87

def on_fault_list_change
	# TODO update balance bus?
end

#on_membership_changeObject



82
83
84
85
# File 'lib/ls4/service/membership.rb', line 82

def on_membership_change
	BalanceBus.update_weight
	MasterSelectBus.update_nodes
end

#runObject



40
41
42
43
44
45
46
47
# File 'lib/ls4/service/membership.rb', line 40

def run
	@fault_path = ConfigBus.get_fault_path
	@membership_path = ConfigBus.get_membership_path
	@fault_list.open(@fault_path) if @fault_path
	@membership.open(@membership_path) if @membership_path
	on_membership_change
	on_fault_list_change
end

#shutdownObject



49
50
51
52
# File 'lib/ls4/service/membership.rb', line 49

def shutdown
	@fault_list.close if @fault_path
	@membership.close if @membership_path
end

#stat_fault_infoObject



78
79
80
# File 'lib/ls4/service/membership.rb', line 78

def stat_fault_info
	@fault_list
end

#stat_membership_infoObject



74
75
76
# File 'lib/ls4/service/membership.rb', line 74

def stat_membership_info
	@membership
end

#stat_replset_infoObject



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/ls4/service/membership.rb', line 91

def stat_replset_info
	rsid_nids = {}
	MembershipBus.get_all_nodes.each {|node|
		node.rsids.each {|rsid|
			(rsid_nids[rsid] ||= []) << node.nid
		}
	}

	rsids = WeightBus.get_registered_rsids + MembershipBus.get_active_rsids
	rsids.uniq!

	result = {}
	rsids.each {|rsid|
		weight = WeightBus.get_weight(rsid)
		nids = rsid_nids[rsid] || []
		result[rsid] = [nids, weight]
	}

	result
end