org.icenigrid.gridsam.core.util
Class BatchUtils

java.lang.Object
  extended by org.icenigrid.gridsam.core.util.BatchUtils

public class BatchUtils
extends java.lang.Object

Purpose:
Provide some utilities for the ease of manipulating the batch system

Version:
1.0.1
Author:
qiaojian
Email: qiaojian@software.ict.ac.cn
Update Date : 2007-7-21

Constructor Summary
BatchUtils()
           
 
Method Summary
static DriverResponseParser cancel(java.lang.String owner, java.lang.String prefix, java.lang.String localJobID, java.lang.String workingDir)
          To cancel local batch job.
static java.lang.String catFile(java.lang.String owner, java.lang.String filePath)
          To cat the content of the indicated file, which is owned by targer user.
static FileDriverResponseParser chmod(java.lang.String owner, java.lang.String dirPath, java.lang.String umask)
          To chmod this directory.
static FileDriverResponseParser chown(java.lang.String owner, java.lang.String group, java.lang.String filePath)
          to change stagein-file's owner to localUser.
static FileDriverResponseParser copyContent(java.lang.String owner, java.lang.String sourceFilePath, java.lang.String targetFilePath)
          To read the content of source file and write to the target file.
static FileDriverResponseParser deleteFile(java.lang.String owner, java.lang.String dirPath)
          To delete the indicated dir or file.
static void deleteTempAfterFailed(JobInstance pJob)
          To delete the temp dir after setting the job as failed! Just try once :)
static DriverResponseParser detail(java.lang.String owner, java.lang.String prefix, java.lang.String localJobID, java.lang.String workingDir)
          To get the details of the indicated local batch job.
static void doProcess(java.lang.String owner, java.lang.String prefix, java.lang.String localJobID, java.lang.String workingDir, java.lang.String processFile)
          do post process in job working directory.
static java.lang.String execProcess(java.lang.String _cmdline, java.lang.String _homedir)
          execute the command-line command in the home directory _homedir.
static java.lang.String file2String(java.lang.String fn)
          read the content of a file whose path is given in fn value , and change the format to String.
static java.lang.String formalizePath(java.lang.String p, java.lang.String h)
          used when generate original job script
static java.lang.String getElementBody(org.w3c.dom.Document d, java.lang.String name)
          get element body using name from document d.
static FileDriverResponseParser getFirstExistPath(java.lang.String owner, java.lang.String dirPath)
          To get the first exist path of the given dirPath.
static java.lang.String getPureName(java.lang.String path)
          get the pure name , pure name means the name without path information.
static FileDriverResponseParser isReadAble(java.lang.String owner, java.lang.String filePath)
          check owner can read filePath or not.
static FileDriverResponseParser isWriteAble(java.lang.String owner, java.lang.String filePath)
          check owner can write in filePath or not.
static java.lang.String[] listZipEntry(java.lang.String zipLocation)
          handle zip file.
static FileDriverResponseParser makeDir(java.lang.String owner, java.lang.String dirPath)
          To create the working dir for the indicated job, which is owned by the correponding linux user.
static FileDriverResponseParser makeDirAndChmod(java.lang.String owner, java.lang.String dirPath, java.lang.String umask)
          To create the dir for the indicated job, and chmod this directory.
static FileDriverResponseParser moveFile(java.lang.String owner, java.lang.String sourceFilePath, java.lang.String targetFilePath)
          To move source file and write to the target file.
static byte[] readProxy(java.lang.String proxyPath)
          To read the proxy content.
static DriverResponseParser screenOutput(java.lang.String owner, java.lang.String prefix, java.lang.String localJobID, java.lang.String workingDir)
          To get the screen output of the indicated local batch job.
static DriverResponseParser status(java.lang.String owner, java.lang.String prefix, java.lang.String localJobID, java.lang.String workingDir)
          To query local batch job status.
static DriverResponseParser stdOutErr(java.lang.String owner, java.lang.String prefix, java.lang.String localJobID, java.lang.String workingDir)
          To get the stdout and stderr file name of the indicated local batch job.
static org.w3c.dom.Document string2Document(java.lang.String str)
          convert a XML String into the XML Document object.
static boolean string2File(java.lang.String src, java.lang.String fn)
          create a file in the intended location , and then inject the content into this file.
static boolean string2FileAppend(java.lang.String src, java.lang.String fn)
          To write the string into the indicated file.
static DriverResponseParser submit(java.lang.String owner, java.lang.String prefix, java.lang.String workingDir)
          To submit local batch job.
static java.lang.String tail(java.lang.String owner, int lineNumber, java.lang.String filePath)
          get tail string of the file.
