Red Hat Training

A Red Hat training course is available for Red Hat JBoss Operations Network

10.2. リソースプロキシーの使用

JBoss ON CLI は、リソースオブジェクトを処理するリモート API を介して JBoss ON サーバーと直接対話し、検索などのタスクのドメイン API を介して直接対話します。
JBoss ON CLI 自体は、一般的な操作を実行しやすい別の API レイヤーを提供します。CLI は CLI で リソースプロキシーオブジェクトを 作成し、オブジェクトが利用可能なクラスを使用できます。 ProxyFactory リモートおよびドメイン API と対話する。
注意することが、プロキシーリソースがリモートおよびドメイン API を引き続き使用していることです。プロキシー API は、多くの操作をスクリプト作成しやすい リモートおよびドメイン API 上 に単純で明確な API を提供します。
注記
The ProxyFactory は、対話モードで JBoss ON CLI を使用するか、スクリプトファイルを使用する場合に使用できます。これは、アラートに使用されるスクリプトなど、サーバースクリプトでも利用できます。
The ProxyFactory のリソースに関する情報を取得します。 getResource() リソースの ID 番号を指定する方法。
最も簡単なものProxyFactory 現在の監視データや特性、リソース名、利用可能なメトリック、利用可能な操作、コンテンツ情報、子インベントリーなど、指定されたリソースに関する完全なサマリーを返します。すべてのリソースはリソースタイプに依存します。例:
rhqadmin@localhost:7080$ ProxyFactory.getResource(10001)
ResourceClientProxy_$$_javassist_0:
                               OSName: Linux
                            OSVersion: 2.6.32-220.4.1.el6.x86_64
                         architecture: x86_64
                             children:
                         contentTypes: {rpm=RPM File}
                          createdDate: Mon Feb 06 11:24:50 EST 2012
                          description: Linux Operating System
                     distributionName: Red Hat Enterprise Linux Server
                  distributionVersion: release 6.2 (Santiago)
                           freeMemory: 16.7GB
                        freeSwapSpace: 25.6GB
                              handler:
                             hostname: server.example.com
                                   id: 10001
                                 idle: 70.8%
                         measurements: [Wait Load, Used Memory, System Load, Distribution Version, Total Memory, OS Name, Free Memory, Hostname, Architecture, Distribution Name, Idle, Total Swap Space, Used Swap Space, User Load, OS Version, Free Swap Space]
                         modifiedDate: Mon Feb 06 11:24:50 EST 2012
                                 name: server.example.com
                           operations: [viewProcessList, cleanYumMetadataCache, manualAutodiscovery]
                  pluginConfiguration:
        pluginConfigurationDefinition: ConfigurationDefinition[xml:id=10009, name=Linux]
                         resourceType: Linux
                           systemLoad: 0.0%
                          totalMemory: 23.5GB
                       totalSwapSpace: 25.6GB
                           usedMemory: 6.8GB
                        usedSwapSpace: 0.0B
                             userLoad: 15.8%
                              version: Linux 2.6.32-220.4.1.el6.x86_64
                             waitLoad: 0.0%
リソースを完全に管理するには、 ProxyFactory リソースプロキシーオブジェクトを作成します。

例10.3 プラットフォームプロキシーリソースの定義

var rhelServerOne = ProxyFactory.getResource(10001)
リソースプロキシーで使用できる方法は、リソースタイプとリソース自体の設定によって異なります。リソースプロキシーで実行できる主な操作には 5 つのタイプがあります。
  • リソースの基本情報(子など)の表示
  • 測定情報の取得
  • 操作の実行
  • リソースおよびプラグイン設定の変更
  • コンテンツの更新および取得
各リソースタイプについて、メソッドが公開され、リソースに関する特定の情報を見つけ、使用できます。さらに、プロキシー API には、監視情報の取得などの一般的なリモート API タスクを実行するためにパラメーターを使用せずに 1 つのキーワードメソッドを提供する「shortcuts」が含まれています。
一般的なリソースタイプのプロキシー API はに記載されてい 「プロキシーリソースに使用できる方法」 ます。
ヒント
インタラクティブ CLI でタブ補完を使用して、リソースタイプに使用できる特定の方法を検索するか、個別のメソッドのメソッド署名を取得します。

