how to write a grid service the grid service will do basic mathematical operations. the math grid...

18
How to Write a Grid Service The grid service will do basic mathematical operations. The math grid service is going to have the following methods: add: The input of the method will be an integer value. The method is going to add the input value to the previous sum. The initial value will be set to 0. The method will not return any value. subtract: This method will work in the same way with ‘add’ operation, as described above. However, it will subtract the values. getValue: The method will return the value.

Upload: alberta-jennings

Post on 06-Jan-2018

216 views

Category:

Documents


2 download

DESCRIPTION

How to Write a Grid Service  We require four files to deploy a basic service: A grid service interface file that defines the service method’s descriptions. A grid service implementation file that implements the interface functions. A WSDD file (Web service deployment descriptor) that describes the web server how it should publish the grid service. A properties file to provide the directory information of the service.

TRANSCRIPT

Page 1: How to Write a Grid Service  The grid service will do basic mathematical operations. The math grid service is going to have the following methods:  add:

How to Write a Grid Service

The grid service will do basic mathematical operations. The math grid service is going to have the following methods:

add: The input of the method will be an integer value. The method is going to add the input value to the previous sum.

The initial value will be set to 0. The method will not return any value.

subtract: This method will work in the same way with ‘add’ operation, as described above. However, it will subtract the values.

getValue: The method will return the value.

Page 2: How to Write a Grid Service  The grid service will do basic mathematical operations. The math grid service is going to have the following methods:  add:

How to Write a Grid Service

Change your directory to “gt3/samples”. cd gt3/samples

Create the following directory structure. This is actually the package name of the service.

Page 3: How to Write a Grid Service  The grid service will do basic mathematical operations. The math grid service is going to have the following methods:  add:

How to Write a Grid Service

We require four files to deploy a basic service: A grid service interface file that defines the service

method’s descriptions. A grid service implementation file that implements

the interface functions. A WSDD file (Web service deployment descriptor)

that describes the web server how it should publish the grid service.

A properties file to provide the directory information of the service.

Page 4: How to Write a Grid Service  The grid service will do basic mathematical operations. The math grid service is going to have the following methods:  add:

How to Write a Grid Service Grid Service Interface

The file name is selected as Math. It should be placed under

/grid/mathtutorial/core/factory/impl The interface should include the package name:

mathtutorial.core.factory.impl The interface name should be as same as the file

name:public interface Math

Page 5: How to Write a Grid Service  The grid service will do basic mathematical operations. The math grid service is going to have the following methods:  add:

How to Write a Grid Service Grid Service Interface

package mathtutorial.core.factory.impl; public interface Math { public void add(int a);

public void subtract(int a); public int getValue();}

Page 6: How to Write a Grid Service  The grid service will do basic mathematical operations. The math grid service is going to have the following methods:  add:

How to Write a Grid Service Grid Service Implementation

The name will be “interface name”+Impl. Hence, here the file name will be MathImpl. If your interface name is X, the file name would be “XImpl”.

It should be placed under /grid/mathtutorial/core/factory/impl The interface should include the package name:

mathtutorial.core.factory.impl The class name will be as same as the file name. It should extend

GridServiceImpl and implements MathPortType. MathPortType is required for your service communication and will be

generated automatically when you deployed. If your service interface name is X, then this would be named as “XPortType”. You are expected to include the following packages for all your services:

import org.globus.ogsa.impl.ogsi.GridServiceImpl;import mathtutorial.core.factory.Math.MathPortType;import java.rmi.RemoteException;

You should implement the each interface method in the implementation file.

Page 7: How to Write a Grid Service  The grid service will do basic mathematical operations. The math grid service is going to have the following methods:  add:

How to Write a Grid Service Grid Service Implementation

package mathtutorial.core.factory.impl;import org.globus.ogsa.impl.ogsi.GridServiceImpl;import mathtutorial.core.factory.Math.MathPortType;import java.rmi.RemoteException;public class MathImpl extends GridServiceImpl implements MathPortType{

private int value = 0;public MathImpl(){super("Simple Math Factory Service");}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;}

}

