...

Feature Pack for OSGi Applications and JPA 2.0 (OSGi)

by user

on
Category: Documents
20

views

Report

Comments

Transcript

Feature Pack for OSGi Applications and JPA 2.0 (OSGi)
Feature Pack for OSGi and JPA 2.0
Feature Pack for
OSGi Applications and JPA 2.0
(OSGi)
WebSphere Application Server v7 Feature Pack Guide
Feature Pack for OSGi and JPA 2.0
Agenda
‰
WAS v7 FP for OSGi and JPA 2.0 概要
€
€
‰
OSGiアプリケーション概要
€
€
€
‰
€
€
OSGi アプリケーションの開発環境
OSGi アプリケーションの作成
OSGi アプリケーションのデプロイ
OSGi アプリケーション管理
€
€
€
‰
OSGiとは
OSGi エンタープライズ・アプリケーション
OSGi アプリケーションとJPA・SCA・トランザクション
OSGi アプリケーション開発
€
‰
Feature Pack 概要
Feature Pack 導入
バンドルのバージョン確認
バンドルのリポジトリー管理
バンドルの更新
参考文献
WebSphere Application Server v7 Feature Pack Guide
2
1
Feature Pack for OSGi and JPA 2.0
WAS v7 FP for OSGi and JPA 2.0 概要
3
WebSphere Application Server v7 Feature Pack Guide
Feature Pack for OSGi and JPA 2.0
Feature Pack 概要
‰
IBM WebSphere Application Server V7 Feature
Pack for OSGi Applications and Java Persistence
API (JPA) 2.0
€
€
€
WebアプリケーションとしてOSGiアプリケーションを動作させる環境を
Feature Packとして提供
JPA 2.0の新機能にも対応
2010年5月29日公開
WebSphere Application Server v7 Feature Pack Guide
4
2
Feature Pack for OSGi and JPA 2.0
特徴
OSGiとJava EE テクノロジーの統合
‰
€
€
€
€
簡素化されたコンポーネント・モデル
モジュール単位での柔軟な変更
OSGiの管理ツールによるモジュールのバージョン管理
Apache Commonsなど、OSSプロジェクトで配布されているJarファイルは、
OSGiバンドルとして利用可能なものも多く存在
JPA 2.0新機能の動作環境を提供
‰
€
€
€
€
€
€
€
悲観的ロックのサポート
キャッシュ仕様の追加
JPQL (Java Persistence Query Language) の強化
Bean Validation(JSR-303)のサポート
コレクションのサポート強化
組み込みオブジェクトのサポート強化
Criteria APIの追加
5
WebSphere Application Server v7 Feature Pack Guide
Feature Pack for OSGi and JPA 2.0
Feature Pack 導入
‰ 前提条件
€
€
WAS v7.0 Fix Pack 9 以上
Java SDK 1.6.0 SR7 Cumulative Fix for WAS v7.0 Fix Pack 9 以上
„
WAS v7.0 Fix Pack 9は以下からダウンロード可能
„
最新のWAS V7.0 Fix Packは以下で確認可能
z
z
http://www-01.ibm.com/support/docview.wss?uid=swg24025883
http://www-01.ibm.com/support/docview.wss?uid=swg27009661
WebSphere Application Server v7 Feature Pack Guide
6
3
Feature Pack for OSGi and JPA 2.0
導入手順 (1/4)
IBM Installation Managerの導入
1.
€
以下のサイトからダウンロード
„
http://www-01.ibm.com/support/docview.wss?rs=180&uid=swg24023498
IBM Installer Manager起動
2.
€
€
IBM WebSphere Application Server Feature Pack V7 for OSGi Applications and Java
Persistence API 2.0」を選択し「次へ」
iFix PM14743も同時に導入可能
7
WebSphere Application Server v7 Feature Pack Guide
Feature Pack for OSGi and JPA 2.0
導入手順 (2/4)
ロケーションの選択
3.
€
「既存のパッケージ・グループの使用」を選択し、「IBM WebSphere Application Server –
ND」を選択
インストールフィーチャーの選択
4.
€
「OSGi Applications」「Java Persistence API 2.0」 を選択
WebSphere Application Server v7 Feature Pack Guide
8
4
Feature Pack for OSGi and JPA 2.0
導入手順 (3/4)
要約の確認
5.
内容を確認し、「インストール」実行
€
導入完了を確認
6.
9
WebSphere Application Server v7 Feature Pack Guide
Feature Pack for OSGi and JPA 2.0
導入手順 (4/4)
プロファイルの作成
7.
OSGi Application Featureから
目的のプロファイルを作成
ND構成用に
「管理プロファイル」、
「カスタムプロファイル」、
「セル」も選択可能
既存プロファイルのOSGi対応も
可能
€
€
€
€
コマンドによるプロファイル作成例
„
既存プロファイルのOSGi対応は –createではなく、–augment オプションを使用
manageprofiles.sh -create -profileName <プロファイル名>
-profilePath <プロファイルパス> -templatePath <テンプレートパス(下記)>
-nodeName <ノード名> -cellName <セル名> -hostName <ホスト名>
€
OSGi用に新しくテンプレートが存在
„
ディレクトリーは <WAS_Install_Root>¥profileTemplates¥aries¥<用途>
cell.aries.fep (セル)
z default.aries.fep (アプリケーション・サーバー・プロファイル)
z managed.aries.fep (カスタム・プロファイル)
z management.aries.fep (管理プロファイル)
z
WebSphere Application Server v7 Feature Pack Guide
10
5
Feature Pack for OSGi and JPA 2.0
OSGi アプリケーション 概要
11
WebSphere Application Server v7 Feature Pack Guide
Feature Pack for OSGi and JPA 2.0
OSGiとは
‰
アプリケーションのライフサイクルの管理を行うための仕様
€
‰
JVMに対しダイナミックな追加削除を実行
JVM上でOSGiを実装したフレームワークが動作
€
€
OSGiフレームワーク上でアプリケーションが動作
代表的なOSGiフレームワーク
„
„
‰
Eclipse Equinox
Apache Felix Framework
OSGiではアプリケーションを「バンドル」と定義
€
€
バンドルをインストール・アンインストールすることで、モジュールの追加・削除を実施
バンドルは1つのJarファイル
Bundle
Bundle
インストール・アンインストールは
JVMに対しダイナミックに実施
Bundle
Bundle
OSGi Framework
Java VM
WebSphere Application Server v7 Feature Pack Guide
12
6
Feature Pack for OSGi and JPA 2.0
OSGiバンドル
‰
OSGiで扱うインストール、アンインストールの単位
‰
実体はマニフェストファイルを持ったJarファイル
€
‰
マニフェストファイル(MANIFEST.MF)にメタデータの記載がある以外は既存のJarファイルと同じ
マニフェストファイルにはバンドルのメタデータを記載
€
€
€
外部から参照するパッケージと、外部に公開するパッケージを記載
記載があることで、Bundle BはBundle Aのcom.ibm.hello内にあるクラスにアクセスが可能に
各バンドル間の依存関係を明確にするのが目的
Bundle A
Bundle B
com.ibm.helloをExport
com.ibm.helloをImport
Bundle AとBundle Bは依存関係がある
13
WebSphere Application Server v7 Feature Pack Guide
Feature Pack for OSGi and JPA 2.0
OSGiのクラス・ローダー実装
‰ 依存関係の実装仕様
€
€
バンドルごとにクラス・ローダーを生成
OSGiのフレームワークが、依存関係を元にバンドルのクラス・ローダーを結合
‰ 依存関係を明確にすることでバンドル間の独立性を高め、変更に
強いシステムを構築
Bundle A
バンドルA~Eと
バンドルF~Hには依存関係はないので、
各バンドル群で独立して扱える
Export
Import
Bundle B
Bundle C
Bundle D
Bundle F
Bundle G
Bundle E
Bundle H
WebSphere Application Server v7 Feature Pack Guide
14
7
Feature Pack for OSGi and JPA 2.0
OSGi採用の検討に当たって
‰
OSGiのメリット
€
導入時の実行性の保証
„
€
高い独立性
€
柔軟な変更
„
„
€
依存関係の明確性により、バンドル変更時の影響範囲が明確になり、テスト範囲も限定可能
アプリケーション全体を再導入しなくても、バンドルのみを容易に変更可能
バージョン管理
„
‰
マニフェストにより依存関係が明確に定義されているため、依存関係の不備はアプリケーションの実行前に
発見可能
アプリケーションで使用中のバンドルのバージョンが管理ツールから把握可能
OSGi開発において考慮すべき点
€
大きなプログラムを、一つの役割を持った、独立した小さなバンドルに分割
„
„
„
„
各バンドルの役割を明確に
バンドルのサイズはなるべく小さく
外部に公開するパッケージ、サービスは限定
外部への不要な参照は避ける
WebSphere Application Server v7 Feature Pack Guide
15
Feature Pack for OSGi and JPA 2.0
OSGiのレイヤー構造
‰ Moduleレイヤー
€
€
複数バージョンのバンドルを管理
バンドル間依存関係の解決
‰ Life
€
€
Cycleレイヤー
ライフサイクルにのっとったバンドルの実行を実現
動的ロードを実現
‰ Servicesレイヤー
€
バンドルをサービスとして公開するための
機能を提供
‰ Securityレイヤー
€
Java 2 Securityをベースに制約を追加
WebSphere Application Server v7 Feature Pack Guide
16
8
Feature Pack for OSGi and JPA 2.0
OSGiのライフサイクル
‰
ライフサイクルがバンドル単位で存在
€
‰
バンドル単位でインストール・アンインストールを実行することで、ダイナミックな変更を
実現
BundleActivator
€
€
ステータスが変更になる際に実行されるライフサイクル・メソッドを規定
BundleActivatorを実装することで、バンドルの起動停止時処理を実行
package com.ibm.jp.myapp;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
public class MyAppActivator implements BundleActivator {
public void start(BundleContext context) throws Exception { System.out.println(“Bundle starts.”); }
public void stop(BundleContext context) throws Exception { System.out.println(“Bundle stops.”); }
}
17
WebSphere Application Server v7 Feature Pack Guide
Feature Pack for OSGi and JPA 2.0
マニフェストファイル
‰
MANIFEST.MFとしてバンドル内に存在し、アプリケーションのメタデータを記載
€
Import-Package
„
€
€
外部から参照するパッケージとそのバージョン範囲
[1.2.0,1.3.0)は 1.2.0以上1.3.0未満を指す
Export-Package
Bundle-Activator
外部に公開するパッケージとそのバージョン
バンドルで用いられるActivatorクラス
Manifest-Version: 1.0
Bundle-SymbolicName: com.ibm.jp.myapp
Bundle-Name: My Application Bundle
Bundle-Vendor: IBM Japan
Bundle-Version: 2.0.0
Import-Package:
com.ibm.jp.mylib1.ui;version="[1.2.0,1.3.0)",
com.ibm.jp.mylib1.util;version="[1.2.0,1.3.0)"
Export-Package:
com.ibm.jp.myapp;version="2.0.0"
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-Activator: com.ibm.jp.myapp.MyAppActivator
‰
バンドルはOSGi Framework実装が管理するリポジトリーに登録され、
その管理下で実行
WebSphere Application Server v7 Feature Pack Guide
18
9
Feature Pack for OSGi and JPA 2.0
OSGi エンタープライズ・アプリケーション仕様
‰ OSGiをJavaエンタープライズ・アプリケーションとして使用
€
OSGi R4 version 4.2 にて定義
‰ Blueprint
€
€
コンポーネント・モデルを採用
Spring Frameworkをベースとし、DIを用いたOSGi エンタープライズ・アプリ
ケーションの構築モデル
BlueprintのXML構成ファイルにて定義
„
„
„
各コンポーネントのバンドル内での接続
OSGi サービス・レジストリーへのサービスの公開
各コンポーネントの依存関係のインジェクション
19
WebSphere Application Server v7 Feature Pack Guide
Feature Pack for OSGi and JPA 2.0
Blueprint コンポーネント・モデル
‰ 各バンドルの処理をサービスとして公開
€
€
€
他のOSGi上のバンドルからサービスを利用
サービスは自由に作成・登録が可能
標準で様々なサービスが定義済み
‰ Blueprint
€
コンテナー
XML構成ファイルの定義に基づいて、コンテナーが依存性をインジェクション
dependencies injected
publishes
service
consumes
service
Blueprint managed bundle
Blueprint managed bundle
Blueprint Components(POJO)
WebSphere Application Server v7 Feature Pack Guide
20
10
Feature Pack for OSGi and JPA 2.0
サービスの登録と呼び出し
サービスの登録
‰
€
OSGiフレームワークの提供するAPIを利用して登録
BundleContext.registerService
(SampleService.class.getName(),new SampleServiceImpl(),null);
€
Blueprint コンポーネント・モデルでは、BlueprintのXML構成ファイルにサービスを登録するこ
とも可能
<service interface="com.ibm.ws.eba.example.blog.api.BloggingService"/>
サービスの呼び出し
‰
€
OSGiフレームワークの提供するAPIを利用して呼び出し
ServiceRefernce sr =
BundleContext.getServiceReference(SampleService.class.getName());
SampleService service = (SampleService)BundleContext.getService(sr);
€
Blueprint コンポーネント・モデルを利用すると、JNDIルックアップを利用した動的な呼び出し
も可能
InitialContext ic = new InitialContext();
(BloggingService)ic.lookup("osgi:service/"+BloggingService.class.getName());
21
WebSphere Application Server v7 Feature Pack Guide
Feature Pack for OSGi and JPA 2.0
Blueprint XML構成ファイル
‰
blueprint.xml
€
€
OSGi-INF/blueprint ディレクトリ下に存在
バンドルが公開しているサービスや外部への参照先、バンドル内のBeanを定義
„
„
„
<reference>
<bean>
<service>
外部への参照先
定義されているBean
外部に公開しているサービス
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0"
default-activation="lazy">
<bean id= "blogAuthorManager"
class="com.ibm.ws.eba.example.blog.BlogAuthorManagerImpl">
<property name="persistenceService" ref="persistenceManager"/>
</bean>
<reference id="persistenceManager"
interface="com.ibm.ws.eba.example.blog.persistence.api.BlogPersistenceService"/>
<bean id="bloggingServiceComponent"
class="com.ibm.ws.eba.example.blog.BloggingServiceImpl">
<property name="blogAuthorManager" ref="blogAuthorManager"/>
</bean>
<service ref="bloggingServiceComponent"
interface="com.ibm.ws.eba.example.blog.api.BloggingService"/>
</blueprint>
WebSphere Application Server v7 Feature Pack Guide
22
11
Feature Pack for OSGi and JPA 2.0
OSGiを適用したWebアプリケーション
‰
Enterprise Bundle Application
(.eba)
€
€
バンドルを扱うための
エンタープライズ・アプリケーション
WASで扱うインストールの単位
„
€
‰
通常のマニフェストファイルに加え、
2つの固有マニフェストファイルを保持
OSGi Bundle(.jar)
€
€
‰
バンドル単位ではなく、
依存性をもったバンドルの集合体として
インストール
拡張子はJar
マニフェストファイルを保持
Enterprise Application
(.ear)
ライブラリ
(.Jar)
Web App
Module (.war)
Enterprise Bundle App
(.eba)
OSGi Bundle
(.jar)
Web App
Bundle (.wab)
Web Application Bundle(.wab)
€
€
バンドルに対応
Web構成ファイルの他に、
マニフェストファイルを保持
23
WebSphere Application Server v7 Feature Pack Guide
Feature Pack for OSGi and JPA 2.0
アプリケーション・マニフェスト
‰
ebaファイルは、MANIFEST.MF以外に2つのマニフェストファイルを保持
‰
アプリケーション・マニフェスト
€
META-INF/APPLICATION.MFとして、ebaファイル内にデプロイ前に存在
€
アプリケーションに含まれるバンドル、外部から用いる共用バンドルの定義などを記述
„
„
Application-Content アプリケーション内部に存在するバンドルとデプロイ可能なバージョンの範囲
Use-Bundle アプリケーションが使用する外部のバンドルとデプロイ可能なバージョンの範囲
Manifest-Version: 1.0
Application-ManifestVersion: 1.0
Application-Name: Aries Blog
Application-SymbolicName: com.ibm.ws.eba.example.blog.app
Application-Version: 1.0
Application-Content: com.ibm.ws.eba.example.blog.api;version=1.0.0,
com.ibm.ws.eba.example.blog.persistence;version=1.0.0,
com.ibm.ws.eba.example.blog.web;version=1.0.0,
com.ibm.ws.eba.example.blog;version=1.0.0
Use-Bundle: com.ibm.json.java;version="[1.0.0,2.0.0)"
WebSphere Application Server v7 Feature Pack Guide
24
12
Feature Pack for OSGi and JPA 2.0
デプロイメント・マニフェスト
デプロイメント・マニフェスト
‰
€
€
META-INF/DEPLOYMENT.MFに配置
アプリケーションを構成し、特定されたバージョンのバンドルを全て列挙
Deployed-Content 実際にデプロイされたバンドルとそのバージョン
DeployedService-Import Deployed-Contentで指定されたバンドルをデプロイする際に実際にイン
ポートされたオブジェクト
Import-Package Deployed-Use-Bundleで指定されたバンドルから実際に使われたパッケージのリスト
Deployed-Use-Bundle 実際にデプロイされたアプリ外部のバンドルとそのバージョン
„
„
„
„
Manifest-Version: 1.0
Application-SymbolicName: com.ibm.ws.eba.example.blog.app
Application-Version: 1.0.0
Deployed-Content: com.ibm.ws.eba.example.blog.web;deployed-version=1.0
.0,com.ibm.ws.eba.example.blog.persistence;deployed-version=1.0.0,com
.ibm.ws.eba.example.blog;deployed-version=1.0.0,com.ibm.ws.eba.exampl
e.blog.api;deployed-version=1.0.0
DeployedService-Import: (&(objectClass=com.ibm.ws.eba.example.blog.com
ment.persistence.api.BlogCommentService)(objectClass=com.ibm.ws.eba.e
xample.blog.comment.persistence.api.BlogCommentService))
Import-Package: com.ibm.json.java;version="1.0.0";bundle-symbolic-name
="com.ibm.json.java";bundle-version="[1.0.0,1.0.0]",javax.persistence
;version="1.0.0"
Deployed-Use-Bundle: com.ibm.json.java;deployed-version=1.0.0
25
WebSphere Application Server v7 Feature Pack Guide
Feature Pack for OSGi and JPA 2.0
アプリケーション・デプロイ時のマニフェストの検査
アプリケーション・マニフェストとデプロイメント・マニフェストの内容は
デプロイ時に検査
‰
€
€
デプロイメント・マニフェストがアプリケーション・マニフェストに対して検査され、
情報が一致するとインストールが続行
検査項目
„
„
„
€
デプロイメント・マニフェストの Application-SymbolicName および Application-Version
が、アプリケーション・マニフェストの対応するエントリーに一致すること
デプロイメント・マニフェスト内の Deployed-Content ヘッダーのバンドル・リストが、アプリケー
ション・マニフェスト内の Application-Content ヘッダーのバンドル・リストと同じであり、対応
するバンドルのバージョン範囲内になっていること
デプロイメント・マニフェストの Deployed-Use-Bundle ヘッダーにリストされているすべてのバ
ンドルが、アプリケーション・マニフェストの Use-Bundle ヘッダーのバンドル・リストにあり、対応
するバンドルのバージョン範囲内になっていること
(Use-Bundle ヘッダーにリストされているバンドルが Deployed-Use-Bundle ヘッダーにリス
トされているバンドルよりも多くても構わない)
アプリケーション内にデプロイメント・マニフェストが存在しない場合は、デプロ
イ時に自動生成
WebSphere Application Server v7 Feature Pack Guide
26
13
Feature Pack for OSGi and JPA 2.0
OSGi セキュリティー
ポリシーファイル
‰
€
€
€
OSGI-INF/permissions.perm に配置
Java エンタープライズ・アプリケーションでJava 2 セキュリティーの使用と同様、OSGi
アプリケーションでもpermissions.permファイルを用いてセキュリティー制御が可能
各バンドルに対する許可を制御
„
„
„
org.osgi.framework.PackagePermission
バンドル内のパッケージに対するインポート権限(Import or exportonly)を指定
org.osgi.framework.ServicePermission
バンドル内のサービスに対する登録権限(get or register)を指定
java.util.PropertyPermission
プロパティーに対するアクセス権(read or write)を指定
( org.osgi.framework.PackagePermission "*" "exportonly" )
( org.osgi.framework.ServicePermission "*" "get,register" )
( java.util.PropertyPermission "java.naming.factory.url.pkgs"
"read" )
27
WebSphere Application Server v7 Feature Pack Guide
Feature Pack for OSGi and JPA 2.0
OSGi アプリケーションとJPA (1/3)
パーシスタント・バンドル
‰
€
€
1つ以上のパーシスタント記述子を含むバンドル
META-INF/MANIFEST.MFにMeta-Persistence ヘッダーがあり、使用さ
れるパーシスタント記述子の位置を記載
„
デフォルト値のMETA-INF/persistence.xmlのみであれば空白でも良い
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.7.0
Created-By: 2.3 (IBM Corporation)
Bundle-ManifestVersion: 2
Bundle-Name: Persistence Plug-in
Bundle-SymbolicName: com.ibm.ws.eba.example.blog.persistence
Bundle-Version: 1.0.0
Bundle-Vendor: IBM
Bundle-ActivationPolicy: lazy
Meta-Persistence: META-INF/persistence.xml (デフォルトであれば空でもよい)
Import-Package:
com.ibm.ws.eba.example.blog.persistence.api;version="[
1.0.0,1.1.0)",javax.persistence;version="1.0.0"
WebSphere Application Server v7 Feature Pack Guide
28
14
Feature Pack for OSGi and JPA 2.0
OSGi アプリケーションとJPA (2/3)
JPAのパーシスタント記述子
‰
€
€
€
デフォルトではMETA-INF/persistence.xml
フィーチャー・パックではJPA 2.0にも対応
内容はJava エンタープライズ・アプリケーションと同じ
<persistence version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="MyPersistenceUnit" transaction-type="JTA">
<provider>com.ibm.websphere.persistence.Persistence
ProviderImpl</provider>
<jta-data-source>jdbc/employ</jta-data-source>
<class>com.ibm.ws.eba.jpa.entity.EmployeeImpl</class>
<properties>
<property name='openjpa.ConnectionDriverName'
value='com.ibm.db2.jcc.DB2Driver' />
</properties>
</persistence-unit>
</persistence>
29
WebSphere Application Server v7 Feature Pack Guide
Feature Pack for OSGi and JPA 2.0
OSGi アプリケーションとJPA (3/3)
‰ Blueprintを利用したリソース参照
€
blueprint.xmlでリソース参照を定義
<blueprint xmlns:rr="http://www.ibm.com/appserver/schemas/8.0/
blueprint/resourcereference">
<rr:resource-reference interface="javax.sql.DataSource"
id="employds" filter="(osgi.jndi.service.name=jdbc/employ)">
<rr:res-auth>Container</rr:res-auth>
<rr:res-sharing-scope>Shareable</rr:res-sharing-scope>
</rr:resource-reference>
€
定義されたIDを用いてデータソースにアクセスも可能
<jta-data-source>blueprint:comp/employds</jta-data-source>
€
デプロイ時に認証エイリアスと結合
WebSphere Application Server v7 Feature Pack Guide
30
15
Feature Pack for OSGi and JPA 2.0
OSGi アプリケーションとSCA
OSGiアプリケーションをSCAコンポーネントとして定義することが
可能
‰
€
アプリケーション・マニフェストの変更
„
€
Blueprint XML 構成ファイルの変更
„
€
Application-ExportService ヘッダーを追加
公開するserviceの追加
SCAコンポジット定義の変更
„
„
implementation.osgiapp コンポーネント・タイプを指定
Blueprint XML 構成ファイルで定義されたサービスを定義
31
WebSphere Application Server v7 Feature Pack Guide
Feature Pack for OSGi and JPA 2.0
OSGiアプリケーションとトランザクション (1/2)
コンポーネント・レベルでのトランザクションの定義
‰
€
€
€
Java エンタープライズ・アプリケーションでのトランザクションと記載の方法は
同様
Blueprint XML構成ファイル内に記載
Bean内のメソッドに対し、トランザクション属性を定義
<blueprint
xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:tx="http://aries.apache.org/xmlns/transactions/v1.0.0"
default-activation="lazy">
<bean id="persistenceImpl"
class="com.ibm.ws.eba.example.blog.persistence.BlogPersistenceServiceImpl">
<tx:transaction method="*" value="Required"/>
</bean>
<service ref="persistenceImpl"
interface="com.ibm.ws.eba.example.blog.persistence.api.BlogPersistenceService">
</service>
</blueprint>
WebSphere Application Server v7 Feature Pack Guide
32
16
Feature Pack for OSGi and JPA 2.0
OSGiアプリケーションとトランザクション (2/2)
サービス・レベルでのトランザクションの指定
‰
€
€
OSGiのインテント・プロパティー service.exported.intentsの値で指定
コンポーネント・レベルでのトランザクション定義とは整合している必要
„
propagatesTransaction
z
z
„
suspendsTransaction
z
z
€
トランザクションが提供されると、そのトランザクションを使用
コンポーネント定義ではRequire、Mandatory、Supportsに対応
トランザクションが提供されても、そのトランザクションは使用しない
コンポーネント定義ではRequiresNew、NotSupported、Neverに対応
Blueprint XML構成ファイル内のプロパティーと値で指定
<service ref="componentImplementation"
interface="com.xyz.MyTransactionalServiceInterface">
<service-properties>
<entry key="service.exported.intents" value="propagatesTransaction"/>
</service-properties>
</service>
33
WebSphere Application Server v7 Feature Pack Guide
Feature Pack for OSGi and JPA 2.0
複合バンドル・アーカイブ
‰
Composite Bundle Archive (.cba)
€
€
‰
バンドルの集合体
複数のバンドルを1セットとしてまとめ、動作を整合させたい場合に作成
複合マニフェストファイル
€
CBAファイルは、META-INF/COMPOSITEBUNDLE.MF を保持
„
„
CompositeBundle-Content
複合バンドル・アーカイブに含まれるバンドル
CompositeBundle-ExportService
複合バンドル・アーカイブとして公開するサービス
Manifest-Version: 1.0
CompositeBundle-ManifestVersion: 1
Bundle-Name: Blog Application
Bundle-SymbolicName: com.ibm.ws.osgi.example.Blog
Bundle-Version: 1.0
CompositeBundle-Content:
com.ibm.ws.osgi.example.blog;version="[1.0,1.0]",
com.ibm.ws.osgi.example.blog.persistence;version="[1.0,1.0]"
Import-Package: com.ibm.ws.other.pkge;version=1.0.0
Export-Package: com.ibm.ws.osgi.example.blog;version=1.0.0
CompositeBundle-ExportService:
com.ibm.ws.osgi.example.blog.BloggingService;
filter="(blog.type=community)"
CompositeBundle-ImportService:
com.ibm.ws.osgi.example.auth.UserAuthService
WebSphere Application Server v7 Feature Pack Guide
34
17
Feature Pack for OSGi and JPA 2.0
OSGi アプリケーション 開発
35
WebSphere Application Server v7 Feature Pack Guide
Feature Pack for OSGi and JPA 2.0
OSGi アプリケーションの開発環境
Eclipse Helios v3.6 Eclipse IDE for Java EE Developers
package
‰
€
developerWorksで提供されているOSGiアプリケーション開発ツールの動
作環境
„
„
„
€
IBM Rational Development Tools for OSGi Applications Version 0.6
http://www.ibm.com/developerworks/rational/downloads/10/rationaldevtoolsforos
giapplications.html
Java version 5 以上が前提
Eclipse Helios v3.6 導入後に、上記開発ツールを導入して使用
IBM Rational Application Developer for WebSphere
Software Version 8.0.0
‰
€
OSGi開発ツールも導入可能
„
デフォルトでは選択されないので、導入時に選択する必要
WebSphere Application Server v7 Feature Pack Guide
36
18
Feature Pack for OSGi and JPA 2.0
OSGiアプリケーション開発ツールの導入手順(1/4)
1.
Eclipse Helios V3.6にOSGiアプリケーション開発ツールを導入する際の手順
Eclipseを起動し、[Help]→[Install New Software]を選択
2.
インストールのダイアログボックスから「Add」
‰
37
WebSphere Application Server v7 Feature Pack Guide
Feature Pack for OSGi and JPA 2.0
OSGiアプリケーション開発ツールの導入手順(2/4)
3.
Add Repositoryの画面から、
名前に[ IBM Rational Development Tools
for OSGi Applications Version 0.6 ]、
ロケーションに
[ http://public.dhe.ibm.com/ibmdl/export/pub/s
oftware/rational/OSGiAppTools ]を入力し「OK」
4.
リストの中から
「OSGi Application Development」を選び「Next」
WebSphere Application Server v7 Feature Pack Guide
38
19
Feature Pack for OSGi and JPA 2.0
OSGiアプリケーション開発ツールの導入手順(3/4)
5.
「Install Detail」の画面では
そのまま「Next」
6.
ライセンスに同意し「Finish」
39
WebSphere Application Server v7 Feature Pack Guide
Feature Pack for OSGi and JPA 2.0
OSGiアプリケーション開発ツールの導入手順(4/4)
7.
「Software Updates」の画面になったら、
「Restart Now」をクリックし、Eclipseを再起動
8.
再起動後、プロジェクトを作成すると、
「OSGi」としてアプリケーション・プロジェクト、
バンドル・プロジェクト、
コンポジット・バンドル・プロジェクトが
作成可能になっていることを確認
WebSphere Application Server v7 Feature Pack Guide
40
20
Feature Pack for OSGi and JPA 2.0
RAD v8.0 の導入
‰ RAD
€
v8.0でもOSGi開発ツールは使用可能
デフォルトではOSGi開発ツールは選択されていないので、フィーチャーの選択
画面時で「OSGi開発ツール」を選択する必要
WebSphere Application Server v7 Feature Pack Guide
41
Feature Pack for OSGi and JPA 2.0
OSGi アプリケーションの作成
開発の流れ
‰
1.
サービス・バンドルの作成
„
例: パーシスタントバンドルの作成
z
z
z
z
z
z
2.
クライアント・バンドルの作成
„
例: Webクライアントバンドルの作成
z
z
z
3.
OSGiバンドル・プロジェクトの作成
MANIFEST.MFの設定
HTMLファイル、サーブレット、JSPファイルの作成
OSGi アプリケーション(EBAファイル)の作成
„
„
4.
OSGi バンドル・プロジェクトの作成
MANIFEST.MFの設定
エンティティ・マネージャー・クラスを作成
エンティティ・クラスを作成
パーシスタント構成ファイルの設定
blueprint.xmlファイルの設定
OSGi アプリケーション・プロジェクトの作成
アプリケーションをEBAとしてエクスポート
アプリケーションのデプロイ
WebSphere Application Server v7 Feature Pack Guide
42
21
Feature Pack for OSGi and JPA 2.0
作成に使用したアプリケーション (1/2)
p.45-58の作成例では、以下のアプリケーションの作成を想定
‰
€
com.ibm.ws.eba.jpa.helloJPAService.app
以下の3つのバンドルを含むエンタープライズ・アプリケーション・バンドル
index.htmlにアクセスし、入力したemployidに相当する1行分のデータを画面表示するアプ
リケーション
„
„
€
com.ibm.ws.eba.jpa.helloJPAService
パーシスタント・バンドル
エンティティ・マネージャー・クラス HelloJPAServiceImpl
„
„
z
z
€
employeeIdをキーとして、エンティティクラスに対し検索処理を実行
エンティティ・クラス EntityImpl
„
データベースEMPLOYのEMPLOYEEテーブルにアクセス
com.ibm.ws.eba.jpa.hello.api
パーシスタント・バンドル内のクラスのインターフェイスを含むバンドル
HelloJPAServiceImplのインターフェイスHelloJPAService、EntityImplのインターフェイス
Entityが存在
„
„
43
WebSphere Application Server v7 Feature Pack Guide
Feature Pack for OSGi and JPA 2.0
作成に使用したアプリケーション (2/2)
€
com.ibm.ws.eba.jpa.helloJPAClient
„
„
Webアプリケーション・バンドル
HTMLファイル index.html
z
„
z
z
„
employidに相当する1行分のデータを表示
クラス JNDIHelper
z
€
JNDIクラスによりサービスを取得し、employidに対し検索処理を実行
実行結果をJSPに
JSP output.jsp
z
„
employidを入力させ、サーブレットに処理を移管
サーブレット JPAServlet
JNDIルックアップにより、helloJPAServiceバンドルで指定されたサービスにアクセス
EMPLOYデータベース
„
„
EMPLOYEEテーブルを保有
固有キーとしてEMPLOYEEIDをもち、他にDEPARTMENT_NAME、
EMPLOYEE_NAME、MONTHLY_SALARYをカラムとして保有
WebSphere Application Server v7 Feature Pack Guide
44
22
Feature Pack for OSGi and JPA 2.0
サービス・バンドルの作成(1/6)
‰
OSGiバンドル・プロジェクトの作成
€
€
€
€
ファイル → 新規 → プロジェクトから
OSGi→OSGiバンドルプロジェクト
を選択
「プロジェクト名」を入力
パーシスタント・バンドルであれば、
Configurationを「OSGi JPA
Configuration」を選択
アプリケーション・プロジェクトを入力
すると、同時にアプリケーション・プロ
ジェクトが作成
45
WebSphere Application Server v7 Feature Pack Guide
Feature Pack for OSGi and JPA 2.0
サービス・バンドルの作成(2/6)
MANIFEST.MFの設定
‰
€
作成したバンドルに対し、インポート・エクスポートするパッケージを指定
„
€
例では、com.ibm.ws.eba.jpa.apiの1.0.0以上、1.1.0未満をインポートする宣言を追加
persistence.xmlが複数ある場合、デフォルトと異なる位置・名前の場合、
Meta-Persistenceに内容を記載
Manifest-Version: 1.0
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-Name: com.ibm.ws.eba.helloJPAService
Meta-Persistence:
Bundle-Blueprint: OSGI-INF/blueprint/*.xml
Bundle-SymbolicName: com.ibm.ws.eba.jpa.helloJPAService
Bundle-Version: 1.0.0
Import-Package: com.ibm.ws.eba.jpa.api;version="[1.0.0,1.1.0)",
javax.persistence;resolution:=optional
Bundle-ManifestVersion: 2
WebSphere Application Server v7 Feature Pack Guide
46
23
Feature Pack for OSGi and JPA 2.0
サービス・バンドルの作成(3/6)
エンティティ・マネージャー・クラスの作成
‰
€
€
例では、@PersistenceContext アノテーションを利用し、永続化ユニット・
MyPersitenceUnitのエンティティ・マネージャーをインジェクション
employeeIdをキーとしてオブジェクトを取得
package com.ibm.ws.eba.jpa;
import
import
import
import
import
com.ibm.ws.eba.jpa.api.HelloJPAService;
javax.persistence.EntityManager;
javax.persistence.PersistenceContext;
com.ibm.ws.eba.jpa.api.Employee;
com.ibm.ws.eba.jpa.entity.EmployeeImpl;
public class HelloJPAServiceImpl implements HelloJPAService {
@PersistenceContext(unitName="MyPersistenceUnit")
private EntityManager em;
@Override
public Employee findEmployeeByPrimaryKey(int employeeId) {
Employee employee = em.find(EmployeeImpl.class, employeeId);
return employee;
}
}
47
WebSphere Application Server v7 Feature Pack Guide
Feature Pack for OSGi and JPA 2.0
サービス・バンドルの作成(4/6)
‰
エンティティ・クラスの作成
€
DBがすでに作成されているのであれば、JPAバンドルを選択し、右クリック→「JPA
Tools」→「Generate Entity from Tables」で自動作成も可能
スキーマとテーブルを選択すると、
カラムが表示される
WebSphere Application Server v7 Feature Pack Guide
48
24
Feature Pack for OSGi and JPA 2.0
サービス・バンドルの作成(5/6)
パーシスタント構成ファイルの設定
‰
€
永続化ユニット名、プロバイダー、エンティティクラス、データソース、接続プロパティーを
設定
„
例では、それぞれ以下に設定
z
z
z
z
z
永続化ユニット名 MyPersistenceUnit
プロバイダー com.ibm.websphere.persistence.PersistenceProviderImpl
エンティティクラス com.ibm.ws.eba.jpa.entity.EmployeeImpl
データソース jdbc/employ (JTAトランザクション)
接続プロパティー 属性openjpa.ConnectionDriverNameの値にcom.ibm.db2.jcc.DB2Driver
<persistence version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="MyPersistenceUnit" transaction-type="JTA">
<provider>com.ibm.websphere.persistence.Persistence
ProviderImpl</provider>
<jta-data-source>jdbc/employ</jta-data-source>
<class>com.ibm.ws.eba.jpa.entity.EmployeeImpl</class>
<properties>
<property name='openjpa.ConnectionDriverName'
value='com.ibm.db2.jcc.DB2Driver' />
</properties>
</persistence-unit>
</persistence>
49
WebSphere Application Server v7 Feature Pack Guide
Feature Pack for OSGi and JPA 2.0
サービス・バンドルの作成(6/6)
blueprint.xmlファイルの設定
‰
€
€
€
ファイル→新規→Othersを選択し、OSGiのblueprint Fileを選択すると作成可能
デフォルトでOSGI-INF/blueprintディレクトリー下に作成
バンドル内のBean、サービス名、インターフェイスを設定
„
„
例では、サービスとして、 com.ibm.ws.eba.jpa.api.HelloJPAServiceをインターフェイスを公開し、
com.ibm.ws.eba.jpa.HelloJPAServiceImplによって実装
トランザクションは「Required」
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:tx="http://aries.apache.org/xmlns/transactions/v1.0.0"
default-activation="lazy">
<bean id="persistenceImpl" class="com.ibm.ws.eba.jpa.HelloJPAServiceImpl">
<tx:transaction method="*" value="Required"/>
</bean>
<service ref="persistenceImpl" interface="com.ibm.ws.eba.jpa.api.HelloJPAService">
</service>
</blueprint>
WebSphere Application Server v7 Feature Pack Guide
50
25
Feature Pack for OSGi and JPA 2.0
クライアント・バンドルの作成(1/6)
‰
OSGiバンドル・プロジェクトの作成
€
€
€
€
ファイル → 新規 → プロジェクトから
OSGi→OSGiバンドル
プロジェクトを選択
「プロジェクト名」を入力
Webアプリケーション・
バンドルであれば
「OSGi Web Configuration」を
選択
Application membershipに
既存のプロジェクトを
選択すると、バンドルが
アプリケーションの中に
取り込まれる
51
WebSphere Application Server v7 Feature Pack Guide
Feature Pack for OSGi and JPA 2.0
クライアント・バンドルの作成(2/6)
‰ MANIFEST.MFの設定
€
作成したバンドルに対し、インポート・エクスポートするパッケージを指定
„
例では、com.ibm.ws.eba.jpa.apiの1.0.0以上、1.1.0未満をインポートする宣言を追加
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: com.ibm.ws.eba.jpa.helloJPAClient
Bundle-SymbolicName: com.ibm.ws.eba.jpa.helloJPAClient
Bundle-Version: 1.0.0
Bundle-ClassPath: WEB-INF/classes
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Web-ContextPath: /helloJPA
Import-Package: com.ibm.ws.eba.jpa.api;version="[1.0.0,1.1.0)",
javax.el;version="2.0";resolution:=optional,
javax.servlet;version="2.5",
javax.servlet.http;version="2.5",
javax.servlet.jsp;version="2.0",
javax.servlet.jsp.el;version="2.0",
javax.servlet.jsp.tagext;version="2.0"
WebSphere Application Server v7 Feature Pack Guide
52
26
Feature Pack for OSGi and JPA 2.0
クライアント・バンドルの作成(3/6)
‰
HTMLファイル、サーブレット、JSPファイルの作成
€
必要に応じてファイルを作成
€
HTMLファイルの例
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-31j">
<title>JPA Application by OSGi</title>
</head>
<body>
<H2><FONT color="royalblue">JPA Application by OSGi</FONT></H2>
<hr color=blue>
<form method="post" name="rowform" action="/helloJPA/JPAServlet">
<p>番号を入力 : <input type="text" name="id" value="1" size="5">
<input type="submit" value="表示" name="submit"></p>
</form>
</body>
</html>
53
WebSphere Application Server v7 Feature Pack Guide
Feature Pack for OSGi and JPA 2.0
クライアント・バンドルの作成(4/6)
€
サーブレットの例
package com.ibm.ws.eba.jpa.web;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import com.ibm.ws.eba.jpa.api.Employee;
import com.ibm.ws.eba.jpa.api.HelloJPAService;
import com.ibm.ws.eba.jpa.web.util.JNDIHelper;
public class JPAServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("Shift_JIS");
String num = request.getParameter("id");
int id=1;
if (num!=null){
id=Integer.parseInt(num);
}
HelloJPAService service = JNDIHelper.getJPAService();
Employee employee = service.findEmployeeByPrimaryKey(id);
request.setAttribute("employee", employee);
this.getServletContext().getRequestDispatcher("/output.jsp").forward(request,
response);
}
}
WebSphere Application Server v7 Feature Pack Guide
54
27
Feature Pack for OSGi and JPA 2.0
クライアント・バンドルの作成(5/6)
€
JSPの例
<%@ page language="java" contentType="text/html; charset=windows-31j"
pageEncoding="windows-31j"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-31j">
<title>JPA Application by OSGi</title></head>
<body>
<jsp:useBean id="employee" type="com.ibm.ws.eba.jpa.api.Employee"
scope="request"></jsp:useBean>
<h2><font color="#4169E1">JPA Application</font></h2>
<hr>
<table border="1" width="70%" BGCOLOR="#FFFFEE">
<tr BGCOLOR="#DDDDFF">
<th>EMPLOYEE_ID</th><th>EMPLOYEE_NAME</th>
<th>DEPARTMENT_NAME</th><th>MONTHLY_SALARY</th>
</tr>
<tr>
<td><%=employee.getEmployeeId()%></td><td><%=employee.getEmployeeName()%></td>
<td><%=employee.getDepartmentName()%></td><td><%=employee.getMonthlySalary()%></td>
</tr>
</TABLE>
</body></html>
55
WebSphere Application Server v7 Feature Pack Guide
Feature Pack for OSGi and JPA 2.0
クライアント・バンドルの作成(6/6)
€
JNDIHelperクラス
„
サービスに指定された、 com.ibm.ws.eba.jpa.api.HelloJPAServiceインターフェイスに
JDNIルックアップを用いてアクセス
package com.ibm.ws.eba.jpa.web.util;
import java.io.IOException;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import com.ibm.ws.eba.jpa.api.HelloJPAService;
public class JNDIHelper {
public static final HelloJPAService getJPAService() throws IOException {
try {
InitialContext ic = new InitialContext();
return (HelloJPAService) ic.lookup("osgi:service/"+
HelloJPAService.class.getName());
} catch (NamingException e) {
e.printStackTrace();
IOException ioe = new IOException("Blogging service resolution failed");
ioe.initCause(e);
throw ioe;
}
}
}
WebSphere Application Server v7 Feature Pack Guide
56
28
Feature Pack for OSGi and JPA 2.0
OSGi アプリケーション(EBAファイル)の作成
‰
OSGi アプリケーション・プロジェクトの作成
€
€
€
€
ファイル → 新規 → プロジェクトから OSGi → OSGi アプリケーション・プロジェクトを選択
「プロジェクト名」を入力
アプリケーションに
取り込むバンドルを選択
OSGi バンドル・プロジェクト作成時に
同時に作成することも可能
WebSphere Application Server v7 Feature Pack Guide
57
Feature Pack for OSGi and JPA 2.0
OSGi アプリケーションのエクスポート
‰
「ファイル」→「エクスポート」より
OSGi Application(EBA)を選択
‰
プロジェクト名・出力先・アプリケー
ションに含めるバンドルを指定
WebSphere Application Server v7 Feature Pack Guide
58
29
Feature Pack for OSGi and JPA 2.0
OSGi アプリケーションのデプロイ
‰ ビジネス・レベル・アプリケーション・フレームワークを使用して、EBA
ファイルをインストール
€
€
EBAファイルは1つのアセットにのみにインポート可能
EBAを含むアセットは1つのビジネス・レベル・アプリケーションのみに追加可能
‰ ビジネス・レベル・アプリケーション(BLA)
€
€
複数コンポーネントをひとつの
ビジネス・アプリケーションとして
関連付ける新しい管理モデル
コンポジション・ユニット
„
€
BLAを作成し、
登録したアセットを取りこみ
BLAにアセットを定義する際の構成情報
BLA
Enterprise
Application
Enterprise
Bundle
Library
EAR
EBA
Java
Library
アセット
„
ビジネス・ロジックを実装した
実際のバイナリー・ファイル
アセットにEBAファイルを登録
59
WebSphere Application Server v7 Feature Pack Guide
Feature Pack for OSGi and JPA 2.0
OSGi アプリケーションのデプロイ手順(1/6)
1.
EBAファイルをアセットとしてインポート
„
管理コンソールの[アプリケーション]→[アプリケーション・タイプ]→[アセット]より[インポート]
„
アセットにインポートする
EBAファイルを入力
WebSphere Application Server v7 Feature Pack Guide
60
30
Feature Pack for OSGi and JPA 2.0
OSGi アプリケーションのデプロイ手順(2/6)
„
アセットのインポートについてのオプション画面
z
z
アセットの説明
インストール先
○
z
z
○
z
„
デフォルトはinstalledEBAs/アセット名
ファイルのアクセス権
他のアセットとの関連
インポートしているアセットが
実行する必要のあるアセットを追加
アセットの妥当性検証の有無
「要約」画面の後、インポートが実行
61
WebSphere Application Server v7 Feature Pack Guide
Feature Pack for OSGi and JPA 2.0
OSGi アプリケーションのデプロイ手順(3/6)
2.
ビジネス・レベル・アプリケーションの新規作成
„
管理コンソールの[アプリケーション]→[アプリケーション・タイプ]→[ビジネス・レベル・アプリケー
ション]より[新規作成]
„
ビジネス・レベル・アプリケーション名を入力
WebSphere Application Server v7 Feature Pack Guide
62
31
Feature Pack for OSGi and JPA 2.0
OSGi アプリケーションのデプロイ手順(4/6)
3.
ビジネス・レベル・アプリケーションにアセットを追加
„
ビジネス・レベル・アプリケーションを選択、[デプロイ済みアセット]より[追加]→[アセットの追加]
„
導入したアセットを選択し、[続行]
63
WebSphere Application Server v7 Feature Pack Guide
Feature Pack for OSGi and JPA 2.0
OSGi アプリケーションのデプロイ手順(5/6)
„
オプションの設定
„
導入先サーバーの指定
WebSphere Application Server v7 Feature Pack Guide
64
32
Feature Pack for OSGi and JPA 2.0
OSGi アプリケーションのデプロイ手順(6/6)
„
コンテキストルートへのマップ
„
仮想ホストへのマップ
„
要約画面の後、ビジネス・レベル・アプリケーションに追加される
65
WebSphere Application Server v7 Feature Pack Guide
Feature Pack for OSGi and JPA 2.0
wsadminを用いたOSGi アプリケーションの導入
AdminTaskコマンドを使用
‰
1.
EBAファイルをアセットとしてインポート
AdminTask.importAsset('-source
C:¥testeba¥com.ibm.ws.eba.helloJPAService.app_1.0.0.eba')
2.
ビジネス・レベル・アプリケーションの新規作成
AdminTask.createEmptyBLA('-name HelloWorldJPA')
3.
ビジネス・レベル・アプリケーションにアセットを追加
AdminTask.addCompUnit('[-blaID "WebSphere:blaname=HelloWorldJPA"
-cuSourceIDWebSphere:assetname=com.ibm.ws.eba.helloJPAService.app_1.0.0 ]')
4.
変更を保管
AdminConfig.save()
WebSphere Application Server v7 Feature Pack Guide
66
33
Feature Pack for OSGi and JPA 2.0
既存のWebアプリケーションからOSGi アプリケーションへの対応
既存のJava エンタープライズ・アプリケーションをOSGiアプリケー
ションに対応させることも可能
‰
1.
2.
‰
‰
EAR ファイル(.ear)の名前をEBA ファイル(.eba)に変更
WAS上で、EBAファイルをアセットとしてインポートし、EBAに登録
ただし、この手順により、自動的にバンドル対応に変換されるの
はEARファイルとWebモジュールのみ
JARファイルやEJB JARファイルはバンドル対応されないため、再
作成が必要
67
WebSphere Application Server v7 Feature Pack Guide
Feature Pack for OSGi and JPA 2.0
OSGi アプリケーション 管理
WebSphere Application Server v7 Feature Pack Guide
68
34
Feature Pack for OSGi and JPA 2.0
バンドルのバージョンの確認 (1/2)
‰
‰
OSGi アプリケーションが使用するバンドルの配置
€
EBAアセット内のバンドルからの読み取り
€
レポジトリーに登録されている共有バンドルからの読み取り
バンドル・バージョンの確認は管理コンソールから確認可能
€
EBAアセット内のバンドル・バージョン確認
„
[アプリケーション]→[アプリケーション・タイプ]→[アセット]→アセット選択→[このアプリケーションにおけるバンド
ル・バージョンの更新]
EBAアセット内に含まれるバンドルの
名前とデプロイ済みのバージョンが表示
アセット外に登録済みの共有バンドルを
使用している場合、
そのバンドル、バージョンも表示
69
WebSphere Application Server v7 Feature Pack Guide
Feature Pack for OSGi and JPA 2.0
バンドルのバージョンの確認 (2/2)
‰ EBAアセット外にバンドルを登録し、共有ライブラリーとしてバンドル
を使用することも可能
€
リポジトリーに登録されているバンドル・バージョンの確認
„
[環境]→[OSGi bundle repository]→[内部・外部 bundle repository]
WebSphere Application Server v7 Feature Pack Guide
70
35
Feature Pack for OSGi and JPA 2.0
バンドルのリポジトリー管理
‰
OSGi アプリケーションは、使用するバンドルをアプリケーション内に含めなくても、
アプリケーション外に登録された共通バンドルからバンドルを使用することも可能
‰
共有バンドルはリポジトリーに登録
‰
内部バンドル・リポジトリー
€
€
‰
WASがもつバンドル・リポジトリー
WASが管理している範囲内で用いられる共有バンドルを登録
外部バンドル・リポジトリー
€
€
WAS外部に登録されているバンドル・リポジトリーへのリンクを追加
名前とURLを登録してWAS外部から共有バンドルを取得
71
WebSphere Application Server v7 Feature Pack Guide
Feature Pack for OSGi and JPA 2.0
内部バンドル・リポジトリーへの登録
‰
登録するJarファイルを指定
€
‰
[環境]→[OSGi bundle repository]→[内部 bundle repository]→[新規作成]
wsadminを利用した登録
AdminTask.addLocalRepositoryBundle('-file
C:/repositoryfiles/com.ibm.ws.eba.example.blog.persistence_1.1.0.jar/')
WebSphere Application Server v7 Feature Pack Guide
72
36
Feature Pack for OSGi and JPA 2.0
外部バンドル・リポジトリーへの登録
‰
名前とURLを指定
€
‰
[環境]→[OSGi bundle repository]→[外部 bundle repository]→[新規作成]
wsadminを利用した登録
AdminTask.addExternalBundleRepository('-name bundle_repository_name
-url http://external_location/repository.xml
[-description bundle_repository_description]')
73
WebSphere Application Server v7 Feature Pack Guide
Feature Pack for OSGi and JPA 2.0
バンドルの更新 (1/4)
1.
バンドルの変更は、EBAアセット内のバンドルを変更しなくても、新規バージョンのアセッ
トをリポジトリーに登録することで変更することが可能
内部バンドル・レポジトリーに
新規バージョンの
バンドルを登録
2.
EBAアセット内のバンドル・バージョン確認画面へ移動
‰
WebSphere Application Server v7 Feature Pack Guide
74
37
Feature Pack for OSGi and JPA 2.0
バンドルの更新 (2/4)
3.
バンドル一覧の新規バージョンから「1.1.0」を選択し「プレビュー」
WebSphere Application Server v7 Feature Pack Guide
75
Feature Pack for OSGi and JPA 2.0
バンドルの更新 (3/4)
4.
変更前と変更後の
バージョン一覧が
表示されるので
「コミット」
5.
変更を保存
デプロイ済みバージョンが
変更されることを確認
6.
WebSphere Application Server v7 Feature Pack Guide
76
38
Feature Pack for OSGi and JPA 2.0
バンドルの更新 (4/4)
wsadminを利用したバンドルの更新
‰
AdminTask.editAsset('[ -assetID com.ibm.ws.example.blog.eba
-UpdateAppContentVersionsStep [[com.ibm.ws.example.blog.persistence 1.0.0 1.1.0 ]]]')
assetIDオプションでアセット名を指定
UpdateAppContentVersionsStepオプションは、バンドル名、現在のバン
ドル・バージョン、新規のバンドル・バージョンの順で引数を指定
€
€
77
WebSphere Application Server v7 Feature Pack Guide
Feature Pack for OSGi and JPA 2.0
バンドルのコマンド行コンソール (1/2)
‰
osgiApplicationConsole コマンド
€
€
‰
<WAS_install_root>/feature_packs/aries/binに存在
OSGi アプリケーションのバンドルのデバッグ用ツールとして使用
サーバーに接続
€
€
osgiApplicationConsole -h ホスト名 –o SOAPポート番号
接続後はプロンプトがwsadminに変更
>osgiApplicationConsole.bat -h localhost -o 8886
‰
OSGiアプリケーションの一覧表示
€
ID、アプリケーション、バージョン、ノード名、サーバー名が表示
wsadmin>list()
ID Framework
0 SharedBundles
1 com.ibm.ws.eba.example.blabber.app
2 com.ibm.ws.eba.example.blog.app
3 com.ibm.ws.eba.helloJPAService.app
4 com.ibm.ws.eba.helloWorld
Version Node
7.0.0 OsgiNode04
1.0.0 OsgiNode04
1.0.0 OsgiNode04
1.0.0 OsgiNode04
1.0.0 OsgiNode04
WebSphere Application Server v7 Feature Pack Guide
Server
server1
server1
server1
server1
server1
78
39
Feature Pack for OSGi and JPA 2.0
バンドルのコマンド行コンソール (2/2)
OSGi アプリケーションに接続
‰
€
connectコマンドの引数にはIDを指定
wsadmin>connect(3)
CWSAJ0035I: ノード OsgiSeleneNode04 およびサーバー server1 のフレームワーク
com.ibm.ws.eba.helloJPAService.app_1.0.0 へ接続中です。
CWSAJ0036I: フレームワーク com.ibm.ws.eba.helloJPAService.app_1.0.0 への接続が成功しました。
バンドルの情報確認
‰
€
OSGi アプリケーションが用いているバンドルが表示
wsadmin>ss()
ID
State
Bundle
0
ACTIVE
org.eclipse.osgi_3.5.2.R35x_v20100126
1
ACTIVE
com.ibm.ws.eba.helloJPAService.app_1.0.0
2
ACTIVE
com.ibm.ws.eba.jpa.helloJPAService_1.0.0
3
ACTIVE
com.ibm.ws.eba.jpa.helloJPAClient_1.0.0
4
ACTIVE
com.ibm.ws.eba.jpa.api_1.0.0
バンドルに対する作業の実施
‰
€
€
作業には引数としてIDを使用
バンドル情報の表示
wsadmin>bundle(3)
€
バンドルの起動停止
wsadmin>start(4)
wsadmin>stop(2)
79
WebSphere Application Server v7 Feature Pack Guide
Feature Pack for OSGi and JPA 2.0
参考文献
‰
OSGi Alliance
€
OSGi Alliance Main
„
‰
OverView
€
OSGi Service Platform Release 4 Version 4.2
„
‰
Index
„
Feature Pack for OSGi Applications and JPA 2.0
„
http://publib.boulder.ibm.com/infocenter/wasinfo/v7r0/index.jsp?topic=/com.ibm.websphere.jpafep.multiplatform.doc/info/ae/ae/welcom
e_fepjpa.html
developerWorks
€
Developing enterprise OSGi applications for WebSphere Application Server
€
Best practices for developing and working with OSGi applications
€
Convert a JPA-based Java EE Web application to OSGi with Blueprint object injection in
WebSphere Application Server V7
„
„
„
‰
http://incubator.apache.org/aries/
WAS v7 Information Center
€
‰
http://www.osgi.org/javadoc/r4v42/index.html?overview-summary.html
Apache Aries
€
‰
http://www.osgi.org/Main/HomePage
http://www.ibm.com/developerworks/websphere/techjournal/1007_robinson/1007_robinson.html?ca=drshttp://www.ibm.com/developerworks/websphere/techjournal/1007_charters/1007_charters.html?ca=drs-
http://www.ibm.com/developerworks/websphere/techjournal/1008_gaffney/1008_gaffney.html?ca=drs-
WebSphere Application Server 技術文書一覧
€
エンタープライズOSGi入門: 第1回:OSGi概要と実行環境の導入
„
http://www.ibm.com/developerworks/jp/websphere/library/was/was7_fep_osgi/1.html
WebSphere Application Server v7 Feature Pack Guide
80
40
Fly UP