Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add job script validations #310

Merged
merged 9 commits into from
Dec 6, 2019
Merged

Add job script validations #310

merged 9 commits into from
Dec 6, 2019

Conversation

qianyuanzhu
Copy link
Contributor

@qianyuanzhu qianyuanzhu commented Nov 14, 2019

Overview

  • Add job script validation and provide recommendation for users

  • Step1: Omit files larger than 65KB for this field

  • Step2: Group files to "suggested" and "others" and sort alphabetically

  • Suggested files meet any of the following criteria
    1. File name extension is one of [".sh", ".job", ".slurm", ".batch", ".qsub", ".sbatch", ".srun", ".bsub"]
    2. First line of the file is a shebang line
    3. First 1000 bytes of the file contain '#PBS' or '#SBATCH"

  • Others files are files not omitted in Step1 and not meet requirement to be suggested

Tests

  • Tested the example on the issue page
  • Tested the job script under the sub folder
    dropdown-with-2-groups

Fixes #105

#
# Find.find returns an enumerator - the first path is always the initial directory
# so we return the array with the first item omitted
# Then, map files to WorkflowFile objects
#
# @return [WorkflowFile] An array of WorkflowFile Objects of all the files of a directory
def folder_contents
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could cache this like:

def folder_contents
  return @folder_contents if defined? @folder_contents

  ...
end

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This actually only works if you set the @folder_contents otherwise. For example:

def folder_contents
  return @folder_contents if defined? @folder_contents

  if File.directory?(self.staged_dir)
    @folder_contents = Find.find(self.staged_dir).drop(1).select {|f| File.file?(f) }.map {|f| WorkflowFile.new(f, self.staged_dir)}
  else
    @folder_contents = []
  end
end

@qianyuanzhu qianyuanzhu changed the title Add job script validations [WIP] Add job script validations Nov 21, 2019
@qianyuanzhu
Copy link
Contributor Author

qianyuanzhu commented Nov 22, 2019

Thank you for your feedback! I cleaned up the code and added error handling for the file permission.

Another issue I had is that the titles for option groups will still be displayed when no options available under that group. It's handled by removing empty option groups.

  1. Have both suggested and other files:
    both valid and suggested

  2. Only have suggested files:
    only suggested

  3. Have valid but not suggested files:
    I changed the group title "Others" to "Other valid file(s)" because "Others" could be confusing when it's the only group available. We can also remove the "Other valid file(s)" title completely if that's more user-friendly.
    only other files

  4. No valid files or folder is empty:
    empty folder

@qianyuanzhu qianyuanzhu changed the title [WIP] Add job script validations Add job script validations Nov 22, 2019
@qianyuanzhu
Copy link
Contributor Author

Thank you for the feedback and help identify the script directives! I updated v.blank? to v.empty?, added the checks for the new resource manager directives, and opened the issue you mentioned: OSC/ood_core#161.

def has_resource_manager_directive?
begin
contents = File.open(path) { |f| f.read(1000) }
contents && (contents.include?("#PBS") || contents.include?("#SBATCH") || contents.include?('#BSUB') || contents.include?('#$'))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the contents.include? predicate I would prefer:

['#PBS', '#SBATCH', '#BSUB', '#$'].any?{ |directive| contents.include?(directive) }

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although this is fine as is: a better design here would be for ood_core's Adapters to provide their directive as a constant and for this array to be built from the available clusters. The more tests we have the more likely we are to get a false positive.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noticed OSC/ood_core#161. +1

@@ -255,7 +285,7 @@ def stop_machete_jobs(jobs)
end
end
end

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pointless whitespace...

Copy link
Contributor

@MorganRodgers MorganRodgers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works for me.

  • Ideally we would build the list of resource manager directives from OODClusters after ood_core has been updated.
  • While this is a good start the workflow to get to here is not what I would expect as a user. I would expect that when creating a new workflow from an existing directory I would be able to select my script there. We could add this to the new_from_path view by adding some JS to listen to the change event on workflow[staging_template_dir], and then updating the script select options via AJAX.

Those changes can be a separate PR.

@MorganRodgers MorganRodgers merged commit 41aacbb into master Dec 6, 2019
@MorganRodgers MorganRodgers deleted the suggest-job-script branch December 6, 2019 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Job Composer's Job Options sets input file set as job script when none is specified
3 participants