Lesson 6: Portlet for job submission - oar.sci-gaia.eu · PDF fileo Customization script....

Preview:

Citation preview

This project has received funding from the European Union’s Horizon 2020

research and innovation programme under grant agreement n° 654237

Lesson 6: Portlet for job submission

Mario Torrisi – University of Catania - Italy (mario.torrisi@ct.infn.it)

Sci-GaIA Winter School

2

Outline

MyJob portleto G&C Engine monitoring module

o UsersTracking database

Portlet Templateo Get portlet code

o Build and deploy

o Job submission and log inspection

Portlet codeo Code structure

o Java Classes

o processInputFile() method

o submitjob() method

o Customization script

MyJobs Portlet

4

MyJobs portlet

Is a core component of the Catania Science Gateway

Framework

Allows users to manage their jobs on DCIs

o Check jobs status

o Retrieve output when jobs complete their execution

MyJobs.war

Interacts with the Grid & Cloud

Engine Monitoring module

You can simply download and

deploy MyJobs portlet into your

Science Gateway

5

MyJobs Portlet

Download

o http://grid.ct.infn.it/csgf/binaries/MyJobs.war

Deploy

o cp /path/to/MyJobs.war /path/to/plugin-sdk/dist

o Check server.log file, you should see MyJobs was successfully deployed

Add MyJobs to page

6

MyJobs Portlet

Active Job

List

Done Job

List

Job status

Job Label

7

User Tracking Database

Each user action which involves the distributed

infrastructure will be tracked by the UsersTracking

Database

Download sql script from here to create the Users Tracking

Database schema

The G&C Engine uses the GridOperations table to

register applications and services accessing the distributed

infrastructure

mysql> describe GridOperations;+-------------+--------------+------+-----+---------+----------------+| Field | Type | Null | Key | Default | Extra |+-------------+--------------+------+-----+---------+----------------+| id | int(11) | NO | PRI | NULL | auto_increment || portal | varchar(120) | NO | | NULL | || description | varchar(200) | NO | | NULL | |+-------------+--------------+------+-----+---------+----------------+3 rows in set (0.00 sec)

8

GridOperations table

How to get GridOperations values

o id – application identifier

o portal – portal name, see picture below to get the right value

o description – human readable application label

Application registration in the GridOperations table is

mandatory for the MyJobs portlet

+-------------+| Field |+-------------+| id || portal || description |+-------------+

9

MyJobs Portlet

In order to MyJobs Portlet (and all the other applications)

works properly you need to create a JDBC Connection

Pool and JDBC Resources in the application server, used

by the G&C Engine to communicate with the Users

Tracking Database.o JDBC Connection Pool is a group of reusable connections for a particular

database1

o JDBC resource (data source) provides applications with a means of

connecting to a database.[ … ] A JDBC resource is identified by its Java

Naming and Directory Interface (JNDI) name1

1 https://docs.oracle.com/cd/E26576_01/doc.312/e24928/jdbc.htm#GSADG00576

10

Application server

JDBC Connection Pool/Resource

G&C Engine

JNDI Resource

Users Tracking

Database

JDBC Driver

Connection Pool

connection

connection

connection

connection

lookup

SQL connection

11

JDBC Connection Pool/Resource

To create JDBC Connection Pool and JDBC Resource you

can

1. Edit the domain.xml file

/path/to/liferay-bundle/glassfish-3.1.2/…/config/domain.xml

Look for <resources> tag

Add an new connection pool using the properties highlighted in next

slide, pay attention to set the right address of DB container

• Tip check the docker inspect command

Add two jdbc resources using the properties highlighted in next slide

Look for <servers> tag

Add two jndi resources as shown in the next slide to allow lookup

Save and close file

Restart domain

2. Configure them through the Glassfish Web Admin interface

12

Here what you should have in your domain.xml file

JDBC Connection Pool

<resources>

...

<jdbc-connection-pool driver-classname="" datasource-

classname="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource" res-

type="javax.sql.ConnectionPoolDataSource" description="" name="UsertrackingPool">

<property name="User" value="tracking_user"></property>

<property name="Url"

value="jdbc:mysql:// :3306/userstracking"></property>

<property name="Password" value="usertracking"></property>

</jdbc-connection-pool>

<jdbc-resource pool-name="UsertrackingPool" description="" jndi-

name="jdbc/UserTrackingPool"></jdbc-resource>

<jdbc-resource pool-name="UsertrackingPool" description="" jndi-

name="jdbc/gehibernatepool"></jdbc-resource>

...

<resources/>

<servers>

<server name=”server” config-ref="server-config">

<resource-ref ref="jdbc/UserTrackingPool"></resource-ref>

<resource-ref ref="jdbc/gehibernatepool"></resource-ref>

...

<servers/>

13

JDBC Connection Pool

1

2

3

14

JDBC Resource

1

2

3

Template Portlet

16

Template Portlet

The Template Portlet is a complete example of portlet able

to submit a sequential Job into a distributed environment.

