You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@inlong.apache.org by do...@apache.org on 2022/04/15 06:50:13 UTC
[incubator-inlong] branch master updated: [INLONG-3679][Manager] Optimize managerctl result display (#3726)
This is an automated email from the ASF dual-hosted git repository.
dockerzhang 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 51541941f [INLONG-3679][Manager] Optimize managerctl result display (#3726)
51541941f is described below
commit 51541941fea18e3851c89f6f11a7587f6d2bffce
Author: haifxu <xh...@gmail.com>
AuthorDate: Fri Apr 15 14:50:08 2022 +0800
[INLONG-3679][Manager] Optimize managerctl result display (#3726)
---
inlong-manager/manager-client-tools/pom.xml | 4 -
.../inlong/manager/client/cli/CommandDescribe.java | 8 +-
.../inlong/manager/client/cli/CommandList.java | 15 ++-
.../inlong/manager/client/cli/CommandUtil.java | 128 ++++++++++++++-------
.../inlong/manager/client/cli/pojo/GroupInfo.java | 33 ++++++
.../inlong/manager/client/cli/pojo/SinkInfo.java | 34 ++++++
.../inlong/manager/client/cli/pojo/SourceInfo.java | 35 ++++++
.../inlong/manager/client/cli/pojo/StreamInfo.java | 35 ++++++
8 files changed, 237 insertions(+), 55 deletions(-)
diff --git a/inlong-manager/manager-client-tools/pom.xml b/inlong-manager/manager-client-tools/pom.xml
index 86c0eef52..ca961b8ca 100644
--- a/inlong-manager/manager-client-tools/pom.xml
+++ b/inlong-manager/manager-client-tools/pom.xml
@@ -43,10 +43,6 @@
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
- <dependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-slf4j-impl</artifactId>
- </dependency>
</dependencies>
</project>
\ No newline at end of file
diff --git a/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/CommandDescribe.java b/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/CommandDescribe.java
index fe8d54196..d2698979c 100644
--- a/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/CommandDescribe.java
+++ b/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/CommandDescribe.java
@@ -31,6 +31,9 @@ import java.util.List;
@Parameters(commandDescription = "Display details of one or more resources")
public class CommandDescribe extends CommandBase {
+ @Parameter()
+ private java.util.List<String> params;
+
public CommandDescribe() {
super("describe");
jcommander.addCommand("stream", new DescribeStream());
@@ -39,9 +42,6 @@ public class CommandDescribe extends CommandBase {
jcommander.addCommand("source", new DescribeSource());
}
- @Parameter()
- private java.util.List<String> params;
-
@Parameters(commandDescription = "Get stream details")
private class DescribeStream extends CommandUtil {
@@ -126,7 +126,7 @@ public class CommandDescribe extends CommandBase {
@Parameter(names = {"-g", "--group"}, required = true, description = "inlong group id")
private String group;
- @Parameter(names = {"-t", "--type"}, required = true, description = "sink type")
+ @Parameter(names = {"-t", "--type"}, description = "sink type")
private String type;
@Override
diff --git a/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/CommandList.java b/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/CommandList.java
index ea4b690f8..45e08fbe4 100644
--- a/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/CommandList.java
+++ b/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/CommandList.java
@@ -21,12 +21,17 @@ import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import com.github.pagehelper.PageInfo;
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.pojo.SinkInfo;
+import org.apache.inlong.manager.client.cli.pojo.SourceInfo;
+import org.apache.inlong.manager.client.cli.pojo.StreamInfo;
import org.apache.inlong.manager.common.pojo.group.InlongGroupListResponse;
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;
import org.apache.inlong.manager.common.pojo.stream.InlongStreamInfo;
+import java.util.ArrayList;
import java.util.List;
@Parameters(commandDescription = "Displays main information for one or more resources")
@@ -57,9 +62,11 @@ public class CommandList extends CommandBase {
InnerInlongManagerClient managerClient = new InnerInlongManagerClient(connect().getConfiguration());
try {
List<FullStreamResponse> fullStreamResponseList = managerClient.listStreamInfo(groupId);
+ List<InlongStreamInfo> inlongStreamInfoList = new ArrayList<>();
fullStreamResponseList.forEach(fullStreamResponse -> {
- print(fullStreamResponse.getStreamInfo(), InlongStreamInfo.class);
+ inlongStreamInfoList.add(fullStreamResponse.getStreamInfo());
});
+ print(inlongStreamInfoList, StreamInfo.class);
} catch (Exception e) {
System.out.println(e.getMessage());
}
@@ -86,7 +93,7 @@ public class CommandList extends CommandBase {
InnerInlongManagerClient managerClient = new InnerInlongManagerClient(connect().getConfiguration());
try {
PageInfo<InlongGroupListResponse> groupPageInfo = managerClient.listGroups(group, status, 1, pageSize);
- print(groupPageInfo.getList(), InlongGroupListResponse.class);
+ print(groupPageInfo.getList(), GroupInfo.class);
} catch (Exception e) {
System.out.println(e.getMessage());
}
@@ -110,7 +117,7 @@ public class CommandList extends CommandBase {
InnerInlongManagerClient managerClient = new InnerInlongManagerClient(connect().getConfiguration());
try {
List<SinkListResponse> sinkListResponses = managerClient.listSinks(group, stream);
- print(sinkListResponses, SinkListResponse.class);
+ print(sinkListResponses, SinkInfo.class);
} catch (Exception e) {
System.out.println(e.getMessage());
}
@@ -137,7 +144,7 @@ public class CommandList extends CommandBase {
InnerInlongManagerClient managerClient = new InnerInlongManagerClient(connect().getConfiguration());
try {
List<SourceListResponse> sourceListResponses = managerClient.listSources(group, stream, type);
- print(sourceListResponses, SourceListResponse.class);
+ print(sourceListResponses, SourceInfo.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/CommandUtil.java b/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/CommandUtil.java
index d24023281..e39edc801 100644
--- a/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/CommandUtil.java
+++ b/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/CommandUtil.java
@@ -21,10 +21,12 @@ import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
+import org.apache.commons.lang3.StringUtils;
import org.apache.inlong.manager.client.api.ClientConfiguration;
import org.apache.inlong.manager.client.api.auth.DefaultAuthentication;
import org.apache.inlong.manager.client.api.impl.InlongClientImpl;
import org.apache.inlong.manager.client.cli.util.GsonUtil;
+import org.springframework.beans.BeanUtils;
import java.io.BufferedInputStream;
import java.io.File;
@@ -35,6 +37,9 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.lang.reflect.Field;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
import java.util.List;
import java.util.Properties;
@@ -60,50 +65,13 @@ abstract class CommandUtil {
return new InlongClientImpl(serviceUrl, configuration);
}
- <T> void print(List<T> item, Class<T> clazz) {
- Field[] fields = clazz.getDeclaredFields();
- for (Field f : fields) {
- System.out.printf("%-30s", f.getName());
- }
- System.out.println();
- if (!item.isEmpty()) {
- item.forEach(t -> {
- try {
- for (Field f : fields) {
- f.setAccessible(true);
- if (f.get(t) != null) {
- System.out.printf("%-30s", f.get(t).toString());
- } else {
- System.out.printf("%-30s", "NULL");
- }
- }
- System.out.println();
- } catch (IllegalAccessException e) {
- System.out.println(e.getMessage());
- }
- });
- }
- }
-
- <T> void print(T item, Class<T> clazz) {
- Field[] fields = clazz.getDeclaredFields();
- for (Field f : fields) {
- System.out.printf("%-30s", f.getName());
- }
- System.out.println();
- try {
- for (Field f : fields) {
- f.setAccessible(true);
- if (f.get(item) != null) {
- System.out.printf("%-30s", f.get(item).toString());
- } else {
- System.out.printf("%-30s", "NULL");
- }
- }
- System.out.println();
- } catch (IllegalAccessException e) {
- System.out.println(e.getMessage());
+ <T, K> void print(List<T> item, Class<K> clazz) {
+ if (item.isEmpty()) {
+ return;
}
+ List<K> list = copyObject(item, clazz);
+ int[] maxColumnWidth = getColumnWidth(list);
+ printTable(list, maxColumnWidth);
}
<T> void printJson(T item) {
@@ -142,4 +110,78 @@ abstract class CommandUtil {
}
abstract void run() throws Exception;
+
+ private <K> void printTable(List<K> list, int[] columnWidth) {
+ Field[] fields = list.get(0).getClass().getDeclaredFields();
+ System.out.print("|");
+ for (int i = 0; i < fields.length; i++) {
+ System.out.printf("%s|", StringUtils.center(fields[i].getName(), columnWidth[i]));
+ }
+ System.out.println();
+ for (int i = 0; i < fields.length; i++) {
+ System.out.printf("%s", StringUtils.leftPad("—", columnWidth[i] + 1, "—"));
+ }
+ System.out.println();
+ list.forEach(k -> {
+ for (int j = 0; j < fields.length; j++) {
+ fields[j].setAccessible(true);
+ try {
+ System.out.print("|");
+ if (fields[j].get(k) != null) {
+ if (fields[j].getType().equals(Date.class)) {
+ SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ String dataFormat = sf.format(fields[j].get(k));
+ System.out.printf("%s", StringUtils.center(dataFormat, columnWidth[j]));
+ } else {
+ System.out.printf("%s", StringUtils.center(fields[j].get(k).toString(), columnWidth[j]));
+ }
+ } else {
+ System.out.printf("%s", StringUtils.center("NULL", columnWidth[j]));
+ }
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ }
+ }
+ System.out.println("|");
+ });
+ }
+
+ private <T, K> List<K> copyObject(List<T> item, Class<K> clazz) {
+ List<K> newList = new ArrayList<>();
+ item.forEach(t -> {
+ try {
+ K k = clazz.newInstance();
+ BeanUtils.copyProperties(t, k);
+ newList.add(k);
+ } catch (InstantiationException | IllegalAccessException e) {
+ e.printStackTrace();
+ }
+ });
+ return newList;
+ }
+
+ private <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 -> {
+ 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().length();
+ maxWidth[j] = Math.max(length, maxWidth[j]);
+ }
+ }
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ }
+ });
+ for (int i = 0; i < maxWidth.length; i++) {
+ maxWidth[i] += 4;
+ }
+ return maxWidth;
+ }
}
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
new file mode 100644
index 000000000..073c4ff14
--- /dev/null
+++ b/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/pojo/GroupInfo.java
@@ -0,0 +1,33 @@
+/*
+ * 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.pojo;
+
+import lombok.Data;
+
+import java.util.Date;
+
+@Data
+public class GroupInfo {
+
+ private Integer id;
+ private String inlongGroupId;
+ private String name;
+ private String cnName;
+ private Integer 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
new file mode 100644
index 000000000..609a550b6
--- /dev/null
+++ b/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/pojo/SinkInfo.java
@@ -0,0 +1,34 @@
+/*
+ * 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.pojo;
+
+import lombok.Data;
+
+import java.util.Date;
+
+@Data
+public class SinkInfo {
+
+ private Integer id;
+ private Integer status;
+ private String inlongGroupId;
+ private String inlongStreamId;
+ private String sinkType;
+ private String sinkName;
+ 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
new file mode 100644
index 000000000..3d89e7f94
--- /dev/null
+++ b/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/pojo/SourceInfo.java
@@ -0,0 +1,35 @@
+/*
+ * 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.pojo;
+
+import lombok.Data;
+
+import java.util.Date;
+
+@Data
+public class SourceInfo {
+
+ private Integer id;
+ private String inlongGroupId;
+ private String inlongStreamId;
+ private String sourceType;
+ private String sourceName;
+ private String serializationType;
+ private Integer 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
new file mode 100644
index 000000000..e94db2fe4
--- /dev/null
+++ b/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/pojo/StreamInfo.java
@@ -0,0 +1,35 @@
+/*
+ * 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.pojo;
+
+import lombok.Data;
+
+import java.util.Date;
+
+@Data
+public class StreamInfo {
+
+ private Integer id;
+ private String name;
+ private String mqResourceObj;
+ private String dataType;
+ private String dataEncoding;
+ private String dataSeparator;
+ private Integer status;
+ private Date modifyTime;
+}