LoginSignup
1
1

More than 5 years have passed since last update.

Elasticsearch::Extensionsを用いたテスト on Ruby on Rails(xception in thread "main" java.lang.IllegalArgumentException: Unknown [gateway] type [none])

Last updated at Posted at 2016-07-24

Exception in thread "main" java.lang.IllegalArgumentException: Unknown [gateway] type [none]

rspecにて、Elasticsearchを用いたアプリのテストを実行中に、上記のエラーが発生しハマったので、備忘録として。。。

ESの起動時はデフォルトだと、gatewayはlocalのはずだがなぜ・・・

調査1

一応エラーからソースを追ってみると、
https://github.com/elastic/elasticsearch/blob/master/core/src/main/java/org/elasticsearch/common/util/ExtensionPoint.java#L150

でこけている。

で、ここからトレースをしてみても。。。
https://github.com/jprante/elasticsearch-server/blob/master/elasticsearch-server-node/src/main/java/org/elasticsearch/gateway/GatewayModule.java#L28

だし、gatewayがnoneとなってしまうのが全くもって不明。

調査2

そして、さらに、謎なのが、

TEST_CLUSTER_NAME=my-testing-cluster \
TEST_CLUSTER_COMMAND=/usr/local/Cellar/elasticsearch/0.90.10/bin/elasticsearch \
TEST_CLUSTER_PORT=9350 \
TEST_CLUSTER_NODES=3 \
TEST_CLUSTER_NAME=my_testing_cluster \
ruby -r elasticsearch -e "require 'elasticsearch/extensions/test/cluster'; Elasticsearch::Extensions::Test::Cluster.start"

みたいな感じでコマンドから実行するとうまくいく・・・という  :astonished:

調査3

ドキュメント漁って。。。。
コマンドで再現をしてみたところ。。。。

~ $ elasticsearch -D es.foreground=yes -D es.cluster.name=elasticsearch-test-apple-no-macbook-pro.local -D es.node.name=node-1 -D es.http.port=9250 -D es.path.data=/tmp/elasticsearch_test -D es.path.work=/tmp -D es.path.logs=/tmp/log/elasticsearch -D es.cluster.routing.allocation.disk.threshold_enabled=false -D es.network.host=localhost -D es.script.inline=true -D es.script.stored=true -D es.node.attr.testattr=test -D es.path.repo=/tmp -D es.repositories.url.allowed_urls=http://snapshot.test* -D es.logger.level=DEBUG -D es.gateway.type=none
:
:
Exception in thread "main" java.lang.IllegalArgumentException: Unknown [gateway] type [none]
    at org.elasticsearch.common.util.ExtensionPoint$SelectedType.bindType(ExtensionPoint.java:146)
    at org.elasticsearch.gateway.GatewayModule.configure(GatewayModule.java:53)
    at <<<guice>>>
    at org.elasticsearch.node.Node.<init>(Node.java:213)
    at org.elasticsearch.node.Node.<init>(Node.java:140)
    at org.elasticsearch.node.NodeBuilder.build(NodeBuilder.java:143)
    at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:178)
    at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:270)
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:35)
Refer to the log for complete error details.

再現できた。

要は

-D es.gateway.type=none

が間違いで、

-D es.gateway=local

とすると

[2016-07-24 21:17:02,368][INFO ][node                     ] [node-1] started
[2016-07-24 21:17:02,371][DEBUG][cluster.service          ] [node-1] processing [local-gateway-elected-state]: execute
[2016-07-24 21:17:02,372][DEBUG][cluster.service          ] [node-1] cluster state updated, version [2], source [local-gateway-elected-state]
[2016-07-24 21:17:02,372][DEBUG][cluster.service          ] [node-1] publishing cluster state version [2]
[2016-07-24 21:17:02,372][DEBUG][cluster.service          ] [node-1] set local cluster state to version 2
[2016-07-24 21:17:02,389][INFO ][gateway                  ] [node-1] recovered [0] indices into cluster_state
[2016-07-24 21:17:02,389][DEBUG][cluster.service          ] [node-1] processing [local-gateway-elected-state]: took 18ms done applying updated cluster_state (version: 2, uuid: -NnoHok5TRWNODw59ligMQ)

となり、無事起動成功。

余談だがデフォルトが localなので、

-D es.gateway=none

でもいける。

結果

Elasticsearch::Extensions::Test::Cluster.start port: 9250, network_host: 'localhost', es_params: '-D es.gateway=local' unless Elasticsearch::Extensions::Test::Cluster.running?(on: 9250)`

TEST Cluster起動時に設定追加して、完了。

ちなみに、network_hostも指定していますが、これはデフォルトだと、 0.0.0.0( デフォルトゲートウェイ)なので、CIテスト時、気持ち悪いため、固定しているだけです。

モヤっと。。。

Exception in thread "main" java.lang.IllegalArgumentException: Unknown [gateway] type [none]

については、なぜこうなったのかが現状まだ不明・・・。
elasticsearch.ymlで 設定しているわけでもなし。。。そもそもバグなのか、、、とりあえずは先に進めたいので、一旦 FIXMEとしておこ。

1
1
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1