Tải bản đầy đủ (.pdf) (23 trang)

CÔNG NGHỆ GRID COMPUTING VÀ ỨNG DỤNG THỬ NGHIỆM TRONG BÀI TOÁN QUẢN TRỊ MẠNG - 10 ppt

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (663.67 KB, 23 trang )









Phụ lục
- 193 -
<xsd:sequence>
<xsd:element name="value" type="xsd:int"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>

<xsd:element name="addResponse">
<xsd:complexType/>
</xsd:element>

</xsd:schema>
</types>

&lt! Messages >

&lt! PortType >

</definitions>

Ở đây định nghĩa các kiểu của các thành phần add và addResponse.


Trên đây vừa trình bày sơ nét về cấu trúc cơ bản của file GWSDL, có thể thêm
các kiểu mới, mở rộng bằng cách tham khảo các không gian tên đã được định nghĩa
sẵn.
C
C
.
.


K
K




t
t
h
h
u
u


t
t


c
c
à

à
i
i


đ
đ


t
t


c
c
á
á
c
c


c
c
h
h


c
c



n
n
ă
ă
n
n
g
g


c
c
ơ
ơ


b
b


n
n


c
c


a

a


G
G
r
r
i
i
d
d


S
S
e
e
r
r
v
v
i
i
c
c
e
e


C

C
.
.
1
1
.
.


K
K




t
t
h
h
u
u


t
t


c
c
à

à
i
i


đ
đ


t
t


O
O
p
p
e
e
r
r
a
a
t
t
i
i
o
o
n

n


P
P
r
r
o
o
v
v
i
i
d
d
e
e
r
r


Như đã giới thiệu, GT3 hỗ trợ 2 cách cài đặt interface trong ngôn ngữ lập trình,
cách thứ nhất là kỹ thuật sử dụng tính kế thừa, ở đây lớp MathImpl kế thừa từ lớp
GridServiceImpl, do GridServiceImpl có tất cả các chức năng cơ bản nên MathImpl
chỉ cần cài đặt tất cả các phương thức của Math portType là đủ. Như trên hình 0-1,
lớp MathImpl chứa tất cả các hàm cài đặt cho các phương thức của portType (L
ưu
ý, ở đây có nhiều hàm hơn). Tuy nhiên, cài đặt tất cả các phương thức của portType
chỉ trong một lớp có thể gây ra nhiều bất tiện đặc biệt là đối với các portType lớn,
có nhiều phương thức. Và kỹ thuật này, đối với Java, lớp MathImpl không thể kế

thừa từ một lớp nào nữa, điều này hạn chế việc tái sử dụng mã.










Phụ lục
- 194 -

Hình 8-1 Lớp triển khai interface của Grid service bằng kỹ thuật kế thừa.

GT3 đưa một hướng tiếp cận mới để giải quyết khuyết điểm của kỹ thuật sử
dụng tính kế thừa, đó là kỹ thuật uỷ quyền. Hướng tiếp cận này cho phép phân tán
các nhóm phương thức vào các lớp khác nhau, các lớp này được gọi là Operation
Provider. Như trên hình 0-2, có thể chia lớp MathImpl thành 3 lớp, ứng với từng
nhóm phương thức.


Hình 8-2 Cài đặt intrface củaGrid service bằng kỹ thuật Operation Provider

Lưu ý là 3 lớp này không thừa kế từ lớp nào hết, chúng chỉ cài đặt một interface
tên là Operation Provider. Lúc này các chức năng của lớp GridServiceImpl không
được kế thừa từ đây mà được yêu cầu Grid service container cung cấp thông qua
bản đặc tả triển khai. Khi tiến hành cài đặt theo cách tiếp cận này, có một số thay
đổi nhỏ so với kỹ thuật sử dụng tính kế thừa, như trình bày dưới đây.


Lớp cung cấp hoạt động (Operation Provider) ở đây gọi là MathProvider cũng
giống như các lớp của MathImpl trước đây, chỉ khác là ở đây cài đặt thêm interface
OperationProvider, file :
$GRIDSER_DEMO/org/globus/progtutorial/services/core/providers/impl
/MathProvider.java








Phụ lục
- 195 -

package org.globus.progtutorial.services.core.providers.impl;
import org.globus.ogsa.GridServiceBase;
import org.globus.ogsa.GridServiceException;
import org.globus.ogsa.OperationProvider;
import java.rmi.RemoteException;
import javax.xml.namespace.QName;
//Luu y o day cai dat OperationProvider
public class MathProvider implements OperationProvider
{
// Cac thuoc tinh cua Operation provider
//Khai bao namespace
private static final String namespace =
"


//Khai bao ten cac phuong thuc duoc cung cap, tuong ung voi file GWSDL
private static final QName[] operations =
new QName[]
{ new QName(namespace, "add"),
new QName(namespace, "subtract"),
new QName(namespace, "getValue") };

private GridServiceBase base;

// Cac phuong thuc cua Operation Provider
public void initialize(GridServiceBase base) throws GridServiceException {
this.base = base;
}
public QName[] getOperations() {
return operations;
}

//Cai dat
private int value = 0;
public void add(int a) throws RemoteException
{
value = value + a;
}
// tuong tu MathImpl
}

File đặc tả triển khai cũng có một số thay đổi, file :

$GRIDSER_DEMO/org/globus/progtutorial/services/core/providers/serv

er-deploy.wsdd

<?xml version="1.0"?>
<deployment
<! Tuong tu tren >

<parameter name="schemaPath"
value="schema/progtutorial/MathService/Math_service.wsdl"/>

<! Ten class >
<parameter name="className"
value="org.globus.progtutorial.stubs.MathService.MathPortType"/>

<! Yeu cau Grid service container goi chuc nang cua
GridServiceImpl nhu la chuc nang co ban cua MathService >
<parameter name="baseClassName"
value="org.globus.ogsa.impl.ogsi.GridServiceImpl"/>