例10.4 リソースの表示

ProxyFactory すべてのプロキシーオブジェクトにメソッドがあります。。プロキシーリソースの子をすべて表示します。
var rhelServerOne = ProxyFactory.getResource(10001)

rhqadmin@localhost:7080$ platform.children
Array of org.rhq.bindings.client.ResourceClientProxy
[10027] Bundle Handler - Ant (Ant Bundle Handler::AntBundlePlugin)
[10026] CPU 6 (CPU::Platforms)
[10025] CPU 0 (CPU::Platforms)
[10024] CPU 5 (CPU::Platforms)
[10023] CPU 1 (CPU::Platforms)
[10022] CPU 4 (CPU::Platforms)
[10021] CPU 2 (CPU::Platforms)
[10020] CPU 3 (CPU::Platforms)
[10019] CPU 7 (CPU::Platforms)
[10018] /boot (File System::Platforms)
[10017] / (File System::Platforms)
[10016] /dev/shm (File System::Platforms)
[10015] /home (File System::Platforms)
[10014] eth1 (Network Adapter::Platforms)
[10013] eth2 (Network Adapter::Platforms)
[10012] eth0 (Network Adapter::Platforms)
[10011] lo (Network Adapter::Platforms)
[10004] postgres (Postgres Server::Postgres)
[10003] AS server.example.com RHQ Server (JBossAS Server::JBossAS)
[10002] RHQ Agent (RHQ Agent::RHQAgent)

例10.5 リソースメトリクスの表示

ProxyFactory リソースタイプの個別の測定に対して、ショートカットメトリックのセットを提供します。これは、 findLiveData() リモート API のメソッドは、簡単にモニタリング情報を取得でき、利用可能なメトリクスを特定する方が簡単です。
単一の測定値を取得するには、そのリソースタイプに方法を使用します。(タブ補完を使用してプロキシーオブジェクトのすべてのメソッド一覧を取得します。)
var jbossas = ProxyFactory.getResource(14832)
	
rhqadmin@localhost:7080$ jbossas.JVMTotalMemory
Measurement:
                name: JVM Total Memory
        displayValue: 995.3MB
	description: The total amount of memory currently available in the app server JVM for current and fut...
アイコンは、を使用して現在の値を持つメトリクスの一覧を取得するだけです。 measurements 方法:
var rhelServerOne = ProxyFactory.getResource(10001)

rhqadmin@localhost:7080$ rhelServerOne.measurements
Array of org.rhq.bindings.client.ResourceClientProxy$Measurement
name                 displayValue                         description
-----------------------------------------------------------------------------------------------------------------------
Wait Load            0.0%                                 Percentage of all CPUs waiting on I/O
Used Memory          6.3GB                                The total used system memory
System Load          0.0%                                 Percentage of all CPUs running in system mode
Distribution Version release 6.2 (Santiago)               version of the Linux distribution
Total Memory         31.4GB                               The total system memory
OS Name              Linux                                Name that the operating system is known as
Free Memory          25.2GB                               The total free system memory
Hostname             server.example.com                   Name that this platform is known as
Architecture         x86_64                               Hardware architecture of the platform
Distribution Name    Red Hat Enterprise Linux Server      name of the Linux distribution
Idle                 92.6%                                Idle percentage of all CPUs
Total Swap Space     33.6GB                               The total system swap
Used Swap Space      0.0B                                 The total used system swap
User Load            16.7%                                Percentage of all CPUs running in user mode
OS Version           2.6.32-220.4.2.el6.x86_64            Version of the operating system
Free Swap Space      33.6GB                               The total free system swap
16 rows

例10.6 プロキシーでの操作の実行

ProxyFactory リソースで利用可能なすべての操作には、ショートカットメソッドがあります。
まず、operations メソッドを使用して、リソース種別で利用可能な操作のリストを取得します。
var rhelServerOne = ProxyFactory.getResource(10001)

