[Why] 1) Each node will report it's infos (roles, ip, direct_ips, direct_macs) when running cluster job, so also add these 2 parameters into node state: "direct_ips", "direct_macs".
Cluster test scripts needs "direct_server_ips" as server client's ip to connect to server to do a test. When request state is "roles_ip", return clients two variables: server, direct_server_ips. Clients will export them.
2) Alter funtion "get_ip"'s name and it's return value to fit for changes.
Signed-off-by: Ren Wen 15991987063@163.com --- src/lib/sched.cr | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-)
diff --git a/src/lib/sched.cr b/src/lib/sched.cr index c32091f..91c0820 100644 --- a/src/lib/sched.cr +++ b/src/lib/sched.cr @@ -99,24 +99,31 @@ class Sched when "write_state" node_roles = env.params.query["node_roles"] node_ip = env.params.query["ip"] + direct_ips = env.params.query["direct_ips"] + direct_macs = env.params.query["direct_macs"] + update_cluster_state(cluster_id, job_id, "roles", node_roles) update_cluster_state(cluster_id, job_id, "ip", node_ip) + update_cluster_state(cluster_id, job_id, "direct_ips", direct_ips) + update_cluster_state(cluster_id, job_id, "direct_macs", direct_macs) when "roles_ip" role = "server" - server_ip = get_ip(cluster_id, role) - return "server=#{server_ip}" + role_state = get_role_state(cluster_id, role) + raise "Missing #{role} state in cluster state" unless role_state + return "server=#{role_state["ip"]}\n" \ + "direct_server_ips=#{role_state["direct_server_ips"]}" end
# show cluster state return @redis.hash_get("sched/cluster_state", cluster_id) end
- # get the ip of role from cluster_state - def get_ip(cluster_id, role) + # get the node state of role from cluster_state + private def get_role_state(cluster_id, role) cluster_state = get_cluster_state(cluster_id) - cluster_state.each_value do |config| - if %(#{config["roles"]}) == role - return config["ip"] + cluster_state.each_value do |role_state| + if %(#{role_state["roles"]}) == role + return role_state end end end