and implemented

Download Report

Transcript and implemented

Developing Service using GT4
Writing Your First Stateful
Web Service in 5 Simple Steps
Adam Belloum
November, 2006
Outline
• What is OGSA, WSRF, GT4?
• The MathService example
• 5 steps to implement GT4 MathService:





Step1:
Step2:
Step3:
Step4:
Step5:
November, 2006
define the Interface in the WSDL
implement the MathService in java
configure the deployment (WSDD & JNDI)
create the deployement File
The client application
Preparation: download GT4, and ANT
• Make sure you use bash shell not a tcshell
Just Type $ bash
• Download the WS-core service of GT4

www.globus.org/toolkit/downloads/4.0.4/#wscore_bin/
 Untar the compressed file: just type
$ tar zxvf ws-core-4.0.4-bin.tar.gz
• Download the Ant version 7
 http://ant.apache.org/bindownload.cgi/
$ tar zxvf apache-ant-1.7.0-bin.tar.gz
NOTE:
November, 2006
Preparation: setting up your environment
• Define & set the environment variable
 ANT_HOME
$ export ANT_HOME=$HOME/<ANT_dir>/
 GLOBUS_LOCATION
$ export GLOBUS_LOCATION=$HOME/<WS-CORE_dir>/
 JAVA_HOME
$ export JAVA_HOME=/usr/java/<jdk_dir>
• PATH:
$ export PATH=$JAVA_HOME/bin: \
$ANT_HOME/bin: \
$GLOBUS_LOCATION/bin:$PATH
NOTE: we use $HOME because installed both ANT and WS-CORE
2006 directory
inNovember,
you home
Preparation: test if it works
• Start the container:
$ globus-start-container –nosec
• Watch your screen carefully spot any Error
message
• Stop the container:
$ globus-stop-container
NOTE: globus-stop-container seem to require grid credential, for now just
November,
stop
the2006
container <ctrl>+C or the unix command kill
Preparation: Finally download the tutorial
• This is a very important step
 if you don’t want to re-write everything from
scratch
• http://gdp.globus.org/gt4-tutorial/
$ tar zxvf progtutorialexamples_0.2.1.tar.gz
November, 2006
You are ready to start your first
experience with The Grid
Enjoy & Good luck
November, 2006
Introduction: OGSA, WSRF, and GT4
• Open Grid Services Architecture (OGSA), developed by The
Global Grid Forum,
• aims to define a common, standard, and open architecture for gridbased applications
• Web Services Resource
Framework, a specification
developed by OASIS.
• WSRF specifies how we can
make our Web Services stateful,
along with adding a lot of other
cool features
WSRF
WSRF
WSRF
WSRF
Notification
Resource
fault
WSRF
Life
Properties
OGSA
requires
specifies
Stateful
Web service
extends
November, 2006
Web service
Introduction: How does this relate to GT4?
Globus
Toolkit 4
• GT4, includes quite a few
high-level services that can be
Implements
Implements
used to build Grid applications
Service
Service
• These services, meet most ofHigh-level
High-level Services
Other
packages
Implementation
Implementation
Services
Adequate
for
Grid
(WSRF.NET,
(java)…)
High-level
Services
(java)
for
Grid
the abstract requirements setAdequate
Applications
Applications
forth in OGSA
Implements
meet requirements of
• GT4 includes a complete
Implemented
on top of
implementation of the WSRF
WSRF
WSRF
WSRF
WSRF
Notification
Resource
OGSA
fault
specification.
WSRF
Life
Properties
• GT4 isn't the only WSRF
requires
specifies
implementation. Another
Stateful
complete implementation of
Web service
the WSRF specification is
extends
WSRF.NET.
November, 2006
Web service
Introduction: The mandatory layered diagram
Standards in the work (ggf)
-VO management
-Security
-Resource Management
-Data services
Etc.
Grid Application based
On the high-level service defined by
OGSA
(not implemented form scratch)
Applications
OGSA
GT4 include many of the
services required by
OGSA
WSRF
Web service
Standardized (W3C) and
implemented
(e.g. Apache axis)
November, 2006
Standardized (OASIS)
and implemented GT4
Tutorial starts:The first web service
• The first web service is an extremely simple Math
Web Service, which we'll refer to as MathService.
• It will allow users to perform the following operations:
o
Addition
o
Subtraction
• MathService will have the
following resource properties
(RPs for short):
o
o
Value (integer)
Last operation performed (string)
November, 2006
public interface Math {
public void add(int a);
public void subtract(int a);
public int getValueRP();
}
The MathService web service
MathService
•Add() & substract() operation on the
resource propertiesContained in the
resource
Void add(int a)
Void sub(int a)
MathResource
Client
Int value
String last Op
•The Client interacts with
the stateless Web service
STATELESS
•GT4 suplies a resource home called
ServiceResourceHome
•When asked for a resource, this special type of
resource home always returns service object
GT4
ServiceResourceHome
STATEFUL
November, 2006
Step 1: Define the Interface in WSDL
• WSRF and GT4-specific features of WSDL
 Resource properties
 The WSDL Preprocessor
 No bindings: Bindings are an essential part of a normal