Phụ lục
- 196 -

<parameter name="operationProviders"
value="org.globus.progtutorial.services.core.providers.impl.Math

Provider"/>

<!—Tuong tu tren >
</deployment>

Các thao tác khác để triển khai service hoàn toàn tương tự như đã giới thiệu ở
trên.


C
C
.
.
2
2
.
.


T
T
h
h
ê
ê
m
m


t

t
h
h
à
à
n
n
h
h


p
p
h
h


n
n


d
d




l
l
i

i


u
u


(
(
S
S
e
e
r
r
v
v
i
i
c
c
e
e


D
D
a
a
t

t
a
a


E
E
l
l
e
e
m
m
e
e
n
n
t
t


(
(
S
S
D
D
E
E
)

)
)
)


Như đã biết, mỗi Grid service đều có các SDE của riêng mình, phần này sẽ xem
xét kỹ thuật thêm SDE cho một service. Ở đây chúng ta thêm một SDE có tên là
MathData chứa các thông tin như giá trị hiện tại (value), phép toán thực hiện cuối
cùng (lastOp), số phép toán đã thực hiện (numOp), MathData chỉ có một và chỉ một
giá trị (cardinality = 1 1) được mô tả trên hình 0-3:

Hình 8-3 Ví dụ về SDE của MathService

+ Đặc tả SDE
Việc định nghĩa một SDE cho một service thông qua file đặc tả GWSDL, tuy
nhiên MathData là một kiểu phức tạp nên mặc dù có thể đặc tả kiểu này trong file
GWSDL, chúng ta có thể đặc tả trong một file khác. File :
$GRIDSER_DEMO/schema/progtutorial/MathService_sd/MathSDE.xsd

<complexType name="MathDataType">
<sequence>
<element name="value" type="int"/>
<element name="lastOp" type="string"/>
<element name="numOps" type="int"/>
</sequence>
</complexType>










Phụ lục
- 197 -
Bây giờ, chúng ta sẽ đặc tả lại inteface của service bằng cách tạo một file
GWSDL mới, file này có nội dung và cấu trúc gần giống với file GWSDL cũ, một
số phần thay đổi được trình bày ở đây. File :
$GRIDSER_DEMO/schema/progtutorial/MathService_sd/Math.gwsdl.

+ Xác định lại namespace,

<definitions name="MathService"
targetNamespace="
xmlns:tns="

xmlns:data="
xmlns:ogsi="
xmlns:gwsdl="

xmlns:sd="
xmlns:xsd="
xmlns="

+ Nhập file MathSDE.xsd định nghĩa MathData vào

<import location="MathSDE.xsd"
namespace=" />/>


+ Khai báo SDE trong đặc tả interface

<gwsdl:portType name="MathPortType" extends="ogsi:GridService">

<! <operation>s >

<sd:serviceData name="MathData"
type="data:MathDataType"
minOccurs="1"
maxOccurs="1"
mutability="mutable"
modifiable="false"
nillable="false">
</sd:serviceData>
</gwsdl:portType>

+ Cài đặt SDE
File :
$GRIDSER_DEMO/org/globus/progtutorial/services/core/servicedata/im
pl/MathImpl.java
Ở đây khai báo lớp không thay đổi:
public class MathImpl extends GridServiceImpl implements MathPortType

Lớp cài đặt này có thêm 2 thuộc tính private mới :
private ServiceData mathDataSDE; //La SDE
private MathDataType mathDataValue; //Chua gia tri cua SDE









Phụ lục
- 198 -
Việc tạo lập các SDE nằm trong hàm postCreate, ở đây chúng ta có thể để
các giá trị khởi tạo cho SDE.
public void postCreate(GridContext context) throws
GridServiceException
{
// Goi ham postCreate lop co so
super.postCreate(context);

//Duoi day la cac buoc tao mot SDE va dua vao Service Data Set
// Tao Service Data Element
mathDataSDE = this.getServiceDataSet().create("MathData");

// Tao mot doi tuong MathDataType va khoi tao cac gia tri
mathDataValue = new MathDataType();
mathDataValue.setLastOp("NONE");
mathDataValue.setNumOps(0);
mathDataValue.setValue(0);

// Dua cac gia tri vao doi tuong MathDataType
mathDataSDE.setValue(mathDataValue);

// Them SDE vao Service Data Set
this.getServiceDataSet().add(mathDataSDE);

}

Các hàm add(), substract() có thêm các lệnh mới để cập nhật lại SDE:

public void add(int a) throws RemoteException
{
//Cac ham setLastOp(),setValue(),setNumOps(), getNumOps() duoc tu
//dong phat sinh tu file dac ta MathSDE.xsd

mathDataValue.setLastOp("Addition");
incrementOps();
mathDataValue.setValue(mathDataValue.getValue() + a);
}

// Ham nay cap nhat MathData SDE tang so phep toan len 1
private void incrementOps()
{
int numOps = mathDataValue.getNumOps();
mathDataValue.setNumOps(numOps + 1);
}

+ Đặc tả cài đặt
Trong file đặc tả chỉ cần thay đổi lại các giá trị tương ứng tên các file mới
vừa tạo ra.
<parameter name="baseClassName"
value="org.globus.progtutorial.services.core.servicedata.impl.MathImpl"
/>
<parameter name="className"
value="org.globus.progtutorial.stubs.MathService_sd.MathPortType
"/>










Phụ lục
- 199 -
<parameter name="schemaPath"
value="schema/progtutorial/MathService_sd/Math_service.wsdl"/>

