edu.isi.pegasus.planner.code.generator

## Class Shell

- java.lang.Object
- - edu.isi.pegasus.planner.code.generator.Abstract
  - - edu.isi.pegasus.planner.code.generator.Shell

All Implemented Interfaces:
  CodeGenerator

    public class Shell
    extends Abstract

This code generator generates a shell script in the submit directory. The shell script can be executed on the submit host to run the workflow locally.

Version:
  $Revision$
Author:
  Karan Vahi

### Field Summary

Fields
`static java.lang.String` `JOBSTATE_JOB_PREFIX` The prefix for events associated with job in jobstate.log file
`static java.lang.String` `JOBSTATE_POST_SCRIPT_PREFIX` The prefix for events associated with POST_SCRIPT in jobstate.log file
`static java.lang.String` `JOBSTATE_PRE_SCRIPT_PREFIX` The prefix for events associated with job in jobstate.log file
`protected CredentialHandlerFactory` `mFactory` Handle to the Credential Factory
`protected GridStartFactory` `mGridStartFactory` The handle to the GridStart Factory.
`protected boolean` `mInitializeGridStart` A boolean indicating whether grid start has been initialized or not.
`private SiteStore` `mSiteStore` Handle to the Site Store.
`private java.io.PrintWriter` `mWriteHandle` The handle to the output file that is being written to.
`static java.lang.String` `PEGASUS_SHELL_RUNNER_FUNCTIONS_BASENAME`

### Fields inherited from class edu.isi.pegasus.planner.code.generator.Abstract

`mBag, mLogger, mPOptions, mProps, mSubmitFileDir`

### Fields inherited from interface edu.isi.pegasus.planner.code.CodeGenerator

`VERSION`

### Constructor Summary

Constructors
Constructor and Description
`Shell()` The default constructor.

### Method Summary

All Methods Instance Methods Concrete Methods
`protected java.lang.String` `generateCallToCheckExitcode(Job job, java.lang.String prefix)` Generates a call to check_exitcode function that is used
`protected java.lang.String` `generateCallToExecuteJob(Job job, java.lang.String scratchDirectory, java.lang.String submitDirectory)` Generates a call to execute_job function , that is used to launch a job from the shell script.
`protected java.lang.String` `generateCallToExecutePostScript(Job job, java.lang.String directory)` Generates a call to execute_post_script function , that is used to launch a job from the shell script.
`java.util.Collection<java.io.File>` `generateCode(ADag dag)` Generates the code for the concrete workflow in the GRMS input format.
`void` `generateCode(ADag dag, Job job)` Generates the code for a single job in the input format of the workflow executor being used.
`java.util.Map<java.lang.String,java.lang.String>` `getAdditionalBraindumpEntries(ADag workflow)` Returns a Map containing additional braindump entries that are specific to a Code Generator
`protected java.lang.String` `getExecutionDirectory(Job job)` Returns the directory in which a job should be executed.
`protected java.lang.String` `getPathToShellScript(ADag dag)` Returns path to the shell script that is generated
`protected java.lang.String` `getScriptFooter()` Returns the footer for the generated shell script.
`protected java.lang.String` `getScriptHeader(java.lang.String submitDirectory)` Returns the header for the generated shell script.
`protected java.lang.String` `getSubmitHostPathToShellRunnerFunctions()` Determines the path to common shell functions file that the generated shell script will use.
`void` `initialize(PegasusBag bag)` Initializes the Code Generator implementation.
`private void` `initializeWriteHandle(java.lang.String filename)` It initializes the write handle to the output file.
`protected boolean` `setXBitOnFile(java.lang.String file)` Sets the xbit on the file.
`protected void` `writeString(java.lang.String st)` Writes a string to the associated write handle with the class

### Methods inherited from class edu.isi.pegasus.planner.code.generator.Abstract

`getDAGFilename, getDAGFilename, getFileBaseName, getWriter, reset, startMonitoring, writeOutBraindump, writeOutDAXReplicaStore, writeOutNotifications, writeOutStampedeEvents`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### PEGASUS_SHELL_RUNNER_FUNCTIONS_BASENAME

    public static final java.lang.String PEGASUS_SHELL_RUNNER_FUNCTIONS_BASENAME

See Also:
  Constant Field Values

#### JOBSTATE_JOB_PREFIX

    public static final java.lang.String JOBSTATE_JOB_PREFIX

The prefix for events associated with job in jobstate.log file

See Also:
  Constant Field Values

#### JOBSTATE_POST_SCRIPT_PREFIX

    public static final java.lang.String JOBSTATE_POST_SCRIPT_PREFIX

The prefix for events associated with POST_SCRIPT in jobstate.log file

See Also:
  Constant Field Values

#### JOBSTATE_PRE_SCRIPT_PREFIX

    public static final java.lang.String JOBSTATE_PRE_SCRIPT_PREFIX

The prefix for events associated with job in jobstate.log file

See Also:
  Constant Field Values

#### mWriteHandle

    private java.io.PrintWriter mWriteHandle