static void UnZip(java.lang.String zipLocation, java.lang.String toDir)
          unzip .
static void UnZipEntry(java.io.File dir, java.io.InputStream zinputStream, java.lang.String entryName, boolean isDirectory)
          unzip.
static boolean ZipFiles(java.util.List list, java.lang.String zipname, boolean type)
           
static boolean ZipFiles(java.lang.String[] files, java.lang.String zipname, boolean type)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BatchUtils

public BatchUtils()
Method Detail

makeDir

public static FileDriverResponseParser makeDir(java.lang.String owner,
                                               java.lang.String dirPath)
                                        throws java.rmi.RemoteException
To create the working dir for the indicated job, which is owned by the correponding linux user.

Parameters:
owner - The owner of the working dir.
dirPath - The path to working dir.
eg:/home/qiaojian/GOS-ff11111111111111111111111
Returns:
FileDriverResponseParser instance
Throws:
java.rmi.RemoteException - fail to make directory.

makeDirAndChmod

public static FileDriverResponseParser makeDirAndChmod(java.lang.String owner,
                                                       java.lang.String dirPath,
                                                       java.lang.String umask)
                                                throws java.rmi.RemoteException
To create the dir for the indicated job, and chmod this directory.

Parameters:
owner - The owner of the working dir.
dirPath - The path to working dir.
eg:/home/qiaojian/GOS-ff11111111111111111111111.
umask - the umask of the dirPath.
Returns:
FileDriverResponseParser instance
Throws:
java.rmi.RemoteException - fail to make directory and chmod.

chmod

public static FileDriverResponseParser chmod(java.lang.String owner,
                                             java.lang.String dirPath,
                                             java.lang.String umask)
                                      throws java.rmi.RemoteException
To chmod this directory.

Parameters:
owner - The owner of the working dir.
dirPath - The path to working dir.
eg:/home/qiaojian/GOS-ff11111111111111111111111.
umask - the umask of the dirPath.
Returns:
FileDriverResponseParser instance
Throws:
java.rmi.RemoteException - fail to chmod.

catFile

public static java.lang.String catFile(java.lang.String owner,
                                       java.lang.String filePath)
                                throws java.rmi.RemoteException
To cat the content of the indicated file, which is owned by targer user.

Parameters:
owner - The owner of the file
filePath - The path to indicated file.
Returns:
string content of file
Throws:
java.rmi.RemoteException - fail to cat the file.

deleteFile

public static FileDriverResponseParser deleteFile(java.lang.String owner,
                                                  java.lang.String dirPath)
                                           throws java.rmi.RemoteException
To delete the indicated dir or file.

Parameters:
owner - The driver user name.
dirPath - The path to target dir or file. /tmp/GOS-111111/result.txt
Returns:
FileDriverResponseParser instance
Throws:
java.rmi.RemoteException - fail to delete file.

copyContent

public static FileDriverResponseParser copyContent(java.lang.String owner,
                                                   java.lang.String sourceFilePath,
                                                   java.lang.String targetFilePath)
                                            throws java.rmi.RemoteException
To read the content of source file and write to the target file. During this process, owner-changing operation will be done.

Parameters:
owner - The linux user who own the real working dir.
sourceFilePath - The absulote path to the original file, which will be read and in the temp dir.
targetFilePath - The absulote path to the target file, which is in the real working dir
Returns:
FileDriverResponseParser instance containing the invoking result.
Throws:
java.rmi.RemoteException - fail to copy the source to target.

moveFile

public static FileDriverResponseParser moveFile(java.lang.String owner,
                                                java.lang.String sourceFilePath,
                                                java.lang.String targetFilePath)
                                         throws java.rmi.RemoteException
To move source file and write to the target file. During this process, owner-changing operation will NOT be done.

Parameters:
owner - The linux user who own the real working dir.
sourceFilePath - The absulote path to the original file, which will be read and in the temp dir.
targetFilePath - The absulote path to the target file, which is in the real working dir
Returns:
FileDriverResponseParser instance containing the invoking result.
Throws:
java.rmi.RemoteException - fail to mv source to target.

chown

public static FileDriverResponseParser chown(java.lang.String owner,
                                             java.lang.String group,
                                             java.lang.String filePath)
                                      throws java.rmi.RemoteException
to change stagein-file's owner to localUser.

Parameters:
owner - file's owner.
group - owner is belong to this group.
filePath - file's path.
Returns:
FileDriverResponseParser instance containing the invoking result.
Throws:
java.rmi.RemoteException - fail to change owner of the file.

isReadAble

