Skip to content

Commit

Permalink
[INLONG-7890][Manager] Add checks for unmodifiable data_node_name and…
Browse files Browse the repository at this point in the history
… cluster_name (#7891)
  • Loading branch information
fuweng11 committed Apr 24, 2023
1 parent fc19b4f commit 7cd7116
Show file tree
Hide file tree
Showing 19 changed files with 199 additions and 122 deletions.
Expand Up @@ -31,6 +31,7 @@ public class DataNodeEntity implements Serializable {
private static final long serialVersionUID = 1L;
private Integer id;
private String name;
private String displayName;
private String type;
private String url;
private String username;
Expand Down
Expand Up @@ -32,6 +32,7 @@ public class InlongClusterEntity implements Serializable {

private Integer id;
private String name;
private String displayName;
private String type;
private String url;
private String clusterTags;
Expand Down
Expand Up @@ -23,6 +23,7 @@
<resultMap id="BaseResultMap" type="org.apache.inlong.manager.dao.entity.DataNodeEntity">
<id column="id" jdbcType="INTEGER" property="id"/>
<result column="name" jdbcType="VARCHAR" property="name"/>
<result column="display_name" jdbcType="VARCHAR" property="displayName"/>
<result column="type" jdbcType="VARCHAR" property="type"/>
<result column="url" jdbcType="VARCHAR" property="url"/>
<result column="username" jdbcType="VARCHAR" property="username"/>
Expand All @@ -39,20 +40,21 @@
<result column="version" jdbcType="INTEGER" property="version"/>
</resultMap>
<sql id="Base_Column_List">
id, name, type, url, username, token, ext_params, description, in_charges, status, is_deleted,
id, name, display_name, type, url, username, token, ext_params, description, 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.DataNodeEntity">
insert into data_node (id, name, type,
insert into data_node (id, name, display_name, type,
url, username, token,
ext_params, description, in_charges,
status, creator, modifier)
values (#{id, jdbcType=INTEGER}, #{name, jdbcType=VARCHAR}, #{type, jdbcType=VARCHAR},
#{url, jdbcType=VARCHAR}, #{username, jdbcType=VARCHAR}, #{token, jdbcType=VARCHAR},
#{extParams,jdbcType=LONGVARCHAR}, #{description, jdbcType=VARCHAR}, #{inCharges, jdbcType=VARCHAR},
#{status, jdbcType=INTEGER}, #{creator, jdbcType=VARCHAR}, #{modifier, jdbcType=VARCHAR})
values (#{id, jdbcType=INTEGER}, #{name, jdbcType=VARCHAR}, #{displayName,jdbcType=VARCHAR},
#{type, jdbcType=VARCHAR}, #{url, jdbcType=VARCHAR}, #{username, jdbcType=VARCHAR},
#{token, jdbcType=VARCHAR}, #{extParams,jdbcType=LONGVARCHAR}, #{description, jdbcType=VARCHAR},
#{inCharges, jdbcType=VARCHAR}, #{status, jdbcType=INTEGER}, #{creator, jdbcType=VARCHAR},
#{modifier, jdbcType=VARCHAR})
</insert>

<select id="selectById" parameterType="java.lang.Integer" resultMap="BaseResultMap">
Expand Down Expand Up @@ -87,6 +89,7 @@
<if test="keyword != null and keyword != ''">
and (
name like CONCAT('%', #{keyword}, '%')
or display_name like CONCAT('%', #{keyword}, '%')
or type like CONCAT('%', #{keyword}, '%')
or url like CONCAT('%', #{keyword}, '%')
)
Expand Down Expand Up @@ -115,18 +118,19 @@
</select>
<update id="updateById" parameterType="org.apache.inlong.manager.dao.entity.DataNodeEntity">
update data_node
set name = #{name, jdbcType=VARCHAR},
type = #{type, jdbcType=VARCHAR},
url = #{url, jdbcType=VARCHAR},
username = #{username, jdbcType=VARCHAR},
token = #{token, jdbcType=VARCHAR},
ext_params = #{extParams, jdbcType=LONGVARCHAR},
description = #{description,jdbcType=VARCHAR},
in_charges = #{inCharges, jdbcType=VARCHAR},
status = #{status, jdbcType=INTEGER},
is_deleted = #{isDeleted, jdbcType=INTEGER},
modifier = #{modifier, jdbcType=VARCHAR},
version = #{version, jdbcType=INTEGER} + 1
set name = #{name, jdbcType=VARCHAR},
display_name = #{displayName, jdbcType=VARCHAR},
type = #{type, jdbcType=VARCHAR},
url = #{url, jdbcType=VARCHAR},
username = #{username, jdbcType=VARCHAR},
token = #{token, jdbcType=VARCHAR},
ext_params = #{extParams, jdbcType=LONGVARCHAR},
description = #{description,jdbcType=VARCHAR},
in_charges = #{inCharges, jdbcType=VARCHAR},
status = #{status, jdbcType=INTEGER},
is_deleted = #{isDeleted, jdbcType=INTEGER},
modifier = #{modifier, jdbcType=VARCHAR},
version = #{version, jdbcType=INTEGER} + 1
where id = #{id, jdbcType=INTEGER}
and version = #{version, jdbcType=INTEGER}
</update>
Expand All @@ -136,6 +140,9 @@
<if test="name != null">
name = #{name, jdbcType=VARCHAR},
</if>
<if test="displayName !=null">
display_name = #{displayName, jdbcType=VARCHAR},
</if>
<if test="type != null">
type = #{type, jdbcType=VARCHAR},
</if>
Expand Down
Expand Up @@ -23,6 +23,7 @@
<resultMap id="BaseResultMap" type="org.apache.inlong.manager.dao.entity.InlongClusterEntity">
<id column="id" jdbcType="INTEGER" property="id"/>
<result column="name" jdbcType="VARCHAR" property="name"/>
<result column="display_name" property="displayName"/>
<result column="type" jdbcType="VARCHAR" property="type"/>
<result column="url" jdbcType="VARCHAR" property="url"/>
<result column="cluster_tags" jdbcType="VARCHAR" property="clusterTags"/>
Expand All @@ -41,35 +42,35 @@
<result column="version" jdbcType="INTEGER" property="version"/>
</resultMap>
<sql id="Base_Column_List">
id, 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,
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.InlongClusterEntity">
insert into inlong_cluster (id, name, type,
insert into inlong_cluster (id, name, display_name, type,
url, cluster_tags, ext_tag,
token, ext_params, description,
heartbeat, in_charges,
status, creator, modifier)
values (#{id,jdbcType=INTEGER}, #{name,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},
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})
</insert>

<insert id="insertOnDuplicateKeyUpdate" useGeneratedKeys="true" keyProperty="id"
parameterType="org.apache.inlong.manager.dao.entity.InlongClusterEntity">
insert into inlong_cluster (id, name, type,
insert into inlong_cluster (id, name, display_name, type,
url, cluster_tags, ext_tag,
token, ext_params, heartbeat,
in_charges, status,
creator, modifier)
values (#{id,jdbcType=INTEGER}, #{name,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},
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})
ON DUPLICATE KEY UPDATE cluster_tags = VALUES(cluster_tags),
ext_tag = VALUES(ext_tag),
Expand Down Expand Up @@ -155,6 +156,7 @@
</if>
<if test="keyword != null and keyword != ''">
and (name like CONCAT('%', #{keyword}, '%')
or display_name like CONCAT('%', #{keyword}, '%')
or cluster_tags like CONCAT('%', #{keyword}, '%')
or ext_tag like CONCAT('%', #{keyword}, '%')
)
Expand Down Expand Up @@ -182,7 +184,7 @@
</where>
order by modify_time desc
</select>
<select id="selectAllClusters" resultType="org.apache.inlong.manager.pojo.sort.standalone.SortSourceClusterInfo" >
<select id="selectAllClusters" resultType="org.apache.inlong.manager.pojo.sort.standalone.SortSourceClusterInfo">
select name,
type,
url,
Expand All @@ -195,20 +197,21 @@

<update id="updateById" parameterType="org.apache.inlong.manager.dao.entity.InlongClusterEntity">
update inlong_cluster
set name = #{name,jdbcType=VARCHAR},
type = #{type,jdbcType=VARCHAR},
url = #{url,jdbcType=VARCHAR},
cluster_tags = #{clusterTags,jdbcType=VARCHAR},
ext_tag = #{extTag,jdbcType=VARCHAR},
token = #{token,jdbcType=VARCHAR},
ext_params = #{extParams,jdbcType=LONGVARCHAR},
description = #{description,jdbcType=VARCHAR},
heartbeat = #{heartbeat,jdbcType=LONGVARCHAR},
in_charges = #{inCharges,jdbcType=VARCHAR},
status = #{status,jdbcType=INTEGER},
is_deleted = #{isDeleted,jdbcType=INTEGER},
modifier = #{modifier,jdbcType=VARCHAR},
version = #{version,jdbcType=INTEGER} + 1
set name = #{name,jdbcType=VARCHAR},
display_name = #{displayName,jdbcType=VARCHAR},
type = #{type,jdbcType=VARCHAR},
url = #{url,jdbcType=VARCHAR},
cluster_tags = #{clusterTags,jdbcType=VARCHAR},
ext_tag = #{extTag,jdbcType=VARCHAR},
token = #{token,jdbcType=VARCHAR},
ext_params = #{extParams,jdbcType=LONGVARCHAR},
description = #{description,jdbcType=VARCHAR},
heartbeat = #{heartbeat,jdbcType=LONGVARCHAR},
in_charges = #{inCharges,jdbcType=VARCHAR},
status = #{status,jdbcType=INTEGER},
is_deleted = #{isDeleted,jdbcType=INTEGER},
modifier = #{modifier,jdbcType=VARCHAR},
version = #{version,jdbcType=INTEGER} + 1
where id = #{id,jdbcType=INTEGER}
and version = #{version,jdbcType=INTEGER}
</update>
Expand All @@ -218,6 +221,9 @@
<if test="name != null">
name = #{name,jdbcType=VARCHAR},
</if>
<if test="displayName != null">
display_name = #{displayName,jdbcType=VARCHAR},
</if>
<if test="type != null">
type = #{type,jdbcType=VARCHAR},
</if>
Expand Down
Expand Up @@ -45,6 +45,9 @@ public abstract class ClusterInfo {
@ApiModelProperty(value = "Cluster name")
private String name;

@ApiModelProperty(value = "Cluster display name, just for display")
private String displayName;

@ApiModelProperty(value = "Cluster type, including TUBEMQ, PULSAR, KAFKA, DATAPROXY, etc.")
private String type;

Expand Down
Expand Up @@ -48,6 +48,9 @@ public class ClusterPageRequest extends PageRequest {
@ApiModelProperty(value = "Cluster name")
private String name;

@ApiModelProperty(value = "Cluster display name, just for display")
private String displayName;

@ApiModelProperty(value = "Parent cluster ID, used for cluster node")
private Integer parentId;

Expand Down
Expand Up @@ -48,11 +48,13 @@ public abstract class ClusterRequest {
private Integer id;

@ApiModelProperty(value = "Cluster name")
@NotBlank(groups = {SaveValidation.class, UpdateByKeyValidation.class}, message = "cluster name cannot be blank")
@Length(min = 1, max = 128, message = "length must be between 1 and 128")
@Pattern(regexp = "^[a-z0-9_.-]{1,128}$", message = "only supports lowercase letters, numbers, '.', '-', or '_'")
@Pattern(regexp = "^[A-Za-z0-9_-]{1,128}$", message = "only supports letters, numbers, '-', or '_'")
private String name;

@ApiModelProperty(value = "Cluster display name, just for display")
@Length(min = 1, max = 128, message = "length must be between 1 and 128")
private String displayName;

@ApiModelProperty(value = "Cluster type, including TUBEMQ, PULSAR, KAFKA, DATAPROXY, etc.")
@NotBlank(message = "cluster type cannot be blank")
@Length(min = 1, max = 20, message = "length must be between 1 and 20")
Expand Down
Expand Up @@ -45,6 +45,9 @@ public abstract class DataNodeInfo {
@ApiModelProperty(value = "Data node name")
private String name;

@ApiModelProperty(value = "Data node display name, just for display")
private String displayName;

@ApiModelProperty(value = "Data node type, including MYSQL, HIVE, KAFKA, ES, etc.")
private String type;

Expand Down
Expand Up @@ -39,10 +39,12 @@ public class DataNodePageRequest extends PageRequest {
private String type;

@ApiModelProperty(value = "Data node name")
@Length(min = 1, max = 128, message = "length must be between 1 and 128")
@Pattern(regexp = "^[A-Za-z0-9_-]{1,128}$", message = "only supports letters, numbers, '-', or '_'")
private String name;

@ApiModelProperty(value = "Data node display name, just for display")
private String displayName;

@ApiModelProperty(value = "Keywords, name, url, etc.")
private String keyword;

Expand Down
Expand Up @@ -48,11 +48,13 @@ public abstract class DataNodeRequest {
private Integer id;

@ApiModelProperty(value = "Data node name")
@NotBlank(groups = {SaveValidation.class, UpdateByKeyValidation.class}, message = "node name cannot be blank")
@Length(min = 1, max = 128, message = "length must be between 1 and 128")
@Pattern(regexp = "^[A-Za-z0-9_-]{1,128}$", message = "only supports letters, numbers, '-', or '_'")
private String name;

@ApiModelProperty(value = "Data node display name, just for display")
@Length(min = 1, max = 128, message = "length must be between 1 and 128")
private String displayName;

@ApiModelProperty(value = "Data node type, including MYSQL, HIVE, KAFKA, ES, etc.")
@NotBlank(message = "node type cannot be blank")
@Length(max = 20, message = "length must be less than or equal to 20")
Expand Down
Expand Up @@ -89,6 +89,7 @@
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;

/**
Expand Down Expand Up @@ -422,7 +423,13 @@ public Integer save(ClusterRequest request, String operator) {

// check if the cluster already exist
String clusterTag = request.getClusterTags();

// The name cannot be modified and is automatically generated by the system
String name = request.getName();
if (StringUtils.isBlank(name)) {
name = UUID.randomUUID().toString();
request.setName(name);
}
String type = request.getType();
List<InlongClusterEntity> exist = clusterMapper.selectByKey(clusterTag, name, type);
if (CollectionUtils.isNotEmpty(exist)) {
Expand All @@ -440,6 +447,12 @@ public Integer save(ClusterRequest request, String operator) {

@Override
public Integer save(ClusterRequest request, UserInfo opInfo) {
// The name cannot be modified and is automatically generated by the system
String name = request.getName();
if (StringUtils.isBlank(name)) {
name = UUID.randomUUID().toString();
request.setName(name);
}
// check if the cluster already exist
List<InlongClusterEntity> exist = clusterMapper.selectByKey(
request.getClusterTags(), request.getName(), request.getType());
Expand Down Expand Up @@ -1408,6 +1421,10 @@ private void chkUnmodifiableParams(InlongClusterEntity entity, ClusterRequest re
// check and append name
if (StringUtils.isBlank(request.getName())) {
request.setName(entity.getName());
} else {
// check name
Preconditions.expectEquals(entity.getName(), request.getName(),
ErrorCodeEnum.INVALID_PARAMETER, "name not allowed modify");
}
// check and append clusterTag
if (StringUtils.isBlank(request.getClusterTags())) {
Expand Down
Expand Up @@ -41,6 +41,7 @@
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;

/**
Expand All @@ -60,7 +61,12 @@ public class DataNodeServiceImpl implements DataNodeService {

@Override
public Integer save(DataNodeRequest request, String operator) {
// The name cannot be modified and is automatically generated by the system
String name = request.getName();
if (StringUtils.isBlank(name)) {
name = UUID.randomUUID().toString();
request.setName(name);
}
String type = request.getType();

// check if data node already exist
Expand All @@ -79,6 +85,13 @@ public Integer save(DataNodeRequest request, String operator) {

@Override
public Integer save(DataNodeRequest request, UserInfo opInfo) {
// The name cannot be modified and is automatically generated by the system
String name = request.getName();
if (StringUtils.isBlank(name)) {
name = UUID.randomUUID().toString();
request.setName(name);
}

// only the person in charges can query
if (!opInfo.getAccountType().equals(UserTypeEnum.ADMIN.getCode())) {
throw new BusinessException(ErrorCodeEnum.PERMISSION_REQUIRED);
Expand Down Expand Up @@ -314,6 +327,13 @@ private void chkUnmodifiableParams(DataNodeEntity curEntity, DataNodeRequest req
// check type
Preconditions.expectEquals(curEntity.getType(), request.getType(),
ErrorCodeEnum.INVALID_PARAMETER, "type not allowed modify");
if (StringUtils.isBlank(request.getName())) {
request.setName(curEntity.getName());
} else {
// check name
Preconditions.expectEquals(curEntity.getName(), request.getName(),
ErrorCodeEnum.INVALID_PARAMETER, "name not allowed modify");
}
// check record version
Preconditions.expectEquals(curEntity.getVersion(), request.getVersion(),
ErrorCodeEnum.CONFIG_EXPIRED,
Expand Down

0 comments on commit 7cd7116

Please sign in to comment.