Skip to content

Commit ecd864d

Browse files
authored
support meterial view, sync code (#188)
1 parent ec03344 commit ecd864d

21 files changed

+468
-235
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.131</version>
14+
<version>0.6.132</version>
1515
<packaging>jar</packaging>
1616

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

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6498,4 +6498,36 @@ public void deleteAsyncSql(DeleteAsyncSqlRequest request) throws LogException {
64986498

64996499
SendData(project, HttpMethod.DELETE, resourceUri, urlParameter, headers, new byte[0], null, realServerIP);
65006500
}
6501+
6502+
@Override
6503+
public void createMaterializedView(CreateMaterializedViewRequest request) throws LogException {
6504+
Map<String, String> headers = GetCommonHeadPara(request.GetProject());
6505+
headers.put(Consts.CONST_CONTENT_TYPE, Consts.CONST_SLS_JSON);
6506+
SendData(request.GetProject(), HttpMethod.POST, "/materializedviews", request.GetAllParams(), headers, request.getRequestBody(), null, realServerIP);
6507+
}
6508+
6509+
@Override
6510+
public void deleteMaterializedView(String project, String materializedView) throws LogException {
6511+
Map<String, String> headers = GetCommonHeadPara(project);
6512+
headers.put(Consts.CONST_CONTENT_TYPE, Consts.CONST_SLS_JSON);
6513+
SendData(project, HttpMethod.DELETE, "/materializedviews/" + materializedView, Collections.emptyMap(), headers, new byte[0], null, realServerIP);
6514+
}
6515+
6516+
public ListMaterializedViewsResponse listMaterializedViews(ListMaterializedViewsRequest request) throws LogException {
6517+
CodingUtils.assertParameterNotNull(request, "request");
6518+
String project = request.GetProject();
6519+
CodingUtils.assertStringNotNullOrEmpty(project, "project");
6520+
Map<String, String> urlParameter = request.GetAllParams();
6521+
Map<String, String> headParameter = GetCommonHeadPara(project);
6522+
String resourceUri = "/materializedviews";
6523+
ResponseMessage response = SendData(project, HttpMethod.GET, resourceUri, urlParameter, headParameter);
6524+
Map<String, String> resHeaders = response.getHeaders();
6525+
String requestId = GetRequestId(resHeaders);
6526+
JSONObject object = parseResponseBody(response, requestId);
6527+
ListMaterializedViewsResponse mvResponse = new ListMaterializedViewsResponse(resHeaders);
6528+
mvResponse.setMaterializedViews(ExtractJsonArray(Consts.CONST_RESULT_MATERIALIZED_VIEWS, object));
6529+
mvResponse.setTotal(object.getIntValue(Consts.CONST_TOTAL));
6530+
mvResponse.setCount(object.getIntValue(Consts.CONST_COUNT));
6531+
return mvResponse;
6532+
}
65016533
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3750,4 +3750,8 @@ ProjectConsumerGroupHeartBeatResponse ProjectConsumerGroupHeartBeat(
37503750
SubmitAsyncSqlResponse submitAsyncSql(SubmitAsyncSqlRequest request) throws LogException;
37513751
GetAsyncSqlResponse getAsyncSql(GetAsyncSqlRequest request) throws LogException;
37523752
void deleteAsyncSql(DeleteAsyncSqlRequest request) throws LogException;
3753+
3754+
void createMaterializedView(CreateMaterializedViewRequest request) throws LogException;
3755+
void deleteMaterializedView(String project, String materializedView) throws LogException;
3756+
ListMaterializedViewsResponse listMaterializedViews(ListMaterializedViewsRequest request) throws LogException;
37533757
}

src/main/java/com/aliyun/openservices/log/common/Consts.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ public String toString() {
255255
public static final String CONST_RESULT_LOG_STORES = "logstores";
256256
public static final String CONST_RESULT_SUB_STORES = "substores";
257257
public static final String CONST_RESULT_EXTERNAL_STORES = "externalstores";
258+
public static final String CONST_RESULT_MATERIALIZED_VIEWS = "materializedViews";
258259
public static final String CONST_EXTERNAL_NAME = "externalStoreName";
259260
public static final String CONST_RESULT_HISTOGRAMS = "histograms";
260261
public static final String CONST_RESULT_PROCESS = "progress";

src/main/java/com/aliyun/openservices/log/request/BatchPutLogsRequest.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,49 +13,49 @@
1313

1414
public class BatchPutLogsRequest extends Request {
1515
private static final long serialVersionUID = 3221252831212912821L;
16-
private final List<LogGroup> mLogGroups = new ArrayList<LogGroup>();
17-
private String mLogStore;
18-
private String mHashKey;
19-
private CompressType mCompressType = CompressType.LZ4;
16+
private final List<LogGroup> logGroups = new ArrayList<LogGroup>();
17+
private String logStore;
18+
private String hashKey;
19+
private CompressType compressType = CompressType.LZ4;
2020

2121
public BatchPutLogsRequest(String project, String logStore, List<LogGroup> logGroups, String hashKey) {
2222
super(project);
23-
mLogStore = logStore;
24-
mHashKey = hashKey;
25-
mLogGroups.addAll(logGroups);
23+
this.logStore = logStore;
24+
this.hashKey = hashKey;
25+
this.logGroups.addAll(logGroups);
2626
}
2727

2828
public String getLogStore() {
29-
return mLogStore;
29+
return logStore;
3030
}
3131

3232
public void setLogStore(String logStore) {
33-
mLogStore = logStore;
33+
this.logStore = logStore;
3434
}
3535

3636
public String getHashKey() {
37-
return mHashKey;
37+
return hashKey;
3838
}
3939

4040
public void setHashKey(String hashKey) {
41-
mHashKey = hashKey;
41+
this.hashKey = hashKey;
4242
}
4343

4444
public List<LogGroup> getLogGroups() {
45-
return mLogGroups;
45+
return logGroups;
4646
}
4747

4848
public void setLogGroups(List<LogGroup> logGroups) {
49-
mLogGroups.clear();
50-
mLogGroups.addAll(logGroups);
49+
this.logGroups.clear();
50+
this.logGroups.addAll(logGroups);
5151
}
5252

5353
public CompressType getCompressType() {
54-
return mCompressType;
54+
return compressType;
5555
}
5656

5757
public void setCompressType(CompressType compressType) {
58-
mCompressType = compressType;
58+
this.compressType = compressType;
5959
}
6060

6161
public byte[] serializeToPb() throws LogException {
@@ -75,7 +75,7 @@ public byte[] serializeToPb() throws LogException {
7575
}
7676

7777
Logs.SlsLogPackageList.Builder builder = Logs.SlsLogPackageList.newBuilder();
78-
for (LogGroup logGroup : mLogGroups) {
78+
for (LogGroup logGroup : logGroups) {
7979
byte[] logGroupBytes = logGroup.serializeToPb();
8080
Logs.SlsLogPackage.Builder packageBuilder = builder.addPackagesBuilder();
8181
packageBuilder.setUncompressSize(logGroupBytes.length);
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package com.aliyun.openservices.log.request;
2+
3+
import com.alibaba.fastjson.JSON;
4+
5+
import java.nio.charset.StandardCharsets;
6+
import java.util.HashMap;
7+
import java.util.Map;
8+
9+
public class CreateMaterializedViewRequest extends Request {
10+
private final String name;
11+
private final String logstore;
12+
private final String originalSql;
13+
private final int aggIntervalMins;
14+
private final int startTime;
15+
private final int ttl;
16+
17+
public CreateMaterializedViewRequest(String project,
18+
String name,
19+
String logstore,
20+
String originalSql,
21+
int aggIntervalMins,
22+
int startTime,
23+
int ttl) {
24+
super(project);
25+
this.name = name;
26+
this.logstore = logstore;
27+
this.originalSql = originalSql;
28+
this.aggIntervalMins = aggIntervalMins;
29+
this.startTime = startTime;
30+
this.ttl = ttl;
31+
}
32+
33+
public String getName() {
34+
return name;
35+
}
36+
37+
public String getLogstore() {
38+
return logstore;
39+
}
40+
41+
public String getOriginalSql() {
42+
return originalSql;
43+
}
44+
45+
public int getAggIntervalMins() {
46+
return aggIntervalMins;
47+
}
48+
49+
public int getStartTime() {
50+
return startTime;
51+
}
52+
53+
public int getTtl() {
54+
return ttl;
55+
}
56+
57+
public byte[] getRequestBody() {
58+
Map<String, Object> body = new HashMap<>();
59+
body.put("name", name);
60+
body.put("logstore", logstore);
61+
body.put("originalSql", originalSql);
62+
body.put("aggIntervalMins", aggIntervalMins);
63+
body.put("startTime", startTime);
64+
body.put("ttl", ttl);
65+
return JSON.toJSONString(body).getBytes(StandardCharsets.UTF_8);
66+
}
67+
}

src/main/java/com/aliyun/openservices/log/request/GetHistogramsRequest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class GetHistogramsRequest extends Request {
1717
*/
1818
private static final long serialVersionUID = -1714940205081492986L;
1919

20-
private String mLogStore;
20+
private String logStore;
2121

2222
/**
2323
* Construct a request with full parameters
@@ -38,7 +38,7 @@ public class GetHistogramsRequest extends Request {
3838
public GetHistogramsRequest(String project, String logStore, String topic,
3939
String query, int from, int to) {
4040
super(project);
41-
mLogStore = logStore;
41+
this.logStore = logStore;
4242
SetTopic(topic);
4343
SetQuery(query);
4444
SetFromTime(from);
@@ -105,7 +105,7 @@ public GetHistogramsRequest(String project, String logStore, String topic,
105105
* log store name
106106
*/
107107
public void SetLogStore(String logStore) {
108-
mLogStore = logStore;
108+
this.logStore = logStore;
109109
}
110110

111111
/**
@@ -114,7 +114,7 @@ public void SetLogStore(String logStore) {
114114
* @return log store name
115115
*/
116116
public String GetLogStore() {
117-
return mLogStore;
117+
return logStore;
118118
}
119119

120120
/**

src/main/java/com/aliyun/openservices/log/request/GetLogsRequest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
public class GetLogsRequest extends Request {
1212
private static final long serialVersionUID = -484272901258629068L;
1313

14-
private String mLogStore;
14+
private String logStore;
1515

1616
private int from;
1717
private int to;
@@ -45,7 +45,7 @@ public class GetLogsRequest extends Request {
4545
public GetLogsRequest(String project, String logStore, int from, int to,
4646
String topic, String query) {
4747
super(project);
48-
mLogStore = logStore;
48+
this.logStore = logStore;
4949
SetTopic(topic);
5050
SetQuery(query);
5151
SetFromTime(from);
@@ -185,7 +185,7 @@ public GetLogsRequest(String project, String logStore, int from, int to,
185185
* @param logStore log store name
186186
*/
187187
public void SetLogStore(String logStore) {
188-
mLogStore = logStore;
188+
this.logStore = logStore;
189189
}
190190

191191
/**
@@ -194,7 +194,7 @@ public void SetLogStore(String logStore) {
194194
* @return log store name
195195
*/
196196
public String GetLogStore() {
197-
return mLogStore;
197+
return logStore;
198198
}
199199

200200
/**
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.aliyun.openservices.log.request;
2+
3+
import com.aliyun.openservices.log.common.Consts;
4+
5+
public class ListMaterializedViewsRequest extends Request{
6+
7+
public ListMaterializedViewsRequest(String project, String storePattern, int offset, int size) {
8+
super(project);
9+
setPattern(storePattern);
10+
setOffset(offset);
11+
setSize(size);
12+
}
13+
14+
public void setOffset(int offset) {
15+
SetParam(Consts.CONST_OFFSET, String.valueOf(offset));
16+
}
17+
18+
public void setSize(int size) {
19+
SetParam(Consts.CONST_SIZE,String.valueOf(size));
20+
}
21+
22+
public void setPattern(String pattern) {
23+
SetParam(Consts.CONST_EXTERNAL_NAME, pattern);
24+
}
25+
}

0 commit comments

Comments
 (0)