Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
Implement Issue influxdata#389 : Support for MessagePack
Browse files Browse the repository at this point in the history
  • Loading branch information
lxhoan committed Jun 13, 2018
1 parent f9ca92f commit f1c4519
Show file tree
Hide file tree
Showing 8 changed files with 497 additions and 99 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,11 @@
<artifactId>converter-moshi</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>org.komamitsu</groupId>
<artifactId>retrofit-converter-msgpack</artifactId>
<version>1.0.0</version>
</dependency>
<!-- If we use okhttp instead of java urlconnection we achieve server failover
of the influxdb server address resolves to all influxdb server ips. -->
<dependency>
Expand Down
23 changes: 22 additions & 1 deletion src/main/java/org/influxdb/InfluxDBFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,30 @@ public static InfluxDB connect(final String url, final OkHttpClient.Builder clie
*/
public static InfluxDB connect(final String url, final String username, final String password,
final OkHttpClient.Builder client) {
return connect(url, username, password, client, false);
}

/**
* Create a connection to a InfluxDB.
*
* @param url
* the url to connect to.
* @param username
* the username which is used to authorize against the influxDB instance.
* @param password
* the password for the username which is used to authorize against the influxDB
* instance.
* @param client
* the HTTP client to use
* @param useMsgPack
* Accept MessagePack format (TRUE) or JSon (FALSE) for response from InfluxDB server
* @return a InfluxDB adapter suitable to access a InfluxDB.
*/
public static InfluxDB connect(final String url, final String username, final String password,
final OkHttpClient.Builder client, final boolean useMsgPack) {
Preconditions.checkNonEmptyString(url, "url");
Preconditions.checkNonEmptyString(username, "username");
Objects.requireNonNull(client, "client");
return new InfluxDBImpl(url, username, password, client);
return new InfluxDBImpl(url, username, password, client, useMsgPack);
}
}
99 changes: 99 additions & 0 deletions src/main/java/org/influxdb/dto/QueryResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.util.List;
import java.util.Map;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

/**
* {Purpose of This Type}.
*
Expand Down Expand Up @@ -68,10 +70,20 @@ public void setError(final String error) {
this.error = error;
}

@JsonIgnoreProperties(ignoreUnknown = true)
public static class Result {
private List<Abc> abc;
private List<Series> series;
private String error;

public List<Abc> getAbc() {
return abc;
}

public void setAbc(final List<Abc> abc) {
this.abc = abc;
}

/**
* @return the series
*/
Expand Down Expand Up @@ -128,6 +140,93 @@ public String toString() {

}

@JsonIgnoreProperties(ignoreUnknown = true)
public static class Abc {
private String name;
private Map<String, String> tags;
private List<String> columns;
private List<List<Object>> values;

/**
* @return the name
*/
public String getName() {
return this.name;
}

/**
* @param name
* the name to set
*/
public void setName(final String name) {
this.name = name;
}

/**
* @return the tags
*/
public Map<String, String> getTags() {
return this.tags;
}

/**
* @param tags
* the tags to set
*/
public void setTags(final Map<String, String> tags) {
this.tags = tags;
}

/**
* @return the columns
*/
public List<String> getColumns() {
return this.columns;
}

/**
* @param columns
* the columns to set
*/
public void setColumns(final List<String> columns) {
this.columns = columns;
}

/**
* @return the values
*/
public List<List<Object>> getValues() {
return this.values;
}

/**
* @param values
* the values to set
*/
public void setValues(final List<List<Object>> values) {
this.values = values;
}

/**
* {@inheritDoc}
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("Series [name=");
builder.append(this.name);
builder.append(", tags=");
builder.append(this.tags);
builder.append(", columns=");
builder.append(this.columns);
builder.append(", values=");
builder.append(this.values);
builder.append("]");
return builder.toString();
}
}

@JsonIgnoreProperties(ignoreUnknown = true)
public static class Series {
private String name;
private Map<String, String> tags;
Expand Down
Loading

0 comments on commit f1c4519

Please sign in to comment.