Github user paul-rogers commented on a diff in the pull request:
https://github.com/apache/drill/pull/648#discussion_r87100583
--- Diff:
exec/java-exec/src/main/java/org/apache/drill/exec/client/DrillClient.java ---
@@ -223,19 +223,65 @@ public void connect(Properties props) throws
RpcException {
connect(null, props);
}
+ /**
+ * Function to populate the endpointList with information of all the
drillbits
+ * provided in the connection string by client
+ * @param endpointList - ArrayList of DrillbitEndpoints
+ * @param drillbits - One or more drillbit ip[:port] provided in
connection string
+ */
+ public void populateEndpointsList(ArrayList<DrillbitEndpoint>
endpointList, String drillbits){
+
+ // If no information about drillbits is provided then just return
empty list.
+ if(drillbits == null || drillbits.length() == 0){
+ return;
+ }
+ final String[] connectInfo = drillbits.split(",");
+
+ /* For direct connection we can get URL string having drillbit
property as below:
+ drillbit=<ip>:<port> --- Use the IP and port specified as the
Foreman IP and port
+ drillbit=<ip> --- Use the IP specified as the Foreman IP
with default port in config file
+ drillbit=<ip1>:<port1>,<ip2>:<port2>... --- Randomly select the
IP and port pair from the specified
+ list as the Foreman
IP and port.
+
+ Fetch ip address and port information for each drillbit and
populate the list
+ */
+ for(String info : connectInfo){
+ info = info.trim();
+
+ if(info != null){
+ // Split each info to get ip address and port value
+ final String[] drillbitInfo = info.split(":");
+
+ // Check for malformed ip:port string
+ if(drillbitInfo == null || drillbitInfo.length == 0){
+ continue;
+ }
+
+ /* If port is present use that one else use the configured one
+ Assumptions: 1) IP Address provided in connection string is
valid
+ 2) Port without IP address is never specified.
+ */
+ final String port = (drillbitInfo.length == 2) ? drillbitInfo[1] :
config.getString(ExecConstants.INITIAL_USER_PORT);
+ final DrillbitEndpoint endpoint = DrillbitEndpoint.newBuilder()
+ .setAddress(drillbitInfo[0])
+
.setUserPort(Integer.parseInt(port))
+ .build();
+ endpointList.add(endpoint);
+ }
+ }
+ }
+
public synchronized void connect(String connect, Properties props)
throws RpcException {
if (connected) {
return;
}
final DrillbitEndpoint endpoint;
+ final ArrayList<DrillbitEndpoint> endpoints = new ArrayList<>();
if (isDirectConnection) {
- final String[] connectInfo =
props.getProperty("drillbit").split(":");
- final String port =
connectInfo.length==2?connectInfo[1]:config.getString(ExecConstants.INITIAL_USER_PORT);
- endpoint = DrillbitEndpoint.newBuilder()
- .setAddress(connectInfo[0])
- .setUserPort(Integer.parseInt(port))
- .build();
+ // Populate the endpoints list with all the drillbit information
provided in the
+ // connection string
+ populateEndpointsList(endpoints,
props.getProperty("drillbit").trim());
--- End diff --
Actually, the code here would be cleaner as:
final List<DrillbitEndpoint> endpoints = parseEndpoints(
props.getProperty("drillbit") );
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---