Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Grid Computing LAB

Download as pdf or txt
Download as pdf or txt
You are on page 1of 63

GRID

COMPUTING
LAB
Ex:No:1 DEVELOP A NEW WEB SERVICE FOR CALCULATOR

Date:
Aim:
To develop a new Web Services for Calculator.

Procedure:
MathService.java:
package pks.math;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;
/**
*
* @author nsp
*/
@WebService(serviceName = "MathService")
public class MathService {
/**
* This is a sample web service operation
*/
@WebMethod(operationName = "hello")
public String hello(@WebParam(name = "name") String txt) {
return "Hello " + txt + " !"; }
@WebMethod(operationName = "addSer")
public String addSer(@WebParam(name = "value1") int v1, @WebParam(name =
"value2") int v2) {
return "Answer: " + (v1+v2) + " !!!"; }
@WebMethod(operationName = "subSer")
public String subSer(@WebParam(name = "value1") int v1, @WebParam(name =
"value2") int v2) {
return "Answer: " + (v1-v2) + " !!!"; }
@WebMethod(operationName = "mulSer")
public String mulSer(@WebParam(name = "value1") int v1, @WebParam(name =
"value2") int v2) {
return "Answer: " + (v1*v2) + " !!!"; }
@WebMethod(operationName = "divSer")
public String divSer(@WebParam(name = "value1") int v1, @WebParam(name =
"value2") int v2) {
float res=0;
try
{ res= ((float)v1)/((float)v2);
return "Answer: " + res + " !!!"; }
catch (ArithmeticException e) {
System.out.println ("Can't be divided by Zero"+e);
return "Answer: "+e.getMessage().toString()+"!!!"; } }

http://localhost:8080/WebApplication1/MathService?Tester
<!-- Published by JAX-WS RI (http://jax-ws.java.net). RI's version is Metro/2.3.1-b419
(branches/2.3.1.x-7937; 2014-08-04T08:11:03+0000) JAXWS-RI/2.2.10-
b140803.1500 JAXWS-API/2.2.11 JAXB-RI/2.2.10-b140802.1033 JAXB-
API/2.2.12-b140109.1041 svn-revision#unknown. -->
<!-- Generated by JAX-WS RI (http://jax-ws.java.net). RI's version is Metro/2.3.1-b419
(branches/2.3.1.x-7937; 2014-08-04T08:11:03+0000) JAXWS-RI/2.2.10-
b140803.1500 JAXWS-API/2.2.11 JAXB-RI/2.2.10-b140802.1033 JAXB-
API/2.2.12-b140109.1041 svn-revision#unknown. -->
<definitions targetNamespace="http://math.pks/" name="MathService">
<types><xsd:schema>
<xsd:import namespace="http://math.pks/"
schemaLocation="http://localhost:8080/WebApplication1/MathService?xsd=1"/>
</xsd:schema></types>
<message name="mulSer"><part name="parameters"
element="tns:mulSer"/></message>
<message name="mulSerResponse">
<part name="parameters" element="tns:mulSerResponse"/></message>
<message name="divSer"><part name="parameters"
element="tns:divSer"/></message>
<message name="divSerResponse">
<part name="parameters" element="tns:divSerResponse"/></message>
<message name="subSer"><part name="parameters"
element="tns:subSer"/></message>
<message name="subSerResponse">
<part name="parameters" element="tns:subSerResponse"/></message>
<message name="addSer"><part name="parameters"
element="tns:addSer"/></message>
<message name="addSerResponse">
<part name="parameters" element="tns:addSerResponse"/></message>
<portType name="MathService">
<operation name="mulSer">
<input wsam:Action="http://math.pks/MathService/mulSerRequest"
message="tns:mulSer"/>
<output wsam:Action="http://math.pks/MathService/mulSerResponse"
message="tns:mulSerResponse"/></operation>
<operation name="divSer">
<input wsam:Action="http://math.pks/MathService/divSerRequest"
message="tns:divSer"/>
<output wsam:Action="http://math.pks/MathService/divSerResponse"
message="tns:divSerResponse"/></operation>
<operation name="subSer">
<input wsam:Action="http://math.pks/MathService/subSerRequest"
message="tns:subSer"/>
<output wsam:Action="http://math.pks/MathService/subSerResponse"
message="tns:subSerResponse"/></operation>
<operation name="addSer">
<input wsam:Action="http://math.pks/MathService/addSerRequest"
message="tns:addSer"/>
<output wsam:Action="http://math.pks/MathService/addSerResponse"
message="tns:addSerResponse"/></operation>
</portType>
<binding name="MathServicePortBinding" type="tns:MathService">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="mulSer"><soap:operation soapAction=""/>
<input><soap:body use="literal"/></input>
<output><soap:body use="literal"/></output></operation>
<operation name="divSer"><soap:operation soapAction=""/>
<input><soap:body use="literal"/></input>
<output><soap:body use="literal"/></output></operation>
<operation name="subSer"><soap:operation soapAction=""/>
<input><soap:body use="literal"/></input>
<output><soap:body use="literal"/></output></operation>
<operation name="addSer"><soap:operation soapAction=""/>
<input><soap:body use="literal"/></input>
<output><soap:body use="literal"/></output></operation></binding>
<service name="MathService">
<port name="MathServicePort" binding="tns:MathServicePortBinding">
<soap:address location="http://localhost:8080/WebApplication1/MathService"/>
</port></service></definitions>
OUTPUT:

Result:
Thus a Web Services for Calculator has been created and executed successfully.
EX:NO:2 DEVELOP NEW OGSA-COMPLIANT WEB SERVICE

Date:
Aim:

To Develop new OGSA-compliant Web Service.

Procedure:

∑ Choose New Project from the main menu.


∑ Select POM Project from the Maven category.

∑ Type MavenOSGiCDIProject as the Project name. Click Finish.


When you click Finish, the IDE creates the POM project and opens the
project in the Projects window.

∑ Expand the Project Files node in the Projects window and double-click pom.xml to
open the file in the editor.

The basic POM for the project should be similar to the following.

<?xml version="1.0" encoding="UTF-8"?>


<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<artifactId>MavenOSGiCDIProject</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<properties><project.build.sourceEncoding>UTF-
8</project.build.sourceEncoding>
</properties></project>

∑ Modify the parent pom.xml to add the following elements. Save your changes.

<?xml version="1.0" encoding="UTF-8"?>


<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<artifactId>MavenOSGiCDIProject</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencyManagement><dependencies><dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<version>4.2.0</version>
<scope>provided</scope>
</dependency></dependencies></dependencyManagement></project>

Creating the OSGi Bundle Projects

The Maven category in the New Projects wizard includes an OSGi Bundle
archetype for creating OSGi bundle projects. When you create an OSGi bundle project,
the generated POM declares the org.osgi.core JAR as a dependency and specifies the
maven-bundle-plugin for building the project.

Creating the MavenHelloServiceApi Interface Bundle

In this exercise you will use the New Project wizard to create an OSGi bundle project
that will provide a simple interface that will be implemented by other bundles. After you
create the bundle and interface, you will modify the POM to update the dependency on
the org.osgi.core artifact that you specified in the parent POM project.

∑ Choose File > New Project to open the New Project wizard.
∑ Choose OSGi Bundle from Maven category. Click Next.
∑ Type MavenHelloServiceApi for the Project Name.
∑ Click Browse and select the MavenOSGiCDIProject POM project as the
Location. Click Finish.

When you click Finish, the IDE creates the bundle project and opens the project
in the Projects window. If you open pom.xml for the MavenHelloServiceApi project in the
editor you can see that the packaging element specifies bundle and that the maven-
bundle-plugin will be used when building the bundle.

<project><modelVersion>4.0.0</modelVersion>
<parent><artifactId>MavenOSGiCDIProject</artifactId>
<groupId>com.mycompany</groupId>
<version>1.0-SNAPSHOT</version></parent>
<groupId>com.mycompany</groupId>
<artifactId>MavenHelloServiceApi</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>bundle</packaging>
<name>MavenHelloServiceApi OSGi Bundle</name>
<properties><project.build.sourceEncoding>UTF-
8</project.build.sourceEncoding>
</properties>
<dependencies><dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<version>4.3.0</version>
<scope>provided</scope>
</dependency></dependencies>
<build><plugins><plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.7</version>
<extensions>true</extensions>
<configuration><instructions>
<Bundle-Activator>com.mycompany.mavenhelloserviceimpl.Activator</Bundle-
Activator>
<Export-Package />
</instructions></configuration></plugin>
...
</plugins></build>
...
<project>
You can also see that when you create an OSGi bundle project using the Maven
OSGi Bundle archetype, the IDE added the org.osgi.core artifact as a dependency by
default.

∑ Right-click the MavenHelloServiceApi project node in the Projects window and


choose Properties.
∑ Select the Sources category in the Project Properties dialog box.
∑ Set the Source/Binary Format to 1.6 and confirm that the Encoding is UTF-8.
Click OK.
∑ Right-click Source Packages node in the Projects window and choose New >
Java Interface.
∑ Type Hello for the Class Name.
∑ Select com.mycompany.mavenhelloserviceapi as the Package. Click Finish.
∑ Add the following sayHello method to the interface (in bold) and save your
changes.
∑ public interface Hello {
∑ String sayHello(String name);
}

∑ Right-click the project node in the Projects window and choose Build.

After you build the project, if you open the Files window and expand the project
node you can see that MavenHelloServiceApi-1.0-SNAPSHOT.jar is created in the
target folder.
The maven-bundle-plugin handles the generation of the MANIFEST.MF file when
you build the project. If you open the MANIFEST.MF file in the compiled JAR you will
see that the plugin generated a manifest header that declares the export packages. For
OSGi, all bundles that you want to be exposed and available to other bundles must be
listed in the Export-Package element in MANIFEST.MF.

∑ Confirm that the MANIFEST.MF contains the Export-Package element (the


element shown in bold in the example below).
∑ Manifest-Version: 1.0
∑ Bnd-LastModified: 1395049732676
∑ Build-Jdk: 1.7.0_45
∑ Built-By: nb
∑ Bundle-Activator: com.mycompany.mavenhelloserviceapi.Activator
∑ Bundle-ManifestVersion: 2
∑ Bundle-Name: MavenHelloServiceApi OSGi Bundle
∑ Bundle-SymbolicName: com.mycompany.MavenHelloServiceApi
∑ Bundle-Version: 1.0.0.SNAPSHOT
∑ Created-By: Apache Maven Bundle Plugin
∑ Export-Package:
com.mycompany.mavenhelloserviceapi;uses:="org.osgi.frame
work";version="1.0.0.SNAPSHOT"
∑ Import-Package: org.osgi.framework;version="[1.6,2)"
Tool: Bnd-1.50.0

The OSGi container will read the Export-Package manifest header to determine
the classes in the bundle that can be accessed from outside the bundle. In this
example, the classes in the com.mycompany.mavenhelloserviceapi package are
exposed.

Note. If the MANIFEST.MF does not contain the Export-Package element, you
will need to enable the default plugin behavior for the plugin in the Project Properties
window and rebuild the project. In the Project Properties window, select the Export
Packages category and select the Default maven-bundle-plugin behavior option. You
can use the Export Packages panel of the Project Properties window to explicitly specify
the packages that should be exposed or specify the packages directly in pom.xml.

Creating the MavenHelloServiceImpl Implementation Bundle

In this exercise you will create the MavenHelloServiceImpl in the POM project.

∑ Choose File > New Project to open the New Project wizard.
∑ Choose OSGi Bundle from the Maven category. Click Next.
∑ Type MavenHelloServiceImpl for the Project Name.
∑ Click Browse and select the MavenOSGiCDIProject POM project as the
Location (if not selected). Click Finish.
∑ Right-click the project node in the Projects window and choose Properties.
∑ Select the Sources category in the Project Properties dialog box.
∑ Set the Source/Binary Format to 1.6 and confirm that the Encoding is UTF-8.
Click OK.
∑ Right-click Source Packages node in the Projects window and choose New >
Java Class.
∑ Type HelloImpl for the Class Name.
∑ Select com.mycompany.mavenhelloserviceimpl as the Package. Click Finish.
∑ Type the following (in bold) and save your changes.
∑ public class HelloImpl implements Hello {
public String sayHello(String name) { return "Hello " + name; }}

When you implement Hello, the IDE will display an error that you need to resolve
by adding the MavenHelloServiceApi project as a dependency.

∑ Right-click the Dependencies node of MavenHelloServiceImpl in the Projects


window and choose Add Dependency.
∑ Click the Open Projects tab in the Add Library dialog.
∑ Select MavenHelloServiceApi OSGi Bundle. Click Add.

∑ Right-click in the HelloImpl.java class that is open in the editor and choose Fix
Imports (Alt-Shift-I; ⌘-Shift-I on Mac) to add an import statement for
com.mycompany.mavenhelloserviceapi.Hello. Save your changes.
∑ Expand the com.mycompany.mavenhelloserviceimpl package and double-click
Activator.java to open the file in the editor.
The IDE automatically created the Activator.java bundle activator class in your
project. A bundle activator is used to manage the lifecycle of a bundle. The bundle
activator class is declared in the MANIFEST.MF of the bundle and instantiated when the
bundle is started by the container.

An OSGi bundle does not require a bundle activator class, but you can use the
start() method in the activator class, for example, to initialize services or other resources
that are required by the bundle. In this exercise you will add some lines of code to the
class that will print messages to the Output window. This will make it easier for you to
identify when the bundle starts and stops.
∑ Modify the start() and stop() methods in the bundle activator class to add the
following lines (in bold).

public class Activator implements BundleActivator {

public void start(BundleContext context) throws Exception {


System.out.println("HelloActivator::start");
context.registerService(Hello.class.getName(), new HelloImpl(), null);
System.out.println("HelloActivator::registration of Hello service
successful"); }

public void stop(BundleContext context) throws Exception {


context.ungetService(context.getServiceReference(Hello.class.getName()));
System.out.println("HelloActivator stopped"); } }

You can see that the bundle activator class imports


org.osgi.framework.BundleActivator and org.osgi.framework.BundleContext. By default
the generated class contains two methods: start() and stop(). The OSGi framework
invokes the start() and stop() methods to start and to stop the functionality provided by
the bundle. When the bundle is started, the service component provided by the bundle
is registered in the OSGi service registry. After a bundle is registered, other bundles can
use the registry to look up and then use the active services via the bundle context.

If you look at the POM for the project you can see the <Bundle-Activator> element
that specifies the bundle activator under the configuration element for the maven-
bundle-plugin.

<plugin><groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.7</version><extensions>true</extensions>
<configuration><instructions><Bundle-
Activator>com.mycompany.mavenhelloserviceimpl.Activator</Bundle-
Activator></instructions></configuration></plugin>

When you build the bundle, the plugin will generate a Manifest Header in the
bundle's manifest file in the JAR and specify the Bundle Activator class. The OSGi
runtime looks for the Bundle-Activator header in the manifest file when a bundle is
deployed.

∑ Fix the import statements in Activator.java to import


com.mycompany.mavenhelloserviceapi.Hello. Save your changes.
∑ Expand the Dependencies node and confirm that the org.osgi.core artifact is
listed as a dependency.

Note. Remove any older versions of the artifact that are listed under the Dependencies
node by right-clicking the artifact and choosing Remove Dependency. The only
dependencies should be the MavenHelloServiceApi project and the org.osgi.core
artifact.
Building and Deploying the OSGi Bundles

In this exercise you will build the OSGi bundles and deploy the bundles to GlassFish.

∑ Right-click the MavenOSGiCDIProject node in the Projects window and choose


Clean and Build.

When you build the project the IDE will create the JAR files in the target folder of
each of the projects and also install the snapshot JAR in the local repository. In the Files
window, you can expand the target folder for each of the two bundle projects to see the
two JAR archives (MavenHelloServiceApi-1.0-SNAPSHOT.jar and
MavenHelloServiceImpl-1.0-SNAPSHOT.jar).

∑ Start the GlassFish server if not already started.


∑ Copy the MavenHelloServiceApi-1.0-SNAPSHOT.jar to the
glassfish/domains/domain1/autodeploy/bundles/ directory of your GlassFish
installation.

You should see output similar to the following in the GlassFish Server log in the
Output window.

INFO: Started bundle: file:/glassfish-


4.0/glassfish/domains/domain1/autodeploy/bundles/MavenHelloServiceApi-1.0-
SNAPSHOT.jar

Right-click the GlassFish server node in the Services window and choose View
Domain Server Log if the server log is not visible in the Output window.

∑ Repeat the steps to copy the MavenHelloServiceImpl-1.0-SNAPSHOT.jar to the


autodeploy/bundles directory.
Output:

INFO: HelloActivator::start
INFO: HelloActivator::registration of Hello service successful
INFO: Started bundle: file:/glassfish-
4.0/glassfish/domains/domain1/autodeploy/bundles/MavenHelloServiceImpl-1.0-
SNAPSHOT.jar
INFO: Started bundle: file:/glassfish-
4.0/glassfish/domains/domain1/autodeploy/bundles/MavenHelloServiceImpl-1.0-
SNAPSHOT.jar

Result:
Thus the new OGSA-compliant Web Service has been developed and
executed successfully.
EX:NO:3 USING APACHE AXIS DEVELOP A GRID SERVICE

Date:
Aim:

To use Apache Axis develop a Grid Service.

Procedure:

Setup the Development Environment


∑ First you need to set up the development environment. Following things are
needed if you want to create Web Services using Axis2 and Eclipse IDE.
∑ Then you have to set the environment variables for Java and Tomcat. There
following variables should be added.

JAVA_HOME :- Set the value to jdk directory (e.g. C:\Program Files\Java\jdk1.6.0_21)


TOMCAT_HOME :- Set the value to top level directory of your Tomcat install (e.g.
D:\programs\apache-tomcat-6.0.29)
PATH :- Set the value to bin directory of your jdk (e.g. C:\Program
Files\Java\jdk1.6.0_21\bin)
∑ Now you have to add runtime environment to eclipse. There go to Windows –->
Preferences and Select the Server --> Runtime Environments.
There select Apache Tomcat v6.0 and in the next window browse your Apache
installation directory and click finish.
∑ Then click on the Web Service –-> Axis2 Preferences and browse the top level
directory of Apache Axis2 Binary Distribution.

Creating the Web Service Using Bottom-Up Approach


∑ First create a new Dynamic Web Project (File --> New –-> Other…) and choose
Web --> Dynamic Web Project.
∑ Set Apache Tomcat as the Target Runtime and click Modify to install Axis2 Web
Services project facet.
∑ Select Axis2 Web Services
∑ Click OK and then Next. There you can choose folders and click Finish when you
are done.

Create Web Service Class


Now you can create a Java class that you would want to expose as a Web Service.
I’m going to create new class called FirstWebService and create public method called
addTwoNumbers which takes two integers as input and return the addition of them.

∑ Right Click on MyFirstWebService in Project Explorer and select New –-> Class
and give suitable package name and class name. I have given com.sencide as
package name and FirstWebService as class name.
package com.sencide;
public class FirstWebService {
public int addTwoNumbers(int firstNumber, int secondNumber){
return firstNumber + secondNumber; }}
∑ Then, select File --> New –-> Other and choose Web Service.
∑ Select the FirstWebService class as service implementation and to make sure
that the Configuration is setup correctly click on Server runtime.
∑ There set the Web Service runtime as Axis2 (Default one is Axis) and click Ok.
∑ Click Next and make sure Generate a default service.xml file is selected.
∑ Click Next and Start the Server and after server is started you can Finish if you
do not want to publish the Web service to a test UDDI repository.
You can go to http://localhost:8888/MyFirstWebService/services/listServices to see
your running service which is deployed by Axis2. You can see the WSDL by clicking the
link FirstWebService.
We have to use Eclipse every time when we want to run the service if we do not
create .aar (Axis Archive) file and deploy it to the server. So let’s see how we can create
it.

Create .aar (Axis Archive) file and Deploying Service


∑ In your eclipse workspace and go to MyFirstWebService folder and there you can
find our web service inside services folder. Go to that directory using command
prompt and give following command. It will create the FirstWebService.aar file
there.

jar cvf FirstWebService.aar com META-INF


∑ Then copy the axis2.war file you can find inside the Apache Axis2 WAR
Distribution (You downloaded this at the first step) to the webapps directory of
Apache Tomcat. Now stop the Apache Tomcat server which is running on
Eclipse IDE.

∑ Using command prompt start the Apache Tomcat (Go to bin directory and run the
file startup.bat). Now there will be new directory called axis2 inside the webapps
directory. Now if you go to the http://localhost:8080/axis2/ you can see the home
page of Axis2 Web Application.
∑ Then click the link Administration and login using username : admin and
password : axis2. There you can see upload service link on top left and there you
can upload the created FirstWebService.aar file. This is equal to manually
copping the FirstWebService.aar to webapps\axis2\WEB-INF\services directory.
∑ Now when you list the services by going to
http://localhost:8080/axis2/services/listServices you should be able to see our
newly added service.
OUTPUT

Creating a Web service client


∑ Select File --> New --> Other… and choose Web Service Client
∑ Set he newly created Axis2 Web service
(http://localhost:8080/axis2/services/FirstWebService?wsdl) as the Service
definition. Then configure the Server runtime as previously and click finish.

∑ This will generate two new classes called FirstWebServiceStub.java and


FirstWebServiceCallbackHandler.java. Now we can create test class for client
and use our web service. Create new class called TestClient.java and paste
following code.

package com.sencide;
import java.rmi.RemoteException;
import com.sencide.FirstWebServiceStub.AddTwoNumbers;
import com.sencide.FirstWebServiceStub.AddTwoNumbersResponse;
public class TestClient {
public static void main(String[] args) throws RemoteException {
FirstWebServiceStub stub = new FirstWebServiceStub();
AddTwoNumbers atn = new AddTwoNumbers();
atn.setFirstNumber(5);
atn.setSecondNumber(7);
AddTwoNumbersResponse res = stub.addTwoNumbers(atn);
System.out.println(res.get_return()); }
}

Result:

Thus a Grid service hasa been developed using Apache Axis and
executed successfully.
Ex:NO:4 DEVELOP APPLICATIONS USING JAVA

Date:
Aim:

To develop applications using Java in grid computing.

Procedure:

This is the list of activities that will be performed in this section:

∑ Start default container

∑ Start the service browser

∑ Create CounterServiceFactoy using the Create counter service instance with the
service browser

∑ Use the counter service using the service browser

∑ Create a new counter service instance with the command line

∑ Use the second counter service instance with the command line

∑ Verify existence of both instances using the service browser

∑ Destroy both instances with the command line

Starting the default container

You may open a new window as globus (the user who installed the toolkit) and
run globus-start-container from the globus-install directory ($GLOBUS_LOCATION).
On x1, as the globus user, issue the following commands to start the container:

$ cd $GLOBUS_LOCATION

$ globus-start-container | tee /tmp/servelog &


Starting the service browser

Because of the quantity of data included in the service browser, make sure the
resolution is set to display the necessary information in the window. In our lab a display
resolution of 1024 by 768 was used. Also, you may need to run xhost to allow the use
of the GUI, as described below.
As root, run xhost:

# xhost +

In a separate window, log in as the itso user and start the service browser. As the
itso user, issue the following commands for this purpose:
$ cd $GLOBUS_LOCATION

$ globus-service-browser | tee /tmp/clientlog &

At the end of this step, a Java-based GUI would have appeared on screen. That
is the service browser tool.

Using the service browser to run the basic counter service

The idea of the service browser, presented in Figure 4-5, is similar to a Web
browser, where you can specify the URL for the required Web location and allow
navigating on it as well. For a Grid service, the URL is replaced by a URI (Uniform
Resource Identifier).
Step 1: Invoking the counter factory service

You may see the Service Group Entry Inspection panel in the bottom portion of
the service browser. All services that are deployed in the container are listed there. You
need to locate the CounterFactoryService in the Table tab
Now, double-click on the highlighted CounterFactoryService to invoke it. The
service browser can take a long time to come up, so please be patient. The window will
show CounterFactoryService in the URI field near the top of the screen

Step 2: Creating a service instance

Near the bottom of the screen, you find a text box for entering an instance name
and a Create Instance button. You may enter an instance name (for example, C1) and
click this button to create a service instance.

After you press the Create Instance button, a new window will show the client
interface for the newly C1 created counter factory service instance (c1),
This is the GSH of the counter factory service instance. Note that the instance
name c1 has been added at the end of GSH.

Step 3: Using the counter service

Now we will perform operations on the counter factory service client. Near the
bottom portion of the screen, under the Counter Example panel, you will find a text box
for entering values and two buttons:

1. Add

2. Subtract

The buttons represents the available operations you can perform on the Counter
Value. Note that the initial the value is 0. Let us increase the value of the counter by
entering 10 in the text box provided for the value and pressing the Add button. Note that
the value is 10 now. Now we can subtract 5 from the counter by entering 5 in the text
box and clicking on the Subtract button.

You may observe that the final value at the end of the operation is 5. In the next
section, let us see how you can perform these steps using command line clients.

Using the command line to run the basic counter service

GT is bundled with the ogsa-samples.jar file, which also contains Java programs
that are basically command line clients. Java classes are available for creating and
destroying counter service instances. Let us now see how to create a second counter
service instance and perform the operations using the command line.

Step 1: Creating a new service instance

In order to create a new instance, you need to use a Java program named
CreateService, and pass the GSH of the factory service and the instance name as
arguments. On x1, as the itso user, issue the following commands to create the service
instance called c2:

$ cd $GLOBUS_LOCATION
$ . setenv.sh
$ java org.globus.ogsa.client.CreateService \
http://localhost:8080/ogsa/services/samples/counter/basic/CounterFactoryService c2
Creating the service instance called c2 output
[itso@x1 globus]$ java org.globus.ogsa.client.CreateService
http://localhost:8080/ogsa/services/samples/counter/basic/CounterFactoryService c2
Termination Time: infinity
Created service with reference:
<definitions name="Counter"
targetNamespace="http://ogsa.globus.org/samples/counter/service"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:counterbinding="http://ogsa.globus.org/samples/counter/bindings"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"><import
location="http://192.168.0.241:8080/schema/samples/counter/counter_bindings.wsdl"
namespace="http://ogsa.globus.org/samples/counter/bindings"/><service
name="CounterService"
xmlns:gsdl="http://ogsa.globus.org/"><gsdl:instanceOf
handle="http://192.168.0.241:8080/ogsa/services/samples/counter/basic/CounterFactor
yService/c2" xmlns=""/><gsdl:instanceOf
handle="http://192.168.0.241:8080/ogsa/services/instance"
xmlns=""/><port binding="counterbinding:CounterSOAPBinding"
name="CounterPort"><soap:address
location="http://192.168.0.241:8080/ogsa/services/samples/counter/basic/CounterFacto
ryService/c2"/></port></service></definitions>
[itso@x1 globus]$

Step 2: Using the service instance

Now we will perform operations on the counter service instance, as presented in


“Step 3:
Using the counter service” on page 57, but now in command line mode. The
permitted operations are still the same:
1. Add
2. Subtract

On x1, as the itso user, issue the following commands to add 5, subtract 2, and get the
results:

$ java org.globus.ogsa.impl.samples.counter.client.Add 5 \
http://localhost:8080/ogsa/services/samples/counter/basic/CounterFactoryService/c2
$ java org.globus.ogsa.impl.samples.counter.client.Subtract 2 \
http://localhost:8080/ogsa/services/samples/counter/basic/CounterFactoryService/c2
$ java org.globus.ogsa.impl.samples.counter.client.GetValue \
http://localhost:8080/ogsa/services/samples/counter/basic/CounterFactoryService/c2
You should get an output.
[itso@x1 globus]$ java org.globus.ogsa.impl.samples.counter.client.Add 5
http://localhost:8080/ogsa/services/samples/counter/basic/CounterFactoryService/c2
Counter Value:5
[itso@x1 globus]$ java org.globus.ogsa.impl.samples.counter.client.Subtract 2
http://localhost:8080/ogsa/services/samples/counter/basic/CounterFactoryService/c2
Counter Value:3
[itso@x1 globus]$ java org.globus.ogsa.impl.samples.counter.client.GetValue
http://localhost:8080/ogsa/services/samples/counter/basic/CounterFactoryService/c2
Counter Value:3

Result:
Thus an application has been developed using Java and the output was verified
successfully.
EX:NO: 5 DEVELOP SECURED APPLICATIONS USING BASIC SECURITY
Date: MECHANISMS AVAILABLE IN GLOBUS TOOLKIT

Aim:

To develop secured applications using basic security mechanisms available in Globus


Toolkit

Procedure:

nsp@nspublin:~$ sudo grid-ca-create -noint

Certificate Au t h o r i t y Setup

This script will setup a Certificate Authority for signing Globus users certificates. It will
also generate a simple CA package that can be distributed to the users of the CA. The
CA information about the certificates it distributes will be kept in:
/var/lib/globus/simple_ca
The unique subject name for this CA is:
cn=Globus Simple CA, ou=simpleCA-nspublin, ou=GlobusTest, o=Grid
Installing new CA files to /etc/grid-security/certificates... done
Creating RPM source tarball... done
globus_simple_ca_1b5e8514.tar.gz
EX:NO .6 DEVELOP A GRID PORTAL, WHERE USER CAN SUBMIT A JOB AND

Date: GET THE RESULT. IMPLEMENT IT WITH AND WITHOUT

GRAM CONCEPT

Aim:

To develop a Grid portal, where user can submit a job and get the result with and
without GRAM concept.

Procedure:
The first step to being able to use GRAM5 after installation is to acquire a
temporary Grid credential to use to authenticate with the GRAM5 service and any file
services your job requires. Normally this is done via either grid-proxy-init or via the
MyProxy service.
Proxy credentials with grid-proxy-init
To generate a proxy credential using the grid-proxy-init program, execute the
command with no arguments.

proxy to use to authenticate with grid services such as GRAM5:

% bin/grid-proxy-init
Your identity: /O=Grid/OU=Example/CN=Joe User
Enter GRID pass phrase for this identity:
Creating proxy ................................. Done
Your proxy is valid until: Tue Oct 26 01:33:42 2010

Delegated Credential Usage


The delegated proxy can be used by the GRAM5 service and the job in a few different
ways:

∑ The GRAM5 service uses the credential to send job state notification messages
to clients which have registered to receive them.
∑ The GRAM5 service uses the credential to contact GASS and GridFTP file
servers to stage files to and from the execution resource
∑ The job executed by the GRAM5 service can use the delegated credential for
application-specific purposes.

Submitting jobs
Resource Names
In GRAM5, a Gatekeeper Service Contact contains the host, port, service name,
and service identity required to contact a particular GRAM service. For convenience,
default values are used when parts of the contact are omitted. An example of a full
gatekeeper service contact is
grid.example.org:2119/jobmanager:/C=US/O=Example/OU=Grid/CN=host/grid.example
.org.

The various forms of the resource name using default values follow:
∑ HOST
∑ HOST:PORT
∑ HOST:PORT/SERVICE
∑ HOST/SERVICE
∑ HOST:/SERVICE
∑ HOST:PORT:SUBJECT
∑ HOST/SERVICE:SUBJECT
∑ HOST:/SERVICE:SUBJECT
∑ HOST:PORT/SERVICE:SUBJECT

The following strings all name the service


grid.example.org:2119/jobmanager:/C=US/O=Example/OU=Grid/CN=host/grid.example
.org using the formats with the various defaults described above.
∑ grid.example.org
∑ grid.example.org:2119
∑ grid.example.org:2119/jobmanager
∑ grid.example.org/jobmanager
∑ grid.example.org:/jobmanager
∑ grid.example.org:2119:/C=US/O=Example/OU=Grid/CN=host/grid.example.org
∑ grid.example.org/jobmanager:/C=US/O=Example/OU=Grid/CN=host/grid.exampl
e.org
∑ grid.example.org:/jobmanager:/C=US/O=Example/OU=Grid/CN=host/grid.exampl
e.org
∑ grid.example.org:2119/jobmanager:/C=US/O=Example/OU=Grid/CN=host/grid.ex
ample.org

Running Jobs with globus-job-run


The globus-job-run provides a simple blocking command-line interface to the
GRAM service. The globus-job-run program submits a job to a GRAM5 resource and
waits for the job to terminate. After the job terminates, the output and error streams of
the job are sent to the output and error streams of globus-job-run as if the job were run
interactively. Note that input to the job must be located in a file prior to running the job;
true interactive I/O is not supported by GRAM5.
The globus-job-run program has command-line options to control most aspects
of jobs run by GRAM5. However, certain behaviors must be specified by definition of an
RSL string containing various job attributes. A more detailed description about the RSL
language is included on the section on running jobs with globusrun below.
The following examples show some of the common command-line options to globus-
job-run.

Minimal job using globus-job-run

The following command line submits a single instance of the /bin/hostname executable
to the resource named by grid.example.org:2119/jobmanager-pbs.

% globus-job-run grid.example.org:2119/jobmanager-pbs /bin/hostname


node1.grid.example.org

Multiprocess job using globus-job-run


The following command line submits ten instances of an executable a.out, staging it
from the client host to the service node using GASS. The a.out program prints the name
of the host it is executing on.

% globus-job-run grid.example.org:2119/jobmanager-pbs -np 10 -s a.out


node1.grid.example.org
node3.grid.example.org
node2.grid.example.org
node5.grid.example.org
node4.grid.example.org
node8.grid.example.org
node6.grid.example.org
node9.grid.example.org
node7.grid.example.org
node10.grid.example.org

Canceling an interactive job

This example shows how using the Control+C (or other system-specific mechanism for
sending the SIGINT signal) can be used to cancel a GRAM job.

% globus-job-run grid.example.org:2119/jobmanager-pbs /bin/sleep 90


Control-C
GRAM Job failed because the user cancelled the job (error code 8)

Setting job environment variables with globus-job-run

The following command line submits one instances of the executable /usr/bin/env,
setting some environment variables in the job environment beyond those set by
GRAM5.

% globus-job-run grid.example.org:2119/jobmanager-pbs -env TEST=1 -env


GRID=1 /usr/bin/env
HOME=/home/juser
LOGNAME=juser
GLOBUS_GRAM_JOB_CONTACT=https://client.example.org:3882/1600157953670079
3196/5295612977485997184/
GLOBUS_LOCATION=/opt/globus-5.0.0
GLOBUS_GASS_CACHE_DEFAULT=/home/juser/.globus/.gass_cache
TEST=1
X509_USER_PROXY=/home/juser/.globus/job/mactop.local/16001579536700793196.5
295612977485997184/x509_user_proxy
GRID=1

Using custom RSL clauses with globus-job-run

The following command line submits an mpi job using globus-job-run, setting the
jobtype RSL attribute to mpi. Any RSL attribute understood by the LRM can be added to
a job via this method.

% globus-job-run grid.example.org:2119/jobmanager-pbs -np 5 -x


'&(jobtype=mpi)' a.out
Hello, MPI (rank: 0, count: 5)
Hello, MPI (rank: 3, count: 5)
Hello, MPI (rank: 1, count: 5)
Hello, MPI (rank: 4, count: 5)
Hello, MPI (rank: 2, count: 5)

Constructing RSL strings with globus-job-run

The globus-job-run program can also generate the RSL language description of a job
based on the command-line options given to it. This example combines some of the
features above and prints out the resulting RSL. This RSL string can be passed to tools
such as globusrun to be run later.
% globus-job-run -dumprsl grid.example.org:2119/jobmanager-pbs -np 5 -x
'&(jobtype=mpi)' -env GRID=1 -env TEST=1 a.out
&(jobtype=mpi)
(executable="a.out")
(environment= ("GRID" "1") ("TEST" "1"))
(count=5)
Submitting Jobs with globus-job-submit

A related tool to globus-job-run is globus-job-submit. This command submits


a job to a GRAM5 service then exits without waiting for the job to terminate. Other tools
(globus-job-cancel, globus-job-clean, and globus-job-get-output) allow futher
interaction with the job.

The globus-job-submit program has most of the same command-line options as


globus-job-run. When run, instead of displaying the output and error streams of the
job, it prints the job contact, which is used with the other globus-job tools to interact with
the job.

globus-job-submit

This example shows the interaction of submitting a job via globus-job-submit,


checking its status with globus-job-status, getting its output with globus-job-get-
output, and then cleaning the job with globus-job-clean.

% globus-job-submit grid.example.org:2119/jobmanager-pbs /bin/hostname


https://grid.example.org:38843/16001600430615223386/5295612977486013582/
% globus-job-status
https://grid.example.org:38843/16001600430615223386/5295612977486013582/
PENDING
% globus-job-status
https://grid.example.org:38843/16001600430615223386/5295612977486013582/
ACTIVE
% globus-job-status
https://grid.example.org:38843/16001600430615223386/5295612977486013582/
DONE
% globus-job-get-output -r grid.example.org:2119/jobmanager-fork \
https://grid.example.org:38843/16001600430615223386/5295612977486013582/
node1.grid.example.org
% globus-job-clean -r grid.example.org:2119/jobmanager-fork \
https://grid.example.org:38843/16001600430615223386/5295612977486013582/

WARNING: Cleaning a job means:


- Kill the job if it still running, and
- Remove the cached output on the remote resource
Are you sure you want to cleanup the job now (Y/N) ? y
Cleanup successful.

Using the globusrun tool

The globusrun tool provides a more flexible tool for submitting, monitoring, and
canceling jobs. With this tool, most of the functionality of the GRAM5 APIs are made
available.

One major difference between globusrun and the other tools described above is
that globusrun uses the RSL language to provide the job description, instead of
multiple command-line options to describe the various aspects of the job. The section
on globus-job-run contained a brief example RSL in the -dumprsl example above.

Checking RSL Syntax

% globusrun-p "&(executable=a.out)"

RSL Parsed Successfully...


% globusrun-p "&/executable=a.out)"
ERROR: cannot parse RSL &/executable=/adfadf/adf /adf /adf)
Syntax: globusrun [-help] [-f RSL file] [-s][-b][-d][...] [-r RM] [RSL]
Use -help to display full usage
Checking Service Contacts

This example shows how to check that a globus-gatekeeper is running at a particular


contact and that the client and service have mutually-trusted credentials.

GRAM Authentication test

% globusrun-a -r grid.example.org:2119/jobmanager-pbs
GRAM Authentication test successful
% globusrun-a -r grid.example.org:2119/jobmanager-lsf
GRAM Authentication test failure: the gatekeeper failed to find the requested service
% globusrun-a -r grid.example.org:2119/jobmanager-pbs:host@not.example.org
GRAM Authentication test failure: an authorization operation failed
globus_xio_gsi: gss_init_sec_context failed.
GSS Major Status: Unexpected Gatekeeper or Service Name
globus_gsi_gssapi: Authorization denied: The name of the remote host
(host@not.example.org), and the expected name for the remote host
(grid.example.org) do not match. This happens when the name in the host certificate
does not match the information obtained from DNS and is often a DNS configuration
problem.

Basic Interactive job with globusrun

This example shows how to submit interactive job with globusrun. When the -s
is used, the output of the job command is returned to the client and displayed as if the
command ran locally. This is similar to the behavior of the globus-job-run program
described above.

Basic Interactive Job

% globusrun-s -r example.grid.org/jobmanager-pbs
"&(executable=/bin/hostname)(count=5)"
node03.grid.example.org
node01.grid.example.org
node02.grid.example.urg
node05.grid.example.org
node04.grid.example.org

Basic batch job with globusrun

This example shows how to submit, monitor, and cancel a batch job using
globusrun. This method is useful for the case where the job may run for a long time,
the job may be queued for a long time, or when there are network reliability issues
between the client and service.

Basic Batch Job

% globusrun-b -r grid.example.org:2119/jobmanager-pbs
"&(executable=/bin/sleep)(arguments=500)"
globus_gram_client_callback_allow successful
GRAM Job submission successful
https://grid.example.org:38824/16001608125017717261/5295612977486019989/
GLOBUS_GRAM_PROTOCOL_JOB_STATE_PENDING
% globusrun-status
https://grid.example.org:38824/16001608125017717261/5295612977486019989/
PENDING
% globusrun-k
https://grid.example.org:38824/16001608125017717261/5295612977486019989/
%

Refreshing a GRAM5 Credential

% globusrun-refresh-proxy
https://grid.example.org:38824/16001608125017717261/5295612977486019989/
% echo $?
0

Dealing with credential expiration

When the Job Manager's credential is about to expire, it sends a message to all
clients registered for GLOBUS_GRAM_PROTOCOL_JOB_STATE_FAILED
notifications that the job manager is terminating and that the job will continue to run
without the job manager. Any client which receives such a message can (if necessary)
generate a new proxy as described above and then submit a restart request to start a
job manager with a new credential. This job manager will resume monitoring the jobs
which were started prior to proxy expiration.

Proxy Expiration Example

% globusrun-r grid.example.org "&(executable=a.out)"


globus_gram_client_callback_allow successful
GRAM Job submission successful
GLOBUS_GRAM_PROTOCOL_JOB_STATE_ACTIVE
GLOBUS_GRAM_PROTOCOL_JOB_STATE_FAILED
GRAM Job failed because the user proxy expired (job is still running) (error code 131)
% grid-proxy-init
Your identity: /DC=org/DC=example/OU=grid/CN=Joe User
Enter GRID pass phrase for this identity:
Creating proxy ........................................................................... Done
Your proxy is valid until: Tue Nov 10 04:25:03 2009
% globusrun-r grid.example.org
"&(restart="https://grid.example.org:1997/16001700477575114131/5295612977486005
428/)"
globus_gram_client_callback_allow successful
GRAM Job submission successful
GLOBUS_GRAM_PROTOCOL_JOB_STATE_ACTIVE
GLOBUS_GRAM_PROTOCOL_JOB_STATE_DONE
Reliable job submit
The globusrun command supports a two-phase commit protocol to ensure that
the client knows the contact of the job which has been created so that it can be
monitored or canceled in the case of a client or service error. The two-phase commit
affects both job submission and termination.

The two-phase protocol is enabled by using the two_phase RSL attribute, as in


the next example. When this is enabled, job submission will fail with the error
GLOBUS_GRAM_PROTOCOL_ERROR_WAITING_FOR_COMMIT. The client must
respond to this signal with either the
GLOBUS_GRAM_PROTOCOL_JOB_SIGNAL_COMMIT_REQUEST or
GLOBUS_GRAM_PROTOCOL_JOB_SIGNAL_COMMIT_EXTEND signals to either
commit the job to execution or delay the commit timeout. One of these signals must be
sent prior to the two phase commit timeout, or the job will be discarded by the GRAM
service.

A two phase protocol is also used at job termination if the save_state RSL
attribute is used along with the two_phase attribute. When the job manager sends a
callback with the job state set to GLOBUS_GRAM_PROTOCOL_JOB_STATE_DONE
or GLOBUS_GRAM_PROTOCOL_JOB_STATE_DONE it will wait to clean up the job
until the two phase commit occurs. The client must reply with the
GLOBUS_GRAM_PROTOCOL_JOB_SIGNAL_COMMIT_END signal to cause the job
to be cleaned. Otherwise, the job will be unloaded from memory until a client restarts
the job and sends the signal.

Two phase commit example


In this example, the user submits a job with a two_phase timeout of 30 seconds
and the save_state attribute. The client must send commit signals to ensure the job
runs.
% globusrun-r grid.example.org:2119/jobmanager-pbs \
"&(two_phase = 30) \
(save_state = yes) \
(executable = a.out)"

globus_gram_client_callback_allow successful
GRAM Job submission successful
GLOBUS_GRAM_PROTOCOL_JOB_STATE_PENDING
GLOBUS_GRAM_PROTOCOL_JOB_STATE_ACTIVE
GLOBUS_GRAM_PROTOCOL_JOB_STATE_DONE
%

Reconnecting to a job

If a job manager or client exits before a job has completed, the job will continue
to run. The client can reconnect to a job manager and receive job state notifications and
output using the restart RSL attribute.

Restart example

This example uses globus-job-submit to submit a batch job and then


globusrun to reconnect to the job.

% globus-job-submitgrid.example.org:2119/jobmanager-pbs /bin/sleep 90
https://grid.example.org:38824/16001746665595486521/5295612977486005662/
% globusrun-r grid.example.org:2119/jobmanager-pbs \
"&(restart =
https://grid.example.org:38824/16001746665595486521/5295612977486005662/)"
globus_gram_client_callback_allow successful
GRAM Job submission successful
GLOBUS_GRAM_PROTOCOL_JOB_STATE_DONE
%

Submitting a Java job


To submit a job that runs a java program, the client must ensure that the job can
find the Java interpreter and its classes. This example sets the default PATH and
CLASSPATH environment variables and uses the shell to locate the path to the java
program.

Java example

This example uses globus-job-submit to submit a java job, staging a jar file
from a remote service.

% globusrun-r grid.example.org:2119/jobmanager-pbs \
"&(environment = (PATH '/usr/bin:/bin') (CLASSPATH \$(SCRATCH_DIRECTORY)))
(scratch_dir = \$(HOME))
(directory = \$(SCRATCH_DIRECTORY))
(rsl_substitution = (JAVA_SERVER http://java.example.org))
(file_stage_in =
(\$(JAVA_SERVER)/example.jar \$(SCRATCH_DIRECTORY)/example.jar)
(\$(JAVA_SERVER)/support.jar \$(SCRATCH_DIRECTORY)/support.jar))
(executable=/bin/sh)
(arguments=-c 'java -jar example.jar')"
globus_gram_client_callback_allow successful
GRAM Job submission successful
GLOBUS_GRAM_PROTOCOL_JOB_STATE_PENDING
GLOBUS_GRAM_PROTOCOL_JOB_STATE_ACTIVE
GLOBUS_GRAM_PROTOCOL_JOB_STATE_DONE
%

Result:

Thus a grid portal for the user to submit a job and get the result using GRAM
concept is created and executed successfully.

You might also like