170 likes | 344 Views
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….
E N D
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 • 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:
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.
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> </deployment>
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.Math.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