Skip to content

Commit 8f14b4e

Browse files
committed
create hosts before creating vc
1 parent 17bc276 commit 8f14b4e

File tree

4 files changed

+56
-25
lines changed

4 files changed

+56
-25
lines changed

conf/container.batch.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ lxc.cgroup.cpu.cfs_quota_us = %CONTAINER_CPU%
4545
lxc.cap.drop = sys_admin net_admin mac_admin mac_override sys_time sys_module
4646

4747
lxc.mount.entry = %FS_PREFIX%/global/users/%USERNAME%/data %ROOTFS%/root/nfs none bind,rw,create=dir 0 0
48-
#lxc.mount.entry = %FS_PREFIX%/global/users/%USERNAME%/hosts/%CLUSTERID%.hosts %ROOTFS%/etc/hosts none bind,ro,create=file 0 0
48+
#lxc.mount.entry = %FS_PREFIX%/global/users/%USERNAME%/hosts/batch-%TASKID%.hosts %ROOTFS%/etc/hosts none bind,ro,create=file 0 0
4949
lxc.mount.entry = %FS_PREFIX%/global/users/%USERNAME%/ssh %ROOTFS%/root/.ssh none bind,ro,create=dir 0 0
5050
lxc.mount.entry = %FS_PREFIX%/local/temp/%LXCNAME%/ %ROOTFS%/tmp none bind,rw,create=dir 0 0
5151

src/master/taskmgr.py

+25-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import threading
22
import time
33
import string
4-
import random, copy
4+
import random, copy, subprocess
55
import json
66
from functools import wraps
77

@@ -48,10 +48,30 @@ def __lt__(self, other):
4848
return self.priority < other.priority
4949

5050
def gen_ips_from_base(self,base_ip):
51+
if self.task_base_ip == None:
52+
return
5153
self.ips = []
5254
for i in range(task.max_size):
5355
self.ips.append(int_to_ip(base_ip + self.task_base_ip + i + 2))
5456

57+
def gen_hosts(self):
58+
username = self.taskinfo.username
59+
taskid = self.taskinfo.taskid
60+
logger.info("Generate hosts for user(%s) task(%s) base_ip(%s)"%(username,taskid,str(self.task_base_ip)))
61+
fspath = env.getenv('FS_PREFIX')
62+
if not os.path.isdir("%s/global/users/%s" % (fspath,username)):
63+
path = env.getenv('DOCKLET_LIB')
64+
subprocess.call([path+"/master/userinit.sh", username])
65+
logger.info("user %s directory not found, create it" % username)
66+
67+
hosts_file = open("%s/global/users/%s/%s.hosts" % (fspath,username,"batch-"+taskid),"w")
68+
hosts_file.write("127.0.0.1 localhost\n")
69+
i = 0
70+
for ip in self.ips:
71+
hosts_file.write(ip+" batch-"+str(i)+"\n")
72+
i += 1
73+
hosts_file.close()
74+
5575
def get_one_resources_need(self):
5676
return self.vnodeinfo.vnode.instance
5777

@@ -225,18 +245,20 @@ def task_processor(self, task, vnodes_workers):
225245

226246
self.acquire_task_net(task)
227247
task.gen_ips_from_base(self.base_ip)
248+
task.gen_hosts()
228249
#need to create hosts
229250
[success, gwip] = self.setup_tasknet(task,[w[1] for w in vnodes_workers])
230251
if not success:
252+
self.release_task_ips(task)
231253
return [False, gwip]
232-
233254
token = ''.join(random.sample(string.ascii_letters + string.digits, 8))
234255
placed_workers = []
235256

236257
# start vc
237258
for vid, worker in vnodes_workers:
238259
vnodeinfo = copy.copy(task.vnodeinfo)
239260
vnodeinfo.vnodeid = vid
261+
vnodeinfo.vnode.hostname = "batch-"+str(vid%task.max_size)
240262
vnode = task.subtask_list[vid]
241263
vnode['status'] = RUNNING
242264
vnode['try_count'] += 1
@@ -253,7 +275,7 @@ def task_processor(self, task, vnodes_workers):
253275
ipaddr = task.ips[vid%task.max_size]
254276
brname = "docklet-batch-%s-%s"%(username, taskid)
255277
networkinfo = Network(ipaddr=ipaddr, gateway=gwip, masterip=self.masterip, brname=brname)
256-
vnode.network = networkinfo
278+
vnodeinfo.vnode.network = networkinfo
257279

258280
try:
259281
self.logger.info('[task_processor] starting vnode for task [%s] instance [%d]' % (task.vnodeinfo.id, vid))

src/protos/rpc_pb2.py

+25-18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/worker/taskworker.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,10 @@ def start_vnode(self, request, context):
178178
gateway = request.vnode.network.gateway
179179
brname = request.vnode.network.brname
180180
masterip = request.vnode.network.masterip
181+
hostname = request.vnode.hostname
181182

182183
#create container
183-
[success, msg] = self.create_container(taskid, vnodeid, username, image, lxcname, instance_type, ipaddr, gateway, brname)
184+
[success, msg] = self.create_container(taskid, vnodeid, username, image, lxcname, instance_type, ipaddr, gateway, brname, hostname)
184185
if not success:
185186
return rpc_pb2.Reply(status=rpc_pb2.Reply.REFUSED, message=msg)
186187

@@ -285,7 +286,7 @@ def stop_vnode(self, request, context):
285286

286287

287288
#accquire ip and create a container
288-
def create_container(self,taskid,vnodeid,username,image,lxcname,quota,ipaddr,gateway,brname):
289+
def create_container(self,taskid,vnodeid,username,image,lxcname,quota,ipaddr,gateway,brname,hostname):
289290
# prepare image and filesystem
290291
status = self.imgmgr.prepareFS(username,image,lxcname,str(quota.disk))
291292
if not status:
@@ -302,7 +303,8 @@ def create_container(self,taskid,vnodeid,username,image,lxcname,quota,ipaddr,gat
302303

303304
def config_prepare(content):
304305
content = content.replace("%ROOTFS%",rootfs)
305-
content = content.replace("%HOSTNAME%","batch-%s" % str(vnodeid))
306+
content = content.replace("%HOSTNAME%",hostname)
307+
content = content.replace("%TASKID%",taskid)
306308
content = content.replace("%CONTAINER_MEMORY%",str(quota.memory))
307309
content = content.replace("%CONTAINER_CPU%",str(quota.cpu*100000))
308310
content = content.replace("%FS_PREFIX%",self.fspath)

0 commit comments

Comments
 (0)