| 1 | """Latent BuildSlave for the Grid Engine Distributen System |
|---|
| 2 | |
|---|
| 3 | Author: Lital Natan <procscsi@gmail.com> |
|---|
| 4 | |
|---|
| 5 | """ |
|---|
| 6 | |
|---|
| 7 | from drmaabuildslave import DRMAALatentBuildSlave |
|---|
| 8 | |
|---|
| 9 | class OptionStub(object): |
|---|
| 10 | def __init__(self, option_name, option_dict): |
|---|
| 11 | self.option_name = option_name |
|---|
| 12 | self.option_dict = option_dict |
|---|
| 13 | |
|---|
| 14 | def setter(self, value): |
|---|
| 15 | self.option_dict[self.option_name] = value |
|---|
| 16 | |
|---|
| 17 | def getter(self): |
|---|
| 18 | return self.option_dict.get(self.option_name, None) |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | class GridEngineLatentBuildSlave(DRMAALatentBuildSlave): |
|---|
| 22 | """Latent BuildSlave for the Grid Engine Distributen System""" |
|---|
| 23 | |
|---|
| 24 | # Dictionary for naming SGE job arguments in a 'human-readable' form |
|---|
| 25 | grid_option_dictionary = { |
|---|
| 26 | 'queue':'-q', |
|---|
| 27 | 'name':'-N', |
|---|
| 28 | 'shell':'-S', |
|---|
| 29 | 'env': '-v', |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | job_options = None # SGE job options (dict[argument]=value) |
|---|
| 33 | job_resources = None # SGE job resources (dict[resource]=amount/object) |
|---|
| 34 | |
|---|
| 35 | def __init__(self, buildslave_setup_command, *args, **kwargs): |
|---|
| 36 | """Default Constructor |
|---|
| 37 | |
|---|
| 38 | buildslave_setup_command -- the o/s command starting the BuildBot slave |
|---|
| 39 | its recommended to use a command starting a |
|---|
| 40 | non-daemon slave instance. |
|---|
| 41 | *args -- non-keyword arguments for the BuildBot slave |
|---|
| 42 | **kwargs -- keyword arguments for the BuildBot slave |
|---|
| 43 | |
|---|
| 44 | """ |
|---|
| 45 | # Default job options |
|---|
| 46 | self.job_options = { |
|---|
| 47 | 'queue': 'all.q', |
|---|
| 48 | 'name': 'BuildSlave', |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | # Default job resources |
|---|
| 52 | self.job_resources = { |
|---|
| 53 | 'arch': '*', |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | DRMAALatentBuildSlave.__init__(self, buildslave_setup_command, *args, **kwargs) |
|---|
| 57 | |
|---|
| 58 | # Create option stubs for all the job parameters 'named' by 'grid_options_dictionary' |
|---|
| 59 | for option_name, option_arg in self.grid_option_dictionary.iteritems(): |
|---|
| 60 | option_stub = OptionStub(option_name, self.job_options) |
|---|
| 61 | setattr(self, "get_job_" + option_name, option_stub.getter) |
|---|
| 62 | setattr(self, "set_job_" + option_name, option_stub.setter) |
|---|
| 63 | |
|---|
| 64 | def _start_instance(self): |
|---|
| 65 | """Startes a BuildSlave instance with the set job options and resources""" |
|---|
| 66 | |
|---|
| 67 | native_specification_string = "" |
|---|
| 68 | # Construct job options in to string |
|---|
| 69 | for option_name, option_value in self.job_options.iteritems(): |
|---|
| 70 | option_arg = self.grid_option_dictionary[option_name] |
|---|
| 71 | native_specification_string += option_arg + " " + option_value + " " |
|---|
| 72 | # Construct job resources in to string |
|---|
| 73 | resource_specification_string = "" |
|---|
| 74 | for res_name, res_value in self.job_resources.iteritems(): |
|---|
| 75 | if resource_specification_string: |
|---|
| 76 | resource_specification_string += "," |
|---|
| 77 | resource_specification_string += res_name + "=" + res_value |
|---|
| 78 | if resource_specification_string: |
|---|
| 79 | native_specification_string += "-l " + resource_specification_string |
|---|
| 80 | self.job_template.nativeSpecification = native_specification_string |
|---|
| 81 | return DRMAALatentBuildSlave._start_instance(self) |
|---|