a2.1 itcs 4010/5010 grid computing, 2005, unc-charlotte, b. wilkinson assignment 2 “simple” grid...

Post on 19-Dec-2015

215 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

A2.1ITCS 4010/5010 Grid Computing, 2005, UNC-Charlotte, B. Wilkinson

Assignment 2

“Simple” Grid Services Assignment

A2.2

GT 4 Stateful Web Services

Preliminaries

• Web services as created in assignment 1 are stateless.

• Stateful web services required for grid computing.

• Obtained in WS-RF by having a web service front-end to a stateful “resource.”

A2.3

Web Service

Resource

Resource properties

Client

Web Service Resource Framework(WS-RF)

Holds information retained between accesses.

A2.4

Assignment Goals

• Build on the Web Services assignment.

• Show how stateful WS-RF web services can be created using Globus 4.0

• See the difference between stateful WS-RF web services and stateless Web services.

A2.5

Purpose of 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).

A2.6

Resource Properties

In the code provided in assignment 2, there are actually two resource properties:

• Value -- an integer acted upon by the operations: add, sub, and getValueRP

and

• “Last operation performed” -- a string holding the name of the last operation done, addition or subtraction, which is not used in assignment 2

A2.7

Math Web Service

Resource

Resource properties“value”

(integer)

“last operationperformed”

(string)

Client

Assignment 2 Resource Properties

A2.8

Steps in Assignment 2

• Preliminary set-up.

• Define the Service Interface using WSDL

• Write the stateful web service code using Java

• Write the Deployment Descriptor

• Build the Math service

• Deploy the Math service

• Write and compile the client

• Start the container and execute the client

• Add functionality to the service

A2.9

WSDL and Service Implementation

• In Assignment 1, we wrote the service implementation first and then provided the WSDL description.

A2.10

Service Implementation

• In Assignment 2, we will start with the interface/WSDL and write the implementation second.

• This is a more appropriate way from a software engineering perspective, i.e. describe what we want to do first and do a specific implementation afterwards.

A2.11

Step 1: Preliminaries

The files that you will need for this assignment are provided in a tar file:

http://cs.wcu.edu/~certauthority/ new_assignment2.tar.gz

which you download.

This tar includes specially written scripts.

A2.12

Step 2: Defining service Interface using WSDL

WSDL file is provided in the tar file in:

assignment2/schema/

examples/MathService_instance/Math.wsdl

This file is discussed in detail in Assignment 2 “Presentation slides” and in lecture slides slides4c.

A2.13

Step 2 Implement Service Using Java

Service is implemented in Java. Code provided in the tar file at:

assignment2/org/globus/examples/services/

MathService/impl/MathImpl.java

A2.14

Service

The code has two major parts:

• Resource properties• Service code (methods)

which are combined into one file for this assignment.

A2.15

Service – Resource Propertiespublic class MathService implements Resource, ResourceProperties { private ResourcePropertySet propSet; /* Resource Property set */ private int value; private String lastOp; public MathService() throws RemoteException { /* RP Constructor */

this.propSet = new SimpleResourcePropertySet( MathQNames.RESOURCE_PROPERTIES); /* Create RP set */ try { /* Initialize the RP's */ ResourceProperty valueRP = new ReflectionResourceProperty( MathQNames.RP_VALUE, "Value", this); this.propSet.add(valueRP); setValue(0); ResourceProperty lastOpRP = new ReflectionResourceProperty( MathQNames.RP_LASTOP, "LastOp", this); this.propSet.add(lastOpRP); setLastOp("NONE"); } catch (Exception e) { throw new RuntimeException(e.getMessage()); }}

Resource Property code

Resource properties

A2.16

/* Get/Setters for the RPs */

public int getValue() {

return value;

}

public void setValue(int value) {

this.value = value;

}

public String getLastOp() {

return lastOp;

}

public void setLastOp(String lastOp) {

this.lastOp = lastOp;

}

Service – Resource Properties methods

A2.17

Service code - methods /* Remotely-accessible operations */  public AddResponse add(int a) throws RemoteException { value += a; lastOp = "ADDITION"; return new AddResponse(); }  public SubtractResponse subtract(int a) throws

RemoteException { value -= a; lastOp = "SUBTRACTION"; return new SubtractResponse(); }  public int getValueRP(GetValueRP params) throws

RemoteException { return value; } /* Required by interface ResourceProperties */ public ResourcePropertySet getResourcePropertySet() { return this.propSet; }

A2.18

Step 4: Writing Deployment Descriptor

Code for deployment descriptor for service is provided in:

org/globus/services/MathService/server-deploy.wsdd

A2.19

Step 5: BuildingInitial building in assignment 2 is done using (in essence) the GT4 command (script):

globus-build-service

This command is embedded in a script:

build.sh

which also includes a script called:

nameChangeScript

to rename student files to make them each unique.

A2.20

Step 6: Deploying Service

Deployment is done using the GT4 command:

globus-deploy-gar

as user “globus”, using gar file created by globus-build-service.

A2.21

Step 7: Write and Compile Clientpublic class Client {public static void main(String[] args) {MathServiceAddressingLocator locator = new MathServiceAddressingLocator();try {String serviceURI = args[0];EndpointReferenceType endpoint = new EndpointReferenceType();endpoint.setAddress(new Address(serviceURI)); //service endpt ref.MathPortType math; math = locator.getMathPortTypePort(endpoint); // Get PortType

math.add(10); // Perform an addition math.add(5); // Perform another addition System.out.println("Current value: " + math.getValueRP(new GetValueRP())); // Access value

math.subtract(5); // Perform a subtraction System.out.println("Current value: " + math.getValueRP(new GetValueRP())); // Access value} catch (Exception e) {e.printStackTrace();}}} 

A2.22

Step 7 (continued)

The code for the client is provided in:

assignment2/org/globus/examples/clients/MathService_instance/Client.java

Compile it using javac.

A2.23

Steps 8-9: Start Container

As user globus, start Globus container on a TCP port not in use:

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 will be listed as two of the services that are available once the container has started.

A2.24

Step 10: Execute Client

Execute client:

java –classpath ./build/classes/org/globus/examples/services/core/yourusername_first/impl/:$CLASSPATH org/globus/examples/clients/MathService_instance/Clienthttp://localhost:yourportnumber/wsrf/services/examples/

core/yourusername_first/MathService

You will see the following result (hopefully): Current value: 15 Current value: 10

 

A2.25

Step 11 Undeploy sevice

Deploy service in preparation to modifying it.

As user Globus, issue command:

globus-undeploy-gar

with (re)named gar file.

A2.26

Step 12: Extend Functionality of Service

Add a multiply method to your Math Service.

Repeat all the steps to test it.

A2.27

Acknowledgment

This assignment is derived from Borja Sotomayor’s Globus Toolkit 4 Programmer’s Tutorial:

http://gdp.globus.org/gt4-tutorial/

top related