1 / 42

Grid Portlet Writing Tutorial

OGCE Base Release 3rd Party Software. Jakarta Tomcat-4.1.18Can use later versions, but must make some minor modifications.Jakarta JetspeedRelease uses a patched version of Jetspeed-1.4b2.Not tested with other versions of jetspeed.Java SDK 1.4Java 1.3 does not include GSSAPI packages.There are workarounds, but really it's time to upgrade..

Patman
Download Presentation

Grid Portlet Writing Tutorial

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


    1. Grid Portlet Writing Tutorial Marlon Pierce Indiana University April 8-9, 2004

    3. Basic Assumptions I will assume you are reasonably familiar with the following: JSP Servlets General Java programming Tomcat configuration issues. XML You attended the previous lecture or have some familiarity with the OGCE portal system. These are required to understand the lecture.

    4. What Are Portlets? A portlet is a piece of java code that can load a particular piece of web content. A portlet is not the web content itself. Jetspeed includes portlets for loading web content in several ways: IFrames: simplest way to wrap legacy pages. HTML JSP Velocity We will review IFrames and JSP portlets. You can also write your own portlets We have portlets useful for working with legacy JSP pages.

    5. A Quick Note on Configuration You can remove any undesired portlets from the left hand side by clicking the Customize button at the bottom. You should see the screen on the right. Click the X to remove, then click the Apply button. Use this interface to add new portlets.

    6. Easy Integration with IFrames

    7. IFrame Portlets Pros Simplest way to include legacy content within the portal. Can easily link in any pages on same and other web servers. Modern browsers support <iframe>tags. Browsers will take care of cookies, form parameters, etc. Works with non-Java server side applications. CGI, PHP, etc. Works well with client side Flash bells and whistles. Cons Wont work with Netscape 4. No standard way to share info with other portlets or the portal container. For example, cant share portal login info without additional work. No control over Web styling of loaded IFrame. Colors, CSS, etc.

    8. Creating an IFrame Shutdown Tomcat. It overwrites xreg files on shutdown, so if you edit these. Go to $TOMCAT/webapps/nmi/WEB-INF/conf. Copy anabas.xreg to ${my-iframe}.xreg Not required, just a short cut. Edit it so that it looks like the following slide. Edited parts are in red. Restart tomcat. Customize your display to add the new portlet. Take afternoon off.

    9. IFrame XREG Entry <?xml version="1.0" encoding="UTF-8"?> <registry> <portlet-entry name=AMES" hidden="false" type="ref"parent="IFramePortlet" application="false"> <meta-info> <title>The Ames Web Site </title> <description>The NASA AMES Web Site</description> </meta-info> <classname>org.apache.jetspeed.portal.portlets.IFramePortlet</classname> <parameter name="width" value=800" hidden="false cachedOnName="true" cachedOnValue="true"/> <parameter name="height" value=800" hidden="false cachedOnName="true cachedOnValue="true"/> <parameter name="source value="http://www.arc.nasa.gov/index.cfm" hidden="false" cachedOnName="true" cachedOnValue="true"/> <media-type ref="html"/> <url cachedOnURL="true"/> </portlet-entry> </registry>

    11. Writing Basic Portlet Templates

    12. Writing a Velocity Portlet Imagine the following simplistic scenario: I have a web form that helps a user submit a job to a supercomputer. I only need one input form to generate the input file, pick a host computer, etc. The output file is written back to the users home directory, so he or she can gridftp it later. Before we can do this, we first need a bit of background on programming portlets.

    13. Velocity Portlet Example Before handling the Grid execution, we will first construct a dummy form. We will use Velocity templates. Jetspeed has better support and documentation for Velocity. Most of the portlets in the release use this. We will examine a JSP example later.

    14. Create the Template Open a new file in nmi/WEB-INF/templates/vm/portlets/html. Give it a name, myTestApp.vm Write the Velocity template Write an xreg file (see next slide). Restart Tomcat. Customize your display to show the new portal. So far, so good. <h3> Enter the command you want to execute</h3> <form method="post"> <table> <tr> <td> Command Name:</td> <td> <input type="text" name="runCommnad" value=""> </td> </tr> </table> </form>

    15. Sample JSP Portlet Template <?xml version="1.0" encoding="UTF-8"?> <registry> <portlet-entry name="myScienceApp" hidden="false" type="ref" parent="CustomizerVelocity" application="false"> <meta-info> <title>Sample Proxy Form</title> <description>Sample Proxy Form</description> </meta-info> <classname>org.apache.jetspeed.portal.portlets.VelocityPortlet</classname> <parameter name="template" value="myScienceApp" hidden="true" cachedOnName="true" cachedOnValue="true"/> <parameter name="action" value="portlets.myScienceAppAction" hidden="true" cachedOnName="true" cachedOnValue="true"/> <media-type ref="html"/> <url cachedOnURL="true"/> </portlet-entry> </registry>

    16. Specifying The Template The parts in red (template and action) point to things that you must write. The line below is used to name the VM template in the XREG. Points to myScienceApp.vm <parameter name="template" value="myScienceApp" hidden="true" cachedOnName="true cachedOnValue="true"/>

    17. Actions in Templates Note our velocity template is just HTML (at this point) with a form action. The action implementation is specified in the XREG file. MyScienceAppAction.java is the code that does the work when you click the button. Jetspeed action managers are responsible for calling your actions. You just need to write the java code, put it in the right place, and connect it to a Velocity template in the XREG file. Jetspeed will take care of the invocation.

    18. Writing An Action A portlet action is just a java class. It should extend VelocityPortletAction You should implement the buildNormalContext() method. This method is called by default when you invoke an HTML form action. This can do anything you want (i.e. make calls to Grid services through the Java COG). You can also implement other action methods.

    19. Getting Started Lets give our simple portlet an action. To do this, we first modify the Dont forget to shutdown tomcat first. The red text is new. We then write the action and compile it into nmi/WEB-INF/classes. See next slide Set classpath correctly! Restart the server. <parameter name="action" value="portlets.myScienceApAction" hidden="true" cachedOnName="true" cachedOnValue="true"/>

    20. A Minimal Action: myScienceAppAction.java package org.apache.jetspeed.modules.actions.portlets; //Import Turbine packages. import org.apache.turbine.util.RunData; //Import Velocity packages import org.apache.velocity.context.Context; //Import Jetspeed packages. import org.apache.jetspeed.modules.actions.portlets.VelocityPortletAction; import org.apache.jetspeed.portal.Portlet; public class myScienceAppAction extends VelocityPortletAction { public void buildNormalContext(VelocityPortlet portlet, Context acontext, RunData rundata) { //Real action code goes here. System.out.println("buildNormalContext called"); } }

    21. Some Miscellaneous Notes This action is automatically called whenever the JSP templates form action is invoked. In the portal release, the chef-1.0.7/modules/nmi-lib directory contains all the jars needed to compile this code. You can use our ant build scripts as templates for writing your own. The portlet actionss system.out.println() is written to catalina.out. If you prefer, you can use Jetspeeds logger, which writes to nmi/WEB-INF/log.

    22. RunData, Requests, and Sessions The method buildNormalContext includes an object called RunData in its arg list. RunData is your access point to all HTTP request, response, and session data. HttpSession session=rundata.getSession(); HttpServletRequest req=rundata.getRequest(); From here, you can do standard java.net.* development. I am not planning to cover this, but we can discuss.

    23. Connecting Multiple Templates In reality, a single web form is not enough to set up a complicated input file, select a host and execute a job. These may be spread over multiple linked forms. Form actions in templates must be handled a bit differently. <form action=SomeOtherPage> This cant point to a template, since it is not directly accessible (in WEB-INF). Jetspeed actions handle this.

    24. Redirecting to Another Page Setting up and running applications from a portal typically requires many successive HTML forms. So we need to see how to do this with Jetspeed. Lets call this myScienceApp2.vm and place it in the same place as myScienceApp.vm.

    25. First, Modify myScienceApp.vm Use the eventSubmit_{action} construction. This action will be tied to a specific method in myScienceAppAction.java. <h3> Enter the command you want to execute</h3> <form method="post"> <table> <tr> <td>Command Name:</td> <td><input type="text" name="runCommnad" value=""></td> </tr> </table> <input type="submit" name="eventSubmit_doGet_command" value="Click to Select Host"> </form>

    26. Next, Modify Your Action Code Add the following method to myScienceAppAction.java. Your method name should follow the pattern given in the form. This particular action runs setTemplate(), which loads the indicated Velocity template. When you click a form, Jetspeed will look for all methods matching eventSubmits pattern. If it finds them, it executes them. If not, buildNormalContext() is the default. public void doGet_command( RunData runData, Context aContext ) { setTemplate(runData, "myVelocityApp2"); }

    27. Write the Destination Template The following is an example of myScienceApp2.vm. Note the eventSubmit. Both of our templates use the same action. We can add a method doGet_host to myScienceAppAction.java to handle host events. You can build Once=anomaly Twice=infinitely reproducible pattern <form method="post"> BigIron: <input type=radio name=host value="BigIron"> <br> IronBird: <input type=radio name=host value="IronBird"> <input type="submit" name="eventSubmit_doGet_host" value="Click to Run"> </form>

    28. Writing Grid Portlet Templates

    29. Grid Portlets There is nothing fundamentally special about Grid portlets Just implement your portlet action with Java COG calls. We handle all access to the Grid through the Java COG kit. Hides differences between Globus toolkit versions. Currently a higher level programming API for the COG is under development as part of NMI. GVL is one of our PIs, so we all have vested interest in this. Basic procedure: Proxy credentials acquired through MyProxy client portlet. Modify your action java class (myScienceAppAction.java) Use convenience methods to get local GSSCredential from memory. Use GSSCredential in COG calls to Grid resources. Develop Velocity user interfaces to collect necessary info from users.

    30. Example Code: Fetching Credentials The OGCE provides a convenience class ProxyManager for storing/fetching proxy creds. Assumes you have logged in to the proxy portlet. HttpSession session = runData.getSession(); GSSCrendential cred = ProxyManager.getDefaultProxy(session);

    31. Example Code: Using GRAM Construct an RSL String (not shown). Specifies remote action. Create a GramJob Set the credential (see previous slide). String theHost=; String rsl=; GramJob job=new GramJob(rsl); Job.setCredential(cred); Gram.request(theHost, job);

    32. More Information on the COG Programming http://www-unix.globus.org/cog/manual-user.pdf

    33. Handling Legacy JSP Pages

    34. Legacy JSP Pages Jetspeed is a more restrictive environment than simple JSP. Its good for you approach of separating actions from visible pages. Enforced MVC Good design practice, but your legacy pages may involve a lot of work to remove control code. Or you may have to adapt your own MVC structure to match Jetspeeds Is there an alternative?

    35. Yes, Of Course Recall that portlets are java classes that extend base portlet classes. Dont confuse portlets with templates or actions. We have a portlet type that will handle HTML form parameters, posts, and Tomcat session cookies. I use this exclusively in my QuakeSim portal project. If you place legacy JSP pages under the webapp/nmi directory, it will inherit all Jetspeed session data Cookies, session variables, etc. Caveats: It doesnt handle JavaScript. If you mangle your <table> tags and <form> elements, it may not work. But well formed HTML is OK. Only successfully tested with JSP pages, but may work with others.

    36. Using WebFormPortlet The portlet code is available as a supplemental ant package. Just build it into the portal release. Create an xreg such as the one on the right. The portlet source just points to a legacy JSP page. This page and all of its links may be included in a portlet. No additional templates or actions. <portlet-entry name=" hidden="false" type="ref parent="WebFormPortlet" application="false"> <classname>commgrids.jetspeed.portlets.WebFormPortlet </classname> <parameter name="portal_id" value="awsportal" hidden="true"/> <parameter name="base_url" value=http://somehost.gov:10081 hidden="false" /> <parameter name="first_page" value="/nmi/mystuff/MyJSP.jsp" hidden="true"/> </portlet-entry>

    37. Cheating on Jetspeed Jetspeed is just another Java web application, so the usual rules apply. The base webapp (nmi) and all of its subdirectories share a common context. You can get access to all of Jetspeeds session variables through the built-in JSP session object. The request and session objects obtained through RunData are the same objects as the built-in request and session objects. So your JSP pages under NMI can get the jetspeed user ID and the proxy credential, if you know the names. Im not describing a security hole. This is just a lower level of working with the objects.

    38. Other Matters

    39. Getting the Portal User The JetspeedUser object has several convenient methods getName, getEmail, etc. Code to the right shows the import and way to get the user. The backdoor way to do this is User auser = (User)session.getAttribute("turbine.user"); You can do this if are cheating (see previous section). import org.apache.jetspeed.om.security.JetspeedUser; JetspeedUser aUser = ((JetspeedRunData)runData).getJetspeedUser();

    40. Job Monitoring GPIR portlets can be used to monitor host machines. Configuration tools and detailed instructions on setting things up are scheduled for April release. You can get a preview from GridPort 3.0 beta.

    41. Persistent Storage We have two solutions for this ContextManager NEESGrid Metadata System. Client side of ContextManager is available now. You can write your own client to the service. IU hosts the service right now, but we are planning to release it. NEESGrid tools are part of the April release

    42. One Last Word Always, always, always shutdown Tomcat before editing XREG files. Tomcat will overwrite these when it shuts down. Will overwrite your edits. Forgetting this will cause you no end of grief while developing.

More Related