Skip to content

Commit 07b102c

Browse files
authored
feat: add soft delete api (#189)
* add soft delete api * update pom.xml
1 parent ecd864d commit 07b102c

11 files changed

+659
-1
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<groupId>com.aliyun.openservices</groupId>
1313
<artifactId>aliyun-log</artifactId>
14-
<version>0.6.132</version>
14+
<version>0.6.133</version>
1515
<packaging>jar</packaging>
1616

1717
<name>Aliyun LOG Java SDK</name>

src/main/java/com/aliyun/openservices/log/Client.java

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6530,4 +6530,61 @@ public ListMaterializedViewsResponse listMaterializedViews(ListMaterializedViews
65306530
mvResponse.setCount(object.getIntValue(Consts.CONST_COUNT));
65316531
return mvResponse;
65326532
}
6533+
6534+
@Override
6535+
public DeleteLogStoreLogsResponse deleteLogStoreLogs(DeleteLogStoreLogsRequest request) throws LogException {
6536+
CodingUtils.assertParameterNotNull(request, "request");
6537+
CodingUtils.assertStringNotNullOrEmpty(request.GetProject(), "project");
6538+
CodingUtils.assertStringNotNullOrEmpty(request.getLogstore(), "logstore");
6539+
6540+
ResponseMessage response = send(request);
6541+
String requestId = GetRequestId(response.getHeaders());
6542+
JSONObject responseBody = parseResponseBody(response, requestId);
6543+
String taskId = responseBody.getString("taskId");
6544+
6545+
return new DeleteLogStoreLogsResponse(response.getHeaders(), taskId);
6546+
}
6547+
6548+
@Override
6549+
public GetDeleteLogStoreLogsTaskResponse getDeleteLogStoreLogsTask(GetDeleteLogStoreLogsTaskRequest request) throws LogException {
6550+
CodingUtils.assertParameterNotNull(request, "request");
6551+
CodingUtils.assertStringNotNullOrEmpty(request.GetProject(), "project");
6552+
CodingUtils.assertStringNotNullOrEmpty(request.getLogstore(), "logstore");
6553+
CodingUtils.assertStringNotNullOrEmpty(request.getTaskId(), "taskId");
6554+
6555+
ResponseMessage response = send(request);
6556+
String requestId = GetRequestId(response.getHeaders());
6557+
JSONObject responseBody = parseResponseBody(response, requestId);
6558+
6559+
DeleteLogStoreLogsTask task = new DeleteLogStoreLogsTask();
6560+
task.fromJsonObject(responseBody);
6561+
6562+
return new GetDeleteLogStoreLogsTaskResponse(response.getHeaders(), task);
6563+
}
6564+
6565+
@Override
6566+
public ListDeleteLogStoreLogsTasksResponse listDeleteLogStoreLogsTasks(ListDeleteLogStoreLogsTasksRequest request) throws LogException {
6567+
CodingUtils.assertParameterNotNull(request, "request");
6568+
CodingUtils.assertStringNotNullOrEmpty(request.GetProject(), "project");
6569+
CodingUtils.assertStringNotNullOrEmpty(request.getLogstore(), "logstore");
6570+
6571+
ResponseMessage response = send(request);
6572+
String requestId = GetRequestId(response.getHeaders());
6573+
JSONObject responseBody = parseResponseBody(response, requestId);
6574+
6575+
int total = responseBody.getIntValue("total");
6576+
JSONArray tasksArray = responseBody.getJSONArray("tasks");
6577+
List<DeleteLogStoreLogsTask> tasks = new ArrayList<>();
6578+
6579+
if (tasksArray != null) {
6580+
for (int i = 0; i < tasksArray.size(); i++) {
6581+
JSONObject taskObj = tasksArray.getJSONObject(i);
6582+
DeleteLogStoreLogsTask task = new DeleteLogStoreLogsTask();
6583+
task.fromJsonObject(taskObj);
6584+
tasks.add(task);
6585+
}
6586+
}
6587+
6588+
return new ListDeleteLogStoreLogsTasksResponse(response.getHeaders(), total, tasks);
6589+
}
65336590
}

