Closer to compiling

Original commit: elastic/x-pack-elasticsearch@630bd7967d
This commit is contained in:
Nik Everett 2017-06-20 14:03:53 -04:00
parent b00105f608
commit 593e6572c1
23 changed files with 82 additions and 77 deletions

View File

@ -86,6 +86,7 @@ dependencies {
// sql deps // sql deps
compile project(':x-pack-elasticsearch:sql-clients:jdbc-proto') compile project(':x-pack-elasticsearch:sql-clients:jdbc-proto')
compile project(':x-pack-elasticsearch:sql-clients:cli-proto') compile project(':x-pack-elasticsearch:sql-clients:cli-proto')
compile 'org.antlr:antlr4-runtime:4.5.1-1'
// common test deps // common test deps
testCompile 'org.elasticsearch:securemock:1.2' testCompile 'org.elasticsearch:securemock:1.2'

View File

@ -84,4 +84,9 @@ public class HttpCliAction extends BaseRestHandler {
} }
channel.sendResponse(response); channel.sendResponse(response);
} }
@Override
public String getName() {
return "sql_cli_action";
}
} }

View File

@ -85,4 +85,9 @@ public class HttpJdbcAction extends BaseRestHandler {
} }
channel.sendResponse(response); channel.sendResponse(response);
} }
@Override
public String getName() {
return "sql_jdbc_action";
}
} }

View File

@ -58,26 +58,32 @@ public class RestSqlAction extends BaseRestHandler {
} }
channel.sendResponse(response); channel.sendResponse(response);
} }
}
class Payload { @Override
static final ObjectParser<Payload, Void> PARSER = new ObjectParser<>("sql/query"); public String getName() {
return "sql_action";
static {
PARSER.declareString(Payload::setQuery, new ParseField("query"));
} }
String query; static class Payload {
static final ObjectParser<Payload, Void> PARSER = new ObjectParser<>("sql/query");
static Payload from(RestRequest request) throws IOException { static {
Payload payload = new Payload(); PARSER.declareString(Payload::setQuery, new ParseField("query"));
try (XContentParser parser = request.contentParser()) {
Payload.PARSER.parse(parser, payload, null);
} }
return payload; String query;
}
public void setQuery(String query) { static Payload from(RestRequest request) throws IOException {
this.query = query; Payload payload = new Payload();
try (XContentParser parser = request.contentParser()) {
Payload.PARSER.parse(parser, payload, null);
}
return payload;
}
public void setQuery(String query) {
this.query = query;
}
} }
} }

View File