+ Client truy xuất SDE
//Khai bao import giong nhu tren
//
public class Client
{
public static void main(String[] args)
{
try
{
// Lay tham so dong lenh
URL GSH = new java.net.URL(args[0]);
int a = Integer.parseInt(args[1]);

// Lay GSR cua Math PortType
MathServiceGridLocator mathServiceLocator = new
MathServiceGridLocator();

MathPortType math = mathServiceLocator.getMathServicePort(GSH);


// Lay SDE "MathData", su dung phuong thuc findServiceData cua
GridServiceImpl
ExtensibilityType extensibility =
math.findServiceData(QueryHelper.getNamesQuery("MathData"));

ServiceDataValuesType serviceData =
AnyHelper.getAsServiceDataValues(extensibility);

MathDataType mathData =
(MathDataType) AnyHelper.getAsSingleObject(serviceData,
MathDataType.class);

// Xuat cac gia tri cua SDE ra man hinh
System.out.println("Value: " + mathData.getValue());
System.out.println("Previous operation: " + mathData.getLastOp());
System.out.println("# of operations: " + mathData.getNumOps());

// Goi phuong thuc cua service.
math.add(a);
}catch(Exception e)
{
System.out.println("ERROR!");
e.printStackTrace();
}
}
}


C
C
.
.
3
3
.
.


C
C
à
à
i
i


đ
đ


t
t


c
c
ơ
ơ



c
c
h
h
ế
ế


N
N
o
o
t
t
i
i
f
f
i
i
c
c
a
a
t
t
i
i

o
o
n
n


Như đã biết, cơ chế Notification cho phép client biết được những gì đang xảy ra
ở một Grid service instance. Cơ chế Notification liên quan mật thiết đến các SDE
của service. Trong GT3, cơ chế Notification hoạt động theo sơ đồ sau với các bước:









Phụ lục
- 200 -

Hình 8-4 Sơ đồ hoạt động của cơ chế Notification trong GT3.

1. addListener : Các client yêu cầu service thông báo cho mình khi có sự
thay đổi của SDE xác định trong lời gọi.
2. notifyChange : Khi có sự thay đổi, MathService sẽ yêu cầu SDE tương
ứng gửi thông báo cho các client đã yêu cầu.
3. deliverNotification : SDE thông báo cho client. Ở đây các giá trị của SDE
được gửi về cho client, do đó client không cần thực hiện thêm bất cứ truy vấn nào
nữa.

Có thể thấy đây là cơ chế “push” notification, GT3 chỉ hỗ trợ duy nhất dạng
này. Dưới đây, chúng ta sẽ xem xét chi tiết k
ỹ thuật cài đặt notification này trong
GT3 với MathService.

+ Khai báo sử dụng Notification trong portType
Thêm cơ chế Notification ảnh hưởng đến interface do chúng ta cần cung cấp
một số phương thức mới ra bên ngoài. Tất nhiên, chúng ta không cần cài đặt các
phương thức này mà chỉ cần khai báo sử dụng lại portType NotificationSource có
sẵn, portType này chứa đầy đủ các phương thức liên quan đến cơ chế Notification.
Do đó file GWSDL ở trên chỉ cần sửa lại như sau: File :
$GRIDSER_DEMO/schema/progtutorial/MathService_sd_notif/Math.gwsdl

<! Khai bao su dung lai portType NotificationSource >
gwsdl:portType name="MathPortType" extends="ogsi:GridService
ogsi:NotificationSource">

<! <cac operation> >

<! <serviceData> >

</gwsdl:portType>

+ Cài đặt
Chúng ta chỉ cần thêm một lệnh duy nhất trong các hàm cài đặt. File :
$GRIDSER_DEMO/org/globus/progtutorial/services/core/notifications/
impl/MathImpl.java

public void add(int a) throws RemoteException
{









Phụ lục
- 201 -
mathDataValue.setLastOp("Addition");
incrementOps();
mathDataValue.setValue(mathDataValue.getValue() + a);

//Yeu cau thong bao cho cac client
mathDataSDE.notifyChange();
}

+ Đặc tả cài đặt
Hoàn toàn giống như trước, chỉ thêm một dòng mới. File:
$GRIDSER_DEMO/org/globus/progtutorial/core/notifications/server-
config.wsdd

<deployment
<!—Khai bao tuong tu tren, dong duoi day duoc them moi >
<parameter name="operationProviders"
value="org.globus.ogsa.impl.ogsi.NotificationSourceProvider"/>
<!—-Tuong tu tren >
</deployment>


+ Client
Client ở đây phức tạp hơn so với các ví dụ trước. Client trong Java (hay đúng
hơn là lớp nhận các thông báo) phải cài đặt phương thức deliverNotification,
phương thức này sẽ được Grid service gọi khi có sự thay đổi trong SDE của mình.
Mã nguồn client như sau, file :
$GRIDSER_DEMO/org/globus/progtutorial/clients/MathService_sd_notif
/ClientListener.java

//Cac khai bao import

public class ClientListener
extends ServicePropertiesImpl implements NotificationSinkCallback
{
public static void main(String[] args)
{
// Lay tham so dong lenh
HandleType GSH = new HandleType(args[0]);
ClientListener clientListener = new ClientListener(GSH);
}

public ClientListener(HandleType GSH) throws Exception
{
// Bat dau dang ky va lang nghe MathService
NotificationSinkManager notifManager =
NotificationSinkManager.getManager();

notifManager.startListening(NotificationSinkManager.MAIN_THREAD);

String sink = notifManager.addListener("MathData", null, GSH, this);
System.out.println("Listening ");


// Cho nguoi dung nhan phim
System.in.read();

// Ket thuc lang nghe
notifManager.removeListener(sink);
notifManager.stopListening();
System.out.println("Not listening anymore!");








Phụ lục
- 202 -
}

//Khi co thay doi trong SDE,ham nay se duoc Grid service goi, se xuat ra man
// hinh cac gia tri cua SDE
public void deliverNotification(ExtensibilityType any) throws
RemoteException
{
try
{
// SDE da thay doi, lay gia tri moi
ServiceDataValuesType serviceData =
AnyHelper.getAsServiceDataValues(any);

MathDataType mathData = (MathDataType)
AnyHelper.getAsSingleObject(serviceData, MathDataType.class);

// Xuat ra man hinh
System.out.println("Current value: " + mathData.getValue());
System.out.println("Previous operation: " + mathData.getLastOp());
System.out.println("# of operations: " + mathData.getNumOps());
}catch(Exception exc)
{
System.out.println("ERROR!");
exc.printStackTrace();
}
}
}

