Skip to content

Commit 4c53390

Browse files
committed
Add DeleteService (#66)
1 parent ace4c94 commit 4c53390

File tree

8 files changed

+265
-33
lines changed

8 files changed

+265
-33
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
### API
44
1. [#65](https://github.com/influxdata/influxdb-client-java/pull/65): Updated swagger to latest version
5-
5+
1. [#66](https://github.com/influxdata/influxdb-client-java/pull/66): Added DeleteApi
66

77
## 1.1.0 [2019-10-11]
88

client/src/generated/java/com/influxdb/client/service/DefaultService.java

+2-32
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,11 @@
11
package com.influxdb.client.service;
22

3-
import retrofit2.Call;
4-
import retrofit2.http.*;
5-
6-
import okhttp3.RequestBody;
7-
import okhttp3.ResponseBody;
8-
import okhttp3.MultipartBody;
9-
10-
import com.influxdb.client.domain.DeletePredicateRequest;
11-
import com.influxdb.client.domain.Error;
123
import com.influxdb.client.domain.Routes;
134

14-
import java.util.ArrayList;
15-
import java.util.HashMap;
16-
import java.util.List;
17-
import java.util.Map;
5+
import retrofit2.Call;
6+
import retrofit2.http.*;
187

198
public interface DefaultService {
20-
/**
21-
* delete Time series data from InfluxDB
22-
*
23-
* @param deletePredicateRequest predicate delete request (required)
24-
* @param zapTraceSpan OpenTracing span context (optional)
25-
* @param org specifies the destination organization for writes (optional)
26-
* @param bucket specifies the destination bucket for writes (optional)
27-
* @param orgID specifies the organization ID of the resource (optional)
28-
* @param bucketID specifies the destination bucket ID for writes (optional)
29-
* @return Call<Void>
30-
*/
31-
@Headers({
32-
"Content-Type:application/json"
33-
})
34-
@POST("api/v2/delete")
35-
Call<Void> deletePost(
36-
@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
37-
);
38-
399
/**
4010
* Map of all top level routes available
4111
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.influxdb.client.service;
2+
3+
import com.influxdb.client.domain.DeletePredicateRequest;
4+
5+
import retrofit2.Call;
6+
import retrofit2.http.Headers;
7+
import retrofit2.http.POST;
8+
9+
/**
10+
* @author Pavlina Rolincova (rolincova@github) (29/10/2019).
11+
*/
12+
public interface DeleteService {
13+
/**
14+
* delete Time series data from InfluxDB
15+
*
16+
* @param deletePredicateRequest predicate delete request (required)
17+
* @param zapTraceSpan OpenTracing span context (optional)
18+
* @param org specifies the destination organization for writes (optional)
19+
* @param bucket specifies the destination bucket for writes (optional)
20+
* @param orgID specifies the organization ID of the resource (optional)
21+
* @param bucketID specifies the destination bucket ID for writes (optional)
22+
* @return Call&lt;Void&gt;
23+
*/
24+
@Headers({
25+
"Content-Type:application/json"
26+
})
27+
@POST("api/v2/delete")
28+
Call<Void> deletePost(
29+
@retrofit2.http.Body DeletePredicateRequest deletePredicateRequest,
30+
@retrofit2.http.Header("Zap-Trace-Span") String zapTraceSpan,
31+
@retrofit2.http.Query("org") String org,
32+
@retrofit2.http.Query("bucket") String bucket,
33+
@retrofit2.http.Query("orgID") String orgID,
34+
@retrofit2.http.Query("bucketID") String bucketID
35+
);
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* The MIT License
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
* THE SOFTWARE.
21+
*/
22+
package com.influxdb.client;
23+
24+
import java.time.OffsetDateTime;
25+
import javax.annotation.Nonnull;
26+
27+
import com.influxdb.client.domain.DeletePredicateRequest;
28+
29+
/**
30+
* API to Delete time-series data from InfluxDB 2.0.
31+
*
32+
* @author Pavlina Rolincova (rolincova@github) (25/10/2019).
33+
*/
34+
public interface DeleteApi {
35+
36+
/**
37+
* Delete Time series data from InfluxDB.
38+
*
39+
* @param start time
40+
* @param stop time
41+
* @param predicate sql where like delete statement.
42+
* @param bucket The bucket from which data will be deleted.
43+
* @param org The organization name of the above bucket.
44+
**/
45+
void delete(@Nonnull final OffsetDateTime start,
46+
@Nonnull final OffsetDateTime stop,
47+
@Nonnull final String predicate,
48+
@Nonnull final String bucket,
49+
@Nonnull final String org);
50+
51+
/**
52+
* Delete Time series data from InfluxDB.
53+
*
54+
* @param predicate delete request.
55+
* @param bucket The bucket from which data will be deleted.
56+
* @param org The organization name of the above bucket.
57+
**/
58+
void delete(@Nonnull final DeletePredicateRequest predicate,
59+
@Nonnull final String bucket,
60+
@Nonnull final String org);
61+
}

client/src/main/java/com/influxdb/client/InfluxDBClient.java

+8
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,14 @@ public interface InfluxDBClient extends AutoCloseable {
207207
@Nonnull
208208
NotificationRulesApi getNotificationRulesApi();
209209

210+
/**
211+
* Get the Delete client.
212+
*
213+
* @return the new client instance for the Delete API
214+
*/
215+
@Nonnull
216+
DeleteApi getDeleteApi();
217+
210218
/**
211219
* Create an implementation of the API endpoints defined by the {@code service} interface.
212220
* <p>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* Permission is hereby granted, free of charge, to any person obtaining a copy
3+
* of this software and associated documentation files (the "Software"), to deal
4+
* in the Software without restriction, including without limitation the rights
5+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
6+
* copies of the Software, and to permit persons to whom the Software is
7+
* furnished to do so, subject to the following conditions:
8+
*
9+
* The above copyright notice and this permission notice shall be included in
10+
* all copies or substantial portions of the Software.
11+
*
12+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
18+
* THE SOFTWARE.
19+
*/
20+
package com.influxdb.client.internal;
21+
22+
import java.time.OffsetDateTime;
23+
import java.util.logging.Level;
24+
import java.util.logging.Logger;
25+
import javax.annotation.Nonnull;
26+
27+
import com.influxdb.Arguments;
28+
import com.influxdb.client.DeleteApi;
29+
import com.influxdb.client.domain.DeletePredicateRequest;
30+
import com.influxdb.client.service.DeleteService;
31+
import com.influxdb.internal.AbstractRestClient;
32+
33+
import retrofit2.Call;
34+
35+
/**
36+
* @author Pavlina Rolincova (rolincova@github) (25/10/2019).
37+
*/
38+
public class DeleteApiImpl extends AbstractRestClient implements DeleteApi {
39+
40+
private static final Logger LOG = Logger.getLogger(DeleteApiImpl.class.getName());
41+
42+
private final DeleteService service;
43+
44+
DeleteApiImpl(DeleteService service) {
45+
46+
Arguments.checkNotNull(service, "service");
47+
48+
this.service = service;
49+
}
50+
51+
@Override
52+
public void delete(@Nonnull OffsetDateTime start,
53+
@Nonnull OffsetDateTime stop,
54+
@Nonnull String predicate,
55+
@Nonnull String bucket,
56+
@Nonnull String organization) {
57+
58+
Arguments.checkNotNull(start, "Start is required");
59+
Arguments.checkNotNull(stop, "Stop is required");
60+
Arguments.checkNotNull(predicate, "Predicate is required");
61+
Arguments.checkNotNull(bucket, "Bucket is required");
62+
Arguments.checkNotNull(organization, "Organization is required");
63+
64+
DeletePredicateRequest request = new DeletePredicateRequest();
65+
request.setStart(start);
66+
request.setStop(stop);
67+
request.setPredicate(predicate);
68+
69+
delete(request, bucket, organization);
70+
}
71+
72+
@Override
73+
public void delete(@Nonnull DeletePredicateRequest predicate,
74+
@Nonnull String bucket,
75+
@Nonnull String organization) {
76+
77+
Arguments.checkNotNull(predicate, "Predicate is required");
78+
Arguments.checkNotNull(bucket, "Bucket is required");
79+
Arguments.checkNotNull(organization, "Organization is required");
80+
81+
LOG.log(Level.FINEST,
82+
"Deleting time-series data from InfluxDB (org={0}, bucket={1})...",
83+
new Object[]{organization, bucket});
84+
85+
Call<Void> call = service.deletePost(predicate, null, organization, bucket,
86+
null, null);
87+
88+
execute(call);
89+
90+
LOG.log(Level.FINEST, "Data was deleted from InfluxDB: (org={0}, bucket={1})",
91+
new Object[]{organization, bucket});
92+
}
93+
}

client/src/main/java/com/influxdb/client/internal/InfluxDBClientImpl.java

+8
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import com.influxdb.client.BucketsApi;
3333
import com.influxdb.client.ChecksApi;
3434
import com.influxdb.client.DashboardsApi;
35+
import com.influxdb.client.DeleteApi;
3536
import com.influxdb.client.InfluxDBClient;
3637
import com.influxdb.client.InfluxDBClientOptions;
3738
import com.influxdb.client.LabelsApi;
@@ -58,6 +59,7 @@
5859
import com.influxdb.client.service.BucketsService;
5960
import com.influxdb.client.service.ChecksService;
6061
import com.influxdb.client.service.DashboardsService;
62+
import com.influxdb.client.service.DeleteService;
6163
import com.influxdb.client.service.LabelsService;
6264
import com.influxdb.client.service.NotificationEndpointsService;
6365
import com.influxdb.client.service.NotificationRulesService;
@@ -214,6 +216,12 @@ public NotificationRulesApi getNotificationRulesApi() {
214216
return new NotificationRulesApiImpl(retrofit.create(NotificationRulesService.class));
215217
}
216218

219+
@Nonnull
220+
@Override
221+
public DeleteApi getDeleteApi() {
222+
return new DeleteApiImpl(retrofit.create(DeleteService.class));
223+
}
224+
217225
@Nonnull
218226
@Override
219227
public <S> S getService(@Nonnull final Class<S> service) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Permission is hereby granted, free of charge, to any person obtaining a copy
3+
* of this software and associated documentation files (the "Software"), to deal
4+
* in the Software without restriction, including without limitation the rights
5+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
6+
* copies of the Software, and to permit persons to whom the Software is
7+
* furnished to do so, subject to the following conditions:
8+
*
9+
* The above copyright notice and this permission notice shall be included in
10+
* all copies or substantial portions of the Software.
11+
*
12+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
18+
* THE SOFTWARE.
19+
*/
20+
package example;
21+
22+
import java.time.OffsetDateTime;
23+
import java.time.temporal.ChronoUnit;
24+
25+
import com.influxdb.client.DeleteApi;
26+
import com.influxdb.client.InfluxDBClient;
27+
import com.influxdb.client.InfluxDBClientFactory;
28+
import com.influxdb.exceptions.InfluxException;
29+
30+
/**
31+
* @author Pavlina Rolincova (rolincova@github) (29/10/2019).
32+
*/
33+
public class DeleteData {
34+
35+
private static char[] token = "my-token".toCharArray();
36+
37+
public static void main(final String[] args) {
38+
39+
InfluxDBClient influxDBClient = InfluxDBClientFactory.create("http://localhost:9999", token);
40+
41+
DeleteApi deleteApi = influxDBClient.getDeleteApi();
42+
43+
try {
44+
45+
OffsetDateTime start = OffsetDateTime.now().minus(1, ChronoUnit.HOURS);
46+
OffsetDateTime stop = OffsetDateTime.now();
47+
48+
deleteApi.delete(start, stop, "", "my-bucket", "my-org");
49+
50+
} catch (InfluxException ie) {
51+
System.out.println("InfluxException: " + ie);
52+
}
53+
54+
influxDBClient.close();
55+
}
56+
}

0 commit comments

Comments
 (0)