@ -1,7 +1,8 @@
apply plugin: 'elasticsearch.build' apply plugin: 'elasticsearch.build'
apply plugin: 'application' apply plugin: 'application'
project.compactProfile = 'full'
dependencies { dependencies {
compile "org.jline:jline:3.3.0" compile "org.jline:jline:3.3.0"
@ -9,6 +10,7 @@ dependencies {
compile project(':x-pack-elasticsearch:sql-clients:cli-proto') compile project(':x-pack-elasticsearch:sql-clients:cli-proto')
testCompile project(":x-pack-elasticsearch:transport-client") testCompile project(":x-pack-elasticsearch:transport-client")
testCompile project(':x-pack-elasticsearch:sql-clients:test-utils')
} }
// TODO seems like we should use the jars.... // TODO seems like we should use the jars....

View File

@ -5,15 +5,6 @@
*/ */
package org.elasticsearch.xpack.sql.cli; package org.elasticsearch.xpack.sql.cli;
import java.awt.Desktop;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Locale;
import java.util.Properties;
import org.elasticsearch.xpack.sql.cli.net.client.HttpCliClient; import org.elasticsearch.xpack.sql.cli.net.client.HttpCliClient;
import org.elasticsearch.xpack.sql.cli.net.protocol.CommandResponse; import org.elasticsearch.xpack.sql.cli.net.protocol.CommandResponse;
import org.elasticsearch.xpack.sql.cli.net.protocol.InfoResponse; import org.elasticsearch.xpack.sql.cli.net.protocol.InfoResponse;
@ -27,6 +18,15 @@ import org.jline.terminal.Terminal;
import org.jline.terminal.TerminalBuilder; import org.jline.terminal.TerminalBuilder;
import org.jline.utils.InfoCmp.Capability; import org.jline.utils.InfoCmp.Capability;
import java.awt.Desktop;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Locale;
import java.util.Properties;
import static java.lang.String.format; import static java.lang.String.format;
public class Cli { public class Cli {

View File

@ -23,7 +23,7 @@ class Keys {
final KeyMap<Key> keys = new KeyMap<>(); final KeyMap<Key> keys = new KeyMap<>();
public Keys(Terminal terminal) { Keys(Terminal terminal) {
keys.setNomatch(Key.NONE); keys.setNomatch(Key.NONE);
keys.setAmbiguousTimeout(400); keys.setAmbiguousTimeout(400);
keys.bind(Key.UP, key(terminal, Capability.key_up)); keys.bind(Key.UP, key(terminal, Capability.key_up));

View File

@ -24,6 +24,10 @@ import org.elasticsearch.xpack.sql.cli.net.protocol.Proto.Action;
import org.elasticsearch.xpack.sql.net.client.util.Bytes; import org.elasticsearch.xpack.sql.net.client.util.Bytes;
public class HttpCliClient implements AutoCloseable { public class HttpCliClient implements AutoCloseable {
@FunctionalInterface
interface DataInputFunction<R> {
R apply(DataInput in) throws IOException;
}
private final HttpClient http; private final HttpClient http;
private final CliConfiguration cfg; private final CliConfiguration cfg;
@ -89,8 +93,3 @@ public class HttpCliClient implements AutoCloseable {
public void close() {} public void close() {}
} }
@FunctionalInterface
interface DataInputFunction<R> {
R apply(DataInput in) throws IOException;
}

View File

@ -6,7 +6,7 @@
package org.elasticsearch.xpack.sql.cli.integration.server; package org.elasticsearch.xpack.sql.cli.integration.server;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
import org.elasticsearch.xpack.sql.net.client.integration.server.ProtoHttpServer; import org.elasticsearch.xpack.sql.test.server.ProtoHttpServer;
public class CliHttpServer extends ProtoHttpServer { public class CliHttpServer extends ProtoHttpServer {

View File

@ -12,9 +12,9 @@ import org.elasticsearch.xpack.sql.TestUtils;
import org.elasticsearch.xpack.sql.cli.net.protocol.ProtoUtils; import org.elasticsearch.xpack.sql.cli.net.protocol.ProtoUtils;
import org.elasticsearch.xpack.sql.cli.net.protocol.Request; import org.elasticsearch.xpack.sql.cli.net.protocol.Request;
import org.elasticsearch.xpack.sql.cli.net.protocol.Response; import org.elasticsearch.xpack.sql.cli.net.protocol.Response;
import org.elasticsearch.xpack.sql.net.client.integration.server.ProtoHandler;
import org.elasticsearch.xpack.sql.plugin.cli.http.CliServerProtoUtils; import org.elasticsearch.xpack.sql.plugin.cli.http.CliServerProtoUtils;
import org.elasticsearch.xpack.sql.plugin.cli.server.CliServer; import org.elasticsearch.xpack.sql.plugin.cli.server.CliServer;
import org.elasticsearch.xpack.sql.test.server.ProtoHandler;
import java.io.DataInput; import java.io.DataInput;
import java.io.IOException; import java.io.IOException;

View File

@ -37,6 +37,7 @@ dependencies {
compile project(':x-pack-elasticsearch:sql-clients:jdbc-proto') compile project(':x-pack-elasticsearch:sql-clients:jdbc-proto')
testCompile project(":x-pack-elasticsearch:transport-client") testCompile project(":x-pack-elasticsearch:transport-client")
testCompile project(':x-pack-elasticsearch:sql-clients:test-utils')
testRuntime "com.h2database:h2:1.4.194" testRuntime "com.h2database:h2:1.4.194"
testRuntime "net.sourceforge.csvjdbc:csvjdbc:1.0.31" testRuntime "net.sourceforge.csvjdbc:csvjdbc:1.0.31"

View File

@ -38,6 +38,10 @@ import org.elasticsearch.xpack.sql.jdbc.util.BytesArray;
import org.elasticsearch.xpack.sql.jdbc.util.FastByteArrayInputStream; import org.elasticsearch.xpack.sql.jdbc.util.FastByteArrayInputStream;
public class HttpJdbcClient implements Closeable { public class HttpJdbcClient implements Closeable {
@FunctionalInterface
interface DataInputFunction<R> {
R apply(DataInput in) throws IOException, SQLException;
}
private final HttpClient http; private final HttpClient http;
private final JdbcConfiguration conCfg; private final JdbcConfiguration conCfg;
@ -203,8 +207,3 @@ public class HttpJdbcClient implements Closeable {
throw new JdbcException("Invalid response status %08X", header); throw new JdbcException("Invalid response status %08X", header);
} }
} }
@FunctionalInterface
interface DataInputFunction<R> {
R apply(DataInput in) throws IOException, SQLException;
}

View File

@ -35,7 +35,7 @@ public class FastByteArrayInputStream extends InputStream {
* position within the buffer by the <code>mark()</code> method. * position within the buffer by the <code>mark()</code> method.
* The current buffer position is set to this point by the * The current buffer position is set to this point by the
* <code>reset()</code> method. * <code>reset()</code> method.
* <p/> * <p>
* If no mark has been set, then the value of mark is the offset * If no mark has been set, then the value of mark is the offset
* passed to the constructor (or 0 if the offset was not supplied). * passed to the constructor (or 0 if the offset was not supplied).
* *
@ -82,7 +82,7 @@ public class FastByteArrayInputStream extends InputStream {
* <code>0</code> to <code>255</code>. If no byte is available * <code>0</code> to <code>255</code>. If no byte is available
* because the end of the stream has been reached, the value * because the end of the stream has been reached, the value
* <code>-1</code> is returned. * <code>-1</code> is returned.
* <p/> * <p>
* This <code>read</code> method * This <code>read</code> method
* cannot block. * cannot block.
* *
@ -108,7 +108,7 @@ public class FastByteArrayInputStream extends InputStream {
* by <code>System.arraycopy</code>. The * by <code>System.arraycopy</code>. The
* value <code>k</code> is added into <code>pos</code> * value <code>k</code> is added into <code>pos</code>
* and <code>k</code> is returned. * and <code>k</code> is returned.
* <p/> * <p>
* This <code>read</code> method cannot block. * This <code>read</code> method cannot block.
* *
* @param b the buffer into which the data is read. * @param b the buffer into which the data is read.
@ -169,7 +169,7 @@ public class FastByteArrayInputStream extends InputStream {
/** /**
* Returns the number of remaining bytes that can be read (or skipped over) * Returns the number of remaining bytes that can be read (or skipped over)
* from this input stream. * from this input stream.
* <p/> * <p>
* The value returned is <code>count&nbsp;- pos</code>, * The value returned is <code>count&nbsp;- pos</code>,
* which is the number of bytes remaining to be read from the input buffer. * which is the number of bytes remaining to be read from the input buffer.
* *
@ -200,11 +200,10 @@ public class FastByteArrayInputStream extends InputStream {
* ByteArrayInputStream objects are marked at position zero by * ByteArrayInputStream objects are marked at position zero by
* default when constructed. They may be marked at another * default when constructed. They may be marked at another
* position within the buffer by this method. * position within the buffer by this method.
* <p/> * <p>
* If no mark has been set, then the value of the mark is the * If no mark has been set, then the value of the mark is the
* offset passed to the constructor (or 0 if the offset was not * offset passed to the constructor (or 0 if the offset was not
* supplied). * supplied).
* <p/>
* <p> Note: The <code>readAheadLimit</code> for this class * <p> Note: The <code>readAheadLimit</code> for this class
* has no meaning. * has no meaning.
* *
@ -227,7 +226,6 @@ public class FastByteArrayInputStream extends InputStream {
* Closing a <tt>ByteArrayInputStream</tt> has no effect. The methods in * Closing a <tt>ByteArrayInputStream</tt> has no effect. The methods in
* this class can be called after the stream has been closed without * this class can be called after the stream has been closed without
* generating an <tt>IOException</tt>. * generating an <tt>IOException</tt>.
* <p/>
*/ */
public void close() {} public void close() {}

View File

@ -20,7 +20,7 @@ public class FastByteArrayOutputStream extends OutputStream {
/** /**
* Creates a new byte array output stream. The buffer capacity is * Creates a new byte array output stream. The buffer capacity is
* initially 1024 bytes, though its size increases if necessary. * initially 1024 bytes, though its size increases if necessary.
* <p/> * <p>
* ES: We use 1024 bytes since we mainly use this to build json/smile * ES: We use 1024 bytes since we mainly use this to build json/smile
* content in memory, and rarely does the 32 byte default in ByteArrayOutputStream fits... * content in memory, and rarely does the 32 byte default in ByteArrayOutputStream fits...
*/ */
@ -33,7 +33,6 @@ public class FastByteArrayOutputStream extends OutputStream {
* the specified size, in bytes. * the specified size, in bytes.
* *
* @param size the initial size. * @param size the initial size.
* @throws EsHadoopIllegalArgumentException if size is negative.
*/ */
public FastByteArrayOutputStream(int size) { public FastByteArrayOutputStream(int size) {
Assert.isTrue(size >= 0, "Negative initial size: " + size); Assert.isTrue(size >= 0, "Negative initial size: " + size);
@ -56,7 +55,7 @@ public class FastByteArrayOutputStream extends OutputStream {
/** /**
* Writes <code>len</code> bytes from the specified byte array * Writes <code>len</code> bytes from the specified byte array
* starting at offset <code>off</code> to this byte array output stream. * starting at offset <code>off</code> to this byte array output stream.
* <p/> * <p>
* <b>NO checks for bounds, parameters must be ok!</b> * <b>NO checks for bounds, parameters must be ok!</b>
* *
* @param b the data. * @param b the data.
@ -118,7 +117,6 @@ public class FastByteArrayOutputStream extends OutputStream {
* Closing a <tt>ByteArrayOutputStream</tt> has no effect. The methods in * Closing a <tt>ByteArrayOutputStream</tt> has no effect. The methods in
* this class can be called after the stream has been closed without * this class can be called after the stream has been closed without
* generating an <tt>IOException</tt>. * generating an <tt>IOException</tt>.
* <p/>
*/ */
public void close() throws IOException {} public void close() throws IOException {}
} }

View File

@ -6,7 +6,7 @@
package org.elasticsearch.xpack.sql.jdbc.integration.server; package org.elasticsearch.xpack.sql.jdbc.integration.server;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
import org.elasticsearch.xpack.sql.net.client.integration.server.ProtoHttpServer; import org.elasticsearch.xpack.sql.test.server.ProtoHttpServer;
public class JdbcHttpServer extends ProtoHttpServer { public class JdbcHttpServer extends ProtoHttpServer {

View File

@ -5,19 +5,19 @@
*/ */
package org.elasticsearch.xpack.sql.jdbc.integration.server; package org.elasticsearch.xpack.sql.jdbc.integration.server;
import java.io.DataInput; import com.sun.net.httpserver.HttpExchange;
import java.io.IOException;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
import org.elasticsearch.xpack.sql.TestUtils; import org.elasticsearch.xpack.sql.TestUtils;
import org.elasticsearch.xpack.sql.jdbc.net.protocol.ProtoUtils; import org.elasticsearch.xpack.sql.jdbc.net.protocol.ProtoUtils;
import org.elasticsearch.xpack.sql.jdbc.net.protocol.Request; import org.elasticsearch.xpack.sql.jdbc.net.protocol.Request;
import org.elasticsearch.xpack.sql.jdbc.net.protocol.Response; import org.elasticsearch.xpack.sql.jdbc.net.protocol.Response;
import org.elasticsearch.xpack.sql.net.client.integration.server.ProtoHandler;
import org.elasticsearch.xpack.sql.plugin.jdbc.server.JdbcServer; import org.elasticsearch.xpack.sql.plugin.jdbc.server.JdbcServer;
import org.elasticsearch.xpack.sql.plugin.jdbc.server.JdbcServerProtoUtils; import org.elasticsearch.xpack.sql.plugin.jdbc.server.JdbcServerProtoUtils;
import org.elasticsearch.xpack.sql.test.server.ProtoHandler;
import com.sun.net.httpserver.HttpExchange; import java.io.DataInput;
import java.io.IOException;
import static org.elasticsearch.action.ActionListener.wrap; import static org.elasticsearch.action.ActionListener.wrap;

View File

@ -6,7 +6,6 @@
package org.elasticsearch.xpack.sql.jdbc.integration.util; package org.elasticsearch.xpack.sql.jdbc.integration.util;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
import org.elasticsearch.xpack.sql.integration.es.LocalEs;
import org.elasticsearch.xpack.sql.jdbc.integration.server.JdbcHttpServer; import org.elasticsearch.xpack.sql.jdbc.integration.server.JdbcHttpServer;
import org.elasticsearch.xpack.sql.jdbc.integration.util.JdbcTemplate.JdbcSupplier; import org.elasticsearch.xpack.sql.jdbc.integration.util.JdbcTemplate.JdbcSupplier;
import org.elasticsearch.xpack.sql.jdbc.jdbc.JdbcDriver; import org.elasticsearch.xpack.sql.jdbc.jdbc.JdbcDriver;
@ -19,15 +18,12 @@ import java.util.Properties;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
public class EsJdbcServer extends ExternalResource implements JdbcSupplier<Connection> { public class EsJdbcServer extends ExternalResource implements JdbcSupplier<Connection> {
private final LocalEs es;
private JdbcHttpServer server; private JdbcHttpServer server;
private String jdbcUrl; private String jdbcUrl;
private JdbcDriver driver; private JdbcDriver driver;
private final Properties properties; private final Properties properties;
public EsJdbcServer(boolean remote, boolean debug) { public EsJdbcServer(boolean remote, boolean debug) {
es = (remote ? null : new LocalEs());
properties = new Properties(); properties = new Properties();
if (debug) { if (debug) {
properties.setProperty("debug", "true"); properties.setProperty("debug", "true");
@ -44,11 +40,7 @@ public class EsJdbcServer extends ExternalResource implements JdbcSupplier<Conne
@Override @Override
protected void before() throws Throwable { protected void before() throws Throwable {
if (es != null) { server = new JdbcHttpServer(null);
es.start();
}
server = new JdbcHttpServer(es != null ? es.client() : null);
driver = new JdbcDriver(); driver = new JdbcDriver();
server.start(0); server.start(0);
@ -59,9 +51,6 @@ public class EsJdbcServer extends ExternalResource implements JdbcSupplier<Conne
protected void after() { protected void after() {
server.stop(); server.stop();
server = null; server = null;
if (es != null) {
es.stop();
}
} }
public Connection jdbc() throws SQLException { public Connection jdbc() throws SQLException {

View File

@ -1,8 +1,3 @@
apply plugin: 'elasticsearch.build' apply plugin: 'elasticsearch.build'
description = 'Common base for protos' description = 'Common base things for protos'
// Tests have some testing utilities
dependencies {
testCompile "org.elasticsearch.client:transport:${version}"
}

View File

@ -0,0 +1,7 @@
apply plugin: 'elasticsearch.build'
description = 'Shared test utilities for jdbc and cli'
dependencies {
compile "org.elasticsearch.client:transport:${version}"
}

View File

@ -3,7 +3,7 @@
* or more contributor license agreements. Licensed under the Elastic License; * or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License. * you may not use this file except in compliance with the Elastic License.
*/ */
package org.elasticsearch.xpack.sql.net.client.integration.server; package org.elasticsearch.xpack.sql.test.server;
import java.io.IOException; import java.io.IOException;

View File

@ -3,7 +3,7 @@
* or more contributor license agreements. Licensed under the Elastic License; * or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License. * you may not use this file except in compliance with the Elastic License.
*/ */
package org.elasticsearch.xpack.sql.net.client.integration.server; package org.elasticsearch.xpack.sql.test.server;
import java.io.DataInput; import java.io.DataInput;
import java.io.DataInputStream; import java.io.DataInputStream;

View File

@ -3,7 +3,7 @@
* or more contributor license agreements. Licensed under the Elastic License; * or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License. * you may not use this file except in compliance with the Elastic License.
*/ */
package org.elasticsearch.xpack.sql.net.client.integration.server; package org.elasticsearch.xpack.sql.test.server;
import java.io.IOException; import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;

View File

@ -3,7 +3,7 @@
* or more contributor license agreements. Licensed under the Elastic License; * or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License. * you may not use this file except in compliance with the Elastic License.
*/ */
package org.elasticsearch.xpack.sql.net.client.integration.server; package org.elasticsearch.xpack.sql.test.server;
import java.io.IOException; import java.io.IOException;