Skip to content

Commit

Permalink
BIGTOP-4265: Refactor APIs for Service Config & Snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinw66 committed Nov 14, 2024
1 parent c761138 commit b18c16a
Show file tree
Hide file tree
Showing 36 changed files with 600 additions and 973 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

import jakarta.persistence.Column;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import jakarta.persistence.Transient;
import java.io.Serializable;
import java.util.List;

@Data
@EqualsAndHashCode(callSuper = true)
Expand All @@ -38,24 +36,24 @@ public class ServiceConfigPO extends BasePO implements Serializable {
@Column(name = "id")
private Long id;

@Column(name = "config_desc")
private String configDesc;
/**
* Config file name, eg: zookeeper-env, hdfs-site
*/
@Column(name = "name")
private String name;

@Column(name = "version")
private Integer version;
/**
* Properties json, represents by key-value pair belongs to a config file
*/
@Column(name = "properties_json")
private String propertiesJson;

@Column(name = "selected")
private Boolean selected;

@ToString.Exclude
private List<TypeConfigPO> configs;
@Column(name = "cluster_id")
private Long clusterId;

@Column(name = "service_id")
private Long serviceId;

@Column(name = "cluster_id")
private Long clusterId;

@Transient
@Column(name = "service_name")
private String serviceName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,26 @@

@Data
@EqualsAndHashCode(callSuper = true)
@Table(name = "type_config")
public class TypeConfigPO extends BasePO implements Serializable {
@Table(name = "service_config_snapshot")
public class ServiceConfigSnapshotPO extends BasePO implements Serializable {

@Id
@Column(name = "id")
private Long id;

@Column(name = "type_name")
private String typeName;
@Column(name = "name")
private String name;

@Column(name = "properties_json")
private String propertiesJson;
@Column(name = "desc")
private String desc;

@Column(name = "service_config_id")
private Long serviceConfigId;
/**
* Config json, not like properties json in {@link ServiceConfigPO}
* this is json for a service, which contains all config file name and it's properties
*/
@Column(name = "config_json")
private String configJson;

@Column(name = "service_id")
private Long serviceId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@

public interface ServiceConfigDao extends BaseDao<ServiceConfigPO> {

List<ServiceConfigPO> findAllByClusterId(@Param("clusterId") Long clusterId);
List<ServiceConfigPO> findByServiceId(@Param("serviceId") Long serviceId);

ServiceConfigPO findByClusterIdAndServiceIdAndSelectedIsTrue(
@Param("clusterId") Long clusterId, @Param("serviceId") Long serviceId);

List<ServiceConfigPO> findAllByClusterIdAndSelectedIsTrue(@Param("clusterId") Long clusterId);
List<ServiceConfigPO> findByClusterId(@Param("clusterId") Long clusterId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@

package org.apache.bigtop.manager.dao.repository;

import org.apache.bigtop.manager.dao.po.TypeConfigPO;
import org.apache.bigtop.manager.dao.po.ServiceConfigSnapshotPO;

public interface TypeConfigDao extends BaseDao<TypeConfigPO> {}
import org.apache.ibatis.annotations.Param;

import java.util.List;

public interface ServiceConfigSnapshotDao extends BaseDao<ServiceConfigSnapshotPO> {

List<ServiceConfigSnapshotPO> findByServiceId(@Param("serviceId") Long serviceId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,95 +24,33 @@
<mapper namespace="org.apache.bigtop.manager.dao.repository.ServiceConfigDao">

<sql id="baseColumns">
id, config_desc, version, selected, service_id, cluster_id, create_time, update_time
id, name, properties_json, cluster_id, service_id, create_time, update_time
</sql>

<sql id="baseColumnsV2">
${alias}.id, ${alias}.config_desc, ${alias}.version, ${alias}.selected, ${alias}.service_id, ${alias}.cluster_id, ${alias}.create_time, ${alias}.update_time
${alias}.id, ${alias}.name, ${alias}.properties_json, ${alias}.cluster_id, ${alias}.service_id, ${alias}.create_time, ${alias}.update_time
</sql>

<resultMap id="serviceConfigMap" type="org.apache.bigtop.manager.dao.po.ServiceConfigPO">
<id column="id" property="id"/>
<result column="config_desc" property="configDesc"/>
<result column="version" property="version"/>
<result column="selected" property="selected"/>
<result column="service_id" property="serviceId"/>
<result column="cluster_id" property="clusterId"/>
<result column="create_time" property="createTime"/>
<result column="update_time" property="updateTime"/>
<result column="service_name" property="serviceName"/>
<collection property="configs" ofType="org.apache.bigtop.manager.dao.po.TypeConfigPO">
<id column="tc_id" property="id"/>
<result column="type_name" property="typeName"/>
<result column="properties_json" property="propertiesJson"/>
</collection>
</resultMap>

<select id="findAllByClusterId" parameterType="java.lang.Long" resultMap="serviceConfigMap">
select
<include refid="baseColumnsV2">
<property name="alias" value="r"/>
</include>
, s.service_name, tc.type_name, tc.properties_json, tc.id as tc_id
from
(select * from service_config
<where>
<if test="clusterId != 0">
cluster_id = #{clusterId}
</if>
</where>
) r
inner join service s
on r.service_id = s.id
inner join type_config tc
on r.id = tc.service_config_id
order by version desc
</select>

<select id="findByClusterIdAndServiceIdAndSelectedIsTrue" resultMap="serviceConfigMap">
select
<select id="findByServiceId" resultType="org.apache.bigtop.manager.dao.po.ServiceConfigPO">
SELECT
<include refid="baseColumnsV2">
<property name="alias" value="r"/>
</include>
, s.service_name, tc.type_name, tc.properties_json
from
(select * from service_config
<where>
selected = 1
<if test="clusterId != 0">
and cluster_id = #{clusterId}
</if>
<if test="serviceId != 0">
and service_id = #{serviceId}
</if>
</where>
) r
inner join service s
on r.service_id = s.id
inner join type_config tc
on r.id = tc.service_config_id
limit 1
<property name="alias" value="sc"/>
</include>, s.service_name
FROM service_config sc
LEFT JOIN service s
ON sc.service_id = s.id
WHERE sc.service_id = #{serviceId}
</select>

<select id="findAllByClusterIdAndSelectedIsTrue" resultMap="serviceConfigMap">
select
<select id="findByClusterId" resultType="org.apache.bigtop.manager.dao.po.ServiceConfigPO">
SELECT
<include refid="baseColumnsV2">
<property name="alias" value="r"/>
</include>
, s.service_name, tc.type_name, tc.properties_json
from
(select * from service_config
<where>
selected = 1
<if test="clusterId != 0">
and cluster_id = #{clusterId}
</if>
</where>
) r
inner join service s
on r.service_id = s.id
inner join type_config tc
on r.id = tc.service_config_id
<property name="alias" value="sc"/>
</include>, s.service_name
FROM service_config sc
LEFT JOIN service s
ON sc.service_id = s.id
WHERE sc.cluster_id = #{clusterId}
</select>

</mapper>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?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.bigtop.manager.dao.repository.ServiceConfigSnapshotDao">

<sql id="baseColumns">
id, name, `desc`, config_json, service_id, create_time, update_time
</sql>

<sql id="baseColumnsV2">
${alias}.id, ${alias}.name, ${alias}.`desc`, ${alias}.config_json, ${alias}.service_id, ${alias}.create_time, ${alias}.update_time
</sql>

<select id="findByServiceId" resultType="org.apache.bigtop.manager.dao.po.ServiceConfigSnapshotPO">
SELECT
<include refid="baseColumns" />
FROM service_config_snapshot
WHERE service_id = #{serviceId}
</select>
</mapper>
Original file line number Diff line number Diff line change
Expand Up @@ -24,95 +24,32 @@
<mapper namespace="org.apache.bigtop.manager.dao.repository.ServiceConfigDao">

<sql id="baseColumns">
id, config_desc, version, selected, service_id, cluster_id, create_time, update_time
id, name, properties_json, cluster_id, service_id, create_time, update_time
</sql>

<sql id="baseColumnsV2">
${alias}.id, ${alias}.config_desc, ${alias}.version, ${alias}.selected, ${alias}.service_id, ${alias}.cluster_id, ${alias}.create_time, ${alias}.update_time
${alias}.id, ${alias}.name, ${alias}.properties_json, ${alias}.cluster_id, ${alias}.service_id, ${alias}.create_time, ${alias}.update_time
</sql>

<resultMap id="serviceConfigMap" type="org.apache.bigtop.manager.dao.po.ServiceConfigPO">
<id column="id" property="id"/>
<result column="config_desc" property="configDesc"/>
<result column="version" property="version"/>
<result column="selected" property="selected"/>
<result column="service_id" property="serviceId"/>
<result column="cluster_id" property="clusterId"/>
<result column="create_time" property="createTime"/>
<result column="update_time" property="updateTime"/>
<result column="service_name" property="serviceName"/>
<collection property="configs" ofType="org.apache.bigtop.manager.dao.po.TypeConfigPO">
<id column="tc_id" property="id"/>
<result column="type_name" property="typeName"/>
<result column="properties_json" property="propertiesJson"/>
</collection>
</resultMap>

<select id="findAllByClusterId" parameterType="java.lang.Long" resultMap="serviceConfigMap">
select
<select id="findByServiceId" resultType="org.apache.bigtop.manager.dao.po.ServiceConfigPO">
SELECT
<include refid="baseColumnsV2">
<property name="alias" value="r"/>
</include>
, s.service_name, tc.type_name, tc.properties_json, tc.id as tc_id
from
(select * from service_config
<where>
<if test="clusterId != 0">
cluster_id = #{clusterId}
</if>
</where>
) r
inner join service s
on r.service_id = s.id
inner join type_config tc
on r.id = tc.service_config_id
order by version desc
<property name="alias" value="sc"/>
</include>, s.service_name
FROM service_config sc
LEFT JOIN service s
ON sc.service_id = s.id
WHERE sc.service_id = #{serviceId}
</select>

<select id="findByClusterIdAndServiceIdAndSelectedIsTrue" resultMap="serviceConfigMap">
select
<select id="findByClusterId" resultType="org.apache.bigtop.manager.dao.po.ServiceConfigPO">
SELECT
<include refid="baseColumnsV2">
<property name="alias" value="r"/>
</include>
, s.service_name, tc.type_name, tc.properties_json
from
(select * from service_config
<where>
selected is true
<if test="clusterId != 0">
and cluster_id = #{clusterId}
</if>
<if test="serviceId != 0">
and service_id = #{serviceId}
</if>
</where>
) r
inner join service s
on r.service_id = s.id
inner join type_config tc
on r.id = tc.service_config_id
limit 1
<property name="alias" value="sc"/>
</include>, s.service_name
FROM service_config sc
LEFT JOIN service s
ON sc.service_id = s.id
WHERE sc.cluster_id = #{clusterId}
</select>

<select id="findAllByClusterIdAndSelectedIsTrue" resultMap="serviceConfigMap">
select
<include refid="baseColumnsV2">
<property name="alias" value="r"/>
</include>
, s.service_name, tc.type_name, tc.properties_json
from
(select * from service_config
<where>
selected is true
<if test="clusterId != 0">
and cluster_id = #{clusterId}
</if>
</where>
) r
inner join service s
on r.service_id = s.id
inner join type_config tc
on r.id = tc.service_config_id
</select>

</mapper>
Loading

0 comments on commit b18c16a

Please sign in to comment.