Skip to content

Commit

Permalink
Add DeleteService (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
rolincova committed Oct 31, 2019
1 parent 4b1c530 commit e8b518d
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 111 deletions.
63 changes: 0 additions & 63 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -361,69 +361,6 @@ public class FluxExample {
}
```

### Delete data from InfluxDB 2.0

The following example demonstrates how to delete data from InfluxDB 2.0.

#### Installation

Download the latest version:

##### Maven dependency:

```XML
<dependency>
<groupId>com.influxdb</groupId>
<artifactId>influxdb-client-flux</artifactId>
<version>1.2.0</version>
</dependency>
```
##### Or when using Gradle:

```groovy
dependencies {
compile "com.influxdb:influxdb-client-flux:1.2.0"
}
```

```java
package example;

import java.time.OffsetDateTime;
import java.time.temporal.ChronoUnit;

import com.influxdb.client.DeleteApi;
import com.influxdb.client.InfluxDBClient;
import com.influxdb.client.InfluxDBClientFactory;
import com.influxdb.exceptions.InfluxException;

public class DeleteData {

private static char[] token = "my-token".toCharArray();

public static void main(final String[] args) {

InfluxDBClient influxDBClient = InfluxDBClientFactory.create("http://localhost:9999", token);

DeleteApi deleteApi = influxDBClient.getDeleteApi();

try {

OffsetDateTime start = OffsetDateTime.now().minus(1, ChronoUnit.HOURS);
OffsetDateTime stop = OffsetDateTime.now();

deleteApi.delete(start, stop, "", "my-bucket", "my-org");

} catch (InfluxException ie) {
System.out.println("InfluxException: " + ie);
}

influxDBClient.close();
}
}
```

## Build Requirements

* Java 1.8+ (tested with jdk8)
Expand Down
42 changes: 42 additions & 0 deletions client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ The reference Java client that allows query, write and management (bucket, organ
- [Advanced Usage](#advanced-usage)
- [Writing data using synchronous blocking API](#writing-data-using-synchronous-blocking-api)
- [Monitoring & Alerting](#monitoring--alerting)
- [Delete data](#delete-data)
- [Client configuration file](#client-configuration-file)
- [Client connection string](#client-connection-string)
- [Gzip support](#gzip-support)
Expand Down Expand Up @@ -800,6 +801,47 @@ influxDBClient
.createSlackRule("Critical status to Slack", "10s", "${ r._message }", RuleStatusLevel.CRIT, endpoint, org.getId());
```

### Delete data

The following example demonstrates how to delete data from InfluxDB 2.0.

```java
package example;

import java.time.OffsetDateTime;
import java.time.temporal.ChronoUnit;

import com.influxdb.client.DeleteApi;
import com.influxdb.client.InfluxDBClient;
import com.influxdb.client.InfluxDBClientFactory;
import com.influxdb.exceptions.InfluxException;

public class DeleteData {

private static char[] token = "my-token".toCharArray();

public static void main(final String[] args) {

InfluxDBClient influxDBClient = InfluxDBClientFactory.create("http://localhost:9999", token);

DeleteApi deleteApi = influxDBClient.getDeleteApi();

try {

OffsetDateTime start = OffsetDateTime.now().minus(1, ChronoUnit.HOURS);
OffsetDateTime stop = OffsetDateTime.now();

deleteApi.delete(start, stop, "", "my-bucket", "my-org");

} catch (InfluxException ie) {
System.out.println("InfluxException: " + ie);
}

influxDBClient.close();
}
}
```

### Client configuration file

A client can be configured via configuration file. The configuration file has to be named as `influx2.properties` and has to be in root of classpath.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,32 @@
package com.influxdb.client.service;

import com.influxdb.client.domain.DeletePredicateRequest;
import com.influxdb.client.domain.Routes;

import retrofit2.Call;
import retrofit2.http.*;
import retrofit2.http.GET;
import retrofit2.http.Headers;
import retrofit2.http.POST;

public interface DefaultService {
/**
* delete Time series data from InfluxDB
*
* @param deletePredicateRequest predicate delete request (required)
* @param zapTraceSpan OpenTracing span context (optional)
* @param org specifies the destination organization for writes (optional)
* @param bucket specifies the destination bucket for writes (optional)
* @param orgID specifies the organization ID of the resource (optional)
* @param bucketID specifies the destination bucket ID for writes (optional)
* @return Call&lt;Void&gt;
*/
@Headers({
"Content-Type:application/json"
})
@POST("api/v2/delete")
Call<Void> deletePost(
@retrofit2.http.Body DeletePredicateRequest deletePredicateRequest, @retrofit2.http.Header("Zap-Trace-Span") String zapTraceSpan, @retrofit2.http.Query("org") String org, @retrofit2.http.Query("bucket") String bucket, @retrofit2.http.Query("orgID") String orgID, @retrofit2.http.Query("bucketID") String bucketID
);

/**
* Map of all top level routes available
*
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,16 @@
*/
package com.influxdb.client.internal;

import javax.annotation.Nonnull;
import java.time.OffsetDateTime;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Nonnull;

import com.influxdb.Arguments;
import com.influxdb.client.DeleteApi;
import com.influxdb.client.domain.DeletePredicateRequest;
import com.influxdb.client.service.DeleteService;
import com.influxdb.client.service.DefaultService;
import com.influxdb.internal.AbstractRestClient;

import retrofit2.Call;

/**
Expand All @@ -41,9 +40,9 @@ public class DeleteApiImpl extends AbstractRestClient implements DeleteApi {

private static final Logger LOG = Logger.getLogger(DeleteApiImpl.class.getName());

private final DeleteService service;
private final DefaultService service;

DeleteApiImpl(@Nonnull final DeleteService service) {
DeleteApiImpl(@Nonnull final DefaultService service) {

Arguments.checkNotNull(service, "service");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
*/
package com.influxdb.client.internal;

import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.logging.Level;
import java.util.logging.Logger;

import com.influxdb.Arguments;
import com.influxdb.LogLevel;
Expand Down Expand Up @@ -59,7 +59,7 @@
import com.influxdb.client.service.BucketsService;
import com.influxdb.client.service.ChecksService;
import com.influxdb.client.service.DashboardsService;
import com.influxdb.client.service.DeleteService;
import com.influxdb.client.service.DefaultService;
import com.influxdb.client.service.LabelsService;
import com.influxdb.client.service.NotificationEndpointsService;
import com.influxdb.client.service.NotificationRulesService;
Expand All @@ -77,7 +77,6 @@
import com.influxdb.client.service.WriteService;
import com.influxdb.exceptions.InfluxException;
import com.influxdb.exceptions.UnprocessableEntityException;

import retrofit2.Call;

/**
Expand Down Expand Up @@ -219,7 +218,7 @@ public NotificationRulesApi getNotificationRulesApi() {
@Nonnull
@Override
public DeleteApi getDeleteApi() {
return new DeleteApiImpl(retrofit.create(DeleteService.class));
return new DeleteApiImpl(retrofit.create(DefaultService.class));
}

@Nonnull
Expand Down

0 comments on commit e8b518d

Please sign in to comment.