From 1d29349546a3a5d7f8f941a881319c218ba0cb72 Mon Sep 17 00:00:00 2001 From: cyjseagull Date: Wed, 28 Aug 2024 11:26:27 +0800 Subject: [PATCH] add jupyter integration --- settings.gradle | 3 + wedpr-adm/db/wedpr_ddl.sql | 7 +- .../env-integration/jupyter/build.gradle | 17 ++ .../jupyter/core/JupyterStatus.java | 55 +++++++ .../jupyter/dao/JupyterInfoDO.java | 63 ++++++++ .../jupyter/dao/JupyterMapper.java | 58 +++++++ .../jupyter/service/JupyterService.java | 64 ++++++++ .../jupyter/service/impl/JupyterConfig.java | 39 +++++ .../jupyter/service/impl/JupyterManager.java | 150 ++++++++++++++++++ .../service/impl/JupyterServiceImpl.java | 101 ++++++++++++ .../main/resources/mapper/JupyterMapper.xml | 128 +++++++++++++++ 11 files changed, 682 insertions(+), 3 deletions(-) create mode 100644 wedpr-components/env-integration/jupyter/build.gradle create mode 100644 wedpr-components/env-integration/jupyter/src/main/java/com/webank/wedpr/components/integration/jupyter/core/JupyterStatus.java create mode 100644 wedpr-components/env-integration/jupyter/src/main/java/com/webank/wedpr/components/integration/jupyter/dao/JupyterInfoDO.java create mode 100644 wedpr-components/env-integration/jupyter/src/main/java/com/webank/wedpr/components/integration/jupyter/dao/JupyterMapper.java create mode 100644 wedpr-components/env-integration/jupyter/src/main/java/com/webank/wedpr/components/integration/jupyter/service/JupyterService.java create mode 100644 wedpr-components/env-integration/jupyter/src/main/java/com/webank/wedpr/components/integration/jupyter/service/impl/JupyterConfig.java create mode 100644 wedpr-components/env-integration/jupyter/src/main/java/com/webank/wedpr/components/integration/jupyter/service/impl/JupyterManager.java create mode 100644 wedpr-components/env-integration/jupyter/src/main/java/com/webank/wedpr/components/integration/jupyter/service/impl/JupyterServiceImpl.java create mode 100644 wedpr-components/env-integration/jupyter/src/main/resources/mapper/JupyterMapper.xml diff --git a/settings.gradle b/settings.gradle index 8c1a4a30..17fe1d6a 100644 --- a/settings.gradle +++ b/settings.gradle @@ -68,6 +68,9 @@ project(":wedpr-components-task-plugin-shell").projectDir=file("wedpr-components include ":wedpr-components-spi" project(":wedpr-components-spi").projectDir=file("wedpr-components/spi") +include ":wedpr-components-jupyter-intergration" +project(":wedpr-components-jupyter-intergration").projectDir=file("wedpr-components/env-integration/jupyter") + include "wedpr-components-user" project(":wedpr-components-user").projectDir=file("wedpr-components/user") diff --git a/wedpr-adm/db/wedpr_ddl.sql b/wedpr-adm/db/wedpr_ddl.sql index b5507fe2..7acf74f5 100644 --- a/wedpr-adm/db/wedpr_ddl.sql +++ b/wedpr-adm/db/wedpr_ddl.sql @@ -295,12 +295,13 @@ create table if not exists `wedpr_jupyter_table`( `id` varchar(64) not null comment "Jupyter资源的ID", `owner` varchar(255) not null comment "Jupyter属主", `agency` varchar(255) not null comment "Jupyter所属机构", - `access_entrypoint` text comment "Jupyter访问入口", + `access_entrypoint` varchar(1024) comment "Jupyter访问入口", `setting` longtext comment "Jupyter配置", - `status` int comment "Jupyter状态", + `status` varchar(1024) comment "Jupyter状态", `create_time` DATETIME DEFAULT CURRENT_TIMESTAMP comment "创建时间", `last_update_time` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP comment "更新时间", PRIMARY KEY (id), index owner_index(`owner`(128)), - index status_index(`status`) + index status_index(`status`(128)), + index access_entrypoint_index(`access_entrypoint`(128)) )ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=DYNAMIC; diff --git a/wedpr-components/env-integration/jupyter/build.gradle b/wedpr-components/env-integration/jupyter/build.gradle new file mode 100644 index 00000000..cf858da8 --- /dev/null +++ b/wedpr-components/env-integration/jupyter/build.gradle @@ -0,0 +1,17 @@ +// Apply the java-library plugin to add support for Java Library +plugins { + id 'java' + id 'com.github.sherter.google-java-format' +} +dependencies{ + compile project(":wedpr-components-mybatis") + compile project(":wedpr-components-uuid") + compile project(":wedpr-components-sys-config") +} +googleJavaFormat { + //toolVersion = '1.7' + options style: 'AOSP' + source = sourceSets*.allJava + include '**/*.java' + //source = *.allJava +} diff --git a/wedpr-components/env-integration/jupyter/src/main/java/com/webank/wedpr/components/integration/jupyter/core/JupyterStatus.java b/wedpr-components/env-integration/jupyter/src/main/java/com/webank/wedpr/components/integration/jupyter/core/JupyterStatus.java new file mode 100644 index 00000000..2d489c49 --- /dev/null +++ b/wedpr-components/env-integration/jupyter/src/main/java/com/webank/wedpr/components/integration/jupyter/core/JupyterStatus.java @@ -0,0 +1,55 @@ +/* + * Copyright 2017-2025 [webank-wedpr] + * + * Licensed 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 com.webank.wedpr.components.integration.jupyter.core; + +import org.apache.commons.lang3.StringUtils; + +public enum JupyterStatus { + Ready("Ready"), + Running("Running"), + OpenFailed("OpenFailed"), + Closed("Closed"); + + private final String status; + + JupyterStatus(String status) { + this.status = status; + } + + public String getStatus() { + return this.status; + } + + public static JupyterStatus deserialize(String status) { + if (StringUtils.isBlank(status)) { + return null; + } + for (JupyterStatus jupyterStatus : JupyterStatus.values()) { + if (jupyterStatus.status.compareToIgnoreCase(status) == 0) { + return jupyterStatus; + } + } + return null; + } + + public boolean isRunning() { + return ordinal() == JupyterStatus.Running.ordinal(); + } + + public boolean isClosed() { + return ordinal() == JupyterStatus.Closed.ordinal(); + } +} diff --git a/wedpr-components/env-integration/jupyter/src/main/java/com/webank/wedpr/components/integration/jupyter/dao/JupyterInfoDO.java b/wedpr-components/env-integration/jupyter/src/main/java/com/webank/wedpr/components/integration/jupyter/dao/JupyterInfoDO.java new file mode 100644 index 00000000..9c214999 --- /dev/null +++ b/wedpr-components/env-integration/jupyter/src/main/java/com/webank/wedpr/components/integration/jupyter/dao/JupyterInfoDO.java @@ -0,0 +1,63 @@ +/* + * Copyright 2017-2025 [webank-wedpr] + * + * Licensed 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 com.webank.wedpr.components.integration.jupyter.dao; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.webank.wedpr.components.integration.jupyter.core.JupyterStatus; +import com.webank.wedpr.components.uuid.generator.WeDPRUuidGenerator; +import com.webank.wedpr.core.utils.TimeRange; +import lombok.Data; + +@Data +public class JupyterInfoDO extends TimeRange { + private String id = WeDPRUuidGenerator.generateID(); + private String owner; + private String agency; + private String accessEntry; + private String setting; + private String status; + private String createTime; + private String lastUpdateTime; + @JsonIgnore private JupyterStatus jupyterStatus; + + public JupyterInfoDO() {} + + public JupyterInfoDO(boolean resetID) { + if (resetID) { + setId(null); + } + } + + public JupyterInfoDO(String id) { + setId(id); + } + + public void setStatus(String status) { + this.status = status; + if (this.status.isEmpty()) { + return; + } + this.jupyterStatus = JupyterStatus.deserialize(status); + } + + public void setJupyterStatus(JupyterStatus jupyterStatus) { + this.jupyterStatus = jupyterStatus; + if (jupyterStatus == null) { + return; + } + this.status = jupyterStatus.getStatus(); + } +} diff --git a/wedpr-components/env-integration/jupyter/src/main/java/com/webank/wedpr/components/integration/jupyter/dao/JupyterMapper.java b/wedpr-components/env-integration/jupyter/src/main/java/com/webank/wedpr/components/integration/jupyter/dao/JupyterMapper.java new file mode 100644 index 00000000..0214c73d --- /dev/null +++ b/wedpr-components/env-integration/jupyter/src/main/java/com/webank/wedpr/components/integration/jupyter/dao/JupyterMapper.java @@ -0,0 +1,58 @@ +/* + * Copyright 2017-2025 [webank-wedpr] + * + * Licensed 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 com.webank.wedpr.components.integration.jupyter.dao; + +import java.util.List; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +@Mapper +public interface JupyterMapper { + /** + * insert the jupyter record + * + * @param jupyterInfo the jupyter record to be inserted into + * @return + */ + public int insertJupyterInfo(@Param("jupyterInfo") JupyterInfoDO jupyterInfo); + + /** + * update the jupyter record + * + * @param id the jupyter record that need to be updated + * @param updatedInfo the updated info + * @return + */ + public int updateJupyterInfo(@Param("updatedInfo") JupyterInfoDO updatedInfo); + + /** + * delete the jupyter record + * + * @param id the jupyter that need to be deleted + * @return + */ + public Integer deleteJupyterInfo(@Param("id") String id, @Param("owner") String owner); + + /** + * query the jupyter information by condition + * + * @param condition the condition used to query + * @return the result + */ + public List queryJupyterInfos(@Param("condition") JupyterInfoDO condition); + + public Integer queryJupyterRecordCount(@Param("condition") JupyterInfoDO condition); +} diff --git a/wedpr-components/env-integration/jupyter/src/main/java/com/webank/wedpr/components/integration/jupyter/service/JupyterService.java b/wedpr-components/env-integration/jupyter/src/main/java/com/webank/wedpr/components/integration/jupyter/service/JupyterService.java new file mode 100644 index 00000000..2be90e12 --- /dev/null +++ b/wedpr-components/env-integration/jupyter/src/main/java/com/webank/wedpr/components/integration/jupyter/service/JupyterService.java @@ -0,0 +1,64 @@ +/* + * Copyright 2017-2025 [webank-wedpr] + * + * Licensed 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 com.webank.wedpr.components.integration.jupyter.service; + +import com.webank.wedpr.components.integration.jupyter.dao.JupyterInfoDO; +import java.util.List; + +public interface JupyterService { + + /** + * allocate the jupyter environment for given user + * + * @param user the user that apply the jupyter + * @param agency the agency of the person + * @return success or failed + */ + public abstract String allocate(String user, String agency) throws Exception; + + /** + * query jupyters by condition + * + * @param condition + * @return + */ + public abstract List queryJupyters( + boolean admin, String queryUser, JupyterInfoDO condition) throws Exception; + + /** + * open the jupyter according to given id + * + * @param id the jupyter id + * @return success/failed + */ + public abstract JupyterInfoDO open(String currentUser, String id) throws Exception; + + /** + * close the jupyter according to given id + * + * @param id specify the jupyter to close + * @return success/failed + */ + public abstract JupyterInfoDO close(String currentUser, String id) throws Exception; + + /** + * destroy the specified jupyter + * + * @param id specify the jupyter to destory + * @return success/failed + */ + public abstract boolean destroy(boolean admin, String currentUser, String id); +} diff --git a/wedpr-components/env-integration/jupyter/src/main/java/com/webank/wedpr/components/integration/jupyter/service/impl/JupyterConfig.java b/wedpr-components/env-integration/jupyter/src/main/java/com/webank/wedpr/components/integration/jupyter/service/impl/JupyterConfig.java new file mode 100644 index 00000000..f4badfa9 --- /dev/null +++ b/wedpr-components/env-integration/jupyter/src/main/java/com/webank/wedpr/components/integration/jupyter/service/impl/JupyterConfig.java @@ -0,0 +1,39 @@ +/* + * Copyright 2017-2025 [webank-wedpr] + * + * Licensed 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 com.webank.wedpr.components.integration.jupyter.service.impl; + +import com.webank.wedpr.core.config.WeDPRConfig; + +public class JupyterConfig { + + private static Integer MAX_JUPYTER_PER_HOST = + WeDPRConfig.apply("wedpr.jupyter.max_count_per_host", 3); + private static String JUPYTER_HOST_CONFIGUATINON_KEY = + WeDPRConfig.apply("wedpr.jupyter.host_configuration_key", "jupyter_entrypoints"); + private static String JUPYTER_ENTRYPOINT_SPLITTER = ";"; + + public static String getJupyterHostConfiguatinonKey() { + return JUPYTER_HOST_CONFIGUATINON_KEY; + } + + public static Integer getMaxJupyterPerHost() { + return MAX_JUPYTER_PER_HOST; + } + + public static String getJupyterEntrypointSplitter() { + return JUPYTER_ENTRYPOINT_SPLITTER; + } +} diff --git a/wedpr-components/env-integration/jupyter/src/main/java/com/webank/wedpr/components/integration/jupyter/service/impl/JupyterManager.java b/wedpr-components/env-integration/jupyter/src/main/java/com/webank/wedpr/components/integration/jupyter/service/impl/JupyterManager.java new file mode 100644 index 00000000..f2041cd2 --- /dev/null +++ b/wedpr-components/env-integration/jupyter/src/main/java/com/webank/wedpr/components/integration/jupyter/service/impl/JupyterManager.java @@ -0,0 +1,150 @@ +/* + * Copyright 2017-2025 [webank-wedpr] + * + * Licensed 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 com.webank.wedpr.components.integration.jupyter.service.impl; + +import com.webank.wedpr.components.integration.jupyter.core.JupyterStatus; +import com.webank.wedpr.components.integration.jupyter.dao.JupyterInfoDO; +import com.webank.wedpr.components.integration.jupyter.dao.JupyterMapper; +import com.webank.wedpr.components.meta.sys.config.dao.SysConfigMapper; +import com.webank.wedpr.core.config.WeDPRCommonConfig; +import com.webank.wedpr.core.utils.WeDPRException; +import java.util.Arrays; +import java.util.List; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class JupyterManager { + private static final Logger logger = LoggerFactory.getLogger(JupyterManager.class); + private final SysConfigMapper sysConfigMapper; + private final JupyterMapper jupyterMapper; + + public JupyterManager(SysConfigMapper sysConfigMapper, JupyterMapper jupyterMapper) { + this.sysConfigMapper = sysConfigMapper; + this.jupyterMapper = jupyterMapper; + } + + protected List getJupyterEntryPoints() { + List entryPoints = + Arrays.asList( + this.sysConfigMapper + .queryConfig(JupyterConfig.getJupyterHostConfiguatinonKey()) + .getConfigValue() + .split(JupyterConfig.getJupyterEntrypointSplitter())); + // TODO: check the entryPoints + entryPoints.removeIf(s -> s.trim().isEmpty()); + return entryPoints; + } + + protected List queryJupyter(String user, String agency, String id) { + JupyterInfoDO condition = new JupyterInfoDO(true); + condition.setOwner(user); + condition.setAgency(agency); + condition.setId(id); + return jupyterMapper.queryJupyterInfos(condition); + } + + protected void updateJupyterStatus(String id, JupyterStatus status) { + JupyterInfoDO updatedInfo = new JupyterInfoDO(id); + updatedInfo.setStatus(status.getStatus()); + jupyterMapper.updateJupyterInfo(updatedInfo); + } + + // destroy the jupyter for given person + public synchronized Integer deleteJupyter(String user, String jupyterID) { + logger.info("deleteJupyter, user: {}, jupyterID: {}", user, jupyterID); + return this.jupyterMapper.deleteJupyterInfo(jupyterID, user); + } + + protected JupyterInfoDO checkJupyterExistence(String user, String jupyterID) throws Exception { + List result = queryJupyter(user, WeDPRCommonConfig.getAgency(), jupyterID); + if (result == null || result.isEmpty()) { + throw new WeDPRException("The jupyter" + jupyterID + " not belongs to user " + user); + } + return result.get(0); + } + + public JupyterInfoDO openJupyter(String user, String jupyterID) throws Exception { + JupyterInfoDO result = checkJupyterExistence(user, jupyterID); + // the jupyter is already in running status + if (result.getJupyterStatus() != null && result.getJupyterStatus().isRunning()) { + logger.info("the jupyter is already running, id: {}", jupyterID); + return result; + } + // TODO: open the jupyter + // update the status to running + updateJupyterStatus(jupyterID, JupyterStatus.Running); + result.setJupyterStatus(JupyterStatus.Running); + return result; + } + + public JupyterInfoDO closeJupyter(String user, String jupyterID) throws Exception { + JupyterInfoDO result = checkJupyterExistence(user, jupyterID); + // the jupyter is already in closed status + if (result.getJupyterStatus() != null && result.getJupyterStatus().isClosed()) { + logger.info("the jupyter is already closed, id: {}", jupyterID); + return result; + } + // TODO: close the jupyter + // update the jupyter to closed + updateJupyterStatus(jupyterID, JupyterStatus.Closed); + result.setJupyterStatus(JupyterStatus.Closed); + return result; + } + + // allocate the jupyter for given person + public synchronized String allocateJupyter(String user, String agency) throws Exception { + // check the user has jupyter or not + if (!queryJupyter(user, agency, null).isEmpty()) { + throw new WeDPRException( + "User " + + user + + " has already allocated the jupyter, one user can only occupy one jupyter-notebook!"); + } + // try to allocate the jupyter for new user + List accessEntryPoints = getJupyterEntryPoints(); + if (accessEntryPoints.isEmpty()) { + throw new WeDPRException("No jupyter resource now!"); + } + // query the allocated jupyter + JupyterInfoDO condition = new JupyterInfoDO(true); + String allocatedEntrypoint = null; + for (String entrypoint : accessEntryPoints) { + condition.setAgency(entrypoint); + Integer allocatedCount = jupyterMapper.queryJupyterRecordCount(condition); + if (allocatedCount >= JupyterConfig.getMaxJupyterPerHost()) { + continue; + } else { + allocatedEntrypoint = entrypoint; + } + } + if (allocatedEntrypoint == null) { + throw new WeDPRException("Insufficient jupyter resources!"); + } + logger.info( + "allocateJupyter, user: {}, agency: {}, entrypoint: {}", + user, + agency, + allocatedEntrypoint); + // insert the information + JupyterInfoDO allocatedJupyter = new JupyterInfoDO(); + allocatedJupyter.setAgency(agency); + allocatedJupyter.setOwner(user); + allocatedJupyter.setAccessEntry(allocatedEntrypoint); + // TODO: set the settings + allocatedJupyter.setStatus(JupyterStatus.Ready.getStatus()); + jupyterMapper.insertJupyterInfo(allocatedJupyter); + return allocatedJupyter.getId(); + } +} diff --git a/wedpr-components/env-integration/jupyter/src/main/java/com/webank/wedpr/components/integration/jupyter/service/impl/JupyterServiceImpl.java b/wedpr-components/env-integration/jupyter/src/main/java/com/webank/wedpr/components/integration/jupyter/service/impl/JupyterServiceImpl.java new file mode 100644 index 00000000..c68b18d6 --- /dev/null +++ b/wedpr-components/env-integration/jupyter/src/main/java/com/webank/wedpr/components/integration/jupyter/service/impl/JupyterServiceImpl.java @@ -0,0 +1,101 @@ +/* + * Copyright 2017-2025 [webank-wedpr] + * + * Licensed 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 com.webank.wedpr.components.integration.jupyter.service.impl; + +import com.webank.wedpr.components.integration.jupyter.dao.JupyterInfoDO; +import com.webank.wedpr.components.integration.jupyter.dao.JupyterMapper; +import com.webank.wedpr.components.integration.jupyter.service.JupyterService; +import com.webank.wedpr.components.meta.sys.config.dao.SysConfigMapper; +import com.webank.wedpr.core.config.WeDPRCommonConfig; +import java.util.List; +import javax.annotation.PostConstruct; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class JupyterServiceImpl implements JupyterService { + private static final Logger logger = LoggerFactory.getLogger(JupyterServiceImpl.class); + + private @Autowired SysConfigMapper sysConfigMapper; + private @Autowired JupyterMapper jupyterMapper; + private JupyterManager jupyterManager; + + @PostConstruct + public void init() { + this.jupyterManager = new JupyterManager(sysConfigMapper, jupyterMapper); + } + /** + * allocate the jupyter environment for given user + * + * @param user the user that apply the jupyter + * @param agency the agency of the person + * @return success or failed + */ + public String allocate(String user, String agency) throws Exception { + return this.jupyterManager.allocateJupyter(user, agency); + } + + /** + * query jupyters by condition + * + * @param condition + * @return + */ + public List queryJupyters( + boolean admin, String queryUser, JupyterInfoDO condition) throws Exception { + if (!admin) { + condition.setOwner(queryUser); + condition.setAgency(WeDPRCommonConfig.getAgency()); + } + return jupyterMapper.queryJupyterInfos(condition); + } + + /** + * destroy the specified jupyter + * + * @param id specify the jupyter to destory + * @return success/failed + */ + public boolean destroy(boolean admin, String currentUser, String id) { + // the admin can delete all jupyter + if (admin) { + return jupyterManager.deleteJupyter(null, id) > 0 ? true : false; + } + return jupyterMapper.deleteJupyterInfo(currentUser, id) > 0 ? true : false; + } + + /** + * open the jupyter according to given id + * + * @param id the jupyter id + * @return success/failed + */ + public JupyterInfoDO open(String currentUser, String id) throws Exception { + return this.jupyterManager.openJupyter(currentUser, id); + } + + /** + * close the jupyter according to given id + * + * @param id specify the jupyter to close + * @return success/failed + */ + public JupyterInfoDO close(String currentUser, String id) throws Exception { + return this.jupyterManager.closeJupyter(currentUser, id); + } +} diff --git a/wedpr-components/env-integration/jupyter/src/main/resources/mapper/JupyterMapper.xml b/wedpr-components/env-integration/jupyter/src/main/resources/mapper/JupyterMapper.xml new file mode 100644 index 00000000..432a1708 --- /dev/null +++ b/wedpr-components/env-integration/jupyter/src/main/resources/mapper/JupyterMapper.xml @@ -0,0 +1,128 @@ + + + + + + + + + + + + + + + + insert into wedpr_jupyter_table(`id`, `owner`, + `agency`, `access_entrypoint`, `setting`, `status`, `create_time`) values + (#{jupyterInfo.id}, #{jupyterInfo.owner}, #{jupyterInfo.agency}, #{jupyterInfo.accessEntry}, + #{jupyterInfo.setting}, #{jupyterInfo.status}, NOW()) + + + update `wedpr_jupyter_table` + + + `access_entrypoint` = #{updatedInfo.accessEntry}, + + + `setting` = #{updatedInfo.setting}, + + + `status` = #{updatedInfo.status}, + + + where 1=1 + + and `id` = #{updatedInfo.id}, + + + and `owner` = #{updatedInfo.owner}, + + + and `agency` = #{updatedInfo.agency}, + + + + public int deleteJupyterInfo(@Param("id")String id); + delete from `wedpr_jupyter_table` where `id` = #{id} + + and `owner` = #{owner} + + + + + \ No newline at end of file