scbi_mapreduce 0.0.35 → 0.0.36

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,6 +1,10 @@
1
+ === 0.0.36 2011-10-14
2
+
3
+ Automatically search for a valid network if a preffered one is not provided
4
+
1
5
  === 0.0.35 2011-07-07
2
6
 
3
- ip list
7
+ Change method to retrieve a list of available ips
4
8
 
5
9
  === 0.0.34 2011-07-07
6
10
 
@@ -3,8 +3,11 @@ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname
3
3
 
4
4
  # $: << File.join(File.dirname(__FILE__),File.basename(__FILE__,File.extname(__FILE__)))
5
5
 
6
+ $: << File.expand_path('scbi_mapreduce')
7
+ # puts $:
8
+
6
9
  module ScbiMapreduce
7
- VERSION = '0.0.35'
10
+ VERSION = '0.0.36'
8
11
  end
9
12
 
10
13
  require 'scbi_mapreduce/manager'
@@ -12,10 +12,10 @@
12
12
  absolute_path="$(cd "${0%/*}" 2>/dev/null; echo "$PWD"/"${0##*/}")"
13
13
 
14
14
  # absolute_path=canonpath $0;
15
- echo ABS: $absolute_path
16
- echo HOST:
15
+ echo Absolute path: $absolute_path
16
+ echo Launching at HOST:
17
17
  hostname
18
- echo YO:
18
+ echo With user:
19
19
  whoami
20
20
 
21
21
  main_worker_path=`dirname $absolute_path`
@@ -1,6 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  # $: << '/Users/dariogf/progs/ruby/gems/scbi_mapreduce/lib'
4
+ $: << File.expand_path(File.join(__FILE__,'..','..'))
5
+ # puts $:
4
6
 
5
7
  require 'scbi_mapreduce'
6
8
 
@@ -45,6 +45,7 @@ module ScbiMapreduce
45
45
  if !ip
46
46
  $SERVER_LOG.info("Ip #{server_ip} not found in available IPs: #{ip_list}")
47
47
  ip='0.0.0.0'
48
+ # gets
48
49
  end
49
50
 
50
51
  @ip = ip
@@ -62,7 +63,14 @@ module ScbiMapreduce
62
63
  @worker_names=[]
63
64
  if workers.is_a?(Integer)
64
65
  @workers=workers
65
- else
66
+ else # workers is a file with names, or an array
67
+
68
+ # read file
69
+ if workers.is_a?(String) && File.exists?(workers)
70
+ $SERVER_LOG.info("Loading workers file: #{workers}")
71
+ workers = File.read(workers).split("\n").map{|w| w.chomp}
72
+ end
73
+
66
74
  # puts "find worker_names"
67
75
  host_name=`hostname`.chomp
68
76
  @workers=workers.count(host_name)
@@ -73,7 +81,8 @@ module ScbiMapreduce
73
81
  end
74
82
 
75
83
  @work_manager_class = work_manager_class
76
- @worker_launcher = WorkerLauncher.new(@ip,port,@workers,custom_worker_file,log_file,init_env_file)
84
+
85
+ @worker_launcher = WorkerLauncher.new(@ip,port,ip_list,@workers,custom_worker_file,log_file,init_env_file)
77
86
 
78
87
 
79
88
  $SERVER_LOG.info("Local workers: #{@workers}")
@@ -2,20 +2,23 @@
2
2
 
3
3
  module ScbiMapreduce
4
4
 
5
+ require 'resolv'
6
+
5
7
  INTERPRETER='ruby'
6
8
 
7
9
  class WorkerLauncher
8
10
 
9
11
  attr_accessor :server_ip, :server_port
10
12
 
11
- def initialize(server_ip,server_port,workers, worker_file, log_file=nil, init_env_file=nil)
13
+ def initialize(server_ip,server_port, server_ip_list,workers, worker_file, log_file=nil, init_env_file=nil)
12
14
  @server_ip = server_ip
13
15
  @server_port = server_port
14
16
  @worker_file = worker_file
15
17
  @workers=workers
16
18
  @init_env_file=init_env_file
19
+ @server_ip_list=server_ip_list
20
+
17
21
 
18
-
19
22
  if log_file.nil?
20
23
  log_file = 'logs/launcher_log.txt'
21
24
  end
@@ -60,6 +63,50 @@ module ScbiMapreduce
60
63
  exec(cmd)
61
64
  end
62
65
 
