Hostname-portlet Template Riccardo Rotondo (riccardo.rotondo@garr.it) Consortium GARR Joint School for Application Porting to Science Gateways Bogotá, 06.06.2012
Portlets Standard JSR168/286 Interaction between jsp pages and java code JSP uses <form… statements to send parameters to Java code Java code extends class GenericPortlet overriding methods: Init, doView, doHelp, doEdit, processAction Java code uses 2 Classes to exchange data from/to JSPs Application Server (Glassfish) JSP page Java code <jsp:useBean <form … > <input … /> </form> Class <you portlet> Extends GenericPortlet … Bogotá, 06.06.2012
Portlet files (root) build.xml docroot/ WEB_INF/ css/ images/ js/ jsp_page_1.jsp … jsp_page_n.jsp Used by ‘ant’ to compile and deploy the portlet Define here JSP’s styles JSP image files Portlet JSP pages Bogotá, 06.06.2012
Portlet files WEB_INF/ glassfish-web.xml web.xml lib/ Job/ liferay-display.xml liferay-plugin-package.properties liferay-portlet.xml portlet.xml src/ <package_name>/code.java tld/ Used to define database and other resources settings Jar Library directory (local scope) Job files (Custom dir) Portlet configuration files Java source files XML structure file Bogotá, 06.06.2012
Parameters exchange (JSP->Java) <form action=action="<portlet:actionURL portletMode="view"> <portlet:param name="param_name_1" value="param value 1"/> … name="param_name_n" value="param value n"/> <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"); Bogotá, 06.06.2012
Parameters exchange (Java->JSP) From Java code: Inside the JSP load values with: 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%> Bogotá, 06.06.2012
Portlet workflow ACTION/VIEW Architecture Hostname code provides two init ACTION/VIEW Architecture Hostname code provides two Enum types: Actions and Views 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’ doView JSP page A ProcessAction V init doView JSP page default A JSP page V V V ProcessAction A A A Bogotá, 06.06.2012
Portlet Session data Two objecst: actionRequest processAction() AR init Two objecst: actionRequest processAction() renderRequest doView() doHelp() doEdit() doView JSP page AR AR RR RR ProcessAction ProcessAction sends parameters to RenderRequest through: ActionResponse (2nd parameter of ProcessAction) response.setRenderParameter("param_name_y", param_value_y); doView/doHelp/doEdit (1st parameter) RenderResponse param_name_w=request.getParameter("param_name_w"); Parameters to jsp and select it: request.setAttribute("JobId", inputJobId); getPortletContext().getRequestDispatcher(”/<view_page>.jsp"); Bogotá, 06.06.2012
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 INPUT (Shows the input fields) SUBMIT (Shows the job submission feedback) Jsp/Java variable ‘PortletStatus’ submit.jsp Bogotá, 06.06.2012
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 Bogotá, 06.06.2012
Hostname Action/View Actions Views ACTION_INPUT ACTION_SUBMIT VIEW_INPUT VIEW_SUBMIT View Select the INPUT form view input.jsp (default view mode) Bogotá, 06.06.2012
Hostname Action/View Actions Views ACTION_INPUT ACTION_SUBMIT VIEW_INPUT VIEW_SUBMIT This action will submit the hostname job into the distributed infrastructure <form enctype="multipart/form-data" action="<portlet:actionURL portletMode="view"> <portlet:param name="PortletStatus" value="ACTION_SUBMIT"/> </portlet:actionURL>" method="post”> Bogotá, 06.06.2012
Hostname Action/View Actions Views ACTION_INPUT ACTION_SUBMIT VIEW_INPUT VIEW_SUBMIT Select the proper view showing the Information page that shows the job has been submitted Bogotá, 06.06.2012
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"); … Bogotá, 06.06.2012
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 Bogotá, 06.06.2012
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>"); Bogotá, 06.06.2012
Job Submission (1/4) // Job details String executable="/bin/sh"; // Application executable String arguments="pilot_script.sh"; // executable' arguments String outputPath="/tmp/"; // Output Path String outputFile="application.out"; // Application stdout String errorFile="application.err"; // Application stderr // InputSandbox (string with comma separated list of file names) String inputSandbox= appServerPath +"/WEB-INF/job/pilot_script.sh” +","+<other files>; // OutputSandbox (string with comma separated list of file names) String outputSandbox="generated_output_file"; Bogotá, 06.06.2012
Job Submission (2/4) // Software tags String jdlRequirements[] = pref_JobRequirements.split(";"); int numRequirements=0; for(int i=0; i<jdlRequirements.length; i++) if(!jdlRequirements[i].equals("")) { jdlRequirements[numRequirements] = "JDLRequirements=("+jdlRequirements[i]+")"; numRequirements++; } // Instanciate the JSAGA object JSagaJobSubmission tmpJSaga = new JSagaJobSubmission(); tmpJSaga.setBDII(bdiiHost); // Infrastructure top BDII Bogotá, 06.06.2012
Job Submission (3/4) // Proxy renewal flag if((pref_pxRobotRenewalFlag.toLowerCase()).equals("true")) pxRobotRenewalFlag=true; else pxRobotRenewalFlag=false; // Associate a valid proxy (Robot/UserProxy) // Specifying a path for local proxy it will be used instead if(pxUserProxy==null || pxUserProxy.equals("")) { tmpJSaga.useRobotProxy( pxRobotId ,pxRobotVO ,pxRobotRole ,pxRobotRenewalFlag ); else tmpJSaga.setUserProxy(pxUserProxy); Bogotá, 06.06.2012
Job Submission (4/4) tmpJSaga.setExecutable(executable); // Specify the executeable tmpJSaga.setArguments(arguments); // Specify the application' arguments tmpJSaga.setOutputPath(outputPath); // Specify the output directory tmpJSaga.setInputFiles(inputSandbox); // Setup input files (InputSandbox) tmpJSaga.setOutputFiles(outputSandbox); // Setup output files (OutputSandbox) tmpJSaga.setJobOutput(outputFile); // Specify the std-outputr file tmpJSaga.setJobError(errorFile); // Specify the std-error file if(numRequirements>0) tmpJSaga.setJDLRequirements(jdlRequirements); // Assign requirements // Submit the job // If a WMS is specified the call to Job submission changes if(wmsHost!=null && !wmsHost.equals("")) tmpJSaga.submitJobAsync(username ,hostUTDB ,applicationId ,wmsHost ,jobIdentifier ); else tmpJSaga.submitJobAsync( username Bogotá, 06.06.2012
From hostname to your portlet https://gilda. ct. infn Extract hostname portlet form svn svn checkout http://svn.ct.infn.it/svn/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 Bogotá, 06.06.2012
Init parameters Your portlet version Infrastructure settings … init_PortletVersion init_bdiiHost init_wmsHost init_pxServerHost init_pxRobotId init_pxRobotVO init_pxRobotRole init_pxUserProxy init_pxRobotRenewalFlag init_SciGwyAppId init_SciGwyUserTrackingDB_Hostname init_SciGwyUserTrackingDB_Username init_SciGwyUserTrackingDB_Password init_SciGwyUserTrackingDB_Database init_JobRequirements init_pilotScript Your portlet version Infrastructure settings … Robot proxy settings Robot 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 file Each application has a unique Id (GridEngine) GridEngine connection credentials (Unused) Grid Job requirements Job’ pilot script (bash) Bogotá, 06.06.2012
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 Bogotá, 06.06.2012
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. Bogotá, 06.06.2012
Create NetBeans project Open new project and select: Categories: Java web Projects: Web Appliacations with existing sources. Press 'Next' Location: Point Netbeans to locate the portlet directory through the VM shared folder. Accept any suggestion and proceed Add other directory places: WEB-INF Content: Select the docroot/WEB-INF directory inside the portlet directory Library folder: point it to docroot/WEB-INF/lib Then press the 'Finish' button and the project will be created Right click on the project name and click on Peferences, then Libraries Select all jars pointed by liferayadmin@<gildavm>:liferay_libs/ directory Bogotá, 06.06.2012
References GILDA VM GILDA VM Instructions hostname portlet template https://gilda.ct.infn.it/services GILDA VM Instructions https://gilda.ct.infn.it/wikimain/-/wiki/Main/GILDA+Liferay+Virtual+Machine hostname portlet template https://gilda.ct.infn.it/wikimain/-/wiki/Main/hostname-portlet Bogotá, 06.06.2012
Questions? Bogotá, 06.06.2012