public static FileDriverResponseParser isReadAble(java.lang.String owner,
                                                  java.lang.String filePath)
                                           throws java.rmi.RemoteException
check owner can read filePath or not.

Parameters:
owner - localUser's name
filePath - file's path.
Returns:
FileDriverResponseParser instance containing the invoking result.
Throws:
java.rmi.RemoteException - fail to get whether the file is readable or not.

tail

public static java.lang.String tail(java.lang.String owner,
                                    int lineNumber,
                                    java.lang.String filePath)
                             throws java.rmi.RemoteException
get tail string of the file.

Parameters:
owner - localUser's name.
lineNumber - tail line number of the file.
filePath - file's path.
Returns:
FileDriverResponseParser instance containing the invoking result.
Throws:
java.rmi.RemoteException - fail to get whether the file is readable or not.

isWriteAble

public static FileDriverResponseParser isWriteAble(java.lang.String owner,
                                                   java.lang.String filePath)
                                            throws java.rmi.RemoteException
check owner can write in filePath or not.

Parameters:
owner - localUser's name
filePath - file's path.
Returns:
FileDriverResponseParser instance containing the invoking result.
Throws:
java.rmi.RemoteException - fail to get whether the file is writeable or not.

getFirstExistPath

public static FileDriverResponseParser getFirstExistPath(java.lang.String owner,
                                                         java.lang.String dirPath)
                                                  throws java.rmi.RemoteException
To get the first exist path of the given dirPath.

Parameters:
owner - The owner of the working dir.
dirPath - The path to check.
eg:/home/qiaojian/GOS-ff11111111111111111111111
Returns:
FileDriverResponseParser instance
Throws:
java.rmi.RemoteException - fail to make directory.

doProcess

public static void doProcess(java.lang.String owner,
                             java.lang.String prefix,
                             java.lang.String localJobID,
                             java.lang.String workingDir,
                             java.lang.String processFile)
                      throws java.rmi.RemoteException
do post process in job working directory.

Parameters:
owner - the local user
prefix - the prefix of the file that generate by system
localJobID - job id
workingDir - woring directory
processFile - the file that contain post process command.
Throws:
java.rmi.RemoteException - fail to do process in job working directory.

submit

public static DriverResponseParser submit(java.lang.String owner,
                                          java.lang.String prefix,
                                          java.lang.String workingDir)
                                   throws java.rmi.RemoteException
To submit local batch job.

Parameters:
owner - The linux user who own the real job
prefix - The file prefix of the indicated job
workingDir - The path to the real working dir
Returns:
DriverResponseParser instance containing the invoking result.
Throws:
java.rmi.RemoteException - fail to sumbit the job.

status

public static DriverResponseParser status(java.lang.String owner,
                                          java.lang.String prefix,
                                          java.lang.String localJobID,
                                          java.lang.String workingDir)
                                   throws java.rmi.RemoteException
To query local batch job status.

Parameters:
owner - The linux user who own the real job
prefix - The file prefix of the indicated job
localJobID - The jobId of the indicated pbs/lsf job.
workingDir - The path to the real working dir
Returns:
DriverResponseParser instance containing the invoking result.
Throws:
java.rmi.RemoteException - fail to get status of the job.

cancel

public static DriverResponseParser cancel(java.lang.String owner,
                                          java.lang.String prefix,
                                          java.lang.String localJobID,
                                          java.lang.String workingDir)
                                   throws java.rmi.RemoteException
To cancel local batch job.

Parameters:
owner - The linux user who own the real job
prefix - The file prefix of the indicated job
localJobID - The jobId of the indicated pbs/lsf job.
workingDir - The path to the real working dir
Returns:
DriverResponseParser instance containing the invoking result.
Throws:
java.rmi.RemoteException - fail to cancel the job.

screenOutput

public static DriverResponseParser screenOutput(java.lang.String owner,
                                                java.lang.String prefix,
                                                java.lang.String localJobID,
                                                java.lang.String workingDir)
                                         throws java.rmi.RemoteException
To get the screen output of the indicated local batch job.

Parameters:
owner - The linux user who own the real job
prefix - The file prefix of the indicated job
localJobID - The jobId of the indicated pbs/lsf job.
workingDir - The path to the real working dir
Returns:
DriverResponseParser instance containing the invoking result.
Throws:
java.rmi.RemoteException - fail to get screen-output of the job.

detail

public static DriverResponseParser detail(java.lang.String owner,
                                          java.lang.String prefix,
                                          java.lang.String localJobID,
                                          java.lang.String workingDir)
                                   throws java.rmi.RemoteException
To get the details of the indicated local batch job.