C
C
.
.
7
7
.
.


C
C
à
à
i

i


đ
đ


t
t


k
k




t
t
h
h
u
u


t
t


t

t


o
o


s
s
e
e
r
r
v
v
i
i
c
c
e
e


đ
đ


n
n
g

g


(
(
T
T
r
r
a
a
n
n
s
s
i
i
e
e
n
n
t
t


s
s
e
e
r

r
v
v
i
i
c
c
e
e
)
)


Làm cho một service có khả năng được tạo lập một cách động (chuyển service
thành transient service) là một trong những việc dễ dàng nhất trong GT3, chúng ta
không cần thay đổi portType cũng như cài đặt của nó. Mọi thứ cần làm là sửa lại
file đặc tả cài đặt.
+ Đặc tả cài đặt
Để có thể thấy rõ hơn về sự thay đổi, chúng ta xem lại file WSDD cũ:
<?xml version="1.0"?>
<deployment name="defaultServerConfig"
xmlns="
xmlns:java="

<service
name="progtutorial/core/first/MathService" provider="Handler"
style="wrapped">

<parameter name="name" value="MathService"/>


<parameter name="baseClassName"
value="org.globus.progtutorial.services.core.first.impl.MathImpl"/>
<parameter name="className"
value="org.globus.progtutorial.stubs.MathService.MathPortType"/>
<parameter name="schemaPath"
value="schema/progtutorial/MathService/Math_service.wsdl"/>

<!—Cac tham so chung >
<parameter name="allowedMethods" value="*"/>
<parameter name="persistent" value="true"/>
<parameter name="handlerClass"
value="org.globus.ogsa.handlers.RPCURIProvider"/>








Phụ lục
- 203 -

</service>

</deployment>

Dưới đây là file WSDD đã sửa đổi theo mô hình tạo service động với một
factory. Lưu ý, chúng ta sẽ khai báo một service factory tĩnh (persistent service) để
chịu trách nhiệm tạo ra các MathService instance động (transient service). File :

$GRIDSER_DEMO/org/globus/progtutorial/services/core/first/server-
deploy.wsdd

<?xml version="1.0"?>
<deployment name="defaultServerConfig"
xmlns="
xmlns:java="

<service name="progtutorial/core/first/MathFactoryService"
provider="Handler"
style="wrapped">

<parameter name="name" value="MathService Factory"/>
<parameter name="instance-name" value="MathService Instance"/>
<parameter name="instance-schemaPath"
value="schema/progtutorial/MathService/Math_service.wsdl"/>
<parameter name="instance-baseClassName"
value="org.globus.progtutorial.services.core.first.impl.MathImpl"/>
<parameter name="instance-className"
value="org.globus.progtutorial.stubs.MathService.MathPortType"/>

<!—Cac tham so chung >
<parameter name="allowedMethods" value="*"/>
<parameter name="persistent" value="true"/>
<parameter name="handlerClass"
value="org.globus.ogsa.handlers.RPCURIProvider"/>

<parameter name="className"
value="org.gridforum.ogsi.Factory"/>
<parameter name="baseClassName"

value="org.globus.ogsa.impl.ogsi.GridServiceImpl"/>
<parameter name="schemaPath"
value="schema/ogsi/ogsi_factory_service.wsdl"/>
<parameter name="operationProviders"
value="org.globus.ogsa.impl.ogsi.FactoryProvider"/>
<parameter name="factoryCallback"
value="org.globus.ogsa.impl.ogsi.DynamicFactoryCallbackImpl"/>
</service>

</deployment>

Một chút khác biệt giữa 2 bản đặc đặc tả:
+ Trước hết, chúng ta đã thêm tiền tố “instance-” vào name, schemaPath,
baseClassName, và className, bằng cách này, chúng ta cho container biết đây
là những tham số để truyền vào khi tạo các instance MathService thông qua
Factory.








Phụ lục
- 204 -
+ Sau đó chúng ta thêm các tham số mới vào “khối tham số chung”, để ý
lúc này, schemaPath, baseClassName, và className tham khảo đến mã thực thi
của Factory (cung cấp bởi GT3), không phải bất cứ mã thực thi nào do chúng ta
tạo ra.

+ Có thể thấy, việc thêm khả năng tạo lập động cho bất kỳ service nào,
đơn giản chỉ gồm 2 bước, thêm các tiền tố “instance-” và sửa lại “khối tham số
chung”

+ Đối với client
Có thể sử dụng lại các client cũ. Ở đây, chúng ta viết một client để demo khả
năng tạo lập, sử dụng và huỷ một service instance thông qua Factory.
File :
$GRIDSER_DEMO/org/globus/progtutorial/clients/MathService/FactoryC
lient.java

package org.globus.progtutorial.clients.MathService;

import org.gridforum.ogsi.OGSIServiceGridLocator;
import org.gridforum.ogsi.Factory;
import org.gridforum.ogsi.LocatorType;
import org.globus.ogsa.utils.GridServiceFactory;

import
org.globus.progtutorial.stubs.MathService.service.MathServiceGridLocator;
import org.globus.progtutorial.stubs.MathService.MathPortType;

import java.net.URL;