Its Java code extends the Liferay MVCPortlet class and

uses JSP pages to generate the input GUI

17

Template Portlet(Features)

It provides a full example of:

o Defining distributed infrastructure settings where the application will run

o Managing input elements from web forms as application input

o Managing upload file requests

o Managing portlet configuration to handle distributed infrastructure settings

o Viewing/Managing the ‘pilot_script’ that contains the batch instructions that will be executed on the remote.

It is a multi-infrastructure multi-middleware portlet to execute the same application on several infrastructures and middleware (currently supports: gLite-based Grids, HPC Clusters, Cloud resources)

It can be used as starting point to develop your own applications

o A customization script is provided in order make its reuse easy

18

Template Portlet(Build & Deploy)

Clone the source repository

o cd /path/to/plugin-sdk/portlet

o git clone https://github.com/sci-gaia/template-portlet.git

o cd template-portlet

o ant deploy

Add to page

19

Template Portlet(Usage)

template-portlet

o Performs the hostname command on DCIs

You can consider it like ‘HelloWorld’ while approaching new

programming languages

o It accepts:

An input file in order to show how to manage file as input of a real

application

A job label string in order to organize users interactions in the MyJobs

portlet (Optional)

o It has two buttons:

Submit: to submit job

Cancel: to reset form fields

20

Template Portlet(Job submission)

Now you are …

… almost ready to submit jobs

A few mandatory steps are missing

21

Template Portlet(Configuration)

Tip: insert the right values in GridOperations table

Add

infrastructure

Manage

infrastructure

View / Edit

pilot_script

22

Template Portlet(Configuration – Infrastructure Management)

23

Before testing the job execution

Install Grid CA certificates, follow instruction for your system from here

Download the tar at this link2 and extract it in the /etc/grid-security/ folder of your liferay container. It contains a directory for each trusted VO. Inside each VO directory two types of files can be found:o An LSC file contains a description of the certificate chain of the certificate used

by a VOMS server to sign VOMS attributes.

o An X509 certificates used by a VOMS server to sign attributes

Open the VPN or be sure the eTokenserver allows incoming connections on port 8082 form your portal IP address

Check the eTokenserver service is reachableo Connect to http://etokenserver2.ct.infn.it:8082/eTokenServer/

o From the interface generate the robot proxy request

o Execute curl or wget on the generated request

2 http://italiangrid.github.io/voms/documentation/voms-clients-guide/3.0.3/

24

Template Portlet(Job submission)

Select a file

(optional)

Specify a label

(optional)

25

Job Execution(Log inspection)

Liferay server.log file reports:

o A full dump of the portlet preference values

o The GridEngine Initialization

o The Robot proxy retrieval

[mi_hostname_portlet:108] dump:Infrastructure #1

enableInfrastructure : 'yes'nameInfrastructure : 'EUMEDGRID-Support infrastructure'acronymInfrastructure: 'EUMEDGRID'

INFO JSagaJobSubmission - Getting adaptor name...JSagaJobSubmission - Using adaptor: wms

INFO RobotProxy - proxyPath=/tmp/7f7e1e98-0fd1-4ebb-a1ae-0627efddf600INFO RobotProxy - get proxy: http://etokenserver.ct.infn.it:8082/eTokenServer/eToken/332576f78a4fe70a52048043e90cd11f?voms=gridit:gridit&proxy-renewal=true

26

Job Execution(Log inspection)

The JSAGA job submission string

The input sandbox file transfers

The job id and the job status thread execution

INFO JSagaJobSubmission - jobSandbox:/opt/liferay-portal-6.1.1-ce-ga2/glassfish-3.1.2/domains/domain1/autodeploy/mi-hostname-portlet/WEB-INF/job/pilot_script.sh>pilot_script.sh,/tmp/20130717133558_test_input_file.txt>20130717133558_test_input_file.txt,/tmp//jobOutput/multiinfrastructuredemojobdescription1_1/<hostname-Output.txt,/tmp//jobOutput/multiinfrastructuredemojobdescription1_1/<hostname-Error.txt

Connecting to Gsiftp service at: wms014.cnaf.infn.it:2811...