Page 8: How to Write a Grid Service  The grid service will do basic mathematical operations. The math grid service is going to have the following methods:  add:

How to Write a Grid Service Grid Service WSDD

One of the key components of the deployment phase is a file called ‘deployment descriptor’. It’s the file that tells the web server how it should publish our grid service. The deployment descriptor is written in WSDD (Web Service Deployment Descriptor) format.

You should do the following changes in your WSDD file each time you deploy your service:

Change the service name accordingly: mathtutorial/core/factory/MathFactoryService

(the directory structure + interface name + “FactoryName”) Change schema path accordingly:

schema/mathtutorial.core.factory/Math/MathService.wsdl(“schema” + the directory structure + interface name + interface name “Service”.wsdl)

The schemaPath tells the grid services container where the WSDL file for this service can be found.

Page 9: How to Write a Grid Service  The grid service will do basic mathematical operations. The math grid service is going to have the following methods:  add:

How to Write a Grid Service Grid Service WSDD

Point the baseClassName variable to your implementation file:

mathtutorial.core.factory.impl.MathImpl Such name conventions are required for

automatic deployment. The build.xml file parses those information, generates all the communication files (such as stubs) and do the namings for you.

The WSDD file should be placed under mathtutorial/core/factory directory.

Page 10: How to Write a Grid Service  The grid service will do basic mathematical operations. The math grid service is going to have the following methods:  add:

How to Write a Grid Service Grid Service 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="mathtutorial/core/factory/MathFactoryService" provider="Handler" style="wrapped"><parameter name="name" value="MathService Factory"/><parameter name="instance-name" value="MathService Instance"/><parameter name="instance-schemaPath" value="schema/mathtutorial.core.factory/Math/MathService.wsdl"/><parameter name="instance-baseClassName" value="mathtutorial.core.factory.impl.MathImpl"/><!-- Start common parameters --><parameter name="allowedMethods" value="*"/><parameter name="persistent" value="true"/><parameter name="className" value="org.gridforum.ogsi.Factory"/><parameter name="baseClassName" value="org.globus.ogsa.impl.ogsi.PersistentGridServiceImpl"/><parameter name="schemaPath" value="schema/ogsi/ogsi_factory_service.wsdl"/><parameter name="handlerClass" value="org.globus.ogsa.handlers.RPCURIProvider"/><parameter name="factoryCallback" value="org.globus.ogsa.impl.ogsi.DynamicFactoryCallbackImpl"/><parameter name="operationProviders" value="org.globus.ogsa.impl.ogsi.FactoryProvider"/></service>

.</deployment>

Page 11: How to Write a Grid Service  The grid service will do basic mathematical operations. The math grid service is going to have the following methods:  add:

How to Write a Grid Service Preparing files to build the service

Copy the following files to your grid directory: cp

/a/juliet/vol/juliet/www/computing/courses/csm23/Tutorials/build.* $HOME/gt3/samples/grid/

We are going to modify the “build.properties” file.ogsa.root=../..interface.name=Mathpackage.dir=./mathtutorial/core/factorypackage=mathtutorial.core.factory

We need to copy and modify these files accordingly each time we want to deploy a service.

Page 12: How to Write a Grid Service  The grid service will do basic mathematical operations. The math grid service is going to have the following methods:  add:

How to Write a Grid Service How to Deploy

Change your directory to $HOME/gt3/samples/grid. Deploy the service:

ant -Djava.interface=true -Dpackage=mathtutorial.core.factory -Dinterface.name=Math -Dpackage.dir=mathtutorial/core/factory/ -Dservices.namespace=factory.core.mathtutorial

Before we proceed, goto $HOME/gt3/samples/grid directory and list the contents of the directory. You will see “build” directory there. Please find the following files and tell where you found them:

