Download Service Data in Grid Services

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Service Data in Grid Services
 Service Data allows
us to easily include a
set of structured data
to any service, which
can then be
processed directly
through its interface.
 State information:
operation results,
intermediate results…
 Service metadata:
system data, cost of
using the service…
How to implement Service Data in Grid
Services
How to implement Service Data in Grid
Services

First, undeploy your previous Grid service.



cd $HOME/gt3
ant undeploy -Dgar.id=mathtutorial
Create a new directory called “servicedata”
under $HOME/gt3/samples/.


cd $HOME/gt3/samples
mkdir servicedata
How to implement Service Data in Grid
Services

Create the package directory structure:
servicedata
build.properties
namespace2mapping
build.xml
mathtutorial
core
factory
Math.wsdd
impl
MathImpl.java
schema
Math.gwsdl
MathSDE.xsd
client
Client.java
How to implement Service Data in Grid
Services

We require the following files:






Implementation file
Web service deployment descriptor that tells the
web server how it should publish our Grid service.
Grid web service description language (GWSDL)
file
Mappings file, which map GWSDL namespaces to
Java packages
XML schema file (extension XSD) which specifies
the complex data type of service data.
Client file to run the service.
How to implement Service Data in Grid
Services

MathSDE.xsd: Create this file under
mathtutorial/core/factory/schema directory.
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="MathData"
targetNamespace="http://www.globus.org/namespaces/2004/02/MathSDE"
xmlns:tns="http://www.globus.org/namespaces/2004/02/MathSDE"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:types>
<schema targetNamespace="http://www.globus.org/namespaces/2004/02/MathSDE"
attributeFormDefault="qualified"
elementFormDefault="qualified"
xmlns="http://www.w3.org/2001/XMLSchema">
<complexType name="MathDataType">
<sequence>
<element name="value" type="int"/>
<element name="lastOp" type="string"/>
<element name="numOps" type="int"/>
</sequence>
</complexType>
</schema>
</wsdl:types>
</wsdl:definitions>
How to implement Service Data in Grid
Services

Service interface: Math.gwsdl which will be saved
mathtutorial/core/factory/schema directory.
<sd:serviceData name="MathData"
type="data:MathDataType"
minOccurs="1"
maxOccurs="1"
mutability="mutable"
modifiable="false"
nillable="false">
</sd:serviceData>
How to implement Service Data in Grid
Services

Namespace file: namespace2package.mappings file to be
saved under servicedata directory.
http\://www.globus.org/namespaces/2004/02/MathSDE=mathtutorial.core.factory
http\://www.globus.org/namespaces/2004/02/bindings=mathtutorial.core.factory.bindings
http\://www.globus.org/namespaces/2004/02/service=mathtutorial.core.factory.service
http\://www.globus.org/namespaces/2004/02=mathtutorial.core.factory.Math
http\://www.gridforum.org/namespaces/2003/03/OGSI=org.gridforum.ogsi
How to implement Service Data in Grid
Services

Implementation file: MathImpl.java file to be saved under
mathtutorial/core/factory/ directory.
package mathtutorial.core.factory.impl;
import org.globus.ogsa.ServiceData;
import org.globus.ogsa.impl.ogsi.GridServiceImpl;
import org.globus.ogsa.GridContext;
import org.globus.ogsa.GridServiceException;
import mathtutorial.core.factory.Math.MathPortType;
import mathtutorial.core.factory.MathDataType;
import mathtutorial.core.factory.Math.*;
import mathtutorial.core.factory.bindings.*;
import mathtutorial.core.factory.service.*;
import java.rmi.RemoteException;
How to implement Service Data in Grid
Services

