Skip to content

Commit dec6e73

Browse files
liuyou2yangzhiyue
authored andcommitted
Provides the orchestrator module with the ability to access database persistence. #355
1 parent 5b6669b commit dec6e73

File tree

3 files changed

+380
-0
lines changed

3 files changed

+380
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright 2019 WeBank
4+
~ Licensed under the Apache License, Version 2.0 (the "License");
5+
~ you may not use this file except in compliance with the License.
6+
~ You may obtain a copy of the License at
7+
~
8+
~ http://www.apache.org/licenses/LICENSE-2.0
9+
~
10+
~ Unless required by applicable law or agreed to in writing, software
11+
~ distributed under the License is distributed on an "AS IS" BASIS,
12+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
~ See the License for the specific language governing permissions and
14+
~ limitations under the License.
15+
~
16+
-->
17+
18+
<project xmlns="http://maven.apache.org/POM/4.0.0"
19+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
21+
<parent>
22+
<artifactId>dss</artifactId>
23+
<groupId>com.webank.wedatasphere.dss</groupId>
24+
<version>1.0.0</version>
25+
</parent>
26+
<modelVersion>4.0.0</modelVersion>
27+
28+
<artifactId>dss-orchestrator-db</artifactId>
29+
<dependencies>
30+
<dependency>
31+
<groupId>com.webank.wedatasphere.dss</groupId>
32+
<artifactId>dss-orchestrator-core</artifactId>
33+
<version>${dss.version}</version>
34+
<scope>provided</scope>
35+
</dependency>
36+
<dependency>
37+
<groupId>com.webank.wedatasphere.linkis</groupId>
38+
<artifactId>linkis-mybatis</artifactId>
39+
<version>${linkis.version}</version>
40+
<scope>provided</scope>
41+
</dependency>
42+
</dependencies>
43+
<build>
44+
<plugins>
45+
<plugin>
46+
<groupId>org.apache.maven.plugins</groupId>
47+
<artifactId>maven-deploy-plugin</artifactId>
48+
</plugin>
49+
50+
<plugin>
51+
<groupId>net.alchim31.maven</groupId>
52+
<artifactId>scala-maven-plugin</artifactId>
53+
</plugin>
54+
<plugin>
55+
<groupId>org.apache.maven.plugins</groupId>
56+
<artifactId>maven-jar-plugin</artifactId>
57+
</plugin>
58+
</plugins>
59+
<resources>
60+
<resource>
61+
<directory>src/main/java</directory>
62+
<includes>
63+
<include>**/*.xml</include>
64+
</includes>
65+
</resource>
66+
<resource>
67+
<directory>src/main/resources</directory>
68+
<excludes>
69+
<exclude>**/*.xml</exclude>
70+
<exclude>**/*.properties</exclude>
71+
<exclude>**/*.yml</exclude>
72+
</excludes>
73+
</resource>
74+
</resources>
75+
</build>
76+
77+
</project>
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/*
2+
* Copyright 2019 WeBank
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*
15+
*/
16+
17+
package com.webank.wedatasphere.dss.orchestrator.db.dao;
18+
19+
import com.webank.wedatasphere.dss.orchestrator.common.entity.DSSOrchestratorInfo;
20+
import com.webank.wedatasphere.dss.orchestrator.common.entity.DSSOrchestratorVersion;
21+
import com.webank.wedatasphere.dss.orchestrator.common.entity.OrchestratorInfo;
22+
import com.webank.wedatasphere.dss.orchestrator.common.entity.OrchestratorUser;
23+
import org.apache.ibatis.annotations.*;
24+
25+
import java.util.Date;
26+
import java.util.List;
27+
28+
@Mapper
29+
public interface OrchestratorMapper {
30+
31+
void addOrchestrator(DSSOrchestratorInfo dssOrchestratorInfo);
32+
33+
DSSOrchestratorInfo getOrchestrator(Long id);
34+
35+
DSSOrchestratorInfo getOrchestratorByUUID(String uuid);
36+
37+
void updateOrchestrator(DSSOrchestratorInfo dssOrchestratorInfo);
38+
39+
void deleteOrchestrator(Long id);
40+
41+
/**
42+
* @param dssOrchestratorVersion
43+
*/
44+
45+
void addOrchestratorVersion(DSSOrchestratorVersion dssOrchestratorVersion);
46+
47+
DSSOrchestratorVersion getOrchestratorVersion(Long versionId);
48+
49+
/**
50+
* 根据id查找最新的版本信息
51+
*
52+
* @param orchestratorId
53+
* @return
54+
*/
55+
DSSOrchestratorVersion getLatestOrchestratorVersionById(Long orchestratorId);
56+
57+
void updateOrchestratorVersion(DSSOrchestratorVersion dssOrchestratorVersion);
58+
59+
void deleteOrchestratorVersion(Long versionId);
60+
61+
/**
62+
* 根据id查找所有的版本信息
63+
*
64+
* @param orchestratorId
65+
* @return
66+
*
67+
*/
68+
List<DSSOrchestratorVersion> getVersionByOrchestratorId(Long orchestratorId);
69+
70+
OrchestratorInfo getOrcInfoByAppId(@Param("appId")Long appId);
71+
72+
@Select("select max(id) from dss_orchestrator_version_info where `orchestrator_id` = #{orchestratorId}")
73+
Long findLatestOrcVersionId(@Param("orchestratorId") Long orchestratorId);
74+
75+
List<DSSOrchestratorVersion> getOrchestratorVersions(@Param("projectId") Long projectId, @Param("orchestratorId") Long orchestratorId);
76+
77+
@Select("select max(`version`) from dss_orchestrator_version_info where orchestrator_id = #{orchestratorId}")
78+
String getLatestVersion(@Param("orchestratorId") Long orchestratorId);
79+
80+
81+
@Select("select uuid from dss_orchestrator_info where project_id = #{projectId} and name = #{name}")
82+
String getOrcNameByParam(@Param("projectId") Long projectId,@Param("name") String name);
83+
84+
@Select("select id from `dss_orchestrator_info` where `project_id` = #{projectId} and `is_published` = 1")
85+
List<Long> getAllOrcIdsByProjectId(@Param("projectId")Long projectId);
86+
87+
@Select("select max(`app_id`) from `dss_orchestrator_version_info` where `orchestrator_id` = #{orchestratorId} and `version` = #{version}")
88+
Long getAppIdByVersion(@Param("orchestratorId") Long orchestratorId, @Param("version") String version);
89+
90+
@Update("update `dss_orchestrator_info` set `is_published` = 1 where id = #{orchestratorId}")
91+
void setPublished(@Param("orchestratorId")Long orchestratorId);
92+
93+
@Select("select `name` from dss_orchestrator_info where `id` = #{orchestratorId}")
94+
String getOrchestratorNameById(@Param("orchestratorId") int orchestratorId);
95+
96+
@Delete("delete from `dss_orchestrator_schedule_info` where `orchestrator_id` = #{orchestratorId}")
97+
int deleteScheduleInfo(@Param("orchestratorId") Integer orchestratorId);
98+
99+
@Update("update dss_orchestrator_schedule_info set active_flag = #{activeFlag} where `orchestrator_id` = #{orchestratorId}")
100+
int updateScheduleInfoActiveFlag(@Param("orchestratorId") Long orchestratorId,@Param("activeFlag") String activeFlag );
101+
102+
103+
@Insert({
104+
"<script>",
105+
"insert into `dss_orchestrator_user`",
106+
"(`workspace_id`, `project_id`, `orchestrator_id`, `username`, `priv`, `last_update_time`)",
107+
"values",
108+
"<foreach collection='accessUsers' item='accessUser' open='(' separator='),(' close=')'>",
109+
" #{workspaceId}, #{projectId}, #{orchestratorId}, #{accessUser}, #{priv}, #{updateTime}",
110+
"</foreach>",
111+
"</script>"
112+
})
113+
void setOrchestratorPriv(@Param("workspaceId")int workspaceId,
114+
@Param("projectId")Long projectId, @Param("orchestratorId")int orchestratorId,
115+
@Param("accessUsers")List<String> accessUsers, @Param("priv")int priv, @Param("updateTime") Date date);
116+
117+
@Delete("delete from `dss_orchestrator_user` " +
118+
"where `workspace_id` = #{workspaceId} " +
119+
"and `project_id` = #{projectId} " +
120+
"and `orchestrator_id` = #{orchestratorId}")
121+
void deleteAllOrchestratorPriv(@Param("workspaceId")int workspaceId, @Param("projectId")Long projectId, @Param("orchestratorId")int orchestratorId);
122+
123+
124+
List<OrchestratorUser> getOrchestratorUserByOrcId(@Param("orchestratorId") Long orchestratorId);
125+
126+
127+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<!--
3+
~ Copyright 2019 WeBank
4+
~ Licensed under the Apache License, Version 2.0 (the "License");
5+
~ you may not use this file except in compliance with the License.
6+
~ You may obtain a copy of the License at
7+
~
8+
~ http://www.apache.org/licenses/LICENSE-2.0
9+
~
10+
~ Unless required by applicable law or agreed to in writing, software
11+
~ distributed under the License is distributed on an "AS IS" BASIS,
12+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
~ See the License for the specific language governing permissions and
14+
~ limitations under the License.
15+
~
16+
-->
17+
18+
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
19+
20+
21+
<mapper namespace="com.webank.wedatasphere.dss.orchestrator.db.dao.OrchestratorMapper">
22+
23+
24+
25+
26+
<sql id="orchestrator_main">
27+
id,`name`,`type`,`desc`,`creator`,`create_time`,`project_id`,`uses`,`appconn_name`,`uuid`,`secondary_type`
28+
</sql>
29+
30+
<sql id="orchestrator_version">
31+
id,`orchestrator_id`,`app_id`,`source`,`version`,`comment`,`update_time`,`updater`,`project_id`,`content`,`context_id`
32+
</sql>
33+
34+
<select id="getOrchestrator" resultType="com.webank.wedatasphere.dss.orchestrator.common.entity.DSSOrchestratorInfo">
35+
SELECT * FROM `dss_orchestrator_info` WHERE id = #{id}
36+
</select>
37+
38+
<select id="getOrchestratorByUUID" resultType="com.webank.wedatasphere.dss.orchestrator.common.entity.DSSOrchestratorInfo">
39+
SELECT * FROM `dss_orchestrator_info` WHERE uuid = #{uuid}
40+
</select>
41+
42+
<insert id="addOrchestrator" useGeneratedKeys="true" keyProperty="id"
43+
parameterType="com.webank.wedatasphere.dss.orchestrator.common.entity.DSSOrchestratorInfo">
44+
INSERT INTO dss_orchestrator_info (<include refid="orchestrator_main"/>)
45+
VALUES
46+
(#{id},#{name},#{type},#{desc},#{creator},#{createTime},#{projectId},#{uses},#{appConnName},#{uuid},#{secondaryType})
47+
</insert>
48+
49+
<update id="updateOrchestrator" parameterType="com.webank.wedatasphere.dss.orchestrator.common.entity.DSSOrchestratorInfo">
50+
UPDATE dss_orchestrator_info
51+
<trim prefix="set" suffixOverrides=",">
52+
<if test="name != null">`name`=#{name},</if>
53+
<if test="desc != null">`desc`=#{desc},</if>
54+
<if test="appConnName != null">`appconn_name`=#{appConnName},</if>
55+
<if test="uses != null">`uses`=#{uses},</if>
56+
<if test="secondaryType != null">`secondary_type`=#{secondaryType}</if>
57+
</trim>
58+
WHERE id = #{id}
59+
</update>
60+
61+
62+
<delete id="deleteOrchestrator">
63+
DELETE
64+
FROM
65+
dss_orchestrator_info
66+
WHERE id = #{id}
67+
</delete>
68+
69+
<insert id="addOrchestratorVersion" useGeneratedKeys="true" keyProperty="id"
70+
parameterType="com.webank.wedatasphere.dss.orchestrator.common.entity.DSSOrchestratorVersion">
71+
INSERT INTO dss_orchestrator_version_info (<include refid="orchestrator_version"/>)
72+
VALUES
73+
(#{id},#{orchestratorId},#{appId},#{source},#{version},#{comment},#{updateTime},#{updater},#{projectId},#{content},#{contextId})
74+
</insert>
75+
76+
77+
<update id="updateOrchestratorVersion"
78+
parameterType="com.webank.wedatasphere.dss.orchestrator.common.entity.DSSOrchestratorVersion">
79+
UPDATE dss_orchestrator_version_info
80+
<trim prefix="set" suffixOverrides=",">
81+
<if test="source != null">`source` = #{source},</if>
82+
<if test="appId != null">`app_id` = #{appId},</if>
83+
<if test="content != null">`content`= #{content},</if>
84+
<if test="comment != null">`comment` = #{comment},</if>
85+
<if test="contextId != null">`context_id` = #{contextId},</if>
86+
<if test="updateTime != null">`update_time` = #{updateTime},</if>
87+
<if test="updater != null">`updater` = #{updater}</if>
88+
</trim>
89+
WHERE id = #{id}
90+
</update>
91+
92+
93+
<select id="getLatestOrchestratorVersionById"
94+
resultType="com.webank.wedatasphere.dss.orchestrator.common.entity.DSSOrchestratorVersion">
95+
SELECT
96+
*
97+
FROM
98+
`dss_orchestrator_version_info`
99+
WHERE
100+
orchestrator_id = #{orchestratorId}
101+
ORDER BY
102+
version DESC
103+
LIMIT 1
104+
</select>
105+
106+
107+
<select id="getOrchestratorVersion" resultType="com.webank.wedatasphere.dss.orchestrator.common.entity.DSSOrchestratorVersion">
108+
SELECT
109+
*
110+
FROM
111+
`dss_orchestrator_version_info`
112+
WHERE
113+
id = #{versionId}
114+
</select>
115+
116+
<delete id="deleteOrchestratorVersion">
117+
DELETE
118+
FROM
119+
dss_orchestrator_version_info
120+
WHERE id = #{versionId}
121+
</delete>
122+
123+
<select id="getVersionByOrchestratorId"
124+
resultType="com.webank.wedatasphere.dss.orchestrator.common.entity.DSSOrchestratorVersion">
125+
SELECT * FROM dss_orchestrator_version_info
126+
WHERE orchestrator_id = #{orchestratorId}
127+
ORDER BY version DESC
128+
</select>
129+
130+
131+
132+
<resultMap id="orcInfo" type="com.webank.wedatasphere.dss.orchestrator.common.entity.OrchestratorInfo">
133+
<result column="id" property="orchestratorVersionId" jdbcType="BIGINT"/>
134+
<result column="orchestrator_id" property="orchestratorId" jdbcType="BIGINT"/>
135+
</resultMap>
136+
137+
138+
<select id="getOrcInfoByAppId" resultMap="orcInfo">
139+
select `id`, `orchestrator_id` from dss_orchestrator_version_info where app_id = #{appId}
140+
</select>
141+
142+
<resultMap id="orchestrator_version_info_result_map" type="com.webank.wedatasphere.dss.orchestrator.common.entity.DSSOrchestratorVersion">
143+
<result column="id" property="id" jdbcType="BIGINT"/>
144+
<result column="orchestrator_id" property="orchestratorId" jdbcType="BIGINT"/>
145+
<result column="app_id" property="appId" jdbcType="BIGINT"/>
146+
<result column="source" property="source" jdbcType="LONGVARCHAR"/>
147+
<result column="version" property="version" jdbcType="LONGVARCHAR"/>
148+
<result column="comment" property="comment" jdbcType="LONGVARCHAR"/>
149+
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
150+
<result column="updater" property="updater" jdbcType="LONGVARCHAR"/>
151+
<result column="project_id" property="projectId" jdbcType="BIGINT"/>
152+
<result column="content" property="content" jdbcType="LONGVARCHAR"/>
153+
</resultMap>
154+
155+
<select id="getOrchestratorVersions" resultMap="orchestrator_version_info_result_map">
156+
select * from `dss_orchestrator_version_info` where `project_id` = #{projectId} and `orchestrator_id` = #{orchestratorId}
157+
</select>
158+
159+
160+
161+
<resultMap id="orchestrator_user_map" type="com.webank.wedatasphere.dss.orchestrator.common.entity.OrchestratorUser">
162+
<result column="id" property="id"/>
163+
<result column="workspace_id" property="workspaceId"/>
164+
<result column="project_id" property="projectId"/>
165+
<result column="username" property="username"/>
166+
<result column="priv" property="priv"/>
167+
<result column="last_update_time" property="lastUpdateTime"/>
168+
</resultMap>
169+
170+
<select id = "getOrchestratorUserByOrcId" resultMap="orchestrator_user_map" parameterType="java.lang.Long">
171+
select * from dss_orchestrator_user where `orchestrator_id` = #{orchestratorId}
172+
</select>
173+
174+
175+
176+
</mapper>

0 commit comments

Comments
 (0)