rhqadmin@localhost:7080$ rhelServerOne.operations
Array of org.rhq.bindings.client.ResourceClientProxy$Operation
name                  description
-----------------------------------------------------------------------------------------------------------------------
viewProcessList       View running processes on this system
cleanYumMetadataCache Deletes all cached package metadata
manualAutodiscovery   Run an immediate discovery to search for resources
3 rows
次に、指定の操作メソッドを実行します。
rhqadmin@localhost:7080$ rhelServerOne.viewProcessList();
Invoking operation viewProcessList
Configuration [11951] - null
  processList [305] {
pid   name                                        size       userTime kernelTime
------------------------------------------------------------------------------------------------------------------
1     init                                        19865600   150      10050
....
26285 httpd                                       214618112  90       80
26286 httpd                                       214618112  90       80
26288 httpd                                       214618112  110      70
26289 httpd                                       214618112  90       80
27357 java                                        4734758912 1289650  373890
30458 postgres                                    218861568  1820     27440
30460 postgres                                    180985856  1210     5330
30462 postgres                                    218984448  13080    42200
30463 postgres                                    218861568  3970     26940
30464 postgres                                    219328512  10600    15320
30465 postgres                                    181407744  18680    78760
30482 httpd                                       185905152  1660     7520
32410 bash                                        108699648  0        10
32420 java                                        6024855552 3890240  669810
305 rows
}

例10.7 設定プロパティーの変更

リソースタイプがリソース設定の編集をサポートする場合や、リソースタイプにプラグイン接続プロパティーがある場合、リソースプロキシーにはメソッドがあります。 editResourceConfiguration() および editPluginConfiguration()それぞれ - それらのプロパティーを編集します。
現在の設定は、を使用して出力できます。 get*Configuration).たとえば、プラグイン設定の場合は以下のようになります。
var rhelServerOne = ProxyFactory.getResource(10001)			 
			 
rhqadmin@localhost:7080$ rhelServerOne.getPluginConfiguration()
Configuration [10793] - null
  metadataCacheTimeout = 1800
  enableContentDiscovery = false
  yumPort = 9080
  enableInternalYumServer = false
  logs [0] {
  }
The edit*Configuration() メソッドを使用すると、すべてのプロパティーを個別に処理し、各値を保持または変更するよう指示する設定ウィザードが表示されます。このプロパティーは、JBoss ON の Web UI が使用する組織に従ってグループ化されます。例:
rhqadmin@localhost:7080$ rhelServerOne.editPluginConfiguration();
Non-Grouped Properties:
Group: Content
enableContentDiscovery[false]:
enableInternalYumServer[false]:
yumPort[9080]:
metadataCacheTimeout[1800]:
Group: Event Logs
[R]eview, [E]dit, Re[V]ert [S]ave or [C]ancel:
...
各グループの後に、変更を元に戻すか、保存するオプションがあります。変更が保存されると、即座に JBoss ON サーバーで更新されます。
キー action
return プロパティーのデフォルトまたは既存の値を選択します。
ctrl-d 設定 UI で unset チェックボックスを選択する場合と同じです。
ctrl-k 設定ウィザードを終了します。
ctrl-e 現在のプロパティーのヘルプの説明を表示します。

例10.8 リソースのコンテンツの管理

リソースの種類によっては、そのリソースに関連するコンテンツがあります。これらは、通常アプリケーションサーバー内の EAR または WAR リソースです。その EAR/WAR リソースに実際に関連付けられる コンテンツファイルは、バッキングコンテンツと呼ば れます。これらは通常 JAR です。
このコンテンツは、リソースから更新またはダウンロードできます。
バッキングコンテンツ(JAR/EAR/WAR ファイルのダウンロード)を取得するには、アプリケーションサーバーでファイル名とファイルパスを指定し ます。例:
var contentResource = ProxyFactory.getResource(14932)
contentResource.retrieveBackingContent("/resources/backup/original.war")
リソースのコンテンツを更新するには、以下を使用します。 updateBackingContent コンテンツとバージョン番号を配置するために、アプリケーションサーバーのパスでファイル名を指定して方法を指定します。例:
contentResource.updateBackingContent("/resources/current/new.war", "2.0")