Repository: zeppelin Updated Branches: refs/heads/master bd714c2b9 -> 8c7d3c35c
[ZEPPELIN-909] Apply new mechanism to Elasticsearch interpreter ### What is this PR for? This PR applies the [new interpreter registration mechanism](https://issues.apache.org/jira/browse/ZEPPELIN-804) to Elasticsearch interpreter. ### What type of PR is it? Improvement ### Todos * [x] - Remove static property definition code lines in `ElasticsearchInterpreter.java` and create `interpreter-setting.json` under `elasticsearch/src/main/resources` * [ ] - fix CI build error ### What is the Jira issue? [ZEPPELIN-909](https://issues.apache.org/jira/browse/ZEPPELIN-909) ### How should this be tested? 1. apply this patch 2. rm -r `interpreter/elasticsearch` and rm `conf/interpreter.json` 3. build source 4. bin/zeppelin-daemon.sh start 5. Run a paragraph with elasticsearch commands ### Screenshots (if appropriate) ### Questions: * Does the licenses files need update? No * Is there breaking changes for older versions? No * Does this needs documentation? No Author: AhyoungRyu <[email protected]> Closes #1162 from AhyoungRyu/ZEPPELIN-909 and squashes the following commits: ca393f3 [AhyoungRyu] Address @bzz comment 331eae6 [AhyoungRyu] Fix CI build failure 76ac45d [AhyoungRyu] Remove static block f1c1156 [AhyoungRyu] Apply new mechanism to Elasticsearch interpreter Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/8c7d3c35 Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/8c7d3c35 Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/8c7d3c35 Branch: refs/heads/master Commit: 8c7d3c35ce9076dffeb27c4be71812f18bc2160d Parents: bd714c2 Author: AhyoungRyu <[email protected]> Authored: Thu Jul 14 13:26:11 2016 +0900 Committer: Alexander Bezzubov <[email protected]> Committed: Fri Jul 15 18:34:52 2016 +0900 ---------------------------------------------------------------------- .../elasticsearch/ElasticsearchInterpreter.java | 21 +++++-------- .../src/main/resources/interpreter-setting.json | 33 ++++++++++++++++++++ 2 files changed, 40 insertions(+), 14 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zeppelin/blob/8c7d3c35/elasticsearch/src/main/java/org/apache/zeppelin/elasticsearch/ElasticsearchInterpreter.java ---------------------------------------------------------------------- diff --git a/elasticsearch/src/main/java/org/apache/zeppelin/elasticsearch/ElasticsearchInterpreter.java b/elasticsearch/src/main/java/org/apache/zeppelin/elasticsearch/ElasticsearchInterpreter.java index e0feece..511f1b5 100644 --- a/elasticsearch/src/main/java/org/apache/zeppelin/elasticsearch/ElasticsearchInterpreter.java +++ b/elasticsearch/src/main/java/org/apache/zeppelin/elasticsearch/ElasticsearchInterpreter.java @@ -103,19 +103,6 @@ public class ElasticsearchInterpreter extends Interpreter { public static final String ELASTICSEARCH_CLUSTER_NAME = "elasticsearch.cluster.name"; public static final String ELASTICSEARCH_RESULT_SIZE = "elasticsearch.result.size"; - static { - Interpreter.register( - "elasticsearch", - "elasticsearch", - ElasticsearchInterpreter.class.getName(), - new InterpreterPropertyBuilder() - .add(ELASTICSEARCH_HOST, "localhost", "The host for Elasticsearch") - .add(ELASTICSEARCH_PORT, "9300", "The port for Elasticsearch") - .add(ELASTICSEARCH_CLUSTER_NAME, "elasticsearch", "The cluster name for Elasticsearch") - .add(ELASTICSEARCH_RESULT_SIZE, "10", "The size of the result set of a search query") - .build()); - } - private final Gson gson = new GsonBuilder().setPrettyPrinting().create(); private Client client; private String host = "localhost"; @@ -128,7 +115,13 @@ public class ElasticsearchInterpreter extends Interpreter { this.host = getProperty(ELASTICSEARCH_HOST); this.port = Integer.parseInt(getProperty(ELASTICSEARCH_PORT)); this.clusterName = getProperty(ELASTICSEARCH_CLUSTER_NAME); - this.resultSize = Integer.parseInt(getProperty(ELASTICSEARCH_RESULT_SIZE)); + try { + this.resultSize = Integer.parseInt(getProperty(ELASTICSEARCH_RESULT_SIZE)); + } catch (NumberFormatException e) { + this.resultSize = 10; + logger.error("Unable to parse " + ELASTICSEARCH_RESULT_SIZE + " : " + + property.get(ELASTICSEARCH_RESULT_SIZE), e); + } } @Override http://git-wip-us.apache.org/repos/asf/zeppelin/blob/8c7d3c35/elasticsearch/src/main/resources/interpreter-setting.json ---------------------------------------------------------------------- diff --git a/elasticsearch/src/main/resources/interpreter-setting.json b/elasticsearch/src/main/resources/interpreter-setting.json new file mode 100644 index 0000000..16a207e --- /dev/null +++ b/elasticsearch/src/main/resources/interpreter-setting.json @@ -0,0 +1,33 @@ +[ + { + "group": "elasticsearch", + "name": "elasticsearch", + "className": "org.apache.zeppelin.elasticsearch.ElasticsearchInterpreter", + "properties": { + "elasticsearch.host": { + "envName": "ELASTICSEARCH_HOST", + "propertyName": "elasticsearch.host", + "defaultValue": "localhost", + "description": "The host for Elasticsearch" + }, + "elasticsearch.port": { + "envName": "ELASTICSEARCH_PORT", + "propertyName": "elasticsearch.port", + "defaultValue": "9300", + "description": "The port for Elasticsearch" + }, + "elasticsearch.cluster.name": { + "envName": "ELASTICSEARCH_CLUSTER_NAME", + "propertyName": "elasticsearch.cluster.name", + "defaultValue": "elasticsearch", + "description": "The cluster name for Elasticsearch" + }, + "elasticsearch.result.size": { + "envName": "ELASTICSEARCH_RESULT_SIZE", + "propertyName": "elasticsearch.result.size", + "defaultValue": "10", + "description": "The size of the result set of a search query" + } + } + } +]
