Title: GT3 Tutorial Chapter 3 and Chapter 4
1GT3 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/
2Chapter 3 Writing your first Grid Service
- Math Service
- Will perform two operations, addition and
subtraction
3Before you start
- Download the tutorial source files to your
account on talon.csce.uark.edu - http//www.casa-sotomayor.net/gt3-tutorial/downloa
d/progtutorial-examples_0.4.2.tar.gz
4- TUTORIAL_DIR
-
- -- schema/
-
- -- progtutorial/ -----gt GWSDL files
-
- --- org/
-
- -- globus/
-
- -- progtutorial/
-
- -- services/
-----gt Service impL files -
- -- clients/ -----gt
Client impl files
5Five 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
6Step 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
7The 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!?!
8Steps to GWSDL (Grid WSDL)
- Write the root element ltdefinitionsgt
- Write the ltgwsdlPortTypegt
- Write an input and output ltmessagegt for each
operation in the PortType. - Write the lttypesgt
9a. Write the root element
- lt?xml version"1.0" encoding"UTF-8"?gt
- ltdefinitions name"MathService"
- targetNamespace"http//www.globus.org/namespaces
/2004/02/progtutorial/MathService" - xmlnstns"http//www.globus.org/namespaces/2004/
02/progtutorial/MathService" - xmlnsogsi"http//www.gridforum.org/namespaces/2
003/03/OGSI" - xmlnsgwsdl"http//www.gridforum.org/namespaces/
2003/03/gridWSDLExtensions" - xmlnsxsd"http//www.w3.org/2001/XMLSchema"
- xmlns"http//schemas.xmlsoap.org/wsdl/"gt
10ltdefinitions gt
- name the name of the GWSDL file. Not related
with the name of the PortType - targetNamespace The target namespace of the
GWSDL file.
11ltimport gt
- ltimport location"../../ogsi/ogsi.gwsdl"
namespace"http//www.gridforum.org/namespaces/200
3/03/OGSI"/gt
12b. Write the PortType
- ltgwsdlportType name"MathPortType"
extends"ogsiGridService"gt - ltoperation name"add"gt
- ltinput message"tnsAddInputMessage"/gt
- ltoutput message"tnsAddOutputMessage"/gt
- ltfault name"Fault" message"ogsiFaultMessage"/
gt - lt/operationgt
- ltoperation name"subtract"gt
- ltinput message"tnsSubtractInputMessage"/gt
- ltoutput message"tnsSubtractOutputMessage"/gt
- ltfault name"Fault" message"ogsiFaultMessage"/
gt - lt/operationgt
- ltoperation name"getValue"gt
- ltinput message"tnsGetValueInputMessage"/gt
- ltoutput message"tnsGetValueOutputMessage"/gt
- ltfault name"Fault" message"ogsiFaultMessage"/
gt - lt/operationgt
- lt/gwsdlportTypegt
13portType 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 ogsiGridService PortType, which all
Grid Services must extend from.
14Inside portType
- An ltoperationgt tag for each method in the
PortType - Operation tag has an input tag, an output tag,
and a fault tag
15c. Write input and output messages for each port
type
- ltmessage name"AddInputMessage"gt
- ltpart name"parameters" element"tnsadd"/gt
- lt/messagegt
- ltmessage name"AddOutputMessage"gt
- ltpart name"parameters" element"tnsaddResponse"
/gt - lt/messagegt
- Message are composed of parts our messages have
one part, in which a single XML element is passed
along
16d. Define the XML elements inside the lttypesgt tag
- lttypesgt
- ltxsdschema targetNamespace"http//www.globus.org
/namespaces/2004/02/progtutorial/MathService" - attributeFormDefault"qualified"
- elementFormDefault"qualified"
- xmlns"http//www.w3.org/2001/XMLSchema"gt
- ltxsdelement name"add"gt
- ltxsdcomplexTypegt
- ltxsdsequencegt
- ltxsdelement name"value" type"xsdint"/gt
lt/xsdsequencegt - lt/xsdcomplexTypegt
- lt/xsdelementgt
- ltxsdelement name"addResponse"gt
- ltxsdcomplexType/gt
- lt/xsdelementgt
- lt/xsdschemagt
- lt/typesgt
17The whole GWSDL file
- http//www.casa-sotomayor.net/gt3-tutorial/multipl
ehtml/apas01.html
18WSDL 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 ltportTypegt
tag, but a tag from the GWSDL namespace
ltgwsdlportTypegt that extends - Can extend from one or more portTypes
- Second improvement is related to Service Data
19Five 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
20Step 2 Implement the Service
- Implement the service MathImpl and place in
- TUTORIAL_DIR/org/globus/progtutorial/services/cor
e/first/impl/MathImpl.java -
21MathImpl.java
- package org.globus.progtutorial.services.core.firs
t.impl - import org.globus.ogsa.impl.ogsi.GridServiceImpl
- import org.globus.progtutorial.stubs.MathService.M
athPortType - 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
-
-
23Five 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
24Step 3 Configure the deployment in WSDD
- Save a file called
- TUTORIAL_DIR/org/globus/progtutorial/services/cor
e/first/server-deploy.wsdd
25- lt?xml version"1.0"?gt
- ltdeployment name"defaultServerConfig"
- xmlns"http//xml.apache.org/axis/wsdd/"
- xmlnsjava"http//xml.apache.org/axis/wsdd/provi
ders/java"gt - ltservice name"progtutorial/core/first/MathServic
e" provider"Handler" style"wrapped"gt - ltparameter name"name" value"MathService"/gt
- ltparameter name"className" value"org.globus.pr
ogtutorial.stubs.MathService.MathPortType"/gt - ltparameter name"baseClassName"
value"org.globus.progtutorial.services.core.first
.impl.MathImpl"/gt - ltparameter name"schemaPath" value"schema/progt
utorial/MathService/Math_service.wsdl"/gt - lt!-- Start common parameters --gt
- ltparameter name"allowedMethods" value""/gt
- ltparameter name"persistent" value"true"/gt
- ltparameter name"handlerClass"
value"org.globus.ogsa.handlers.RPCURIProvider"/gt - lt/servicegt
26Root element
- lt?xml version"1.0"?gt
- ltdeployment name"defaultServerConfig"
xmlns"http//xml.apache.org/axis/wsdd/"
xmlnsjava"http//xml.apache.org/axis/wsdd/provid
ers/java"gt
27Service name
- ltservice name"progtutorial/core/first/MathService
" provider"Handler" style"wrapped"gt - 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//localhost8080/ogsa/services. - Therefore, our service's GSH would be
- http//localhost8080/ogsa/services/progtutorial/c
ore/first/MathService
28Service name again
- ltparameter name"name" value"MathService"/gt
- The service element has both a name attribute and
a name parameter!
29className and baseClassName
- ltparameter name"className" value"org.globus.prog
tutorial.stubs.MathService.MathPortType"/gt - ltparameter name"baseClassName"
value"org.globus.progtutorial.services.core.first
.impl.MathImpl"/gt - 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.
30WSDL file
- ltparameter name"schemaPath" value"schema/progtut
orial/MathService/Math_service.wsdl"/gt - 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.
31Common parameters
- lt!-- Start common parameters --gt
- ltparameter name"allowedMethods" value""/gt
- ltparameter name"persistent" value"true"/gt
- ltparameter name"handlerClass" value"org.globus.o
gsa.handlers.RPCURIProvider"/gt - Three parameters found in every grid service we
program.
32Five 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
33Step 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.
34Creating 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 - Well have a detailed discussion on ant soon.
35Using the tutorial scripts
- ./tutorial_build.sh ltservice base directorygt
ltservice's GWSDL filegt - Run this from TUTORIAL_DIR
- A GAR file will be generated
- TUTORIAL_DIR/build/lib/org_globus_progtutorial_se
rvices_core_first.gar
36Five 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
37Step 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.nameltfull path of GAR filegt
- For example, with the GAR just created
- ant deploy \ -Dgar.nameTUTORIAL_DIR/build/lib/or
g_globus_progtutorial_services_core_first.gar
38A simple client
- package org.globus.progtutorial.clients.MathServic
e - import org.globus.progtutorial.stubs.MathService.s
ervice.MathServiceGridLocator - import org.globus.progtutorial.stubs.MathService.M
athPortType - import java.net.URL
- public class Client
-
- public static void main(String args)
-
- try
- // Get command-line arguments
- URL GSH new java.net.URL(args0)
- int a Integer.parseInt(args1)
39- // Get a reference to the MathService instance
- MathServiceGridLocator mathServiceLocator new
MathServiceGridLocator() - MathPortType math mathServiceLocator.getMathServ
icePort(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()
-
-
-
40Compile 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
41Start the container (and the service)
- globus-start-container
- See if the following line appears in the list of
services! - http//127.0.0.18080/ogsa/services/progtutorial/c
ore/first/MathService
42Execute the client
- java \
- -classpath ./build/classes/CLASSPATH \
org.globus.progtutorial.clients.MathService.Client
\ http//127.0.0.18080/ogsa/services/progtutoria
l/core/first/MathService \ - 5
- If all goes well, you should see the following
- Added 5
- Current value 5
43Chapter 4Operation Providers
- The previous example showed implementation by
inheritance - public class MathImpl extends GridServiceImpl
implements MathPortType - Operation providers offer implementation by
delegation
44Implementation by inheritanceMathImpl class has
to provide all the operations specified
45Implementation by delegationThe operations of
PortType are in several classes.
46Implementation by delegation
- The classes dont 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
47Cant extend another Java class and extend
GridServiceImpl
48Can extend another Java class and implement
OperationProvider
49Tradeoffs 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
50Writing an operation provider
- Same GWSDL as before
- Implementation of service is a little different
51- public class MathProvider implements
OperationProvider -
- // Operation provider properties
- private static final String namespace
"http//www.globus.org/namespaces/2004/02/progtuto
rial/MathService" - private static final QName operations
- new QName
- new QName(namespace, "add"),
- new QName(namespace, "subtract"),
- new QName(namespace, "getValue")
-
- private GridServiceBase base
- // Operation Provider methods
- public void initialize(GridServiceBase base)
throws GridServiceException -
- this.base base
-
- public QName getOperations() return
operations
52Writing an operation provider
- The deployment descriptor is a little different
- See http//www.casa-sotomayor.net/gt3-tutorial/mul
tiplehtml/ch04s03.html - Client is the same