Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[INLONG-10363][Manager] Support template multi tenant management #10372

Merged
merged 2 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public enum OperationTarget {

INLONG_ROLE,

TENANT_ROLE
TENANT_ROLE,

TEMPLATE

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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.dao.entity;

import lombok.Data;

import java.io.Serializable;
import java.util.Date;

@Data
public class TenantTemplateEntity implements Serializable {

private static final long serialVersionUID = 1L;

private Integer id;
private String tenant;
private String templateName;
private Integer isDeleted;
private String creator;
private String modifier;
private Date createTime;
private Date modifyTime;
private Integer version;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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.dao.mapper;

import org.apache.inlong.manager.dao.entity.TenantTemplateEntity;
import org.apache.inlong.manager.pojo.cluster.TenantClusterTagPageRequest;

import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface TenantTemplateEntityMapper {

int updateByIdSelective(TenantTemplateEntity record);

int insert(TenantTemplateEntity record);

TenantTemplateEntity selectByPrimaryKey(Integer id);

TenantTemplateEntity selectByUniqueKey(String templateName, String tenant);

List<TenantTemplateEntity> selectByTemplateName(String templateName);

List<TenantTemplateEntity> selectByCondition(TenantClusterTagPageRequest request);

}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
and (t.visible_range = "ALL" or
(t.visible_range = "IN_CHARGE"
and find_in_set(#{currentUser, jdbcType=VARCHAR}, t.in_charges))
or (t.visible_range = "TENANT" and #{tenant, jdbcType=VARCHAR} in (select tet.tenant from tenant_template tet where tet.template_name = t.name and tet.is_deleted=0 ))
)
<if test="visibleRange != null">
and t.visible_range = #{visibleRange,jdbcType=VARCHAR}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->

<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.apache.inlong.manager.dao.mapper.TenantTemplateEntityMapper">
<resultMap id="BaseResultMap" type="org.apache.inlong.manager.dao.entity.TenantTemplateEntity">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="tenant" jdbcType="VARCHAR" property="tenant" />
<result column="template_name" jdbcType="VARCHAR" property="templateName" />
<result column="is_deleted" jdbcType="INTEGER" property="isDeleted" />
<result column="creator" jdbcType="VARCHAR" property="creator" />
<result column="modifier" jdbcType="VARCHAR" property="modifier" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
<result column="modify_time" jdbcType="TIMESTAMP" property="modifyTime" />
<result column="version" jdbcType="INTEGER" property="version" />
</resultMap>
<sql id="Base_Column_List">
id, tenant, template_name, is_deleted, creator, modifier, create_time, modify_time,
version
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from tenant_template
where id = #{id,jdbcType=INTEGER}
</select>
<select id="selectByUniqueKey" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from tenant_template
where tenant = #{tenant,jdbcType=VARCHAR}
and template_name = #{templateName,jdbcType=VARCHAR}
and is_deleted = 0
</select>
<select id="selectByTemplateName" parameterType="java.lang.String" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from tenant_template
where is_deleted = 0
and template_name = #{templateName,jdbcType=VARCHAR}
</select>
<select id="selectByCondition" parameterType="org.apache.inlong.manager.pojo.stream.TenantTemplatePageRequest"
resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from tenant_template
<where>
is_deleted = 0
<if test="tenant != null and tenant != ''">
and tenant = #{tenant,jdbcType=VARCHAR}
</if>
<if test="keyword != null and keyword != ''">
and template_name like CONCAT('%', #{keyword}, '%')
</if>
<if test="tenantList != null and tenantList.size() > 0">
and tenant in
<foreach item="item" index="index" collection="tenantList" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
</where>
group by template_name, tenant
order by modify_time desc
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from tenant_template
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="org.apache.inlong.manager.dao.entity.TenantTemplateEntity">
insert into tenant_template (id, tenant, template_name,
creator, modifier)
values (#{id,jdbcType=INTEGER}, #{tenant,jdbcType=VARCHAR}, #{templateName,jdbcType=VARCHAR},
#{creator,jdbcType=VARCHAR}, #{modifier,jdbcType=VARCHAR})
</insert>
<update id="updateByIdSelective" parameterType="org.apache.inlong.manager.dao.entity.TenantTemplateEntity">
update tenant_template
<set>
<if test="tenant != null">
tenant = #{tenant,jdbcType=VARCHAR},
</if>
<if test="templateName != null">
template_name = #{templateName,jdbcType=VARCHAR},
</if>
<if test="isDeleted != null">
is_deleted = #{isDeleted,jdbcType=INTEGER},
</if>
<if test="modifier != null">
modifier = #{modifier,jdbcType=VARCHAR},
</if>
version = #{version,jdbcType=INTEGER} + 1
</set>
where id = #{id,jdbcType=INTEGER}
and version = #{version,jdbcType=INTEGER}
</update>
</mapper>
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public class TemplateField implements Serializable {
@ApiModelProperty(value = "Value expression of predefined field")
private String preExpression;

@ApiModelProperty("Is this field a meta field, 0: no, 1: yes, default is 0")
@ApiModelProperty("Is this field a meta field, 0: no, 1: yes")
@Builder.Default
private Integer isMetaField = 0;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* 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.pojo.stream;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Date;

/**
* Tenant template response
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ApiModel("Tenant template tag response")
public class TenantTemplateInfo {

@ApiModelProperty(value = "Primary key")
private Integer id;

@ApiModelProperty(value = "Template name")
private String templateName;

@ApiModelProperty(value = "Tenant")
private String tenant;

@ApiModelProperty(value = "Name of in creator")
private String creator;

@ApiModelProperty(value = "Name of in modifier")
private String modifier;

@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZ", timezone = "GMT+8")
private Date createTime;

@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZ", timezone = "GMT+8")
private Date modifyTime;

@ApiModelProperty(value = "Version number")
private Integer version;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* 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.pojo.stream;

import org.apache.inlong.manager.pojo.common.PageRequest;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@EqualsAndHashCode(callSuper = false)
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ApiModel("Template paging query request")
public class TenantTemplatePageRequest extends PageRequest {

@ApiModelProperty(value = "Inlong tenant list")
private List<String> tenantList;

@ApiModelProperty(value = "Inlong tenant")
private String tenant;

@ApiModelProperty(value = "Keywords, used for fuzzy query")
private String keyword;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* 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.pojo.stream;

import org.apache.inlong.manager.common.validation.SaveValidation;
import org.apache.inlong.manager.common.validation.UpdateValidation;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

/**
* Tenant template tag request
*/
@Data
@ApiModel("Tenant template tag request")
public class TenantTemplateRequest {

@ApiModelProperty(value = "Primary key")
@NotNull(groups = UpdateValidation.class, message = "id cannot be null")
private Integer id;

@ApiModelProperty(value = "Template name")
private String templateName;

@ApiModelProperty(value = "Inlong tenant which template")
@NotBlank(groups = SaveValidation.class, message = "tenant cannot be blank")
@Length(min = 1, max = 256, message = "length must be between 1 and 256")
private String tenant;

@ApiModelProperty(value = "Version number")
@NotNull(groups = UpdateValidation.class, message = "version cannot be null")
private Integer version;
}
Loading
Loading