Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
University of Surrey Department of Computing Introductory Grid Computing Tutorial Notes #4 Date: 6/02/2005 Objectives: This tutorial aims to teach: Notifications in Grid Services References: For all the tutorial notes, you are expected to know the basics in Unix and Java. Please refer to the following tutorials for more information: Unix Tutorial for Beginners: http://www.ee.surrey.ac.uk/Teaching/Unix/ Java Tutorials and Code Camps: http://java.sun.com/learning/tutorial/index.html The Globus Toolkit 3 Programmer’s Tutorial: http://gdp.globus.org/gt3-tutorial/ You can download the tutorials from the course web page, which is: http://www.computing.surrey.ac.uk/courses/csm23 You can download the tutorial files from: http://www.computing.surrey.ac.uk/courses/csm23/Tutorials/Tutorial3_Files/ Instead of writing the commands manually, you can refer to the online version of the tutorials. Please do not forget to change the host ip and port name accordingly in the commands, when it is necessary. The implementations and the most explanations were taken from The Globus Toolkit 3 programmer’s tutorial, which was written by Borjo Sotomayor. You want to know when an observable has reached a certain number of users. One way of achieving this is to send a query to the server in frequent time intervals. However, this is not an efficient method as the network traffic will become busy and CPU use increases. Notifications in Grid technology aims to deal with this issue. You (observer) ask the observable to inform you when it reaches certain number of users and the server responds your query. So you are not required to send your query periodically. There are two principal observer/observable design patterns: 1. Pull: The observer asks the observable to notify itself when the requested change (query) has occurred. The observable informs the observer regarding the change but does not send the information relative to that change. The benefit of this approach is that different observers may require different information regarding the change. 2. Push: The data travels along with the notification information. This is beneficial if all the observers need the same information. Section I: Notifications in Grid Services 1. Undeploy your previous project: (Directory: $HOME/gt3) ant undeploy -Dgar.id=mathtutorial 2. Create a new directory called “notification” under $HOME/gt3/samples/. cd $HOME/gt3/samples mkdir notification 3. Create the following directory structure (Directory: $HOME/gt3/samples/notification) mkdir mathtutorial cd mathtutorial mkdir core cd core mkdir factory cd factory mkdir client mkdir impl University of Surrey Department of Computing Introductory Grid Computing Tutorial Notes #4 Date: 6/02/2005 mkdir schema notification build.properties namespace2mapping build.xml mathtutorial core factory Math.wsdd impl MathImpl.java schema Math.gwsdl MathSDE.xsd client ClienListener.java ClientAdder.java 4. Set the TUTORIAL_DIR environment variable to $HOME/gt3/samples/notification setenv TUTORIAL_DIR $HOME/gt3/samples/notification 5. Copy Math.gwsdl file to $TUTORIAL_DIR/mathtutorial/core/factory/schema. 6. Modify the following line in Math.gwsdl file: <gwsdl:portType name=”MathPortType” extends=”ogsi:GridService”> Change above line to the following: <gwsdl:portType name="MathPortType" extends="ogsi:GridService ogsi:NotificationSource"> 7. Copy MathSDE.xsd to $TUTORIAL_DIR/mathtutorial/code/factory/schema. 8. Copy namespace2package.mappings under $TUTORIAL_DIR. Please do not forget to change the contents of “namespace2package.mappings” file when you want to change the package name in your program. 9. Create Math.wsdd under $TUTORIAL_DIR/mathtutorial/code/factory and write the following lines to the file. <?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/MathService" provider="Handler" style="wrapped"> University of Surrey Department of Computing Introductory Grid Computing Tutorial Notes #4 Date: 6/02/2005 <parameter name="name" value="MathService "/> <parameter name="instance-name" value="MathService Instance"/> <parameter name="instance-schemaPath" value="schema/mathtutorial.core.factory/Math/Math_service.wsdl"/> <parameter name="instance-baseClassName" value="mathtutorial.core.factory.impl.MathImpl"/> <!-- Start common parameters --> <parameter name="name" value="MathService (with Notifications)"/> <parameter name="allowedMethods" value="*"/> <parameter name="persistent" value="true"/> <parameter name="className" value="mathtutorial.core.factory.Math.MathPortType"/> <parameter name="baseClassName" value="mathtutorial.core.factory.impl.MathImpl"/> <parameter name="schemaPath" value="schema/mathtutorial.core.factory/Math/Math_service.wsdl"/> <parameter name="handlerClass" value="org.globus.ogsa.handlers.RPCURIProvider"/> <parameter name="operationProviders" value="org.globus.ogsa.impl.ogsi.NotificationSourceProvider"/> </service> </deployment> The first part of Math.wsdd (parameter names starting with “instance”) file refers to the grid factory events. The second part deals with generic grid services. 10. Copy “MathImpl.java” to $TUTORIAL_DIR/mathtutorial/code/factory/impl. 11. Modify the following code block in MathImpl.java as follows: public void add(int a) throws RemoteException { mathDataValue.setLastOp("Addition"); incrementOps(); mathDataValue.setValue(mathDataValue.getValue() + a); mathDataSDE.notifyChange(); } Make the necessary changes in “subtract” method as well. “notifyChange” method notifies the subscribed clients. 12. Modify the MathImpl.java by importing the following packages. 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.MathDataType; import java.rmi.RemoteException; import org.globus.ogsa.impl.ogsi.PersistentGridServiceImpl; Then change the class inheritance to: public class MathImpl extends PersistentGridServiceImpl 13. Write the following lines to ClientListener.java, which should be placed under $TUTORIAL_DIR/mathtutorial/core/factory/client. package mathtutorial.core.factory.client; import org.globus.ogsa.client.managers.NotificationSinkManager; import org.globus.ogsa.NotificationSinkCallback; University of Surrey Department of Computing Introductory Grid Computing Tutorial Notes #4 Date: 6/02/2005 import org.globus.ogsa.impl.core.service.ServicePropertiesImpl; import java.rmi.RemoteException; import org.globus.ogsa.utils.AnyHelper; import org.gridforum.ogsi.ExtensibilityType; import org.gridforum.ogsi.HandleType; import org.gridforum.ogsi.ServiceDataValuesType; import mathtutorial.core.factory.MathDataType; import java.net.URL; public class ClientListener extends ServicePropertiesImpl implements NotificationSinkCallback { public static void main(String[] args) { try { // Get command-line arguments HandleType GSH = new HandleType(args[0]); ClientListener clientListener = new ClientListener(GSH); }catch(Exception e) { System.out.println("ERROR!"); e.printStackTrace(); } } public ClientListener(HandleType GSH) throws Exception { // Start listening to the MathService NotificationSinkManager notifManager = NotificationSinkManager.getManager(); notifManager.startListening(NotificationSinkManager.MAIN_THREAD); String sink = notifManager.addListener("MathData", null, GSH, this); System.out.println("Listening..."); // Wait for key press System.in.read(); // Stop listening notifManager.removeListener(sink); notifManager.stopListening(); System.out.println("Not listening anymore!"); } public void deliverNotification(ExtensibilityType any) throws RemoteException { try { // Service Data has changed. Show new data. ServiceDataValuesType serviceData = AnyHelper.getAsServiceDataValues(any); MathDataType mathData = (MathDataType) AnyHelper.getAsSingleObject(serviceData, MathDataType.class); // Write service data System.out.println("Current value: " + mathData.getValue()); System.out.println("Previous operation: " + mathData.getLastOp()); System.out.println("# of operations: " + mathData.getNumOps()); }catch(Exception exc) University of Surrey Department of Computing Introductory Grid Computing Tutorial Notes #4 Date: 6/02/2005 { System.out.println("ERROR!"); exc.printStackTrace(); } } } You should modify “deliverNotification” method above when you want to change the message format you received from the grid service. 14. Write the following lines to ClientAdder.java, which should be placed under $TUTORIAL_DIR/mathtutorial/core/factory/client. package mathtutorial.core.factory.client; import mathtutorial.core.factory.service.MathServiceGridLocator; import mathtutorial.core.factory.Math.MathPortType; import java.net.URL; public class ClientAdder { 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 Grid Service instance MathServiceGridLocator mathServiceLocator = new MathServiceGridLocator(); MathPortType math = mathServiceLocator.getMathServicePort(GSH); // Call remote method 'add' math.add(a); System.out.println("Added " + a); }catch(Exception e) { System.out.println("ERROR!"); e.printStackTrace(); } } } 15. Deploy your service (Directory = $TUTORIAL_DIR) ant -Dgwsdl.interface=true -Dpackage=mathtutorial.core.factory -Dinterface.name=Math Dpackage.dir=mathtutorial/core/factory -Dsde.schema.file=MathSDE.xsd When you provide your own gwsdl file, you have to specify the following parameter: -Dgwsdl.interface=true If you want to generate schema files from java interface files, then you should provide the following parameter: -Djava.interface=true However, you should create a Math.java file (the interface of your implementation) and the file should be placed under $TUTORIAL_DIR/mathtutorial/core/factory/impl. factmathtutorial ccfactmathtutori oservicedata al ry oservicedata lient ry lient ccore factory University of Surrey Department of Computing Introductory Grid Computing Tutorial Notes #4 Date: 6/02/2005 lmathtutorial servicedata 16. Then, deploy your service into Globus container (Directory = $HOME/gt3). ant deploy -Dgar.name=$TUTORIAL_DIR/build/lib/mathtutorial.core.factory.Math.gar The reason why we run this command under $HOME/gt3 is that Math.gar file will be unzipped to the appropriate directories under gt3. Please see the contents of the file by opening the Math.gar file (other files as well under /build/lib) with Winzip. 17. Run your globus container and check whether your service is displayed. globus-start-container –p $MYPORT 18. Open another terminal. Then, compile and run your client (Directory = $TUTORIAL_DIR). javac -classpath ./build/classes/:$CLASSPATH mathtutorial/core/factory/client/ClientListener.java 19. Run your client. java -classpath ./build/classes/:$CLASSPATH Dorg.globus.ogsa.schema.root=http://131.227.74.147:28161/ mathtutorial.core.factory.client.ClientListener http://131.227.74.147:28161/ogsa/services/mathtutorial/core/factory/MathService If the command is successful, “Listening…” message will be displayed on your screen. Please do not press any key unless you want to stop listening the service. 20. Open another terminal. Then, compile and run your other client. javac -classpath ./build/classes/:$CLASSPATH mathtutorial/core/factory/client/ClientAdder.java java -classpath ./build/classes/:$CLASSPATH Dorg.globus.ogsa.schema.root=http://131.227.74.147:28161/ mathtutorial.core.factory.client.ClientAdder http://131.227.74.147:28161/ogsa/services/mathtutorial/core/factory/MathService 5 Please follow the messages displayed on your other client window when you execute the above command. EXERCISE: Add a service data element, called “subtractnum”, which will hold the total number of “subtract” operations. When “subtractnum” exceeds a certain value, say, 3, the subscribed client will be notified.