This is an automated email from the ASF dual-hosted git repository.
healchow pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-inlong.git
The following commit(s) were added to refs/heads/master by this push:
new 0b416e429 [INLONG-4439][Manager] Removed the Gson adapter and replaced
it with Jackson annotations (#4499)
0b416e429 is described below
commit 0b416e4297b0255d478046fa8cfb83a61b107f2d
Author: haifxu <[email protected]>
AuthorDate: Sat Jun 4 16:47:34 2022 +0800
[INLONG-4439][Manager] Removed the Gson adapter and replaced it with
Jackson annotations (#4499)
* [INLONG-4439][Manager] Remove Gson adapter
* [INLONG-4439][Manager] Use global instance of ObjectMapper
* Add Java docs for PrintUtils
Co-authored-by: healchow <[email protected]>
---
.../manager/client/cli/AbstractCommandRunner.java | 9 ++
.../inlong/manager/client/cli/CreateCommand.java | 4 +-
.../inlong/manager/client/cli/DescribeCommand.java | 16 +--
.../inlong/manager/client/cli/ListCommand.java | 12 +--
.../inlong/manager/client/cli/pojo/GroupInfo.java | 5 +-
.../inlong/manager/client/cli/pojo/SinkInfo.java | 5 +-
.../inlong/manager/client/cli/pojo/SourceInfo.java | 5 +-
.../inlong/manager/client/cli/pojo/StreamInfo.java | 5 +-
.../manager/client/cli/util/DataFormatAdapter.java | 42 --------
.../inlong/manager/client/cli/util/GsonUtils.java | 49 ---------
.../client/cli/util/InlongGroupInfoAdapter.java | 62 ------------
.../util/{CharsetAdapter.java => ParseStatus.java} | 23 ++---
.../inlong/manager/client/cli/util/PrintUtils.java | 110 +++++++++++++++------
.../manager/client/cli/util/SeparatorAdapter.java | 38 -------
.../client/cli/util/SortBaseConfAdapter.java | 56 -----------
.../manager/client/cli/util/StatusAdapter.java | 39 --------
.../manager/client/cli/util/StreamSinkAdapter.java | 61 ------------
.../client/cli/util/StreamSourceAdapter.java | 61 ------------
18 files changed, 124 insertions(+), 478 deletions(-)
diff --git
a/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/AbstractCommandRunner.java
b/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/AbstractCommandRunner.java
index aff34302d..a479460b2 100644
---
a/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/AbstractCommandRunner.java
+++
b/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/AbstractCommandRunner.java
@@ -17,12 +17,21 @@
package org.apache.inlong.manager.client.cli;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.inlong.manager.common.util.JsonUtils;
+
/**
* The runner of command.
* of command for creat connect by config file.
*/
public abstract class AbstractCommandRunner {
+ protected final ObjectMapper objectMapper = new ObjectMapper();
+
+ AbstractCommandRunner() {
+ JsonUtils.initJsonTypeDefine(objectMapper);
+ }
+
/**
* Execute the specified command.
*/
diff --git
a/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/CreateCommand.java
b/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/CreateCommand.java
index f32b93cfa..0967c66d0 100644
---
a/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/CreateCommand.java
+++
b/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/CreateCommand.java
@@ -26,7 +26,6 @@ import org.apache.inlong.manager.client.api.InlongGroup;
import org.apache.inlong.manager.client.api.InlongStreamBuilder;
import org.apache.inlong.manager.client.cli.pojo.CreateGroupConf;
import org.apache.inlong.manager.client.cli.util.ClientUtils;
-import org.apache.inlong.manager.client.cli.util.GsonUtils;
import java.io.File;
@@ -64,8 +63,7 @@ public class CreateCommand extends AbstractCommand {
System.out.println("Create group failed: file was empty!");
return;
}
-
- CreateGroupConf groupConf =
GsonUtils.GSON.fromJson(fileContent, CreateGroupConf.class);
+ CreateGroupConf groupConf =
objectMapper.readValue(fileContent, CreateGroupConf.class);
InlongClient inlongClient = ClientUtils.getClient();
InlongGroup group =
inlongClient.forGroup(groupConf.getGroupInfo());
InlongStreamBuilder streamBuilder =
group.createStream(groupConf.getStreamInfo());
diff --git
a/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/DescribeCommand.java
b/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/DescribeCommand.java
index 9c38564cb..c81a4f695 100644
---
a/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/DescribeCommand.java
+++
b/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/DescribeCommand.java
@@ -22,9 +22,11 @@ import com.beust.jcommander.Parameters;
import com.github.pagehelper.PageInfo;
import org.apache.inlong.manager.client.api.impl.InlongClientImpl;
import org.apache.inlong.manager.client.api.inner.InnerInlongManagerClient;
+import org.apache.inlong.manager.client.cli.pojo.GroupInfo;
import org.apache.inlong.manager.client.cli.util.ClientUtils;
import org.apache.inlong.manager.client.cli.util.PrintUtils;
import org.apache.inlong.manager.common.pojo.group.InlongGroupListResponse;
+import org.apache.inlong.manager.common.pojo.group.InlongGroupPageRequest;
import org.apache.inlong.manager.common.pojo.sink.SinkListResponse;
import org.apache.inlong.manager.common.pojo.source.SourceListResponse;
import org.apache.inlong.manager.common.pojo.stream.FullStreamResponse;
@@ -35,7 +37,7 @@ import java.util.List;
/**
* Describe the info of resources.
*/
-@Parameters(commandDescription = "Display details of one or more resources")
+@Parameters(commandDescription = "Display details of one resource")
public class DescribeCommand extends AbstractCommand {
@Parameter()
@@ -93,14 +95,14 @@ public class DescribeCommand extends AbstractCommand {
@Parameter()
private java.util.List<String> params;
- @Parameter(names = {"-s", "--status"})
+ @Parameter(names = {"-s", "--status"}, description = "inlong group
status")
private int status;
- @Parameter(names = {"-g", "--group"}, description = "inlong group id")
+ @Parameter(names = {"-g", "--group"}, required = true, description =
"inlong group id")
private String group;
@Parameter(names = {"-n", "--num"}, description = "the number
displayed")
- private int pageSize = 10;
+ private int pageSize;
DescribeGroup(InnerInlongManagerClient managerClient) {
this.managerClient = managerClient;
@@ -109,8 +111,10 @@ public class DescribeCommand extends AbstractCommand {
@Override
void run() {
try {
- PageInfo<InlongGroupListResponse> groupPageInfo =
managerClient.listGroups(group, status, 1, pageSize);
- groupPageInfo.getList().forEach(PrintUtils::printJson);
+ InlongGroupPageRequest pageRequest = new
InlongGroupPageRequest();
+ pageRequest.setKeyword(group);
+ PageInfo<InlongGroupListResponse> pageInfo =
managerClient.listGroups(pageRequest);
+ PrintUtils.print(pageInfo.getList(), GroupInfo.class);
} catch (Exception e) {
System.out.println(e.getMessage());
}
diff --git
a/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/ListCommand.java
b/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/ListCommand.java
index 809be596b..2a8a46291 100644
---
a/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/ListCommand.java
+++
b/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/ListCommand.java
@@ -43,7 +43,7 @@ import java.util.stream.Collectors;
/**
* Get main information of resources.
*/
-@Parameters(commandDescription = "Displays main information for one or more
resources")
+@Parameters(commandDescription = "Displays summary information about one or
more resources")
public class ListCommand extends AbstractCommand {
@Parameter()
@@ -68,7 +68,7 @@ public class ListCommand extends AbstractCommand {
jcommander.addCommand("source", new ListSource(managerClient));
}
- @Parameters(commandDescription = "Get stream main information")
+ @Parameters(commandDescription = "Get stream summary information")
private static class ListStream extends AbstractCommandRunner {
private final InnerInlongManagerClient managerClient;
@@ -97,7 +97,7 @@ public class ListCommand extends AbstractCommand {
}
}
- @Parameters(commandDescription = "Get group details")
+ @Parameters(commandDescription = "Get group summary information")
private static class ListGroup extends AbstractCommandRunner {
private static final int DEFAULT_PAGE_SIZE = 10;
@@ -107,7 +107,7 @@ public class ListCommand extends AbstractCommand {
@Parameter()
private List<String> params;
- @Parameter(names = {"-s", "--status"})
+ @Parameter(names = {"-s", "--status"}, description = "inlong group
status")
private String status;
@Parameter(names = {"-g", "--group"}, description = "inlong group id")
@@ -142,7 +142,7 @@ public class ListCommand extends AbstractCommand {
}
}
- @Parameters(commandDescription = "Get sink details")
+ @Parameters(commandDescription = "Get sink summary information")
private static class ListSink extends AbstractCommandRunner {
private final InnerInlongManagerClient managerClient;
@@ -171,7 +171,7 @@ public class ListCommand extends AbstractCommand {
}
}
- @Parameters(commandDescription = "Get source details")
+ @Parameters(commandDescription = "Get source summary information")
private static class ListSource extends AbstractCommandRunner {
private final InnerInlongManagerClient managerClient;
diff --git
a/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/pojo/GroupInfo.java
b/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/pojo/GroupInfo.java
index 4e2bfb341..27f4b4b0f 100644
---
a/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/pojo/GroupInfo.java
+++
b/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/pojo/GroupInfo.java
@@ -17,9 +17,8 @@
package org.apache.inlong.manager.client.cli.pojo;
-import com.google.gson.annotations.JsonAdapter;
import lombok.Data;
-import org.apache.inlong.manager.client.cli.util.StatusAdapter;
+import org.apache.inlong.manager.client.cli.util.ParseStatus;
import java.util.Date;
@@ -33,7 +32,7 @@ public class GroupInfo {
private String inlongGroupId;
private String name;
- @JsonAdapter(StatusAdapter.class)
+ @ParseStatus
private String status;
private Date modifyTime;
diff --git
a/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/pojo/SinkInfo.java
b/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/pojo/SinkInfo.java
index 9f4be8411..2804be3f1 100644
---
a/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/pojo/SinkInfo.java
+++
b/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/pojo/SinkInfo.java
@@ -17,9 +17,8 @@
package org.apache.inlong.manager.client.cli.pojo;
-import com.google.gson.annotations.JsonAdapter;
import lombok.Data;
-import org.apache.inlong.manager.client.cli.util.StatusAdapter;
+import org.apache.inlong.manager.client.cli.util.ParseStatus;
import java.util.Date;
@@ -35,7 +34,7 @@ public class SinkInfo {
private String sinkType;
private String sinkName;
- @JsonAdapter(StatusAdapter.class)
+ @ParseStatus
private String status;
private Date modifyTime;
}
diff --git
a/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/pojo/SourceInfo.java
b/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/pojo/SourceInfo.java
index 155d81802..ebe62ae37 100644
---
a/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/pojo/SourceInfo.java
+++
b/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/pojo/SourceInfo.java
@@ -17,9 +17,8 @@
package org.apache.inlong.manager.client.cli.pojo;
-import com.google.gson.annotations.JsonAdapter;
import lombok.Data;
-import org.apache.inlong.manager.client.cli.util.StatusAdapter;
+import org.apache.inlong.manager.client.cli.util.ParseStatus;
import java.util.Date;
@@ -36,7 +35,7 @@ public class SourceInfo {
private String sourceName;
private String serializationType;
- @JsonAdapter(StatusAdapter.class)
+ @ParseStatus
private String status;
private Date modifyTime;
}
diff --git
a/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/pojo/StreamInfo.java
b/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/pojo/StreamInfo.java
index 5454aed22..df48dcfab 100644
---
a/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/pojo/StreamInfo.java
+++
b/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/pojo/StreamInfo.java
@@ -17,9 +17,8 @@
package org.apache.inlong.manager.client.cli.pojo;
-import com.google.gson.annotations.JsonAdapter;
import lombok.Data;
-import org.apache.inlong.manager.client.cli.util.StatusAdapter;
+import org.apache.inlong.manager.client.cli.util.ParseStatus;
import java.util.Date;
@@ -36,7 +35,7 @@ public class StreamInfo {
private String dataEncoding;
private String dataSeparator;
- @JsonAdapter(StatusAdapter.class)
+ @ParseStatus
private String status;
private Date modifyTime;
}
diff --git
a/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/util/DataFormatAdapter.java
b/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/util/DataFormatAdapter.java
deleted file mode 100644
index 7524ca600..000000000
---
a/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/util/DataFormatAdapter.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.inlong.manager.client.cli.util;
-
-import com.google.gson.JsonDeserializationContext;
-import com.google.gson.JsonDeserializer;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonParseException;
-import org.apache.inlong.manager.common.enums.DataFormat;
-
-import java.lang.reflect.Type;
-
-/**
- * Data format adapter.
- */
-public class DataFormatAdapter implements JsonDeserializer {
-
- @Override
- public DataFormat deserialize(JsonElement jsonElement, Type type,
JsonDeserializationContext context)
- throws JsonParseException {
- return DataFormat.forName(jsonElement.getAsString());
- }
-}
-
-
-
-
diff --git
a/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/util/GsonUtils.java
b/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/util/GsonUtils.java
deleted file mode 100644
index d92c572be..000000000
---
a/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/util/GsonUtils.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.inlong.manager.client.cli.util;
-
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-import org.apache.inlong.manager.common.enums.DataFormat;
-import org.apache.inlong.manager.common.enums.DataSeparator;
-import org.apache.inlong.manager.common.pojo.group.InlongGroupInfo;
-import org.apache.inlong.manager.common.pojo.sink.StreamSink;
-import org.apache.inlong.manager.common.pojo.sort.BaseSortConf;
-import org.apache.inlong.manager.common.pojo.source.StreamSource;
-
-import java.nio.charset.Charset;
-
-/**
- * Util of gson for register each type of adapter, such as charsetAdapter,
streamSourceAdapter, etc.
- */
-public class GsonUtils {
-
- /**
- * Init gson instance with register type adapter.
- */
- public static final Gson GSON = new GsonBuilder()
- .registerTypeAdapter(InlongGroupInfo.class, new
InlongGroupInfoAdapter())
- .registerTypeAdapter(BaseSortConf.class, new SortBaseConfAdapter())
- .registerTypeAdapter(Charset.class, new CharsetAdapter())
- .registerTypeAdapter(DataSeparator.class, new SeparatorAdapter())
- .registerTypeAdapter(DataFormat.class, new DataFormatAdapter())
- .registerTypeAdapter(StreamSource.class, new StreamSourceAdapter())
- .registerTypeAdapter(StreamSink.class, new StreamSinkAdapter())
- .create();
-
-}
diff --git
a/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/util/InlongGroupInfoAdapter.java
b/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/util/InlongGroupInfoAdapter.java
deleted file mode 100644
index ab2dae017..000000000
---
a/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/util/InlongGroupInfoAdapter.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.inlong.manager.client.cli.util;
-
-import com.google.gson.Gson;
-import com.google.gson.JsonDeserializationContext;
-import com.google.gson.JsonDeserializer;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonParseException;
-import org.apache.inlong.manager.common.pojo.group.InlongGroupInfo;
-import org.apache.inlong.manager.common.pojo.group.none.InlongNoneMqInfo;
-import org.apache.inlong.manager.common.pojo.group.pulsar.InlongPulsarInfo;
-import org.apache.inlong.manager.common.pojo.group.pulsar.InlongTdmqPulsarInfo;
-import org.apache.inlong.manager.common.pojo.group.tube.InlongTubeInfo;
-
-import java.lang.reflect.Type;
-
-/**
- * Inlong group info adapter for JSON deserialize.
- */
-public class InlongGroupInfoAdapter implements
JsonDeserializer<InlongGroupInfo> {
-
- @Override
- public InlongGroupInfo deserialize(JsonElement jsonElement, Type type,
JsonDeserializationContext context)
- throws JsonParseException {
- JsonObject jsonObject = jsonElement.getAsJsonObject();
- String mqType = jsonObject.get("mqType").getAsString();
- try {
- switch (mqType) {
- case "PULSAR":
- return new Gson().fromJson(jsonElement, (Type)
Class.forName((InlongPulsarInfo.class).getName()));
- case "TUBE":
- return new Gson().fromJson(jsonElement, (Type)
Class.forName((InlongTubeInfo.class).getName()));
- case "TDMQ_PULSAR":
- return new Gson().fromJson(jsonElement,
- (Type)
Class.forName((InlongTdmqPulsarInfo.class).getName()));
- case "NONE":
- return new Gson().fromJson(jsonElement, (Type)
Class.forName((InlongNoneMqInfo.class).getName()));
- default:
- throw new
IllegalArgumentException(String.format("Unsupported mqType=%s", mqType));
- }
- } catch (Exception e) {
- throw new JsonParseException(e);
- }
- }
-}
diff --git
a/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/util/CharsetAdapter.java
b/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/util/ParseStatus.java
similarity index 61%
rename from
inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/util/CharsetAdapter.java
rename to
inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/util/ParseStatus.java
index 71a2cace4..d553c14a8 100644
---
a/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/util/CharsetAdapter.java
+++
b/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/util/ParseStatus.java
@@ -17,22 +17,17 @@
package org.apache.inlong.manager.client.cli.util;
-import com.google.gson.JsonDeserializationContext;
-import com.google.gson.JsonDeserializer;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonParseException;
-
-import java.lang.reflect.Type;
-import java.nio.charset.Charset;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
/**
- * Charset adapter.
+ * Parse status as STATUS (status).
+ * e.g. FAILED (120)
*/
-public class CharsetAdapter implements JsonDeserializer<Charset> {
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.FIELD)
+public @interface ParseStatus {
- @Override
- public Charset deserialize(JsonElement jsonElement, Type type,
JsonDeserializationContext context)
- throws JsonParseException {
- return Charset.forName(jsonElement.getAsString());
- }
}
diff --git
a/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/util/PrintUtils.java
b/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/util/PrintUtils.java
index 79daf4c02..945abaa43 100644
---
a/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/util/PrintUtils.java
+++
b/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/util/PrintUtils.java
@@ -17,11 +17,11 @@
package org.apache.inlong.manager.client.cli.util;
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonParser;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.lang3.StringUtils;
+import org.apache.inlong.manager.client.api.enums.SimpleGroupStatus;
import java.lang.reflect.Field;
import java.text.SimpleDateFormat;
@@ -38,6 +38,11 @@ public class PrintUtils {
private static final String horizontal = "—";
private static final String vertical = "|";
+ private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
+
+ /**
+ * Print a list info to console with format.
+ */
public static <T, K> void print(List<T> item, Class<K> clazz) {
if (item.isEmpty()) {
return;
@@ -47,39 +52,48 @@ public class PrintUtils {
printTable(list, maxColumnWidth);
}
+ /**
+ * Print the given item to the console in JSON format.
+ */
public static <T> void printJson(T item) {
- Gson gson = new GsonBuilder().setPrettyPrinting().create();
- JsonObject jsonObject =
JsonParser.parseString(gson.toJson(item)).getAsJsonObject();
- System.out.println(gson.toJson(jsonObject));
+ try {
+
System.out.println(OBJECT_MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(item));
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException(e);
+ }
}
+ /**
+ * Prints the given list to the console with the specified width.
+ */
private static <K> void printTable(List<K> list, int[] columnWidth) {
Field[] fields = list.get(0).getClass().getDeclaredFields();
-
- String format = "%s" + vertical;
printLine(columnWidth, fields.length);
System.out.print(vertical);
+
+ String format = "%s" + vertical;
for (int i = 0; i < fields.length; i++) {
System.out.printf(format, StringUtils.center(fields[i].getName(),
columnWidth[i]));
}
System.out.println();
printLine(columnWidth, fields.length);
- list.forEach(k -> {
+
+ list.forEach(item -> {
for (int i = 0; i < fields.length; i++) {
fields[i].setAccessible(true);
try {
System.out.print(vertical);
- if (fields[i].get(k) != null) {
- int charNum =
getSpecialCharNum(fields[i].get(k).toString());
+ Object obj = fields[i].get(item);
+ if (obj != null) {
+ int charNum = getSpecialCharNum(obj.toString());
if (fields[i].getType().equals(Date.class)) {
- SimpleDateFormat sf = new
SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- String dataFormat = sf.format(fields[i].get(k));
- System.out.printf("%s",
StringUtils.center(dataFormat, columnWidth[i]));
+ SimpleDateFormat dateFormat = new
SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ String date = dateFormat.format(obj);
+ System.out.printf("%s", StringUtils.center(date,
columnWidth[i]));
} else if (charNum > 0) {
- System.out.printf("%s",
-
StringUtils.center(fields[i].get(k).toString(), columnWidth[i] - charNum));
+ System.out.printf("%s",
StringUtils.center(obj.toString(), columnWidth[i] - charNum));
} else {
- System.out.printf("%s",
StringUtils.center(fields[i].get(k).toString(), columnWidth[i]));
+ System.out.printf("%s",
StringUtils.center(obj.toString(), columnWidth[i]));
}
} else {
System.out.printf("%s", StringUtils.center("NULL",
columnWidth[i]));
@@ -93,29 +107,40 @@ public class PrintUtils {
printLine(columnWidth, fields.length);
}
- private static <T, K> List<K> copyObject(List<T> item, Class<K> clazz) {
+ /**
+ * Copy the objects in the list, converting them to the specified type.
+ */
+ private static <T, K> List<K> copyObject(List<T> list, Class<K> clazz) {
List<K> newList = new ArrayList<>();
- Gson gson = new Gson();
- item.forEach(t -> {
- K k = gson.fromJson(gson.toJson(t), clazz);
- newList.add(k);
+
OBJECT_MAPPER.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
+ list.forEach(item -> {
+ try {
+ K value =
OBJECT_MAPPER.readValue(OBJECT_MAPPER.writeValueAsString(item), clazz);
+ parseStatus(value);
+ newList.add(value);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
});
return newList;
}
+ /**
+ * Get the max-width for all columns in the given list info.
+ */
private static <K> int[] getColumnWidth(List<K> list) {
Field[] fields = list.get(0).getClass().getDeclaredFields();
int[] maxWidth = new int[fields.length];
for (int i = 0; i < fields.length; i++) {
maxWidth[i] = Math.max(fields[i].getName().length(), maxWidth[i]);
}
- list.forEach(k -> {
+ list.forEach(item -> {
try {
- for (int j = 0; j < fields.length; j++) {
- fields[j].setAccessible(true);
- if (fields[j].get(k) != null) {
- int length =
fields[j].get(k).toString().getBytes().length;
- maxWidth[j] = Math.max(length, maxWidth[j]);
+ for (int i = 0; i < fields.length; i++) {
+ fields[i].setAccessible(true);
+ if (fields[i].get(item) != null) {
+ int length =
fields[i].get(item).toString().getBytes().length;
+ maxWidth[i] = Math.max(length, maxWidth[i]);
}
}
} catch (IllegalAccessException e) {
@@ -128,6 +153,9 @@ public class PrintUtils {
return maxWidth;
}
+ /**
+ * Print the format line to the console.
+ */
private static void printLine(int[] columnWidth, int fieldNum) {
System.out.print(joint);
for (int i = 0; i < fieldNum; i++) {
@@ -136,8 +164,32 @@ public class PrintUtils {
System.out.println();
}
+ /**
+ * Get the char number for special string, such as the Chinese string.
+ */
private static int getSpecialCharNum(String str) {
int i = str.getBytes().length - str.length();
return i / 2;
}
+
+ /**
+ * Parse the {@link ParseStatus} annotation, and transfer the status param
to 'STATUS (status)',
+ * such as 'STARTED (130)'
+ */
+ private static <T> void parseStatus(T target) {
+ Field[] fields = target.getClass().getDeclaredFields();
+ for (Field field : fields) {
+ field.setAccessible(true);
+ if (field.isAnnotationPresent(ParseStatus.class)) {
+ try {
+ int status =
Integer.parseInt(field.get(target).toString());
+ SimpleGroupStatus groupStatus =
SimpleGroupStatus.parseStatusByCode(status);
+ field.set(target, String.format("%s (%d)", groupStatus,
status));
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+ }
+
}
diff --git
a/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/util/SeparatorAdapter.java
b/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/util/SeparatorAdapter.java
deleted file mode 100644
index 12d19f311..000000000
---
a/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/util/SeparatorAdapter.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.inlong.manager.client.cli.util;
-
-import com.google.gson.JsonDeserializationContext;
-import com.google.gson.JsonDeserializer;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonParseException;
-import org.apache.inlong.manager.common.enums.DataSeparator;
-
-import java.lang.reflect.Type;
-
-/**
- * Separator adapter.
- */
-public class SeparatorAdapter implements JsonDeserializer<DataSeparator> {
-
- @Override
- public DataSeparator deserialize(JsonElement jsonElement, Type type,
JsonDeserializationContext context)
- throws JsonParseException {
- return DataSeparator.forAscii(jsonElement.getAsInt());
- }
-}
diff --git
a/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/util/SortBaseConfAdapter.java
b/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/util/SortBaseConfAdapter.java
deleted file mode 100644
index 512788a17..000000000
---
a/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/util/SortBaseConfAdapter.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.inlong.manager.client.cli.util;
-
-import com.google.gson.Gson;
-import com.google.gson.JsonDeserializationContext;
-import com.google.gson.JsonDeserializer;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonParseException;
-import org.apache.inlong.manager.common.pojo.sort.BaseSortConf;
-import org.apache.inlong.manager.common.pojo.sort.FlinkSortConf;
-import org.apache.inlong.manager.common.pojo.sort.UserDefinedSortConf;
-
-import java.lang.reflect.Type;
-
-/**
- * Sort base config adapter for JSON deserialize.
- */
-public class SortBaseConfAdapter implements JsonDeserializer<BaseSortConf> {
-
- @Override
- public BaseSortConf deserialize(JsonElement jsonElement, Type type,
JsonDeserializationContext context)
- throws JsonParseException {
- JsonObject jsonObject = jsonElement.getAsJsonObject();
- String sortType = jsonObject.get("type").getAsString();
- Gson gson = GsonUtils.GSON;
- try {
- switch (sortType) {
- case "FLINK":
- return gson.fromJson(jsonElement, (Type)
Class.forName((FlinkSortConf.class).getName()));
- case "USER_DEFINED":
- return gson.fromJson(jsonElement, (Type)
Class.forName((UserDefinedSortConf.class).getName()));
- default:
- throw new
IllegalArgumentException(String.format("Unsupported sortType=%s", sortType));
- }
- } catch (Exception e) {
- throw new JsonParseException(e);
- }
- }
-}
diff --git
a/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/util/StatusAdapter.java
b/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/util/StatusAdapter.java
deleted file mode 100644
index d8f86b6de..000000000
---
a/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/util/StatusAdapter.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.inlong.manager.client.cli.util;
-
-import com.google.gson.JsonDeserializationContext;
-import com.google.gson.JsonDeserializer;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonParseException;
-import org.apache.inlong.manager.client.api.enums.SimpleGroupStatus;
-
-import java.lang.reflect.Type;
-
-/**
- * Status adapter.
- */
-public class StatusAdapter implements JsonDeserializer {
-
- @Override
- public String deserialize(JsonElement json, Type typeOfT,
JsonDeserializationContext context)
- throws JsonParseException {
- SimpleGroupStatus simpleGroupStatus =
SimpleGroupStatus.parseStatusByCode(json.getAsInt());
- return simpleGroupStatus + " (" + json.getAsInt() + ")";
- }
-}
diff --git
a/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/util/StreamSinkAdapter.java
b/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/util/StreamSinkAdapter.java
deleted file mode 100644
index c05c8e8cf..000000000
---
a/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/util/StreamSinkAdapter.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.inlong.manager.client.cli.util;
-
-import com.google.gson.Gson;
-import com.google.gson.JsonDeserializationContext;
-import com.google.gson.JsonDeserializer;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonParseException;
-import org.apache.inlong.manager.common.pojo.sink.StreamSink;
-
-import java.lang.reflect.Type;
-
-/**
- * Stream sink adapter.
- */
-public class StreamSinkAdapter implements JsonDeserializer<StreamSink> {
-
- /**
- * TODO refactor by {@link
org.apache.inlong.manager.common.util.JsonTypeDefine}
- */
- @Override
- public StreamSink deserialize(JsonElement jsonElement, Type type,
JsonDeserializationContext context)
- throws JsonParseException {
- JsonObject jsonObject = jsonElement.getAsJsonObject();
- String sinkType = jsonObject.get("sinkType").getAsString();
- Gson gson = GsonUtils.GSON;
- try {
- /*switch (sinkType) {
- case SinkType.SINK_HIVE:
- return gson.fromJson(jsonElement, (Type)
Class.forName((HiveSink.class).getName()));
- case SinkType.SINK_KAFKA:
- return gson.fromJson(jsonElement, (Type)
Class.forName((KafkaSink.class).getName()));
- case SinkType.SINK_CLICKHOUSE:
- return gson.fromJson(jsonElement, (Type)
Class.forName((ClickHouseSink.class).getName()));
- default:
- throw new
IllegalArgumentException(String.format("Unsupported sink type=%s for Inlong",
sinkType));
- }*/
- } catch (
- Exception e) {
- e.printStackTrace();
- }
- return null;
- }
-}
diff --git
a/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/util/StreamSourceAdapter.java
b/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/util/StreamSourceAdapter.java
deleted file mode 100644
index 4b1ec4b7b..000000000
---
a/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/util/StreamSourceAdapter.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.inlong.manager.client.cli.util;
-
-import com.google.gson.Gson;
-import com.google.gson.JsonDeserializationContext;
-import com.google.gson.JsonDeserializer;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonParseException;
-import org.apache.inlong.manager.common.pojo.source.StreamSource;
-
-import java.lang.reflect.Type;
-
-/**
- * Stream source adapter.
- */
-public class StreamSourceAdapter implements JsonDeserializer<StreamSource> {
-
- /**
- * TODO refactor by {@link
org.apache.inlong.manager.common.util.JsonTypeDefine}
- */
- @Override
- public StreamSource deserialize(JsonElement jsonElement, Type type,
JsonDeserializationContext context)
- throws JsonParseException {
- JsonObject jsonObject = jsonElement.getAsJsonObject();
- String sourceType = jsonObject.get("sourceType").getAsString();
- Gson gson = GsonUtils.GSON;
- /*try {
- switch (sourceType) {
- case SourceType.SOURCE_KAFKA:
- return gson.fromJson(jsonElement, (Type)
Class.forName((KafkaSource.class).getName()));
- case SourceType.SOURCE_BINLOG:
- return gson.fromJson(jsonElement, (Type)
Class.forName((MySQLBinlogSource.class).getName()));
- case SourceType.SOURCE_FILE:
- return gson.fromJson(jsonElement, (Type)
Class.forName((AgentFileSource.class).getName()));
- default:
- throw new IllegalArgumentException(
- String.format("Unsupported source type=%s for
Inlong", sourceType));
- }
- } catch (Exception e) {
- e.printStackTrace();
- }*/
- return null;
- }
-}
\ No newline at end of file