示例#1
0
    def add_job(self, job_dict):
        assert (job_dict)
        assert (job_dict["toolName"])
        logger.debug(job_dict["toolName"])

        template = CommandTemplate()
        template.setup(self, job_dict)
        template.parse_parameter_description()

        self.job_dict = job_dict
        if "toolId" not in job_dict:
            raise InvalidRequestError("Submitted job %s lacks toolId" %
                                      job_dict["toolName"])
        self.tool = Tool.objects.get(id=job_dict["toolId"])
        if not self.tool.enabled:
            raise InvalidRequestError(
                "Can't process workflow with disabled tool '%s'" %
                self.tool.name)
        if not self.tool.does_user_have_access_to(self.user):
            raise InvalidRequestError(
                "Can't process workflow with inaccessible tool '%s'" %
                self.tool.name)

        # lets work out the highest copy level supported by this tool and store it in job. This makes no account for the backends capabilities.
        # that will be resolved later when the stagein is created during the walk
        self.preferred_stagein_method = 'link' if self.tool.link_supported else 'lcopy' if self.tool.lcopy_supported else 'copy'

        self.preferred_stageout_method = 'lcopy' if self.tool.lcopy_supported else 'copy'  # stageouts should never be linked. Only local copy or remote copy

        # cache job for later reference
        self.command_template = template.serialise()
        self.command = str(template)  # text description of command

        self.status = const.STATUS_PENDING
        self.stageout = "%s%s/" % (
            self.workflow.stageout, "%d - %s" %
            (self.order + 1, self.tool.get_display_name()))
        self.exec_backend = self.get_backend_uri(self.exec_credential)
        self.fs_backend = self.get_backend_uri(self.fs_credential)
        self.cpus = self.tool.cpus
        self.walltime = self.tool.walltime
        self.module = self.tool.module
        self.queue = self.tool.queue
        self.max_memory = self.tool.max_memory
        self.job_type = self.tool.job_type

        self.save()
示例#2
0
    def add_job(self, job_dict):
        assert(job_dict)
        assert(job_dict["toolName"])
        logger.debug(job_dict["toolName"])

        template = CommandTemplate()
        template.setup(self, job_dict)
        template.parse_parameter_description()

        self.job_dict = job_dict
        if "toolId" not in job_dict:
            raise InvalidRequestError("Submitted job %s lacks toolId" % job_dict["toolName"])
        self.tool = Tool.objects.get(id=job_dict["toolId"])
        if not self.tool.enabled:
            raise InvalidRequestError("Can't process workflow with disabled tool '%s'" % self.tool.name)
        if not self.tool.does_user_have_access_to(self.user):
            raise InvalidRequestError("Can't process workflow with inaccessible tool '%s'" % self.tool.name)

        # lets work out the highest copy level supported by this tool and store it in job. This makes no account for the backends capabilities.
        # that will be resolved later when the stagein is created during the walk
        self.preferred_stagein_method = 'link' if self.tool.link_supported else 'lcopy' if self.tool.lcopy_supported else 'copy'

        self.preferred_stageout_method = 'lcopy' if self.tool.lcopy_supported else 'copy'                                                   # stageouts should never be linked. Only local copy or remote copy

        # cache job for later reference
        self.command_template = template.serialise()
        self.command = str(template)                    # text description of command

        self.status = const.STATUS_PENDING
        self.stageout = "%s%s/" % (self.workflow.stageout, "%d - %s" % (self.order + 1, self.tool.get_display_name()))
        self.exec_backend = self.get_backend_uri(self.exec_credential)
        self.fs_backend = self.get_backend_uri(self.fs_credential)
        self.cpus = self.tool.cpus
        self.walltime = self.tool.walltime
        self.module = self.tool.module
        self.queue = self.tool.queue
        self.max_memory = self.tool.max_memory
        self.job_type = self.tool.job_type

        self.save()
示例#3
0
class CommandLineTemplateTest(unittest.TestCase):
    def setUp(self):
        demo_user = m.User.objects.get(name='demo')
        workflow = mommy.make('Workflow', user=demo_user)
        self.job = mommy.make('Job', workflow=workflow, order=0)
        self.td = mommy.make('ToolDesc', name='my-tool')
        self.tool = mommy.make('Tool', desc=self.td, path='tool.sh')
        combined_with_equals = ParameterSwitchUse.objects.get(
            display_text='combined with equals')
        value_only = ParameterSwitchUse.objects.get(display_text='valueOnly')
        mommy.make('ToolParameter',
                   tool=self.td,
                   switch="-arg1",
                   switch_use=combined_with_equals,
                   rank=2)
        mommy.make('ToolParameter',
                   tool=self.td,
                   switch="-arg2",
                   switch_use=value_only,
                   rank=1)
        mommy.make('ToolParameter',
                   tool=self.td,
                   switch="-arg3",
                   switch_use=value_only,
                   file_assignment='batch')

        self.template = CommandTemplate()
        self.job_1_dict = {
            "jobId": 1,
            "toolName": "my-tool",
            "toolId": self.tool.id,
            "parameterList": {
                "parameter": []
            }
        }

    def tearDown(self):
        self.job.workflow.delete()
        self.td.delete()

    def job_dict_with_params(self, *params):
        import copy
        d = copy.copy(self.job_1_dict)
        if params:
            d['parameterList']['parameter'] = params
        return d

    def render_command(self, job, job_dict, uri_conversion=None):
        self.template.setup(job, job_dict)
        self.template.parse_parameter_description()

        if uri_conversion is not None:
            self.template.set_uri_conversion(uri_conversion)

        return self.template.render()

    def test_no_params(self):
        job_dict = self.job_1_dict

        command = self.render_command(self.job, job_dict)

        self.assertEquals("tool.sh", command)

    def test_param_combined_with_equals(self):
        job_dict = self.job_dict_with_params({
            'switchName': '-arg1',
            'valid': True,
            'value': ['value']
        })

        command = self.render_command(self.job, job_dict)

        self.assertEquals('tool.sh -arg1=value', command)

    def test_param_value_only(self):
        job_dict = self.job_dict_with_params({
            'switchName': '-arg2',
            'valid': True,
            'value': ['a value']
        })

        command = self.render_command(self.job, job_dict)

        self.assertEquals("tool.sh 'a value'", command)

    def test_rank_respected(self):
        job_dict = self.job_dict_with_params(
            {
                'switchName': '-arg1',
                'valid': True,
                'value': ['value']
            }, {
                'switchName': '-arg2',
                'valid': True,
                'value': ['other value']
            })

        command = self.render_command(self.job, job_dict)

        self.assertEquals("tool.sh 'other value' -arg1=value", command)

    def test_direct_file_reference(self):
        job_dict = self.job_dict_with_params({
            'switchName':
            '-arg3',
            'valid':
            True,
            'value': [{
                'path': ['some', 'path'],
                'root': 'sftp://demo@localhost:22/',
                'type': 'file',
                'filename': 'a file.txt'
            }]
        })

        command = self.render_command(
            self.job,
            job_dict,
            uri_conversion='/tools/workdir/input/%(filename)s')

        self.assertEquals("tool.sh '/tools/workdir/input/a file.txt'", command)