第6章 Realtime Decision Server for OpenShift の実行および設定

イメージの Realtime Decision Server for OpenShift 設定は、S2I テンプレートまたは変更された Realtime Decision Server for OpenShift のいずれかを使用して変更することができます。

6.1. Realtime Decision Server for OpenShift の S2I (Source-to-Image) プロセスの使用

Realtime Decision Server for OpenShift の実行および設定方法として、OpenShift S2I プロセスをアプリケーションパラメーターおよび環境変数と共に使用することが推奨されます。

Realtime Decision Server for OpenShift の S2I プロセスは以下のように機能します。

  1. ソースリポジトリーに pom.xml ファイルがある場合、Maven ビルドが $MAVEN_ARGS 環境変数の内容でトリガーされます。

    • デフォルトでは パッケージ のゴール (goal) が、テストのスキップ (-DskipTests) および Red Hat GA リポジトリーの有効化 (-Dcom.redhat.xpaas.repo.redhatga) のシステムプロパティーを含む openshiftプロファイルで使用されます。
  2. 正常な Maven ビルドの結果はローカル Maven リポジトリー /home/jboss/.m2/repository/ に、オフライン使用のためのすべての依存関係と共にインストールされます。Realtime Decision Server for OpenShift はこのローカルリポジトリーから作成済みの kjar を読み込みます。

    • Maven ビルドの結果として生じる kjar に加え、デプロイメントのソースディレクトリーにあるすべての kjar もローカルの Maven リポジトリーにインストールされます。Kjar は EAP_HOME/standalone/deployments/ ディレクトリーには置かれません。
  3. deployments ソースリポジトリーディレクトリーにあるすべての JAR (kjar ではない)、WAR、および EAR は EAP_HOME/standalone/deployments ディレクトリーにコピーされ、その後に JBoss EAP デプロイメントスキャナーを使用してデプロイされます。
  4. configuration ソースリポジトリーにあるすべてのファイルは EAP_HOME/standalone/configuration にコピーされます。

    注記

    カスタム JBoss EAP 設定ファイルを使用する必要がある場合、その名前は standalone-openshift.xml になります。

  5. modules ソースリポジトリーディレクトリーのすべてのファイルは EAP_HOME/modules にコピーされます。

S2I に対してカスタム Maven アーティファクトリポジトリーのミラーを使用するよう指示する方法の詳細な説明については、「アーティファクトリポジトリーのミラー」セクションを参照してください。

6.2. バイナリービルド

既存アプリケーションを OpenShift にデプロイするには、バイナリーソース 機能を使用することができます。

前提条件:

  1. アプリケーションアーカイブの取得またはアプリケーションのローカルビルド

    以下の例では、helloruleshellorules-client のクイックスタートを使用しています。

    • ソースコードのクローンを作成します。

      $ git clone https://github.com/jboss-openshift/openshift-quickstarts.git
    • Red Hat JBoss Middleware Maven リポジトリー設定 します。
    • アプリケーションをビルドします (helloruleshellorules-client クイックスタートの両方を使用)。

      注記

      以下の mvn clean package コマンドの出力は、選択した情報のみが含まれるように短縮されています。

      $ cd openshift-quickstarts/decisionserver/
      $ mvn clean package
      [INFO] Scanning for projects...
      ...
      [INFO] ------------------------------------------------------------------------
      [INFO] Reactor Build Order:
      [INFO]
      [INFO] OpenShift Quickstarts: Decision Server: Hello Rules
      [INFO] OpenShift Quickstarts: Decision Server: Hello Rules - Client
      [INFO] OpenShift Quickstarts: Decision Server: Parent
      [INFO]
      [INFO] ------------------------------------------------------------------------
      [INFO] Building OpenShift Quickstarts: Decision Server: Hello Rules 1.4.0.Final
      [INFO] ------------------------------------------------------------------------
      ...
      [INFO] ------------------------------------------------------------------------
      [INFO] Building OpenShift Quickstarts: Decision Server: Hello Rules - Client 1.4.0.Final
      [INFO] ------------------------------------------------------------------------
      ...
      [INFO] ------------------------------------------------------------------------
      [INFO] Reactor Summary:
      [INFO]
      [INFO] OpenShift Quickstarts: Decision Server: Hello Rules  SUCCESS [  0.844 s]
      [INFO] OpenShift Quickstarts: Decision Server: Hello Rules - Client SUCCESS [  7.446 s]
      [INFO] OpenShift Quickstarts: Decision Server: Parent ..... SUCCESS [  0.002 s]
      [INFO] ------------------------------------------------------------------------
      [INFO] BUILD SUCCESS
      [INFO] ------------------------------------------------------------------------
      [INFO] Total time: 9.286 s
      [INFO] Finished at: 2017-06-27T16:49:25+02:00
      [INFO] Final Memory: 49M/502M
      [INFO] ------------------------------------------------------------------------
  1. ローカルファイルシステムでのディレクトリー構造の作成

    メインのバイナリービルドディレクトリーの deployments/ サブディレクトリーにあるアプリケーションアーカイブは、OpenShift にビルドされるイメージの 標準デプロイメントフォルダー に直接コピーされます。デプロイするアプリケーションについては、web アプリケーションデータを含むディレクトリー階層を適切に構成する必要があります。

    ローカルファイルシステムにバイナリービルドのメインディレクトリーとその中に入る deployments/ サブディレクトリーを作成します。事前にビルドされた hellorules クイックスタートの JAR アーカイブと hellorules-client クイックスタート の WAR アーカイブの両方を deployments/ サブディレクトリーにコピーします。

    decisionserver]$ ls
    hellorules  hellorules-client  pom.xml
    $ mkdir -p ocp/deployments
    $ cp hellorules/target/decisionserver-hellorules-1.4.0.Final.jar ocp/deployments/
    $ cp hellorules-client/target/decisionserver-hellorules-client-1.4.0.Final.war ocp/deployments/
    注記

    標準デプロイメントのディレクトリーの場所は、アプリケーションのデプロイに使用された基礎となるベースイメージによって異なります。以下の図を参照してください。

    表6.1 デプロイメントディレクトリーの標準的な場所

    基礎となるベースイメージの名前デプロイメントディレクトリーの標準的な場所

    EAP for OpenShift 6.4 および 7.0

    $JBOSS_HOME/standalone/deployments

    Java S2I for OpenShift

    /deployments

    JWS for OpenShift

    $JWS_HOME/webapps

