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/09/21 10:54:51 UTC
[inlong] branch master updated: [INLONG-5102][Manager] Command tools add CRUD for inlong cluster (#5958)
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/inlong.git
The following commit(s) were added to refs/heads/master by this push:
new 767a0edea [INLONG-5102][Manager] Command tools add CRUD for inlong cluster (#5958)
767a0edea is described below
commit 767a0edea9e4c0d76517717456fed47da31351cc
Author: haifxu <xh...@gmail.com>
AuthorDate: Wed Sep 21 18:54:46 2022 +0800
[INLONG-5102][Manager] Command tools add CRUD for inlong cluster (#5958)
---
.../inlong/manager/client/cli/CreateCommand.java | 34 ++++++++++++++++++--
.../inlong/manager/client/cli/DeleteCommand.java | 29 +++++++++++++++--
.../inlong/manager/client/cli/DescribeCommand.java | 36 ++++++++++++++++++---
.../inlong/manager/client/cli/ListCommand.java | 33 +++++++++++++++++++
.../inlong/manager/client/cli/UpdateCommand.java | 37 ++++++++++++++++++++--
.../manager/client/cli/pojo/ClusterInfo.java} | 20 +++++++-----
.../cli/validator/ClusterTypeValidator.java} | 23 +++++++++-----
.../api/inner/client/InlongClusterClient.java | 2 ++
.../inlong/manager/common/enums/ClusterType.java | 29 +++++++++++++++++
9 files changed, 216 insertions(+), 27 deletions(-)
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 24b46f34a..b0579e5d4 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
@@ -24,10 +24,13 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.inlong.manager.client.api.InlongClient;
import org.apache.inlong.manager.client.api.InlongGroup;
import org.apache.inlong.manager.client.api.InlongStreamBuilder;
+import org.apache.inlong.manager.client.api.inner.client.InlongClusterClient;
import org.apache.inlong.manager.client.cli.pojo.CreateGroupConf;
import org.apache.inlong.manager.client.cli.util.ClientUtils;
+import org.apache.inlong.manager.pojo.cluster.ClusterRequest;
import java.io.File;
+import java.util.List;
/**
* Create resource by json file.
@@ -36,18 +39,19 @@ import java.io.File;
public class CreateCommand extends AbstractCommand {
@Parameter()
- private java.util.List<String> params;
+ private List<String> params;
public CreateCommand() {
super("create");
jcommander.addCommand("group", new CreateGroup());
+ jcommander.addCommand("cluster", new CreateCluster());
}
@Parameters(commandDescription = "Create group by json file")
private static class CreateGroup extends AbstractCommandRunner {
@Parameter()
- private java.util.List<String> params;
+ private List<String> params;
@Parameter(names = {"-f", "--file"},
converter = FileConverter.class,
@@ -90,4 +94,30 @@ public class CreateCommand extends AbstractCommand {
}
}
}
+
+ @Parameters(commandDescription = "Create cluster by json file")
+ private static class CreateCluster extends AbstractCommandRunner {
+
+ @Parameter()
+ private List<String> params;
+
+ @Parameter(names = {"-f", "--file"}, description = "json file", converter = FileConverter.class)
+ private File file;
+
+ @Override
+ void run() throws Exception {
+ String content = ClientUtils.readFile(file);
+ if (StringUtils.isBlank(content)) {
+ System.out.println("Create cluster failed: file was empty!");
+ return;
+ }
+ ClusterRequest request = objectMapper.readValue(content, ClusterRequest.class);
+ ClientUtils.initClientFactory();
+ InlongClusterClient clusterClient = ClientUtils.clientFactory.getClusterClient();
+ Integer clusterId = clusterClient.saveCluster(request);
+ if (clusterId != null) {
+ System.out.println("Create cluster success! ID:" + clusterId);
+ }
+ }
+ }
}
diff --git a/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/DeleteCommand.java b/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/DeleteCommand.java
index e7746deb2..e5392346b 100644
--- a/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/DeleteCommand.java
+++ b/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/DeleteCommand.java
@@ -21,6 +21,7 @@ import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import org.apache.inlong.manager.client.api.InlongClient;
import org.apache.inlong.manager.client.api.InlongGroup;
+import org.apache.inlong.manager.client.api.inner.client.InlongClusterClient;
import org.apache.inlong.manager.client.cli.util.ClientUtils;
import java.util.List;
@@ -37,7 +38,8 @@ public class DeleteCommand extends AbstractCommand {
public DeleteCommand() {
super("delete");
- jcommander.addCommand("group", new DeleteCommand.DeleteGroup());
+ jcommander.addCommand("group", new DeleteGroup());
+ jcommander.addCommand("cluster", new DeleteCluster());
}
@Parameters(commandDescription = "Delete group by group id")
@@ -57,10 +59,33 @@ public class DeleteCommand extends AbstractCommand {
InlongClient inlongClient = ClientUtils.getClient();
InlongGroup group = inlongClient.getGroup(inlongGroupId);
group.delete();
- System.out.println("delete group success");
+ System.out.println("Delete group success!");
} catch (Exception e) {
System.out.format("Delete group failed! message: %s \n", e.getMessage());
}
}
}
+
+ @Parameters(commandDescription = "Delete cluster by cluster id")
+ private static class DeleteCluster extends AbstractCommandRunner {
+
+ @Parameter()
+ private List<String> params;
+
+ @Parameter(names = {"-id", "--id"}, required = true, description = "cluster id")
+ private int clusterId;
+
+ @Override
+ void run() {
+ try {
+ ClientUtils.initClientFactory();
+ InlongClusterClient clusterClient = ClientUtils.clientFactory.getClusterClient();
+ if (clusterClient.delete(clusterId)) {
+ System.out.println("Delete cluster success!");
+ }
+ } 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/DescribeCommand.java b/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/DescribeCommand.java
index 4a5d33df7..9aa166fdd 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
@@ -19,6 +19,7 @@ package org.apache.inlong.manager.client.cli;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
+import org.apache.inlong.manager.client.api.inner.client.InlongClusterClient;
import org.apache.inlong.manager.client.api.inner.client.InlongGroupClient;
import org.apache.inlong.manager.client.api.inner.client.InlongStreamClient;
import org.apache.inlong.manager.client.api.inner.client.StreamSinkClient;
@@ -26,6 +27,7 @@ import org.apache.inlong.manager.client.api.inner.client.StreamSourceClient;
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.pojo.cluster.ClusterInfo;
import org.apache.inlong.manager.pojo.common.PageResult;
import org.apache.inlong.manager.pojo.group.InlongGroupBriefInfo;
import org.apache.inlong.manager.pojo.group.InlongGroupPageRequest;
@@ -42,7 +44,7 @@ import java.util.List;
public class DescribeCommand extends AbstractCommand {
@Parameter()
- private java.util.List<String> params;
+ private List<String> params;
public DescribeCommand() {
super("describe");
@@ -51,13 +53,14 @@ public class DescribeCommand extends AbstractCommand {
jcommander.addCommand("group", new DescribeGroup());
jcommander.addCommand("sink", new DescribeSink());
jcommander.addCommand("source", new DescribeSource());
+ jcommander.addCommand("cluster", new DescribeCluster());
}
@Parameters(commandDescription = "Get stream details")
private static class DescribeStream extends AbstractCommandRunner {
@Parameter()
- private java.util.List<String> params;
+ private List<String> params;
@Parameter(names = {"-g", "--group"}, required = true, description = "inlong group id")
private String groupId;
@@ -79,7 +82,7 @@ public class DescribeCommand extends AbstractCommand {
private static class DescribeGroup extends AbstractCommandRunner {
@Parameter()
- private java.util.List<String> params;
+ private List<String> params;
@Parameter(names = {"-s", "--status"}, description = "inlong group status")
private int status;
@@ -99,6 +102,7 @@ public class DescribeCommand extends AbstractCommand {
pageRequest.setKeyword(group);
PageResult<InlongGroupBriefInfo> pageInfo = groupClient.listGroups(pageRequest);
PrintUtils.print(pageInfo.getList(), GroupInfo.class);
+ pageInfo.getList().forEach(PrintUtils::printJson);
} catch (Exception e) {
System.out.println(e.getMessage());
}
@@ -109,7 +113,7 @@ public class DescribeCommand extends AbstractCommand {
private static class DescribeSink extends AbstractCommandRunner {
@Parameter()
- private java.util.List<String> params;
+ private List<String> params;
@Parameter(names = {"-s", "--stream"}, required = true, description = "inlong stream id")
private String stream;
@@ -134,7 +138,7 @@ public class DescribeCommand extends AbstractCommand {
private static class DescribeSource extends AbstractCommandRunner {
@Parameter()
- private java.util.List<String> params;
+ private List<String> params;
@Parameter(names = {"-s", "--stream"}, required = true, description = "inlong stream id")
private String stream;
@@ -157,4 +161,26 @@ public class DescribeCommand extends AbstractCommand {
}
}
}
+
+ @Parameters(commandDescription = "Get cluster details")
+ private static class DescribeCluster extends AbstractCommandRunner {
+
+ @Parameter()
+ private List<String> params;
+
+ @Parameter(names = {"-id", "--id"}, required = true, description = "cluster id")
+ private int clusterId;
+
+ @Override
+ void run() {
+ try {
+ ClientUtils.initClientFactory();
+ InlongClusterClient clusterClient = ClientUtils.clientFactory.getClusterClient();
+ ClusterInfo clusterInfo = clusterClient.get(clusterId);
+ PrintUtils.printJson(clusterInfo);
+ } 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 5db28cb72..3c5a658b6 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
@@ -19,6 +19,7 @@ package org.apache.inlong.manager.client.cli;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
+import org.apache.inlong.manager.client.api.inner.client.InlongClusterClient;
import org.apache.inlong.manager.client.api.inner.client.InlongGroupClient;
import org.apache.inlong.manager.client.api.inner.client.InlongStreamClient;
import org.apache.inlong.manager.client.api.inner.client.StreamSinkClient;
@@ -29,7 +30,10 @@ import org.apache.inlong.manager.client.cli.pojo.SourceInfo;
import org.apache.inlong.manager.client.cli.pojo.StreamInfo;
import org.apache.inlong.manager.client.cli.util.ClientUtils;
import org.apache.inlong.manager.client.cli.util.PrintUtils;
+import org.apache.inlong.manager.client.cli.validator.ClusterTypeValidator;
import org.apache.inlong.manager.common.enums.SimpleGroupStatus;
+import org.apache.inlong.manager.pojo.cluster.ClusterInfo;
+import org.apache.inlong.manager.pojo.cluster.ClusterPageRequest;
import org.apache.inlong.manager.pojo.common.PageResult;
import org.apache.inlong.manager.pojo.group.InlongGroupBriefInfo;
import org.apache.inlong.manager.pojo.group.InlongGroupPageRequest;
@@ -55,6 +59,7 @@ public class ListCommand extends AbstractCommand {
jcommander.addCommand("group", new ListGroup());
jcommander.addCommand("sink", new ListSink());
jcommander.addCommand("source", new ListSource());
+ jcommander.addCommand("cluster", new ListCluster());
}
@Parameters(commandDescription = "Get stream summary information")
@@ -173,4 +178,32 @@ public class ListCommand extends AbstractCommand {
}
}
}
+
+ @Parameters(commandDescription = "Get cluster summary information")
+ private static class ListCluster extends AbstractCommandRunner {
+
+ @Parameter()
+ private List<String> params;
+
+ @Parameter(names = {"--type"}, description = "cluster type", validateWith = ClusterTypeValidator.class)
+ private String type;
+
+ @Parameter(names = {"--tag"}, description = "cluster tag")
+ private String tag;
+
+ @Override
+ void run() {
+ try {
+ ClientUtils.initClientFactory();
+ ClusterPageRequest request = new ClusterPageRequest();
+ request.setType(type);
+ request.setClusterTag(tag);
+ InlongClusterClient clusterClient = ClientUtils.clientFactory.getClusterClient();
+ PageResult<ClusterInfo> clusterInfo = clusterClient.list(request);
+ PrintUtils.print(clusterInfo.getList(), org.apache.inlong.manager.client.cli.pojo.ClusterInfo.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/UpdateCommand.java b/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/UpdateCommand.java
index 6e7ad8ec5..e6a7c2b33 100644
--- a/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/UpdateCommand.java
+++ b/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/UpdateCommand.java
@@ -19,10 +19,13 @@ package org.apache.inlong.manager.client.cli;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
+import com.beust.jcommander.converters.FileConverter;
import org.apache.commons.lang3.StringUtils;
import org.apache.inlong.manager.client.api.InlongClient;
import org.apache.inlong.manager.client.api.InlongGroup;
+import org.apache.inlong.manager.client.api.inner.client.InlongClusterClient;
import org.apache.inlong.manager.client.cli.util.ClientUtils;
+import org.apache.inlong.manager.pojo.cluster.ClusterRequest;
import org.apache.inlong.manager.pojo.sort.BaseSortConf;
import java.io.File;
@@ -41,6 +44,7 @@ public class UpdateCommand extends AbstractCommand {
public UpdateCommand() {
super("update");
jcommander.addCommand("group", new UpdateCommand.UpdateGroup());
+ jcommander.addCommand("cluster", new UpdateCommand.UpdateCluster());
}
@Parameters(commandDescription = "Update group by json file")
@@ -66,10 +70,39 @@ public class UpdateCommand extends AbstractCommand {
System.out.println("Update group failed: file was empty!");
return;
}
- // first extract groupconfig from the file passed in
+ // first extract group config from the file passed in
BaseSortConf sortConf = objectMapper.readValue(fileContent, BaseSortConf.class);
group.update(sortConf);
- System.out.println("update group success");
+ System.out.println("Update group success!");
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ @Parameters(commandDescription = "Update cluster by json file")
+ private static class UpdateCluster extends AbstractCommandRunner {
+
+ @Parameter()
+ private List<String> params;
+
+ @Parameter(names = {"-f", "--file"}, description = "json file", converter = FileConverter.class)
+ private File file;
+
+ @Override
+ void run() {
+ try {
+ String content = ClientUtils.readFile(file);
+ if (StringUtils.isBlank(content)) {
+ System.out.println("Update cluster failed: file was empty!");
+ return;
+ }
+ ClusterRequest request = objectMapper.readValue(content, ClusterRequest.class);
+ ClientUtils.initClientFactory();
+ InlongClusterClient clusterClient = ClientUtils.clientFactory.getClusterClient();
+ if (clusterClient.update(request)) {
+ System.out.println("Update cluster success!");
+ }
} catch (Exception e) {
e.printStackTrace();
}
diff --git a/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/enums/ClusterType.java b/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/pojo/ClusterInfo.java
similarity index 69%
copy from inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/enums/ClusterType.java
copy to inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/pojo/ClusterInfo.java
index 8b433888e..7d97fec85 100644
--- a/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/enums/ClusterType.java
+++ b/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/pojo/ClusterInfo.java
@@ -15,16 +15,20 @@
* limitations under the License.
*/
-package org.apache.inlong.manager.common.enums;
+package org.apache.inlong.manager.client.cli.pojo;
+
+import lombok.Data;
/**
- * Constant of cluster type.
+ * Cluster info, including cluster name, cluster type, etc.
*/
-public class ClusterType {
+@Data
+public class ClusterInfo {
- public static final String AGENT = "AGENT";
- public static final String TUBEMQ = "TUBEMQ";
- public static final String PULSAR = "PULSAR";
- public static final String DATAPROXY = "DATAPROXY";
- public static final String KAFKA = "KAFKA";
+ private int id;
+ private String name;
+ private String type;
+ private String url;
+ private String clusterTags;
+ private Integer status;
}
diff --git a/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/enums/ClusterType.java b/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/validator/ClusterTypeValidator.java
similarity index 58%
copy from inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/enums/ClusterType.java
copy to inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/validator/ClusterTypeValidator.java
index 8b433888e..f9a3bc0e2 100644
--- a/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/enums/ClusterType.java
+++ b/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/validator/ClusterTypeValidator.java
@@ -15,16 +15,23 @@
* limitations under the License.
*/
-package org.apache.inlong.manager.common.enums;
+package org.apache.inlong.manager.client.cli.validator;
+
+import com.beust.jcommander.IParameterValidator;
+import com.beust.jcommander.ParameterException;
+import org.apache.inlong.manager.common.enums.ClusterType;
/**
- * Constant of cluster type.
+ * Class for cluster type verification.
*/
-public class ClusterType {
+public class ClusterTypeValidator implements IParameterValidator {
- public static final String AGENT = "AGENT";
- public static final String TUBEMQ = "TUBEMQ";
- public static final String PULSAR = "PULSAR";
- public static final String DATAPROXY = "DATAPROXY";
- public static final String KAFKA = "KAFKA";
+ @Override
+ public void validate(String name, String value) throws ParameterException {
+ try {
+ ClusterType.checkType(value);
+ } catch (Exception e) {
+ throw new ParameterException(e.getMessage());
+ }
+ }
}
diff --git a/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/inner/client/InlongClusterClient.java b/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/inner/client/InlongClusterClient.java
index 48cee95bd..2312125f5 100644
--- a/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/inner/client/InlongClusterClient.java
+++ b/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/inner/client/InlongClusterClient.java
@@ -154,6 +154,8 @@ public class InlongClusterClient {
* @return whether succeed
*/
public Boolean update(ClusterRequest request) {
+ Preconditions.checkNotNull(request.getId(), "inlong cluster id cannot be empty");
+
Response<Boolean> response = ClientUtils.executeHttpCall(inlongClusterApi.update(request));
ClientUtils.assertRespSuccess(response);
return response.getData();
diff --git a/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/enums/ClusterType.java b/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/enums/ClusterType.java
index 8b433888e..d2934fc6c 100644
--- a/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/enums/ClusterType.java
+++ b/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/enums/ClusterType.java
@@ -17,6 +17,11 @@
package org.apache.inlong.manager.common.enums;
+import org.apache.inlong.manager.common.exceptions.BusinessException;
+
+import java.util.HashSet;
+import java.util.Set;
+
/**
* Constant of cluster type.
*/
@@ -27,4 +32,28 @@ public class ClusterType {
public static final String PULSAR = "PULSAR";
public static final String DATAPROXY = "DATAPROXY";
public static final String KAFKA = "KAFKA";
+
+ private static final Set<String> TYPE_SET = new HashSet<String>() {
+ {
+ add(ClusterType.AGENT);
+ add(ClusterType.TUBEMQ);
+ add(ClusterType.PULSAR);
+ add(ClusterType.DATAPROXY);
+ add(ClusterType.KAFKA);
+ }
+ };
+
+ /**
+ * Check whether the cluster type is supported
+ *
+ * @param clusterType cluster type
+ * @return cluster type
+ */
+ public static String checkType(String clusterType) {
+ if (TYPE_SET.contains(clusterType)) {
+ return clusterType;
+ }
+ throw new BusinessException(String.format("Unsupported cluster type=%s,"
+ + " supported cluster types are: %s", clusterType, TYPE_SET));
+ }
}