1 / 52

GT3 Tutorial Chapter 3 and Chapter 4

GT3 Tutorial Chapter 3 and Chapter 4. Lecture for Cluster and Grid Computing, CSCE 490/590 Fall 2004, University of Arkansas, Dr. Amy Apon http://csce.uark.edu/~aapon/courses/gridcomputing/index.html from http://www.casa-sotomayor.net/gt3-tutorial/. Chapter 3: Writing your first Grid Service.

mimis
Download Presentation

GT3 Tutorial Chapter 3 and Chapter 4

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. GT3 TutorialChapter 3 and Chapter 4 Lecture for Cluster and Grid Computing, CSCE 490/590 Fall 2004, University of Arkansas, Dr. Amy Apon http://csce.uark.edu/~aapon/courses/gridcomputing/index.html from http://www.casa-sotomayor.net/gt3-tutorial/

  2. Chapter 3:Writing your first Grid Service • Math Service • Will perform two operations, addition and subtraction

  3. Before you start • Download the tutorial source files to your account on talon.csce.uark.edu • http://www.casa-sotomayor.net/gt3-tutorial/download/progtutorial-examples_0.4.2.tar.gz

  4. $TUTORIAL_DIR | |-- schema/ | | | |-- progtutorial/ -----> GWSDL files | |--- org/ | |-- globus/ | |-- progtutorial/ | |-- services/ -----> Service impL files | |-- clients/ -----> Client impl files

  5. Five Steps • Define the service's interface. This is done with GWSDL • Implement the service. This is done with Java • Define the deployment parameters. This is done with WSDD • Compile everything and generate GAR file. This is done with Ant • Deploy service. This is also done with Ant

  6. Step 1: Define the interface in GWSDL – Two options • Writing the WSDL directly. • This is the most versatile option. • Total control over the description of our portType. • Generating WSDL from a Java interface. • The easiest option, but very complicated interfaces are not always converted correctly to WSDL

  7. The interface in Java public interface Math { public void add(int a); public void subtract(int a); public int getValue(); } Notice there is only one parameter!?!

  8. Steps to GWSDL (Grid WSDL) • Write the root element <definitions> • Write the <gwsdl:PortType> • Write an input and output <message> for each operation in the PortType. • Write the <types>

  9. a. Write the root element <?xml version="1.0" encoding="UTF-8"?> <definitions name="MathService" targetNamespace="http://www.globus.org/namespaces/2004/02/progtutorial/MathService" xmlns:tns="http://www.globus.org/namespaces/2004/02/progtutorial/MathService" xmlns:ogsi="http://www.gridforum.org/namespaces/2003/03/OGSI" xmlns:gwsdl="http://www.gridforum.org/namespaces/2003/03/gridWSDLExtensions" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/">

  10. <definitions …> name: the ‘name’ of the GWSDL file. Not related with the name of the PortType targetNamespace: The target namespace of the GWSDL file.

  11. <import …> <import location="../../ogsi/ogsi.gwsdl" namespace="http://www.gridforum.org/namespaces/2003/03/OGSI"/>

  12. b. Write the PortType <gwsdl:portType name="MathPortType" extends="ogsi:GridService"> <operation name="add"> <input message="tns:AddInputMessage"/> <output message="tns:AddOutputMessage"/> <fault name="Fault" message="ogsi:FaultMessage"/> </operation> <operation name="subtract"> <input message="tns:SubtractInputMessage"/> <output message="tns:SubtractOutputMessage"/> <fault name="Fault" message="ogsi:FaultMessage"/> </operation> <operation name="getValue"> <input message="tns:GetValueInputMessage"/> <output message="tns:GetValueOutputMessage"/> <fault name="Fault" message="ogsi:FaultMessage"/> </operation> </gwsdl:portType>

  13. portType tag important attributes • name: name of the PortType • extends • One of the main differences with plain WSDL. • Allow definition of PortType as an extension of an existing PortType. • Extend from ogsi:GridService PortType, which all Grid Services must extend from.

  14. Inside portType • An <operation> tag for each method in the PortType • Operation tag has an input tag, an output tag, and a fault tag

  15. c. Write input and output messages for each port type <message name="AddInputMessage"> <part name="parameters" element="tns:add"/> </message> <message name="AddOutputMessage"> <part name="parameters" element="tns:addResponse"/> </message> • Message are composed of parts – our messages have one part, in which a single XML element is passed along

  16. d. Define the XML elements inside the <types> tag <types> <xsd:schema targetNamespace="http://www.globus.org/namespaces/2004/02/progtutorial/MathService" attributeFormDefault="qualified" elementFormDefault="qualified" xmlns="http://www.w3.org/2001/XMLSchema"> <xsd:element name="add"> <xsd:complexType> <xsd:sequence> <xsd:element name="value" type="xsd:int"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="addResponse"> <xsd:complexType/> </xsd:element> </xsd:schema> </types>

  17. The whole GWSDL file http://www.casa-sotomayor.net/gt3-tutorial/multiplehtml/apas01.html

  18. WSDL and GWSDL • GWSDL has certain features that WSDL 1.1 doesn't have, but which will be available in WSDL 1.2/2.0 (still a W3C working draft) • GWSDL is a temporary solution • First improvement: not using the WSDL <portType> tag, but a tag from the GWSDL namespace: <gwsdl:portType> that extends … • Can extend from one or more portTypes • Second improvement is related to Service Data

  19. Five Steps • Define the service's interface. This is done with GWSDL • Implement the service. This is done with Java • Define the deployment parameters. This is done with WSDD • Compile everything and generate GAR file. This is done with Ant • Deploy service. This is also done with Ant

  20. Step 2: Implement the Service Implement the service MathImpl and place in: $TUTORIAL_DIR/org/globus/progtutorial/services/core/first/impl/MathImpl.java

  21. MathImpl.java package org.globus.progtutorial.services.core.first.impl; import org.globus.ogsa.impl.ogsi.GridServiceImpl; import org.globus.progtutorial.stubs.MathService.MathPortType; import java.rmi.RemoteException; public class MathImpl extends GridServiceImpl implements MathPortType • MathImpl is a child class of GridServiceImpl • All Grid Services extend GridServiceImpl. • This is what is usually called the skeleton class • Our Grid Service implements an interface named MathPortType • one of the stub files which will be generated from the GWSDL file once we compile the service

  22. public class MathImpl extends GridServiceImpl implements MathPortType { private int value = 0; public MathImpl() { super("Simple MathService"); } public void add(int a) throws RemoteException { value = value + a; } public void subtract(int a) throws RemoteException { value = value - a; } public int getValue() throws RemoteException { return value; } }

  23. Five Steps • Define the service's interface. This is done with GWSDL • Implement the service. This is done with Java • Define the deployment parameters. This is done with WSDD • Compile everything and generate GAR file. This is done with Ant • Deploy service. This is also done with Ant

  24. Step 3: Configure the deployment in WSDD Save a file called $TUTORIAL_DIR/org/globus/progtutorial/services/core/first/server-deploy.wsdd

  25. <?xml version="1.0"?> <deployment name="defaultServerConfig" xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java"> <service name="progtutorial/core/first/MathService" provider="Handler" style="wrapped"> <parameter name="name" value="MathService"/> <parameter name="className" value="org.globus.progtutorial.stubs.MathService.MathPortType"/> <parameter name="baseClassName" value="org.globus.progtutorial.services.core.first.impl.MathImpl"/> <parameter name="schemaPath" value="schema/progtutorial/MathService/Math_service.wsdl"/> <!-- Start common parameters --> <parameter name="allowedMethods" value="*"/> <parameter name="persistent" value="true"/> <parameter name="handlerClass" value="org.globus.ogsa.handlers.RPCURIProvider"/> </service> </deployment>

  26. Root element <?xml version="1.0"?> <deployment name="defaultServerConfig" xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">

  27. Service name <service name="progtutorial/core/first/MathService" provider="Handler" style="wrapped"> • Specifies the location where our Grid Service will be found. • Combined with the base address of Grid Service container, gives the full GSH of the Grid Service. • For example, if we are using the GT3 standalone container, the base URL will probably be http://localhost:8080/ogsa/services. • Therefore, our service's GSH would be: http://localhost:8080/ogsa/services/progtutorial/core/first/MathService

  28. Service name again <parameter name="name" value="MathService"/> The service element has both a name attribute and a name parameter!

  29. className and baseClassName <parameter name="className" value="org.globus.progtutorial.stubs.MathService.MathPortType"/> <parameter name="baseClassName" value="org.globus.progtutorial.services.core.first.impl.MathImpl"/> • className refers to the interface that exposes all the functionality of the grid service (MathPortType) • baseClassName is the class that provides the implementation for our grid service.

  30. WSDL file <parameter name="schemaPath" value="schema/progtutorial/MathService/Math_service.wsdl"/> • Tells the grid service container where the WSDL file for this service can be found • GWSDL is a (non-standard) extension of WSDL • It must first be converted to WSDL so it can be truly interoperable with existing web services technologies. • WSDL file (Math_service.wsdl) will be generated automatically by a GT3 tool when we compile the service.

  31. Common parameters <!-- Start common parameters --> <parameter name="allowedMethods" value="*"/> <parameter name="persistent" value="true"/> <parameter name="handlerClass" value="org.globus.ogsa.handlers.RPCURIProvider"/> Three parameters found in every grid service we program.

  32. Five Steps • Define the service's interface. This is done with GWSDL • Implement the service. This is done with Java • Define the deployment parameters. This is done with WSDD • Compile everything and generate GAR file. This is done with Ant • Deploy service. This is also done with Ant

  33. Step 4: Create a GAR file with ANT • Using those three files we wrote we generate a Grid Archive, or GAR file. • This GAR file is a single file which contains all the files and information the grid services container need to deploy our service and make it available to the whole world.

  34. Creating a GAR • Converting the GWSDL into WSDL • Creating the stub classes from the WSDL • Compiling the stubs classes • Compiling the service implementation • Organize all the files into a very specific directory structure We’ll have a detailed discussion on ant soon.

  35. Using the tutorial scripts ./tutorial_build.sh <service base directory> <service's GWSDL file> • Run this from $TUTORIAL_DIR • A GAR file will be generated: $TUTORIAL_DIR/build/lib/org_globus_progtutorial_services_core_first.gar

  36. Five Steps • Define the service's interface. This is done with GWSDL • Implement the service. This is done with Java • Define the deployment parameters. This is done with WSDD • Compile everything and generate GAR file. This is done with Ant • Deploy service. This is also done with Ant

  37. Step 5: Deploy the service into a grid service • GAR file contains all the files and information the web server needs to deploy the Grid Service ant deploy -Dgar.name=<full path of GAR file> For example, with the GAR just created: ant deploy \ -Dgar.name=$TUTORIAL_DIR/build/lib/org_globus_progtutorial_services_core_first.gar

  38. A simple client package org.globus.progtutorial.clients.MathService; import org.globus.progtutorial.stubs.MathService.service.MathServiceGridLocator; import org.globus.progtutorial.stubs.MathService.MathPortType; import java.net.URL; public class Client { public static void main(String[] args) { try { // Get command-line arguments URL GSH = new java.net.URL(args[0]); int a = Integer.parseInt(args[1]);

  39. // Get a reference to the MathService instance MathServiceGridLocator mathServiceLocator = new MathServiceGridLocator(); MathPortType math = mathServiceLocator.getMathServicePort(GSH); // Call remote method 'add' math.add(a); System.out.println("Added " + a); // Get current value through remote method 'getValue' int value = math.getValue(); System.out.println("Current value: " + value); }catch(Exception e) { System.out.println("ERROR!"); e.printStackTrace(); } } } Save this file in $TUTORIAL_DIR/org/globus/progtutorial/clients/MathService/Client.java

  40. Compile the client source $GLOBUS_LOCATION/etc/globus-devel-env.sh • To put the Globus libraries into your CLASSPATH javac \ -classpath ./build/classes/:$CLASSPATH \ org/globus/progtutorial/clients/MathService/Client.java

  41. Start the container (and the service) globus-start-container • See if the following line appears in the list of services! http://127.0.0.1:8080/ogsa/services/progtutorial/core/first/MathService

  42. Execute the client java \ -classpath ./build/classes/:$CLASSPATH \ org.globus.progtutorial.clients.MathService.Client \ http://127.0.0.1:8080/ogsa/services/progtutorial/core/first/MathService \ 5 If all goes well, you should see the following: Added 5 Current value: 5

  43. Chapter 4:Operation Providers • The previous example showed implementation by inheritance public class MathImpl extends GridServiceImpl implements MathPortType • Operation providers offer implementation by delegation

  44. Implementation by inheritanceMathImpl class has to provide all the operations specified

  45. Implementation by delegationThe operations of PortType are in several classes.

  46. Implementation by delegation • The classes don’t extend any base class • The only implement an interface called Operation Provider • We tell the Grid Service container that GridServiceImpl will supply the basic functionality • done with the deployment descriptor

  47. Can’t extend another Java class and extend GridServiceImpl

  48. Can extend another Java class and implement OperationProvider

  49. Tradeoffs of implementation by delegation • Favors more modular, uncoupled, and reusable designs • Is somewhat more work to code than the inheritance approach • Both approaches are not mutually exclusive • Can implement part of portType in a class that extends from GridServiceImpl and then complete the implementation with operation providers

  50. Writing an operation provider • Same GWSDL as before • Implementation of service is a little different

More Related