プログラミングによるモジュールの準備および更新

既存のアプリケーションのモジュールの更新は、管理コンソール、 wsadmin ツール、またはプログラミングによって行うことができます。モジュールを更新すると、 既存のモジュールが新規バージョンで置き換えられます。この例を使用し、プログラミングによってモジュールを更新します。

始める前に

このタスクでは、MBean プログラミングに関する基本的な知識があることが前提になっています。MBean プログラミングについて詳しくは、MBean Java™ アプリケーション・プログラミング・インターフェース (API) に関する文書を参照してください。このインフォメーション・センターでは、「参照」 > 「Mbean インターフェース (Mbean interfaces)」をクリックします。

WebSphere® Application Server 上でモジュールを更新する前に、まずアプリケーションをインストールする必要があります。

このタスクについて

以下のタスクを実行し、プログラミングによってモジュールを更新します。

手順

  1. アプリケーション・デプロイメント・コントローラー・インスタンスを作成して、バインディング情報を Java アーカイブ・ファイルに取り込みます。
  2. モジュールにバインディング情報を保管します。
  3. インストール・オプションを取得します。
  4. 準備フェーズ (EAR ファイルへのデータ取り込み) が実行されない場合は、以下のアクションを実行します。
    1. updateApplication MBean API に渡されるオプション・テーブルを作成します。
    2. サーバー関係に対してモジュールのテーブルを作成し、そのテーブルをオプション・テーブルに追加します。
  5. WebSphere Application Server に接続します。
  6. アプリケーション管理プロキシーを作成します。
  7. 通知フィルターを作成します。
  8. リスナーを追加します。
  9. アプリケーション内のモジュールを置き換えます。
  10. 新規モジュールのターゲットを指定します。
  11. プログラムが終了しないように、タイムアウトまで待ちます。
  12. Java Management Extensions (JMX) 通知を listen し、操作の完了を認識します。
  13. モジュールが追加されたら、リスナーを除去して終了します。

タスクの結果

コードが正常に実行されると、既存のモジュールが新規モジュールに置き換えられます。

以下の例には、前のステップに基づいた、アプリケーションへのモジュールの追加方法が示されています。 一部のステートメントは印刷目的のために複数行に分割されています。

//Inputs:
//moduleName specifies the name of the module that you add to the application.
//moduleURI specifies a URI that gives the target location of the module 
// archive contents on a file system. The URI provides the location of the new
// module after installation. この URI は、アプリケーションの URL について相対です。
//uniquemoduleURI specfies the URI that gives the target location of the
// deployment descriptor file. この URI は、アプリケーションの URL について相対です。
//target specifies the cell, node, and server on which the module is installed.
//appName specifies the name of the application to update.
[Windows]
String moduleName = "C:¥apps¥foo.jar";
[Linux][HP-UX][Solaris][AIX][z/OS][IBM i]
String moduleName = "/apps/foo.jar";
String moduleURI = "Increment.jar";
String uniquemoduleURI = "Increment.jar+META-INF/ejb-jar.xml";
String target = "WebSphere:cell=cellname,node=nodename,server=servername";
String appName = "MyApp";

//Get the administrative client to connect to
//WebSphere Application Server.
AdminClient client = ...;
AppManagement proxy = AppManagementProxy.getJMXProxyForClient (client);

Vector tasks = proxy.getApplicationInfo (appName, new Hashtable(), null);

//Create an application deployment controller instance, AppDeploymentController,
//to populate the Java archive (JAR) file with binding information.  
//The binding information is WebSphere Application Server-specific deployment information.

