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 7c2d266efc [INLONG-8547][Manager] Add workflow approver automatically
when create a new tenant (#8550)
7c2d266efc is described below
commit 7c2d266efc000ecba1b2bab4993f2908ee86324a
Author: vernedeng <[email protected]>
AuthorDate: Tue Jul 18 14:07:27 2023 +0800
[INLONG-8547][Manager] Add workflow approver automatically when create a
new tenant (#8550)
---
.../manager/dao/entity/InlongClusterEntity.java | 1 +
.../manager/dao/entity/InlongClusterTagEntity.java | 1 +
.../dao/mapper/InlongClusterEntityMapper.java | 3 ++
.../dao/mapper/InlongClusterTagEntityMapper.java | 2 +
.../mappers/InlongClusterEntityMapper.xml | 50 ++++++++++++----------
.../mappers/InlongClusterTagEntityMapper.xml | 26 ++++++-----
.../dao/mapper/InlongClusterEntityMapperTest.java | 23 ++++++++++
.../manager/pojo/cluster/ClusterPageRequest.java | 3 ++
.../manager/pojo/cluster/ClusterRequest.java | 4 ++
.../pojo/cluster/ClusterTagPageRequest.java | 3 ++
.../manager/pojo/cluster/ClusterTagRequest.java | 4 ++
.../service/tenant/InlongTenantServiceImpl.java | 29 +++++++++++++
.../service/core/impl/AgentServiceTest.java | 4 +-
.../main/resources/h2/apache_inlong_manager.sql | 2 +
.../manager-web/sql/apache_inlong_manager.sql | 5 ++-
inlong-manager/manager-web/sql/changes-1.8.0.sql | 14 +++++-
.../web/controller/InlongClusterController.java | 23 +++++-----
17 files changed, 148 insertions(+), 49 deletions(-)
diff --git
a/inlong-manager/manager-dao/src/main/java/org/apache/inlong/manager/dao/entity/InlongClusterEntity.java
b/inlong-manager/manager-dao/src/main/java/org/apache/inlong/manager/dao/entity/InlongClusterEntity.java
index 98d150d0bb..0e0e6f079f 100644
---
a/inlong-manager/manager-dao/src/main/java/org/apache/inlong/manager/dao/entity/InlongClusterEntity.java
+++
b/inlong-manager/manager-dao/src/main/java/org/apache/inlong/manager/dao/entity/InlongClusterEntity.java
@@ -42,6 +42,7 @@ public class InlongClusterEntity implements Serializable {
private String extParams;
private String description;
private String heartbeat;
+ private String tenant;
private String inCharges;
private Integer status;
diff --git
a/inlong-manager/manager-dao/src/main/java/org/apache/inlong/manager/dao/entity/InlongClusterTagEntity.java
b/inlong-manager/manager-dao/src/main/java/org/apache/inlong/manager/dao/entity/InlongClusterTagEntity.java
index a92390cd9a..55afa3396d 100644
---
a/inlong-manager/manager-dao/src/main/java/org/apache/inlong/manager/dao/entity/InlongClusterTagEntity.java
+++
b/inlong-manager/manager-dao/src/main/java/org/apache/inlong/manager/dao/entity/InlongClusterTagEntity.java
@@ -33,6 +33,7 @@ public class InlongClusterTagEntity implements Serializable {
private String clusterTag;
private String extParams;
private String description;
+ private String tenant;
private String inCharges;
private Integer status;
diff --git
a/inlong-manager/manager-dao/src/main/java/org/apache/inlong/manager/dao/mapper/InlongClusterEntityMapper.java
b/inlong-manager/manager-dao/src/main/java/org/apache/inlong/manager/dao/mapper/InlongClusterEntityMapper.java
index ce2644691d..d6ae75ef1a 100644
---
a/inlong-manager/manager-dao/src/main/java/org/apache/inlong/manager/dao/mapper/InlongClusterEntityMapper.java
+++
b/inlong-manager/manager-dao/src/main/java/org/apache/inlong/manager/dao/mapper/InlongClusterEntityMapper.java
@@ -17,6 +17,7 @@
package org.apache.inlong.manager.dao.mapper;
+import org.apache.inlong.manager.common.tenant.MultiTenantQuery;
import org.apache.inlong.manager.dao.entity.InlongClusterEntity;
import org.apache.inlong.manager.pojo.cluster.ClusterPageRequest;
import org.apache.inlong.manager.pojo.sort.standalone.SortSourceClusterInfo;
@@ -29,6 +30,7 @@ import org.springframework.stereotype.Repository;
import java.util.List;
+@MultiTenantQuery
@Repository
public interface InlongClusterEntityMapper {
@@ -53,6 +55,7 @@ public interface InlongClusterEntityMapper {
*
* @return All cluster info.
*/
+ @MultiTenantQuery(with = false)
@Options(resultSetType = ResultSetType.FORWARD_ONLY, fetchSize =
Integer.MIN_VALUE)
Cursor<SortSourceClusterInfo> selectAllClusters();
diff --git
a/inlong-manager/manager-dao/src/main/java/org/apache/inlong/manager/dao/mapper/InlongClusterTagEntityMapper.java
b/inlong-manager/manager-dao/src/main/java/org/apache/inlong/manager/dao/mapper/InlongClusterTagEntityMapper.java
index 0afed687f0..44b7640650 100644
---
a/inlong-manager/manager-dao/src/main/java/org/apache/inlong/manager/dao/mapper/InlongClusterTagEntityMapper.java
+++
b/inlong-manager/manager-dao/src/main/java/org/apache/inlong/manager/dao/mapper/InlongClusterTagEntityMapper.java
@@ -17,6 +17,7 @@
package org.apache.inlong.manager.dao.mapper;
+import org.apache.inlong.manager.common.tenant.MultiTenantQuery;
import org.apache.inlong.manager.dao.entity.InlongClusterTagEntity;
import org.apache.inlong.manager.pojo.cluster.ClusterTagPageRequest;
@@ -25,6 +26,7 @@ import org.springframework.stereotype.Repository;
import java.util.List;
+@MultiTenantQuery
@Repository
public interface InlongClusterTagEntityMapper {
diff --git
a/inlong-manager/manager-dao/src/main/resources/mappers/InlongClusterEntityMapper.xml
b/inlong-manager/manager-dao/src/main/resources/mappers/InlongClusterEntityMapper.xml
index e95cf6de36..e513afe492 100644
---
a/inlong-manager/manager-dao/src/main/resources/mappers/InlongClusterEntityMapper.xml
+++
b/inlong-manager/manager-dao/src/main/resources/mappers/InlongClusterEntityMapper.xml
@@ -32,6 +32,7 @@
<result column="ext_params" jdbcType="LONGVARCHAR"
property="extParams"/>
<result column="description" jdbcType="VARCHAR"
property="description"/>
<result column="heartbeat" jdbcType="LONGVARCHAR"
property="heartbeat"/>
+ <result column="tenant" jdbcType="VARCHAR" property="tenant"/>
<result column="in_charges" jdbcType="VARCHAR" property="inCharges"/>
<result column="status" jdbcType="INTEGER" property="status"/>
<result column="is_deleted" jdbcType="INTEGER" property="isDeleted"/>
@@ -42,7 +43,7 @@
<result column="version" jdbcType="INTEGER" property="version"/>
</resultMap>
<sql id="Base_Column_List">
- id, name, display_name, type, url, cluster_tags, ext_tag, token,
ext_params, description, heartbeat,
+ id, name, display_name, type, url, cluster_tags, ext_tag, token,
ext_params, description, heartbeat, tenant,
in_charges, status, is_deleted, creator, modifier, create_time,
modify_time, version
</sql>
@@ -51,13 +52,14 @@
insert into inlong_cluster (id, name, display_name, type,
url, cluster_tags, ext_tag,
token, ext_params, description,
- heartbeat, in_charges,
+ heartbeat, tenant, in_charges,
status, creator, modifier)
values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR},
#{displayName,jdbcType=VARCHAR},
#{type,jdbcType=VARCHAR}, #{url,jdbcType=VARCHAR},
#{clusterTags,jdbcType=VARCHAR},
#{extTag,jdbcType=VARCHAR}, #{token,jdbcType=VARCHAR},
#{extParams,jdbcType=LONGVARCHAR},
- #{description, jdbcType=VARCHAR},
#{heartbeat,jdbcType=LONGVARCHAR}, #{inCharges,jdbcType=VARCHAR},
- #{status,jdbcType=INTEGER}, #{creator,jdbcType=VARCHAR},
#{modifier,jdbcType=VARCHAR})
+ #{description, jdbcType=VARCHAR},
#{heartbeat,jdbcType=LONGVARCHAR}, #{tenant,jdbcType=VARCHAR},
+ #{inCharges,jdbcType=VARCHAR}, #{status,jdbcType=INTEGER},
#{creator,jdbcType=VARCHAR},
+ #{modifier,jdbcType=VARCHAR})
</insert>
<insert id="insertOnDuplicateKeyUpdate" useGeneratedKeys="true"
keyProperty="id"
@@ -65,28 +67,30 @@
insert into inlong_cluster (id, name, display_name, type,
url, cluster_tags, ext_tag,
token, ext_params, heartbeat,
- in_charges, status,
+ tenant, in_charges, status,
creator, modifier)
values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR},
#{displayName,jdbcType=VARCHAR},
#{type,jdbcType=VARCHAR}, #{url,jdbcType=VARCHAR},
#{clusterTags,jdbcType=VARCHAR},
#{extTag,jdbcType=VARCHAR},#{token,jdbcType=VARCHAR},
#{extParams,jdbcType=LONGVARCHAR},
- #{heartbeat,jdbcType=LONGVARCHAR},
#{inCharges,jdbcType=VARCHAR}, #{status,jdbcType=INTEGER},
- #{creator,jdbcType=VARCHAR}, #{modifier,jdbcType=VARCHAR})
+ #{heartbeat,jdbcType=LONGVARCHAR}, #{tenant,jdbcType=VARCHAR},
#{inCharges,jdbcType=VARCHAR},
+ #{status,jdbcType=INTEGER}, #{creator,jdbcType=VARCHAR},
#{modifier,jdbcType=VARCHAR})
ON DUPLICATE KEY UPDATE cluster_tags = VALUES(cluster_tags),
ext_tag = VALUES(ext_tag),
token = VALUES(token),
ext_params = VALUES(ext_params),
heartbeat = VALUES(heartbeat),
+ tenant = VALUES(tenant),
in_charges = VALUES(in_charges),
status = VALUES(status),
modifier = VALUES(modifier)
</insert>
- <select id="selectById" parameterType="java.lang.Integer"
resultMap="BaseResultMap">
+ <select id="selectById" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from inlong_cluster
- where is_deleted = 0
+ where tenant = #{tenant,jdbcType=VARCHAR}
+ and is_deleted = 0
and id = #{id,jdbcType=INTEGER}
</select>
<select id="selectByKey"
resultType="org.apache.inlong.manager.dao.entity.InlongClusterEntity">
@@ -94,7 +98,8 @@
<include refid="Base_Column_List"/>
from inlong_cluster
<where>
- is_deleted = 0
+ tenant = #{tenant,jdbcType=VARCHAR}
+ and is_deleted = 0
<if test="type != null and type != ''">
and type = #{type, jdbcType=VARCHAR}
</if>
@@ -112,7 +117,8 @@
<include refid="Base_Column_List"/>
from inlong_cluster
<where>
- is_deleted = 0
+ tenant = #{tenant,jdbcType=VARCHAR}
+ and is_deleted = 0
<if test="type != null and type != ''">
and type = #{type, jdbcType=VARCHAR}
</if>
@@ -129,7 +135,8 @@
<include refid="Base_Column_List"/>
from inlong_cluster
<where>
- is_deleted = 0
+ tenant = #{tenant,jdbcType=VARCHAR}
+ and is_deleted = 0
<if test="name != null and name != ''">
and name = #{name, jdbcType=VARCHAR}
</if>
@@ -161,11 +168,6 @@
or ext_tag like CONCAT('%', #{keyword}, '%')
)
</if>
- <if test="isAdminRole == false">
- and (
- creator = #{currentUser, jdbcType=VARCHAR} or
find_in_set(#{currentUser, jdbcType=VARCHAR}, in_charges)
- )
- </if>
<if test="status != null and status != ''">
and status = #{status, jdbcType=INTEGER}
</if>
@@ -177,7 +179,8 @@
<include refid="Base_Column_List"/>
from inlong_cluster
<where>
- is_deleted = 0
+ tenant = #{tenant,jdbcType=VARCHAR}
+ and is_deleted = 0
<if test="clusterTag != null and clusterTag != ''">
and find_in_set(#{clusterTag, jdbcType=VARCHAR}, cluster_tags)
</if>
@@ -212,7 +215,8 @@
is_deleted = #{isDeleted,jdbcType=INTEGER},
modifier = #{modifier,jdbcType=VARCHAR},
version = #{version,jdbcType=INTEGER} + 1
- where id = #{id,jdbcType=INTEGER}
+ where tenant = #{tenant,jdbcType=VARCHAR}
+ and id = #{id,jdbcType=INTEGER}
and version = #{version,jdbcType=INTEGER}
</update>
<update id="updateByIdSelective"
parameterType="org.apache.inlong.manager.dao.entity.InlongClusterEntity">
@@ -262,13 +266,15 @@
</if>
version = #{version,jdbcType=INTEGER} + 1
</set>
- where id = #{id,jdbcType=INTEGER}
+ where tenant = #{tenant,jdbcType=VARCHAR}
+ and id = #{id,jdbcType=INTEGER}
and version = #{version,jdbcType=INTEGER}
</update>
- <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
+ <delete id="deleteByPrimaryKey">
delete
from inlong_cluster
- where id = #{id,jdbcType=INTEGER}
+ where tenant = #{tenant,jdbcType=VARCHAR}
+ and id = #{id,jdbcType=INTEGER}
</delete>
</mapper>
diff --git
a/inlong-manager/manager-dao/src/main/resources/mappers/InlongClusterTagEntityMapper.xml
b/inlong-manager/manager-dao/src/main/resources/mappers/InlongClusterTagEntityMapper.xml
index 7054323383..96160b856d 100644
---
a/inlong-manager/manager-dao/src/main/resources/mappers/InlongClusterTagEntityMapper.xml
+++
b/inlong-manager/manager-dao/src/main/resources/mappers/InlongClusterTagEntityMapper.xml
@@ -25,6 +25,7 @@
<result column="cluster_tag" jdbcType="VARCHAR" property="clusterTag"/>
<result column="ext_params" jdbcType="LONGVARCHAR"
property="extParams"/>
<result column="description" jdbcType="VARCHAR"
property="description"/>
+ <result column="tenant" jdbcType="VARCHAR" property="tenant"/>
<result column="in_charges" jdbcType="VARCHAR" property="inCharges"/>
<result column="status" jdbcType="INTEGER" property="status"/>
<result column="is_deleted" jdbcType="INTEGER" property="isDeleted"/>
@@ -35,31 +36,33 @@
<result column="version" jdbcType="INTEGER" property="version"/>
</resultMap>
<sql id="Base_Column_List">
- id, cluster_tag, ext_params, description, in_charges, status,
is_deleted,
+ id, cluster_tag, ext_params, description, tenant, in_charges, status,
is_deleted,
creator, modifier, create_time, modify_time, version
</sql>
<insert id="insert" useGeneratedKeys="true" keyProperty="id"
parameterType="org.apache.inlong.manager.dao.entity.InlongClusterTagEntity">
insert into inlong_cluster_tag (id, cluster_tag, ext_params,
- description, in_charges,
+ description, tenant, in_charges,
status, creator, modifier)
values (#{id,jdbcType=INTEGER}, #{clusterTag,jdbcType=VARCHAR},
#{extParams,jdbcType=LONGVARCHAR},
- #{description, jdbcType=VARCHAR},
#{inCharges,jdbcType=VARCHAR},
+ #{description, jdbcType=VARCHAR}, #{tenant,jdbcType=VARCHAR},
#{inCharges,jdbcType=VARCHAR},
#{status,jdbcType=INTEGER}, #{creator,jdbcType=VARCHAR},
#{modifier,jdbcType=VARCHAR})
</insert>
- <select id="selectById" parameterType="java.lang.Integer"
resultMap="BaseResultMap">
+ <select id="selectById" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from inlong_cluster_tag
- where id = #{id,jdbcType=INTEGER}
+ where tenant = #{tenant,jdbcType=VARCHAR}
+ and id = #{id,jdbcType=INTEGER}
</select>
<select id="selectByTag"
resultType="org.apache.inlong.manager.dao.entity.InlongClusterTagEntity">
select
<include refid="Base_Column_List"/>
from inlong_cluster_tag
- where cluster_tag = #{clusterTag, jdbcType=VARCHAR}
+ where tenant = #{tenant,jdbcType=VARCHAR}
+ and cluster_tag = #{clusterTag, jdbcType=VARCHAR}
and is_deleted = 0
</select>
<select id="selectByCondition"
@@ -69,7 +72,8 @@
<include refid="Base_Column_List"/>
from inlong_cluster_tag
<where>
- is_deleted = 0
+ tenant = #{tenant,jdbcType=VARCHAR}
+ and is_deleted = 0
<if test="keyword != null and keyword != ''">
and cluster_tag like CONCAT('%', #{keyword}, '%')
</if>
@@ -103,13 +107,15 @@
</if>
version = #{version,jdbcType=INTEGER} + 1
</set>
- where id = #{id,jdbcType=INTEGER}
+ where tenant = #{tenant,jdbcType=VARCHAR}
+ and id = #{id,jdbcType=INTEGER}
and version = #{version,jdbcType=INTEGER}
</update>
- <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
+ <delete id="deleteByPrimaryKey">
delete
from inlong_cluster_tag
- where id = #{id,jdbcType=INTEGER}
+ where tenant = #{tenant,jdbcType=VARCHAR}
+ and id = #{id,jdbcType=INTEGER}
</delete>
</mapper>
\ No newline at end of file
diff --git
a/inlong-manager/manager-dao/src/test/java/org/apache/inlong/manager/dao/mapper/InlongClusterEntityMapperTest.java
b/inlong-manager/manager-dao/src/test/java/org/apache/inlong/manager/dao/mapper/InlongClusterEntityMapperTest.java
index 0fc1294d1e..96e246fb32 100644
---
a/inlong-manager/manager-dao/src/test/java/org/apache/inlong/manager/dao/mapper/InlongClusterEntityMapperTest.java
+++
b/inlong-manager/manager-dao/src/test/java/org/apache/inlong/manager/dao/mapper/InlongClusterEntityMapperTest.java
@@ -41,6 +41,17 @@ public class InlongClusterEntityMapperTest extends
DaoBaseTest {
Assertions.assertNull(entityMapper.selectByNameAndType(entity.getName(),
entity.getType()));
}
+ @Test
+ public void deleteByPrimaryKeyWithOtherTenant() {
+ InlongClusterEntity entity = genEntity();
+ entityMapper.insert(entity);
+ setOtherTenant(ANOTHER_TENANT);
+ Assertions.assertEquals(0,
entityMapper.deleteByPrimaryKey(entity.getId()));
+
Assertions.assertNull(entityMapper.selectByNameAndType(entity.getName(),
entity.getType()));
+ setOtherTenant(PUBLIC_TENANT);
+
Assertions.assertNotNull(entityMapper.selectByNameAndType(entity.getName(),
entity.getType()));
+ }
+
@Test
public void selectByCondition() {
InlongClusterEntity entity = genEntity();
@@ -50,6 +61,8 @@ public class InlongClusterEntityMapperTest extends
DaoBaseTest {
request.setClusterTag("testTag");
Assertions.assertEquals(1,
entityMapper.selectByCondition(request).size());
+ setOtherTenant(ANOTHER_TENANT);
+ Assertions.assertEquals(0,
entityMapper.selectByCondition(request).size());
}
@Test
@@ -61,7 +74,17 @@ public class InlongClusterEntityMapperTest extends
DaoBaseTest {
String newType = "newType";
entity.setType(newType);
+ // the tenant will be modified in mybatis interceptor, set tenant here
does not work
+ entity.setTenant(ANOTHER_TENANT);
Assertions.assertEquals(1, entityMapper.updateById(entity));
+ entity = entityMapper.selectById(entity.getId());
+ Assertions.assertEquals(newType, entity.getType());
+
+ // should be public
+ Assertions.assertEquals(PUBLIC_TENANT, entity.getTenant());
+
+ setOtherTenant(ANOTHER_TENANT);
+ Assertions.assertEquals(0, entityMapper.updateById(entity));
}
private InlongClusterEntity genEntity() {
diff --git
a/inlong-manager/manager-pojo/src/main/java/org/apache/inlong/manager/pojo/cluster/ClusterPageRequest.java
b/inlong-manager/manager-pojo/src/main/java/org/apache/inlong/manager/pojo/cluster/ClusterPageRequest.java
index 2e2b0d4ae2..fece364a20 100644
---
a/inlong-manager/manager-pojo/src/main/java/org/apache/inlong/manager/pojo/cluster/ClusterPageRequest.java
+++
b/inlong-manager/manager-pojo/src/main/java/org/apache/inlong/manager/pojo/cluster/ClusterPageRequest.java
@@ -55,6 +55,9 @@ public class ClusterPageRequest extends PageRequest {
@ApiModelProperty(value = "Parent cluster ID, used for cluster node")
private Integer parentId;
+ @ApiModelProperty(value = "Inlong tenant of cluster", hidden = true)
+ private String tenant;
+
@ApiModelProperty(value = "Keywords, name, url, cluster tag, etc.")
private String keyword;
diff --git
a/inlong-manager/manager-pojo/src/main/java/org/apache/inlong/manager/pojo/cluster/ClusterRequest.java
b/inlong-manager/manager-pojo/src/main/java/org/apache/inlong/manager/pojo/cluster/ClusterRequest.java
index a2dd867a0c..46c2b826ac 100644
---
a/inlong-manager/manager-pojo/src/main/java/org/apache/inlong/manager/pojo/cluster/ClusterRequest.java
+++
b/inlong-manager/manager-pojo/src/main/java/org/apache/inlong/manager/pojo/cluster/ClusterRequest.java
@@ -90,6 +90,10 @@ public abstract class ClusterRequest {
@Length(max = 256, message = "length must be less than or equal to 256")
private String description;
+ @ApiModelProperty(value = "Inlong tenant of cluster", hidden = true)
+ @Length(max = 256, message = "length must be less than or equal to 256")
+ private String tenant;
+
@ApiModelProperty(value = "Name of responsible person, separated by
commas")
@Length(max = 512, message = "length must be less than or equal to 512")
private String inCharges;
diff --git
a/inlong-manager/manager-pojo/src/main/java/org/apache/inlong/manager/pojo/cluster/ClusterTagPageRequest.java
b/inlong-manager/manager-pojo/src/main/java/org/apache/inlong/manager/pojo/cluster/ClusterTagPageRequest.java
index de2fb00eaf..cdc704fa2d 100644
---
a/inlong-manager/manager-pojo/src/main/java/org/apache/inlong/manager/pojo/cluster/ClusterTagPageRequest.java
+++
b/inlong-manager/manager-pojo/src/main/java/org/apache/inlong/manager/pojo/cluster/ClusterTagPageRequest.java
@@ -44,6 +44,9 @@ public class ClusterTagPageRequest extends PageRequest {
@ApiModelProperty(value = "Status")
private Integer status;
+ @ApiModelProperty(value = "Inlong tenant of cluster tag", hidden = true)
+ private String tenant;
+
@ApiModelProperty(value = "Current user", hidden = true)
private String currentUser;
diff --git
a/inlong-manager/manager-pojo/src/main/java/org/apache/inlong/manager/pojo/cluster/ClusterTagRequest.java
b/inlong-manager/manager-pojo/src/main/java/org/apache/inlong/manager/pojo/cluster/ClusterTagRequest.java
index a5ba5546ae..46ecbb2694 100644
---
a/inlong-manager/manager-pojo/src/main/java/org/apache/inlong/manager/pojo/cluster/ClusterTagRequest.java
+++
b/inlong-manager/manager-pojo/src/main/java/org/apache/inlong/manager/pojo/cluster/ClusterTagRequest.java
@@ -54,6 +54,10 @@ public class ClusterTagRequest {
@Length(max = 256, message = "length must be less than or equal to 256")
private String description;
+ @ApiModelProperty(value = "Inlong tenant of cluster tag", hidden = true)
+ @Length(max = 256, message = "length must be less than or equal to 256")
+ private String tenant;
+
@ApiModelProperty(value = "Name of in charges, separated by commas")
@Length(max = 512, message = "length must be less than or equal to 512")
private String inCharges;
diff --git
a/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/tenant/InlongTenantServiceImpl.java
b/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/tenant/InlongTenantServiceImpl.java
index 6aea00c35b..746380c66a 100644
---
a/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/tenant/InlongTenantServiceImpl.java
+++
b/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/tenant/InlongTenantServiceImpl.java
@@ -19,6 +19,7 @@ package org.apache.inlong.manager.service.tenant;
import org.apache.inlong.manager.common.consts.InlongConstants;
import org.apache.inlong.manager.common.enums.ErrorCodeEnum;
+import org.apache.inlong.manager.common.enums.ProcessName;
import org.apache.inlong.manager.common.exceptions.BusinessException;
import org.apache.inlong.manager.common.util.CommonBeanUtils;
import org.apache.inlong.manager.common.util.Preconditions;
@@ -30,6 +31,8 @@ import
org.apache.inlong.manager.pojo.tenant.InlongTenantPageRequest;
import org.apache.inlong.manager.pojo.tenant.InlongTenantRequest;
import org.apache.inlong.manager.pojo.user.LoginUserUtils;
import org.apache.inlong.manager.pojo.user.UserInfo;
+import org.apache.inlong.manager.pojo.workflow.ApproverRequest;
+import org.apache.inlong.manager.service.core.WorkflowApproverService;
import org.apache.inlong.manager.service.user.TenantRoleService;
import com.github.pagehelper.Page;
@@ -40,9 +43,12 @@ import
org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.ScheduledThreadPoolExecutor;
import static org.apache.inlong.manager.pojo.user.UserRoleCode.INLONG_ADMIN;
import static org.apache.inlong.manager.pojo.user.UserRoleCode.INLONG_OPERATOR;
+import static
org.apache.inlong.manager.service.workflow.WorkflowDefinition.UT_ADMIN_NAME;
@Service
@Slf4j
@@ -52,6 +58,9 @@ public class InlongTenantServiceImpl implements
InlongTenantService {
private InlongTenantEntityMapper inlongTenantEntityMapper;
@Autowired
private TenantRoleService tenantRoleService;
+ @Autowired
+ private WorkflowApproverService workflowApproverService;
+ private ExecutorService executorService = new
ScheduledThreadPoolExecutor(1);
@Override
public InlongTenantInfo getByName(String name) {
@@ -77,9 +86,29 @@ public class InlongTenantServiceImpl implements
InlongTenantService {
entity.setCreator(operator);
entity.setModifier(operator);
inlongTenantEntityMapper.insert(entity);
+
+ UserInfo loginUserInfo = LoginUserUtils.getLoginUser();
+ executorService.submit(() -> {
+ loginUserInfo.setTenant(request.getName());
+ LoginUserUtils.setUserLoginInfo(loginUserInfo);
+
saveDefaultWorkflowApprovers(ProcessName.APPLY_GROUP_PROCESS.name(),
+ UT_ADMIN_NAME, operator);
+
saveDefaultWorkflowApprovers(ProcessName.APPLY_CONSUME_PROCESS.name(),
+ UT_ADMIN_NAME, operator);
+ LoginUserUtils.removeUserLoginInfo();
+ });
+
return entity.getId();
}
+ private Integer saveDefaultWorkflowApprovers(String processName, String
taskName, String approver) {
+ ApproverRequest request = new ApproverRequest();
+ request.setProcessName(processName);
+ request.setApprovers(approver);
+ request.setTaskName(taskName);
+ return workflowApproverService.save(request, approver);
+ }
+
@Override
public PageResult<InlongTenantInfo>
listByCondition(InlongTenantPageRequest request, UserInfo userInfo) {
PageHelper.startPage(request.getPageNum(), request.getPageSize());
diff --git
a/inlong-manager/manager-service/src/test/java/org/apache/inlong/manager/service/core/impl/AgentServiceTest.java
b/inlong-manager/manager-service/src/test/java/org/apache/inlong/manager/service/core/impl/AgentServiceTest.java
index 6ac8682346..c8d127c505 100644
---
a/inlong-manager/manager-service/src/test/java/org/apache/inlong/manager/service/core/impl/AgentServiceTest.java
+++
b/inlong-manager/manager-service/src/test/java/org/apache/inlong/manager/service/core/impl/AgentServiceTest.java
@@ -66,10 +66,10 @@ class AgentServiceTest extends ServiceBaseTest {
private static MockAgent agent;
@Autowired
- private HeartbeatService heartbeatService;
- @Autowired
private StreamSourceService sourceService;
@Autowired
+ private HeartbeatService heartbeatService;
+ @Autowired
private AgentService agentService;
@Autowired
private InlongGroupEntityMapper groupMapper;
diff --git
a/inlong-manager/manager-test/src/main/resources/h2/apache_inlong_manager.sql
b/inlong-manager/manager-test/src/main/resources/h2/apache_inlong_manager.sql
index d8017e86fb..a12c0dcba6 100644
---
a/inlong-manager/manager-test/src/main/resources/h2/apache_inlong_manager.sql
+++
b/inlong-manager/manager-test/src/main/resources/h2/apache_inlong_manager.sql
@@ -81,6 +81,7 @@ CREATE TABLE IF NOT EXISTS `inlong_cluster_tag`
`cluster_tag` varchar(128) NOT NULL COMMENT 'Cluster tag',
`ext_params` mediumtext DEFAULT NULL COMMENT 'Extended params,
will be saved as JSON string',
`description` varchar(256) DEFAULT '' COMMENT 'Description of
cluster tag',
+ `tenant` varchar(256) DEFAULT 'public' COMMENT 'Inlong
tenant of the inlong cluster tag',
`in_charges` varchar(512) NOT NULL COMMENT 'Name of responsible person,
separated by commas',
`status` int(4) DEFAULT '0' COMMENT 'Cluster status',
`is_deleted` int(11) DEFAULT '0' COMMENT 'Whether to
delete, 0: not deleted, > 0: deleted',
@@ -109,6 +110,7 @@ CREATE TABLE IF NOT EXISTS `inlong_cluster`
`ext_params` mediumtext DEFAULT NULL COMMENT
'Extended params, will be saved as JSON string',
`description` varchar(256) DEFAULT '' COMMENT
'Description of cluster',
`heartbeat` mediumtext DEFAULT NULL COMMENT
'Cluster heartbeat info',
+ `tenant` varchar(256) NOT NULL DEFAULT 'public' COMMENT
'Inlong tenant of cluster',
`in_charges` varchar(512) NOT NULL COMMENT 'Name of responsible
person, separated by commas',
`status` int(4) DEFAULT '0' COMMENT 'Cluster
status',
`is_deleted` int(11) DEFAULT '0' COMMENT 'Whether
to delete, 0: not deleted, > 0: deleted',
diff --git a/inlong-manager/manager-web/sql/apache_inlong_manager.sql
b/inlong-manager/manager-web/sql/apache_inlong_manager.sql
index 8b0f155f36..c38e413f30 100644
--- a/inlong-manager/manager-web/sql/apache_inlong_manager.sql
+++ b/inlong-manager/manager-web/sql/apache_inlong_manager.sql
@@ -90,6 +90,7 @@ CREATE TABLE IF NOT EXISTS `inlong_cluster_tag`
`cluster_tag` varchar(128) NOT NULL COMMENT 'Cluster tag',
`ext_params` mediumtext DEFAULT NULL COMMENT 'Extended params,
will be saved as JSON string',
`description` varchar(256) DEFAULT '' COMMENT 'Description of
cluster tag',
+ `tenant` varchar(256) DEFAULT 'public' COMMENT 'Inlong
tenant of the inlong cluster tag',
`in_charges` varchar(512) NOT NULL COMMENT 'Name of responsible person,
separated by commas',
`status` int(4) DEFAULT '0' COMMENT 'Cluster status',
`is_deleted` int(11) DEFAULT '0' COMMENT 'Whether to
delete, 0: not deleted, > 0: deleted',
@@ -119,6 +120,7 @@ CREATE TABLE IF NOT EXISTS `inlong_cluster`
`ext_params` mediumtext DEFAULT NULL COMMENT
'Extended params, will be saved as JSON string',
`description` varchar(256) DEFAULT '' COMMENT
'Description of cluster',
`heartbeat` mediumtext DEFAULT NULL COMMENT
'Cluster heartbeat info',
+ `tenant` varchar(256) NOT NULL DEFAULT 'public' COMMENT
'Inlong tenant of cluster',
`in_charges` varchar(512) NOT NULL COMMENT 'Name of responsible
person, separated by commas',
`status` int(4) DEFAULT '0' COMMENT 'Cluster
status',
`is_deleted` int(11) DEFAULT '0' COMMENT 'Whether
to delete, 0: not deleted, > 0: deleted',
@@ -129,7 +131,8 @@ CREATE TABLE IF NOT EXISTS `inlong_cluster`
`version` int(11) NOT NULL DEFAULT '1' COMMENT 'Version
number, which will be incremented by 1 after modification',
PRIMARY KEY (`id`),
UNIQUE KEY `unique_inlong_cluster` (`name`, `type`, `is_deleted`),
- INDEX `cluster_type_index` (`type`)
+ INDEX `cluster_type_index` (`type`),
+ INDEX `cluster_tenant_index` (`tenant`, `is_deleted`)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4 COMMENT ='Inlong cluster table';
diff --git a/inlong-manager/manager-web/sql/changes-1.8.0.sql
b/inlong-manager/manager-web/sql/changes-1.8.0.sql
index 99a5a4eb96..b1ef5f8a78 100644
--- a/inlong-manager/manager-web/sql/changes-1.8.0.sql
+++ b/inlong-manager/manager-web/sql/changes-1.8.0.sql
@@ -83,8 +83,8 @@ INSERT INTO tenant_user_role(username, role_code, tenant,
creator)
FROM user;
-- To avoid the ambiguity, rename "tenant" in PulsarGroup & PulsarCluster to
"pulsarTenant"
-UPDATE inlong_group SET ext_params = replace(ext_params, '"tenant":',
'"pulsarTenant":');
-UPDATE inlong_cluster SET ext_params = replace(ext_params, '"tenant":',
'"pulsarTenant":');
+UPDATE inlong_group SET ext_params = replace(ext_params, '"tenant"',
'"pulsarTenant"');
+UPDATE inlong_cluster SET ext_params = replace(ext_params, '"tenant"',
'"pulsarTenant"');
ALTER TABLE `inlong_stream` MODIFY COLUMN `name` varchar(256) DEFAULT NULL
COMMENT 'The name of the inlong stream page display, can be Chinese';
@@ -99,6 +99,16 @@ ALTER TABLE `data_node`
CREATE INDEX datanode_tenant_index
ON data_node (`tenant`, `is_deleted`);
+-- To support multi-tenancy of cluster. Please see #8365
+ALTER TABLE `inlong_cluster`
+ ADD `tenant` VARCHAR(256) DEFAULT 'public' NOT NULL comment 'Inlong tenant
of cluster' after `heartbeat`;
+CREATE INDEX cluster_tenant_index
+ ON inlong_cluster (`tenant`, `is_deleted`);
+
+-- To support multi-tenancy of cluster tag. Please see #8378
+ALTER TABLE `inlong_cluster_tag`
+ ADD `tenant` VARCHAR(256) DEFAULT 'public' NOT NULL comment 'Inlong tenant
of inlong cluster tag' after `description`;
+
-- To support multi-tenancy of inlong consume. Please see #8378
ALTER TABLE `inlong_consume`
ADD `tenant` VARCHAR(256) DEFAULT 'public' NOT NULL comment 'Inlong tenant
of consume' after `ext_params`;
diff --git
a/inlong-manager/manager-web/src/main/java/org/apache/inlong/manager/web/controller/InlongClusterController.java
b/inlong-manager/manager-web/src/main/java/org/apache/inlong/manager/web/controller/InlongClusterController.java
index 119f5151e5..6abdeef97c 100644
---
a/inlong-manager/manager-web/src/main/java/org/apache/inlong/manager/web/controller/InlongClusterController.java
+++
b/inlong-manager/manager-web/src/main/java/org/apache/inlong/manager/web/controller/InlongClusterController.java
@@ -74,7 +74,7 @@ public class InlongClusterController {
@PostMapping(value = "/cluster/tag/save")
@ApiOperation(value = "Save cluster tag")
@OperationLog(operation = OperationType.CREATE)
- @RequiresRoles(value = UserRoleCode.INLONG_ADMIN)
+ @RequiresRoles(logical = Logical.OR, value = {UserRoleCode.TENANT_ADMIN,
UserRoleCode.INLONG_ADMIN})
public Response<Integer> saveTag(@Validated(SaveValidation.class)
@RequestBody ClusterTagRequest request) {
String currentUser = LoginUserUtils.getLoginUser().getName();
return Response.success(clusterService.saveTag(request, currentUser));
@@ -83,7 +83,6 @@ public class InlongClusterController {
@GetMapping(value = "/cluster/tag/get/{id}")
@ApiOperation(value = "Get cluster tag by id")
@ApiImplicitParam(name = "id", value = "Cluster ID", dataTypeClass =
Integer.class, required = true)
- @RequiresRoles(logical = Logical.OR, value = {UserRoleCode.INLONG_ADMIN,
UserRoleCode.INLONG_OPERATOR})
public Response<ClusterTagResponse> getTag(@PathVariable Integer id) {
String currentUser = LoginUserUtils.getLoginUser().getName();
return Response.success(clusterService.getTag(id, currentUser));
@@ -91,16 +90,17 @@ public class InlongClusterController {
@PostMapping(value = "/cluster/tag/list")
@ApiOperation(value = "List cluster tags")
- @RequiresRoles(logical = Logical.OR, value = {UserRoleCode.INLONG_ADMIN,
UserRoleCode.INLONG_OPERATOR})
public Response<PageResult<ClusterTagResponse>> listTag(@RequestBody
ClusterTagPageRequest request) {
request.setCurrentUser(LoginUserUtils.getLoginUser().getName());
+ request.setIsAdminRole(
+
LoginUserUtils.getLoginUser().getRoles().contains(TenantUserTypeEnum.TENANT_ADMIN.name()));
return Response.success(clusterService.listTag(request));
}
@PostMapping(value = "/cluster/tag/update")
@OperationLog(operation = OperationType.UPDATE)
@ApiOperation(value = "Update cluster tag")
- @RequiresRoles(value = UserRoleCode.INLONG_ADMIN)
+ @RequiresRoles(logical = Logical.OR, value = {UserRoleCode.TENANT_ADMIN,
UserRoleCode.INLONG_ADMIN})
public Response<Boolean> updateTag(@Validated(UpdateValidation.class)
@RequestBody ClusterTagRequest request) {
String username = LoginUserUtils.getLoginUser().getName();
return Response.success(clusterService.updateTag(request, username));
@@ -110,7 +110,7 @@ public class InlongClusterController {
@ApiOperation(value = "Delete cluster tag by id")
@OperationLog(operation = OperationType.DELETE)
@ApiImplicitParam(name = "id", value = "Cluster tag ID", dataTypeClass =
Integer.class, required = true)
- @RequiresRoles(value = UserRoleCode.INLONG_ADMIN)
+ @RequiresRoles(logical = Logical.OR, value = {UserRoleCode.TENANT_ADMIN,
UserRoleCode.INLONG_ADMIN})
public Response<Boolean> deleteTag(@PathVariable Integer id) {
return Response.success(clusterService.deleteTag(id,
LoginUserUtils.getLoginUser().getName()));
}
@@ -118,7 +118,7 @@ public class InlongClusterController {
@PostMapping(value = "/cluster/save")
@ApiOperation(value = "Save cluster")
@OperationLog(operation = OperationType.CREATE)
- @RequiresRoles(value = UserRoleCode.INLONG_ADMIN)
+ @RequiresRoles(logical = Logical.OR, value = {UserRoleCode.TENANT_ADMIN,
UserRoleCode.INLONG_ADMIN})
public Response<Integer> save(@Validated(SaveValidation.class)
@RequestBody ClusterRequest request) {
String currentUser = LoginUserUtils.getLoginUser().getName();
return Response.success(clusterService.save(request, currentUser));
@@ -127,7 +127,6 @@ public class InlongClusterController {
@GetMapping(value = "/cluster/get/{id}")
@ApiOperation(value = "Get cluster by id")
@ApiImplicitParam(name = "id", value = "Cluster ID", dataTypeClass =
Integer.class, required = true)
- @RequiresRoles(logical = Logical.OR, value = {UserRoleCode.INLONG_ADMIN,
UserRoleCode.INLONG_OPERATOR})
public Response<ClusterInfo> get(@PathVariable Integer id) {
String currentUser = LoginUserUtils.getLoginUser().getName();
return Response.success(clusterService.get(id, currentUser));
@@ -145,7 +144,7 @@ public class InlongClusterController {
@PostMapping(value = "/cluster/update")
@OperationLog(operation = OperationType.UPDATE)
@ApiOperation(value = "Update cluster")
- @RequiresRoles(value = UserRoleCode.INLONG_ADMIN)
+ @RequiresRoles(logical = Logical.OR, value = {UserRoleCode.TENANT_ADMIN,
UserRoleCode.INLONG_ADMIN})
public Response<Boolean> update(@Validated(UpdateByIdValidation.class)
@RequestBody ClusterRequest request) {
String username = LoginUserUtils.getLoginUser().getName();
return Response.success(clusterService.update(request, username));
@@ -154,7 +153,7 @@ public class InlongClusterController {
@PostMapping(value = "/cluster/updateByKey")
@OperationLog(operation = OperationType.UPDATE)
@ApiOperation(value = "Update cluster by key")
- @RequiresRoles(value = UserRoleCode.INLONG_ADMIN)
+ @RequiresRoles(logical = Logical.OR, value = {UserRoleCode.TENANT_ADMIN,
UserRoleCode.INLONG_ADMIN})
public Response<UpdateResult> updateByKey(
@Validated(UpdateByKeyValidation.class) @RequestBody
ClusterRequest request) {
String username = LoginUserUtils.getLoginUser().getName();
@@ -164,7 +163,7 @@ public class InlongClusterController {
@PostMapping(value = "/cluster/bindTag")
@OperationLog(operation = OperationType.UPDATE)
@ApiOperation(value = "Bind or unbind cluster tag")
- @RequiresRoles(value = UserRoleCode.INLONG_ADMIN)
+ @RequiresRoles(logical = Logical.OR, value = {UserRoleCode.TENANT_ADMIN,
UserRoleCode.INLONG_ADMIN})
public Response<Boolean> bindTag(@Validated @RequestBody BindTagRequest
request) {
String username = LoginUserUtils.getLoginUser().getName();
return Response.success(clusterService.bindTag(request, username));
@@ -174,7 +173,7 @@ public class InlongClusterController {
@ApiOperation(value = "Delete cluster by id")
@OperationLog(operation = OperationType.DELETE)
@ApiImplicitParam(name = "id", value = "Cluster ID", dataTypeClass =
Integer.class, required = true)
- @RequiresRoles(value = UserRoleCode.INLONG_ADMIN)
+ @RequiresRoles(logical = Logical.OR, value = {UserRoleCode.TENANT_ADMIN,
UserRoleCode.INLONG_ADMIN})
public Response<Boolean> delete(@PathVariable Integer id) {
return Response.success(clusterService.delete(id,
LoginUserUtils.getLoginUser().getName()));
}
@@ -186,7 +185,7 @@ public class InlongClusterController {
@ApiImplicitParam(name = "name", value = "Cluster name",
dataTypeClass = String.class, required = true),
@ApiImplicitParam(name = "type", value = "Cluster type",
dataTypeClass = String.class, required = true),
})
- @RequiresRoles(value = UserRoleCode.INLONG_ADMIN)
+ @RequiresRoles(logical = Logical.OR, value = {UserRoleCode.TENANT_ADMIN,
UserRoleCode.INLONG_ADMIN})
public Response<Boolean> deleteByKey(@RequestParam String name,
@RequestParam String type) {
return Response.success(clusterService.deleteByKey(name, type,
LoginUserUtils.getLoginUser().getName()));