Riccardo Rotondo
Tutorial on Science Gateways, Roma, 04.06.2013
Job Management Portlet
A portlet example to access job managment service
Generic Porlets Life Cycle
Riccardo Rotondo
End of Services?
NOYES
Tutorial on Science Gateways, Roma, 04.06.2013
Generic Porltlets Interface MethodClass GenericPortlets {init (PortletConfig);processAction (ActionRequest, ActionResponse);render (RenderRequest, RenderResponse);destroy();doView (Request, Response);doEdit (Reuqest, Response);doHelp (Request, Response);}
Riccardo RotondoTutorial on Science Gateways, Roma, 04.06.2013
Portlet Mode A porltet works in three
different states. View Mode: generate a
markup ( a portion of a web page);
Edit Mode: allow portlet customisation and setting preferences.
Help Mode: explains portlet functionalities.
Riccardo RotondoTutorial on Science Gateways, Roma, 04.06.2013
doEdit()
Action/Render Request
Riccardo Rotondo
ActionRequest
processAction()
RenderRequest
view.jsp doView() edit.jsp
ActionRequest
processAction()
RenderRequest
edit.jsp view.jsp
Tutorial on Science Gateways, Roma, 04.06.2013
RenderRequest
view.jsp doView() view2.jsp
Riccardo Rotondo
Portlet workflow
JSP pagedoView
ProcessAction
ACTION/VIEW ArchitectureHostname code provides two Enum types:
Actions and
Views
For each Action a different View can be selected and easily managed byswitch statements
The two enumerated types used to manage the portlet behavior Between portlet methods: ‘doView and ProcessAction’.
Jsp/Java Variable: ‘PortletStatus’
doView
A
V
A JSP page
ProcessAction
A A A
VV
VJSP page
default
init
init
Tutorial on Science Gateways, Roma, 04.06.2013
Riccardo Rotondo
Portlet Session data
JSP pagedoView
ProcessAction
Two objecst:
actionRequest processAction()
renderRequestdoView()doHelp()doEdit()
RR
AR
AR
RR
init
ProcessAction sends parameters to the other methods with a RenderRequest through:
ActionResponse (2nd parameter of ProcessAction)response.setRenderParameter("param_name_y", param_value_y);
doView/doHelp/doEdit (1st parameter) RenderRequestparam_name_w=request.getParameter("param_name_w");
Parameters to jsp and select it:request.setAttribute("JobId", inputJobId);getPortletContext().getRequestDispatcher(”/<view_page>.jsp");
Tutorial on Science Gateways, Roma, 04.06.2013
Parameters exchange (JSP->Java)
Portlet modes: VIEW – Userd for normal portlet operations -> calls processAction() EDIT – Userd to configure portlet parameters -> calls doEdit() HELP – Userd to show help information -> calls doHelp()
<form action=action="<portlet:actionURL portletMode="view"> <portlet:param name="param_name_1" value="param value 1"/>
…<portlet:param
name="param_name_n" value="param value n"/>…
<input … /><input … />
<input type="submit" … /></form>
• processAction(ActionRequest request,…• doView/doHelp/doEdit(RenderRequest request,…
// To obtain the parameter just set …String param_i = request.getParameter("param_name_i");
Tutorial on Science Gateways, Roma, 04.06.2013
Riccardo Rotondo
Parameters exchange (Java->JSP)
<% // To load variables from Portlet Class …%><jsp:useBean id="param_name_k" class="<variable type k>" scope="request"/>
<% // To reference a param value%><%=param_name_k%>
doView/doHelp/doEdit(RenderRequest request,…// To send the parameter just call …request.setAttribute("param_name_j", param_name_j);
Tutorial on Science Gateways, Roma, 04.06.2013
Riccardo Rotondo
hostname-portlet example Portlet to send a test job into a
distributed infrastructure Input:
Input file or a text A human readable job identifier
Ouput Hostname of running machine File containing information about the
running machine
Portlet statuses INPUT
(Shows the input fields) SUBMIT
(Shows the job submission feedback)
Jsp/Java variable ‘PortletStatus’
input.jsp
submit.jsp
Tutorial on Science Gateways, Roma, 04.06.2013
Riccardo Rotondo
Hostname Action/View enums
Actions ACTION_INPUT ACTION_SUBMIT
Views (Possible portlet views) VIEW_INPUT VIEW_SUBMIT
Default Action
• Simply forward portlet status to the doView() in: RenderParameter
Tutorial on Science Gateways, Roma, 04.06.2013
Riccardo Rotondo
Hostname Action/View
Actions ACTION_INPUT ACTION_SUBMIT
Views VIEW_INPUT VIEW_SUBMIT
View
• Select the INPUT form view input.jsp (default view mode)
Tutorial on Science Gateways, Roma, 04.06.2013
Riccardo Rotondo
Hostname Action/View
Actions ACTION_INPUT ACTION_SUBMIT
Views VIEW_INPUT VIEW_SUBMIT
This action will submit the hostname job into the distributedinfrastructure
<form enctype="multipart/form-data" action="<portlet:actionURL portletMode="view"> <portlet:param name="PortletStatus" value="ACTION_SUBMIT"/> </portlet:actionURL>" method="post”>
Tutorial on Science Gateways, Roma, 04.06.2013
Riccardo Rotondo
Hostname Action/View
Actions ACTION_INPUT ACTION_SUBMIT
Views VIEW_INPUT VIEW_SUBMIT
Select the proper view showing theInformation page that shows the job has been submitted
Tutorial on Science Gateways, Roma, 04.06.2013
Riccardo Rotondo
Portlet Initialization
portlet.xlm contains portlet initialization parameters<init-param> <name>init parameter name</name> <value>init parameter value</value> </init-param>
The init() method uses <init-param>s to load Portlet’ default parameter values
Some of the default parameters values will be used to load portlet default preferences
public void init() throws PortletException { // Load default values from portlet.xml
init_PortletVersion = getInitParameter(“init parameter name");…
Tutorial on Science Gateways, Roma, 04.06.2013
Riccardo Rotondo
hostname’ <init-param>
To make parameter management easier all values are threated as String type
init_PortletVersion - Portlet version number init_bdiiHost - Information system service (ldap://...:2170) init_wmsHost - Infrastructure resource manager (wms://...:7443/glite_wms_wmproxy_server) init_pxServerHost - Hostname of Robot proxy server (myproxy.ct.infn.it not used yet) init_pxRobotId - Id of the robot certificate init_pxRobotVO - Infrastructure virtual organization init_pxRobotRole - Role of generated proxy init_pxUserProxy - Standard proxy file (instead of Robots) init_pxRobotRenewalFlag - Allows automatic job renewal mechanism init_SciGwyAppId - Science Gateway application identifier '9' for GILDA VM tester application
GridEngine' User tracking database (UTDB) access credentials init_SciGwyUserTrackingDB_Hostname init_SciGwyUserTrackingDB_Username init_SciGwyUserTrackingDB_Password init_SciGwyUserTrackingDB_Database – Users should not use Direct DB access to
UTDB init_JobRequirements - Application job requirements init_pilotScript - Application pilot script
Tutorial on Science Gateways, Roma, 04.06.2013
Riccardo Rotondo
Hostname Portlet preferences
getPreferences method called by both: doView and processAction
private void getPreferences( ActionRequest actionRequest ,RenderRequest renderRequest) {
PortletPreferences prefs=null; if(null!=actionRequest) prefs = actionRequest.getPreferences(); else if(null != renderRequest) prefs = renderRequest.getPreferences(); if (null != prefs) {
// The second parameter assigns a default value pref_value=prefs.getValue("<pref_name>", "<init_name>");
Tutorial on Science Gateways, Roma, 04.06.2013
Riccardo Rotondo
Initialize Method for submission
// Initialize the GridEngine Multi Infrastructure Job Submission object MultiInfrastructureJobSubmission miJobSubmission = new MultiInfrastructureJobSubmission();
// Assigns all enabled infrastructures InfrastructureInfo[] infrastructuresInfo=appPreferences.getEnabledInfrastructures();
Tutorial on Science Gateways, Roma, 04.06.2013
Riccardo Rotondo
Job parameters
// Job detailsString executable="/bin/sh"; // Application executableString arguments =appPreferences.getPilotScript(); //executable' arguments String outputPath="/tmp/"; // Output PathString outputFile="hostname-Output.txt"; // Distributed application standard outputString errorFile ="hostname-Error.txt"; // Distrubuted application standard errorString appFile ="hostname-Files.tar.gz"; // Hostname output files (created by the pilot script)
Tutorial on Science Gateways, Roma, 04.06.2013
Riccardo Rotondo
Input & Output
// InputSandbox (string with comma separated list of file names)String inputSandbox=appServerPath+"WEB-INF/job/" +appPreferences.getPilotScript() // pilot script +","+appInput.inputSandbox_inputFile // input file ; // OutputSandbox (string with comma separated list of file names)String outputSandbox=appFile; // Output file
Tutorial on Science Gateways, Roma, 04.06.2013
Riccardo Rotondo
Job Requirement
// Take care of job requirements// More requirements can be specified in the preference value 'jobRequirements’// separating each requirement by the ';' characterString jdlRequirements[] = appPreferences.getJobRequirements().split(";"); int numRequirements=0; for(int i=0; i<jdlRequirements.length; i++) { if(!jdlRequirements[i].equals("")) { jdlRequirements[numRequirements] =
"JDLRequirements=("+jdlRequirements[i]+")"; numRequirements++; } } // for each jobRequirement
Tutorial on Science Gateways, Roma, 04.06.2013
Riccardo Rotondo
Setting parameter and submit
// Other job initialization settingsmiJobSubmission.setExecutable (executable); // Specify the executeablemiJobSubmission.setArguments (arguments); // Specify the application' argumentsmiJobSubmission.setOutputPath (outputPath); // Specify the output directory miJobSubmission.setOutputFiles(outputSandbox); // Setup output files (OutputSandbox)miJobSubmission.setJobOutput (outputFile); // Specify the std-outputr filemiJobSubmission.setJobError (errorFile); // Specify the std-error fileif(null != inputSandbox // Setup input files (InputSandbox) avoiding empty inputSandboxes && inputSandbox.length() > 0) miJobSubmission.setInputFiles(inputSandbox); if(numRequirements>0) // Setup the JDL requirements miJobSubmission.setJDLRequirements(jdlRequirements);
// Submit JobmiJobSubmission.submitJobAsync(appInput.username, portalIPAddress, applicationId, appInput.jobIdentifier);
Tutorial on Science Gateways, Roma, 04.06.2013
Riccardo Rotondo
From hostname to your portlethttps://gilda.ct.infn.it/wikimain/-/wiki/Main/hostname-portlet
Extract hostname portlet form svnsvn checkout svn://svn.code.sf.net/p/ctsciencegtwys/liferay/trunk/gilda/mi-hostname-portlet
‘cd’ inside the hostname-portlet directory and try to compile it with the command: ant deploy
If the compilation is successful create a physical copy of the portlet directory source code cp –r hostname-portlet <yourname>-portlet
Customize your portlet settings configuring several XML files: docroot/WEB-INF/portlet.xml
<portlet-name><yourname>-portlet</portlet-name><display-name><yourname>-portlet</display-name><portlet-class><your.package.path.<yourname>_portlet</portlet-class>…<init-param> <name>init_PortletVersion</name> <value>Specify your Portlet' version number</value></init-param>… other init parameters
Tutorial on Science Gateways, Roma, 04.06.2013
Riccardo Rotondo
Init parameters
init_PortletVersioninit_bdiiHostinit_wmsHostinit_pxServerHostinit_pxRobotIdinit_pxRobotVOinit_pxRobotRoleinit_pxUserProxyinit_pxRobotRenewalFlaginit_SciGwyAppIdinit_SciGwyUserTrackingDB_Hostnameinit_SciGwyUserTrackingDB_Usernameinit_SciGwyUserTrackingDB_Passwordinit_SciGwyUserTrackingDB_Databaseinit_JobRequirementsinit_pilotScript
Your portlet version
Infrastructure settings …
Robot proxy settingsRobot Id, Virtual
Organization,Proxy Role, Renewal Flag
pxUserProxy (mutually exclusive to Robots)
Allows the use of a user proxy
Just provide a valid path to a proxy fileEach application has a unique Id (GridEngine)
GridEngine connection credentials (Unused)
Grid Job requirements
Job’ pilot script (bash)
Tutorial on Science Gateways, Roma, 04.06.2013
Riccardo Rotondo
Parameter in portlet preferences
Tutorial on Science Gateways, Roma, 04.06.2013
Riccardo Rotondo
From hostname to your portlet docroot/WEB-INF/portlet.xml (still)
<portlet-info> <title>Title of yor porltlet <short-title>Short title <keywords>Portlet' keywords
docroot/WEB-INF/liferay-display.xml<category name="<place your category name here>" (your institution ‘GILDA’)<portlet id="<place your portlet identifier>" (name displayed into the mangment interface)
docroot/WEB-INF/libOverrides or extends the portlet java code global library repository (/opt/glassfish3/glassfish/domains/liferay/lib/)
docroot/WEB-INF/liferay-portlet.xml<portlet-name><css-class-wrapper>
docroot/WEB-INF/glassfish-web.xml<context-root> (Information managed by App server Glassfish)
docroot/images/Each image used by the jsp pages should be located here
docroot/icon.pngPlace here a 16x16 image file with your portlet icon
Tutorial on Science Gateways, Roma, 04.06.2013
Riccardo Rotondo
From hostname to your portlet /docroot/WEB-INF/src/it/infn/ct/hostname_portlet.java
Make a copy of this source file into directory: <your.package.name>/<yourname_portlet>.java>
WARNING: Do not forget to assign to the class the same name of the java file
Start to develop the interface modifying jsp files and change java code Enums with correct Actions and Views modes using human readable identifiers. For simple Appliocation user interfaces there will be no need to add other JSPs or action/view modes to the existing Enum
Edit the java code in order to manage your application specific interface and prepare the correct sandboxes to submit properly the job
Prepare the pilot script and use it as parameter.
Tutorial on Science Gateways, Roma, 04.06.2013
Riccardo Rotondo
References
SVN: http://sourceforge.net/p/ctsciencegtwys/liferay/
MI-hostname project: http://sourceforge.net/p/ctsciencegtwys/liferay/HEAD/tree/trunk/gilda/
MI-hostname main source: http://sourceforge.net/p/ctsciencegtwys/liferay/HEAD/tree/trunk/gilda/mi-hostname-portlet/docroot/WEB-INF/src/it/infn/ct/mi_hostname_portlet.java#
l1253 Gilda Wiki:
Installation and configuration of the developing environment
Basic portlet for a sequential jobTutorial on Science Gateways, Roma, 04.06.2013