GRAM4 Audit
From TeraGrid Wiki
←Older revision | Newer revision→
Contents |
TeraGrid Audit-enabled GRAM Services
Audit enabled GRAM services have been installed on the TG node "tg-grid.uc.teragrid.org".
Contact Strings:
(1) GRAM2: tg-grid.uc.teragrid.org:2121/jobmanager-pbs
(2) GRAM4: tg-grid.uc.teragrid.org:9554
Command line clients and the portal can use the above contact string to contact the service.
Command Line Job Submission Example
(1) GRAM2: The following example submits a /bin/date job to the audit enabled GRAM2 service. The -batch option has been added to get the job contact.
globusrun -r tg-grid.uc.teragrid.org:2121/jobmanager-pbs "&(executable=/bin/date)" -batch
(2) GRAM4: The following example submits a /bin/date job to the audit
enabled GRAM4 service. The -o option has been added to provide a file
to save the job contact information.
globusrun-ws -submit -o jobEpr PBS -F tg-grid.uc.teragrid.org:9554 -c /bin/date
Converting GRAM4 EPR to Grid Job Id
The GRAM4 job submission returns an EPR that points to the job. This need to be converted into a Grid Job Id to be able to perform usage queries. A utility class EPRUtil.java is provided with the method that does the conversion. This class is distributed as a standard function in GT 4.2, but can be downloaded as a separate jar for GT 4.0.x installation.
Along with the utility a command line client that can be used to convert an EPR to string is provided. The command line client is specific to GRAM (i.e it converts GRAM job EPRs) and uses the generic utility. Both these can be deployed into any GT 4.0.x installation which has WS GRAM deployed.
(1) Download the EPR Utility GAR. This contains both a utility and
a command line client to convert EPR to Grid Job Id.
(2) Copy gar to $GLOBUS_LOCATION
(3) Deploy the gar. Note that Ant needs to be installed for this to work.
cd $GLOBUS_LOCATION
bin/globus-deploy-gar globus_epr_util.gar
(4) Command line client maybe used as follows. The Grid Job Id will be printed to standard out.
$GLOBUS_LOCATION/bin/globus-epr-to-gridid -e jobEpr
(5) To programmatically incorporate the conversion, use the following code snippet.
import org.apache.axis.message.addressing.EndpointReferenceType;
import java.io.FileInputStream;
import org.xml.sax.InputSource;
import org.globus.wsrf.impl.security.util.EPRUtil;
String jobGridId = null;
jobEndpoint = null;
FileInputStream in = null;
// Key QName. For GRAM4 it is, ManagedJobConstants.RESOURCE_KEY_QNAME,
QName qName = keyQName;
// Key type class. For GRAM it is String.class
Class clazz = String.class; try {
// this is the file used as paramter for option -o
in = new FileInputStream(eprFileName);
EndpointReferenceType jobEndpoint =
(EndpointReferenceType)ObjectDeserializer.deserialize(
new InputSource(in),
EndpointReferenceType.class);
jobGridId = EPRUtil.getEPRAsString(jobEndpoint,
qName, clazz);
} catch (Exception e) {
// Throw relevant exception and add error logs
} finally {
if (in != null) {
try { in.close(); } catch (Exception e) {}
}
}
Querying usage information
Local Commandline Usage query
Usage query clients have been installed on tg-grid1.uc.teragrid.org. After a remote job submit using either GRAM2 or GRAM4 service, job contact string can be used to run installed client on the local machine.
Note that for GRAM4 you will need to convert EPR to Grid Job Id.
(1) Set GLOBUS_LOCATION to /home/globus/Audit/globus (2) Copy /home/lane/demo-client to your working directory. (3) Refer to next section for information on querying audit and account information separately. (4) Run the following:
./demo-client https://tg-grid1.uc.teragrid.org:9554/wsrf/services/ogsadai/Teragrid TeraGridResource https://tg-grid1.uc.teragrid.org:9554/wsrf/services/ManagedExecutableJobService?Tb1eLvO6mVl/Of9KGw9nSOmgGmU=
Note:
- You have to replace the last parameter with your GRAM4 Job Grid Id or GRAM2 job contact string.
- This will work only when the central accounting database has been updated.
The output of the sample command is as follows:
Service URL: https://tg-grid1.uc.teragrid.org:9554/wsrf/services/ogsadai/Teragrid Data Service Resource ID: TeraGridResource Grid Job ID: https://tg-grid1.uc.teragrid.org:9554/wsrf/services/ManagedExecutableJobService? Tb1eLvO6mVl/Of9KGw9nSOmgGmU= User's DN: /DC=org/DC=doegrids/OU=People/CN=Peter G Lane 364243 The charge for this job is: 0.00384666666666667
This is an example of how a custom client should format the XML documents returned by OGSA DAI clents and processed using an API and formatted for human consumption.
Programmatic Query
This is a mechanism where OGSA DAI client side API can be used to
remotely obtain usage query information. Gateways can use this
mechanism to obtain usage information by either by incoporating OGSA
DAI Client side code.
(1) Install the OGSA DAI code jars.
- Download OGSA DAI Core jars - Untar and place all jars in $GLOBUS_LOCATION/lib
(2) Install the OGSA DAI TeraGrid specific jar
- Download TeraGrid Specific OGSA DAI Clients - Copy the jar to $GLOBUS_LOCATION/lib
(3) Refer to Demo Client Code for code on retrieving usage programmatically.
Other queries
Audit Query
Following is an example perform document that simulates the first half of what OGSA-DAI would do in a charge query:
<?xml version="1.0" encoding="UTF-8"?> <perform xmlns="http://ogsadai.org.uk/namespaces/2005/10/types"> <documentation> This example performs a simple select statement to retrieve one row from the test database. The results are delivered within the response document. </documentation> <sqlQueryStatement name="statement"> <expression>select local_job_id,queued_time from gram_audit_table where job_grid_id='https://tg-grid1.uc.teragrid.org:9554/wsrf/services/ManagedExecutableJobService?Tb1eLvO6mVl/Of9KGw9nSOmgGmU=' AND subject_name='/DC=org/DC=doegrids/OU=People/CN=Peter G Lane 364243' </expression> <resultStream name="statementOutputRS"/> </sqlQueryStatement> <sqlResultsToXML name="statementRSToXML"> <resultSet from="statementOutputRS"/> <webRowSet name="statementOutput"/> </sqlResultsToXML> </perform>
If you save this to a file named, say, ./perform_audit.xml, then you can execute the following command using the "ogsadai-client" found in my /home/lane on tg-grid1:
./ogsadai-client -u https://tg-grid1.uc.teragrid.org:9554/wsrf/services/ogsadai/Teragrid -k \ Audit_tg-grid1.uc.teragrid.org -tls encrypt ./perform_audit.xml
This will query the audit database through OGSA-DAI using the query specified in the above perform document. The value of the -k option is an arbitrary resource key I picked for associating with audit queries.
The will return the following result document on stdout:
<?xml version="1.0" encoding="UTF-8"?> <ns1:response xmlns:ns1="http://ogsadai.org.uk/namespaces/2005/10/types"> <ns1:session id="session-ogsadai-10c2730f792"/> <ns1:request status="COMPLETED"/> <ns1:result name="statement" status="COMPLETED"/> <ns1:result name="statementRSToXML" status="COMPLETED"/> <ns1:result name="statementOutput" status="COMPLETED"> <![CDATA[<webRowSet xmlns="http://java.sun.com/xml/ns/jdbc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/jdbc http://java.sun.com/xml/ns/jdbc/webrowset.xsd"> <properties> <command></command> <concurrency>1007</concurrency> <datasource></datasource> <escape-processing>true</escape-processing> <fetch-direction>1000</fetch-direction> <fetch-size>0</fetch-size> <isolation-level>0</isolation-level> <key-columns></key-columns> <map></map> <max-field-size>0</max-field-size> <max-rows>0</max-rows> <query-timeout>0</query-timeout> <read-only>true</read-only> <rowset-type>ResultSet.TYPE_FORWARD_ONLY</rowset-type> <show-deleted>false</show-deleted>
<url></url> <sync-provider> <sync-provider-name/> <sync-provider-vendor/> <sync-provider-version/> <sync-provider-grade/> <data-source-lock/> </sync-provider> </properties> <metadata> <column-count>2</column-count> <column-definition> <column-index>1</column-index> <auto-increment>false</auto-increment> <case-sensitive>true</case-sensitive> <currency>false</currency> <nullable>1</nullable> <signed>false</signed> <searchable>true</searchable> <column-display-size>512</column-display-size> <column-label>local_job_id</column-label> <column-name>local_job_id</column-name> <schema-name></schema-name> <column-precision>512</column-precision> <column-scale>0</column-scale>
<catalog-name></catalog-name> <column-type>12</column-type> <column-type-name>varchar</column-type-name> </column-definition> <column-definition> <column-index>2</column-index> <auto-increment>false</auto-increment> <case-sensitive>false</case-sensitive> <currency>false</currency> <nullable>1</nullable> <signed>false</signed> <searchable>true</searchable> <column-display-size>26</column-display-size> <column-label>queued_time</column-label> <column-name>queued_time</column-name> <schema-name></schema-name> <column-precision>0</column-precision> <column-scale>6</column-scale>
<catalog-name></catalog-name> <column-type>93</column-type> <column-type-name>timestamp</column-type-name> </column-definition> </metadata> <data><currentRow> <columnValue>287254.tg-master.uc.teragrid.org</columnValue> <columnValue>2006-06-22 15:44:10</columnValue> </currentRow></data> </webRowSet>]]></ns1:result> </ns1:response>
The interesting part is the 5th and 4th to last lines ("<columnValue>" elements), and from now on I'll cut the boring stuff out. Ideally a custom client would be created that converts the XML document into a data structure that can be walked through via an API. At any rate, this results document gives the values of the columns we requested (logal_job_id and queued_time). Specifically, these values are "288114.tg-master.uc.teragrid.org" and "2006-06-30 21:09:44".
Changing the <expression> element in the above perform document to the following:
<expression> select local_job_id,queued_time from gram_audit_table where username='lane' </expression>
will yield the following result when the ogsadai-client command is run again:
[...] <data><currentRow> <columnValue>3d985e94-0221-11db-8a3d-0007e9d81215:2624</columnValue> <columnValue>2006-06-22 13:59:32</columnValue> </currentRow><currentRow> <columnValue>287254.tg-master.uc.teragrid.org</columnValue> <columnValue>2006-06-22 15:44:10</columnValue> </currentRow><currentRow> <columnValue><null/></columnValue> <columnValue><null/></columnValue> </currentRow><currentRow> <columnValue><null/></columnValue> <columnValue><null/></columnValue> </currentRow><currentRow> <columnValue>288114.tg-master.uc.teragrid.org</columnValue> <columnValue>2006-06-30 21:09:44</columnValue> </currentRow></data> </webRowSet>]]></ns1:result> </ns1:response>
The <columnValue> elements contain the local_job_id and queued_time data for each job that user "lane" has submitted to this compute resource.
For the LEAD Project, we created an OGSA-DAI client to the auditing service that may be useful for others. You can download the auditing-ogsadai-client-0.1 tarball. To see how to use this client, see the included Demo.java file. - Marcuschristie
Accounting Query
Now copy the audit perform document and name it perform_accounting.xml. Change the <expression> element to the following:
<expression> select charge from jobs where local_jobid='287254.tg-master.uc.teragrid.org' and resource_name='dtf.anl.teragrid' and '2006-06-22 15:44:10' between submit_time - INTERVAL '24 hours' and submit_time + INTERVAL '24 hours' </expression>
The above query is an example of a query OGSA-DAI might make to the accounting database after it has obtained the results from the first audit query example above.
Execute the following command to query the accounting database via OGSA-DAI using the new perform document:
./ogsadai-client -u https://tg-grid1.uc.teragrid.org:9554/wsrf/services/ogsadai/Teragrid -k
TeragridAccounting -tls encrypt ./perform_accounting.xml
Notice that I changed the value of the -k option to "TeragridAccounting". Again, this is an arbitrary resource key. In this case it is associated with performing queries to the TeraGrid-wide accounting database. The results of the command are as follows:
[...] <data><currentRow> <columnValue>0.00384666666666667</columnValue> </currentRow></data> </webRowSet>]]></ns1:result> </ns1:response>
So the charge on the job with Grid ID "https://tg-grid1.uc.teragrid.org:9554/wsrf/services/ManagedExecutableJobService?Tb1eLvO6mVl/Of9KGw9nSOmgGmU=" has a charge of "0.00384666666666667".
For the LEAD Project, we created an OGSA-DAI client to the accounting service that may be useful for others. You can download the auditing-ogsadai-client-0.1 tarball. To see how to use this client, see the included Demo.java file. - Marcuschristie