Implementation file: MathImpl.java file to be saved under
mathtutorial/core/factory/impl directory.
public class MathImpl extends GridServiceImpl implements MathPortType
{
private ServiceData mathDataSDE;
private MathDataType mathDataValue;
public MathImpl()
{ super("Simple MathService with Service Data");}
public void postCreate(GridContext context) throws GridServiceException
{
super.postCreate(context);
mathDataSDE = this.getServiceDataSet().create("MathData");
mathDataValue = new MathDataType();
mathDataValue.setLastOp("NONE");
mathDataValue.setNumOps(0);
mathDataValue.setValue(0);
mathDataSDE.setValue(mathDataValue);
this.getServiceDataSet().add(mathDataSDE);
}
How to implement Service Data in Grid
Services

Implementation file: MathImpl.java file to be saved under
mathtutorial/core/factory/impl directory.
private void incrementOps()
{
int numOps = mathDataValue.getNumOps();
mathDataValue.setNumOps(numOps + 1);
}
public void add(int a) throws RemoteException
{
mathDataValue.setLastOp("Addition");
incrementOps();
mathDataValue.setValue(mathDataValue.getValue() + a);
}
public void subtract(int a) throws RemoteException
{
mathDataValue.setLastOp("Subtraction");
incrementOps();
mathDataValue.setValue(mathDataValue.getValue() - a);
}
}
How to implement Service Data in Grid
Services

WSDD file: Math.wsdd file to be saved under
mathtutorial/core/factory/ directory.
c
<?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>
How to implement Service Data in Grid
Services

Build.properties file: build.properties file to be saved
under servicedata directory.
ogsa.root=../..
interface.name=Math
package.dir=./mathtutorial/core/factory
package=mathtutorial.core.factory
Copy build.xml file to be saved under servicedata directory.
How to implement Service Data in Grid
Services

Client file: client.java to be saved under
mathtutorial/core/factory/client directory.
package mathtutorial.core.factory.client;
import org.gridforum.ogsi.ExtensibilityType;
import org.gridforum.ogsi.ServiceDataValuesType;
import org.globus.ogsa.utils.AnyHelper;
import org.globus.ogsa.utils.QueryHelper;
import mathtutorial.core.factory.service.MathServiceGridLocator;
import mathtutorial.core.factory.Math.MathPortType;
import mathtutorial.core.factory.MathDataType;
import java.net.URL;
How to implement Service Data in Grid
Services

Client file: client.java to be saved under
mathtutorial/core/factory/client directory.
URL GSH = new java.net.URL(args[0]);
int a = Integer.parseInt(args[1]);
// Get a reference to the Math PortType
MathServiceGridLocator mathServiceLocator = new MathServiceGridLocator();
MathPortType math = mathServiceLocator.getMathServicePort(GSH);
// Get Service Data Element "MathData"
ExtensibilityType extensibility = math.findServiceData(QueryHelper.getNamesQuery("MathData"));
ServiceDataValuesType serviceData = AnyHelper.getAsServiceDataValues(extensibility);
MathDataType mathData = (MathDataType) AnyHelper.getAsSingleObject(serviceData, MathDataType.class);
// Write service data
System.out.println("Value: " + mathData.getValue());
System.out.println("Previous operation: " + mathData.getLastOp());
System.out.println("# of operations: " + mathData.getNumOps());
// Call remote method
math.add(a);
How to implement Service Data in Grid
Services

Deployment:


Set the TUTORIAL_DIR environment variable to
$HOME/gt3/samples/servicedata
 setenv TUTORIAL_DIR $HOME/gt3/samples/servicedata
Deploy your service (Directory = $TUTORIAL_DIR)
 ant -Dgwsdl.interface=true -Dpackage=mathtutorial.core.factory Dinterface.name=Math -Dpackage.dir=mathtutorial/core/factory/ Dgwsdl.interface=Math.gwsdl -Dsde.schema.file=MathSDE.xsd

Deploy in GT3 directory.
 ant deploy Dgar.name=$TUTORIAL_DIR/build/lib/mathtutorial.core.factory.Mat
h.gar

Run your Grid service container:
 globus-start-container –p $MYPORT
How to implement Service Data in Grid
Services

Client Side:


Open another terminal.
Compile the Client.java:
 javac -classpath ./build/classes/:$CLASSPATH
mathtutorial/core/factory/client/Client.java

Create an instance from your service.
 ogsi-create-service
http://131.227.74.147:28161/ogsa/services/mathtutorial/core/factory
/MathFactoryService math1

Run your client.
 java -classpath ./build/classes/:$CLASSPATH
mathtutorial/core/factory/client/Client
http://131.227.74.147:28161/ogsa/services/mathtutorial/core/factory
/MathFactoryService/math1 5