Rhythm & Biology

Engineering, Science, et al.

WildFly: デプロイ時のnameとruntime-nameの役割

WildFlyへのCLIツールを利用したデプロイ時に--nameオプションと--runtime-nameオプションがあり、それぞれが何を意味しているのか分からなかったため、実験しつつ調べてみました。

まずはヘルプを読む

ざっくり把握した内容

  • nameはユニークでなければならない
  • 明示的に指定されなければ、ファイル名(war)がそのままnameになる
  • runtime-nameはユニークである必要はない
  • runtime-nameが重複している場合、どれか一つしか起動できない
[standalone@localhost:9990 /] deploy --help
SYNOPSIS

    deploy ((file_path | --url=deployment_url)
               [--script=script_name] [--name=deployment_name]
               [--runtime-name=deployment_runtime_name]
               [--force | --disabled] [--unmanaged])
           | --name=deployment_name
           [--server-groups=group_name (,group_name)* | --all-server-groups]
           [--headers={operation_header (;operation_header)*}]

DESCRIPTION

  Deploys the application designated by the file_path or enables an already
  existing but disabled in the repository deployment designated by the name
  argument. If executed w/o arguments, will list all the existing deployments.

ARGUMENTS
...(中略)...

 --name            - the unique name of the deployment. If the file path
                     argument is specified the name argument is optional with
                     the file name been the default value. If the file path
                     argument isn't specified then the command is supposed to
                     enable an already existing but disabled deployment, and in
                     this case the name argument is required.

 --runtime-name    - optional, the runtime name for the deployment. This will
                     form the basis for such things as default Java EE
                     application and module names. This would typically be the
                     same as --name, and if not specified the value used for
                     --name will be used. In some cases users may wish to have
                     two deployments with the same 'runtime-name' (e.g. two
                     versions of "example.war") both available in the management
                     configuration, in which case the deployments would need to
                     have distinct 'name' values but would have the same
                     'runtime-name'. Within an individual server, only one
                     deployment with a given 'runtime-name' can deployed.
                     However, multiple deployments with the same 'runtime-name'
                     can exist in the configuration, so long as only one is
                     enabled.

...(略)...

サンプルアプリケーション

2つのごく単純なアプリケーション(war)を用意

  • app-a.war: 「Hello, A」と表示
  • app-b.war: 「Hello, B」と表示

何もオプションを指定せずデプロイ

NAMERUNTIME-NAMEはどちらもそのままwarファイル名となります。
アプリケーションにアクセスする際も、warファイル名がURLに含まれます(suffixは除く)。

[standalone@localhost:9990 /] deploy app-a.war
[standalone@localhost:9990 /] deployment-info
NAME      RUNTIME-NAME PERSISTENT ENABLED STATUS 
app-a.war app-a.war    true       true    OK     
app-b.war app-b.war    true       true    OK

アンデプロイする時はNAME(=warファイル名)を指定します。
ファイルは残してdisabled状態にしたい場合は、--keep-contentオプションを付けます。

この状態でアクセスすると、どちらも「404 - Not Found」と表示されます。

[standalone@localhost:9990 /] undeploy app-a.war
[standalone@localhost:9990 /] undeploy app-b.war --keep-content
[standalone@localhost:9990 /] deployment-info 
NAME      RUNTIME-NAME PERSISTENT ENABLED STATUS  
app-b.war app-b.war    true       false   STOPPED

--nameオプションを指定してデプロイ

hoge.warにすると/hogeでアクセス出来るようになります。

[standalone@localhost:9990 /] deploy app-a.war --name=A.war
[standalone@localhost:9990 /] deploy app-b.war --name=B.war
[standalone@localhost:9990 /] deployment-info 
NAME  RUNTIME-NAME PERSISTENT ENABLED STATUS 
A.war A.war        true       true    OK     
B.war B.war        true       true    OK

アンデプロイは自分で指定したNAMEでやります。

[standalone@localhost:9990 /] undeploy A.war
[standalone@localhost:9990 /] undeploy B.war

--runtime-nameオプションを指定してデプロイ

どちらもapp.warというruntime-nameで起動しようとしてみます。

[standalone@localhost:9990 /] deploy app-a.war --runtime-name=app.war
[standalone@localhost:9990 /] deployment-info 
NAME      RUNTIME-NAME PERSISTENT ENABLED STATUS 
app-a.war app.war      true       true    OK     
[standalone@localhost:9990 /] deploy app-b.war --runtime-name=app.war
{"JBAS014653: Composite operation failed and was rolled back. Steps that failed:" => {"Operation step-1" => "JBAS018785: There is already a deployment called app-a.war with the same runtime name app.war"}}

app-b.warのほうは、runtime-nameがかぶってしまったため、デプロイ失敗しました。
この状態で http://localhost:8080/app/ にアクセスすると「Hello, A」と表示されます。

次に、app-a.wardisabled状態に変えて、app-b.warをデプロイしてみます。

[standalone@localhost:9990 /] undeploy app-a.war --keep-content
[standalone@localhost:9990 /] deploy app-b.war --runtime-name=app.war
[standalone@localhost:9990 /] deployment-info 
NAME      RUNTIME-NAME PERSISTENT ENABLED STATUS  
app-a.war app.war      true       false   STOPPED 
app-b.war app.war      true       true    OK

この状態で http://localhost:8080/app/ にアクセスすると「Hello, B」という表示に変わっています。

まとめ

  • nameは管理上利用する名称
    • デプロイ・アンデプロイ時のコマンドの引数として与える
    • ユニークでなければならない
  • runtime-nameはURLの一部となる
    • ユニークである必要はない
    • 同一のruntime-nameのものは、どれか1つしかデプロイ状態にできない