This repository has been archived by the owner on May 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_dispatcher.py
185 lines (150 loc) · 6.49 KB
/
test_dispatcher.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# -*- coding: utf-8 -*-
#========================
# :Date:Aug 29, 2013
# :Authors: Bertrand Néron
# :Contact: bneron<at>pasteur<dot>fr
# :Organization: Institut Pasteur
# :license: GPLv3
#========================
import sys
sys.path.insert(0, '/home/bneron/Mobyle/2.0/mobyle2.exec_engine/mob2exec')
import random
from itertools import izip
from mobyle.common.config import Config
config = Config('/home/bneron/Mobyle/2.0/mobyle2.conf/mobyle.ini')
from mobyle.common.connection import connection
from mobyle.common.users import User
from mobyle.common.project import Project
from mobyle.common.job import Status
from mobyle.common.job import ClJob
from mobyle.common.job_routing_model import ExecutionSystem
from mobyle.common.job_routing_model import ExecutionRoutes
from mobyle.common.mobyleError import MobyleError
def clean_db():
old_jobs = connection.Job.find({})
for obj in old_jobs:
obj.delete()
old_users = connection.User.find({})
for obj in old_users:
obj.delete()
old_projects = connection.Project.find({})
for obj in old_projects:
obj.delete()
try:
old_exec_sys = connection.ExecutionSystem.find({})
for obj in old_exec_sys:
obj.delete()
except AttributeError:
print >> sys.stderr, "collection ExecutionSystem not found"
try:
old_routes = connection.ExecutionRoutes.find({})
for obj in old_routes:
obj.delete()
except AttributeError:
print >> sys.stderr, "collection ExecutionRoutes not found"
def create_user(name):
user = connection.User()
user['email'] = '{0}@pieds.nickelés.fr'.format(name)
user.save()
return user
def create_project(user, name):
project = connection.Project()
project['owner'] = user['_id']
project['name'] = name
project.save()
return project
def create_job(name, project ):
job = connection.ClJob()
job.project = project.id
job.name = name
job.status = Status(Status.TO_BE_BUILT)
job.owner = {'id': project.id, 'klass': 'Project'}
job.save()
return job
def push_exec_sys_in_db(conf):
exec_sys = connection.ExecutionSystem()
exec_sys['_id'] = conf['_id']
exec_sys['class'] = conf['class']
if "drm_options" in conf:
exec_sys["drm_options"] = conf["drm_options"]
if "native_specifications" in conf:
exec_sys["native_specifications"] = conf["native_specifications"]
exec_sys.save()
def push_routes_in_db(conf_map):
_map = connection.ExecutionRoutes()
_map["map"] = conf_map
_map.save()
################### Preparation ##########################
clean_db()
pieds_nickeles = {}
projects = []
name_str = ('Filochard', 'Ribouldingue', 'Croquignol')
p_str = ('organisateurs de voyage', 'dans le cambouis', "l'Opération congélation")
for u_name ,p_name in izip(name_str, p_str):
pieds_nickeles[u_name] = create_user(u_name)
projects.append(create_project(pieds_nickeles[u_name], p_name))
conf = { "execution_systems" : [{"_id" : "big_one",
"class" : "OgsDRMAA",
"drm_options" : {"drmaa_library_path" : "path/to/sge/libdrmaa.so",
"cell" : '/usr/local/sge',
"root" : 'default',
},
"native_specifications": " -q mobyle-long "
},
{"_id" : "small_one",
"class" : "OgsDRMAA",
"drm_options" : {"drmaa_library_path" : "path/to/sge/libdrmaa.so",
"cell" : '/usr/local/sge',
"root" : 'default'
},
"native_specifications": " -q mobyle-small "
},
{"_id" : "cluster_two",
"class" : "TorqueDRMAA",
"drm_options" : {"drmaa_library_path" : "path/to/torque/libdrmaa.so",
"server_name" : "localhost"
},
"native_specifications": " -q mobyle-small "
},
{"_id" : "local",
"class" : "Local",
"native_specifications" : " nice -n 18 "
}],
"map": [ {"name": "route_1",
"rules" : [{"name" : "user_is_local"} , {"name" : "job_name_match",
"parameters" : {"name": "Filochard"}
}
],
"exec_system" : "big_one"
},
{"name" :"route_2",
"rules" : [{"name" : "project_match", "parameters" : {"name": "dans le cambouis"}} ],
"exec_system" : "small_one"
},
{"name" : "default",
"rules" : [],
"exec_system" : "cluster_two"
}
]
}
for exec_sys in conf["execution_systems"]:
push_exec_sys_in_db(exec_sys)
push_routes_in_db(conf["map"])
############## Test #####################################
#from mobyle.execution_engine.systems.execution_system import load_execution_classes
#from mobyle.execution_engine.job_routing.route import Rule, Route, Dispatcher
#from mobyle.execution_engine.job_routing.route import Dispatcher
from mobyle.execution_engine.job_routing.route import get_dispatcher
recieved_routes = []
dispatcher = get_dispatcher()
for i in range(0, 3):
job = create_job(name_str[i], projects[i])
print "----------------"
print "job name ", name_str[i]
print "project ", p_str[i]
recieved_routes.append((job, dispatcher.which_route(job)))
print "======================="
for item in recieved_routes:
print "----------------"
print "job name", item[0].name
print "route name", item[1].name