src/main/java/com/aliyun/openservices/log/LogService.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3754,4 +3754,31 @@ ProjectConsumerGroupHeartBeatResponse ProjectConsumerGroupHeartBeat(
37543754
void createMaterializedView(CreateMaterializedViewRequest request) throws LogException;
37553755
void deleteMaterializedView(String project, String materializedView) throws LogException;
37563756
ListMaterializedViewsResponse listMaterializedViews(ListMaterializedViewsRequest request) throws LogException;
3757+
3758+
/**
3759+
* Delete logs from a log store
3760+
*
3761+
* @param request An instance of {@link DeleteLogStoreLogsRequest}
3762+
* @return An instance of {@link DeleteLogStoreLogsResponse}
3763+
* @throws LogException if any error occurs
3764+
*/
3765+
DeleteLogStoreLogsResponse deleteLogStoreLogs(DeleteLogStoreLogsRequest request) throws LogException;
3766+
3767+
/**
3768+
* Get delete log store logs task status
3769+
*
3770+
* @param request An instance of {@link GetDeleteLogStoreLogsTaskRequest}
3771+
* @return An instance of {@link GetDeleteLogStoreLogsTaskResponse}
3772+
* @throws LogException if any error occurs
3773+
*/
3774+
GetDeleteLogStoreLogsTaskResponse getDeleteLogStoreLogsTask(GetDeleteLogStoreLogsTaskRequest request) throws LogException;
3775+
3776+
/**
3777+
* List delete log store logs tasks
3778+
*
3779+
* @param request An instance of {@link ListDeleteLogStoreLogsTasksRequest}
3780+
* @return An instance of {@link ListDeleteLogStoreLogsTasksResponse}
3781+
* @throws LogException if any error occurs
3782+
*/
3783+
ListDeleteLogStoreLogsTasksResponse listDeleteLogStoreLogsTasks(ListDeleteLogStoreLogsTasksRequest request) throws LogException;
37573784
}
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
package com.aliyun.openservices.log.common;
2+
3+
import com.alibaba.fastjson.JSONObject;
4+
import com.alibaba.fastjson.annotation.JSONField;
5+
import com.aliyun.openservices.log.exception.LogException;
6+
import com.aliyun.openservices.log.internal.ErrorCodes;
7+
8+
import java.io.Serializable;
9+
10+
/**
11+
* DeleteLogStoreLogsTask represents a soft delete task for log store logs
12+
*/
13+
public class DeleteLogStoreLogsTask implements Serializable {
14+
private static final long serialVersionUID = 6842917394758326187L;
15+
16+
@JSONField
17+
private int progress;
18+
19+
@JSONField
20+
private String taskId;
21+
22+
@JSONField
23+
private String query;
24+
25+
@JSONField
26+
private int errorCode;
27+
28+
@JSONField
29+
private int from;
30+
31+
@JSONField
32+
private int to;
33+
34+
@JSONField
35+
private String errorMessage;
36+
37+
public DeleteLogStoreLogsTask() {
38+
}
39+
40+
public DeleteLogStoreLogsTask(String taskId, String query, int from, int to) {
41+
this.taskId = taskId;
42+
this.query = query;
43+
this.from = from;
44+
this.to = to;
45+
this.progress = 0;
46+
this.errorCode = 0;
47+
this.errorMessage = "";
48+
}
49+
50+
public int getProgress() {
51+
return progress;
52+
}
53+
54+
public void setProgress(int progress) {
55+
this.progress = progress;
56+
}
57+
58+
public String getTaskId() {
59+
return taskId;
60+
}
61+
62+
public void setTaskId(String taskId) {
63+
this.taskId = taskId;
64+
}
65+
66+
public String getQuery() {
67+
return query;
68+
}
69+
70+
public void setQuery(String query) {
71+
this.query = query;
72+
}
73+
74+
public int getErrorCode() {
75+
return errorCode;
76+
}
77+
78+
public void setErrorCode(int errorCode) {
79+
this.errorCode = errorCode;
80+
}
81+
82+
public int getFrom() {
83+
return from;
84+
}
85+
86+
public void setFrom(int from) {
87+
this.from = from;
88+
}
89+
90+
public int getTo() {
91+
return to;
92+
}
93+
94+
public void setTo(int to) {
95+
this.to = to;
96+
}
97+
98+
public String getErrorMessage() {
99+
return errorMessage;
100+
}
101+
102+
public void setErrorMessage(String errorMessage) {
103+
this.errorMessage = errorMessage;
104+
}
105+
106+
public JSONObject toJsonObject() {
107+
JSONObject json = new JSONObject();
108+
json.put("progress", progress);
109+
json.put("taskId", taskId);
110+
json.put("query", query);
111+
json.put("errorCode", errorCode);
112+
json.put("from", from);
113+
json.put("to", to);
114+
json.put("errorMessage", errorMessage);
115+
return json;
116+
}
117+
118+
public void fromJsonObject(JSONObject jsonObject) throws LogException {
119+
try {
120+
this.progress = jsonObject.getIntValue("progress");
121+
this.taskId = jsonObject.getString("taskId");
122+
this.query = jsonObject.getString("query");
123+
this.errorCode = jsonObject.getIntValue("errorCode");
124+
this.from = jsonObject.getIntValue("from");
125+
this.to = jsonObject.getIntValue("to");
126+
this.errorMessage = jsonObject.getString("errorMessage");
127+
} catch (Exception ex) {
128+
throw new LogException(ErrorCodes.BAD_RESPONSE,
129+
"Failed to parse DeleteLogStoreLogsTask from JSON: " + ex.getMessage(), ex, "");
130+
}
131+
}
132+
133+
@Override
134+
public String toString() {
135+
return "DeleteLogStoreLogsTask{" +
136+
"progress=" + progress +
137+
", taskId='" + taskId + '\'' +
138+
", query='" + query + '\'' +
139+
", errorCode=" + errorCode +
140+
", from=" + from +
141+
", to=" + to +
142+
", errorMessage='" + errorMessage + '\'' +
143+
'}';
144+
}
145+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package com.aliyun.openservices.log.request;
2+
3+
import com.alibaba.fastjson.JSONObject;
4+
import com.aliyun.openservices.log.http.client.HttpMethod;
5+
6+
/**
7+
* Request for deleting logs from a log store
8+
*/
9+
public class DeleteLogStoreLogsRequest extends BasicRequest {
10+
11+
private static final long serialVersionUID = 2859364729401856234L;
12+
13+
private String logstore;
14+
private int from;
15+
private int to;
16+
private String query;
17+
18+
/**
19+
* Construct a delete log store logs request
20+
*
21+
* @param project project name
22+
* @param logstore log store name
23+
* @param from start time (unix timestamp)
24+
* @param to end time (unix timestamp)
25+
* @param query query condition for filtering logs to delete
26+
*/
27+
public DeleteLogStoreLogsRequest(String project, String logstore, int from, int to, String query) {
28+
super(project);
29+
this.logstore = logstore;
30+
this.from = from;
31+
this.to = to;
32+
this.query = query;
33+
}
34+
35+
public String getLogstore() {
36+
return logstore;
37+
}
38+
39+
public void setLogstore(String logstore) {
40+
this.logstore = logstore;
41+
}
42+
43+
public int getFrom() {
44+
return from;
45+
}
46+
47+
public void setFrom(int from) {
48+
this.from = from;
49+
}
50+
51+
public int getTo() {
52+
return to;
53+
}
54+
55+
public void setTo(int to) {
56+
this.to = to;
57+
}
58+
59+
public String getQuery() {
60+
return query;
61+
}
62+
63+
public void setQuery(String query) {
64+
this.query = query;
65+
}
66+
67+
@Override
68+
public HttpMethod getMethod() {
69+
return HttpMethod.POST;
70+
}
71+
72+
@Override
73+
public String getUri() {
74+
return "/logstores/" + logstore + "/deletelogtasks";
75+
}
76+
77+
@Override
78+
public Object getBody() {
79+
JSONObject body = new JSONObject();
80+
body.put("from", from);
81+
body.put("to", to);
82+
body.put("query", query);
83+
return body;
84+
}
85+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.aliyun.openservices.log.request;
2+
3+
import com.aliyun.openservices.log.http.client.HttpMethod;
4+
5+
/**
6+
* Request for getting a delete log store logs task status
7+
*/
8+
public class GetDeleteLogStoreLogsTaskRequest extends BasicRequest {
9+
10+
private static final long serialVersionUID = 4731685092846173965L;
11+
12+
private String logstore;
13+
private String taskId;
14+
15+
/**
16+
* Construct a get delete log store logs task request
17+
*
18+
* @param project project name
19+
* @param logstore log store name
20+
* @param taskId task ID
21+
*/
22+
public GetDeleteLogStoreLogsTaskRequest(String project, String logstore, String taskId) {
23+
super(project);
24+
this.logstore = logstore;
25+
this.taskId = taskId;
26+
}
27+
28+
public String getLogstore() {
29+
return logstore;
30+
}
31+
32+
public void setLogstore(String logstore) {
33+
this.logstore = logstore;
34+
}
35+
36+
public String getTaskId() {
37+
return taskId;
38+
}
39+
40+
public void setTaskId(String taskId) {
41+
this.taskId = taskId;
42+
}
43+
44+
@Override
45+
public HttpMethod getMethod() {
46+
return HttpMethod.GET;
47+
}
48+
49+
@Override
50+
public String getUri() {
51+
return "/logstores/" + logstore + "/deletelogtasks/" + taskId;
52+
}
53+
}

0 commit comments

Comments
 (0)