17
17
18
18
package org .apache .inlong .manager .client .api .util ;
19
19
20
+ import static org .apache .inlong .manager .common .enums .SourceType .BINLOG ;
21
+ import static org .apache .inlong .manager .common .enums .SourceType .KAFKA ;
22
+
20
23
import com .github .pagehelper .PageInfo ;
24
+ import com .google .common .collect .Lists ;
21
25
import com .google .common .reflect .TypeToken ;
22
26
import com .google .gson .JsonArray ;
23
27
import com .google .gson .JsonObject ;
28
+ import java .util .List ;
24
29
import org .apache .commons .lang3 .tuple .Pair ;
25
30
import org .apache .inlong .manager .common .beans .Response ;
26
31
import org .apache .inlong .manager .common .enums .Constant ;
32
+ import org .apache .inlong .manager .common .enums .SinkType ;
27
33
import org .apache .inlong .manager .common .enums .SourceType ;
28
34
import org .apache .inlong .manager .common .pojo .group .InlongGroupApproveRequest ;
29
35
import org .apache .inlong .manager .common .pojo .group .InlongGroupListResponse ;
30
36
import org .apache .inlong .manager .common .pojo .group .InlongGroupPulsarInfo ;
31
37
import org .apache .inlong .manager .common .pojo .group .InlongGroupResponse ;
32
38
import org .apache .inlong .manager .common .pojo .sink .SinkListResponse ;
39
+ import org .apache .inlong .manager .common .pojo .sink .SinkResponse ;
40
+ import org .apache .inlong .manager .common .pojo .sink .ck .ClickHouseSinkResponse ;
41
+ import org .apache .inlong .manager .common .pojo .sink .hive .HiveSinkResponse ;
42
+ import org .apache .inlong .manager .common .pojo .sink .iceberg .IcebergSinkResponse ;
43
+ import org .apache .inlong .manager .common .pojo .sink .kafka .KafkaSinkResponse ;
33
44
import org .apache .inlong .manager .common .pojo .source .SourceListResponse ;
34
45
import org .apache .inlong .manager .common .pojo .source .binlog .BinlogSourceListResponse ;
35
46
import org .apache .inlong .manager .common .pojo .source .kafka .KafkaSourceListResponse ;
39
50
import org .apache .inlong .manager .common .pojo .workflow .EventLogView ;
40
51
import org .apache .inlong .manager .common .pojo .workflow .WorkflowResult ;
41
52
42
- import java .util .List ;
43
-
44
- import static org .apache .inlong .manager .common .enums .SourceType .BINLOG ;
45
- import static org .apache .inlong .manager .common .enums .SourceType .KAFKA ;
46
-
47
53
/**
48
54
* Parser for Inlong entity
49
55
*/
50
56
public class InlongParser {
51
57
58
+ public static final String GROUP_INFO = "groupInfo" ;
59
+ public static final String MQ_EXT_INFO = "mqExtInfo" ;
60
+ public static final String MIDDLEWARE_TYPE = "middlewareType" ;
61
+ public static final String SINK_INFO = "sinkInfo" ;
62
+ public static final String SINK_TYPE = "sinkType" ;
63
+
52
64
public static Response parseResponse (String responseBody ) {
53
65
Response response = GsonUtil .fromJson (responseBody , Response .class );
54
66
return response ;
@@ -62,7 +74,16 @@ public static WorkflowResult parseWorkflowResult(Response response) {
62
74
63
75
public static InlongGroupResponse parseGroupInfo (Response response ) {
64
76
Object data = response .getData ();
65
- return GsonUtil .fromJson (GsonUtil .toJson (data ), InlongGroupResponse .class );
77
+ JsonObject groupJson = GsonUtil .fromJson (GsonUtil .toJson (data ), JsonObject .class );
78
+ InlongGroupResponse inlongGroupResponse = GsonUtil .fromJson (GsonUtil .toJson (data ), InlongGroupResponse .class );
79
+ JsonObject mqExtInfo = groupJson .getAsJsonObject (MQ_EXT_INFO );
80
+ if (mqExtInfo != null && mqExtInfo .get (MIDDLEWARE_TYPE ) != null ) {
81
+ if (Constant .MIDDLEWARE_PULSAR .equals (mqExtInfo .get (MIDDLEWARE_TYPE ).getAsString ())) {
82
+ InlongGroupPulsarInfo pulsarInfo = GsonUtil .fromJson (mqExtInfo .toString (), InlongGroupPulsarInfo .class );
83
+ inlongGroupResponse .setMqExtInfo (pulsarInfo );
84
+ }
85
+ }
86
+ return inlongGroupResponse ;
66
87
}
67
88
68
89
public static PageInfo <InlongGroupListResponse > parseGroupList (Response response ) {
@@ -78,12 +99,51 @@ public static InlongStreamInfo parseStreamInfo(Response response) {
78
99
return GsonUtil .fromJson (GsonUtil .toJson (data ), InlongStreamInfo .class );
79
100
}
80
101
81
- public static PageInfo <FullStreamResponse > parseStreamList (Response response ) {
102
+ public static List <FullStreamResponse > parseStreamList (Response response ) {
82
103
Object data = response .getData ();
83
- String pageInfoJson = GsonUtil .toJson (data );
84
- return GsonUtil .fromJson (pageInfoJson ,
85
- new TypeToken <PageInfo <FullStreamResponse >>() {
86
- }.getType ());
104
+ JsonObject pageInfoJson = GsonUtil .fromJson (GsonUtil .toJson (data ), JsonObject .class );
105
+ JsonArray fullStreamArray = pageInfoJson .getAsJsonArray ("list" );
106
+ List <FullStreamResponse > list = Lists .newArrayList ();
107
+ for (int i = 0 ; i < fullStreamArray .size (); i ++) {
108
+ JsonObject fullStreamJson = (JsonObject ) fullStreamArray .get (i );
109
+ FullStreamResponse fullStreamResponse = GsonUtil .fromJson (fullStreamJson .toString (),
110
+ FullStreamResponse .class );
111
+ list .add (fullStreamResponse );
112
+ //Parse sinkResponse in each stream
113
+ JsonArray sinkJsonArr = fullStreamJson .getAsJsonArray (SINK_INFO );
114
+ List <SinkResponse > sinkResponses = Lists .newArrayList ();
115
+ fullStreamResponse .setSinkInfo (sinkResponses );
116
+ for (int j = 0 ; j < sinkJsonArr .size (); j ++) {
117
+ JsonObject sinkJson = (JsonObject ) sinkJsonArr .get (i );
118
+ String type = sinkJson .get (SINK_TYPE ).getAsString ();
119
+ SinkType sinkType = SinkType .forType (type );
120
+ switch (sinkType ) {
121
+ case HIVE :
122
+ HiveSinkResponse hiveSinkResponse = GsonUtil .fromJson (sinkJson .toString (),
123
+ HiveSinkResponse .class );
124
+ sinkResponses .add (hiveSinkResponse );
125
+ break ;
126
+ case KAFKA :
127
+ KafkaSinkResponse kafkaSinkResponse = GsonUtil .fromJson (sinkJson .toString (),
128
+ KafkaSinkResponse .class );
129
+ sinkResponses .add (kafkaSinkResponse );
130
+ break ;
131
+ case ICEBERG :
132
+ IcebergSinkResponse icebergSinkResponse = GsonUtil .fromJson (sinkJson .toString (),
133
+ IcebergSinkResponse .class );
134
+ sinkResponses .add (icebergSinkResponse );
135
+ break ;
136
+ case CLICKHOUSE :
137
+ ClickHouseSinkResponse clickHouseSinkResponse = GsonUtil .fromJson (sinkJson .toString (),
138
+ ClickHouseSinkResponse .class );
139
+ sinkResponses .add (clickHouseSinkResponse );
140
+ break ;
141
+ default :
142
+ throw new RuntimeException (String .format ("Unsupport sinkType=%s for Inlong" , sinkType ));
143
+ }
144
+ }
145
+ }
146
+ return list ;
87
147
}
88
148
89
149
public static PageInfo <SourceListResponse > parseSourceList (Response response ) {
@@ -107,9 +167,9 @@ public static PageInfo<SourceListResponse> parseSourceList(Response response) {
107
167
}
108
168
throw new IllegalArgumentException (
109
169
String .format ("Unsupported sourceType=%s for Inlong" , sourceType ));
110
-
170
+ } else {
171
+ return new PageInfo <>();
111
172
}
112
- throw new IllegalArgumentException (String .format ("pageInfo is empty for Inlong" ));
113
173
}
114
174
115
175
public static PageInfo <SinkListResponse > parseSinkList (Response response ) {
@@ -121,25 +181,24 @@ public static PageInfo<SinkListResponse> parseSinkList(Response response) {
121
181
}
122
182
123
183
public static Pair <InlongGroupApproveRequest , List <InlongStreamApproveRequest >> parseGroupForm (String formJson ) {
124
- final String groupInfoField = "groupInfo" ;
125
- final String mqExtInfoField = "mqExtInfo" ;
126
184
JsonObject formData = GsonUtil .fromJson (formJson , JsonObject .class );
127
- JsonObject groupJson = formData .getAsJsonObject (groupInfoField );
185
+ JsonObject groupJson = formData .getAsJsonObject (GROUP_INFO );
128
186
InlongGroupApproveRequest groupApproveInfo = GsonUtil .fromJson (groupJson .toString (),
129
187
InlongGroupApproveRequest .class );
130
- JsonObject mqExtInfo = groupJson .getAsJsonObject (mqExtInfoField );
131
- if (mqExtInfo != null && mqExtInfo .get ("middlewareType" ) != null
132
- && Constant .MIDDLEWARE_PULSAR .equals (mqExtInfo .get ("middlewareType" ).getAsString ())) {
133
- InlongGroupPulsarInfo pulsarInfo = GsonUtil .fromJson (mqExtInfo .toString (), InlongGroupPulsarInfo .class );
134
- groupApproveInfo .setAckQuorum (pulsarInfo .getAckQuorum ());
135
- groupApproveInfo .setEnsemble (pulsarInfo .getEnsemble ());
136
- groupApproveInfo .setWriteQuorum (pulsarInfo .getWriteQuorum ());
137
- groupApproveInfo .setRetentionTime (pulsarInfo .getRetentionTime ());
138
- groupApproveInfo .setRetentionTimeUnit (pulsarInfo .getRetentionTimeUnit ());
139
- groupApproveInfo .setTtl (pulsarInfo .getTtl ());
140
- groupApproveInfo .setTtlUnit (pulsarInfo .getTtlUnit ());
141
- groupApproveInfo .setRetentionSize (pulsarInfo .getRetentionSize ());
142
- groupApproveInfo .setRetentionSizeUnit (pulsarInfo .getRetentionSizeUnit ());
188
+ JsonObject mqExtInfo = groupJson .getAsJsonObject (MQ_EXT_INFO );
189
+ if (mqExtInfo != null && mqExtInfo .get (MIDDLEWARE_TYPE ) != null ) {
190
+ if (Constant .MIDDLEWARE_PULSAR .equals (mqExtInfo .get (MIDDLEWARE_TYPE ).getAsString ())) {
191
+ InlongGroupPulsarInfo pulsarInfo = GsonUtil .fromJson (mqExtInfo .toString (), InlongGroupPulsarInfo .class );
192
+ groupApproveInfo .setAckQuorum (pulsarInfo .getAckQuorum ());
193
+ groupApproveInfo .setEnsemble (pulsarInfo .getEnsemble ());
194
+ groupApproveInfo .setWriteQuorum (pulsarInfo .getWriteQuorum ());
195
+ groupApproveInfo .setRetentionTime (pulsarInfo .getRetentionTime ());
196
+ groupApproveInfo .setRetentionTimeUnit (pulsarInfo .getRetentionTimeUnit ());
197
+ groupApproveInfo .setTtl (pulsarInfo .getTtl ());
198
+ groupApproveInfo .setTtlUnit (pulsarInfo .getTtlUnit ());
199
+ groupApproveInfo .setRetentionSize (pulsarInfo .getRetentionSize ());
200
+ groupApproveInfo .setRetentionSizeUnit (pulsarInfo .getRetentionSizeUnit ());
201
+ }
143
202
}
144
203
JsonArray streamJson = formData .getAsJsonArray ("streamInfoList" );
145
204
List <InlongStreamApproveRequest > streamApproveList = GsonUtil .fromJson (streamJson .toString (),
0 commit comments