レベル: 中級 Vladimir Silva, Contractor, Pervasive Systems Development, IBM
2004年 10月 26日 まもなくリリース (Globus Web サイトによれば 2005 年1月 31日) される Globus Toolkit 4 (GT4) の特長は、Web Services Resource Framework (WSRF) [1] と Web Service Notification (WSN) [2] の両規格を新たに実装していることです。GT4 には、異機種混合の分散コンピューティング環境を対象としたステートフルな Web サービスを構築するための API が備えられています。この記事の目的は、GT4 で使用される新規格とその実際の応用例を紹介することによって、自組織に適したステートフル・サービスのモデル化を支援することです。
新機能 :WS-Components
GT4 には、以下のような Web サービス・コンポーネントが新たに組み込まれています。
-
WS Authentication Authorization
WS Authentication Authorization は、Grid Security Infrastructure (GSI) に代わるものであり、その内容は Message level security と Authorization framework の 2 つに分けられます。Message level security は、WS-Security と WS-SecureConversation の 2 つの標準規格を実装したものです。これらの標準規格により、SOAP メッセージの暗号化、保全性、リプレイ保護が可能になります。
Authorization Framework は、多くの認証スキーマ、例えば grid-mapfile、アクセス制御リスト (ACL)、SAML プロトコル経由のカスタム認証ハンドラーなどを取り扱えるように設計されたコンポーネントです。
-
WS Core
WS Core は、WSRF と Web Services Notification (WSN) の 2 つの新規格を実装しています。その他の新機能としては、Apache Tomcat ベースの JNDI レジストリー、HTTP/1.1 のクライアントとサーバーのサポート、URI から WS-Addressing に変換するためのリゾルバー・サービスなどがあります。
-
C WS Core
この機能は C 言語プログラマーから高く評価されることでしょう。GT4 には、WSRF 対応の Web サービスおよびクライアント (いずれも WS-Resource と WS-Notification に準拠) を作成するための、C 言語基本ツールセットが用意されています。この C Core には、以下のような画期的機能が組み込まれています。
- スタンドアロンのサービス・コンテナー
- C アプリケーションにサービスを埋め込むための API
- サービス内部から資源を管理するための資源 API
- HTTP/1.1 のクライアントとサーバーに対するサポート
- WSDL スキーマから純粋な C スタブ (ブロッキング型または非同期型) を直接生成
- 新規の拡張APIに基づいて、オペレーション・プロバイダーとサービス・モジュールを動的にロード可能

 |
