Before reading this user guide, you are reminded you must already satifised the prerequisites(obtain a valid personal certificate signed from trusted CA & have access right to HKU campus network) and before going through the following steps.

1. Get approval from TWgrid VOMS:
Assume that you already own a personal certificate from trusted CA as mentioned in prerequisites section, then you should have a personal certificate file (pkcs12 format) and the personal certificate password.

TWGRID VO Website: https://voms.grid.sinica.edu.tw:8443/voms/twgrid/

2. Login to UI and import your personal certificate:
After getting approval to use twgrid VOMS, you can ask system administrator to create an account in UI server(glite04.grid.hku.hk). Then you can connect glite04.grid.hku.hk from HKU campus network by SSH and also upload your personal certificate file(pkcs12 format). Then you have to create a .globus folder and put your personal certificate to this folder. You have to convert your personal certificate file(pkcs12 format) into PEM certificate file(usercert.pem) and private key file(userkey.pem) as well.


[linux]$ cd
[linux]$ mkdir .globus
[linux]$ mv my_cert.p12 .globus
[linux]$ cd .globus
[linux]$ openssl pkcs12 -nocerts -in my_cert.p12 -out key.pem
Type your personal certificate password
[linux]$ openssl rsa -in key.pem -out userkey.pem
Type your personal certificate password
[linux]$ rm -f key.pem
[linux]$ openssl pkcs12 -nokeys -clcerts -in my_cert.p12 -out usercert.pem
Type your personal certificate password
[linux]$ chmod 400 userkey.pem
[linux]$ chmod 644 usercert.pem

Important: The usercert.pem file generated in this way may also contain the private key information. You must use editor (e.g. vi) to delete lines of private key information at the beginning of the usercert.pem file.
Make sure the usercert.pem file begin as the following lines (or similar):
-----BEGIN CERTIFICATE-----
MIIFAjCCA+qgAwIBAgIBATANBgkqhkiG9w0BAQUFADBXMRIwEAYKCZImiZPyLGQB
GRYCQ04xFDASBgoJkiaJk/IsZAEZFgRHcmlkMSswKQYDVQQDDCJSb290IENlcnRp
....
Afterward make sure both userkey.pem and usercert.pem file exist in the .globus folder

3. Initalize a valid proxy session and check the current proxy session:
At your account there is a sample-job folder contains a few sample scripts.
Now you may initialize a valid proxy session using ‘init-proxy.sh‘ at the sample-job folder.


[linux]$ cd sample-job
[sample-job]$ sh init-proxy.sh
Make sure you already uploaded cert and joined TWGrid VO
Contacting voms.grid.sinica.edu.tw:15010 [/C=TW/O=AS/OU=GRID/CN=voms.grid.sinica.edu.tw] "twgrid"...
Remote VOMS server contacted succesfully.

Created proxy in /tmp/x509up_u501.

Your proxy is valid until Tue Dec 18 14:51:41 2015
subject   : /DC=HK/DC=HKU/DC=GRID/O=HKU/OU=CC/CN=Yuk Lin Chan (12345)/CN=proxy
issuer    : /DC=HK/DC=HKU/DC=GRID/O=HKU/OU=CC/CN=Yuk Lin Chan (12345)
identity  : /DC=HK/DC=HKU/DC=GRID/O=HKU/OU=CC/CN=Yuk Lin Chan (12345)
type      : proxy
strength  : 1024 bits
path      : /tmp/x509up_u501
timeleft  : 23:59:59
key usage : Digital Signature, Key Encipherment, Data Encipherment
=== VO twgrid extension information ===
VO        : twgrid
subject   : /DC=HK/DC=HKU/DC=GRID/O=HKU/OU=CC/CN=Yuk Lin Chan (12345)
issuer    : /C=TW/O=AS/OU=GRID/CN=voms.grid.sinica.edu.tw
attribute : /twgrid/Role=NULL/Capability=NULL
timeleft  : 23:59:59
uri       : voms.grid.sinica.edu.tw:15010

And then you may check the proxy information by ‘check-proxy.sh‘ at the sample-job folder.

[sample-job]$ sh check-proxy.sh 
subject   : /DC=HK/DC=HKU/DC=GRID/O=HKU/OU=CC/CN=Yuk Lin Chan (12345)/CN=proxy
issuer    : /DC=HK/DC=HKU/DC=GRID/O=HKU/OU=CC/CN=Yuk Lin Chan (12345)
identity  : /DC=HK/DC=HKU/DC=GRID/O=HKU/OU=CC/CN=Yuk Lin Chan (12345)
type      : full legacy globus proxy
strength  : 1024 bits
path      : /tmp/x509up_u501
timeleft  : 23:59:52
key usage : Digital Signature, Key Encipherment, Data Encipherment
=== VO twgrid extension information ===
VO        : twgrid
subject   : /DC=HK/DC=HKU/DC=GRID/O=HKU/OU=CC/CN=Yuk Lin Chan (12345)
issuer    : /C=TW/O=AS/OU=GRID/CN=voms.grid.sinica.edu.tw
attribute : /twgrid/Role=NULL/Capability=NULL
timeleft  : 23:59:52
uri       : voms.grid.sinica.edu.tw:15010