public class FactoryClient
{
public static void main(String[] args)
{
try
{

// Lay tham so dong lenh
URL GSH = new java.net.URL(args[0]);
int a = Integer.parseInt(args[1]);

// Lay GSR cua MathService Factory
OGSIServiceGridLocator gridLocator = new OGSIServiceGridLocator();
Factory factory = gridLocator.getFactoryPort(GSH);
GridServiceFactory mathFactory = new GridServiceFactory(factory);

// Tao mot MathService instance moi va lay GSR cua no
LocatorType locator = mathFactory.createService();
MathServiceGridLocator mathLocator = new MathServiceGridLocator();
MathPortType math = mathLocator.getMathServicePort(locator);

// Goi phuong thuc Add()
math.add(a);
System.out.println("Added " + a);
int value = math.getValue();
System.out.println("Current value: " + value);

// Huy service instance sau khi su dung
math.destroy();
}catch(Exception e)
{
System.out.println("ERROR!");
e.printStackTrace();









Phụ lục
- 205 -
}
}
}
C
C
.
.
5
5
.
.


K
K




t
t
h
h
u

u


t
t


L
L
o
o
g
g
g
g
i
i
n
n
g
g


(
(
G
G
h
h
i

i


v
v
ế
ế
t
t
)
)


Logging là một kỹ thuật quan trọng trong phát triển và bảo trì phần mềm, cho
phép theo dõi các sự kiện đặc biệt của hệ thống, các sự kiện ghi nhận có thể được
kết xuất ra màn hình. GT3 cung cấp khả năng logging theo mô hình Apache Jakarta
Commons Logging ( />). Mô hình này đưa
ra 6 cấp độ thông tin logging, gồm Debug, Trace, Info, Warn, Error, Fatal. Việc
quyết định thông tin nào ở mức độ nào là tuỳ thuộc vào người lập trình ứng dụng.
Ở đây chúng ta sẽ thêm tính năng logging vào MathService, sử dụng lại ví dụ
đầu tiên. Khi thêm tính năng logging, chúng ta không cần sửa lại portType, chỉ cần
thêm các lệnh cần thiết vào mã cài đặt portType.

+ Cài đặt
File:
$GRIDSER_DEMO/org/globus/progtutorial/services/core/logging/impl/M
athImpl.java

//


import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

//

public class MathImpl extends GridServiceImpl implements MathPortType
{

// Tao logger cho class nay
static Log logger = LogFactory.getLog(MathImpl.class.getName());
//
public void add(int a) throws RemoteException
{

logger.info("Addition invoked with parameter a=" + String.valueOf(a));
if (a==0)
logger.warn("Adding zero doesn't modify the internal value!");

value = value + a;
}
//
public int getValue() throws RemoteException
{
logger.info("getValue() invoked");
return value;
}
}

+ Xem các kết xuất log
Để xem kết xuất log của MathService, thêm dòng sau vào cuối file:

$GLOBUS_LOCATION/ogsilogging.properties(Đây là file cấu hình Log
của GT3)








Phụ lục
- 206 -
#Cho biet can xuat cac log o cap do Info ra man hinh console, co the
sua #lai cac cap do khac, va ghi ra file
org.globus.progtutorial.services.core.logging.impl.MathImpl=console,in
fo
C
C
.
.
6
6
.
.


K
K





t
t
h
h
u
u


t
t


q
q
u
u


n
n


l
l
ý
ý



c
c
h
h
u
u


t
t
r
r
ì
ì
n
n
h
h


s
s


n
n
g
g



c
c


a
a


s
s
e
e
r
r
v
v
i
i
c
c
e
e


(
(
L
L
i
i

f
f
e
e
c
c
y
y
c
c
l
l
e
e


M
M
a
a
n
n
a
a
g
g
e
e
m
m

e
e
n
n
t
t
)
)


Như đã biết việc quản lý chu trình sống của các service instance được tạo lập
động rất quan trọng. GT3 cung cấp các công cụ hữu ích để quản lý các service như
phương thức callback (callback method), theo dõi chu trình sống (lifecycle
monitor). Ở đây chúng ta sẽ sử dụng lại các ví dụ trong phần transient service và
logging để demo 2 kỹ thuật trên.
+ Kỹ thuật Callback method.
Một cách đơn giản để quản lý chu trình sống bằng callback method (tương tự
các hàm sự kiện khi lập trình với MS Windows). Các phương thức callback được
gọi trong một số thời điểm xác định trong chu trình sống của service. GT3 hỗ trợ
các hàm callback sau:

Hàm Thời điểm được gọi
preCreate Khi quá trình tạo lập Grid Service bắt đầu, lúc này tất cả cấu hình
chưa được nạp.
postCreate Khi service đã được tạo ra và cấu hình service đã được tạo lập.
activate Tất cả Grid service đều mặc định ở trạng thái “không kích
hoạt”(deactivated), hàm này được gọi khi service được kích hoạt.
deactivate Khi service trở về trạng thái “không kích hoạt”
preDestroy Ngay trước khi service bị huỷ.
Bảng 8-2 Các hàm callback trong GT3.

File :
$GRIDSER_DEMO/org/globus/progtutorial/services/core/lifecycle/impl
/MathImpl.java

//
import org.globus.ogsa.GridServiceCallback;
//
public class MathImpl extends GridServiceImpl
implements MathPortType, GridServiceCallback
{
//
// Cai dat cac phuong thuc Callback, chi can su dung lai cac ham cai san cua
lop cha GridServiceImpl

public void preCreate(GridServiceBase base) throws GridServiceException
{
super.preCreate(base);
logger.info("Instance is going to be created (preCreate)");
}
public void postCreate(GridContext context) throws GridServiceException
{








Phụ lục

- 207 -
super.postCreate(context);
logger.info("Instance has been created (postCreate)");
}
public void activate(GridContext context) throws GridServiceException
{
super.activate(context);
logger.info("Instance has been activated (activate)");
}
public void deactivate(GridContext context) throws GridServiceException
{
super.deactivate(context);
logger.info("Instance has been deactivated (deactivate)");
}
public void preDestroy(GridContext context) throws GridServiceException
{
super.preDestroy(context);
logger.info("Instance is going to be destroyed (preDestroy)");
}
}