旧プロトコルの変更点
GT3 の周知のプロトコル (資源管理用の WS-GRAM、データ管理用の RFT、情報サービス用の MDS) はすべて、WSRF を使用できるように再設計されました。セキュリティー・プロトコルである GSI は、WS Authentication Authorization という名称に変更されました。以下の互換性の表は、次期リリースの Globus Toolkit の主要プロトコルの基本機能と互換性について、概略を示したものです。詳細な情報は、[4] に記載されています。
表 1. GT4 の新しいプロトコル
|
サービス
|
プロトコル
|
機能
|
後方互換性
| | データ転送 | Reliable File Transfer (RFT) |
- GridFTP を使用して、サード・パーティーのファイル転送を制御、監視
- 指数バックオフ
- All または None の転送
- 並列転送
- TCP バッファー・サイズ
- 再帰的ディレクトリー転送
| OGSI (GT3.2) との下位互換性はありません | | 資源管理 | WS-GRAM |
- ジョブ・パフォーマンスの向上 :並行性、スループット、レイテンシー
- 信頼性/リカバリーの向上
- 以下の内容を含む、mpich-g2 ジョブのサポート
- マルチジョブの実行依頼
- ジョブ内のプロセスの調整
- マルチジョブ内のサブジョブ間の調整
| このプロトコルは、WSRF に準拠するように変更されました。このバージョンと以前のバージョンとの間に下位互換性はありません。 | | 情報サービス | MDS4 |
インデックス・サービス
- OGSI ではなく WSRF に準拠
- Xindice のサポートは排除済み
- 集約の永続的構成はリファクタリング済み
新規のサービス
- トリガー・サービス
- 統合サービス
- アーカイブ・サービス
| OGSI ではなく WSRF を使用するようにサービスの再モデル化が行われたため、GT3.2 のインデックス・サービスとの互換性はありません |
WSRF について
WSRF でステートフル・サービスが提供される仕組みを理解するには、まず Web サービスについて把握し、標準的な方法で状態を定義する必要があります。「Web サービスとは、マシン間の対話をサポートするソフトウェア・コンポーネントであり、マシンで処理できる形式 (WSDL) で記述された、ネットワーク越しに呼び出し可能なインターフェースを有します。サービス間の対話は、SOAP メッセージを使用して表されます。そのSOAP メッセージは通常、HTTPなどのWeb標準トランスポート・プロトコルを使用して、XML シリアライゼーションによって構成されます」[3]
ここでいう「サービス指向アーキテクチャー (SOA) は、メッセージ交換によって協調して動作するような Web サービスで構成された分散システムを定義します。Web サービスはステートレスなので、入力メッセージに含まれない情報については、アクセスも使用もせずにメッセージを交換します。
ステートフル・サービスとは、メッセージ交換時に実行コンテキストをヘッダーで伝搬することにより、論理的なステートフル・リソースに対するアクセスや操作を行うサービスです。一般的には、ステートレス・サービスのほうが信頼性とスケーラビリティーに優れています。(例えば、障害が発生した場合でも、過去のやり取りに関係なくサービスを再開できます。また、システム負荷に応じて、サービス・インスタンスを新規生成したり破棄したりすることも可能です。)そのため、Web サービスのコミュニティーでは、ステートレス・サービスのほうが設計上望ましいと考えられています。
しかし、ステートフル・サービス (メッセージ交換に基づいてステートフル・リソースを操作するサービス) のほうが望ましいと考えられる場合もあります。サービス間の相互運用性に関わるシナリオがこれに該当します。そこで、「相互運用性のあるサービスの構築と使用を容易にするために、状態の表現と操作を行うパターンを明確化し、標準化することが重要」[3 の p.9] という考えが生まれます。
WS-Resource は、1 つの Web サービスと 1 つの「ステートフル・リソース」で構成されるエンティティーとして定義されます。ステートフル・リソースは、Web サービスのメッセージ交換で使用できます。WS-Resource は生成と破棄が可能で、その状態はメッセージ交換を介して照会、変更できます。
WS-Resource には、「ACID プロパティー」として知られる、ソフトウェア・エンジニアリングで非常に重要視される 4 つの特性があります。これらのプロパティーのほとんどは、Web Services Atomic Transaction 仕様 [WS-AtomicTransaction] に記述されています。
-
原子性 (A):トランザクション単位内でのステートフル・リソースの更新は「全か無か」方式で行われます。
-
一貫性 (C):ステートフル・リソースは、障害後であっても常に一貫した状態であることが必要です。
-
独立性 (I):ステートフル・リソースの更新は、任意のトランザクション作業単位内で独立していることが必要です。
-
耐久性 (D):トランザクション単位内でなされたステートフルリソースへの更新の耐久性を提供します。
ステートフル・リソース
ステートフル・リソースは、以下の 3 つの特性を持つコンポーネントとして定義できます。[3 の p.10]
- XML 形式で定義された「状態」データで構成されている。
- ライフ・サイクルがある。
- 1 つ以上の Web サービスによって操作可能。
ステートフル・リソースの例には、ファイル、Java オブジェクト、データベース内の行などがあります。ステートフル・リソースは複合 (他のリソースを内包すること) が可能で、そのインスタンスはサービス・ファクトリーによって生成または破棄できます。ステートフル・リソースのインスタンスは ID (リソース ID) によって識別する必要があります。また、リソースを使用するアプリケーションは、追加の ID (エイリアス) を割り当てることができます。
Web サービスとステートフル・リソースの関係は「リソース・パターン」の概念によって定義されます。ここでいうリソース・パターンとは、ステートフル・リソースを Web サービスのメッセージ交換に関連付ける仕組みを定義するものです。この関係は、リソースとサービスの関連付けが配備時に行われる場合は静的で、メッセージ交換時に行われる場合は動的です。リソース・パターンは、XML、WSDL、WS-Addressing などの標準規格に基づいて実装されます。
WS-Addressing
WS-Addressing は、エンドポイント・リファレンスを標準化するための構造です。エンドポイント・リファレンスは、ネットワーク・エンドポイント上に配備された Web サービスのアドレスを表すものであり、通常は新規リソースを生成する Web サービス要求によって返される、XML シリアライゼーションとして表現されます。エンドポイント・リファレンスには、Web サービスのアドレス以外に、サービスの記述や「リファレンス・プロパティー」などのメタデータが含まれている場合があります。
リスト 1. WS-Addressing のエンドポイント・リファレンス
<wsa:EndpointReference>
<!-- Web Service address over a network endpoint -->
<wsa:Address>
http://helloworld.com/myWebService
</wsa:Address>
<!-- Meta Data -->
<!-- Endpoint reference properties -->
<wsa:ReferenceProperties>
<tns:resourceID> ID-12345 </tns:resourceID>
</wsa:ReferenceProperties>
</wsa:EndpointReference>
|
エンドポイント・リファレンスの使用方法について、以下の図で例示します。この例は、呼び出された Web サービス (LIFService、つまり、大きな整数の素因数分解) を生成するためのメッセージ交換を示したものです。
図 1. Web サービス生成の SOAP 要求
図 2. Web サービス生成の SOAP 応答
WS-Resource のライフ・サイクル
ライフ・サイクルは、WS-Resource の生成から消滅まで (下記の説明参照) の期間として定義されます。
生成
通常、ステートフル・リソースはリソース・ファクトリーによって生成されます。生成の呼び出しにより、エンドポイント・リファレンスは新しいステートフル・リソースに返されます。
消滅
ステートフル・リソースの破棄とシステム・リソースの回収に使用される方法を定義します。
リソース ID
ステートフル・リソースには、リソース ID が少なくとも 1 つ必要です。リソース ID はエンドポイント・リファレンスの一部として返され、分散システム内のその他の Web サービスで利用できます。
WS-Resource Properties
WS-Resource Properties は、WS-Resource の状態を Web サービス・インターフェース経由で操作できるように、その構造を定義します。それぞれのリソース・プロパティーは、リソースの状態の各コンポーネントに対応します。
WS-Resource のセキュリティー
セキュリティーは、Web サービスのセキュリティー・ロードマップの一部である WS-Policy 仕様と WS-SecurityPolicy 仕様に基づいて定義されます。これらの仕様は、クライアントと Web サービスの間のメッセージ交換を保護するためのポリシーの集合を明らかにしています。
実用的な WSRF サービス :大きな整数の素因数分解 (LIF)
最初に紹介する WSRF 対応 Web サービスに実装されているのは、2 次ふるい法によって大きな整数を素因数分解するアルゴリズムです。今日の通信におけるセキュリティー保護技術の大部分は、素数である大きな整数 (つまり 100 桁を超える素数) の素因数分解の困難さの上に成り立っているので、暗号研究者の間では、これは一般的な話題です。
Web サービス記述 (WSDL) ファイル
Web サービスとのインターフェースはいずれも、WSDL (Web サービス記述言語) で記述されています。WSDL では、Web サービスによって公開されるオペレーション、およびそのサービスへの到達に必要なネットワーク・エンドポイントを定義できます。この例で紹介するサービスでは、1 つの文字列を引き数として 1 つの文字列の結果を返す、「factor」という名前のオペレーションが公開されます。
リスト 2. 大きな整数の素因数分解の Web サービス記述ファイル
<?xml version="1.0" encoding="UTF-8"?>
<definitions name="LIF"
targetNamespace="http://lif.com"
xmlns:tns="http://lif.com"
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/03/addressing"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:gtwsdl="http://www.globus.org/namespaces/2004/01/GTWSDLExtensions"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:wsrlw=
"http://docs.oasis-open.org/wsrf/2004/06/
wsrf-WS-ResourceLifetime-1.2-draft-01.wsdl"
xmlns:wsrp=
"http://docs.oasis-open.org/wsrf/2004/06/
wsrf-WS-ResourceProperties-1.2-draft-01.xsd"
xmlns:wsrpw=
"http://docs.oasis-open.org/wsrf/2004/06/
wsrf-WS-ResourceProperties-1.2-draft-01.wsdl"
xmlns:wsntw=
"http://docs.oasis-open.org/wsn/2004/06/
wsn-WS-BaseNotification-1.2-draft-01.wsdl"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!-- LIF (Large Integer Factorization) Web Service description file -->
<wsdl:import
namespace=
"http://docs.oasis-open.org/wsrf/2004/06/
wsrf-WS-ResourceProperties-1.2-draft-01.wsdl"
location="../../../wsrf/properties/WS-ResourceProperties.wsdl" />
<wsdl:import
namespace=
"http://docs.oasis-open.org/wsrf/2004/06/
wsrf-WS-ResourceLifetime-1.2-draft-01.wsdl"
location="../../../wsrf/lifetime/WS-ResourceLifetime.wsdl" />
<wsdl:import
namespace=
"http://docs.oasis-open.org/wsn/2004/06/
wsn-WS-BaseNotification-1.2-draft-01.wsdl"
location="../../../wsrf/notification/WS-BaseN.wsdl" />
<types>
<xsd:schema targetNamespace="http://lif.com"
xmlns:tns="http://lif.com"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:import
namespace=
"http://schemas.xmlsoap.org/ws/2004/03/addressing"
schemaLocation="../../../ws/addressing/WS-Addressing.xsd"
/>
<xsd:element name="createLIF">
<xsd:complexType/>
</xsd:element>
<xsd:element name="createLIFResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="wsa:EndpointReference"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="factor" type="xsd:string"/>
<xsd:element name="factorResponse" type="xsd:string"/>
<xsd:element name="Value" type="xsd:int"/>
<xsd:element name="LIFRP">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="tns:Value"
minOccurs="1" maxOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</types>
<message name="CreateLIFRequest">
<part name="request" element="tns:createLIF"/>
</message>
<message name="CreateLIFResponse">
<part name="response" element="tns:createLIFResponse"/>
</message>
<!-- factor operation input/output arguments -->
<!-- Input is a string argument-->
<message name="FactorInputMessage">
<part name="parameters" element="tns:factor"/>
</message>
<!-- Output is a string value -->
<message name="FactorOutputMessage">
<part name="parameters" element="tns:factorResponse"/>
</message>
<portType name="LIFPortType"
gtwsdl:implements="wsntw:NotificationProducer
wsrlw:ImmediateResourceTermination
wsrlw:ScheduledResourceTermination"
wsrp:ResourceProperties ="tns:LIFRP">
<!-- Operation invoked when creating the web service -->
<operation name="createLIF">
<input message="tns:CreateLIFRequest"/>
<output message="tns:CreateLIFResponse"/>
</operation>
<!-- Factorization operation (factor) -->
<operation name="factor">
<input message="tns:FactorInputMessage"/>
<output message="tns:FactorOutputMessage"/>
</operation>
</portType>
</definitions>
|

 |
