-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from zapr-oss/develop
Releasing Druid Client and version bumped to 2.0
- Loading branch information
Showing
14 changed files
with
508 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/java/in/zapr/druid/druidry/client/DruidClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package in.zapr.druid.druidry.client; | ||
|
||
import java.util.List; | ||
|
||
import in.zapr.druid.druidry.client.exception.ConnectionException; | ||
import in.zapr.druid.druidry.client.exception.QueryException; | ||
import in.zapr.druid.druidry.query.DruidQuery; | ||
|
||
public interface DruidClient { | ||
|
||
/** | ||
* Connects with Druid | ||
* | ||
* @throws ConnectionException When connection is not formed | ||
*/ | ||
void connect() throws ConnectionException; | ||
|
||
/** | ||
* Closes connection with Druid | ||
* @throws ConnectionException When connection is not closed | ||
*/ | ||
void close() throws ConnectionException; | ||
|
||
/** | ||
* Queries druid | ||
* | ||
* @param druidQuery Druid Query object | ||
* @return Result from Druid | ||
* @throws QueryException Error while querying | ||
*/ | ||
String query(DruidQuery druidQuery) throws QueryException; | ||
|
||
/** | ||
* Queries druid | ||
* | ||
* @param druidQuery Druid Query Object | ||
* @param className Class according to which DruidResult should be converted to | ||
* @param <T> Class according to which DruidResult should be converted to | ||
* @return Druid Result in the form of class T object | ||
* @throws QueryException Error while querying | ||
*/ | ||
<T> List<T> query(DruidQuery druidQuery, Class<T> className) throws QueryException; | ||
} |
104 changes: 104 additions & 0 deletions
104
src/main/java/in/zapr/druid/druidry/client/DruidConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package in.zapr.druid.druidry.client; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
public class DruidConfiguration { | ||
|
||
private static final int DEFAULT_HTTP_PORT = 8082; | ||
private static final int DEFAULT_HTTPS_PORT = 8282; | ||
|
||
/** | ||
* Protocol by which Druid Broker is accessible | ||
* Defaults to HTTP | ||
*/ | ||
private DruidQueryProtocol protocol; | ||
|
||
/** | ||
* Address of Druid Broker Instance | ||
*/ | ||
private String host; | ||
|
||
/** | ||
* Port at which Druid Broker is listening. | ||
* {@value DEFAULT_HTTP_PORT} if protocol is 8082 | ||
* {@value DEFAULT_HTTPS_PORT} if protocol is 8282 | ||
*/ | ||
private Integer port; | ||
|
||
/** | ||
* Endpoint (without host address) at which query needs to be fired | ||
*/ | ||
private String endpoint; | ||
|
||
/** | ||
* Number of connections to be maintained in connection pool | ||
* Is Ignored when custom JerseyConfig is passed. | ||
*/ | ||
private Integer concurrentConnectionsRequired; | ||
|
||
@Builder | ||
private DruidConfiguration(DruidQueryProtocol protocol, | ||
String host, | ||
Integer port, | ||
String endpoint, | ||
Integer concurrentConnectionsRequired) { | ||
|
||
if (StringUtils.isEmpty(host)) { | ||
throw new IllegalArgumentException("Host cannot be null or empty"); | ||
} | ||
|
||
if (port != null && port < 0) { | ||
throw new IllegalArgumentException("Port cannot be negative"); | ||
} | ||
|
||
if (concurrentConnectionsRequired != null && concurrentConnectionsRequired < 1) { | ||
throw new IllegalArgumentException("Connections required cannot be less than 1"); | ||
} | ||
|
||
if (protocol == null) { | ||
protocol = DruidQueryProtocol.HTTP; | ||
} | ||
|
||
if (port == null) { | ||
port = getDefaultPortOnBasisOfProtocol(protocol); | ||
} | ||
|
||
this.protocol = protocol; | ||
this.host = host; | ||
this.port = port; | ||
this.endpoint = endpoint; | ||
this.concurrentConnectionsRequired = concurrentConnectionsRequired; | ||
} | ||
|
||
protected String getUrl() { | ||
|
||
String endpoint = this.getEndpoint(); | ||
if (endpoint == null) { | ||
endpoint = ""; | ||
} | ||
|
||
return String.format("%s://%s:%d/%s", | ||
this.getProtocol(), | ||
this.getHost(), | ||
this.getPort(), | ||
endpoint); | ||
} | ||
|
||
private Integer getDefaultPortOnBasisOfProtocol(DruidQueryProtocol protocol) { | ||
|
||
switch (protocol) { | ||
case HTTP: | ||
return DEFAULT_HTTP_PORT; | ||
case HTTPS: | ||
return DEFAULT_HTTPS_PORT; | ||
default: | ||
throw new IllegalArgumentException("Druid Query Protocol not handled"); | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/in/zapr/druid/druidry/client/DruidError.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package in.zapr.druid.druidry.client; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class DruidError { | ||
|
||
private String error; | ||
private String errorMessage; | ||
private String errorClass; | ||
private String host; | ||
} |
Oops, something went wrong.