WSDL file. However, we don't have to add them, they are
generated automatically by a GT4 tool that is called when
we build the service
• Namespace mappings
 WSDL is that it's language-neutral. Because we need to
refer to the interface defined in WSDL from some specific
language we need to:
o
o
map WSDL namespaces to specific language (Java
packages)
$EXAMPLES_DIR/namespace2package.properties
November, 2006
Step 1: Define the Interface in WSDL
<?xml version="1.0" encoding="UTF-8"?>
<!--===== Headers ===========-->
<definitions name="MathService"
<wsdl:import namespace=http://<URL-of-wsrf-WS-ResourceProperties.wsdl>
location="../../wsrf/properties/WS-ResourceProperties.wsdl" />
<!--===== T Y P E S ===========-->
<!-- REQUESTS AND RESPONSES -->
<types>
<!– LIST …
OF MESSAGES -->
…
<!-- RESOURCE PROPERTIES -->
</types>
… name="AddInputMessage">
<message
<!--===== M E S S A G E S =====-->
<part name="parameters" element="tns:add"/>
<message >
</message>
</message>
…
…
<!--===== P O R T T Y P E ======-->
<portType name="MathPortType"
<!– LIST OF OPERATIONS -->
wsdlpp:extends="wsrpw:GetResourceProperty“
wsrp:ResourceProperties="tns:MathResourceProperties">
>
<operation name="add">
…
<input message="tns:AddInputMessage"/>
</portType>
<output message="tns:AddOutputMessage"/>
</definitions>
</operation>
November, 2006
…
$EXAMPLES_DIR/schema/examples/MathService_instance/Math.wsdl
Step 2: Implementing the Service
• The QNames interface
o
QNames includes a namespace and a local name.
o
For example, the QName of the Value RP is:


{http://www.globus.org/namespaces/examples/co
re/MathService_instance}Value
$EXAMPLES_DIR/org/globus/examples/services/co
re/first/impl/MathQNames.java
• The service implementation
•

