<commit_before><?xml version="1.0" encoding="UTF-8"?>
<job xmlns="urn:proactive:jobdescriptor:dev" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:proactive:jobdescriptor:dev ../../src/scheduler/src/org/ow2/proactive/scheduler/common/xml/schemas/jobdescriptor/dev/schedulerjob.xsd" name="job-slurm" priority="normal" cancelJobOnError="true">

    <variables>
        <variable name="sbatch_arguments" value="--exclusive"/>
        <variable name="sbatch_script" value="b.sh"/>
        <variable name="sbatch_script_arguments" value="foo doo"/>
    </variables>

	<taskFlow>

        <task name="submit-job">
            <inputFiles>
                <files includes="${sbatch_script}" accessMode="transferFromUserSpace"/>
            </inputFiles>
            <scriptExecutable>
                <script >
                    <code language="groovy">
                        <![CDATA[
                        import groovy.json.JsonOutput
                        import org.ow2.proactive.datascale.slurm.OutputParser

                        def sbatch = "sbatch"
                        def sbatch_arguments = "${sbatch_arguments}"
                        def sbatch_script = "${sbatch_script}"
                        def sbatch_script_arguments = "${sbatch_script_arguments}"

                        def root = new File(new URI(localspace.getRealURI()))
                        def script = new File(root, sbatch_script).getAbsoluteFile()
                        def scriptPath = script.getAbsolutePath()

                        if (!script.exists()) {
                            def files = root.list()
                            throw new FileNotFoundException(scriptPath, "localspace contains: $files")
                        }

                        def cmd = sbatch + " " + " " + sbatch_arguments + " " + scriptPath + " " + sbatch_script_arguments
                        def p = cmd.execute()
                        p.waitFor()
                        def stderr = p.err.text
                        def stdout = p.text
                        def errcode = p.exitValue()

                        def job = getJobId(stdout)

                        result = JsonOutput.toJson(
                                [
                                        job: job,
                                        errcode: errcode,
                                        cmd: cmd,
                                        script: scriptPath,
                                        stdout: stdout,
                                        stderr: stderr
                                ])

                        println "Result: " + JsonOutput.prettyPrint(result)

                        def getJobId(txt) {
                            def regx = /(?s).*?job (\d+).*?/
                            def matcher = ( txt =~ regx )

                            if (matcher.matches()) {
                                return matcher[0][1]
                            } else {
                                return "unknown"
                            }
                        }

                        ]]>
                    </code><commit_msg>WC: workflow slurm-job-submit uses USERSPACE:/test.sh syntax for script file, more user friendly.<commit_after><?xml version="1.0" encoding="UTF-8"?>
<job xmlns="urn:proactive:jobdescriptor:dev" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:proactive:jobdescriptor:dev ../../src/scheduler/src/org/ow2/proactive/scheduler/common/xml/schemas/jobdescriptor/dev/schedulerjob.xsd" name="slurm-job-submit" priority="normal" cancelJobOnError="true">

    <variables>
        <variable name="sbatch_arguments" value="--exclusive"/>
        <variable name="sbatch_script" value="USERSPACE:/test.sh"/>
        <variable name="sbatch_script_arguments" value=""/>
    </variables>

	<taskFlow>

        <task name="submit-job">
            <inputFiles>
                <!-- Only script -->
                <!--<files includes="${sbatch_script}" accessMode="transferFromUserSpace"/>-->
                <!-- All files -->
                <files includes="*" accessMode="transferFromUserSpace"/>
            </inputFiles>
            <scriptExecutable>
                <script >
                    <code language="groovy">
                        <![CDATA[
                        import groovy.json.JsonOutput
                        import org.ow2.proactive.datascale.slurm.OutputParser

                        def sbatch = "sbatch"
                        def sbatch_arguments = "${sbatch_arguments}"
                        def sbatch_script = "${sbatch_script}"
                        def sbatch_script_arguments = "${sbatch_script_arguments}"

                        def root = new File(new URI(localspace.getRealURI()))

                        sbatch_script = sbatch_script.replace("USERSPACE:", root.getAbsolutePath())
                        sbatch_script_arguments = sbatch_script_arguments.replace("USERSPACE:", root.getAbsolutePath())

                        def cmd = sbatch + " " + " " + sbatch_arguments + " " + sbatch_script + " " + sbatch_script_arguments
                        def p = cmd.execute()
                        p.waitFor()
                        def stderr = p.err.text
                        def stdout = p.text
                        def errcode = p.exitValue()

                        def job = getJobId(stdout)

                        result = JsonOutput.toJson(
                                [
                                        job: job,
                                        errcode: errcode,
                                        cmd: cmd,
                                        script: sbatch_script,
                                        stdout: stdout,
                                        stderr: stderr
                                ])

                        println "Result: " + JsonOutput.prettyPrint(result)

                        def getJobId(txt) {
                            def regx = /(?s).*?job (\d+).*?/
                            def matcher = ( txt =~ regx )

                            if (matcher.matches()) {
                                return matcher[0][1]
                            } else {
                                return "unknown"
                            }
                        }

                        ]]>
                    </code>
{'fraction_non_alphanumeric': 0.10291382517048978, 'fraction_numerical': 0.0037197768133911966, 'mean_word_length': 1.1033246414602347, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 2, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 8}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2772353', 'n_tokens_mistral': 1556, 'n_tokens_neox': 1443, 'n_words': 269}