リソースの実装
WSRF サービス内のリソースを使用すると、クライアントと Web サービスの間のメッセージ交換を通じて、サービス呼び出しの前後で状態を維持できます。この例では、LIF (Large Integer Factors) という名前のリソースを使用して、素因数分解オペレーションの結果を格納しています。
リスト 3. WSRF ステートフル・リソースの実装例
/**
* Large Integer Factorization (LIF) WSRF Service
* Description: A WSRF Service for large integer factorization
*
* @author Vladimir Silva
*/
package org.globus.wsrf.samples.lif;
import java.util.Calendar;
import javax.xml.namespace.QName;
import org.globus.wsrf.ResourceIdentifier;
import org.globus.wsrf.ResourceProperties;
import org.globus.wsrf.ResourceProperty;
import org.globus.wsrf.ResourcePropertySet;
import org.globus.wsrf.Topic;
import org.globus.wsrf.TopicList;
import org.globus.wsrf.TopicListAccessor;
import org.globus.wsrf.ResourceLifetime;
import org.globus.wsrf.WSRFConstants;
import org.globus.wsrf.impl.ReflectionResourceProperty;
import org.globus.wsrf.impl.ResourcePropertyTopic;
import org.globus.wsrf.impl.SimpleResourcePropertySet;
import org.globus.wsrf.impl.SimpleTopicList;
import org.globus.wsrf.impl.SimpleTopic;
import org.globus.wsrf.impl.SimpleResourceProperty;
/**
* LIF Resource Implementation
* A LIF resource is used to save the value of a specific
* factorization
*/
public class LIF
implements
ResourceLifetime,
ResourceIdentifier,
ResourceProperties,
TopicListAccessor {
public static final QName KEY =
new QName("http://lif.com", "LIFKey");
public static final QName RP_SET =
new QName("http://lif.com", "LIF");
public static final QName VALUE =
new QName("http://lif.com", "Value");
private ResourcePropertySet propSet;
private TopicList topicList;
protected Calendar terminationTime = null;
protected Object key;
protected ResourceProperty value;
/**
* initialize Resource
* @param key
*/
protected void initialize(Object key) {
this.key = key;
this.propSet = new SimpleResourcePropertySet(RP_SET);
this.topicList = new SimpleTopicList(this);
ResourceProperty prop = null;
try {
this.value =
new ResourcePropertyTopic(
new SimpleResourceProperty(VALUE));
this.propSet.add(this.value);
this.topicList.addTopic( (Topic)this.value);
this.value.add(new String());
prop =
new ReflectionResourceProperty(
WSRFConstants.TERMINATION_TIME,
this);
this.propSet.add(prop);
this.topicList.addTopic(
new SimpleTopic(WSRFConstants.
TERMINATION_TOPIC));
prop =
new ReflectionResourceProperty(
WSRFConstants.CURRENT_TIME,
this);
this.propSet.add(prop);
}
catch (Exception e) {
throw new RuntimeException(e.getMessage());
}
}
public ResourcePropertySet getResourcePropertySet() {
return this.propSet;
}
public TopicList getTopicList() {
return this.topicList;
}
/*
* Methods to get or set the value of the resource
*/
public String getValue(int idx) {
return ( (String)this.value.get(idx));
}
public void setValue(String value) {
this.value.set(0, value);
}
/**
* Called when a new LIF resource is created.
*
* @return the resource key
*/
public Object create() throws Exception {
// just an example, might be a file already...
this.key = new Integer(hashCode());
initialize(key);
return key;
}
public Object getID() {
return this.key;
}
/* Service Lifetime Management methods
* (non-Javadoc)
* @see org.globus.wsrf.ResourceLifetime
#setTerminationTime(java.util.Calendar)
*/
public void setTerminationTime(Calendar time) {
this.terminationTime = time;
}
/*
* (non-Javadoc)
* @see org.globus.wsrf.ResourceLifetime
* #getTerminationTime()
*/
public Calendar getTerminationTime() {
return this.terminationTime;
}
public Calendar getCurrentTime() {
return Calendar.getInstance();
}
}
|

 |