JSagaJobSubmission - Job Submitted: [wms://wms014.cnaf.infn.it:7443/glite_wms_wmproxy_server]-[https://wms014.cnaf.infn.it:9000/kznSb62LcqCW0fXTiTfr7Q]UsersTrackingDBInterface - UpdateJobsStatusAsync running in Thread : Thread[pool-103-thread-1,5,grizzly-kernel]

Portlet Code

28

Portlet code(Code structure)

29

AppInfrastructureInfo.javao This class extends InfratructureInfo G&C Engine class to provide

some other useful methods

AppInput.java

o This class is meant to collect all application GUI inputs and must be dynamically instantiated inside the action method as soon as the user press the ‘Submit’ button

AppPreferences.java

o Class that contains all portlet’s preferences values

ConfigurationActionImpl.java

o This class implements ConfigurationAction Liferay interface

o Manage the code for portlet configuration

TemplatePortlet.java

o We will see this class more in depth later …

Portlet code(Java Classes)

30

Portlet code(Java Classes)

Constats.java

o This class is meant to collect application constants

Utils.java

o This class is used to manage useful methods that interact with:

Application preferences

file2String(), string2File() methods

G&C Engine infrastructure parameters conversion

31

Portlet code(TemplatePortlet.java)

32

ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest

.getAttribute(WebKeys.THEME_DISPLAY);

User user = themeDisplay.getUser();

String username = user.getScreenName();

appInput.setUsername(username);

Gets AppPreferences and AppInfrastructureInfo from portlet

preferences

Gets username using Liferay API

Action method

@ProcessAction(name = "submit")

public void submit(ActionRequest actionRequest,

ActionResponse actionResponse) throws IOException, PortletException {

AppInput appInput = new AppInput();

PortletPreferences preferences = actionRequest.getPreferences();

String JSONAppPrefs = GetterUtil.getString(preferences.getValue(

Constants.APP_PREFERENCES, null));

AppPreferences appPrefs = Utils.getAppPreferences(JSONAppPrefs);

String JSONAppInfras = GetterUtil.getString(preferences.getValue(

Constants.APP_INFRASTRUCTURE_INFO_PREFERENCES, null));

33

Action method

UploadPortletRequest uploadRequest = PortalUtil

.getUploadPortletRequest(actionRequest);

File uploadedFile = processInputFile(uploadRequest, username,

timestamp, appInput);

List<AppInfrastructureInfo> enabledInfras = Utils

.getEnabledInfrastructureInfo(JSONAppInfras);

if (enabledInfras.size() > 0) {

InfrastructureInfo infrastructureInfo[] = Utils

.convertAppInfrastructureInfo(enabledInfras);

submitJob(appPrefs, appInput, infrastructureInfo);

Extracts UploadRequest from ActionRequest, calls processInputfile()

method and then submitJob()

34

private File processInputFile(UploadPortletRequest uploadRequest,

String username, String timestamp, AppInput appInput)

throws IOException {

File file = null;

String fileInputName = "fileupload";

String sourceFileName = uploadRequest.getFileName(fileInputName);

if (Validator.isNotNull(sourceFileName)) {

_log.debug("Uploading file: " + sourceFileName + " ...");

String fileName = FileUtil.stripExtension(sourceFileName);

_log.debug(fileName);

appInput.setInputFileName(fileName);

String extension = FileUtil.getExtension(sourceFileName);

_log.debug(extension);

// Get the uploaded file as a file.

File uploadedFile = uploadRequest.getFile(fileInputName, true);

File folder = new File(Constants.ROOT_FOLDER_NAME);

// This is our final file path.

file = new File(folder.getAbsolutePath() + Constants.FILE_SEPARATOR

+ username + "_" + timestamp + "_" + fileName

+ ((!extension.isEmpty()) ? "." + extension : ""));

FileUtil.move(uploadedFile, file);

}

return file;

}

processInputFile()

35

Initializes variable for JobSubmssion

private void submitJob(AppPreferences preferences, AppInput appInput,

InfrastructureInfo[] enabledInfrastructures) {

// Job details

String executable = "/bin/sh";

String arguments = FileUtil.getShortFileName(pilotScript) + " "

+ appInput.getInputFileName();

String outputPath = "/tmp/";

String outputFile = "hostname-Output.txt";

String errorFile = "hostname-Error.txt";

String appFile = "hostname-Files.tar.gz";

// InputSandbox (string with comma separated list of file names)

String inputSandbox = pilotScript + "," + appInput.getInputSandbox();

// OutputSandbox (string with comma separated list of file names)

String outputSandbox = appFile;

...

submitJob()

36

submitJob()

// Prepare the GridEngine job description

GEJobDescription jobDesc = new GEJobDescription();

jobDesc.setExecutable(executable);

jobDesc.setArguments(arguments);

jobDesc.setOutputPath(outputPath);

jobDesc.setOutput(outputFile);

jobDesc.setError(errorFile);

jobDesc.setOutputFiles(outputSandbox);

jobDesc.setInputFiles(inputSandbox);

// GridEngine' MultiInfrastructure job submission object

MultiInfrastructureJobSubmission miJobSubmission = null

...

// Ready now to submit the Job

miJobSubmission.submitJobAsync(appInput.getUsername(), portalIPAddress,

applicationId, appInput.getJobLabel());

Creates GEJobDescription object

Actual job submission

37

Customization script

customize.sh

38

References

Template portlet source code repository

o https://github.com/sci-gaia/template-portlet

Discussion Forum

o http://discourse.sci-gaia.eu/

EGI IGTF Release

o https://wiki.egi.eu/wiki/EGI_IGTF_Release

VOMS Clients guide

o http://italiangrid.github.io/voms/documentation/voms-clients-

guide/3.0.3/

Thank you! mario.torrisi@ct.infn.it

sci-gaia.eu