Use embedded client inside the planner as well

Original commit: elastic/x-pack-elasticsearch@c9d20672be
This commit is contained in:
Costin Leau 2017-10-11 22:08:20 +03:00
parent 125f140620
commit d6881e25c9
4 changed files with 16 additions and 8 deletions

View File

@ -24,7 +24,7 @@ class CliProtoHandler extends ProtoHandler {
private final RestSqlCliAction action;
CliProtoHandler(Client client) {
super(new EmbeddedModeFilterClient(client, planExecutor(client)));
super(client);
action = new RestSqlCliAction(Settings.EMPTY, mock(RestController.class));
}

View File

@ -23,15 +23,20 @@ import org.elasticsearch.xpack.sql.plugin.sql.action.SqlRequest;
import org.elasticsearch.xpack.sql.plugin.sql.action.SqlResponse;
import org.elasticsearch.xpack.sql.plugin.sql.action.TransportSqlAction;
import java.util.Objects;
/**
* Implements embedded sql mode by intercepting requests to SQL APIs and executing them locally.
*/
public class EmbeddedModeFilterClient extends FilterClient {
private final PlanExecutor planExecutor;
private PlanExecutor planExecutor;
public EmbeddedModeFilterClient(Client in, PlanExecutor planExecutor) {
public EmbeddedModeFilterClient(Client in) {
super(in);
this.planExecutor = planExecutor;
}
public void setPlanExecutor(PlanExecutor executor) {
this.planExecutor = executor;
}
@Override
@ -41,6 +46,8 @@ public class EmbeddedModeFilterClient extends FilterClient {
RequestBuilder extends ActionRequestBuilder<Request, Response, RequestBuilder>>
void doExecute(Action<Request, Response, RequestBuilder> action,
Request request, ActionListener<Response> listener) {
Objects.requireNonNull(planExecutor, "plan executor not set on EmbeddedClient");
if (action == SqlAction.INSTANCE) {
TransportSqlAction.operation(planExecutor, (SqlRequest) request, (ActionListener<SqlResponse>) listener);
} else if (action == SqlGetIndicesAction.INSTANCE) {

View File

@ -25,7 +25,7 @@ class JdbcProtoHandler extends ProtoHandler {
private final RestSqlJdbcAction action;
JdbcProtoHandler(Client client) {
super(new EmbeddedModeFilterClient(client, planExecutor(client)));
super(client);
action = new RestSqlJdbcAction(Settings.EMPTY, mock(RestController.class), new SqlLicenseChecker(() -> {}, () -> {}));
}

View File

@ -28,7 +28,7 @@ import java.util.function.Supplier;
import static org.elasticsearch.common.unit.TimeValue.timeValueMinutes;
public abstract class ProtoHandler implements HttpHandler, AutoCloseable {
protected static PlanExecutor planExecutor(Client client) {
private static PlanExecutor planExecutor(EmbeddedModeFilterClient client) {
Supplier<ClusterState> clusterStateSupplier =
() -> client.admin().cluster().prepareState().get(timeValueMinutes(1)).getState();
return new PlanExecutor(client, clusterStateSupplier, EsCatalog::new);
@ -37,13 +37,14 @@ public abstract class ProtoHandler implements HttpHandler, AutoCloseable {
protected static final Logger log = ESLoggerFactory.getLogger(ProtoHandler.class.getName());
private final TimeValue TV = TimeValue.timeValueSeconds(5);
protected final Client client;
protected final EmbeddedModeFilterClient client;
protected final NodeInfo info;
protected final String clusterName;
protected ProtoHandler(Client client) {
NodesInfoResponse niResponse = client.admin().cluster().prepareNodesInfo("_local").clear().get(TV);
this.client = client;
this.client = !(client instanceof EmbeddedModeFilterClient) ? new EmbeddedModeFilterClient(client) : (EmbeddedModeFilterClient) client;
this.client.setPlanExecutor(planExecutor(this.client));
info = niResponse.getNodes().get(0);
clusterName = niResponse.getClusterName().value();
}