+ Kỹ thuật Lifecycle Monitor
Kỹ thuật Callback Method khá tốt, tuy nhiên nó khó có thể sử dụng lại. Giả
sử chúng ta có 2 hàm preCreate() và postCreate() và muốn sử dụng lại trong tất cả
các Grid Service, với kỹ thuật Callback Method, chỉ có cách đưa nó vào một lớp
cha, rồi cho tất cả các lớp Grid Service khác thừa kế từ nó. Tất nhiên đây có sự hạn
chế như đã giới thiệu trong phần Operation Provider.
GT3 đưa ra giải pháp mới là Lifecycle Monitor. Một lifecycle monitor là một
lớp triển khai interface ServiceLifeCycleMonitor, mộ
t interface với các hàm

callback được gọi tại các thời điểm quan trọng trong thời gian sống của Grid
service. Chúng ta không cần kế thừa hay tham thảo interface này trực tiếp từ mã
nguồn. Chúng ta chỉ cần thêm một dòng vào bản đặc tả triển khai yêu cầu lớp
lifecycle monitor phải được gọi khi có sự kiện đặc biệt xảy ra. Do đó, chúng ta có
thể dùng cùng một lifecycle monitor cho nhiều Grid service khác nhau.
Dưới đây là một lớp lifecycle monitor đơn giản, file :
$GRIDSER_DEMO/org/globus/progtutorial/services/core/lifecycle/impl
/MathLifecycleMonitor.java
package org.globus.progtutorial.services.core.lifecycle.impl;