Hashtable preferences = new Hashtable();
preferences.put (AppConstants.APPDEPL_LOCALE, Locale.getDefault());
preferences.put (AppConstants.APPUPDATE_CONTENTTYPE, AppConstants.APPUPDATE_CONTENT_MODULEFILE);
// When a module is update, there are three possible merge actions: 
// AppConstants.APPREDEPL_DEFAULT_MERGE (the default merge action),
//   This option specifies during the update action, the binding information from
//   the new version of the EAR file or module is preferred
//   over the corresponding binding information from the old version. If any element
//   of binding is missing in the new version, the corresponding
//   element from the old version is used.
// AppConstants.APPREDEPL_IGNORE_OLDBND,
//   This option specifies that during the update action, the binding information
//   from the new version of the module is preferred over
//   the corresponding binding information from the old version. The bindings from
//   the old version of the application or module are ignored.
// AppConstants.APPREDEPL_IGNORE_NEWBND
//   This option specifies that during the update action, binding information from
//   the old version of the module is preferred over
//   the corresponding binding information from the new version. If any element of
//   the binding does not exist in the old version,
//   the element from the new version is used.
//
// To find the matching configuration object to perform the merge action, the values
// of the read only fields of the task for the new module are compared
// with the values of the read only fields of the task from the existing module.
// If all the read only values match, then the appropriate merge action is
// performed.
preferences.put (AppConstants.APPREDEPL_IGNORE_NEWBND, Boolean.TRUE);
AppDeploymentController controller = AppManagementFactory.readArchiveForUpdate(
				moduleName, 
				moduleURI, 
				AppConstants.APPUPDATE_UPDATE,
				preferences, 
								tasks);

アプリケーション用に更新するモジュールにバインディングがない場合は、 バインディングを追加することによって、モジュールの更新が機能します。本製品 で提供されているパブリック API を使用して、バインディングを収集および追加します。 WebSphere Application Server 固有のバインディング情報を収集してタスクに取り込む方法について詳しくは、AppDeploymentController インスタンスに関する Java の文書を参照してください。AppDeploymentController インスタンスには、入力モジュール内の Java クラスに定義されているアノテーションとともに、XML ベースのデプロイメント記述子に定義されているメタデータが含まれています。

//After you collect all the binding information, save it in the module.
controller.saveAndClose();

//Create the notification filter.
  NotificationFilterSupport myFilter = new NotificationFilterSupport();
  myFilter.enableType (NotificationConstants.TYPE_APPMANAGEMENT);
  //Add the listener.
  NotificationListener listener = new AListener(_soapClient, myFilter,
"Install: " + appName, AppNotification.UPDATE);

//Get the installation options.
Hashtable options = controller. getAppDeploymentSavedResults();

//Update the existing application by adding the module.

options.put (AppConstants.APPUPDATE_CONTENTTYPE, 
			AppConstants. APPUPDATE_CONTENT_MODULEFILE);

//Specify the target for the new module
Hashtable mod2svr = new Hashtable();
options.put (AppConstants.APPDEPL_MODULE_TO_SERVER, mod2svr);
mod2svr.put (uniquemoduleURI, target);

proxy.updateApplication (	appName,
				moduleURI, 
				moduleName,
				AppConstants.APPUPDATE_UPDATE,
				options,
				null);
// Wait. The installation application programming interface (API) is 
//  asynchronous and so returns immediately.
// If the program does not wait here, the program ends.
  Thread.sleep(300000); // Wait so that the program does not end.
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }
}
// Specify the Java Management Extensions (JMX) notification listener for JMX events.
class AListener implements NotificationListener
{
    AdminClient _soapClient;
    NotificationFilterSupport  myFilter;
    Object handback;
    ObjectName on;
    String eventTypeToCheck;

    public AListener(AdminClient cl, NotificationFilterSupport fl,
Object h, String eType) throws Exception
    {
        _soapClient = cl;
        myFilter = fl;
        handback = h;
        eventTypeToCheck = eType;

        Iterator iter = _soapClient.queryNames (new ObjectName(
"WebSphere:type=AppManagement,*"), null).iterator();
        on = (ObjectName)iter.next();
        System.out.println ("ObjectName: " + on);
        _soapClient.addNotificationListener (on, this, myFilter, handback);
    }

    public void handleNotification (Notification notf, Object handback)
    {
            AppNotification ev = (AppNotification) notf.getUserData();
            System.out.println ("!! JMX event Recd: (handback obj= " + handback+ "): " + ev);

            //When the installation is done, remove the listener and quit

            if (ev.taskName.equals (eventTypeToCheck) &&
                (ev.taskStatus.equals (AppNotification.STATUS_COMPLETED) ||
                 ev.taskStatus.equals (AppNotification.STATUS_FAILED)))
            {
                    try
                    {
                            _soapClient.removeNotificationListener (on, this);
                    }
            catch (Throwable th)
                    {
                        System.out.println ("Error removing listener: " + th);
                    }
                    System.exit (0);
        }
    }
}

トピックのタイプを示すアイコン タスク・トピック



タイム・スタンプ・アイコン 最終更新: last_date
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-nd-mp&topic=tjmx_update_module
ファイル名:tjmx_update_module.html