Parameters:
owner - The linux user who own the real job
prefix - The file prefix of the indicated job
localJobID - The jobId of the indicated pbs/lsf job.
workingDir - The path to the real working dir
Returns:
DriverResponseParser instance containing the invoking result.
Throws:
java.rmi.RemoteException - fail to get detail info of the job.

stdOutErr

public static DriverResponseParser stdOutErr(java.lang.String owner,
                                             java.lang.String prefix,
                                             java.lang.String localJobID,
                                             java.lang.String workingDir)
                                      throws java.rmi.RemoteException
To get the stdout and stderr file name of the indicated local batch job.

Parameters:
owner - The linux user who own the real job
prefix - The file prefix of the indicated job
localJobID - The jobId of the indicated pbs/lsf job.
workingDir - The path to the real working dir
Returns:
DriverResponseParser instance containing the invoking result.
Throws:
java.rmi.RemoteException - fail to get standand ouput or standard error output.

deleteTempAfterFailed

public static void deleteTempAfterFailed(JobInstance pJob)
To delete the temp dir after setting the job as failed! Just try once :)

Parameters:
pJob - The job instance which own the temp Dir.

readProxy

public static byte[] readProxy(java.lang.String proxyPath)
                        throws java.lang.Exception
To read the proxy content.

Parameters:
proxyPath - the path of the proxy file.
Returns:
byte[] proxy the content of the proxy file.
Throws:
java.lang.Exception - fail to read proxy file.

string2File

public static boolean string2File(java.lang.String src,
                                  java.lang.String fn)
create a file in the intended location , and then inject the content into this file.

Parameters:
src - content which should be written into the created file
fn - file location which will be created
Returns:
true if success

string2FileAppend

public static boolean string2FileAppend(java.lang.String src,
                                        java.lang.String fn)
To write the string into the indicated file.

Parameters:
src - the content you want to set to a file.
fn - file name.
Returns:
true if success

string2Document

public static org.w3c.dom.Document string2Document(java.lang.String str)
convert a XML String into the XML Document object.

Parameters:
str - xml String.
Returns:
Document instance from string content

getPureName

public static java.lang.String getPureName(java.lang.String path)
get the pure name , pure name means the name without path information. e.g: pure name of "d:/1234/newfolder/1.txt" is "1.txt"

Parameters:
path - path name.
Returns:
pure name string

getElementBody

public static java.lang.String getElementBody(org.w3c.dom.Document d,
                                              java.lang.String name)
get element body using name from document d.

Parameters:
d - document instance.
name - element tag name.
Returns:
elementbody string

execProcess

public static java.lang.String execProcess(java.lang.String _cmdline,
                                           java.lang.String _homedir)
execute the command-line command in the home directory _homedir.

Parameters:
_cmdline - command.
_homedir - home directory.
Returns:
stdout content string of this process

file2String

public static java.lang.String file2String(java.lang.String fn)
read the content of a file whose path is given in fn value , and change the format to String.

Parameters:
fn - file name.
Returns:
file content string

listZipEntry

public static java.lang.String[] listZipEntry(java.lang.String zipLocation)
                                       throws java.lang.Exception
handle zip file.

Parameters:
zipLocation - zip file path.
Returns:
String[] zip entries
Throws:
java.lang.Exception - fail to list zip entry of the file.

UnZip

public static void UnZip(java.lang.String zipLocation,
                         java.lang.String toDir)
                  throws java.lang.Exception
unzip . it is for the use of blaster

Parameters:
zipLocation - zip file path.
toDir - unzip file to this directory.
Throws:
java.lang.Exception - fail to unzip the file.

UnZipEntry

public static void UnZipEntry(java.io.File dir,
                              java.io.InputStream zinputStream,
                              java.lang.String entryName,
                              boolean isDirectory)
                       throws java.io.IOException
unzip.

Parameters:
dir -
zinputStream -
entryName -
isDirectory -
Throws:
java.io.IOException

ZipFiles

public static boolean ZipFiles(java.util.List list,
                               java.lang.String zipname,
                               boolean type)
                        throws java.lang.Exception
Parameters:
list -
zipname -
type -
Returns:
true if success
Throws:
java.lang.Exception

formalizePath

public static java.lang.String formalizePath(java.lang.String p,
                                             java.lang.String h)
used when generate original job script

Parameters:
p -
h -
Returns:
formalizePath string

ZipFiles

public static boolean ZipFiles(java.lang.String[] files,
                               java.lang.String zipname,
                               boolean type)
                        throws java.lang.Exception
Parameters:
files -
zipname -
type -
Returns:
true if ZipFiles success
Throws:
java.lang.Exception


Copyright © 2008. All Rights Reserved.