66
+ def find_common_ip(machine_ip,ip_list)
67
+
68
+ def left_largest_common_substr(s1,s2)
69
+ res=''
70
+
71
+ s2.scan(/./).each_with_index do |l1,i|
72
+ if s1[i]==l1
73
+ res << l1
74
+ else
75
+ break
76
+ end
77
+ end
78
+ res
79
+
80
+ end
81
+
82
+ def remove_final_dot(s)
83
+ res=s
84
+ # remove final dot
85
+ if res[res.length-1]=='.'
86
+ res=res[0,res.length-1]
87
+ end
88
+
89
+ return res
90
+ end
91
+
92
+
93
+ res=''
94
+ common_ip=''
95
+
96
+ ip_list.each do |ip|
97
+
98
+ res=left_largest_common_substr(ip,machine_ip)
99
+ res=remove_final_dot(res)
100
+
101
+ if res.length>common_ip.length
102
+ common_ip=res
103
+ end
104
+ end
105
+
106
+ return common_ip
107
+ end
108
+
109
+
63
110
  def launch_external_workers(workers)
64
111
  puts "Launching #{workers.count} external workers: #{workers}"
65
112
  worker_id=0
@@ -86,16 +133,31 @@ module ScbiMapreduce
86
133
 
87
134
  workers.each do |machine|
88
135
 
89
- # cmd = "ssh #{machine} \"#{init} #{cd} #{INTERPRETER} #{File.join(File.dirname(__FILE__),'main_worker.rb')} #{worker_id.to_s} #{@server_ip} #{@server_port} #{@worker_file}\""
90
- cmd = "ssh #{machine} \"nohup #{File.join(File.dirname(__FILE__),'launcher.sh')} #{worker_id.to_s} #{@server_ip} #{@server_port} #{@worker_file} #{init_dir} #{init_path} </dev/null >> #{log_file} 2>> #{log_file} & \""
91
-
92
- $LAUNCHER_LOG.info cmd
136
+ # if server_ip is not in valid ips
137
+ if !@server_ip_list.include?(@server_ip)
138
+ # find matching ip between server and worker
139
+ machine_ip = Resolv.getaddress(machine)
140
+ matching_ip=find_common_ip(machine_ip,@server_ip_list)
141
+ found_ip=@server_ip_list.select{|one_ip| one_ip.index(matching_ip)==0}.first
142
+ else
143
+ found_ip=@server_ip
144
+ end
145
+
146
+ if !found_ip.nil?
147
+ # cmd = "ssh #{machine} \"#{init} #{cd} #{INTERPRETER} #{File.join(File.dirname(__FILE__),'main_worker.rb')} #{worker_id.to_s} #{@server_ip} #{@server_port} #{@worker_file}\""
148
+ # cmd = "ssh #{machine} \"nohup #{File.join(File.dirname(__FILE__),'launcher.sh')} #{worker_id.to_s} #{@server_ip} #{@server_port} #{@worker_file} #{init_dir} #{init_path} </dev/null >> #{log_file} 2>> #{log_file} & \""
149
+ cmd = "ssh #{machine} \"nohup #{File.join(File.dirname(__FILE__),'launcher.sh')} #{worker_id.to_s} #{found_ip} #{@server_port} #{@worker_file} #{init_dir} #{init_path} </dev/null >> #{log_file} 2>> #{log_file} & \""
93
150
 
94
- pid=fork{
95
- exec(cmd)
96
- }
151
+ $LAUNCHER_LOG.info cmd
97
152
 
98
- worker_id+=1
153
+ pid=fork{
154
+ exec(cmd)
155
+ }
156
+
157
+ worker_id+=1
158
+ else
159
+ $LAUNCHER_LOG.error("Couldn't find a matching ip between worker (#{machine_ip}) and server #{ip_list.to_json}")
160
+ end
99
161
  end
100
162
  end
101
163
 
@@ -4,7 +4,7 @@ $: << File.dirname(__FILE__)
4
4
 
5
5
  require "logger"
6
6
 
7
- # $: << '/Users/dariogf/progs/ruby/gems/scbi_mapreduce/lib'
7
+ $: << File.expand_path('../../lib')
8
8
 
9
9
  require 'scbi_mapreduce'
10
10
  require 'my_worker_manager'
@@ -17,6 +17,8 @@ ip='0.0.0.0'
17
17
  port = 50000
18
18
  workers = 8
19
19
 
20
+ workers = File.expand_path('workers')
21
+
20
22
  custom_worker_file = File.join(File.dirname(__FILE__),'my_worker.rb')
21
23
 
22
24
  $LOG.info 'Starting server'
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: scbi_mapreduce
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.35
5
+ version: 0.0.36
6
6
  platform: ruby
7
7
  authors:
8
8
  - Dario Guerrero
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-07-08 00:00:00 Z
13
+ date: 2011-10-14 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: eventmachine