200 likes | 360 Views
Assignment 2 “Simple” Grid Services Assignment. Grid Services Exercise. Preliminaries Web services are stateless, whereas Grid services can be either stateful or stateless, and transient or persistent. Grid services also use a factory service to manufacture instances. Goals.
E N D
Grid Services Exercise Preliminaries Web services are stateless, whereas Grid services can be either stateful or stateless, and transient or persistent. Grid services also use a factory service to manufacture instances.
Goals • Build on the Web Services assignment. • Show how Grid services differ from Web services. • Show how to create a stateful Grid service using Globus 3.2 (GT3.2)
Purpose of Grid Service To store an integer value which can be acted upon by methods to: • Get its value • Increment its value (add one), and • Decrement its value (subtract one). These methods are given. Further methods will be implemented. The service is stateful (the value is retained between accesses).
ant(Another Neat Tool) • A build tool used in this assignment for deploying service. • Uses XML configuration files.
Steps • Preliminary set-up. • Define the Grid Service Using Java • Define the Grid Service Interface using GWSDL • Write the Deployment Descriptor • Build the Math Service • Deploy the Math Service using ANT • Write and Compile the Client • Start the Grid Service • Execute the Client • Add Functionality to the Grid Service
Step 1: Set-up • GT3.2 not set up for a multi-developer environment. • ant uses a common build directory for the deployment of all services • All users added to a common “globus” group • Users need to create unique service names • Users need to revise subdirectory structure of services in user’s home directory We wrote NameChangeScript to do this.
Step 2: Define/Implement Grid Service Using Java // package and import statements not shown public class MathImpl extends GridServiceImpl implements MathPortType{ private int value = 0; public MathImpl() { super(“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; } }
Step 2 (continued) This service is stateful. The value can be modified via add or subtract, and accessed via getValue. Service implemented in Java. Code provided in: yourusernameAssignments/services/ MathService/impl/MathImpl.java which is in the directory /home/yourusername/GridServices/
Step 3: Define Grid Service Interface using GWSDL The service interface is defined in GWSDL and provided in: schema/yourusernameAssignments/ MathService/impl/Math.gwsdl which is in the directory: /home/yourusername/GridServices/
Step 3 (continued) The GWSDL (Grid Web Services Description Language) file specifies the namespace being used: http://www.globus.org/namespaces/ yourusernameAssignments/MathService
Step 4: Writing Deployment Descriptor Code for deployment descriptor for service provided in yourusernameAssignments/services/ MathService/server-deploy.wsdd which is in the directory /home/yourusername/GridServices/ Two key sections of deployment descriptor specify the Math Service and the Math Service Factory.
Step 5: Building the Math Service Use the build script build.sh which specifies path to your service and path to GWSDL file for the service. [yourusername@terra GridServices] $ ./build.sh yourusernameAssignments/services/MathService schema/yourusernameAssignments/MathService/Math.gwsdl A directory named build is created that contains all the stub files, class files, and the GAR file. The GAR file contains the java class files, GWSDL files, compiled stubs, and the deployment descriptor
Step 5 continued: Deploy Grid Service using ant ANT is a build program similar to the make program but the dependencies are specified using xml. Command line from globus directory: [yourusername@terra globus] ant deploy -Dgar.name =/home/yourusername/GridServices/build/lib/yourusernameAssignments_services_MathService.gar
Step 6: Write and Compile Client public class MathClient { 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 myServiceLocator = new MathServiceGridLocator(); MathPortType myprog = myServiceLocator.getMathService(GSH); // Call remote method 'add' myprog.add(a); System.out.println("Added " + a); // Get current value through remote method 'getValue' int value = myprog.getValue(); System.out.println("Current value: " + value); } catch(Exception e) { System.out.println("ERROR!"); e.printStackTrace(); } } }
Step 6 (continued) The code for the client is provided in: yourusernameAssignments/clients/ MathService/Client.java which is in the directory /home/yourusername/GridServices Compile it using javac.
Step 7: Start Grid Service Start globus container on a TCP port not in use. From GridServices directory: globus-start-container -p 8081 This example assumes port 8081 is not in use; use netstat –t –all to see which ports are in use. MathService and MathServiceFactory will be listed as two of the services that are available once the container has started.
Step 8: Execute Client Execute client. From GridServices directory: java –classpath ./build/classes/:$CLASSPATH yourusernameAssignments.clients.MathService.Client http://152.30.5.102:8081/ogsa/services/yourusernameAssignments/MathService 5 You will see the following result: Added 5 Current value: 5
Step 9: Extend Functionality of Service Add a multiply method to your Math Service. Repeat all the steps to test it.
Acknowledgment This assignment and slides are derived from: “Classroom Exercises for Grid Services” by A. Apon, J. Mache, Y. Yara, and K. Landrus, Proc. 5th Int. Conference on Linux Clusters: The HPC Revolution, May 2004.