From 275fdcc08dad1f193e2d0305ed79ebaff7cec0bc Mon Sep 17 00:00:00 2001 From: Michael McCandless Date: Fri, 3 Jul 2015 05:59:16 -0400 Subject: [PATCH 01/10] fix silly smoke_test_plugin bugs when ES actually succeeds in starting with the installed plugins --- dev-tools/smoke_test_plugins.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/dev-tools/smoke_test_plugins.py b/dev-tools/smoke_test_plugins.py index b6f1f978044..70d1be0c67b 100644 --- a/dev-tools/smoke_test_plugins.py +++ b/dev-tools/smoke_test_plugins.py @@ -79,10 +79,10 @@ def readServerOutput(p, startupEvent, failureEvent): startupEvent.set() print('ES: **process exit**\n') break - line = line.decode('utf-8') + line = line.decode('utf-8').rstrip() if line.endswith('started') and not startupEvent.isSet(): startupEvent.set() - print('ES: %s' % line.rstrip()) + print('ES: %s' % line) except: print() print('Exception reading Elasticsearch output:') @@ -109,14 +109,14 @@ if __name__ == '__main__': run('tar -xzf core/target/releases/%s -C %s' % (artifact, tmp_dir)) es_install_dir = os.path.join(tmp_dir, artifact[:-7]) es_plugin_path = os.path.join(es_install_dir, 'bin/plugin') - plugin_names = set() + installed_plugin_names = set() print('Find plugins:') for name in os.listdir('plugins'): if name not in ('target', 'pom.xml'): url = 'file://%s/plugins/%s/target/releases/elasticsearch-%s-2.0.0-SNAPSHOT.zip' % (os.path.abspath('.'), name, name) print(' install plugin %s...' % name) run('%s; %s --url %s -install %s' % (JAVA_ENV, es_plugin_path, url, name)) - plugin_names.add(name) + installed_plugin_names.add(name) print('Start Elasticsearch') @@ -153,11 +153,12 @@ if __name__ == '__main__': for _, node in nodes.items(): node_plugins = node['plugins'] for node_plugin in node_plugins: - if not plugin_names.get(node_plugin['name'], False): - raise RuntimeError('Unexpeced plugin %s' % node_plugin['name']) - del plugin_names[node_plugin['name']] - if plugin_names: - raise RuntimeError('Plugins not loaded %s' % list(plugin_names.keys())) + plugin_name = node_plugin['name'] + if plugin_name not in installed_plugin_names: + raise RuntimeError('Unexpeced plugin %s' % plugin_name) + installed_plugin_names.remove(plugin_name) + if len(installed_plugin_names) > 0: + raise RuntimeError('Plugins not loaded %s' % installed_plugin_names) else: raise RuntimeError('Expected HTTP 200 but got %s' % res.status) finally: From ac32f3d31083040f9e604cbad127ff8fbc7e0763 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Fri, 3 Jul 2015 12:13:56 +0200 Subject: [PATCH 02/10] Don't special-case on ElasticsearchWrapperException in toXContent the specialization can cause stack overflows if an exception is a ElasticsearchWrapperException as well as a ElasticsearchException. This commit just relies on the unwrap logic now to find the cause and only renders if we the rendering exception is the cause otherwise forwards to the generic exception rendering. Closes #11994 --- .../org/elasticsearch/ElasticsearchException.java | 3 ++- .../elasticsearch/ElasticsearchExceptionTests.java | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/elasticsearch/ElasticsearchException.java b/core/src/main/java/org/elasticsearch/ElasticsearchException.java index 1fa95d6b1b0..789589f3f64 100644 --- a/core/src/main/java/org/elasticsearch/ElasticsearchException.java +++ b/core/src/main/java/org/elasticsearch/ElasticsearchException.java @@ -246,7 +246,8 @@ public class ElasticsearchException extends RuntimeException implements ToXConte @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - if (this instanceof ElasticsearchWrapperException) { + Throwable ex = ExceptionsHelper.unwrapCause(this); + if (ex != this) { toXContent(builder, params, this); } else { builder.field("type", getExceptionName()); diff --git a/core/src/test/java/org/elasticsearch/ElasticsearchExceptionTests.java b/core/src/test/java/org/elasticsearch/ElasticsearchExceptionTests.java index 34bc1178b02..581868ff395 100644 --- a/core/src/test/java/org/elasticsearch/ElasticsearchExceptionTests.java +++ b/core/src/test/java/org/elasticsearch/ElasticsearchExceptionTests.java @@ -32,14 +32,17 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentLocation; import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexException; import org.elasticsearch.index.query.QueryParsingException; import org.elasticsearch.index.query.TestQueryParsingException; import org.elasticsearch.indices.IndexMissingException; import org.elasticsearch.rest.RestStatus; +import org.elasticsearch.search.SearchParseException; import org.elasticsearch.search.SearchShardTarget; import org.elasticsearch.test.ElasticsearchTestCase; +import org.elasticsearch.test.TestSearchContext; import org.elasticsearch.test.VersionUtils; import org.elasticsearch.test.hamcrest.ElasticsearchAssertions; import org.elasticsearch.transport.RemoteTransportException; @@ -177,6 +180,16 @@ public class ElasticsearchExceptionTests extends ElasticsearchTestCase { } public void testToXContent() throws IOException { + { + ElasticsearchException ex = new SearchParseException(new TestSearchContext(), "foo", new XContentLocation(1,0)); + XContentBuilder builder = XContentFactory.jsonBuilder(); + builder.startObject(); + ex.toXContent(builder, ToXContent.EMPTY_PARAMS); + builder.endObject(); + + String expected = "{\"type\":\"search_parse_exception\",\"reason\":\"foo\",\"line\":1,\"col\":0}"; + assertEquals(expected, builder.string()); + } { ElasticsearchException ex = new ElasticsearchException("foo", new ElasticsearchException("bar", new IllegalArgumentException("index is closed", new RuntimeException("foobar")))); XContentBuilder builder = XContentFactory.jsonBuilder(); @@ -226,6 +239,7 @@ public class ElasticsearchExceptionTests extends ElasticsearchTestCase { ex.toXContent(otherBuilder, ToXContent.EMPTY_PARAMS); otherBuilder.endObject(); assertEquals(otherBuilder.string(), builder.string()); + assertEquals("{\"type\":\"file_not_found_exception\",\"reason\":\"foo not found\"}", builder.string()); } } From 9495816cb7d7720d96a6c38887b13388fe4a274c Mon Sep 17 00:00:00 2001 From: Tanguy Leroux Date: Fri, 3 Jul 2015 10:32:01 +0200 Subject: [PATCH 03/10] Remove sigar completely --- core/bin/elasticsearch.in.bat | 2 +- core/bin/elasticsearch.in.sh | 2 +- core/licenses/sigar-1.6.4.jar.sha1 | 1 - core/licenses/sigar-LICENSE.txt | 201 ------------------ core/licenses/sigar-NOTICE.txt | 117 ---------- core/pom.xml | 31 +-- core/src/main/assemblies/common-bin.xml | 8 - .../elasticsearch/bootstrap/Bootstrap.java | 18 +- .../elasticsearch/monitor/MonitorModule.java | 35 +-- .../monitor/fs/SigarFsProbe.java | 106 --------- .../monitor/network/SigarNetworkProbe.java | 166 --------------- .../monitor/os/SigarOsProbe.java | 133 ------------ .../monitor/process/SigarProcessProbe.java | 81 ------- .../monitor/sigar/SigarService.java | 67 ------ .../cluster/stats/ClusterStatsTests.java | 9 +- .../mapping/ManyMappingsBenchmark.java | 2 +- .../recovery/ReplicaRecoveryBenchmark.java | 2 +- .../aggregations/GlobalOrdinalsBenchmark.java | 2 +- ...AggregationSearchCollectModeBenchmark.java | 2 +- ...AggregationSearchAndIndexingBenchmark.java | 2 +- .../TermsAggregationSearchBenchmark.java | 2 +- .../bootstrap/BootstrapForTesting.java | 4 +- .../org/elasticsearch/monitor/SigarTests.java | 42 ---- .../test/InternalTestCluster.java | 1 - dev-tools/ElasticSearch.launch | 2 +- plugins/pom.xml | 5 - pom.xml | 19 -- 27 files changed, 20 insertions(+), 1042 deletions(-) delete mode 100644 core/licenses/sigar-1.6.4.jar.sha1 delete mode 100644 core/licenses/sigar-LICENSE.txt delete mode 100644 core/licenses/sigar-NOTICE.txt delete mode 100644 core/src/main/java/org/elasticsearch/monitor/fs/SigarFsProbe.java delete mode 100644 core/src/main/java/org/elasticsearch/monitor/network/SigarNetworkProbe.java delete mode 100644 core/src/main/java/org/elasticsearch/monitor/os/SigarOsProbe.java delete mode 100644 core/src/main/java/org/elasticsearch/monitor/process/SigarProcessProbe.java delete mode 100644 core/src/main/java/org/elasticsearch/monitor/sigar/SigarService.java delete mode 100644 core/src/test/java/org/elasticsearch/monitor/SigarTests.java diff --git a/core/bin/elasticsearch.in.bat b/core/bin/elasticsearch.in.bat index 91a731e8260..b25a679fc9e 100644 --- a/core/bin/elasticsearch.in.bat +++ b/core/bin/elasticsearch.in.bat @@ -88,7 +88,7 @@ set JAVA_OPTS=%JAVA_OPTS% -Dfile.encoding=UTF-8 REM Use our provided JNA always versus the system one set JAVA_OPTS=%JAVA_OPTS% -Djna.nosys=true -set CORE_CLASSPATH=%ES_HOME%/lib/${project.build.finalName}.jar;%ES_HOME%/lib/*;%ES_HOME%/lib/sigar/* +set CORE_CLASSPATH=%ES_HOME%/lib/${project.build.finalName}.jar;%ES_HOME%/lib/* if "%ES_CLASSPATH%" == "" ( set ES_CLASSPATH=%CORE_CLASSPATH% ) else ( diff --git a/core/bin/elasticsearch.in.sh b/core/bin/elasticsearch.in.sh index 9e1c8d9d42e..92eab40307e 100644 --- a/core/bin/elasticsearch.in.sh +++ b/core/bin/elasticsearch.in.sh @@ -1,6 +1,6 @@ #!/bin/sh -CORE_CLASSPATH="$ES_HOME/lib/${project.build.finalName}.jar:$ES_HOME/lib/*:$ES_HOME/lib/sigar/*" +CORE_CLASSPATH="$ES_HOME/lib/${project.build.finalName}.jar:$ES_HOME/lib/*" if [ "x$ES_CLASSPATH" = "x" ]; then ES_CLASSPATH="$CORE_CLASSPATH" diff --git a/core/licenses/sigar-1.6.4.jar.sha1 b/core/licenses/sigar-1.6.4.jar.sha1 deleted file mode 100644 index 8cfa355b9f6..00000000000 --- a/core/licenses/sigar-1.6.4.jar.sha1 +++ /dev/null @@ -1 +0,0 @@ -e91a355d337a0b1991f54181627d63c9973624c3 diff --git a/core/licenses/sigar-LICENSE.txt b/core/licenses/sigar-LICENSE.txt deleted file mode 100644 index 11069edd790..00000000000 --- a/core/licenses/sigar-LICENSE.txt +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - -TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - -1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - -2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - -3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - -4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - -5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - -6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - -7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - -8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - -9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - -END OF TERMS AND CONDITIONS - -APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - -Copyright [yyyy] [name of copyright owner] - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. diff --git a/core/licenses/sigar-NOTICE.txt b/core/licenses/sigar-NOTICE.txt deleted file mode 100644 index c184394d05d..00000000000 --- a/core/licenses/sigar-NOTICE.txt +++ /dev/null @@ -1,117 +0,0 @@ -Copyright (c) 2004-2011 VMware, Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - -http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - -ADDITIONAL LICENSE INFORMATION: - -Hyperic SIGAR includes some third-party open source components -in its distribution. The list below identifies the community or -organization and links to their appropriate license terms. - -The Hyperic team would like to thank all the communities -of the projects listed below for their contributions. - ----------------------------------------------------------- -Components under the Apache License 2.0: ----------------------------------------------------------- - -The following components are included without modification: - -- log4j - -Information: http://logging.apache.org/ -License: http://www.apache.org/licenses/LICENSE-2.0 - -The following components are included with modification: - -- cpptasks - -Information: http://ant-contrib.sourceforge.net/ -License: http://www.apache.org/licenses/LICENSE-2.0 - -- (portions of) APR - -Information: http://apr.apache.org/ -License: http://www.apache.org/licenses/LICENSE-2.0 - ----------------------------------------------------------- -Components under BSD/MIT Style Licenses: ----------------------------------------------------------- - -The following components are included with modification: - -- solaris get_mib2 - -Information: ftp://vic.cc.purdue.edu/pub/tools/unix/solaris/get_mib2/ -License: within src/os/solaris/get_mib2.[ch] - -Copyright 1995 Purdue Research Foundation, West Lafayette, Indiana -47907. All rights reserved. - -Written by Victor A. Abell - -This software is not subject to any license of the American Telephone -and Telegraph Company or the Regents of the University of California. - -Permission is granted to anyone to use this software for any purpose on -any computer system, and to alter it and redistribute it freely, subject -to the following restrictions: - -1. Neither Victor A Abell nor Purdue University are responsible for - any consequences of the use of this software. - -2. The origin of this software must not be misrepresented, either by - explicit claim or by omission. Credit to Victor A. Abell and Purdue - University must appear in documentation and sources. - -3. Altered versions must be plainly marked as such, and must not be - misrepresented as being the original software. - -4. This notice may not be removed or altered. - -- getline by Chris Thewalt - -Information: http://tinyurl.com/r438r -License: within src/sigar_getline.c - -Copyright (C) 1991, 1992 by Chris Thewalt (thewalt@ce.berkeley.edu) - -Permission to use, copy, modify, and distribute this software -for any purpose and without fee is hereby granted, provided -that the above copyright notices appear in all copies and that both the -copyright notice and this permission notice appear in supporting -documentation. This software is provided "as is" without express or -implied warranty. - -- PrintfFormat.java - -Information: http://java.sun.com/developer/technicalArticles/Programming/sprintf/PrintfFormat.java -License: within bindings/java/src/org/hyperic/sigar/util/PrintfFormat.java - -(c) 2000 Sun Microsystems, Inc. -ALL RIGHTS RESERVED - -License Grant- - -Permission to use, copy, modify, and distribute this Software and its -documentation for NON-COMMERCIAL or COMMERCIAL purposes and without fee is -hereby granted. - -This Software is provided "AS IS". All express warranties, including any -implied warranty of merchantability, satisfactory quality, fitness for a -particular purpose, or non-infringement, are disclaimed, except to the extent -that such disclaimers are held to be legally invalid. - -You acknowledge that Software is not designed, licensed or intended for use in -the design, construction, operation or maintenance of any nuclear facility -("High Risk Activities"). Sun disclaims any express or implied warranty of -fitness for such uses. - -Please refer to the file http://www.sun.com/policies/trademarks/ for further -important trademark information and to -http://java.sun.com/nav/business/index.html for further important licensing -information for the Java Technology. diff --git a/core/pom.xml b/core/pom.xml index 7a5f1a631f0..300cf5fddb7 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -214,11 +214,6 @@ jna true - - org.fusesource - sigar - true - @@ -708,20 +703,9 @@ root - - ${project.basedir}/lib/sigar/ - sigar-*.jar, libsigar-*-linux.* - directory - - perm - ${packaging.elasticsearch.home.dir}/lib/sigar - root - root - - ${project.build.directory}/lib - ${project.build.finalName}-shaded.jar,${project.build.finalName}-sources.jar,${project.build.finalName}-tests.jar,${project.build.finalName}-test-sources.jar,slf4j-api-*.jar,sigar-*.jar + ${project.build.finalName}-shaded.jar,${project.build.finalName}-sources.jar,${project.build.finalName}-tests.jar,${project.build.finalName}-test-sources.jar,slf4j-api-*.jar directory perm @@ -889,7 +873,6 @@ ${project.build.finalName}-tests.jar ${project.build.finalName}-test-sources.jar slf4j-api-*.jar - sigar-*.jar @@ -900,18 +883,6 @@ - - ${packaging.elasticsearch.home.dir}/lib/sigar - - - lib/sigar - - sigar*.jar - libsigar-*-linux.* - - - - /etc/init.d diff --git a/core/src/main/assemblies/common-bin.xml b/core/src/main/assemblies/common-bin.xml index d5a19ba37ed..dafd901aecd 100644 --- a/core/src/main/assemblies/common-bin.xml +++ b/core/src/main/assemblies/common-bin.xml @@ -77,14 +77,6 @@ plugin - - - lib/sigar - lib/sigar - - * - - diff --git a/core/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java b/core/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java index 0d8ef345336..006d55edaee 100644 --- a/core/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java +++ b/core/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java @@ -44,7 +44,6 @@ import org.elasticsearch.monitor.process.JmxProcessProbe; import org.elasticsearch.node.Node; import org.elasticsearch.node.NodeBuilder; import org.elasticsearch.node.internal.InternalSettingsPreparer; -import org.hyperic.sigar.Sigar; import java.io.IOException; import java.lang.reflect.Method; @@ -97,7 +96,7 @@ public class Bootstrap { } /** initialize native resources */ - public static void initializeNatives(boolean mlockAll, boolean ctrlHandler, boolean loadSigar) { + public static void initializeNatives(boolean mlockAll, boolean ctrlHandler) { final ESLogger logger = Loggers.getLogger(Bootstrap.class); // check if the user is running as root, and bail @@ -140,18 +139,6 @@ public class Bootstrap { // we've already logged this. } - if (loadSigar) { - // initialize sigar explicitly - try { - Sigar.load(); - logger.trace("sigar libraries loaded successfully"); - } catch (Throwable t) { - logger.trace("failed to load sigar libraries", t); - } - } else { - logger.trace("sigar not loaded, disabled via settings"); - } - // init lucene random seed. it will use /dev/urandom where available: StringHelper.randomId(); } @@ -162,8 +149,7 @@ public class Bootstrap { private void setup(boolean addShutdownHook, Settings settings, Environment environment) throws Exception { initializeNatives(settings.getAsBoolean("bootstrap.mlockall", false), - settings.getAsBoolean("bootstrap.ctrlhandler", true), - settings.getAsBoolean("bootstrap.sigar", true)); + settings.getAsBoolean("bootstrap.ctrlhandler", true)); if (addShutdownHook) { Runtime.getRuntime().addShutdownHook(new Thread() { diff --git a/core/src/main/java/org/elasticsearch/monitor/MonitorModule.java b/core/src/main/java/org/elasticsearch/monitor/MonitorModule.java index 23a64ccabb0..a5b9118e9a5 100644 --- a/core/src/main/java/org/elasticsearch/monitor/MonitorModule.java +++ b/core/src/main/java/org/elasticsearch/monitor/MonitorModule.java @@ -20,27 +20,21 @@ package org.elasticsearch.monitor; import org.elasticsearch.common.inject.AbstractModule; -import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.monitor.fs.FsProbe; import org.elasticsearch.monitor.fs.FsService; import org.elasticsearch.monitor.fs.JmxFsProbe; -import org.elasticsearch.monitor.fs.SigarFsProbe; import org.elasticsearch.monitor.jvm.JvmMonitorService; import org.elasticsearch.monitor.jvm.JvmService; import org.elasticsearch.monitor.network.JmxNetworkProbe; import org.elasticsearch.monitor.network.NetworkProbe; import org.elasticsearch.monitor.network.NetworkService; -import org.elasticsearch.monitor.network.SigarNetworkProbe; import org.elasticsearch.monitor.os.JmxOsProbe; import org.elasticsearch.monitor.os.OsProbe; import org.elasticsearch.monitor.os.OsService; -import org.elasticsearch.monitor.os.SigarOsProbe; import org.elasticsearch.monitor.process.JmxProcessProbe; import org.elasticsearch.monitor.process.ProcessProbe; import org.elasticsearch.monitor.process.ProcessService; -import org.elasticsearch.monitor.process.SigarProcessProbe; -import org.elasticsearch.monitor.sigar.SigarService; /** * @@ -59,29 +53,12 @@ public class MonitorModule extends AbstractModule { @Override protected void configure() { - boolean sigarLoaded = false; - try { - settings.getClassLoader().loadClass("org.hyperic.sigar.Sigar"); - SigarService sigarService = new SigarService(settings); - if (sigarService.sigarAvailable()) { - bind(SigarService.class).toInstance(sigarService); - bind(ProcessProbe.class).to(SigarProcessProbe.class).asEagerSingleton(); - bind(OsProbe.class).to(SigarOsProbe.class).asEagerSingleton(); - bind(NetworkProbe.class).to(SigarNetworkProbe.class).asEagerSingleton(); - bind(FsProbe.class).to(SigarFsProbe.class).asEagerSingleton(); - sigarLoaded = true; - } - } catch (Throwable e) { - // no sigar - Loggers.getLogger(SigarService.class).trace("failed to load sigar", e); - } - if (!sigarLoaded) { - // bind non sigar implementations - bind(ProcessProbe.class).to(JmxProcessProbe.class).asEagerSingleton(); - bind(OsProbe.class).to(JmxOsProbe.class).asEagerSingleton(); - bind(NetworkProbe.class).to(JmxNetworkProbe.class).asEagerSingleton(); - bind(FsProbe.class).to(JmxFsProbe.class).asEagerSingleton(); - } + // bind default implementations + bind(ProcessProbe.class).to(JmxProcessProbe.class).asEagerSingleton(); + bind(OsProbe.class).to(JmxOsProbe.class).asEagerSingleton(); + bind(NetworkProbe.class).to(JmxNetworkProbe.class).asEagerSingleton(); + bind(FsProbe.class).to(JmxFsProbe.class).asEagerSingleton(); + // bind other services bind(ProcessService.class).asEagerSingleton(); bind(OsService.class).asEagerSingleton(); diff --git a/core/src/main/java/org/elasticsearch/monitor/fs/SigarFsProbe.java b/core/src/main/java/org/elasticsearch/monitor/fs/SigarFsProbe.java deleted file mode 100644 index 38625dee111..00000000000 --- a/core/src/main/java/org/elasticsearch/monitor/fs/SigarFsProbe.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.monitor.fs; - -import com.google.common.collect.Maps; -import org.elasticsearch.common.component.AbstractComponent; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.env.NodeEnvironment; -import org.elasticsearch.env.NodeEnvironment.NodePath; -import org.elasticsearch.monitor.sigar.SigarService; -import org.hyperic.sigar.FileSystem; -import org.hyperic.sigar.FileSystemMap; -import org.hyperic.sigar.FileSystemUsage; -import org.hyperic.sigar.Sigar; -import org.hyperic.sigar.SigarException; - -import java.nio.file.Path; -import java.util.Map; - -public class SigarFsProbe extends AbstractComponent implements FsProbe { - - private final NodeEnvironment nodeEnv; - - private final SigarService sigarService; - - private Map fileSystems = Maps.newHashMap(); - - @Inject - public SigarFsProbe(Settings settings, NodeEnvironment nodeEnv, SigarService sigarService) { - super(settings); - this.nodeEnv = nodeEnv; - this.sigarService = sigarService; - } - - @Override - public synchronized FsStats stats() { - if (!nodeEnv.hasNodeFile()) { - return new FsStats(System.currentTimeMillis(), new FsStats.Info[0]); - } - NodePath[] nodePaths = nodeEnv.nodePaths(); - FsStats.Info[] infos = new FsStats.Info[nodePaths.length]; - for (int i = 0; i < nodePaths.length; i++) { - NodePath nodePath = nodePaths[i]; - Path dataLocation = nodePath.path; - - FsStats.Info info = new FsStats.Info(); - info.path = dataLocation.toAbsolutePath().toString(); - - try { - FileSystem fileSystem = fileSystems.get(dataLocation); - Sigar sigar = sigarService.sigar(); - if (fileSystem == null) { - FileSystemMap fileSystemMap = sigar.getFileSystemMap(); - if (fileSystemMap != null) { - fileSystem = fileSystemMap.getMountPoint(dataLocation.toAbsolutePath().toString()); - fileSystems.put(dataLocation, fileSystem); - } - } - if (fileSystem != null) { - info.mount = fileSystem.getDirName(); - info.dev = fileSystem.getDevName(); - info.type = fileSystem.getSysTypeName(); - info.spins = nodePath.spins; - - FileSystemUsage fileSystemUsage = sigar.getFileSystemUsage(fileSystem.getDirName()); - if (fileSystemUsage != null) { - // total/free/available seem to be in megabytes? - info.total = fileSystemUsage.getTotal() * 1024; - info.free = fileSystemUsage.getFree() * 1024; - info.available = fileSystemUsage.getAvail() * 1024; - info.diskReads = fileSystemUsage.getDiskReads(); - info.diskWrites = fileSystemUsage.getDiskWrites(); - info.diskReadBytes = fileSystemUsage.getDiskReadBytes(); - info.diskWriteBytes = fileSystemUsage.getDiskWriteBytes(); - info.diskQueue = fileSystemUsage.getDiskQueue(); - info.diskServiceTime = fileSystemUsage.getDiskServiceTime(); - } - } - } catch (SigarException e) { - // failed... - } - - infos[i] = info; - } - - return new FsStats(System.currentTimeMillis(), infos); - } -} diff --git a/core/src/main/java/org/elasticsearch/monitor/network/SigarNetworkProbe.java b/core/src/main/java/org/elasticsearch/monitor/network/SigarNetworkProbe.java deleted file mode 100644 index 35be3504891..00000000000 --- a/core/src/main/java/org/elasticsearch/monitor/network/SigarNetworkProbe.java +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.monitor.network; - -import org.elasticsearch.common.component.AbstractComponent; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.monitor.sigar.SigarService; -import org.hyperic.sigar.*; - -/** - * - */ -public class SigarNetworkProbe extends AbstractComponent implements NetworkProbe { - - private final SigarService sigarService; - - @Inject - public SigarNetworkProbe(Settings settings, SigarService sigarService) { - super(settings); - this.sigarService = sigarService; - } - - @Override - public NetworkInfo networkInfo() { - Sigar sigar = sigarService.sigar(); - - NetworkInfo networkInfo = new NetworkInfo(); - - try { - NetInterfaceConfig netInterfaceConfig = sigar.getNetInterfaceConfig(null); - networkInfo.primary = new NetworkInfo.Interface(netInterfaceConfig.getName(), netInterfaceConfig.getAddress(), netInterfaceConfig.getHwaddr()); - } catch (SigarException e) { - // ignore - } - - return networkInfo; - } - - @Override - public synchronized NetworkStats networkStats() { - Sigar sigar = sigarService.sigar(); - - NetworkStats stats = new NetworkStats(); - stats.timestamp = System.currentTimeMillis(); - - try { - Tcp tcp = sigar.getTcp(); - stats.tcp = new NetworkStats.Tcp(); - stats.tcp.activeOpens = tcp.getActiveOpens(); - stats.tcp.passiveOpens = tcp.getPassiveOpens(); - stats.tcp.attemptFails = tcp.getAttemptFails(); - stats.tcp.estabResets = tcp.getEstabResets(); - stats.tcp.currEstab = tcp.getCurrEstab(); - stats.tcp.inSegs = tcp.getInSegs(); - stats.tcp.outSegs = tcp.getOutSegs(); - stats.tcp.retransSegs = tcp.getRetransSegs(); - stats.tcp.inErrs = tcp.getInErrs(); - stats.tcp.outRsts = tcp.getOutRsts(); - } catch (SigarException e) { - // ignore - } - - return stats; - } - - @Override - public String ifconfig() { - Sigar sigar = sigarService.sigar(); - StringBuilder sb = new StringBuilder(); - try { - for (String ifname : sigar.getNetInterfaceList()) { - NetInterfaceConfig ifconfig = null; - try { - ifconfig = sigar.getNetInterfaceConfig(ifname); - } catch (SigarException e) { - sb.append(ifname + "\t" + "Not Avaialbe [" + e.getMessage() + "]"); - continue; - } - long flags = ifconfig.getFlags(); - - String hwaddr = ""; - if (!NetFlags.NULL_HWADDR.equals(ifconfig.getHwaddr())) { - hwaddr = " HWaddr " + ifconfig.getHwaddr(); - } - - if (!ifconfig.getName().equals(ifconfig.getDescription())) { - sb.append(ifconfig.getDescription()).append('\n'); - } - - sb.append(ifconfig.getName() + "\t" + "Link encap:" + ifconfig.getType() + hwaddr).append('\n'); - - String ptp = ""; - if ((flags & NetFlags.IFF_POINTOPOINT) > 0) { - ptp = " P-t-P:" + ifconfig.getDestination(); - } - - String bcast = ""; - if ((flags & NetFlags.IFF_BROADCAST) > 0) { - bcast = " Bcast:" + ifconfig.getBroadcast(); - } - - sb.append("\t" + - "inet addr:" + ifconfig.getAddress() + - ptp + //unlikely - bcast + - " Mask:" + ifconfig.getNetmask()).append('\n'); - - sb.append("\t" + - NetFlags.getIfFlagsString(flags) + - " MTU:" + ifconfig.getMtu() + - " Metric:" + ifconfig.getMetric()).append('\n'); - try { - NetInterfaceStat ifstat = sigar.getNetInterfaceStat(ifname); - - sb.append("\t" + - "RX packets:" + ifstat.getRxPackets() + - " errors:" + ifstat.getRxErrors() + - " dropped:" + ifstat.getRxDropped() + - " overruns:" + ifstat.getRxOverruns() + - " frame:" + ifstat.getRxFrame()).append('\n'); - - sb.append("\t" + - "TX packets:" + ifstat.getTxPackets() + - " errors:" + ifstat.getTxErrors() + - " dropped:" + ifstat.getTxDropped() + - " overruns:" + ifstat.getTxOverruns() + - " carrier:" + ifstat.getTxCarrier()).append('\n'); - sb.append("\t" + "collisions:" + - ifstat.getTxCollisions()).append('\n'); - - long rxBytes = ifstat.getRxBytes(); - long txBytes = ifstat.getTxBytes(); - - sb.append("\t" + - "RX bytes:" + rxBytes + - " (" + Sigar.formatSize(rxBytes) + ")" + - " " + - "TX bytes:" + txBytes + - " (" + Sigar.formatSize(txBytes) + ")").append('\n'); - } catch (SigarException e) { - } - } - return sb.toString(); - } catch (SigarException e) { - return "NA"; - } - } -} diff --git a/core/src/main/java/org/elasticsearch/monitor/os/SigarOsProbe.java b/core/src/main/java/org/elasticsearch/monitor/os/SigarOsProbe.java deleted file mode 100644 index 87f00199c82..00000000000 --- a/core/src/main/java/org/elasticsearch/monitor/os/SigarOsProbe.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.monitor.os; - -import org.elasticsearch.common.component.AbstractComponent; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.monitor.sigar.SigarService; -import org.hyperic.sigar.*; - -/** - * - */ -public class SigarOsProbe extends AbstractComponent implements OsProbe { - - private final SigarService sigarService; - - @Inject - public SigarOsProbe(Settings settings, SigarService sigarService) { - super(settings); - this.sigarService = sigarService; - } - - @Override - public OsInfo osInfo() { - Sigar sigar = sigarService.sigar(); - OsInfo info = new OsInfo(); - try { - CpuInfo[] infos = sigar.getCpuInfoList(); - info.cpu = new OsInfo.Cpu(); - info.cpu.vendor = infos[0].getVendor(); - info.cpu.model = infos[0].getModel(); - info.cpu.mhz = infos[0].getMhz(); - info.cpu.totalCores = infos[0].getTotalCores(); - info.cpu.totalSockets = infos[0].getTotalSockets(); - info.cpu.coresPerSocket = infos[0].getCoresPerSocket(); - if (infos[0].getCacheSize() != Sigar.FIELD_NOTIMPL) { - info.cpu.cacheSize = infos[0].getCacheSize(); - } - } catch (SigarException e) { - // ignore - } - - try { - Mem mem = sigar.getMem(); - info.mem = new OsInfo.Mem(); - info.mem.total = mem.getTotal(); - } catch (SigarException e) { - // ignore - } - - try { - Swap swap = sigar.getSwap(); - info.swap = new OsInfo.Swap(); - info.swap.total = swap.getTotal(); - } catch (SigarException e) { - // ignore - } - - - return info; - } - - @Override - public OsStats osStats() { - Sigar sigar = sigarService.sigar(); - OsStats stats = new OsStats(); - stats.timestamp = System.currentTimeMillis(); - try { - stats.loadAverage = sigar.getLoadAverage(); - } catch (SigarException e) { - // ignore - } - - try { - stats.uptime = (long) sigar.getUptime().getUptime(); - } catch (SigarException e) { - // ignore - } - - try { - CpuPerc cpuPerc = sigar.getCpuPerc(); - stats.cpu = new OsStats.Cpu(); - stats.cpu.sys = (short) (cpuPerc.getSys() * 100); - stats.cpu.user = (short) (cpuPerc.getUser() * 100); - stats.cpu.idle = (short) (cpuPerc.getIdle() * 100); - stats.cpu.stolen = (short) (cpuPerc.getStolen() * 100); - } catch (SigarException e) { - // ignore - } - - try { - Mem mem = sigar.getMem(); - stats.mem = new OsStats.Mem(); - stats.mem.free = mem.getFree(); - stats.mem.freePercent = (short) mem.getFreePercent(); - stats.mem.used = mem.getUsed(); - stats.mem.usedPercent = (short) mem.getUsedPercent(); - stats.mem.actualFree = mem.getActualFree(); - stats.mem.actualUsed = mem.getActualUsed(); - } catch (SigarException e) { - // ignore - } - - try { - Swap swap = sigar.getSwap(); - stats.swap = new OsStats.Swap(); - stats.swap.free = swap.getFree(); - stats.swap.used = swap.getUsed(); - } catch (SigarException e) { - // ignore - } - - return stats; - } -} diff --git a/core/src/main/java/org/elasticsearch/monitor/process/SigarProcessProbe.java b/core/src/main/java/org/elasticsearch/monitor/process/SigarProcessProbe.java deleted file mode 100644 index d24d6aa27bc..00000000000 --- a/core/src/main/java/org/elasticsearch/monitor/process/SigarProcessProbe.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.monitor.process; - -import org.elasticsearch.common.component.AbstractComponent; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.monitor.sigar.SigarService; -import org.hyperic.sigar.ProcCpu; -import org.hyperic.sigar.ProcMem; -import org.hyperic.sigar.Sigar; -import org.hyperic.sigar.SigarException; - -/** - * - */ -public class SigarProcessProbe extends AbstractComponent implements ProcessProbe { - - private final SigarService sigarService; - - @Inject - public SigarProcessProbe(Settings settings, SigarService sigarService) { - super(settings); - this.sigarService = sigarService; - } - - @Override - public synchronized ProcessInfo processInfo() { - return new ProcessInfo(sigarService.sigar().getPid(), JmxProcessProbe.getMaxFileDescriptorCount()); - } - - @Override - public synchronized ProcessStats processStats() { - Sigar sigar = sigarService.sigar(); - ProcessStats stats = new ProcessStats(); - stats.timestamp = System.currentTimeMillis(); - stats.openFileDescriptors = JmxProcessProbe.getOpenFileDescriptorCount(); - try { - if (stats.openFileDescriptors == -1) { - stats.openFileDescriptors = sigar.getProcFd(sigar.getPid()).getTotal(); - } - ProcCpu cpu = sigar.getProcCpu(sigar.getPid()); - stats.cpu = new ProcessStats.Cpu(); - stats.cpu.percent = (short) (cpu.getPercent() * 100); - stats.cpu.sys = cpu.getSys(); - stats.cpu.user = cpu.getUser(); - stats.cpu.total = cpu.getTotal(); - } catch (SigarException e) { - // ignore - } - - try { - ProcMem mem = sigar.getProcMem(sigar.getPid()); - stats.mem = new ProcessStats.Mem(); - stats.mem.totalVirtual = mem.getSize(); - stats.mem.resident = mem.getResident(); - stats.mem.share = mem.getShare(); - } catch (SigarException e) { - // ignore - } - - return stats; - } -} diff --git a/core/src/main/java/org/elasticsearch/monitor/sigar/SigarService.java b/core/src/main/java/org/elasticsearch/monitor/sigar/SigarService.java deleted file mode 100644 index f13dd35643c..00000000000 --- a/core/src/main/java/org/elasticsearch/monitor/sigar/SigarService.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.monitor.sigar; - -import org.elasticsearch.common.component.AbstractComponent; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.settings.Settings; -import org.hyperic.sigar.Sigar; - -/** - * - */ -public class SigarService extends AbstractComponent { - - private final Sigar sigar; - - @Inject - public SigarService(Settings settings) { - super(settings); - Sigar sigar = null; - if (settings.getAsBoolean("bootstrap.sigar", true)) { - try { - sigar = new Sigar(); - // call it to make sure the library was loaded - sigar.getPid(); - logger.trace("sigar loaded successfully"); - } catch (Throwable t) { - logger.trace("failed to load sigar", t); - if (sigar != null) { - try { - sigar.close(); - } catch (Throwable t1) { - // ignore - } finally { - sigar = null; - } - } - } - } - this.sigar = sigar; - } - - public boolean sigarAvailable() { - return sigar != null; - } - - public Sigar sigar() { - return this.sigar; - } -} diff --git a/core/src/test/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsTests.java b/core/src/test/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsTests.java index 9945eceaa5c..13c0ffa7cc1 100644 --- a/core/src/test/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsTests.java +++ b/core/src/test/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsTests.java @@ -26,7 +26,6 @@ import org.elasticsearch.client.Requests; import org.elasticsearch.common.Priority; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.store.Store; -import org.elasticsearch.monitor.sigar.SigarService; import org.elasticsearch.test.ElasticsearchIntegrationTest; import org.elasticsearch.test.ElasticsearchIntegrationTest.ClusterScope; import org.hamcrest.Matchers; @@ -134,7 +133,6 @@ public class ClusterStatsTests extends ElasticsearchIntegrationTest { public void testValuesSmokeScreen() throws IOException { internalCluster().ensureAtMostNumDataNodes(5); internalCluster().ensureAtLeastNumDataNodes(1); - SigarService sigarService = internalCluster().getInstance(SigarService.class); assertAcked(prepareCreate("test1").setSettings(settingsBuilder().put(Store.INDEX_STORE_STATS_REFRESH_INTERVAL, 0).build())); index("test1", "type", "1", "f", "f"); /* @@ -150,12 +148,7 @@ public class ClusterStatsTests extends ElasticsearchIntegrationTest { assertThat(msg, response.nodesStats.getFs().getTotal().bytes(), Matchers.greaterThan(0l)); assertThat(msg, response.nodesStats.getJvm().getVersions().size(), Matchers.greaterThan(0)); - if (sigarService.sigarAvailable()) { - // We only get those if we have sigar - assertThat(msg, response.nodesStats.getOs().getAvailableProcessors(), Matchers.greaterThan(0)); - assertThat(msg, response.nodesStats.getOs().getAvailableMemory().bytes(), Matchers.greaterThan(0l)); - assertThat(msg, response.nodesStats.getOs().getCpus().size(), Matchers.greaterThan(0)); - } + assertThat(msg, response.nodesStats.getVersions().size(), Matchers.greaterThan(0)); assertThat(msg, response.nodesStats.getVersions().contains(Version.CURRENT), Matchers.equalTo(true)); assertThat(msg, response.nodesStats.getPlugins().size(), Matchers.greaterThanOrEqualTo(0)); diff --git a/core/src/test/java/org/elasticsearch/benchmark/mapping/ManyMappingsBenchmark.java b/core/src/test/java/org/elasticsearch/benchmark/mapping/ManyMappingsBenchmark.java index b40d29a948c..5a347ef1029 100644 --- a/core/src/test/java/org/elasticsearch/benchmark/mapping/ManyMappingsBenchmark.java +++ b/core/src/test/java/org/elasticsearch/benchmark/mapping/ManyMappingsBenchmark.java @@ -85,7 +85,7 @@ public class ManyMappingsBenchmark { public static void main(String[] args) throws Exception { System.setProperty("es.logger.prefix", ""); - Bootstrap.initializeNatives(true, false, false); + Bootstrap.initializeNatives(true, false); Settings settings = settingsBuilder() .put("") .put(SETTING_NUMBER_OF_SHARDS, 5) diff --git a/core/src/test/java/org/elasticsearch/benchmark/recovery/ReplicaRecoveryBenchmark.java b/core/src/test/java/org/elasticsearch/benchmark/recovery/ReplicaRecoveryBenchmark.java index 1ac7c433038..0d3375d1c6b 100644 --- a/core/src/test/java/org/elasticsearch/benchmark/recovery/ReplicaRecoveryBenchmark.java +++ b/core/src/test/java/org/elasticsearch/benchmark/recovery/ReplicaRecoveryBenchmark.java @@ -57,7 +57,7 @@ public class ReplicaRecoveryBenchmark { public static void main(String[] args) throws Exception { System.setProperty("es.logger.prefix", ""); - Bootstrap.initializeNatives(true, false, false); + Bootstrap.initializeNatives(true, false); Settings settings = settingsBuilder() .put("gateway.type", "local") diff --git a/core/src/test/java/org/elasticsearch/benchmark/search/aggregations/GlobalOrdinalsBenchmark.java b/core/src/test/java/org/elasticsearch/benchmark/search/aggregations/GlobalOrdinalsBenchmark.java index c415dbf9b2b..808d64d0323 100644 --- a/core/src/test/java/org/elasticsearch/benchmark/search/aggregations/GlobalOrdinalsBenchmark.java +++ b/core/src/test/java/org/elasticsearch/benchmark/search/aggregations/GlobalOrdinalsBenchmark.java @@ -66,7 +66,7 @@ public class GlobalOrdinalsBenchmark { public static void main(String[] args) throws Exception { System.setProperty("es.logger.prefix", ""); - Bootstrap.initializeNatives(true, false, false); + Bootstrap.initializeNatives(true, false); Random random = new Random(); Settings settings = settingsBuilder() diff --git a/core/src/test/java/org/elasticsearch/benchmark/search/aggregations/SubAggregationSearchCollectModeBenchmark.java b/core/src/test/java/org/elasticsearch/benchmark/search/aggregations/SubAggregationSearchCollectModeBenchmark.java index bf13b774edc..91fc72b8d57 100644 --- a/core/src/test/java/org/elasticsearch/benchmark/search/aggregations/SubAggregationSearchCollectModeBenchmark.java +++ b/core/src/test/java/org/elasticsearch/benchmark/search/aggregations/SubAggregationSearchCollectModeBenchmark.java @@ -71,7 +71,7 @@ public class SubAggregationSearchCollectModeBenchmark { static Node[] nodes; public static void main(String[] args) throws Exception { - Bootstrap.initializeNatives(true, false, false); + Bootstrap.initializeNatives(true, false); Random random = new Random(); Settings settings = settingsBuilder() diff --git a/core/src/test/java/org/elasticsearch/benchmark/search/aggregations/TermsAggregationSearchAndIndexingBenchmark.java b/core/src/test/java/org/elasticsearch/benchmark/search/aggregations/TermsAggregationSearchAndIndexingBenchmark.java index 45f7dbf9562..517f6bac531 100644 --- a/core/src/test/java/org/elasticsearch/benchmark/search/aggregations/TermsAggregationSearchAndIndexingBenchmark.java +++ b/core/src/test/java/org/elasticsearch/benchmark/search/aggregations/TermsAggregationSearchAndIndexingBenchmark.java @@ -71,7 +71,7 @@ public class TermsAggregationSearchAndIndexingBenchmark { static Node[] nodes; public static void main(String[] args) throws Exception { - Bootstrap.initializeNatives(true, false, false); + Bootstrap.initializeNatives(true, false); Settings settings = settingsBuilder() .put("refresh_interval", "-1") .put(SETTING_NUMBER_OF_SHARDS, 1) diff --git a/core/src/test/java/org/elasticsearch/benchmark/search/aggregations/TermsAggregationSearchBenchmark.java b/core/src/test/java/org/elasticsearch/benchmark/search/aggregations/TermsAggregationSearchBenchmark.java index 71ddbfcb908..e669b0d4f93 100644 --- a/core/src/test/java/org/elasticsearch/benchmark/search/aggregations/TermsAggregationSearchBenchmark.java +++ b/core/src/test/java/org/elasticsearch/benchmark/search/aggregations/TermsAggregationSearchBenchmark.java @@ -99,7 +99,7 @@ public class TermsAggregationSearchBenchmark { } public static void main(String[] args) throws Exception { - Bootstrap.initializeNatives(true, false, false); + Bootstrap.initializeNatives(true, false); Random random = new Random(); Settings settings = settingsBuilder() diff --git a/core/src/test/java/org/elasticsearch/bootstrap/BootstrapForTesting.java b/core/src/test/java/org/elasticsearch/bootstrap/BootstrapForTesting.java index e73805ff995..083affa50b1 100644 --- a/core/src/test/java/org/elasticsearch/bootstrap/BootstrapForTesting.java +++ b/core/src/test/java/org/elasticsearch/bootstrap/BootstrapForTesting.java @@ -50,7 +50,7 @@ public class BootstrapForTesting { static { // just like bootstrap, initialize natives, then SM - Bootstrap.initializeNatives(true, true, true); + Bootstrap.initializeNatives(true, true); // check for jar hell try { @@ -85,8 +85,6 @@ public class BootstrapForTesting { // target/classes, target/test-classes Security.addPath(perms, basedir.resolve("target").resolve("classes"), "read,readlink"); Security.addPath(perms, basedir.resolve("target").resolve("test-classes"), "read,readlink"); - // lib/sigar - Security.addPath(perms, basedir.resolve("lib").resolve("sigar"), "read,readlink"); // .m2/repository Path m2repoDir = PathUtils.get(Objects.requireNonNull(System.getProperty("m2.repository"), "please set ${m2.repository} in pom.xml")); diff --git a/core/src/test/java/org/elasticsearch/monitor/SigarTests.java b/core/src/test/java/org/elasticsearch/monitor/SigarTests.java deleted file mode 100644 index f582c2fdc1c..00000000000 --- a/core/src/test/java/org/elasticsearch/monitor/SigarTests.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.monitor; - -import org.elasticsearch.test.ElasticsearchTestCase; -import org.hyperic.sigar.Sigar; - -public class SigarTests extends ElasticsearchTestCase { - - @Override - public void setUp() throws Exception { - super.setUp(); - assumeTrue("we can only ensure sigar is working when running from maven", - Boolean.parseBoolean(System.getProperty("tests.maven"))); - } - - public void testSigarLoads() throws Exception { - Sigar.load(); - } - - public void testSigarWorks() throws Exception { - Sigar sigar = new Sigar(); - assertNotNull(sigar.getCpu()); - } -} diff --git a/core/src/test/java/org/elasticsearch/test/InternalTestCluster.java b/core/src/test/java/org/elasticsearch/test/InternalTestCluster.java index b8da49e8345..18e5c9ce083 100644 --- a/core/src/test/java/org/elasticsearch/test/InternalTestCluster.java +++ b/core/src/test/java/org/elasticsearch/test/InternalTestCluster.java @@ -279,7 +279,6 @@ public final class InternalTestCluster extends TestCluster { builder.put("path.data", dataPath.toString()); } } - builder.put("bootstrap.sigar", rarely(random)); builder.put("path.home", baseDir); builder.put("path.repo", baseDir.resolve("repos")); builder.put("transport.tcp.port", BASE_PORT + "-" + (BASE_PORT+100)); diff --git a/dev-tools/ElasticSearch.launch b/dev-tools/ElasticSearch.launch index 7574d20b39f..c501e4b8818 100644 --- a/dev-tools/ElasticSearch.launch +++ b/dev-tools/ElasticSearch.launch @@ -13,5 +13,5 @@ - + diff --git a/plugins/pom.xml b/plugins/pom.xml index df9aa1b7394..acc9af82ec2 100644 --- a/plugins/pom.xml +++ b/plugins/pom.xml @@ -207,11 +207,6 @@ jna provided - - org.fusesource - sigar - provided - org.apache.httpcomponents diff --git a/pom.xml b/pom.xml index b637996bb0e..43678cb4c42 100644 --- a/pom.xml +++ b/pom.xml @@ -430,24 +430,6 @@ true - - org.fusesource - sigar - 1.6.4 - - - - - org.jacoco @@ -624,7 +606,6 @@ -Xmx${tests.heap.size} -Xms${tests.heap.size} ${java.permGenSpace} - -Djava.library.path=${project.basedir}/lib/sigar -XX:MaxDirectMemorySize=512m -Des.logger.prefix= -XX:+HeapDumpOnOutOfMemoryError From d74eac94f228a1b9f819cff79660d86d9faf1fb3 Mon Sep 17 00:00:00 2001 From: Boaz Leskes Date: Fri, 3 Jul 2015 12:33:46 +0200 Subject: [PATCH 04/10] ZenDiscovery: #11960 failed to remove eager reroute from node join It is removed now :) Closes #12019 --- .../elasticsearch/discovery/zen/ZenDiscovery.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java b/core/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java index baf6a4a7fdb..57dbcb98a68 100644 --- a/core/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java +++ b/core/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java @@ -30,6 +30,7 @@ import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.cluster.routing.RoutingNode; import org.elasticsearch.cluster.routing.RoutingService; import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; import org.elasticsearch.cluster.service.InternalClusterService; @@ -939,14 +940,15 @@ public class ZenDiscovery extends AbstractLifecycleComponent implemen } } - ClusterState.Builder stateBuilder = ClusterState.builder(currentState); + + // we must return a new cluster state instance to force publishing. This is important + // for the joining node to finalize it's join and set us as a master + final ClusterState.Builder newState = ClusterState.builder(currentState); if (nodeAdded) { - stateBuilder.nodes(nodesBuilder); + newState.nodes(nodesBuilder); } - currentState = stateBuilder.build(); - // eagerly run reroute to apply the node addition - RoutingAllocation.Result result = routingService.getAllocationService().reroute(currentState); - return ClusterState.builder(currentState).routingResult(result).build(); + + return newState.build(); } @Override From 1e5e4439ce8baceb62d1bfd6ea139bded30769d5 Mon Sep 17 00:00:00 2001 From: Clinton Gormley Date: Sun, 5 Jul 2015 18:24:06 +0200 Subject: [PATCH 05/10] Merge pull request #11983 from cdosborn/patch-1 Grammar fix to match query docs --- docs/reference/query-dsl/match-query.asciidoc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/reference/query-dsl/match-query.asciidoc b/docs/reference/query-dsl/match-query.asciidoc index 26029e0bb17..f98baad0822 100644 --- a/docs/reference/query-dsl/match-query.asciidoc +++ b/docs/reference/query-dsl/match-query.asciidoc @@ -1,8 +1,9 @@ [[query-dsl-match-query]] === Match Query -A family of `match` queries that accept text/numerics/dates, analyzes -it, and constructs a query out of it. For example: + +A family of `match` queries that accepts text/numerics/dates, analyzes +them, and constructs a query. For example: [source,js] -------------------------------------------------- From c5d3c4694389a5b035559e0abc8844d0c71f43ec Mon Sep 17 00:00:00 2001 From: Clinton Gormley Date: Sun, 5 Jul 2015 20:24:25 +0200 Subject: [PATCH 06/10] Added build and test labels to es release notes script --- dev-tools/es_release_notes.pl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dev-tools/es_release_notes.pl b/dev-tools/es_release_notes.pl index 7e65731a411..464678560f4 100644 --- a/dev-tools/es_release_notes.pl +++ b/dev-tools/es_release_notes.pl @@ -28,8 +28,8 @@ my $User_Repo = 'elastic/elasticsearch/'; my $Issue_URL = "http://github.com/${User_Repo}issues/"; my @Groups = qw( - breaking deprecation feature - enhancement bug regression doc test + breaking deprecation feature + enhancement bug regression build doc test ); my %Group_Labels = ( breaking => 'Breaking changes', @@ -41,7 +41,7 @@ my %Group_Labels = ( bug => 'Bug fixes', regression => 'Regression', test => 'Tests', - other => 'Not classified', + other => 'NOT CLASSIFIED', ); use JSON(); From d0850887931e662689f40c17bbb60fa380523ca1 Mon Sep 17 00:00:00 2001 From: javanna Date: Mon, 6 Jul 2015 11:02:09 +0200 Subject: [PATCH 07/10] BoolQueryBuilder#hasClauses to take into account filterClauses too --- .../java/org/elasticsearch/index/query/BoolQueryBuilder.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/index/query/BoolQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/BoolQueryBuilder.java index 56cee6e38fc..c3776673101 100644 --- a/core/src/main/java/org/elasticsearch/index/query/BoolQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/BoolQueryBuilder.java @@ -133,11 +133,11 @@ public class BoolQueryBuilder extends QueryBuilder implements BoostableQueryBuil } /** - * Returns true iff this query builder has at least one should, must or mustNot clause. + * Returns true iff this query builder has at least one should, must, must not or filter clause. * Otherwise false. */ public boolean hasClauses() { - return !(mustClauses.isEmpty() && shouldClauses.isEmpty() && mustNotClauses.isEmpty()); + return !(mustClauses.isEmpty() && shouldClauses.isEmpty() && mustNotClauses.isEmpty() && filterClauses.isEmpty()); } /** From f95981b97760ae8f2b248f143f360173b7572918 Mon Sep 17 00:00:00 2001 From: markharwood Date: Fri, 3 Jul 2015 17:29:45 +0100 Subject: [PATCH 08/10] =?UTF-8?q?Search=20enhancement:=20adds=20a=20specia?= =?UTF-8?q?l=20case=20for=20the=20=E2=80=9C=5Findex=E2=80=9D=20field=20whi?= =?UTF-8?q?ch=20allows=20queries=20to=20test=20the=20name=20of=20the=20ind?= =?UTF-8?q?ex.=20Adding=20this=20capability=20means=20we=20can=20deprecate?= =?UTF-8?q?=20the=20specialist=20indices=20query.=20IndexFieldMapper=20is?= =?UTF-8?q?=20changed=20to=20make=20the=20term=20query=20factories=20produ?= =?UTF-8?q?ce=20match=5Fall=20or=20match=5Fnone=20queries=20based=20on=20t?= =?UTF-8?q?ests=20on=20the=20index=20name.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #3316 --- .../mapper/internal/IndexFieldMapper.java | 62 ++++++++++++++++++- .../search/query/SearchQueryTests.java | 52 ++++++++++++++++ 2 files changed, 113 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/elasticsearch/index/mapper/internal/IndexFieldMapper.java b/core/src/main/java/org/elasticsearch/index/mapper/internal/IndexFieldMapper.java index 513dd1a8841..aa9d9669d56 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/internal/IndexFieldMapper.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/internal/IndexFieldMapper.java @@ -22,10 +22,13 @@ package org.elasticsearch.index.mapper.internal; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.index.IndexOptions; +import org.apache.lucene.search.Query; +import org.apache.lucene.util.BytesRef; import org.elasticsearch.Version; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Strings; import org.elasticsearch.common.lucene.Lucene; +import org.elasticsearch.common.lucene.search.Queries; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.index.fielddata.FieldDataType; @@ -34,9 +37,10 @@ import org.elasticsearch.index.mapper.Mapper; import org.elasticsearch.index.mapper.MapperParsingException; import org.elasticsearch.index.mapper.MergeMappingException; import org.elasticsearch.index.mapper.MergeResult; -import org.elasticsearch.index.mapper.ParseContext; import org.elasticsearch.index.mapper.MetadataFieldMapper; +import org.elasticsearch.index.mapper.ParseContext; import org.elasticsearch.index.mapper.core.AbstractFieldMapper; +import org.elasticsearch.index.query.QueryParseContext; import java.io.IOException; import java.util.Iterator; @@ -135,6 +139,62 @@ public class IndexFieldMapper extends MetadataFieldMapper { return CONTENT_TYPE; } + @Override + public boolean useTermQueryWithQueryString() { + // As we spoof the presence of an indexed field we have to override + // the default of returning false which otherwise leads MatchQuery + // et al to run an analyzer over the query string and then try to + // hit the search index. We need them to use our termQuery(..) + // method which checks index names + return true; + } + + /** + * This termQuery impl looks at the context to determine the index that + * is being queried and then returns a MATCH_ALL_QUERY or MATCH_NO_QUERY + * if the value matches this index. This can be useful if aliases or + * wildcards are used but the aim is to restrict the query to specific + * indices + */ + @Override + public Query termQuery(Object value, @Nullable QueryParseContext context) { + if (context == null) { + return super.termQuery(value, context); + } + if (isSameIndex(value, context.index().getName())) { + return Queries.newMatchAllQuery(); + } else { + return Queries.newMatchNoDocsQuery(); + } + } + + + + @Override + public Query termsQuery(List values, QueryParseContext context) { + if (context == null) { + return super.termsQuery(values, context); + } + for (Object value : values) { + if (isSameIndex(value, context.index().getName())) { + // No need to OR these clauses - we can only logically be + // running in the context of just one of these index names. + return Queries.newMatchAllQuery(); + } + } + // None of the listed index names are this one + return Queries.newMatchNoDocsQuery(); + } + + private boolean isSameIndex(Object value, String indexName) { + if (value instanceof BytesRef) { + BytesRef indexNameRef = new BytesRef(indexName); + return (indexNameRef.bytesEquals((BytesRef) value)); + } else { + return indexName.equals(value.toString()); + } + } + @Override public String value(Object value) { if (value == null) { diff --git a/core/src/test/java/org/elasticsearch/search/query/SearchQueryTests.java b/core/src/test/java/org/elasticsearch/search/query/SearchQueryTests.java index ee08d41c71e..21b2c83af76 100644 --- a/core/src/test/java/org/elasticsearch/search/query/SearchQueryTests.java +++ b/core/src/test/java/org/elasticsearch/search/query/SearchQueryTests.java @@ -699,6 +699,58 @@ public class SearchQueryTests extends ElasticsearchIntegrationTest { assertSearchHits(searchResponse, "1", "3"); } + @Test + public void term_indexQueryTestsIndexed() throws Exception { + term_indexQueryTests("not_analyzed"); + } + + @Test + public void term_indexQueryTestsNotIndexed() throws Exception { + term_indexQueryTests("no"); + } + + private void term_indexQueryTests(String index) throws Exception { + Settings indexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_1_4_2.id).build(); + String[] indexNames = { "test1", "test2" }; + for (String indexName : indexNames) { + assertAcked(client() + .admin() + .indices() + .prepareCreate(indexName) + .setSettings(indexSettings) + .addMapping( + "type1", + jsonBuilder().startObject().startObject("type1").startObject("_index").field("index", index).endObject() + .endObject().endObject())); + + indexRandom(true, client().prepareIndex(indexName, "type1", indexName + "1").setSource("field1", "value1")); + + } + for (String indexName : indexNames) { + SearchResponse request = client().prepareSearch().setQuery(constantScoreQuery(termQuery("_index", indexName))).get(); + SearchResponse searchResponse = assertSearchResponse(request); + assertHitCount(searchResponse, 1l); + assertSearchHits(searchResponse, indexName + "1"); + } + for (String indexName : indexNames) { + SearchResponse request = client().prepareSearch().setQuery(constantScoreQuery(termsQuery("_index", indexName))).get(); + SearchResponse searchResponse = assertSearchResponse(request); + assertHitCount(searchResponse, 1l); + assertSearchHits(searchResponse, indexName + "1"); + } + for (String indexName : indexNames) { + SearchResponse request = client().prepareSearch().setQuery(constantScoreQuery(matchQuery("_index", indexName))).get(); + SearchResponse searchResponse = assertSearchResponse(request); + assertHitCount(searchResponse, 1l); + assertSearchHits(searchResponse, indexName + "1"); + } + { + SearchResponse request = client().prepareSearch().setQuery(constantScoreQuery(termsQuery("_index", indexNames))).get(); + SearchResponse searchResponse = assertSearchResponse(request); + assertHitCount(searchResponse, indexNames.length); + } + } + @Test public void testLimitFilter() throws Exception { assertAcked(client().admin().indices().prepareCreate("test").setSettings(SETTING_NUMBER_OF_SHARDS, 1)); From b93512e000219e2968150146cd7c9242dd910037 Mon Sep 17 00:00:00 2001 From: Colin Goodheart-Smithe Date: Mon, 6 Jul 2015 12:04:22 +0100 Subject: [PATCH 09/10] [TEST] NettyTransportMultiPortTests now checks selected random ports are free before using them --- .../netty/NettyTransportMultiPortTests.java | 32 +++++++++++++++---- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/core/src/test/java/org/elasticsearch/transport/netty/NettyTransportMultiPortTests.java b/core/src/test/java/org/elasticsearch/transport/netty/NettyTransportMultiPortTests.java index 213500dc4df..016dfe4b836 100644 --- a/core/src/test/java/org/elasticsearch/transport/netty/NettyTransportMultiPortTests.java +++ b/core/src/test/java/org/elasticsearch/transport/netty/NettyTransportMultiPortTests.java @@ -20,6 +20,7 @@ package org.elasticsearch.transport.netty; import com.carrotsearch.hppc.IntHashSet; import com.google.common.base.Charsets; + import org.elasticsearch.Version; import org.elasticsearch.cache.recycler.PageCacheRecycler; import org.elasticsearch.common.component.Lifecycle; @@ -30,8 +31,8 @@ import org.elasticsearch.common.transport.InetSocketTransportAddress; import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.indices.breaker.NoneCircuitBreakerService; import org.elasticsearch.test.ElasticsearchTestCase; -import org.elasticsearch.test.junit.rule.RepeatOnExceptionRule; import org.elasticsearch.test.cache.recycler.MockBigArrays; +import org.elasticsearch.test.junit.rule.RepeatOnExceptionRule; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.BindTransportException; import org.elasticsearch.transport.TransportService; @@ -42,6 +43,7 @@ import java.io.IOException; import java.io.OutputStream; import java.net.InetAddress; import java.net.InetSocketAddress; +import java.net.ServerSocket; import java.net.Socket; import static org.elasticsearch.common.settings.Settings.settingsBuilder; @@ -181,14 +183,30 @@ public class NettyTransportMultiPortTests extends ElasticsearchTestCase { private int[] getRandomPorts(int numberOfPorts) { IntHashSet ports = new IntHashSet(); + int nextPort = randomIntBetween(49152, 65535); for (int i = 0; i < numberOfPorts; i++) { - int port = randomIntBetween(49152, 65535); - while (ports.contains(port)) { - port = randomIntBetween(49152, 65535); - } - ports.add(port); - } + boolean foundPortInRange = false; + while (!foundPortInRange) { + if (!ports.contains(nextPort)) { + logger.debug("looking to see if port [{}]is available", nextPort); + try (ServerSocket serverSocket = new ServerSocket()) { + // Set SO_REUSEADDR as we may bind here and not be able + // to reuse the address immediately without it. + serverSocket.setReuseAddress(NetworkUtils.defaultReuseAddress()); + serverSocket.bind(new InetSocketAddress(nextPort)); + // bind was a success + logger.debug("port [{}] available.", nextPort); + foundPortInRange = true; + ports.add(nextPort); + } catch (IOException e) { + // Do nothing + logger.debug("port [{}] not available.", e, nextPort); + } + } + nextPort = randomIntBetween(49152, 65535); + } + } return ports.toArray(); } From 8ef1708395533172e0934865c7c466e66bc01b05 Mon Sep 17 00:00:00 2001 From: Alex Ksikes Date: Mon, 6 Jul 2015 15:27:38 +0200 Subject: [PATCH 10/10] [TEST] fix testMoreLikeThisArtificialDocs Ensure that the indexed doc hasn't all its fields empty and that the artificial doc requested is always routed to the shard having that doc. --- .../elasticsearch/search/morelikethis/MoreLikeThisTests.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/test/java/org/elasticsearch/search/morelikethis/MoreLikeThisTests.java b/core/src/test/java/org/elasticsearch/search/morelikethis/MoreLikeThisTests.java index 70e452edeb9..85c52a36d34 100644 --- a/core/src/test/java/org/elasticsearch/search/morelikethis/MoreLikeThisTests.java +++ b/core/src/test/java/org/elasticsearch/search/morelikethis/MoreLikeThisTests.java @@ -451,14 +451,14 @@ public class MoreLikeThisTests extends ElasticsearchIntegrationTest { logger.info("Indexing a single document ..."); XContentBuilder doc = jsonBuilder().startObject(); for (int i = 0; i < numFields; i++) { - doc.field("field"+i, generateRandomStringArray(5, 10, false)); + doc.field("field"+i, generateRandomStringArray(5, 10, false)+"a"); // make sure they are not all empty } doc.endObject(); indexRandom(true, client().prepareIndex("test", "type1", "0").setSource(doc)); logger.info("Checking the document matches ..."); MoreLikeThisQueryBuilder mltQuery = moreLikeThisQuery() - .like((Item) new Item().doc(doc).index("test").type("type1")) + .like((Item) new Item().doc(doc).index("test").type("type1").routing("0")) // routing to ensure we hit the shard with the doc .minTermFreq(0) .minDocFreq(0) .maxQueryTerms(100)