The handle to the output file that is being written to.

#### mSiteStore

    private SiteStore mSiteStore

Handle to the Site Store.

#### mGridStartFactory

    protected GridStartFactory mGridStartFactory

The handle to the GridStart Factory.

#### mFactory

    protected CredentialHandlerFactory mFactory

Handle to the Credential Factory

#### mInitializeGridStart

    protected boolean mInitializeGridStart

A boolean indicating whether grid start has been initialized or not.

### Constructor Detail

#### Shell

    public Shell()

The default constructor.

### Method Detail

#### initialize

    public void initialize(PegasusBag bag)
                    throws CodeGeneratorException

Initializes the Code Generator implementation.

Specified by:
  `initialize` in interface `CodeGenerator`
Overrides:
  `initialize` in class `Abstract`
Parameters:
  `bag` - the bag of initialization objects.
Throws:
  `CodeGeneratorException` - in case of any error occuring code generation.

#### generateCode

    public java.util.Collection<java.io.File> generateCode(ADag dag)
                                                    throws CodeGeneratorException

Generates the code for the concrete workflow in the GRMS input format. The GRMS input format is xml based. One XML file is generated per workflow.

Parameters:
  `dag` - the concrete workflow.
Returns:
  handle to the GRMS output file.
Throws:
  `CodeGeneratorException` - in case of any error occuring code generation.

#### generateCode

    public void generateCode(ADag dag,
                             Job job)
                      throws CodeGeneratorException

Generates the code for a single job in the input format of the workflow executor being used.

Parameters:
  `dag` - the dag of which the job is a part of.
  `job` - the `Job` object holding the information about that particular job.
Throws:
  `CodeGeneratorException` - in case of any error occuring code generation.

#### getAdditionalBraindumpEntries

    public java.util.Map<java.lang.String,java.lang.String> getAdditionalBraindumpEntries(ADag workflow)

Returns a Map containing additional braindump entries that are specific to a Code Generator

Specified by:
  `getAdditionalBraindumpEntries` in class `Abstract`
Parameters:
  `workflow` - the executable workflow
Returns:
  Map

#### generateCallToCheckExitcode

    protected java.lang.String generateCallToCheckExitcode(Job job,
                                                           java.lang.String prefix)

Generates a call to check_exitcode function that is used

Parameters:
  `job` - the associated job
  `prefix` - the prefix for the jobstate.log events
Returns:
  the call to execute job function.

#### generateCallToExecutePostScript

    protected java.lang.String generateCallToExecutePostScript(Job job,
                                                               java.lang.String directory)

Generates a call to execute_post_script function , that is used to launch a job from the shell script.

Parameters:
  `job` - the job to be launched
  `directory` - the directory in which the job needs to be launched.
Returns:
  the call to execute job function.

#### generateCallToExecuteJob

    protected java.lang.String generateCallToExecuteJob(Job job,
                                                        java.lang.String scratchDirectory,
                                                        java.lang.String submitDirectory)

Generates a call to execute_job function , that is used to launch a job from the shell script.

Parameters:
  `job` - the job to be launched
  `scratchDirectory` - the workflow specific execution directory created during running of the workflow
  `submitDirectory` - the submit directory of the workflow
Returns:
  the call to execute job function.

#### getScriptHeader

    protected java.lang.String getScriptHeader(java.lang.String submitDirectory)

Returns the header for the generated shell script. The header contains the code block that sources the common plan script from $PEGASUS_HOME/bin and initializes the jobstate.log file.

Parameters:
  `submitDirectory` - the submit directory for the workflow.
Returns:
  the script header

#### getSubmitHostPathToShellRunnerFunctions

    protected java.lang.String getSubmitHostPathToShellRunnerFunctions()

Determines the path to common shell functions file that the generated shell script will use.

Returns:
  the path on the submit host.

#### getScriptFooter

    protected java.lang.String getScriptFooter()

Returns the footer for the generated shell script.

Returns:
  the script footer.

#### getPathToShellScript

    protected java.lang.String getPathToShellScript(ADag dag)

Returns path to the shell script that is generated

Parameters:
  `dag` - the workflow
Returns:
  path

#### initializeWriteHandle

    private void initializeWriteHandle(java.lang.String filename)
                                throws CodeGeneratorException

It initializes the write handle to the output file.

Parameters:
  `filename` - the name of the file to which you want the write handle.
Throws:
  `CodeGeneratorException`

#### writeString

    protected void writeString(java.lang.String st)

Writes a string to the associated write handle with the class

Parameters:
  `st` - the string to be written.

#### getExecutionDirectory

    protected java.lang.String getExecutionDirectory(Job job)

Returns the directory in which a job should be executed.

Parameters:
  `job` - the job.
Returns:
  the directory

#### setXBitOnFile

    protected boolean setXBitOnFile(java.lang.String file)

Sets the xbit on the file.

Parameters:
  `file` - the file for which the xbit is to be set
Returns:
  boolean indicating whether xbit was set or not.