This document describes how to develop job software while testing it under the Job Harness and what needs to be done in order to make releases of job software for production deployment.
The Job Harness runs your software through two main programs in order to assure required input files are available and to capture any produced output files. It a production setting it also controls which versions of the job software are available and run.
In order to provide this it make some requirements on the operating environment, job software and LIMS server.
The running environment must provide:
The job software must be written to provide:
modulefile)
For a job to run under the Job Harness it must first be registered with LIMS. Only job name/version pairs that are registered may be run through the Job Harness. It is also through LIMS that any dependencies are expressed. If JobB needs the output file from JobA, it is through this registration where that is declared.
This section describes how to configure your account to develop your job software while running it under the Job Harness. When a concrete example is shown it assumes the account name is operator, the job name is analyze and the job version is devel. In a production deployment the job version should indicate an actual version. (v1.2.3, etc).
There is much flexibility in how development is done while still using the job harness. Depending on the number of jobs and their granularity and interrelatedness these following examples may be expanded on.
Pick some top-level working directory to work in:
$ mkdir /home/operator/lcatr $ cd /home/operator/lcatr
For the following sections, all relative directories will be w.r.t. this one.
For development, a production deployment of the Job Harness should be used. It is installed into a virtualenv directory. To set up your shell environment it is suggested to run and configure a subshell. This can be done by making two short shell scripts:
In your top-level working directory, copy this into job-harness-shell:
#!/bin/bash mydir=$(dirname $(readlink -f $BASH_SOURCE)) ssh-agent /bin/bash --rcfile $mydir/job-harness.sh
And, copy this into job-harness.sh:
#!/bin/bash source VIRTUALENV/bin/activate export PS1="(jh)\u@\h:\w> " export https_proxy=http://lsstproxy.rcf.bnl.gov:3128/ export http_proxy=http://lsstproxy.rcf.bnl.gov:3128/
Now edit this last one:
$ emacs job-harness.sh $ chmod +x job-harness-shell
And replace VIRTUALENV with the directory holding the virtualenv area.
You can now start your shell:
$ ./job-harness-shell (jh)$ lcatr-harness --help (jh)$ exit
On RACF one can start the job harness shell like:
~bvastro/lcatr/job-harness-shell
After running job-harness-shell you may notice your prompt now has a (jh) prepended to indicate a sub-shell was started. At this point you can run the Job Harness with the --help flag to see its help page. When done using the harness you can exit the shell and drop back to your normal one.
Your account needs an SSH private key that can be used to access the archive account. Normally this is installed by the deployment system. You may get one for use in development.
$ cp .... ~/.ssh/id_archive $ chmod 400 ~/.ssh/id_archive
The Job Harness takes many parameters. To avoid having to specify them on the command line all the time it is recommended that they be placed in a configuration file which goes in the operators home directory.
Copy this to ~/.lcatr.cfg:
[DEFAULT] archive_host = astroftp.rhic.bnl.gov lims_url = https://www.lsst.bnl.gov:8088 archive_user = ccdarxiv unit_type = CCD user = ccdtest archive_root = /astro/astronfs01/ccdarchive/tst stage_root = /PATH/TO/LOCAL/stage
Now, edit the file and set the stage_root variable to point to a
large disk which you can write to.
modulefile
Your job software main programs are located by the Job Harness with an Environment Modules modulefile. This file itself is located by searching for it in a sub-directory named like <job name>/<job version>/modulefile. Make this directory in your working area
$ mkdir -p lcatr/analyze/devel
Or, if you already have code in a repository clone it into a "devel" target
$ mkdir -p lcatr/analyze/ $ git clone http://git.server//analyze lcatr/analyze/devel
Now, edit the lcatr/analyze/devel/modulefile to look something like:
#%Module1.0 #-*-tcl-*-# source "$::env(LCATR_MODULES)/lcatr.tcl" lcatr_package /home/operator/lcatr/analyze/devel/producer /home/operator/lcatr/analyze/devel/validator
This last line is the important one and sets the path to your producer and validator programs. They should be adjusted to match their actual names. Note, when readied for development this line should not include absolute paths to the producer/validator programs.
Note, you do not have to keep the producer/validator programs in the same directory as the modulefile. You can also have multiple jobs implemented in one area or git repository. However, each job needs a distinct <job name>/<job version>/modulefile.
To register a job name/version pair with LIMS you must have a LIMS account. At BNL you will likely have to have the special HTTP proxy set (the job-harness-shell example sets up the needed environment variables).
https://www.lsst.bnl.gov:8088
Note that port 8088 is used. This instance of LIMS is tied to the testing. Do not use these developer instructions with the production LIMS!
Once the above has been set up you should be able to run your job software's producer and validator programs under the Job Harness.
(jh)$ lcatr-harness --job analyze \
--version devel \
--unit-id 112-04 \
--operator bv \
--modules-path=/home/operator/lcatr
Any and all of these options may be placed in the ~/.lcatr.cfg file. The command line will override them.
When your test station or analysis job is written in Python it is best to put virtually all of your code inside a Python package. This will best assure that it runs the same in your development and production environments and minimize the amount of external environment that needs to be correct.
Here, the term Python package means something specific in Python (and will be italicized here) and should not be confused with the more general usage in the context of the greater Job Harness system.
The examples continue the assumption that your job is named "analyze" and all examples assume you have cd'ed into your code directory (which was analyze/devel/ in the previous section). It is also assumed that you are working in the sub-shell started by running job-harness-shell.
A Python package is really nothing more than a directory with an __init__.py file (which may even be empty) marking the directory as such. There is flexibility in where you make this directory. During development we will let Python locate it by adjusting the PYTHONPATH environment variable. In a production context Python will locate it because it will get installed in Python's site-packages system area.
Make the (initially) empty analyze package:
mkdir analyze touch analyze/__init__.py
Let Python find this package in your development environment. You should still be in the directory holding your source (eg. analyze/devel/) when you issue this command as the output of pwd is used to set the directory:
export PYTHONPATH=`pwd`
Note, the pwd command is surrounded by backtick quotes.
You can now test that this Python package is correct right from the shell command line:
python -c 'import analyze'
echo $?
: 0
You should get no errors
Now you are all ready to add code into your Python package directory. Every file you make under analyze/ will result in a Python module that can be accessed in Python code after the Python import operator is used. Here we make a trivial example module by just echo'ing a line of Python code into a file from the shell:
echo 'print "Hello World"' > analyze/hello.py
The analyze/hello.py file has just this one line, you would of course use an editor to place something more substantial:
print "Hello World"
Here is how you would use the module from some other Python code
import analyze.hello
: Hello World
The second line shows the result you should see when you execute the Python code.
Normally you would not place top-level code in a Python module file. Here is a second example where a function is defined:
echo 'def say(): print "Bye"' > analyze/goodbye.py
Then it may be used like:
from analyze import goodbye def myfun(): goodbye.say() myfun(): Bye
Or, you can import individual functions or classes from their module like:
from analyze.goodbye import say say(): Bye
Continue to build up your Python package by adding code or more Python files to the analyze/ directory. Sub-modules, for example analyze.tools can also be made:
mkdir analyze/tools touch analyze/tools/__init__.py echo 'print "I am a tool sub-module"' > analyze/tools/sometool.py python -c 'from analyze.tools import sometool' echo echo 'The Python package layout is now:' echo ls -R analyze
I am a tool sub-module The Python package layout is now: analyze: goodbye.py goodbye.pyc hello.py hello.pyc __init__.py __init__.pyc tools analyze/tools: __init__.py __init__.pyc sometool.py sometool.pyc
With a well organized Python package your main producer and validator scripts that the Job Harness calls may become very trivial. For example the producer might be just:
from analyze import producer producer.run()
The following is mostly from an older version of this document but still applicable.
In order to be "harnessed" your software must be augmented to satisfy the following aspects:
It is expected that these aspects can be satisfied by writing thing "shim" scripts that "glue" your existing software into the job harness. The expected, general steps to follow are:
The instructions for each step are described in detail in the rest of this document. In addition, for information about testing your software under the job harness see the document "LCATR Testing".
The scope of a harnessed job is a balance between being as inclusive as possible to avoid a proliferation of jobs (and their developer overheard) and being as atomic as possible so that one problem does lead to an abort an loss of progress. It's up to the developer to determine this. Some guidelines:
The harness identifies a job by its canonical name (and its installed version). Once a name is selected it becomes a reserved identifier in various parts of the system. Since it is a primary descriptor it is best for the named test to not evolve far beyond its original intention. If a radical change is needed then a new canonical name should be chosen.
Your software may be written in a variety of ways but some general rules to keep in mind:
It is recommended that output file names be static from job to job and not encode timestamps, CCD IDs, version strings, etc as these are reflected by the job harness in the output directory path and are recorded to the LIMS database. Encoding this information makes it more difficult for downstream processing to locate input files.
For each atomic job, the harness will run two programs one after the other which must be provided by your software. They may be named as you like but first is identified as the producer and the second as the validator. They will likely be written as interpreted scripts but need not be.
The producer program is meant to perform the primary functionality of your test or analysis software. It is free to produce any needed output files which may be in any desired format.
The validator program has two responsibilities. First, it should
perform any validation on the output of the producer that the author
sees fitting. Second it must produce a summary.lims file that is in
a schema-compliant format. See the document "LCATR Schema" for
details on producing this file.
To define the environment your software must provide an Environment Module1. In this file all variables required by the harness to run your software must be defined. These variables can be defined automatically by including this boilerplate:
#%Module1.0 #-*-tcl-*-#
source "$::env(LCATR_MODULES)/lcatr.tcl"
lcatr_package PRODUCER VALIDATOR
Replace the strings PRODUCER and VALIDATOR with the names of your
producer and validator executable files. They should be specified as
paths relative to the software's top-level installation directory
(more on installation below).
If your software requires additional environment variables they may be included in this file as well. Keep in mind that any information about individual units of testing have no place here.
Environment Modules are described at http://modules.sf.net/ and see the document "LCATR Environment Modules" for details about writing them for your software.
One special environment variable that your producer will need to use
if it reads in files that were produced from other jobs that have been
run on the same unit of test is the LCATR_DEPENDENCY_PATH. This
variable holds a ":"-delimited list of directories that contain output
file from the prior jobs run on the same CCD (or RTM) that your
software is testing. This directory path list is the sole mechanism
for dependent packages to find input files that were produced as
output from prior jobs.
If you write your producer in Python the function dependency_glob()
will help you search for a files matching a pattern in this path.
from lcatr.harness.helpers import dependency_glob filenames = dependency_glob("somefile_*.data") for filename in filenames: f = open(filenames[0]) data = f.read() # ...
You can test this outside of the harness by doing the following:
# fake what the harness provides $ export LCATR_DEPENDENCY_PATH="/data/bvastro/stage_root/CCD/112-04/TS3-Fe55/devel/28:/data/bvastro/stage_root/CCD/112-04/TS3-QE/devel/23:/data/bvastro/stage_root/CCD/112-04/TS3-i_dark/v1/24:/data/bvastro/stage_root/CCD/112-04/TS3-PTCmono/v1/25" $ python >>> from lcatr.harness.helpers import dependency_glob >>> print '\n'.join(dependency_glob("*.fits"))
Note: the pattern very much must match the file layout. For early data copied by the "real fake" TS3 jobs you would use something like:
for everyfile in dependency_glob('*/*.fits'): print everyfile for just_qe in dependency_glob('*/*.fits','TS3-QE'): print just_qe
You tell the job harness which CCD ID is being run with the --unit-id command line flag (or equivalent configuration file variable) and it then tells your job via the LCATR_UNIT_ID environment variable. Here is how your Python code can get this information:
import os ccd_id = os.environ['LCATR_UNIT_ID']
All production code must be specified by a tag in a git repository. This section gives brief commands on how to perform the required git mechanics.
Before getting starting a repository must be requested from the site git repository manager. You should provide the canonical name for your software and you will be given a git URL. If you do not yet have a local git repository you will clone the (empty) new one and fill it with your software files. If you are already using git to manage your software you will add this new repository as a remote. The following examples use an existing (non-empty) repository.
Clone a remote git repository:
git clone https://git.racf.bnl.gov/astro/git/lcatr/jobs/example_station_A.git
When done, the remote name defaults to "origin". To add a remote repository to an already existing local one do:
git remote add <remotename> https://git.racf.bnl.gov/astro/git/lcatr/jobs/example_station_A.git
To tag a release one runs the following from your local git-controlled area
git tag <tagname> [<commit> | <object>]
The form of the tag name is left to your discretion but it is
recommended that some convention is chosen and carefully followed. By
default this will tag the current "head" commit. If another commit is
desired its hash may be specified. Running gitk can help identify
the commit.
Git allows for changing a tag after it has been made. This should be strongly avoided but, strictly speaking, it will only cause a problem if done after the tag was used to install, select and run your software in a production setting.
So far you have only made changes to your local repository. To send the commits associated with the tag you "push" them like:
git push <remotename> <tagname>
After the git mechanics above are complete, the next step is to inform the software manager that a new release has been made and requires installation. This notification should include at least:
It is expected that only the first item will change from release to release.
As described above, your job finds input files that were output by any jobs on which your job depends based on information that the harness provides. The harness gets this information from the LIMS database but it must ultimately come from the test software developer. You need to communicate this to LIMS.
Specifics are found in the document LCATR Job Installation.
Date: 2014-10-03 11:44:45 PDT
HTML generated by org-mode 6.21b in emacs 23