diff --git a/.idea/dictionaries/kimchy.xml b/.idea/dictionaries/kimchy.xml index cf3699ea307..682b8904c64 100644 --- a/.idea/dictionaries/kimchy.xml +++ b/.idea/dictionaries/kimchy.xml @@ -3,6 +3,7 @@ addr amazonaws + apis appendable args asciifolding @@ -120,6 +121,7 @@ startup stopwords streamable + struct substring successul tagline diff --git a/.idea/modules.xml b/.idea/modules.xml index 2667b1760d8..fa37f509890 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -10,6 +10,7 @@ + diff --git a/.idea/modules/elasticsearch-root.iml b/.idea/modules/elasticsearch-root.iml index ab33aa0ed8a..957b36b52ef 100644 --- a/.idea/modules/elasticsearch-root.iml +++ b/.idea/modules/elasticsearch-root.iml @@ -16,6 +16,7 @@ + diff --git a/.idea/modules/plugin-transport-thrift.iml b/.idea/modules/plugin-transport-thrift.iml new file mode 100644 index 00000000000..7f77c2b8526 --- /dev/null +++ b/.idea/modules/plugin-transport-thrift.iml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/http/netty/NettyHttpRequest.java b/modules/elasticsearch/src/main/java/org/elasticsearch/http/netty/NettyHttpRequest.java index 0fd666e7a18..5886995e7c8 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/http/netty/NettyHttpRequest.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/http/netty/NettyHttpRequest.java @@ -27,7 +27,6 @@ import org.elasticsearch.rest.support.RestUtils; import java.nio.charset.Charset; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.Set; @@ -141,10 +140,6 @@ public class NettyHttpRequest extends AbstractRestRequest implements HttpRequest return request.getHeader(name); } - @Override public List headers(String name) { - return request.getHeaders(name); - } - @Override public String cookie() { return request.getHeader(HttpHeaders.Names.COOKIE); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/RestRequest.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/RestRequest.java index c5536748a02..3addfd56fb9 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/RestRequest.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/RestRequest.java @@ -23,7 +23,6 @@ import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.ToXContent; -import java.util.List; import java.util.Map; import java.util.Set; @@ -67,8 +66,6 @@ public interface RestRequest extends ToXContent.Params { String header(String name); - List headers(String name); - String cookie(); boolean hasParam(String key); 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 index 65e5f407d6e..31fe3a405f1 100644 --- a/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/MemcachedRestRequest.java +++ b/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/MemcachedRestRequest.java @@ -19,15 +19,12 @@ package org.elasticsearch.memcached; -import org.elasticsearch.common.Booleans; import org.elasticsearch.common.Unicode; -import org.elasticsearch.common.collect.ImmutableList; import org.elasticsearch.common.collect.ImmutableSet; import org.elasticsearch.rest.support.AbstractRestRequest; import org.elasticsearch.rest.support.RestUtils; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.Set; @@ -148,10 +145,6 @@ public class MemcachedRestRequest extends AbstractRestRequest { return null; } - @Override public List headers(String name) { - return ImmutableList.of(); - } - @Override public String cookie() { return null; } @@ -175,16 +168,4 @@ public class MemcachedRestRequest extends AbstractRestRequest { } return defaultValue; } - - @Override public boolean paramAsBoolean(String key, boolean defaultValue) { - return Booleans.parseBoolean(param(key), defaultValue); - } - - @Override public Boolean paramAsBoolean(String key, Boolean defaultValue) { - String sValue = param(key); - if (sValue == null) { - return defaultValue; - } - return !(sValue.equals("false") || sValue.equals("0") || sValue.equals("off")); - } } diff --git a/plugins/transport/thrift/build.gradle b/plugins/transport/thrift/build.gradle new file mode 100644 index 00000000000..bee9fac21ee --- /dev/null +++ b/plugins/transport/thrift/build.gradle @@ -0,0 +1,147 @@ +dependsOn(':elasticsearch') + +apply plugin: 'java' +apply plugin: 'maven' + +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.4.0' + compile 'org.slf4j:slf4j-api:1.5.11' + compile('org.slf4j:slf4j-log4j12:1.5.11') { transitive = false } + + distLib("org.elasticsearch:es-libthrift:0.4.0") { transitive = false } + distLib 'org.slf4j:slf4j-api:1.5.11' + distLib('org.slf4j:slf4j-log4j12:1.5.11') { transitive = false } + + testCompile project(':test-testng') + testCompile('org.testng:testng:5.10:jdk15') { transitive = false } + testCompile 'org.hamcrest:hamcrest-all:1.1' +} + +test { + useTestNG() + jmvArgs = ["-ea", "-Xmx1024m"] + suiteName = project.name + listeners = ["org.elasticsearch.util.testng.Listeners"] + systemProperties["es.test.log.conf"] = System.getProperty("es.test.log.conf", "log4j-gradle.properties") +} + +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 + } + } +} \ No newline at end of file diff --git a/plugins/transport/thrift/elasticsearch.thrift b/plugins/transport/thrift/elasticsearch.thrift new file mode 100644 index 00000000000..749a8e52e2d --- /dev/null +++ b/plugins/transport/thrift/elasticsearch.thrift @@ -0,0 +1,81 @@ +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 params + 4: optional map headers + 5: optional binary body +} + +enum Status { + CONTINUE = 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 new file mode 100644 index 00000000000..ce420edb9dd --- /dev/null +++ b/plugins/transport/thrift/src/main/gen-java/org/elasticsearch/thrift/Method.java @@ -0,0 +1,74 @@ +/* + * 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. + */ + +/** + * Autogenerated by Thrift + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + */ +package org.elasticsearch.thrift; + + +import org.apache.thrift.TEnum; + +public enum Method implements 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 new file mode 100644 index 00000000000..7318438b9de --- /dev/null +++ b/plugins/transport/thrift/src/main/gen-java/org/elasticsearch/thrift/Rest.java @@ -0,0 +1,830 @@ +/* + * 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. + */ + +/** + * Autogenerated by Thrift + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + */ +package org.elasticsearch.thrift; + +import org.apache.thrift.*; +import org.apache.thrift.async.*; +import org.apache.thrift.meta_data.FieldMetaData; +import org.apache.thrift.meta_data.StructMetaData; +import org.apache.thrift.protocol.*; +import org.apache.thrift.transport.TMemoryInputTransport; +import org.apache.thrift.transport.TNonblockingTransport; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.*; + +public class Rest { + + public interface Iface { + + public RestResponse execute(RestRequest request) throws TException; + + } + + public interface AsyncIface { + + public void execute(RestRequest request, AsyncMethodCallback resultHandler) throws TException; + + } + + public static class Client implements TServiceClient, Iface { + public static class Factory implements TServiceClientFactory { + public Factory() { + } + + public Client getClient(TProtocol prot) { + return new Client(prot); + } + + public Client getClient(TProtocol iprot, TProtocol oprot) { + return new Client(iprot, oprot); + } + } + + public Client(TProtocol prot) { + this(prot, prot); + } + + public Client(TProtocol iprot, TProtocol oprot) { + iprot_ = iprot; + oprot_ = oprot; + } + + protected TProtocol iprot_; + protected TProtocol oprot_; + + protected int seqid_; + + public TProtocol getInputProtocol() { + return this.iprot_; + } + + public TProtocol getOutputProtocol() { + return this.oprot_; + } + + public RestResponse execute(RestRequest request) throws TException { + send_execute(request); + return recv_execute(); + } + + public void send_execute(RestRequest request) throws TException { + oprot_.writeMessageBegin(new TMessage("execute", 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 TException { + TMessage msg = iprot_.readMessageBegin(); + if (msg.type == TMessageType.EXCEPTION) { + TApplicationException x = TApplicationException.read(iprot_); + iprot_.readMessageEnd(); + throw x; + } + if (msg.seqid != seqid_) { + throw new TApplicationException(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 TApplicationException(TApplicationException.MISSING_RESULT, "execute failed: unknown result"); + } + + } + + public static class AsyncClient extends TAsyncClient implements AsyncIface { + public static class Factory implements TAsyncClientFactory { + private TAsyncClientManager clientManager; + private TProtocolFactory protocolFactory; + + public Factory(TAsyncClientManager clientManager, TProtocolFactory protocolFactory) { + this.clientManager = clientManager; + this.protocolFactory = protocolFactory; + } + + public AsyncClient getAsyncClient(TNonblockingTransport transport) { + return new AsyncClient(protocolFactory, clientManager, transport); + } + } + + public AsyncClient(TProtocolFactory protocolFactory, TAsyncClientManager clientManager, TNonblockingTransport transport) { + super(protocolFactory, clientManager, transport); + } + + public void execute(RestRequest request, AsyncMethodCallback resultHandler) throws TException { + checkReady(); + execute_call method_call = new execute_call(request, resultHandler, this, protocolFactory, transport); + manager.call(method_call); + } + + public static class execute_call extends TAsyncMethodCall { + private RestRequest request; + + public execute_call(RestRequest request, AsyncMethodCallback resultHandler, TAsyncClient client, TProtocolFactory protocolFactory, TNonblockingTransport transport) throws TException { + super(client, protocolFactory, transport, resultHandler, false); + this.request = request; + } + + public void write_args(TProtocol prot) throws TException { + prot.writeMessageBegin(new TMessage("execute", TMessageType.CALL, 0)); + execute_args args = new execute_args(); + args.setRequest(request); + args.write(prot); + prot.writeMessageEnd(); + } + + public RestResponse getResult() throws TException { + if (getState() != State.RESPONSE_READ) { + throw new IllegalStateException("Method call not finished!"); + } + TMemoryInputTransport memoryTransport = new TMemoryInputTransport(getFrameBuffer().array()); + TProtocol prot = client.getProtocolFactory().getProtocol(memoryTransport); + return (new Client(prot)).recv_execute(); + } + } + + } + + public static class Processor implements 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, TProtocol iprot, TProtocol oprot) throws TException; + } + + private Iface iface_; + protected final HashMap processMap_ = new HashMap(); + + public boolean process(TProtocol iprot, TProtocol oprot) throws TException { + TMessage msg = iprot.readMessageBegin(); + ProcessFunction fn = processMap_.get(msg.name); + if (fn == null) { + TProtocolUtil.skip(iprot, TType.STRUCT); + iprot.readMessageEnd(); + TApplicationException x = new TApplicationException(TApplicationException.UNKNOWN_METHOD, "Invalid method name: '" + msg.name + "'"); + oprot.writeMessageBegin(new TMessage(msg.name, 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, TProtocol iprot, TProtocol oprot) throws TException { + execute_args args = new execute_args(); + try { + args.read(iprot); + } catch (TProtocolException e) { + iprot.readMessageEnd(); + TApplicationException x = new TApplicationException(TApplicationException.PROTOCOL_ERROR, e.getMessage()); + oprot.writeMessageBegin(new TMessage("execute", 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 TMessage("execute", TMessageType.REPLY, seqid)); + result.write(oprot); + oprot.writeMessageEnd(); + oprot.getTransport().flush(); + } + + } + + } + + public static class execute_args implements TBase, java.io.Serializable, Cloneable { + private static final TStruct STRUCT_DESC = new TStruct("execute_args"); + + private static final TField REQUEST_FIELD_DESC = new TField("request", 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 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, FieldMetaData> metaDataMap; + + static { + Map<_Fields, FieldMetaData> tmpMap = new EnumMap<_Fields, FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.REQUEST, new FieldMetaData("request", TFieldRequirementType.REQUIRED, + new StructMetaData(TType.STRUCT, RestRequest.class))); + metaDataMap = Collections.unmodifiableMap(tmpMap); + 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); + } + + @Deprecated + public execute_args clone() { + 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 asigned 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 void setFieldValue(int fieldID, Object value) { + setFieldValue(_Fields.findByThriftIdOrThrow(fieldID), value); + } + + public Object getFieldValue(_Fields field) { + switch (field) { + case REQUEST: + return getRequest(); + + } + throw new IllegalStateException(); + } + + public Object getFieldValue(int fieldId) { + return getFieldValue(_Fields.findByThriftIdOrThrow(fieldId)); + } + + /** + * Returns true if field corresponding to fieldID is set (has been asigned a value) and false otherwise + */ + public boolean isSet(_Fields field) { + switch (field) { + case REQUEST: + return isSetRequest(); + } + throw new IllegalStateException(); + } + + public boolean isSet(int fieldID) { + return isSet(_Fields.findByThriftIdOrThrow(fieldID)); + } + + @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 = TBaseHelper.compareTo(this.request, typedOther.request); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + public void read(TProtocol iprot) throws TException { + TField field; + iprot.readStructBegin(); + while (true) { + field = iprot.readFieldBegin(); + if (field.type == TType.STOP) { + break; + } + switch (field.id) { + case 1: // REQUEST + if (field.type == TType.STRUCT) { + this.request = new RestRequest(); + this.request.read(iprot); + } else { + TProtocolUtil.skip(iprot, field.type); + } + break; + default: + 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(TProtocol oprot) throws 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 TException { + // check for required fields + if (request == null) { + throw new TProtocolException("Required field 'request' was not present! Struct: " + toString()); + } + } + + } + + public static class execute_result implements TBase, java.io.Serializable, Cloneable { + private static final TStruct STRUCT_DESC = new TStruct("execute_result"); + + private static final TField SUCCESS_FIELD_DESC = new TField("success", 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 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, FieldMetaData> metaDataMap; + + static { + Map<_Fields, FieldMetaData> tmpMap = new EnumMap<_Fields, FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.SUCCESS, new FieldMetaData("success", TFieldRequirementType.DEFAULT, + new StructMetaData(TType.STRUCT, RestResponse.class))); + metaDataMap = Collections.unmodifiableMap(tmpMap); + 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); + } + + @Deprecated + public execute_result clone() { + 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 asigned 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 void setFieldValue(int fieldID, Object value) { + setFieldValue(_Fields.findByThriftIdOrThrow(fieldID), value); + } + + public Object getFieldValue(_Fields field) { + switch (field) { + case SUCCESS: + return getSuccess(); + + } + throw new IllegalStateException(); + } + + public Object getFieldValue(int fieldId) { + return getFieldValue(_Fields.findByThriftIdOrThrow(fieldId)); + } + + /** + * Returns true if field corresponding to fieldID is set (has been asigned a value) and false otherwise + */ + public boolean isSet(_Fields field) { + switch (field) { + case SUCCESS: + return isSetSuccess(); + } + throw new IllegalStateException(); + } + + public boolean isSet(int fieldID) { + return isSet(_Fields.findByThriftIdOrThrow(fieldID)); + } + + @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 = TBaseHelper.compareTo(this.success, typedOther.success); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + public void read(TProtocol iprot) throws TException { + TField field; + iprot.readStructBegin(); + while (true) { + field = iprot.readFieldBegin(); + if (field.type == TType.STOP) { + break; + } + switch (field.id) { + case 0: // SUCCESS + if (field.type == TType.STRUCT) { + this.success = new RestResponse(); + this.success.read(iprot); + } else { + TProtocolUtil.skip(iprot, field.type); + } + break; + default: + 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(TProtocol oprot) throws 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 TException { + // check for required fields + } + + } + +} 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 new file mode 100644 index 00000000000..d57f16ba2f4 --- /dev/null +++ b/plugins/transport/thrift/src/main/gen-java/org/elasticsearch/thrift/RestRequest.java @@ -0,0 +1,787 @@ +/** + * Autogenerated by Thrift + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + */ +package org.elasticsearch.thrift; + +import org.apache.thrift.*; +import org.apache.thrift.meta_data.EnumMetaData; +import org.apache.thrift.meta_data.FieldMetaData; +import org.apache.thrift.meta_data.FieldValueMetaData; +import org.apache.thrift.meta_data.MapMetaData; +import org.apache.thrift.protocol.*; + +import java.nio.ByteBuffer; +import java.util.*; + +public class RestRequest implements TBase, java.io.Serializable, Cloneable { + private static final TStruct STRUCT_DESC = new TStruct("RestRequest"); + + private static final TField METHOD_FIELD_DESC = new TField("method", TType.I32, (short) 1); + private static final TField URI_FIELD_DESC = new TField("uri", TType.STRING, (short) 2); + private static final TField PARAMS_FIELD_DESC = new TField("params", TType.MAP, (short) 3); + private static final TField HEADERS_FIELD_DESC = new TField("headers", TType.MAP, (short) 4); + private static final TField BODY_FIELD_DESC = new TField("body", TType.STRING, (short) 5); + + /** + * @see org.elasticsearch.thrift.Method + */ + public Method method; + public String uri; + public Map params; + 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 TFieldIdEnum { + /** + * @see org.elasticsearch.thrift.Method + */ + METHOD((short) 1, "method"), + URI((short) 2, "uri"), + PARAMS((short) 3, "params"), + 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: // PARAMS + return PARAMS; + 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, FieldMetaData> metaDataMap; + + static { + Map<_Fields, FieldMetaData> tmpMap = new EnumMap<_Fields, FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.METHOD, new FieldMetaData("method", TFieldRequirementType.REQUIRED, + new EnumMetaData(TType.ENUM, Method.class))); + tmpMap.put(_Fields.URI, new FieldMetaData("uri", TFieldRequirementType.REQUIRED, + new FieldValueMetaData(TType.STRING))); + tmpMap.put(_Fields.PARAMS, new FieldMetaData("params", TFieldRequirementType.OPTIONAL, + new MapMetaData(TType.MAP, + new FieldValueMetaData(TType.STRING), + new FieldValueMetaData(TType.STRING)))); + tmpMap.put(_Fields.HEADERS, new FieldMetaData("headers", TFieldRequirementType.OPTIONAL, + new MapMetaData(TType.MAP, + new FieldValueMetaData(TType.STRING), + new FieldValueMetaData(TType.STRING)))); + tmpMap.put(_Fields.BODY, new FieldMetaData("body", TFieldRequirementType.OPTIONAL, + new FieldValueMetaData(TType.STRING))); + metaDataMap = Collections.unmodifiableMap(tmpMap); + 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.isSetParams()) { + Map __this__params = new HashMap(); + for (Map.Entry other_element : other.params.entrySet()) { + + String other_element_key = other_element.getKey(); + String other_element_value = other_element.getValue(); + + String __this__params_copy_key = other_element_key; + + String __this__params_copy_value = other_element_value; + + __this__params.put(__this__params_copy_key, __this__params_copy_value); + } + this.params = __this__params; + } + 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 = ByteBuffer.wrap(new byte[other.body.limit() - other.body.arrayOffset()]); + System.arraycopy(other.body.array(), other.body.arrayOffset(), body.array(), 0, other.body.limit() - other.body.arrayOffset()); + } + } + + public RestRequest deepCopy() { + return new RestRequest(this); + } + + @Deprecated + public RestRequest clone() { + return new RestRequest(this); + } + + @Override + public void clear() { + this.method = null; + this.uri = null; + this.params = null; + this.headers = null; + this.body = null; + } + + /** + * @see org.elasticsearch.thrift.Method + */ + public Method getMethod() { + return this.method; + } + + /** + * @see org.elasticsearch.thrift.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 asigned 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 asigned a value) and false otherwise + */ + public boolean isSetUri() { + return this.uri != null; + } + + public void setUriIsSet(boolean value) { + if (!value) { + this.uri = null; + } + } + + public int getParamsSize() { + return (this.params == null) ? 0 : this.params.size(); + } + + public void putToParams(String key, String val) { + if (this.params == null) { + this.params = new HashMap(); + } + this.params.put(key, val); + } + + public Map getParams() { + return this.params; + } + + public RestRequest setParams(Map params) { + this.params = params; + return this; + } + + public void unsetParams() { + this.params = null; + } + + /** + * Returns true if field params is set (has been asigned a value) and false otherwise + */ + public boolean isSetParams() { + return this.params != null; + } + + public void setParamsIsSet(boolean value) { + if (!value) { + this.params = 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 asigned a value) and false otherwise + */ + public boolean isSetHeaders() { + return this.headers != null; + } + + public void setHeadersIsSet(boolean value) { + if (!value) { + this.headers = null; + } + } + + public ByteBuffer getBody() { + return this.body; + } + + 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 asigned 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 PARAMS: + if (value == null) { + unsetParams(); + } else { + setParams((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 void setFieldValue(int fieldID, Object value) { + setFieldValue(_Fields.findByThriftIdOrThrow(fieldID), value); + } + + public Object getFieldValue(_Fields field) { + switch (field) { + case METHOD: + return getMethod(); + + case URI: + return getUri(); + + case PARAMS: + return getParams(); + + case HEADERS: + return getHeaders(); + + case BODY: + return getBody(); + + } + throw new IllegalStateException(); + } + + public Object getFieldValue(int fieldId) { + return getFieldValue(_Fields.findByThriftIdOrThrow(fieldId)); + } + + /** + * Returns true if field corresponding to fieldID is set (has been asigned a value) and false otherwise + */ + public boolean isSet(_Fields field) { + switch (field) { + case METHOD: + return isSetMethod(); + case URI: + return isSetUri(); + case PARAMS: + return isSetParams(); + case HEADERS: + return isSetHeaders(); + case BODY: + return isSetBody(); + } + throw new IllegalStateException(); + } + + public boolean isSet(int fieldID) { + return isSet(_Fields.findByThriftIdOrThrow(fieldID)); + } + + @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_params = true && this.isSetParams(); + boolean that_present_params = true && that.isSetParams(); + if (this_present_params || that_present_params) { + if (!(this_present_params && that_present_params)) + return false; + if (!this.params.equals(that.params)) + 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 = 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 = TBaseHelper.compareTo(this.uri, typedOther.uri); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = Boolean.valueOf(isSetParams()).compareTo(typedOther.isSetParams()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetParams()) { + lastComparison = TBaseHelper.compareTo(this.params, typedOther.params); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = Boolean.valueOf(isSetHeaders()).compareTo(typedOther.isSetHeaders()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetHeaders()) { + lastComparison = 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 = TBaseHelper.compareTo(this.body, typedOther.body); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + public void read(TProtocol iprot) throws TException { + TField field; + iprot.readStructBegin(); + while (true) { + field = iprot.readFieldBegin(); + if (field.type == TType.STOP) { + break; + } + switch (field.id) { + case 1: // METHOD + if (field.type == TType.I32) { + this.method = Method.findByValue(iprot.readI32()); + } else { + TProtocolUtil.skip(iprot, field.type); + } + break; + case 2: // URI + if (field.type == TType.STRING) { + this.uri = iprot.readString(); + } else { + TProtocolUtil.skip(iprot, field.type); + } + break; + case 3: // PARAMS + if (field.type == TType.MAP) { + { + TMap _map0 = iprot.readMapBegin(); + this.params = new HashMap(2 * _map0.size); + for (int _i1 = 0; _i1 < _map0.size; ++_i1) { + String _key2; + String _val3; + _key2 = iprot.readString(); + _val3 = iprot.readString(); + this.params.put(_key2, _val3); + } + iprot.readMapEnd(); + } + } else { + TProtocolUtil.skip(iprot, field.type); + } + break; + case 4: // HEADERS + if (field.type == TType.MAP) { + { + 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 { + TProtocolUtil.skip(iprot, field.type); + } + break; + case 5: // BODY + if (field.type == TType.STRING) { + this.body = iprot.readBinary(); + } else { + TProtocolUtil.skip(iprot, field.type); + } + break; + default: + 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(TProtocol oprot) throws 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.params != null) { + if (isSetParams()) { + oprot.writeFieldBegin(PARAMS_FIELD_DESC); + { + oprot.writeMapBegin(new TMap(TType.STRING, TType.STRING, this.params.size())); + for (Map.Entry _iter8 : this.params.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 TMap(TType.STRING, 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 (isSetParams()) { + if (!first) sb.append(", "); + sb.append("params:"); + if (this.params == null) { + sb.append("null"); + } else { + sb.append(this.params); + } + 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 { + TBaseHelper.toString(this.body, sb); + } + first = false; + } + sb.append(")"); + return sb.toString(); + } + + public void validate() throws TException { + // check for required fields + if (method == null) { + throw new TProtocolException("Required field 'method' was not present! Struct: " + toString()); + } + if (uri == null) { + throw new TProtocolException("Required field 'uri' was not present! Struct: " + toString()); + } + } + +} + 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 new file mode 100644 index 00000000000..605132fde6d --- /dev/null +++ b/plugins/transport/thrift/src/main/gen-java/org/elasticsearch/thrift/RestResponse.java @@ -0,0 +1,557 @@ +/** + * Autogenerated by Thrift + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + */ +package org.elasticsearch.thrift; + +import org.apache.thrift.*; +import org.apache.thrift.meta_data.EnumMetaData; +import org.apache.thrift.meta_data.FieldMetaData; +import org.apache.thrift.meta_data.FieldValueMetaData; +import org.apache.thrift.meta_data.MapMetaData; +import org.apache.thrift.protocol.*; + +import java.nio.ByteBuffer; +import java.util.*; + +public class RestResponse implements TBase, java.io.Serializable, Cloneable { + private static final TStruct STRUCT_DESC = new TStruct("RestResponse"); + + private static final TField STATUS_FIELD_DESC = new TField("status", TType.I32, (short) 1); + private static final TField HEADERS_FIELD_DESC = new TField("headers", TType.MAP, (short) 2); + private static final TField BODY_FIELD_DESC = new TField("body", TType.STRING, (short) 3); + + /** + * @see org.elasticsearch.thrift.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 TFieldIdEnum { + /** + * @see org.elasticsearch.thrift.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, FieldMetaData> metaDataMap; + + static { + Map<_Fields, FieldMetaData> tmpMap = new EnumMap<_Fields, FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.STATUS, new FieldMetaData("status", TFieldRequirementType.REQUIRED, + new EnumMetaData(TType.ENUM, Status.class))); + tmpMap.put(_Fields.HEADERS, new FieldMetaData("headers", TFieldRequirementType.OPTIONAL, + new MapMetaData(TType.MAP, + new FieldValueMetaData(TType.STRING), + new FieldValueMetaData(TType.STRING)))); + tmpMap.put(_Fields.BODY, new FieldMetaData("body", TFieldRequirementType.OPTIONAL, + new FieldValueMetaData(TType.STRING))); + metaDataMap = Collections.unmodifiableMap(tmpMap); + 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 = ByteBuffer.wrap(new byte[other.body.limit() - other.body.arrayOffset()]); + System.arraycopy(other.body.array(), other.body.arrayOffset(), body.array(), 0, other.body.limit() - other.body.arrayOffset()); + } + } + + public RestResponse deepCopy() { + return new RestResponse(this); + } + + @Deprecated + public RestResponse clone() { + return new RestResponse(this); + } + + @Override + public void clear() { + this.status = null; + this.headers = null; + this.body = null; + } + + /** + * @see org.elasticsearch.thrift.Status + */ + public Status getStatus() { + return this.status; + } + + /** + * @see org.elasticsearch.thrift.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 asigned 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 asigned a value) and false otherwise + */ + public boolean isSetHeaders() { + return this.headers != null; + } + + public void setHeadersIsSet(boolean value) { + if (!value) { + this.headers = null; + } + } + + public ByteBuffer getBody() { + return this.body; + } + + 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 asigned 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 void setFieldValue(int fieldID, Object value) { + setFieldValue(_Fields.findByThriftIdOrThrow(fieldID), value); + } + + public Object getFieldValue(_Fields field) { + switch (field) { + case STATUS: + return getStatus(); + + case HEADERS: + return getHeaders(); + + case BODY: + return getBody(); + + } + throw new IllegalStateException(); + } + + public Object getFieldValue(int fieldId) { + return getFieldValue(_Fields.findByThriftIdOrThrow(fieldId)); + } + + /** + * Returns true if field corresponding to fieldID is set (has been asigned a value) and false otherwise + */ + public boolean isSet(_Fields field) { + switch (field) { + case STATUS: + return isSetStatus(); + case HEADERS: + return isSetHeaders(); + case BODY: + return isSetBody(); + } + throw new IllegalStateException(); + } + + public boolean isSet(int fieldID) { + return isSet(_Fields.findByThriftIdOrThrow(fieldID)); + } + + @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 = 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 = 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 = TBaseHelper.compareTo(this.body, typedOther.body); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + public void read(TProtocol iprot) throws TException { + TField field; + iprot.readStructBegin(); + while (true) { + field = iprot.readFieldBegin(); + if (field.type == TType.STOP) { + break; + } + switch (field.id) { + case 1: // STATUS + if (field.type == TType.I32) { + this.status = Status.findByValue(iprot.readI32()); + } else { + TProtocolUtil.skip(iprot, field.type); + } + break; + case 2: // HEADERS + if (field.type == TType.MAP) { + { + 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 { + TProtocolUtil.skip(iprot, field.type); + } + break; + case 3: // BODY + if (field.type == TType.STRING) { + this.body = iprot.readBinary(); + } else { + TProtocolUtil.skip(iprot, field.type); + } + break; + default: + 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(TProtocol oprot) throws 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 TMap(TType.STRING, 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 { + TBaseHelper.toString(this.body, sb); + } + first = false; + } + sb.append(")"); + return sb.toString(); + } + + public void validate() throws TException { + // check for required fields + if (status == null) { + throw new TProtocolException("Required field 'status' was not present! Struct: " + toString()); + } + } + +} + 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 new file mode 100644 index 00000000000..77a39fe733b --- /dev/null +++ b/plugins/transport/thrift/src/main/gen-java/org/elasticsearch/thrift/Status.java @@ -0,0 +1,169 @@ +/** + * Autogenerated by Thrift + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + */ +package org.elasticsearch.thrift; + + +import org.apache.thrift.TEnum; + +public enum Status implements TEnum { + CONTINUE(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 CONTINUE; + 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 new file mode 100644 index 00000000000..b22b8c42ade --- /dev/null +++ b/plugins/transport/thrift/src/main/java/es-plugin.properties @@ -0,0 +1 @@ +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 new file mode 100644 index 00000000000..41022da5299 --- /dev/null +++ b/plugins/transport/thrift/src/main/java/org/elasticsearch/plugin/transport/thrift/ThriftTransportPlugin.java @@ -0,0 +1,67 @@ +/* + * 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 new file mode 100644 index 00000000000..8da5638c252 --- /dev/null +++ b/plugins/transport/thrift/src/main/java/org/elasticsearch/thrift/ThriftRestImpl.java @@ -0,0 +1,167 @@ +/* + * 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.settings.Settings; +import org.elasticsearch.rest.RestChannel; +import org.elasticsearch.rest.RestController; +import org.elasticsearch.rest.RestResponse; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.atomic.AtomicReference; + +/** + * @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 { + final CountDownLatch latch = new CountDownLatch(1); + final AtomicReference ref = new AtomicReference(); + restController.dispatchRequest(new ThriftRestRequest(request), new RestChannel() { + @Override public void sendResponse(RestResponse response) { + ref.set(response); + latch.countDown(); + } + }); + try { + latch.await(); + return convert(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) { + tResponse.setBody(ByteBuffer.wrap(response.content(), 0, response.contentLength())); + } + return tResponse; + } + + private Status getStatus(RestResponse.Status status) { + switch (status) { + case CONTINUE: + return Status.CONTINUE; + 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 new file mode 100644 index 00000000000..1afd6b6466e --- /dev/null +++ b/plugins/transport/thrift/src/main/java/org/elasticsearch/thrift/ThriftRestRequest.java @@ -0,0 +1,142 @@ +/* + * 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.Unicode; +import org.elasticsearch.common.collect.ImmutableSet; +import org.elasticsearch.rest.support.AbstractRestRequest; +import org.elasticsearch.rest.support.RestUtils; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +/** + * @author kimchy (shay.banon) + */ +public class ThriftRestRequest extends AbstractRestRequest implements org.elasticsearch.rest.RestRequest { + + private final org.elasticsearch.thrift.RestRequest request; + + private final String path; + + private final Map params; + + public ThriftRestRequest(org.elasticsearch.thrift.RestRequest request) { + this.request = request; + this.params = request.getParams() == null ? new HashMap() : request.getParams(); + + int pathEndPos = request.getUri().indexOf('?'); + if (pathEndPos < 0) { + this.path = request.getUri(); + } else { + this.path = 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 path() { + return this.path; + } + + @Override public boolean hasContent() { + return request.getBody() != null && request.getBody().remaining() > 0; + } + + @Override public boolean contentUnsafe() { + return false; + } + + @Override public byte[] contentByteArray() { + return request.getBody().array(); + } + + @Override public int contentByteArrayOffset() { + return request.getBody().arrayOffset(); + } + + @Override public int contentLength() { + return request.getBody().remaining(); + } + + @Override public String contentAsString() { + return Unicode.fromBytes(contentByteArray(), contentByteArrayOffset(), contentLength()); + } + + @Override public Set headerNames() { + if (request.getHeaders() == null) { + return ImmutableSet.of(); + } + return request.getHeaders().keySet(); + } + + @Override public String header(String name) { + if (request.getHeaders() == null) { + return null; + } + return request.getHeaders().get(name); + } + + @Override public String cookie() { + 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 value; + } + return defaultValue; + } +} 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 new file mode 100644 index 00000000000..feeeddc0104 --- /dev/null +++ b/plugins/transport/thrift/src/main/java/org/elasticsearch/thrift/ThriftServer.java @@ -0,0 +1,143 @@ +/* + * 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.THsHaServer; +import org.apache.thrift.server.TNonblockingServer; +import org.apache.thrift.server.TServer; +import org.apache.thrift.server.TThreadPoolServer; +import org.apache.thrift.transport.*; +import org.elasticsearch.ElasticSearchException; +import org.elasticsearch.action.admin.cluster.node.info.TransportNodesInfoAction; +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.transport.BindTransportException; + +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 String type; + + final String port; + + final String bindHost; + + final String publishHost; + + private final NetworkService networkService; + + private final TransportNodesInfoAction nodesInfoAction; + + private final ThriftRestImpl client; + + private final TProtocolFactory protocolFactory; + + private volatile TServer server; + + private volatile int portNumber; + + @Inject public ThriftServer(Settings settings, NetworkService networkService, TransportNodesInfoAction nodesInfoAction, ThriftRestImpl client) { + super(settings); + this.client = client; + this.networkService = networkService; + this.nodesInfoAction = nodesInfoAction; + this.type = componentSettings.get("type", "threadpool"); + this.port = componentSettings.get("port", "9500-9600"); + this.bindHost = componentSettings.get("bind_host"); + this.publishHost = componentSettings.get("publish_host"); + + if (componentSettings.get("protocol", "binary").equals("compact")) { + protocolFactory = new TCompactProtocol.Factory(); + } else { + protocolFactory = new TBinaryProtocol.Factory(); + } + } + + @Override protected void doStart() throws ElasticSearchException { + 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); + if ("threadpool_framed".equals(type) || "threadpool".equals("threadpool")) { + TTransportFactory transportFactory; + if ("threadpool_framed".equals(type)) { + transportFactory = new TFramedTransport.Factory(); + } else { + transportFactory = new TTransportFactory(); + } + TServerTransport serverTransport = new TServerSocket(portNumber); + server = new TThreadPoolServer(processor, serverTransport, transportFactory, protocolFactory); + } else if ("nonblocking".equals(type) || "hsha".equals(type)) { + TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(portNumber); + TFramedTransport.Factory transportFactory = new TFramedTransport.Factory(); + if ("nonblocking".equals(type)) { + server = new TNonblockingServer(processor, serverTransport, transportFactory, protocolFactory); + } else { + server = new THsHaServer(processor, serverTransport, transportFactory, protocolFactory); + } + } + } 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 { + nodesInfoAction.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 { + nodesInfoAction.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 new file mode 100644 index 00000000000..6034a52dce9 --- /dev/null +++ b/plugins/transport/thrift/src/main/java/org/elasticsearch/thrift/ThriftServerModule.java @@ -0,0 +1,40 @@ +/* + * 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 new file mode 100644 index 00000000000..0bdf2dafea4 --- /dev/null +++ b/plugins/transport/thrift/src/test/java/org/elasticsearch/thrift/test/SimpleThriftTests.java @@ -0,0 +1,84 @@ +/* + * 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.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.node.Node; +import org.elasticsearch.thrift.*; +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("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.OK)); + assertThat(map.get("ok").toString(), equalTo("true")); + assertThat(map.get("_index").toString(), equalTo("test")); + assertThat(map.get("_type").toString(), equalTo("type1")); + } + + private Map parseBody(RestResponse response) throws IOException { + return XContentFactory.xContent(XContentType.JSON).createParser(response.getBody().array(), response.getBody().arrayOffset(), response.getBody().remaining()).map(); + } +} diff --git a/settings.gradle b/settings.gradle index a88c55c07bf..601c039e206 100644 --- a/settings.gradle +++ b/settings.gradle @@ -14,6 +14,7 @@ include 'plugins-analysis-icu' include 'plugins-mapper-attachments' include 'plugins-client-groovy' include 'plugins-transport-memcached' +include 'plugins-transport-thrift' rootProject.name = 'elasticsearch-root' rootProject.children.each {project ->