MathPortType.class MathGridServiceLocator.class MathImpl.class

Note: To change the directory use “cd”, and to display the contents of the directory, use “ls” command.

Page 13: How to Write a Grid Service  The grid service will do basic mathematical operations. The math grid service is going to have the following methods:  add:

How to Write a Grid Service How to Deploy

Set the sample directory environment variable.setenv TUTORIAL_DIR $HOME/gt3/samples/grid

Goto GT3 directory for finalise deployment.cd $HOME/gt3

We deploy our service.ant deploy -Dgar.name=$TUTORIAL_DIR/build/lib/mathtutorial.core.factory.Math.gar Before proceeding, open “build.xml” using pico editor. Find the “deploy” keyword

using CTRL+W command. You should see the following lines: <target name="deploy"> <ant antfile="${build.packages}" target="deployGar"> <property name="gar.name" value="${gar.name}"/> </ant> </target> Explain what is indicated in these lines.

Page 14: How to Write a Grid Service  The grid service will do basic mathematical operations. The math grid service is going to have the following methods:  add:

How to Write a Grid Service How to Deploy

Go to $HOME/gt3/schema directory and try to find your package. cd $HOME/gt3/schema

Did you find it? Can you point where your MathService.wsdl?

Can you relate it to your WSDD file? Open the file and explain the section comprising “add”

operation. <element name="add"> <complexType> <sequence> <element name="in0" type="xsd:int"/> </sequence> </complexType> </element>

Page 15: How to Write a Grid Service  The grid service will do basic mathematical operations. The math grid service is going to have the following methods:  add:

How to Write a Grid Service Testing the Grid Service

Start the service container:globus-start-container –p $MYPORT

Go to your client directory.cd $HOME/gt3/samples/grid/mathtutorial/core/factory/client Then, open a new file called “MathClient.java”. The package name will be:

mathtutorial.core.factory.client The following packages should be included in the client

program:import mathtutorial.core.factory.Math.MathServiceGridLocator;import mathtutorial.core.factory.Math.MathPortType;

Page 16: How to Write a Grid Service  The grid service will do basic mathematical operations. The math grid service is going to have the following methods:  add:

How to Write a Grid Service Testing the Grid Service

package mathtutorial.core.factory.client;import mathtutorial.core.factory.Math.MathServiceGridLocator;import mathtutorial.core.factory.Math.MathPortType;import java.net.URL;public class MathClient{

public static void main(String[] args){try{// Get command-line argumentsURL GSH = new java.net.URL(args[0]);int a = Integer.parseInt(args[1]);// Get a reference to the MathService instanceMathServiceGridLocator mathServiceLocator = new MathServiceGridLocator();MathPortType math = mathServiceLocator.getMathService(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();}}

}

Page 17: How to Write a Grid Service  The grid service will do basic mathematical operations. The math grid service is going to have the following methods:  add:

How to Write a Grid Service Testing the Grid Service

cd $HOME/gt3/samples/grid javac -classpath ./build/classes:$CLASSPATH mathtutorial/core/factory/client/MathClient.java

Create an instance from the service:ogsi-create-service http://131.227.74.148:9090/ogsa/services/mathtutorial/core/factory/MathFactoryService math1

Run the client program:java mathtutorial.core.factory.client.MathClient http://131.227.74.148:9090/ogsa/services/mathtutorial/core/factory/MathFactoryService/math1 3

DO NOT FORGET TO CHANGE THE PORT NUMBER AND IP ADDRESS BY LOOKING AT YOUR SERVICE CONTAINER.

Page 18: How to Write a Grid Service  The grid service will do basic mathematical operations. The math grid service is going to have the following methods:  add:

How to Write a Grid Service Exercises

Modify the client program to subtract a value. Add multiplication operation to the service.

Note: Before you modify the service, you should undeploy the service. Because the changes you made will not take effect.

cd $HOME/gt3 ant undeploy -Dgar.id=mathtutorial