Skip to content

Commit

Permalink
add jupyter integration
Browse files Browse the repository at this point in the history
  • Loading branch information
cyjseagull committed Aug 28, 2024
1 parent 062c6c5 commit 1d29349
Show file tree
Hide file tree
Showing 11 changed files with 682 additions and 3 deletions.
3 changes: 3 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
7 changes: 4 additions & 3 deletions wedpr-adm/db/wedpr_ddl.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;
17 changes: 17 additions & 0 deletions wedpr-components/env-integration/jupyter/build.gradle
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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<JupyterInfoDO> queryJupyterInfos(@Param("condition") JupyterInfoDO condition);

public Integer queryJupyterRecordCount(@Param("condition") JupyterInfoDO condition);
}
Original file line number Diff line number Diff line change
@@ -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<JupyterInfoDO> 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);
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Loading

0 comments on commit 1d29349

Please sign in to comment.