This is an automated email from the ASF dual-hosted git repository. vernedeng pushed a commit to branch branch-1.8 in repository https://gitbox.apache.org/repos/asf/inlong.git
commit e1678cdc6a1e8560b7940c09eb10fb3e1e856588 Author: haibo.duan <[email protected]> AuthorDate: Thu Jul 13 09:46:07 2023 +0800 [INLONG-8374][Manager] Manager client tools support multiple tenant (#8488) --- .../inlong/manager/client/cli/CreateCommand.java | 72 +++++++++++++++++++ .../inlong/manager/client/cli/DescribeCommand.java | 50 +++++++++++++ .../inlong/manager/client/cli/ListCommand.java | 56 +++++++++++++++ .../inlong/manager/client/cli/UpdateCommand.java | 84 ++++++++++++++++++++++ .../inlong/manager/client/cli/pojo/TenantInfo.java | 38 ++++++++++ .../manager/client/cli/pojo/TenantRoleInfo.java | 40 +++++++++++ 6 files changed, 340 insertions(+) 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 7d240f6a71..fe221a13ab 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 @@ -22,6 +22,8 @@ import org.apache.inlong.manager.client.api.InlongGroup; import org.apache.inlong.manager.client.api.InlongGroupContext; import org.apache.inlong.manager.client.api.InlongStreamBuilder; import org.apache.inlong.manager.client.api.inner.client.InlongClusterClient; +import org.apache.inlong.manager.client.api.inner.client.InlongTenantClient; +import org.apache.inlong.manager.client.api.inner.client.InlongTenantRoleClient; import org.apache.inlong.manager.client.api.inner.client.UserClient; import org.apache.inlong.manager.client.cli.pojo.CreateGroupConf; import org.apache.inlong.manager.client.cli.util.ClientUtils; @@ -34,6 +36,8 @@ import org.apache.inlong.manager.pojo.cluster.ClusterRequest; import org.apache.inlong.manager.pojo.cluster.ClusterTagRequest; import org.apache.inlong.manager.pojo.sort.FlinkSortConf; import org.apache.inlong.manager.pojo.stream.InlongStreamInfo; +import org.apache.inlong.manager.pojo.tenant.InlongTenantRequest; +import org.apache.inlong.manager.pojo.user.TenantRoleRequest; import org.apache.inlong.manager.pojo.user.UserRequest; import com.beust.jcommander.Parameter; @@ -66,6 +70,8 @@ public class CreateCommand extends AbstractCommand { jcommander.addCommand("cluster-tag", new CreateClusterTag()); jcommander.addCommand("cluster-node", new CreateClusterNode()); jcommander.addCommand("user", new CreateUser()); + jcommander.addCommand("tenant", new CreateTenant()); + jcommander.addCommand("tenant-role", new CreateTenantRole()); } @Parameters(commandDescription = "Create group by json file") @@ -267,4 +273,70 @@ public class CreateCommand extends AbstractCommand { } } } + + @Parameters(commandDescription = "Create tenant") + private static class CreateTenant extends AbstractCommandRunner { + + @Parameter() + private List<String> params; + + @Parameter(names = {"-n", "--name"}, description = "tenant name") + private String name; + + @Parameter(names = {"-d", "--description"}, description = "tenant description") + private String description; + + @Override + void run() { + try { + InlongTenantRequest request = new InlongTenantRequest(); + request.setName(name); + request.setDescription(description); + request.setVersion(0); + ClientUtils.initClientFactory(); + InlongTenantClient tenantClient = ClientUtils.clientFactory.getInlongTenantClient(); + Integer userId = tenantClient.save(request); + if (userId != null) { + System.out.println("Create tenant success! ID: " + userId); + } + } catch (Exception e) { + System.out.println(e.getMessage()); + } + } + } + + @Parameters(commandDescription = "Create tenant role") + private static class CreateTenantRole extends AbstractCommandRunner { + + @Parameter() + private List<String> params; + + @Parameter(names = {"-u", "--username"}, description = "username") + private String username; + + @Parameter(names = {"-p", "--role-code"}, description = "role code") + private String roleCode; + + @Parameter(names = {"-t", "--tenant"}, description = "tenant") + private String tenant; + + @Override + void run() { + try { + TenantRoleRequest request = new TenantRoleRequest(); + request.setUsername(username); + request.setRoleCode(roleCode); + request.setTenant(tenant); + request.setVersion(0); + ClientUtils.initClientFactory(); + InlongTenantRoleClient roleClient = ClientUtils.clientFactory.getInlongTenantRoleClient(); + Integer roleId = roleClient.save(request); + if (roleId != null) { + System.out.println("Create role success! ID: " + roleId); + } + } 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 0165da8c96..ec50e2e04e 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 @@ -20,6 +20,8 @@ package org.apache.inlong.manager.client.cli; 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.InlongTenantClient; +import org.apache.inlong.manager.client.api.inner.client.InlongTenantRoleClient; import org.apache.inlong.manager.client.api.inner.client.StreamSinkClient; import org.apache.inlong.manager.client.api.inner.client.StreamSourceClient; import org.apache.inlong.manager.client.api.inner.client.StreamTransformClient; @@ -35,7 +37,9 @@ import org.apache.inlong.manager.pojo.group.InlongGroupPageRequest; import org.apache.inlong.manager.pojo.sink.StreamSink; import org.apache.inlong.manager.pojo.source.StreamSource; import org.apache.inlong.manager.pojo.stream.InlongStreamInfo; +import org.apache.inlong.manager.pojo.tenant.InlongTenantInfo; import org.apache.inlong.manager.pojo.transform.TransformResponse; +import org.apache.inlong.manager.pojo.user.TenantRoleInfo; import org.apache.inlong.manager.pojo.user.UserInfo; import com.beust.jcommander.Parameter; @@ -64,6 +68,8 @@ public class DescribeCommand extends AbstractCommand { jcommander.addCommand("cluster-tag", new DescribeClusterTag()); jcommander.addCommand("cluster-node", new DescribeClusterNode()); jcommander.addCommand("user", new DescribeUser()); + jcommander.addCommand("tenant", new DescribeTenant()); + jcommander.addCommand("tenant-role", new DescribeTenantRole()); } @Parameters(commandDescription = "Get stream details") @@ -283,4 +289,48 @@ public class DescribeCommand extends AbstractCommand { } } } + + @Parameters(commandDescription = "Get tenant details") + private static class DescribeTenant extends AbstractCommandRunner { + + @Parameter() + private List<String> params; + + @Parameter(names = {"-name", "--name"}, required = true, description = "tenant name") + private String name; + + @Override + void run() { + try { + ClientUtils.initClientFactory(); + InlongTenantClient tenantClient = ClientUtils.clientFactory.getInlongTenantClient(); + InlongTenantInfo tenantInfo = tenantClient.getTenantByName(name); + PrintUtils.printJson(tenantInfo); + } catch (Exception e) { + System.out.println(e.getMessage()); + } + } + } + + @Parameters(commandDescription = "Get tenant role details") + private static class DescribeTenantRole extends AbstractCommandRunner { + + @Parameter() + private List<String> params; + + @Parameter(names = {"-id", "--id"}, required = true, description = "tenant role id") + private int id; + + @Override + void run() { + try { + ClientUtils.initClientFactory(); + InlongTenantRoleClient tenantRoleClient = ClientUtils.clientFactory.getInlongTenantRoleClient(); + TenantRoleInfo tenantRoleInfo = tenantRoleClient.get(id); + PrintUtils.printJson(tenantRoleInfo); + } 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 a2673d60b1..af334e52cc 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 @@ -20,6 +20,8 @@ package org.apache.inlong.manager.client.cli; 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.InlongTenantClient; +import org.apache.inlong.manager.client.api.inner.client.InlongTenantRoleClient; import org.apache.inlong.manager.client.api.inner.client.StreamSinkClient; import org.apache.inlong.manager.client.api.inner.client.StreamSourceClient; import org.apache.inlong.manager.client.api.inner.client.StreamTransformClient; @@ -48,7 +50,11 @@ import org.apache.inlong.manager.pojo.group.InlongGroupPageRequest; import org.apache.inlong.manager.pojo.sink.StreamSink; import org.apache.inlong.manager.pojo.source.StreamSource; import org.apache.inlong.manager.pojo.stream.InlongStreamInfo; +import org.apache.inlong.manager.pojo.tenant.InlongTenantInfo; +import org.apache.inlong.manager.pojo.tenant.InlongTenantPageRequest; import org.apache.inlong.manager.pojo.transform.TransformResponse; +import org.apache.inlong.manager.pojo.user.TenantRoleInfo; +import org.apache.inlong.manager.pojo.user.TenantRolePageRequest; import org.apache.inlong.manager.pojo.user.UserInfo; import org.apache.inlong.manager.pojo.user.UserRequest; @@ -78,6 +84,8 @@ public class ListCommand extends AbstractCommand { jcommander.addCommand("cluster-tag", new ListClusterTag()); jcommander.addCommand("cluster-node", new ListClusterNode()); jcommander.addCommand("user", new ListUser()); + jcommander.addCommand("tenant", new ListTenant()); + jcommander.addCommand("tenant-role", new ListTenantRole()); } @Parameters(commandDescription = "Get stream summary information") @@ -330,4 +338,52 @@ public class ListCommand extends AbstractCommand { } } } + + @Parameters(commandDescription = "Get tenant summary information") + private static class ListTenant extends AbstractCommandRunner { + + @Parameter() + private List<String> params; + + @Parameter(names = {"-keyword", "--keyword"}, description = "keyword") + private String keyword; + + @Override + void run() { + try { + ClientUtils.initClientFactory(); + InlongTenantPageRequest request = new InlongTenantPageRequest(); + request.setKeyword(keyword); + InlongTenantClient tenantClient = ClientUtils.clientFactory.getInlongTenantClient(); + PageResult<InlongTenantInfo> tenantInfo = tenantClient.listByCondition(request); + PrintUtils.print(tenantInfo.getList(), org.apache.inlong.manager.client.cli.pojo.TenantInfo.class); + } catch (Exception e) { + System.out.println(e.getMessage()); + } + } + } + + @Parameters(commandDescription = "Get tenant role summary information") + private static class ListTenantRole extends AbstractCommandRunner { + + @Parameter() + private List<String> params; + + @Parameter(names = {"-keyword", "--keyword"}, description = "keyword") + private String keyword; + + @Override + void run() { + try { + ClientUtils.initClientFactory(); + TenantRolePageRequest request = new TenantRolePageRequest(); + request.setKeyword(keyword); + InlongTenantRoleClient tenantRoleClient = ClientUtils.clientFactory.getInlongTenantRoleClient(); + PageResult<TenantRoleInfo> tenantInfo = tenantRoleClient.listByCondition(request); + PrintUtils.print(tenantInfo.getList(), org.apache.inlong.manager.client.cli.pojo.TenantRoleInfo.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 10214b1624..5834e135fc 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 @@ -20,6 +20,8 @@ package org.apache.inlong.manager.client.cli; 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.api.inner.client.InlongTenantClient; +import org.apache.inlong.manager.client.api.inner.client.InlongTenantRoleClient; import org.apache.inlong.manager.client.api.inner.client.UserClient; import org.apache.inlong.manager.client.cli.util.ClientUtils; import org.apache.inlong.manager.common.exceptions.BusinessException; @@ -28,6 +30,10 @@ import org.apache.inlong.manager.pojo.cluster.ClusterNodeRequest; import org.apache.inlong.manager.pojo.cluster.ClusterRequest; import org.apache.inlong.manager.pojo.cluster.ClusterTagRequest; import org.apache.inlong.manager.pojo.sort.BaseSortConf; +import org.apache.inlong.manager.pojo.tenant.InlongTenantInfo; +import org.apache.inlong.manager.pojo.tenant.InlongTenantRequest; +import org.apache.inlong.manager.pojo.user.TenantRoleInfo; +import org.apache.inlong.manager.pojo.user.TenantRoleRequest; import org.apache.inlong.manager.pojo.user.UserInfo; import org.apache.inlong.manager.pojo.user.UserRequest; @@ -56,6 +62,8 @@ public class UpdateCommand extends AbstractCommand { jcommander.addCommand("cluster-tag", new UpdateCommand.UpdateClusterTag()); jcommander.addCommand("cluster-node", new UpdateCommand.UpdateClusterNode()); jcommander.addCommand("user", new UpdateCommand.UpdateUser()); + jcommander.addCommand("tenant", new UpdateCommand.UpdateTenant()); + jcommander.addCommand("tenant-role", new UpdateCommand.UpdateTenantRole()); } @Parameters(commandDescription = "Update group by json file") @@ -205,4 +213,80 @@ public class UpdateCommand extends AbstractCommand { } } } + + @Parameters(commandDescription = "Update Tenant") + private static class UpdateTenant extends AbstractCommandRunner { + + @Parameter() + private List<String> params; + + @Parameter(names = {"-n", "--name"}, description = "name to be modify") + private String name; + + @Parameter(names = {"-d", "--description"}, description = "new description") + private String description; + + @Override + void run() { + try { + InlongTenantRequest request = new InlongTenantRequest(); + request.setName(name); + ClientUtils.initClientFactory(); + InlongTenantClient tenantClient = ClientUtils.clientFactory.getInlongTenantClient(); + InlongTenantInfo tenantInfo = tenantClient.getTenantByName(name); + if (tenantInfo == null) { + throw new BusinessException(name + " not exist, please check."); + } + request.setId(tenantInfo.getId()); + request.setDescription(description); + request.setVersion(tenantInfo.getVersion()); + if (tenantClient.update(request)) { + System.out.println("Update user success!"); + } + } catch (Exception e) { + System.out.println(e.getMessage()); + } + } + } + + @Parameters(commandDescription = "Update Tenant Role") + private static class UpdateTenantRole extends AbstractCommandRunner { + + @Parameter() + private List<String> params; + + @Parameter(names = {"-id", "--id"}, description = "id to be modify") + private Integer id; + + @Parameter(names = {"-rc", "--role-code"}, description = "new role code") + private String roleCode; + + @Override + void run() { + try { + TenantRoleRequest request = new TenantRoleRequest(); + request.setId(id); + ClientUtils.initClientFactory(); + InlongTenantRoleClient roleClient = ClientUtils.clientFactory.getInlongTenantRoleClient(); + TenantRoleInfo roleInfo = roleClient.get(id); + if (roleInfo == null) { + throw new BusinessException(id + " not exist, please check."); + } + request.setUsername(roleInfo.getUsername()); + request.setDisabled(roleInfo.getDisabled()); + request.setVersion(roleInfo.getVersion()); + if (StringUtils.isNotEmpty(roleCode)) { + request.setRoleCode(roleCode); + } else { + request.setRoleCode(roleInfo.getRoleCode()); + } + request.setTenant(roleInfo.getTenant()); + if (roleClient.update(request)) { + System.out.println("Update user 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/pojo/TenantInfo.java b/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/pojo/TenantInfo.java new file mode 100644 index 0000000000..1365bf0049 --- /dev/null +++ b/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/pojo/TenantInfo.java @@ -0,0 +1,38 @@ +/* + * 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 com.fasterxml.jackson.annotation.JsonFormat; + +import java.util.Date; + +public class TenantInfo { + + private Integer id; + private String name; + private String description; + private String creator; + private String modifier; + + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date createTime; + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date modifyTime; + + private Integer version; +} diff --git a/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/pojo/TenantRoleInfo.java b/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/pojo/TenantRoleInfo.java new file mode 100644 index 0000000000..b7570dbd68 --- /dev/null +++ b/inlong-manager/manager-client-tools/src/main/java/org/apache/inlong/manager/client/cli/pojo/TenantRoleInfo.java @@ -0,0 +1,40 @@ +/* + * 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 com.fasterxml.jackson.annotation.JsonFormat; + +import java.util.Date; + +public class TenantRoleInfo { + + private Integer id; + private String username; + private String roleCode; + private String tenant; + private Integer disabled; + private String creator; + private String modifier; + + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date createTime; + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date modifyTime; + + private Integer version; +}
