Gt3 tutorial chapter 3 and chapter 4
This presentation is the property of its rightful owner.
Sponsored Links
1 / 52

GT3 Tutorial Chapter 3 and Chapter 4 PowerPoint PPT Presentation


  • 155 Views
  • Uploaded on
  • Presentation posted in: General

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.

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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


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/


Chapter 3:Writing your first Grid Service

  • Math Service

    • Will perform two operations, addition and subtraction


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


$TUTORIAL_DIR

|

|-- schema/

| |

| |-- progtutorial/ -----> GWSDL files

|

|--- org/

|

|-- globus/

|

|-- progtutorial/

|

|-- services/ -----> Service impL files

|

|-- clients/ -----> Client impl files


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


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


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!?!


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>


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/">


<definitions …>

name: the ‘name’ of the GWSDL file. Not related with the name of the PortType

targetNamespace: The target namespace of the GWSDL file.


<import …>

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


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>


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.


Inside portType

  • An <operation> tag for each method in the PortType

  • Operation tag has an input tag, an output tag, and a fault tag


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


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>


The whole GWSDL file

http://www.casa-sotomayor.net/gt3-tutorial/multiplehtml/apas01.html


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


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


Step 2: Implement the Service

Implement the service MathImpl and place in:

$TUTORIAL_DIR/org/globus/progtutorial/services/core/first/impl/MathImpl.java


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


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;

}

}


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


Step 3: Configure the deployment in WSDD

Save a file called

$TUTORIAL_DIR/org/globus/progtutorial/services/core/first/server-deploy.wsdd


<?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>


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">


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


Service name again

<parameter name="name" value="MathService"/>

The service element has both a name attribute and a name parameter!


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.


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.


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.


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


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.


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.


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


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


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


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]);


// 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


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


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


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


Chapter 4:Operation Providers

  • The previous example showed implementation by inheritance

    public class MathImpl extends GridServiceImpl implements MathPortType

  • Operation providers offer implementation by delegation


Implementation by inheritanceMathImpl class has to provide all the operations specified


Implementation by delegationThe operations of PortType are in several classes.


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


Can’t extend another Java class and extend GridServiceImpl


Can extend another Java class and implement OperationProvider


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


Writing an operation provider

  • Same GWSDL as before

  • Implementation of service is a little different


public class MathProvider implements OperationProvider

{

// Operation provider properties

private static final String namespace = "http://www.globus.org/namespaces/2004/02/progtutorial/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; }


Writing an operation provider

  • The deployment descriptor is a little different

    See http://www.casa-sotomayor.net/gt3-tutorial/multiplehtml/ch04s03.html

  • Client is the same


  • Login