import org.globus.ogsa.GridServiceException;
import org.globus.ogsa.ServiceLifecycleMonitor;
import org.globus.ogsa.GridContext;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class MathLifecycleMonitor implements ServiceLifecycleMonitor
{
// Tao logger cho lop
static Log logger = LogFactory.getLog(MathLifecycleMonitor.class.getName());

//Cac phuong thuc can callback
public void create(GridContext context) throws GridServiceException
{
logger.info("Instance is going to be created (create)");
}









Phụ lục
- 208 -
public void destroy(GridContext context) throws GridServiceException
{
logger.info("Instance is going to be destroyed (destroy)");
}
public void preCall(GridContext context) throws GridServiceException
{
logger.info("Service is going to be invoked (preCall)");
}
public void postCall(GridContext context) throws GridServiceException
{
logger.info("Service invocation has finished (postCall)");
}
public void preSerializationCall(GridContext context)
{
logger.info("Input parameters are going to be deserialized
(preSerializationCall)");
}
public void postSerializationCall(GridContext context)
{
logger.info("Input parameters have been deserialized
(postSerializationCall)");
}
}


Và thêm dòng sau vào file đặc tả triển khai (.WSDD)

<parameter name="lifecycleMonitorClass"
value="org.globus.progtutorial.services.core.lifecycle.impl.MathLifecycleMonitor"/>

D
D
.
.


C
C
á
á
c
c


i
i
n
n
t
t
e
e
r
r

f
f
a
a
c
c
e
e


c
c


a
a


m
m


t
t


O
O
G
G

S
S
I
I


S
S
e
e
r
r
v
v
i
i
c
c
e
e



Bảng 0-3 tóm tắt các interface của một Grid Service được định nghĩa trong
OGSI 1.0:

Interface Loại Tên chi tiết Diễn giải
Định nghĩa các ứng xử cơ bản của một service.
interface Danh sách tên (QName) các
interface của service.

serviceDataName
Danh sách tên (QName) các
SDE của service (động và
tĩnh)
factoryLocator
Vị trí (ogsi:LocatorType) của
factory tạo ra service instance
này
gridServiceHandle
Zero hoặc nhiều GSH của
service instance
Grid
Service

SDE
gridServiceReference
Một hoặc nhiều GSR của
service instance








Phụ lục
- 209 -
findServiceDataExtensibility
Tập các phương thức mở

rộng của phương thức
findServiceData
setServiceDataExtensibility
Tập các phương thức mở
rộng của phương thức
setServiceData
terminationTime
Thời gian dự kiến kết thúc
của service instance.


findServiceData
Truy vấn thông tin của
service.
setServiceData
Cho phép thay đổi giá trị các
SDE được phép thay đổi giá
trị. (modifiable= “true”)
requestTerminationAfter
Yêu cầu thay đổi
terminationTime của service
instance. Phương thức này
xác định thời gian kết thúc
sớm nhất có thể được.
requestTerminationBefore
Yêu cầu thay đổi
terminationTime của service
instance. Phương thức này
xác định thời gian kết thúc trễ
nhất có thể được.


Phương
thức
destroy
Huỷ tường minh service
instance.
Thực hiện ánh xạ từ GSH sang GSR
handleResolverScheme
Tập các URI xác định lược
đồ GSH sử dụng để phân giải
thành GSR.
SDE

Handle
Resolver

Phương
thức
findByHandle
Trả về vị trí
(ogsi:LocatorType) chức các
GSR tương với GSH đươc
yêu cầu.
Cho phép các client đặt các yêu cầu cung cấp các thông báo
notifiableServiceDataName
Tập các QName của SDE
được yêu cầu thông báo mỗi
khi có sự thay đổi.
subscribeExtensibility
Tập các phương thức mở

rộng của phương thức
subscribe
SDE

Notification
Source

Phương
thức
subscribe
Yêu cầu phải được thông báo
mỗi khi có sự thay đổi của
các SDE xác định trong
notifiableServiceDataName.
Định nghĩa phương thức phân phối các thông điệp








Phụ lục
- 210 -
Định nghĩa phương thức phân phối các thông điệp
SDE Không có
Notification
Sink


Phương
thức
deliverNotification
Phân phối các thông báo.
Xác định mối quan hệ giữa một cặp NotificationSource và
NotificationSink

subscriptionExpression

sinkLocator

SDE

Notification
Subscription

Phương
thức
Không có
Cung cấp các cách thức chuẩn để tạo các service instance
createServiceExtensibility
Tập các phương thức mở
rộng của phương thức
createService
SDE

Factory
Phương
thức
createService

Tạo service instance mới.
Cho phép client quản lý một nhóm các service.
membershipContentRule
Là một cấu trúc liên kết một
portType với một tập các
QName. Mỗi service instance
nếu muốn là thành viên của
nhóm phải có một hoặc nhiều
interface xác định trong SDE
này.
SDE
entry
Biểu diễn thông tin về một
thành viên của ServiceGroup.
Service
Group

Phương
thức
Không có
Cho phép thêm và loại bỏ các Grid service instance trong các
ServiceGroup,
addExtensibility
Tập các phương thức mở
rộng của phương thức add
removeExtensibility
Tập các phương thức mở
rộng của phương thức
remove
SDE


add
Tạo một ServiceGroupEntry
và đưa vào ServiceGroup.
Service
Group
Registration

Phương
thức
remove
Loại bỏ ServiceGroupEntry
thoả yêu cầu đưa vào.
Định nghĩa mối quan hệ thành viên của service instance với ServiceGroup.
Service
Group
Entry

SDE
memberServiceLocator
Chứa vị trí
(ogsi:LocatorType) của
service instance được tham
khảo đến.









Phụ lục
- 211 -
content
Cung cấp một số thông tin về
service instance đang chứa.



Phương
thức
Không có
Bảng 8-3 Các interface của một OGSI Service
E
E
.
.


C
C


u
u


t
t

r
r
ú
ú
c
c


m
m


t
t


c
c
h
h


n
n
g
g


c
c

h
h




đ
đ
i
i


n
n


t
t




Một chứng chỉ điện tử bao gồm các phần chính : một subject (distinguished
name (DN)) duy nhất trong không gian tên của hệ thống Grid xác định người hoặc
đối tượng mà chứng chỉ đại diện, một khóa công khai đi kèm với subject, phần nhận
dạng CA thực hiện ký chứng nhận chứng chỉ, chữ ký của CA và phần mở rộng chứa
thông tin về cá nhân hay host được chứng nhận. Một số thông tin có thể là địa chỉ

email, tên tổ chức, …
Hình vẽ sau mô tả chi tiết cấu trúc một chứng chỉ điện tử:



Hình 8-5 Cấu trúc một chứng chỉ điện tử.

* Việc lấy chứng nhận cho một người dùng (lưu ý có thể là người dùng
thật sự hay host) trong Grid bao gồm các bước:
1. Người dùng Grid phát sinh một cặp khoá (khóa bí mật và khóa công
khai tương ứng), và một bản yêu cầu chứng nhận chứa khoá công khai và các
thông tin cần thiết theo yêu của CA.








Phụ lục
- 212 -
2. Sau đó, người dùng gửi bản yêu cầu đến CA. Còn khóa bí mật được
giữ lại và lưu trữ một cách cẩn thận.
3. CA (hay mở rộng ra là RA) thực hiện xác minh thông tin trong bản yêu
cầu là đúng sự thật, tức là tìm cách chứng minh user gửi yêu cầu chính là chủ
sở hữu của khóa công khai trong bản yêu cầu. Việc này có thể thực hiện bằng
nhiều cách khác nhau, có thể thông qua điện thoại, email, hay bằng con
đường tiếp xúc trự
c tiếp giữa hai bên,…
4. Sau khi kiểm tra xong, CA tạo một chứng chỉ bằng cách ký tên vào bản
yêu cầu, và gửi chứng chỉ này lại cho người dùng đã yêu cầu chứng nhận.


Việc yêu cầu chứng thực trên trên đây chỉ cần thực hiện một lần duy nhất,
từ khi nhận được chứng chỉ, người dùng có thể dùng nó đế đại diện cho mình
khi giao tiếp với bất kỳ hệ thống nào có yêu cầ
u chứng thực.










Phụ lục
- 213 -
T
T
à
à
i
i


l
l
i
i



u
u


t
t
h
h
a
a
m
m


k
k
h
h


o
o



[1] Ian Foster, The Grid, CLUSTERWORLD, vol 1, no.1, 2001,pp. 1-2

[2] Ian Foster, Carl Kesselman, Steven Tuecke, The Anatomy of Grid, Intl J.
Supercomputer Applications, 2001.


[3] Ian Foster, What is the Grid? A Three Point Checklist, Argonne National
Laboratory & University of Chicago, 20/06/2002.

[4] Ian Foster,Carl Kesselman, Jeffrey M. Nick, Steven Tuecke, The Physiology of
the Grid - An Open Grid Services Architecture for Distributed Systems
Integration, Version: 6/22/2002.

[5] I. Foster, D. Gannon, H. Kishimoto, The Open Grid Services Architecture,
GLOBAL GRID FORUM, 10/03/2004, />wg

[6] S. Tuecke, K. Czajkowski, I. Foster, J. Frey, S. Graham, C. Kesselman, T.
Maquire, T. Sandholm, D. Snelling, P. Vanderbilt, Open Grid Services
Infrastructure (OGSI) Version 1.0, GLOBAL GRID FORUM, 27/06/2003,
/>

[7] Mark Baker, Rajkumar Buyya, Domenico Laforenza, Grids and Grid
technologies for wide-area distributed computing, John Wiley & Sons Ltd, 2002

[8] Steven Fitzgerald, Ian Foster, Carl Kesselman, Gregor von Laszewski,
Warren Smith, Steven Tuecke, A Directory Service for Configuring
High-Performance Distributed Computations, 1997,

[9] Ian Foster, Carl Kesselman, Globus: A Metacomputing Infrastructure Toolkit,



[10] Karl Czajkowski, Steven Fitzgerald, Ian Foster, Carl Kesselman, Grid
Information Services for Distributed Resource Sharing, Proc. 10th IEEE
International Symposium on High-Performance Distributed Computing (HPDC-
10), IEEE Press, 2001.


[11] Karl Czajkowski, Ian Foster, Nicholas Karonis, Carl Kesselman,
Stuart Martin, Warren Smith, Steven Tuecke, A Resource Management
Architecture for Metacomputing Systems, 1997, www.globus.org

[12] Sam Lang, Sam Meder, Security and Credential Management on the Grid,
CLUSTERWORLD volume 1 no 2 , pp. 8-11, 02/2004

[13] Von Welch, Frank Siebenlist, Ian Foster, John Bresnahan,
Karl Czajkowski, Jarek Gawor, Carl Kesselman, Sam Meder,








Phụ lục
- 214 -
Laura Pearlman, Steven Tuecke, Security for Grid Services, www.globus.org.

[14] Von Welch, Ian Foster, Carl Kesselman, Olle Mulmo, Laura Pearlman, Steven
Tuecke, Jarek Gawor, Sam Meder, Frank Siebenlist, X.509 Proxy Certificates for
Dynamic Delegation, www.globus.org.

[15] Ian Foster, Carl Kesselman, Gene Tsudik, Steven Tuecke, A Security
Architecture for Computational Grids, 5th ACM Conference on Computer and
Communication Security, www.globus.org



[16] Bart Jacob, How Grid infrastructure affects application design, RedBooks,
IBM, 06/2003.

[17] Bart Jacob, Taking advantage of Grid computing for application enablement,
RedBooks, IBM, 06/2003.

[18] Martin C. Brown, Grid computing moving to a standardized platform,
RedBooks, IBM, 08/2003.

[19] IBM Corp. , The Era of Grid Computing: A new standard for successful IT
strategies, 01/2004, www.ibm.com


[20] Viktors Berstis, Fundamentals of Grid Computing, Redbooks, IBM Corp, 2002,
www.ibm.com/redbooks


[21] Luis Ferreira,Viktors Berstis, Jonathan Armstrong, Mike Kendzierski, Andreas
Neukoetter, Introduction to Grid Computing with Globus, Redbooks,IBM Corp,
09/2003, www.ibm.com/redbooks


[22] Bart Jacob, Luis Ferreira, Norbert Bieberstein, Candice Gilzean, Jean-Yves
Girard, Roman Strachowski, Seong (Steve) Yu, Enabling Applications for Grid
Computing with Globus, Redbooks, IBM Corp, 06/2003,
www.ibm.com/redbooks


[23] Luis Ferreira, Bart Jacob, Sean Slevin, Michael Brown, Srikrishnan Sundararajan,

Jean Lepesant, Judi Bank, Globus Toolkit 3.0 Quick Start, Redbooks, IBM Corp,
09/2003, www.ibm.com/redbooks


[24] Borja Sotomayor, The Globus Toolkit 3 Programmer's Tutorial, 2003-2004.
www.globus.org


[25] Richard Sharpe, Ed Warnicke, Ulf Lamping, Ethereal User's Guide: V2.00 for
Ethereal 0.10.5, 2004, www.ethereal.com


[26] Luis Ferreira, Arun Thakore, Michael Brown, Fabiano Lucchese, Huang RuoBo,
Linda Lin, Paul Manesco, Jeff Mausolf, Nasser Momtaheni, Karthik Subbian,
Olegario, Hernandez, Grid Services Programming and Application Enablement,
Redbooks,IBM Corp, 05/2004, www.ibm.com/redbooks










Phụ lục
- 215 -
[27] Parvin Asadzadeh, Rajkumar Buyya1, Chun Ling Kei, Deepa Nayar, Srikumar
Venugopal, Global Grids and Software Toolkits: A Study of Four Grid

Middleware Technologies, Grid Computing and Distributed Systems (GRIDS)
Laboratory, The University of Melbourne, Australia

[28] Matthew Strebe, Network Security JumpStart, SYBEX Inc., 2002

[29] James Stanger, Patrick Lane, Tim Crothers, CIW:Security Professional
Study Guide, SYBEX Inc., 2002, www.sybex.com


[30] Wenke Lee, Salvatore J. Stolfo, Kui W. Mok, Adaptive Intrusion Detection: a
Data Mining Approach, Kluwer Academic Publishers, 2000.

[31] John McHugh, Alan Christie, Julia Allen, Defending Yourself: The Role of
Intrusion Detection Systems, IEEE SOFTWARE, 10/2000.

[32] Thomas H. Ptacek, Timothy N. Newsham, Insertion, Evasion, and Denial of
Service:Eluding Network Intrusion Detection, Secure Networks Inc.,01/1998

[33] Detmar Liesen, Requirements for Enterprise-Wide Scaling Intrusion Detection
Products, 2002

[34] William Allcock, Programming with GridFTP Client Library,
CLUSTERWORLD volume 2 no 9 , pp. 1-6, 10/2004

[35] Globus Alliance, MDS ver 2.2 User’s Guide, Globus Aliance, www.globus.org
,
3/10/2003.

[36] William Allcock, GridFTP: Protocol Extensions to FTP for the Grid, Argonne
National Laboratory, 03/2003


[37] Snort Project, Snort Users Manual 2.3.2, www.snort.org
, 10/032005

×