4. List the available CE and SE at the VO:
After having a valid proxy session, you may do some simple query first to check the available resources at twgrid VO.
e.g. List the computing elements: lcg-infosites –vo twgrid ce

[sample-job]$ lcg-infosites --vo twgrid ce
#   CPU   Free Total Jobs  Running Waiting ComputingElement
-------------------------------------------------------------
     48     48          0        0       0 as-ce01.euasiagrid.org:8443/cream-pbs-twgrid
      8      8          0        0       0 glite02.grid.hku.hk:8443/cream-pbs-twgrid

e.g. List the storage elements:lcg-infosites –vo twgrid [se /closeSE]

[sample-job]$ lcg-infosites --vo twgrid se
 Avail Space(kB)  Used Space(kB)  Type  SE
------------------------------------------
       120941903        21400182  SRM   as-ds01.euasiagrid.org
     82463372083             n.a  gftp  f-dpm001.grid.sinica.edu.tw
      4360423615    415966494114  gftp  f-dpm001.grid.sinica.edu.tw
      1027069603        55050186  SRM   glite01.grid.hku.hk
    114561980893      6384298162  SRM   tw-dpm01.grid.sinica.edu.tw
      5497436536          121602  SRM   tw-dpm01.grid.sinica.edu.tw
        48240252        20734150  SRM   w-dpm01.grid.sinica.edu.tw
[sample-job]$ lcg-infosites --vo twgrid closeSE
Name of the CE: glite02.grid.hku.hk:8443/cream-pbs-twgrid
        glite01.grid.hku.hk

5. Prepare the job script and the JDL(job description language) file:
You have to prepare JDL(Job Description Language) file to tell grid resource broker about the property of your job. This is a simple example of JDL file named ‘job1.jdl‘:

[
Executable = "job1.sh"; 
Arguments = "Hello world!";
StdOutput = "std.out"; 
StdError = "std.err"; 
InputSandbox = {"/home/[user]/sample-job/job1.sh"}; 
OutputSandbox = {"std.err","std.out"}; 
OutputSandboxBaseDestURI = "gsiftp://glite01.grid.hku.hk/dpm/grid.hku.hk/home/twgrid/[user]";
]

This JDL would make the executable ‘job1.sh‘ transferred to the remote CREAM CE and run with arguments ‘Hello world!‘. A detailed description of the available JDL attributes and of the rules for building correct JDL files is provided at JDL Guide.

A simple executable ‘job1.sh‘ for demo:

echo $1
/usr/bin/id
/bin/hostname
/bin/uname -a
/bin/date

6. Submitting the job:
Now you can submit your job by specifying the JDL file and the Job-ID file (Job-ID file is to store the identities of submitted jobs):
./job-submit.sh [jdl-file] [job-id-file]

[sample-job]$ ./job-submit.sh job1.jdl job1.jid
https://glite02.grid.hku.hk:8443/CREAM719410123

7. Checking the job status:
You can then check the job running status by the job ID file:
./job-checkstatus.sh [job-id-file]

[sample-job]$./job-checkstatus.sh job1.jid
******  JobID=[https://glite02.grid.hku.hk:8443/CREAM719410123]
        Status        = [REALLY-RUNNING]

This status “[REALLY_RUNNING]” means the job is running.

[sample-job]$./job-checkstatus.sh job1.jid
******  JobID=[https://glite02.grid.hku.hk:8443/CREAM719410123]
        Status        = [DONE-OK]
        ExitCode      = [0]

The job status is “DONE-OK” that mean the job was executed. You may check the return code to see if it is successful or not.

8. Fetch the job output/error files:
After you are sure that you job was completed (by checking the status to be ‘Done’), you can fetch the output and error file from remote grid systems by ‘glite-ce-job-output’. The fetched files will be copied to a folder under current directory.
./job-getresult.sh [job-id-file]

[sample-job]$./job-getresult.sh job1.jid
2015-12-18 10:42:05,480 INFO - For JobID [https://glite02.grid.hku.hk:8443/CREAM719410123] output will be stored in the dir ./glite02.grid.hku.hk_8443_CREAM719410123

9. Check the job output/error files:
Then you can change the path to the output folder to view the output file.

[sample-job]$ cd glite02.grid.hku.hk_8443_CREAM719410123
[glite02.grid.hku.hk_8443_CREAM719410123]$ ls
std.err   std.out
[glite02.grid.hku.hk_8443_CREAM719410123]$ cat std.out
Hello world!
uid=22116(twgrid007) gid=1088(twgrid)  groups=1088(twgrid)
glite02.grid.hku.hk
Linux glite02.grid.hku.hk 2.6.32-xxx.el6.x86_64 #1 SMP xxxxxx 2015 x86_64 x86_64 x86_64 GNU/Linux
Fri Dec  18  10:09:00 UTC 2015