You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by no...@apache.org on 2020/08/06 07:47:48 UTC
[lucene-solr] 01/01: The interfaces
This is an automated email from the ASF dual-hosted git repository.
noble pushed a commit to branch jira/solr14712
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git
commit 675e42573bcf621b4307f405c29bf67c4b459392
Author: noblepaul <no...@gmail.com>
AuthorDate: Thu Aug 6 17:46:52 2020 +1000
The interfaces
---
.../solr/client/solrj/impl/CloudSolrClient.java | 8 ++
.../solr/client/solrj/impl/RpcFactoryImpl.java | 18 +++
.../org/apache/solr/common/util/RpcFactory.java | 133 +++++++++++++++++++++
3 files changed, 159 insertions(+)
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java
index cb9e7c2..8af1892 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java
@@ -32,6 +32,7 @@ import org.apache.solr.common.cloud.DocCollection;
import org.apache.solr.common.cloud.DocRouter;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.util.NamedList;
+import org.apache.solr.common.util.RpcFactory;
/**
* SolrJ client class to communicate with SolrCloud.
@@ -478,4 +479,11 @@ public class CloudSolrClient extends BaseCloudSolrClient {
return this;
}
}
+
+ private final RpcFactory factory = new RpcFactoryImpl(this);
+
+ public RpcFactory getRpcFactory() {
+ return factory;
+
+ }
}
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/RpcFactoryImpl.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/RpcFactoryImpl.java
new file mode 100644
index 0000000..31071c0
--- /dev/null
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/RpcFactoryImpl.java
@@ -0,0 +1,18 @@
+package org.apache.solr.client.solrj.impl;
+
+import org.apache.solr.common.util.RpcFactory;
+
+public class RpcFactoryImpl implements RpcFactory {
+ private final CloudSolrClient cloudSolrClient;
+
+ RpcFactoryImpl(CloudSolrClient cloudSolrClient) {
+ this.cloudSolrClient = cloudSolrClient;
+ }
+
+ @Override
+ //TODO
+ public Rpc create() {
+ return null;
+ }
+
+}
diff --git a/solr/solrj/src/java/org/apache/solr/common/util/RpcFactory.java b/solr/solrj/src/java/org/apache/solr/common/util/RpcFactory.java
new file mode 100644
index 0000000..0f8be4f
--- /dev/null
+++ b/solr/solrj/src/java/org/apache/solr/common/util/RpcFactory.java
@@ -0,0 +1,133 @@
+package org.apache.solr.common.util;
+
+import org.apache.solr.client.solrj.SolrRequest;
+import org.apache.solr.common.SolrException;
+import org.apache.solr.common.cloud.Replica;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Map;
+import java.util.function.Function;
+
+public interface RpcFactory {
+
+ Rpc create();
+
+
+ interface Rpc {
+ /** A request is made to the leader of the shard
+ *
+ */
+ Rpc toShardLeader(String collection, String shard);
+
+ /** Make a request to any replica of the shard
+ */
+ Rpc toShard(String collection, String shard);
+
+ /** Make a request to any replica of the shard of type
+ */
+ Rpc toShard(String collection, String shard, Replica.Type type);
+
+ /**Identify the shard using the routeKey and send the request to the leader
+ * replica
+ */
+ Rpc routeToShardLeader(String collection, String routeKey);
+
+ /**Identify the shard using the route key and send the request to a given replica type
+ */
+ Rpc routeToShard(String collection, String routeKey, Replica.Type type);
+
+ /**Identify the shard using the route key and send the request to a random replica
+ */
+ Rpc routeToShard(String collection, String routeKey);
+ /**Make a request to a specific replica
+ */
+ Rpc toReplica(String collection, String shard, String replica);
+
+ /**To any dolr vore that may host this collection
+ */
+ Rpc toCollection(String collection);
+
+ /**The request is to a specific node
+ *
+ */
+ Rpc withTargetNode(String node);
+
+ /** Add a request param
+ */
+ Rpc addParam(String key, String val);
+
+ /**Add multiple request params
+ */
+ Rpc addParams(Map<String, String> params);
+
+ /** Add a request header
+ */
+ Rpc addHeader(String key, String val);
+
+ /**Consumer for the response data
+ */
+ Rpc withResponseConsumer(OutputConsumer sink);
+
+ /** Use Send a payload
+ */
+ Rpc withPayload(InputSupplier payload);
+
+ /**Http method
+ */
+ Rpc withHttpMethod(SolrRequest.METHOD method);
+
+ /**The uri. The semantics depends on
+ * whether it is made to a node or replica
+ * if it is a shard/replica the uri is the name of the handler
+ * if it is node it is a full path
+ */
+ Rpc withV1Uri(String uri);
+
+ /**The uri. The semantics depends on
+ * whether it is made to a node or replica
+ * if it is a shard/replica the uri is the name of the handler
+ * if it is node it is a full path
+ */
+ Rpc withV2Uri(String uri);
+
+
+ /**Invoke a synchronous request. The return object depends on the output of the
+ * {@link OutputConsumer}
+ */
+ Object invoke() throws RPCException;
+
+ }
+
+ interface OutputConsumer {
+ Object accept(InputStream is) throws IOException;
+ }
+
+ /**Provide the payload stream
+ *
+ */
+ interface InputSupplier {
+ void write(OutputStream os) throws IOException;
+
+ String getContentType();
+ }
+
+
+ class RPCException extends SolrException {
+
+ public RPCException(ErrorCode code, String msg) {
+ super(code, msg);
+ }
+ }
+ /** Consumer of header data
+ */
+ interface HeaderConsumer {
+ /**
+ * read all required values from the header
+ * @param status the HTTP status code
+ * @return true to proceed to processing body. if false , ignore the body
+ */
+ boolean readHeader(int status, Function<String, String> headerProvider);
+ }
+}