以下の手順を実行し、バイナリー入力で構成されるアプリケーションを OpenShift で実行します。

  1. OpenShift インスタンスにログインします。

    $ oc login
  2. 新規プロジェクトを作成します。

    $ oc new-project ds-bin-demo
  3. (オプション) 特定イメージのイメージストリームを識別します。

    $ oc get is -n openshift | grep ^jboss-decisionserver | cut -f1 -d ' '
    jboss-decisionserver62-openshift
    jboss-decisionserver63-openshift
    注記

    jboss-decisionserver62-openshift イメージストリームのイメージは古くなっているため、以下の jboss-decisionserver63-openshift を使用します。

  4. イメージストリームおよびアプリケーション名を指定して、新規のバイナリービルドを作成します。

    注記

    KIE_SERVER_USER および KIE_SERVER_PASSWORD 環境変数にカスタム値を指定して、KIE サーバーの REST インターフェースにアクセスするデフォルトのユーザー名とパスワードを変更することができます。

    $ oc new-build --binary=true \
    --name=ds-hr-app \
    --image-stream=jboss-decisionserver63-openshift \
    -e KIE_SERVER_USER=kieserveruser \
    -e KIE_SERVER_PASSWORD=kieserverPwd1!
    --> Found image 4a6c0ce (5 weeks old) in image stream "jboss-decisionserver63-openshift" in project "openshift" under tag "latest" for "jboss-decisionserver63-openshift"
    
        JBoss BRMS Realtime Decision Server 6.3
        ---------------------------------------
        Platform for executing business rules on JBoss BRMS Realtime Decision Server 6.3.
    
        Tags: builder, decisionserver, decisionserver6
    
        * A source build using binary input will be created
          * The resulting image will be pushed to image stream "ds-hr-app:latest"
          * Use 'start-build --from-dir=DIR|--from-repo=DIR|--from-file=FILE' to trigger a new build
          * WARNING: a binary build was created, you must specify one of --from-dir|--from-file|--from-repo when starting builds
    
    --> Creating resources with label build=ds-hr-app ...
        imagestream "ds-hr-app" created
        buildconfig "ds-hr-app" created
    --> Success
  5. バイナリービルドを開始します。oc 実行可能プログラムに対し、前述の手順 で作成したバイナリービルドのメインディレクトリーを、OpenShift ビルドのバイナリー入力を含むバイナリーとして使用するように指示します。

    注記

    次のコマンドの出力は、簡潔に表示できるよう短縮されています。

    $ oc start-build ds-hr-app --from-dir=./ocp/ --follow
    Uploading directory "ocp" as binary input for the build ...
    build "ds-hr-app-1" started
    Receiving source from STDIN as archive ...
    
    Copying all war artifacts from /home/jboss/source/. directory into /opt/eap/standalone/deployments for later deployment...
    Copying all ear artifacts from /home/jboss/source/. directory into /opt/eap/standalone/deployments for later deployment...
    Copying all rar artifacts from /home/jboss/source/. directory into /opt/eap/standalone/deployments for later deployment...
    Copying all jar artifacts from /home/jboss/source/. directory into /opt/eap/standalone/deployments for later deployment...
    Copying all war artifacts from /home/jboss/source/deployments directory into /opt/eap/standalone/deployments for later deployment...
    '/home/jboss/source/deployments/decisionserver-hellorules-client-1.4.0.Final.war' -> '/opt/eap/standalone/deployments/decisionserver-hellorules-client-1.4.0.Final.war'
    Copying all ear artifacts from /home/jboss/source/deployments directory into /opt/eap/standalone/deployments for later deployment...
    Copying all rar artifacts from /home/jboss/source/deployments directory into /opt/eap/standalone/deployments for later deployment...
    Copying all jar artifacts from /home/jboss/source/deployments directory into /opt/eap/standalone/deployments for later deployment...
    '/home/jboss/source/deployments/decisionserver-hellorules-1.4.0.Final.jar' -> '/opt/eap/standalone/deployments/decisionserver-hellorules-1.4.0.Final.jar'
    /opt/eap/standalone/deployments/decisionserver-hellorules-1.4.0.Final.jar is a kjar
    ...
    INFO: org.openshift.quickstarts:decisionserver-hellorules:1.4.0.Final verified.
    
    
    Pushing image 172.30.202.111:5000/ds-bin-demo/ds-hr-app:latest ...
    Pushed 6/9 layers, 67% complete
    Pushed 7/9 layers, 78% complete
    Pushed 8/9 layers, 89% complete
    Pushed 9/9 layers, 100% complete
    Push successful
  6. ビルドをベースにして新規の OpenShift アプリケーションを作成します。

    $ oc new-app ds-hr-app
    --> Found image c2c182e (48 seconds old) in image stream ds-hr-app under tag "latest" for "ds-hr-app"
    
        ds-bin-demo/ds-hr-app-2:ea504dd7
        --------------------------------
        Platform for executing business rules on JBoss BRMS Realtime Decision Server 6.3.
    
        Tags: builder, decisionserver, decisionserver6
    
        * This image will be deployed in deployment config "ds-hr-app"
        * Ports 8080/tcp, 8443/tcp, 8778/tcp will be load balanced by service "ds-hr-app"
          * Other containers can access this service through the hostname "ds-hr-app"
    
    --> Creating resources with label app=ds-hr-app ...
        deploymentconfig "ds-hr-app" created
        service "ds-hr-app" created
    --> Success
        Run 'oc status' to view your app.
  7. サービスをルートとして公開します。

    $ oc get svc -o name
    service/ds-hr-app
    $ oc expose svc/ds-hr-app
    route "ds-hr-app" exposed
  8. アプリケーションにアクセスします。

    URL の http://ds-hr-app-ds-bin-demo.openshift.example.com/hellorules/ にアクセスして、hellorules アプリケーションの利用可能なクエリー文字列の引数一覧を取得できます。

    URL の http://ds-hr-app-ds-bin-demo.openshift.example.com/hellorules?command=runLocal を使用して hellorules-client サーブレットを実行します。

    注記

    REST API の専用 server/ ページの http://ds-hr-app-ds-bin-demo.openshift.example.com/kie-server/services/rest/server/ にアクセスして現行の KIE サーバーの状態を確認することができます。前述の ユーザー名およびパスワードを使用してこのページにアクセスします (またはサーバーの REST API メソッド)。

