diff --git a/.gitignore b/.gitignore
index f3ac701..2f7896d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1 @@
-/target
-integration-credentials.properties
+target/
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index da24710..0000000
--- a/.travis.yml
+++ /dev/null
@@ -1,9 +0,0 @@
-language: java
-
-jdk:
- - oraclejdk7
- - openjdk6
-
-notifications:
- email:
- - tech@tempo-db.com
diff --git a/CHANGELOG.md b/CHANGELOG.md
deleted file mode 100644
index 0b1eac0..0000000
--- a/CHANGELOG.md
+++ /dev/null
@@ -1,7 +0,0 @@
-## 1.1.5
-
-* Updated the pom for release to maven central.
-
-## 1.1.2
-
-* URL escape series keys. Note: this is a potentially breaking change if you have been pre-escaping series keys. This release will cause the key to be double-encoded. You can safely stop escaping the key outside of this library.
diff --git a/LICENSE b/LICENSE
index cb4dd03..87d6c50 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,4 +1,4 @@
-Copyright (c) 2013 TempoDB Inc.
+Copyright (c) 2012 TempoDB Inc.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
diff --git a/README.md b/README.md
index af2f72a..c7018c2 100644
--- a/README.md
+++ b/README.md
@@ -1,18 +1,7 @@
## TempoDB Java API Client
-
-[](https://travis-ci.org/tempodb/tempodb-java)
-
-Releases are available on our maven server. Ensure that you can pull from maven central,
-and add the following dependency to your pom:
-
-
- com.tempodb
- tempodb-java
- 1.1.5
-
-
-Or, you can clone the repository and build with maven.
+A release can be downloaded [here](https://github.com/tempodb/tempodb-java/downloads) or
+you can clone the repository and build with maven.
mvn compile
-Javadocs are located [here](http://tempodb.github.com/tempodb-java/javadocs/1.1.2/)
+Javadocs are located [here](http://tempodb.github.com/tempodb-java/javadocs/apidocs/)
diff --git a/pom.xml b/pom.xml
index 49232bc..1678080 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,247 +1,149 @@
-
+4.0.0
-
com.tempodbtempodb-java
- 1.1.6-SNAPSHOTjar
-
+ 0.4.0tempodb-java
- http://github.com/tempodb/tempodb-java
- TempoDB REST Client
-
- scm:git:file://${basedir}
- scm:git:file://${basedir}
- http://github.com/tempodb/tempodb
- HEAD
-
-
-
- tempodb
- TempoDB Open Source
- opensource@tempo-db.com
- http://tempo-db.com
-
-
-
-
- The MIT License
- http://www.opensource.org/licenses/mit-license.php
- repo
-
-
-
+ http://maven.apache.orgUTF-8UTF-8
-
- src/integration-test
- ${integration-test.directory}/java
- ${integration-test.directory}/resources
- ${project.build.directory}/integrationtest-classes
+
-
-
- release-sign-artifacts
-
-
- performRelease
- true
-
-
-
-
-
- org.apache.maven.plugins
- maven-gpg-plugin
- 1.4
-
- ${gpg.passphrase}
-
-
-
- sign-artifacts
- verify
-
- sign
-
-
-
-
-
-
-
-
+
+ commons-codec
+ commons-codec
+ 1.4
+
-
-
- sonatype-nexus-staging
- Sonatype Nexus release repository
- https://oss.sonatype.org/service/local/staging/deploy/maven2/
-
-
- sonatype-nexus-snapshots
- Sonatype Nexus snapshot repository
- https://oss.sonatype.org/content/repositories/snapshots
-
-
+
+ commons-logging
+ commons-logging
+ 1.1.1
+
- org.apache.httpcomponentshttpclient
- 4.2.5
+ 4.1.3
+
- org.apache.commons
- commons-lang3
- 3.1
+ org.apache.httpcomponents
+ httpclient-cache
+ 4.1.3
+
- joda-time
- joda-time
- 2.3
+ org.apache.httpcomponents
+ httpcore
+ 4.1.4
+
+
+
+ org.apache.httpcomponents
+ httpmime
+ 4.1.3
+
+
+ org.json
+ json
+ 20090211
+
+
+
+ com.fasterxml.jackson.core
+ jackson-databind
+ 2.0.0
+
+
+
+ com.fasterxml.jackson.core
+ jackson-annotations
+ 2.0.0
+
+
+
+ com.fasterxml.jackson.core
+ jackson-core
+ 2.0.0
+
+
com.fasterxml.jackson.datatypejackson-datatype-joda
- 2.2.3
+ 2.0.0-RC3
- junit
- junit
- 4.8.2
- test
+ joda-time
+ joda-time
+ 2.1
+
- org.mockito
- mockito-core
- 1.9.5
+ junit
+ junit
+ 3.8.1test
-
+
+
+
+ src/main/resources
+ true
+
+ org.apache.maven.plugins
- maven-compiler-plugin
- 3.1
+ maven-javadoc-plugin
+ 2.8.1
- 1.6
- 1.6
- -Xlint:unchecked
+ com.tempodb.examples
- org.codehaus.mojo
- build-helper-maven-plugin
- 1.8
-
-
- add-test-source
- generate-test-sources
-
- add-test-source
-
-
-
- ${integration-test.testSourceDirectory}
-
-
-
-
- add-test-resource
- generate-test-resources
-
- add-test-resource
-
-
-
-
- ${integration-test.docDirectory}
- ${integration-test.testOutputDirectory}
-
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-failsafe-plugin
- 2.16
-
-
-
- integration-test
- verify
-
-
-
-
-
- org.apache.maven.plugins
- maven-source-plugin
- 2.0.4
-
-
- attach-sources
-
- jar
-
-
-
-
-
- org.apache.maven.plugins
- maven-javadoc-plugin
- 2.9.1
+ maven-assembly-plugin
+ 2.3
-
- http://www.joda.org/joda-time/apidocs/
- http://fasterxml.github.io/jackson-databind/javadoc/2.2.0/
-
- -J-Xmx2G
+ false
+ ${project.build.directory}/releases/
+
+ ${basedir}/src/main/assemblies/targz-bin.xml
+ ${basedir}/src/main/assemblies/zip-bin.xml
+
-
- attach-javadocs
-
- jar
-
-
+
+ package
+
+ single
+
+
- org.codehaus.mojo
- findbugs-maven-plugin
- 2.5.2
-
- Max
- Default
- true
-
-
+ maven-dependency-plugin
-
-
- check
-
-
+
+ prepare-package
+
+ copy-dependencies
+
+
+ ${project.build.directory}/lib
+
+
-
- org.apache.maven.plugins
- maven-release-plugin
- 2.4.1
-
- v@{project.version}
- true
-
-
+
diff --git a/src/integration-test/java/com/tempodb/ClientIT.java b/src/integration-test/java/com/tempodb/ClientIT.java
deleted file mode 100644
index 646b623..0000000
--- a/src/integration-test/java/com/tempodb/ClientIT.java
+++ /dev/null
@@ -1,401 +0,0 @@
-package com.tempodb;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.net.InetSocketAddress;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-
-import org.joda.time.DateTime;
-import org.joda.time.DateTimeZone;
-import org.joda.time.Interval;
-import org.joda.time.Period;
-import org.junit.*;
-import static org.junit.Assert.*;
-
-import static com.tempodb.util.Preconditions.*;
-
-
-public class ClientIT {
- private static final Client client;
- private static final Client invalidClient;
- private static final DateTimeZone timezone = DateTimeZone.UTC;
- private static final DateTime start = new DateTime(1500, 1, 1, 0, 0, 0, 0, timezone);
- private static final DateTime end = new DateTime(3000, 1, 1, 0, 0, 0, 0, timezone);
- private static final Interval interval = new Interval(start, end);
-
- private static final int SLEEP = 5000;
-
- static {
- File credentials = new File("integration-credentials.properties");
- if(!credentials.exists()) {
- String message = "Missing credentials file for integration test.\n" +
- "Please supply a file 'integration-credentials.properties' with the following format:\n" +
- " database.id=\n" +
- " credentials.key=\n" +
- " credentials.secret=\n" +
- " hostname=\n" +
- " port=\n" +
- " scheme=\n";
-
- System.out.println(message);
- System.exit(1);
- }
-
- client = getClient(credentials);
- invalidClient = new Client(client.getDatabase(), new Credentials("key", "secret"),
- client.getHost(), client.getScheme());
- }
-
- static Client getClient(File propertiesFile) {
- Properties properties = new Properties();
- try {
- properties.load(new FileInputStream(propertiesFile));
- } catch (Exception e) {
- throw new IllegalArgumentException("No credentials file", e);
- }
-
- String id = checkNotNull(properties.getProperty("database.id"));
- String key = checkNotNull(properties.getProperty("credentials.key"));
- String secret = checkNotNull(properties.getProperty("credentials.secret"));
- String hostname = checkNotNull(properties.getProperty("hostname"));
- int port = Integer.parseInt(checkNotNull(properties.getProperty("port")));
- String scheme = checkNotNull(properties.getProperty("scheme"));
-
- Database database = new Database(id);
- Credentials credentials = new Credentials(key, secret);
- InetSocketAddress host = new InetSocketAddress(hostname, port);
- return new Client(database, credentials, host, scheme);
- }
-
- @BeforeClass
- static public void onetimeSetup() {
- cleanup();
- }
-
- static public void cleanup() {
- /* Delete all datapoints all series */
- Cursor cursor = client.getSeries(new Filter());
- for(Series series : cursor) {
- Result result = client.deleteDataPoints(series, interval);
- assertEquals(State.SUCCESS, result.getState());
- }
-
- /* Delete all series */
- Result result = client.deleteAllSeries();
- assertEquals(State.SUCCESS, result.getState());
- }
-
- @After
- public void tearDown() { cleanup(); }
-
- @Test
- public void testInvalidCredentials() {
- Series series = new Series("key1", "", new HashSet(), new HashMap());
- Result result = invalidClient.createSeries(series);
- Result expected = new Result(null, 403, "Forbidden");
- assertEquals(expected, result);
- }
-
- @Test
- public void testCreateSeries() {
- HashSet tags = new HashSet();
- tags.add("create");
-
- Series series = new Series("create-series", "name", tags, new HashMap());
-
- Result result = client.createSeries(series);
- Result expected = new Result(series, 200, "OK");
-
- assertEquals(expected, result);
- }
-
- @Test
- public void testDeleteDataPointsBySeries() throws InterruptedException {
- // Write datapoints
- DataPoint dp = new DataPoint(new DateTime(2012, 1, 1, 0, 0, 0, 0, timezone), 12.34);
- Result result1 = client.writeDataPoints(new Series("key1"), Arrays.asList(dp));
- assertEquals(State.SUCCESS, result1.getState());
- Thread.sleep(SLEEP);
-
- // Read datapoints
- List expected1 = Arrays.asList(dp);
- Cursor cursor1 = client.readDataPoints(new Series("key1"), interval, timezone);
- assertEquals(expected1, toList(cursor1));
-
- // Delete datapoints
- Result result2 = client.deleteDataPoints(new Series("key1"), interval);
- assertEquals(new Result(null, 200, "OK"), result2);
-
- // Read datapoints again
- List expected2 = new ArrayList();
- Cursor cursor2 = client.readDataPoints(new Series("key1"), interval, timezone);
- assertEquals(expected2, toList(cursor2));
- }
-
- @Test
- public void testWriteDataPointBySeries() {
- DataPoint dp = new DataPoint(new DateTime(2012, 1, 1, 0, 0, 0, 0, timezone), 12.34);
- Result result = client.writeDataPoints(new Series("key1"), Arrays.asList(dp));
- assertEquals(State.SUCCESS, result.getState());
- }
-
- @Test
- public void testFindDataPointBySeries() throws InterruptedException {
- DataPoint dp1 = new DataPoint(new DateTime(2012, 1, 2, 0, 0 ,0, 0, timezone), 23.45);
- DataPoint dp2 = new DataPoint(new DateTime(2012, 1, 2, 1, 0 ,0, 0, timezone), 34.56);
-
- Result result = client.writeDataPoints(new Series("key-find"), Arrays.asList(dp1, dp2));
- assertEquals(State.SUCCESS, result.getState());
- Thread.sleep(SLEEP);
-
- DateTime start = new DateTime(2012, 1, 2, 0, 0, 0, 0, timezone);
- DateTime end = new DateTime(2012, 1, 3, 0, 0, 0, 0, timezone);
- Interval interval = new Interval(start, end);
- Predicate predicate = new Predicate(Period.days(1), "max");
- DataPointFound dpf1 = new DataPointFound(interval, dp2);
-
- List expected = Arrays.asList(dpf1);
- Cursor cursor = client.findDataPoints(new Series("key-find"), new Interval(start, end), predicate, timezone);
- assertEquals(expected, toList(cursor));
- }
-
- @Test
- public void testReadDataPointByKey() throws InterruptedException {
- DataPoint dp1 = new DataPoint(new DateTime(2012, 1, 2, 0, 0 ,0, 0, timezone), 23.45);
- DataPoint dp2 = new DataPoint(new DateTime(2012, 1, 2, 1, 0 ,0, 0, timezone), 34.56);
-
- Result result = client.writeDataPoints(new Series("key1"), Arrays.asList(dp1, dp2));
- assertEquals(State.SUCCESS, result.getState());
- Thread.sleep(SLEEP);
-
- DateTime start = new DateTime(2012, 1, 2, 0, 0, 0, 0, timezone);
- DateTime end = new DateTime(2012, 1, 3, 0, 0, 0, 0, timezone);
-
- List expected = Arrays.asList(dp1, dp2);
- Cursor cursor = client.readDataPoints(new Series("key1"), new Interval(start, end), timezone);
- assertEquals(expected, toList(cursor));
- }
-
- @Test
- public void testReadSingleValue() throws InterruptedException {
- DataPoint dp1 = new DataPoint(new DateTime(2012, 1, 2, 0, 0 ,0, 0, timezone), 23.45);
- DataPoint dp2 = new DataPoint(new DateTime(2012, 1, 2, 1, 0 ,0, 0, timezone), 34.56);
-
- Result result = client.writeDataPoints(new Series("key1"), Arrays.asList(dp1, dp2));
- assertEquals(State.SUCCESS, result.getState());
- Thread.sleep(SLEEP);
-
- DateTime ts = new DateTime(2012, 1, 2, 0, 0, 0, 0, timezone);
-
- SingleValue expected = new SingleValue(new Series("key1"), new DataPoint(ts, 23.45));
- Result value = client.readSingleValue(new Series("key1"), ts, timezone, Direction.EXACT);
- assertEquals(expected, value.getValue());
- }
-
- @Test
- public void testReadMultiDataPoints() throws InterruptedException {
- WriteRequest wr = new WriteRequest()
- .add(new Series("key1"), new DataPoint(new DateTime(2012, 1, 1, 0, 0, 0, 0, timezone), 5.0))
- .add(new Series("key2"), new DataPoint(new DateTime(2012, 1, 1, 0, 0, 0, 0, timezone), 6.0))
- .add(new Series("key1"), new DataPoint(new DateTime(2012, 1, 1, 0, 1, 0, 0, timezone), 7.0))
- .add(new Series("key2"), new DataPoint(new DateTime(2012, 1, 1, 0, 1, 0, 0, timezone), 8.0));
-
- Result result1 = client.writeDataPoints(wr);
- assertEquals(new Result(null, 200, "OK"), result1);
-
- Thread.sleep(SLEEP);
-
- Filter filter = new Filter();
- filter.addKey("key1");
- filter.addKey("key2");
- Cursor cursor = client.readMultiDataPoints(filter, interval, timezone);
-
- Map data1 = new HashMap();
- data1.put("key1", 5.0);
- data1.put("key2", 6.0);
-
- Map data2 = new HashMap();
- data2.put("key1", 7.0);
- data2.put("key2", 8.0);
-
- List expected = Arrays.asList(
- new MultiDataPoint(new DateTime(2012, 1, 1, 0, 0, 0, 0, timezone), data1),
- new MultiDataPoint(new DateTime(2012, 1, 1, 0, 1, 0, 0, timezone), data2)
- );
- assertEquals(expected, toList(cursor));
- }
-
- @Test
- public void testReadMultiRollupDataPointByKey() throws InterruptedException {
- DataPoint dp1 = new DataPoint(new DateTime(2012, 1, 2, 0, 0 ,0, 0, timezone), 23.45);
- DataPoint dp2 = new DataPoint(new DateTime(2012, 1, 2, 1, 0 ,0, 0, timezone), 34.56);
-
- Result result = client.writeDataPoints(new Series("key1"), Arrays.asList(dp1, dp2));
- assertEquals(State.SUCCESS, result.getState());
- Thread.sleep(SLEEP);
-
- DateTime start = new DateTime(2012, 1, 2, 0, 0, 0, 0, timezone);
- DateTime end = new DateTime(2012, 1, 3, 0, 0, 0, 0, timezone);
- MultiRollup rollup = new MultiRollup(Period.days(1), new Fold[] { Fold.MAX, Fold.MIN });
-
- Cursor cursor = client.readMultiRollupDataPoints(new Series("key1"), new Interval(start, end), timezone, rollup);
-
- Map data1 = new HashMap();
- data1.put("max", 34.56);
- data1.put("min", 23.45);
-
- MultiDataPoint mdp1 = new MultiDataPoint(new DateTime(2012, 1, 2, 0, 0, 0, 0, timezone), data1);
- List expected = Arrays.asList(mdp1);
-
- assertEquals(expected, toList(cursor));
- }
-
- @Test
- public void testWriteDataPoints() throws InterruptedException {
- WriteRequest wr = new WriteRequest()
- .add(new Series("key1"), new DataPoint(new DateTime(2012, 1, 1, 0, 0, 0, 0, timezone), 5.0))
- .add(new Series("key2"), new DataPoint(new DateTime(2012, 1, 1, 0, 0, 0, 0, timezone), 6.0))
- .add(new Series("key1"), new DataPoint(new DateTime(2012, 1, 1, 0, 1, 0, 0, timezone), 7.0))
- .add(new Series("key2"), new DataPoint(new DateTime(2012, 1, 1, 0, 2, 0, 0, timezone), 8.0));
-
- Thread.sleep(SLEEP);
-
- Result result = client.writeDataPoints(wr);
- assertEquals(new Result(null, 200, "OK"), result);
- }
-
- @Test
- public void testReadDataPoints() throws InterruptedException {
- WriteRequest wr = new WriteRequest()
- .add(new Series("key1"), new DataPoint(new DateTime(2012, 1, 1, 0, 0, 0, 0, timezone), 5.0))
- .add(new Series("key2"), new DataPoint(new DateTime(2012, 1, 1, 0, 0, 0, 0, timezone), 6.0))
- .add(new Series("key1"), new DataPoint(new DateTime(2012, 1, 1, 0, 1, 0, 0, timezone), 7.0))
- .add(new Series("key2"), new DataPoint(new DateTime(2012, 1, 1, 0, 1, 0, 0, timezone), 8.0));
-
- Result result1 = client.writeDataPoints(wr);
- assertEquals(new Result(null, 200, "OK"), result1);
-
- Thread.sleep(SLEEP);
-
- Filter filter = new Filter();
- filter.addKey("key1");
- filter.addKey("key2");
- Aggregation aggregation = new Aggregation(Fold.SUM);
- Cursor cursor = client.readDataPoints(filter, interval, timezone, aggregation);
-
- DataPoint dp1 = new DataPoint(new DateTime(2012, 1, 1, 0, 0, 0, 0, timezone), 11.0);
- DataPoint dp2 = new DataPoint(new DateTime(2012, 1, 1, 0, 1, 0, 0, timezone), 15.0);
- List expected = Arrays.asList(dp1, dp2);
- assertEquals(expected, toList(cursor));
- }
-
- @Test
- public void testGetSeriesByKey() {
- // Create a series
- HashMap attributes = new HashMap();
- attributes.put("appidÜ", "1234");
- attributes.put("txn", "/def ault");
-
- Series series = new Series("appidÜ:1234.txn:/def ault.cou+()+={}nt", "name", new HashSet(), attributes);
- Result result1 = client.createSeries(series);
-
- // Get the series
- Result result2 = client.getSeries("appidÜ:1234.txn:/def ault.cou+()+={}nt");
- Result expected = new Result(series, 200, "OK");
- assertEquals(expected, result2);
- }
-
- @Test
- public void testGetSeriesByFilter() {
- // Create a series
- HashSet tags = new HashSet();
- tags.add("get-filter");
- Series series = new Series("create-series", "name", tags, new HashMap());
- Result result1 = client.createSeries(series);
-
- // Get the series by filter
- Filter filter = new Filter();
- filter.addTag("get-filter");
- Cursor cursor = client.getSeries(filter);
- List expected = Arrays.asList(series);
- assertEquals(expected, toList(cursor));
- }
-
- @Test
- public void testUpdateSeries() {
- // Create a series
- HashSet tags = new HashSet();
- tags.add("update");
- Series series = new Series("update-series", "name", tags, new HashMap());
- Result result1 = client.createSeries(series);
-
- // Update the series
- series.getTags().add("update2");
- Result result2 = client.updateSeries(series);
- assertEquals(new Result(series, 200, "OK"), result2);
-
- // Get the series
- Result result3 = client.getSeries("update-series");
- Result expected = new Result(series, 200, "OK");
- assertEquals(expected, result3);
- }
-
- @Test
- public void testDeleteSeries() {
- // Create a series
- HashSet tags = new HashSet();
- tags.add("delete");
- Series series = new Series("delete-series", "name", tags, new HashMap());
- Result result1 = client.createSeries(series);
-
- // Delete the series
- Result result2 = client.deleteSeries(series);
- assertEquals(new Result(null, 200, "OK"), result2);
-
- // Get the series
- Result result3 = client.getSeries("delete-series");
- Result expected = new Result(null, 403, "Forbidden");
- assertEquals(expected, result3);
- }
-
- @Test
- public void testDeleteSeriesByFilter() {
- // Create a series
- HashSet tags = new HashSet();
- tags.add("delete-filter");
- Series series1 = new Series("delete-series", "name", tags, new HashMap());
- Series series2 = new Series("delete-series2", "name", new HashSet(), new HashMap());
- Result result1 = client.createSeries(series1);
- Result result2 = client.createSeries(series2);
-
- // Get the series by filter
- Filter filter = new Filter();
- filter.addTag("delete-filter");
- Cursor cursor = client.getSeries(filter);
- List expected1 = Arrays.asList(series1);
- assertEquals(expected1, toList(cursor));
-
- // Delete the series by filter
- Result result3 = client.deleteSeries(filter);
- assertEquals(new Result(new DeleteSummary(1), 200, "OK"), result3);
-
- // Get the series by filter again
- Cursor cursor2 = client.getSeries(filter);
- List expected2 = Arrays.asList();
- assertEquals(expected2, toList(cursor2));
- }
-
- private List toList(Cursor cursor) {
- List output = new ArrayList();
- for(T dp : cursor) {
- output.add(dp);
- }
- return output;
- }
-}
diff --git a/src/integration-test/resources/integration-credentials.properties.example b/src/integration-test/resources/integration-credentials.properties.example
deleted file mode 100644
index c7fd315..0000000
--- a/src/integration-test/resources/integration-credentials.properties.example
+++ /dev/null
@@ -1,6 +0,0 @@
-database.id=
-credentials.key=
-credentials.secret=
-hostname=
-port=
-scheme=http
diff --git a/src/main/assemblies/common-bin.xml b/src/main/assemblies/common-bin.xml
new file mode 100644
index 0000000..52323dc
--- /dev/null
+++ b/src/main/assemblies/common-bin.xml
@@ -0,0 +1,13 @@
+
+
+
+ /lib
+
+
+
+
+ README.md
+ /
+
+
+
diff --git a/src/main/assemblies/targz-bin.xml b/src/main/assemblies/targz-bin.xml
new file mode 100644
index 0000000..f342f6a
--- /dev/null
+++ b/src/main/assemblies/targz-bin.xml
@@ -0,0 +1,13 @@
+
+
+ targz
+
+ tar.gz
+
+
+ true
+
+
+ src/main/assemblies/common-bin.xml
+
+
diff --git a/src/main/assemblies/zip-bin.xml b/src/main/assemblies/zip-bin.xml
new file mode 100644
index 0000000..6ac0f7a
--- /dev/null
+++ b/src/main/assemblies/zip-bin.xml
@@ -0,0 +1,13 @@
+
+
+ zip
+
+ zip
+
+
+ true
+
+
+ src/main/assemblies/common-bin.xml
+
+
diff --git a/src/main/java/com/tempodb/Aggregation.java b/src/main/java/com/tempodb/Aggregation.java
deleted file mode 100644
index e268778..0000000
--- a/src/main/java/com/tempodb/Aggregation.java
+++ /dev/null
@@ -1,80 +0,0 @@
-package com.tempodb;
-
-import java.io.Serializable;
-
-import org.apache.commons.lang3.builder.EqualsBuilder;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
-
-import static com.tempodb.util.Preconditions.*;
-
-
-/**
- * The representation of an aggregation between multiple Series.
- *
- * An Aggregation allows you to specify a new Series that is a mathematical
- * operation across multiple Series. For instance, the following Aggregation
- * specifies the sum of multiple Series:
- *
- *
- * Aggregation aggregation = new Aggregation(Fold.SUM);
- *
- * @see Fold
- * @since 1.0.0
- */
-public class Aggregation implements Serializable {
- private Fold fold;
-
- /** Serialization lock */
- private static final long serialVersionUID = 1L;
-
- public Aggregation() {
- this(Fold.SUM);
- }
-
- /**
- * Base constructor
- * @param fold The aggregation's folding function.
- * @since 1.0.0
- */
- public Aggregation(Fold fold) {
- this.fold = checkNotNull(fold);
- }
-
- /**
- * Returns the {@link Fold}.
- * @return The aggregation's folding function.
- * @since 1.0.0
- */
- public Fold getFold() { return fold; }
-
- /**
- * Sets the {@link Fold}.
- * @param fold The folding function to use.
- * @since 1.0.0
- */
- public void setFold(Fold fold) { this.fold = checkNotNull(fold); }
-
- @Override
- public String toString() {
- return String.format("Aggregation(fold=%s)", fold.toString().toLowerCase());
- }
-
- @Override
- public int hashCode() {
- return new HashCodeBuilder(107, 109)
- .append(fold)
- .toHashCode();
- }
-
- @Override
- public boolean equals(Object obj) {
- if(obj == null) return false;
- if(obj == this) return true;
- if(!(obj instanceof Aggregation)) return false;
-
- Aggregation rhs = (Aggregation)obj;
- return new EqualsBuilder()
- .append(fold, rhs.fold)
- .isEquals();
- }
-}
diff --git a/src/main/java/com/tempodb/Client.java b/src/main/java/com/tempodb/Client.java
deleted file mode 100644
index f6d753d..0000000
--- a/src/main/java/com/tempodb/Client.java
+++ /dev/null
@@ -1,1309 +0,0 @@
-package com.tempodb;
-
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.net.InetSocketAddress;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URLEncoder;
-import java.nio.charset.Charset;
-import java.util.List;
-import java.util.Map;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import org.apache.http.*;
-import org.apache.http.auth.*;
-import org.apache.http.client.*;
-import org.apache.http.client.entity.GzipDecompressingEntity;
-import org.apache.http.client.methods.*;
-import org.apache.http.client.protocol.ClientContext;
-import org.apache.http.client.utils.URIBuilder;
-import org.apache.http.conn.ConnectionKeepAliveStrategy;
-import org.apache.http.entity.StringEntity;
-import org.apache.http.impl.auth.BasicScheme;
-import org.apache.http.impl.client.*;
-import org.apache.http.impl.conn.PoolingClientConnectionManager;
-import org.apache.http.message.BasicHeaderElementIterator;
-import org.apache.http.message.BasicNameValuePair;
-import org.apache.http.params.*;
-import org.apache.http.protocol.*;
-import org.joda.time.DateTime;
-import org.joda.time.DateTimeZone;
-import org.joda.time.Interval;
-import org.joda.time.format.DateTimeFormat;
-import org.joda.time.format.DateTimeFormatter;
-
-import com.tempodb.json.Json;
-import static com.tempodb.util.Preconditions.*;
-
-/**
- * The main object used to make calls to the TempoDB api.
- *
- * It is a thin wrapper around the TempoDB Rest API
- *
- *
A client object holds the session information required to authenticate and connect to the Rest api. An api key and secret
- * are required. These can be obtained by signing up at http://tempo-db.com. The client
- * also lets you specify a different hostname (for instance, if you are on a dedicated cluster) and port, and whether to
- * use SSL encryption on the connection.
- *
- *
Using the client, you can:
- *
- *
Retrieve a filtered list of Series
- *
Retrieve a Series by key
- *
Retrieve datapoints for a single series in a specific time interval
- *
Write datapoints for a single series
- *
Retrieve datapoints aggregated across multiple Series
- *
Write datapoints to multiple Series
- *
- *
- *
The following example initializes a Client object and retrieves datapoints for a Series referenced by the key "my-key"
- * for the time period 2012-01-01 to 2010-01-02, returning the hourly average. This calls returns a Cursor<DataPoint>
- * which provides a lazily loaded iterable of DataPoints.
- *
- *
The TempoDB Rest API supports http keep-alive, and the Client object is designed to be thread-safe. It is recommended
- * that a Client object be created and then reused for subsequent calls. This help to amoritize the cost of setting up the
- * http client across many calls.
- */
-public class Client {
-
- private final Database database;
- private final Credentials credentials;
- private final InetSocketAddress host;
- private final String scheme;
-
- private HttpClient client = null;
- private HttpHost target = null;
-
- private static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8");
- // Timeout on milliseconds
- private static final int DEFAULT_TIMEOUT_MILLIS = 50000; // 50 seconds
- private static final long DEFAULT_KEEPALIVE_TIMEOUT_MILLIS = 50000; // 50 seconds
- private static final int GENERIC_ERROR_CODE = 600;
- private static final String VERSION = "1.0-SNAPSHOT";
- private static final String API_VERSION = "v1";
- private final DateTimeFormatter iso8601 = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
-
- private enum HttpMethod { GET, POST, PUT, DELETE }
-
- /**
- * Base constructor for a Client object.
- *
- * @param database Database to connect to
- * @param credentials Api credentials
- * @param host Api server host address
- * @param scheme Scheme for requests. "http" and "https" are supported.
- */
- public Client(Database database, Credentials credentials, InetSocketAddress host, String scheme) {
- checkArgument(scheme.equals("http") || scheme.equals("https"), "Scheme must be either \"http\" or \"https\".");
- this.database = checkNotNull(database, "Database cannot be null.");
- this.credentials = checkNotNull(credentials, "Credentials cannot be null.");
- this.host = checkNotNull(host, "Host cannot be null.");
- this.scheme = checkNotNull(scheme, "Scheme cannot be null.");
- }
-
- /**
- * Returns the database the client is connected to.
- * @return Client database
- * @since 1.0.0
- */
- public Database getDatabase() { return database; }
-
- /**
- * Returns the client's credentials.
- * @return Api credentials
- * @since 1.0.0
- */
- public Credentials getCredentials() { return credentials; }
-
- /**
- * Returns client's api server host.
- * @return Api server host address.
- * @since 1.0.0
- */
- public InetSocketAddress getHost() { return host; }
-
- /**
- * Returns client's api server scheme.
- * @return Api server scheme.
- * @since 1.0.0
- */
- public String getScheme() { return scheme; }
-
- /**
- * Creates a Series
- * @param series The Series to create
- * @return The created Series
- *
- * @since 1.0.0
- * @throws NullPointerException If the input Series is null.
- */
- public Result createSeries(Series series) {
- checkNotNull(series);
-
- URI uri = null;
- try {
- URIBuilder builder = new URIBuilder(String.format("/%s/series/", API_VERSION));
- uri = builder.build();
- } catch (URISyntaxException e) {
- String message = "Could not build URI";
- throw new IllegalArgumentException(message, e);
- }
-
- Result result = null;
- String body = null;
- try {
- body = Json.dumps(series);
- } catch (JsonProcessingException e) {
- String message = "Error serializing the body of the request. More detail: " + e.getMessage();
- result = new Result(null, GENERIC_ERROR_CODE, message);
- return result;
- }
-
- HttpRequest request = buildRequest(uri.toString(), HttpMethod.POST, body);
- result = execute(request, Series.class);
- return result;
- }
-
- /**
- * Deletes a range of datapoints for a Series specified by key.
- *
- * @param series The series
- * @param interval The start/end datetime interval to delete.
- * @return Void
- *
- * @since 1.0.0
- */
- public Result deleteDataPoints(Series series, Interval interval) {
- checkNotNull(series);
- checkNotNull(interval);
-
- URI uri = null;
- try {
- URIBuilder builder = new URIBuilder(String.format("/%s/series/key/%s/data/", API_VERSION, urlencode(series.getKey())));
- addIntervalToURI(builder, interval);
- uri = builder.build();
- } catch (URISyntaxException e) {
- String message = String.format("Could not build URI with inputs: key: %s, interval: %s", series.getKey(), interval);
- throw new IllegalArgumentException(message, e);
- }
-
- HttpRequest request = buildRequest(uri.toString(), HttpMethod.DELETE);
- Result result = execute(request, Void.class);
- return result;
- }
-
- /**
- * Deletes a Series.
- *
- * @param series The Series to delete
- * @return {@link Void}
- * @since 1.0.0
- */
- public Result deleteSeries(Series series) {
- checkNotNull(series);
-
- URI uri = null;
- try {
- URIBuilder builder = new URIBuilder(String.format("/%s/series/key/%s/", API_VERSION, urlencode(series.getKey())));
- uri = builder.build();
- } catch (URISyntaxException e) {
- String message = String.format("Could not build URI with inputs: key: %s", series.getKey());
- throw new IllegalArgumentException(message, e);
- }
-
- HttpRequest request = buildRequest(uri.toString(), HttpMethod.DELETE);
- Result result = execute(request, Void.class);
- return result;
- }
-
- /**
- * Deletes set of series by a filter.
- *
- * @param filter The series filter @see Filter
- * @return A DeleteSummary providing information about the series deleted.
- *
- * @see DeleteSummary
- * @see Filter
- * @since 1.0.0
- */
- public Result deleteSeries(Filter filter) {
- URI uri = null;
- try {
- URIBuilder builder = new URIBuilder(String.format("/%s/series/", API_VERSION));
- addFilterToURI(builder, filter);
- uri = builder.build();
- } catch (URISyntaxException e) {
- String message = String.format("Could not build URI with input - filter: %s", filter);
- throw new IllegalArgumentException(message, e);
- }
-
- HttpRequest request = buildRequest(uri.toString(), HttpMethod.DELETE);
- Result result = execute(request, DeleteSummary.class);
- return result;
- }
-
- /**
- * Deletes all Series in a database.
- *
- * @return A DeleteSummary providing information about the series deleted.
- *
- * @see DeleteSummary
- * @since 1.0.0
- */
- public Result deleteAllSeries() {
- URI uri = null;
- try {
- URIBuilder builder = new URIBuilder(String.format("/%s/series/", API_VERSION));
- builder.addParameter("allow_truncation", "true");
- uri = builder.build();
- } catch (URISyntaxException e) {
- String message = "Could not build URI";
- throw new IllegalArgumentException(message, e);
- }
-
- HttpRequest request = buildRequest(uri.toString(), HttpMethod.DELETE);
- Result result = execute(request, DeleteSummary.class);
- return result;
- }
-
- /**
- * Returns a cursor of intervals/datapoints matching a predicate specified by series.
- *
The system default timezone is used for the returned DateTimes.
- *
- * @param series The series
- * @param interval An interval of time for the query (start/end datetimes)
- * @param predicate The predicate for the query.
- * @return A Cursor of DataPoints. The cursor.iterator().next() may throw a {@link TempoDBException} if an error occurs while making a request.
- *
- * @see Cursor
- * @since 1.1.0
- */
- public Cursor findDataPoints(Series series, Interval interval, Predicate predicate) {
- return findDataPoints(series, interval, predicate, DateTimeZone.getDefault());
- }
-
- /**
- * Returns a cursor of intervals/datapoints matching a predicate specified by series.
- *
- * @param series The series
- * @param interval An interval of time for the query (start/end datetimes)
- * @param predicate The predicate for the query.
- * @param timezone The time zone for the returned datapoints.
- * @return A Cursor of DataPoints. The cursor.iterator().next() may throw a {@link TempoDBException} if an error occurs while making a request.
- *
- * @see Cursor
- * @since 1.1.0
- */
- public Cursor findDataPoints(Series series, Interval interval, Predicate predicate, DateTimeZone timezone) {
- checkNotNull(series);
- checkNotNull(interval);
- checkNotNull(predicate);
- checkNotNull(timezone);
-
- URI uri = null;
- try {
- URIBuilder builder = new URIBuilder(String.format("/%s/series/key/%s/find/", API_VERSION, urlencode(series.getKey())));
- addIntervalToURI(builder, interval);
- addPredicateToURI(builder, predicate);
- addTimeZoneToURI(builder, timezone);
- uri = builder.build();
- } catch (URISyntaxException e) {
- String message = String.format("Could not build URI with inputs: key: %s, interval: %s, predicate: %s, timezone: %s", series.getKey(), interval, predicate, timezone);
- throw new IllegalArgumentException(message, e);
- }
-
- Cursor cursor = new DataPointFoundCursor(uri, this);
- return cursor;
- }
-
- /**
- * Returns a Series referenced by key.
- *
- * @param key The Series key to retrieve
- * @return The requested Series.
- * @since 1.0.0
- */
- public Result getSeries(String key) {
- checkNotNull(key);
-
- URI uri = null;
- try {
- URIBuilder builder = new URIBuilder(String.format("/%s/series/key/%s/", API_VERSION, urlencode(key)));
- uri = builder.build();
- } catch (URISyntaxException e) {
- String message = String.format("Could not build URI with inputs: key: %s", key);
- throw new IllegalArgumentException(message, e);
- }
-
- HttpRequest request = buildRequest(uri.toString());
- Result result = execute(request, Series.class);
- return result;
- }
-
- /**
- * Returns a cursor of series specified by a filter.
- *
- * @param filter The series filter
- * @return A Cursor of Series. The cursor.iterator().next() may throw a {@link TempoDBException} if an error occurs while making a request.
- *
- * @see Cursor
- * @see Filter
- * @since 1.0.0
- */
- public Cursor getSeries(Filter filter) {
- URI uri = null;
- try {
- URIBuilder builder = new URIBuilder(String.format("/%s/series/", API_VERSION));
- addFilterToURI(builder, filter);
- uri = builder.build();
- } catch (URISyntaxException e) {
- String message = String.format("Could not build URI with input - filter: %s", filter);
- throw new IllegalArgumentException(message, e);
- }
-
- Cursor cursor = new SeriesCursor(uri, this);
- return cursor;
- }
-
- /**
- * Reads a single value for a series at a specific timestamp (exact match).
- *
The returned value (datapoint) can be null if there are no
- * datapoints in the series or in the specified direction. The system default
- * timezone is used.
- *
- * @param series The series to read from
- * @param timestamp The timestamp to read a value at
- * @return The value at the specified timestamp
- *
- * @see SingleValue
- * @since 1.1.0
- */
- public Result readSingleValue(Series series, DateTime timestamp) {
- return readSingleValue(series, timestamp, DateTimeZone.getDefault(), Direction.EXACT);
- }
-
- /**
- * Reads a single value for a series at a specific timestamp (exact match).
- *
The returned value (datapoint) can be null if there are no
- * datapoints in the series or in the specified direction.
- *
- * @param series The series to read from
- * @param timestamp The timestamp to read a value at
- * @param timezone The timezone of the returned datapoint
- * @return The value at the specified timestamp
- *
- * @see SingleValue
- * @since 1.1.0
- */
- public Result readSingleValue(Series series, DateTime timestamp, DateTimeZone timezone) {
- return readSingleValue(series, timestamp, timezone, Direction.EXACT);
- }
-
- /**
- * Reads a single value for a series at a specific timestamp.
- *
The returned value (datapoint) can be null if there are no
- * datapoints in the series or in the specified direction. The system
- * default timezone is used.
- *
- * @param series The series to read from
- * @param timestamp The timestamp to read a value at
- * @param direction The direction to search if an exact timestamp match is not found
- * @return The value at the specified timestamp
- *
- * @see SingleValue
- * @since 1.1.0
- */
- public Result readSingleValue(Series series, DateTime timestamp, Direction direction) {
- return readSingleValue(series, timestamp, DateTimeZone.getDefault(), direction);
- }
-
- /**
- * Reads a single value for a series at a specific timestamp.
- *
The returned value (datapoint) can be null if there are no
- * datapoints in the series or in the specified direction.
- *
- * @param series The series to read from
- * @param timestamp The timestamp to read a value at
- * @param timezone The timezone of the returned datapoint
- * @param direction The direction to search if an exact timestamp match is not found
- * @return The value at the specified timestamp
- *
- * @see SingleValue
- * @since 1.1.0
- */
- public Result readSingleValue(Series series, DateTime timestamp, DateTimeZone timezone, Direction direction) {
- checkNotNull(series);
- checkNotNull(timestamp);
- checkNotNull(timezone);
- checkNotNull(direction);
-
- URI uri = null;
- try {
- URIBuilder builder = new URIBuilder(String.format("/%s/series/key/%s/single/", API_VERSION, urlencode(series.getKey())));
- addTimestampToURI(builder, timestamp);
- addTimeZoneToURI(builder, timezone);
- addDirectionToURI(builder, direction);
- uri = builder.build();
- } catch (URISyntaxException e) {
- String message = String.format("Could not build URI with inputs: key: %s, timestamp: %s, timezone: %s, direction: %s", series.getKey(), timestamp.toString(), timezone.toString(), direction.toString());
- throw new IllegalArgumentException(message, e);
- }
-
- HttpRequest request = buildRequest(uri.toString());
- Result result = execute(request, SingleValue.class);
- return result;
- }
-
- /**
- * Returns a cursor of single value for a set of series
- *
The returned values (datapoints) can be null if there are no
- * datapoints in the series or in the specified direction. The
- * system default timezone is used. The direction is set to EXACT.
- *
- * @param filter The filter of series to read from
- * @param timestamp The timestamp to read a value at
- * @return A cursor over the values at the specified timestamp
- *
- * @see Cursor
- * @see SingleValue
- * @since 1.1.0
- */
- public Cursor readSingleValue(Filter filter, DateTime timestamp) {
- return readSingleValue(filter, timestamp, DateTimeZone.getDefault(), Direction.EXACT);
- }
-
- /**
- * Returns a cursor of single value for a set of series
- *
The returned values (datapoints) can be null if there are no
- * datapoints in the series or in the specified direction.
- * The direction is set to EXACT.
- *
- * @param filter The filter of series to read from
- * @param timestamp The timestamp to read a value at
- * @param timezone The timezone of the returned datapoints
- * @return A cursor over the values at the specified timestamp
- *
- * @see Cursor
- * @see SingleValue
- * @since 1.1.0
- */
- public Cursor readSingleValue(Filter filter, DateTime timestamp, DateTimeZone timezone) {
- return readSingleValue(filter, timestamp, timezone, Direction.EXACT);
- }
-
- /**
- * Returns a cursor of single value for a set of series
- *
The returned values (datapoints) can be null if there are no
- * datapoints in the series or in the specified direction. The
- * system default timezone is used.
- *
- * @param filter The filter of series to read from
- * @param timestamp The timestamp to read a value at
- * @param direction The direction to search if an exact timestamp match is not found
- * @return A cursor over the values at the specified timestamp
- *
- * @see Cursor
- * @see SingleValue
- * @since 1.1.0
- */
- public Cursor readSingleValue(Filter filter, DateTime timestamp, Direction direction) {
- return readSingleValue(filter, timestamp, DateTimeZone.getDefault(), direction);
- }
-
- /**
- * Returns a cursor of single value for a set of series
- *
The returned values (datapoints) can be null if there are no
- * datapoints in the series or in the specified direction.
- *
- * @param filter The filter of series to read from
- * @param timestamp The timestamp to read a value at
- * @param timezone The timezone of the returned datapoint
- * @param direction The direction to search if an exact timestamp match is not found
- * @return A cursor over the values at the specified timestamp
- *
- * @see Cursor
- * @see SingleValue
- * @since 1.1.0
- */
- public Cursor readSingleValue(Filter filter, DateTime timestamp, DateTimeZone timezone, Direction direction) {
- URI uri = null;
- try {
- URIBuilder builder = new URIBuilder(String.format("/%s/single/", API_VERSION));
- addFilterToURI(builder, filter);
- addTimestampToURI(builder, timestamp);
- addTimeZoneToURI(builder, timezone);
- addDirectionToURI(builder, direction);
- uri = builder.build();
- } catch (URISyntaxException e) {
- String message = String.format("Could not build URI with input - filter: %s", filter);
- throw new IllegalArgumentException(message, e);
- }
-
- Cursor cursor = new SingleValueCursor(uri, this);
- return cursor;
- }
-
- /**
- * Reads summary statistics for a series for the specified interval.
- *
- * @param series The series to read from
- * @param interval The interval of data to summarize
- * @return A set of statistics for an interval of data
- *
- * @see SingleValue
- * @since 1.1.0
- */
- public Result readSummary(Series series, Interval interval) {
- checkNotNull(series);
- checkNotNull(interval);
- DateTimeZone timezone = interval.getStart().getChronology().getZone();
-
- URI uri = null;
- try {
- URIBuilder builder = new URIBuilder(String.format("/%s/series/key/%s/summary/", API_VERSION, urlencode(series.getKey())));
- addIntervalToURI(builder, interval);
- addTimeZoneToURI(builder, timezone);
- uri = builder.build();
- } catch (URISyntaxException e) {
- String message = String.format("Could not build URI with inputs: key: %s, interval: %s, timezone: %s", series.getKey(), interval.toString(), timezone.toString());
- throw new IllegalArgumentException(message, e);
- }
-
- HttpRequest request = buildRequest(uri.toString());
- Result result = execute(request, Summary.class);
- return result;
- }
-
- /**
- * Returns a cursor of datapoints specified by series.
- *
The system default timezone is used for the returned DateTimes.
- *
- * @param series The series
- * @param interval An interval of time for the query (start/end datetimes)
- * @return A Cursor of DataPoints. The cursor.iterator().next() may throw a {@link TempoDBException} if an error occurs while making a request.
- *
- * @see Cursor
- * @since 1.0.0
- */
- public Cursor readDataPoints(Series series, Interval interval) {
- return readDataPoints(series, interval, DateTimeZone.getDefault(), null, null);
- }
-
- /**
- * Returns a cursor of datapoints specified by series.
- *
- * @param series The series
- * @param interval An interval of time for the query (start/end datetimes)
- * @param timezone The time zone for the returned datapoints.
- * @return A Cursor of DataPoints. The cursor.iterator().next() may throw a {@link TempoDBException} if an error occurs while making a request.
- *
- * @see Cursor
- * @since 1.0.0
- */
- public Cursor readDataPoints(Series series, Interval interval, DateTimeZone timezone) {
- return readDataPoints(series, interval, timezone, null, null);
- }
-
- /**
- * Returns a cursor of datapoints specified by series.
- *
The system default timezone is used for the returned DateTimes.
- *
- * @param series The series
- * @param interval An interval of time for the query (start/end datetimes)
- * @param rollup The rollup for the read query. This can be null.
- * @return A Cursor of DataPoints. The cursor.iterator().next() may throw a {@link TempoDBException} if an error occurs while making a request.
- *
- * @see Cursor
- * @since 1.0.0
- */
- public Cursor readDataPoints(Series series, Interval interval, Rollup rollup) {
- return readDataPoints(series, interval, DateTimeZone.getDefault(), rollup, null);
- }
-
- /**
- * Returns a cursor of datapoints specified by series.
- *
- * @param series The series
- * @param interval An interval of time for the query (start/end datetimes)
- * @param timezone The time zone for the returned datapoints.
- * @param rollup The rollup for the read query. This can be null.
- * @param interpolation The interpolation for the read query. This can be null.
- * @return A Cursor of DataPoints. The cursor.iterator().next() may throw a {@link TempoDBException} if an error occurs while making a request.
- *
- * @see Cursor
- * @since 1.0.0
- */
- public Cursor readDataPoints(Series series, Interval interval, DateTimeZone timezone, Rollup rollup, Interpolation interpolation) {
- checkNotNull(series);
- checkNotNull(interval);
- checkNotNull(timezone);
-
- URI uri = null;
- try {
- URIBuilder builder = new URIBuilder(String.format("/%s/series/key/%s/segment/", API_VERSION, urlencode(series.getKey())));
- addInterpolationToURI(builder, interpolation);
- addIntervalToURI(builder, interval);
- addRollupToURI(builder, rollup);
- addTimeZoneToURI(builder, timezone);
- uri = builder.build();
- } catch (URISyntaxException e) {
- String message = String.format("Could not build URI with inputs: key: %s, interval: %s, rollup: %s, timezone: %s", series.getKey(), interval, rollup, timezone);
- throw new IllegalArgumentException(message, e);
- }
-
- Cursor cursor = new DataPointCursor(uri, this);
- return cursor;
- }
-
- /**
- * Returns a cursor of datapoints specified by series with multiple rollups.
- *
The system default timezone is used for the returned DateTimes.
- *
- * @param series The series
- * @param interval An interval of time for the query (start/end datetimes)
- * @param rollup The MultiRollup for the read query.
- * @return A Cursor of DataPoints. The cursor.iterator().next() may throw a {@link TempoDBException} if an error occurs while making a request.
- *
- * @see Cursor
- * @see MultiRollup
- * @since 1.1.0
- */
- public Cursor readMultiRollupDataPoints(Series series, Interval interval, MultiRollup rollup) {
- return readMultiRollupDataPoints(series, interval, DateTimeZone.getDefault(), rollup, null);
- }
-
- /**
- * Returns a cursor of datapoints specified by series with multiple rollups.
- *
- * @param series The series
- * @param interval An interval of time for the query (start/end datetimes)
- * @param timezone The time zone for the returned datapoints.
- * @param rollup The MultiRollup for the read query.
- * @return A Cursor of DataPoints. The cursor.iterator().next() may throw a {@link TempoDBException} if an error occurs while making a request.
- *
- * @see Cursor
- * @see MultiRollup
- * @since 1.0.0
- */
- public Cursor readMultiRollupDataPoints(Series series, Interval interval, DateTimeZone timezone, MultiRollup rollup) {
- return readMultiRollupDataPoints(series, interval, timezone, rollup, null);
- }
-
- /**
- * Returns a cursor of datapoints specified by series with multiple rollups.
- *
- * @param series The series
- * @param interval An interval of time for the query (start/end datetimes)
- * @param timezone The time zone for the returned datapoints.
- * @param rollup The MultiRollup for the read query.
- * @param interpolation The interpolation for the read query. This can be null.
- * @return A Cursor of DataPoints. The cursor.iterator().next() may throw a {@link TempoDBException} if an error occurs while making a request.
- *
- * @see Cursor
- * @see MultiRollup
- * @since 1.0.0
- */
- public Cursor readMultiRollupDataPoints(Series series, Interval interval, DateTimeZone timezone, MultiRollup rollup, Interpolation interpolation) {
- checkNotNull(series);
- checkNotNull(interval);
- checkNotNull(timezone);
- checkNotNull(rollup);
-
- URI uri = null;
- try {
- URIBuilder builder = new URIBuilder(String.format("/%s/series/key/%s/data/rollups/segment/", API_VERSION, urlencode(series.getKey())));
- addInterpolationToURI(builder, interpolation);
- addIntervalToURI(builder, interval);
- addMultiRollupToURI(builder, rollup);
- addTimeZoneToURI(builder, timezone);
- uri = builder.build();
- } catch (URISyntaxException e) {
- String message = String.format("Could not build URI with inputs: key: %s, interval: %s, rollup: %s, timezone: %s", series.getKey(), interval, rollup, timezone);
- throw new IllegalArgumentException(message, e);
- }
-
- Cursor cursor = new MultiRollupDataPointCursor(uri, this);
- return cursor;
- }
-
- /**
- * Returns a cursor of datapoints specified by a series filter.
- *
- *
This endpoint allows one to request multiple series and apply an aggregation function.
- * The system default timezone is used for the returned DateTimes.
- *
- * @param filter The series filter
- * @param interval An interval of time for the query (start/end datetimes)
- * @param aggregation The aggregation for the read query. This is required.
- * @return A Cursor of DataPoints. The cursor.iterator().next() may throw a {@link TempoDBException} if an error occurs while making a request.
- *
- * @see Aggregation
- * @see Cursor
- * @see Filter
- * @since 1.0.0
- */
- public Cursor readDataPoints(Filter filter, Interval interval, Aggregation aggregation) {
- return readDataPoints(filter, interval, DateTimeZone.getDefault(), aggregation, null, null);
- }
-
- /**
- * Returns a cursor of datapoints specified by a series filter.
- *
- *
This endpoint allows one to request multiple series and apply an aggregation function.
- * The system default timezone is used for the returned DateTimes.
- *
- * @param filter The series filter
- * @param interval An interval of time for the query (start/end datetimes)
- * @param aggregation The aggregation for the read query. This is required.
- * @param rollup The rollup for the read query. This can be null.
- * @return A Cursor of DataPoints. The cursor.iterator().next() may throw a {@link TempoDBException} if an error occurs while making a request.
- *
- * @see Aggregation
- * @see Cursor
- * @see Filter
- * @see Rollup
- * @since 1.0.0
- */
- public Cursor readDataPoints(Filter filter, Interval interval, Aggregation aggregation, Rollup rollup) {
- return readDataPoints(filter, interval, DateTimeZone.getDefault(), aggregation, rollup, null);
- }
-
- /**
- * Returns a cursor of datapoints specified by a series filter.
- *
- * This endpoint allows one to request multiple series and apply an aggregation function.
- *
- * @param filter The series filter
- * @param interval An interval of time for the query (start/end datetimes)
- * @param timezone The time zone for the returned datapoints.
- * @param aggregation The aggregation for the read query. This is required.
- * @return A Cursor of DataPoints. The cursor.iterator().next() may throw a {@link TempoDBException} if an error occurs while making a request.
- *
- * @see Aggregation
- * @see Cursor
- * @see Filter
- * @since 1.0.0
- */
- public Cursor readDataPoints(Filter filter, Interval interval, DateTimeZone timezone, Aggregation aggregation) {
- return readDataPoints(filter, interval, timezone, aggregation, null, null);
- }
-
- /**
- * Returns a cursor of datapoints specified by a series filter.
- *
- * This endpoint allows one to request multiple series and apply an aggregation function.
- *
- * @param filter The series filter
- * @param interval An interval of time for the query (start/end datetimes)
- * @param timezone The time zone for the returned datapoints.
- * @param aggregation The aggregation for the read query. This is required.
- * @param rollup The rollup for the read query. This can be null.
- * @param interpolation The interpolation for the read query. This can be null.
- * @return A Cursor of DataPoints. The cursor.iterator().next() may throw a {@link TempoDBException} if an error occurs while making a request.
- *
- * @see Aggregation
- * @see Cursor
- * @see Filter
- * @see Interpolation
- * @see Rollup
- * @since 1.0.0
- */
- public Cursor readDataPoints(Filter filter, Interval interval, DateTimeZone timezone, Aggregation aggregation, Rollup rollup, Interpolation interpolation) {
- checkNotNull(filter);
- checkNotNull(interval);
- checkNotNull(aggregation);
- checkNotNull(timezone);
-
- URI uri = null;
- try {
- URIBuilder builder = new URIBuilder(String.format("/%s/segment/", API_VERSION));
- addFilterToURI(builder, filter);
- addInterpolationToURI(builder, interpolation);
- addIntervalToURI(builder, interval);
- addAggregationToURI(builder, aggregation);
- addRollupToURI(builder, rollup);
- addTimeZoneToURI(builder, timezone);
- uri = builder.build();
- } catch (URISyntaxException e) {
- String message = String.format("Could not build URI with inputs: filter: %s, interval: %s, aggregation: %s, rollup: %s, timezone: %s", filter, interval, aggregation, rollup, timezone);
- throw new IllegalArgumentException(message, e);
- }
-
- Cursor cursor = new DataPointCursor(uri, this);
- return cursor;
- }
-
- /**
- * Returns a cursor of multi-datapoints specified by a series filter.
- *
- *
This endpoint allows one to request datapoints for multiple series in one call.
- * The system default timezone is used for the returned DateTimes.
- *
- * @param filter The series filter
- * @param interval An interval of time for the query (start/end datetimes)
- * @return A Cursor of MultiDataPoints. The cursor.iterator().next() may throw a {@link TempoDBException} if an error occurs while making a request.
- *
- * @see Cursor
- * @see Filter
- * @see MultiDataPoint
- * @since 1.1.0
- */
- public Cursor readMultiDataPoints(Filter filter, Interval interval) {
- return readMultiDataPoints(filter, interval, DateTimeZone.getDefault(), null, null);
- }
-
- /**
- * Returns a cursor of multi-datapoints specified by a series filter.
- *
- *
This endpoint allows one to request datapoints for multiple series in one call.
- * The system default timezone is used for the returned DateTimes.
- *
- * @param filter The series filter
- * @param interval An interval of time for the query (start/end datetimes)
- * @param rollup The rollup for the read query. This can be null.
- * @return A Cursor of MultiDataPoints. The cursor.iterator().next() may throw a {@link TempoDBException} if an error occurs while making a request.
- *
- * @see Cursor
- * @see Filter
- * @see MultiDataPoint
- * @see Rollup
- * @since 1.1.0
- */
- public Cursor readMultiDataPoints(Filter filter, Interval interval, Rollup rollup) {
- return readMultiDataPoints(filter, interval, DateTimeZone.getDefault(), rollup, null);
- }
-
- /**
- * Returns a cursor of multi-datapoints specified by a series filter.
- *
- * This endpoint allows one to request datapoints for multiple series in one call.
- *
- * @param filter The series filter
- * @param interval An interval of time for the query (start/end datetimes)
- * @param timezone The time zone for the returned datapoints.
- * @return A Cursor of MultiDataPoints. The cursor.iterator().next() may throw a {@link TempoDBException} if an error occurs while making a request.
- *
- * @see Cursor
- * @see Filter
- * @see MultiDataPoint
- * @see Rollup
- * @since 1.1.0
- */
- public Cursor readMultiDataPoints(Filter filter, Interval interval, DateTimeZone timezone) {
- return readMultiDataPoints(filter, interval, timezone, null, null);
- }
-
- /**
- * Returns a cursor of multi-datapoints specified by a series filter.
- *
- * This endpoint allows one to request datapoints for multiple series in one call.
- *
- * @param filter The series filter
- * @param interval An interval of time for the query (start/end datetimes)
- * @param timezone The time zone for the returned datapoints.
- * @param rollup The rollup for the read query. This can be null.
- * @param interpolation The interpolation for the read query. This can be null.
- * @return A Cursor of MultiDataPoints. The cursor.iterator().next() may throw a {@link TempoDBException} if an error occurs while making a request.
- *
- * @see Cursor
- * @see Filter
- * @see Interpolation
- * @see MultiDataPoint
- * @see Rollup
- * @since 1.1.0
- */
- public Cursor readMultiDataPoints(Filter filter, Interval interval, DateTimeZone timezone, Rollup rollup, Interpolation interpolation) {
- checkNotNull(filter);
- checkNotNull(interval);
- checkNotNull(timezone);
-
- URI uri = null;
- try {
- URIBuilder builder = new URIBuilder(String.format("/%s/multi/", API_VERSION));
- addFilterToURI(builder, filter);
- addInterpolationToURI(builder, interpolation);
- addIntervalToURI(builder, interval);
- addRollupToURI(builder, rollup);
- addTimeZoneToURI(builder, timezone);
- uri = builder.build();
- } catch (URISyntaxException e) {
- String message = String.format("Could not build URI with inputs: filter: %s, interval: %s, rollup: %s, timezone: %s", filter, interval, rollup, timezone);
- throw new IllegalArgumentException(message, e);
- }
-
- Cursor cursor = new MultiDataPointCursor(uri, this);
- return cursor;
- }
-
- /**
- * Updates all of a Series metadata
- *
- * @param series The series to update
- * @return The updated Series
- *
- * @see Series
- * @since 1.0.0
- */
- public Result updateSeries(Series series) {
- URI uri = null;
- try {
- URIBuilder builder = new URIBuilder(String.format("/%s/series/key/%s/", API_VERSION, urlencode(series.getKey())));
- uri = builder.build();
- } catch (URISyntaxException e) {
- String message = "Could not build URI";
- throw new IllegalArgumentException(message, e);
- }
-
- Result result = null;
- String body = null;
- try {
- body = Json.dumps(series);
- } catch (JsonProcessingException e) {
- String message = "Error serializing the body of the request. More detail: " + e.getMessage();
- result = new Result(null, GENERIC_ERROR_CODE, message);
- return result;
- }
-
- HttpRequest request = buildRequest(uri.toString(), HttpMethod.PUT, body);
- result = execute(request, Series.class);
- return result;
- }
-
- /**
- * Writes datapoints to single Series.
- *
- * @param series The series to write to.
- * @param data A list of datapoints
- * @return {@link Void}
- *
- * @see DataPoint
- * @see Void
- * @since 1.0.0
- */
- public Result writeDataPoints(Series series, List data) {
- checkNotNull(series);
- checkNotNull(data);
-
- URI uri = null;
- try {
- URIBuilder builder = new URIBuilder(String.format("/%s/series/key/%s/data/", API_VERSION, urlencode(series.getKey())));
- uri = builder.build();
- } catch (URISyntaxException e) {
- String message = String.format("Could not build URI with inputs: key: %s", series.getKey());
- throw new IllegalArgumentException(message, e);
- }
-
- Result result = null;
- String body = null;
- try{
- body = Json.dumps(data);
- } catch (JsonProcessingException e) {
- String message = "Error serializing the body of the request. More detail: " + e.getMessage();
- result = new Result(null, GENERIC_ERROR_CODE, message);
- return result;
- }
-
- HttpRequest request = buildRequest(uri.toString(), HttpMethod.POST, body);
- result = execute(request, Void.class);
- return result;
- }
-
- /**
- * Writes datapoints to multiple Series.
- *
- *