4. 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 Rotondo
Tutorial on Science Gateways, Roma, 04.06.2013
6. Portlet workflow
init
doView
JSP page
ACTION/VIEW Architecture
Hostname code provides two
Enum types:
Actions and
Views
ProcessAction
init
doView
default
JSP page
JSP page
For each Action a different View
can be selected and easily managed by
switch statements
The two enumerated types used to
manage the portlet behavior
Between portlet methods:
‘doView and ProcessAction’.
Jsp/Java Variable: ‘PortletStatus’
ProcessAction
Riccardo Rotondo
Tutorial on Science Gateways, Roma, 04.06.2013
7. Portlet Session data
init
doView
Two objecst:
JSP page
ProcessAction
actionRequest
processAction()
renderRequest
doView()
doHelp()
doEdit()
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) RenderRequest
param_name_w=request.getParameter("param_name_w");
Parameters to jsp and select it:
request.setAttribute("JobId", inputJobId);
getPortletContext().getRequestDispatcher(”/<view_page>.jsp");
Riccardo Rotondo
Tutorial on Science Gateways, Roma, 04.06.2013
8. Parameters exchange (JSP->Java)
<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>
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()
•
•
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
9. Parameters exchange (Java->JSP)
doView/doHelp/doEdit(RenderRequest request,…
// To send the parameter just call …
request.setAttribute("param_name_j", param_name_j);
<%
// 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%>
Riccardo Rotondo
Tutorial on Science Gateways, Roma, 04.06.2013
10. hostname-portlet example
input.jsp
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
submit.jsp
INPUT
(Shows the input fields)
SUBMIT
(Shows the job submission feedback)
Jsp/Java variable ‘PortletStatus’
Riccardo Rotondo
Tutorial on Science Gateways, Roma, 04.06.2013
11. Hostname Action/View enums
Actions
ACTION_INPUT
ACTION_SUBMIT
Default Action
• Simply forward portlet status to
the doView() in:
RenderParameter
Views (Possible portlet views)
VIEW_INPUT
VIEW_SUBMIT
Riccardo Rotondo
Tutorial on Science Gateways, Roma, 04.06.2013
13. Hostname Action/View
Actions
ACTION_INPUT
ACTION_SUBMIT
This action will submit the
hostname job into the distributed
infrastructure
Views
VIEW_INPUT
VIEW_SUBMIT
<form enctype="multipart/form-data" action="<portlet:actionURL
portletMode="view">
<portlet:param name="PortletStatus" value="ACTION_SUBMIT"/>
</portlet:actionURL>"
method="post”>
Riccardo Rotondo
Tutorial on Science Gateways, Roma, 04.06.2013
14. Hostname Action/View
Actions
ACTION_INPUT
ACTION_SUBMIT
Views
VIEW_INPUT
VIEW_SUBMIT
Select the proper view showing
the
Information page that shows the
job has been submitted
Riccardo Rotondo
Tutorial on Science Gateways, Roma, 04.06.2013
15. Portlet Initialization
portlet.xlm contains portlet initialization parameters
<init-param>
<name>init parameter name</name>
<value>init parameter value</value>
</init-param>
public void init() throws PortletException {
// Load default values from portlet.xml
init_PortletVersion = getInitParameter(“init parameter name");
…
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
Riccardo Rotondo
Tutorial on Science Gateways, Roma, 04.06.2013
16. 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
Riccardo Rotondo
Tutorial on Science Gateways, Roma, 04.06.2013
17. Hostname Portlet preferences
private void getPreferences( ActionRequest actionRequest
,RenderRequest renderRequest) {
PortletPreferences prefs=null;
if(null!=actionRequest)
prefs = actionRequest.getPreferences();
getPreferences
else if(null != renderRequest)
doView andrenderRequest.getPreferences();
prefs = processAction
method called by both:
if (null != prefs) {
// The second parameter assigns a default value
pref_value=prefs.getValue("<pref_name>", "<init_name>");
Riccardo Rotondo
Tutorial on Science Gateways, Roma, 04.06.2013
18. Initialize Method for submission
// Initialize the GridEngine Multi Infrastructure Job Submission
object
MultiInfrastructureJobSubmission miJobSubmission =
new MultiInfrastructureJobSubmission();
// Assigns all enabled infrastructures
InfrastructureInfo[]
infrastructuresInfo=appPreferences.getEnabledInfrastru
ctures();
Riccardo Rotondo
Tutorial on Science Gateways, Roma, 04.06.2013
19. Job parameters
// Job details
String executable="/bin/sh"; // Application executable
String arguments =appPreferences.getPilotScript(); //executable'
arguments
String outputPath="/tmp/";
// Output Path
String outputFile="hostname-Output.txt"; // Distributed application
standard output
String errorFile ="hostname-Error.txt"; // Distrubuted application
standard error
String appFile
="hostname-Files.tar.gz"; // Hostname output files
(created by the pilot script)
Riccardo Rotondo
Tutorial on Science Gateways, Roma, 04.06.2013
20. 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
Riccardo Rotondo
Tutorial on Science Gateways, Roma, 04.06.2013
21. Job Requirement
// Take care of job requirements
// More requirements can be specified in the preference value 'jobRequirements’
// separating each requirement by the ';' character
String 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
Riccardo Rotondo
Tutorial on Science Gateways, Roma, 04.06.2013
22. Setting parameter and submit
// Other job initialization settings
miJobSubmission.setExecutable (executable); // Specify the executeable
miJobSubmission.setArguments (arguments); // Specify the application' arguments
miJobSubmission.setOutputPath (outputPath); // Specify the output directory
miJobSubmission.setOutputFiles(outputSandbox); // Setup output files (OutputSandbox)
miJobSubmission.setJobOutput (outputFile); // Specify the std-outputr file
miJobSubmission.setJobError
(errorFile); // Specify the std-error file
if(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 Job
miJobSubmission.submitJobAsync(appInput.username, portalIPAddress, applicationId,
appInput.jobIdentifier);
Riccardo Rotondo
Tutorial on Science Gateways, Roma, 04.06.2013
23. From hostname to your portlet
https://gilda.ct.infn.it/wikimain/-/wiki/Main/hostname-portlet
Extract hostname portlet form svn
svn 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
Riccardo Rotondo
Tutorial on Science Gateways, Roma, 04.06.2013
25. Parameter in portlet preferences
Riccardo Rotondo
Tutorial on Science Gateways, Roma, 04.06.2013
26. 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/lib
Overrides 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.png
Place here a 16x16 image file with your portlet icon
Riccardo Rotondo
Tutorial on Science Gateways, Roma, 04.06.2013
27. 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.
Riccardo Rotondo
Tutorial on Science Gateways, Roma, 04.06.2013
28. 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-hostnameportlet/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 job
Riccardo Rotondo
Tutorial on Science Gateways, Roma, 04.06.2013