Job Managment Portlet

274 views
198 views

Published on

A portlet example to access job managment service

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
274
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
6
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Job Managment Portlet

  1. 1. Job Management Portlet A portlet example to access job managment service Riccardo Rotondo Tutorial on Science Gateways, Roma, 04.06.2013
  2. 2. Generic Porlets Life Cycle YES NO End of Services? Riccardo Rotondo Tutorial on Science Gateways, Roma, 04.06.2013
  3. 3. Generic Porltlets Interface Method Class GenericPortlets { init (PortletConfig); processAction (ActionRequest, ActionResponse); render (RenderRequest, RenderResponse); destroy(); doView (Request, Response); doEdit (Reuqest, Response); doHelp (Request, Response); } Riccardo Rotondo Tutorial on Science Gateways, Roma, 04.06.2013
  4. 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
  5. 5. Action/Render Request Action Request view.jsp Render Request processAction() Action Request edit.jsp doView() edit.jsp doEdit() view.jsp Render Request processAction() Render Request view.jsp doView() view2.jsp Riccardo Rotondo Tutorial on Science Gateways, Roma, 04.06.2013
  6. 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. 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. 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. 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. 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. 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
  12. 12. Hostname Action/View  Actions  ACTION_INPUT  ACTION_SUBMIT  Views  VIEW_INPUT  VIEW_SUBMIT View • Select the INPUT form view input.jsp (default view mode) Riccardo Rotondo Tutorial on Science Gateways, Roma, 04.06.2013
  13. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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
  24. 24. Init parameters 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) proxy file Allows the use of a user proxy Just provide a valid path to a Each application has a unique Id (GridEngine) GridEngine connection credentials (Unused) Grid Job requirements Job’ pilot script (bash) Riccardo Rotondo Tutorial on Science Gateways, Roma, 04.06.2013
  25. 25. Parameter in portlet preferences Riccardo Rotondo Tutorial on Science Gateways, Roma, 04.06.2013
  26. 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. 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. 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

×