November, 2006
$EXAMPLE_DIR/org/globus/examples/services/cor
e/first/impl/MathService.java
Step 2: Implementing the Service
package org.globus.examples.services.core.first.impl;
import java.rmi.RemoteException;
Import <org.globus….>
public class MathService implements Resource, ResourceProperties {
}
public MathService() throws RemoteException {
/* Create
/* Resource Property
set */ RP set */
this.propSet
= new SimpleResourcePropertySet(
private ResourcePropertySet
propSet;
MathQNames.RESOURCE_PROPERTIES);
/* Constructor. Initializes
RPs */
/* Initialize
the RP's */
public MathService()
try {throws RemoteException {…}
ResourceProperty valueRP =
/* Get/Setters for the RPs */
new ReflectionResourceProperty(
…
MathQNames.RP_VALUE, "Value", this);
/* Remotely-accessible operations */
this.propSet.add(valueRP);
…
setValue(0);add(int a) throws RemoteException {
public AddResponse
/* Required by interface ResourceProperties */
value…
+= a;
public ResourcePropertySet
getResourcePropertySet()
{
public
int getValue()
{ e) {
}
catch
(Exception
lastOp
=
"ADDITION";
return this.propSet;
return
value;
throw
new RuntimeException(e.getMessage());
}
} return
}
new AddResponse();
}
November, 2006
Step 3: Configuring the deployment in
WSDD (and JNDI)
• The WSDD deployment descriptor
 The
file that tells the Web Services container how it should
<?xml version="1.0"
encoding="UTF-8"?>
publish our web service
<deployment name="defaultServerConfig"
<?xml version="1.0" encoding="UTF-8"?>
xmlns="http://xml.apache.org/axis/wsdd/"
 deployment descriptor is written in WSDD format (Web Service
<jndiConfig xmlns="http://wsrf.globus.org/jndi/config">
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java"
Deployment Descriptor)
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<service name="examples/core/first/MathService">
• The
JNDIname="home"
deployment
file specifies:
<resource
type="org.globus.wsrf.impl.ServiceResourceHome">
<service name="examples/core/first/MathService"
<resourceParams>
 what resource home our service has to use to get a hold of
provider="Handler"
use="literal" style="document">
resources.
<parameter name="className“
<parameter>
 value="org.globus…..core.first.impl.MathService"/>
parameters related to how the resource home manages those
<name>factory</name>
<wsdlFile>share/schema/examples/…/Math_service.wsdl</wsdlFile>
resources.
<value>org.globus.wsrf.jndi.BeanFactory</value>
<parameter name="allowedMethods" value="*"/>
</parameter>
 Here we use the standard GT4 ServiceResourceHome which
<parameter name="handlerClass" value="org.globus.axis.providers.RPCProvider"/>
always returns
service object
<parameter name="scope"
value="Application"/>
</resourceParams>
<parameter name="providers" value="GetRPProvider"/>
<parameter name="loadOnStartup" value="true"/>
</resource>
</service>
</service>
</jndiConfig>
November, 2006
Step 4: Create & deploy a GAR file
Service
Interface
(WSDL)
Service
Service
Service
Implementation
Implementation
Implementation
(java)
(java)
(java)
GT4build
build
GT4
GT4
build
files
files
files
Apache Ant
•Provided with the GT4
distribution
GAR
File
Deployment
Deployment
Files
Files
WSDD
WSDD
&
&JNDI
JNDI
Ant Build file
build.xml
•Provided with GT4 tutorial
globus-deploy-gar $EXAMPLES_DIR/org_globus_examples_services_core_first.gar
globus-undeploy-gar
org_globus_examples_services_core_first
./globus-build-service.sh
\
-d org/globus/examples/services/core/first/ \
-s schema/examples/MathService_instance/Math.wsdl
NOTE:
deployment command must be run with a user that has write
November, 2006
permission in $GLOBUS_LOCATION
Step 5: Simple Client
• create an EndpointReferenceType
object representing the endpoint
reference of this service.
•Obtain a reference to the service'sportType.
…
•This is done with a stub class called
public static void main(String[] args) {
MathServiceAddressingLocator that,
•given the service's EPR, returns a MathPortType
object
will allow to contact the Math
MathServiceAddressingLocator locator =
new that
MathServiceAddressingLocator();
portType.
.
try {
String serviceURI=args[0];
•invoke the remote add operation, we simply
//step: 1
have to use the add method in the
EndpointReferenceType endpoint = new EndpointReferenceType();
MathPortType object. .
endpoint.setAddress(new Address(serviceURI));
//step: 2
MathPortType math = locator.getMathPortTypePort(endpoint);
//step: 3
math.add(10);
System.out.println("Current value:" + math.getValue(new GetValueRP()));
} catch (Exception e) {
e.printStackTrace();
}
November, 2006
Step 5: compile and run the Simple Client
1. Set the environment for the client
$ source \
$GLOBUS_LOCATION/etc/globus-devel-env.sh
2. Compile the simple client
$
javac –classpath \
./build/stubs/classes/:$CLASSPATH \
org/globus/examples/clients/MathService_instance/Client.java
3. run the simple client
$ java \ -classpath \
./build/stubs/classes/:$CLASSPATH \
org.globus.examples.clients.MathService_instance.Client
\
http://127.0.0.1:8080/wsrf/services/examples/core/first/MathService
November, 2006
Test your knowledge
1. What is OGSA, WSRF, GT4 ?
2. How does GT4 related to OGSA and WSRF?
3. which standardization body are involved? Who is doing
what ?
4. What are the WSRF specific part to be added to the a
standard WSDL
5. what is the role of the mapping
6. What is the role of the Qname
7. what is the Role of WSDD and JNDI
8. what are the steps to do to be able to use the service
9. What will happened if multiple clients try to use the first
implementation ?
10.What are the limits of this first implementation ?
November, 2006