6.3. 変更された Decision Server xPaaS イメージの使用

別の方法として、イメージに変更を加え後に変更したイメージを OpenShift で使用することもできます。以下は、現時点でサポートされるインターフェースと共に提供されているテンプレートの一覧です。

表6.2 提供されているテンプレート

テンプレート名サポートされているインターフェース

decisionserver63-basic-s2i.json

http-rest、jms-hornetq

decisionserver63-https-s2i.json

http-rest、https-rest、jms-hornetq

decisionserver63-amq-s2i.json

http-rest、https-rest、jms-activemq

Realtime Decision Server for OpenShift は Docker で実行でき、Realtime Decision Server for OpenShift に含まれる JBoss EAP 管理 CLI (EAP_HOME/bin/jboss-cli.sh) を使用して必要な設定の変更を行い、変更されたコンテナーを新規イメージとしてコミットすることができます。その後に変更されたイメージを OpenShift で実行できます。

重要

JBoss EAP xPaaS 設定ファイルの OpenShift プレースホルダーでは置換を実行しないことが推奨されます。これらのプレースホルダーは、コンテナーのデプロイメント時に (メッセージング、データストア、HTTPS などの) サービスを自動的に設定するために使用されるためです。これらの設定値は、環境変数を使用して設定されることが意図されています。

注記