From 473b0f4dff504690754acc0f00967c275bf322a8 Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Mon, 5 Dec 2011 21:00:10 +0200 Subject: [PATCH] Migrate built in plugins to their own repos, closes #1520. --- .idea/modules.xml | 14 - .idea/modules/elasticsearch-root.iml | 13 - plugins/analysis/icu/build.gradle | 134 --- .../icu/src/main/java/es-plugin.properties | 1 - .../analysis/IcuAnalysisBinderProcessor.java | 37 - .../IcuCollationTokenFilterFactory.java | 104 --- .../IcuFoldingTokenFilterFactory.java | 43 - .../IcuNormalizerTokenFilterFactory.java | 50 -- .../analysis/icu/AnalysisICUPlugin.java | 46 - .../analysis/SimpleIcuAnalysisTests.java | 58 -- plugins/cloud/aws/build.gradle | 140 --- .../aws/src/main/java/es-plugin.properties | 2 - .../cloud/aws/AwsEc2Service.java | 143 --- .../elasticsearch/cloud/aws/AwsModule.java | 33 - .../elasticsearch/cloud/aws/AwsS3Service.java | 135 --- .../cloud/aws/AwsSettingsFilter.java | 36 - .../blobstore/AbstractS3BlobContainer.java | 128 --- .../cloud/aws/blobstore/S3BlobStore.java | 115 --- .../blobstore/S3ImmutableBlobContainer.java | 58 -- .../cloud/aws/network/Ec2NameResolver.java | 138 --- .../aws/node/Ec2CustomNodeAttributes.java | 76 -- .../ec2/AwsEc2UnicastHostsProvider.java | 195 ----- .../discovery/ec2/Ec2Discovery.java | 66 -- .../discovery/ec2/Ec2DiscoveryModule.java | 33 - .../elasticsearch/gateway/s3/S3Gateway.java | 104 --- .../gateway/s3/S3GatewayModule.java | 33 - .../index/gateway/s3/S3IndexGateway.java | 47 - .../gateway/s3/S3IndexGatewayModule.java | 33 - .../index/gateway/s3/S3IndexShardGateway.java | 46 - .../plugin/cloud/aws/CloudAwsPlugin.java | 68 -- plugins/hadoop/build.gradle | 138 --- .../hadoop/src/main/java/es-plugin.properties | 1 - .../hdfs/AbstractHdfsBlobContainer.java | 119 --- .../common/blobstore/hdfs/HdfsBlobStore.java | 111 --- .../hdfs/HdfsImmutableBlobContainer.java | 90 -- .../gateway/hdfs/HdfsGateway.java | 105 --- .../gateway/hdfs/HdfsGatewayModule.java | 33 - .../gateway/hdfs/HdfsIndexGatewayModule.java | 34 - .../index/gateway/hdfs/HdfsIndexGateway.java | 46 - .../gateway/hdfs/HdfsIndexShardGateway.java | 45 - .../plugin/hadoop/HadoopPlugin.java | 36 - .../hadoop/gateway/HdfsGatewayTests.java | 226 ----- plugins/lang/groovy/build.gradle | 134 --- .../groovy/client/GAdminClient.groovy | 39 - .../groovy/client/GClient.groovy | 357 -------- .../groovy/client/GClusterAdminClient.groovy | 205 ----- .../groovy/client/GIndicesAdminClient.groovy | 483 ---------- .../groovy/client/action/GActionFuture.java | 167 ---- .../common/xcontent/GXContentBuilder.groovy | 189 ---- .../elasticsearch/groovy/node/GNode.groovy | 70 -- .../groovy/node/GNodeBuilder.groovy | 69 -- .../groovy/src/main/java/es-plugin.properties | 1 - .../plugin/groovy/GroovyPlugin.java | 45 - .../groovy/GroovyScriptEngineService.java | 201 ----- .../groovy/src/test/groovy/log4j.properties | 21 - .../xcontent/GXContentBuilderTests.groovy | 136 --- .../test/client/BuilderActionsTests.groovy | 97 --- .../client/DifferentApiExecutionTests.groovy | 156 ---- .../test/client/SimpleActionsTests.groovy | 161 ---- .../groovy/test/node/GNodeBuilderTests.groovy | 44 - .../lang/groovy/src/test/groovy/sample.groovy | 36 - .../groovy/GroovyScriptMultiThreadedTest.java | 168 ---- .../groovy/GroovyScriptSearchTests.java | 262 ------ .../script/groovy/SimpleBench.java | 61 -- plugins/lang/javascript/build.gradle | 138 --- .../src/main/java/es-plugin.properties | 1 - .../plugin/javascript/JavaScriptPlugin.java | 45 - .../JavaScriptScriptEngineService.java | 279 ------ .../script/javascript/support/NativeList.java | 207 ----- .../script/javascript/support/NativeMap.java | 223 ----- .../support/ScriptValueConverter.java | 183 ---- .../support/ScriptableLinkedHashMap.java | 188 ---- .../javascript/support/ScriptableMap.java | 32 - .../support/ScriptableWrappedMap.java | 342 -------- .../JavaScriptScriptEngineTests.java | 163 ---- .../JavaScriptScriptMultiThreadedTest.java | 168 ---- .../JavaScriptScriptSearchTests.java | 261 ------ .../script/javascript/SimpleBench.java | 71 -- plugins/lang/python/build.gradle | 138 --- .../python/src/main/java/es-plugin.properties | 1 - .../plugin/python/PythonPlugin.java | 45 - .../python/PythonScriptEngineService.java | 206 ----- .../python/PythonScriptEngineTests.java | 140 --- .../python/PythonScriptMultiThreadedTest.java | 169 ---- .../python/PythonScriptSearchTests.java | 246 ------ .../script/python/SimpleBench.java | 71 -- plugins/mapper/attachments/build.gradle | 132 --- .../src/main/java/es-plugin.properties | 1 - .../mapper/attachment/AttachmentMapper.java | 341 -------- .../attachment/RegisterAttachmentType.java | 39 - .../attachments/AttachmentsIndexModule.java | 33 - .../attachments/MapperAttachmentsPlugin.java | 47 - .../mapper/attachments/tika/TikaInstance.java | 34 - .../xcontent/SimpleAttachmentMapperTests.java | 74 -- .../index/mapper/xcontent/test-mapping.json | 7 - .../index/mapper/xcontent/testXHTML.html | 29 - .../SimpleAttachmentIntegrationTests.java | 95 -- plugins/river/couchdb/.gitignore | 1 - plugins/river/couchdb/build.gradle | 129 --- .../src/main/java/es-plugin.properties | 2 - .../river/couchdb/CouchdbRiverPlugin.java | 50 -- .../river/couchdb/CouchdbRiver.java | 526 ----------- .../river/couchdb/CouchdbRiverModule.java | 33 - .../couchdb/CouchdbRiverAttachementTest.java | 73 -- .../river/couchdb/CouchdbRiverTest.java | 40 - plugins/river/rabbitmq/build.gradle | 134 --- .../src/main/java/es-plugin.properties | 2 - .../river/rabbitmq/RabbitmqRiverPlugin.java | 49 -- .../river/rabbitmq/RabbitmqRiver.java | 315 ------- .../river/rabbitmq/RabbitmqRiverModule.java | 33 - .../river/rabbitmq/RabbitMQRiverTest.java | 65 -- plugins/river/twitter/build.gradle | 134 --- .../src/main/java/es-plugin.properties | 2 - .../river/twitter/TwitterRiverPlugin.java | 50 -- .../river/twitter/TwitterRiver.java | 511 ----------- .../river/twitter/TwitterRiverModule.java | 33 - plugins/river/wikipedia/build.gradle | 129 --- .../src/main/java/es-plugin.properties | 2 - .../river/wikipedia/WikipediaRiverPlugin.java | 49 -- .../river/wikipedia/WikipediaRiver.java | 236 ----- .../river/wikipedia/WikipediaRiverModule.java | 33 - .../river/wikipedia/support/InfoBox.java | 37 - .../wikipedia/support/IteratorHandler.java | 34 - .../support/PageCallbackHandler.java | 26 - .../support/SAXPageCallbackHandler.java | 60 -- .../river/wikipedia/support/WikiPage.java | 150 ---- .../wikipedia/support/WikiPageIterator.java | 47 - .../wikipedia/support/WikiTextParser.java | 196 ----- .../wikipedia/support/WikiXMLParser.java | 92 -- .../support/WikiXMLParserFactory.java | 14 - .../wikipedia/support/WikiXMLSAXParser.java | 97 --- .../river/wikipedia/support/package-info.java | 6 - plugins/transport/memcached/build.gradle | 137 --- .../src/main/java/es-plugin.properties | 1 - .../memcached/MemcachedRestRequest.java | 161 ---- .../memcached/MemcachedServer.java | 64 -- .../memcached/MemcachedServerModule.java | 48 - .../memcached/MemcachedServerTransport.java | 31 - .../MemcachedTransportException.java | 36 - .../memcached/netty/MemcachedDecoder.java | 242 ----- .../memcached/netty/MemcachedDispatcher.java | 58 -- .../memcached/netty/MemcachedRestChannel.java | 176 ---- .../netty/NettyMemcachedServerTransport.java | 211 ----- .../NettyMemcachedServerTransportModule.java | 33 - .../memcached/MemcachedTransportPlugin.java | 67 -- .../test/AbstractMemcachedActionsTests.java | 108 --- .../test/BinaryMemcachedActionTests.java | 38 - .../test/TextMemcachedActionTests.java | 37 - plugins/transport/thrift/build.gradle | 140 --- plugins/transport/thrift/elasticsearch.thrift | 81 -- .../org/elasticsearch/thrift/Method.java | 53 -- .../org/elasticsearch/thrift/Rest.java | 823 ------------------ .../org/elasticsearch/thrift/RestRequest.java | 801 ----------------- .../elasticsearch/thrift/RestResponse.java | 571 ------------ .../org/elasticsearch/thrift/Status.java | 167 ---- .../thrift/src/main/java/es-plugin.properties | 1 - .../thrift/ThriftTransportPlugin.java | 67 -- .../elasticsearch/thrift/ThriftRestImpl.java | 202 ----- .../thrift/ThriftRestRequest.java | 142 --- .../elasticsearch/thrift/ThriftServer.java | 156 ---- .../thrift/ThriftServerModule.java | 40 - .../thrift/test/SimpleThriftTests.java | 99 --- plugins/transport/wares/build.gradle | 127 --- .../org/elasticsearch/wares/NodeServlet.java | 167 ---- .../wares/ServletRestRequest.java | 113 --- settings.gradle | 18 - 166 files changed, 18970 deletions(-) delete mode 100644 plugins/analysis/icu/build.gradle delete mode 100644 plugins/analysis/icu/src/main/java/es-plugin.properties delete mode 100644 plugins/analysis/icu/src/main/java/org/elasticsearch/index/analysis/IcuAnalysisBinderProcessor.java delete mode 100644 plugins/analysis/icu/src/main/java/org/elasticsearch/index/analysis/IcuCollationTokenFilterFactory.java delete mode 100644 plugins/analysis/icu/src/main/java/org/elasticsearch/index/analysis/IcuFoldingTokenFilterFactory.java delete mode 100644 plugins/analysis/icu/src/main/java/org/elasticsearch/index/analysis/IcuNormalizerTokenFilterFactory.java delete mode 100644 plugins/analysis/icu/src/main/java/org/elasticsearch/plugin/analysis/icu/AnalysisICUPlugin.java delete mode 100644 plugins/analysis/icu/src/test/java/org/elasticsearch/index/analysis/SimpleIcuAnalysisTests.java delete mode 100644 plugins/cloud/aws/build.gradle delete mode 100644 plugins/cloud/aws/src/main/java/es-plugin.properties delete mode 100644 plugins/cloud/aws/src/main/java/org/elasticsearch/cloud/aws/AwsEc2Service.java delete mode 100644 plugins/cloud/aws/src/main/java/org/elasticsearch/cloud/aws/AwsModule.java delete mode 100644 plugins/cloud/aws/src/main/java/org/elasticsearch/cloud/aws/AwsS3Service.java delete mode 100644 plugins/cloud/aws/src/main/java/org/elasticsearch/cloud/aws/AwsSettingsFilter.java delete mode 100644 plugins/cloud/aws/src/main/java/org/elasticsearch/cloud/aws/blobstore/AbstractS3BlobContainer.java delete mode 100644 plugins/cloud/aws/src/main/java/org/elasticsearch/cloud/aws/blobstore/S3BlobStore.java delete mode 100644 plugins/cloud/aws/src/main/java/org/elasticsearch/cloud/aws/blobstore/S3ImmutableBlobContainer.java delete mode 100755 plugins/cloud/aws/src/main/java/org/elasticsearch/cloud/aws/network/Ec2NameResolver.java delete mode 100644 plugins/cloud/aws/src/main/java/org/elasticsearch/cloud/aws/node/Ec2CustomNodeAttributes.java delete mode 100644 plugins/cloud/aws/src/main/java/org/elasticsearch/discovery/ec2/AwsEc2UnicastHostsProvider.java delete mode 100755 plugins/cloud/aws/src/main/java/org/elasticsearch/discovery/ec2/Ec2Discovery.java delete mode 100644 plugins/cloud/aws/src/main/java/org/elasticsearch/discovery/ec2/Ec2DiscoveryModule.java delete mode 100644 plugins/cloud/aws/src/main/java/org/elasticsearch/gateway/s3/S3Gateway.java delete mode 100644 plugins/cloud/aws/src/main/java/org/elasticsearch/gateway/s3/S3GatewayModule.java delete mode 100644 plugins/cloud/aws/src/main/java/org/elasticsearch/index/gateway/s3/S3IndexGateway.java delete mode 100644 plugins/cloud/aws/src/main/java/org/elasticsearch/index/gateway/s3/S3IndexGatewayModule.java delete mode 100644 plugins/cloud/aws/src/main/java/org/elasticsearch/index/gateway/s3/S3IndexShardGateway.java delete mode 100644 plugins/cloud/aws/src/main/java/org/elasticsearch/plugin/cloud/aws/CloudAwsPlugin.java delete mode 100644 plugins/hadoop/build.gradle delete mode 100644 plugins/hadoop/src/main/java/es-plugin.properties delete mode 100644 plugins/hadoop/src/main/java/org/elasticsearch/common/blobstore/hdfs/AbstractHdfsBlobContainer.java delete mode 100644 plugins/hadoop/src/main/java/org/elasticsearch/common/blobstore/hdfs/HdfsBlobStore.java delete mode 100644 plugins/hadoop/src/main/java/org/elasticsearch/common/blobstore/hdfs/HdfsImmutableBlobContainer.java delete mode 100644 plugins/hadoop/src/main/java/org/elasticsearch/gateway/hdfs/HdfsGateway.java delete mode 100644 plugins/hadoop/src/main/java/org/elasticsearch/gateway/hdfs/HdfsGatewayModule.java delete mode 100644 plugins/hadoop/src/main/java/org/elasticsearch/gateway/hdfs/HdfsIndexGatewayModule.java delete mode 100644 plugins/hadoop/src/main/java/org/elasticsearch/index/gateway/hdfs/HdfsIndexGateway.java delete mode 100644 plugins/hadoop/src/main/java/org/elasticsearch/index/gateway/hdfs/HdfsIndexShardGateway.java delete mode 100644 plugins/hadoop/src/main/java/org/elasticsearch/plugin/hadoop/HadoopPlugin.java delete mode 100644 plugins/hadoop/src/test/java/org/elasticsearch/hadoop/gateway/HdfsGatewayTests.java delete mode 100644 plugins/lang/groovy/build.gradle delete mode 100644 plugins/lang/groovy/src/main/groovy/org/elasticsearch/groovy/client/GAdminClient.groovy delete mode 100644 plugins/lang/groovy/src/main/groovy/org/elasticsearch/groovy/client/GClient.groovy delete mode 100644 plugins/lang/groovy/src/main/groovy/org/elasticsearch/groovy/client/GClusterAdminClient.groovy delete mode 100644 plugins/lang/groovy/src/main/groovy/org/elasticsearch/groovy/client/GIndicesAdminClient.groovy delete mode 100644 plugins/lang/groovy/src/main/groovy/org/elasticsearch/groovy/client/action/GActionFuture.java delete mode 100644 plugins/lang/groovy/src/main/groovy/org/elasticsearch/groovy/common/xcontent/GXContentBuilder.groovy delete mode 100644 plugins/lang/groovy/src/main/groovy/org/elasticsearch/groovy/node/GNode.groovy delete mode 100644 plugins/lang/groovy/src/main/groovy/org/elasticsearch/groovy/node/GNodeBuilder.groovy delete mode 100644 plugins/lang/groovy/src/main/java/es-plugin.properties delete mode 100644 plugins/lang/groovy/src/main/java/org/elasticsearch/plugin/groovy/GroovyPlugin.java delete mode 100644 plugins/lang/groovy/src/main/java/org/elasticsearch/script/groovy/GroovyScriptEngineService.java delete mode 100644 plugins/lang/groovy/src/test/groovy/log4j.properties delete mode 100644 plugins/lang/groovy/src/test/groovy/org/elasticsearch/groovy/common/xcontent/GXContentBuilderTests.groovy delete mode 100644 plugins/lang/groovy/src/test/groovy/org/elasticsearch/groovy/test/client/BuilderActionsTests.groovy delete mode 100644 plugins/lang/groovy/src/test/groovy/org/elasticsearch/groovy/test/client/DifferentApiExecutionTests.groovy delete mode 100644 plugins/lang/groovy/src/test/groovy/org/elasticsearch/groovy/test/client/SimpleActionsTests.groovy delete mode 100644 plugins/lang/groovy/src/test/groovy/org/elasticsearch/groovy/test/node/GNodeBuilderTests.groovy delete mode 100644 plugins/lang/groovy/src/test/groovy/sample.groovy delete mode 100644 plugins/lang/groovy/src/test/java/org/elasticsearch/script/groovy/GroovyScriptMultiThreadedTest.java delete mode 100644 plugins/lang/groovy/src/test/java/org/elasticsearch/script/groovy/GroovyScriptSearchTests.java delete mode 100644 plugins/lang/groovy/src/test/java/org/elasticsearch/script/groovy/SimpleBench.java delete mode 100644 plugins/lang/javascript/build.gradle delete mode 100644 plugins/lang/javascript/src/main/java/es-plugin.properties delete mode 100644 plugins/lang/javascript/src/main/java/org/elasticsearch/plugin/javascript/JavaScriptPlugin.java delete mode 100644 plugins/lang/javascript/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java delete mode 100644 plugins/lang/javascript/src/main/java/org/elasticsearch/script/javascript/support/NativeList.java delete mode 100644 plugins/lang/javascript/src/main/java/org/elasticsearch/script/javascript/support/NativeMap.java delete mode 100644 plugins/lang/javascript/src/main/java/org/elasticsearch/script/javascript/support/ScriptValueConverter.java delete mode 100644 plugins/lang/javascript/src/main/java/org/elasticsearch/script/javascript/support/ScriptableLinkedHashMap.java delete mode 100644 plugins/lang/javascript/src/main/java/org/elasticsearch/script/javascript/support/ScriptableMap.java delete mode 100644 plugins/lang/javascript/src/main/java/org/elasticsearch/script/javascript/support/ScriptableWrappedMap.java delete mode 100644 plugins/lang/javascript/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineTests.java delete mode 100644 plugins/lang/javascript/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptMultiThreadedTest.java delete mode 100644 plugins/lang/javascript/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java delete mode 100644 plugins/lang/javascript/src/test/java/org/elasticsearch/script/javascript/SimpleBench.java delete mode 100644 plugins/lang/python/build.gradle delete mode 100644 plugins/lang/python/src/main/java/es-plugin.properties delete mode 100644 plugins/lang/python/src/main/java/org/elasticsearch/plugin/python/PythonPlugin.java delete mode 100644 plugins/lang/python/src/main/java/org/elasticsearch/script/python/PythonScriptEngineService.java delete mode 100644 plugins/lang/python/src/test/java/org/elasticsearch/script/python/PythonScriptEngineTests.java delete mode 100644 plugins/lang/python/src/test/java/org/elasticsearch/script/python/PythonScriptMultiThreadedTest.java delete mode 100644 plugins/lang/python/src/test/java/org/elasticsearch/script/python/PythonScriptSearchTests.java delete mode 100644 plugins/lang/python/src/test/java/org/elasticsearch/script/python/SimpleBench.java delete mode 100644 plugins/mapper/attachments/build.gradle delete mode 100644 plugins/mapper/attachments/src/main/java/es-plugin.properties delete mode 100644 plugins/mapper/attachments/src/main/java/org/elasticsearch/index/mapper/attachment/AttachmentMapper.java delete mode 100644 plugins/mapper/attachments/src/main/java/org/elasticsearch/index/mapper/attachment/RegisterAttachmentType.java delete mode 100644 plugins/mapper/attachments/src/main/java/org/elasticsearch/plugin/mapper/attachments/AttachmentsIndexModule.java delete mode 100644 plugins/mapper/attachments/src/main/java/org/elasticsearch/plugin/mapper/attachments/MapperAttachmentsPlugin.java delete mode 100644 plugins/mapper/attachments/src/main/java/org/elasticsearch/plugin/mapper/attachments/tika/TikaInstance.java delete mode 100644 plugins/mapper/attachments/src/test/java/org/elasticsearch/index/mapper/xcontent/SimpleAttachmentMapperTests.java delete mode 100644 plugins/mapper/attachments/src/test/java/org/elasticsearch/index/mapper/xcontent/test-mapping.json delete mode 100644 plugins/mapper/attachments/src/test/java/org/elasticsearch/index/mapper/xcontent/testXHTML.html delete mode 100644 plugins/mapper/attachments/src/test/java/org/elasticsearch/plugin/mapper/attachments/test/SimpleAttachmentIntegrationTests.java delete mode 100644 plugins/river/couchdb/.gitignore delete mode 100644 plugins/river/couchdb/build.gradle delete mode 100644 plugins/river/couchdb/src/main/java/es-plugin.properties delete mode 100644 plugins/river/couchdb/src/main/java/org/elasticsearch/plugin/river/couchdb/CouchdbRiverPlugin.java delete mode 100644 plugins/river/couchdb/src/main/java/org/elasticsearch/river/couchdb/CouchdbRiver.java delete mode 100644 plugins/river/couchdb/src/main/java/org/elasticsearch/river/couchdb/CouchdbRiverModule.java delete mode 100644 plugins/river/couchdb/src/test/java/org/elasticsearch/river/couchdb/CouchdbRiverAttachementTest.java delete mode 100644 plugins/river/couchdb/src/test/java/org/elasticsearch/river/couchdb/CouchdbRiverTest.java delete mode 100644 plugins/river/rabbitmq/build.gradle delete mode 100644 plugins/river/rabbitmq/src/main/java/es-plugin.properties delete mode 100644 plugins/river/rabbitmq/src/main/java/org/elasticsearch/plugin/river/rabbitmq/RabbitmqRiverPlugin.java delete mode 100644 plugins/river/rabbitmq/src/main/java/org/elasticsearch/river/rabbitmq/RabbitmqRiver.java delete mode 100644 plugins/river/rabbitmq/src/main/java/org/elasticsearch/river/rabbitmq/RabbitmqRiverModule.java delete mode 100644 plugins/river/rabbitmq/src/test/java/org/elasticsearch/river/rabbitmq/RabbitMQRiverTest.java delete mode 100644 plugins/river/twitter/build.gradle delete mode 100644 plugins/river/twitter/src/main/java/es-plugin.properties delete mode 100644 plugins/river/twitter/src/main/java/org/elasticsearch/plugin/river/twitter/TwitterRiverPlugin.java delete mode 100644 plugins/river/twitter/src/main/java/org/elasticsearch/river/twitter/TwitterRiver.java delete mode 100644 plugins/river/twitter/src/main/java/org/elasticsearch/river/twitter/TwitterRiverModule.java delete mode 100644 plugins/river/wikipedia/build.gradle delete mode 100644 plugins/river/wikipedia/src/main/java/es-plugin.properties delete mode 100644 plugins/river/wikipedia/src/main/java/org/elasticsearch/plugin/river/wikipedia/WikipediaRiverPlugin.java delete mode 100644 plugins/river/wikipedia/src/main/java/org/elasticsearch/river/wikipedia/WikipediaRiver.java delete mode 100644 plugins/river/wikipedia/src/main/java/org/elasticsearch/river/wikipedia/WikipediaRiverModule.java delete mode 100644 plugins/river/wikipedia/src/main/java/org/elasticsearch/river/wikipedia/support/InfoBox.java delete mode 100644 plugins/river/wikipedia/src/main/java/org/elasticsearch/river/wikipedia/support/IteratorHandler.java delete mode 100644 plugins/river/wikipedia/src/main/java/org/elasticsearch/river/wikipedia/support/PageCallbackHandler.java delete mode 100644 plugins/river/wikipedia/src/main/java/org/elasticsearch/river/wikipedia/support/SAXPageCallbackHandler.java delete mode 100644 plugins/river/wikipedia/src/main/java/org/elasticsearch/river/wikipedia/support/WikiPage.java delete mode 100644 plugins/river/wikipedia/src/main/java/org/elasticsearch/river/wikipedia/support/WikiPageIterator.java delete mode 100644 plugins/river/wikipedia/src/main/java/org/elasticsearch/river/wikipedia/support/WikiTextParser.java delete mode 100644 plugins/river/wikipedia/src/main/java/org/elasticsearch/river/wikipedia/support/WikiXMLParser.java delete mode 100644 plugins/river/wikipedia/src/main/java/org/elasticsearch/river/wikipedia/support/WikiXMLParserFactory.java delete mode 100644 plugins/river/wikipedia/src/main/java/org/elasticsearch/river/wikipedia/support/WikiXMLSAXParser.java delete mode 100644 plugins/river/wikipedia/src/main/java/org/elasticsearch/river/wikipedia/support/package-info.java delete mode 100644 plugins/transport/memcached/build.gradle delete mode 100644 plugins/transport/memcached/src/main/java/es-plugin.properties delete mode 100644 plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/MemcachedRestRequest.java delete mode 100644 plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/MemcachedServer.java delete mode 100644 plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/MemcachedServerModule.java delete mode 100644 plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/MemcachedServerTransport.java delete mode 100644 plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/MemcachedTransportException.java delete mode 100644 plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/netty/MemcachedDecoder.java delete mode 100644 plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/netty/MemcachedDispatcher.java delete mode 100644 plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/netty/MemcachedRestChannel.java delete mode 100644 plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/netty/NettyMemcachedServerTransport.java delete mode 100644 plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/netty/NettyMemcachedServerTransportModule.java delete mode 100644 plugins/transport/memcached/src/main/java/org/elasticsearch/plugin/transport/memcached/MemcachedTransportPlugin.java delete mode 100644 plugins/transport/memcached/src/test/java/org/elasticsearch/memcached/test/AbstractMemcachedActionsTests.java delete mode 100644 plugins/transport/memcached/src/test/java/org/elasticsearch/memcached/test/BinaryMemcachedActionTests.java delete mode 100644 plugins/transport/memcached/src/test/java/org/elasticsearch/memcached/test/TextMemcachedActionTests.java delete mode 100644 plugins/transport/thrift/build.gradle delete mode 100644 plugins/transport/thrift/elasticsearch.thrift delete mode 100644 plugins/transport/thrift/src/main/gen-java/org/elasticsearch/thrift/Method.java delete mode 100644 plugins/transport/thrift/src/main/gen-java/org/elasticsearch/thrift/Rest.java delete mode 100644 plugins/transport/thrift/src/main/gen-java/org/elasticsearch/thrift/RestRequest.java delete mode 100644 plugins/transport/thrift/src/main/gen-java/org/elasticsearch/thrift/RestResponse.java delete mode 100644 plugins/transport/thrift/src/main/gen-java/org/elasticsearch/thrift/Status.java delete mode 100644 plugins/transport/thrift/src/main/java/es-plugin.properties delete mode 100644 plugins/transport/thrift/src/main/java/org/elasticsearch/plugin/transport/thrift/ThriftTransportPlugin.java delete mode 100644 plugins/transport/thrift/src/main/java/org/elasticsearch/thrift/ThriftRestImpl.java delete mode 100644 plugins/transport/thrift/src/main/java/org/elasticsearch/thrift/ThriftRestRequest.java delete mode 100644 plugins/transport/thrift/src/main/java/org/elasticsearch/thrift/ThriftServer.java delete mode 100644 plugins/transport/thrift/src/main/java/org/elasticsearch/thrift/ThriftServerModule.java delete mode 100644 plugins/transport/thrift/src/test/java/org/elasticsearch/thrift/test/SimpleThriftTests.java delete mode 100644 plugins/transport/wares/build.gradle delete mode 100644 plugins/transport/wares/src/main/java/org/elasticsearch/wares/NodeServlet.java delete mode 100644 plugins/transport/wares/src/main/java/org/elasticsearch/wares/ServletRestRequest.java diff --git a/.idea/modules.xml b/.idea/modules.xml index 2ab1229cbf5..8da55ea3b4f 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -5,20 +5,6 @@ - - - - - - - - - - - - - - diff --git a/.idea/modules/elasticsearch-root.iml b/.idea/modules/elasticsearch-root.iml index a5fa5cf3cb0..f762beaf0fa 100644 --- a/.idea/modules/elasticsearch-root.iml +++ b/.idea/modules/elasticsearch-root.iml @@ -16,19 +16,6 @@ - - - - - - - - - - - - - diff --git a/plugins/analysis/icu/build.gradle b/plugins/analysis/icu/build.gradle deleted file mode 100644 index d3791dd5f52..00000000000 --- a/plugins/analysis/icu/build.gradle +++ /dev/null @@ -1,134 +0,0 @@ -dependsOn(':elasticsearch') - -apply plugin: 'java' -apply plugin: 'maven' -apply plugin: 'eclipse' - -archivesBaseName = "elasticsearch-analysis-icu" - -explodedDistDir = new File(distsDir, 'exploded') - -manifest.mainAttributes("Implementation-Title": "ElasticSearch::Plugins::Analysis::ICU", "Implementation-Version": rootProject.version, "Implementation-Date": buildTimeStr) - -configurations.compile.transitive = true -configurations.testCompile.transitive = true - -// no need to use the resource dir -sourceSets.main.resources.srcDirs 'src/main/java' -sourceSets.test.resources.srcDirs 'src/test/java' - -// add the source files to the dist jar -//jar { -// from sourceSets.main.allJava -//} - -configurations { - dists - distLib { - visible = false - transitive = false - } -} - -dependencies { - compile project(':elasticsearch') - - compile('org.apache.lucene:lucene-icu4j:3.2.0') { transitive = false } - distLib('org.apache.lucene:lucene-icu4j:3.2.0') { transitive = false } - compile('org.apache.lucene:lucene-icu:3.5.0') { transitive = false } - distLib('org.apache.lucene:lucene-icu:3.5.0') { transitive = false } -} - -task explodedDist(dependsOn: [jar], description: 'Builds the plugin zip file') << { - [explodedDistDir]*.mkdirs() - - copy { - from configurations.distLib - into explodedDistDir - } - - // remove elasticsearch files (compile above adds the elasticsearch one) - ant.delete { fileset(dir: explodedDistDir, includes: "elasticsearch-*.jar") } - - copy { - from libsDir - into explodedDistDir - } - - ant.delete { fileset(dir: explodedDistDir, includes: "elasticsearch-*-javadoc.jar") } - ant.delete { fileset(dir: explodedDistDir, includes: "elasticsearch-*-sources.jar") } -} - -task zip(type: Zip, dependsOn: ['explodedDist']) { - from(explodedDistDir) { - } -} - -task release(dependsOn: [zip]) << { - ant.delete(dir: explodedDistDir) - copy { - from distsDir - into(new File(rootProject.distsDir, "plugins")) - } -} - -configurations { - deployerJars -} - -dependencies { - deployerJars "org.apache.maven.wagon:wagon-http:1.0-beta-2" -} - -task sourcesJar(type: Jar, dependsOn: classes) { - classifier = 'sources' - from sourceSets.main.allSource -} - -task javadocJar(type: Jar, dependsOn: javadoc) { - classifier = 'javadoc' - from javadoc.destinationDir -} - -artifacts { - archives sourcesJar - archives javadocJar -} - -uploadArchives { - repositories.mavenDeployer { - configuration = configurations.deployerJars - repository(url: rootProject.mavenRepoUrl) { - authentication(userName: rootProject.mavenRepoUser, password: rootProject.mavenRepoPass) - } - snapshotRepository(url: rootProject.mavenSnapshotRepoUrl) { - authentication(userName: rootProject.mavenRepoUser, password: rootProject.mavenRepoPass) - } - - pom.project { - inceptionYear '2009' - name 'elasticsearch-plugins-analysis-icu' - description 'ICU Analysis Plugin for ElasticSearch' - licenses { - license { - name 'The Apache Software License, Version 2.0' - url 'http://www.apache.org/licenses/LICENSE-2.0.txt' - distribution 'repo' - } - } - scm { - connection 'git://github.com/elasticsearch/elasticsearch.git' - developerConnection 'git@github.com:elasticsearch/elasticsearch.git' - url 'http://github.com/elasticsearch/elasticsearch' - } - } - - pom.whenConfigured {pom -> - pom.dependencies = pom.dependencies.findAll {dep -> dep.scope != 'test' } // removes the test scoped ones - } - } -} - -eclipseClasspath { - defaultOutputDir = file('build/eclipse-build') -} diff --git a/plugins/analysis/icu/src/main/java/es-plugin.properties b/plugins/analysis/icu/src/main/java/es-plugin.properties deleted file mode 100644 index b694c79bec0..00000000000 --- a/plugins/analysis/icu/src/main/java/es-plugin.properties +++ /dev/null @@ -1 +0,0 @@ -plugin=org.elasticsearch.plugin.analysis.icu.AnalysisICUPlugin diff --git a/plugins/analysis/icu/src/main/java/org/elasticsearch/index/analysis/IcuAnalysisBinderProcessor.java b/plugins/analysis/icu/src/main/java/org/elasticsearch/index/analysis/IcuAnalysisBinderProcessor.java deleted file mode 100644 index e5e0b23dfcf..00000000000 --- a/plugins/analysis/icu/src/main/java/org/elasticsearch/index/analysis/IcuAnalysisBinderProcessor.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.index.analysis; - -/** - * @author kimchy (shay.banon) - */ -public class IcuAnalysisBinderProcessor extends AnalysisModule.AnalysisBinderProcessor { - - @Override public void processTokenFilters(TokenFiltersBindings tokenFiltersBindings) { - tokenFiltersBindings.processTokenFilter("icuNormalizer", IcuNormalizerTokenFilterFactory.class); - tokenFiltersBindings.processTokenFilter("icu_normalizer", IcuNormalizerTokenFilterFactory.class); - - tokenFiltersBindings.processTokenFilter("icuFolding", IcuFoldingTokenFilterFactory.class); - tokenFiltersBindings.processTokenFilter("icu_folding", IcuFoldingTokenFilterFactory.class); - - tokenFiltersBindings.processTokenFilter("icuCollation", IcuCollationTokenFilterFactory.class); - tokenFiltersBindings.processTokenFilter("icu_collation", IcuCollationTokenFilterFactory.class); - } -} diff --git a/plugins/analysis/icu/src/main/java/org/elasticsearch/index/analysis/IcuCollationTokenFilterFactory.java b/plugins/analysis/icu/src/main/java/org/elasticsearch/index/analysis/IcuCollationTokenFilterFactory.java deleted file mode 100644 index 8d089385734..00000000000 --- a/plugins/analysis/icu/src/main/java/org/elasticsearch/index/analysis/IcuCollationTokenFilterFactory.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.index.analysis; - -import com.ibm.icu.text.Collator; -import com.ibm.icu.text.RuleBasedCollator; -import org.apache.lucene.analysis.TokenStream; -import org.apache.lucene.collation.ICUCollationKeyFilter; -import org.elasticsearch.ElasticSearchIllegalArgumentException; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.inject.assistedinject.Assisted; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.env.Environment; -import org.elasticsearch.env.FailedToResolveConfigException; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.settings.IndexSettings; - -import java.io.IOException; -import java.util.Locale; - -/** - * An ICU based collation token filter. There are two ways to configure collation: - * - *

The first is simply specifying the locale (defaults to the default locale). The language - * parameter is the lowercase two-letter ISO-639 code. An additional country and variant - * can be provided. - * - *

The second option is to specify collation rules as defined in the - * Collation customization chapter in icu docs. The rules parameter can either embed the rules definition - * in the settings or refer to an external location (preferable located under the config location, relative to it). - * - * @author kimchy (shay.banon) - */ -public class IcuCollationTokenFilterFactory extends AbstractTokenFilterFactory { - - private final Collator collator; - - @Inject public IcuCollationTokenFilterFactory(Index index, @IndexSettings Settings indexSettings, Environment environment, @Assisted String name, @Assisted Settings settings) { - super(index, indexSettings, name, settings); - - Collator collator; - String rules = settings.get("rules"); - if (rules != null) { - FailedToResolveConfigException failureToResolve = null; - try { - rules = environment.resolveConfigAndLoadToString(rules); - } catch (FailedToResolveConfigException e) { - failureToResolve = e; - } catch (IOException e) { - throw new ElasticSearchIllegalArgumentException("Failed to load collation rules", e); - } - try { - collator = new RuleBasedCollator(rules); - } catch (Exception e) { - if (failureToResolve != null) { - throw new ElasticSearchIllegalArgumentException("Failed to resolve collation rules location", failureToResolve); - } else { - throw new ElasticSearchIllegalArgumentException("Failed to parse collation rules", e); - } - } - } else { - String language = settings.get("language"); - if (language != null) { - Locale locale; - String country = settings.get("country"); - if (country != null) { - String variant = settings.get("variant"); - if (variant != null) { - locale = new Locale(language, country, variant); - } else { - locale = new Locale(language, country); - } - } else { - locale = new Locale(language); - } - collator = Collator.getInstance(locale); - } else { - collator = Collator.getInstance(); - } - } - this.collator = collator; - } - - @Override public TokenStream create(TokenStream tokenStream) { - return new ICUCollationKeyFilter(tokenStream, collator); - } -} diff --git a/plugins/analysis/icu/src/main/java/org/elasticsearch/index/analysis/IcuFoldingTokenFilterFactory.java b/plugins/analysis/icu/src/main/java/org/elasticsearch/index/analysis/IcuFoldingTokenFilterFactory.java deleted file mode 100644 index f17956e4017..00000000000 --- a/plugins/analysis/icu/src/main/java/org/elasticsearch/index/analysis/IcuFoldingTokenFilterFactory.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.index.analysis; - -import org.apache.lucene.analysis.TokenStream; -import org.apache.lucene.analysis.icu.ICUFoldingFilter; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.inject.assistedinject.Assisted; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.settings.IndexSettings; - - -/** - * @author kimchy (shay.banon) - */ -public class IcuFoldingTokenFilterFactory extends AbstractTokenFilterFactory { - - @Inject public IcuFoldingTokenFilterFactory(Index index, @IndexSettings Settings indexSettings, @Assisted String name, @Assisted Settings settings) { - super(index, indexSettings, name, settings); - } - - @Override public TokenStream create(TokenStream tokenStream) { - return new ICUFoldingFilter(tokenStream); - } -} \ No newline at end of file diff --git a/plugins/analysis/icu/src/main/java/org/elasticsearch/index/analysis/IcuNormalizerTokenFilterFactory.java b/plugins/analysis/icu/src/main/java/org/elasticsearch/index/analysis/IcuNormalizerTokenFilterFactory.java deleted file mode 100644 index 1dd6e524006..00000000000 --- a/plugins/analysis/icu/src/main/java/org/elasticsearch/index/analysis/IcuNormalizerTokenFilterFactory.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.index.analysis; - -import com.ibm.icu.text.Normalizer2; -import org.apache.lucene.analysis.TokenStream; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.inject.assistedinject.Assisted; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.settings.IndexSettings; - - -/** - * Uses the {@link org.apache.lucene.analysis.icu.ICUNormalizer2Filter} to normalize tokens. - * - *

The name can be used to provide the type of normalization to perform. - * - * @author kimchy (shay.banon) - */ -public class IcuNormalizerTokenFilterFactory extends AbstractTokenFilterFactory { - - private final String name; - - @Inject public IcuNormalizerTokenFilterFactory(Index index, @IndexSettings Settings indexSettings, @Assisted String name, @Assisted Settings settings) { - super(index, indexSettings, name, settings); - this.name = settings.get("name", "nfkc_cf"); - } - - @Override public TokenStream create(TokenStream tokenStream) { - return new org.apache.lucene.analysis.icu.ICUNormalizer2Filter(tokenStream, Normalizer2.getInstance(null, name, Normalizer2.Mode.COMPOSE)); - } -} \ No newline at end of file diff --git a/plugins/analysis/icu/src/main/java/org/elasticsearch/plugin/analysis/icu/AnalysisICUPlugin.java b/plugins/analysis/icu/src/main/java/org/elasticsearch/plugin/analysis/icu/AnalysisICUPlugin.java deleted file mode 100644 index 589f60dc985..00000000000 --- a/plugins/analysis/icu/src/main/java/org/elasticsearch/plugin/analysis/icu/AnalysisICUPlugin.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.plugin.analysis.icu; - -import org.elasticsearch.common.inject.Module; -import org.elasticsearch.index.analysis.AnalysisModule; -import org.elasticsearch.index.analysis.IcuAnalysisBinderProcessor; -import org.elasticsearch.plugins.AbstractPlugin; - -/** - * @author kimchy (shay.banon) - */ -public class AnalysisICUPlugin extends AbstractPlugin { - - @Override public String name() { - return "analysis-icu"; - } - - @Override public String description() { - return "UTF related ICU analysis support"; - } - - @Override public void processModule(Module module) { - if (module instanceof AnalysisModule) { - AnalysisModule analysisModule = (AnalysisModule) module; - analysisModule.addProcessor(new IcuAnalysisBinderProcessor()); - } - } -} diff --git a/plugins/analysis/icu/src/test/java/org/elasticsearch/index/analysis/SimpleIcuAnalysisTests.java b/plugins/analysis/icu/src/test/java/org/elasticsearch/index/analysis/SimpleIcuAnalysisTests.java deleted file mode 100644 index 1f0563b3fdd..00000000000 --- a/plugins/analysis/icu/src/test/java/org/elasticsearch/index/analysis/SimpleIcuAnalysisTests.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.index.analysis; - -import org.elasticsearch.common.inject.Injector; -import org.elasticsearch.common.inject.ModulesBuilder; -import org.elasticsearch.common.settings.SettingsModule; -import org.elasticsearch.env.Environment; -import org.elasticsearch.env.EnvironmentModule; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.IndexNameModule; -import org.elasticsearch.index.settings.IndexSettingsModule; -import org.elasticsearch.indices.analysis.IndicesAnalysisModule; -import org.elasticsearch.indices.analysis.IndicesAnalysisService; -import org.hamcrest.MatcherAssert; -import org.testng.annotations.Test; - -import static org.elasticsearch.common.settings.ImmutableSettings.Builder.*; -import static org.hamcrest.Matchers.*; - -/** - * @author kimchy (shay.banon) - */ -public class SimpleIcuAnalysisTests { - - @Test public void testDefaultsIcuAnalysis() { - Index index = new Index("test"); - - Injector parentInjector = new ModulesBuilder().add(new SettingsModule(EMPTY_SETTINGS), new EnvironmentModule(new Environment(EMPTY_SETTINGS)), new IndicesAnalysisModule()).createInjector(); - Injector injector = new ModulesBuilder().add( - new IndexSettingsModule(index, EMPTY_SETTINGS), - new IndexNameModule(index), - new AnalysisModule(EMPTY_SETTINGS, parentInjector.getInstance(IndicesAnalysisService.class)).addProcessor(new IcuAnalysisBinderProcessor())) - .createChildInjector(parentInjector); - - AnalysisService analysisService = injector.getInstance(AnalysisService.class); - - TokenFilterFactory filterFactory = analysisService.tokenFilter("icu_normalizer"); - MatcherAssert.assertThat(filterFactory, instanceOf(IcuNormalizerTokenFilterFactory.class)); - } -} diff --git a/plugins/cloud/aws/build.gradle b/plugins/cloud/aws/build.gradle deleted file mode 100644 index a9314947cdd..00000000000 --- a/plugins/cloud/aws/build.gradle +++ /dev/null @@ -1,140 +0,0 @@ -dependsOn(':elasticsearch') - -apply plugin: 'java' -apply plugin: 'maven' -apply plugin: 'eclipse' - -archivesBaseName = "elasticsearch-cloud-aws" - -explodedDistDir = new File(distsDir, 'exploded') - -configurations.compile.transitive = true -configurations.testCompile.transitive = true - -// no need to use the resource dir -sourceSets.main.resources.srcDirs 'src/main/java' -sourceSets.test.resources.srcDirs 'src/test/java' - -jar { -// from sourceSets.main.allJava - manifest { - attributes("Implementation-Title": "ElasticSearch", "Implementation-Version": rootProject.version, "Implementation-Date": buildTimeStr) - } -} - -configurations { - dists - distLib { - visible = false - transitive = false - } -} - -dependencies { - compile project(':elasticsearch') - compile("com.amazonaws:aws-java-sdk:1.2.12") { transitive = false } - runtime("commons-logging:commons-logging:1.1.1") { transitive = false } - runtime("commons-codec:commons-codec:1.3") { transitive = false } - runtime("org.apache.httpcomponents:httpclient:4.1.1") { transitive = false } - runtime("org.apache.httpcomponents:httpcore:4.1") { transitive = false } - - distLib("com.amazonaws:aws-java-sdk:1.2.12") { transitive = false } - distLib("commons-codec:commons-codec:1.3") { transitive = false } - distLib("commons-logging:commons-logging:1.1.1") { transitive = false } - distLib("org.apache.httpcomponents:httpclient:4.1.1") { transitive = false } - distLib("org.apache.httpcomponents:httpcore:4.1") { transitive = false } -} - -task explodedDist(dependsOn: [jar], description: 'Builds the plugin zip file') << { - [explodedDistDir]*.mkdirs() - - copy { - from configurations.distLib - into explodedDistDir - } - - // remove elasticsearch files (compile above adds the elasticsearch one) - ant.delete { fileset(dir: explodedDistDir, includes: "elasticsearch-*.jar") } - - copy { - from libsDir - into explodedDistDir - } - - ant.delete { fileset(dir: explodedDistDir, includes: "elasticsearch-*-javadoc.jar") } - ant.delete { fileset(dir: explodedDistDir, includes: "elasticsearch-*-sources.jar") } -} - -task zip(type: Zip, dependsOn: ['explodedDist']) { - from(explodedDistDir) { - } -} - -task release(dependsOn: [zip]) << { - ant.delete(dir: explodedDistDir) - copy { - from distsDir - into(new File(rootProject.distsDir, "plugins")) - } -} - -configurations { - deployerJars -} - -dependencies { - deployerJars "org.apache.maven.wagon:wagon-http:1.0-beta-2" -} - -task sourcesJar(type: Jar, dependsOn: classes) { - classifier = 'sources' - from sourceSets.main.allSource -} - -task javadocJar(type: Jar, dependsOn: javadoc) { - classifier = 'javadoc' - from javadoc.destinationDir -} - -artifacts { - archives sourcesJar - archives javadocJar -} - -uploadArchives { - repositories.mavenDeployer { - configuration = configurations.deployerJars - repository(url: rootProject.mavenRepoUrl) { - authentication(userName: rootProject.mavenRepoUser, password: rootProject.mavenRepoPass) - } - snapshotRepository(url: rootProject.mavenSnapshotRepoUrl) { - authentication(userName: rootProject.mavenRepoUser, password: rootProject.mavenRepoPass) - } - - pom.project { - inceptionYear '2009' - name 'elasticsearch-plugins-cloud-aws' - description 'Cloud AWS Plugin for ElasticSearch' - licenses { - license { - name 'The Apache Software License, Version 2.0' - url 'http://www.apache.org/licenses/LICENSE-2.0.txt' - distribution 'repo' - } - } - scm { - connection 'git://github.com/elasticsearch/elasticsearch.git' - developerConnection 'git@github.com:elasticsearch/elasticsearch.git' - url 'http://github.com/elasticsearch/elasticsearch' - } - } - - pom.whenConfigured {pom -> - pom.dependencies = pom.dependencies.findAll {dep -> dep.scope != 'test' } // removes the test scoped ones - } - } -} - -eclipseClasspath { - defaultOutputDir = file('build/eclipse-build') -} \ No newline at end of file diff --git a/plugins/cloud/aws/src/main/java/es-plugin.properties b/plugins/cloud/aws/src/main/java/es-plugin.properties deleted file mode 100644 index 43b40e7fc79..00000000000 --- a/plugins/cloud/aws/src/main/java/es-plugin.properties +++ /dev/null @@ -1,2 +0,0 @@ -plugin=org.elasticsearch.plugin.cloud.aws.CloudAwsPlugin - diff --git a/plugins/cloud/aws/src/main/java/org/elasticsearch/cloud/aws/AwsEc2Service.java b/plugins/cloud/aws/src/main/java/org/elasticsearch/cloud/aws/AwsEc2Service.java deleted file mode 100644 index e6969be0d15..00000000000 --- a/plugins/cloud/aws/src/main/java/org/elasticsearch/cloud/aws/AwsEc2Service.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.cloud.aws; - -import com.amazonaws.ClientConfiguration; -import com.amazonaws.Protocol; -import com.amazonaws.auth.BasicAWSCredentials; -import com.amazonaws.services.ec2.AmazonEC2; -import com.amazonaws.services.ec2.AmazonEC2Client; -import org.elasticsearch.ElasticSearchException; -import org.elasticsearch.ElasticSearchIllegalArgumentException; -import org.elasticsearch.cloud.aws.network.Ec2NameResolver; -import org.elasticsearch.cloud.aws.node.Ec2CustomNodeAttributes; -import org.elasticsearch.cluster.node.DiscoveryNodeService; -import org.elasticsearch.common.component.AbstractLifecycleComponent; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.network.NetworkService; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.settings.SettingsFilter; - -/** - * @author kimchy (shay.banon) - */ -public class AwsEc2Service extends AbstractLifecycleComponent { - - public static final String EC2_METADATA_URL = "http://169.254.169.254/latest/meta-data/"; - - private AmazonEC2Client client; - - @Inject public AwsEc2Service(Settings settings, SettingsFilter settingsFilter, NetworkService networkService, DiscoveryNodeService discoveryNodeService) { - super(settings); - settingsFilter.addFilter(new AwsSettingsFilter()); - // add specific ec2 name resolver - networkService.addCustomNameResolver(new Ec2NameResolver(settings)); - discoveryNodeService.addCustomAttributeProvider(new Ec2CustomNodeAttributes(settings)); - } - - public synchronized AmazonEC2 client() { - if (client != null) { - return client; - } - - ClientConfiguration clientConfiguration = new ClientConfiguration(); - String protocol = componentSettings.get("protocol", "http").toLowerCase(); - if ("http".equals(protocol)) { - clientConfiguration.setProtocol(Protocol.HTTP); - } else if ("https".equals(protocol)) { - clientConfiguration.setProtocol(Protocol.HTTPS); - } else { - throw new ElasticSearchIllegalArgumentException("No protocol supported [" + protocol + "], can either be [http] or [https]"); - } - String account = componentSettings.get("access_key", settings.get("cloud.account")); - String key = componentSettings.get("secret_key", settings.get("cloud.key")); - - if (account == null) { - throw new ElasticSearchIllegalArgumentException("No aws access_key defined for ec2 discovery"); - } - if (key == null) { - throw new ElasticSearchIllegalArgumentException("No aws secret_key defined for ec2 discovery"); - } - - String proxyHost = componentSettings.get("proxy_host"); - if (proxyHost != null) { - String portString = componentSettings.get("proxy_port", "80"); - Integer proxyPort; - try { - proxyPort = Integer.parseInt(portString, 10); - } catch (NumberFormatException ex) { - throw new ElasticSearchIllegalArgumentException("The configured proxy port value [" + portString + "] is invalid", ex); - } - clientConfiguration.withProxyHost(proxyHost).setProxyPort(proxyPort); - } - - this.client = new AmazonEC2Client(new BasicAWSCredentials(account, key), clientConfiguration); - - if (componentSettings.get("ec2.endpoint") != null) { - client.setEndpoint(componentSettings.get("ec2.endpoint")); - } else if (componentSettings.get("region") != null) { - String endpoint; - String region = componentSettings.get("region"); - if ("us-east".equals(region.toLowerCase())) { - endpoint = "ec2.us-east-1.amazonaws.com"; - } else if ("us-east-1".equals(region.toLowerCase())) { - endpoint = "ec2.us-east-1.amazonaws.com"; - } else if ("us-west".equals(region.toLowerCase())) { - endpoint = "ec2.us-west-1.amazonaws.com"; - } else if ("us-west-1".equals(region.toLowerCase())) { - endpoint = "ec2.us-west-1.amazonaws.com"; - } else if ("us-west-2".equals(region.toLowerCase())) { - endpoint = "ec2.us-west-2.amazonaws.com"; - } else if ("ap-southeast".equals(region.toLowerCase())) { - endpoint = "ec2.ap-southeast-1.amazonaws.com"; - } else if ("ap-southeast-1".equals(region.toLowerCase())) { - endpoint = "ec2.ap-southeast-1.amazonaws.com"; - } else if ("ap-northeast".equals(region.toLowerCase())) { - endpoint = "ec2.ap-northeast.amazonaws.com\t"; - } else if ("ap-northeast-1".equals(region.toLowerCase())) { - endpoint = "ec2.ap-northeast-1.amazonaws.com\t"; - } else if ("eu-west".equals(region.toLowerCase())) { - endpoint = "ec2.eu-west-1.amazonaws.com"; - } else if ("eu-west-1".equals(region.toLowerCase())) { - endpoint = "ec2.eu-west-1.amazonaws.com"; - } else { - throw new ElasticSearchIllegalArgumentException("No automatic endpoint could be derived from region [" + region + "]"); - } - if (endpoint != null) { - client.setEndpoint(endpoint); - } - } - - return this.client; - - } - - @Override protected void doStart() throws ElasticSearchException { - } - - @Override protected void doStop() throws ElasticSearchException { - } - - @Override protected void doClose() throws ElasticSearchException { - if (client != null) { - client.shutdown(); - } - } -} diff --git a/plugins/cloud/aws/src/main/java/org/elasticsearch/cloud/aws/AwsModule.java b/plugins/cloud/aws/src/main/java/org/elasticsearch/cloud/aws/AwsModule.java deleted file mode 100644 index 3d61eaacccc..00000000000 --- a/plugins/cloud/aws/src/main/java/org/elasticsearch/cloud/aws/AwsModule.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.cloud.aws; - -import org.elasticsearch.common.inject.AbstractModule; - -/** - * @author kimchy (shay.banon) - */ -public class AwsModule extends AbstractModule { - - @Override protected void configure() { - bind(AwsS3Service.class).asEagerSingleton(); - bind(AwsEc2Service.class).asEagerSingleton(); - } -} diff --git a/plugins/cloud/aws/src/main/java/org/elasticsearch/cloud/aws/AwsS3Service.java b/plugins/cloud/aws/src/main/java/org/elasticsearch/cloud/aws/AwsS3Service.java deleted file mode 100644 index bf20dc50cb2..00000000000 --- a/plugins/cloud/aws/src/main/java/org/elasticsearch/cloud/aws/AwsS3Service.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.cloud.aws; - -import com.amazonaws.ClientConfiguration; -import com.amazonaws.Protocol; -import com.amazonaws.auth.BasicAWSCredentials; -import com.amazonaws.services.s3.AmazonS3; -import com.amazonaws.services.s3.AmazonS3Client; -import org.elasticsearch.ElasticSearchException; -import org.elasticsearch.ElasticSearchIllegalArgumentException; -import org.elasticsearch.common.component.AbstractLifecycleComponent; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.settings.SettingsFilter; - -/** - * @author kimchy (shay.banon) - */ -public class AwsS3Service extends AbstractLifecycleComponent { - - private AmazonS3Client client; - - @Inject public AwsS3Service(Settings settings, SettingsFilter settingsFilter) { - super(settings); - - settingsFilter.addFilter(new AwsSettingsFilter()); - } - - public synchronized AmazonS3 client() { - if (client != null) { - return client; - } - - ClientConfiguration clientConfiguration = new ClientConfiguration(); - String protocol = componentSettings.get("protocol", "http").toLowerCase(); - if ("http".equals(protocol)) { - clientConfiguration.setProtocol(Protocol.HTTP); - } else if ("https".equals(protocol)) { - clientConfiguration.setProtocol(Protocol.HTTPS); - } else { - throw new ElasticSearchIllegalArgumentException("No protocol supported [" + protocol + "], can either be [http] or [https]"); - } - String account = componentSettings.get("access_key", settings.get("cloud.account")); - String key = componentSettings.get("secret_key", settings.get("cloud.key")); - - if (account == null) { - throw new ElasticSearchIllegalArgumentException("No s3 access_key defined for s3 gateway"); - } - if (key == null) { - throw new ElasticSearchIllegalArgumentException("No s3 secret_key defined for s3 gateway"); - } - - String proxyHost = componentSettings.get("proxy_host"); - if (proxyHost != null) { - String portString = componentSettings.get("proxy_port", "80"); - Integer proxyPort; - try { - proxyPort = Integer.parseInt(portString, 10); - } catch (NumberFormatException ex) { - throw new ElasticSearchIllegalArgumentException("The configured proxy port value [" + portString + "] is invalid", ex); - } - clientConfiguration.withProxyHost(proxyHost).setProxyPort(proxyPort); - } - - this.client = new AmazonS3Client(new BasicAWSCredentials(account, key), clientConfiguration); - - if (componentSettings.get("s3.endpoint") != null) { - client.setEndpoint(componentSettings.get("s3.endpoint")); - } else if (componentSettings.get("region") != null) { - String endpoint; - String region = componentSettings.get("region"); - if ("us-east".equals(region.toLowerCase())) { - endpoint = "s3.amazonaws.com"; - } else if ("us-east-1".equals(region.toLowerCase())) { - endpoint = "s3.amazonaws.com"; - } else if ("us-west".equals(region.toLowerCase())) { - endpoint = "s3-us-west-1.amazonaws.com"; - } else if ("us-west-1".equals(region.toLowerCase())) { - endpoint = "s3-us-west-1.amazonaws.com"; - } else if ("us-west-2".equals(region.toLowerCase())) { - endpoint = "s3-us-west-2.amazonaws.com"; - } else if ("ap-southeast".equals(region.toLowerCase())) { - endpoint = "s3-ap-southeast-1.amazonaws.com"; - } else if ("ap-southeast-1".equals(region.toLowerCase())) { - endpoint = "s3-ap-southeast-1.amazonaws.com"; - } else if ("ap-northeast".equals(region.toLowerCase())) { - endpoint = "s3-ap-northeast-1.amazonaws.com"; - } else if ("ap-northeast-1".equals(region.toLowerCase())) { - endpoint = "s3-ap-northeast-1.amazonaws.com"; - } else if ("eu-west".equals(region.toLowerCase())) { - endpoint = "s3-eu-west-1.amazonaws.com"; - } else if ("eu-west-1".equals(region.toLowerCase())) { - endpoint = "s3-eu-west-1.amazonaws.com"; - } else { - throw new ElasticSearchIllegalArgumentException("No automatic endpoint could be derived from region [" + region + "]"); - } - if (endpoint != null) { - client.setEndpoint(endpoint); - } - } - - return this.client; - } - - @Override protected void doStart() throws ElasticSearchException { - } - - @Override protected void doStop() throws ElasticSearchException { - } - - @Override protected void doClose() throws ElasticSearchException { - if (client != null) { - client.shutdown(); - } - } - -} diff --git a/plugins/cloud/aws/src/main/java/org/elasticsearch/cloud/aws/AwsSettingsFilter.java b/plugins/cloud/aws/src/main/java/org/elasticsearch/cloud/aws/AwsSettingsFilter.java deleted file mode 100644 index 9e58b89ac48..00000000000 --- a/plugins/cloud/aws/src/main/java/org/elasticsearch/cloud/aws/AwsSettingsFilter.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.cloud.aws; - -import org.elasticsearch.common.settings.ImmutableSettings; -import org.elasticsearch.common.settings.SettingsFilter; - -/** - * @author kimchy (shay.banon) - */ -public class AwsSettingsFilter implements SettingsFilter.Filter { - - @Override public void filter(ImmutableSettings.Builder settings) { - settings.remove("cloud.key"); - settings.remove("cloud.account"); - settings.remove("cloud.aws.access_key"); - settings.remove("cloud.aws.secret_key"); - } -} diff --git a/plugins/cloud/aws/src/main/java/org/elasticsearch/cloud/aws/blobstore/AbstractS3BlobContainer.java b/plugins/cloud/aws/src/main/java/org/elasticsearch/cloud/aws/blobstore/AbstractS3BlobContainer.java deleted file mode 100644 index 7fb21a9d240..00000000000 --- a/plugins/cloud/aws/src/main/java/org/elasticsearch/cloud/aws/blobstore/AbstractS3BlobContainer.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.cloud.aws.blobstore; - -import com.amazonaws.services.s3.model.ObjectListing; -import com.amazonaws.services.s3.model.S3Object; -import com.amazonaws.services.s3.model.S3ObjectSummary; -import org.elasticsearch.common.Nullable; -import org.elasticsearch.common.blobstore.BlobMetaData; -import org.elasticsearch.common.blobstore.BlobPath; -import org.elasticsearch.common.blobstore.support.AbstractBlobContainer; -import org.elasticsearch.common.blobstore.support.PlainBlobMetaData; -import org.elasticsearch.common.collect.ImmutableMap; - -import java.io.IOException; -import java.io.InputStream; - -/** - * @author kimchy (shay.banon) - */ -public class AbstractS3BlobContainer extends AbstractBlobContainer { - - protected final S3BlobStore blobStore; - - protected final String keyPath; - - public AbstractS3BlobContainer(BlobPath path, S3BlobStore blobStore) { - super(path); - this.blobStore = blobStore; - this.keyPath = path.buildAsString("/") + "/"; - } - - @Override public boolean blobExists(String blobName) { - try { - blobStore.client().getObjectMetadata(blobStore.bucket(), buildKey(blobName)); - return true; - } catch (Exception e) { - return false; - } - } - - @Override public boolean deleteBlob(String blobName) throws IOException { - blobStore.client().deleteObject(blobStore.bucket(), buildKey(blobName)); - return true; - } - - @Override public void readBlob(final String blobName, final ReadBlobListener listener) { - blobStore.executor().execute(new Runnable() { - @Override public void run() { - InputStream is; - try { - S3Object object = blobStore.client().getObject(blobStore.bucket(), buildKey(blobName)); - is = object.getObjectContent(); - } catch (Exception e) { - listener.onFailure(e); - return; - } - byte[] buffer = new byte[blobStore.bufferSizeInBytes()]; - try { - int bytesRead; - while ((bytesRead = is.read(buffer)) != -1) { - listener.onPartial(buffer, 0, bytesRead); - } - listener.onCompleted(); - } catch (Exception e) { - try { - is.close(); - } catch (IOException e1) { - // ignore - } - listener.onFailure(e); - } - } - }); - } - - @Override public ImmutableMap listBlobsByPrefix(@Nullable String blobNamePrefix) throws IOException { - ImmutableMap.Builder blobsBuilder = ImmutableMap.builder(); - ObjectListing prevListing = null; - while (true) { - ObjectListing list; - if (prevListing != null) { - list = blobStore.client().listNextBatchOfObjects(prevListing); - } else { - if (blobNamePrefix != null) { - list = blobStore.client().listObjects(blobStore.bucket(), buildKey(blobNamePrefix)); - } else { - list = blobStore.client().listObjects(blobStore.bucket(), keyPath); - } - } - for (S3ObjectSummary summary : list.getObjectSummaries()) { - String name = summary.getKey().substring(keyPath.length()); - blobsBuilder.put(name, new PlainBlobMetaData(name, summary.getSize())); - } - if (list.isTruncated()) { - prevListing = list; - } else { - break; - } - } - return blobsBuilder.build(); - } - - @Override public ImmutableMap listBlobs() throws IOException { - return listBlobsByPrefix(null); - } - - protected String buildKey(String blobName) { - return keyPath + blobName; - } -} diff --git a/plugins/cloud/aws/src/main/java/org/elasticsearch/cloud/aws/blobstore/S3BlobStore.java b/plugins/cloud/aws/src/main/java/org/elasticsearch/cloud/aws/blobstore/S3BlobStore.java deleted file mode 100644 index e4431891c3d..00000000000 --- a/plugins/cloud/aws/src/main/java/org/elasticsearch/cloud/aws/blobstore/S3BlobStore.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.cloud.aws.blobstore; - -import com.amazonaws.services.s3.AmazonS3; -import com.amazonaws.services.s3.model.ObjectListing; -import com.amazonaws.services.s3.model.S3ObjectSummary; -import org.elasticsearch.common.Nullable; -import org.elasticsearch.common.blobstore.BlobPath; -import org.elasticsearch.common.blobstore.BlobStore; -import org.elasticsearch.common.blobstore.ImmutableBlobContainer; -import org.elasticsearch.common.component.AbstractComponent; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.unit.ByteSizeUnit; -import org.elasticsearch.common.unit.ByteSizeValue; - -import java.util.concurrent.Executor; - -/** - * @author kimchy (shay.banon) - */ -public class S3BlobStore extends AbstractComponent implements BlobStore { - - private final AmazonS3 client; - - private final String bucket; - - private final String region; - - private final Executor executor; - - private final int bufferSizeInBytes; - - public S3BlobStore(Settings settings, AmazonS3 client, String bucket, @Nullable String region, Executor executor) { - super(settings); - this.client = client; - this.bucket = bucket; - this.region = region; - this.executor = executor; - - this.bufferSizeInBytes = (int) settings.getAsBytesSize("buffer_size", new ByteSizeValue(100, ByteSizeUnit.KB)).bytes(); - - if (!client.doesBucketExist(bucket)) { - if (region != null) { - client.createBucket(bucket, region); - } else { - client.createBucket(bucket); - } - } - } - - @Override public String toString() { - return (region == null ? "" : region + "/") + bucket; - } - - public AmazonS3 client() { - return client; - } - - public String bucket() { - return bucket; - } - - public Executor executor() { - return executor; - } - - public int bufferSizeInBytes() { - return bufferSizeInBytes; - } - - @Override public ImmutableBlobContainer immutableBlobContainer(BlobPath path) { - return new S3ImmutableBlobContainer(path, this); - } - - @Override public void delete(BlobPath path) { - ObjectListing prevListing = null; - while (true) { - ObjectListing list; - if (prevListing != null) { - list = client.listNextBatchOfObjects(prevListing); - } else { - list = client.listObjects(bucket, path.buildAsString("/")); - } - for (S3ObjectSummary summary : list.getObjectSummaries()) { - client.deleteObject(summary.getBucketName(), summary.getKey()); - } - if (list.isTruncated()) { - prevListing = list; - } else { - break; - } - } - } - - @Override public void close() { - } -} diff --git a/plugins/cloud/aws/src/main/java/org/elasticsearch/cloud/aws/blobstore/S3ImmutableBlobContainer.java b/plugins/cloud/aws/src/main/java/org/elasticsearch/cloud/aws/blobstore/S3ImmutableBlobContainer.java deleted file mode 100644 index 90a74bdaabf..00000000000 --- a/plugins/cloud/aws/src/main/java/org/elasticsearch/cloud/aws/blobstore/S3ImmutableBlobContainer.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.cloud.aws.blobstore; - -import com.amazonaws.services.s3.model.ObjectMetadata; -import com.amazonaws.services.s3.model.PutObjectResult; -import org.elasticsearch.common.blobstore.BlobPath; -import org.elasticsearch.common.blobstore.ImmutableBlobContainer; -import org.elasticsearch.common.blobstore.support.BlobStores; - -import java.io.IOException; -import java.io.InputStream; - -/** - * @author kimchy (shay.banon) - */ -public class S3ImmutableBlobContainer extends AbstractS3BlobContainer implements ImmutableBlobContainer { - - public S3ImmutableBlobContainer(BlobPath path, S3BlobStore blobStore) { - super(path, blobStore); - } - - @Override public void writeBlob(final String blobName, final InputStream is, final long sizeInBytes, final WriterListener listener) { - blobStore.executor().execute(new Runnable() { - @Override public void run() { - try { - ObjectMetadata md = new ObjectMetadata(); - md.setContentLength(sizeInBytes); - PutObjectResult objectResult = blobStore.client().putObject(blobStore.bucket(), buildKey(blobName), is, md); - listener.onCompleted(); - } catch (Exception e) { - listener.onFailure(e); - } - } - }); - } - - @Override public void writeBlob(String blobName, InputStream is, long sizeInBytes) throws IOException { - BlobStores.syncWriteBlob(this, blobName, is, sizeInBytes); - } -} diff --git a/plugins/cloud/aws/src/main/java/org/elasticsearch/cloud/aws/network/Ec2NameResolver.java b/plugins/cloud/aws/src/main/java/org/elasticsearch/cloud/aws/network/Ec2NameResolver.java deleted file mode 100755 index 6534fc247e3..00000000000 --- a/plugins/cloud/aws/src/main/java/org/elasticsearch/cloud/aws/network/Ec2NameResolver.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.cloud.aws.network; - -import org.elasticsearch.ExceptionsHelper; -import org.elasticsearch.cloud.aws.AwsEc2Service; -import org.elasticsearch.common.component.AbstractComponent; -import org.elasticsearch.common.io.Closeables; -import org.elasticsearch.common.network.NetworkService.CustomNameResolver; -import org.elasticsearch.common.settings.Settings; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.net.InetAddress; -import java.net.URL; -import java.net.URLConnection; - -/** - * Resolves certain ec2 related 'meta' hostnames into an actual hostname - * obtained from ec2 meta-data. - *

- * Valid config values for {@link Ec2HostnameType}s are - - *

    - *
  • _ec2_ - maps to privateIpv4
  • - *
  • _ec2:privateIp_ - maps to privateIpv4
  • - *
  • _ec2:privateIpv4_
  • - *
  • _ec2:privateDns_
  • - *
  • _ec2:publicIp_ - maps to publicIpv4
  • - *
  • _ec2:publicIpv4_
  • - *
  • _ec2:publicDns_
  • - *
- * - * @author Paul_Loy (keteracel) - */ -public class Ec2NameResolver extends AbstractComponent implements CustomNameResolver { - - /** - * enum that can be added to over time with more meta-data types (such as ipv6 when this is available) - * - * @author Paul_Loy - */ - private static enum Ec2HostnameType { - - PRIVATE_IPv4("ec2:privateIpv4", "local-ipv4"), - PRIVATE_DNS("ec2:privateDns", "local-hostname"), - PUBLIC_IPv4("ec2:publicIpv4", "public-ipv4"), - PUBLIC_DNS("ec2:publicDns", "public-hostname"), - - // some less verbose defaults - PUBLIC_IP("ec2:publicIp", PUBLIC_IPv4.ec2Name), - PRIVATE_IP("ec2:privateIp", PRIVATE_IPv4.ec2Name), - EC2("ec2", PRIVATE_IPv4.ec2Name); - - final String configName; - final String ec2Name; - - private Ec2HostnameType(String configName, String ec2Name) { - this.configName = configName; - this.ec2Name = ec2Name; - } - } - - /** - * Construct a {@link CustomNameResolver}. - */ - public Ec2NameResolver(Settings settings) { - super(settings); - } - - /** - * @param type the ec2 hostname type to discover. - * @return the appropriate host resolved from ec2 meta-data. - * @throws IOException if ec2 meta-data cannot be obtained. - * @see CustomNameResolver#resolveIfPossible(String) - */ - public InetAddress resolve(Ec2HostnameType type, boolean warnOnFailure) { - URLConnection urlConnection = null; - InputStream in = null; - try { - URL url = new URL(AwsEc2Service.EC2_METADATA_URL + type.ec2Name); - logger.debug("obtaining ec2 hostname from ec2 meta-data url {}", url); - urlConnection = url.openConnection(); - urlConnection.setConnectTimeout(2000); - in = urlConnection.getInputStream(); - BufferedReader urlReader = new BufferedReader(new InputStreamReader(in)); - - String metadataResult = urlReader.readLine(); - if (metadataResult == null || metadataResult.length() == 0) { - logger.error("no ec2 metadata returned from {}", url); - return null; - } - return InetAddress.getByName(metadataResult); - } catch (IOException e) { - if (warnOnFailure) { - logger.warn("failed to get metadata for [" + type.configName + "]: " + ExceptionsHelper.detailedMessage(e)); - } else { - logger.debug("failed to get metadata for [" + type.configName + "]: " + ExceptionsHelper.detailedMessage(e)); - } - return null; - } finally { - Closeables.closeQuietly(in); - } - } - - @Override public InetAddress resolveDefault() { - return null; // using this, one has to explicitly specify _ec2_ in network setting -// return resolve(Ec2HostnameType.DEFAULT, false); - } - - @Override public InetAddress resolveIfPossible(String value) { - for (Ec2HostnameType type : Ec2HostnameType.values()) { - if (type.configName.equals(value)) { - return resolve(type, true); - } - } - return null; - } - -} diff --git a/plugins/cloud/aws/src/main/java/org/elasticsearch/cloud/aws/node/Ec2CustomNodeAttributes.java b/plugins/cloud/aws/src/main/java/org/elasticsearch/cloud/aws/node/Ec2CustomNodeAttributes.java deleted file mode 100644 index dd942b1a9af..00000000000 --- a/plugins/cloud/aws/src/main/java/org/elasticsearch/cloud/aws/node/Ec2CustomNodeAttributes.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.cloud.aws.node; - -import org.elasticsearch.ExceptionsHelper; -import org.elasticsearch.cloud.aws.AwsEc2Service; -import org.elasticsearch.cluster.node.DiscoveryNodeService; -import org.elasticsearch.common.collect.Maps; -import org.elasticsearch.common.component.AbstractComponent; -import org.elasticsearch.common.io.Closeables; -import org.elasticsearch.common.settings.Settings; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.net.URL; -import java.net.URLConnection; -import java.util.Map; - -/** - */ -public class Ec2CustomNodeAttributes extends AbstractComponent implements DiscoveryNodeService.CustomAttributesProvider { - - public Ec2CustomNodeAttributes(Settings settings) { - super(settings); - } - - @Override public Map buildAttributes() { - if (!settings.getAsBoolean("cloud.node.auto_attributes", false)) { - return null; - } - Map ec2Attributes = Maps.newHashMap(); - - URLConnection urlConnection; - InputStream in = null; - try { - URL url = new URL(AwsEc2Service.EC2_METADATA_URL + "placement/availability-zone"); - logger.debug("obtaining ec2 [placement/availability-zone] from ec2 meta-data url {}", url); - urlConnection = url.openConnection(); - urlConnection.setConnectTimeout(2000); - in = urlConnection.getInputStream(); - BufferedReader urlReader = new BufferedReader(new InputStreamReader(in)); - - String metadataResult = urlReader.readLine(); - if (metadataResult == null || metadataResult.length() == 0) { - logger.error("no ec2 metadata returned from {}", url); - return null; - } - ec2Attributes.put("aws_availability_zone", metadataResult); - } catch (IOException e) { - logger.debug("failed to get metadata for [placement/availability-zone]: " + ExceptionsHelper.detailedMessage(e)); - } finally { - Closeables.closeQuietly(in); - } - - return ec2Attributes; - } -} diff --git a/plugins/cloud/aws/src/main/java/org/elasticsearch/discovery/ec2/AwsEc2UnicastHostsProvider.java b/plugins/cloud/aws/src/main/java/org/elasticsearch/discovery/ec2/AwsEc2UnicastHostsProvider.java deleted file mode 100644 index 556eadf7d6b..00000000000 --- a/plugins/cloud/aws/src/main/java/org/elasticsearch/discovery/ec2/AwsEc2UnicastHostsProvider.java +++ /dev/null @@ -1,195 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.discovery.ec2; - -import com.amazonaws.services.ec2.AmazonEC2; -import com.amazonaws.services.ec2.model.DescribeInstancesRequest; -import com.amazonaws.services.ec2.model.DescribeInstancesResult; -import com.amazonaws.services.ec2.model.Instance; -import com.amazonaws.services.ec2.model.InstanceState; -import com.amazonaws.services.ec2.model.Reservation; -import com.amazonaws.services.ec2.model.Tag; -import org.elasticsearch.cluster.node.DiscoveryNode; -import org.elasticsearch.common.Strings; -import org.elasticsearch.common.collect.ImmutableMap; -import org.elasticsearch.common.collect.ImmutableSet; -import org.elasticsearch.common.collect.Lists; -import org.elasticsearch.common.collect.Sets; -import org.elasticsearch.common.component.AbstractComponent; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.transport.TransportAddress; -import org.elasticsearch.discovery.zen.ping.unicast.UnicastHostsProvider; -import org.elasticsearch.discovery.zen.ping.unicast.UnicastZenPing; -import org.elasticsearch.transport.TransportService; - -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Set; - -/** - * @author kimchy (shay.banon) - */ -public class AwsEc2UnicastHostsProvider extends AbstractComponent implements UnicastHostsProvider { - - private static enum HostType { - PRIVATE_IP, - PUBLIC_IP, - PRIVATE_DNS, - PUBLIC_DNS - } - - private final TransportService transportService; - - private final AmazonEC2 client; - - private final boolean bindAnyGroup; - - private final ImmutableSet groups; - - private final ImmutableMap tags; - - private final ImmutableSet availabilityZones; - - private final HostType hostType; - - @Inject public AwsEc2UnicastHostsProvider(Settings settings, TransportService transportService, AmazonEC2 client) { - super(settings); - this.transportService = transportService; - this.client = client; - - this.hostType = HostType.valueOf(componentSettings.get("host_type", "private_ip").toUpperCase()); - - this.bindAnyGroup = componentSettings.getAsBoolean("any_group", true); - this.groups = ImmutableSet.copyOf(componentSettings.getAsArray("groups")); - - this.tags = componentSettings.getByPrefix("tag.").getAsMap(); - - Set availabilityZones = Sets.newHashSet(componentSettings.getAsArray("availability_zones")); - if (componentSettings.get("availability_zones") != null) { - availabilityZones.addAll(Strings.commaDelimitedListToSet(componentSettings.get("availability_zones"))); - } - this.availabilityZones = ImmutableSet.copyOf(availabilityZones); - - if (logger.isDebugEnabled()) { - logger.debug("using host_type [{}], tags [{}], groups [{}] with any_group [{}], availability_zones [{}]", hostType, tags, groups, bindAnyGroup, availabilityZones); - } - } - - @Override public List buildDynamicNodes() { - List discoNodes = Lists.newArrayList(); - - DescribeInstancesResult descInstances = client.describeInstances(new DescribeInstancesRequest()); - - logger.trace("building dynamic unicast discovery nodes..."); - for (Reservation reservation : descInstances.getReservations()) { - if (!groups.isEmpty()) { - // lets see if we can filter based on groups - List groupNames = reservation.getGroupNames(); - if (bindAnyGroup) { - if (Collections.disjoint(groups, groupNames)) { - logger.trace("filtering out reservation {} based on groups {}, not part of {}", reservation.getReservationId(), groupNames, groups); - // continue to the next reservation - continue; - } - } else { - if (!groupNames.containsAll(groups)) { - logger.trace("filtering out reservation {} based on groups {}, does not include all of {}", reservation.getReservationId(), groupNames, groups); - // continue to the next reservation - continue; - } - } - } - - for (Instance instance : reservation.getInstances()) { - if (!availabilityZones.isEmpty()) { - if (!availabilityZones.contains(instance.getPlacement().getAvailabilityZone())) { - logger.trace("filtering out instance {} based on availability_zone {}, not part of {}", instance.getInstanceId(), instance.getPlacement().getAvailabilityZone(), availabilityZones); - continue; - } - } - // see if we need to filter by tags - boolean filterByTag = false; - if (!tags.isEmpty()) { - if (instance.getTags() == null) { - filterByTag = true; - } else { - // check that all tags listed are there on the instance - for (Map.Entry entry : tags.entrySet()) { - boolean found = false; - for (Tag tag : instance.getTags()) { - if (entry.getKey().equals(tag.getKey()) && entry.getValue().equals(tag.getValue())) { - found = true; - break; - } - } - if (!found) { - filterByTag = true; - break; - } - } - } - } - if (filterByTag) { - logger.trace("filtering out instance {} based tags {}, not part of {}", instance.getInstanceId(), tags, instance.getTags()); - continue; - } - - InstanceState state = instance.getState(); - if (state.getName().equalsIgnoreCase("pending") || state.getName().equalsIgnoreCase("running")) { - String address = null; - switch (hostType) { - case PRIVATE_DNS: - address = instance.getPrivateDnsName(); - break; - case PRIVATE_IP: - address = instance.getPrivateIpAddress(); - break; - case PUBLIC_DNS: - address = instance.getPublicDnsName(); - break; - case PUBLIC_IP: - address = instance.getPublicDnsName(); - break; - } - if (address != null) { - try { - TransportAddress[] addresses = transportService.addressesFromString(address); - // we only limit to 1 addresses, makes no sense to ping 100 ports - for (int i = 0; (i < addresses.length && i < UnicastZenPing.LIMIT_PORTS_COUNT); i++) { - logger.trace("adding {}, address {}, transport_address {}", instance.getInstanceId(), address, addresses[i]); - discoNodes.add(new DiscoveryNode("#cloud-" + instance.getInstanceId() + "-" + i, addresses[i])); - } - } catch (Exception e) { - logger.warn("failed ot add {}, address {}", e, instance.getInstanceId(), address); - } - } else { - logger.trace("not adding {}, address is null, host_type {}", instance.getInstanceId(), hostType); - } - } - } - } - - logger.debug("using dynamic discovery nodes {}", discoNodes); - - return discoNodes; - } -} diff --git a/plugins/cloud/aws/src/main/java/org/elasticsearch/discovery/ec2/Ec2Discovery.java b/plugins/cloud/aws/src/main/java/org/elasticsearch/discovery/ec2/Ec2Discovery.java deleted file mode 100755 index 7005860717f..00000000000 --- a/plugins/cloud/aws/src/main/java/org/elasticsearch/discovery/ec2/Ec2Discovery.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.discovery.ec2; - -import org.elasticsearch.cloud.aws.AwsEc2Service; -import org.elasticsearch.cluster.ClusterName; -import org.elasticsearch.cluster.ClusterService; -import org.elasticsearch.cluster.node.DiscoveryNodeService; -import org.elasticsearch.common.collect.ImmutableList; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.discovery.zen.ZenDiscovery; -import org.elasticsearch.discovery.zen.ping.ZenPing; -import org.elasticsearch.discovery.zen.ping.ZenPingService; -import org.elasticsearch.discovery.zen.ping.unicast.UnicastZenPing; -import org.elasticsearch.node.settings.NodeSettingsService; -import org.elasticsearch.threadpool.ThreadPool; -import org.elasticsearch.transport.TransportService; - -/** - * @author kimchy (shay.banon) - */ -public class Ec2Discovery extends ZenDiscovery { - - @Inject public Ec2Discovery(Settings settings, ClusterName clusterName, ThreadPool threadPool, TransportService transportService, - ClusterService clusterService, NodeSettingsService nodeSettingsService, ZenPingService pingService, - DiscoveryNodeService discoveryNodeService, AwsEc2Service ec2Service) { - super(settings, clusterName, threadPool, transportService, clusterService, nodeSettingsService, discoveryNodeService, pingService); - if (settings.getAsBoolean("cloud.enabled", true)) { - ImmutableList zenPings = pingService.zenPings(); - UnicastZenPing unicastZenPing = null; - for (ZenPing zenPing : zenPings) { - if (zenPing instanceof UnicastZenPing) { - unicastZenPing = (UnicastZenPing) zenPing; - break; - } - } - - if (unicastZenPing != null) { - // update the unicast zen ping to add cloud hosts provider - // and, while we are at it, use only it and not the multicast for example - unicastZenPing.addHostsProvider(new AwsEc2UnicastHostsProvider(settings, transportService, ec2Service.client())); - pingService.zenPings(ImmutableList.of(unicastZenPing)); - } else { - logger.warn("failed to apply ec2 unicast discovery, no unicast ping found"); - } - } - } -} diff --git a/plugins/cloud/aws/src/main/java/org/elasticsearch/discovery/ec2/Ec2DiscoveryModule.java b/plugins/cloud/aws/src/main/java/org/elasticsearch/discovery/ec2/Ec2DiscoveryModule.java deleted file mode 100644 index 09ebce0a518..00000000000 --- a/plugins/cloud/aws/src/main/java/org/elasticsearch/discovery/ec2/Ec2DiscoveryModule.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.discovery.ec2; - -import org.elasticsearch.discovery.Discovery; -import org.elasticsearch.discovery.zen.ZenDiscoveryModule; - -/** - * @author kimchy (shay.banon) - */ -public class Ec2DiscoveryModule extends ZenDiscoveryModule { - - @Override protected void bindDiscovery() { - bind(Discovery.class).to(Ec2Discovery.class).asEagerSingleton(); - } -} diff --git a/plugins/cloud/aws/src/main/java/org/elasticsearch/gateway/s3/S3Gateway.java b/plugins/cloud/aws/src/main/java/org/elasticsearch/gateway/s3/S3Gateway.java deleted file mode 100644 index 8a89e6eed84..00000000000 --- a/plugins/cloud/aws/src/main/java/org/elasticsearch/gateway/s3/S3Gateway.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.gateway.s3; - -import org.elasticsearch.ElasticSearchException; -import org.elasticsearch.ElasticSearchIllegalArgumentException; -import org.elasticsearch.cloud.aws.AwsS3Service; -import org.elasticsearch.cloud.aws.blobstore.S3BlobStore; -import org.elasticsearch.cluster.ClusterName; -import org.elasticsearch.cluster.ClusterService; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.inject.Module; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.unit.ByteSizeUnit; -import org.elasticsearch.common.unit.ByteSizeValue; -import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.common.util.concurrent.DynamicExecutors; -import org.elasticsearch.common.util.concurrent.EsExecutors; -import org.elasticsearch.gateway.blobstore.BlobStoreGateway; -import org.elasticsearch.index.gateway.s3.S3IndexGatewayModule; -import org.elasticsearch.threadpool.ThreadPool; - -import java.io.IOException; -import java.util.concurrent.ExecutorService; - -/** - * @author kimchy (shay.banon) - */ -public class S3Gateway extends BlobStoreGateway { - - private final ExecutorService concurrentStreamPool; - - @Inject public S3Gateway(Settings settings, ThreadPool threadPool, ClusterService clusterService, - ClusterName clusterName, AwsS3Service s3Service) throws IOException { - super(settings, threadPool, clusterService); - - String bucket = componentSettings.get("bucket"); - if (bucket == null) { - throw new ElasticSearchIllegalArgumentException("No bucket defined for s3 gateway"); - } - - String region = componentSettings.get("region"); - if (region == null) { - if (settings.get("cloud.aws.region") != null) { - String regionSetting = settings.get("cloud.aws.region"); - if ("us-east".equals(regionSetting.toLowerCase())) { - region = null; - } else if ("us-east-1".equals(regionSetting.toLowerCase())) { - region = null; - } else if ("us-west".equals(regionSetting.toLowerCase())) { - region = "us-west-1"; - } else if ("us-west-1".equals(regionSetting.toLowerCase())) { - region = "us-west-1"; - } else if ("ap-southeast".equals(regionSetting.toLowerCase())) { - region = "ap-southeast-1"; - } else if ("ap-southeast-1".equals(regionSetting.toLowerCase())) { - region = "ap-southeast-1"; - } else if ("eu-west".equals(regionSetting.toLowerCase())) { - region = "EU"; - } else if ("eu-west-1".equals(regionSetting.toLowerCase())) { - region = "EU"; - } - } - } - ByteSizeValue chunkSize = componentSettings.getAsBytesSize("chunk_size", new ByteSizeValue(100, ByteSizeUnit.MB)); - - int concurrentStreams = componentSettings.getAsInt("concurrent_streams", 5); - this.concurrentStreamPool = DynamicExecutors.newScalingThreadPool(1, concurrentStreams, TimeValue.timeValueSeconds(5).millis(), EsExecutors.daemonThreadFactory(settings, "[s3_stream]")); - - logger.debug("using bucket [{}], region [{}], chunk_size [{}], concurrent_streams [{}]", bucket, region, chunkSize, concurrentStreams); - - initialize(new S3BlobStore(settings, s3Service.client(), bucket, region, concurrentStreamPool), clusterName, chunkSize); - } - - @Override protected void doClose() throws ElasticSearchException { - super.doClose(); - concurrentStreamPool.shutdown(); - } - - @Override public String type() { - return "s3"; - } - - @Override public Class suggestIndexGateway() { - return S3IndexGatewayModule.class; - } -} diff --git a/plugins/cloud/aws/src/main/java/org/elasticsearch/gateway/s3/S3GatewayModule.java b/plugins/cloud/aws/src/main/java/org/elasticsearch/gateway/s3/S3GatewayModule.java deleted file mode 100644 index ebe9e8026b1..00000000000 --- a/plugins/cloud/aws/src/main/java/org/elasticsearch/gateway/s3/S3GatewayModule.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.gateway.s3; - -import org.elasticsearch.gateway.Gateway; -import org.elasticsearch.gateway.blobstore.BlobStoreGatewayModule; - -/** - * @author kimchy (shay.banon) - */ -public class S3GatewayModule extends BlobStoreGatewayModule { - - @Override protected void configure() { - bind(Gateway.class).to(S3Gateway.class).asEagerSingleton(); - } -} diff --git a/plugins/cloud/aws/src/main/java/org/elasticsearch/index/gateway/s3/S3IndexGateway.java b/plugins/cloud/aws/src/main/java/org/elasticsearch/index/gateway/s3/S3IndexGateway.java deleted file mode 100644 index a79989ff0ee..00000000000 --- a/plugins/cloud/aws/src/main/java/org/elasticsearch/index/gateway/s3/S3IndexGateway.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.index.gateway.s3; - -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.gateway.Gateway; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.gateway.IndexShardGateway; -import org.elasticsearch.index.gateway.blobstore.BlobStoreIndexGateway; -import org.elasticsearch.index.settings.IndexSettings; - -/** - * @author kimchy (shay.banon) - */ -public class S3IndexGateway extends BlobStoreIndexGateway { - - @Inject public S3IndexGateway(Index index, @IndexSettings Settings indexSettings, Gateway gateway) { - super(index, indexSettings, gateway); - } - - @Override public String type() { - return "s3"; - } - - @Override public Class shardGatewayClass() { - return S3IndexShardGateway.class; - } -} - diff --git a/plugins/cloud/aws/src/main/java/org/elasticsearch/index/gateway/s3/S3IndexGatewayModule.java b/plugins/cloud/aws/src/main/java/org/elasticsearch/index/gateway/s3/S3IndexGatewayModule.java deleted file mode 100644 index 005f141bf49..00000000000 --- a/plugins/cloud/aws/src/main/java/org/elasticsearch/index/gateway/s3/S3IndexGatewayModule.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.index.gateway.s3; - -import org.elasticsearch.common.inject.AbstractModule; -import org.elasticsearch.index.gateway.IndexGateway; - -/** - * @author kimchy (shay.banon) - */ -public class S3IndexGatewayModule extends AbstractModule { - - @Override protected void configure() { - bind(IndexGateway.class).to(S3IndexGateway.class).asEagerSingleton(); - } -} diff --git a/plugins/cloud/aws/src/main/java/org/elasticsearch/index/gateway/s3/S3IndexShardGateway.java b/plugins/cloud/aws/src/main/java/org/elasticsearch/index/gateway/s3/S3IndexShardGateway.java deleted file mode 100644 index 02c71d2aa5e..00000000000 --- a/plugins/cloud/aws/src/main/java/org/elasticsearch/index/gateway/s3/S3IndexShardGateway.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.index.gateway.s3; - -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.gateway.IndexGateway; -import org.elasticsearch.index.gateway.blobstore.BlobStoreIndexShardGateway; -import org.elasticsearch.index.settings.IndexSettings; -import org.elasticsearch.index.shard.ShardId; -import org.elasticsearch.index.shard.service.IndexShard; -import org.elasticsearch.index.store.Store; -import org.elasticsearch.threadpool.ThreadPool; - -/** - * @author kimchy (shay.banon) - */ -public class S3IndexShardGateway extends BlobStoreIndexShardGateway { - - @Inject public S3IndexShardGateway(ShardId shardId, @IndexSettings Settings indexSettings, ThreadPool threadPool, IndexGateway indexGateway, - IndexShard indexShard, Store store) { - super(shardId, indexSettings, threadPool, indexGateway, indexShard, store); - } - - @Override public String type() { - return "s3"; - } -} - diff --git a/plugins/cloud/aws/src/main/java/org/elasticsearch/plugin/cloud/aws/CloudAwsPlugin.java b/plugins/cloud/aws/src/main/java/org/elasticsearch/plugin/cloud/aws/CloudAwsPlugin.java deleted file mode 100644 index af0bc2e8cc0..00000000000 --- a/plugins/cloud/aws/src/main/java/org/elasticsearch/plugin/cloud/aws/CloudAwsPlugin.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.plugin.cloud.aws; - -import org.elasticsearch.cloud.aws.AwsEc2Service; -import org.elasticsearch.cloud.aws.AwsModule; -import org.elasticsearch.cloud.aws.AwsS3Service; -import org.elasticsearch.common.collect.Lists; -import org.elasticsearch.common.component.LifecycleComponent; -import org.elasticsearch.common.inject.Module; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.plugins.AbstractPlugin; - -import java.util.Collection; - -/** - * @author kimchy (shay.banon) - */ -public class CloudAwsPlugin extends AbstractPlugin { - - private final Settings settings; - - public CloudAwsPlugin(Settings settings) { - this.settings = settings; - } - - @Override public String name() { - return "cloud-aws"; - } - - @Override public String description() { - return "Cloud AWS Plugin"; - } - - @Override public Collection> modules() { - Collection> modules = Lists.newArrayList(); - if (settings.getAsBoolean("cloud.enabled", true)) { - modules.add(AwsModule.class); - } - return modules; - } - - @Override public Collection> services() { - Collection> services = Lists.newArrayList(); - if (settings.getAsBoolean("cloud.enabled", true)) { - services.add(AwsS3Service.class); - services.add(AwsEc2Service.class); - } - return services; - } -} diff --git a/plugins/hadoop/build.gradle b/plugins/hadoop/build.gradle deleted file mode 100644 index 329bef93eed..00000000000 --- a/plugins/hadoop/build.gradle +++ /dev/null @@ -1,138 +0,0 @@ -dependsOn(':elasticsearch') - -apply plugin: 'java' -apply plugin: 'maven' -apply plugin: 'eclipse' - -archivesBaseName = "elasticsearch-hadoop" - -explodedDistDir = new File(distsDir, 'exploded') - -configurations.compile.transitive = true -configurations.testCompile.transitive = true - -// no need to use the resource dir -sourceSets.main.resources.srcDirs 'src/main/java' -sourceSets.test.resources.srcDirs 'src/test/java' - -// add the source files to the dist jar -//jar { -// from sourceSets.main.allJava -//} - -configurations { - dists - distLib { - visible = false - } -} - -dependencies { - compile project(':elasticsearch') - compile("org.apache.hadoop:hadoop-core:0.20.2") { transitive = false } - runtime("commons-logging:commons-logging:1.1.1") { transitive = false } - - distLib("org.apache.hadoop:hadoop-core:0.20.2") { transitive = false } - distLib("commons-logging:commons-logging:1.1.1") { transitive = false } -} - -task explodedDist(dependsOn: [jar], description: 'Builds the plugin zip file') << { - [explodedDistDir]*.mkdirs() - - copy { - from configurations.distLib - into explodedDistDir - } - - // remove elasticsearch files (compile above adds the elasticsearch one) - ant.delete { fileset(dir: explodedDistDir, includes: "elasticsearch-*.jar") } - - copy { - from libsDir - into explodedDistDir - } - - ant.delete { fileset(dir: explodedDistDir, includes: "elasticsearch-*-javadoc.jar") } - ant.delete { fileset(dir: explodedDistDir, includes: "elasticsearch-*-sources.jar") } -} - -task zip(type: Zip, dependsOn: ['explodedDist']) { - from(explodedDistDir) { - } -} - -task release(dependsOn: [zip]) << { - ant.delete(dir: explodedDistDir) - copy { - from distsDir - into(new File(rootProject.distsDir, "plugins")) - } -} - -configurations { - deployerJars -} - -dependencies { - deployerJars "org.apache.maven.wagon:wagon-http:1.0-beta-2" -} - -task sourcesJar(type: Jar, dependsOn: classes) { - classifier = 'sources' - from sourceSets.main.allSource -} - -task javadocJar(type: Jar, dependsOn: javadoc) { - classifier = 'javadoc' - from javadoc.destinationDir -} - -jar { -// from sourceSets.main.allJava - manifest { - attributes("Implementation-Title": "ElasticSearch", "Implementation-Version": rootProject.version, "Implementation-Date": buildTimeStr) - } -} - -artifacts { - archives sourcesJar - archives javadocJar -} - -uploadArchives { - repositories.mavenDeployer { - configuration = configurations.deployerJars - repository(url: rootProject.mavenRepoUrl) { - authentication(userName: rootProject.mavenRepoUser, password: rootProject.mavenRepoPass) - } - snapshotRepository(url: rootProject.mavenSnapshotRepoUrl) { - authentication(userName: rootProject.mavenRepoUser, password: rootProject.mavenRepoPass) - } - - pom.project { - inceptionYear '2009' - name 'elasticsearch-plugins-hadoop' - description 'Hadoop Plugin for ElasticSearch' - licenses { - license { - name 'The Apache Software License, Version 2.0' - url 'http://www.apache.org/licenses/LICENSE-2.0.txt' - distribution 'repo' - } - } - scm { - connection 'git://github.com/elasticsearch/elasticsearch.git' - developerConnection 'git@github.com:elasticsearch/elasticsearch.git' - url 'http://github.com/elasticsearch/elasticsearch' - } - } - - pom.whenConfigured {pom -> - pom.dependencies = pom.dependencies.findAll {dep -> dep.scope != 'test' } // removes the test scoped ones - } - } -} - -eclipseClasspath { - defaultOutputDir = file('build/eclipse-build') -} diff --git a/plugins/hadoop/src/main/java/es-plugin.properties b/plugins/hadoop/src/main/java/es-plugin.properties deleted file mode 100644 index 54382bb9d84..00000000000 --- a/plugins/hadoop/src/main/java/es-plugin.properties +++ /dev/null @@ -1 +0,0 @@ -plugin=org.elasticsearch.plugin.hadoop.HadoopPlugin diff --git a/plugins/hadoop/src/main/java/org/elasticsearch/common/blobstore/hdfs/AbstractHdfsBlobContainer.java b/plugins/hadoop/src/main/java/org/elasticsearch/common/blobstore/hdfs/AbstractHdfsBlobContainer.java deleted file mode 100644 index 49ac1f556e2..00000000000 --- a/plugins/hadoop/src/main/java/org/elasticsearch/common/blobstore/hdfs/AbstractHdfsBlobContainer.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.common.blobstore.hdfs; - -import org.apache.hadoop.fs.FSDataInputStream; -import org.apache.hadoop.fs.FileStatus; -import org.apache.hadoop.fs.Path; -import org.apache.hadoop.fs.PathFilter; -import org.elasticsearch.common.blobstore.BlobMetaData; -import org.elasticsearch.common.blobstore.BlobPath; -import org.elasticsearch.common.blobstore.support.AbstractBlobContainer; -import org.elasticsearch.common.blobstore.support.PlainBlobMetaData; -import org.elasticsearch.common.collect.ImmutableMap; - -import java.io.IOException; - -/** - * @author kimchy (shay.banon) - */ -public abstract class AbstractHdfsBlobContainer extends AbstractBlobContainer { - - protected final HdfsBlobStore blobStore; - - protected final Path path; - - public AbstractHdfsBlobContainer(HdfsBlobStore blobStore, BlobPath blobPath, Path path) { - super(blobPath); - this.blobStore = blobStore; - this.path = path; - } - - public ImmutableMap listBlobs() throws IOException { - FileStatus[] files = blobStore.fileSystem().listStatus(path); - if (files == null || files.length == 0) { - return ImmutableMap.of(); - } - ImmutableMap.Builder builder = ImmutableMap.builder(); - for (FileStatus file : files) { - builder.put(file.getPath().getName(), new PlainBlobMetaData(file.getPath().getName(), file.getLen())); - } - return builder.build(); - } - - @Override public ImmutableMap listBlobsByPrefix(final String blobNamePrefix) throws IOException { - FileStatus[] files = blobStore.fileSystem().listStatus(path, new PathFilter() { - @Override public boolean accept(Path path) { - return path.getName().startsWith(blobNamePrefix); - } - }); - if (files == null || files.length == 0) { - return ImmutableMap.of(); - } - ImmutableMap.Builder builder = ImmutableMap.builder(); - for (FileStatus file : files) { - builder.put(file.getPath().getName(), new PlainBlobMetaData(file.getPath().getName(), file.getLen())); - } - return builder.build(); - } - - public boolean deleteBlob(String blobName) throws IOException { - return blobStore.fileSystem().delete(new Path(path, blobName), true); - } - - @Override public boolean blobExists(String blobName) { - try { - return blobStore.fileSystem().exists(new Path(path, blobName)); - } catch (IOException e) { - return false; - } - } - - @Override public void readBlob(final String blobName, final ReadBlobListener listener) { - blobStore.executor().execute(new Runnable() { - @Override public void run() { - byte[] buffer = new byte[blobStore.bufferSizeInBytes()]; - - - FSDataInputStream fileStream; - try { - fileStream = blobStore.fileSystem().open(new Path(path, blobName)); - } catch (IOException e) { - listener.onFailure(e); - return; - } - try { - int bytesRead; - while ((bytesRead = fileStream.read(buffer)) != -1) { - listener.onPartial(buffer, 0, bytesRead); - } - listener.onCompleted(); - } catch (Exception e) { - try { - fileStream.close(); - } catch (IOException e1) { - // ignore - } - listener.onFailure(e); - } - } - }); - } -} \ No newline at end of file diff --git a/plugins/hadoop/src/main/java/org/elasticsearch/common/blobstore/hdfs/HdfsBlobStore.java b/plugins/hadoop/src/main/java/org/elasticsearch/common/blobstore/hdfs/HdfsBlobStore.java deleted file mode 100644 index 28471403bd4..00000000000 --- a/plugins/hadoop/src/main/java/org/elasticsearch/common/blobstore/hdfs/HdfsBlobStore.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.common.blobstore.hdfs; - -import org.apache.hadoop.fs.FileSystem; -import org.apache.hadoop.fs.Path; -import org.elasticsearch.common.blobstore.BlobPath; -import org.elasticsearch.common.blobstore.BlobStore; -import org.elasticsearch.common.blobstore.ImmutableBlobContainer; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.unit.ByteSizeUnit; -import org.elasticsearch.common.unit.ByteSizeValue; - -import java.io.IOException; -import java.util.concurrent.Executor; - -/** - * @author kimchy (shay.banon) - */ -public class HdfsBlobStore implements BlobStore { - - private final FileSystem fileSystem; - - private final Path path; - - private final Executor executor; - - private final int bufferSizeInBytes; - - public HdfsBlobStore(Settings settings, FileSystem fileSystem, Executor executor, Path path) throws IOException { - this.fileSystem = fileSystem; - this.path = path; - - if (!fileSystem.exists(path)) { - fileSystem.mkdirs(path); - } - - this.bufferSizeInBytes = (int) settings.getAsBytesSize("buffer_size", new ByteSizeValue(100, ByteSizeUnit.KB)).bytes(); - this.executor = executor; - } - - @Override public String toString() { - return path.toString(); - } - - public int bufferSizeInBytes() { - return this.bufferSizeInBytes; - } - - public FileSystem fileSystem() { - return fileSystem; - } - - public Path path() { - return path; - } - - public Executor executor() { - return executor; - } - - @Override public ImmutableBlobContainer immutableBlobContainer(BlobPath path) { - return new HdfsImmutableBlobContainer(this, path, buildAndCreate(path)); - } - - @Override public void delete(BlobPath path) { - try { - fileSystem.delete(buildPath(path), true); - } catch (IOException e) { - // ignore - } - } - - @Override public void close() { - } - - private Path buildAndCreate(BlobPath blobPath) { - Path path = buildPath(blobPath); - try { - fileSystem.mkdirs(path); - } catch (IOException e) { - // ignore - } - return path; - } - - private Path buildPath(BlobPath blobPath) { - Path path = this.path; - for (String p : blobPath) { - path = new Path(path, p); - } - return path; - } -} diff --git a/plugins/hadoop/src/main/java/org/elasticsearch/common/blobstore/hdfs/HdfsImmutableBlobContainer.java b/plugins/hadoop/src/main/java/org/elasticsearch/common/blobstore/hdfs/HdfsImmutableBlobContainer.java deleted file mode 100644 index 8959027d446..00000000000 --- a/plugins/hadoop/src/main/java/org/elasticsearch/common/blobstore/hdfs/HdfsImmutableBlobContainer.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.common.blobstore.hdfs; - -import org.apache.hadoop.fs.FSDataOutputStream; -import org.apache.hadoop.fs.Path; -import org.elasticsearch.common.blobstore.BlobPath; -import org.elasticsearch.common.blobstore.ImmutableBlobContainer; -import org.elasticsearch.common.blobstore.support.BlobStores; - -import java.io.IOException; -import java.io.InputStream; - -/** - * @author kimchy (shay.banon) - */ -public class HdfsImmutableBlobContainer extends AbstractHdfsBlobContainer implements ImmutableBlobContainer { - - public HdfsImmutableBlobContainer(HdfsBlobStore blobStore, BlobPath blobPath, Path path) { - super(blobStore, blobPath, path); - } - - @Override public void writeBlob(final String blobName, final InputStream is, final long sizeInBytes, final WriterListener listener) { - blobStore.executor().execute(new Runnable() { - @Override public void run() { - Path file = new Path(path, blobName); - - FSDataOutputStream fileStream; - try { - fileStream = blobStore.fileSystem().create(file, true); - } catch (IOException e) { - listener.onFailure(e); - return; - } - try { - try { - byte[] buffer = new byte[blobStore.bufferSizeInBytes()]; - int bytesRead; - while ((bytesRead = is.read(buffer)) != -1) { - fileStream.write(buffer, 0, bytesRead); - } - } finally { - try { - is.close(); - } catch (IOException ex) { - // do nothing - } - try { - fileStream.close(); - } catch (IOException ex) { - // do nothing - } - } - listener.onCompleted(); - } catch (Exception e) { - // just on the safe size, try and delete it on failure - try { - if (blobStore.fileSystem().exists(file)) { - blobStore.fileSystem().delete(file, true); - } - } catch (Exception e1) { - // ignore - } - listener.onFailure(e); - } - } - }); - } - - @Override public void writeBlob(String blobName, InputStream is, long sizeInBytes) throws IOException { - BlobStores.syncWriteBlob(this, blobName, is, sizeInBytes); - } -} \ No newline at end of file diff --git a/plugins/hadoop/src/main/java/org/elasticsearch/gateway/hdfs/HdfsGateway.java b/plugins/hadoop/src/main/java/org/elasticsearch/gateway/hdfs/HdfsGateway.java deleted file mode 100644 index 78931047acd..00000000000 --- a/plugins/hadoop/src/main/java/org/elasticsearch/gateway/hdfs/HdfsGateway.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.gateway.hdfs; - -import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.fs.FileSystem; -import org.apache.hadoop.fs.Path; -import org.elasticsearch.ElasticSearchException; -import org.elasticsearch.ElasticSearchIllegalArgumentException; -import org.elasticsearch.cluster.ClusterName; -import org.elasticsearch.cluster.ClusterService; -import org.elasticsearch.common.blobstore.hdfs.HdfsBlobStore; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.inject.Module; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.common.util.concurrent.DynamicExecutors; -import org.elasticsearch.common.util.concurrent.EsExecutors; -import org.elasticsearch.gateway.blobstore.BlobStoreGateway; -import org.elasticsearch.threadpool.ThreadPool; - -import java.io.IOException; -import java.net.URI; -import java.util.Map; -import java.util.concurrent.ExecutorService; - -/** - * @author kimchy (shay.banon) - */ -public class HdfsGateway extends BlobStoreGateway { - - private final boolean closeFileSystem; - - private final FileSystem fileSystem; - - private final ExecutorService concurrentStreamPool; - - @Inject public HdfsGateway(Settings settings, ThreadPool threadPool, ClusterService clusterService, - ClusterName clusterName) throws IOException { - super(settings, threadPool, clusterService); - - this.closeFileSystem = componentSettings.getAsBoolean("close_fs", true); - String uri = componentSettings.get("uri"); - if (uri == null) { - throw new ElasticSearchIllegalArgumentException("hdfs gateway requires the 'uri' setting to be set"); - } - String path = componentSettings.get("path"); - if (path == null) { - throw new ElasticSearchIllegalArgumentException("hdfs gateway requires the 'path' path setting to be set"); - } - Path hPath = new Path(new Path(path), clusterName.value()); - - int concurrentStreams = componentSettings.getAsInt("concurrent_streams", 5); - this.concurrentStreamPool = DynamicExecutors.newScalingThreadPool(1, concurrentStreams, TimeValue.timeValueSeconds(5).millis(), EsExecutors.daemonThreadFactory(settings, "[s3_stream]")); - - logger.debug("Using uri [{}], path [{}], concurrent_streams [{}]", uri, hPath, concurrentStreams); - - Configuration conf = new Configuration(); - Settings hdfsSettings = settings.getByPrefix("hdfs.conf."); - for (Map.Entry entry : hdfsSettings.getAsMap().entrySet()) { - conf.set(entry.getKey(), entry.getValue()); - } - - fileSystem = FileSystem.get(URI.create(uri), conf); - - initialize(new HdfsBlobStore(settings, fileSystem, concurrentStreamPool, hPath), clusterName, null); - } - - @Override public String type() { - return "hdfs"; - } - - @Override public Class suggestIndexGateway() { - return HdfsIndexGatewayModule.class; - } - - @Override protected void doClose() throws ElasticSearchException { - super.doClose(); - if (closeFileSystem) { - try { - fileSystem.close(); - } catch (IOException e) { - // ignore - } - } - concurrentStreamPool.shutdown(); - } -} diff --git a/plugins/hadoop/src/main/java/org/elasticsearch/gateway/hdfs/HdfsGatewayModule.java b/plugins/hadoop/src/main/java/org/elasticsearch/gateway/hdfs/HdfsGatewayModule.java deleted file mode 100644 index 4678035b8fa..00000000000 --- a/plugins/hadoop/src/main/java/org/elasticsearch/gateway/hdfs/HdfsGatewayModule.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.gateway.hdfs; - -import org.elasticsearch.gateway.Gateway; -import org.elasticsearch.gateway.blobstore.BlobStoreGatewayModule; - -/** - * @author kimchy (shay.banon) - */ -public class HdfsGatewayModule extends BlobStoreGatewayModule { - - @Override protected void configure() { - bind(Gateway.class).to(HdfsGateway.class).asEagerSingleton(); - } -} \ No newline at end of file diff --git a/plugins/hadoop/src/main/java/org/elasticsearch/gateway/hdfs/HdfsIndexGatewayModule.java b/plugins/hadoop/src/main/java/org/elasticsearch/gateway/hdfs/HdfsIndexGatewayModule.java deleted file mode 100644 index 68c5c9ee8a4..00000000000 --- a/plugins/hadoop/src/main/java/org/elasticsearch/gateway/hdfs/HdfsIndexGatewayModule.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.gateway.hdfs; - -import org.elasticsearch.common.inject.AbstractModule; -import org.elasticsearch.index.gateway.IndexGateway; -import org.elasticsearch.index.gateway.hdfs.HdfsIndexGateway; - -/** - * @author kimchy (Shay Banon) - */ -public class HdfsIndexGatewayModule extends AbstractModule { - - @Override protected void configure() { - bind(IndexGateway.class).to(HdfsIndexGateway.class).asEagerSingleton(); - } -} \ No newline at end of file diff --git a/plugins/hadoop/src/main/java/org/elasticsearch/index/gateway/hdfs/HdfsIndexGateway.java b/plugins/hadoop/src/main/java/org/elasticsearch/index/gateway/hdfs/HdfsIndexGateway.java deleted file mode 100644 index 1ef7041dfec..00000000000 --- a/plugins/hadoop/src/main/java/org/elasticsearch/index/gateway/hdfs/HdfsIndexGateway.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.index.gateway.hdfs; - -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.gateway.Gateway; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.gateway.IndexShardGateway; -import org.elasticsearch.index.gateway.blobstore.BlobStoreIndexGateway; -import org.elasticsearch.index.settings.IndexSettings; - -/** - * @author kimchy (shay.banon) - */ -public class HdfsIndexGateway extends BlobStoreIndexGateway { - - @Inject public HdfsIndexGateway(Index index, @IndexSettings Settings indexSettings, Gateway gateway) { - super(index, indexSettings, gateway); - } - - @Override public String type() { - return "hdfs"; - } - - @Override public Class shardGatewayClass() { - return HdfsIndexShardGateway.class; - } -} diff --git a/plugins/hadoop/src/main/java/org/elasticsearch/index/gateway/hdfs/HdfsIndexShardGateway.java b/plugins/hadoop/src/main/java/org/elasticsearch/index/gateway/hdfs/HdfsIndexShardGateway.java deleted file mode 100644 index 85fdbdab2ed..00000000000 --- a/plugins/hadoop/src/main/java/org/elasticsearch/index/gateway/hdfs/HdfsIndexShardGateway.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.index.gateway.hdfs; - -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.gateway.IndexGateway; -import org.elasticsearch.index.gateway.blobstore.BlobStoreIndexShardGateway; -import org.elasticsearch.index.settings.IndexSettings; -import org.elasticsearch.index.shard.ShardId; -import org.elasticsearch.index.shard.service.IndexShard; -import org.elasticsearch.index.store.Store; -import org.elasticsearch.threadpool.ThreadPool; - -/** - * @author kimchy (shay.banon) - */ -public class HdfsIndexShardGateway extends BlobStoreIndexShardGateway { - - @Inject public HdfsIndexShardGateway(ShardId shardId, @IndexSettings Settings indexSettings, ThreadPool threadPool, IndexGateway hdfsIndexGateway, - IndexShard indexShard, Store store) { - super(shardId, indexSettings, threadPool, hdfsIndexGateway, indexShard, store); - } - - @Override public String type() { - return "hdfs"; - } -} diff --git a/plugins/hadoop/src/main/java/org/elasticsearch/plugin/hadoop/HadoopPlugin.java b/plugins/hadoop/src/main/java/org/elasticsearch/plugin/hadoop/HadoopPlugin.java deleted file mode 100644 index 1fdace23f19..00000000000 --- a/plugins/hadoop/src/main/java/org/elasticsearch/plugin/hadoop/HadoopPlugin.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.plugin.hadoop; - -import org.elasticsearch.plugins.AbstractPlugin; - -/** - * @author kimchy (shay.banon) - */ -public class HadoopPlugin extends AbstractPlugin { - - @Override public String name() { - return "hadoop"; - } - - @Override public String description() { - return "Hadoop Plugin"; - } -} diff --git a/plugins/hadoop/src/test/java/org/elasticsearch/hadoop/gateway/HdfsGatewayTests.java b/plugins/hadoop/src/test/java/org/elasticsearch/hadoop/gateway/HdfsGatewayTests.java deleted file mode 100644 index 1c23bb2f263..00000000000 --- a/plugins/hadoop/src/test/java/org/elasticsearch/hadoop/gateway/HdfsGatewayTests.java +++ /dev/null @@ -1,226 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.hadoop.gateway; - -import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; -import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus; -import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse; -import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; -import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse; -import org.elasticsearch.action.get.GetResponse; -import org.elasticsearch.client.Requests; -import org.elasticsearch.common.logging.ESLogger; -import org.elasticsearch.common.logging.Loggers; -import org.elasticsearch.common.network.NetworkUtils; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.gateway.Gateway; -import org.elasticsearch.indices.IndexAlreadyExistsException; -import org.elasticsearch.node.Node; -import org.elasticsearch.node.internal.InternalNode; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import static org.elasticsearch.client.Requests.*; -import static org.elasticsearch.common.settings.ImmutableSettings.*; -import static org.elasticsearch.node.NodeBuilder.*; -import static org.hamcrest.MatcherAssert.*; -import static org.hamcrest.Matchers.*; - -/** - * @author kimchy (shay.banon) - */ -public class HdfsGatewayTests { - - protected final ESLogger logger = Loggers.getLogger(getClass()); - - private Node node; - - @BeforeMethod void setUpNodes() throws Exception { - // start the node and reset the gateway - node = buildNode(); - ((InternalNode) node).injector().getInstance(Gateway.class).reset(); - node.close(); - // now start the node clean - node = buildNode().start(); - } - - private Node buildNode() { - Settings settings = settingsBuilder() - .put("cluster.name", "test-cluster-" + NetworkUtils.getLocalAddress().getHostName()) - .put("gateway.type", "hdfs") - .put("gateway.hdfs.uri", "file:///") -// .put("gateway.hdfs.uri", "hdfs://training-vm.local:8022") - .put("gateway.hdfs.path", "data/hdfs/gateway") - .build(); - return nodeBuilder().settings(settingsBuilder().put(settings).put("node.name", "node1")).build(); - } - - @AfterMethod void closeNodes() throws Exception { - node.stop(); - ((InternalNode) node).injector().getInstance(Gateway.class).reset(); - node.close(); - } - - @Test public void testHdfsGateway() throws Exception { - // first, test meta data - CreateIndexResponse createIndexResponse = node.client().admin().indices().create(createIndexRequest("test")).actionGet(); - assertThat(createIndexResponse.acknowledged(), equalTo(true)); - node.close(); - node = buildNode().start(); - - logger.info("--> waiting for green status"); - ClusterHealthResponse health = node.client().admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet(); - assertThat(health.timedOut(), equalTo(false)); - - try { - node.client().admin().indices().create(createIndexRequest("test")).actionGet(); - assert false : "index should exists"; - } catch (IndexAlreadyExistsException e) { - // all is well - } - - logger.info("Running Cluster Health (wait for the shards to startup)"); - ClusterHealthResponse clusterHealth = node.client().admin().cluster().health(clusterHealthRequest().waitForYellowStatus().waitForActiveShards(1)).actionGet(); - logger.info("Done Cluster Health, status " + clusterHealth.status()); - assertThat(clusterHealth.timedOut(), equalTo(false)); - assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.YELLOW)); - - // Translog tests - // create a mapping - PutMappingResponse putMappingResponse = node.client().admin().indices().putMapping(putMappingRequest("test").type("type1") - .source(mappingSource())).actionGet(); - assertThat(putMappingResponse.acknowledged(), equalTo(true)); - - // verify that mapping is there - ClusterStateResponse clusterState = node.client().admin().cluster().state(clusterStateRequest()).actionGet(); - assertThat(clusterState.state().metaData().index("test").mapping("type1"), notNullValue()); - - // create two and delete the first - logger.info("Indexing #1"); - node.client().index(Requests.indexRequest("test").type("type1").id("1").source(source("1", "test"))).actionGet(); - logger.info("Indexing #2"); - node.client().index(Requests.indexRequest("test").type("type1").id("2").source(source("2", "test"))).actionGet(); - logger.info("Deleting #1"); - node.client().delete(deleteRequest("test").type("type1").id("1")).actionGet(); - - // perform snapshot to the index - logger.info("Gateway Snapshot"); - node.client().admin().indices().gatewaySnapshot(gatewaySnapshotRequest("test")).actionGet(); - logger.info("Gateway Snapshot (should be a no op)"); - // do it again, it should be a no op - node.client().admin().indices().gatewaySnapshot(gatewaySnapshotRequest("test")).actionGet(); - - logger.info("Closing the server"); - node.close(); - logger.info("Starting the server, should recover from the gateway (only translog should be populated)"); - node = buildNode().start(); - - logger.info("Running Cluster Health (wait for the shards to startup)"); - clusterHealth = node.client().admin().cluster().health(clusterHealthRequest().waitForYellowStatus().waitForActiveShards(1)).actionGet(); - logger.info("Done Cluster Health, status " + clusterHealth.status()); - assertThat(clusterHealth.timedOut(), equalTo(false)); - assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.YELLOW)); - - // verify that mapping is there - clusterState = node.client().admin().cluster().state(clusterStateRequest()).actionGet(); - assertThat(clusterState.state().metaData().index("test").mapping("type1"), notNullValue()); - - logger.info("Getting #1, should not exists"); - GetResponse getResponse = node.client().get(getRequest("test").type("type1").id("1")).actionGet(); - assertThat(getResponse.exists(), equalTo(false)); - logger.info("Getting #2"); - getResponse = node.client().get(getRequest("test").type("type1").id("2")).actionGet(); - assertThat(getResponse.sourceAsString(), equalTo(source("2", "test"))); - - // Now flush and add some data (so we have index recovery as well) - logger.info("Flushing, so we have actual content in the index files (#2 should be in the index)"); - node.client().admin().indices().flush(flushRequest("test")).actionGet(); - logger.info("Indexing #3, so we have something in the translog as well"); - node.client().index(Requests.indexRequest("test").type("type1").id("3").source(source("3", "test"))).actionGet(); - - logger.info("Gateway Snapshot"); - node.client().admin().indices().gatewaySnapshot(gatewaySnapshotRequest("test")).actionGet(); - logger.info("Gateway Snapshot (should be a no op)"); - node.client().admin().indices().gatewaySnapshot(gatewaySnapshotRequest("test")).actionGet(); - - logger.info("Closing the server"); - node.close(); - logger.info("Starting the server, should recover from the gateway (both index and translog)"); - node = buildNode().start(); - - logger.info("Running Cluster Health (wait for the shards to startup)"); - clusterHealth = node.client().admin().cluster().health(clusterHealthRequest().waitForYellowStatus().waitForActiveShards(1)).actionGet(); - logger.info("Done Cluster Health, status " + clusterHealth.status()); - assertThat(clusterHealth.timedOut(), equalTo(false)); - assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.YELLOW)); - - logger.info("Getting #1, should not exists"); - getResponse = node.client().get(getRequest("test").type("type1").id("1")).actionGet(); - assertThat(getResponse.exists(), equalTo(false)); - logger.info("Getting #2 (not from the translog, but from the index)"); - getResponse = node.client().get(getRequest("test").type("type1").id("2")).actionGet(); - assertThat(getResponse.sourceAsString(), equalTo(source("2", "test"))); - logger.info("Getting #3 (from the translog)"); - getResponse = node.client().get(getRequest("test").type("type1").id("3")).actionGet(); - assertThat(getResponse.sourceAsString(), equalTo(source("3", "test"))); - - logger.info("Flushing, so we have actual content in the index files (#3 should be in the index now as well)"); - node.client().admin().indices().flush(flushRequest("test")).actionGet(); - - logger.info("Gateway Snapshot"); - node.client().admin().indices().gatewaySnapshot(gatewaySnapshotRequest("test")).actionGet(); - logger.info("Gateway Snapshot (should be a no op)"); - node.client().admin().indices().gatewaySnapshot(gatewaySnapshotRequest("test")).actionGet(); - - logger.info("Closing the server"); - node.close(); - logger.info("Starting the server, should recover from the gateway (just from the index, nothing in the translog)"); - node = buildNode().start(); - - logger.info("Running Cluster Health (wait for the shards to startup)"); - clusterHealth = node.client().admin().cluster().health(clusterHealthRequest().waitForYellowStatus().waitForActiveShards(1)).actionGet(); - logger.info("Done Cluster Health, status " + clusterHealth.status()); - assertThat(clusterHealth.timedOut(), equalTo(false)); - assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.YELLOW)); - - logger.info("Getting #1, should not exists"); - getResponse = node.client().get(getRequest("test").type("type1").id("1")).actionGet(); - assertThat(getResponse.exists(), equalTo(false)); - logger.info("Getting #2 (not from the translog, but from the index)"); - getResponse = node.client().get(getRequest("test").type("type1").id("2")).actionGet(); - assertThat(getResponse.sourceAsString(), equalTo(source("2", "test"))); - logger.info("Getting #3 (not from the translog, but from the index)"); - getResponse = node.client().get(getRequest("test").type("type1").id("3")).actionGet(); - assertThat(getResponse.sourceAsString(), equalTo(source("3", "test"))); - - logger.info("Deleting the index"); - node.client().admin().indices().delete(deleteIndexRequest("test")).actionGet(); - } - - - private String mappingSource() { - return "{ type1 : { properties : { name : { type : \"string\" } } } }"; - } - - private String source(String id, String nameValue) { - return "{ type1 : { \"id\" : \"" + id + "\", \"name\" : \"" + nameValue + "\" } }"; - } -} diff --git a/plugins/lang/groovy/build.gradle b/plugins/lang/groovy/build.gradle deleted file mode 100644 index b1f9098dbe5..00000000000 --- a/plugins/lang/groovy/build.gradle +++ /dev/null @@ -1,134 +0,0 @@ -dependsOn(':elasticsearch') - -apply plugin: 'groovy' -apply plugin: 'maven' - -archivesBaseName = "elasticsearch-lang-groovy" - -explodedDistDir = new File(distsDir, 'exploded') - -configurations.compile.transitive = true -configurations.testCompile.transitive = true - -// no need to use the resource dir -sourceSets.main.resources.srcDirs 'src/main/groovy', 'src/main/java' -sourceSets.test.resources.srcDirs 'src/test/groovy', 'src/test/java' - -// add the source files to the dist jar -//jar { -// from sourceSets.main.allSource -//} - -configurations { - dists - distLib { - visible = false - transitive = false - } -} - -dependencies { - compile project(':elasticsearch') - - groovy group: 'org.codehaus.groovy', name: 'groovy-all', version: '1.8.2' - distLib('org.codehaus.groovy:groovy-all:1.8.2') { transitive = false } - testCompile('junit:junit:4.8.1') {transitive = false} -} - -task explodedDist(dependsOn: [jar], description: 'Builds the plugin zip file') << { - [explodedDistDir]*.mkdirs() - - copy { - from configurations.distLib - into explodedDistDir - } - - // remove elasticsearch files (compile above adds the elasticsearch one) - ant.delete { fileset(dir: explodedDistDir, includes: "elasticsearch-*.jar") } - - copy { - from libsDir - into explodedDistDir - } - - ant.delete { fileset(dir: explodedDistDir, includes: "elasticsearch-*-javadoc.jar") } - ant.delete { fileset(dir: explodedDistDir, includes: "elasticsearch-*-sources.jar") } -} - -task zip(type: Zip, dependsOn: ['explodedDist']) { - from(explodedDistDir) { - } -} - -task release(dependsOn: [zip]) << { - ant.delete(dir: explodedDistDir) - copy { - from distsDir - into(new File(rootProject.distsDir, "plugins")) - } -} - -configurations { - deployerJars -} - -dependencies { - deployerJars "org.apache.maven.wagon:wagon-http:1.0-beta-2" -} - -task sourcesJar(type: Jar, dependsOn: classes) { - classifier = 'sources' - from sourceSets.main.allSource -} - -task javadocJar(type: Jar, dependsOn: javadoc) { - classifier = 'javadoc' - from javadoc.destinationDir -} - -jar { -// from sourceSets.main.allJava - manifest { - attributes("Implementation-Title": "ElasticSearch", "Implementation-Version": rootProject.version, "Implementation-Date": buildTimeStr) - } -} - - -artifacts { - archives sourcesJar - archives javadocJar -} - -uploadArchives { - repositories.mavenDeployer { - configuration = configurations.deployerJars - repository(url: rootProject.mavenRepoUrl) { - authentication(userName: rootProject.mavenRepoUser, password: rootProject.mavenRepoPass) - } - snapshotRepository(url: rootProject.mavenSnapshotRepoUrl) { - authentication(userName: rootProject.mavenRepoUser, password: rootProject.mavenRepoPass) - } - - pom.project { - inceptionYear '2009' - name 'elasticsearch-plugins-lang-groovy' - description 'Groovy Plugin for ElasticSearch' - licenses { - license { - name 'The Apache Software License, Version 2.0' - url 'http://www.apache.org/licenses/LICENSE-2.0.txt' - distribution 'repo' - } - } - scm { - connection 'git://github.com/elasticsearch/elasticsearch.git' - developerConnection 'git@github.com:elasticsearch/elasticsearch.git' - url 'http://github.com/elasticsearch/elasticsearch' - } - } - - pom.whenConfigured {pom -> - pom.dependencies = pom.dependencies.findAll {dep -> dep.scope != 'test' } // removes the test scoped ones - } - } -} \ No newline at end of file diff --git a/plugins/lang/groovy/src/main/groovy/org/elasticsearch/groovy/client/GAdminClient.groovy b/plugins/lang/groovy/src/main/groovy/org/elasticsearch/groovy/client/GAdminClient.groovy deleted file mode 100644 index 22f5bd964b1..00000000000 --- a/plugins/lang/groovy/src/main/groovy/org/elasticsearch/groovy/client/GAdminClient.groovy +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.groovy.client - -/** - * @author kimchy (shay.banon) - */ -class GAdminClient { - - private final GClient gClient - - final GIndicesAdminClient indices - - final GClusterAdminClient cluster - - GAdminClient(gClient) { - this.gClient = gClient - - this.indices = new GIndicesAdminClient(gClient) - this.cluster = new GClusterAdminClient(gClient) - } -} diff --git a/plugins/lang/groovy/src/main/groovy/org/elasticsearch/groovy/client/GClient.groovy b/plugins/lang/groovy/src/main/groovy/org/elasticsearch/groovy/client/GClient.groovy deleted file mode 100644 index 3c908b2056c..00000000000 --- a/plugins/lang/groovy/src/main/groovy/org/elasticsearch/groovy/client/GClient.groovy +++ /dev/null @@ -1,357 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.groovy.client - -import org.elasticsearch.action.ActionListener -import org.elasticsearch.action.ListenableActionFuture -import org.elasticsearch.action.count.CountRequest -import org.elasticsearch.action.count.CountResponse -import org.elasticsearch.action.delete.DeleteRequest -import org.elasticsearch.action.delete.DeleteResponse -import org.elasticsearch.action.deletebyquery.DeleteByQueryRequest -import org.elasticsearch.action.deletebyquery.DeleteByQueryResponse -import org.elasticsearch.action.get.GetRequest -import org.elasticsearch.action.get.GetResponse -import org.elasticsearch.action.index.IndexRequest -import org.elasticsearch.action.index.IndexResponse -import org.elasticsearch.action.mlt.MoreLikeThisRequest -import org.elasticsearch.action.percolate.PercolateRequest -import org.elasticsearch.action.percolate.PercolateResponse -import org.elasticsearch.action.search.SearchRequest -import org.elasticsearch.action.search.SearchResponse -import org.elasticsearch.client.Client -import org.elasticsearch.client.action.count.CountRequestBuilder -import org.elasticsearch.client.action.delete.DeleteRequestBuilder -import org.elasticsearch.client.action.deletebyquery.DeleteByQueryRequestBuilder -import org.elasticsearch.client.action.get.GetRequestBuilder -import org.elasticsearch.client.action.index.IndexRequestBuilder -import org.elasticsearch.client.action.percolate.PercolateRequestBuilder -import org.elasticsearch.client.action.search.SearchRequestBuilder -import org.elasticsearch.client.action.support.BaseRequestBuilder -import org.elasticsearch.client.internal.InternalClient -import org.elasticsearch.common.xcontent.XContentType -import org.elasticsearch.groovy.client.action.GActionFuture -import org.elasticsearch.groovy.common.xcontent.GXContentBuilder - -/** - * @author kimchy (shay.banon) - */ -class GClient { - - static { - BaseRequestBuilder.metaClass.gexecute = { - ListenableActionFuture future = delegate.execute() - return new GActionFuture(future) - } - - IndexRequest.metaClass.setSource = {Closure c -> - delegate.source(new GXContentBuilder().buildAsBytes(c, indexContentType)) - } - IndexRequest.metaClass.source = {Closure c -> - delegate.source(new GXContentBuilder().buildAsBytes(c, indexContentType)) - } - IndexRequestBuilder.metaClass.setSource = {Closure c -> - delegate.setSource(new GXContentBuilder().buildAsBytes(c, indexContentType)) - } - IndexRequestBuilder.metaClass.source = {Closure c -> - delegate.setSource(new GXContentBuilder().buildAsBytes(c, indexContentType)) - } - - DeleteByQueryRequest.metaClass.setQuery = {Closure c -> - delegate.query(new GXContentBuilder().buildAsBytes(c, contentType)) - } - DeleteByQueryRequest.metaClass.query = {Closure c -> - delegate.query(new GXContentBuilder().buildAsBytes(c, contentType)) - } - DeleteByQueryRequestBuilder.metaClass.setQuery = {Closure c -> - delegate.setQuery(new GXContentBuilder().buildAsBytes(c, contentType)) - } - DeleteByQueryRequestBuilder.metaClass.query = {Closure c -> - delegate.setQuery(new GXContentBuilder().buildAsBytes(c, contentType)) - } - - CountRequest.metaClass.setQuery = {Closure c -> - delegate.query(new GXContentBuilder().buildAsBytes(c, contentType)) - } - CountRequest.metaClass.query = {Closure c -> - delegate.query(new GXContentBuilder().buildAsBytes(c, contentType)) - } - CountRequestBuilder.metaClass.setQuery = {Closure c -> - delegate.setQuery(new GXContentBuilder().buildAsBytes(c, contentType)) - } - CountRequestBuilder.metaClass.query = {Closure c -> - delegate.setQuery(new GXContentBuilder().buildAsBytes(c, contentType)) - } - - SearchRequest.metaClass.setSource = {Closure c -> - delegate.source(new GXContentBuilder().buildAsBytes(c, contentType)) - } - SearchRequest.metaClass.source = {Closure c -> - delegate.source(new GXContentBuilder().buildAsBytes(c, contentType)) - } - SearchRequest.metaClass.setExtraSource = {Closure c -> - delegate.extraSource(new GXContentBuilder().buildAsBytes(c, contentType)) - } - SearchRequest.metaClass.extraSource = {Closure c -> - delegate.extraSource(new GXContentBuilder().buildAsBytes(c, contentType)) - } - SearchRequestBuilder.metaClass.setSource = {Closure c -> - delegate.setSource(new GXContentBuilder().buildAsBytes(c, contentType)) - } - SearchRequestBuilder.metaClass.source = {Closure c -> - delegate.setSource(new GXContentBuilder().buildAsBytes(c, contentType)) - } - SearchRequestBuilder.metaClass.setExtraSource = {Closure c -> - delegate.setExtraSource(new GXContentBuilder().buildAsBytes(c, contentType)) - } - SearchRequestBuilder.metaClass.extraSource = {Closure c -> - delegate.setExtraSource(new GXContentBuilder().buildAsBytes(c, contentType)) - } - SearchRequestBuilder.metaClass.setQuery = {Closure c -> - delegate.setQuery(new GXContentBuilder().buildAsBytes(c, contentType)) - } - SearchRequestBuilder.metaClass.query = {Closure c -> - delegate.setQuery(new GXContentBuilder().buildAsBytes(c, contentType)) - } - SearchRequestBuilder.metaClass.setFilter = {Closure c -> - delegate.setFilter(new GXContentBuilder().buildAsBytes(c, contentType)) - } - SearchRequestBuilder.metaClass.filter = {Closure c -> - delegate.setFilter(new GXContentBuilder().buildAsBytes(c, contentType)) - } - SearchRequestBuilder.metaClass.setFacets = {Closure c -> - delegate.setFilter(new GXContentBuilder().buildAsBytes(c, contentType)) - } - SearchRequestBuilder.metaClass.facets = {Closure c -> - delegate.setFilter(new GXContentBuilder().buildAsBytes(c, contentType)) - } - - MoreLikeThisRequest.metaClass.setSearchSource = {Closure c -> - delegate.searchSource(new GXContentBuilder().buildAsBytes(c, contentType)) - } - MoreLikeThisRequest.metaClass.searchSource = {Closure c -> - delegate.searchSource(new GXContentBuilder().buildAsBytes(c, contentType)) - } - - PercolateRequest.metaClass.setSource = {Closure c -> - delegate.source(new GXContentBuilder().buildAsBytes(c, indexContentType)) - } - PercolateRequest.metaClass.source = {Closure c -> - delegate.source(new GXContentBuilder().buildAsBytes(c, indexContentType)) - } - PercolateRequestBuilder.metaClass.setSource = {Closure c -> - delegate.setSource(new GXContentBuilder().buildAsBytes(c, indexContentType)) - } - PercolateRequestBuilder.metaClass.source = {Closure c -> - delegate.setSource(new GXContentBuilder().buildAsBytes(c, indexContentType)) - } - } - - public static XContentType contentType = XContentType.SMILE - - public static XContentType indexContentType = XContentType.JSON - - final Client client - - int resolveStrategy = Closure.DELEGATE_FIRST - - private final InternalClient internalClient - - final GAdminClient admin - - GClient(client) { - this.client = client - this.internalClient = client - - this.admin = new GAdminClient(this) - } - - IndexRequestBuilder prepareIndex(String index, String type) { - return client.prepareIndex(index, type) - } - - IndexRequestBuilder prepareIndex(String index, String type, String id) { - return client.prepareIndex(index, type, id) - } - - GActionFuture index(Closure c) { - IndexRequest request = new IndexRequest() - c.setDelegate request - c.resolveStrategy = resolveStrategy - c.call() - index(request) - } - - GActionFuture index(IndexRequest request) { - GActionFuture future = new GActionFuture(internalClient.threadPool(), request) - client.index(request, future) - return future - } - - void index(IndexRequest request, ActionListener listener) { - client.index(request, listener) - } - - GetRequestBuilder prepareGet(String index, String type, String id) { - return client.prepareGet(index, type, id) - } - - GActionFuture get(Closure c) { - GetRequest request = new GetRequest() - c.setDelegate request - c.resolveStrategy = resolveStrategy - c.call() - get(request) - } - - GActionFuture get(GetRequest request) { - GActionFuture future = new GActionFuture(internalClient.threadPool(), request) - client.get(request, future) - return future - } - - void get(GetRequest request, ActionListener listener) { - client.get(request, listener) - } - - DeleteRequestBuilder prepareDelete(String index, String type, String id) { - return client.prepareDelete(index, type, id) - } - - GActionFuture delete(Closure c) { - DeleteRequest request = new DeleteRequest() - c.resolveStrategy = resolveStrategy - c.setDelegate request - c.call() - delete(request) - } - - GActionFuture delete(DeleteRequest request) { - GActionFuture future = new GActionFuture(internalClient.threadPool(), request) - client.delete(request, future) - return future - } - - void delete(DeleteRequest request, ActionListener listener) { - client.delete(request, listener) - } - - DeleteByQueryRequestBuilder prepareDeleteByQuery(String... indices) { - return client.prepareDeleteByQuery(indices) - } - - GActionFuture deleteByQuery(Closure c) { - DeleteByQueryRequest request = new DeleteByQueryRequest() - c.resolveStrategy = resolveStrategy - c.setDelegate request - c.call() - deleteByQuery(request) - } - - GActionFuture deleteByQuery(DeleteByQueryRequest request) { - GActionFuture future = new GActionFuture(internalClient.threadPool(), request) - client.deleteByQuery(request, future) - return future - } - - void deleteByQuery(DeleteByQueryRequest request, ActionListener listener) { - client.deleteByQuery(request, listener) - } - - CountRequestBuilder prepareCount(String... indices) { - return client.prepareCount(indices) - } - - GActionFuture count(Closure c) { - CountRequest request = new CountRequest() - c.resolveStrategy = resolveStrategy - c.setDelegate request - c.call() - count(request) - } - - GActionFuture count(CountRequest request) { - GActionFuture future = new GActionFuture(internalClient.threadPool(), request) - client.count(request, future) - return future - } - - void count(CountRequest request, ActionListener listener) { - client.count(request, listener) - } - - SearchRequestBuilder prepareSearch(String... indices) { - return client.prepareSearch(indices) - } - - GActionFuture search(Closure c) { - SearchRequest request = new SearchRequest() - c.resolveStrategy = resolveStrategy - c.setDelegate request - c.call() - search(request) - } - - GActionFuture search(SearchRequest request) { - GActionFuture future = new GActionFuture(internalClient.threadPool(), request) - client.search(request, future) - return future - } - - void search(SearchRequest request, ActionListener listener) { - client.search(request, listener) - } - - PercolateRequestBuilder preparePercolate(String index, String type) { - return client.preparePercolate(index, type); - } - - GActionFuture percolate(Closure c) { - PercolateRequest request = new PercolateRequest(); - c.resolveStrategy = resolveStrategy - c.setDelegate request - c.call() - percolate(request) - } - - GActionFuture percolate(PercolateRequest request) { - GActionFuture future = new GActionFuture(internalClient.threadPool(), request) - client.percolate(request, future) - return future - } - - GActionFuture moreLikeThis(Closure c) { - MoreLikeThisRequest request = new MoreLikeThisRequest() - c.resolveStrategy = resolveStrategy - c.setDelegate request - c.call() - moreLikeThis(request) - } - - GActionFuture moreLikeThis(MoreLikeThisRequest request) { - GActionFuture future = new GActionFuture(internalClient.threadPool(), request) - client.moreLikeThis(request, future) - return future - } - - void moreLikeThis(MoreLikeThisRequest request, ActionListener listener) { - client.moreLikeThis(request, listener) - } -} diff --git a/plugins/lang/groovy/src/main/groovy/org/elasticsearch/groovy/client/GClusterAdminClient.groovy b/plugins/lang/groovy/src/main/groovy/org/elasticsearch/groovy/client/GClusterAdminClient.groovy deleted file mode 100644 index c8a7134df1f..00000000000 --- a/plugins/lang/groovy/src/main/groovy/org/elasticsearch/groovy/client/GClusterAdminClient.groovy +++ /dev/null @@ -1,205 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.groovy.client - -import org.elasticsearch.action.ActionListener -import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest -import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse -import org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest -import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse -import org.elasticsearch.action.admin.cluster.node.restart.NodesRestartRequest -import org.elasticsearch.action.admin.cluster.node.restart.NodesRestartResponse -import org.elasticsearch.action.admin.cluster.node.shutdown.NodesShutdownRequest -import org.elasticsearch.action.admin.cluster.node.shutdown.NodesShutdownResponse -import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest -import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse -import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest -import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse -import org.elasticsearch.client.ClusterAdminClient -import org.elasticsearch.client.action.admin.cluster.health.ClusterHealthRequestBuilder -import org.elasticsearch.client.action.admin.cluster.node.info.NodesInfoRequestBuilder -import org.elasticsearch.client.action.admin.cluster.node.restart.NodesRestartRequestBuilder -import org.elasticsearch.client.action.admin.cluster.node.shutdown.NodesShutdownRequestBuilder -import org.elasticsearch.client.action.admin.cluster.node.stats.NodesStatsRequestBuilder -import org.elasticsearch.client.action.admin.cluster.state.ClusterStateRequestBuilder -import org.elasticsearch.client.internal.InternalClient -import org.elasticsearch.groovy.client.action.GActionFuture - -/** - * @author kimchy (shay.banon) - */ -class GClusterAdminClient { - - private final GClient gClient - - private final InternalClient internalClient - - final ClusterAdminClient clusterAdminClient - - def GClusterAdminClient(gClient) { - this.gClient = gClient - this.internalClient = gClient.client - this.clusterAdminClient = internalClient.admin().cluster() - } - - // HEALTH - - ClusterHealthRequestBuilder prepareHealth(String... indices) { - clusterAdminClient.prepareHealth(indices) - } - - GActionFuture health(Closure c) { - ClusterHealthRequest request = new ClusterHealthRequest() - c.setDelegate request - c.resolveStrategy = gClient.resolveStrategy - c.call() - health(request) - } - - GActionFuture health(ClusterHealthRequest request) { - GActionFuture future = new GActionFuture(internalClient.threadPool(), request) - clusterAdminClient.health(request, future) - return future - } - - void status(ClusterHealthRequest request, ActionListener listener) { - clusterAdminClient.health(request, listener) - } - - // STATE - - ClusterStateRequestBuilder prepareState() { - clusterAdminClient.prepareState() - } - - GActionFuture state(Closure c) { - ClusterStateRequest request = new ClusterStateRequest() - c.setDelegate request - c.resolveStrategy = gClient.resolveStrategy - c.call() - state(request) - } - - GActionFuture state(ClusterStateRequest request) { - GActionFuture future = new GActionFuture(internalClient.threadPool(), request) - clusterAdminClient.state(request, future) - return future - } - - void state(ClusterStateRequest request, ActionListener listener) { - clusterAdminClient.state(request, listener) - } - - // NODES INFO - - NodesInfoRequestBuilder prepareNodesInfo(String... nodesIds) { - clusterAdminClient.prepareNodesInfo(nodesIds) - } - - GActionFuture nodesInfo(Closure c) { - NodesInfoRequest request = new NodesInfoRequest() - c.setDelegate request - c.resolveStrategy = gClient.resolveStrategy - c.call() - nodesInfo(request) - } - - GActionFuture nodesInfo(NodesInfoRequest request) { - GActionFuture future = new GActionFuture(internalClient.threadPool(), request) - clusterAdminClient.nodesInfo(request, future) - return future - } - - void nodesInfo(NodesInfoRequest request, ActionListener listener) { - clusterAdminClient.nodesInfo(request, listener) - } - - // NODES STATS - - NodesStatsRequestBuilder prepareNodesStats(String... nodesIds) { - clusterAdminClient.prepareNodesStats(nodesIds) - } - - GActionFuture nodesStats(Closure c) { - NodesStatsRequest request = new NodesStatsRequest() - c.setDelegate request - c.resolveStrategy = gClient.resolveStrategy - c.call() - nodesStats(request) - } - - GActionFuture nodesStats(NodesStatsRequest request) { - GActionFuture future = new GActionFuture(internalClient.threadPool(), request) - clusterAdminClient.nodesStats(request, future) - return future - } - - void nodesStats(NodesStatsRequest request, ActionListener listener) { - clusterAdminClient.nodesStats(request, listener) - } - - // NODES SHUTDOWN - - NodesShutdownRequestBuilder prepareNodesShutdown(String... nodesIds) { - clusterAdminClient.prepareNodesShutdown(nodesIds) - } - - GActionFuture nodesShutdown(Closure c) { - NodesShutdownRequest request = new NodesShutdownRequest() - c.setDelegate request - c.resolveStrategy = gClient.resolveStrategy - c.call() - nodesShutdown(request) - } - - GActionFuture nodesShutdown(NodesShutdownRequest request) { - GActionFuture future = new GActionFuture(internalClient.threadPool(), request) - clusterAdminClient.nodesShutdown(request, future) - return future - } - - void nodesShutdown(NodesShutdownRequest request, ActionListener listener) { - clusterAdminClient.nodesShutdown(request, listener) - } - - // NODES RESTART - - NodesRestartRequestBuilder prepareNodesRestart(String... nodesIds) { - clusterAdminClient.prepareNodesRestart(nodesIds) - } - - GActionFuture nodesRestart(Closure c) { - NodesRestartRequest request = new NodesRestartRequest() - c.setDelegate request - c.resolveStrategy = gClient.resolveStrategy - c.call() - nodesRestart(request) - } - - GActionFuture nodesRestart(NodesRestartRequest request) { - GActionFuture future = new GActionFuture(internalClient.threadPool(), request) - clusterAdminClient.nodesRestart(request, future) - return future - } - - void nodesRestart(NodesRestartRequest request, ActionListener listener) { - clusterAdminClient.nodesRestart(request, listener) - } -} diff --git a/plugins/lang/groovy/src/main/groovy/org/elasticsearch/groovy/client/GIndicesAdminClient.groovy b/plugins/lang/groovy/src/main/groovy/org/elasticsearch/groovy/client/GIndicesAdminClient.groovy deleted file mode 100644 index fefa340afd7..00000000000 --- a/plugins/lang/groovy/src/main/groovy/org/elasticsearch/groovy/client/GIndicesAdminClient.groovy +++ /dev/null @@ -1,483 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.groovy.client - -import org.elasticsearch.action.ActionListener -import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest -import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse -import org.elasticsearch.action.admin.indices.analyze.AnalyzeRequest -import org.elasticsearch.action.admin.indices.analyze.AnalyzeResponse -import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest -import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheResponse -import org.elasticsearch.action.admin.indices.create.CreateIndexRequest -import org.elasticsearch.action.admin.indices.create.CreateIndexResponse -import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest -import org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse -import org.elasticsearch.action.admin.indices.flush.FlushRequest -import org.elasticsearch.action.admin.indices.flush.FlushResponse -import org.elasticsearch.action.admin.indices.gateway.snapshot.GatewaySnapshotRequest -import org.elasticsearch.action.admin.indices.gateway.snapshot.GatewaySnapshotResponse -import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest -import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse -import org.elasticsearch.action.admin.indices.optimize.OptimizeRequest -import org.elasticsearch.action.admin.indices.optimize.OptimizeResponse -import org.elasticsearch.action.admin.indices.refresh.RefreshRequest -import org.elasticsearch.action.admin.indices.refresh.RefreshResponse -import org.elasticsearch.action.admin.indices.settings.UpdateSettingsRequest -import org.elasticsearch.action.admin.indices.settings.UpdateSettingsResponse -import org.elasticsearch.action.admin.indices.stats.IndicesStats -import org.elasticsearch.action.admin.indices.stats.IndicesStatsRequest -import org.elasticsearch.action.admin.indices.status.IndicesStatusRequest -import org.elasticsearch.action.admin.indices.status.IndicesStatusResponse -import org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest -import org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateResponse -import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest -import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateResponse -import org.elasticsearch.client.IndicesAdminClient -import org.elasticsearch.client.action.admin.indices.alias.IndicesAliasesRequestBuilder -import org.elasticsearch.client.action.admin.indices.analyze.AnalyzeRequestBuilder -import org.elasticsearch.client.action.admin.indices.cache.clear.ClearIndicesCacheRequestBuilder -import org.elasticsearch.client.action.admin.indices.create.CreateIndexRequestBuilder -import org.elasticsearch.client.action.admin.indices.delete.DeleteIndexRequestBuilder -import org.elasticsearch.client.action.admin.indices.flush.FlushRequestBuilder -import org.elasticsearch.client.action.admin.indices.gateway.snapshot.GatewaySnapshotRequestBuilder -import org.elasticsearch.client.action.admin.indices.mapping.put.PutMappingRequestBuilder -import org.elasticsearch.client.action.admin.indices.optimize.OptimizeRequestBuilder -import org.elasticsearch.client.action.admin.indices.refresh.RefreshRequestBuilder -import org.elasticsearch.client.action.admin.indices.settings.UpdateSettingsRequestBuilder -import org.elasticsearch.client.action.admin.indices.stats.IndicesStatsRequestBuilder -import org.elasticsearch.client.action.admin.indices.status.IndicesStatusRequestBuilder -import org.elasticsearch.client.action.admin.indices.template.delete.DeleteIndexTemplateRequestBuilder -import org.elasticsearch.client.action.admin.indices.template.put.PutIndexTemplateRequestBuilder -import org.elasticsearch.client.internal.InternalClient -import org.elasticsearch.groovy.client.action.GActionFuture -import org.elasticsearch.groovy.common.xcontent.GXContentBuilder - -/** - * @author kimchy (shay.banon) - */ -class GIndicesAdminClient { - - static { - CreateIndexRequest.metaClass.setSettings = {Closure c -> - delegate.settings(new GXContentBuilder().buildAsString(c)) - } - CreateIndexRequest.metaClass.settings = {Closure c -> - delegate.settings(new GXContentBuilder().buildAsString(c)) - } - CreateIndexRequest.metaClass.mapping = {String type, Closure c -> - delegate.mapping(type, new GXContentBuilder().buildAsString(c)) - } - CreateIndexRequest.metaClass.setMapping = {String type, Closure c -> - delegate.mapping(type, new GXContentBuilder().buildAsString(c)) - } - CreateIndexRequestBuilder.metaClass.setSettings = {Closure c -> - delegate.setSettings(new GXContentBuilder().buildAsString(c)) - } - CreateIndexRequestBuilder.metaClass.settings = {Closure c -> - delegate.setSettings(new GXContentBuilder().buildAsString(c)) - } - CreateIndexRequestBuilder.metaClass.addMapping = {String type, Closure c -> - delegate.addMapping(type, new GXContentBuilder().buildAsString(c)) - } - - PutMappingRequest.metaClass.setSource = {Closure c -> - delegate.source(new GXContentBuilder().buildAsString(c)) - } - PutMappingRequest.metaClass.source = {Closure c -> - delegate.source(new GXContentBuilder().buildAsString(c)) - } - PutMappingRequestBuilder.metaClass.setSource = {Closure c -> - delegate.setSource(new GXContentBuilder().buildAsString(c)) - } - PutMappingRequestBuilder.metaClass.source = {Closure c -> - delegate.setSource(new GXContentBuilder().buildAsString(c)) - } - - UpdateSettingsRequest.metaClass.setSettings = {Closure c -> - delegate.settings(new GXContentBuilder().buildAsString(c)) - } - UpdateSettingsRequest.metaClass.settings = {Closure c -> - delegate.settings(new GXContentBuilder().buildAsString(c)) - } - UpdateSettingsRequestBuilder.metaClass.setSettings = {Closure c -> - delegate.setSettings(new GXContentBuilder().buildAsString(c)) - } - UpdateSettingsRequestBuilder.metaClass.settings = {Closure c -> - delegate.setSettings(new GXContentBuilder().buildAsString(c)) - } - } - - private final GClient gClient - - private final InternalClient internalClient - - final IndicesAdminClient indicesAdminClient - - def GIndicesAdminClient(gClient) { - this.gClient = gClient - this.internalClient = gClient.client - this.indicesAdminClient = internalClient.admin().indices() - } - - // STATUS - - IndicesStatusRequestBuilder prepareStatus(String... indices) { - indicesAdminClient.prepareStatus(indices) - } - - GActionFuture status(Closure c) { - IndicesStatusRequest request = new IndicesStatusRequest() - c.setDelegate request - c.resolveStrategy = gClient.resolveStrategy - c.call() - status(request) - } - - GActionFuture status(IndicesStatusRequest request) { - GActionFuture future = new GActionFuture(internalClient.threadPool(), request) - indicesAdminClient.status(request, future) - return future - } - - void status(IndicesStatusRequest request, ActionListener listener) { - indicesAdminClient.status(request, listener) - } - - // STATS - - IndicesStatsRequestBuilder prepareStats(String... indices) { - indicesAdminClient.prepareStats(indices) - } - - GActionFuture stats(Closure c) { - IndicesStatsRequest request = new IndicesStatsRequest() - c.setDelegate request - c.resolveStrategy = gClient.resolveStrategy - c.call() - stats(request) - } - - GActionFuture stats(IndicesStatsRequest request) { - GActionFuture future = new GActionFuture(internalClient.threadPool(), request) - indicesAdminClient.stats(request, future) - return future - } - - void stats(IndicesStatsRequest request, ActionListener listener) { - indicesAdminClient.stats(request, listener) - } - - // CREATE - - CreateIndexRequestBuilder prepareCreate(String index) { - indicesAdminClient.prepareCreate(index) - } - - GActionFuture create(Closure c) { - CreateIndexRequest request = new CreateIndexRequest() - c.setDelegate request - c.resolveStrategy = gClient.resolveStrategy - c.call() - create(request) - } - - GActionFuture create(CreateIndexRequest request) { - GActionFuture future = new GActionFuture(internalClient.threadPool(), request) - indicesAdminClient.create(request, future) - return future - } - - void create(CreateIndexRequest request, ActionListener listener) { - indicesAdminClient.create(request, listener) - } - - // DELETE - - DeleteIndexRequestBuilder prepareDelete(String index) { - indicesAdminClient.prepareDelete(index) - } - - GActionFuture delete(Closure c) { - DeleteIndexRequest request = new DeleteIndexRequest() - c.setDelegate request - c.resolveStrategy = gClient.resolveStrategy - c.call() - delete(request) - } - - GActionFuture delete(DeleteIndexRequest request) { - GActionFuture future = new GActionFuture(internalClient.threadPool(), request) - indicesAdminClient.delete(request, future) - return future - } - - void delete(DeleteIndexRequest request, ActionListener listener) { - indicesAdminClient.delete(request, listener) - } - - // REFRESH - - RefreshRequestBuilder prepareRefresh(String... indices) { - indicesAdminClient.prepareRefresh(indices) - } - - GActionFuture refresh(Closure c) { - RefreshRequest request = new RefreshRequest() - c.setDelegate request - c.resolveStrategy = gClient.resolveStrategy - c.call() - refresh(request) - } - - GActionFuture refresh(RefreshRequest request) { - GActionFuture future = new GActionFuture(internalClient.threadPool(), request) - indicesAdminClient.refresh(request, future) - return future - } - - void refresh(RefreshRequest request, ActionListener listener) { - indicesAdminClient.refresh(request, listener) - } - - // FLUSH - - FlushRequestBuilder prepareFlush(String... indices) { - indicesAdminClient.prepareFlush(indices) - } - - GActionFuture flush(Closure c) { - FlushRequest request = new FlushRequest() - c.setDelegate request - c.resolveStrategy = gClient.resolveStrategy - c.call() - flush(request) - } - - GActionFuture flush(FlushRequest request) { - GActionFuture future = new GActionFuture(internalClient.threadPool(), request) - indicesAdminClient.flush(request, future) - return future - } - - void flush(FlushRequest request, ActionListener listener) { - indicesAdminClient.flush(request, listener) - } - - // OPTIMIZE - - OptimizeRequestBuilder prepareOptimize(String... indices) { - indicesAdminClient.prepareOptimize(indices) - } - - GActionFuture optimize(Closure c) { - OptimizeRequest request = new OptimizeRequest() - c.setDelegate request - c.resolveStrategy = gClient.resolveStrategy - c.call() - optimize(request) - } - - GActionFuture optimize(OptimizeRequest request) { - GActionFuture future = new GActionFuture(internalClient.threadPool(), request) - indicesAdminClient.optimize(request, future) - return future - } - - void optimize(OptimizeRequest request, ActionListener listener) { - indicesAdminClient.optimize(request, listener) - } - - // PUT MAPPING - - PutMappingRequestBuilder preparePutMapping(String... indices) { - indicesAdminClient.preparePutMapping(indices) - } - - GActionFuture putMapping(Closure c) { - PutMappingRequest request = new PutMappingRequest() - c.setDelegate request - c.resolveStrategy = gClient.resolveStrategy - c.call() - putMapping(request) - } - - GActionFuture putMapping(PutMappingRequest request) { - GActionFuture future = new GActionFuture(internalClient.threadPool(), request) - indicesAdminClient.putMapping(request, future) - return future - } - - void putMapping(PutMappingRequest request, ActionListener listener) { - indicesAdminClient.putMapping(request, listener) - } - - // GATEWAY SNAPSHOT - - GatewaySnapshotRequestBuilder prepareGatewaySnapshot(String... indices) { - indicesAdminClient.prepareGatewaySnapshot(indices) - } - - GActionFuture gatewaySnapshot(Closure c) { - GatewaySnapshotRequest request = new GatewaySnapshotRequest() - c.setDelegate request - c.resolveStrategy = gClient.resolveStrategy - c.call() - gatewaySnapshot(request) - } - - GActionFuture gatewaySnapshot(GatewaySnapshotRequest request) { - GActionFuture future = new GActionFuture(internalClient.threadPool(), request) - indicesAdminClient.gatewaySnapshot(request, future) - return future - } - - void gatewaySnapshot(GatewaySnapshotRequest request, ActionListener listener) { - indicesAdminClient.gatewaySnapshot(request, listener) - } - - // Aliases - - IndicesAliasesRequestBuilder prepareAliases() { - indicesAdminClient.prepareAliases() - } - - GActionFuture aliases(Closure c) { - IndicesAliasesRequest request = new IndicesAliasesRequest() - c.setDelegate request - c.resolveStrategy = gClient.resolveStrategy - c.call() - aliases(request) - } - - GActionFuture aliases(IndicesAliasesRequest request) { - GActionFuture future = new GActionFuture(internalClient.threadPool(), request) - indicesAdminClient.aliases(request, future) - return future - } - - void aliases(IndicesAliasesRequest request, ActionListener listener) { - indicesAdminClient.aliases(request, listener) - } - - void aliases(ClearIndicesCacheRequest request, ActionListener listener) { - indicesAdminClient.clearCache(request, listener) - } - - // CLEAR CACHE - - ClearIndicesCacheRequestBuilder prepareClearCache(String... indices) { - indicesAdminClient.prepareClearCache(indices) - } - - GActionFuture clearCache(Closure c) { - ClearIndicesCacheRequest request = new ClearIndicesCacheRequest() - c.setDelegate request - c.resolveStrategy = gClient.resolveStrategy - c.call() - clearCache(request) - } - - GActionFuture clearCache(ClearIndicesCacheRequest request) { - GActionFuture future = new GActionFuture(internalClient.threadPool(), request) - indicesAdminClient.clearCache(request, future) - return future - } - - // UPDATE SETTINGS - - UpdateSettingsRequestBuilder prepareUpdateSettings(String... indices) { - indicesAdminClient.prepareUpdateSettings(indices) - } - - GActionFuture updateSettings(Closure c) { - UpdateSettingsRequest request = new UpdateSettingsRequest() - c.setDelegate request - c.resolveStrategy = gClient.resolveStrategy - c.call() - updateSettings(request) - } - - GActionFuture updateSettings(UpdateSettingsRequest request) { - GActionFuture future = new GActionFuture(internalClient.threadPool(), request) - indicesAdminClient.updateSettings(request, future) - return future - } - - // ANALYZE - - AnalyzeRequestBuilder prepareAnalyze(String index, String text) { - indicesAdminClient.prepareAnalyze(index, text) - } - - GActionFuture analyze(Closure c) { - AnalyzeRequest request = new AnalyzeRequest() - c.setDelegate request - c.resolveStrategy = gClient.resolveStrategy - c.call() - analyze(request) - } - - GActionFuture analyze(AnalyzeRequest request) { - GActionFuture future = new GActionFuture(internalClient.threadPool(), request) - indicesAdminClient.analyze(request, future) - return future - } - - // PUT INDEX TEMPLATE - - PutIndexTemplateRequestBuilder preparePutTemplate(String name) { - indicesAdminClient.preparePutTemplate(name) - } - - GActionFuture putTemplate(Closure c) { - PutIndexTemplateRequest request = new PutIndexTemplateRequest() - c.setDelegate request - c.resolveStrategy = gClient.resolveStrategy - c.call() - putTemplate(request) - } - - GActionFuture putTemplate(PutIndexTemplateRequest request) { - GActionFuture future = new GActionFuture(internalClient.threadPool(), request) - indicesAdminClient.putTemplate(request, future) - return future - } - - // DELETE INDEX TEMPLATE - - DeleteIndexTemplateRequestBuilder prepareDeleteTemplate(String name) { - indicesAdminClient.prepareDeleteTemplate(name) - } - - GActionFuture deleteTemplate(Closure c) { - DeleteIndexTemplateRequest request = new DeleteIndexTemplateRequest() - c.setDelegate request - c.resolveStrategy = gClient.resolveStrategy - c.call() - deleteTemplate(request) - } - - GActionFuture deleteTemplate(DeleteIndexTemplateRequest request) { - GActionFuture future = new GActionFuture(internalClient.threadPool(), request) - indicesAdminClient.deleteTemplate(request, future) - return future - } -} diff --git a/plugins/lang/groovy/src/main/groovy/org/elasticsearch/groovy/client/action/GActionFuture.java b/plugins/lang/groovy/src/main/groovy/org/elasticsearch/groovy/client/action/GActionFuture.java deleted file mode 100644 index a03df5c6e45..00000000000 --- a/plugins/lang/groovy/src/main/groovy/org/elasticsearch/groovy/client/action/GActionFuture.java +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.groovy.client.action; - -import groovy.lang.Closure; -import org.elasticsearch.ElasticSearchException; -import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.ActionRequest; -import org.elasticsearch.action.ListenableActionFuture; -import org.elasticsearch.action.support.PlainListenableActionFuture; -import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.threadpool.ThreadPool; - -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; - -/** - * @author kimchy (shay.banon) - */ -public class GActionFuture implements ListenableActionFuture, ActionListener { - - private final PlainListenableActionFuture future; - - public GActionFuture(ListenableActionFuture future) { - this.future = (PlainListenableActionFuture) future; - } - - public GActionFuture(ThreadPool threadPool, ActionRequest request) { - this.future = new PlainListenableActionFuture(request.listenerThreaded(), threadPool); - } - - public void setListener(final Closure listener) { - addListener(new ActionListener() { - @Override public void onResponse(T t) { - listener.call(this); - } - - @Override public void onFailure(Throwable e) { - listener.call(this); - } - }); - } - - public void setSuccess(final Closure success) { - addListener(new ActionListener() { - @Override public void onResponse(T t) { - success.call(t); - } - - @Override public void onFailure(Throwable e) { - // ignore - } - }); - } - - public void setFailure(final Closure failure) { - addListener(new ActionListener() { - @Override public void onResponse(T t) { - // nothing - } - - @Override public void onFailure(Throwable e) { - failure.call(e); - } - }); - } - - public T getResponse() { - return actionGet(); - } - - public T response(String timeout) throws ElasticSearchException { - return actionGet(timeout); - } - - public T response(long timeoutMillis) throws ElasticSearchException { - return actionGet(timeoutMillis); - } - - public T response(TimeValue timeout) throws ElasticSearchException { - return actionGet(timeout); - } - - public T response(long timeout, TimeUnit unit) throws ElasticSearchException { - return actionGet(timeout, unit); - } - - @Override public void onResponse(T t) { - future.onResponse(t); - } - - @Override public void onFailure(Throwable e) { - future.onFailure(e); - } - - // delegate methods - - public void addListener(ActionListener tActionListener) { - future.addListener(tActionListener); - } - - @Override public void addListener(Runnable listener) { - future.addListener(listener); - } - - @Override public T actionGet() throws ElasticSearchException { - return future.actionGet(); - } - - @Override public T actionGet(String timeout) throws ElasticSearchException { - return future.actionGet(timeout); - } - - @Override public T actionGet(long timeoutMillis) throws ElasticSearchException { - return future.actionGet(timeoutMillis); - } - - @Override public T actionGet(long timeout, TimeUnit unit) throws ElasticSearchException { - return future.actionGet(timeout, unit); - } - - @Override public T actionGet(TimeValue timeout) throws ElasticSearchException { - return future.actionGet(timeout); - } - - @Override public boolean cancel(boolean mayInterruptIfRunning) { - return future.cancel(mayInterruptIfRunning); - } - - @Override public boolean isCancelled() { - return future.isCancelled(); - } - - @Override public boolean isDone() { - return future.isDone(); - } - - @Override public T get() throws InterruptedException, ExecutionException { - return future.get(); - } - - @Override public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { - return future.get(timeout, unit); - } - - @Override public Throwable getRootFailure() { - return future.getRootFailure(); - } -} diff --git a/plugins/lang/groovy/src/main/groovy/org/elasticsearch/groovy/common/xcontent/GXContentBuilder.groovy b/plugins/lang/groovy/src/main/groovy/org/elasticsearch/groovy/common/xcontent/GXContentBuilder.groovy deleted file mode 100644 index 71aa29ed4c4..00000000000 --- a/plugins/lang/groovy/src/main/groovy/org/elasticsearch/groovy/common/xcontent/GXContentBuilder.groovy +++ /dev/null @@ -1,189 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.groovy.common.xcontent - -import org.elasticsearch.common.xcontent.XContentBuilder -import org.elasticsearch.common.xcontent.XContentFactory -import org.elasticsearch.common.xcontent.XContentType - -/** - * Used to build JSON data. - * - * @author Marc Palmer - * @author Graeme Rocher - * - * @since 1.2 - */ -class GXContentBuilder { - - static NODE_ELEMENT = 'element' - - static int rootResolveStrategy = Closure.OWNER_FIRST // the default in Closure - - def root - - def current - - def nestingStack = [] - - def build(Closure c) { - return buildRoot(c) - } - - String buildAsString(Closure c) { - XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON) - def json = build(c) - builder.map(json) - return builder.string() - } - - byte[] buildAsBytes(Closure c) { - return buildAsBytes(c, XContentType.JSON) - } - - byte[] buildAsBytes(Closure c, XContentType contentType) { - XContentBuilder builder = XContentFactory.contentBuilder(contentType) - def json = build(c) - builder.map(json) - return builder.copiedBytes() - } - - private buildRoot(Closure c) { - c.delegate = this - c.resolveStrategy = rootResolveStrategy - root = [:] - current = root - def returnValue = c.call() - if (!root) { - return returnValue - } - return root - } - - def invokeMethod(String methodName) { - current[methodName] = [] - } - - List array(Closure c) { - def prev = current - def list = [] - try { - current = list - c.call(list) - } - finally { - current = prev - } - return list - } - - def invokeMethod(String methodName, Object args) { - if (args.size()) { - if (args[0] instanceof Map) { - // switch root to an array if elements used at top level - if ((current == root) && (methodName == NODE_ELEMENT) && !(root instanceof List)) { - if (root.size()) { - throw new IllegalArgumentException('Cannot have array elements in root node if properties of root have already been set') - } else { - root = [] - current = root - } - } - def n = [:] - if (current instanceof List) { - current << n - } else { - current[methodName] = n - } - n.putAll(args[0]) - } else if (args[-1] instanceof Closure) { - final Object callable = args[-1] - handleClosureNode(methodName, callable) - } else if (args.size() == 1) { - if (methodName != NODE_ELEMENT) { - throw new IllegalArgumentException('Array elements must be defined with the "element" method call eg: element(value)') - } - // switch root to an array if elements used at top level - if (current == root) { - if (root.size() && methodName != NODE_ELEMENT) { - throw new IllegalArgumentException('Cannot have array elements in root node if properties of root have already been set') - } else if (!(root instanceof List)) { - root = [] - current = root - } - } - if (current instanceof List) { - current << args[0] - } else { - throw new IllegalArgumentException('Array elements can only be defined under "array" nodes') - } - } else { - throw new IllegalArgumentException("This builder does not support invocation of [$methodName] with arg list ${args.dump()}") - } - } else { - current[methodName] = [] - } - } - - private handleClosureNode(String methodName, callable) { - def n = [:] - nestingStack << current - - if (current instanceof List) { - current << n - } - else { - current[methodName] = n - } - current = n - callable.call() - current = nestingStack.pop() - } - - - void setProperty(String propName, Object value) { - if (value instanceof Closure) { - handleClosureNode(propName, value) - } - else if (value instanceof List) { - value = value.collect { - if (it instanceof Closure) { - def callable = it - final GXContentBuilder localBuilder = new GXContentBuilder() - callable.delegate = localBuilder - callable.resolveStrategy = Closure.DELEGATE_FIRST - final Map nestedObject = localBuilder.buildRoot(callable) - return nestedObject - } - else { - return it - } - } - current[propName] = value - } - else { - current[propName] = value - } - } - - def getProperty(String propName) { - current[propName] - } -} diff --git a/plugins/lang/groovy/src/main/groovy/org/elasticsearch/groovy/node/GNode.groovy b/plugins/lang/groovy/src/main/groovy/org/elasticsearch/groovy/node/GNode.groovy deleted file mode 100644 index fecefd95e8b..00000000000 --- a/plugins/lang/groovy/src/main/groovy/org/elasticsearch/groovy/node/GNode.groovy +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.groovy.node - -import org.elasticsearch.common.settings.Settings -import org.elasticsearch.groovy.client.GClient -import org.elasticsearch.node.Node - -/** - * @author kimchy (shay.banon) - */ -class GNode { - - final Node node - - final GClient client - - GNode(Node node) { - this.node = node - this.client = new GClient(node.client()) - } - - /** - * The settings that were used to create the node. - */ - Settings getSettings() { - node.settings() - } - - /** - * Start the node. If the node is already started, this method is no-op. - */ - GNode start() { - node.start() - this - } - - /** - * Stops the node. If the node is already started, this method is no-op. - */ - GNode stop() { - node.stop() - this - } - - /** - * Closes the node (and {@link #stop}s if it's running). - */ - GNode close() { - node.close() - this - } -} diff --git a/plugins/lang/groovy/src/main/groovy/org/elasticsearch/groovy/node/GNodeBuilder.groovy b/plugins/lang/groovy/src/main/groovy/org/elasticsearch/groovy/node/GNodeBuilder.groovy deleted file mode 100644 index 75ab3eb551f..00000000000 --- a/plugins/lang/groovy/src/main/groovy/org/elasticsearch/groovy/node/GNodeBuilder.groovy +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.groovy.node - -import org.elasticsearch.common.settings.ImmutableSettings -import org.elasticsearch.common.settings.Settings -import org.elasticsearch.common.settings.loader.JsonSettingsLoader -import org.elasticsearch.groovy.common.xcontent.GXContentBuilder -import org.elasticsearch.node.Node -import org.elasticsearch.node.internal.InternalNode - -/** - * The node builder allow to build a {@link GNode} instance. - * - * @author kimchy (shay.banon) - */ -class GNodeBuilder { - - private final ImmutableSettings.Builder settingsBuilder = ImmutableSettings.settingsBuilder() - - private boolean loadConfigSettings = true - - static GNodeBuilder nodeBuilder() { - new GNodeBuilder() - } - - ImmutableSettings.Builder getSettings() { - settingsBuilder - } - - ImmutableSettings.Builder settings(Settings.Builder settings) { - settingsBuilder.put(settings.build()) - } - - ImmutableSettings.Builder settings(Settings settings) { - settingsBuilder.put(settings) - } - - ImmutableSettings.Builder settings(Closure settings) { - byte[] settingsBytes = new GXContentBuilder().buildAsBytes(settings) - settingsBuilder.put(new JsonSettingsLoader().load(settingsBytes)) - } - - GNode build() { - Node node = new InternalNode(settingsBuilder.build(), loadConfigSettings) - new GNode(node) - } - - GNode node() { - build().start() - } -} diff --git a/plugins/lang/groovy/src/main/java/es-plugin.properties b/plugins/lang/groovy/src/main/java/es-plugin.properties deleted file mode 100644 index f7ad5b29fbc..00000000000 --- a/plugins/lang/groovy/src/main/java/es-plugin.properties +++ /dev/null @@ -1 +0,0 @@ -plugin=org.elasticsearch.plugin.groovy.GroovyPlugin diff --git a/plugins/lang/groovy/src/main/java/org/elasticsearch/plugin/groovy/GroovyPlugin.java b/plugins/lang/groovy/src/main/java/org/elasticsearch/plugin/groovy/GroovyPlugin.java deleted file mode 100644 index 69dd1a99c25..00000000000 --- a/plugins/lang/groovy/src/main/java/org/elasticsearch/plugin/groovy/GroovyPlugin.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.plugin.groovy; - -import org.elasticsearch.common.inject.Module; -import org.elasticsearch.plugins.AbstractPlugin; -import org.elasticsearch.script.ScriptModule; -import org.elasticsearch.script.groovy.GroovyScriptEngineService; - -/** - * @author kimchy (shay.banon) - */ -public class GroovyPlugin extends AbstractPlugin { - - @Override public String name() { - return "lang-groovy"; - } - - @Override public String description() { - return "Groovy plugin allowing to add groovy scripting support"; - } - - @Override public void processModule(Module module) { - if (module instanceof ScriptModule) { - ((ScriptModule) module).addScriptEngine(GroovyScriptEngineService.class); - } - } -} diff --git a/plugins/lang/groovy/src/main/java/org/elasticsearch/script/groovy/GroovyScriptEngineService.java b/plugins/lang/groovy/src/main/java/org/elasticsearch/script/groovy/GroovyScriptEngineService.java deleted file mode 100644 index 5fedebc761f..00000000000 --- a/plugins/lang/groovy/src/main/java/org/elasticsearch/script/groovy/GroovyScriptEngineService.java +++ /dev/null @@ -1,201 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.script.groovy; - -import groovy.lang.Binding; -import groovy.lang.GroovyClassLoader; -import groovy.lang.Script; -import org.apache.lucene.index.IndexReader; -import org.apache.lucene.search.Scorer; -import org.elasticsearch.common.Nullable; -import org.elasticsearch.common.component.AbstractComponent; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.script.ExecutableScript; -import org.elasticsearch.script.ScriptEngineService; -import org.elasticsearch.script.ScriptException; -import org.elasticsearch.script.SearchScript; -import org.elasticsearch.search.lookup.SearchLookup; - -import java.util.Map; -import java.util.concurrent.atomic.AtomicLong; - -/** - */ -public class GroovyScriptEngineService extends AbstractComponent implements ScriptEngineService { - - private final AtomicLong counter = new AtomicLong(); - - private final GroovyClassLoader loader; - - @Inject public GroovyScriptEngineService(Settings settings) { - super(settings); - this.loader = new GroovyClassLoader(settings.getClassLoader()); - } - - @Override public void close() { - loader.clearCache(); - } - - @Override public String[] types() { - return new String[]{"groovy"}; - } - - @Override public String[] extensions() { - return new String[]{"groovy"}; - } - - @Override public Object compile(String script) { - return loader.parseClass(script, generateScriptName()); - } - - @SuppressWarnings({"unchecked"}) - @Override public ExecutableScript executable(Object compiledScript, Map vars) { - try { - Class scriptClass = (Class) compiledScript; - Script scriptObject = (Script) scriptClass.newInstance(); - Binding binding = new Binding(); - if (vars != null) { - binding.getVariables().putAll(vars); - } - scriptObject.setBinding(binding); - return new GroovyExecutableScript(scriptObject); - } catch (Exception e) { - throw new ScriptException("failed to build executable script", e); - } - } - - @SuppressWarnings({"unchecked"}) - @Override public SearchScript search(Object compiledScript, SearchLookup lookup, @Nullable Map vars) { - try { - Class scriptClass = (Class) compiledScript; - Script scriptObject = (Script) scriptClass.newInstance(); - Binding binding = new Binding(); - binding.getVariables().putAll(lookup.asMap()); - if (vars != null) { - binding.getVariables().putAll(vars); - } - scriptObject.setBinding(binding); - return new GroovySearchScript(scriptObject, lookup); - } catch (Exception e) { - throw new ScriptException("failed to build search script", e); - } - } - - @Override public Object execute(Object compiledScript, Map vars) { - try { - Class scriptClass = (Class) compiledScript; - Script scriptObject = (Script) scriptClass.newInstance(); - Binding binding = new Binding(vars); - scriptObject.setBinding(binding); - return scriptObject.run(); - } catch (Exception e) { - throw new ScriptException("failed to execute script", e); - } - } - - @Override public Object unwrap(Object value) { - return value; - } - - private String generateScriptName() { - return "Script" + counter.incrementAndGet() + ".groovy"; - } - - public static class GroovyExecutableScript implements ExecutableScript { - - private final Script script; - - public GroovyExecutableScript(Script script) { - this.script = script; - } - - @SuppressWarnings({"unchecked"}) - @Override public void setNextVar(String name, Object value) { - script.getBinding().getVariables().put(name, value); - } - - @Override public Object run() { - return script.run(); - } - - @Override public Object unwrap(Object value) { - return value; - } - } - - public static class GroovySearchScript implements SearchScript { - - private final Script script; - - private final SearchLookup lookup; - - public GroovySearchScript(Script script, SearchLookup lookup) { - this.script = script; - this.lookup = lookup; - } - - @Override public void setScorer(Scorer scorer) { - lookup.setScorer(scorer); - } - - @Override public void setNextReader(IndexReader reader) { - lookup.setNextReader(reader); - } - - @Override public void setNextDocId(int doc) { - lookup.setNextDocId(doc); - } - - @SuppressWarnings({"unchecked"}) - @Override public void setNextScore(float score) { - script.getBinding().getVariables().put("_score", score); - } - - @SuppressWarnings({"unchecked"}) - @Override public void setNextVar(String name, Object value) { - script.getBinding().getVariables().put(name, value); - } - - @Override public void setNextSource(Map source) { - lookup.source().setNextSource(source); - } - - @Override public Object run() { - return script.run(); - } - - @Override public float runAsFloat() { - return ((Number) run()).floatValue(); - } - - @Override public long runAsLong() { - return ((Number) run()).longValue(); - } - - @Override public double runAsDouble() { - return ((Number) run()).doubleValue(); - } - - @Override public Object unwrap(Object value) { - return value; - } - } -} diff --git a/plugins/lang/groovy/src/test/groovy/log4j.properties b/plugins/lang/groovy/src/test/groovy/log4j.properties deleted file mode 100644 index 86d72561ccf..00000000000 --- a/plugins/lang/groovy/src/test/groovy/log4j.properties +++ /dev/null @@ -1,21 +0,0 @@ -log4j.rootLogger=INFO, out -log4j.logger.jgroups=WARN - -#log4j.logger.discovery=TRACE -#log4j.logger.cluster.service=TRACE -#log4j.logger.cluster.action.shard=DEBUG -#log4j.logger.indices.cluster=DEBUG -#log4j.logger.index=TRACE -#log4j.logger.index.engine=DEBUG -#log4j.logger.index.shard.service=DEBUG -#log4j.logger.index.shard.recovery=DEBUG -#log4j.logger.index.cache=DEBUG -#log4j.logger.http=TRACE -#log4j.logger.monitor.memory=TRACE -#log4j.logger.monitor.memory=TRACE -#log4j.logger.cluster.action.shard=TRACE -#log4j.logger.index.gateway=TRACE - -log4j.appender.out=org.apache.log4j.ConsoleAppender -log4j.appender.out.layout=org.apache.log4j.PatternLayout -log4j.appender.out.layout.ConversionPattern=[%d{ABSOLUTE}][%-5p][%-25c] %m%n diff --git a/plugins/lang/groovy/src/test/groovy/org/elasticsearch/groovy/common/xcontent/GXContentBuilderTests.groovy b/plugins/lang/groovy/src/test/groovy/org/elasticsearch/groovy/common/xcontent/GXContentBuilderTests.groovy deleted file mode 100644 index 02654975d4d..00000000000 --- a/plugins/lang/groovy/src/test/groovy/org/elasticsearch/groovy/common/xcontent/GXContentBuilderTests.groovy +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.groovy.common.xcontent - -/** - * @author kimchy (shay.banon) - */ -class GXContentBuilderTests extends GroovyTestCase { - - void testSimple() { - def builder = new GXContentBuilder() - - def result = builder.buildAsString { - rootprop = 'something' - } - - assertEquals '{"rootprop":"something"}', result.toString() - } - - void testArrays() { - def builder = new GXContentBuilder() - - def result = builder.buildAsString { - categories = ['a', 'b', 'c'] - rootprop = 'something' - } - - assertEquals '{"categories":["a","b","c"],"rootprop":"something"}', result.toString() - } - - void testSubObjects() { - def builder = new GXContentBuilder() - - def result = builder.buildAsString { - categories = ['a', 'b', 'c'] - rootprop = 'something' - test { - subprop = 10 - } - } - - assertEquals '{"categories":["a","b","c"],"rootprop":"something","test":{"subprop":10}}', result.toString() - } - - void testAssignedObjects() { - def builder = new GXContentBuilder() - - def result = builder.buildAsString { - categories = ['a', 'b', 'c'] - rootprop = 'something' - test = { - subprop = 10 - } - } - - assertEquals '{"categories":["a","b","c"],"rootprop":"something","test":{"subprop":10}}', result.toString() - } - - void testNamedArgumentHandling() { - def builder = new GXContentBuilder() - def result = builder.buildAsString { - categories = ['a', 'b', 'c'] - rootprop = 'something' - test subprop: 10, three: [1, 2, 3] - } - - assertEquals '{"categories":["a","b","c"],"rootprop":"something","test":{"subprop":10,"three":[1,2,3]}}', result.toString() - } - - - void testArrayOfClosures() { - def builder = new GXContentBuilder() - def result = builder.buildAsString { - foo = [{ bar = 'hello' }] - } - - assertEquals '{"foo":[{"bar":"hello"}]}', result.toString() - } - - void testExampleFromReferenceGuide() { - def builder = new GXContentBuilder() - - def results = ['one', 'two', 'three'] - - def result = builder.buildAsString { - books = results.collect { - [title: it] - } - } - - assertEquals '{"books":[{"title":"one"},{"title":"two"},{"title":"three"}]}', result.toString() - - result = builder.buildAsString { - books = array { - for (b in results) { - book title: b - } - } - } - - assertEquals '{"books":[{"title":"one"},{"title":"two"},{"title":"three"}]}', result.toString() - } - - void testAppendToArray() { - def builder = new GXContentBuilder() - - def results = ['one', 'two', 'three'] - - def result = builder.buildAsString { - books = array { list -> - for (b in results) { - list << [title: b] - } - } - } - - assertEquals '{"books":[{"title":"one"},{"title":"two"},{"title":"three"}]}', result.toString() - } -} diff --git a/plugins/lang/groovy/src/test/groovy/org/elasticsearch/groovy/test/client/BuilderActionsTests.groovy b/plugins/lang/groovy/src/test/groovy/org/elasticsearch/groovy/test/client/BuilderActionsTests.groovy deleted file mode 100644 index eab660a3dae..00000000000 --- a/plugins/lang/groovy/src/test/groovy/org/elasticsearch/groovy/test/client/BuilderActionsTests.groovy +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.groovy.test.client - -import org.elasticsearch.groovy.node.GNode -import org.elasticsearch.groovy.node.GNodeBuilder -import org.testng.annotations.AfterMethod -import org.testng.annotations.BeforeMethod -import org.testng.annotations.Test -import static org.hamcrest.MatcherAssert.* -import static org.hamcrest.Matchers.* - -/** - * @author kimchy (shay.banon) - */ - -class BuilderActionsTests { - - def GNode node - - @BeforeMethod - protected void setUp() { - GNodeBuilder nodeBuilder = new GNodeBuilder() - nodeBuilder.settings { - node { - local = true - } - gateway { - type = 'none' - } - } - - node = nodeBuilder.node() - } - - @AfterMethod - protected void tearDown() { - node.close() - } - - @Test - void testSimpleOperations() { - def indexR = node.client.prepareIndex('test', 'type1', '1').setSource({ - test = 'value' - complex { - value1 = 'value1' - value2 = 'value2' - } - }).gexecute() - - assertThat indexR.response.index, equalTo('test') - assertThat indexR.response.type, equalTo('type1') - assertThat indexR.response.id, equalTo('1') - - node.client.admin.indices.refresh {}.actionGet() - - def countR = node.client.prepareCount('test').setQuery({ - term(test: 'value') - }).gexecute() - - assertThat countR.response.count, equalTo(1l) - - def searchR = node.client.prepareSearch('test').setQuery({ - term(test: 'value') - }).gexecute() - - assertThat searchR.response.hits.totalHits, equalTo(1l) - - def delete = node.client.prepareDelete('test', 'type1', '1').gexecute() - assertThat delete.response.index, equalTo('test') - assertThat delete.response.type, equalTo('type1') - assertThat delete.response.id, equalTo('1') - - def refresh = node.client.admin.indices.refresh {} - assertThat refresh.response.failedShards, equalTo(0) - - def get = node.client.prepareGet('test', 'type1', '1').gexecute() - assertThat get.response.exists, equalTo(false) - } -} diff --git a/plugins/lang/groovy/src/test/groovy/org/elasticsearch/groovy/test/client/DifferentApiExecutionTests.groovy b/plugins/lang/groovy/src/test/groovy/org/elasticsearch/groovy/test/client/DifferentApiExecutionTests.groovy deleted file mode 100644 index e99e1a5c316..00000000000 --- a/plugins/lang/groovy/src/test/groovy/org/elasticsearch/groovy/test/client/DifferentApiExecutionTests.groovy +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.groovy.test.client - -import java.util.concurrent.CountDownLatch -import org.elasticsearch.action.index.IndexRequest -import org.elasticsearch.action.index.IndexResponse -import org.elasticsearch.groovy.node.GNode -import org.elasticsearch.groovy.node.GNodeBuilder -import org.testng.annotations.AfterMethod -import org.testng.annotations.BeforeMethod -import org.testng.annotations.Test -import static org.elasticsearch.client.Requests.* -import static org.hamcrest.MatcherAssert.* -import static org.hamcrest.Matchers.* - -/** - * @author kimchy (shay.banon) - */ -class DifferentApiExecutionTests { - - def GNode node - - @BeforeMethod - protected void setUp() { - GNodeBuilder nodeBuilder = new GNodeBuilder() - nodeBuilder.settings { - node { - local = true - } - gateway { - type = 'none' - } - } - - node = nodeBuilder.node() - } - - @AfterMethod - protected void tearDown() { - node.close() - } - - @Test - void verifyDifferentApiExecutions() { - def response = node.client.index(new IndexRequest( - index: 'test', - type: 'type1', - id: '1', - source: { - test = 'value' - complex { - value1 = 'value1' - value2 = 'value2' - } - })).response - assertThat response.index, equalTo('test') - assertThat response.type, equalTo('type1') - assertThat response.id, equalTo('1') - - def refresh = node.client.admin.indices.refresh {} - assertThat 0, equalTo(refresh.response.failedShards) - - def getR = node.client.get { - index 'test' - type 'type1' - id '1' - } - assertThat getR.response.exists, equalTo(true) - assertThat getR.response.index, equalTo('test') - assertThat getR.response.type, equalTo('type1') - assertThat getR.response.id, equalTo('1') - assertThat getR.response.sourceAsString(), equalTo('{"test":"value","complex":{"value1":"value1","value2":"value2"}}') - assertThat getR.response.source.test, equalTo('value') - assertThat getR.response.source.complex.value1, equalTo('value1') - - response = node.client.index({ - index = 'test' - type = 'type1' - id = '1' - source = { - test = 'value' - complex { - value1 = 'value1' - value2 = 'value2' - } - } - }).response - assertThat response.index, equalTo('test') - assertThat response.type, equalTo('type1') - assertThat response.id, equalTo('1') - - def indexR = node.client.index(indexRequest().with { - index 'test' - type 'type1' - id '1' - source { - test = 'value' - complex { - value1 = 'value1' - value2 = 'value2' - } - } - }) - CountDownLatch latch = new CountDownLatch(1) - indexR.success = { IndexResponse responseX -> - assertThat responseX.index, equalTo('test') - assertThat indexR.response.index, equalTo('test') - assertThat responseX.type, equalTo('type1') - assertThat indexR.response.type, equalTo('type1') - assertThat response.id, equalTo('1') - assertThat indexR.response.id, equalTo('1') - latch.countDown() - } - latch.await() - - indexR = node.client.index { - index 'test' - type 'type1' - id '1' - source { - test = 'value' - complex { - value1 = 'value1' - value2 = 'value2' - } - } - } - latch = new CountDownLatch(1) - indexR.listener = { - assertThat indexR.response.index, equalTo('test') - assertThat indexR.response.type, equalTo('type1') - assertThat indexR.response.id, equalTo('1') - latch.countDown() - } - latch.await() - } -} - diff --git a/plugins/lang/groovy/src/test/groovy/org/elasticsearch/groovy/test/client/SimpleActionsTests.groovy b/plugins/lang/groovy/src/test/groovy/org/elasticsearch/groovy/test/client/SimpleActionsTests.groovy deleted file mode 100644 index 29e16fafd8e..00000000000 --- a/plugins/lang/groovy/src/test/groovy/org/elasticsearch/groovy/test/client/SimpleActionsTests.groovy +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.groovy.test.client - -import org.elasticsearch.groovy.node.GNode -import org.elasticsearch.groovy.node.GNodeBuilder -import org.testng.annotations.AfterMethod -import org.testng.annotations.BeforeMethod -import org.testng.annotations.Test -import static org.hamcrest.MatcherAssert.* -import static org.hamcrest.Matchers.* - -/** - * @author kimchy (shay.banon) - */ -class SimpleActionsTests { - - def GNode node - - @BeforeMethod - protected void setUp() { - GNodeBuilder nodeBuilder = new GNodeBuilder() - nodeBuilder.settings { - node { - local = true - } - gateway { - type = 'none' - } - } - - node = nodeBuilder.node() - } - - @AfterMethod - protected void tearDown() { - node.close() - } - - @Test - void testSimpleOperations() { - def value1 = new org.elasticsearch.groovy.common.xcontent.GXContentBuilder().buildAsString { - something = 'test' - } - println value1 - - def indexR = node.client.index { - index 'test' - type 'type1' - id '1' - source { - test = 'value' - complex { - value1 = 'value1' - value2 = 'value2' - } - } - } - assertThat indexR.response.index, equalTo('test') - assertThat indexR.response.type, equalTo('type1') - assertThat indexR.response.id, equalTo('1') - - def delete = node.client.delete { - index 'test' - type 'type1' - id '1' - } - assertThat delete.response.index, equalTo('test') - assertThat delete.response.type, equalTo('type1') - assertThat delete.response.id, equalTo('1') - - def refresh = node.client.admin.indices.refresh {} - assertThat refresh.response.failedShards, equalTo(0) - - def get = node.client.get { - index 'test' - type 'type1' - id '1' - } - assertThat get.response.exists, equalTo(false) - - indexR = node.client.index { - index 'test' - type 'type1' - id '1' - source { - test = 'value' - complex { - value1 = 'value1' - value2 = 'value2' - } - } - } - assertThat indexR.response.index, equalTo('test') - assertThat indexR.response.type, equalTo('type1') - assertThat indexR.response.id, equalTo('1') - - refresh = node.client.admin.indices.refresh {} - assertThat refresh.response.failedShards, equalTo(0) - - def count = node.client.count { - indices 'test' - types 'type1' - query { - term { - test = 'value' - } - } - } - assertThat count.response.failedShards, equalTo(0) - assertThat count.response.count, equalTo(1l) - - def search = node.client.search { - indices 'test' - types 'type1' - source { - query { - term(test: 'value') - } - } - } - assertThat search.response.failedShards, equalTo(0) - assertThat search.response.hits.totalHits, equalTo(1l) - assertThat search.response.hits[0].source.test, equalTo('value') - - def deleteByQuery = node.client.deleteByQuery { - indices 'test' - query { - term(test: 'value') - } - } - assertThat deleteByQuery.response.indices.test.failedShards, equalTo(0) - - refresh = node.client.admin.indices.refresh {} - assertThat refresh.response.failedShards, equalTo(0) - - get = node.client.get { - index 'test' - type 'type1' - id '1' - } - assertThat get.response.exists, equalTo(false) - } -} diff --git a/plugins/lang/groovy/src/test/groovy/org/elasticsearch/groovy/test/node/GNodeBuilderTests.groovy b/plugins/lang/groovy/src/test/groovy/org/elasticsearch/groovy/test/node/GNodeBuilderTests.groovy deleted file mode 100644 index 859611a7582..00000000000 --- a/plugins/lang/groovy/src/test/groovy/org/elasticsearch/groovy/test/node/GNodeBuilderTests.groovy +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.groovy.test.node - -import org.elasticsearch.groovy.node.GNode -import org.elasticsearch.groovy.node.GNodeBuilder -import static org.elasticsearch.groovy.node.GNodeBuilder.* - -/** - * @author kimchy (shay.banon) - */ -class GNodeBuilderTests extends GroovyTestCase { - - void testGNodeBuilder() { - GNodeBuilder nodeBuilder = nodeBuilder() - nodeBuilder.settings { - node { - local = true - } - cluster { - name = 'test' - } - } - GNode node = nodeBuilder.node() - node.stop().close() - } -} diff --git a/plugins/lang/groovy/src/test/groovy/sample.groovy b/plugins/lang/groovy/src/test/groovy/sample.groovy deleted file mode 100644 index a6c5c640311..00000000000 --- a/plugins/lang/groovy/src/test/groovy/sample.groovy +++ /dev/null @@ -1,36 +0,0 @@ -//@Grapes([ -// @Grab(group = 'org.elasticsearch', module = 'elasticsearch-groovy', version = '0.7.0-SNAPSHOT'), -// @Grab(group = 'org.slf4j', module = 'slf4j-simple', version = '1.5.8') -///* @Grab(group = 'org.slf4j', module = 'slf4j-log4j12', version = '1.5.8')*/ -//]) - -def startNode() { - def nodeBuilder = new org.elasticsearch.groovy.node.GNodeBuilder() - nodeBuilder.settings { - node { - client = true - } - } - nodeBuilder.node() -} - - -def node = startNode() - -println "settings $node.settings.asMap" - -println "Node started" - -future = node.client.index { - index "twitter" - lang "tweet" - id "1" - source { - user = "kimchy" - message = "this is a tweet" - } -} - -println "Indexed $future.response.index/$future.response.type/$future.response.id" - -node.close() diff --git a/plugins/lang/groovy/src/test/java/org/elasticsearch/script/groovy/GroovyScriptMultiThreadedTest.java b/plugins/lang/groovy/src/test/java/org/elasticsearch/script/groovy/GroovyScriptMultiThreadedTest.java deleted file mode 100644 index bf46ea7ac49..00000000000 --- a/plugins/lang/groovy/src/test/java/org/elasticsearch/script/groovy/GroovyScriptMultiThreadedTest.java +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.script.groovy; - -import org.elasticsearch.common.logging.ESLogger; -import org.elasticsearch.common.logging.Loggers; -import org.elasticsearch.common.settings.ImmutableSettings; -import org.elasticsearch.common.util.concurrent.jsr166y.ThreadLocalRandom; -import org.elasticsearch.script.ExecutableScript; -import org.testng.annotations.Test; - -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.CyclicBarrier; -import java.util.concurrent.atomic.AtomicBoolean; - -import static org.hamcrest.MatcherAssert.*; -import static org.hamcrest.Matchers.*; - -/** - * @author kimchy (shay.banon) - */ -@Test -public class GroovyScriptMultiThreadedTest { - - protected final ESLogger logger = Loggers.getLogger(getClass()); - - @Test public void testExecutableNoRuntimeParams() throws Exception { - final GroovyScriptEngineService se = new GroovyScriptEngineService(ImmutableSettings.Builder.EMPTY_SETTINGS); - final Object compiled = se.compile("x + y"); - final AtomicBoolean failed = new AtomicBoolean(); - - Thread[] threads = new Thread[50]; - final CountDownLatch latch = new CountDownLatch(threads.length); - final CyclicBarrier barrier = new CyclicBarrier(threads.length + 1); - for (int i = 0; i < threads.length; i++) { - threads[i] = new Thread(new Runnable() { - @Override public void run() { - try { - barrier.await(); - long x = ThreadLocalRandom.current().nextInt(); - long y = ThreadLocalRandom.current().nextInt(); - long addition = x + y; - Map vars = new HashMap(); - vars.put("x", x); - vars.put("y", y); - ExecutableScript script = se.executable(compiled, vars); - for (int i = 0; i < 100000; i++) { - long result = ((Number) script.run()).longValue(); - assertThat(result, equalTo(addition)); - } - } catch (Throwable t) { - failed.set(true); - logger.error("failed", t); - } finally { - latch.countDown(); - } - } - }); - } - for (int i = 0; i < threads.length; i++) { - threads[i].start(); - } - barrier.await(); - latch.await(); - assertThat(failed.get(), equalTo(false)); - } - - - @Test public void testExecutableWithRuntimeParams() throws Exception { - final GroovyScriptEngineService se = new GroovyScriptEngineService(ImmutableSettings.Builder.EMPTY_SETTINGS); - final Object compiled = se.compile("x + y"); - final AtomicBoolean failed = new AtomicBoolean(); - - Thread[] threads = new Thread[50]; - final CountDownLatch latch = new CountDownLatch(threads.length); - final CyclicBarrier barrier = new CyclicBarrier(threads.length + 1); - for (int i = 0; i < threads.length; i++) { - threads[i] = new Thread(new Runnable() { - @Override public void run() { - try { - barrier.await(); - long x = ThreadLocalRandom.current().nextInt(); - Map vars = new HashMap(); - vars.put("x", x); - ExecutableScript script = se.executable(compiled, vars); - for (int i = 0; i < 100000; i++) { - long y = ThreadLocalRandom.current().nextInt(); - long addition = x + y; - script.setNextVar("y", y); - long result = ((Number) script.run()).longValue(); - assertThat(result, equalTo(addition)); - } - } catch (Throwable t) { - failed.set(true); - logger.error("failed", t); - } finally { - latch.countDown(); - } - } - }); - } - for (int i = 0; i < threads.length; i++) { - threads[i].start(); - } - barrier.await(); - latch.await(); - assertThat(failed.get(), equalTo(false)); - } - - @Test public void testExecute() throws Exception { - final GroovyScriptEngineService se = new GroovyScriptEngineService(ImmutableSettings.Builder.EMPTY_SETTINGS); - final Object compiled = se.compile("x + y"); - final AtomicBoolean failed = new AtomicBoolean(); - - Thread[] threads = new Thread[50]; - final CountDownLatch latch = new CountDownLatch(threads.length); - final CyclicBarrier barrier = new CyclicBarrier(threads.length + 1); - for (int i = 0; i < threads.length; i++) { - threads[i] = new Thread(new Runnable() { - @Override public void run() { - try { - barrier.await(); - Map runtimeVars = new HashMap(); - for (int i = 0; i < 100000; i++) { - long x = ThreadLocalRandom.current().nextInt(); - long y = ThreadLocalRandom.current().nextInt(); - long addition = x + y; - runtimeVars.put("x", x); - runtimeVars.put("y", y); - long result = ((Number) se.execute(compiled, runtimeVars)).longValue(); - assertThat(result, equalTo(addition)); - } - } catch (Throwable t) { - failed.set(true); - logger.error("failed", t); - } finally { - latch.countDown(); - } - } - }); - } - for (int i = 0; i < threads.length; i++) { - threads[i].start(); - } - barrier.await(); - latch.await(); - assertThat(failed.get(), equalTo(false)); - } -} diff --git a/plugins/lang/groovy/src/test/java/org/elasticsearch/script/groovy/GroovyScriptSearchTests.java b/plugins/lang/groovy/src/test/java/org/elasticsearch/script/groovy/GroovyScriptSearchTests.java deleted file mode 100644 index 36ce7848075..00000000000 --- a/plugins/lang/groovy/src/test/java/org/elasticsearch/script/groovy/GroovyScriptSearchTests.java +++ /dev/null @@ -1,262 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.script.groovy; - -import org.elasticsearch.action.search.SearchResponse; -import org.elasticsearch.action.search.SearchType; -import org.elasticsearch.client.Client; -import org.elasticsearch.common.logging.ESLogger; -import org.elasticsearch.common.logging.Loggers; -import org.elasticsearch.common.network.NetworkUtils; -import org.elasticsearch.common.settings.ImmutableSettings; -import org.elasticsearch.node.Node; -import org.elasticsearch.node.NodeBuilder; -import org.elasticsearch.search.sort.SortOrder; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import java.util.List; -import java.util.Map; - -import static org.elasticsearch.client.Requests.*; -import static org.elasticsearch.common.xcontent.XContentFactory.*; -import static org.elasticsearch.index.query.FilterBuilders.*; -import static org.elasticsearch.index.query.QueryBuilders.*; -import static org.elasticsearch.search.builder.SearchSourceBuilder.*; -import static org.hamcrest.MatcherAssert.*; -import static org.hamcrest.Matchers.*; - -/** - * @author kimchy (shay.banon) - */ -public class GroovyScriptSearchTests { - - protected final ESLogger logger = Loggers.getLogger(getClass()); - - private Node node; - - private Client client; - - @BeforeMethod public void createNodes() throws Exception { - node = NodeBuilder.nodeBuilder().settings(ImmutableSettings.settingsBuilder() - .put("cluster.name", "test-cluster-" + NetworkUtils.getLocalAddress()) - .put("gateway.type", "none") - .put("number_of_shards", 1)).node(); - client = node.client(); - } - - @AfterMethod public void closeNodes() { - client.close(); - node.close(); - } - - @Test public void testGroovyScriptFilter() throws Exception { - client.admin().indices().prepareCreate("test").execute().actionGet(); - client.prepareIndex("test", "type1", "1") - .setSource(jsonBuilder().startObject().field("test", "value beck").field("num1", 1.0f).endObject()) - .execute().actionGet(); - client.admin().indices().prepareFlush().execute().actionGet(); - client.prepareIndex("test", "type1", "2") - .setSource(jsonBuilder().startObject().field("test", "value beck").field("num1", 2.0f).endObject()) - .execute().actionGet(); - client.admin().indices().prepareFlush().execute().actionGet(); - client.prepareIndex("test", "type1", "3") - .setSource(jsonBuilder().startObject().field("test", "value beck").field("num1", 3.0f).endObject()) - .execute().actionGet(); - client.admin().indices().refresh(refreshRequest()).actionGet(); - - logger.info("running doc['num1'].value > 1"); - SearchResponse response = client.prepareSearch() - .setQuery(filteredQuery(matchAllQuery(), scriptFilter("doc['num1'].value > 1").lang("groovy"))) - .addSort("num1", SortOrder.ASC) - .addScriptField("sNum1", "groovy", "doc['num1'].value", null) - .execute().actionGet(); - - assertThat(response.hits().totalHits(), equalTo(2l)); - assertThat(response.hits().getAt(0).id(), equalTo("2")); - assertThat((Double) response.hits().getAt(0).fields().get("sNum1").values().get(0), equalTo(2.0)); - assertThat(response.hits().getAt(1).id(), equalTo("3")); - assertThat((Double) response.hits().getAt(1).fields().get("sNum1").values().get(0), equalTo(3.0)); - - logger.info("running doc['num1'].value > param1"); - response = client.prepareSearch() - .setQuery(filteredQuery(matchAllQuery(), scriptFilter("doc['num1'].value > param1").lang("groovy").addParam("param1", 2))) - .addSort("num1", SortOrder.ASC) - .addScriptField("sNum1", "groovy", "doc['num1'].value", null) - .execute().actionGet(); - - assertThat(response.hits().totalHits(), equalTo(1l)); - assertThat(response.hits().getAt(0).id(), equalTo("3")); - assertThat((Double) response.hits().getAt(0).fields().get("sNum1").values().get(0), equalTo(3.0)); - - logger.info("running doc['num1'].value > param1"); - response = client.prepareSearch() - .setQuery(filteredQuery(matchAllQuery(), scriptFilter("doc['num1'].value > param1").lang("groovy").addParam("param1", -1))) - .addSort("num1", SortOrder.ASC) - .addScriptField("sNum1", "groovy", "doc['num1'].value", null) - .execute().actionGet(); - - assertThat(response.hits().totalHits(), equalTo(3l)); - assertThat(response.hits().getAt(0).id(), equalTo("1")); - assertThat((Double) response.hits().getAt(0).fields().get("sNum1").values().get(0), equalTo(1.0)); - assertThat(response.hits().getAt(1).id(), equalTo("2")); - assertThat((Double) response.hits().getAt(1).fields().get("sNum1").values().get(0), equalTo(2.0)); - assertThat(response.hits().getAt(2).id(), equalTo("3")); - assertThat((Double) response.hits().getAt(2).fields().get("sNum1").values().get(0), equalTo(3.0)); - } - - @SuppressWarnings({"unchecked"}) - @Test public void testScriptFieldUsingSource() throws Exception { - client.admin().indices().prepareCreate("test").execute().actionGet(); - client.prepareIndex("test", "type1", "1") - .setSource(jsonBuilder().startObject() - .startObject("obj1").field("test", "something").endObject() - .startObject("obj2").startArray("arr2").value("arr_value1").value("arr_value2").endArray().endObject() - .endObject()) - .execute().actionGet(); - client.admin().indices().refresh(refreshRequest()).actionGet(); - - SearchResponse response = client.prepareSearch() - .setQuery(matchAllQuery()) - .addField("_source.obj1") // we also automatically detect _source in fields - .addScriptField("s_obj1", "groovy", "_source.obj1", null) - .addScriptField("s_obj1_test", "groovy", "_source.obj1.test", null) - .addScriptField("s_obj2", "groovy", "_source.obj2", null) - .addScriptField("s_obj2_arr2", "groovy", "_source.obj2.arr2", null) - .execute().actionGet(); - - Map sObj1 = (Map) response.hits().getAt(0).field("_source.obj1").value(); - assertThat(sObj1.get("test").toString(), equalTo("something")); - assertThat(response.hits().getAt(0).field("s_obj1_test").value().toString(), equalTo("something")); - - sObj1 = (Map) response.hits().getAt(0).field("s_obj1").value(); - assertThat(sObj1.get("test").toString(), equalTo("something")); - assertThat(response.hits().getAt(0).field("s_obj1_test").value().toString(), equalTo("something")); - - Map sObj2 = (Map) response.hits().getAt(0).field("s_obj2").value(); - List sObj2Arr2 = (List) sObj2.get("arr2"); - assertThat(sObj2Arr2.size(), equalTo(2)); - assertThat(sObj2Arr2.get(0).toString(), equalTo("arr_value1")); - assertThat(sObj2Arr2.get(1).toString(), equalTo("arr_value2")); - - sObj2Arr2 = (List) response.hits().getAt(0).field("s_obj2_arr2").value(); - assertThat(sObj2Arr2.size(), equalTo(2)); - assertThat(sObj2Arr2.get(0).toString(), equalTo("arr_value1")); - assertThat(sObj2Arr2.get(1).toString(), equalTo("arr_value2")); - } - - @Test public void testCustomScriptBoost() throws Exception { - // execute a search before we create an index - try { - client.prepareSearch().setQuery(termQuery("test", "value")).execute().actionGet(); - assert false : "should fail"; - } catch (Exception e) { - // ignore, no indices - } - - try { - client.prepareSearch("test").setQuery(termQuery("test", "value")).execute().actionGet(); - assert false : "should fail"; - } catch (Exception e) { - // ignore, no indices - } - - client.admin().indices().create(createIndexRequest("test")).actionGet(); - client.index(indexRequest("test").type("type1").id("1") - .source(jsonBuilder().startObject().field("test", "value beck").field("num1", 1.0f).endObject())).actionGet(); - client.index(indexRequest("test").type("type1").id("2") - .source(jsonBuilder().startObject().field("test", "value check").field("num1", 2.0f).endObject())).actionGet(); - client.admin().indices().refresh(refreshRequest()).actionGet(); - - logger.info("--- QUERY_THEN_FETCH"); - - logger.info("running doc['num1'].value"); - SearchResponse response = client.search(searchRequest() - .searchType(SearchType.QUERY_THEN_FETCH) - .source(searchSource().explain(true).query(customScoreQuery(termQuery("test", "value")).script("doc['num1'].value").lang("groovy"))) - ).actionGet(); - - assertThat(response.hits().totalHits(), equalTo(2l)); - logger.info("Hit[0] {} Explanation {}", response.hits().getAt(0).id(), response.hits().getAt(0).explanation()); - logger.info("Hit[1] {} Explanation {}", response.hits().getAt(1).id(), response.hits().getAt(1).explanation()); - assertThat(response.hits().getAt(0).id(), equalTo("2")); - assertThat(response.hits().getAt(1).id(), equalTo("1")); - - logger.info("running -doc['num1'].value"); - response = client.search(searchRequest() - .searchType(SearchType.QUERY_THEN_FETCH) - .source(searchSource().explain(true).query(customScoreQuery(termQuery("test", "value")).script("-doc['num1'].value").lang("groovy"))) - ).actionGet(); - - assertThat(response.hits().totalHits(), equalTo(2l)); - logger.info("Hit[0] {} Explanation {}", response.hits().getAt(0).id(), response.hits().getAt(0).explanation()); - logger.info("Hit[1] {} Explanation {}", response.hits().getAt(1).id(), response.hits().getAt(1).explanation()); - assertThat(response.hits().getAt(0).id(), equalTo("1")); - assertThat(response.hits().getAt(1).id(), equalTo("2")); - - - logger.info("running pow(doc['num1'].value, 2)"); - response = client.search(searchRequest() - .searchType(SearchType.QUERY_THEN_FETCH) - .source(searchSource().explain(true).query(customScoreQuery(termQuery("test", "value")).script("Math.pow(doc['num1'].value, 2)").lang("groovy"))) - ).actionGet(); - - assertThat(response.hits().totalHits(), equalTo(2l)); - logger.info("Hit[0] {} Explanation {}", response.hits().getAt(0).id(), response.hits().getAt(0).explanation()); - logger.info("Hit[1] {} Explanation {}", response.hits().getAt(1).id(), response.hits().getAt(1).explanation()); - assertThat(response.hits().getAt(0).id(), equalTo("2")); - assertThat(response.hits().getAt(1).id(), equalTo("1")); - - logger.info("running max(doc['num1'].value, 1)"); - response = client.search(searchRequest() - .searchType(SearchType.QUERY_THEN_FETCH) - .source(searchSource().explain(true).query(customScoreQuery(termQuery("test", "value")).script("Math.max(doc['num1'].value, 1d)").lang("groovy"))) - ).actionGet(); - - assertThat(response.hits().totalHits(), equalTo(2l)); - logger.info("Hit[0] {} Explanation {}", response.hits().getAt(0).id(), response.hits().getAt(0).explanation()); - logger.info("Hit[1] {} Explanation {}", response.hits().getAt(1).id(), response.hits().getAt(1).explanation()); - assertThat(response.hits().getAt(0).id(), equalTo("2")); - assertThat(response.hits().getAt(1).id(), equalTo("1")); - - logger.info("running doc['num1'].value * _score"); - response = client.search(searchRequest() - .searchType(SearchType.QUERY_THEN_FETCH) - .source(searchSource().explain(true).query(customScoreQuery(termQuery("test", "value")).script("doc['num1'].value * _score").lang("groovy"))) - ).actionGet(); - - assertThat(response.hits().totalHits(), equalTo(2l)); - logger.info("Hit[0] {} Explanation {}", response.hits().getAt(0).id(), response.hits().getAt(0).explanation()); - logger.info("Hit[1] {} Explanation {}", response.hits().getAt(1).id(), response.hits().getAt(1).explanation()); - assertThat(response.hits().getAt(0).id(), equalTo("2")); - assertThat(response.hits().getAt(1).id(), equalTo("1")); - - logger.info("running param1 * param2 * _score"); - response = client.search(searchRequest() - .searchType(SearchType.QUERY_THEN_FETCH) - .source(searchSource().explain(true).query(customScoreQuery(termQuery("test", "value")).script("param1 * param2 * _score").param("param1", 2).param("param2", 2).lang("groovy"))) - ).actionGet(); - - assertThat(response.hits().totalHits(), equalTo(2l)); - logger.info("Hit[0] {} Explanation {}", response.hits().getAt(0).id(), response.hits().getAt(0).explanation()); - logger.info("Hit[1] {} Explanation {}", response.hits().getAt(1).id(), response.hits().getAt(1).explanation()); - } -} diff --git a/plugins/lang/groovy/src/test/java/org/elasticsearch/script/groovy/SimpleBench.java b/plugins/lang/groovy/src/test/java/org/elasticsearch/script/groovy/SimpleBench.java deleted file mode 100644 index cffbb899e6a..00000000000 --- a/plugins/lang/groovy/src/test/java/org/elasticsearch/script/groovy/SimpleBench.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.script.groovy; - -import org.elasticsearch.common.StopWatch; -import org.elasticsearch.common.settings.ImmutableSettings; -import org.elasticsearch.script.ExecutableScript; - -import java.util.HashMap; -import java.util.Map; - -/** - * @author kimchy (shay.banon) - */ -public class SimpleBench { - - public static void main(String[] args) { - GroovyScriptEngineService se = new GroovyScriptEngineService(ImmutableSettings.Builder.EMPTY_SETTINGS); - Object compiled = se.compile("x + y"); - - Map vars = new HashMap(); - // warm up - for (int i = 0; i < 1000; i++) { - vars.put("x", i); - vars.put("y", i + 1); - se.execute(compiled, vars); - } - - final long ITER = 100000; - - StopWatch stopWatch = new StopWatch().start(); - for (long i = 0; i < ITER; i++) { - se.execute(compiled, vars); - } - System.out.println("Execute Took: " + stopWatch.stop().lastTaskTime()); - - stopWatch = new StopWatch().start(); - ExecutableScript executableScript = se.executable(compiled, vars); - for (long i = 0; i < ITER; i++) { - executableScript.run(); - } - System.out.println("Executable Took: " + stopWatch.stop().lastTaskTime()); - } -} diff --git a/plugins/lang/javascript/build.gradle b/plugins/lang/javascript/build.gradle deleted file mode 100644 index ee63c191062..00000000000 --- a/plugins/lang/javascript/build.gradle +++ /dev/null @@ -1,138 +0,0 @@ -dependsOn(':elasticsearch') - -apply plugin: 'java' -apply plugin: 'maven' -apply plugin: 'eclipse' - -archivesBaseName = "elasticsearch-lang-javascript" - -explodedDistDir = new File(distsDir, 'exploded') - -configurations.compile.transitive = true -configurations.testCompile.transitive = true - -// no need to use the resource dir -sourceSets.main.resources.srcDirs 'src/main/java' -sourceSets.test.resources.srcDirs 'src/test/java' - -// add the source files to the dist jar -//jar { -// from sourceSets.main.allSource -//} - -configurations { - dists - distLib { - visible = false - transitive = false - } -} - -dependencies { - compile project(':elasticsearch') - - compile('org.mozilla:rhino:1.7R3') - distLib('org.mozilla:rhino:1.7R3') { transitive = false } -} - -task explodedDist(dependsOn: [jar], description: 'Builds the plugin zip file') << { - [explodedDistDir]*.mkdirs() - - copy { - from configurations.distLib - into explodedDistDir - } - - // remove elasticsearch files (compile above adds the elasticsearch one) - ant.delete { fileset(dir: explodedDistDir, includes: "elasticsearch-*.jar") } - - copy { - from libsDir - into explodedDistDir - } - - ant.delete { fileset(dir: explodedDistDir, includes: "elasticsearch-*-javadoc.jar") } - ant.delete { fileset(dir: explodedDistDir, includes: "elasticsearch-*-sources.jar") } -} - -task zip(type: Zip, dependsOn: ['explodedDist']) { - from(explodedDistDir) { - } -} - -task release(dependsOn: [zip]) << { - ant.delete(dir: explodedDistDir) - copy { - from distsDir - into(new File(rootProject.distsDir, "plugins")) - } -} - -configurations { - deployerJars -} - -dependencies { - deployerJars "org.apache.maven.wagon:wagon-http:1.0-beta-2" -} - -task sourcesJar(type: Jar, dependsOn: classes) { - classifier = 'sources' - from sourceSets.main.allSource -} - -task javadocJar(type: Jar, dependsOn: javadoc) { - classifier = 'javadoc' - from javadoc.destinationDir -} - -jar { -// from sourceSets.main.allJava - manifest { - attributes("Implementation-Title": "ElasticSearch", "Implementation-Version": rootProject.version, "Implementation-Date": buildTimeStr) - } -} - - -artifacts { - archives sourcesJar - archives javadocJar -} - -uploadArchives { - repositories.mavenDeployer { - configuration = configurations.deployerJars - repository(url: rootProject.mavenRepoUrl) { - authentication(userName: rootProject.mavenRepoUser, password: rootProject.mavenRepoPass) - } - snapshotRepository(url: rootProject.mavenSnapshotRepoUrl) { - authentication(userName: rootProject.mavenRepoUser, password: rootProject.mavenRepoPass) - } - - pom.project { - inceptionYear '2009' - name 'elasticsearch-plugins-lang-javascript' - description 'JavaScript Plugin for ElasticSearch' - licenses { - license { - name 'The Apache Software License, Version 2.0' - url 'http://www.apache.org/licenses/LICENSE-2.0.txt' - distribution 'repo' - } - } - scm { - connection 'git://github.com/elasticsearch/elasticsearch.git' - developerConnection 'git@github.com:elasticsearch/elasticsearch.git' - url 'http://github.com/elasticsearch/elasticsearch' - } - } - - pom.whenConfigured {pom -> - pom.dependencies = pom.dependencies.findAll {dep -> dep.scope != 'test' } // removes the test scoped ones - } - } -} - -eclipseClasspath { - defaultOutputDir = file('build/eclipse-build') -} \ No newline at end of file diff --git a/plugins/lang/javascript/src/main/java/es-plugin.properties b/plugins/lang/javascript/src/main/java/es-plugin.properties deleted file mode 100644 index e88bdca70c8..00000000000 --- a/plugins/lang/javascript/src/main/java/es-plugin.properties +++ /dev/null @@ -1 +0,0 @@ -plugin=org.elasticsearch.plugin.javascript.JavaScriptPlugin diff --git a/plugins/lang/javascript/src/main/java/org/elasticsearch/plugin/javascript/JavaScriptPlugin.java b/plugins/lang/javascript/src/main/java/org/elasticsearch/plugin/javascript/JavaScriptPlugin.java deleted file mode 100644 index bef185fe425..00000000000 --- a/plugins/lang/javascript/src/main/java/org/elasticsearch/plugin/javascript/JavaScriptPlugin.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.plugin.javascript; - -import org.elasticsearch.common.inject.Module; -import org.elasticsearch.plugins.AbstractPlugin; -import org.elasticsearch.script.ScriptModule; -import org.elasticsearch.script.javascript.JavaScriptScriptEngineService; - -/** - * @author kimchy (shay.banon) - */ -public class JavaScriptPlugin extends AbstractPlugin { - - @Override public String name() { - return "lang-javascript"; - } - - @Override public String description() { - return "JavaScript plugin allowing to add javascript scripting support"; - } - - @Override public void processModule(Module module) { - if (module instanceof ScriptModule) { - ((ScriptModule) module).addScriptEngine(JavaScriptScriptEngineService.class); - } - } -} diff --git a/plugins/lang/javascript/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java b/plugins/lang/javascript/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java deleted file mode 100644 index a85a21e1cba..00000000000 --- a/plugins/lang/javascript/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java +++ /dev/null @@ -1,279 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.script.javascript; - -import org.apache.lucene.index.IndexReader; -import org.apache.lucene.search.Scorer; -import org.elasticsearch.common.Nullable; -import org.elasticsearch.common.component.AbstractComponent; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.script.ExecutableScript; -import org.elasticsearch.script.ScriptEngineService; -import org.elasticsearch.script.SearchScript; -import org.elasticsearch.script.javascript.support.NativeList; -import org.elasticsearch.script.javascript.support.NativeMap; -import org.elasticsearch.script.javascript.support.ScriptValueConverter; -import org.elasticsearch.search.lookup.SearchLookup; -import org.mozilla.javascript.Context; -import org.mozilla.javascript.Script; -import org.mozilla.javascript.Scriptable; -import org.mozilla.javascript.ScriptableObject; -import org.mozilla.javascript.WrapFactory; - -import java.util.List; -import java.util.Map; -import java.util.concurrent.atomic.AtomicLong; - -/** - * @author kimchy (shay.banon) - */ -public class JavaScriptScriptEngineService extends AbstractComponent implements ScriptEngineService { - - private final AtomicLong counter = new AtomicLong(); - - private static WrapFactory wrapFactory = new CustomWrapFactory(); - - private final int optimizationLevel; - - private Scriptable globalScope; - - @Inject public JavaScriptScriptEngineService(Settings settings) { - super(settings); - - this.optimizationLevel = componentSettings.getAsInt("optimization_level", 1); - - Context ctx = Context.enter(); - try { - ctx.setWrapFactory(wrapFactory); - globalScope = ctx.initStandardObjects(null, true); - } finally { - Context.exit(); - } - } - - @Override public void close() { - - } - - @Override public String[] types() { - return new String[]{"js", "javascript"}; - } - - @Override public String[] extensions() { - return new String[]{"js"}; - } - - @Override public Object compile(String script) { - Context ctx = Context.enter(); - try { - ctx.setWrapFactory(wrapFactory); - ctx.setOptimizationLevel(optimizationLevel); - return ctx.compileString(script, generateScriptName(), 1, null); - } finally { - Context.exit(); - } - } - - @Override public ExecutableScript executable(Object compiledScript, Map vars) { - Context ctx = Context.enter(); - try { - ctx.setWrapFactory(wrapFactory); - - Scriptable scope = ctx.newObject(globalScope); - scope.setPrototype(globalScope); - scope.setParentScope(null); - for (Map.Entry entry : vars.entrySet()) { - ScriptableObject.putProperty(scope, entry.getKey(), entry.getValue()); - } - - return new JavaScriptExecutableScript((Script) compiledScript, scope); - } finally { - Context.exit(); - } - } - - @Override public SearchScript search(Object compiledScript, SearchLookup lookup, @Nullable Map vars) { - Context ctx = Context.enter(); - try { - ctx.setWrapFactory(wrapFactory); - - Scriptable scope = ctx.newObject(globalScope); - scope.setPrototype(globalScope); - scope.setParentScope(null); - - for (Map.Entry entry : lookup.asMap().entrySet()) { - ScriptableObject.putProperty(scope, entry.getKey(), entry.getValue()); - } - - if (vars != null) { - for (Map.Entry entry : vars.entrySet()) { - ScriptableObject.putProperty(scope, entry.getKey(), entry.getValue()); - } - } - - return new JavaScriptSearchScript((Script) compiledScript, scope, lookup); - } finally { - Context.exit(); - } - } - - @Override public Object execute(Object compiledScript, Map vars) { - Context ctx = Context.enter(); - ctx.setWrapFactory(wrapFactory); - try { - Script script = (Script) compiledScript; - Scriptable scope = ctx.newObject(globalScope); - scope.setPrototype(globalScope); - scope.setParentScope(null); - - for (Map.Entry entry : vars.entrySet()) { - ScriptableObject.putProperty(scope, entry.getKey(), entry.getValue()); - } - Object ret = script.exec(ctx, scope); - return ScriptValueConverter.unwrapValue(ret); - } finally { - Context.exit(); - } - } - - @Override public Object unwrap(Object value) { - return ScriptValueConverter.unwrapValue(value); - } - - private String generateScriptName() { - return "Script" + counter.incrementAndGet() + ".js"; - } - - public static class JavaScriptExecutableScript implements ExecutableScript { - - private final Script script; - - private final Scriptable scope; - - public JavaScriptExecutableScript(Script script, Scriptable scope) { - this.script = script; - this.scope = scope; - } - - @Override public Object run() { - Context ctx = Context.enter(); - try { - ctx.setWrapFactory(wrapFactory); - return ScriptValueConverter.unwrapValue(script.exec(ctx, scope)); - } finally { - Context.exit(); - } - } - - @Override public void setNextVar(String name, Object value) { - ScriptableObject.putProperty(scope, name, value); - } - - @Override public Object unwrap(Object value) { - return ScriptValueConverter.unwrapValue(value); - } - } - - public static class JavaScriptSearchScript implements SearchScript { - - private final Script script; - - private final Scriptable scope; - - private final SearchLookup lookup; - - public JavaScriptSearchScript(Script script, Scriptable scope, SearchLookup lookup) { - this.script = script; - this.scope = scope; - this.lookup = lookup; - } - - @Override public void setScorer(Scorer scorer) { - lookup.setScorer(scorer); - } - - @Override public void setNextReader(IndexReader reader) { - lookup.setNextReader(reader); - } - - @Override public void setNextDocId(int doc) { - lookup.setNextDocId(doc); - } - - @Override public void setNextScore(float score) { - ScriptableObject.putProperty(scope, "_score", score); - } - - @Override public void setNextVar(String name, Object value) { - ScriptableObject.putProperty(scope, name, value); - } - - @Override public void setNextSource(Map source) { - lookup.source().setNextSource(source); - } - - @Override public Object run() { - Context ctx = Context.enter(); - try { - ctx.setWrapFactory(wrapFactory); - return ScriptValueConverter.unwrapValue(script.exec(ctx, scope)); - } finally { - Context.exit(); - } - } - - @Override public float runAsFloat() { - return ((Number) run()).floatValue(); - } - - @Override public long runAsLong() { - return ((Number) run()).longValue(); - } - - @Override public double runAsDouble() { - return ((Number) run()).doubleValue(); - } - - @Override public Object unwrap(Object value) { - return ScriptValueConverter.unwrapValue(value); - } - } - - /** - * Wrap Factory for Rhino Script Engine - */ - public static class CustomWrapFactory extends WrapFactory { - - public CustomWrapFactory() { - setJavaPrimitiveWrap(false); // RingoJS does that..., claims its annoying... - } - - public Scriptable wrapAsJavaObject(Context cx, Scriptable scope, Object javaObject, Class staticType) { - if (javaObject instanceof Map) { - return new NativeMap(scope, (Map) javaObject); - } - if (javaObject instanceof List) { - return new NativeList(scope, (List) javaObject); - } - return super.wrapAsJavaObject(cx, scope, javaObject, staticType); - } - } -} diff --git a/plugins/lang/javascript/src/main/java/org/elasticsearch/script/javascript/support/NativeList.java b/plugins/lang/javascript/src/main/java/org/elasticsearch/script/javascript/support/NativeList.java deleted file mode 100644 index 9a967d48a38..00000000000 --- a/plugins/lang/javascript/src/main/java/org/elasticsearch/script/javascript/support/NativeList.java +++ /dev/null @@ -1,207 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.script.javascript.support; - -import org.mozilla.javascript.Scriptable; -import org.mozilla.javascript.Undefined; -import org.mozilla.javascript.Wrapper; - -import java.util.List; - -/** - * @author kimchy (shay.banon) - */ -public class NativeList implements Scriptable, Wrapper { - private static final long serialVersionUID = 3664761893203964569L; - - private List list; - private Scriptable parentScope; - private Scriptable prototype; - - - public static NativeList wrap(Scriptable scope, List list) { - return new NativeList(scope, list); - } - - public NativeList(Scriptable scope, List list) { - this.parentScope = scope; - this.list = list; - } - - /* (non-Javadoc) - * @see org.mozilla.javascript.Wrapper#unwrap() - */ - - public Object unwrap() { - return list; - } - - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#getClassName() - */ - - public String getClassName() { - return "NativeList"; - } - - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#get(java.lang.String, org.mozilla.javascript.Scriptable) - */ - - public Object get(String name, Scriptable start) { - if ("length".equals(name)) { - return list.size(); - } else { - return Undefined.instance; - } - } - - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#get(int, org.mozilla.javascript.Scriptable) - */ - - public Object get(int index, Scriptable start) { - if (index < 0 || index >= list.size()) { - return Undefined.instance; - } - return list.get(index); - } - - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#has(java.lang.String, org.mozilla.javascript.Scriptable) - */ - - public boolean has(String name, Scriptable start) { - if ("length".equals(name)) { - return true; - } - return false; - } - - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#has(int, org.mozilla.javascript.Scriptable) - */ - - public boolean has(int index, Scriptable start) { - return index >= 0 && index < list.size(); - } - - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#put(java.lang.String, org.mozilla.javascript.Scriptable, java.lang.Object) - */ - - @SuppressWarnings("unchecked") - public void put(String name, Scriptable start, Object value) { - // do nothing here... - } - - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#put(int, org.mozilla.javascript.Scriptable, java.lang.Object) - */ - - public void put(int index, Scriptable start, Object value) { - if (index == list.size()) { - list.add(value); - } else { - list.set(index, value); - } - } - - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#delete(java.lang.String) - */ - - public void delete(String name) { - // nothing here - } - - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#delete(int) - */ - - public void delete(int index) { - list.remove(index); - } - - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#getPrototype() - */ - - public Scriptable getPrototype() { - return this.prototype; - } - - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#setPrototype(org.mozilla.javascript.Scriptable) - */ - - public void setPrototype(Scriptable prototype) { - this.prototype = prototype; - } - - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#getParentScope() - */ - - public Scriptable getParentScope() { - return this.parentScope; - } - - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#setParentScope(org.mozilla.javascript.Scriptable) - */ - - public void setParentScope(Scriptable parent) { - this.parentScope = parent; - } - - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#getIds() - */ - - public Object[] getIds() { - int size = list.size(); - Object[] ids = new Object[size]; - for (int i = 0; i < size; ++i) { - ids[i] = i; - } - return ids; - } - - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#getDefaultValue(java.lang.Class) - */ - - public Object getDefaultValue(Class hint) { - return null; - } - - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#hasInstance(org.mozilla.javascript.Scriptable) - */ - - public boolean hasInstance(Scriptable value) { - if (!(value instanceof Wrapper)) - return false; - Object instance = ((Wrapper) value).unwrap(); - return List.class.isInstance(instance); - } - -} diff --git a/plugins/lang/javascript/src/main/java/org/elasticsearch/script/javascript/support/NativeMap.java b/plugins/lang/javascript/src/main/java/org/elasticsearch/script/javascript/support/NativeMap.java deleted file mode 100644 index 2e9cc4d72fc..00000000000 --- a/plugins/lang/javascript/src/main/java/org/elasticsearch/script/javascript/support/NativeMap.java +++ /dev/null @@ -1,223 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.script.javascript.support; - -import org.mozilla.javascript.Scriptable; -import org.mozilla.javascript.Wrapper; - -import java.util.Iterator; -import java.util.Map; - -/** - * Wrapper for exposing maps in Rhino scripts. - * - * @author kimchy (shay.banon) - */ -public class NativeMap implements Scriptable, Wrapper { - private static final long serialVersionUID = 3664761893203964569L; - - private Map map; - private Scriptable parentScope; - private Scriptable prototype; - - - /** - * Construct - * - * @param scope - * @param map - * @return native map - */ - public static NativeMap wrap(Scriptable scope, Map map) { - return new NativeMap(scope, map); - } - - /** - * Construct - * - * @param scope - * @param map - */ - public NativeMap(Scriptable scope, Map map) { - this.parentScope = scope; - this.map = map; - } - - /* (non-Javadoc) - * @see org.mozilla.javascript.Wrapper#unwrap() - */ - - public Object unwrap() { - return map; - } - - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#getClassName() - */ - - public String getClassName() { - return "NativeMap"; - } - - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#get(java.lang.String, org.mozilla.javascript.Scriptable) - */ - - public Object get(String name, Scriptable start) { - // get the property from the underlying QName map - if ("length".equals(name)) { - return map.size(); - } else { - return map.get(name); - } - } - - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#get(int, org.mozilla.javascript.Scriptable) - */ - - public Object get(int index, Scriptable start) { - Object value = null; - int i = 0; - Iterator itrValues = map.values().iterator(); - while (i++ <= index && itrValues.hasNext()) { - value = itrValues.next(); - } - return value; - } - - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#has(java.lang.String, org.mozilla.javascript.Scriptable) - */ - - public boolean has(String name, Scriptable start) { - // locate the property in the underlying map - return map.containsKey(name); - } - - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#has(int, org.mozilla.javascript.Scriptable) - */ - - public boolean has(int index, Scriptable start) { - return (index >= 0 && map.values().size() > index); - } - - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#put(java.lang.String, org.mozilla.javascript.Scriptable, java.lang.Object) - */ - - @SuppressWarnings("unchecked") - public void put(String name, Scriptable start, Object value) { - map.put(name, value); - } - - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#put(int, org.mozilla.javascript.Scriptable, java.lang.Object) - */ - - public void put(int index, Scriptable start, Object value) { - // TODO: implement? - } - - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#delete(java.lang.String) - */ - - public void delete(String name) { - map.remove(name); - } - - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#delete(int) - */ - - public void delete(int index) { - int i = 0; - Iterator itrKeys = map.keySet().iterator(); - while (i <= index && itrKeys.hasNext()) { - Object key = itrKeys.next(); - if (i == index) { - map.remove(key); - break; - } - } - } - - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#getPrototype() - */ - - public Scriptable getPrototype() { - return this.prototype; - } - - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#setPrototype(org.mozilla.javascript.Scriptable) - */ - - public void setPrototype(Scriptable prototype) { - this.prototype = prototype; - } - - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#getParentScope() - */ - - public Scriptable getParentScope() { - return this.parentScope; - } - - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#setParentScope(org.mozilla.javascript.Scriptable) - */ - - public void setParentScope(Scriptable parent) { - this.parentScope = parent; - } - - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#getIds() - */ - - public Object[] getIds() { - return map.keySet().toArray(); - } - - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#getDefaultValue(java.lang.Class) - */ - - public Object getDefaultValue(Class hint) { - return null; - } - - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#hasInstance(org.mozilla.javascript.Scriptable) - */ - - public boolean hasInstance(Scriptable value) { - if (!(value instanceof Wrapper)) - return false; - Object instance = ((Wrapper) value).unwrap(); - return Map.class.isInstance(instance); - } - -} diff --git a/plugins/lang/javascript/src/main/java/org/elasticsearch/script/javascript/support/ScriptValueConverter.java b/plugins/lang/javascript/src/main/java/org/elasticsearch/script/javascript/support/ScriptValueConverter.java deleted file mode 100644 index 37976e29473..00000000000 --- a/plugins/lang/javascript/src/main/java/org/elasticsearch/script/javascript/support/ScriptValueConverter.java +++ /dev/null @@ -1,183 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.script.javascript.support; - -import org.mozilla.javascript.*; - -import java.util.*; - -/** - * Value Converter to marshal objects between Java and Javascript. - * - * @author kimchy (shay.banon) - */ -public final class ScriptValueConverter { - private static final String TYPE_DATE = "Date"; - - - /** - * Private constructor - methods are static - */ - private ScriptValueConverter() { - } - - /** - * Convert an object from a script wrapper value to a serializable value valid outside - * of the Rhino script processor context. - * - * This includes converting JavaScript Array objects to Lists of valid objects. - * - * @param value Value to convert from script wrapper object to external object value. - * @return unwrapped and converted value. - */ - public static Object unwrapValue(Object value) { - if (value == null) { - return null; - } else if (value instanceof Wrapper) { - // unwrap a Java object from a JavaScript wrapper - // recursively call this method to convert the unwrapped value - value = unwrapValue(((Wrapper) value).unwrap()); - } else if (value instanceof IdScriptableObject) { - // check for special case Native object wrappers - String className = ((IdScriptableObject) value).getClassName(); - // check for special case of the String object - if ("String".equals(className)) { - value = Context.jsToJava(value, String.class); - } - // check for special case of a Date object - else if ("Date".equals(className)) { - value = Context.jsToJava(value, Date.class); - } else { - // a scriptable object will probably indicate a multi-value property set - // set using a JavaScript associative Array object - Scriptable values = (Scriptable) value; - Object[] propIds = values.getIds(); - - // is it a JavaScript associative Array object using Integer indexes? - if (values instanceof NativeArray && isArray(propIds)) { - // convert JavaScript array of values to a List of Serializable objects - List propValues = new ArrayList(propIds.length); - for (int i = 0; i < propIds.length; i++) { - // work on each key in turn - Integer propId = (Integer) propIds[i]; - - // we are only interested in keys that indicate a list of values - if (propId instanceof Integer) { - // get the value out for the specified key - Object val = values.get(propId, values); - // recursively call this method to convert the value - propValues.add(unwrapValue(val)); - } - } - - value = propValues; - } else { - // any other JavaScript object that supports properties - convert to a Map of objects - Map propValues = new HashMap(propIds.length); - for (int i = 0; i < propIds.length; i++) { - // work on each key in turn - Object propId = propIds[i]; - - // we are only interested in keys that indicate a list of values - if (propId instanceof String) { - // get the value out for the specified key - Object val = values.get((String) propId, values); - // recursively call this method to convert the value - propValues.put((String) propId, unwrapValue(val)); - } - } - value = propValues; - } - } - } else if (value instanceof Object[]) { - // convert back a list Object Java values - Object[] array = (Object[]) value; - ArrayList list = new ArrayList(array.length); - for (int i = 0; i < array.length; i++) { - list.add(unwrapValue(array[i])); - } - value = list; - } else if (value instanceof Map) { - // ensure each value in the Map is unwrapped (which may have been an unwrapped NativeMap!) - Map map = (Map) value; - Map copyMap = new HashMap(map.size()); - for (Object key : map.keySet()) { - copyMap.put(key, unwrapValue(map.get(key))); - } - value = copyMap; - } - return value; - } - - /** - * Convert an object from any repository serialized value to a valid script object. - * This includes converting Collection multi-value properties into JavaScript Array objects. - * - * @param scope Scripting scope - * @param value Property value - * @return Value safe for scripting usage - */ - public static Object wrapValue(Scriptable scope, Object value) { - // perform conversions from Java objects to JavaScript scriptable instances - if (value == null) { - return null; - } else if (value instanceof Date) { - // convert Date to JavaScript native Date object - // call the "Date" constructor on the root scope object - passing in the millisecond - // value from the Java date - this will construct a JavaScript Date with the same value - Date date = (Date) value; - value = ScriptRuntime.newObject( - Context.getCurrentContext(), scope, TYPE_DATE, new Object[]{date.getTime()}); - } else if (value instanceof Collection) { - // recursively convert each value in the collection - Collection collection = (Collection) value; - Object[] array = new Object[collection.size()]; - int index = 0; - for (Object obj : collection) { - array[index++] = wrapValue(scope, obj); - } - // convert array to a native JavaScript Array - value = Context.getCurrentContext().newArray(scope, array); - } else if (value instanceof Map) { - value = new NativeMap(scope, (Map) value); - } - - // simple numbers, strings and booleans are wrapped automatically by Rhino - - return value; - } - - /** - * Look at the id's of a native array and try to determine whether it's actually an Array or a Hashmap - * - * @param ids id's of the native array - * @return boolean true if it's an array, false otherwise (ie it's a map) - */ - private static boolean isArray(final Object[] ids) { - boolean result = true; - for (int i = 0; i < ids.length; i++) { - if (ids[i] instanceof Integer == false) { - result = false; - break; - } - } - return result; - } -} diff --git a/plugins/lang/javascript/src/main/java/org/elasticsearch/script/javascript/support/ScriptableLinkedHashMap.java b/plugins/lang/javascript/src/main/java/org/elasticsearch/script/javascript/support/ScriptableLinkedHashMap.java deleted file mode 100644 index 4b06f006105..00000000000 --- a/plugins/lang/javascript/src/main/java/org/elasticsearch/script/javascript/support/ScriptableLinkedHashMap.java +++ /dev/null @@ -1,188 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.script.javascript.support; - -import org.mozilla.javascript.Scriptable; - -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.Map; - -/** - * Implementation of a Scriptable Map. This is the best choice for maps that want to represent - * JavaScript associative arrays - allowing access via key and integer index. It maintains and - * respects insertion order of the elements and allows either string or integer keys. - * - * @author kimchy (shay.banon) - */ -public class ScriptableLinkedHashMap extends LinkedHashMap implements ScriptableMap { - private static final long serialVersionUID = 3774167893214964123L; - - private Scriptable parentScope; - private Scriptable prototype; - - - public ScriptableLinkedHashMap() { - } - - public ScriptableLinkedHashMap(int initialCapacity) { - super(initialCapacity); - } - - public ScriptableLinkedHashMap(Map source) { - super(source); - } - - /** - * @see org.mozilla.javascript.Scriptable#getClassName() - */ - public String getClassName() { - return "ScriptableMap"; - } - - /** - * @see org.mozilla.javascript.Scriptable#get(java.lang.String, org.mozilla.javascript.Scriptable) - */ - public Object get(String name, Scriptable start) { - // get the property from the underlying QName map - if ("length".equals(name)) { - return this.size(); - } else { - return get(name); - } - } - - /** - * @see org.mozilla.javascript.Scriptable#get(int, org.mozilla.javascript.Scriptable) - */ - public Object get(int index, Scriptable start) { - Object value = null; - int i = 0; - Iterator itrValues = this.values().iterator(); - while (i++ <= index && itrValues.hasNext()) { - value = itrValues.next(); - } - return value; - } - - /** - * @see org.mozilla.javascript.Scriptable#has(java.lang.String, org.mozilla.javascript.Scriptable) - */ - public boolean has(String name, Scriptable start) { - // locate the property in the underlying map - return containsKey(name); - } - - /** - * @see org.mozilla.javascript.Scriptable#has(int, org.mozilla.javascript.Scriptable) - */ - public boolean has(int index, Scriptable start) { - return (index >= 0 && this.values().size() > index); - } - - /** - * @see org.mozilla.javascript.Scriptable#put(java.lang.String, org.mozilla.javascript.Scriptable, java.lang.Object) - */ - @SuppressWarnings("unchecked") - public void put(String name, Scriptable start, Object value) { - // add the property to the underlying QName map - put((K) name, (V) value); - } - - /** - * @see org.mozilla.javascript.Scriptable#put(int, org.mozilla.javascript.Scriptable, java.lang.Object) - */ - public void put(int index, Scriptable start, Object value) { - // TODO: implement? - } - - /** - * @see org.mozilla.javascript.Scriptable#delete(java.lang.String) - */ - public void delete(String name) { - // remove the property from the underlying QName map - remove(name); - } - - /** - * @see org.mozilla.javascript.Scriptable#delete(int) - */ - public void delete(int index) { - int i = 0; - Iterator itrKeys = this.keySet().iterator(); - while (i <= index && itrKeys.hasNext()) { - Object key = itrKeys.next(); - if (i == index) { - remove(key); - break; - } - } - } - - /** - * @see org.mozilla.javascript.Scriptable#getPrototype() - */ - public Scriptable getPrototype() { - return this.prototype; - } - - /** - * @see org.mozilla.javascript.Scriptable#setPrototype(org.mozilla.javascript.Scriptable) - */ - public void setPrototype(Scriptable prototype) { - this.prototype = prototype; - } - - /** - * @see org.mozilla.javascript.Scriptable#getParentScope() - */ - public Scriptable getParentScope() { - return this.parentScope; - } - - /** - * @see org.mozilla.javascript.Scriptable#setParentScope(org.mozilla.javascript.Scriptable) - */ - public void setParentScope(Scriptable parent) { - this.parentScope = parent; - } - - /** - * @see org.mozilla.javascript.Scriptable#getIds() - */ - public Object[] getIds() { - return keySet().toArray(); - } - - /** - * @see org.mozilla.javascript.Scriptable#getDefaultValue(java.lang.Class) - */ - public Object getDefaultValue(Class hint) { - return null; - } - - /** - * @see org.mozilla.javascript.Scriptable#hasInstance(org.mozilla.javascript.Scriptable) - */ - public boolean hasInstance(Scriptable instance) { - return instance instanceof ScriptableLinkedHashMap; - } -} - diff --git a/plugins/lang/javascript/src/main/java/org/elasticsearch/script/javascript/support/ScriptableMap.java b/plugins/lang/javascript/src/main/java/org/elasticsearch/script/javascript/support/ScriptableMap.java deleted file mode 100644 index 07a22c32bf5..00000000000 --- a/plugins/lang/javascript/src/main/java/org/elasticsearch/script/javascript/support/ScriptableMap.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.script.javascript.support; - -import org.mozilla.javascript.Scriptable; - -import java.util.Map; - -/** - * Contract to be implemented by classes providing Map like collections to JavaScript. - * - * @author kimchy (shay.banon) - */ -public interface ScriptableMap extends Scriptable, Map { -} \ No newline at end of file diff --git a/plugins/lang/javascript/src/main/java/org/elasticsearch/script/javascript/support/ScriptableWrappedMap.java b/plugins/lang/javascript/src/main/java/org/elasticsearch/script/javascript/support/ScriptableWrappedMap.java deleted file mode 100644 index 1434a9b097c..00000000000 --- a/plugins/lang/javascript/src/main/java/org/elasticsearch/script/javascript/support/ScriptableWrappedMap.java +++ /dev/null @@ -1,342 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.script.javascript.support; - -import org.mozilla.javascript.Scriptable; -import org.mozilla.javascript.Wrapper; - -import java.util.Collection; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -/** - * Implementation of a Scriptable Map. This is the best choice where you want values to be - * persisted directly to an underlying map supplied on construction. The class automatically - * wraps/unwraps JS objects as they enter/leave the underlying map via the Scriptable interface - * methods - objects are untouched if accessed via the usual Map interface methods. - * - *

Access should be by string key only - not integer index - unless you are sure the wrapped - * map will maintain insertion order of the elements. - * - * @author kimchy (shay.banon) - */ -public class ScriptableWrappedMap implements ScriptableMap, Wrapper { - private Map map; - private Scriptable parentScope; - private Scriptable prototype; - - - /** - * Construction - * - * @param scope - * @param map - * @return scriptable wrapped map - */ - public static ScriptableWrappedMap wrap(Scriptable scope, Map map) { - return new ScriptableWrappedMap(scope, map); - } - - /** - * Construct - * - * @param map - */ - public ScriptableWrappedMap(Map map) { - this.map = map; - } - - /** - * Construct - * - * @param scope - * @param map - */ - public ScriptableWrappedMap(Scriptable scope, Map map) { - this.parentScope = scope; - this.map = map; - } - - /* (non-Javadoc) - * @see org.mozilla.javascript.Wrapper#unwrap() - */ - - public Object unwrap() { - return map; - } - - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#getClassName() - */ - - public String getClassName() { - return "ScriptableWrappedMap"; - } - - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#get(java.lang.String, org.mozilla.javascript.Scriptable) - */ - - public Object get(String name, Scriptable start) { - // get the property from the underlying QName map - if ("length".equals(name)) { - return map.size(); - } else { - return ScriptValueConverter.wrapValue(this.parentScope != null ? this.parentScope : start, map.get(name)); - } - } - - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#get(int, org.mozilla.javascript.Scriptable) - */ - - public Object get(int index, Scriptable start) { - Object value = null; - int i = 0; - Iterator itrValues = map.values().iterator(); - while (i++ <= index && itrValues.hasNext()) { - value = itrValues.next(); - } - return ScriptValueConverter.wrapValue(this.parentScope != null ? this.parentScope : start, value); - } - - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#has(java.lang.String, org.mozilla.javascript.Scriptable) - */ - - public boolean has(String name, Scriptable start) { - // locate the property in the underlying map - return map.containsKey(name); - } - - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#has(int, org.mozilla.javascript.Scriptable) - */ - - public boolean has(int index, Scriptable start) { - return (index >= 0 && map.values().size() > index); - } - - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#put(java.lang.String, org.mozilla.javascript.Scriptable, java.lang.Object) - */ - - @SuppressWarnings("unchecked") - public void put(String name, Scriptable start, Object value) { - map.put(name, ScriptValueConverter.unwrapValue(value)); - } - - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#put(int, org.mozilla.javascript.Scriptable, java.lang.Object) - */ - - public void put(int index, Scriptable start, Object value) { - // TODO: implement? - } - - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#delete(java.lang.String) - */ - - public void delete(String name) { - map.remove(name); - } - - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#delete(int) - */ - - public void delete(int index) { - int i = 0; - Iterator itrKeys = map.keySet().iterator(); - while (i <= index && itrKeys.hasNext()) { - Object key = itrKeys.next(); - if (i == index) { - map.remove(key); - break; - } - } - } - - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#getPrototype() - */ - - public Scriptable getPrototype() { - return this.prototype; - } - - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#setPrototype(org.mozilla.javascript.Scriptable) - */ - - public void setPrototype(Scriptable prototype) { - this.prototype = prototype; - } - - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#getParentScope() - */ - - public Scriptable getParentScope() { - return this.parentScope; - } - - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#setParentScope(org.mozilla.javascript.Scriptable) - */ - - public void setParentScope(Scriptable parent) { - this.parentScope = parent; - } - - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#getIds() - */ - - public Object[] getIds() { - return map.keySet().toArray(); - } - - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#getDefaultValue(java.lang.Class) - */ - - public Object getDefaultValue(Class hint) { - return null; - } - - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#hasInstance(org.mozilla.javascript.Scriptable) - */ - - public boolean hasInstance(Scriptable value) { - if (!(value instanceof Wrapper)) - return false; - Object instance = ((Wrapper) value).unwrap(); - return Map.class.isInstance(instance); - } - - /* (non-Javadoc) - * @see java.util.Map#clear() - */ - - public void clear() { - this.map.clear(); - } - - /* (non-Javadoc) - * @see java.util.Map#containsKey(java.lang.Object) - */ - - public boolean containsKey(Object key) { - return this.map.containsKey(key); - } - - /* (non-Javadoc) - * @see java.util.Map#containsValue(java.lang.Object) - */ - - public boolean containsValue(Object value) { - return this.map.containsValue(value); - } - - /* (non-Javadoc) - * @see java.util.Map#entrySet() - */ - - public Set entrySet() { - return this.map.entrySet(); - } - - /* (non-Javadoc) - * @see java.util.Map#get(java.lang.Object) - */ - - public Object get(Object key) { - return this.map.get(key); - } - - /* (non-Javadoc) - * @see java.util.Map#isEmpty() - */ - - public boolean isEmpty() { - return (this.map.size() == 0); - } - - /* (non-Javadoc) - * @see java.util.Map#keySet() - */ - - public Set keySet() { - return this.map.keySet(); - } - - /* (non-Javadoc) - * @see java.util.Map#put(java.lang.Object, java.lang.Object) - */ - - public Object put(Object key, Object value) { - return this.map.put(key, value); - } - - /* (non-Javadoc) - * @see java.util.Map#putAll(java.util.Map) - */ - - public void putAll(Map t) { - this.map.putAll(t); - } - - /* (non-Javadoc) - * @see java.util.Map#remove(java.lang.Object) - */ - - public Object remove(Object key) { - return this.map.remove(key); - } - - /* (non-Javadoc) - * @see java.util.Map#size() - */ - - public int size() { - return this.map.size(); - } - - /* (non-Javadoc) - * @see java.util.Map#values() - */ - - public Collection values() { - return this.map.values(); - } - - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ - - @Override - public String toString() { - return (this.map != null ? this.map.toString() : super.toString()); - } -} diff --git a/plugins/lang/javascript/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineTests.java b/plugins/lang/javascript/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineTests.java deleted file mode 100644 index 1420975ef5c..00000000000 --- a/plugins/lang/javascript/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineTests.java +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.script.javascript; - -import org.elasticsearch.common.collect.Lists; -import org.elasticsearch.common.collect.MapBuilder; -import org.elasticsearch.common.settings.ImmutableSettings; -import org.elasticsearch.script.ExecutableScript; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import static org.hamcrest.MatcherAssert.*; -import static org.hamcrest.Matchers.*; - -/** - * @author kimchy (shay.banon) - */ -public class JavaScriptScriptEngineTests { - - private JavaScriptScriptEngineService se; - - @BeforeClass public void setup() { - se = new JavaScriptScriptEngineService(ImmutableSettings.Builder.EMPTY_SETTINGS); - } - - @AfterClass public void close() { - se.close(); - } - - @Test public void testSimpleEquation() { - Map vars = new HashMap(); - Object o = se.execute(se.compile("1 + 2"), vars); - assertThat(((Number) o).intValue(), equalTo(3)); - } - - @Test public void testMapAccess() { - Map vars = new HashMap(); - - Map obj2 = MapBuilder.newMapBuilder().put("prop2", "value2").map(); - Map obj1 = MapBuilder.newMapBuilder().put("prop1", "value1").put("obj2", obj2).put("l", Lists.newArrayList("2", "1")).map(); - vars.put("obj1", obj1); - Object o = se.execute(se.compile("obj1"), vars); - assertThat(o, instanceOf(Map.class)); - obj1 = (Map) o; - assertThat((String) obj1.get("prop1"), equalTo("value1")); - assertThat((String) ((Map) obj1.get("obj2")).get("prop2"), equalTo("value2")); - - o = se.execute(se.compile("obj1.l[0]"), vars); - assertThat(((String) o), equalTo("2")); - } - - @Test public void testJavaScriptObjectToMap() { - Map vars = new HashMap(); - Object o = se.execute(se.compile("var obj1 = {}; obj1.prop1 = 'value1'; obj1.obj2 = {}; obj1.obj2.prop2 = 'value2'; obj1"), vars); - Map obj1 = (Map) o; - assertThat((String) obj1.get("prop1"), equalTo("value1")); - assertThat((String) ((Map) obj1.get("obj2")).get("prop2"), equalTo("value2")); - } - - @Test public void testJavaScriptObjectMapInter() { - Map vars = new HashMap(); - Map ctx = new HashMap(); - Map obj1 = new HashMap(); - obj1.put("prop1", "value1"); - ctx.put("obj1", obj1); - vars.put("ctx", ctx); - - se.execute(se.compile("ctx.obj2 = {}; ctx.obj2.prop2 = 'value2'; ctx.obj1.prop1 = 'uvalue1'"), vars); - ctx = (Map) se.unwrap(vars.get("ctx")); - assertThat(ctx.containsKey("obj1"), equalTo(true)); - assertThat((String) ((Map) ctx.get("obj1")).get("prop1"), equalTo("uvalue1")); - assertThat(ctx.containsKey("obj2"), equalTo(true)); - assertThat((String) ((Map) ctx.get("obj2")).get("prop2"), equalTo("value2")); - } - - @Test public void testJavaScriptInnerArrayCreation() { - Map ctx = new HashMap(); - Map doc = new HashMap(); - ctx.put("doc", doc); - - Object complied = se.compile("ctx.doc.field1 = ['value1', 'value2']"); - ExecutableScript script = se.executable(complied, new HashMap()); - script.setNextVar("ctx", ctx); - script.run(); - - Map unwrap = (Map) script.unwrap(ctx); - - assertThat(((Map) unwrap.get("doc")).get("field1"), instanceOf(List.class)); - } - - @Test public void testAccessListInScript() { - Map vars = new HashMap(); - Map obj2 = MapBuilder.newMapBuilder().put("prop2", "value2").map(); - Map obj1 = MapBuilder.newMapBuilder().put("prop1", "value1").put("obj2", obj2).map(); - vars.put("l", Lists.newArrayList("1", "2", "3", obj1)); - - Object o = se.execute(se.compile("l.length"), vars); - assertThat(((Number) o).intValue(), equalTo(4)); - - o = se.execute(se.compile("l[0]"), vars); - assertThat(((String) o), equalTo("1")); - - o = se.execute(se.compile("l[3]"), vars); - obj1 = (Map) o; - assertThat((String) obj1.get("prop1"), equalTo("value1")); - assertThat((String) ((Map) obj1.get("obj2")).get("prop2"), equalTo("value2")); - - o = se.execute(se.compile("l[3].prop1"), vars); - assertThat(((String) o), equalTo("value1")); - } - - @Test public void testChangingVarsCrossExecution1() { - Map vars = new HashMap(); - Map ctx = new HashMap(); - vars.put("ctx", ctx); - Object compiledScript = se.compile("ctx.value"); - - ExecutableScript script = se.executable(compiledScript, vars); - ctx.put("value", 1); - Object o = script.run(); - assertThat(((Number) o).intValue(), equalTo(1)); - - ctx.put("value", 2); - o = script.run(); - assertThat(((Number) o).intValue(), equalTo(2)); - } - - @Test public void testChangingVarsCrossExecution2() { - Map vars = new HashMap(); - Object compiledScript = se.compile("value"); - - ExecutableScript script = se.executable(compiledScript, vars); - script.setNextVar("value", 1); - Object o = script.run(); - assertThat(((Number) o).intValue(), equalTo(1)); - - script.setNextVar("value", 2); - o = script.run(); - assertThat(((Number) o).intValue(), equalTo(2)); - } -} diff --git a/plugins/lang/javascript/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptMultiThreadedTest.java b/plugins/lang/javascript/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptMultiThreadedTest.java deleted file mode 100644 index f1b9305e8dd..00000000000 --- a/plugins/lang/javascript/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptMultiThreadedTest.java +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.script.javascript; - -import org.elasticsearch.common.logging.ESLogger; -import org.elasticsearch.common.logging.Loggers; -import org.elasticsearch.common.settings.ImmutableSettings; -import org.elasticsearch.common.util.concurrent.jsr166y.ThreadLocalRandom; -import org.elasticsearch.script.ExecutableScript; -import org.testng.annotations.Test; - -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.CyclicBarrier; -import java.util.concurrent.atomic.AtomicBoolean; - -import static org.hamcrest.MatcherAssert.*; -import static org.hamcrest.Matchers.*; - -/** - * @author kimchy (shay.banon) - */ -@Test -public class JavaScriptScriptMultiThreadedTest { - - protected final ESLogger logger = Loggers.getLogger(getClass()); - - @Test public void testExecutableNoRuntimeParams() throws Exception { - final JavaScriptScriptEngineService se = new JavaScriptScriptEngineService(ImmutableSettings.Builder.EMPTY_SETTINGS); - final Object compiled = se.compile("x + y"); - final AtomicBoolean failed = new AtomicBoolean(); - - Thread[] threads = new Thread[50]; - final CountDownLatch latch = new CountDownLatch(threads.length); - final CyclicBarrier barrier = new CyclicBarrier(threads.length + 1); - for (int i = 0; i < threads.length; i++) { - threads[i] = new Thread(new Runnable() { - @Override public void run() { - try { - barrier.await(); - long x = ThreadLocalRandom.current().nextInt(); - long y = ThreadLocalRandom.current().nextInt(); - long addition = x + y; - Map vars = new HashMap(); - vars.put("x", x); - vars.put("y", y); - ExecutableScript script = se.executable(compiled, vars); - for (int i = 0; i < 100000; i++) { - long result = ((Number) script.run()).longValue(); - assertThat(result, equalTo(addition)); - } - } catch (Throwable t) { - failed.set(true); - logger.error("failed", t); - } finally { - latch.countDown(); - } - } - }); - } - for (int i = 0; i < threads.length; i++) { - threads[i].start(); - } - barrier.await(); - latch.await(); - assertThat(failed.get(), equalTo(false)); - } - - - @Test public void testExecutableWithRuntimeParams() throws Exception { - final JavaScriptScriptEngineService se = new JavaScriptScriptEngineService(ImmutableSettings.Builder.EMPTY_SETTINGS); - final Object compiled = se.compile("x + y"); - final AtomicBoolean failed = new AtomicBoolean(); - - Thread[] threads = new Thread[50]; - final CountDownLatch latch = new CountDownLatch(threads.length); - final CyclicBarrier barrier = new CyclicBarrier(threads.length + 1); - for (int i = 0; i < threads.length; i++) { - threads[i] = new Thread(new Runnable() { - @Override public void run() { - try { - barrier.await(); - long x = ThreadLocalRandom.current().nextInt(); - Map vars = new HashMap(); - vars.put("x", x); - ExecutableScript script = se.executable(compiled, vars); - for (int i = 0; i < 100000; i++) { - long y = ThreadLocalRandom.current().nextInt(); - long addition = x + y; - script.setNextVar("y", y); - long result = ((Number) script.run()).longValue(); - assertThat(result, equalTo(addition)); - } - } catch (Throwable t) { - failed.set(true); - logger.error("failed", t); - } finally { - latch.countDown(); - } - } - }); - } - for (int i = 0; i < threads.length; i++) { - threads[i].start(); - } - barrier.await(); - latch.await(); - assertThat(failed.get(), equalTo(false)); - } - - @Test public void testExecute() throws Exception { - final JavaScriptScriptEngineService se = new JavaScriptScriptEngineService(ImmutableSettings.Builder.EMPTY_SETTINGS); - final Object compiled = se.compile("x + y"); - final AtomicBoolean failed = new AtomicBoolean(); - - Thread[] threads = new Thread[50]; - final CountDownLatch latch = new CountDownLatch(threads.length); - final CyclicBarrier barrier = new CyclicBarrier(threads.length + 1); - for (int i = 0; i < threads.length; i++) { - threads[i] = new Thread(new Runnable() { - @Override public void run() { - try { - barrier.await(); - Map runtimeVars = new HashMap(); - for (int i = 0; i < 100000; i++) { - long x = ThreadLocalRandom.current().nextInt(); - long y = ThreadLocalRandom.current().nextInt(); - long addition = x + y; - runtimeVars.put("x", x); - runtimeVars.put("y", y); - long result = ((Number) se.execute(compiled, runtimeVars)).longValue(); - assertThat(result, equalTo(addition)); - } - } catch (Throwable t) { - failed.set(true); - logger.error("failed", t); - } finally { - latch.countDown(); - } - } - }); - } - for (int i = 0; i < threads.length; i++) { - threads[i].start(); - } - barrier.await(); - latch.await(); - assertThat(failed.get(), equalTo(false)); - } -} diff --git a/plugins/lang/javascript/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java b/plugins/lang/javascript/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java deleted file mode 100644 index 91d208de858..00000000000 --- a/plugins/lang/javascript/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java +++ /dev/null @@ -1,261 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.script.javascript; - -import org.elasticsearch.action.search.SearchResponse; -import org.elasticsearch.action.search.SearchType; -import org.elasticsearch.client.Client; -import org.elasticsearch.common.logging.ESLogger; -import org.elasticsearch.common.logging.Loggers; -import org.elasticsearch.common.network.NetworkUtils; -import org.elasticsearch.common.settings.ImmutableSettings; -import org.elasticsearch.node.Node; -import org.elasticsearch.node.NodeBuilder; -import org.elasticsearch.search.sort.SortOrder; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import java.util.List; -import java.util.Map; - -import static org.elasticsearch.client.Requests.*; -import static org.elasticsearch.common.xcontent.XContentFactory.*; -import static org.elasticsearch.index.query.FilterBuilders.*; -import static org.elasticsearch.index.query.QueryBuilders.*; -import static org.elasticsearch.search.builder.SearchSourceBuilder.*; -import static org.hamcrest.MatcherAssert.*; -import static org.hamcrest.Matchers.*; - -/** - * @author kimchy (shay.banon) - */ -public class JavaScriptScriptSearchTests { - - protected final ESLogger logger = Loggers.getLogger(getClass()); - - private Node node; - - private Client client; - - @BeforeMethod public void createNodes() throws Exception { - node = NodeBuilder.nodeBuilder().settings(ImmutableSettings.settingsBuilder() - .put("cluster.name", "test-cluster-" + NetworkUtils.getLocalAddress()) - .put("gateway.type", "none") - .put("number_of_shards", 1)).node(); - client = node.client(); - } - - @AfterMethod public void closeNodes() { - client.close(); - node.close(); - } - - @Test public void testJavaScriptFilter() throws Exception { - client.admin().indices().prepareCreate("test").execute().actionGet(); - client.prepareIndex("test", "type1", "1") - .setSource(jsonBuilder().startObject().field("test", "value beck").field("num1", 1.0f).endObject()) - .execute().actionGet(); - client.admin().indices().prepareFlush().execute().actionGet(); - client.prepareIndex("test", "type1", "2") - .setSource(jsonBuilder().startObject().field("test", "value beck").field("num1", 2.0f).endObject()) - .execute().actionGet(); - client.admin().indices().prepareFlush().execute().actionGet(); - client.prepareIndex("test", "type1", "3") - .setSource(jsonBuilder().startObject().field("test", "value beck").field("num1", 3.0f).endObject()) - .execute().actionGet(); - client.admin().indices().refresh(refreshRequest()).actionGet(); - - logger.info("running doc['num1'].value > 1"); - SearchResponse response = client.prepareSearch() - .setQuery(filteredQuery(matchAllQuery(), scriptFilter("doc['num1'].value > 1").lang("js"))) - .addSort("num1", SortOrder.ASC) - .addScriptField("sNum1", "js", "doc['num1'].value", null) - .execute().actionGet(); - - assertThat(response.hits().totalHits(), equalTo(2l)); - assertThat(response.hits().getAt(0).id(), equalTo("2")); - assertThat((Double) response.hits().getAt(0).fields().get("sNum1").values().get(0), equalTo(2.0)); - assertThat(response.hits().getAt(1).id(), equalTo("3")); - assertThat((Double) response.hits().getAt(1).fields().get("sNum1").values().get(0), equalTo(3.0)); - - logger.info("running doc['num1'].value > param1"); - response = client.prepareSearch() - .setQuery(filteredQuery(matchAllQuery(), scriptFilter("doc['num1'].value > param1").lang("js").addParam("param1", 2))) - .addSort("num1", SortOrder.ASC) - .addScriptField("sNum1", "js", "doc['num1'].value", null) - .execute().actionGet(); - - assertThat(response.hits().totalHits(), equalTo(1l)); - assertThat(response.hits().getAt(0).id(), equalTo("3")); - assertThat((Double) response.hits().getAt(0).fields().get("sNum1").values().get(0), equalTo(3.0)); - - logger.info("running doc['num1'].value > param1"); - response = client.prepareSearch() - .setQuery(filteredQuery(matchAllQuery(), scriptFilter("doc['num1'].value > param1").lang("js").addParam("param1", -1))) - .addSort("num1", SortOrder.ASC) - .addScriptField("sNum1", "js", "doc['num1'].value", null) - .execute().actionGet(); - - assertThat(response.hits().totalHits(), equalTo(3l)); - assertThat(response.hits().getAt(0).id(), equalTo("1")); - assertThat((Double) response.hits().getAt(0).fields().get("sNum1").values().get(0), equalTo(1.0)); - assertThat(response.hits().getAt(1).id(), equalTo("2")); - assertThat((Double) response.hits().getAt(1).fields().get("sNum1").values().get(0), equalTo(2.0)); - assertThat(response.hits().getAt(2).id(), equalTo("3")); - assertThat((Double) response.hits().getAt(2).fields().get("sNum1").values().get(0), equalTo(3.0)); - } - - @Test public void testScriptFieldUsingSource() throws Exception { - client.admin().indices().prepareCreate("test").execute().actionGet(); - client.prepareIndex("test", "type1", "1") - .setSource(jsonBuilder().startObject() - .startObject("obj1").field("test", "something").endObject() - .startObject("obj2").startArray("arr2").value("arr_value1").value("arr_value2").endArray().endObject() - .endObject()) - .execute().actionGet(); - client.admin().indices().refresh(refreshRequest()).actionGet(); - - SearchResponse response = client.prepareSearch() - .setQuery(matchAllQuery()) - .addField("_source.obj1") // we also automatically detect _source in fields - .addScriptField("s_obj1", "js", "_source.obj1", null) - .addScriptField("s_obj1_test", "js", "_source.obj1.test", null) - .addScriptField("s_obj2", "js", "_source.obj2", null) - .addScriptField("s_obj2_arr2", "js", "_source.obj2.arr2", null) - .execute().actionGet(); - - Map sObj1 = (Map) response.hits().getAt(0).field("_source.obj1").value(); - assertThat(sObj1.get("test").toString(), equalTo("something")); - assertThat(response.hits().getAt(0).field("s_obj1_test").value().toString(), equalTo("something")); - - sObj1 = (Map) response.hits().getAt(0).field("s_obj1").value(); - assertThat(sObj1.get("test").toString(), equalTo("something")); - assertThat(response.hits().getAt(0).field("s_obj1_test").value().toString(), equalTo("something")); - - Map sObj2 = (Map) response.hits().getAt(0).field("s_obj2").value(); - List sObj2Arr2 = (List) sObj2.get("arr2"); - assertThat(sObj2Arr2.size(), equalTo(2)); - assertThat(sObj2Arr2.get(0).toString(), equalTo("arr_value1")); - assertThat(sObj2Arr2.get(1).toString(), equalTo("arr_value2")); - - sObj2Arr2 = (List) response.hits().getAt(0).field("s_obj2_arr2").value(); - assertThat(sObj2Arr2.size(), equalTo(2)); - assertThat(sObj2Arr2.get(0).toString(), equalTo("arr_value1")); - assertThat(sObj2Arr2.get(1).toString(), equalTo("arr_value2")); - } - - @Test public void testCustomScriptBoost() throws Exception { - // execute a search before we create an index - try { - client.prepareSearch().setQuery(termQuery("test", "value")).execute().actionGet(); - assert false : "should fail"; - } catch (Exception e) { - // ignore, no indices - } - - try { - client.prepareSearch("test").setQuery(termQuery("test", "value")).execute().actionGet(); - assert false : "should fail"; - } catch (Exception e) { - // ignore, no indices - } - - client.admin().indices().create(createIndexRequest("test")).actionGet(); - client.index(indexRequest("test").type("type1").id("1") - .source(jsonBuilder().startObject().field("test", "value beck").field("num1", 1.0f).endObject())).actionGet(); - client.index(indexRequest("test").type("type1").id("2") - .source(jsonBuilder().startObject().field("test", "value check").field("num1", 2.0f).endObject())).actionGet(); - client.admin().indices().refresh(refreshRequest()).actionGet(); - - logger.info("--- QUERY_THEN_FETCH"); - - logger.info("running doc['num1'].value"); - SearchResponse response = client.search(searchRequest() - .searchType(SearchType.QUERY_THEN_FETCH) - .source(searchSource().explain(true).query(customScoreQuery(termQuery("test", "value")).script("doc['num1'].value").lang("js"))) - ).actionGet(); - - assertThat(response.hits().totalHits(), equalTo(2l)); - logger.info("Hit[0] {} Explanation {}", response.hits().getAt(0).id(), response.hits().getAt(0).explanation()); - logger.info("Hit[1] {} Explanation {}", response.hits().getAt(1).id(), response.hits().getAt(1).explanation()); - assertThat(response.hits().getAt(0).id(), equalTo("2")); - assertThat(response.hits().getAt(1).id(), equalTo("1")); - - logger.info("running -doc['num1'].value"); - response = client.search(searchRequest() - .searchType(SearchType.QUERY_THEN_FETCH) - .source(searchSource().explain(true).query(customScoreQuery(termQuery("test", "value")).script("-doc['num1'].value").lang("js"))) - ).actionGet(); - - assertThat(response.hits().totalHits(), equalTo(2l)); - logger.info("Hit[0] {} Explanation {}", response.hits().getAt(0).id(), response.hits().getAt(0).explanation()); - logger.info("Hit[1] {} Explanation {}", response.hits().getAt(1).id(), response.hits().getAt(1).explanation()); - assertThat(response.hits().getAt(0).id(), equalTo("1")); - assertThat(response.hits().getAt(1).id(), equalTo("2")); - - - logger.info("running pow(doc['num1'].value, 2)"); - response = client.search(searchRequest() - .searchType(SearchType.QUERY_THEN_FETCH) - .source(searchSource().explain(true).query(customScoreQuery(termQuery("test", "value")).script("Math.pow(doc['num1'].value, 2)").lang("js"))) - ).actionGet(); - - assertThat(response.hits().totalHits(), equalTo(2l)); - logger.info("Hit[0] {} Explanation {}", response.hits().getAt(0).id(), response.hits().getAt(0).explanation()); - logger.info("Hit[1] {} Explanation {}", response.hits().getAt(1).id(), response.hits().getAt(1).explanation()); - assertThat(response.hits().getAt(0).id(), equalTo("2")); - assertThat(response.hits().getAt(1).id(), equalTo("1")); - - logger.info("running max(doc['num1'].value, 1)"); - response = client.search(searchRequest() - .searchType(SearchType.QUERY_THEN_FETCH) - .source(searchSource().explain(true).query(customScoreQuery(termQuery("test", "value")).script("Math.max(doc['num1'].value, 1)").lang("js"))) - ).actionGet(); - - assertThat(response.hits().totalHits(), equalTo(2l)); - logger.info("Hit[0] {} Explanation {}", response.hits().getAt(0).id(), response.hits().getAt(0).explanation()); - logger.info("Hit[1] {} Explanation {}", response.hits().getAt(1).id(), response.hits().getAt(1).explanation()); - assertThat(response.hits().getAt(0).id(), equalTo("2")); - assertThat(response.hits().getAt(1).id(), equalTo("1")); - - logger.info("running doc['num1'].value * _score"); - response = client.search(searchRequest() - .searchType(SearchType.QUERY_THEN_FETCH) - .source(searchSource().explain(true).query(customScoreQuery(termQuery("test", "value")).script("doc['num1'].value * _score").lang("js"))) - ).actionGet(); - - assertThat(response.hits().totalHits(), equalTo(2l)); - logger.info("Hit[0] {} Explanation {}", response.hits().getAt(0).id(), response.hits().getAt(0).explanation()); - logger.info("Hit[1] {} Explanation {}", response.hits().getAt(1).id(), response.hits().getAt(1).explanation()); - assertThat(response.hits().getAt(0).id(), equalTo("2")); - assertThat(response.hits().getAt(1).id(), equalTo("1")); - - logger.info("running param1 * param2 * _score"); - response = client.search(searchRequest() - .searchType(SearchType.QUERY_THEN_FETCH) - .source(searchSource().explain(true).query(customScoreQuery(termQuery("test", "value")).script("param1 * param2 * _score").param("param1", 2).param("param2", 2).lang("js"))) - ).actionGet(); - - assertThat(response.hits().totalHits(), equalTo(2l)); - logger.info("Hit[0] {} Explanation {}", response.hits().getAt(0).id(), response.hits().getAt(0).explanation()); - logger.info("Hit[1] {} Explanation {}", response.hits().getAt(1).id(), response.hits().getAt(1).explanation()); - } -} diff --git a/plugins/lang/javascript/src/test/java/org/elasticsearch/script/javascript/SimpleBench.java b/plugins/lang/javascript/src/test/java/org/elasticsearch/script/javascript/SimpleBench.java deleted file mode 100644 index f0106b461f1..00000000000 --- a/plugins/lang/javascript/src/test/java/org/elasticsearch/script/javascript/SimpleBench.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.script.javascript; - -import org.elasticsearch.common.StopWatch; -import org.elasticsearch.common.settings.ImmutableSettings; -import org.elasticsearch.script.ExecutableScript; - -import java.util.HashMap; -import java.util.Map; - -/** - * @author kimchy (shay.banon) - */ -public class SimpleBench { - - public static void main(String[] args) { - JavaScriptScriptEngineService se = new JavaScriptScriptEngineService(ImmutableSettings.Builder.EMPTY_SETTINGS); - Object compiled = se.compile("x + y"); - - Map vars = new HashMap(); - // warm up - for (int i = 0; i < 1000; i++) { - vars.put("x", i); - vars.put("y", i + 1); - se.execute(compiled, vars); - } - - final long ITER = 100000; - - StopWatch stopWatch = new StopWatch().start(); - for (long i = 0; i < ITER; i++) { - se.execute(compiled, vars); - } - System.out.println("Execute Took: " + stopWatch.stop().lastTaskTime()); - - stopWatch = new StopWatch().start(); - ExecutableScript executableScript = se.executable(compiled, vars); - for (long i = 0; i < ITER; i++) { - executableScript.run(); - } - System.out.println("Executable Took: " + stopWatch.stop().lastTaskTime()); - - stopWatch = new StopWatch().start(); - executableScript = se.executable(compiled, vars); - for (long i = 0; i < ITER; i++) { - for (Map.Entry entry : vars.entrySet()) { - executableScript.setNextVar(entry.getKey(), entry.getValue()); - } - executableScript.run(); - } - System.out.println("Executable (vars) Took: " + stopWatch.stop().lastTaskTime()); - } -} diff --git a/plugins/lang/python/build.gradle b/plugins/lang/python/build.gradle deleted file mode 100644 index 4ac508f495a..00000000000 --- a/plugins/lang/python/build.gradle +++ /dev/null @@ -1,138 +0,0 @@ -dependsOn(':elasticsearch') - -apply plugin: 'java' -apply plugin: 'maven' -apply plugin: 'eclipse' - -archivesBaseName = "elasticsearch-lang-python" - -explodedDistDir = new File(distsDir, 'exploded') - -configurations.compile.transitive = true -configurations.testCompile.transitive = true - -// no need to use the resource dir -sourceSets.main.resources.srcDirs 'src/main/java' -sourceSets.test.resources.srcDirs 'src/test/java' - -// add the source files to the dist jar -//jar { -// from sourceSets.main.allSource -//} - -configurations { - dists - distLib { - visible = false - transitive = false - } -} - -dependencies { - compile project(':elasticsearch') - - compile('org.python:jython-standalone:2.5.2') { transitive = false } - distLib('org.python:jython-standalone:2.5.2') { transitive = false } -} - -task explodedDist(dependsOn: [jar], description: 'Builds the plugin zip file') << { - [explodedDistDir]*.mkdirs() - - copy { - from configurations.distLib - into explodedDistDir - } - - // remove elasticsearch files (compile above adds the elasticsearch one) - ant.delete { fileset(dir: explodedDistDir, includes: "elasticsearch-*.jar") } - - copy { - from libsDir - into explodedDistDir - } - - ant.delete { fileset(dir: explodedDistDir, includes: "elasticsearch-*-javadoc.jar") } - ant.delete { fileset(dir: explodedDistDir, includes: "elasticsearch-*-sources.jar") } -} - -task zip(type: Zip, dependsOn: ['explodedDist']) { - from(explodedDistDir) { - } -} - -task release(dependsOn: [zip]) << { - ant.delete(dir: explodedDistDir) - copy { - from distsDir - into(new File(rootProject.distsDir, "plugins")) - } -} - -configurations { - deployerJars -} - -dependencies { - deployerJars "org.apache.maven.wagon:wagon-http:1.0-beta-2" -} - -task sourcesJar(type: Jar, dependsOn: classes) { - classifier = 'sources' - from sourceSets.main.allSource -} - -task javadocJar(type: Jar, dependsOn: javadoc) { - classifier = 'javadoc' - from javadoc.destinationDir -} - -jar { -// from sourceSets.main.allJava - manifest { - attributes("Implementation-Title": "ElasticSearch", "Implementation-Version": rootProject.version, "Implementation-Date": buildTimeStr) - } -} - - -artifacts { - archives sourcesJar - archives javadocJar -} - -uploadArchives { - repositories.mavenDeployer { - configuration = configurations.deployerJars - repository(url: rootProject.mavenRepoUrl) { - authentication(userName: rootProject.mavenRepoUser, password: rootProject.mavenRepoPass) - } - snapshotRepository(url: rootProject.mavenSnapshotRepoUrl) { - authentication(userName: rootProject.mavenRepoUser, password: rootProject.mavenRepoPass) - } - - pom.project { - inceptionYear '2009' - name 'elasticsearch-plugins-lang-python' - description 'Python Plugin for ElasticSearch' - licenses { - license { - name 'The Apache Software License, Version 2.0' - url 'http://www.apache.org/licenses/LICENSE-2.0.txt' - distribution 'repo' - } - } - scm { - connection 'git://github.com/elasticsearch/elasticsearch.git' - developerConnection 'git@github.com:elasticsearch/elasticsearch.git' - url 'http://github.com/elasticsearch/elasticsearch' - } - } - - pom.whenConfigured {pom -> - pom.dependencies = pom.dependencies.findAll {dep -> dep.scope != 'test' } // removes the test scoped ones - } - } -} - -eclipseClasspath { - defaultOutputDir = file('build/eclipse-build') -} \ No newline at end of file diff --git a/plugins/lang/python/src/main/java/es-plugin.properties b/plugins/lang/python/src/main/java/es-plugin.properties deleted file mode 100644 index a24df54c363..00000000000 --- a/plugins/lang/python/src/main/java/es-plugin.properties +++ /dev/null @@ -1 +0,0 @@ -plugin=org.elasticsearch.plugin.python.PythonPlugin diff --git a/plugins/lang/python/src/main/java/org/elasticsearch/plugin/python/PythonPlugin.java b/plugins/lang/python/src/main/java/org/elasticsearch/plugin/python/PythonPlugin.java deleted file mode 100644 index 8aad9447f5d..00000000000 --- a/plugins/lang/python/src/main/java/org/elasticsearch/plugin/python/PythonPlugin.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.plugin.python; - -import org.elasticsearch.common.inject.Module; -import org.elasticsearch.plugins.AbstractPlugin; -import org.elasticsearch.script.ScriptModule; -import org.elasticsearch.script.python.PythonScriptEngineService; - -/** - * @author kimchy (shay.banon) - */ -public class PythonPlugin extends AbstractPlugin { - - @Override public String name() { - return "lang-python"; - } - - @Override public String description() { - return "Python plugin allowing to add javascript scripting support"; - } - - @Override public void processModule(Module module) { - if (module instanceof ScriptModule) { - ((ScriptModule) module).addScriptEngine(PythonScriptEngineService.class); - } - } -} diff --git a/plugins/lang/python/src/main/java/org/elasticsearch/script/python/PythonScriptEngineService.java b/plugins/lang/python/src/main/java/org/elasticsearch/script/python/PythonScriptEngineService.java deleted file mode 100644 index 1f265e6dbdf..00000000000 --- a/plugins/lang/python/src/main/java/org/elasticsearch/script/python/PythonScriptEngineService.java +++ /dev/null @@ -1,206 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.script.python; - -import org.apache.lucene.index.IndexReader; -import org.apache.lucene.search.Scorer; -import org.elasticsearch.common.Nullable; -import org.elasticsearch.common.component.AbstractComponent; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.script.ExecutableScript; -import org.elasticsearch.script.ScriptEngineService; -import org.elasticsearch.script.SearchScript; -import org.elasticsearch.search.lookup.SearchLookup; -import org.python.core.Py; -import org.python.core.PyCode; -import org.python.core.PyObject; -import org.python.core.PyStringMap; -import org.python.util.PythonInterpreter; - -import java.util.Map; - -/** - * @author kimchy (shay.banon) - */ -//TODO we can optimize the case for Map similar to PyStringMap -public class PythonScriptEngineService extends AbstractComponent implements ScriptEngineService { - - private final PythonInterpreter interp; - - @Inject public PythonScriptEngineService(Settings settings) { - super(settings); - - this.interp = PythonInterpreter.threadLocalStateInterpreter(null); - } - - @Override public String[] types() { - return new String[]{"python", "py"}; - } - - @Override public String[] extensions() { - return new String[]{"py"}; - } - - @Override public Object compile(String script) { - return interp.compile(script); - } - - @Override public ExecutableScript executable(Object compiledScript, Map vars) { - return new PythonExecutableScript((PyCode) compiledScript, vars); - } - - @Override public SearchScript search(Object compiledScript, SearchLookup lookup, @Nullable Map vars) { - return new PythonSearchScript((PyCode) compiledScript, vars, lookup); - } - - @Override public Object execute(Object compiledScript, Map vars) { - PyObject pyVars = Py.java2py(vars); - interp.setLocals(pyVars); - PyObject ret = interp.eval((PyCode) compiledScript); - if (ret == null) { - return null; - } - return ret.__tojava__(Object.class); - } - - @Override public Object unwrap(Object value) { - return unwrapValue(value); - } - - @Override public void close() { - interp.cleanup(); - } - - public class PythonExecutableScript implements ExecutableScript { - - private final PyCode code; - - private final PyStringMap pyVars; - - public PythonExecutableScript(PyCode code, Map vars) { - this.code = code; - this.pyVars = new PyStringMap(); - for (Map.Entry entry : vars.entrySet()) { - pyVars.__setitem__(entry.getKey(), Py.java2py(entry.getValue())); - } - } - - @Override public void setNextVar(String name, Object value) { - pyVars.__setitem__(name, Py.java2py(value)); - } - - @Override public Object run() { - interp.setLocals(pyVars); - PyObject ret = interp.eval(code); - if (ret == null) { - return null; - } - return ret.__tojava__(Object.class); - } - - @Override public Object unwrap(Object value) { - return unwrapValue(value); - } - } - - public class PythonSearchScript implements SearchScript { - - private final PyCode code; - - private final PyStringMap pyVars; - - private final SearchLookup lookup; - - public PythonSearchScript(PyCode code, Map vars, SearchLookup lookup) { - this.code = code; - this.pyVars = new PyStringMap(); - for (Map.Entry entry : lookup.asMap().entrySet()) { - pyVars.__setitem__(entry.getKey(), Py.java2py(entry.getValue())); - } - if (vars != null) { - for (Map.Entry entry : vars.entrySet()) { - pyVars.__setitem__(entry.getKey(), Py.java2py(entry.getValue())); - } - } - this.lookup = lookup; - } - - @Override public void setScorer(Scorer scorer) { - lookup.setScorer(scorer); - } - - @Override public void setNextReader(IndexReader reader) { - lookup.setNextReader(reader); - } - - @Override public void setNextDocId(int doc) { - lookup.setNextDocId(doc); - } - - @Override public void setNextSource(Map source) { - lookup.source().setNextSource(source); - } - - @Override public void setNextScore(float score) { - pyVars.__setitem__("_score", Py.java2py(score)); - } - - @Override public void setNextVar(String name, Object value) { - pyVars.__setitem__(name, Py.java2py(value)); - } - - @Override public Object run() { - interp.setLocals(pyVars); - PyObject ret = interp.eval(code); - if (ret == null) { - return null; - } - return ret.__tojava__(Object.class); - } - - @Override public float runAsFloat() { - return ((Number) run()).floatValue(); - } - - @Override public long runAsLong() { - return ((Number) run()).longValue(); - } - - @Override public double runAsDouble() { - return ((Number) run()).doubleValue(); - } - - @Override public Object unwrap(Object value) { - return unwrapValue(value); - } - } - - - public static Object unwrapValue(Object value) { - if (value == null) { - return null; - } else if (value instanceof PyObject) { - // seems like this is enough, inner PyDictionary will do the conversion for us for example, so expose it directly - return ((PyObject) value).__tojava__(Object.class); - } - return value; - } -} diff --git a/plugins/lang/python/src/test/java/org/elasticsearch/script/python/PythonScriptEngineTests.java b/plugins/lang/python/src/test/java/org/elasticsearch/script/python/PythonScriptEngineTests.java deleted file mode 100644 index cd6de57beba..00000000000 --- a/plugins/lang/python/src/test/java/org/elasticsearch/script/python/PythonScriptEngineTests.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.script.python; - -import org.elasticsearch.common.collect.Lists; -import org.elasticsearch.common.collect.MapBuilder; -import org.elasticsearch.common.settings.ImmutableSettings; -import org.elasticsearch.script.ExecutableScript; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import java.util.HashMap; -import java.util.Map; - -import static org.hamcrest.MatcherAssert.*; -import static org.hamcrest.Matchers.*; - -/** - * @author kimchy (shay.banon) - */ -public class PythonScriptEngineTests { - - private PythonScriptEngineService se; - - @BeforeClass public void setup() { - se = new PythonScriptEngineService(ImmutableSettings.Builder.EMPTY_SETTINGS); - } - - @AfterClass public void close() { - se.close(); - } - - @Test public void testSimpleEquation() { - Map vars = new HashMap(); - Object o = se.execute(se.compile("1 + 2"), vars); - assertThat(((Number) o).intValue(), equalTo(3)); - } - - @Test public void testMapAccess() { - Map vars = new HashMap(); - - Map obj2 = MapBuilder.newMapBuilder().put("prop2", "value2").map(); - Map obj1 = MapBuilder.newMapBuilder().put("prop1", "value1").put("obj2", obj2).put("l", Lists.newArrayList("2", "1")).map(); - vars.put("obj1", obj1); - Object o = se.execute(se.compile("obj1"), vars); - assertThat(o, instanceOf(Map.class)); - obj1 = (Map) o; - assertThat((String) obj1.get("prop1"), equalTo("value1")); - assertThat((String) ((Map) obj1.get("obj2")).get("prop2"), equalTo("value2")); - - o = se.execute(se.compile("obj1['l'][0]"), vars); - assertThat(((String) o), equalTo("2")); - } - - @Test public void testObjectMapInter() { - Map vars = new HashMap(); - Map ctx = new HashMap(); - Map obj1 = new HashMap(); - obj1.put("prop1", "value1"); - ctx.put("obj1", obj1); - vars.put("ctx", ctx); - - se.execute(se.compile("ctx['obj2'] = { 'prop2' : 'value2' }; ctx['obj1']['prop1'] = 'uvalue1'"), vars); - ctx = (Map) se.unwrap(vars.get("ctx")); - assertThat(ctx.containsKey("obj1"), equalTo(true)); - assertThat((String) ((Map) ctx.get("obj1")).get("prop1"), equalTo("uvalue1")); - assertThat(ctx.containsKey("obj2"), equalTo(true)); - assertThat((String) ((Map) ctx.get("obj2")).get("prop2"), equalTo("value2")); - } - - @Test public void testAccessListInScript() { - Map vars = new HashMap(); - Map obj2 = MapBuilder.newMapBuilder().put("prop2", "value2").map(); - Map obj1 = MapBuilder.newMapBuilder().put("prop1", "value1").put("obj2", obj2).map(); - vars.put("l", Lists.newArrayList("1", "2", "3", obj1)); - -// Object o = se.execute(se.compile("l.length"), vars); -// assertThat(((Number) o).intValue(), equalTo(4)); - - Object o = se.execute(se.compile("l[0]"), vars); - assertThat(((String) o), equalTo("1")); - - o = se.execute(se.compile("l[3]"), vars); - obj1 = (Map) o; - assertThat((String) obj1.get("prop1"), equalTo("value1")); - assertThat((String) ((Map) obj1.get("obj2")).get("prop2"), equalTo("value2")); - - o = se.execute(se.compile("l[3]['prop1']"), vars); - assertThat(((String) o), equalTo("value1")); - } - - @Test public void testChangingVarsCrossExecution1() { - Map vars = new HashMap(); - Map ctx = new HashMap(); - vars.put("ctx", ctx); - Object compiledScript = se.compile("ctx['value']"); - - ExecutableScript script = se.executable(compiledScript, vars); - ctx.put("value", 1); - Object o = script.run(); - assertThat(((Number) o).intValue(), equalTo(1)); - - ctx.put("value", 2); - o = script.run(); - assertThat(((Number) o).intValue(), equalTo(2)); - } - - @Test public void testChangingVarsCrossExecution2() { - Map vars = new HashMap(); - Map ctx = new HashMap(); - Object compiledScript = se.compile("value"); - - ExecutableScript script = se.executable(compiledScript, vars); - script.setNextVar("value", 1); - Object o = script.run(); - assertThat(((Number) o).intValue(), equalTo(1)); - - script.setNextVar("value", 2); - o = script.run(); - assertThat(((Number) o).intValue(), equalTo(2)); - } -} diff --git a/plugins/lang/python/src/test/java/org/elasticsearch/script/python/PythonScriptMultiThreadedTest.java b/plugins/lang/python/src/test/java/org/elasticsearch/script/python/PythonScriptMultiThreadedTest.java deleted file mode 100644 index 4dfd9d58078..00000000000 --- a/plugins/lang/python/src/test/java/org/elasticsearch/script/python/PythonScriptMultiThreadedTest.java +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.script.python; - -import org.elasticsearch.common.logging.ESLogger; -import org.elasticsearch.common.logging.Loggers; -import org.elasticsearch.common.settings.ImmutableSettings; -import org.elasticsearch.common.util.concurrent.jsr166y.ThreadLocalRandom; -import org.elasticsearch.script.ExecutableScript; -import org.testng.annotations.Test; - -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.CyclicBarrier; -import java.util.concurrent.atomic.AtomicBoolean; - -import static org.hamcrest.MatcherAssert.*; -import static org.hamcrest.Matchers.*; - -/** - * @author kimchy (shay.banon) - */ -@Test -public class PythonScriptMultiThreadedTest { - - protected final ESLogger logger = Loggers.getLogger(getClass()); - - @Test public void testExecutableNoRuntimeParams() throws Exception { - final PythonScriptEngineService se = new PythonScriptEngineService(ImmutableSettings.Builder.EMPTY_SETTINGS); - final Object compiled = se.compile("x + y"); - final AtomicBoolean failed = new AtomicBoolean(); - - Thread[] threads = new Thread[50]; - final CountDownLatch latch = new CountDownLatch(threads.length); - final CyclicBarrier barrier = new CyclicBarrier(threads.length + 1); - for (int i = 0; i < threads.length; i++) { - threads[i] = new Thread(new Runnable() { - @Override public void run() { - try { - barrier.await(); - long x = ThreadLocalRandom.current().nextInt(); - long y = ThreadLocalRandom.current().nextInt(); - long addition = x + y; - Map vars = new HashMap(); - vars.put("x", x); - vars.put("y", y); - ExecutableScript script = se.executable(compiled, vars); - for (int i = 0; i < 100000; i++) { - long result = ((Number) script.run()).longValue(); - assertThat(result, equalTo(addition)); - } - } catch (Throwable t) { - failed.set(true); - logger.error("failed", t); - } finally { - latch.countDown(); - } - } - }); - } - for (int i = 0; i < threads.length; i++) { - threads[i].start(); - } - barrier.await(); - latch.await(); - assertThat(failed.get(), equalTo(false)); - } - - -// @Test public void testExecutableWithRuntimeParams() throws Exception { -// final PythonScriptEngineService se = new PythonScriptEngineService(ImmutableSettings.Builder.EMPTY_SETTINGS); -// final Object compiled = se.compile("x + y"); -// final AtomicBoolean failed = new AtomicBoolean(); -// -// Thread[] threads = new Thread[50]; -// final CountDownLatch latch = new CountDownLatch(threads.length); -// final CyclicBarrier barrier = new CyclicBarrier(threads.length + 1); -// for (int i = 0; i < threads.length; i++) { -// threads[i] = new Thread(new Runnable() { -// @Override public void run() { -// try { -// barrier.await(); -// long x = ThreadLocalRandom.current().nextInt(); -// Map vars = new HashMap(); -// vars.put("x", x); -// ExecutableScript script = se.executable(compiled, vars); -// Map runtimeVars = new HashMap(); -// for (int i = 0; i < 100000; i++) { -// long y = ThreadLocalRandom.current().nextInt(); -// long addition = x + y; -// runtimeVars.put("y", y); -// long result = ((Number) script.run(runtimeVars)).longValue(); -// assertThat(result, equalTo(addition)); -// } -// } catch (Throwable t) { -// failed.set(true); -// logger.error("failed", t); -// } finally { -// latch.countDown(); -// } -// } -// }); -// } -// for (int i = 0; i < threads.length; i++) { -// threads[i].start(); -// } -// barrier.await(); -// latch.await(); -// assertThat(failed.get(), equalTo(false)); -// } - - @Test public void testExecute() throws Exception { - final PythonScriptEngineService se = new PythonScriptEngineService(ImmutableSettings.Builder.EMPTY_SETTINGS); - final Object compiled = se.compile("x + y"); - final AtomicBoolean failed = new AtomicBoolean(); - - Thread[] threads = new Thread[50]; - final CountDownLatch latch = new CountDownLatch(threads.length); - final CyclicBarrier barrier = new CyclicBarrier(threads.length + 1); - for (int i = 0; i < threads.length; i++) { - threads[i] = new Thread(new Runnable() { - @Override public void run() { - try { - barrier.await(); - Map runtimeVars = new HashMap(); - for (int i = 0; i < 100000; i++) { - long x = ThreadLocalRandom.current().nextInt(); - long y = ThreadLocalRandom.current().nextInt(); - long addition = x + y; - runtimeVars.put("x", x); - runtimeVars.put("y", y); - long result = ((Number) se.execute(compiled, runtimeVars)).longValue(); - assertThat(result, equalTo(addition)); - } - } catch (Throwable t) { - failed.set(true); - logger.error("failed", t); - } finally { - latch.countDown(); - } - } - }); - } - for (int i = 0; i < threads.length; i++) { - threads[i].start(); - } - barrier.await(); - latch.await(); - assertThat(failed.get(), equalTo(false)); - } -} diff --git a/plugins/lang/python/src/test/java/org/elasticsearch/script/python/PythonScriptSearchTests.java b/plugins/lang/python/src/test/java/org/elasticsearch/script/python/PythonScriptSearchTests.java deleted file mode 100644 index f0af0192e1f..00000000000 --- a/plugins/lang/python/src/test/java/org/elasticsearch/script/python/PythonScriptSearchTests.java +++ /dev/null @@ -1,246 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.script.python; - -import org.elasticsearch.action.search.SearchResponse; -import org.elasticsearch.action.search.SearchType; -import org.elasticsearch.client.Client; -import org.elasticsearch.common.logging.ESLogger; -import org.elasticsearch.common.logging.Loggers; -import org.elasticsearch.common.network.NetworkUtils; -import org.elasticsearch.common.settings.ImmutableSettings; -import org.elasticsearch.node.Node; -import org.elasticsearch.node.NodeBuilder; -import org.elasticsearch.search.sort.SortOrder; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import java.util.Arrays; -import java.util.List; -import java.util.Map; - -import static org.elasticsearch.client.Requests.*; -import static org.elasticsearch.common.xcontent.XContentFactory.*; -import static org.elasticsearch.index.query.FilterBuilders.*; -import static org.elasticsearch.index.query.QueryBuilders.*; -import static org.elasticsearch.search.builder.SearchSourceBuilder.*; -import static org.hamcrest.MatcherAssert.*; -import static org.hamcrest.Matchers.*; - -/** - * @author kimchy (shay.banon) - */ -public class PythonScriptSearchTests { - - protected final ESLogger logger = Loggers.getLogger(getClass()); - - private Node node; - - private Client client; - - @BeforeMethod public void createNodes() throws Exception { - node = NodeBuilder.nodeBuilder().settings(ImmutableSettings.settingsBuilder() - .put("cluster.name", "test-cluster-" + NetworkUtils.getLocalAddress()) - .put("gateway.type", "none") - .put("number_of_shards", 1)).node(); - client = node.client(); - } - - @AfterMethod public void closeNodes() { - client.close(); - node.close(); - } - - @Test public void testPythonFilter() throws Exception { - client.admin().indices().prepareCreate("test").execute().actionGet(); - client.prepareIndex("test", "type1", "1") - .setSource(jsonBuilder().startObject().field("test", "value beck").field("num1", 1.0f).endObject()) - .execute().actionGet(); - client.admin().indices().prepareFlush().execute().actionGet(); - client.prepareIndex("test", "type1", "2") - .setSource(jsonBuilder().startObject().field("test", "value beck").field("num1", 2.0f).endObject()) - .execute().actionGet(); - client.admin().indices().prepareFlush().execute().actionGet(); - client.prepareIndex("test", "type1", "3") - .setSource(jsonBuilder().startObject().field("test", "value beck").field("num1", 3.0f).endObject()) - .execute().actionGet(); - client.admin().indices().refresh(refreshRequest()).actionGet(); - - logger.info("running doc['num1'].value > 1"); - SearchResponse response = client.prepareSearch() - .setQuery(filteredQuery(matchAllQuery(), scriptFilter("doc['num1'].value > 1").lang("python"))) - .addSort("num1", SortOrder.ASC) - .addScriptField("sNum1", "python", "doc['num1'].value", null) - .execute().actionGet(); - - assertThat(response.hits().totalHits(), equalTo(2l)); - assertThat(response.hits().getAt(0).id(), equalTo("2")); - assertThat((Double) response.hits().getAt(0).fields().get("sNum1").values().get(0), equalTo(2.0)); - assertThat(response.hits().getAt(1).id(), equalTo("3")); - assertThat((Double) response.hits().getAt(1).fields().get("sNum1").values().get(0), equalTo(3.0)); - - logger.info("running doc['num1'].value > param1"); - response = client.prepareSearch() - .setQuery(filteredQuery(matchAllQuery(), scriptFilter("doc['num1'].value > param1").lang("python").addParam("param1", 2))) - .addSort("num1", SortOrder.ASC) - .addScriptField("sNum1", "python", "doc['num1'].value", null) - .execute().actionGet(); - - assertThat(response.hits().totalHits(), equalTo(1l)); - assertThat(response.hits().getAt(0).id(), equalTo("3")); - assertThat((Double) response.hits().getAt(0).fields().get("sNum1").values().get(0), equalTo(3.0)); - - logger.info("running doc['num1'].value > param1"); - response = client.prepareSearch() - .setQuery(filteredQuery(matchAllQuery(), scriptFilter("doc['num1'].value > param1").lang("python").addParam("param1", -1))) - .addSort("num1", SortOrder.ASC) - .addScriptField("sNum1", "python", "doc['num1'].value", null) - .execute().actionGet(); - - assertThat(response.hits().totalHits(), equalTo(3l)); - assertThat(response.hits().getAt(0).id(), equalTo("1")); - assertThat((Double) response.hits().getAt(0).fields().get("sNum1").values().get(0), equalTo(1.0)); - assertThat(response.hits().getAt(1).id(), equalTo("2")); - assertThat((Double) response.hits().getAt(1).fields().get("sNum1").values().get(0), equalTo(2.0)); - assertThat(response.hits().getAt(2).id(), equalTo("3")); - assertThat((Double) response.hits().getAt(2).fields().get("sNum1").values().get(0), equalTo(3.0)); - } - - @Test public void testScriptFieldUsingSource() throws Exception { - client.admin().indices().prepareCreate("test").execute().actionGet(); - client.prepareIndex("test", "type1", "1") - .setSource(jsonBuilder().startObject() - .startObject("obj1").field("test", "something").endObject() - .startObject("obj2").startArray("arr2").value("arr_value1").value("arr_value2").endArray().endObject() - .endObject()) - .execute().actionGet(); - client.admin().indices().refresh(refreshRequest()).actionGet(); - - SearchResponse response = client.prepareSearch() - .setQuery(matchAllQuery()) - .addField("_source.obj1") // we also automatically detect _source in fields - .addScriptField("s_obj1", "python", "_source['obj1']", null) - .addScriptField("s_obj1_test", "python", "_source['obj1']['test']", null) - .addScriptField("s_obj2", "python", "_source['obj2']", null) - .addScriptField("s_obj2_arr2", "python", "_source['obj2']['arr2']", null) - .execute().actionGet(); - - Map sObj1 = (Map) response.hits().getAt(0).field("_source.obj1").value(); - assertThat(sObj1.get("test").toString(), equalTo("something")); - assertThat(response.hits().getAt(0).field("s_obj1_test").value().toString(), equalTo("something")); - - sObj1 = (Map) response.hits().getAt(0).field("s_obj1").value(); - assertThat(sObj1.get("test").toString(), equalTo("something")); - assertThat(response.hits().getAt(0).field("s_obj1_test").value().toString(), equalTo("something")); - - Map sObj2 = (Map) response.hits().getAt(0).field("s_obj2").value(); - List sObj2Arr2 = (List) sObj2.get("arr2"); - assertThat(sObj2Arr2.size(), equalTo(2)); - assertThat(sObj2Arr2.get(0).toString(), equalTo("arr_value1")); - assertThat(sObj2Arr2.get(1).toString(), equalTo("arr_value2")); - - sObj2Arr2 = (List) response.hits().getAt(0).field("s_obj2_arr2").value(); - assertThat(sObj2Arr2.size(), equalTo(2)); - assertThat(sObj2Arr2.get(0).toString(), equalTo("arr_value1")); - assertThat(sObj2Arr2.get(1).toString(), equalTo("arr_value2")); - } - - @Test public void testCustomScriptBoost() throws Exception { - // execute a search before we create an index - try { - client.prepareSearch().setQuery(termQuery("test", "value")).execute().actionGet(); - assert false : "should fail"; - } catch (Exception e) { - // ignore, no indices - } - - try { - client.prepareSearch("test").setQuery(termQuery("test", "value")).execute().actionGet(); - assert false : "should fail"; - } catch (Exception e) { - // ignore, no indices - } - - client.admin().indices().create(createIndexRequest("test")).actionGet(); - client.index(indexRequest("test").type("type1").id("1") - .source(jsonBuilder().startObject().field("test", "value beck").field("num1", 1.0f).endObject())).actionGet(); - client.index(indexRequest("test").type("type1").id("2") - .source(jsonBuilder().startObject().field("test", "value check").field("num1", 2.0f).endObject())).actionGet(); - client.admin().indices().refresh(refreshRequest()).actionGet(); - - logger.info("--- QUERY_THEN_FETCH"); - - logger.info("running doc['num1'].value"); - SearchResponse response = client.search(searchRequest() - .searchType(SearchType.QUERY_THEN_FETCH) - .source(searchSource().explain(true).query(customScoreQuery(termQuery("test", "value")).script("doc['num1'].value").lang("python"))) - ).actionGet(); - - assertThat("Failures " + Arrays.toString(response.shardFailures()), response.shardFailures().length, equalTo(0)); - - assertThat(response.hits().totalHits(), equalTo(2l)); - logger.info("Hit[0] {} Explanation {}", response.hits().getAt(0).id(), response.hits().getAt(0).explanation()); - logger.info("Hit[1] {} Explanation {}", response.hits().getAt(1).id(), response.hits().getAt(1).explanation()); - assertThat(response.hits().getAt(0).id(), equalTo("2")); - assertThat(response.hits().getAt(1).id(), equalTo("1")); - - logger.info("running -doc['num1'].value"); - response = client.search(searchRequest() - .searchType(SearchType.QUERY_THEN_FETCH) - .source(searchSource().explain(true).query(customScoreQuery(termQuery("test", "value")).script("-doc['num1'].value").lang("python"))) - ).actionGet(); - - assertThat("Failures " + Arrays.toString(response.shardFailures()), response.shardFailures().length, equalTo(0)); - - assertThat(response.hits().totalHits(), equalTo(2l)); - logger.info("Hit[0] {} Explanation {}", response.hits().getAt(0).id(), response.hits().getAt(0).explanation()); - logger.info("Hit[1] {} Explanation {}", response.hits().getAt(1).id(), response.hits().getAt(1).explanation()); - assertThat(response.hits().getAt(0).id(), equalTo("1")); - assertThat(response.hits().getAt(1).id(), equalTo("2")); - - - logger.info("running doc['num1'].value * _score"); - response = client.search(searchRequest() - .searchType(SearchType.QUERY_THEN_FETCH) - .source(searchSource().explain(true).query(customScoreQuery(termQuery("test", "value")).script("doc['num1'].value * _score").lang("python"))) - ).actionGet(); - - assertThat("Failures " + Arrays.toString(response.shardFailures()), response.shardFailures().length, equalTo(0)); - - assertThat(response.hits().totalHits(), equalTo(2l)); - logger.info("Hit[0] {} Explanation {}", response.hits().getAt(0).id(), response.hits().getAt(0).explanation()); - logger.info("Hit[1] {} Explanation {}", response.hits().getAt(1).id(), response.hits().getAt(1).explanation()); - assertThat(response.hits().getAt(0).id(), equalTo("2")); - assertThat(response.hits().getAt(1).id(), equalTo("1")); - - logger.info("running param1 * param2 * _score"); - response = client.search(searchRequest() - .searchType(SearchType.QUERY_THEN_FETCH) - .source(searchSource().explain(true).query(customScoreQuery(termQuery("test", "value")).script("param1 * param2 * _score").param("param1", 2).param("param2", 2).lang("python"))) - ).actionGet(); - - assertThat("Failures " + Arrays.toString(response.shardFailures()), response.shardFailures().length, equalTo(0)); - - assertThat(response.hits().totalHits(), equalTo(2l)); - logger.info("Hit[0] {} Explanation {}", response.hits().getAt(0).id(), response.hits().getAt(0).explanation()); - logger.info("Hit[1] {} Explanation {}", response.hits().getAt(1).id(), response.hits().getAt(1).explanation()); - } -} diff --git a/plugins/lang/python/src/test/java/org/elasticsearch/script/python/SimpleBench.java b/plugins/lang/python/src/test/java/org/elasticsearch/script/python/SimpleBench.java deleted file mode 100644 index 0273d9a4583..00000000000 --- a/plugins/lang/python/src/test/java/org/elasticsearch/script/python/SimpleBench.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.script.python; - -import org.elasticsearch.common.StopWatch; -import org.elasticsearch.common.settings.ImmutableSettings; -import org.elasticsearch.script.ExecutableScript; - -import java.util.HashMap; -import java.util.Map; - -/** - * @author kimchy (shay.banon) - */ -public class SimpleBench { - - public static void main(String[] args) { - PythonScriptEngineService se = new PythonScriptEngineService(ImmutableSettings.Builder.EMPTY_SETTINGS); - Object compiled = se.compile("x + y"); - - Map vars = new HashMap(); - // warm up - for (int i = 0; i < 1000; i++) { - vars.put("x", i); - vars.put("y", i + 1); - se.execute(compiled, vars); - } - - final long ITER = 100000; - - StopWatch stopWatch = new StopWatch().start(); - for (long i = 0; i < ITER; i++) { - se.execute(compiled, vars); - } - System.out.println("Execute Took: " + stopWatch.stop().lastTaskTime()); - - stopWatch = new StopWatch().start(); - ExecutableScript executableScript = se.executable(compiled, vars); - for (long i = 0; i < ITER; i++) { - executableScript.run(); - } - System.out.println("Executable Took: " + stopWatch.stop().lastTaskTime()); - - stopWatch = new StopWatch().start(); - executableScript = se.executable(compiled, vars); - for (long i = 0; i < ITER; i++) { - for (Map.Entry entry : vars.entrySet()) { - executableScript.setNextVar(entry.getKey(), entry.getValue()); - } - executableScript.run(); - } - System.out.println("Executable (vars) Took: " + stopWatch.stop().lastTaskTime()); - } -} diff --git a/plugins/mapper/attachments/build.gradle b/plugins/mapper/attachments/build.gradle deleted file mode 100644 index 6b565214132..00000000000 --- a/plugins/mapper/attachments/build.gradle +++ /dev/null @@ -1,132 +0,0 @@ -dependsOn(':elasticsearch') - -apply plugin: 'java' -apply plugin: 'maven' -apply plugin: 'eclipse' - -archivesBaseName = "elasticsearch-mapper-attachments" - -explodedDistDir = new File(distsDir, 'exploded') - -configurations.compile.transitive = true -configurations.testCompile.transitive = true - -// no need to use the resource dir -sourceSets.main.resources.srcDirs 'src/main/java' -sourceSets.test.resources.srcDirs 'src/test/java' - -jar { -// from sourceSets.main.allJava - manifest { - attributes("Implementation-Title": "ElasticSearch", "Implementation-Version": rootProject.version, "Implementation-Date": buildTimeStr) - } -} - -configurations { - dists - distLib { - visible = false - transitive = false - } -} - -dependencies { - compile project(':elasticsearch') - - compile('org.apache.tika:tika-app:0.10') { transitive = false } - distLib('org.apache.tika:tika-app:0.10') { transitive = false } -} - -task explodedDist(dependsOn: [jar], description: 'Builds the plugin zip file') << { - [explodedDistDir]*.mkdirs() - - copy { - from configurations.distLib - into explodedDistDir - } - - // remove elasticsearch files (compile above adds the elasticsearch one) - ant.delete { fileset(dir: explodedDistDir, includes: "elasticsearch-*.jar") } - - copy { - from libsDir - into explodedDistDir - } - - ant.delete { fileset(dir: explodedDistDir, includes: "elasticsearch-*-javadoc.jar") } - ant.delete { fileset(dir: explodedDistDir, includes: "elasticsearch-*-sources.jar") } -} - -task zip(type: Zip, dependsOn: ['explodedDist']) { - from(explodedDistDir) { - } -} - -task release(dependsOn: [zip]) << { - ant.delete(dir: explodedDistDir) - copy { - from distsDir - into(new File(rootProject.distsDir, "plugins")) - } -} - -configurations { - deployerJars -} - -dependencies { - deployerJars "org.apache.maven.wagon:wagon-http:1.0-beta-2" -} - -task sourcesJar(type: Jar, dependsOn: classes) { - classifier = 'sources' - from sourceSets.main.allSource -} - -task javadocJar(type: Jar, dependsOn: javadoc) { - classifier = 'javadoc' - from javadoc.destinationDir -} - -artifacts { - archives sourcesJar - archives javadocJar -} - -uploadArchives { - repositories.mavenDeployer { - configuration = configurations.deployerJars - repository(url: rootProject.mavenRepoUrl) { - authentication(userName: rootProject.mavenRepoUser, password: rootProject.mavenRepoPass) - } - snapshotRepository(url: rootProject.mavenSnapshotRepoUrl) { - authentication(userName: rootProject.mavenRepoUser, password: rootProject.mavenRepoPass) - } - - pom.project { - inceptionYear '2009' - name 'elasticsearch-plugins-mapper-attachments' - description 'Attachments Plugin for ElasticSearch' - licenses { - license { - name 'The Apache Software License, Version 2.0' - url 'http://www.apache.org/licenses/LICENSE-2.0.txt' - distribution 'repo' - } - } - scm { - connection 'git://github.com/elasticsearch/elasticsearch.git' - developerConnection 'git@github.com:elasticsearch/elasticsearch.git' - url 'http://github.com/elasticsearch/elasticsearch' - } - } - - pom.whenConfigured {pom -> - pom.dependencies = pom.dependencies.findAll {dep -> dep.scope != 'test' } // removes the test scoped ones - } - } -} - -eclipseClasspath { - defaultOutputDir = file('build/eclipse-build') -} \ No newline at end of file diff --git a/plugins/mapper/attachments/src/main/java/es-plugin.properties b/plugins/mapper/attachments/src/main/java/es-plugin.properties deleted file mode 100644 index 08c6c9331d4..00000000000 --- a/plugins/mapper/attachments/src/main/java/es-plugin.properties +++ /dev/null @@ -1 +0,0 @@ -plugin=org.elasticsearch.plugin.mapper.attachments.MapperAttachmentsPlugin diff --git a/plugins/mapper/attachments/src/main/java/org/elasticsearch/index/mapper/attachment/AttachmentMapper.java b/plugins/mapper/attachments/src/main/java/org/elasticsearch/index/mapper/attachment/AttachmentMapper.java deleted file mode 100644 index 9836e39a09d..00000000000 --- a/plugins/mapper/attachments/src/main/java/org/elasticsearch/index/mapper/attachment/AttachmentMapper.java +++ /dev/null @@ -1,341 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.index.mapper.attachment; - -import org.apache.tika.exception.TikaException; -import org.apache.tika.metadata.Metadata; -import org.elasticsearch.common.io.FastByteArrayInputStream; -import org.elasticsearch.common.netty.util.internal.SystemPropertyUtil; -import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.index.mapper.ContentPath; -import org.elasticsearch.index.mapper.FieldMapperListener; -import org.elasticsearch.index.mapper.Mapper; -import org.elasticsearch.index.mapper.MapperParsingException; -import org.elasticsearch.index.mapper.MergeContext; -import org.elasticsearch.index.mapper.MergeMappingException; -import org.elasticsearch.index.mapper.ObjectMapperListener; -import org.elasticsearch.index.mapper.ParseContext; -import org.elasticsearch.index.mapper.core.DateFieldMapper; -import org.elasticsearch.index.mapper.core.StringFieldMapper; - -import java.io.IOException; -import java.util.Map; - -import static org.elasticsearch.index.mapper.MapperBuilders.*; -import static org.elasticsearch.index.mapper.core.TypeParsers.*; -import static org.elasticsearch.plugin.mapper.attachments.tika.TikaInstance.*; - -/** - *

- *      field1 : "..."
- * 
- *

Or: - *

- * {
- *      file1 : {
- *          _content_type : "application/pdf",
- *          _name : "..../something.pdf",
- *          content : ""
- *      }
- * }
- * 
- * - * @author kimchy (shay.banon) - */ -public class AttachmentMapper implements Mapper { - - public static final String CONTENT_TYPE = "attachment"; - - public static class Defaults { - public static final ContentPath.Type PATH_TYPE = ContentPath.Type.FULL; - } - - public static class Builder extends Mapper.Builder { - - private ContentPath.Type pathType = Defaults.PATH_TYPE; - - private StringFieldMapper.Builder contentBuilder; - - private StringFieldMapper.Builder titleBuilder = stringField("title"); - - private StringFieldMapper.Builder authorBuilder = stringField("author"); - - private StringFieldMapper.Builder keywordsBuilder = stringField("keywords"); - - private DateFieldMapper.Builder dateBuilder = dateField("date"); - - private StringFieldMapper.Builder contentTypeBuilder = stringField("content_type"); - - public Builder(String name) { - super(name); - this.builder = this; - this.contentBuilder = stringField(name); - } - - public Builder pathType(ContentPath.Type pathType) { - this.pathType = pathType; - return this; - } - - public Builder content(StringFieldMapper.Builder content) { - this.contentBuilder = content; - return this; - } - - public Builder date(DateFieldMapper.Builder date) { - this.dateBuilder = date; - return this; - } - - public Builder author(StringFieldMapper.Builder author) { - this.authorBuilder = author; - return this; - } - - public Builder title(StringFieldMapper.Builder title) { - this.titleBuilder = title; - return this; - } - - public Builder keywords(StringFieldMapper.Builder keywords) { - this.keywordsBuilder = keywords; - return this; - } - - public Builder contentType(StringFieldMapper.Builder contentType) { - this.contentTypeBuilder = contentType; - return this; - } - - @Override public AttachmentMapper build(BuilderContext context) { - ContentPath.Type origPathType = context.path().pathType(); - context.path().pathType(pathType); - - // create the content mapper under the actual name - StringFieldMapper contentMapper = contentBuilder.build(context); - - // create the DC one under the name - context.path().add(name); - DateFieldMapper dateMapper = dateBuilder.build(context); - StringFieldMapper authorMapper = authorBuilder.build(context); - StringFieldMapper titleMapper = titleBuilder.build(context); - StringFieldMapper keywordsMapper = keywordsBuilder.build(context); - StringFieldMapper contentTypeMapper = contentTypeBuilder.build(context); - context.path().remove(); - - context.path().pathType(origPathType); - - return new AttachmentMapper(name, pathType, contentMapper, dateMapper, titleMapper, authorMapper, keywordsMapper, contentTypeMapper); - } - } - - /** - *
-     *  field1 : { type : "attachment" }
-     * 
- * Or: - *
-     *  field1 : {
-     *      type : "attachment",
-     *      fields : {
-     *          field1 : {type : "binary"},
-     *          title : {store : "yes"},
-     *          date : {store : "yes"}
-     *      }
-     * }
-     * 
- * - * @author kimchy (shay.banon) - */ - public static class TypeParser implements Mapper.TypeParser { - - @SuppressWarnings({"unchecked"}) @Override public Mapper.Builder parse(String name, Map node, ParserContext parserContext) throws MapperParsingException { - AttachmentMapper.Builder builder = new AttachmentMapper.Builder(name); - - for (Map.Entry entry : node.entrySet()) { - String fieldName = entry.getKey(); - Object fieldNode = entry.getValue(); - if (fieldName.equals("path")) { - builder.pathType(parsePathType(name, fieldNode.toString())); - } else if (fieldName.equals("fields")) { - Map fieldsNode = (Map) fieldNode; - for (Map.Entry entry1 : fieldsNode.entrySet()) { - String propName = entry1.getKey(); - Object propNode = entry1.getValue(); - - if (name.equals(propName)) { - // that is the content - builder.content((StringFieldMapper.Builder) parserContext.typeParser("string").parse(name, (Map) propNode, parserContext)); - } else if ("date".equals(propName)) { - builder.date((DateFieldMapper.Builder) parserContext.typeParser("date").parse("date", (Map) propNode, parserContext)); - } else if ("title".equals(propName)) { - builder.title((StringFieldMapper.Builder) parserContext.typeParser("string").parse("title", (Map) propNode, parserContext)); - } else if ("author".equals(propName)) { - builder.author((StringFieldMapper.Builder) parserContext.typeParser("string").parse("author", (Map) propNode, parserContext)); - } else if ("keywords".equals(propName)) { - builder.keywords((StringFieldMapper.Builder) parserContext.typeParser("string").parse("keywords", (Map) propNode, parserContext)); - } else if ("content_type".equals(propName)) { - builder.contentType((StringFieldMapper.Builder) parserContext.typeParser("string").parse("content_type", (Map) propNode, parserContext)); - } - } - } - } - - return builder; - } - } - - private final String name; - - private final ContentPath.Type pathType; - - private final StringFieldMapper contentMapper; - - private final DateFieldMapper dateMapper; - - private final StringFieldMapper authorMapper; - - private final StringFieldMapper titleMapper; - - private final StringFieldMapper keywordsMapper; - - private final StringFieldMapper contentTypeMapper; - - public AttachmentMapper(String name, ContentPath.Type pathType, StringFieldMapper contentMapper, - DateFieldMapper dateMapper, StringFieldMapper titleMapper, StringFieldMapper authorMapper, - StringFieldMapper keywordsMapper, StringFieldMapper contentTypeMapper) { - this.name = name; - this.pathType = pathType; - this.contentMapper = contentMapper; - this.dateMapper = dateMapper; - this.titleMapper = titleMapper; - this.authorMapper = authorMapper; - this.keywordsMapper = keywordsMapper; - this.contentTypeMapper = contentTypeMapper; - } - - @Override public String name() { - return name; - } - - @Override public void parse(ParseContext context) throws IOException { - byte[] content = null; - String contentType = null; - String name = null; - - XContentParser parser = context.parser(); - XContentParser.Token token = parser.currentToken(); - if (token == XContentParser.Token.VALUE_STRING) { - content = parser.binaryValue(); - } else { - String currentFieldName = null; - while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { - if (token == XContentParser.Token.FIELD_NAME) { - currentFieldName = parser.currentName(); - } else if (token == XContentParser.Token.VALUE_STRING) { - if ("content".equals(currentFieldName)) { - content = parser.binaryValue(); - } else if ("_content_type".equals(currentFieldName)) { - contentType = parser.text(); - } else if ("_name".equals(currentFieldName)) { - name = parser.text(); - } - } - } - } - - Metadata metadata = new Metadata(); - if (contentType != null) { - metadata.add(Metadata.CONTENT_TYPE, contentType); - } - if (name != null) { - metadata.add(Metadata.RESOURCE_NAME_KEY, name); - } - - String parsedContent; - try { - parsedContent = tika().parseToString(new FastByteArrayInputStream(content), metadata); - } catch (TikaException e) { - throw new MapperParsingException("Failed to extract text for [" + name + "]", e); - } - - context.externalValue(parsedContent); - contentMapper.parse(context); - - context.externalValue(metadata.get(Metadata.DATE)); - dateMapper.parse(context); - - context.externalValue(metadata.get(Metadata.TITLE)); - titleMapper.parse(context); - - context.externalValue(metadata.get(Metadata.AUTHOR)); - authorMapper.parse(context); - - context.externalValue(metadata.get(Metadata.KEYWORDS)); - keywordsMapper.parse(context); - - context.externalValue(metadata.get(Metadata.CONTENT_TYPE)); - contentTypeMapper.parse(context); - } - - @Override public void merge(Mapper mergeWith, MergeContext mergeContext) throws MergeMappingException { - // ignore this for now - } - - @Override public void traverse(FieldMapperListener fieldMapperListener) { - contentMapper.traverse(fieldMapperListener); - dateMapper.traverse(fieldMapperListener); - titleMapper.traverse(fieldMapperListener); - authorMapper.traverse(fieldMapperListener); - keywordsMapper.traverse(fieldMapperListener); - contentTypeMapper.traverse(fieldMapperListener); - } - - @Override public void traverse(ObjectMapperListener objectMapperListener) { - } - - @Override public void close() { - contentMapper.close(); - dateMapper.close(); - titleMapper.close(); - authorMapper.close(); - keywordsMapper.close(); - contentTypeMapper.close(); - } - - @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - builder.startObject(name); - builder.field("type", CONTENT_TYPE); - builder.field("path", pathType.name().toLowerCase()); - - builder.startObject("fields"); - contentMapper.toXContent(builder, params); - authorMapper.toXContent(builder, params); - titleMapper.toXContent(builder, params); - dateMapper.toXContent(builder, params); - keywordsMapper.toXContent(builder, params); - contentTypeMapper.toXContent(builder, params); - builder.endObject(); - - builder.endObject(); - return builder; - } -} diff --git a/plugins/mapper/attachments/src/main/java/org/elasticsearch/index/mapper/attachment/RegisterAttachmentType.java b/plugins/mapper/attachments/src/main/java/org/elasticsearch/index/mapper/attachment/RegisterAttachmentType.java deleted file mode 100644 index 2798a73fafe..00000000000 --- a/plugins/mapper/attachments/src/main/java/org/elasticsearch/index/mapper/attachment/RegisterAttachmentType.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.index.mapper.attachment; - -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.AbstractIndexComponent; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.mapper.MapperService; -import org.elasticsearch.index.settings.IndexSettings; - -/** - * @author kimchy (shay.banon) - */ -public class RegisterAttachmentType extends AbstractIndexComponent { - - @Inject public RegisterAttachmentType(Index index, @IndexSettings Settings indexSettings, MapperService mapperService) { - super(index, indexSettings); - - mapperService.documentMapperParser().putTypeParser("attachment", new AttachmentMapper.TypeParser()); - } -} diff --git a/plugins/mapper/attachments/src/main/java/org/elasticsearch/plugin/mapper/attachments/AttachmentsIndexModule.java b/plugins/mapper/attachments/src/main/java/org/elasticsearch/plugin/mapper/attachments/AttachmentsIndexModule.java deleted file mode 100644 index 7bdc3a80dff..00000000000 --- a/plugins/mapper/attachments/src/main/java/org/elasticsearch/plugin/mapper/attachments/AttachmentsIndexModule.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.plugin.mapper.attachments; - -import org.elasticsearch.common.inject.AbstractModule; -import org.elasticsearch.index.mapper.attachment.RegisterAttachmentType; - -/** - * @author kimchy (shay.banon) - */ -public class AttachmentsIndexModule extends AbstractModule { - - @Override protected void configure() { - bind(RegisterAttachmentType.class).asEagerSingleton(); - } -} diff --git a/plugins/mapper/attachments/src/main/java/org/elasticsearch/plugin/mapper/attachments/MapperAttachmentsPlugin.java b/plugins/mapper/attachments/src/main/java/org/elasticsearch/plugin/mapper/attachments/MapperAttachmentsPlugin.java deleted file mode 100644 index 8244cc4bd0b..00000000000 --- a/plugins/mapper/attachments/src/main/java/org/elasticsearch/plugin/mapper/attachments/MapperAttachmentsPlugin.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.plugin.mapper.attachments; - -import org.elasticsearch.common.inject.Module; -import org.elasticsearch.plugins.AbstractPlugin; - -import java.util.Collection; - -import static org.elasticsearch.common.collect.Lists.*; - -/** - * @author kimchy (shay.banon) - */ -public class MapperAttachmentsPlugin extends AbstractPlugin { - - @Override public String name() { - return "mapper-attachments"; - } - - @Override public String description() { - return "Adds the attachment type allowing to parse difference attachment formats"; - } - - @Override public Collection> indexModules() { - Collection> modules = newArrayList(); - modules.add(AttachmentsIndexModule.class); - return modules; - } -} diff --git a/plugins/mapper/attachments/src/main/java/org/elasticsearch/plugin/mapper/attachments/tika/TikaInstance.java b/plugins/mapper/attachments/src/main/java/org/elasticsearch/plugin/mapper/attachments/tika/TikaInstance.java deleted file mode 100644 index a5bcc0b931c..00000000000 --- a/plugins/mapper/attachments/src/main/java/org/elasticsearch/plugin/mapper/attachments/tika/TikaInstance.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.plugin.mapper.attachments.tika; - -import org.apache.tika.Tika; - -/** - * @author kimchy (shay.banon) - */ -public class TikaInstance { - - private static final Tika tika = new Tika(); - - public static Tika tika() { - return tika; - } -} diff --git a/plugins/mapper/attachments/src/test/java/org/elasticsearch/index/mapper/xcontent/SimpleAttachmentMapperTests.java b/plugins/mapper/attachments/src/test/java/org/elasticsearch/index/mapper/xcontent/SimpleAttachmentMapperTests.java deleted file mode 100644 index f646673e5e5..00000000000 --- a/plugins/mapper/attachments/src/test/java/org/elasticsearch/index/mapper/xcontent/SimpleAttachmentMapperTests.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.index.mapper.xcontent; - -import org.apache.lucene.document.Document; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.analysis.AnalysisService; -import org.elasticsearch.index.mapper.DocumentMapper; -import org.elasticsearch.index.mapper.DocumentMapperParser; -import org.elasticsearch.index.mapper.attachment.AttachmentMapper; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import static org.elasticsearch.common.io.Streams.*; -import static org.elasticsearch.common.xcontent.XContentFactory.*; -import static org.hamcrest.MatcherAssert.*; -import static org.hamcrest.Matchers.*; - -/** - * @author kimchy (shay.banon) - */ -@Test -public class SimpleAttachmentMapperTests { - - private DocumentMapperParser mapperParser; - - @BeforeClass public void setupMapperParser() { - mapperParser = new DocumentMapperParser(new Index("test"), new AnalysisService(new Index("test"))); - mapperParser.putTypeParser(AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser()); - } - - @Test public void testSimpleMappings() throws Exception { - String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/xcontent/test-mapping.json"); - DocumentMapper docMapper = mapperParser.parse(mapping); - byte[] html = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/xcontent/testXHTML.html"); - - byte[] json = jsonBuilder().startObject().field("_id", 1).field("file", html).endObject().copiedBytes(); - - Document doc = docMapper.parse(json).rootDoc(); - - assertThat(doc.get(docMapper.mappers().smartName("file.content_type").mapper().names().indexName()), equalTo("application/xhtml+xml")); - assertThat(doc.get(docMapper.mappers().smartName("file.title").mapper().names().indexName()), equalTo("XHTML test document")); - assertThat(doc.get(docMapper.mappers().smartName("file").mapper().names().indexName()), containsString("This document tests the ability of Apache Tika to extract content")); - - // re-parse it - String builtMapping = docMapper.mappingSource().string(); - docMapper = mapperParser.parse(builtMapping); - - json = jsonBuilder().startObject().field("_id", 1).field("file", html).endObject().copiedBytes(); - - doc = docMapper.parse(json).rootDoc(); - - assertThat(doc.get(docMapper.mappers().smartName("file.content_type").mapper().names().indexName()), equalTo("application/xhtml+xml")); - assertThat(doc.get(docMapper.mappers().smartName("file.title").mapper().names().indexName()), equalTo("XHTML test document")); - assertThat(doc.get(docMapper.mappers().smartName("file").mapper().names().indexName()), containsString("This document tests the ability of Apache Tika to extract content")); - } -} diff --git a/plugins/mapper/attachments/src/test/java/org/elasticsearch/index/mapper/xcontent/test-mapping.json b/plugins/mapper/attachments/src/test/java/org/elasticsearch/index/mapper/xcontent/test-mapping.json deleted file mode 100644 index 7194967ea55..00000000000 --- a/plugins/mapper/attachments/src/test/java/org/elasticsearch/index/mapper/xcontent/test-mapping.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - person : { - properties : { - "file" : { type : "attachment" } - } - } -} \ No newline at end of file diff --git a/plugins/mapper/attachments/src/test/java/org/elasticsearch/index/mapper/xcontent/testXHTML.html b/plugins/mapper/attachments/src/test/java/org/elasticsearch/index/mapper/xcontent/testXHTML.html deleted file mode 100644 index bdccf83ba50..00000000000 --- a/plugins/mapper/attachments/src/test/java/org/elasticsearch/index/mapper/xcontent/testXHTML.html +++ /dev/null @@ -1,29 +0,0 @@ - - - - XHTML test document - - - - -

- This document tests the ability of Apache Tika to extract content - from an XHTML document. -

- - \ No newline at end of file diff --git a/plugins/mapper/attachments/src/test/java/org/elasticsearch/plugin/mapper/attachments/test/SimpleAttachmentIntegrationTests.java b/plugins/mapper/attachments/src/test/java/org/elasticsearch/plugin/mapper/attachments/test/SimpleAttachmentIntegrationTests.java deleted file mode 100644 index 2b217f44fe0..00000000000 --- a/plugins/mapper/attachments/src/test/java/org/elasticsearch/plugin/mapper/attachments/test/SimpleAttachmentIntegrationTests.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.plugin.mapper.attachments.test; - -import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; -import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus; -import org.elasticsearch.action.count.CountResponse; -import org.elasticsearch.common.logging.ESLogger; -import org.elasticsearch.common.logging.Loggers; -import org.elasticsearch.common.network.NetworkUtils; -import org.elasticsearch.node.Node; -import org.testng.annotations.AfterClass; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import static org.elasticsearch.client.Requests.*; -import static org.elasticsearch.common.io.Streams.*; -import static org.elasticsearch.common.settings.ImmutableSettings.*; -import static org.elasticsearch.common.xcontent.XContentFactory.*; -import static org.elasticsearch.index.query.QueryBuilders.*; -import static org.elasticsearch.node.NodeBuilder.*; -import static org.hamcrest.MatcherAssert.*; -import static org.hamcrest.Matchers.*; - -/** - * @author kimchy (shay.banon) - */ -@Test -public class SimpleAttachmentIntegrationTests { - - private final ESLogger logger = Loggers.getLogger(getClass()); - - private Node node; - - @BeforeClass public void setupServer() { - node = nodeBuilder().local(true).settings(settingsBuilder() - .put("cluster.name", "test-cluster-" + NetworkUtils.getLocalAddress()) - .put("gateway.type", "none")).node(); - } - - @AfterClass public void closeServer() { - node.close(); - } - - @BeforeMethod public void createIndex() { - logger.info("creating index [test]"); - node.client().admin().indices().create(createIndexRequest("test").settings(settingsBuilder().put("index.numberOfReplicas", 0))).actionGet(); - logger.info("Running Cluster Health"); - ClusterHealthResponse clusterHealth = node.client().admin().cluster().health(clusterHealthRequest().waitForGreenStatus()).actionGet(); - logger.info("Done Cluster Health, status " + clusterHealth.status()); - assertThat(clusterHealth.timedOut(), equalTo(false)); - assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.GREEN)); - } - - @AfterMethod public void deleteIndex() { - logger.info("deleting index [test]"); - node.client().admin().indices().delete(deleteIndexRequest("test")).actionGet(); - } - - @Test public void testSimpleAttachment() throws Exception { - String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/xcontent/test-mapping.json"); - byte[] html = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/xcontent/testXHTML.html"); - - node.client().admin().indices().putMapping(putMappingRequest("test").type("person").source(mapping)).actionGet(); - - node.client().index(indexRequest("test").type("person") - .source(jsonBuilder().startObject().field("file", html).endObject())).actionGet(); - node.client().admin().indices().refresh(refreshRequest()).actionGet(); - - CountResponse countResponse = node.client().count(countRequest("test").query(fieldQuery("file.title", "test document"))).actionGet(); - assertThat(countResponse.count(), equalTo(1l)); - - countResponse = node.client().count(countRequest("test").query(fieldQuery("file", "tests the ability"))).actionGet(); - assertThat(countResponse.count(), equalTo(1l)); - } -} \ No newline at end of file diff --git a/plugins/river/couchdb/.gitignore b/plugins/river/couchdb/.gitignore deleted file mode 100644 index 3af0ccb687b..00000000000 --- a/plugins/river/couchdb/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/data diff --git a/plugins/river/couchdb/build.gradle b/plugins/river/couchdb/build.gradle deleted file mode 100644 index c66111926d3..00000000000 --- a/plugins/river/couchdb/build.gradle +++ /dev/null @@ -1,129 +0,0 @@ -dependsOn(':elasticsearch') - -apply plugin: 'java' -apply plugin: 'maven' -apply plugin: 'eclipse' - -archivesBaseName = "elasticsearch-river-couchdb" - -explodedDistDir = new File(distsDir, 'exploded') - -manifest.mainAttributes("Implementation-Title": "ElasticSearch::Plugins::River::CouchDB", "Implementation-Version": rootProject.version, "Implementation-Date": buildTimeStr) - -configurations.compile.transitive = true -configurations.testCompile.transitive = true - -// no need to use the resource dir -sourceSets.main.resources.srcDirs 'src/main/java' -sourceSets.test.resources.srcDirs 'src/test/java' - -// add the source files to the dist jar -//jar { -// from sourceSets.main.allJava -//} - -configurations { - dists - distLib { - visible = false - transitive = false - } -} - -dependencies { - compile project(':elasticsearch') -} - -task explodedDist(dependsOn: [jar], description: 'Builds the plugin zip file') << { - [explodedDistDir]*.mkdirs() - - copy { - from configurations.distLib - into explodedDistDir - } - - // remove elasticsearch files (compile above adds the elasticsearch one) - ant.delete { fileset(dir: explodedDistDir, includes: "elasticsearch-*.jar") } - - copy { - from libsDir - into explodedDistDir - } - - ant.delete { fileset(dir: explodedDistDir, includes: "elasticsearch-*-javadoc.jar") } - ant.delete { fileset(dir: explodedDistDir, includes: "elasticsearch-*-sources.jar") } -} - -task zip(type: Zip, dependsOn: ['explodedDist']) { - from(explodedDistDir) { - } -} - -task release(dependsOn: [zip]) << { - ant.delete(dir: explodedDistDir) - copy { - from distsDir - into(new File(rootProject.distsDir, "plugins")) - } -} - -configurations { - deployerJars -} - -dependencies { - deployerJars "org.apache.maven.wagon:wagon-http:1.0-beta-2" -} - -task sourcesJar(type: Jar, dependsOn: classes) { - classifier = 'sources' - from sourceSets.main.allSource -} - -task javadocJar(type: Jar, dependsOn: javadoc) { - classifier = 'javadoc' - from javadoc.destinationDir -} - -artifacts { - archives sourcesJar - archives javadocJar -} - -uploadArchives { - repositories.mavenDeployer { - configuration = configurations.deployerJars - repository(url: rootProject.mavenRepoUrl) { - authentication(userName: rootProject.mavenRepoUser, password: rootProject.mavenRepoPass) - } - snapshotRepository(url: rootProject.mavenSnapshotRepoUrl) { - authentication(userName: rootProject.mavenRepoUser, password: rootProject.mavenRepoPass) - } - - pom.project { - inceptionYear '2009' - name 'elasticsearch-plugins-river-couchdb' - description 'CouchDB River Plugin for ElasticSearch' - licenses { - license { - name 'The Apache Software License, Version 2.0' - url 'http://www.apache.org/licenses/LICENSE-2.0.txt' - distribution 'repo' - } - } - scm { - connection 'git://github.com/elasticsearch/elasticsearch.git' - developerConnection 'git@github.com:elasticsearch/elasticsearch.git' - url 'http://github.com/elasticsearch/elasticsearch' - } - } - - pom.whenConfigured {pom -> - pom.dependencies = pom.dependencies.findAll {dep -> dep.scope != 'test' } // removes the test scoped ones - } - } -} - -eclipseClasspath { - defaultOutputDir = file('build/eclipse-build') -} \ No newline at end of file diff --git a/plugins/river/couchdb/src/main/java/es-plugin.properties b/plugins/river/couchdb/src/main/java/es-plugin.properties deleted file mode 100644 index 7a4c324ac7d..00000000000 --- a/plugins/river/couchdb/src/main/java/es-plugin.properties +++ /dev/null @@ -1,2 +0,0 @@ -plugin=org.elasticsearch.plugin.river.couchdb.CouchdbRiverPlugin - diff --git a/plugins/river/couchdb/src/main/java/org/elasticsearch/plugin/river/couchdb/CouchdbRiverPlugin.java b/plugins/river/couchdb/src/main/java/org/elasticsearch/plugin/river/couchdb/CouchdbRiverPlugin.java deleted file mode 100644 index 55cd13b8fa5..00000000000 --- a/plugins/river/couchdb/src/main/java/org/elasticsearch/plugin/river/couchdb/CouchdbRiverPlugin.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.plugin.river.couchdb; - -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.inject.Module; -import org.elasticsearch.plugins.AbstractPlugin; -import org.elasticsearch.river.RiversModule; -import org.elasticsearch.river.couchdb.CouchdbRiverModule; - -/** - * @author kimchy (shay.banon) - */ -public class CouchdbRiverPlugin extends AbstractPlugin { - - @Inject public CouchdbRiverPlugin() { - } - - @Override public String name() { - return "river-couchdb"; - } - - @Override public String description() { - return "River CouchDB Plugin"; - } - - - @Override public void processModule(Module module) { - if (module instanceof RiversModule) { - ((RiversModule) module).registerRiver("couchdb", CouchdbRiverModule.class); - } - } -} diff --git a/plugins/river/couchdb/src/main/java/org/elasticsearch/river/couchdb/CouchdbRiver.java b/plugins/river/couchdb/src/main/java/org/elasticsearch/river/couchdb/CouchdbRiver.java deleted file mode 100644 index 8b09dd9a1e6..00000000000 --- a/plugins/river/couchdb/src/main/java/org/elasticsearch/river/couchdb/CouchdbRiver.java +++ /dev/null @@ -1,526 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.river.couchdb; - -import org.elasticsearch.ExceptionsHelper; -import org.elasticsearch.action.bulk.BulkResponse; -import org.elasticsearch.action.get.GetResponse; -import org.elasticsearch.client.Client; -import org.elasticsearch.client.action.bulk.BulkRequestBuilder; -import org.elasticsearch.cluster.block.ClusterBlockException; -import org.elasticsearch.common.Base64; -import org.elasticsearch.common.collect.Maps; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.io.Closeables; -import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.common.util.concurrent.EsExecutors; -import org.elasticsearch.common.util.concurrent.jsr166y.LinkedTransferQueue; -import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentFactory; -import org.elasticsearch.common.xcontent.XContentType; -import org.elasticsearch.common.xcontent.support.XContentMapValues; -import org.elasticsearch.indices.IndexAlreadyExistsException; -import org.elasticsearch.river.AbstractRiverComponent; -import org.elasticsearch.river.River; -import org.elasticsearch.river.RiverIndexName; -import org.elasticsearch.river.RiverName; -import org.elasticsearch.river.RiverSettings; -import org.elasticsearch.script.ExecutableScript; -import org.elasticsearch.script.ScriptService; - -import javax.net.ssl.HostnameVerifier; -import javax.net.ssl.HttpsURLConnection; -import javax.net.ssl.SSLSession; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.UnsupportedEncodingException; -import java.net.HttpURLConnection; -import java.net.URL; -import java.net.URLEncoder; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ArrayBlockingQueue; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.TimeUnit; - -import static org.elasticsearch.client.Requests.*; -import static org.elasticsearch.common.xcontent.XContentFactory.*; - -/** - * @author kimchy (shay.banon) - * @author dadoonet (David Pilato) for attachments filter - */ -public class CouchdbRiver extends AbstractRiverComponent implements River { - - private final Client client; - - private final String riverIndexName; - - private final String couchProtocol; - private final String couchHost; - private final int couchPort; - private final String couchDb; - private final String couchFilter; - private final String couchFilterParamsUrl; - private final String basicAuth; - private final boolean noVerify; - private final boolean couchIgnoreAttachments; - - private final String indexName; - private final String typeName; - private final int bulkSize; - private final TimeValue bulkTimeout; - private final int throttleSize; - - private final ExecutableScript script; - - private volatile Thread slurperThread; - private volatile Thread indexerThread; - private volatile boolean closed; - - private final BlockingQueue stream; - - @SuppressWarnings({"unchecked"}) - @Inject public CouchdbRiver(RiverName riverName, RiverSettings settings, @RiverIndexName String riverIndexName, Client client, ScriptService scriptService) { - super(riverName, settings); - this.riverIndexName = riverIndexName; - this.client = client; - - if (settings.settings().containsKey("couchdb")) { - Map couchSettings = (Map) settings.settings().get("couchdb"); - couchProtocol = XContentMapValues.nodeStringValue(couchSettings.get("protocol"), "http"); - noVerify = XContentMapValues.nodeBooleanValue(couchSettings.get("no_verify"), false); - couchHost = XContentMapValues.nodeStringValue(couchSettings.get("host"), "localhost"); - couchPort = XContentMapValues.nodeIntegerValue(couchSettings.get("port"), 5984); - couchDb = XContentMapValues.nodeStringValue(couchSettings.get("db"), riverName.name()); - couchFilter = XContentMapValues.nodeStringValue(couchSettings.get("filter"), null); - if (couchSettings.containsKey("filter_params")) { - Map filterParams = (Map) couchSettings.get("filter_params"); - StringBuilder sb = new StringBuilder(); - for (Map.Entry entry : filterParams.entrySet()) { - try { - sb.append("&").append(URLEncoder.encode(entry.getKey(), "UTF-8")).append("=").append(URLEncoder.encode(entry.getValue().toString(), "UTF-8")); - } catch (UnsupportedEncodingException e) { - // should not happen... - } - } - couchFilterParamsUrl = sb.toString(); - } else { - couchFilterParamsUrl = null; - } - couchIgnoreAttachments = XContentMapValues.nodeBooleanValue(couchSettings.get("ignore_attachments"), false); - if (couchSettings.containsKey("user") && couchSettings.containsKey("password")) { - String user = couchSettings.get("user").toString(); - String password = couchSettings.get("password").toString(); - basicAuth = "Basic " + Base64.encodeBytes((user + ":" + password).getBytes()); - } else { - basicAuth = null; - } - - if (couchSettings.containsKey("script")) { - script = scriptService.executable("js", couchSettings.get("script").toString(), Maps.newHashMap()); - } else { - script = null; - } - } else { - couchProtocol = "http"; - couchHost = "localhost"; - couchPort = 5984; - couchDb = "db"; - couchFilter = null; - couchFilterParamsUrl = null; - couchIgnoreAttachments = false; - noVerify = false; - basicAuth = null; - script = null; - } - - if (settings.settings().containsKey("index")) { - Map indexSettings = (Map) settings.settings().get("index"); - indexName = XContentMapValues.nodeStringValue(indexSettings.get("index"), couchDb); - typeName = XContentMapValues.nodeStringValue(indexSettings.get("type"), couchDb); - bulkSize = XContentMapValues.nodeIntegerValue(indexSettings.get("bulk_size"), 100); - if (indexSettings.containsKey("bulk_timeout")) { - bulkTimeout = TimeValue.parseTimeValue(XContentMapValues.nodeStringValue(indexSettings.get("bulk_timeout"), "10ms"), TimeValue.timeValueMillis(10)); - } else { - bulkTimeout = TimeValue.timeValueMillis(10); - } - throttleSize = XContentMapValues.nodeIntegerValue(indexSettings.get("throttle_size"), bulkSize * 5); - } else { - indexName = couchDb; - typeName = couchDb; - bulkSize = 100; - bulkTimeout = TimeValue.timeValueMillis(10); - throttleSize = bulkSize * 5; - } - if (throttleSize == -1) { - stream = new LinkedTransferQueue(); - } else { - stream = new ArrayBlockingQueue(throttleSize); - } - } - - @Override public void start() { - logger.info("starting couchdb stream: host [{}], port [{}], filter [{}], db [{}], indexing to [{}]/[{}]", couchHost, couchPort, couchFilter, couchDb, indexName, typeName); - try { - client.admin().indices().prepareCreate(indexName).execute().actionGet(); - } catch (Exception e) { - if (ExceptionsHelper.unwrapCause(e) instanceof IndexAlreadyExistsException) { - // that's fine - } else if (ExceptionsHelper.unwrapCause(e) instanceof ClusterBlockException) { - // ok, not recovered yet..., lets start indexing and hope we recover by the first bulk - // TODO: a smarter logic can be to register for cluster event listener here, and only start sampling when the block is removed... - } else { - logger.warn("failed to create index [{}], disabling river...", e, indexName); - return; - } - } - - slurperThread = EsExecutors.daemonThreadFactory(settings.globalSettings(), "couchdb_river_slurper").newThread(new Slurper()); - indexerThread = EsExecutors.daemonThreadFactory(settings.globalSettings(), "couchdb_river_indexer").newThread(new Indexer()); - indexerThread.start(); - slurperThread.start(); - } - - @Override public void close() { - if (closed) { - return; - } - logger.info("closing couchdb stream river"); - slurperThread.interrupt(); - indexerThread.interrupt(); - closed = true; - } - - @SuppressWarnings({"unchecked"}) - private Object processLine(String s, BulkRequestBuilder bulk) { - Map ctx; - try { - ctx = XContentFactory.xContent(XContentType.JSON).createParser(s).mapAndClose(); - } catch (IOException e) { - logger.warn("failed to parse {}", e, s); - return null; - } - if (ctx.containsKey("error")) { - logger.warn("received error {}", s); - return null; - } - Object seq = ctx.get("seq"); - String id = ctx.get("id").toString(); - - // Ignore design documents - if (id.startsWith("_design/")) { - if (logger.isTraceEnabled()) { - logger.trace("ignoring design document {}", id); - } - return seq; - } - - if (script != null) { - script.setNextVar("ctx", ctx); - try { - script.run(); - // we need to unwrap the ctx... - ctx = (Map) script.unwrap(ctx); - } catch (Exception e) { - logger.warn("failed to script process {}, ignoring", e, ctx); - return seq; - } - } - - if (ctx.containsKey("ignore") && ctx.get("ignore").equals(Boolean.TRUE)) { - // ignore dock - } else if (ctx.containsKey("deleted") && ctx.get("deleted").equals(Boolean.TRUE)) { - String index = extractIndex(ctx); - String type = extractType(ctx); - if (logger.isTraceEnabled()) { - logger.trace("processing [delete]: [{}]/[{}]/[{}]", index, type, id); - } - bulk.add(deleteRequest(index).type(type).id(id).routing(extractRouting(ctx)).parent(extractParent(ctx))); - } else if (ctx.containsKey("doc")) { - String index = extractIndex(ctx); - String type = extractType(ctx); - Map doc = (Map) ctx.get("doc"); - - // Remove _attachment from doc if needed - if (couchIgnoreAttachments) { - // no need to log that we removed it, the doc indexed will be shown without it - doc.remove("_attachments"); - } else { - // TODO by now, couchDB river does not really store attachments but only attachments meta infomration - // So we perhaps need to fully support attachments - } - - if (logger.isTraceEnabled()) { - logger.trace("processing [index ]: [{}]/[{}]/[{}], source {}", index, type, id, doc); - } - - bulk.add(indexRequest(index).type(type).id(id).source(doc).routing(extractRouting(ctx)).parent(extractParent(ctx))); - } else { - logger.warn("ignoring unknown change {}", s); - } - return seq; - } - - private String extractParent(Map ctx) { - return (String) ctx.get("_parent"); - } - - private String extractRouting(Map ctx) { - return (String) ctx.get("_routing"); - } - - private String extractType(Map ctx) { - String type = (String) ctx.get("_type"); - if (type == null) { - type = typeName; - } - return type; - } - - private String extractIndex(Map ctx) { - String index = (String) ctx.get("_index"); - if (index == null) { - index = indexName; - } - return index; - } - - private class Indexer implements Runnable { - @Override public void run() { - while (true) { - if (closed) { - return; - } - String s; - try { - s = stream.take(); - } catch (InterruptedException e) { - if (closed) { - return; - } - continue; - } - BulkRequestBuilder bulk = client.prepareBulk(); - Object lastSeq = null; - Object lineSeq = processLine(s, bulk); - if (lineSeq != null) { - lastSeq = lineSeq; - } - - // spin a bit to see if we can get some more changes - try { - while ((s = stream.poll(bulkTimeout.millis(), TimeUnit.MILLISECONDS)) != null) { - lineSeq = processLine(s, bulk); - if (lineSeq != null) { - lastSeq = lineSeq; - } - - if (bulk.numberOfActions() >= bulkSize) { - break; - } - } - } catch (InterruptedException e) { - if (closed) { - return; - } - } - - if (lastSeq != null) { - try { - // we always store it as a string - String lastSeqAsString = null; - if (lastSeq instanceof List) { - // bigcouch uses array for the seq - try { - XContentBuilder builder = XContentFactory.jsonBuilder(); - //builder.startObject(); - builder.startArray(); - for (Object value : ((List) lastSeq)) { - builder.value(value); - } - builder.endArray(); - //builder.endObject(); - lastSeqAsString = builder.string(); - } catch (Exception e) { - logger.error("failed to convert last_seq to a json string", e); - } - } else { - lastSeqAsString = lastSeq.toString(); - } - if (logger.isTraceEnabled()) { - logger.trace("processing [_seq ]: [{}]/[{}]/[{}], last_seq [{}]", riverIndexName, riverName.name(), "_seq", lastSeqAsString); - } - bulk.add(indexRequest(riverIndexName).type(riverName.name()).id("_seq") - .source(jsonBuilder().startObject().startObject("couchdb").field("last_seq", lastSeqAsString).endObject().endObject())); - } catch (IOException e) { - logger.warn("failed to add last_seq entry to bulk indexing"); - } - } - - try { - BulkResponse response = bulk.execute().actionGet(); - if (response.hasFailures()) { - // TODO write to exception queue? - logger.warn("failed to execute" + response.buildFailureMessage()); - } - } catch (Exception e) { - logger.warn("failed to execute bulk", e); - } - } - } - } - - - private class Slurper implements Runnable { - @SuppressWarnings({"unchecked"}) - @Override public void run() { - - while (true) { - if (closed) { - return; - } - - String lastSeq = null; - try { - client.admin().indices().prepareRefresh(riverIndexName).execute().actionGet(); - GetResponse lastSeqGetResponse = client.prepareGet(riverIndexName, riverName().name(), "_seq").execute().actionGet(); - if (lastSeqGetResponse.exists()) { - Map couchdbState = (Map) lastSeqGetResponse.sourceAsMap().get("couchdb"); - if (couchdbState != null) { - lastSeq = couchdbState.get("last_seq").toString(); // we know its always a string - } - } - } catch (Exception e) { - logger.warn("failed to get last_seq, throttling....", e); - try { - Thread.sleep(5000); - continue; - } catch (InterruptedException e1) { - if (closed) { - return; - } - } - } - - String file = "/" + couchDb + "/_changes?feed=continuous&include_docs=true&heartbeat=10000"; - if (couchFilter != null) { - try { - file = file + "&filter=" + URLEncoder.encode(couchFilter, "UTF-8"); - } catch (UnsupportedEncodingException e) { - // should not happen! - } - if (couchFilterParamsUrl != null) { - file = file + couchFilterParamsUrl; - } - } - - if (lastSeq != null) { - try { - file = file + "&since=" + URLEncoder.encode(lastSeq, "UTF-8"); - } catch (UnsupportedEncodingException e) { - // should not happen, but in any case... - file = file + "&since=" + lastSeq; - } - } - - if (logger.isDebugEnabled()) { - logger.debug("using host [{}], port [{}], path [{}]", couchHost, couchPort, file); - } - - HttpURLConnection connection = null; - InputStream is = null; - try { - URL url = new URL(couchProtocol, couchHost, couchPort, file); - connection = (HttpURLConnection) url.openConnection(); - if (basicAuth != null) { - connection.addRequestProperty("Authorization", basicAuth); - } - connection.setDoInput(true); - connection.setUseCaches(false); - - if (noVerify) { - ((HttpsURLConnection) connection).setHostnameVerifier( - new HostnameVerifier() { - public boolean verify(String string, SSLSession ssls) { - return true; - } - } - ); - } - - is = connection.getInputStream(); - - final BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8")); - String line; - while ((line = reader.readLine()) != null) { - if (closed) { - return; - } - if (line.length() == 0) { - logger.trace("[couchdb] heartbeat"); - continue; - } - if (logger.isTraceEnabled()) { - logger.trace("[couchdb] {}", line); - } - // we put here, so we block if there is no space to add - stream.put(line); - } - } catch (Exception e) { - Closeables.closeQuietly(is); - if (connection != null) { - try { - connection.disconnect(); - } catch (Exception e1) { - // ignore - } finally { - connection = null; - } - } - if (closed) { - return; - } - logger.warn("failed to read from _changes, throttling....", e); - try { - Thread.sleep(5000); - } catch (InterruptedException e1) { - if (closed) { - return; - } - } - } finally { - Closeables.closeQuietly(is); - if (connection != null) { - try { - connection.disconnect(); - } catch (Exception e1) { - // ignore - } finally { - connection = null; - } - } - } - } - } - } -} diff --git a/plugins/river/couchdb/src/main/java/org/elasticsearch/river/couchdb/CouchdbRiverModule.java b/plugins/river/couchdb/src/main/java/org/elasticsearch/river/couchdb/CouchdbRiverModule.java deleted file mode 100644 index 3526455dfa1..00000000000 --- a/plugins/river/couchdb/src/main/java/org/elasticsearch/river/couchdb/CouchdbRiverModule.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.river.couchdb; - -import org.elasticsearch.common.inject.AbstractModule; -import org.elasticsearch.river.River; - -/** - * @author kimchy (shay.banon) - */ -public class CouchdbRiverModule extends AbstractModule { - - @Override protected void configure() { - bind(River.class).to(CouchdbRiver.class).asEagerSingleton(); - } -} diff --git a/plugins/river/couchdb/src/test/java/org/elasticsearch/river/couchdb/CouchdbRiverAttachementTest.java b/plugins/river/couchdb/src/test/java/org/elasticsearch/river/couchdb/CouchdbRiverAttachementTest.java deleted file mode 100644 index 55fdce0b961..00000000000 --- a/plugins/river/couchdb/src/test/java/org/elasticsearch/river/couchdb/CouchdbRiverAttachementTest.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.river.couchdb; - -import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; - -import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; -import org.elasticsearch.common.settings.ImmutableSettings; -import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.indices.IndexMissingException; -import org.elasticsearch.node.Node; -import org.elasticsearch.node.NodeBuilder; - -/** - * This is a simple test case for testing attachements removing.
- * You may have a couchdb instance running on localhost:5984 with a mytest database.
- * If you push documents with attachements in it, attachements should be ignored by the river. - * @author dadoonet (David Pilato) - */ -public class CouchdbRiverAttachementTest { - - public static void main(String[] args) throws Exception { - String host = "localhost"; - String port = "5984"; - String db = "mytest"; - boolean ignoreAttachements = true; - - Node node = NodeBuilder.nodeBuilder().settings(ImmutableSettings.settingsBuilder().put("gateway.type", "local")).node(); - Thread.sleep(1000); - try { - node.client().admin().indices().delete(new DeleteIndexRequest("_river")).actionGet(); - } catch (IndexMissingException e) { - // Index does not exist... Fine - } - Thread.sleep(1000); - try { - node.client().admin().indices().delete(new DeleteIndexRequest(db)).actionGet(); - } catch (IndexMissingException e) { - // Index does not exist... Fine - } - - XContentBuilder xb = jsonBuilder() - .startObject() - .field("type", "couchdb") - .startObject("couchdb") - .field("host", host) - .field("port", port) - .field("db", db) - .field("ignoreAttachements", ignoreAttachements) - .endObject() - .endObject(); - node.client().prepareIndex("_river", db, "_meta").setSource(xb).execute().actionGet(); - - Thread.sleep(100000); - } -} diff --git a/plugins/river/couchdb/src/test/java/org/elasticsearch/river/couchdb/CouchdbRiverTest.java b/plugins/river/couchdb/src/test/java/org/elasticsearch/river/couchdb/CouchdbRiverTest.java deleted file mode 100644 index 02fab0c5fff..00000000000 --- a/plugins/river/couchdb/src/test/java/org/elasticsearch/river/couchdb/CouchdbRiverTest.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.river.couchdb; - -import org.elasticsearch.common.settings.ImmutableSettings; -import org.elasticsearch.node.Node; -import org.elasticsearch.node.NodeBuilder; - -import static org.elasticsearch.common.xcontent.XContentFactory.*; - -/** - * @author kimchy (shay.banon) - */ -public class CouchdbRiverTest { - - public static void main(String[] args) throws Exception { - Node node = NodeBuilder.nodeBuilder().settings(ImmutableSettings.settingsBuilder().put("gateway.type", "local")).node(); - Thread.sleep(1000); - node.client().prepareIndex("_river", "db", "_meta").setSource(jsonBuilder().startObject().field("type", "couchdb").endObject()).execute().actionGet(); - - Thread.sleep(1000000); - } -} diff --git a/plugins/river/rabbitmq/build.gradle b/plugins/river/rabbitmq/build.gradle deleted file mode 100644 index 03f81480230..00000000000 --- a/plugins/river/rabbitmq/build.gradle +++ /dev/null @@ -1,134 +0,0 @@ -dependsOn(':elasticsearch') - -apply plugin: 'java' -apply plugin: 'maven' -apply plugin: 'eclipse' - -archivesBaseName = "elasticsearch-river-rabbitmq" - -explodedDistDir = new File(distsDir, 'exploded') - -manifest.mainAttributes("Implementation-Title": "ElasticSearch::Plugins::River::RabbitMQ", "Implementation-Version": rootProject.version, "Implementation-Date": buildTimeStr) - -configurations.compile.transitive = true -configurations.testCompile.transitive = true - -// no need to use the resource dir -sourceSets.main.resources.srcDirs 'src/main/java' -sourceSets.test.resources.srcDirs 'src/test/java' - -// add the source files to the dist jar -//jar { -// from sourceSets.main.allJava -//} - -configurations { - dists - distLib { - visible = false - transitive = false - } -} - -dependencies { - compile project(':elasticsearch') - - compile('com.rabbitmq:amqp-client:2.5.1') { transitive = false } - compile("commons-io:commons-io:1.2") { transitive = false } - distLib('com.rabbitmq:amqp-client:2.5.1') { transitive = false } - distLib("commons-io:commons-io:1.2") { transitive = false } -} - -task explodedDist(dependsOn: [jar], description: 'Builds the plugin zip file') << { - [explodedDistDir]*.mkdirs() - - copy { - from configurations.distLib - into explodedDistDir - } - - // remove elasticsearch files (compile above adds the elasticsearch one) - ant.delete { fileset(dir: explodedDistDir, includes: "elasticsearch-*.jar") } - - copy { - from libsDir - into explodedDistDir - } - - ant.delete { fileset(dir: explodedDistDir, includes: "elasticsearch-*-javadoc.jar") } - ant.delete { fileset(dir: explodedDistDir, includes: "elasticsearch-*-sources.jar") } -} - -task zip(type: Zip, dependsOn: ['explodedDist']) { - from(explodedDistDir) { - } -} - -task release(dependsOn: [zip]) << { - ant.delete(dir: explodedDistDir) - copy { - from distsDir - into(new File(rootProject.distsDir, "plugins")) - } -} - -configurations { - deployerJars -} - -dependencies { - deployerJars "org.apache.maven.wagon:wagon-http:1.0-beta-2" -} - -task sourcesJar(type: Jar, dependsOn: classes) { - classifier = 'sources' - from sourceSets.main.allSource -} - -task javadocJar(type: Jar, dependsOn: javadoc) { - classifier = 'javadoc' - from javadoc.destinationDir -} - -artifacts { - archives sourcesJar - archives javadocJar -} - -uploadArchives { - repositories.mavenDeployer { - configuration = configurations.deployerJars - repository(url: rootProject.mavenRepoUrl) { - authentication(userName: rootProject.mavenRepoUser, password: rootProject.mavenRepoPass) - } - snapshotRepository(url: rootProject.mavenSnapshotRepoUrl) { - authentication(userName: rootProject.mavenRepoUser, password: rootProject.mavenRepoPass) - } - - pom.project { - inceptionYear '2009' - name 'elasticsearch-plugins-river-rabbitmq' - description 'RabbitMQ River Plugin for ElasticSearch' - licenses { - license { - name 'The Apache Software License, Version 2.0' - url 'http://www.apache.org/licenses/LICENSE-2.0.txt' - distribution 'repo' - } - } - scm { - connection 'git://github.com/elasticsearch/elasticsearch.git' - developerConnection 'git@github.com:elasticsearch/elasticsearch.git' - url 'http://github.com/elasticsearch/elasticsearch' - } - } - - pom.whenConfigured {pom -> - pom.dependencies = pom.dependencies.findAll {dep -> dep.scope != 'test' } // removes the test scoped ones - } - } -} - -eclipseClasspath { - defaultOutputDir = file('build/eclipse-build') -} \ No newline at end of file diff --git a/plugins/river/rabbitmq/src/main/java/es-plugin.properties b/plugins/river/rabbitmq/src/main/java/es-plugin.properties deleted file mode 100644 index e8f5b6dbf76..00000000000 --- a/plugins/river/rabbitmq/src/main/java/es-plugin.properties +++ /dev/null @@ -1,2 +0,0 @@ -plugin=org.elasticsearch.plugin.river.rabbitmq.RabbitmqRiverPlugin - diff --git a/plugins/river/rabbitmq/src/main/java/org/elasticsearch/plugin/river/rabbitmq/RabbitmqRiverPlugin.java b/plugins/river/rabbitmq/src/main/java/org/elasticsearch/plugin/river/rabbitmq/RabbitmqRiverPlugin.java deleted file mode 100644 index 95cbf8ee527..00000000000 --- a/plugins/river/rabbitmq/src/main/java/org/elasticsearch/plugin/river/rabbitmq/RabbitmqRiverPlugin.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.plugin.river.rabbitmq; - -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.inject.Module; -import org.elasticsearch.plugins.AbstractPlugin; -import org.elasticsearch.river.RiversModule; -import org.elasticsearch.river.rabbitmq.RabbitmqRiverModule; - -/** - * @author kimchy (shay.banon) - */ -public class RabbitmqRiverPlugin extends AbstractPlugin { - - @Inject public RabbitmqRiverPlugin() { - } - - @Override public String name() { - return "river-rabbitmq"; - } - - @Override public String description() { - return "River RabbitMQ Plugin"; - } - - @Override public void processModule(Module module) { - if (module instanceof RiversModule) { - ((RiversModule) module).registerRiver("rabbitmq", RabbitmqRiverModule.class); - } - } -} diff --git a/plugins/river/rabbitmq/src/main/java/org/elasticsearch/river/rabbitmq/RabbitmqRiver.java b/plugins/river/rabbitmq/src/main/java/org/elasticsearch/river/rabbitmq/RabbitmqRiver.java deleted file mode 100644 index c43133c1be3..00000000000 --- a/plugins/river/rabbitmq/src/main/java/org/elasticsearch/river/rabbitmq/RabbitmqRiver.java +++ /dev/null @@ -1,315 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.river.rabbitmq; - -import com.rabbitmq.client.Channel; -import com.rabbitmq.client.Connection; -import com.rabbitmq.client.ConnectionFactory; -import com.rabbitmq.client.QueueingConsumer; -import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.bulk.BulkResponse; -import org.elasticsearch.client.Client; -import org.elasticsearch.client.action.bulk.BulkRequestBuilder; -import org.elasticsearch.common.collect.Lists; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.common.util.concurrent.EsExecutors; -import org.elasticsearch.common.xcontent.support.XContentMapValues; -import org.elasticsearch.river.AbstractRiverComponent; -import org.elasticsearch.river.River; -import org.elasticsearch.river.RiverName; -import org.elasticsearch.river.RiverSettings; - -import java.io.IOException; -import java.util.List; -import java.util.Map; - -/** - * @author kimchy (shay.banon) - */ -public class RabbitmqRiver extends AbstractRiverComponent implements River { - - private final Client client; - - private final String rabbitHost; - private final int rabbitPort; - private final String rabbitUser; - private final String rabbitPassword; - private final String rabbitVhost; - - private final String rabbitQueue; - private final String rabbitExchange; - private final String rabbitExchangeType; - private final String rabbitRoutingKey; - private final boolean rabbitExchangeDurable; - private final boolean rabbitQueueDurable; - private final boolean rabbitQueueAutoDelete; - - private final int bulkSize; - private final TimeValue bulkTimeout; - private final boolean ordered; - - private volatile boolean closed = false; - - private volatile Thread thread; - - private volatile ConnectionFactory connectionFactory; - - @SuppressWarnings({"unchecked"}) - @Inject public RabbitmqRiver(RiverName riverName, RiverSettings settings, Client client) { - super(riverName, settings); - this.client = client; - - if (settings.settings().containsKey("rabbitmq")) { - Map rabbitSettings = (Map) settings.settings().get("rabbitmq"); - rabbitHost = XContentMapValues.nodeStringValue(rabbitSettings.get("host"), ConnectionFactory.DEFAULT_HOST); - rabbitPort = XContentMapValues.nodeIntegerValue(rabbitSettings.get("port"), ConnectionFactory.DEFAULT_AMQP_PORT); - rabbitUser = XContentMapValues.nodeStringValue(rabbitSettings.get("user"), ConnectionFactory.DEFAULT_USER); - rabbitPassword = XContentMapValues.nodeStringValue(rabbitSettings.get("pass"), ConnectionFactory.DEFAULT_PASS); - rabbitVhost = XContentMapValues.nodeStringValue(rabbitSettings.get("vhost"), ConnectionFactory.DEFAULT_VHOST); - - - rabbitQueue = XContentMapValues.nodeStringValue(rabbitSettings.get("queue"), "elasticsearch"); - rabbitExchange = XContentMapValues.nodeStringValue(rabbitSettings.get("exchange"), "elasticsearch"); - rabbitExchangeType = XContentMapValues.nodeStringValue(rabbitSettings.get("exchange_type"), "direct"); - rabbitRoutingKey = XContentMapValues.nodeStringValue(rabbitSettings.get("routing_key"), "elasticsearch"); - rabbitExchangeDurable = XContentMapValues.nodeBooleanValue(rabbitSettings.get("exchange_durable"), true); - rabbitQueueDurable = XContentMapValues.nodeBooleanValue(rabbitSettings.get("queue_durable"), true); - rabbitQueueAutoDelete = XContentMapValues.nodeBooleanValue(rabbitSettings.get("queue_auto_delete"), false); - } else { - rabbitHost = ConnectionFactory.DEFAULT_HOST; - rabbitPort = ConnectionFactory.DEFAULT_AMQP_PORT; - rabbitUser = ConnectionFactory.DEFAULT_USER; - rabbitPassword = ConnectionFactory.DEFAULT_PASS; - rabbitVhost = ConnectionFactory.DEFAULT_VHOST; - - rabbitQueue = "elasticsearch"; - rabbitQueueAutoDelete = false; - rabbitQueueDurable = true; - rabbitExchange = "elasticsearch"; - rabbitExchangeType = "direct"; - rabbitExchangeDurable = true; - rabbitRoutingKey = "elasticsearch"; - } - - if (settings.settings().containsKey("index")) { - Map indexSettings = (Map) settings.settings().get("index"); - bulkSize = XContentMapValues.nodeIntegerValue(indexSettings.get("bulk_size"), 100); - if (indexSettings.containsKey("bulk_timeout")) { - bulkTimeout = TimeValue.parseTimeValue(XContentMapValues.nodeStringValue(indexSettings.get("bulk_timeout"), "10ms"), TimeValue.timeValueMillis(10)); - } else { - bulkTimeout = TimeValue.timeValueMillis(10); - } - ordered = XContentMapValues.nodeBooleanValue(indexSettings.get("ordered"), false); - } else { - bulkSize = 100; - bulkTimeout = TimeValue.timeValueMillis(10); - ordered = false; - } - } - - @Override public void start() { - connectionFactory = new ConnectionFactory(); - connectionFactory.setHost(rabbitHost); - connectionFactory.setPort(rabbitPort); - connectionFactory.setUsername(rabbitUser); - connectionFactory.setPassword(rabbitPassword); - connectionFactory.setVirtualHost(rabbitVhost); - - logger.info("creating rabbitmq river, host [{}], port [{}], user [{}], vhost [{}]", connectionFactory.getHost(), connectionFactory.getPort(), connectionFactory.getUsername(), connectionFactory.getVirtualHost()); - - thread = EsExecutors.daemonThreadFactory(settings.globalSettings(), "rabbitmq_river").newThread(new Consumer()); - thread.start(); - } - - @Override public void close() { - if (closed) { - return; - } - logger.info("closing rabbitmq river"); - closed = true; - thread.interrupt(); - } - - private class Consumer implements Runnable { - - private Connection connection; - - private Channel channel; - - @Override public void run() { - while (true) { - if (closed) { - return; - } - try { - connection = connectionFactory.newConnection(); - channel = connection.createChannel(); - } catch (Exception e) { - if (!closed) { - logger.warn("failed to created a connection / channel", e); - } else { - continue; - } - cleanup(0, "failed to connect"); - try { - Thread.sleep(5000); - } catch (InterruptedException e1) { - // ignore, if we are closing, we will exit later - } - } - - QueueingConsumer consumer = new QueueingConsumer(channel); - // define the queue - try { - channel.exchangeDeclare(rabbitExchange/*exchange*/, rabbitExchangeType/*type*/, rabbitExchangeDurable); - channel.queueDeclare(rabbitQueue/*queue*/, rabbitQueueDurable/*durable*/, false/*exclusive*/, rabbitQueueAutoDelete/*autoDelete*/, null); - channel.queueBind(rabbitQueue/*queue*/, rabbitExchange/*exchange*/, rabbitRoutingKey/*routingKey*/); - channel.basicConsume(rabbitQueue/*queue*/, false/*noAck*/, consumer); - } catch (Exception e) { - if (!closed) { - logger.warn("failed to create queue [{}]", e, rabbitQueue); - } - cleanup(0, "failed to create queue"); - continue; - } - - // now use the queue to listen for messages - while (true) { - if (closed) { - break; - } - QueueingConsumer.Delivery task; - try { - task = consumer.nextDelivery(); - } catch (Exception e) { - if (!closed) { - logger.error("failed to get next message, reconnecting...", e); - } - cleanup(0, "failed to get message"); - break; - } - - if (task != null && task.getBody() != null) { - final List deliveryTags = Lists.newArrayList(); - - BulkRequestBuilder bulkRequestBuilder = client.prepareBulk(); - - try { - bulkRequestBuilder.add(task.getBody(), 0, task.getBody().length, false); - } catch (Exception e) { - logger.warn("failed to parse request for delivery tag [{}], ack'ing...", e, task.getEnvelope().getDeliveryTag()); - try { - channel.basicAck(task.getEnvelope().getDeliveryTag(), false); - } catch (IOException e1) { - logger.warn("failed to ack [{}]", e1, task.getEnvelope().getDeliveryTag()); - } - continue; - } - - deliveryTags.add(task.getEnvelope().getDeliveryTag()); - - if (bulkRequestBuilder.numberOfActions() < bulkSize) { - // try and spin some more of those without timeout, so we have a bigger bulk (bounded by the bulk size) - try { - while ((task = consumer.nextDelivery(bulkTimeout.millis())) != null) { - try { - bulkRequestBuilder.add(task.getBody(), 0, task.getBody().length, false); - } catch (Exception e) { - logger.warn("failed to parse request for delivery tag [{}], ack'ing...", e, task.getEnvelope().getDeliveryTag()); - try { - channel.basicAck(task.getEnvelope().getDeliveryTag(), false); - } catch (IOException e1) { - logger.warn("failed to ack on failure [{}]", e1, task.getEnvelope().getDeliveryTag()); - } - } - deliveryTags.add(task.getEnvelope().getDeliveryTag()); - if (bulkRequestBuilder.numberOfActions() >= bulkSize) { - break; - } - } - } catch (InterruptedException e) { - if (closed) { - break; - } - } - } - - if (logger.isTraceEnabled()) { - logger.trace("executing bulk with [{}] actions", bulkRequestBuilder.numberOfActions()); - } - - if (ordered) { - try { - BulkResponse response = bulkRequestBuilder.execute().actionGet(); - if (response.hasFailures()) { - // TODO write to exception queue? - logger.warn("failed to execute" + response.buildFailureMessage()); - } - for (Long deliveryTag : deliveryTags) { - try { - channel.basicAck(deliveryTag, false); - } catch (IOException e1) { - logger.warn("failed to ack [{}]", e1, deliveryTag); - } - } - } catch (Exception e) { - logger.warn("failed to execute bulk", e); - } - } else { - bulkRequestBuilder.execute(new ActionListener() { - @Override public void onResponse(BulkResponse response) { - if (response.hasFailures()) { - // TODO write to exception queue? - logger.warn("failed to execute" + response.buildFailureMessage()); - } - for (Long deliveryTag : deliveryTags) { - try { - channel.basicAck(deliveryTag, false); - } catch (IOException e1) { - logger.warn("failed to ack [{}]", e1, deliveryTag); - } - } - } - - @Override public void onFailure(Throwable e) { - logger.warn("failed to execute bulk for delivery tags [{}], not ack'ing", e, deliveryTags); - } - }); - } - } - } - } - } - - private void cleanup(int code, String message) { - try { - channel.close(code, message); - } catch (Exception e) { - logger.debug("failed to close channel", e); - } - try { - connection.close(code, message); - } catch (Exception e) { - logger.debug("failed to close connection", e); - } - } - } -} diff --git a/plugins/river/rabbitmq/src/main/java/org/elasticsearch/river/rabbitmq/RabbitmqRiverModule.java b/plugins/river/rabbitmq/src/main/java/org/elasticsearch/river/rabbitmq/RabbitmqRiverModule.java deleted file mode 100644 index 8508813162e..00000000000 --- a/plugins/river/rabbitmq/src/main/java/org/elasticsearch/river/rabbitmq/RabbitmqRiverModule.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.river.rabbitmq; - -import org.elasticsearch.common.inject.AbstractModule; -import org.elasticsearch.river.River; - -/** - * @author kimchy (shay.banon) - */ -public class RabbitmqRiverModule extends AbstractModule { - - @Override protected void configure() { - bind(River.class).to(RabbitmqRiver.class).asEagerSingleton(); - } -} diff --git a/plugins/river/rabbitmq/src/test/java/org/elasticsearch/river/rabbitmq/RabbitMQRiverTest.java b/plugins/river/rabbitmq/src/test/java/org/elasticsearch/river/rabbitmq/RabbitMQRiverTest.java deleted file mode 100644 index 57525fcc4f3..00000000000 --- a/plugins/river/rabbitmq/src/test/java/org/elasticsearch/river/rabbitmq/RabbitMQRiverTest.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.river.rabbitmq; - -import com.rabbitmq.client.AMQP; -import com.rabbitmq.client.Channel; -import com.rabbitmq.client.Connection; -import com.rabbitmq.client.ConnectionFactory; -import org.elasticsearch.common.settings.ImmutableSettings; -import org.elasticsearch.node.Node; -import org.elasticsearch.node.NodeBuilder; - -import static org.elasticsearch.common.xcontent.XContentFactory.*; - -/** - * @author kimchy (shay.banon) - */ -public class RabbitMQRiverTest { - - public static void main(String[] args) throws Exception { - - Node node = NodeBuilder.nodeBuilder().settings(ImmutableSettings.settingsBuilder().put("gateway.type", "none")).node(); - - node.client().prepareIndex("_river", "test1", "_meta").setSource(jsonBuilder().startObject().field("type", "rabbitmq").endObject()).execute().actionGet(); - - ConnectionFactory cfconn = new ConnectionFactory(); - cfconn.setHost("localhost"); - cfconn.setPort(AMQP.PROTOCOL.PORT); - Connection conn = cfconn.newConnection(); - - Channel ch = conn.createChannel(); - ch.exchangeDeclare("elasticsearch", "direct", true); - ch.queueDeclare("elasticsearch", true, false, false, null); - - String message = "{ \"index\" : { \"index\" : \"test\", \"type\" : \"type1\", \"id\" : \"1\" }\n" + - "{ \"type1\" : { \"field1\" : \"value1\" } }\n" + - "{ \"delete\" : { \"index\" : \"test\", \"type\" : \"type1\", \"id\" : \"2\" } }\n" + - "{ \"create\" : { \"index\" : \"test\", \"type\" : \"type1\", \"id\" : \"1\" }\n" + - "{ \"type1\" : { \"field1\" : \"value1\" } }"; - - ch.basicPublish("elasticsearch", "elasticsearch", null, message.getBytes()); - - ch.close(); - conn.close(); - - Thread.sleep(100000); - } -} diff --git a/plugins/river/twitter/build.gradle b/plugins/river/twitter/build.gradle deleted file mode 100644 index e394aae78e6..00000000000 --- a/plugins/river/twitter/build.gradle +++ /dev/null @@ -1,134 +0,0 @@ -dependsOn(':elasticsearch') - -apply plugin: 'java' -apply plugin: 'maven' -apply plugin: 'eclipse' - -archivesBaseName = "elasticsearch-river-twitter" - -explodedDistDir = new File(distsDir, 'exploded') - -manifest.mainAttributes("Implementation-Title": "ElasticSearch::Plugins::River::Twitter", "Implementation-Version": rootProject.version, "Implementation-Date": buildTimeStr) - -configurations.compile.transitive = true -configurations.testCompile.transitive = true - -// no need to use the resource dir -sourceSets.main.resources.srcDirs 'src/main/java' -sourceSets.test.resources.srcDirs 'src/test/java' - -// add the source files to the dist jar -//jar { -// from sourceSets.main.allJava -//} - -configurations { - dists - distLib { - visible = false - transitive = false - } -} - -dependencies { - compile project(':elasticsearch') - - compile('org.twitter4j:twitter4j-core:2.2.5') { transitive = false } - compile('org.twitter4j:twitter4j-stream:2.2.5') { transitive = false } - distLib('org.twitter4j:twitter4j-core:2.2.5') { transitive = false } - distLib('org.twitter4j:twitter4j-stream:2.2.5') { transitive = false } -} - -task explodedDist(dependsOn: [jar], description: 'Builds the plugin zip file') << { - [explodedDistDir]*.mkdirs() - - copy { - from configurations.distLib - into explodedDistDir - } - - // remove elasticsearch files (compile above adds the elasticsearch one) - ant.delete { fileset(dir: explodedDistDir, includes: "elasticsearch-*.jar") } - - copy { - from libsDir - into explodedDistDir - } - - ant.delete { fileset(dir: explodedDistDir, includes: "elasticsearch-*-javadoc.jar") } - ant.delete { fileset(dir: explodedDistDir, includes: "elasticsearch-*-sources.jar") } -} - -task zip(type: Zip, dependsOn: ['explodedDist']) { - from(explodedDistDir) { - } -} - -task release(dependsOn: [zip]) << { - ant.delete(dir: explodedDistDir) - copy { - from distsDir - into(new File(rootProject.distsDir, "plugins")) - } -} - -configurations { - deployerJars -} - -dependencies { - deployerJars "org.apache.maven.wagon:wagon-http:1.0-beta-2" -} - -task sourcesJar(type: Jar, dependsOn: classes) { - classifier = 'sources' - from sourceSets.main.allSource -} - -task javadocJar(type: Jar, dependsOn: javadoc) { - classifier = 'javadoc' - from javadoc.destinationDir -} - -artifacts { - archives sourcesJar - archives javadocJar -} - -uploadArchives { - repositories.mavenDeployer { - configuration = configurations.deployerJars - repository(url: rootProject.mavenRepoUrl) { - authentication(userName: rootProject.mavenRepoUser, password: rootProject.mavenRepoPass) - } - snapshotRepository(url: rootProject.mavenSnapshotRepoUrl) { - authentication(userName: rootProject.mavenRepoUser, password: rootProject.mavenRepoPass) - } - - pom.project { - inceptionYear '2009' - name 'elasticsearch-plugins-river-twitter' - description 'Twitter River Plugin for ElasticSearch' - licenses { - license { - name 'The Apache Software License, Version 2.0' - url 'http://www.apache.org/licenses/LICENSE-2.0.txt' - distribution 'repo' - } - } - scm { - connection 'git://github.com/elasticsearch/elasticsearch.git' - developerConnection 'git@github.com:elasticsearch/elasticsearch.git' - url 'http://github.com/elasticsearch/elasticsearch' - } - } - - pom.whenConfigured {pom -> - pom.dependencies = pom.dependencies.findAll {dep -> dep.scope != 'test' } // removes the test scoped ones - } - } -} - -eclipseClasspath { - defaultOutputDir = file('build/eclipse-build') -} diff --git a/plugins/river/twitter/src/main/java/es-plugin.properties b/plugins/river/twitter/src/main/java/es-plugin.properties deleted file mode 100644 index 1642f8c3961..00000000000 --- a/plugins/river/twitter/src/main/java/es-plugin.properties +++ /dev/null @@ -1,2 +0,0 @@ -plugin=org.elasticsearch.plugin.river.twitter.TwitterRiverPlugin - diff --git a/plugins/river/twitter/src/main/java/org/elasticsearch/plugin/river/twitter/TwitterRiverPlugin.java b/plugins/river/twitter/src/main/java/org/elasticsearch/plugin/river/twitter/TwitterRiverPlugin.java deleted file mode 100644 index d0fccae8d66..00000000000 --- a/plugins/river/twitter/src/main/java/org/elasticsearch/plugin/river/twitter/TwitterRiverPlugin.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.plugin.river.twitter; - -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.inject.Module; -import org.elasticsearch.plugins.AbstractPlugin; -import org.elasticsearch.river.RiversModule; -import org.elasticsearch.river.twitter.TwitterRiverModule; - -/** - * @author kimchy (shay.banon) - */ -public class TwitterRiverPlugin extends AbstractPlugin { - - @Inject public TwitterRiverPlugin() { - } - - @Override public String name() { - return "river-twitter"; - } - - @Override public String description() { - return "River Twitter Plugin"; - } - - - @Override public void processModule(Module module) { - if (module instanceof RiversModule) { - ((RiversModule) module).registerRiver("twitter", TwitterRiverModule.class); - } - } -} diff --git a/plugins/river/twitter/src/main/java/org/elasticsearch/river/twitter/TwitterRiver.java b/plugins/river/twitter/src/main/java/org/elasticsearch/river/twitter/TwitterRiver.java deleted file mode 100644 index 420eebb584a..00000000000 --- a/plugins/river/twitter/src/main/java/org/elasticsearch/river/twitter/TwitterRiver.java +++ /dev/null @@ -1,511 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.river.twitter; - -import org.elasticsearch.ExceptionsHelper; -import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.bulk.BulkResponse; -import org.elasticsearch.client.Client; -import org.elasticsearch.client.Requests; -import org.elasticsearch.client.action.bulk.BulkRequestBuilder; -import org.elasticsearch.cluster.block.ClusterBlockException; -import org.elasticsearch.common.Strings; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentFactory; -import org.elasticsearch.common.xcontent.support.XContentMapValues; -import org.elasticsearch.indices.IndexAlreadyExistsException; -import org.elasticsearch.river.AbstractRiverComponent; -import org.elasticsearch.river.River; -import org.elasticsearch.river.RiverName; -import org.elasticsearch.river.RiverSettings; -import org.elasticsearch.threadpool.ThreadPool; -import twitter4j.*; -import twitter4j.conf.ConfigurationBuilder; - -import java.util.List; -import java.util.Map; -import java.util.concurrent.atomic.AtomicInteger; - -/** - * @author kimchy (shay.banon) - */ -public class TwitterRiver extends AbstractRiverComponent implements River { - - private final ThreadPool threadPool; - - private final Client client; - - private String user; - private String password; - - private String oauthConsumerKey = null; - private String oauthConsumerSecret = null; - private String oauthAccessToken = null; - private String oauthAccessTokenSecret = null; - - private final String indexName; - - private final String typeName; - - private final int bulkSize; - - private final int dropThreshold; - - private FilterQuery filterQuery; - - private String streamType; - - - private volatile TwitterStream stream; - - private final AtomicInteger onGoingBulks = new AtomicInteger(); - - private volatile BulkRequestBuilder currentRequest; - - private volatile boolean closed = false; - - @SuppressWarnings({"unchecked"}) - @Inject public TwitterRiver(RiverName riverName, RiverSettings settings, Client client, ThreadPool threadPool) { - super(riverName, settings); - this.client = client; - this.threadPool = threadPool; - - if (settings.settings().containsKey("twitter")) { - Map twitterSettings = (Map) settings.settings().get("twitter"); - user = XContentMapValues.nodeStringValue(twitterSettings.get("user"), null); - password = XContentMapValues.nodeStringValue(twitterSettings.get("password"), null); - if (twitterSettings.containsKey("oauth")) { - Map oauth = (Map) twitterSettings.get("oauth"); - if (oauth.containsKey("consumerKey")) { - oauthConsumerKey = XContentMapValues.nodeStringValue(oauth.get("consumerKey"), null); - } - if (oauth.containsKey("consumer_key")) { - oauthConsumerKey = XContentMapValues.nodeStringValue(oauth.get("consumer_key"), null); - } - if (oauth.containsKey("consumerSecret")) { - oauthConsumerSecret = XContentMapValues.nodeStringValue(oauth.get("consumerSecret"), null); - } - if (oauth.containsKey("consumer_secret")) { - oauthConsumerSecret = XContentMapValues.nodeStringValue(oauth.get("consumer_secret"), null); - } - if (oauth.containsKey("accessToken")) { - oauthAccessToken = XContentMapValues.nodeStringValue(oauth.get("accessToken"), null); - } - if (oauth.containsKey("access_token")) { - oauthAccessToken = XContentMapValues.nodeStringValue(oauth.get("access_token"), null); - } - if (oauth.containsKey("accessTokenSecret")) { - oauthAccessTokenSecret = XContentMapValues.nodeStringValue(oauth.get("accessTokenSecret"), null); - } - if (oauth.containsKey("access_token_secret")) { - oauthAccessTokenSecret = XContentMapValues.nodeStringValue(oauth.get("access_token_secret"), null); - } - } - streamType = XContentMapValues.nodeStringValue(twitterSettings.get("type"), "sample"); - Map filterSettings = (Map) twitterSettings.get("filter"); - if (filterSettings != null) { - filterQuery = new FilterQuery(); - filterQuery.count(XContentMapValues.nodeIntegerValue(filterSettings.get("count"), 0)); - Object tracks = filterSettings.get("tracks"); - if (tracks != null) { - if (tracks instanceof List) { - List lTracks = (List) tracks; - filterQuery.track(lTracks.toArray(new String[lTracks.size()])); - } else { - filterQuery.track(Strings.commaDelimitedListToStringArray(tracks.toString())); - } - } - Object follow = filterSettings.get("follow"); - if (follow != null) { - if (follow instanceof List) { - List lFollow = (List) follow; - long[] followIds = new long[lFollow.size()]; - for (int i = 0; i < lFollow.size(); i++) { - Object o = lFollow.get(i); - if (o instanceof Number) { - followIds[i] = ((Number) o).intValue(); - } else { - followIds[i] = Integer.parseInt(o.toString()); - } - } - filterQuery.follow(followIds); - } else { - String[] ids = Strings.commaDelimitedListToStringArray(follow.toString()); - long[] followIds = new long[ids.length]; - for (int i = 0; i < ids.length; i++) { - followIds[i] = Integer.parseInt(ids[i]); - } - filterQuery.follow(followIds); - } - } - Object locations = filterSettings.get("locations"); - if (locations != null) { - if (locations instanceof List) { - List lLocations = (List) locations; - double[][] dLocations = new double[lLocations.size()][]; - for (int i = 0; i < lLocations.size(); i++) { - Object loc = lLocations.get(i); - double lat; - double lon; - if (loc instanceof List) { - List lLoc = (List) loc; - if (lLoc.get(0) instanceof Number) { - lat = ((Number) lLoc.get(0)).doubleValue(); - } else { - lat = Double.parseDouble(lLoc.get(0).toString()); - } - if (lLoc.get(1) instanceof Number) { - lon = ((Number) lLoc.get(1)).doubleValue(); - } else { - lon = Double.parseDouble(lLoc.get(1).toString()); - } - } else { - String[] sLoc = Strings.commaDelimitedListToStringArray(loc.toString()); - lat = Double.parseDouble(sLoc[0]); - lon = Double.parseDouble(sLoc[1]); - } - dLocations[i] = new double[]{lat, lon}; - } - filterQuery.locations(dLocations); - } else { - String[] sLocations = Strings.commaDelimitedListToStringArray(locations.toString()); - double[][] dLocations = new double[sLocations.length / 2][]; - int dCounter = 0; - for (int i = 0; i < sLocations.length; i++) { - double lat = Double.parseDouble(sLocations[i]); - double lon = Double.parseDouble(sLocations[++i]); - dLocations[dCounter++] = new double[]{lat, lon}; - } - filterQuery.locations(dLocations); - } - } - } - } - - logger.info("creating twitter stream river for [{}]", user); - - if (user == null && password == null && oauthAccessToken == null && oauthConsumerKey == null && oauthConsumerSecret == null && oauthAccessTokenSecret == null) { - stream = null; - indexName = null; - typeName = "status"; - bulkSize = 100; - dropThreshold = 10; - logger.warn("no user/password or oauth specified, disabling river..."); - return; - } - - if (settings.settings().containsKey("index")) { - Map indexSettings = (Map) settings.settings().get("index"); - indexName = XContentMapValues.nodeStringValue(indexSettings.get("index"), riverName.name()); - typeName = XContentMapValues.nodeStringValue(indexSettings.get("type"), "status"); - this.bulkSize = XContentMapValues.nodeIntegerValue(indexSettings.get("bulk_size"), 100); - this.dropThreshold = XContentMapValues.nodeIntegerValue(indexSettings.get("drop_threshold"), 10); - } else { - indexName = riverName.name(); - typeName = "status"; - bulkSize = 100; - dropThreshold = 10; - } - - ConfigurationBuilder cb = new ConfigurationBuilder(); - if (oauthAccessToken != null && oauthConsumerKey != null && oauthConsumerSecret != null && oauthAccessTokenSecret != null) { - cb.setOAuthConsumerKey(oauthConsumerKey) - .setOAuthConsumerSecret(oauthConsumerSecret) - .setOAuthAccessToken(oauthAccessToken) - .setOAuthAccessTokenSecret(oauthAccessTokenSecret); - } else { - cb.setUser(user).setPassword(password); - } - stream = new TwitterStreamFactory(cb.build()).getInstance(); - stream.addListener(new StatusHandler()); - } - - @Override public void start() { - if (stream == null) { - return; - } - logger.info("starting twitter stream"); - try { - String mapping = XContentFactory.jsonBuilder().startObject().startObject(typeName).startObject("properties") - .startObject("location").field("type", "geo_point").endObject() - .startObject("user").startObject("properties").startObject("screen_name").field("type", "string").field("index", "not_analyzed").endObject().endObject().endObject() - .startObject("mention").startObject("properties").startObject("screen_name").field("type", "string").field("index", "not_analyzed").endObject().endObject().endObject() - .startObject("in_reply").startObject("properties").startObject("user_screen_name").field("type", "string").field("index", "not_analyzed").endObject().endObject().endObject() - .endObject().endObject().endObject().string(); - client.admin().indices().prepareCreate(indexName).addMapping(typeName, mapping).execute().actionGet(); - } catch (Exception e) { - if (ExceptionsHelper.unwrapCause(e) instanceof IndexAlreadyExistsException) { - // that's fine - } else if (ExceptionsHelper.unwrapCause(e) instanceof ClusterBlockException) { - // ok, not recovered yet..., lets start indexing and hope we recover by the first bulk - // TODO: a smarter logic can be to register for cluster event listener here, and only start sampling when the block is removed... - } else { - logger.warn("failed to create index [{}], disabling river...", e, indexName); - return; - } - } - currentRequest = client.prepareBulk(); - if (streamType.equals("filter") || filterQuery != null) { - - stream.filter(filterQuery); - - } else if (streamType.equals("firehose")) { - stream.firehose(0); - } else { - stream.sample(); - } - } - - private void reconnect() { - if (closed) { - return; - } - try { - stream.cleanUp(); - } catch (Exception e) { - logger.debug("failed to cleanup after failure", e); - } - try { - stream.shutdown(); - } catch (Exception e) { - logger.debug("failed to shutdown after failure", e); - } - if (closed) { - return; - } - - try { - ConfigurationBuilder cb = new ConfigurationBuilder(); - if (oauthAccessToken != null && oauthConsumerKey != null && oauthConsumerSecret != null && oauthAccessTokenSecret != null) { - cb.setOAuthConsumerKey(oauthConsumerKey) - .setOAuthConsumerSecret(oauthConsumerSecret) - .setOAuthAccessToken(oauthAccessToken) - .setOAuthAccessTokenSecret(oauthAccessTokenSecret); - } else { - cb.setUser(user).setPassword(password); - } - stream = new TwitterStreamFactory(cb.build()).getInstance(); - stream.addListener(new StatusHandler()); - - if (streamType.equals("filter") || filterQuery != null) { - stream.filter(filterQuery); - - } else if (streamType.equals("firehose")) { - stream.firehose(0); - } else { - stream.sample(); - } - } catch (Exception e) { - if (closed) { - close(); - return; - } - // TODO, we can update the status of the river to RECONNECT - logger.warn("failed to connect after failure, throttling", e); - threadPool.schedule(TimeValue.timeValueSeconds(10), ThreadPool.Names.CACHED, new Runnable() { - @Override public void run() { - reconnect(); - } - }); - } - } - - @Override public void close() { - this.closed = true; - logger.info("closing twitter stream river"); - if (stream != null) { - stream.cleanUp(); - stream.shutdown(); - } - } - - private class StatusHandler extends StatusAdapter { - - @Override public void onStatus(Status status) { - if (logger.isTraceEnabled()) { - logger.trace("status {} : {}", status.getUser().getName(), status.getText()); - } - try { - XContentBuilder builder = XContentFactory.jsonBuilder().startObject(); - builder.field("text", status.getText()); - builder.field("created_at", status.getCreatedAt()); - builder.field("source", status.getSource()); - builder.field("truncated", status.isTruncated()); - - if (status.getUserMentionEntities() != null) { - builder.startArray("mention"); - for (UserMentionEntity user : status.getUserMentionEntities()) { - builder.startObject(); - builder.field("id", user.getId()); - builder.field("name", user.getName()); - builder.field("screen_name", user.getScreenName()); - builder.field("start", user.getStart()); - builder.field("end", user.getEnd()); - builder.endObject(); - } - builder.endArray(); - } - - if (status.getRetweetCount() != -1) { - builder.field("retweet_count", status.getRetweetCount()); - } - - if (status.getInReplyToStatusId() != -1) { - builder.startObject("in_reply"); - builder.field("status", status.getInReplyToStatusId()); - if (status.getInReplyToUserId() != -1) { - builder.field("user_id", status.getInReplyToUserId()); - builder.field("user_screen_name", status.getInReplyToScreenName()); - } - builder.endObject(); - } - - if (status.getHashtagEntities() != null) { - builder.startArray("hashtag"); - for (HashtagEntity hashtag : status.getHashtagEntities()) { - builder.startObject(); - builder.field("text", hashtag.getText()); - builder.field("start", hashtag.getStart()); - builder.field("end", hashtag.getEnd()); - builder.endObject(); - } - builder.endArray(); - } - if (status.getContributors() != null) { - builder.array("contributor", status.getContributors()); - } - if (status.getGeoLocation() != null) { - builder.startObject("location"); - builder.field("lat", status.getGeoLocation().getLatitude()); - builder.field("lon", status.getGeoLocation().getLongitude()); - builder.endObject(); - } - if (status.getPlace() != null) { - builder.startObject("place"); - builder.field("id", status.getPlace().getId()); - builder.field("name", status.getPlace().getName()); - builder.field("type", status.getPlace().getPlaceType()); - builder.field("full_name", status.getPlace().getFullName()); - builder.field("street_address", status.getPlace().getStreetAddress()); - builder.field("country", status.getPlace().getCountry()); - builder.field("country_code", status.getPlace().getCountryCode()); - builder.field("url", status.getPlace().getURL()); - builder.endObject(); - } - if (status.getURLEntities() != null) { - builder.startArray("link"); - for (URLEntity url : status.getURLEntities()) { - if (url != null) { - builder.startObject(); - if (url.getURL() != null) { - builder.field("url", url.getURL().toExternalForm()); - } - if (url.getDisplayURL() != null) { - builder.field("display_url", url.getDisplayURL()); - } - if (url.getExpandedURL() != null) { - builder.field("expand_url", url.getExpandedURL()); - } - builder.field("start", url.getStart()); - builder.field("end", url.getEnd()); - builder.endObject(); - } - } - builder.endArray(); - } - if (status.getAnnotations() != null) { - builder.startObject("annotation"); - List annotations = status.getAnnotations().getAnnotations(); - for (Annotation ann : annotations) { - builder.startObject(ann.getType()); - Map attributes = ann.getAttributes(); - for (Map.Entry entry : attributes.entrySet()) { - builder.field(entry.getKey(), entry.getValue()); - } - builder.endObject(); - } - builder.endObject(); - } - - builder.startObject("user"); - builder.field("id", status.getUser().getId()); - builder.field("name", status.getUser().getName()); - builder.field("screen_name", status.getUser().getScreenName()); - builder.field("location", status.getUser().getLocation()); - builder.field("description", status.getUser().getDescription()); - builder.endObject(); - - builder.endObject(); - currentRequest.add(Requests.indexRequest(indexName).type(typeName).id(Long.toString(status.getId())).create(true).source(builder)); - processBulkIfNeeded(); - } catch (Exception e) { - logger.warn("failed to construct index request", e); - } - } - - @Override public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) { - if (statusDeletionNotice.getStatusId() != -1) { - currentRequest.add(Requests.deleteRequest(indexName).type(typeName).id(Long.toString(statusDeletionNotice.getStatusId()))); - processBulkIfNeeded(); - } - } - - @Override public void onTrackLimitationNotice(int numberOfLimitedStatuses) { - logger.info("received track limitation notice, number_of_limited_statuses {}", numberOfLimitedStatuses); - } - - @Override public void onException(Exception ex) { - logger.warn("stream failure, restarting stream...", ex); - threadPool.cached().execute(new Runnable() { - @Override public void run() { - reconnect(); - } - }); - } - - private void processBulkIfNeeded() { - if (currentRequest.numberOfActions() >= bulkSize) { - // execute the bulk operation - int currentOnGoingBulks = onGoingBulks.incrementAndGet(); - if (currentOnGoingBulks > dropThreshold) { - onGoingBulks.decrementAndGet(); - logger.warn("dropping bulk, [{}] crossed threshold [{}]", onGoingBulks, dropThreshold); - } else { - try { - currentRequest.execute(new ActionListener() { - @Override public void onResponse(BulkResponse bulkResponse) { - onGoingBulks.decrementAndGet(); - } - - @Override public void onFailure(Throwable e) { - logger.warn("failed to execute bulk"); - } - }); - } catch (Exception e) { - logger.warn("failed to process bulk", e); - } - } - currentRequest = client.prepareBulk(); - } - } - } -} diff --git a/plugins/river/twitter/src/main/java/org/elasticsearch/river/twitter/TwitterRiverModule.java b/plugins/river/twitter/src/main/java/org/elasticsearch/river/twitter/TwitterRiverModule.java deleted file mode 100644 index 5d276848c05..00000000000 --- a/plugins/river/twitter/src/main/java/org/elasticsearch/river/twitter/TwitterRiverModule.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.river.twitter; - -import org.elasticsearch.common.inject.AbstractModule; -import org.elasticsearch.river.River; - -/** - * @author kimchy (shay.banon) - */ -public class TwitterRiverModule extends AbstractModule { - - @Override protected void configure() { - bind(River.class).to(TwitterRiver.class).asEagerSingleton(); - } -} diff --git a/plugins/river/wikipedia/build.gradle b/plugins/river/wikipedia/build.gradle deleted file mode 100644 index 54c7bbc685e..00000000000 --- a/plugins/river/wikipedia/build.gradle +++ /dev/null @@ -1,129 +0,0 @@ -dependsOn(':elasticsearch') - -apply plugin: 'java' -apply plugin: 'maven' -apply plugin: 'eclipse' - -archivesBaseName = "elasticsearch-river-wikipedia" - -explodedDistDir = new File(distsDir, 'exploded') - -manifest.mainAttributes("Implementation-Title": "ElasticSearch::Plugins::River::Wikipedia", "Implementation-Version": rootProject.version, "Implementation-Date": buildTimeStr) - -configurations.compile.transitive = true -configurations.testCompile.transitive = true - -// no need to use the resource dir -sourceSets.main.resources.srcDirs 'src/main/java' -sourceSets.test.resources.srcDirs 'src/test/java' - -// add the source files to the dist jar -//jar { -// from sourceSets.main.allJava -//} - -configurations { - dists - distLib { - visible = false - transitive = false - } -} - -dependencies { - compile project(':elasticsearch') -} - -task explodedDist(dependsOn: [jar], description: 'Builds the plugin zip file') << { - [explodedDistDir]*.mkdirs() - - copy { - from configurations.distLib - into explodedDistDir - } - - // remove elasticsearch files (compile above adds the elasticsearch one) - ant.delete { fileset(dir: explodedDistDir, includes: "elasticsearch-*.jar") } - - copy { - from libsDir - into explodedDistDir - } - - ant.delete { fileset(dir: explodedDistDir, includes: "elasticsearch-*-javadoc.jar") } - ant.delete { fileset(dir: explodedDistDir, includes: "elasticsearch-*-sources.jar") } -} - -task zip(type: Zip, dependsOn: ['explodedDist']) { - from(explodedDistDir) { - } -} - -task release(dependsOn: [zip]) << { - ant.delete(dir: explodedDistDir) - copy { - from distsDir - into(new File(rootProject.distsDir, "plugins")) - } -} - -configurations { - deployerJars -} - -dependencies { - deployerJars "org.apache.maven.wagon:wagon-http:1.0-beta-2" -} - -task sourcesJar(type: Jar, dependsOn: classes) { - classifier = 'sources' - from sourceSets.main.allSource -} - -task javadocJar(type: Jar, dependsOn: javadoc) { - classifier = 'javadoc' - from javadoc.destinationDir -} - -artifacts { - archives sourcesJar - archives javadocJar -} - -uploadArchives { - repositories.mavenDeployer { - configuration = configurations.deployerJars - repository(url: rootProject.mavenRepoUrl) { - authentication(userName: rootProject.mavenRepoUser, password: rootProject.mavenRepoPass) - } - snapshotRepository(url: rootProject.mavenSnapshotRepoUrl) { - authentication(userName: rootProject.mavenRepoUser, password: rootProject.mavenRepoPass) - } - - pom.project { - inceptionYear '2009' - name 'elasticsearch-plugins-river-wikipedia' - description 'Wikipedia River Plugin for ElasticSearch' - licenses { - license { - name 'The Apache Software License, Version 2.0' - url 'http://www.apache.org/licenses/LICENSE-2.0.txt' - distribution 'repo' - } - } - scm { - connection 'git://github.com/elasticsearch/elasticsearch.git' - developerConnection 'git@github.com:elasticsearch/elasticsearch.git' - url 'http://github.com/elasticsearch/elasticsearch' - } - } - - pom.whenConfigured {pom -> - pom.dependencies = pom.dependencies.findAll {dep -> dep.scope != 'test' } // removes the test scoped ones - } - } -} - -eclipseClasspath { - defaultOutputDir = file('build/eclipse-build') -} \ No newline at end of file diff --git a/plugins/river/wikipedia/src/main/java/es-plugin.properties b/plugins/river/wikipedia/src/main/java/es-plugin.properties deleted file mode 100644 index 38b8df1dae5..00000000000 --- a/plugins/river/wikipedia/src/main/java/es-plugin.properties +++ /dev/null @@ -1,2 +0,0 @@ -plugin=org.elasticsearch.plugin.river.wikipedia.WikipediaRiverPlugin - diff --git a/plugins/river/wikipedia/src/main/java/org/elasticsearch/plugin/river/wikipedia/WikipediaRiverPlugin.java b/plugins/river/wikipedia/src/main/java/org/elasticsearch/plugin/river/wikipedia/WikipediaRiverPlugin.java deleted file mode 100644 index 4b507b3ba67..00000000000 --- a/plugins/river/wikipedia/src/main/java/org/elasticsearch/plugin/river/wikipedia/WikipediaRiverPlugin.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.plugin.river.wikipedia; - -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.inject.Module; -import org.elasticsearch.plugins.AbstractPlugin; -import org.elasticsearch.river.RiversModule; -import org.elasticsearch.river.wikipedia.WikipediaRiverModule; - -/** - * @author kimchy (shay.banon) - */ -public class WikipediaRiverPlugin extends AbstractPlugin { - - @Inject public WikipediaRiverPlugin() { - } - - @Override public String name() { - return "river-wikipedia"; - } - - @Override public String description() { - return "River Wikipedia Plugin"; - } - - @Override public void processModule(Module module) { - if (module instanceof RiversModule) { - ((RiversModule) module).registerRiver("wikipedia", WikipediaRiverModule.class); - } - } -} diff --git a/plugins/river/wikipedia/src/main/java/org/elasticsearch/river/wikipedia/WikipediaRiver.java b/plugins/river/wikipedia/src/main/java/org/elasticsearch/river/wikipedia/WikipediaRiver.java deleted file mode 100644 index 7094ef117e9..00000000000 --- a/plugins/river/wikipedia/src/main/java/org/elasticsearch/river/wikipedia/WikipediaRiver.java +++ /dev/null @@ -1,236 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.river.wikipedia; - -import org.elasticsearch.ExceptionsHelper; -import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.bulk.BulkResponse; -import org.elasticsearch.client.Client; -import org.elasticsearch.client.Requests; -import org.elasticsearch.client.action.bulk.BulkRequestBuilder; -import org.elasticsearch.cluster.block.ClusterBlockException; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.util.concurrent.EsExecutors; -import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentFactory; -import org.elasticsearch.common.xcontent.support.XContentMapValues; -import org.elasticsearch.indices.IndexAlreadyExistsException; -import org.elasticsearch.river.AbstractRiverComponent; -import org.elasticsearch.river.River; -import org.elasticsearch.river.RiverName; -import org.elasticsearch.river.RiverSettings; -import org.elasticsearch.river.wikipedia.support.PageCallbackHandler; -import org.elasticsearch.river.wikipedia.support.WikiPage; -import org.elasticsearch.river.wikipedia.support.WikiXMLParser; -import org.elasticsearch.river.wikipedia.support.WikiXMLParserFactory; - -import java.net.MalformedURLException; -import java.net.URL; -import java.util.Map; -import java.util.concurrent.atomic.AtomicInteger; - -/** - * @author kimchy (shay.banon) - */ -public class WikipediaRiver extends AbstractRiverComponent implements River { - - private StringBuilder sb = new StringBuilder(); - - private final Client client; - - private final URL url; - - private final String indexName; - - private final String typeName; - - private final int bulkSize; - - private final int dropThreshold; - - - private final AtomicInteger onGoingBulks = new AtomicInteger(); - - private volatile Thread thread; - - private volatile boolean closed = false; - - private volatile BulkRequestBuilder currentRequest; - - @SuppressWarnings({"unchecked"}) - @Inject public WikipediaRiver(RiverName riverName, RiverSettings settings, Client client) throws MalformedURLException { - super(riverName, settings); - this.client = client; - - String url = "http://download.wikimedia.org/enwiki/latest/enwiki-latest-pages-articles.xml.bz2"; - if (settings.settings().containsKey("wikipedia")) { - Map wikipediaSettings = (Map) settings.settings().get("wikipedia"); - url = XContentMapValues.nodeStringValue(wikipediaSettings.get("url"), url); - } - - logger.info("creating wikipedia stream river for [{}]", url); - this.url = new URL(url); - - if (settings.settings().containsKey("index")) { - Map indexSettings = (Map) settings.settings().get("index"); - indexName = XContentMapValues.nodeStringValue(indexSettings.get("index"), riverName.name()); - typeName = XContentMapValues.nodeStringValue(indexSettings.get("type"), "status"); - this.bulkSize = XContentMapValues.nodeIntegerValue(settings.settings().get("bulk_size"), 100); - this.dropThreshold = XContentMapValues.nodeIntegerValue(settings.settings().get("drop_threshold"), 10); - } else { - indexName = riverName.name(); - typeName = "page"; - bulkSize = 100; - dropThreshold = 10; - } - } - - @Override public void start() { - logger.info("starting twitter stream"); - try { - client.admin().indices().prepareCreate(indexName).execute().actionGet(); - } catch (Exception e) { - if (ExceptionsHelper.unwrapCause(e) instanceof IndexAlreadyExistsException) { - // that's fine - } else if (ExceptionsHelper.unwrapCause(e) instanceof ClusterBlockException) { - // ok, not recovered yet..., lets start indexing and hope we recover by the first bulk - // TODO: a smarter logic can be to register for cluster event listener here, and only start sampling when the block is removed... - } else { - logger.warn("failed to create index [{}], disabling river...", e, indexName); - return; - } - } - currentRequest = client.prepareBulk(); - WikiXMLParser parser = WikiXMLParserFactory.getSAXParser(url); - try { - parser.setPageCallback(new PageCallback()); - } catch (Exception e) { - logger.error("failed to create parser", e); - return; - } - thread = EsExecutors.daemonThreadFactory(settings.globalSettings(), "wikipedia_slurper").newThread(new Parser(parser)); - thread.start(); - } - - @Override public void close() { - logger.info("closing wikipedia river"); - closed = true; - if (thread != null) { - thread.interrupt(); - } - } - - private class Parser implements Runnable { - private final WikiXMLParser parser; - - private Parser(WikiXMLParser parser) { - this.parser = parser; - } - - @Override public void run() { - try { - parser.parse(); - } catch (Exception e) { - if (closed) { - return; - } - logger.error("failed to parse stream", e); - } - } - } - - private class PageCallback implements PageCallbackHandler { - - @Override public void process(WikiPage page) { - if (closed) { - return; - } - String title = stripTitle(page.getTitle()); - if (logger.isTraceEnabled()) { - logger.trace("page {} : {}", page.getID(), page.getTitle()); - } - try { - XContentBuilder builder = XContentFactory.jsonBuilder().startObject(); - builder.field("title", title); - builder.field("text", page.getText()); - builder.field("redirect", page.isRedirect()); - builder.field("special", page.isSpecialPage()); - builder.field("stub", page.isStub()); - builder.field("disambiguation", page.isDisambiguationPage()); - - builder.startArray("category"); - for (String s : page.getCategories()) { - builder.value(s); - } - builder.endArray(); - - builder.startArray("link"); - for (String s : page.getLinks()) { - builder.value(s); - } - builder.endArray(); - - builder.endObject(); - // For now, we index (and not create) since we need to keep track of what we indexed... - currentRequest.add(Requests.indexRequest(indexName).type(typeName).id(page.getID()).create(false).source(builder)); - processBulkIfNeeded(); - } catch (Exception e) { - logger.warn("failed to construct index request", e); - } - } - - private void processBulkIfNeeded() { - if (currentRequest.numberOfActions() >= bulkSize) { - // execute the bulk operation - int currentOnGoingBulks = onGoingBulks.incrementAndGet(); - if (currentOnGoingBulks > dropThreshold) { - // TODO, just wait here!, we can slow down the wikipedia parsing - onGoingBulks.decrementAndGet(); - logger.warn("dropping bulk, [{}] crossed threshold [{}]", onGoingBulks, dropThreshold); - } else { - try { - currentRequest.execute(new ActionListener() { - @Override public void onResponse(BulkResponse bulkResponse) { - onGoingBulks.decrementAndGet(); - } - - @Override public void onFailure(Throwable e) { - logger.warn("failed to execute bulk"); - } - }); - } catch (Exception e) { - logger.warn("failed to process bulk", e); - } - } - currentRequest = client.prepareBulk(); - } - } - } - - - private String stripTitle(String title) { - sb.setLength(0); - sb.append(title); - while (sb.length() > 0 && (sb.charAt(sb.length() - 1) == '\n' || (sb.charAt(sb.length() - 1) == ' '))) { - sb.deleteCharAt(sb.length() - 1); - } - return sb.toString(); - } -} diff --git a/plugins/river/wikipedia/src/main/java/org/elasticsearch/river/wikipedia/WikipediaRiverModule.java b/plugins/river/wikipedia/src/main/java/org/elasticsearch/river/wikipedia/WikipediaRiverModule.java deleted file mode 100644 index e430908dc91..00000000000 --- a/plugins/river/wikipedia/src/main/java/org/elasticsearch/river/wikipedia/WikipediaRiverModule.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.river.wikipedia; - -import org.elasticsearch.common.inject.AbstractModule; -import org.elasticsearch.river.River; - -/** - * @author kimchy (shay.banon) - */ -public class WikipediaRiverModule extends AbstractModule { - - @Override protected void configure() { - bind(River.class).to(WikipediaRiver.class).asEagerSingleton(); - } -} diff --git a/plugins/river/wikipedia/src/main/java/org/elasticsearch/river/wikipedia/support/InfoBox.java b/plugins/river/wikipedia/src/main/java/org/elasticsearch/river/wikipedia/support/InfoBox.java deleted file mode 100644 index 38e9902a206..00000000000 --- a/plugins/river/wikipedia/src/main/java/org/elasticsearch/river/wikipedia/support/InfoBox.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.river.wikipedia.support; - -/** - * A class abstracting Wiki infobox - * - * @author Delip Rao - */ -public class InfoBox { - String infoBoxWikiText = null; - - InfoBox(String infoBoxWikiText) { - this.infoBoxWikiText = infoBoxWikiText; - } - - public String dumpRaw() { - return infoBoxWikiText; - } -} diff --git a/plugins/river/wikipedia/src/main/java/org/elasticsearch/river/wikipedia/support/IteratorHandler.java b/plugins/river/wikipedia/src/main/java/org/elasticsearch/river/wikipedia/support/IteratorHandler.java deleted file mode 100644 index d9b320d967a..00000000000 --- a/plugins/river/wikipedia/src/main/java/org/elasticsearch/river/wikipedia/support/IteratorHandler.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.river.wikipedia.support; - -public class IteratorHandler implements PageCallbackHandler { - - private WikiXMLParser parser = null; - - public IteratorHandler(WikiXMLParser myParser) { - parser = myParser; - } - - public void process(WikiPage page) { - parser.notifyPage(page); - } - -} diff --git a/plugins/river/wikipedia/src/main/java/org/elasticsearch/river/wikipedia/support/PageCallbackHandler.java b/plugins/river/wikipedia/src/main/java/org/elasticsearch/river/wikipedia/support/PageCallbackHandler.java deleted file mode 100644 index 2f6b2a640a2..00000000000 --- a/plugins/river/wikipedia/src/main/java/org/elasticsearch/river/wikipedia/support/PageCallbackHandler.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.elasticsearch.river.wikipedia.support; - -/** - * Interface to allow streamed processing of pages. - * This allows a SAX style processing of Wikipedia XML files. - * The registered callback is executed on each page - * element in the XML file. - *

- * Using callbacks will consume lesser memory, an useful feature for large - * dumps like English and German. - * - * @author Delip Rao - * @see WikiXMLDOMParser - * @see WikiPage - */ - -public interface PageCallbackHandler { - /** - * This is the callback method that should be implemented before - * registering with WikiXMLDOMParser - * - * @param page a wikipedia page object - * @see WikiPage - */ - public void process(WikiPage page); -} diff --git a/plugins/river/wikipedia/src/main/java/org/elasticsearch/river/wikipedia/support/SAXPageCallbackHandler.java b/plugins/river/wikipedia/src/main/java/org/elasticsearch/river/wikipedia/support/SAXPageCallbackHandler.java deleted file mode 100644 index 263d362ca9a..00000000000 --- a/plugins/river/wikipedia/src/main/java/org/elasticsearch/river/wikipedia/support/SAXPageCallbackHandler.java +++ /dev/null @@ -1,60 +0,0 @@ -package org.elasticsearch.river.wikipedia.support; - -import org.xml.sax.Attributes; -import org.xml.sax.helpers.DefaultHandler; - -/** - * A Wrapper class for the PageCallbackHandler - * - * @author Jason Smith - */ -public class SAXPageCallbackHandler extends DefaultHandler { - - private PageCallbackHandler pageHandler; - private WikiPage currentPage; - private String currentTag; - - private String currentWikitext; - private String currentTitle; - private String currentID; - - public SAXPageCallbackHandler(PageCallbackHandler ph) { - pageHandler = ph; - } - - public void startElement(String uri, String name, String qName, Attributes attr) { - currentTag = qName; - if (qName.equals("page")) { - currentPage = new WikiPage(); - currentWikitext = ""; - currentTitle = ""; - currentID = ""; - } - } - - public void endElement(String uri, String name, String qName) { - if (qName.equals("page")) { - currentPage.setTitle(currentTitle); - currentPage.setID(currentID); - currentPage.setWikiText(currentWikitext); - pageHandler.process(currentPage); - } - if (qName.equals("mediawiki")) { - // TODO hasMoreElements() should now return false - } - } - - public void characters(char ch[], int start, int length) { - if (currentTag.equals("title")) { - currentTitle = currentTitle.concat(new String(ch, start, length)); - } - // TODO: To avoid looking at the revision ID, only the first ID is taken. - // I'm not sure how big the block size is in each call to characters(), - // so this may be unsafe. - else if ((currentTag.equals("id")) && (currentID.length() == 0)) { - currentID = new String(ch, start, length); - } else if (currentTag.equals("text")) { - currentWikitext = currentWikitext.concat(new String(ch, start, length)); - } - } -} diff --git a/plugins/river/wikipedia/src/main/java/org/elasticsearch/river/wikipedia/support/WikiPage.java b/plugins/river/wikipedia/src/main/java/org/elasticsearch/river/wikipedia/support/WikiPage.java deleted file mode 100644 index 4943bd7c278..00000000000 --- a/plugins/river/wikipedia/src/main/java/org/elasticsearch/river/wikipedia/support/WikiPage.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.river.wikipedia.support; - -import java.util.List; - -/** - * Data structures for a wikipedia page. - * - * @author Delip Rao - */ -public class WikiPage { - - private String title = null; - private WikiTextParser wikiTextParser = null; - private String id = null; - - /** - * Set the page title. This is not intended for direct use. - * - * @param title - */ - public void setTitle(String title) { - this.title = title; - } - - /** - * Set the wiki text associated with this page. - * This setter also introduces side effects. This is not intended for direct use. - * - * @param wtext wiki-formatted text - */ - public void setWikiText(String wtext) { - wikiTextParser = new WikiTextParser(wtext); - } - - /** - * @return a string containing the page title. - */ - public String getTitle() { - return title; - } - - /** - * @param languageCode - * @return a string containing the title translated - * in the given languageCode. - */ - public String getTranslatedTitle(String languageCode) { - return wikiTextParser.getTranslatedTitle(languageCode); - } - - /** - * @return true if this a disambiguation page. - */ - public boolean isDisambiguationPage() { - if (title.contains("(disambiguation)") || - wikiTextParser.isDisambiguationPage()) - return true; - else return false; - } - - /** - * @return true for "special pages" -- like Category:, Wikipedia:, etc - */ - public boolean isSpecialPage() { - return title.contains(":"); - } - - /** - * Use this method to get the wiki text associated with this page. - * Useful for custom processing the wiki text. - * - * @return a string containing the wiki text. - */ - public String getWikiText() { - return wikiTextParser.getText(); - } - - /** - * @return true if this is a redirection page - */ - public boolean isRedirect() { - return wikiTextParser.isRedirect(); - } - - /** - * @return true if this is a stub page - */ - public boolean isStub() { - return wikiTextParser.isStub(); - } - - /** - * @return the title of the page being redirected to. - */ - public String getRedirectPage() { - return wikiTextParser.getRedirectText(); - } - - /** - * @return plain text stripped of all wiki formatting. - */ - public String getText() { - return wikiTextParser.getPlainText(); - } - - /** - * @return a list of categories the page belongs to, null if this a redirection/disambiguation page - */ - public List getCategories() { - return wikiTextParser.getCategories(); - } - - /** - * @return a list of links contained in the page - */ - public List getLinks() { - return wikiTextParser.getLinks(); - } - - public void setID(String id) { - this.id = id; - } - - public InfoBox getInfoBox() { - return wikiTextParser.getInfoBox(); - } - - public String getID() { - return id; - } -} diff --git a/plugins/river/wikipedia/src/main/java/org/elasticsearch/river/wikipedia/support/WikiPageIterator.java b/plugins/river/wikipedia/src/main/java/org/elasticsearch/river/wikipedia/support/WikiPageIterator.java deleted file mode 100644 index 0a793d5c45d..00000000000 --- a/plugins/river/wikipedia/src/main/java/org/elasticsearch/river/wikipedia/support/WikiPageIterator.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.elasticsearch.river.wikipedia.support; - -import java.util.Vector; - -/** - * A class to iterate the pages after the wikipedia XML file has been parsed with {@link WikiXMLDOMParser}. - * - * @author Delip Rao - * @see WikiXMLDOMParser - */ -public class WikiPageIterator { - - private int currentPage = 0; - private int lastPage = 0; - Vector pageList = null; - - public WikiPageIterator(Vector list) { - pageList = list; - if (pageList != null) - lastPage = pageList.size(); - } - - /** - * @return true if there are more pages to be read - */ - public boolean hasMorePages() { - return (currentPage < lastPage); - } - - /** - * Reset the iterator. - */ - public void reset() { - currentPage = 0; - } - - /** - * Advances the iterator by one position. - * - * @return a {@link WikiPage} - */ - public WikiPage nextPage() { - if (hasMorePages()) - return pageList.elementAt(currentPage++); - return null; - } -} diff --git a/plugins/river/wikipedia/src/main/java/org/elasticsearch/river/wikipedia/support/WikiTextParser.java b/plugins/river/wikipedia/src/main/java/org/elasticsearch/river/wikipedia/support/WikiTextParser.java deleted file mode 100644 index 0459b936838..00000000000 --- a/plugins/river/wikipedia/src/main/java/org/elasticsearch/river/wikipedia/support/WikiTextParser.java +++ /dev/null @@ -1,196 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.river.wikipedia.support; - -import java.util.ArrayList; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * For internal use only -- Used by the {@link WikiPage} class. - * Can also be used as a stand alone class to parse wiki formatted text. - * - * @author Delip Rao - */ -public class WikiTextParser { - - private String wikiText = null; - private ArrayList pageCats = null; - private ArrayList pageLinks = null; - private boolean redirect = false; - private String redirectString = null; - private static Pattern redirectPattern = - Pattern.compile("#REDIRECT\\s+\\[\\[(.*?)\\]\\]"); - private boolean stub = false; - private boolean disambiguation = false; - private static Pattern stubPattern = Pattern.compile("\\-stub\\}\\}"); - private static Pattern disambCatPattern = Pattern.compile("\\{\\{disambig\\}\\}"); - private InfoBox infoBox = null; - - public WikiTextParser(String wtext) { - wikiText = wtext; - Matcher matcher = redirectPattern.matcher(wikiText); - if (matcher.find()) { - redirect = true; - if (matcher.groupCount() == 1) - redirectString = matcher.group(1); - } - matcher = stubPattern.matcher(wikiText); - stub = matcher.find(); - matcher = disambCatPattern.matcher(wikiText); - disambiguation = matcher.find(); - } - - public boolean isRedirect() { - return redirect; - } - - public boolean isStub() { - return stub; - } - - public String getRedirectText() { - return redirectString; - } - - public String getText() { - return wikiText; - } - - public ArrayList getCategories() { - if (pageCats == null) parseCategories(); - return pageCats; - } - - public ArrayList getLinks() { - if (pageLinks == null) parseLinks(); - return pageLinks; - } - - private void parseCategories() { - pageCats = new ArrayList(); - Pattern catPattern = Pattern.compile("\\[\\[Category:(.*?)\\]\\]", Pattern.MULTILINE); - Matcher matcher = catPattern.matcher(wikiText); - while (matcher.find()) { - String[] temp = matcher.group(1).split("\\|"); - pageCats.add(temp[0]); - } - } - - private void parseLinks() { - pageLinks = new ArrayList(); - - Pattern catPattern = Pattern.compile("\\[\\[(.*?)\\]\\]", Pattern.MULTILINE); - Matcher matcher = catPattern.matcher(wikiText); - while (matcher.find()) { - String[] temp = matcher.group(1).split("\\|"); - if (temp == null || temp.length == 0) continue; - String link = temp[0]; - if (link.contains(":") == false) { - pageLinks.add(link); - } - } - } - - public String getPlainText() { - String text = wikiText.replaceAll(">", ">"); - text = text.replaceAll("<", "<"); - text = text.replaceAll(".*?", " "); - text = text.replaceAll("", " "); - text = text.replaceAll("\\{\\{.*?\\}\\}", " "); - text = text.replaceAll("\\[\\[.*?:.*?\\]\\]", " "); - text = text.replaceAll("\\[\\[(.*?)\\]\\]", "$1"); - text = text.replaceAll("\\s(.*?)\\|(\\w+\\s)", " $2"); - text = text.replaceAll("\\[.*?\\]", " "); - text = text.replaceAll("\\'+", ""); - return text; - } - - public InfoBox getInfoBox() { - //parseInfoBox is expensive. Doing it only once like other parse* methods - if (infoBox == null) - infoBox = parseInfoBox(); - return infoBox; - } - - private InfoBox parseInfoBox() { - String INFOBOX_CONST_STR = "{{Infobox"; - int startPos = wikiText.indexOf(INFOBOX_CONST_STR); - if (startPos < 0) return null; - int bracketCount = 2; - int endPos = startPos + INFOBOX_CONST_STR.length(); - for (; endPos < wikiText.length(); endPos++) { - switch (wikiText.charAt(endPos)) { - case '}': - bracketCount--; - break; - case '{': - bracketCount++; - break; - default: - } - if (bracketCount == 0) break; - } - String infoBoxText = wikiText.substring(startPos, endPos + 1); - infoBoxText = stripCite(infoBoxText); // strip clumsy {{cite}} tags - // strip any html formatting - infoBoxText = infoBoxText.replaceAll(">", ">"); - infoBoxText = infoBoxText.replaceAll("<", "<"); - infoBoxText = infoBoxText.replaceAll(".*?", " "); - infoBoxText = infoBoxText.replaceAll("", " "); - return new InfoBox(infoBoxText); - } - - private String stripCite(String text) { - String CITE_CONST_STR = "{{cite"; - int startPos = text.indexOf(CITE_CONST_STR); - if (startPos < 0) return text; - int bracketCount = 2; - int endPos = startPos + CITE_CONST_STR.length(); - for (; endPos < text.length(); endPos++) { - switch (text.charAt(endPos)) { - case '}': - bracketCount--; - break; - case '{': - bracketCount++; - break; - default: - } - if (bracketCount == 0) break; - } - text = text.substring(0, startPos - 1) + text.substring(endPos); - return stripCite(text); - } - - public boolean isDisambiguationPage() { - return disambiguation; - } - - public String getTranslatedTitle(String languageCode) { - Pattern pattern = Pattern.compile("^\\[\\[" + languageCode + ":(.*?)\\]\\]$", Pattern.MULTILINE); - Matcher matcher = pattern.matcher(wikiText); - if (matcher.find()) { - return matcher.group(1); - } - return null; - } - -} diff --git a/plugins/river/wikipedia/src/main/java/org/elasticsearch/river/wikipedia/support/WikiXMLParser.java b/plugins/river/wikipedia/src/main/java/org/elasticsearch/river/wikipedia/support/WikiXMLParser.java deleted file mode 100644 index 253a0fc3dd2..00000000000 --- a/plugins/river/wikipedia/src/main/java/org/elasticsearch/river/wikipedia/support/WikiXMLParser.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.river.wikipedia.support; - -import org.elasticsearch.common.compress.bzip2.CBZip2InputStream; -import org.xml.sax.InputSource; - -import java.io.BufferedReader; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.net.URL; -import java.util.zip.GZIPInputStream; - -/** - * @author Delip Rao - * @author Jason Smith - */ -public abstract class WikiXMLParser { - - private URL wikiXMLFile = null; - protected WikiPage currentPage = null; - - public WikiXMLParser(URL fileName) { - wikiXMLFile = fileName; - } - - /** - * Set a callback handler. The callback is executed every time a - * page instance is detected in the stream. Custom handlers are - * implementations of {@link PageCallbackHandler} - * - * @param handler - * @throws Exception - */ - public abstract void setPageCallback(PageCallbackHandler handler) throws Exception; - - /** - * The main parse method. - * - * @throws Exception - */ - public abstract void parse() throws Exception; - - /** - * @return an iterator to the list of pages - * @throws Exception - */ - public abstract WikiPageIterator getIterator() throws Exception; - - /** - * @return An InputSource created from wikiXMLFile - * @throws Exception - */ - protected InputSource getInputSource() throws Exception { - BufferedReader br = null; - - if (wikiXMLFile.toExternalForm().endsWith(".gz")) { - br = new BufferedReader(new InputStreamReader(new GZIPInputStream(wikiXMLFile.openStream()), "UTF-8")); - } else if (wikiXMLFile.toExternalForm().endsWith(".bz2")) { - InputStream fis = wikiXMLFile.openStream(); - byte[] ignoreBytes = new byte[2]; - fis.read(ignoreBytes); //"B", "Z" bytes from commandline tools - br = new BufferedReader(new InputStreamReader(new CBZip2InputStream(fis), "UTF-8")); - } else { - br = new BufferedReader(new InputStreamReader(wikiXMLFile.openStream(), "UTF-8")); - } - - return new InputSource(br); - } - - protected void notifyPage(WikiPage page) { - currentPage = page; - - } -} diff --git a/plugins/river/wikipedia/src/main/java/org/elasticsearch/river/wikipedia/support/WikiXMLParserFactory.java b/plugins/river/wikipedia/src/main/java/org/elasticsearch/river/wikipedia/support/WikiXMLParserFactory.java deleted file mode 100644 index a7aeb60156c..00000000000 --- a/plugins/river/wikipedia/src/main/java/org/elasticsearch/river/wikipedia/support/WikiXMLParserFactory.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.elasticsearch.river.wikipedia.support; - -import java.net.URL; - -/** - * @author Delip Rao - */ -public class WikiXMLParserFactory { - - public static WikiXMLParser getSAXParser(URL fileName) { - return new WikiXMLSAXParser(fileName); - } - -} diff --git a/plugins/river/wikipedia/src/main/java/org/elasticsearch/river/wikipedia/support/WikiXMLSAXParser.java b/plugins/river/wikipedia/src/main/java/org/elasticsearch/river/wikipedia/support/WikiXMLSAXParser.java deleted file mode 100644 index 3f64715f466..00000000000 --- a/plugins/river/wikipedia/src/main/java/org/elasticsearch/river/wikipedia/support/WikiXMLSAXParser.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.river.wikipedia.support; - -import org.xml.sax.SAXException; -import org.xml.sax.XMLReader; -import org.xml.sax.helpers.XMLReaderFactory; - -import java.net.URL; - -/** - * A SAX Parser for Wikipedia XML dumps. - * - * @author Jason Smith - */ -public class WikiXMLSAXParser extends WikiXMLParser { - - private XMLReader xmlReader; - private PageCallbackHandler pageHandler = null; - - public WikiXMLSAXParser(URL fileName) { - super(fileName); - try { - xmlReader = XMLReaderFactory.createXMLReader(); - pageHandler = new IteratorHandler(this); - } catch (SAXException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - /** - * Set a callback handler. The callback is executed every time a - * page instance is detected in the stream. Custom handlers are - * implementations of {@link PageCallbackHandler} - * - * @param handler - * @throws Exception - */ - public void setPageCallback(PageCallbackHandler handler) throws Exception { - pageHandler = handler; - } - - /** - * The main parse method. - * - * @throws Exception - */ - public void parse() throws Exception { - xmlReader.setContentHandler(new SAXPageCallbackHandler(pageHandler)); - xmlReader.parse(getInputSource()); - } - - /** - * This parser is event driven, so it - * can't provide a page iterator. - */ - @Override - public WikiPageIterator getIterator() throws Exception { - if (!(pageHandler instanceof IteratorHandler)) { - throw new Exception("Custom page callback found. Will not iterate."); - } - throw new UnsupportedOperationException(); - } - - /** - * A convenience method for the Wikipedia SAX interface - * - * @param dumpFile - path to the Wikipedia dump - * @param handler - callback handler used for parsing - * @throws Exception - */ - public static void parseWikipediaDump(URL dumpFile, - PageCallbackHandler handler) throws Exception { - WikiXMLParser wxsp = WikiXMLParserFactory.getSAXParser(dumpFile); - wxsp.setPageCallback(handler); - wxsp.parse(); - } - -} diff --git a/plugins/river/wikipedia/src/main/java/org/elasticsearch/river/wikipedia/support/package-info.java b/plugins/river/wikipedia/src/main/java/org/elasticsearch/river/wikipedia/support/package-info.java deleted file mode 100644 index 9f41cbee375..00000000000 --- a/plugins/river/wikipedia/src/main/java/org/elasticsearch/river/wikipedia/support/package-info.java +++ /dev/null @@ -1,6 +0,0 @@ -/** - * Copied from wikixmlj on 2010-10-03. - * - * Changed from File handling to URL handling, and removed Dom parser. - */ -package org.elasticsearch.river.wikipedia.support; \ No newline at end of file diff --git a/plugins/transport/memcached/build.gradle b/plugins/transport/memcached/build.gradle deleted file mode 100644 index ee1a8a8c0d7..00000000000 --- a/plugins/transport/memcached/build.gradle +++ /dev/null @@ -1,137 +0,0 @@ -dependsOn(':elasticsearch') - -apply plugin: 'java' -apply plugin: 'maven' -apply plugin: 'eclipse' - -archivesBaseName = "elasticsearch-transport-memcached" - -explodedDistDir = new File(distsDir, 'exploded') - -configurations.compile.transitive = true -configurations.testCompile.transitive = true - -// no need to use the resource dir -sourceSets.main.resources.srcDirs 'src/main/java' -sourceSets.test.resources.srcDirs 'src/test/java' - -jar { -// from sourceSets.main.allJava - manifest { - attributes("Implementation-Title": "ElasticSearch", "Implementation-Version": rootProject.version, "Implementation-Date": buildTimeStr) - } -} - -configurations { - dists - distLib { - visible = false - transitive = false - } -} - -repositories { - mavenRepo urls: "http://bleu.west.spy.net/~dustin/m2repo/" -} - -dependencies { - compile project(':elasticsearch') - - testCompile 'spy:memcached:2.5' -} - -task explodedDist(dependsOn: [jar], description: 'Builds the plugin zip file') << { - [explodedDistDir]*.mkdirs() - - copy { - from configurations.distLib - into explodedDistDir - } - - // remove elasticsearch files (compile above adds the elasticsearch one) - ant.delete { fileset(dir: explodedDistDir, includes: "elasticsearch-*.jar") } - - copy { - from libsDir - into explodedDistDir - } - - ant.delete { fileset(dir: explodedDistDir, includes: "elasticsearch-*-javadoc.jar") } - ant.delete { fileset(dir: explodedDistDir, includes: "elasticsearch-*-sources.jar") } -} - -task zip(type: Zip, dependsOn: ['explodedDist']) { - from(explodedDistDir) { - } -} - -task release(dependsOn: [zip]) << { - ant.delete(dir: explodedDistDir) - copy { - from distsDir - into(new File(rootProject.distsDir, "plugins")) - } -} - -configurations { - deployerJars - tools -} - -dependencies { - deployerJars "org.apache.maven.wagon:wagon-http:1.0-beta-2" - tools "com.google.code:jarjar:1.0" -} - -task sourcesJar(type: Jar, dependsOn: classes) { - classifier = 'sources' - from sourceSets.main.allSource -} - -task javadocJar(type: Jar, dependsOn: javadoc) { - classifier = 'javadoc' - from javadoc.destinationDir -} - -artifacts { - archives sourcesJar - archives javadocJar -} - -uploadArchives { - repositories.mavenDeployer { - configuration = configurations.deployerJars - repository(url: rootProject.mavenRepoUrl) { - authentication(userName: rootProject.mavenRepoUser, password: rootProject.mavenRepoPass) - } - snapshotRepository(url: rootProject.mavenSnapshotRepoUrl) { - authentication(userName: rootProject.mavenRepoUser, password: rootProject.mavenRepoPass) - } - - pom.project { - inceptionYear '2009' - name 'elasticsearch-plugins-transport-memcached' - description 'Memcacehd Plugin for ElasticSearch' - licenses { - license { - name 'The Apache Software License, Version 2.0' - url 'http://www.apache.org/licenses/LICENSE-2.0.txt' - distribution 'repo' - } - } - scm { - connection 'git://github.com/elasticsearch/elasticsearch.git' - developerConnection 'git@github.com:elasticsearch/elasticsearch.git' - url 'http://github.com/elasticsearch/elasticsearch' - } - } - - pom.whenConfigured {pom -> - pom.dependencies = pom.dependencies.findAll {dep -> dep.scope != 'test' } // removes the test scoped ones - } - } -} - -eclipseClasspath { - defaultOutputDir = file('build/eclipse-build') -} \ No newline at end of file diff --git a/plugins/transport/memcached/src/main/java/es-plugin.properties b/plugins/transport/memcached/src/main/java/es-plugin.properties deleted file mode 100644 index 108e2a058ff..00000000000 --- a/plugins/transport/memcached/src/main/java/es-plugin.properties +++ /dev/null @@ -1 +0,0 @@ -plugin=org.elasticsearch.plugin.transport.memcached.MemcachedTransportPlugin diff --git a/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/MemcachedRestRequest.java b/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/MemcachedRestRequest.java deleted file mode 100644 index b1e362af5cc..00000000000 --- a/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/MemcachedRestRequest.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.memcached; - -import org.elasticsearch.common.Unicode; -import org.elasticsearch.rest.support.AbstractRestRequest; -import org.elasticsearch.rest.support.RestUtils; - -import java.util.HashMap; -import java.util.Map; - -/** - * @author kimchy (shay.banon) - */ -public class MemcachedRestRequest extends AbstractRestRequest { - - private final Method method; - - private final String uri; - - private final byte[] uriBytes; - - private final int dataSize; - - private boolean binary; - - private final Map params; - - private final String rawPath; - - private byte[] data; - - private int opaque; - - private boolean quiet; - - public MemcachedRestRequest(Method method, String uri, byte[] uriBytes, int dataSize, boolean binary) { - this.method = method; - this.uri = uri; - this.uriBytes = uriBytes; - this.dataSize = dataSize; - this.binary = binary; - this.params = new HashMap(); - int pathEndPos = uri.indexOf('?'); - if (pathEndPos < 0) { - this.rawPath = uri; - } else { - this.rawPath = uri.substring(0, pathEndPos); - RestUtils.decodeQueryString(uri, pathEndPos + 1, params); - } - } - - @Override public Method method() { - return this.method; - } - - @Override public String uri() { - return this.uri; - } - - @Override public String rawPath() { - return this.rawPath; - } - - public byte[] getUriBytes() { - return uriBytes; - } - - public boolean isBinary() { - return binary; - } - - public int getOpaque() { - return opaque; - } - - public void setOpaque(int opaque) { - this.opaque = opaque; - } - - public boolean isQuiet() { - return quiet; - } - - public void setQuiet(boolean quiet) { - this.quiet = quiet; - } - - public int getDataSize() { - return dataSize; - } - - public void setData(byte[] data) { - this.data = data; - } - - @Override public boolean hasContent() { - return data != null; - } - - @Override public boolean contentUnsafe() { - return false; - } - - @Override public byte[] contentByteArray() { - return data; - } - - @Override public int contentByteArrayOffset() { - return 0; - } - - @Override public int contentLength() { - return dataSize; - } - - @Override public String contentAsString() { - return Unicode.fromBytes(data); - } - - @Override public String header(String name) { - return null; - } - - @Override public boolean hasParam(String key) { - return params.containsKey(key); - } - - @Override public String param(String key) { - return params.get(key); - } - - @Override public Map params() { - return params; - } - - @Override public String param(String key, String defaultValue) { - String value = params.get(key); - if (value == null) { - return defaultValue; - } - return value; - } -} diff --git a/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/MemcachedServer.java b/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/MemcachedServer.java deleted file mode 100644 index ef8738698fa..00000000000 --- a/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/MemcachedServer.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.memcached; - -import org.elasticsearch.ElasticSearchException; -import org.elasticsearch.common.component.AbstractLifecycleComponent; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.node.service.NodeService; -import org.elasticsearch.rest.RestController; - -/** - * @author kimchy (shay.banon) - */ -public class MemcachedServer extends AbstractLifecycleComponent { - - private final MemcachedServerTransport transport; - - private final NodeService nodeService; - - private final RestController restController; - - @Inject public MemcachedServer(Settings settings, MemcachedServerTransport transport, - RestController restController, NodeService nodeService) { - super(settings); - this.transport = transport; - this.restController = restController; - this.nodeService = nodeService; - } - - @Override protected void doStart() throws ElasticSearchException { - transport.start(); - if (logger.isInfoEnabled()) { - logger.info("{}", transport.boundAddress()); - } - nodeService.putNodeAttribute("memcached_address", transport.boundAddress().publishAddress().toString()); - } - - @Override protected void doStop() throws ElasticSearchException { - nodeService.removeNodeAttribute("memcached_address"); - transport.stop(); - } - - @Override protected void doClose() throws ElasticSearchException { - transport.close(); - } -} diff --git a/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/MemcachedServerModule.java b/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/MemcachedServerModule.java deleted file mode 100644 index f63f912566a..00000000000 --- a/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/MemcachedServerModule.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.memcached; - -import org.elasticsearch.common.collect.ImmutableList; -import org.elasticsearch.common.inject.AbstractModule; -import org.elasticsearch.common.inject.Module; -import org.elasticsearch.common.inject.Modules; -import org.elasticsearch.common.inject.SpawnModules; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.memcached.netty.NettyMemcachedServerTransportModule; - -/** - * @author kimchy (shay.banon) - */ -public class MemcachedServerModule extends AbstractModule implements SpawnModules { - - private final Settings settings; - - public MemcachedServerModule(Settings settings) { - this.settings = settings; - } - - @Override public Iterable spawnModules() { - return ImmutableList.of(Modules.createModule(settings.getAsClass("memcached.type", NettyMemcachedServerTransportModule.class, "org.elasticsearch.memcached.", "MemcachedServerTransportModule"), settings)); - } - - @SuppressWarnings({"unchecked"}) @Override protected void configure() { - bind(MemcachedServer.class).asEagerSingleton(); - } -} diff --git a/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/MemcachedServerTransport.java b/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/MemcachedServerTransport.java deleted file mode 100644 index 950b7775327..00000000000 --- a/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/MemcachedServerTransport.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.memcached; - -import org.elasticsearch.common.component.LifecycleComponent; -import org.elasticsearch.common.transport.BoundTransportAddress; - -/** - * @author kimchy (shay.banon) - */ -public interface MemcachedServerTransport extends LifecycleComponent { - - BoundTransportAddress boundAddress(); -} diff --git a/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/MemcachedTransportException.java b/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/MemcachedTransportException.java deleted file mode 100644 index 925630cdb70..00000000000 --- a/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/MemcachedTransportException.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.memcached; - -import org.elasticsearch.ElasticSearchException; - -/** - * @author kimchy (shay.banon) - */ -public class MemcachedTransportException extends ElasticSearchException { - - public MemcachedTransportException(String msg) { - super(msg); - } - - public MemcachedTransportException(String msg, Throwable cause) { - super(msg, cause); - } -} diff --git a/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/netty/MemcachedDecoder.java b/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/netty/MemcachedDecoder.java deleted file mode 100644 index 8db4da4288c..00000000000 --- a/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/netty/MemcachedDecoder.java +++ /dev/null @@ -1,242 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.memcached.netty; - -import org.elasticsearch.Version; -import org.elasticsearch.common.Unicode; -import org.elasticsearch.common.logging.ESLogger; -import org.elasticsearch.common.netty.buffer.ChannelBuffer; -import org.elasticsearch.common.netty.buffer.ChannelBuffers; -import org.elasticsearch.common.netty.channel.Channel; -import org.elasticsearch.common.netty.channel.ChannelHandlerContext; -import org.elasticsearch.common.netty.channel.ExceptionEvent; -import org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder; -import org.elasticsearch.memcached.MemcachedRestRequest; -import org.elasticsearch.rest.RestRequest; - -import java.io.StreamCorruptedException; -import java.util.regex.Pattern; - -/** - * @author kimchy (shay.banon) - */ -public class MemcachedDecoder extends FrameDecoder { - - private final ESLogger logger; - - private final Pattern lineSplit = Pattern.compile(" +"); - - public static final byte CR = 13; - public static final byte LF = 10; - public static final byte[] CRLF = new byte[]{CR, LF}; - - private volatile StringBuffer sb = new StringBuffer(); - - private volatile MemcachedRestRequest request; - private volatile boolean ending = false; - - public MemcachedDecoder(ESLogger logger) { - super(false); - this.logger = logger; - } - - @Override protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer) throws Exception { - MemcachedRestRequest request = this.request; - if (request == null) { - buffer.markReaderIndex(); - - if (buffer.readableBytes() < 1) { - return null; - } - short magic = buffer.readUnsignedByte(); - if (magic == 0x80) { - if (buffer.readableBytes() < 23) { - buffer.resetReaderIndex(); // but back magic - return null; - } - short opcode = buffer.readUnsignedByte(); - short keyLength = buffer.readShort(); - short extraLength = buffer.readUnsignedByte(); - short dataType = buffer.readUnsignedByte(); // unused - short reserved = buffer.readShort(); // unused - int totalBodyLength = buffer.readInt(); - int opaque = buffer.readInt(); - long cas = buffer.readLong(); - - // we want the whole of totalBodyLength; otherwise, keep waiting. - if (buffer.readableBytes() < totalBodyLength) { - buffer.resetReaderIndex(); - return null; - } - - buffer.skipBytes(extraLength); // get extras, can be empty - - if (opcode == 0x00) { // GET - byte[] key = new byte[keyLength]; - buffer.readBytes(key); - String uri = Unicode.fromBytes(key); - request = new MemcachedRestRequest(RestRequest.Method.GET, uri, key, -1, true); - request.setOpaque(opaque); - return request; - } else if (opcode == 0x04) { // DELETE - byte[] key = new byte[keyLength]; - buffer.readBytes(key); - String uri = Unicode.fromBytes(key); - request = new MemcachedRestRequest(RestRequest.Method.DELETE, uri, key, -1, true); - request.setOpaque(opaque); - return request; - } else if (opcode == 0x01/* || opcode == 0x11*/) { // SET - byte[] key = new byte[keyLength]; - buffer.readBytes(key); - String uri = Unicode.fromBytes(key); - // the remainder of the message -- that is, totalLength - (keyLength + extraLength) should be the payload - int size = totalBodyLength - keyLength - extraLength; - request = new MemcachedRestRequest(RestRequest.Method.POST, uri, key, size, true); - request.setOpaque(opaque); - byte[] data = new byte[size]; - buffer.readBytes(data, 0, size); - request.setData(data); - request.setQuiet(opcode == 0x11); - return request; - } else if (opcode == 0x0A || opcode == 0x10) { // NOOP or STATS - // TODO once we support setQ we need to wait for them to flush - ChannelBuffer writeBuffer = ChannelBuffers.dynamicBuffer(24); - writeBuffer.writeByte(0x81); // magic - writeBuffer.writeByte(opcode); // opcode - writeBuffer.writeShort(0); // key length - writeBuffer.writeByte(0); // extra length = flags + expiry - writeBuffer.writeByte(0); // data type unused - writeBuffer.writeShort(0x0000); // OK - writeBuffer.writeInt(0); // data length - writeBuffer.writeInt(opaque); // opaque - writeBuffer.writeLong(0); // cas - channel.write(writeBuffer); - return MemcachedDispatcher.IGNORE_REQUEST; - } else if (opcode == 0x07) { // QUIT - channel.disconnect(); - } else { - logger.error("Unsupported opcode [0x{}], ignoring and closing connection", Integer.toHexString(opcode)); - channel.disconnect(); - return null; - } - } else { - buffer.resetReaderIndex(); // reset to get to the first byte - // need to read a header - boolean done = false; - StringBuffer sb = this.sb; - int readableBytes = buffer.readableBytes(); - for (int i = 0; i < readableBytes; i++) { - byte next = buffer.readByte(); - if (!ending && next == CR) { - ending = true; - } else if (ending && next == LF) { - ending = false; - done = true; - break; - } else if (ending) { - logger.error("Corrupt stream, expected LF, found [0x{}]", Integer.toHexString(next)); - throw new StreamCorruptedException("Expecting LF after CR"); - } else { - sb.append((char) next); - } - } - if (!done) { - // let's keep the buffer and bytes read -// buffer.discardReadBytes(); - buffer.markReaderIndex(); - return null; - } - - String[] args = lineSplit.split(sb); - // we read the text, clear it - sb.setLength(0); - - String cmd = args[0]; - if ("get".equals(cmd)) { - request = new MemcachedRestRequest(RestRequest.Method.GET, args[1], null, -1, false); - if (args.length > 3) { - request.setData(Unicode.fromStringAsBytes(args[2])); - } - return request; - } else if ("delete".equals(cmd)) { - request = new MemcachedRestRequest(RestRequest.Method.DELETE, args[1], null, -1, false); - // if (args.length > 3) { - // request.setData(Unicode.fromStringAsBytes(args[2])); - // } - return request; - } else if ("set".equals(cmd)) { - this.request = new MemcachedRestRequest(RestRequest.Method.POST, args[1], null, Integer.parseInt(args[4]), false); - buffer.markReaderIndex(); - } else if ("version".equals(cmd)) { // sent as a noop - byte[] bytes = Version.CURRENT.toString().getBytes(); - ChannelBuffer writeBuffer = ChannelBuffers.dynamicBuffer(bytes.length); - writeBuffer.writeBytes(bytes); - channel.write(writeBuffer); - return MemcachedDispatcher.IGNORE_REQUEST; - } else if ("quit".equals(cmd)) { - if (channel.isConnected()) { // we maybe in the process of clearing the queued bits - channel.disconnect(); - } - } else { - logger.error("Unsupported command [{}], ignoring and closing connection", cmd); - if (channel.isConnected()) { // we maybe in the process of clearing the queued bits - channel.disconnect(); - } - return null; - } - } - } else { - if (buffer.readableBytes() < (request.getDataSize() + 2)) { - return null; - } - byte[] data = new byte[request.getDataSize()]; - buffer.readBytes(data, 0, data.length); - byte next = buffer.readByte(); - if (next == CR) { - next = buffer.readByte(); - if (next == LF) { - request.setData(data); - // reset - this.request = null; - return request; - } else { - this.request = null; - throw new StreamCorruptedException("Expecting separator after data block"); - } - } else { - this.request = null; - throw new StreamCorruptedException("Expecting separator after data block"); - } - } - return null; - } - - @Override public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception { - this.request = null; - this.ending = false; - this.sb.setLength(0); - - if (ctx.getChannel().isConnected()) { - ctx.getChannel().disconnect(); - } - - logger.error("caught exception on memcached decoder", e); - } -} \ No newline at end of file diff --git a/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/netty/MemcachedDispatcher.java b/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/netty/MemcachedDispatcher.java deleted file mode 100644 index 4e130113428..00000000000 --- a/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/netty/MemcachedDispatcher.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.memcached.netty; - -import org.elasticsearch.common.netty.channel.ChannelHandlerContext; -import org.elasticsearch.common.netty.channel.MessageEvent; -import org.elasticsearch.common.netty.channel.SimpleChannelUpstreamHandler; -import org.elasticsearch.memcached.MemcachedRestRequest; -import org.elasticsearch.rest.RestController; -import org.elasticsearch.rest.StringRestResponse; - -import static org.elasticsearch.rest.RestStatus.*; - -/** - * @author kimchy (shay.banon) - */ -public class MemcachedDispatcher extends SimpleChannelUpstreamHandler { - - public static final Object IGNORE_REQUEST = new Object(); - - private final RestController restController; - - public MemcachedDispatcher(RestController restController) { - this.restController = restController; - } - - @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - if (e.getMessage() == IGNORE_REQUEST) { - super.messageReceived(ctx, e); - return; - } - MemcachedRestRequest request = (MemcachedRestRequest) e.getMessage(); - MemcachedRestChannel channel = new MemcachedRestChannel(ctx.getChannel(), request); - - if (!restController.dispatchRequest(request, channel)) { - channel.sendResponse(new StringRestResponse(BAD_REQUEST, "No handler found for uri [" + request.uri() + "] and method [" + request.method() + "]")); - } - - super.messageReceived(ctx, e); - } -} diff --git a/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/netty/MemcachedRestChannel.java b/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/netty/MemcachedRestChannel.java deleted file mode 100644 index a87b24703a7..00000000000 --- a/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/netty/MemcachedRestChannel.java +++ /dev/null @@ -1,176 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.memcached.netty; - -import org.elasticsearch.common.Bytes; -import org.elasticsearch.common.Unicode; -import org.elasticsearch.common.io.stream.CachedStreamOutput; -import org.elasticsearch.common.netty.buffer.ChannelBuffer; -import org.elasticsearch.common.netty.buffer.ChannelBuffers; -import org.elasticsearch.common.netty.channel.Channel; -import org.elasticsearch.common.netty.channel.ChannelFuture; -import org.elasticsearch.common.netty.channel.ChannelFutureListener; -import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.memcached.MemcachedRestRequest; -import org.elasticsearch.memcached.MemcachedTransportException; -import org.elasticsearch.rest.RestChannel; -import org.elasticsearch.rest.RestRequest; -import org.elasticsearch.rest.RestResponse; -import org.elasticsearch.rest.XContentRestResponse; -import org.elasticsearch.transport.netty.NettyTransport; - -import java.nio.charset.Charset; - -/** - * @author kimchy (shay.banon) - */ -public class MemcachedRestChannel implements RestChannel { - - public static final ChannelBuffer CRLF = ChannelBuffers.copiedBuffer("\r\n", Charset.forName("US-ASCII")); - private static final ChannelBuffer VALUE = ChannelBuffers.copiedBuffer("VALUE ", Charset.forName("US-ASCII")); - private static final ChannelBuffer EXISTS = ChannelBuffers.copiedBuffer("EXISTS\r\n", Charset.forName("US-ASCII")); - private static final ChannelBuffer NOT_FOUND = ChannelBuffers.copiedBuffer("NOT_FOUND\r\n", Charset.forName("US-ASCII")); - private static final ChannelBuffer NOT_STORED = ChannelBuffers.copiedBuffer("NOT_STORED\r\n", Charset.forName("US-ASCII")); - private static final ChannelBuffer STORED = ChannelBuffers.copiedBuffer("STORED\r\n", Charset.forName("US-ASCII")); - private static final ChannelBuffer DELETED = ChannelBuffers.copiedBuffer("DELETED\r\n", Charset.forName("US-ASCII")); - private static final ChannelBuffer END = ChannelBuffers.copiedBuffer("END\r\n", Charset.forName("US-ASCII")); - private static final ChannelBuffer OK = ChannelBuffers.copiedBuffer("OK\r\n", Charset.forName("US-ASCII")); - private static final ChannelBuffer ERROR = ChannelBuffers.copiedBuffer("ERROR\r\n", Charset.forName("US-ASCII")); - private static final ChannelBuffer CLIENT_ERROR = ChannelBuffers.copiedBuffer("CLIENT_ERROR\r\n", Charset.forName("US-ASCII")); - - private final Channel channel; - - private final MemcachedRestRequest request; - - public MemcachedRestChannel(Channel channel, MemcachedRestRequest request) { - this.channel = channel; - this.request = request; - } - - @Override public void sendResponse(RestResponse response) { - if (request.isBinary()) { - if (request.isQuiet() && response.status().getStatus() < 500) { - // nothing to send and all is well - return; - } - try { - ChannelBuffer writeBuffer = ChannelBuffers.dynamicBuffer(24 + request.getUriBytes().length + response.contentLength() + 12); - writeBuffer.writeByte(0x81); // magic - if (request.method() == RestRequest.Method.GET) { - writeBuffer.writeByte(0x00); // opcode - } else if (request.method() == RestRequest.Method.POST) { - if (request.isQuiet()) { - writeBuffer.writeByte(0x11); // opcode - } else { - writeBuffer.writeByte(0x01); // opcode - } - } else if (request.method() == RestRequest.Method.DELETE) { - writeBuffer.writeByte(0x04); // opcode - } - short keyLength = request.method() == RestRequest.Method.GET ? (short) request.getUriBytes().length : 0; - writeBuffer.writeShort(keyLength); - int extrasLength = request.method() == RestRequest.Method.GET ? 4 : 0; - writeBuffer.writeByte(extrasLength); // extra length = flags + expiry - writeBuffer.writeByte(0); // data type unused - - if (response.status().getStatus() >= 500) { - // TODO should we use this? - writeBuffer.writeShort(0x0A); // status code - } else { - writeBuffer.writeShort(0x0000); // OK - } - - int dataLength = request.method() == RestRequest.Method.GET ? response.contentLength() : 0; - writeBuffer.writeInt(dataLength + keyLength + extrasLength); // data length - writeBuffer.writeInt(request.getOpaque()); // opaque - writeBuffer.writeLong(0); // cas - - if (extrasLength > 0) { - writeBuffer.writeShort(0); - writeBuffer.writeShort(0); - } - if (keyLength > 0) { - writeBuffer.writeBytes(request.getUriBytes()); - } - ChannelFutureListener releaseContentListener = null; - if (dataLength > 0) { - if (response instanceof XContentRestResponse) { - // if its a builder based response, and it was created with a CachedStreamOutput, we can release it - // after we write the response, and no need to do an extra copy because its not thread safe - XContentBuilder builder = ((XContentRestResponse) response).builder(); - if (builder.payload() instanceof CachedStreamOutput.Entry) { - releaseContentListener = new NettyTransport.CacheFutureListener((CachedStreamOutput.Entry) builder.payload()); - ChannelBuffer buf = ChannelBuffers.wrappedBuffer(builder.underlyingBytes(), 0, builder.underlyingBytesLength()); - writeBuffer = ChannelBuffers.wrappedBuffer(writeBuffer, buf); - } else if (response.contentThreadSafe()) { - ChannelBuffer buf = ChannelBuffers.wrappedBuffer(builder.underlyingBytes(), 0, builder.underlyingBytesLength()); - writeBuffer = ChannelBuffers.wrappedBuffer(writeBuffer, buf); - } else { - writeBuffer.writeBytes(response.content(), 0, response.contentLength()); - } - } else { - if (response.contentThreadSafe()) { - ChannelBuffer buf = ChannelBuffers.wrappedBuffer(response.content(), 0, response.contentLength()); - writeBuffer = ChannelBuffers.wrappedBuffer(writeBuffer, buf); - } else { - writeBuffer.writeBytes(response.content(), 0, response.contentLength()); - } - } - } - ChannelFuture future = channel.write(writeBuffer); - if (releaseContentListener != null) { - future.addListener(releaseContentListener); - } - } catch (Exception e) { - throw new MemcachedTransportException("Failed to write response", e); - } - } else { - if (response.status().getStatus() >= 500) { - channel.write(ERROR.duplicate()); - } else { - if (request.method() == RestRequest.Method.POST) { - // TODO this is SET, can we send a payload? - channel.write(STORED.duplicate()); - } else if (request.method() == RestRequest.Method.DELETE) { - channel.write(DELETED.duplicate()); - } else { // GET - try { - ChannelBuffer writeBuffer = ChannelBuffers.dynamicBuffer(response.contentLength() + 512); - writeBuffer.writeBytes(VALUE.duplicate()); - writeBuffer.writeBytes(Unicode.fromStringAsBytes(request.uri())); - writeBuffer.writeByte(' '); - writeBuffer.writeByte('0'); - writeBuffer.writeByte(' '); - writeBuffer.writeBytes(Bytes.itoa(response.contentLength())); - writeBuffer.writeByte('\r'); - writeBuffer.writeByte('\n'); - writeBuffer.writeBytes(response.content(), 0, response.contentLength()); - writeBuffer.writeByte('\r'); - writeBuffer.writeByte('\n'); - writeBuffer.writeBytes(END.duplicate()); - channel.write(writeBuffer); - } catch (Exception e) { - throw new MemcachedTransportException("Failed to write 'get' response", e); - } - } - } - } - } -} diff --git a/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/netty/NettyMemcachedServerTransport.java b/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/netty/NettyMemcachedServerTransport.java deleted file mode 100644 index 54573670734..00000000000 --- a/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/netty/NettyMemcachedServerTransport.java +++ /dev/null @@ -1,211 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.memcached.netty; - -import org.elasticsearch.ElasticSearchException; -import org.elasticsearch.common.component.AbstractLifecycleComponent; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.netty.OpenChannelsHandler; -import org.elasticsearch.common.netty.bootstrap.ServerBootstrap; -import org.elasticsearch.common.netty.channel.Channel; -import org.elasticsearch.common.netty.channel.ChannelPipeline; -import org.elasticsearch.common.netty.channel.ChannelPipelineFactory; -import org.elasticsearch.common.netty.channel.Channels; -import org.elasticsearch.common.netty.channel.socket.nio.NioServerSocketChannelFactory; -import org.elasticsearch.common.netty.channel.socket.oio.OioServerSocketChannelFactory; -import org.elasticsearch.common.network.NetworkService; -import org.elasticsearch.common.network.NetworkUtils; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.transport.BoundTransportAddress; -import org.elasticsearch.common.transport.InetSocketTransportAddress; -import org.elasticsearch.common.transport.PortsRange; -import org.elasticsearch.common.unit.ByteSizeValue; -import org.elasticsearch.http.BindHttpException; -import org.elasticsearch.memcached.MemcachedServerTransport; -import org.elasticsearch.rest.RestController; -import org.elasticsearch.transport.BindTransportException; - -import java.io.IOException; -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.util.concurrent.Executors; -import java.util.concurrent.atomic.AtomicReference; - -import static org.elasticsearch.common.network.NetworkService.TcpSettings.*; -import static org.elasticsearch.common.util.concurrent.EsExecutors.*; - -/** - * @author kimchy (shay.banon) - */ -public class NettyMemcachedServerTransport extends AbstractLifecycleComponent implements MemcachedServerTransport { - - private final RestController restController; - - private final NetworkService networkService; - - private final int workerCount; - - private final boolean blockingServer; - - private final String port; - - private final String bindHost; - - private final String publishHost; - - private final Boolean tcpNoDelay; - - private final Boolean tcpKeepAlive; - - private final Boolean reuseAddress; - - private final ByteSizeValue tcpSendBufferSize; - - private final ByteSizeValue tcpReceiveBufferSize; - - private volatile ServerBootstrap serverBootstrap; - - private volatile BoundTransportAddress boundAddress; - - private volatile Channel serverChannel; - - private volatile OpenChannelsHandler serverOpenChannels; - - @Inject public NettyMemcachedServerTransport(Settings settings, RestController restController, NetworkService networkService) { - super(settings); - this.restController = restController; - this.networkService = networkService; - - this.workerCount = componentSettings.getAsInt("worker_count", Runtime.getRuntime().availableProcessors() * 2); - this.blockingServer = componentSettings.getAsBoolean("memcached.blocking_server", settings.getAsBoolean(TCP_BLOCKING_SERVER, settings.getAsBoolean(TCP_BLOCKING, false))); - this.port = componentSettings.get("port", settings.get("memcached.port", "11211-11311")); - this.bindHost = componentSettings.get("bind_host"); - this.publishHost = componentSettings.get("publish_host"); - this.tcpNoDelay = componentSettings.getAsBoolean("tcp_no_delay", settings.getAsBoolean(TCP_NO_DELAY, true)); - this.tcpKeepAlive = componentSettings.getAsBoolean("tcp_keep_alive", settings.getAsBoolean(TCP_KEEP_ALIVE, true)); - this.reuseAddress = componentSettings.getAsBoolean("reuse_address", settings.getAsBoolean(TCP_REUSE_ADDRESS, NetworkUtils.defaultReuseAddress())); - this.tcpSendBufferSize = componentSettings.getAsBytesSize("tcp_send_buffer_size", settings.getAsBytesSize(TCP_SEND_BUFFER_SIZE, TCP_DEFAULT_SEND_BUFFER_SIZE)); - this.tcpReceiveBufferSize = componentSettings.getAsBytesSize("tcp_receive_buffer_size", settings.getAsBytesSize(TCP_RECEIVE_BUFFER_SIZE, TCP_DEFAULT_RECEIVE_BUFFER_SIZE)); - } - - @Override public BoundTransportAddress boundAddress() { - return boundAddress; - } - - @Override protected void doStart() throws ElasticSearchException { - this.serverOpenChannels = new OpenChannelsHandler(logger); - - if (blockingServer) { - serverBootstrap = new ServerBootstrap(new OioServerSocketChannelFactory( - Executors.newCachedThreadPool(daemonThreadFactory(settings, "memcached_server_boss")), - Executors.newCachedThreadPool(daemonThreadFactory(settings, "memcached_server_worker")) - )); - } else { - serverBootstrap = new ServerBootstrap(new NioServerSocketChannelFactory( - Executors.newCachedThreadPool(daemonThreadFactory(settings, "memcached_server_boss")), - Executors.newCachedThreadPool(daemonThreadFactory(settings, "memcached_server_worker")), - workerCount)); - } - - ChannelPipelineFactory pipelineFactory = new ChannelPipelineFactory() { - @Override public ChannelPipeline getPipeline() throws Exception { - ChannelPipeline pipeline = Channels.pipeline(); - pipeline.addLast("openChannels", serverOpenChannels); - pipeline.addLast("decoder", new MemcachedDecoder(logger)); - pipeline.addLast("dispatcher", new MemcachedDispatcher(restController)); - return pipeline; - } - }; - - serverBootstrap.setPipelineFactory(pipelineFactory); - - if (tcpNoDelay != null) { - serverBootstrap.setOption("child.tcpNoDelay", tcpNoDelay); - } - if (tcpKeepAlive != null) { - serverBootstrap.setOption("child.keepAlive", tcpKeepAlive); - } - if (tcpSendBufferSize != null) { - serverBootstrap.setOption("child.sendBufferSize", tcpSendBufferSize.bytes()); - } - if (tcpReceiveBufferSize != null) { - serverBootstrap.setOption("child.receiveBufferSize", tcpReceiveBufferSize.bytes()); - } - if (reuseAddress != null) { - serverBootstrap.setOption("reuseAddress", reuseAddress); - serverBootstrap.setOption("child.reuseAddress", reuseAddress); - } - - // Bind and start to accept incoming connections. - InetAddress hostAddressX; - try { - hostAddressX = networkService.resolveBindHostAddress(bindHost); - } catch (IOException e) { - throw new BindHttpException("Failed to resolve host [" + bindHost + "]", e); - } - final InetAddress hostAddress = hostAddressX; - - PortsRange portsRange = new PortsRange(port); - final AtomicReference lastException = new AtomicReference(); - boolean success = portsRange.iterate(new PortsRange.PortCallback() { - @Override public boolean onPortNumber(int portNumber) { - try { - serverChannel = serverBootstrap.bind(new InetSocketAddress(hostAddress, portNumber)); - } catch (Exception e) { - lastException.set(e); - return false; - } - return true; - } - }); - if (!success) { - throw new BindHttpException("Failed to bind to [" + port + "]", lastException.get()); - } - - InetSocketAddress boundAddress = (InetSocketAddress) serverChannel.getLocalAddress(); - InetSocketAddress publishAddress; - try { - publishAddress = new InetSocketAddress(networkService.resolvePublishHostAddress(publishHost), boundAddress.getPort()); - } catch (Exception e) { - throw new BindTransportException("Failed to resolve publish address", e); - } - this.boundAddress = new BoundTransportAddress(new InetSocketTransportAddress(boundAddress), new InetSocketTransportAddress(publishAddress)); - } - - @Override protected void doStop() throws ElasticSearchException { - if (serverChannel != null) { - serverChannel.close().awaitUninterruptibly(); - serverChannel = null; - } - - if (serverOpenChannels != null) { - serverOpenChannels.close(); - serverOpenChannels = null; - } - - if (serverBootstrap != null) { - serverBootstrap.releaseExternalResources(); - serverBootstrap = null; - } - } - - @Override protected void doClose() throws ElasticSearchException { - } -} diff --git a/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/netty/NettyMemcachedServerTransportModule.java b/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/netty/NettyMemcachedServerTransportModule.java deleted file mode 100644 index ecc7966c48c..00000000000 --- a/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/netty/NettyMemcachedServerTransportModule.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.memcached.netty; - -import org.elasticsearch.common.inject.AbstractModule; -import org.elasticsearch.memcached.MemcachedServerTransport; - -/** - * @author kimchy (shay.banon) - */ -public class NettyMemcachedServerTransportModule extends AbstractModule { - - @Override protected void configure() { - bind(MemcachedServerTransport.class).to(NettyMemcachedServerTransport.class).asEagerSingleton(); - } -} \ No newline at end of file diff --git a/plugins/transport/memcached/src/main/java/org/elasticsearch/plugin/transport/memcached/MemcachedTransportPlugin.java b/plugins/transport/memcached/src/main/java/org/elasticsearch/plugin/transport/memcached/MemcachedTransportPlugin.java deleted file mode 100644 index 5ca1d4f38dd..00000000000 --- a/plugins/transport/memcached/src/main/java/org/elasticsearch/plugin/transport/memcached/MemcachedTransportPlugin.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.plugin.transport.memcached; - -import org.elasticsearch.common.component.LifecycleComponent; -import org.elasticsearch.common.inject.Module; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.memcached.MemcachedServer; -import org.elasticsearch.memcached.MemcachedServerModule; -import org.elasticsearch.plugins.AbstractPlugin; - -import java.util.Collection; - -import static org.elasticsearch.common.collect.Lists.*; - -/** - * @author kimchy (shay.banon) - */ -public class MemcachedTransportPlugin extends AbstractPlugin { - - private final Settings settings; - - public MemcachedTransportPlugin(Settings settings) { - this.settings = settings; - } - - @Override public String name() { - return "transport-memcached"; - } - - @Override public String description() { - return "Exports elasticsearch APIs over memcached"; - } - - @Override public Collection> modules() { - Collection> modules = newArrayList(); - if (settings.getAsBoolean("memcached.enabled", true)) { - modules.add(MemcachedServerModule.class); - } - return modules; - } - - @Override public Collection> services() { - Collection> services = newArrayList(); - if (settings.getAsBoolean("memcached.enabled", true)) { - services.add(MemcachedServer.class); - } - return services; - } -} \ No newline at end of file diff --git a/plugins/transport/memcached/src/test/java/org/elasticsearch/memcached/test/AbstractMemcachedActionsTests.java b/plugins/transport/memcached/src/test/java/org/elasticsearch/memcached/test/AbstractMemcachedActionsTests.java deleted file mode 100644 index ea08c82083e..00000000000 --- a/plugins/transport/memcached/src/test/java/org/elasticsearch/memcached/test/AbstractMemcachedActionsTests.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.memcached.test; - -import net.spy.memcached.MemcachedClient; -import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; -import org.elasticsearch.common.network.NetworkUtils; -import org.elasticsearch.node.Node; -import org.hamcrest.Matchers; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import java.io.IOException; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; - -import static org.elasticsearch.common.settings.ImmutableSettings.*; -import static org.elasticsearch.common.xcontent.XContentFactory.*; -import static org.elasticsearch.node.NodeBuilder.*; -import static org.hamcrest.MatcherAssert.*; -import static org.hamcrest.Matchers.*; - -/** - * @author kimchy (shay.banon) - */ -public abstract class AbstractMemcachedActionsTests { - - private Node node; - - private MemcachedClient memcachedClient; - - @BeforeMethod - public void setup() throws IOException { - node = nodeBuilder().settings(settingsBuilder() - .put("cluster.name", "test-cluster-" + NetworkUtils.getLocalAddress()) - .put("gateway.type", "none")).node(); - memcachedClient = createMemcachedClient(); - } - - protected abstract MemcachedClient createMemcachedClient() throws IOException; - - @AfterMethod - public void tearDown() { - memcachedClient.shutdown(); - node.close(); - } - - @Test public void testSimpleOperations() throws Exception { - // TODO seems to use SetQ, which is not really supported yet -// List> setResults = Lists.newArrayList(); -// -// for (int i = 0; i < 10; i++) { -// setResults.add(memcachedClient.set("/test/person/" + i, 0, jsonBuilder().startObject().field("test", "value").endObject().copiedBytes())); -// } -// -// for (Future setResult : setResults) { -// assertThat(setResult.get(10, TimeUnit.SECONDS), equalTo(true)); -// } - - Future setResult = memcachedClient.set("/test/person/1", 0, jsonBuilder().startObject().field("test", "value").endObject().copiedBytes()); - assertThat(setResult.get(10, TimeUnit.SECONDS), equalTo(true)); - - ClusterHealthResponse health = node.client().admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet(); - assertThat(health.timedOut(), equalTo(false)); - - String getResult = (String) memcachedClient.get("/_refresh"); - System.out.println("REFRESH " + getResult); - assertThat(getResult, Matchers.containsString("\"total\":10")); - assertThat(getResult, Matchers.containsString("\"successful\":5")); - assertThat(getResult, Matchers.containsString("\"failed\":0")); - - getResult = (String) memcachedClient.get("/test/person/1"); - System.out.println("GET " + getResult); - assertThat(getResult, Matchers.containsString("\"_index\":\"test\"")); - assertThat(getResult, Matchers.containsString("\"_type\":\"person\"")); - assertThat(getResult, Matchers.containsString("\"_id\":\"1\"")); - - Future deleteResult = memcachedClient.delete("/test/person/1"); - assertThat(deleteResult.get(10, TimeUnit.SECONDS), equalTo(true)); - - getResult = (String) memcachedClient.get("/_refresh"); - System.out.println("REFRESH " + getResult); - assertThat(getResult, Matchers.containsString("\"total\":10")); - assertThat(getResult, Matchers.containsString("\"successful\":5")); - assertThat(getResult, Matchers.containsString("\"failed\":0")); - - getResult = (String) memcachedClient.get("/test/person/1"); - System.out.println("GET " + getResult); - } -} diff --git a/plugins/transport/memcached/src/test/java/org/elasticsearch/memcached/test/BinaryMemcachedActionTests.java b/plugins/transport/memcached/src/test/java/org/elasticsearch/memcached/test/BinaryMemcachedActionTests.java deleted file mode 100644 index 3a87b2dd3f1..00000000000 --- a/plugins/transport/memcached/src/test/java/org/elasticsearch/memcached/test/BinaryMemcachedActionTests.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.memcached.test; - -import net.spy.memcached.AddrUtil; -import net.spy.memcached.BinaryConnectionFactory; -import net.spy.memcached.MemcachedClient; -import org.testng.annotations.Test; - -import java.io.IOException; - -/** - * @author kimchy (shay.banon) - */ -@Test -public class BinaryMemcachedActionTests extends AbstractMemcachedActionsTests { - - @Override protected MemcachedClient createMemcachedClient() throws IOException { - return new MemcachedClient(new BinaryConnectionFactory(), AddrUtil.getAddresses("localhost:11211")); - } -} \ No newline at end of file diff --git a/plugins/transport/memcached/src/test/java/org/elasticsearch/memcached/test/TextMemcachedActionTests.java b/plugins/transport/memcached/src/test/java/org/elasticsearch/memcached/test/TextMemcachedActionTests.java deleted file mode 100644 index 7c8a4a80407..00000000000 --- a/plugins/transport/memcached/src/test/java/org/elasticsearch/memcached/test/TextMemcachedActionTests.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.memcached.test; - -import net.spy.memcached.AddrUtil; -import net.spy.memcached.MemcachedClient; -import org.testng.annotations.Test; - -import java.io.IOException; - -/** - * @author kimchy (shay.banon) - */ -@Test -public class TextMemcachedActionTests extends AbstractMemcachedActionsTests { - - @Override protected MemcachedClient createMemcachedClient() throws IOException { - return new MemcachedClient(AddrUtil.getAddresses("localhost:11211")); - } -} diff --git a/plugins/transport/thrift/build.gradle b/plugins/transport/thrift/build.gradle deleted file mode 100644 index e4631e8e971..00000000000 --- a/plugins/transport/thrift/build.gradle +++ /dev/null @@ -1,140 +0,0 @@ -dependsOn(':elasticsearch') - -apply plugin: 'java' -apply plugin: 'maven' -apply plugin: 'eclipse' - -archivesBaseName = "elasticsearch-transport-thrift" - -explodedDistDir = new File(distsDir, 'exploded') - -configurations.compile.transitive = true -configurations.testCompile.transitive = true - -sourceSets.main.java.srcDirs 'src/main/java', 'src/main/gen-java' - -// no need to use the resource dir -sourceSets.main.resources.srcDirs 'src/main/java' -sourceSets.test.resources.srcDirs 'src/test/java' - -jar { -// from sourceSets.main.allJava - manifest { - attributes("Implementation-Title": "ElasticSearch", "Implementation-Version": rootProject.version, "Implementation-Date": buildTimeStr) - } -} - -configurations { - dists - distLib { - visible = false - transitive = false - } -} - -dependencies { - compile project(':elasticsearch') - compile 'org.elasticsearch:es-libthrift:0.6.1' - compile 'org.slf4j:slf4j-api:1.5.11' - compile('org.slf4j:slf4j-log4j12:1.5.11') { transitive = false } - - distLib("org.elasticsearch:es-libthrift:0.6.1") { transitive = false } - distLib 'org.slf4j:slf4j-api:1.5.11' - distLib('org.slf4j:slf4j-log4j12:1.5.11') { transitive = false } -} - -task explodedDist(dependsOn: [jar], description: 'Builds the plugin zip file') << { - [explodedDistDir]*.mkdirs() - - copy { - from configurations.distLib - into explodedDistDir - } - - // remove elasticsearch files (compile above adds the elasticsearch one) - ant.delete { fileset(dir: explodedDistDir, includes: "elasticsearch-*.jar") } - - copy { - from libsDir - into explodedDistDir - } - - ant.delete { fileset(dir: explodedDistDir, includes: "elasticsearch-*-javadoc.jar") } - ant.delete { fileset(dir: explodedDistDir, includes: "elasticsearch-*-sources.jar") } -} - -task zip(type: Zip, dependsOn: ['explodedDist']) { - from(explodedDistDir) { - } -} - -task release(dependsOn: [zip]) << { - ant.delete(dir: explodedDistDir) - copy { - from distsDir - into(new File(rootProject.distsDir, "plugins")) - } -} - -configurations { - deployerJars - tools -} - -dependencies { - deployerJars "org.apache.maven.wagon:wagon-http:1.0-beta-2" - tools "com.google.code:jarjar:1.0" -} - -task sourcesJar(type: Jar, dependsOn: classes) { - classifier = 'sources' - from sourceSets.main.allSource -} - -task javadocJar(type: Jar, dependsOn: javadoc) { - classifier = 'javadoc' - from javadoc.destinationDir -} - -artifacts { - archives sourcesJar - archives javadocJar -} - -uploadArchives { - repositories.mavenDeployer { - configuration = configurations.deployerJars - repository(url: rootProject.mavenRepoUrl) { - authentication(userName: rootProject.mavenRepoUser, password: rootProject.mavenRepoPass) - } - snapshotRepository(url: rootProject.mavenSnapshotRepoUrl) { - authentication(userName: rootProject.mavenRepoUser, password: rootProject.mavenRepoPass) - } - - pom.project { - inceptionYear '2009' - name 'elasticsearch-plugins-transport-thrift' - description 'Thrift Plugin for ElasticSearch' - licenses { - license { - name 'The Apache Software License, Version 2.0' - url 'http://www.apache.org/licenses/LICENSE-2.0.txt' - distribution 'repo' - } - } - scm { - connection 'git://github.com/elasticsearch/elasticsearch.git' - developerConnection 'git@github.com:elasticsearch/elasticsearch.git' - url 'http://github.com/elasticsearch/elasticsearch' - } - } - - pom.whenConfigured {pom -> - pom.dependencies = pom.dependencies.findAll {dep -> dep.scope != 'test' } // removes the test scoped ones - } - } -} - -eclipseClasspath { - defaultOutputDir = file('build/eclipse-build') -} \ No newline at end of file diff --git a/plugins/transport/thrift/elasticsearch.thrift b/plugins/transport/thrift/elasticsearch.thrift deleted file mode 100644 index 45a5ae4857a..00000000000 --- a/plugins/transport/thrift/elasticsearch.thrift +++ /dev/null @@ -1,81 +0,0 @@ -namespace java org.elasticsearch.thrift -namespace csharp ElasticSearch.Thrift -namespace cpp elasticsearch.thrift -namespace rb ElasticSearch.Thrift -namespace py elasticsearch -namespace perl Elasticsearch - -enum Method { - GET = 0, - PUT = 1, - POST = 2, - DELETE = 3, - HEAD = 4, - OPTIONS = 5 -} - -struct RestRequest { - 1: required Method method, - 2: required string uri - 3: optional map parameters - 4: optional map headers - 5: optional binary body -} - -enum Status { - CONT = 100, - SWITCHING_PROTOCOLS = 101, - OK = 200, - CREATED = 201, - ACCEPTED = 202, - NON_AUTHORITATIVE_INFORMATION = 203, - NO_CONTENT = 204, - RESET_CONTENT = 205, - PARTIAL_CONTENT = 206, - MULTI_STATUS = 207, - MULTIPLE_CHOICES = 300, - MOVED_PERMANENTLY = 301, - FOUND = 302, - SEE_OTHER = 303, - NOT_MODIFIED = 304, - USE_PROXY = 305, - TEMPORARY_REDIRECT = 307, - BAD_REQUEST = 400, - UNAUTHORIZED = 401, - PAYMENT_REQUIRED = 402, - FORBIDDEN = 403, - NOT_FOUND = 404, - METHOD_NOT_ALLOWED = 405, - NOT_ACCEPTABLE = 406, - PROXY_AUTHENTICATION = 407, - REQUEST_TIMEOUT = 408, - CONFLICT = 409, - GONE = 410, - LENGTH_REQUIRED = 411, - PRECONDITION_FAILED = 412, - REQUEST_ENTITY_TOO_LARGE = 413, - REQUEST_URI_TOO_LONG = 414, - UNSUPPORTED_MEDIA_TYPE = 415, - REQUESTED_RANGE_NOT_SATISFIED = 416, - EXPECTATION_FAILED = 417, - UNPROCESSABLE_ENTITY = 422, - LOCKED = 423, - FAILED_DEPENDENCY = 424, - INTERNAL_SERVER_ERROR = 500, - NOT_IMPLEMENTED = 501, - BAD_GATEWAY = 502, - SERVICE_UNAVAILABLE = 503, - GATEWAY_TIMEOUT = 504, - INSUFFICIENT_STORAGE = 506 -} - -struct RestResponse { - 1: required Status status, - 2: optional map headers, - 3: optional binary body -} - -service Rest { - RestResponse execute(1:required RestRequest request) -} - diff --git a/plugins/transport/thrift/src/main/gen-java/org/elasticsearch/thrift/Method.java b/plugins/transport/thrift/src/main/gen-java/org/elasticsearch/thrift/Method.java deleted file mode 100644 index 45f01c00628..00000000000 --- a/plugins/transport/thrift/src/main/gen-java/org/elasticsearch/thrift/Method.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * Autogenerated by Thrift - * - * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING - */ -package org.elasticsearch.thrift; - - -public enum Method implements org.apache.thrift.TEnum { - GET(0), - PUT(1), - POST(2), - DELETE(3), - HEAD(4), - OPTIONS(5); - - private final int value; - - private Method(int value) { - this.value = value; - } - - /** - * Get the integer value of this enum value, as defined in the Thrift IDL. - */ - public int getValue() { - return value; - } - - /** - * Find a the enum type by its integer value, as defined in the Thrift IDL. - * - * @return null if the value is not found. - */ - public static Method findByValue(int value) { - switch (value) { - case 0: - return GET; - case 1: - return PUT; - case 2: - return POST; - case 3: - return DELETE; - case 4: - return HEAD; - case 5: - return OPTIONS; - default: - return null; - } - } -} diff --git a/plugins/transport/thrift/src/main/gen-java/org/elasticsearch/thrift/Rest.java b/plugins/transport/thrift/src/main/gen-java/org/elasticsearch/thrift/Rest.java deleted file mode 100644 index 5487497728f..00000000000 --- a/plugins/transport/thrift/src/main/gen-java/org/elasticsearch/thrift/Rest.java +++ /dev/null @@ -1,823 +0,0 @@ -/** - * Autogenerated by Thrift - * - * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING - */ -package org.elasticsearch.thrift; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Collections; -import java.util.EnumMap; -import java.util.EnumSet; -import java.util.HashMap; -import java.util.Map; - -public class Rest { - - public interface Iface { - - public RestResponse execute(RestRequest request) throws org.apache.thrift.TException; - - } - - public interface AsyncIface { - - public void execute(RestRequest request, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException; - - } - - public static class Client implements org.apache.thrift.TServiceClient, Iface { - public static class Factory implements org.apache.thrift.TServiceClientFactory { - public Factory() { - } - - public Client getClient(org.apache.thrift.protocol.TProtocol prot) { - return new Client(prot); - } - - public Client getClient(org.apache.thrift.protocol.TProtocol iprot, org.apache.thrift.protocol.TProtocol oprot) { - return new Client(iprot, oprot); - } - } - - public Client(org.apache.thrift.protocol.TProtocol prot) { - this(prot, prot); - } - - public Client(org.apache.thrift.protocol.TProtocol iprot, org.apache.thrift.protocol.TProtocol oprot) { - iprot_ = iprot; - oprot_ = oprot; - } - - protected org.apache.thrift.protocol.TProtocol iprot_; - protected org.apache.thrift.protocol.TProtocol oprot_; - - protected int seqid_; - - public org.apache.thrift.protocol.TProtocol getInputProtocol() { - return this.iprot_; - } - - public org.apache.thrift.protocol.TProtocol getOutputProtocol() { - return this.oprot_; - } - - public RestResponse execute(RestRequest request) throws org.apache.thrift.TException { - send_execute(request); - return recv_execute(); - } - - public void send_execute(RestRequest request) throws org.apache.thrift.TException { - oprot_.writeMessageBegin(new org.apache.thrift.protocol.TMessage("execute", org.apache.thrift.protocol.TMessageType.CALL, ++seqid_)); - execute_args args = new execute_args(); - args.setRequest(request); - args.write(oprot_); - oprot_.writeMessageEnd(); - oprot_.getTransport().flush(); - } - - public RestResponse recv_execute() throws org.apache.thrift.TException { - org.apache.thrift.protocol.TMessage msg = iprot_.readMessageBegin(); - if (msg.type == org.apache.thrift.protocol.TMessageType.EXCEPTION) { - org.apache.thrift.TApplicationException x = org.apache.thrift.TApplicationException.read(iprot_); - iprot_.readMessageEnd(); - throw x; - } - if (msg.seqid != seqid_) { - throw new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.BAD_SEQUENCE_ID, "execute failed: out of sequence response"); - } - execute_result result = new execute_result(); - result.read(iprot_); - iprot_.readMessageEnd(); - if (result.isSetSuccess()) { - return result.success; - } - throw new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.MISSING_RESULT, "execute failed: unknown result"); - } - - } - - public static class AsyncClient extends org.apache.thrift.async.TAsyncClient implements AsyncIface { - public static class Factory implements org.apache.thrift.async.TAsyncClientFactory { - private org.apache.thrift.async.TAsyncClientManager clientManager; - private org.apache.thrift.protocol.TProtocolFactory protocolFactory; - - public Factory(org.apache.thrift.async.TAsyncClientManager clientManager, org.apache.thrift.protocol.TProtocolFactory protocolFactory) { - this.clientManager = clientManager; - this.protocolFactory = protocolFactory; - } - - public AsyncClient getAsyncClient(org.apache.thrift.transport.TNonblockingTransport transport) { - return new AsyncClient(protocolFactory, clientManager, transport); - } - } - - public AsyncClient(org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.async.TAsyncClientManager clientManager, org.apache.thrift.transport.TNonblockingTransport transport) { - super(protocolFactory, clientManager, transport); - } - - public void execute(RestRequest request, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException { - checkReady(); - execute_call method_call = new execute_call(request, resultHandler, this, protocolFactory, transport); - this.currentMethod = method_call; - manager.call(method_call); - } - - public static class execute_call extends org.apache.thrift.async.TAsyncMethodCall { - private RestRequest request; - - public execute_call(RestRequest request, org.apache.thrift.async.AsyncMethodCallback resultHandler, org.apache.thrift.async.TAsyncClient client, org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.transport.TNonblockingTransport transport) throws org.apache.thrift.TException { - super(client, protocolFactory, transport, resultHandler, false); - this.request = request; - } - - public void write_args(org.apache.thrift.protocol.TProtocol prot) throws org.apache.thrift.TException { - prot.writeMessageBegin(new org.apache.thrift.protocol.TMessage("execute", org.apache.thrift.protocol.TMessageType.CALL, 0)); - execute_args args = new execute_args(); - args.setRequest(request); - args.write(prot); - prot.writeMessageEnd(); - } - - public RestResponse getResult() throws org.apache.thrift.TException { - if (getState() != org.apache.thrift.async.TAsyncMethodCall.State.RESPONSE_READ) { - throw new IllegalStateException("Method call not finished!"); - } - org.apache.thrift.transport.TMemoryInputTransport memoryTransport = new org.apache.thrift.transport.TMemoryInputTransport(getFrameBuffer().array()); - org.apache.thrift.protocol.TProtocol prot = client.getProtocolFactory().getProtocol(memoryTransport); - return (new Client(prot)).recv_execute(); - } - } - - } - - public static class Processor implements org.apache.thrift.TProcessor { - private static final Logger LOGGER = LoggerFactory.getLogger(Processor.class.getName()); - - public Processor(Iface iface) { - iface_ = iface; - processMap_.put("execute", new execute()); - } - - protected static interface ProcessFunction { - public void process(int seqid, org.apache.thrift.protocol.TProtocol iprot, org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException; - } - - private Iface iface_; - protected final HashMap processMap_ = new HashMap(); - - public boolean process(org.apache.thrift.protocol.TProtocol iprot, org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { - org.apache.thrift.protocol.TMessage msg = iprot.readMessageBegin(); - ProcessFunction fn = processMap_.get(msg.name); - if (fn == null) { - org.apache.thrift.protocol.TProtocolUtil.skip(iprot, org.apache.thrift.protocol.TType.STRUCT); - iprot.readMessageEnd(); - org.apache.thrift.TApplicationException x = new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.UNKNOWN_METHOD, "Invalid method name: '" + msg.name + "'"); - oprot.writeMessageBegin(new org.apache.thrift.protocol.TMessage(msg.name, org.apache.thrift.protocol.TMessageType.EXCEPTION, msg.seqid)); - x.write(oprot); - oprot.writeMessageEnd(); - oprot.getTransport().flush(); - return true; - } - fn.process(msg.seqid, iprot, oprot); - return true; - } - - private class execute implements ProcessFunction { - public void process(int seqid, org.apache.thrift.protocol.TProtocol iprot, org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { - execute_args args = new execute_args(); - try { - args.read(iprot); - } catch (org.apache.thrift.protocol.TProtocolException e) { - iprot.readMessageEnd(); - org.apache.thrift.TApplicationException x = new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.PROTOCOL_ERROR, e.getMessage()); - oprot.writeMessageBegin(new org.apache.thrift.protocol.TMessage("execute", org.apache.thrift.protocol.TMessageType.EXCEPTION, seqid)); - x.write(oprot); - oprot.writeMessageEnd(); - oprot.getTransport().flush(); - return; - } - iprot.readMessageEnd(); - execute_result result = new execute_result(); - result.success = iface_.execute(args.request); - oprot.writeMessageBegin(new org.apache.thrift.protocol.TMessage("execute", org.apache.thrift.protocol.TMessageType.REPLY, seqid)); - result.write(oprot); - oprot.writeMessageEnd(); - oprot.getTransport().flush(); - } - - } - - } - - public static class execute_args implements org.apache.thrift.TBase, java.io.Serializable, Cloneable { - private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("execute_args"); - - private static final org.apache.thrift.protocol.TField REQUEST_FIELD_DESC = new org.apache.thrift.protocol.TField("request", org.apache.thrift.protocol.TType.STRUCT, (short) 1); - - public RestRequest request; - - /** - * The set of fields this struct contains, along with convenience methods for finding and manipulating them. - */ - public enum _Fields implements org.apache.thrift.TFieldIdEnum { - REQUEST((short) 1, "request"); - - private static final Map byName = new HashMap(); - - static { - for (_Fields field : EnumSet.allOf(_Fields.class)) { - byName.put(field.getFieldName(), field); - } - } - - /** - * Find the _Fields constant that matches fieldId, or null if its not found. - */ - public static _Fields findByThriftId(int fieldId) { - switch (fieldId) { - case 1: // REQUEST - return REQUEST; - default: - return null; - } - } - - /** - * Find the _Fields constant that matches fieldId, throwing an exception - * if it is not found. - */ - public static _Fields findByThriftIdOrThrow(int fieldId) { - _Fields fields = findByThriftId(fieldId); - if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); - return fields; - } - - /** - * Find the _Fields constant that matches name, or null if its not found. - */ - public static _Fields findByName(String name) { - return byName.get(name); - } - - private final short _thriftId; - private final String _fieldName; - - _Fields(short thriftId, String fieldName) { - _thriftId = thriftId; - _fieldName = fieldName; - } - - public short getThriftFieldId() { - return _thriftId; - } - - public String getFieldName() { - return _fieldName; - } - } - - // isset id assignments - - public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; - - static { - Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); - tmpMap.put(_Fields.REQUEST, new org.apache.thrift.meta_data.FieldMetaData("request", org.apache.thrift.TFieldRequirementType.REQUIRED, - new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, RestRequest.class))); - metaDataMap = Collections.unmodifiableMap(tmpMap); - org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(execute_args.class, metaDataMap); - } - - public execute_args() { - } - - public execute_args( - RestRequest request) { - this(); - this.request = request; - } - - /** - * Performs a deep copy on other. - */ - public execute_args(execute_args other) { - if (other.isSetRequest()) { - this.request = new RestRequest(other.request); - } - } - - public execute_args deepCopy() { - return new execute_args(this); - } - - @Override - public void clear() { - this.request = null; - } - - public RestRequest getRequest() { - return this.request; - } - - public execute_args setRequest(RestRequest request) { - this.request = request; - return this; - } - - public void unsetRequest() { - this.request = null; - } - - /** - * Returns true if field request is set (has been assigned a value) and false otherwise - */ - public boolean isSetRequest() { - return this.request != null; - } - - public void setRequestIsSet(boolean value) { - if (!value) { - this.request = null; - } - } - - public void setFieldValue(_Fields field, Object value) { - switch (field) { - case REQUEST: - if (value == null) { - unsetRequest(); - } else { - setRequest((RestRequest) value); - } - break; - - } - } - - public Object getFieldValue(_Fields field) { - switch (field) { - case REQUEST: - return getRequest(); - - } - throw new IllegalStateException(); - } - - /** - * Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise - */ - public boolean isSet(_Fields field) { - if (field == null) { - throw new IllegalArgumentException(); - } - - switch (field) { - case REQUEST: - return isSetRequest(); - } - throw new IllegalStateException(); - } - - @Override - public boolean equals(Object that) { - if (that == null) - return false; - if (that instanceof execute_args) - return this.equals((execute_args) that); - return false; - } - - public boolean equals(execute_args that) { - if (that == null) - return false; - - boolean this_present_request = true && this.isSetRequest(); - boolean that_present_request = true && that.isSetRequest(); - if (this_present_request || that_present_request) { - if (!(this_present_request && that_present_request)) - return false; - if (!this.request.equals(that.request)) - return false; - } - - return true; - } - - @Override - public int hashCode() { - return 0; - } - - public int compareTo(execute_args other) { - if (!getClass().equals(other.getClass())) { - return getClass().getName().compareTo(other.getClass().getName()); - } - - int lastComparison = 0; - execute_args typedOther = (execute_args) other; - - lastComparison = Boolean.valueOf(isSetRequest()).compareTo(typedOther.isSetRequest()); - if (lastComparison != 0) { - return lastComparison; - } - if (isSetRequest()) { - lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.request, typedOther.request); - if (lastComparison != 0) { - return lastComparison; - } - } - return 0; - } - - public _Fields fieldForId(int fieldId) { - return _Fields.findByThriftId(fieldId); - } - - public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { - org.apache.thrift.protocol.TField field; - iprot.readStructBegin(); - while (true) { - field = iprot.readFieldBegin(); - if (field.type == org.apache.thrift.protocol.TType.STOP) { - break; - } - switch (field.id) { - case 1: // REQUEST - if (field.type == org.apache.thrift.protocol.TType.STRUCT) { - this.request = new RestRequest(); - this.request.read(iprot); - } else { - org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type); - } - break; - default: - org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type); - } - iprot.readFieldEnd(); - } - iprot.readStructEnd(); - - // check for required fields of primitive type, which can't be checked in the validate method - validate(); - } - - public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { - validate(); - - oprot.writeStructBegin(STRUCT_DESC); - if (this.request != null) { - oprot.writeFieldBegin(REQUEST_FIELD_DESC); - this.request.write(oprot); - oprot.writeFieldEnd(); - } - oprot.writeFieldStop(); - oprot.writeStructEnd(); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder("execute_args("); - boolean first = true; - - sb.append("request:"); - if (this.request == null) { - sb.append("null"); - } else { - sb.append(this.request); - } - first = false; - sb.append(")"); - return sb.toString(); - } - - public void validate() throws org.apache.thrift.TException { - // check for required fields - if (request == null) { - throw new org.apache.thrift.protocol.TProtocolException("Required field 'request' was not present! Struct: " + toString()); - } - } - - private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { - try { - write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); - } catch (org.apache.thrift.TException te) { - throw new java.io.IOException(te); - } - } - - private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { - try { - read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); - } catch (org.apache.thrift.TException te) { - throw new java.io.IOException(te); - } - } - - } - - public static class execute_result implements org.apache.thrift.TBase, java.io.Serializable, Cloneable { - private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("execute_result"); - - private static final org.apache.thrift.protocol.TField SUCCESS_FIELD_DESC = new org.apache.thrift.protocol.TField("success", org.apache.thrift.protocol.TType.STRUCT, (short) 0); - - public RestResponse success; - - /** - * The set of fields this struct contains, along with convenience methods for finding and manipulating them. - */ - public enum _Fields implements org.apache.thrift.TFieldIdEnum { - SUCCESS((short) 0, "success"); - - private static final Map byName = new HashMap(); - - static { - for (_Fields field : EnumSet.allOf(_Fields.class)) { - byName.put(field.getFieldName(), field); - } - } - - /** - * Find the _Fields constant that matches fieldId, or null if its not found. - */ - public static _Fields findByThriftId(int fieldId) { - switch (fieldId) { - case 0: // SUCCESS - return SUCCESS; - default: - return null; - } - } - - /** - * Find the _Fields constant that matches fieldId, throwing an exception - * if it is not found. - */ - public static _Fields findByThriftIdOrThrow(int fieldId) { - _Fields fields = findByThriftId(fieldId); - if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); - return fields; - } - - /** - * Find the _Fields constant that matches name, or null if its not found. - */ - public static _Fields findByName(String name) { - return byName.get(name); - } - - private final short _thriftId; - private final String _fieldName; - - _Fields(short thriftId, String fieldName) { - _thriftId = thriftId; - _fieldName = fieldName; - } - - public short getThriftFieldId() { - return _thriftId; - } - - public String getFieldName() { - return _fieldName; - } - } - - // isset id assignments - - public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; - - static { - Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); - tmpMap.put(_Fields.SUCCESS, new org.apache.thrift.meta_data.FieldMetaData("success", org.apache.thrift.TFieldRequirementType.DEFAULT, - new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, RestResponse.class))); - metaDataMap = Collections.unmodifiableMap(tmpMap); - org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(execute_result.class, metaDataMap); - } - - public execute_result() { - } - - public execute_result( - RestResponse success) { - this(); - this.success = success; - } - - /** - * Performs a deep copy on other. - */ - public execute_result(execute_result other) { - if (other.isSetSuccess()) { - this.success = new RestResponse(other.success); - } - } - - public execute_result deepCopy() { - return new execute_result(this); - } - - @Override - public void clear() { - this.success = null; - } - - public RestResponse getSuccess() { - return this.success; - } - - public execute_result setSuccess(RestResponse success) { - this.success = success; - return this; - } - - public void unsetSuccess() { - this.success = null; - } - - /** - * Returns true if field success is set (has been assigned a value) and false otherwise - */ - public boolean isSetSuccess() { - return this.success != null; - } - - public void setSuccessIsSet(boolean value) { - if (!value) { - this.success = null; - } - } - - public void setFieldValue(_Fields field, Object value) { - switch (field) { - case SUCCESS: - if (value == null) { - unsetSuccess(); - } else { - setSuccess((RestResponse) value); - } - break; - - } - } - - public Object getFieldValue(_Fields field) { - switch (field) { - case SUCCESS: - return getSuccess(); - - } - throw new IllegalStateException(); - } - - /** - * Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise - */ - public boolean isSet(_Fields field) { - if (field == null) { - throw new IllegalArgumentException(); - } - - switch (field) { - case SUCCESS: - return isSetSuccess(); - } - throw new IllegalStateException(); - } - - @Override - public boolean equals(Object that) { - if (that == null) - return false; - if (that instanceof execute_result) - return this.equals((execute_result) that); - return false; - } - - public boolean equals(execute_result that) { - if (that == null) - return false; - - boolean this_present_success = true && this.isSetSuccess(); - boolean that_present_success = true && that.isSetSuccess(); - if (this_present_success || that_present_success) { - if (!(this_present_success && that_present_success)) - return false; - if (!this.success.equals(that.success)) - return false; - } - - return true; - } - - @Override - public int hashCode() { - return 0; - } - - public int compareTo(execute_result other) { - if (!getClass().equals(other.getClass())) { - return getClass().getName().compareTo(other.getClass().getName()); - } - - int lastComparison = 0; - execute_result typedOther = (execute_result) other; - - lastComparison = Boolean.valueOf(isSetSuccess()).compareTo(typedOther.isSetSuccess()); - if (lastComparison != 0) { - return lastComparison; - } - if (isSetSuccess()) { - lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.success, typedOther.success); - if (lastComparison != 0) { - return lastComparison; - } - } - return 0; - } - - public _Fields fieldForId(int fieldId) { - return _Fields.findByThriftId(fieldId); - } - - public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { - org.apache.thrift.protocol.TField field; - iprot.readStructBegin(); - while (true) { - field = iprot.readFieldBegin(); - if (field.type == org.apache.thrift.protocol.TType.STOP) { - break; - } - switch (field.id) { - case 0: // SUCCESS - if (field.type == org.apache.thrift.protocol.TType.STRUCT) { - this.success = new RestResponse(); - this.success.read(iprot); - } else { - org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type); - } - break; - default: - org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type); - } - iprot.readFieldEnd(); - } - iprot.readStructEnd(); - - // check for required fields of primitive type, which can't be checked in the validate method - validate(); - } - - public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { - oprot.writeStructBegin(STRUCT_DESC); - - if (this.isSetSuccess()) { - oprot.writeFieldBegin(SUCCESS_FIELD_DESC); - this.success.write(oprot); - oprot.writeFieldEnd(); - } - oprot.writeFieldStop(); - oprot.writeStructEnd(); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder("execute_result("); - boolean first = true; - - sb.append("success:"); - if (this.success == null) { - sb.append("null"); - } else { - sb.append(this.success); - } - first = false; - sb.append(")"); - return sb.toString(); - } - - public void validate() throws org.apache.thrift.TException { - // check for required fields - } - - private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { - try { - write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); - } catch (org.apache.thrift.TException te) { - throw new java.io.IOException(te); - } - } - - private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { - try { - read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); - } catch (org.apache.thrift.TException te) { - throw new java.io.IOException(te); - } - } - - } - -} diff --git a/plugins/transport/thrift/src/main/gen-java/org/elasticsearch/thrift/RestRequest.java b/plugins/transport/thrift/src/main/gen-java/org/elasticsearch/thrift/RestRequest.java deleted file mode 100644 index 6bb62e81397..00000000000 --- a/plugins/transport/thrift/src/main/gen-java/org/elasticsearch/thrift/RestRequest.java +++ /dev/null @@ -1,801 +0,0 @@ -/** - * Autogenerated by Thrift - * - * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING - */ -package org.elasticsearch.thrift; - -import java.nio.ByteBuffer; -import java.util.Collections; -import java.util.EnumMap; -import java.util.EnumSet; -import java.util.HashMap; -import java.util.Map; - -public class RestRequest implements org.apache.thrift.TBase, java.io.Serializable, Cloneable { - private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("RestRequest"); - - private static final org.apache.thrift.protocol.TField METHOD_FIELD_DESC = new org.apache.thrift.protocol.TField("method", org.apache.thrift.protocol.TType.I32, (short) 1); - private static final org.apache.thrift.protocol.TField URI_FIELD_DESC = new org.apache.thrift.protocol.TField("uri", org.apache.thrift.protocol.TType.STRING, (short) 2); - private static final org.apache.thrift.protocol.TField PARAMETERS_FIELD_DESC = new org.apache.thrift.protocol.TField("parameters", org.apache.thrift.protocol.TType.MAP, (short) 3); - private static final org.apache.thrift.protocol.TField HEADERS_FIELD_DESC = new org.apache.thrift.protocol.TField("headers", org.apache.thrift.protocol.TType.MAP, (short) 4); - private static final org.apache.thrift.protocol.TField BODY_FIELD_DESC = new org.apache.thrift.protocol.TField("body", org.apache.thrift.protocol.TType.STRING, (short) 5); - - /** - * @see Method - */ - public Method method; - public String uri; - public Map parameters; - public Map headers; - public ByteBuffer body; - - /** - * The set of fields this struct contains, along with convenience methods for finding and manipulating them. - */ - public enum _Fields implements org.apache.thrift.TFieldIdEnum { - /** - * @see Method - */ - METHOD((short) 1, "method"), - URI((short) 2, "uri"), - PARAMETERS((short) 3, "parameters"), - HEADERS((short) 4, "headers"), - BODY((short) 5, "body"); - - private static final Map byName = new HashMap(); - - static { - for (_Fields field : EnumSet.allOf(_Fields.class)) { - byName.put(field.getFieldName(), field); - } - } - - /** - * Find the _Fields constant that matches fieldId, or null if its not found. - */ - public static _Fields findByThriftId(int fieldId) { - switch (fieldId) { - case 1: // METHOD - return METHOD; - case 2: // URI - return URI; - case 3: // PARAMETERS - return PARAMETERS; - case 4: // HEADERS - return HEADERS; - case 5: // BODY - return BODY; - default: - return null; - } - } - - /** - * Find the _Fields constant that matches fieldId, throwing an exception - * if it is not found. - */ - public static _Fields findByThriftIdOrThrow(int fieldId) { - _Fields fields = findByThriftId(fieldId); - if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); - return fields; - } - - /** - * Find the _Fields constant that matches name, or null if its not found. - */ - public static _Fields findByName(String name) { - return byName.get(name); - } - - private final short _thriftId; - private final String _fieldName; - - _Fields(short thriftId, String fieldName) { - _thriftId = thriftId; - _fieldName = fieldName; - } - - public short getThriftFieldId() { - return _thriftId; - } - - public String getFieldName() { - return _fieldName; - } - } - - // isset id assignments - - public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; - - static { - Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); - tmpMap.put(_Fields.METHOD, new org.apache.thrift.meta_data.FieldMetaData("method", org.apache.thrift.TFieldRequirementType.REQUIRED, - new org.apache.thrift.meta_data.EnumMetaData(org.apache.thrift.protocol.TType.ENUM, Method.class))); - tmpMap.put(_Fields.URI, new org.apache.thrift.meta_data.FieldMetaData("uri", org.apache.thrift.TFieldRequirementType.REQUIRED, - new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING))); - tmpMap.put(_Fields.PARAMETERS, new org.apache.thrift.meta_data.FieldMetaData("parameters", org.apache.thrift.TFieldRequirementType.OPTIONAL, - new org.apache.thrift.meta_data.MapMetaData(org.apache.thrift.protocol.TType.MAP, - new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING), - new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING)))); - tmpMap.put(_Fields.HEADERS, new org.apache.thrift.meta_data.FieldMetaData("headers", org.apache.thrift.TFieldRequirementType.OPTIONAL, - new org.apache.thrift.meta_data.MapMetaData(org.apache.thrift.protocol.TType.MAP, - new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING), - new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING)))); - tmpMap.put(_Fields.BODY, new org.apache.thrift.meta_data.FieldMetaData("body", org.apache.thrift.TFieldRequirementType.OPTIONAL, - new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING, true))); - metaDataMap = Collections.unmodifiableMap(tmpMap); - org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(RestRequest.class, metaDataMap); - } - - public RestRequest() { - } - - public RestRequest( - Method method, - String uri) { - this(); - this.method = method; - this.uri = uri; - } - - /** - * Performs a deep copy on other. - */ - public RestRequest(RestRequest other) { - if (other.isSetMethod()) { - this.method = other.method; - } - if (other.isSetUri()) { - this.uri = other.uri; - } - if (other.isSetParameters()) { - Map __this__parameters = new HashMap(); - for (Map.Entry other_element : other.parameters.entrySet()) { - - String other_element_key = other_element.getKey(); - String other_element_value = other_element.getValue(); - - String __this__parameters_copy_key = other_element_key; - - String __this__parameters_copy_value = other_element_value; - - __this__parameters.put(__this__parameters_copy_key, __this__parameters_copy_value); - } - this.parameters = __this__parameters; - } - if (other.isSetHeaders()) { - Map __this__headers = new HashMap(); - for (Map.Entry other_element : other.headers.entrySet()) { - - String other_element_key = other_element.getKey(); - String other_element_value = other_element.getValue(); - - String __this__headers_copy_key = other_element_key; - - String __this__headers_copy_value = other_element_value; - - __this__headers.put(__this__headers_copy_key, __this__headers_copy_value); - } - this.headers = __this__headers; - } - if (other.isSetBody()) { - this.body = org.apache.thrift.TBaseHelper.copyBinary(other.body); - ; - } - } - - public RestRequest deepCopy() { - return new RestRequest(this); - } - - @Override - public void clear() { - this.method = null; - this.uri = null; - this.parameters = null; - this.headers = null; - this.body = null; - } - - /** - * @see Method - */ - public Method getMethod() { - return this.method; - } - - /** - * @see Method - */ - public RestRequest setMethod(Method method) { - this.method = method; - return this; - } - - public void unsetMethod() { - this.method = null; - } - - /** - * Returns true if field method is set (has been assigned a value) and false otherwise - */ - public boolean isSetMethod() { - return this.method != null; - } - - public void setMethodIsSet(boolean value) { - if (!value) { - this.method = null; - } - } - - public String getUri() { - return this.uri; - } - - public RestRequest setUri(String uri) { - this.uri = uri; - return this; - } - - public void unsetUri() { - this.uri = null; - } - - /** - * Returns true if field uri is set (has been assigned a value) and false otherwise - */ - public boolean isSetUri() { - return this.uri != null; - } - - public void setUriIsSet(boolean value) { - if (!value) { - this.uri = null; - } - } - - public int getParametersSize() { - return (this.parameters == null) ? 0 : this.parameters.size(); - } - - public void putToParameters(String key, String val) { - if (this.parameters == null) { - this.parameters = new HashMap(); - } - this.parameters.put(key, val); - } - - public Map getParameters() { - return this.parameters; - } - - public RestRequest setParameters(Map parameters) { - this.parameters = parameters; - return this; - } - - public void unsetParameters() { - this.parameters = null; - } - - /** - * Returns true if field parameters is set (has been assigned a value) and false otherwise - */ - public boolean isSetParameters() { - return this.parameters != null; - } - - public void setParametersIsSet(boolean value) { - if (!value) { - this.parameters = null; - } - } - - public int getHeadersSize() { - return (this.headers == null) ? 0 : this.headers.size(); - } - - public void putToHeaders(String key, String val) { - if (this.headers == null) { - this.headers = new HashMap(); - } - this.headers.put(key, val); - } - - public Map getHeaders() { - return this.headers; - } - - public RestRequest setHeaders(Map headers) { - this.headers = headers; - return this; - } - - public void unsetHeaders() { - this.headers = null; - } - - /** - * Returns true if field headers is set (has been assigned a value) and false otherwise - */ - public boolean isSetHeaders() { - return this.headers != null; - } - - public void setHeadersIsSet(boolean value) { - if (!value) { - this.headers = null; - } - } - - public byte[] getBody() { - setBody(org.apache.thrift.TBaseHelper.rightSize(body)); - return body == null ? null : body.array(); - } - - public ByteBuffer bufferForBody() { - return body; - } - - public RestRequest setBody(byte[] body) { - setBody(body == null ? (ByteBuffer) null : ByteBuffer.wrap(body)); - return this; - } - - public RestRequest setBody(ByteBuffer body) { - this.body = body; - return this; - } - - public void unsetBody() { - this.body = null; - } - - /** - * Returns true if field body is set (has been assigned a value) and false otherwise - */ - public boolean isSetBody() { - return this.body != null; - } - - public void setBodyIsSet(boolean value) { - if (!value) { - this.body = null; - } - } - - public void setFieldValue(_Fields field, Object value) { - switch (field) { - case METHOD: - if (value == null) { - unsetMethod(); - } else { - setMethod((Method) value); - } - break; - - case URI: - if (value == null) { - unsetUri(); - } else { - setUri((String) value); - } - break; - - case PARAMETERS: - if (value == null) { - unsetParameters(); - } else { - setParameters((Map) value); - } - break; - - case HEADERS: - if (value == null) { - unsetHeaders(); - } else { - setHeaders((Map) value); - } - break; - - case BODY: - if (value == null) { - unsetBody(); - } else { - setBody((ByteBuffer) value); - } - break; - - } - } - - public Object getFieldValue(_Fields field) { - switch (field) { - case METHOD: - return getMethod(); - - case URI: - return getUri(); - - case PARAMETERS: - return getParameters(); - - case HEADERS: - return getHeaders(); - - case BODY: - return getBody(); - - } - throw new IllegalStateException(); - } - - /** - * Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise - */ - public boolean isSet(_Fields field) { - if (field == null) { - throw new IllegalArgumentException(); - } - - switch (field) { - case METHOD: - return isSetMethod(); - case URI: - return isSetUri(); - case PARAMETERS: - return isSetParameters(); - case HEADERS: - return isSetHeaders(); - case BODY: - return isSetBody(); - } - throw new IllegalStateException(); - } - - @Override - public boolean equals(Object that) { - if (that == null) - return false; - if (that instanceof RestRequest) - return this.equals((RestRequest) that); - return false; - } - - public boolean equals(RestRequest that) { - if (that == null) - return false; - - boolean this_present_method = true && this.isSetMethod(); - boolean that_present_method = true && that.isSetMethod(); - if (this_present_method || that_present_method) { - if (!(this_present_method && that_present_method)) - return false; - if (!this.method.equals(that.method)) - return false; - } - - boolean this_present_uri = true && this.isSetUri(); - boolean that_present_uri = true && that.isSetUri(); - if (this_present_uri || that_present_uri) { - if (!(this_present_uri && that_present_uri)) - return false; - if (!this.uri.equals(that.uri)) - return false; - } - - boolean this_present_parameters = true && this.isSetParameters(); - boolean that_present_parameters = true && that.isSetParameters(); - if (this_present_parameters || that_present_parameters) { - if (!(this_present_parameters && that_present_parameters)) - return false; - if (!this.parameters.equals(that.parameters)) - return false; - } - - boolean this_present_headers = true && this.isSetHeaders(); - boolean that_present_headers = true && that.isSetHeaders(); - if (this_present_headers || that_present_headers) { - if (!(this_present_headers && that_present_headers)) - return false; - if (!this.headers.equals(that.headers)) - return false; - } - - boolean this_present_body = true && this.isSetBody(); - boolean that_present_body = true && that.isSetBody(); - if (this_present_body || that_present_body) { - if (!(this_present_body && that_present_body)) - return false; - if (!this.body.equals(that.body)) - return false; - } - - return true; - } - - @Override - public int hashCode() { - return 0; - } - - public int compareTo(RestRequest other) { - if (!getClass().equals(other.getClass())) { - return getClass().getName().compareTo(other.getClass().getName()); - } - - int lastComparison = 0; - RestRequest typedOther = (RestRequest) other; - - lastComparison = Boolean.valueOf(isSetMethod()).compareTo(typedOther.isSetMethod()); - if (lastComparison != 0) { - return lastComparison; - } - if (isSetMethod()) { - lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.method, typedOther.method); - if (lastComparison != 0) { - return lastComparison; - } - } - lastComparison = Boolean.valueOf(isSetUri()).compareTo(typedOther.isSetUri()); - if (lastComparison != 0) { - return lastComparison; - } - if (isSetUri()) { - lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.uri, typedOther.uri); - if (lastComparison != 0) { - return lastComparison; - } - } - lastComparison = Boolean.valueOf(isSetParameters()).compareTo(typedOther.isSetParameters()); - if (lastComparison != 0) { - return lastComparison; - } - if (isSetParameters()) { - lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.parameters, typedOther.parameters); - if (lastComparison != 0) { - return lastComparison; - } - } - lastComparison = Boolean.valueOf(isSetHeaders()).compareTo(typedOther.isSetHeaders()); - if (lastComparison != 0) { - return lastComparison; - } - if (isSetHeaders()) { - lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.headers, typedOther.headers); - if (lastComparison != 0) { - return lastComparison; - } - } - lastComparison = Boolean.valueOf(isSetBody()).compareTo(typedOther.isSetBody()); - if (lastComparison != 0) { - return lastComparison; - } - if (isSetBody()) { - lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.body, typedOther.body); - if (lastComparison != 0) { - return lastComparison; - } - } - return 0; - } - - public _Fields fieldForId(int fieldId) { - return _Fields.findByThriftId(fieldId); - } - - public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { - org.apache.thrift.protocol.TField field; - iprot.readStructBegin(); - while (true) { - field = iprot.readFieldBegin(); - if (field.type == org.apache.thrift.protocol.TType.STOP) { - break; - } - switch (field.id) { - case 1: // METHOD - if (field.type == org.apache.thrift.protocol.TType.I32) { - this.method = Method.findByValue(iprot.readI32()); - } else { - org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type); - } - break; - case 2: // URI - if (field.type == org.apache.thrift.protocol.TType.STRING) { - this.uri = iprot.readString(); - } else { - org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type); - } - break; - case 3: // PARAMETERS - if (field.type == org.apache.thrift.protocol.TType.MAP) { - { - org.apache.thrift.protocol.TMap _map0 = iprot.readMapBegin(); - this.parameters = new HashMap(2 * _map0.size); - for (int _i1 = 0; _i1 < _map0.size; ++_i1) { - String _key2; - String _val3; - _key2 = iprot.readString(); - _val3 = iprot.readString(); - this.parameters.put(_key2, _val3); - } - iprot.readMapEnd(); - } - } else { - org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type); - } - break; - case 4: // HEADERS - if (field.type == org.apache.thrift.protocol.TType.MAP) { - { - org.apache.thrift.protocol.TMap _map4 = iprot.readMapBegin(); - this.headers = new HashMap(2 * _map4.size); - for (int _i5 = 0; _i5 < _map4.size; ++_i5) { - String _key6; - String _val7; - _key6 = iprot.readString(); - _val7 = iprot.readString(); - this.headers.put(_key6, _val7); - } - iprot.readMapEnd(); - } - } else { - org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type); - } - break; - case 5: // BODY - if (field.type == org.apache.thrift.protocol.TType.STRING) { - this.body = iprot.readBinary(); - } else { - org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type); - } - break; - default: - org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type); - } - iprot.readFieldEnd(); - } - iprot.readStructEnd(); - - // check for required fields of primitive type, which can't be checked in the validate method - validate(); - } - - public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { - validate(); - - oprot.writeStructBegin(STRUCT_DESC); - if (this.method != null) { - oprot.writeFieldBegin(METHOD_FIELD_DESC); - oprot.writeI32(this.method.getValue()); - oprot.writeFieldEnd(); - } - if (this.uri != null) { - oprot.writeFieldBegin(URI_FIELD_DESC); - oprot.writeString(this.uri); - oprot.writeFieldEnd(); - } - if (this.parameters != null) { - if (isSetParameters()) { - oprot.writeFieldBegin(PARAMETERS_FIELD_DESC); - { - oprot.writeMapBegin(new org.apache.thrift.protocol.TMap(org.apache.thrift.protocol.TType.STRING, org.apache.thrift.protocol.TType.STRING, this.parameters.size())); - for (Map.Entry _iter8 : this.parameters.entrySet()) { - oprot.writeString(_iter8.getKey()); - oprot.writeString(_iter8.getValue()); - } - oprot.writeMapEnd(); - } - oprot.writeFieldEnd(); - } - } - if (this.headers != null) { - if (isSetHeaders()) { - oprot.writeFieldBegin(HEADERS_FIELD_DESC); - { - oprot.writeMapBegin(new org.apache.thrift.protocol.TMap(org.apache.thrift.protocol.TType.STRING, org.apache.thrift.protocol.TType.STRING, this.headers.size())); - for (Map.Entry _iter9 : this.headers.entrySet()) { - oprot.writeString(_iter9.getKey()); - oprot.writeString(_iter9.getValue()); - } - oprot.writeMapEnd(); - } - oprot.writeFieldEnd(); - } - } - if (this.body != null) { - if (isSetBody()) { - oprot.writeFieldBegin(BODY_FIELD_DESC); - oprot.writeBinary(this.body); - oprot.writeFieldEnd(); - } - } - oprot.writeFieldStop(); - oprot.writeStructEnd(); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder("RestRequest("); - boolean first = true; - - sb.append("method:"); - if (this.method == null) { - sb.append("null"); - } else { - sb.append(this.method); - } - first = false; - if (!first) sb.append(", "); - sb.append("uri:"); - if (this.uri == null) { - sb.append("null"); - } else { - sb.append(this.uri); - } - first = false; - if (isSetParameters()) { - if (!first) sb.append(", "); - sb.append("parameters:"); - if (this.parameters == null) { - sb.append("null"); - } else { - sb.append(this.parameters); - } - first = false; - } - if (isSetHeaders()) { - if (!first) sb.append(", "); - sb.append("headers:"); - if (this.headers == null) { - sb.append("null"); - } else { - sb.append(this.headers); - } - first = false; - } - if (isSetBody()) { - if (!first) sb.append(", "); - sb.append("body:"); - if (this.body == null) { - sb.append("null"); - } else { - org.apache.thrift.TBaseHelper.toString(this.body, sb); - } - first = false; - } - sb.append(")"); - return sb.toString(); - } - - public void validate() throws org.apache.thrift.TException { - // check for required fields - if (method == null) { - throw new org.apache.thrift.protocol.TProtocolException("Required field 'method' was not present! Struct: " + toString()); - } - if (uri == null) { - throw new org.apache.thrift.protocol.TProtocolException("Required field 'uri' was not present! Struct: " + toString()); - } - } - - private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { - try { - write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); - } catch (org.apache.thrift.TException te) { - throw new java.io.IOException(te); - } - } - - private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { - try { - read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); - } catch (org.apache.thrift.TException te) { - throw new java.io.IOException(te); - } - } - -} - diff --git a/plugins/transport/thrift/src/main/gen-java/org/elasticsearch/thrift/RestResponse.java b/plugins/transport/thrift/src/main/gen-java/org/elasticsearch/thrift/RestResponse.java deleted file mode 100644 index affa85930b2..00000000000 --- a/plugins/transport/thrift/src/main/gen-java/org/elasticsearch/thrift/RestResponse.java +++ /dev/null @@ -1,571 +0,0 @@ -/** - * Autogenerated by Thrift - * - * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING - */ -package org.elasticsearch.thrift; - -import java.nio.ByteBuffer; -import java.util.Collections; -import java.util.EnumMap; -import java.util.EnumSet; -import java.util.HashMap; -import java.util.Map; - -public class RestResponse implements org.apache.thrift.TBase, java.io.Serializable, Cloneable { - private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("RestResponse"); - - private static final org.apache.thrift.protocol.TField STATUS_FIELD_DESC = new org.apache.thrift.protocol.TField("status", org.apache.thrift.protocol.TType.I32, (short) 1); - private static final org.apache.thrift.protocol.TField HEADERS_FIELD_DESC = new org.apache.thrift.protocol.TField("headers", org.apache.thrift.protocol.TType.MAP, (short) 2); - private static final org.apache.thrift.protocol.TField BODY_FIELD_DESC = new org.apache.thrift.protocol.TField("body", org.apache.thrift.protocol.TType.STRING, (short) 3); - - /** - * @see Status - */ - public Status status; - public Map headers; - public ByteBuffer body; - - /** - * The set of fields this struct contains, along with convenience methods for finding and manipulating them. - */ - public enum _Fields implements org.apache.thrift.TFieldIdEnum { - /** - * @see Status - */ - STATUS((short) 1, "status"), - HEADERS((short) 2, "headers"), - BODY((short) 3, "body"); - - private static final Map byName = new HashMap(); - - static { - for (_Fields field : EnumSet.allOf(_Fields.class)) { - byName.put(field.getFieldName(), field); - } - } - - /** - * Find the _Fields constant that matches fieldId, or null if its not found. - */ - public static _Fields findByThriftId(int fieldId) { - switch (fieldId) { - case 1: // STATUS - return STATUS; - case 2: // HEADERS - return HEADERS; - case 3: // BODY - return BODY; - default: - return null; - } - } - - /** - * Find the _Fields constant that matches fieldId, throwing an exception - * if it is not found. - */ - public static _Fields findByThriftIdOrThrow(int fieldId) { - _Fields fields = findByThriftId(fieldId); - if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); - return fields; - } - - /** - * Find the _Fields constant that matches name, or null if its not found. - */ - public static _Fields findByName(String name) { - return byName.get(name); - } - - private final short _thriftId; - private final String _fieldName; - - _Fields(short thriftId, String fieldName) { - _thriftId = thriftId; - _fieldName = fieldName; - } - - public short getThriftFieldId() { - return _thriftId; - } - - public String getFieldName() { - return _fieldName; - } - } - - // isset id assignments - - public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; - - static { - Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); - tmpMap.put(_Fields.STATUS, new org.apache.thrift.meta_data.FieldMetaData("status", org.apache.thrift.TFieldRequirementType.REQUIRED, - new org.apache.thrift.meta_data.EnumMetaData(org.apache.thrift.protocol.TType.ENUM, Status.class))); - tmpMap.put(_Fields.HEADERS, new org.apache.thrift.meta_data.FieldMetaData("headers", org.apache.thrift.TFieldRequirementType.OPTIONAL, - new org.apache.thrift.meta_data.MapMetaData(org.apache.thrift.protocol.TType.MAP, - new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING), - new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING)))); - tmpMap.put(_Fields.BODY, new org.apache.thrift.meta_data.FieldMetaData("body", org.apache.thrift.TFieldRequirementType.OPTIONAL, - new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING, true))); - metaDataMap = Collections.unmodifiableMap(tmpMap); - org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(RestResponse.class, metaDataMap); - } - - public RestResponse() { - } - - public RestResponse( - Status status) { - this(); - this.status = status; - } - - /** - * Performs a deep copy on other. - */ - public RestResponse(RestResponse other) { - if (other.isSetStatus()) { - this.status = other.status; - } - if (other.isSetHeaders()) { - Map __this__headers = new HashMap(); - for (Map.Entry other_element : other.headers.entrySet()) { - - String other_element_key = other_element.getKey(); - String other_element_value = other_element.getValue(); - - String __this__headers_copy_key = other_element_key; - - String __this__headers_copy_value = other_element_value; - - __this__headers.put(__this__headers_copy_key, __this__headers_copy_value); - } - this.headers = __this__headers; - } - if (other.isSetBody()) { - this.body = org.apache.thrift.TBaseHelper.copyBinary(other.body); - ; - } - } - - public RestResponse deepCopy() { - return new RestResponse(this); - } - - @Override - public void clear() { - this.status = null; - this.headers = null; - this.body = null; - } - - /** - * @see Status - */ - public Status getStatus() { - return this.status; - } - - /** - * @see Status - */ - public RestResponse setStatus(Status status) { - this.status = status; - return this; - } - - public void unsetStatus() { - this.status = null; - } - - /** - * Returns true if field status is set (has been assigned a value) and false otherwise - */ - public boolean isSetStatus() { - return this.status != null; - } - - public void setStatusIsSet(boolean value) { - if (!value) { - this.status = null; - } - } - - public int getHeadersSize() { - return (this.headers == null) ? 0 : this.headers.size(); - } - - public void putToHeaders(String key, String val) { - if (this.headers == null) { - this.headers = new HashMap(); - } - this.headers.put(key, val); - } - - public Map getHeaders() { - return this.headers; - } - - public RestResponse setHeaders(Map headers) { - this.headers = headers; - return this; - } - - public void unsetHeaders() { - this.headers = null; - } - - /** - * Returns true if field headers is set (has been assigned a value) and false otherwise - */ - public boolean isSetHeaders() { - return this.headers != null; - } - - public void setHeadersIsSet(boolean value) { - if (!value) { - this.headers = null; - } - } - - public byte[] getBody() { - setBody(org.apache.thrift.TBaseHelper.rightSize(body)); - return body == null ? null : body.array(); - } - - public ByteBuffer bufferForBody() { - return body; - } - - public RestResponse setBody(byte[] body) { - setBody(body == null ? (ByteBuffer) null : ByteBuffer.wrap(body)); - return this; - } - - public RestResponse setBody(ByteBuffer body) { - this.body = body; - return this; - } - - public void unsetBody() { - this.body = null; - } - - /** - * Returns true if field body is set (has been assigned a value) and false otherwise - */ - public boolean isSetBody() { - return this.body != null; - } - - public void setBodyIsSet(boolean value) { - if (!value) { - this.body = null; - } - } - - public void setFieldValue(_Fields field, Object value) { - switch (field) { - case STATUS: - if (value == null) { - unsetStatus(); - } else { - setStatus((Status) value); - } - break; - - case HEADERS: - if (value == null) { - unsetHeaders(); - } else { - setHeaders((Map) value); - } - break; - - case BODY: - if (value == null) { - unsetBody(); - } else { - setBody((ByteBuffer) value); - } - break; - - } - } - - public Object getFieldValue(_Fields field) { - switch (field) { - case STATUS: - return getStatus(); - - case HEADERS: - return getHeaders(); - - case BODY: - return getBody(); - - } - throw new IllegalStateException(); - } - - /** - * Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise - */ - public boolean isSet(_Fields field) { - if (field == null) { - throw new IllegalArgumentException(); - } - - switch (field) { - case STATUS: - return isSetStatus(); - case HEADERS: - return isSetHeaders(); - case BODY: - return isSetBody(); - } - throw new IllegalStateException(); - } - - @Override - public boolean equals(Object that) { - if (that == null) - return false; - if (that instanceof RestResponse) - return this.equals((RestResponse) that); - return false; - } - - public boolean equals(RestResponse that) { - if (that == null) - return false; - - boolean this_present_status = true && this.isSetStatus(); - boolean that_present_status = true && that.isSetStatus(); - if (this_present_status || that_present_status) { - if (!(this_present_status && that_present_status)) - return false; - if (!this.status.equals(that.status)) - return false; - } - - boolean this_present_headers = true && this.isSetHeaders(); - boolean that_present_headers = true && that.isSetHeaders(); - if (this_present_headers || that_present_headers) { - if (!(this_present_headers && that_present_headers)) - return false; - if (!this.headers.equals(that.headers)) - return false; - } - - boolean this_present_body = true && this.isSetBody(); - boolean that_present_body = true && that.isSetBody(); - if (this_present_body || that_present_body) { - if (!(this_present_body && that_present_body)) - return false; - if (!this.body.equals(that.body)) - return false; - } - - return true; - } - - @Override - public int hashCode() { - return 0; - } - - public int compareTo(RestResponse other) { - if (!getClass().equals(other.getClass())) { - return getClass().getName().compareTo(other.getClass().getName()); - } - - int lastComparison = 0; - RestResponse typedOther = (RestResponse) other; - - lastComparison = Boolean.valueOf(isSetStatus()).compareTo(typedOther.isSetStatus()); - if (lastComparison != 0) { - return lastComparison; - } - if (isSetStatus()) { - lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.status, typedOther.status); - if (lastComparison != 0) { - return lastComparison; - } - } - lastComparison = Boolean.valueOf(isSetHeaders()).compareTo(typedOther.isSetHeaders()); - if (lastComparison != 0) { - return lastComparison; - } - if (isSetHeaders()) { - lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.headers, typedOther.headers); - if (lastComparison != 0) { - return lastComparison; - } - } - lastComparison = Boolean.valueOf(isSetBody()).compareTo(typedOther.isSetBody()); - if (lastComparison != 0) { - return lastComparison; - } - if (isSetBody()) { - lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.body, typedOther.body); - if (lastComparison != 0) { - return lastComparison; - } - } - return 0; - } - - public _Fields fieldForId(int fieldId) { - return _Fields.findByThriftId(fieldId); - } - - public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { - org.apache.thrift.protocol.TField field; - iprot.readStructBegin(); - while (true) { - field = iprot.readFieldBegin(); - if (field.type == org.apache.thrift.protocol.TType.STOP) { - break; - } - switch (field.id) { - case 1: // STATUS - if (field.type == org.apache.thrift.protocol.TType.I32) { - this.status = Status.findByValue(iprot.readI32()); - } else { - org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type); - } - break; - case 2: // HEADERS - if (field.type == org.apache.thrift.protocol.TType.MAP) { - { - org.apache.thrift.protocol.TMap _map10 = iprot.readMapBegin(); - this.headers = new HashMap(2 * _map10.size); - for (int _i11 = 0; _i11 < _map10.size; ++_i11) { - String _key12; - String _val13; - _key12 = iprot.readString(); - _val13 = iprot.readString(); - this.headers.put(_key12, _val13); - } - iprot.readMapEnd(); - } - } else { - org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type); - } - break; - case 3: // BODY - if (field.type == org.apache.thrift.protocol.TType.STRING) { - this.body = iprot.readBinary(); - } else { - org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type); - } - break; - default: - org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type); - } - iprot.readFieldEnd(); - } - iprot.readStructEnd(); - - // check for required fields of primitive type, which can't be checked in the validate method - validate(); - } - - public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { - validate(); - - oprot.writeStructBegin(STRUCT_DESC); - if (this.status != null) { - oprot.writeFieldBegin(STATUS_FIELD_DESC); - oprot.writeI32(this.status.getValue()); - oprot.writeFieldEnd(); - } - if (this.headers != null) { - if (isSetHeaders()) { - oprot.writeFieldBegin(HEADERS_FIELD_DESC); - { - oprot.writeMapBegin(new org.apache.thrift.protocol.TMap(org.apache.thrift.protocol.TType.STRING, org.apache.thrift.protocol.TType.STRING, this.headers.size())); - for (Map.Entry _iter14 : this.headers.entrySet()) { - oprot.writeString(_iter14.getKey()); - oprot.writeString(_iter14.getValue()); - } - oprot.writeMapEnd(); - } - oprot.writeFieldEnd(); - } - } - if (this.body != null) { - if (isSetBody()) { - oprot.writeFieldBegin(BODY_FIELD_DESC); - oprot.writeBinary(this.body); - oprot.writeFieldEnd(); - } - } - oprot.writeFieldStop(); - oprot.writeStructEnd(); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder("RestResponse("); - boolean first = true; - - sb.append("status:"); - if (this.status == null) { - sb.append("null"); - } else { - sb.append(this.status); - } - first = false; - if (isSetHeaders()) { - if (!first) sb.append(", "); - sb.append("headers:"); - if (this.headers == null) { - sb.append("null"); - } else { - sb.append(this.headers); - } - first = false; - } - if (isSetBody()) { - if (!first) sb.append(", "); - sb.append("body:"); - if (this.body == null) { - sb.append("null"); - } else { - org.apache.thrift.TBaseHelper.toString(this.body, sb); - } - first = false; - } - sb.append(")"); - return sb.toString(); - } - - public void validate() throws org.apache.thrift.TException { - // check for required fields - if (status == null) { - throw new org.apache.thrift.protocol.TProtocolException("Required field 'status' was not present! Struct: " + toString()); - } - } - - private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { - try { - write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); - } catch (org.apache.thrift.TException te) { - throw new java.io.IOException(te); - } - } - - private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { - try { - read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); - } catch (org.apache.thrift.TException te) { - throw new java.io.IOException(te); - } - } - -} - diff --git a/plugins/transport/thrift/src/main/gen-java/org/elasticsearch/thrift/Status.java b/plugins/transport/thrift/src/main/gen-java/org/elasticsearch/thrift/Status.java deleted file mode 100644 index f79316815b9..00000000000 --- a/plugins/transport/thrift/src/main/gen-java/org/elasticsearch/thrift/Status.java +++ /dev/null @@ -1,167 +0,0 @@ -/** - * Autogenerated by Thrift - * - * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING - */ -package org.elasticsearch.thrift; - - -public enum Status implements org.apache.thrift.TEnum { - CONT(100), - SWITCHING_PROTOCOLS(101), - OK(200), - CREATED(201), - ACCEPTED(202), - NON_AUTHORITATIVE_INFORMATION(203), - NO_CONTENT(204), - RESET_CONTENT(205), - PARTIAL_CONTENT(206), - MULTI_STATUS(207), - MULTIPLE_CHOICES(300), - MOVED_PERMANENTLY(301), - FOUND(302), - SEE_OTHER(303), - NOT_MODIFIED(304), - USE_PROXY(305), - TEMPORARY_REDIRECT(307), - BAD_REQUEST(400), - UNAUTHORIZED(401), - PAYMENT_REQUIRED(402), - FORBIDDEN(403), - NOT_FOUND(404), - METHOD_NOT_ALLOWED(405), - NOT_ACCEPTABLE(406), - PROXY_AUTHENTICATION(407), - REQUEST_TIMEOUT(408), - CONFLICT(409), - GONE(410), - LENGTH_REQUIRED(411), - PRECONDITION_FAILED(412), - REQUEST_ENTITY_TOO_LARGE(413), - REQUEST_URI_TOO_LONG(414), - UNSUPPORTED_MEDIA_TYPE(415), - REQUESTED_RANGE_NOT_SATISFIED(416), - EXPECTATION_FAILED(417), - UNPROCESSABLE_ENTITY(422), - LOCKED(423), - FAILED_DEPENDENCY(424), - INTERNAL_SERVER_ERROR(500), - NOT_IMPLEMENTED(501), - BAD_GATEWAY(502), - SERVICE_UNAVAILABLE(503), - GATEWAY_TIMEOUT(504), - INSUFFICIENT_STORAGE(506); - - private final int value; - - private Status(int value) { - this.value = value; - } - - /** - * Get the integer value of this enum value, as defined in the Thrift IDL. - */ - public int getValue() { - return value; - } - - /** - * Find a the enum type by its integer value, as defined in the Thrift IDL. - * - * @return null if the value is not found. - */ - public static Status findByValue(int value) { - switch (value) { - case 100: - return CONT; - case 101: - return SWITCHING_PROTOCOLS; - case 200: - return OK; - case 201: - return CREATED; - case 202: - return ACCEPTED; - case 203: - return NON_AUTHORITATIVE_INFORMATION; - case 204: - return NO_CONTENT; - case 205: - return RESET_CONTENT; - case 206: - return PARTIAL_CONTENT; - case 207: - return MULTI_STATUS; - case 300: - return MULTIPLE_CHOICES; - case 301: - return MOVED_PERMANENTLY; - case 302: - return FOUND; - case 303: - return SEE_OTHER; - case 304: - return NOT_MODIFIED; - case 305: - return USE_PROXY; - case 307: - return TEMPORARY_REDIRECT; - case 400: - return BAD_REQUEST; - case 401: - return UNAUTHORIZED; - case 402: - return PAYMENT_REQUIRED; - case 403: - return FORBIDDEN; - case 404: - return NOT_FOUND; - case 405: - return METHOD_NOT_ALLOWED; - case 406: - return NOT_ACCEPTABLE; - case 407: - return PROXY_AUTHENTICATION; - case 408: - return REQUEST_TIMEOUT; - case 409: - return CONFLICT; - case 410: - return GONE; - case 411: - return LENGTH_REQUIRED; - case 412: - return PRECONDITION_FAILED; - case 413: - return REQUEST_ENTITY_TOO_LARGE; - case 414: - return REQUEST_URI_TOO_LONG; - case 415: - return UNSUPPORTED_MEDIA_TYPE; - case 416: - return REQUESTED_RANGE_NOT_SATISFIED; - case 417: - return EXPECTATION_FAILED; - case 422: - return UNPROCESSABLE_ENTITY; - case 423: - return LOCKED; - case 424: - return FAILED_DEPENDENCY; - case 500: - return INTERNAL_SERVER_ERROR; - case 501: - return NOT_IMPLEMENTED; - case 502: - return BAD_GATEWAY; - case 503: - return SERVICE_UNAVAILABLE; - case 504: - return GATEWAY_TIMEOUT; - case 506: - return INSUFFICIENT_STORAGE; - default: - return null; - } - } -} diff --git a/plugins/transport/thrift/src/main/java/es-plugin.properties b/plugins/transport/thrift/src/main/java/es-plugin.properties deleted file mode 100644 index b22b8c42ade..00000000000 --- a/plugins/transport/thrift/src/main/java/es-plugin.properties +++ /dev/null @@ -1 +0,0 @@ -plugin=org.elasticsearch.plugin.transport.thrift.ThriftTransportPlugin diff --git a/plugins/transport/thrift/src/main/java/org/elasticsearch/plugin/transport/thrift/ThriftTransportPlugin.java b/plugins/transport/thrift/src/main/java/org/elasticsearch/plugin/transport/thrift/ThriftTransportPlugin.java deleted file mode 100644 index 41022da5299..00000000000 --- a/plugins/transport/thrift/src/main/java/org/elasticsearch/plugin/transport/thrift/ThriftTransportPlugin.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.plugin.transport.thrift; - -import org.elasticsearch.common.component.LifecycleComponent; -import org.elasticsearch.common.inject.Module; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.plugins.AbstractPlugin; -import org.elasticsearch.thrift.ThriftServer; -import org.elasticsearch.thrift.ThriftServerModule; - -import java.util.Collection; - -import static org.elasticsearch.common.collect.Lists.*; - -/** - * @author kimchy (shay.banon) - */ -public class ThriftTransportPlugin extends AbstractPlugin { - - private final Settings settings; - - public ThriftTransportPlugin(Settings settings) { - this.settings = settings; - } - - @Override public String name() { - return "transport-thrift"; - } - - @Override public String description() { - return "Exports elasticsearch REST APIs over thrift"; - } - - @Override public Collection> modules() { - Collection> modules = newArrayList(); - if (settings.getAsBoolean("thrift.enabled", true)) { - modules.add(ThriftServerModule.class); - } - return modules; - } - - @Override public Collection> services() { - Collection> services = newArrayList(); - if (settings.getAsBoolean("thrift.enabled", true)) { - services.add(ThriftServer.class); - } - return services; - } -} \ No newline at end of file diff --git a/plugins/transport/thrift/src/main/java/org/elasticsearch/thrift/ThriftRestImpl.java b/plugins/transport/thrift/src/main/java/org/elasticsearch/thrift/ThriftRestImpl.java deleted file mode 100644 index 93afbd56e84..00000000000 --- a/plugins/transport/thrift/src/main/java/org/elasticsearch/thrift/ThriftRestImpl.java +++ /dev/null @@ -1,202 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.thrift; - -import org.apache.thrift.TException; -import org.elasticsearch.common.component.AbstractComponent; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.io.stream.CachedStreamOutput; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.rest.RestChannel; -import org.elasticsearch.rest.RestController; -import org.elasticsearch.rest.RestResponse; -import org.elasticsearch.rest.RestStatus; -import org.elasticsearch.rest.StringRestResponse; -import org.elasticsearch.rest.XContentRestResponse; - -import java.io.IOException; -import java.nio.ByteBuffer; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.atomic.AtomicReference; - -import static org.elasticsearch.rest.RestStatus.*; - -/** - * @author kimchy (shay.banon) - */ -public class ThriftRestImpl extends AbstractComponent implements Rest.Iface { - - private final RestController restController; - - @Inject public ThriftRestImpl(Settings settings, RestController restController) { - super(settings); - this.restController = restController; - } - - @Override public org.elasticsearch.thrift.RestResponse execute(RestRequest request) throws TException { - if (logger.isTraceEnabled()) { - logger.trace("thrift message {}", request); - } - final CountDownLatch latch = new CountDownLatch(1); - final AtomicReference ref = new AtomicReference(); - boolean dispatched = restController.dispatchRequest(new ThriftRestRequest(request), new RestChannel() { - @Override public void sendResponse(RestResponse response) { - try { - ref.set(convert(response)); - } catch (IOException e) { - // ignore, should not happen... - } - latch.countDown(); - } - }); - if (!dispatched) { - try { - ref.set(convert(new StringRestResponse(BAD_REQUEST, "No handler found for uri [" + request.getUri() + "] and method [" + request.getMethod() + "]"))); - } catch (IOException e) { - // ignore, will not happen... (from convert) - } - latch.countDown(); - } - try { - latch.await(); - return ref.get(); - } catch (Exception e) { - throw new TException("failed to generate response", e); - } - } - - private org.elasticsearch.thrift.RestResponse convert(RestResponse response) throws IOException { - org.elasticsearch.thrift.RestResponse tResponse = new org.elasticsearch.thrift.RestResponse(getStatus(response.status())); - if (response.contentLength() > 0) { - if (response.contentThreadSafe()) { - tResponse.setBody(ByteBuffer.wrap(response.content(), 0, response.contentLength())); - } else { - // argh!, we need to copy it over since we are not on the same thread... - byte[] body = new byte[response.contentLength()]; - System.arraycopy(response.content(), 0, body, 0, response.contentLength()); - tResponse.setBody(ByteBuffer.wrap(body)); - if (response instanceof XContentRestResponse) { - XContentBuilder builder = ((XContentRestResponse) response).builder(); - if (builder.payload() instanceof CachedStreamOutput.Entry) { - CachedStreamOutput.pushEntry((CachedStreamOutput.Entry) builder.payload()); - } - } - } - } - return tResponse; - } - - private Status getStatus(RestStatus status) { - switch (status) { - case CONTINUE: - return Status.CONT; - case SWITCHING_PROTOCOLS: - return Status.SWITCHING_PROTOCOLS; - case OK: - return Status.OK; - case CREATED: - return Status.CREATED; - case ACCEPTED: - return Status.ACCEPTED; - case NON_AUTHORITATIVE_INFORMATION: - return Status.NON_AUTHORITATIVE_INFORMATION; - case NO_CONTENT: - return Status.NO_CONTENT; - case RESET_CONTENT: - return Status.RESET_CONTENT; - case PARTIAL_CONTENT: - return Status.PARTIAL_CONTENT; - case MULTI_STATUS: - // no status for this?? - return Status.INTERNAL_SERVER_ERROR; - case MULTIPLE_CHOICES: - return Status.MULTIPLE_CHOICES; - case MOVED_PERMANENTLY: - return Status.MOVED_PERMANENTLY; - case FOUND: - return Status.FOUND; - case SEE_OTHER: - return Status.SEE_OTHER; - case NOT_MODIFIED: - return Status.NOT_MODIFIED; - case USE_PROXY: - return Status.USE_PROXY; - case TEMPORARY_REDIRECT: - return Status.TEMPORARY_REDIRECT; - case BAD_REQUEST: - return Status.BAD_REQUEST; - case UNAUTHORIZED: - return Status.UNAUTHORIZED; - case PAYMENT_REQUIRED: - return Status.PAYMENT_REQUIRED; - case FORBIDDEN: - return Status.FORBIDDEN; - case NOT_FOUND: - return Status.NOT_FOUND; - case METHOD_NOT_ALLOWED: - return Status.METHOD_NOT_ALLOWED; - case NOT_ACCEPTABLE: - return Status.NOT_ACCEPTABLE; - case PROXY_AUTHENTICATION: - return Status.INTERNAL_SERVER_ERROR; - case REQUEST_TIMEOUT: - return Status.REQUEST_TIMEOUT; - case CONFLICT: - return Status.CONFLICT; - case GONE: - return Status.GONE; - case LENGTH_REQUIRED: - return Status.LENGTH_REQUIRED; - case PRECONDITION_FAILED: - return Status.PRECONDITION_FAILED; - case REQUEST_ENTITY_TOO_LARGE: - return Status.REQUEST_ENTITY_TOO_LARGE; - case REQUEST_URI_TOO_LONG: - return Status.REQUEST_URI_TOO_LONG; - case UNSUPPORTED_MEDIA_TYPE: - return Status.UNSUPPORTED_MEDIA_TYPE; - case REQUESTED_RANGE_NOT_SATISFIED: - return Status.INTERNAL_SERVER_ERROR; - case EXPECTATION_FAILED: - return Status.EXPECTATION_FAILED; - case UNPROCESSABLE_ENTITY: - return Status.BAD_REQUEST; - case LOCKED: - return Status.BAD_REQUEST; - case FAILED_DEPENDENCY: - return Status.BAD_REQUEST; - case INTERNAL_SERVER_ERROR: - return Status.INTERNAL_SERVER_ERROR; - case NOT_IMPLEMENTED: - return Status.NOT_IMPLEMENTED; - case BAD_GATEWAY: - return Status.BAD_GATEWAY; - case SERVICE_UNAVAILABLE: - return Status.SERVICE_UNAVAILABLE; - case GATEWAY_TIMEOUT: - return Status.GATEWAY_TIMEOUT; - case HTTP_VERSION_NOT_SUPPORTED: - return Status.INTERNAL_SERVER_ERROR; - default: - return Status.INTERNAL_SERVER_ERROR; - } - } -} diff --git a/plugins/transport/thrift/src/main/java/org/elasticsearch/thrift/ThriftRestRequest.java b/plugins/transport/thrift/src/main/java/org/elasticsearch/thrift/ThriftRestRequest.java deleted file mode 100644 index 4724a1a93b3..00000000000 --- a/plugins/transport/thrift/src/main/java/org/elasticsearch/thrift/ThriftRestRequest.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.thrift; - -import org.elasticsearch.common.Bytes; -import org.elasticsearch.common.Unicode; -import org.elasticsearch.rest.support.AbstractRestRequest; -import org.elasticsearch.rest.support.RestUtils; - -import java.util.HashMap; -import java.util.Map; - -/** - * @author kimchy (shay.banon) - */ -public class ThriftRestRequest extends AbstractRestRequest implements org.elasticsearch.rest.RestRequest { - - private final org.elasticsearch.thrift.RestRequest request; - - private final String rawPath; - - private final Map params; - - public ThriftRestRequest(org.elasticsearch.thrift.RestRequest request) { - this.request = request; - this.params = request.getParameters() == null ? new HashMap() : request.getParameters(); - - int pathEndPos = request.getUri().indexOf('?'); - if (pathEndPos < 0) { - this.rawPath = request.getUri(); - } else { - this.rawPath = request.getUri().substring(0, pathEndPos); - RestUtils.decodeQueryString(request.getUri(), pathEndPos + 1, params); - } - } - - @Override public Method method() { - switch (request.getMethod()) { - case GET: - return Method.GET; - case POST: - return Method.POST; - case PUT: - return Method.PUT; - case DELETE: - return Method.DELETE; - case HEAD: - return Method.HEAD; - case OPTIONS: - return Method.OPTIONS; - } - return null; - } - - @Override public String uri() { - return request.getUri(); - } - - @Override public String rawPath() { - return this.rawPath; - } - - @Override public boolean hasContent() { - return request.isSetBody() && request.bufferForBody().remaining() > 0; - } - - @Override public boolean contentUnsafe() { - return false; - } - - @Override public byte[] contentByteArray() { - if (!request.isSetBody()) { - return Bytes.EMPTY_ARRAY; - } - return request.bufferForBody().array(); - } - - @Override public int contentByteArrayOffset() { - if (!request.isSetBody()) { - return 0; - } - return request.bufferForBody().arrayOffset() + request.bufferForBody().position(); - } - - @Override public int contentLength() { - if (!request.isSetBody()) { - return 0; - } - return request.bufferForBody().remaining(); - } - - @Override public String contentAsString() { - if (!request.isSetBody()) { - return ""; - } - return Unicode.fromBytes(contentByteArray(), contentByteArrayOffset(), contentLength()); - } - - @Override public String header(String name) { - if (request.getHeaders() == null) { - return null; - } - return request.getHeaders().get(name); - } - - @Override public boolean hasParam(String key) { - return params.containsKey(key); - } - - @Override public String param(String key) { - return params.get(key); - } - - @Override public Map params() { - return params; - } - - @Override public String param(String key, String defaultValue) { - String value = params.get(key); - if (value == null) { - return defaultValue; - } - return value; - } -} diff --git a/plugins/transport/thrift/src/main/java/org/elasticsearch/thrift/ThriftServer.java b/plugins/transport/thrift/src/main/java/org/elasticsearch/thrift/ThriftServer.java deleted file mode 100644 index 59d239e1a80..00000000000 --- a/plugins/transport/thrift/src/main/java/org/elasticsearch/thrift/ThriftServer.java +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.thrift; - -import org.apache.thrift.protocol.TBinaryProtocol; -import org.apache.thrift.protocol.TCompactProtocol; -import org.apache.thrift.protocol.TProtocolFactory; -import org.apache.thrift.server.TServer; -import org.apache.thrift.server.TThreadPoolServer; -import org.apache.thrift.transport.TFramedTransport; -import org.apache.thrift.transport.TServerSocket; -import org.apache.thrift.transport.TTransportFactory; -import org.elasticsearch.ElasticSearchException; -import org.elasticsearch.common.component.AbstractLifecycleComponent; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.network.NetworkService; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.transport.PortsRange; -import org.elasticsearch.common.unit.ByteSizeValue; -import org.elasticsearch.node.service.NodeService; -import org.elasticsearch.transport.BindTransportException; - -import java.io.IOException; -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.util.concurrent.atomic.AtomicReference; - -import static org.elasticsearch.common.util.concurrent.EsExecutors.*; - -/** - * @author kimchy (shay.banon) - */ -public class ThriftServer extends AbstractLifecycleComponent { - - final int frame; - - final String port; - - final String bindHost; - - final String publishHost; - - private final NetworkService networkService; - - private final NodeService nodeService; - - private final ThriftRestImpl client; - - private final TProtocolFactory protocolFactory; - - private volatile TServer server; - - private volatile int portNumber; - - @Inject public ThriftServer(Settings settings, NetworkService networkService, NodeService nodeService, ThriftRestImpl client) { - super(settings); - this.client = client; - this.networkService = networkService; - this.nodeService = nodeService; - this.frame = (int) componentSettings.getAsBytesSize("frame", new ByteSizeValue(-1)).bytes(); - this.port = componentSettings.get("port", "9500-9600"); - this.bindHost = componentSettings.get("bind_host", settings.get("transport.bind_host", settings.get("transport.host"))); - this.publishHost = componentSettings.get("publish_host", settings.get("transport.publish_host", settings.get("transport.host"))); - - if (componentSettings.get("protocol", "binary").equals("compact")) { - protocolFactory = new TCompactProtocol.Factory(); - } else { - protocolFactory = new TBinaryProtocol.Factory(); - } - } - - @Override protected void doStart() throws ElasticSearchException { - InetAddress bindAddrX; - try { - bindAddrX = networkService.resolveBindHostAddress(bindHost); - } catch (IOException e) { - throw new BindTransportException("Failed to resolve host [" + bindHost + "]", e); - } - final InetAddress bindAddr = bindAddrX; - - PortsRange portsRange = new PortsRange(port); - final AtomicReference lastException = new AtomicReference(); - boolean success = portsRange.iterate(new PortsRange.PortCallback() { - @Override public boolean onPortNumber(int portNumber) { - ThriftServer.this.portNumber = portNumber; - try { - Rest.Processor processor = new Rest.Processor(client); - - // Bind and start to accept incoming connections. - TServerSocket serverSocket = new TServerSocket(new InetSocketAddress(bindAddr, portNumber)); - - TThreadPoolServer.Args args = new TThreadPoolServer.Args(serverSocket) - .minWorkerThreads(16) - .maxWorkerThreads(Integer.MAX_VALUE) - .inputProtocolFactory(protocolFactory) - .outputProtocolFactory(protocolFactory) - .processor(processor); - - if (frame <= 0) { - args.inputTransportFactory(new TTransportFactory()); - args.outputTransportFactory(new TTransportFactory()); - } else { - args.inputTransportFactory(new TFramedTransport.Factory(frame)); - args.outputTransportFactory(new TFramedTransport.Factory(frame)); - } - - server = new TThreadPoolServer(args); - } catch (Exception e) { - lastException.set(e); - return false; - } - return true; - } - }); - if (!success) { - throw new BindTransportException("Failed to bind to [" + port + "]", lastException.get()); - } - logger.info("bound on port [{}]", portNumber); - try { - nodeService.putNodeAttribute("thrift_address", new InetSocketAddress(networkService.resolvePublishHostAddress(publishHost), portNumber).toString()); - } catch (Exception e) { - // ignore - } - - daemonThreadFactory(settings, "thrift_server").newThread(new Runnable() { - @Override public void run() { - server.serve(); - } - }).start(); - } - - @Override protected void doStop() throws ElasticSearchException { - nodeService.removeNodeAttribute("thrift_address"); - server.stop(); - } - - @Override protected void doClose() throws ElasticSearchException { - } -} diff --git a/plugins/transport/thrift/src/main/java/org/elasticsearch/thrift/ThriftServerModule.java b/plugins/transport/thrift/src/main/java/org/elasticsearch/thrift/ThriftServerModule.java deleted file mode 100644 index 6034a52dce9..00000000000 --- a/plugins/transport/thrift/src/main/java/org/elasticsearch/thrift/ThriftServerModule.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.thrift; - -import org.elasticsearch.common.inject.AbstractModule; -import org.elasticsearch.common.settings.Settings; - -/** - * @author kimchy (shay.banon) - */ -public class ThriftServerModule extends AbstractModule { - - private final Settings settings; - - public ThriftServerModule(Settings settings) { - this.settings = settings; - } - - @SuppressWarnings({"unchecked"}) @Override protected void configure() { - bind(ThriftRestImpl.class).asEagerSingleton(); - bind(ThriftServer.class).asEagerSingleton(); - } -} diff --git a/plugins/transport/thrift/src/test/java/org/elasticsearch/thrift/test/SimpleThriftTests.java b/plugins/transport/thrift/src/test/java/org/elasticsearch/thrift/test/SimpleThriftTests.java deleted file mode 100644 index c94bd4a4292..00000000000 --- a/plugins/transport/thrift/src/test/java/org/elasticsearch/thrift/test/SimpleThriftTests.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.thrift.test; - -import org.apache.thrift.protocol.TBinaryProtocol; -import org.apache.thrift.protocol.TProtocol; -import org.apache.thrift.transport.TSocket; -import org.apache.thrift.transport.TTransport; -import org.apache.thrift.transport.TTransportException; -import org.elasticsearch.common.network.NetworkUtils; -import org.elasticsearch.common.xcontent.XContentFactory; -import org.elasticsearch.common.xcontent.XContentType; -import org.elasticsearch.node.Node; -import org.elasticsearch.thrift.Method; -import org.elasticsearch.thrift.Rest; -import org.elasticsearch.thrift.RestRequest; -import org.elasticsearch.thrift.RestResponse; -import org.elasticsearch.thrift.Status; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import java.io.IOException; -import java.nio.ByteBuffer; -import java.util.Map; - -import static org.elasticsearch.common.settings.ImmutableSettings.*; -import static org.elasticsearch.node.NodeBuilder.*; -import static org.hamcrest.MatcherAssert.*; -import static org.hamcrest.Matchers.*; - -/** - * @author kimchy (shay.banon) - */ -public class SimpleThriftTests { - - private Node node; - - private TTransport transport; - - private Rest.Client client; - - @BeforeMethod public void setup() throws IOException, TTransportException { - node = nodeBuilder().settings(settingsBuilder() - .put("cluster.name", "test-cluster-" + NetworkUtils.getLocalAddress()) - .put("gateway.type", "none")).node(); - transport = new TSocket("localhost", 9500); - TProtocol protocol = new TBinaryProtocol(transport); - client = new Rest.Client(protocol); - transport.open(); - } - - @AfterMethod public void tearDown() { - transport.close(); - node.close(); - } - - @Test public void testSimpleApis() throws Exception { - RestRequest request = new RestRequest(Method.POST, "/test/type1"); - request.setBody(ByteBuffer.wrap(XContentFactory.jsonBuilder().startObject() - .field("field", "value") - .endObject().copiedBytes())); - RestResponse response = client.execute(request); - Map map = parseBody(response); - assertThat(response.getStatus(), equalTo(Status.CREATED)); - assertThat(map.get("ok").toString(), equalTo("true")); - assertThat(map.get("_index").toString(), equalTo("test")); - assertThat(map.get("_type").toString(), equalTo("type1")); - - request = new RestRequest(Method.GET, "/_cluster/health"); - response = client.execute(request); - assertThat(response.getStatus(), equalTo(Status.OK)); - - request = new RestRequest(Method.GET, "/bogusindex"); - response = client.execute(request); - assertThat(response.getStatus(), equalTo(Status.BAD_REQUEST)); - } - - private Map parseBody(RestResponse response) throws IOException { - return XContentFactory.xContent(XContentType.JSON).createParser(response.bufferForBody().array(), response.bufferForBody().arrayOffset(), response.bufferForBody().remaining()).map(); - } -} diff --git a/plugins/transport/wares/build.gradle b/plugins/transport/wares/build.gradle deleted file mode 100644 index 36040e0385f..00000000000 --- a/plugins/transport/wares/build.gradle +++ /dev/null @@ -1,127 +0,0 @@ -dependsOn(':elasticsearch') - -apply plugin: 'java' -apply plugin: 'maven' - -archivesBaseName = "elasticsearch-transport-wares" - -explodedDistDir = new File(distsDir, 'exploded') - -configurations.compile.transitive = true -configurations.testCompile.transitive = true - -// no need to use the resource dir -sourceSets.main.resources.srcDirs 'src/main/java' -sourceSets.test.resources.srcDirs 'src/test/java' - -jar { -// from sourceSets.main.allJava - manifest { - attributes("Implementation-Title": "ElasticSearch", "Implementation-Version": rootProject.version, "Implementation-Date": buildTimeStr) - } -} - -configurations { - dists - distLib { - visible = false - transitive = false - } -} - -dependencies { - compile project(':elasticsearch') - compile 'javax.servlet:servlet-api:2.5' -} - -task explodedDist(dependsOn: [jar], description: 'Builds the plugin zip file') << { - [explodedDistDir]*.mkdirs() - - copy { - from configurations.distLib - into explodedDistDir - } - - // remove elasticsearch files (compile above adds the elasticsearch one) - ant.delete { fileset(dir: explodedDistDir, includes: "elasticsearch-*.jar") } - - copy { - from libsDir - into explodedDistDir - } - - ant.delete { fileset(dir: explodedDistDir, includes: "elasticsearch-*-javadoc.jar") } - ant.delete { fileset(dir: explodedDistDir, includes: "elasticsearch-*-sources.jar") } -} - -task zip(type: Zip, dependsOn: ['explodedDist']) { - from(explodedDistDir) { - } -} - -task release(dependsOn: [zip]) << { - ant.delete(dir: explodedDistDir) - copy { - from distsDir - into(new File(rootProject.distsDir, "plugins")) - } -} - -configurations { - deployerJars - tools -} - -dependencies { - deployerJars "org.apache.maven.wagon:wagon-http:1.0-beta-2" - tools "com.google.code:jarjar:1.0" -} - -task sourcesJar(type: Jar, dependsOn: classes) { - classifier = 'sources' - from sourceSets.main.allSource -} - -task javadocJar(type: Jar, dependsOn: javadoc) { - classifier = 'javadoc' - from javadoc.destinationDir -} - -artifacts { - archives sourcesJar - archives javadocJar -} - -uploadArchives { - repositories.mavenDeployer { - configuration = configurations.deployerJars - repository(url: rootProject.mavenRepoUrl) { - authentication(userName: rootProject.mavenRepoUser, password: rootProject.mavenRepoPass) - } - snapshotRepository(url: rootProject.mavenSnapshotRepoUrl) { - authentication(userName: rootProject.mavenRepoUser, password: rootProject.mavenRepoPass) - } - - pom.project { - inceptionYear '2009' - name 'elasticsearch-plugins-transport-wares' - description 'War Plugin for ElasticSearch' - licenses { - license { - name 'The Apache Software License, Version 2.0' - url 'http://www.apache.org/licenses/LICENSE-2.0.txt' - distribution 'repo' - } - } - scm { - connection 'git://github.com/elasticsearch/elasticsearch.git' - developerConnection 'git@github.com:elasticsearch/elasticsearch.git' - url 'http://github.com/elasticsearch/elasticsearch' - } - } - - pom.whenConfigured {pom -> - pom.dependencies = pom.dependencies.findAll {dep -> dep.scope != 'test' } // removes the test scoped ones - } - } -} \ No newline at end of file diff --git a/plugins/transport/wares/src/main/java/org/elasticsearch/wares/NodeServlet.java b/plugins/transport/wares/src/main/java/org/elasticsearch/wares/NodeServlet.java deleted file mode 100644 index e56648728ef..00000000000 --- a/plugins/transport/wares/src/main/java/org/elasticsearch/wares/NodeServlet.java +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.wares; - -import org.elasticsearch.common.settings.ImmutableSettings; -import org.elasticsearch.node.Node; -import org.elasticsearch.node.NodeBuilder; -import org.elasticsearch.node.internal.InternalNode; -import org.elasticsearch.rest.RestChannel; -import org.elasticsearch.rest.RestController; -import org.elasticsearch.rest.RestRequest; -import org.elasticsearch.rest.RestResponse; -import org.elasticsearch.rest.support.RestUtils; - -import javax.servlet.ServletException; -import javax.servlet.ServletOutputStream; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.io.InputStream; -import java.util.concurrent.CountDownLatch; - -/** - * A servlet that can be used to dispatch requests to elasticsearch. A {@link Node} will be started, reading - * config from either /WEB-INF/elasticsearch.json or /WEB-INF/elasticsearch.yml but, by defualt, - * with its internal HTTP interface disabled. - * - *

The node is registered as a servlet context attribute under elasticsearchNode so its easily - * accessible from other web resources if needed. - * - *

The servlet can be registered under a prefix URI, and it will automatically adjust to handle it. - */ -public class NodeServlet extends HttpServlet { - - public static String NODE_KEY = "elasticsearchNode"; - - private Node node; - - private RestController restController; - - @Override public void init() throws ServletException { - getServletContext().log("Initializing elasticsearch Node '" + getServletName() + "'"); - ImmutableSettings.Builder settings = ImmutableSettings.settingsBuilder(); - - InputStream resourceAsStream = getServletContext().getResourceAsStream("/WEB-INF/elasticsearch.json"); - if (resourceAsStream != null) { - settings.loadFromStream("/WEB-INF/elasticsearch.json", resourceAsStream); - try { - resourceAsStream.close(); - } catch (IOException e) { - // ignore - } - } - - resourceAsStream = getServletContext().getResourceAsStream("/WEB-INF/elasticsearch.yml"); - if (resourceAsStream != null) { - settings.loadFromStream("/WEB-INF/elasticsearch.yml", resourceAsStream); - try { - resourceAsStream.close(); - } catch (IOException e) { - // ignore - } - } - if (settings.get("http.enabled") == null) { - settings.put("http.enabled", false); - } - - node = NodeBuilder.nodeBuilder().settings(settings).node(); - restController = ((InternalNode) node).injector().getInstance(RestController.class); - getServletContext().setAttribute(NODE_KEY, node); - } - - @Override public void destroy() { - if (node != null) { - getServletContext().removeAttribute(NODE_KEY); - node.close(); - } - } - - @Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - ServletRestRequest request = new ServletRestRequest(req); - ServletRestChannel channel = new ServletRestChannel(request, resp); - try { - if (!restController.dispatchRequest(request, channel)) { - throw new ServletException("No mapping found for [" + request.uri() + "]"); - } - channel.latch.await(); - } catch (ServletException e) { - throw e; - } catch (Exception e) { - throw new IOException("failed to dispatch request", e); - } - if (channel.sendFailure != null) { - throw channel.sendFailure; - } - } - - static class ServletRestChannel implements RestChannel { - - final RestRequest restRequest; - - final HttpServletResponse resp; - - final CountDownLatch latch; - - IOException sendFailure; - - ServletRestChannel(RestRequest restRequest, HttpServletResponse resp) { - this.restRequest = restRequest; - this.resp = resp; - this.latch = new CountDownLatch(1); - } - - @Override public void sendResponse(RestResponse response) { - resp.setContentType(response.contentType()); - if (RestUtils.isBrowser(restRequest.header("User-Agent"))) { - resp.addHeader("Access-Control-Allow-Origin", "*"); - if (restRequest.method() == RestRequest.Method.OPTIONS) { - // also add more access control parameters - resp.addHeader("Access-Control-Max-Age", "1728000"); - resp.addHeader("Access-Control-Allow-Methods", "PUT, DELETE"); - resp.addHeader("Access-Control-Allow-Headers", "X-Requested-With"); - } - } - String opaque = restRequest.header("X-Opaque-Id"); - if (opaque != null) { - resp.addHeader("X-Opaque-Id", opaque); - } - try { - int contentLength = response.contentLength() + response.prefixContentLength() + response.suffixContentLength(); - resp.setContentLength(contentLength); - - ServletOutputStream out = resp.getOutputStream(); - if (response.prefixContent() != null) { - out.write(response.prefixContent(), 0, response.prefixContentLength()); - } - out.write(response.content(), 0, response.contentLength()); - if (response.suffixContent() != null) { - out.write(response.suffixContent(), 0, response.suffixContentLength()); - } - out.close(); - } catch (IOException e) { - sendFailure = e; - } finally { - latch.countDown(); - } - } - } -} \ No newline at end of file diff --git a/plugins/transport/wares/src/main/java/org/elasticsearch/wares/ServletRestRequest.java b/plugins/transport/wares/src/main/java/org/elasticsearch/wares/ServletRestRequest.java deleted file mode 100644 index 7e45f96f74a..00000000000 --- a/plugins/transport/wares/src/main/java/org/elasticsearch/wares/ServletRestRequest.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.wares; - -import org.elasticsearch.common.Unicode; -import org.elasticsearch.common.io.Streams; -import org.elasticsearch.rest.support.AbstractRestRequest; -import org.elasticsearch.rest.support.RestUtils; - -import javax.servlet.http.HttpServletRequest; -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - -public class ServletRestRequest extends AbstractRestRequest implements org.elasticsearch.rest.RestRequest { - - private final HttpServletRequest servletRequest; - - private final Method method; - - private final Map params; - - private final byte[] content; - - public ServletRestRequest(HttpServletRequest servletRequest) throws IOException { - this.servletRequest = servletRequest; - this.method = Method.valueOf(servletRequest.getMethod()); - this.params = new HashMap(); - - if (servletRequest.getQueryString() != null) { - RestUtils.decodeQueryString(servletRequest.getQueryString(), 0, params); - } - - content = Streams.copyToByteArray(servletRequest.getInputStream()); - } - - @Override public Method method() { - return this.method; - } - - @Override public String uri() { - return servletRequest.getRequestURI().substring(servletRequest.getContextPath().length() + servletRequest.getServletPath().length()); - } - - @Override public String rawPath() { - return servletRequest.getRequestURI().substring(servletRequest.getContextPath().length() + servletRequest.getServletPath().length()); - } - - @Override public boolean hasContent() { - return content.length > 0; - } - - @Override public boolean contentUnsafe() { - return false; - } - - @Override public byte[] contentByteArray() { - return content; - } - - @Override public int contentByteArrayOffset() { - return 0; - } - - @Override public int contentLength() { - return content.length; - } - - @Override public String contentAsString() { - return Unicode.fromBytes(contentByteArray(), contentByteArrayOffset(), contentLength()); - } - - @Override public String header(String name) { - return servletRequest.getHeader(name); - } - - @Override public Map params() { - return params; - } - - @Override public boolean hasParam(String key) { - return params.containsKey(key); - } - - @Override public String param(String key) { - return params.get(key); - } - - @Override public String param(String key, String defaultValue) { - String value = params.get(key); - if (value == null) { - return defaultValue; - } - return value; - } -} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index beab68705c2..6edf3206add 100644 --- a/settings.gradle +++ b/settings.gradle @@ -8,24 +8,6 @@ include 'test-integration' include 'benchmark-micro' -include 'plugins-cloud-aws' -include 'plugins-hadoop' -include 'plugins-analysis-icu' -include 'plugins-mapper-attachments' - -include 'plugins-lang-groovy' -include 'plugins-lang-javascript' -include 'plugins-lang-python' - -include 'plugins-transport-memcached' -include 'plugins-transport-thrift' -include 'plugins-transport-wares' - -include 'plugins-river-twitter' -include 'plugins-river-wikipedia' -include 'plugins-river-rabbitmq' -include 'plugins-river-couchdb' - rootProject.name = 'elasticsearch-root' rootProject.children.each {project -> String fileBaseName = project.name.replaceAll("\\p{Upper}") { "-${it.toLowerCase()}" }