サービスの実装
サービスの実装には、Web サービスによって外部に公開されるオペレーションも含まれます。この例では、以下の 2 種類のオペレーションが公開されています。
- createLIF:Web サービスのインスタンス生成時に起動します。主な機能は、リソース・キーで識別されるステートフル・リソースと、応答メッセージ内で返されるエンドポイント・リファレンスを生成することです。
- Factor:2 次ふるい法によって大きな整数を素因数分解する場合に使用されるオペレーションです。このオペレーションでは、ステートフル・リソースを使用して結果を格納します。
リスト 4. サービスの実装
package org.globus.wsrf.samples.lif;
import java.rmi.RemoteException;
import org.apache.axis.message.addressing.EndpointReferenceType;
import org.globus.wsrf.ResourceContext;
import org.globus.wsrf.ResourceKey;
import org.globus.wsrf.utils.AddressingUtils;
import com.lif._createLIF;
import com.lif._createLIFResponse;
import javax.math.factorization.Factorizer;
import java.math.BigInteger;
/**
* Large Integer Factorization (LIF) WSRF Service
* Description: A WSRF Service for large integer factorization
*
* Service Implementation
* @author Vladimir Silva
*/
public class LIFService {
ResourceKey key = null;
/**
* OPERATION1: Fires when the Web service is created.
* Creates a stateful resource (identified by a key)
* and endpoint reference (EPR) which is returned
* @param request
* @return Response object containing an endpoint reference (EPR)
* @throws RemoteException
*/
public _createLIFResponse createLIF(_createLIF request) throws
RemoteException {
ResourceContext ctx = null;
LIFHome home = null;
/*
* Create a Resource...
*/
try {
ctx = ResourceContext.getResourceContext();
home = (LIFHome) ctx.getResourceHome();
key = home.create();
}
catch (RemoteException e) {
throw e;
}
catch (Exception e) {
throw new RemoteException(", e);
}
/*
* Add an endpoint reference to the response
*/
EndpointReferenceType epr = null;
try {
epr = AddressingUtils.createEndpointReference(ctx, key);
}
catch (Exception e) {
throw new RemoteException(", e);
}
_createLIFResponse response = new _createLIFResponse();
response.setEndpointReference(epr);
return response;
}
/**
* OPERATION2: Find factors operation
* @param largeInteger Large prime/integer string to be factored
* @return Result of the form: f1^p1 * f2^p2 ... fn^pn
* @throws RemoteException
*/
public String factor(String largeInteger)
throws RemoteException
{
/*
* Retrieve resource
*/
Object resource = null;
try {
resource = ResourceContext.getResourceContext().
getResource();
}
catch (RemoteException e) {
throw e;
}
catch (Exception e) {
throw new RemoteException(", e);
}
LIF lif = (LIF) resource;
/*
* Use a quadratic sieve to find factors
*/
Factorizer f;
try {
// Factorize number, Timeout = 10 secs, verbose = false
f = new Factorizer(new BigInteger(largeInteger), 10, false);
f.factor();
}
catch (Exception ex) {
throw new RemoteException("Factorizer", ex);
}
// save factors within the LIF resource
lif.setValue(f.factorsAsString());
return f.factorsAsString();
}
}
|

 |
サービス・クライアント
実装プロセスの最終段階は、サービスの呼び出しに使用するサービス・クライアントを記述することです。Globus には、ロー・レベルの作業の大部分を取り扱える API が用意されています。サービスのオペレーションを呼び出すための必要手順は簡単です。
- 次のように、サービス・アドレス・ロケーターを取得します。
LIFServiceAddressingLocator locator = new LIFServiceAddressingLocator();
- 次のように、エンドポイント・リファレンス (EPR) と、目的の Web サービスオペレーションを呼び出すためのポートを取得します。
EndpointReferenceType endpoint = new EndpointReferenceType();
endpoint.setAddress(new Address("http://localhost:8080/wdrf/services/MyService"));
LIFPortType port = locator.getLIFPortTypePort(endpoint);
- 目的のオペレーションを呼び出します。例えば、次のようにすると、大きな整数の素因数分解 (LIF) のサービスのインスタンスが生成されます。
_createLIFResponse createResponse = port.createLIF(new _createLIF());
endpoint = createResponse.getEndpointReference();
完成したプロセスを、以下のサービス・クライアント・プログラムに示します。
リスト 6. Web サービス・クライアント・プログラム
package org.globus.wsrf.samples.lif.client;
/**
* <p>Title: LIF (Large Integer Factorization) WSRF Service</p>
* <p>Description: Large Integer Factorization service for GT4</p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @author Vladimir Silva
* @version 1.0
*/
import java.util.List;
import org.apache.axis.message.addressing.Address;
import org.apache.axis.message.addressing.EndpointReferenceType;
import org.globus.wsrf.NotificationConsumerManager;
import com.lif.LIFPortType;
import com.lif._createLIF;
import com.lif._createLIFResponse;
import com.lif.service.LIFServiceAddressingLocator;
import org.oasis.wsrf.lifetime._Destroy;
import javax.xml.rpc.Stub;
import org.globus.wsrf.impl.security.authentication.Constants;
import org.globus.wsrf.impl.security.authorization.SelfAuthorization;
import org.globus.wsrf.client.BaseClient;
import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.CommandLine;
/**
* Large Integer Factorization (LIF) WSRF Service
* Description: A WSRF Service for large integer factorization
*
* This class is used to create a resource which will be used
* to save the result of a given factorization
*
* @author Vladimir Silva
*/
public class FactorClient
extends BaseClient {
public static void main(String[] args) {
FactorClient client = new FactorClient();
// client takes 1 arg : large integer
client.setCustomUsage("{large integer}");
LIFServiceAddressingLocator locator =
new LIFServiceAddressingLocator();
// GSI Secure Conversation, signature,
// without delegation, self authz.
String CLIENT_DESC =
"org/globus/wsrf/samples/lif/client/client-security-config.xml";
NotificationConsumerManager consumer = null;
// large number to factor
String largeInt;
try {
// Parse arguments: 1 arg => large number
CommandLine line = client.parse(args);
List options = line.getArgList();
if (options == null || options.isEmpty()) {
throw new ParseException("Expected large integer argument");
}
// get number to factor from cmd line
largeInt = (String) options.get(0);
// Service URL
String servURL = line.getOptionValue("s");
if (servURL == null) {
servURL = "http://localhost:8080/wsrf/services/LIFService";
// Use security? (Use security if the Service URL contains
// Secure e.g SecureLIFService
}
boolean secure = (servURL.indexOf("Secure") > 0) ? true : false;
//System.out.println("LIF service URL: " + servURL +
//" Number:" + largeInt + " Secure:" + secure);
// STEP1: Obtain a SOAP endpoint reference (EPR)
// Contains the service URL and metadata
// such as resource properties)
EndpointReferenceType endpoint = new EndpointReferenceType();
endpoint.setAddress(new Address(servURL));
// STEP2: Obtain a Port (using the EPR) to create a
// web service instance
LIFPortType port = locator.getLIFPortTypePort(endpoint);
if (secure) {
( (Stub) port)._setProperty(
Constants.CLIENT_DESCRIPTOR_FILE,
CLIENT_DESC);
}
// Create lif (Large Integer factorizer) resource
// Returns the EPR of the new instance
_createLIFResponse createResponse =
port.createLIF(new _createLIF());
endpoint = createResponse.getEndpointReference();
// STEP3: Use the new EPR to obtain a second Port used to
// factor the number
LIFPortType factorPort = locator.getLIFPortTypePort(endpoint);
if (secure) {
// Secure message
( (Stub) factorPort)._setProperty(
Constants.GSI_SEC_MSG,
Constants.SIGNATURE);
( (Stub) factorPort)._setProperty(
Constants.AUTHORIZATION,
new SelfAuthorization());
}
// Show factorization result
System.out.println(largeInt + "=" +
factorPort.factor(largeInt));
// STEP3: Use the EPR to obtain a third port
// to destroy the service
LIFPortType destroyPort = locator.getLIFPortTypePort(endpoint);
if (secure) {
( (Stub) destroyPort)._setProperty(
Constants.CLIENT_DESCRIPTOR_FILE,
CLIENT_DESC);
}
// Destroy the lif resource
destroyPort.destroy(new _Destroy());
}
catch (Exception e) {
e.printStackTrace();
}
}
}
|

 |
セキュリティー対応
サービスにセキュリティー機能を組み入れる場合は、一連の手順とファイルが別途必要です。上の例の場合は、リソース・クラスのセキュリティー対応バージョンのサービスとサービス実装ファイルを記述しなければなりません。また、サービス用のセキュリティー設定 XML ファイルが要求されるほか、クライアント・プログラムをセキュリティー対応にする必要もあります。手順を簡略化するため、将来の作業ではセキュア・サービスについて検討する予定です。ただし、提供されるソース・コード(zipファイル)にはセキュリティー対応ファイルが含まれています。
構築と配備
Globus では、便利な ant スクリプトのセットを使用することにより、サービスのコンパイルと配備をあらかじめ簡略化しています。したがって、(適切なファイルが揃っている場合は) 次のコマンドを実行するだけで、サービスをパッケージ化して配備できます。
To deploy (within the project directory):
set GLOBUS_LOCATION=[WSRF_CONTAINER_LOCATION]
ant deploy
To un-deploy:
ant undeploy
ランタイム・テスト
サービスの配備に成功したら、図 3 に示すように、$GLOBUS_LOCATION/bin ディレクトリー内で「lif-client -s http://localhost:8080/wsrf/services/LIFService [number]」を実行してください。これにより、WSRF コンテナーが起動し、サービスが実行されます。
図 3. サービスのテスト
まとめ
次期バージョンの Globus Toolkit には、以前のプロトコルを継承しつつ、最新の Web サービス仕様が組み込まれる予定です。この記事の目的は、これらの新仕様の概要とグリッド・サービスの実用例をいち早く紹介することです。自組織のサービス実装に取り掛かる際は、この記事をぜひお役立てください。
ダウンロード | 内容 | ファイル名 | サイズ | ダウンロード形式 |
|---|
| Source code for this article | wsrf-source.zip | 500KB |
FTP |
|---|
参考文献
- この記事で使用されているソース・コード(zipファイル)をダウンロードしてください。
- WSRF の詳細情報は、OASIS Web Services Resource Framework Technical Committeeのページで取得してください。
また、OASIS Web Services Notificationも参照してください。
- 背景情報については、Foster、Frey、Graham、Tuecke、Czajkowski、Ferguson、Leyman、Nally の共著による仕様書「Modeling Stateful Resources with Web Services」を参照してください。 (著作権 : Copyright Computer Associates International, Inc., Fujitsu Limited, Hewlett-Packard Development Company, International Business Machines Corporation and The University of Chicago 2003, 2004.)
著者について  | |  | Vladimir Silvaはエクアドルのキトーの生まれです。1994年に陸軍工科学校でシステムアナリストの学位を取得し、同年交換留学生として、ミドルテネシー州立大学でコンピューターサイエンスの経験を積むべく渡米しました。卒業後は、IBMに入社し、Web-Ahead テクノロジーの研究機関に所属しました。グリッド・コンピューティング、ニューラル・ネット、人工知能に興味を持っており、OCPやMCSD、MCPなどを含め、数え切れない程の IT 認定証を持っています。 |
記事の評価
|