Merge branch 'dev_jupyter' of https://bdgit.educoder.net/Hjqreturn/educoder into dev_jupyter

chromesetting
杨树林 5 years ago
commit b360366846

@ -103,3 +103,6 @@ gem 'diffy'
# oauth2 # oauth2
gem 'omniauth', '~> 1.9.0' gem 'omniauth', '~> 1.9.0'
gem 'omniauth-oauth2', '~> 1.6.0' gem 'omniauth-oauth2', '~> 1.6.0'
# global var
gem 'request_store'

@ -303,7 +303,7 @@ class ApplicationController < ActionController::Base
current_domain_session = session[:"#{default_yun_session}"] current_domain_session = session[:"#{default_yun_session}"]
if current_domain_session if current_domain_session
# existing session # existing session
(User.active.find(current_domain_session) rescue nil) User.current = (User.active.find(current_domain_session) rescue nil)
elsif autologin_user = try_to_autologin elsif autologin_user = try_to_autologin
autologin_user autologin_user
elsif params[:format] == 'atom' && params[:key] && request.get? && accept_rss_auth? elsif params[:format] == 'atom' && params[:key] && request.get? && accept_rss_auth?

@ -30,5 +30,17 @@ class JupytersController < ApplicationController
render json: {status: 0, url: url, port: port} render json: {status: 0, url: url, port: port}
end end
def reset_with_tpi
myshixun = Myshixun.find_by(identifier: params[:identifier])
info = jupyter_tpi_reset(myshixun)
render json: {status: 0, url: info[:url], port: info[:port]}
end
def reset_with_tpm
shixun = Shixun.find_by(identifier: params[:identifier])
info = jupyter_tpm_reset(shixun)
render json: {status: 0, url: info[:url], port: info[:port]}
end
end end

@ -38,12 +38,20 @@ class Laboratory < ApplicationRecord
find_by_identifier(subdomain) find_by_identifier(subdomain)
end end
def self.current=(laboratory) # def self.current=(laboratory)
Thread.current[:current_laboratory] = laboratory # Thread.current[:current_laboratory] = laboratory
# end
#
# def self.current
# Thread.current[:current_laboratory] ||= Laboratory.find(1)
# end
def self.current=(user)
RequestStore.store[:current_laboratory] = user
end end
def self.current def self.current
Thread.current[:current_laboratory] ||= Laboratory.find(1) RequestStore.store[:current_laboratory] ||= User.anonymous
end end
def shixuns def shixuns

@ -540,12 +540,20 @@ class User < ApplicationRecord
mail.present? mail.present?
end end
# def self.current=(user)
# Thread.current[:current_user] = user
# end
#
# def self.current
# Thread.current[:current_user] ||= User.anonymous
# end
def self.current=(user) def self.current=(user)
Thread.current[:current_user] = user RequestStore.store[:current_user] = user
end end
def self.current def self.current
Thread.current[:current_user] ||= User.anonymous RequestStore.store[:current_user] ||= User.anonymous
end end
def self.anonymous def self.anonymous

@ -7,7 +7,7 @@ module JupyterService
shixun_tomcat = edu_setting('cloud_bridge') shixun_tomcat = edu_setting('cloud_bridge')
uri = "#{shixun_tomcat}/bridge/jupyter/get" uri = "#{shixun_tomcat}/bridge/jupyter/get"
tpiID = "tpm#{shixun.id}" tpiID = "tpm#{shixun.id}"
params = {tpiID: tpiID, :containers => "#{Base64.urlsafe_encode64(shixun_container_limit(shixun))}"} params = {tpiID: tpiID, identifier: shixun.identifier, :containers => "#{Base64.urlsafe_encode64(shixun_container_limit(shixun))}"}
logger.info "test_juypter: uri->#{uri}, params->#{params}" logger.info "test_juypter: uri->#{uri}, params->#{params}"
res = uri_post uri, params res = uri_post uri, params
@ -45,7 +45,7 @@ module JupyterService
uri = "#{shixun_tomcat}/bridge/jupyter/get" uri = "#{shixun_tomcat}/bridge/jupyter/get"
tpiID = myshixun.id tpiID = myshixun.id
params = {tpiID: tpiID, :containers => "#{Base64.urlsafe_encode64(shixun_container_limit(shixun))}"} params = {tpiID: tpiID, identifier: shixun.identifier, :containers => "#{Base64.urlsafe_encode64(shixun_container_limit(shixun))}"}
res = uri_post uri, params res = uri_post uri, params
logger.info "test_juypter: #{res}" logger.info "test_juypter: #{res}"
@ -130,4 +130,59 @@ module JupyterService
end end
##重置jupyter环境
def jupyter_tpi_reset(myshixun)
jupyter_delete_tpi(myshixun)
url = jupyter_url_with_game(myshixun)
port = jupyter_port_with_game(myshixun)
{url: url, port: port}
end
## 重置tpm环境
def jupyter_tpm_reset(shixun)
jupyter_delete_tpm(shixun)
url = jupyter_url_with_shixun(shixun)
port = jupyter_port_with_shixun(shixun)
{url: url, port: port}
end
# 删除pod
def jupyter_delete_tpi(myshixun)
myshixun_id = myshixun.id
digest = myshixun.identifier + edu_setting('bridge_secret_key')
digest_key = Digest::SHA1.hexdigest("#{digest}")
begin
shixun_tomcat = edu_setting('cloud_bridge')
uri = "#{shixun_tomcat}/bridge/jupyter/delete"
Rails.logger.info("#{current_user} => cloese_jupyter digest is #{digest}")
params = {:tpiID => myshixun_id, :digestKey => digest_key, :identifier => myshixun.identifier}
res = uri_post uri, params
if res && res['code'].to_i != 0
raise("实训云平台繁忙繁忙等级110")
end
end
end
def jupyter_delete_tpm(shixun)
tpiID = "tpm#{shixun.id}"
digest = shixun.identifier + edu_setting('bridge_secret_key')
digest_key = Digest::SHA1.hexdigest("#{digest}")
begin
shixun_tomcat = edu_setting('cloud_bridge')
uri = "#{shixun_tomcat}/bridge/jupyter/delete"
Rails.logger.info("#{current_user} => cloese_jupyter digest is #{digest}")
params = {:tpiID => tpiID, :digestKey => digest_key, :identifier => shixun.identifier}
res = uri_post uri, params
if res && res['code'].to_i != 0
raise("实训云平台繁忙繁忙等级110")
end
end
end
end end

@ -31,6 +31,8 @@ Rails.application.routes.draw do
get :save_with_tpm get :save_with_tpm
get :get_info_with_tpi get :get_info_with_tpi
get :get_info_with_tpm get :get_info_with_tpm
get :reset_with_tpi
get :reset_with_tpm
end end
end end

@ -69,16 +69,16 @@ export default class Shixuninformation extends Component {
} }
componentDidMount() { componentDidMount() {
if (this.props.data&&this.props.data.shixun) { if (this.props.data) {
if (this.props.data.shixun) {
this.setState({ this.setState({
can_copy:this.props.data.shixun && this.props.data.shixun.can_copy === undefined ? false : this.props.data.shixun&&this.props.data.shixun.can_copy, can_copy: this.props.data && this.props.data.shixun.can_copy === undefined ? false : this.props.data && this.props.data.shixun.can_copy,
use_scope: this.props.data.shixun && this.props.data.shixun.use_scope, use_scope: this.props.data && this.props.data.shixun.use_scope,
opening_time: this.props.data.shixun && this.props.data.shixun.opening_time, opening_time: this.props.data && this.props.data.shixun.opening_time,
opentime: !this.props.data.shixun && this.props.data.shixun.opening_time ? false : true, opentime: !this.props.data && this.props.data.shixun.opening_time ? false : true,
oldscope_partment:this.props.data.shixun && this.props.data.shixun.scope_partment, oldscope_partment: this.props.data && this.props.data.shixun.scope_partment,
}) })
}
} }
let departmentsUrl = `/shixuns/departments.json`; let departmentsUrl = `/shixuns/departments.json`;
axios.get(departmentsUrl).then((response) => { axios.get(departmentsUrl).then((response) => {
@ -98,15 +98,15 @@ export default class Shixuninformation extends Component {
componentDidUpdate(prevProps, prevState) { componentDidUpdate(prevProps, prevState) {
if (prevProps.data != this.props.data) { if (prevProps.data != this.props.data) {
if (this.props.data) { if (this.props.data) {
if (this.props.data.shixun) {
this.setState({ this.setState({
can_copy: this.props.data.shixun && this.props.data.shixun.can_copy === undefined ? false : this.props.data.shixun&&this.props.data.shixun.can_copy, can_copy: this.props.data && this.props.data.shixun.can_copy === undefined ? false : this.props.data && this.props.data.shixun.can_copy,
use_scope: this.props.data.shixun&& this.props.data.shixun.use_scope, use_scope: this.props.data && this.props.data.shixun.use_scope,
opening_time: this.props.data.shixun && this.props.data.shixun.opening_time, opening_time: this.props.data && this.props.data.shixun.opening_time,
opentime: !this.props.data.shixun && this.props.data.shixun.opening_time ? false : true, opentime: !this.props.data && this.props.data.shixun.opening_time ? false : true,
oldscope_partment: this.props.data.shixun && this.props.data.shixun.scope_partment, oldscope_partment: this.props.data && this.props.data.shixun.scope_partment,
}) })
}
} }
} }
} }
@ -262,7 +262,7 @@ export default class Shixuninformation extends Component {
</div> </div>
<div className="edu-back-white mb10 ml30 mt20"> <div className="edu-back-white mb10 ml30 mt20">
{this.props.data.shixun && this.props.data.shixun.use_scope === 0 && this.props.data.shixun && this.props.data.shixun.status === 2 ? "" : {this.props.data && this.props.data.shixun.use_scope === 0 && this.props.data && this.props.data.shixun.status === 2 ? "" :
<div> <div>
<span className="color-grey-6 mt5 fl font-16" style={{minWidth: '45px'}}>公开程度:</span> <span className="color-grey-6 mt5 fl font-16" style={{minWidth: '45px'}}>公开程度:</span>
<span className="fl mt8 ml20"> <span className="fl mt8 ml20">

@ -34,8 +34,8 @@ export default class Shixuninformation extends Component {
componentDidMount() { componentDidMount() {
if (this.props.data&&this.props.data.shixun) { if (this.props.data ) {
if (this.props.data.shixun) {
this.setState({ this.setState({
vnc: this.props.data && this.props.data.shixun.vnc, vnc: this.props.data && this.props.data.shixun.vnc,
code_hidden: this.props.data && this.props.data.shixun.code_hidden, code_hidden: this.props.data && this.props.data.shixun.code_hidden,
@ -56,13 +56,14 @@ export default class Shixuninformation extends Component {
// } // }
} }
}
} }
componentDidUpdate(prevProps, prevState) { componentDidUpdate(prevProps, prevState) {
if (prevProps.data != this.props.data) { if (prevProps.data != this.props.data) {
if (this.props.data) { if (this.props.data) {
if (this.props.data.shixun) {
this.setState({ this.setState({
vnc: this.props.data && this.props.data.shixun.vnc, vnc: this.props.data && this.props.data.shixun.vnc,
code_hidden: this.props.data && this.props.data.shixun.code_hidden, code_hidden: this.props.data && this.props.data.shixun.code_hidden,
@ -85,6 +86,7 @@ export default class Shixuninformation extends Component {
} }
} }
} }
}
onSubmits = () => { onSubmits = () => {

@ -55,38 +55,40 @@ class Shixuninformation extends Component {
componentDidUpdate(prevProps, prevState) { componentDidUpdate(prevProps, prevState) {
if (prevProps.data != this.props.data) { if (prevProps.data != this.props.data) {
if (this.props.data&&this.props.data.shixun) {
if (this.props.data ) {
if (this.props.data.shixun){
this.setState({ this.setState({
shixunName: this.props.data.shixun&&this.props.data.shixun.name, shixunName: this.props.data && this.props.data.shixun.name,
trainee:this.props.data.shixun&&this.props.data.shixun.trainee, trainee: this.props.data && this.props.data.shixun.trainee,
choice_main_type: this.props.data.shixun&&this.props.data.shixun.choice_main_type, choice_main_type: this.props.data && this.props.data.shixun.choice_main_type,
choice_small_type: this.props.data.shixun&&this.props.data.shixun.choice_small_type, choice_small_type: this.props.data && this.props.data.shixun.choice_small_type,
choice_standard_scripts:this.props.data.shixun&&this.props.data.shixun.choice_standard_scripts, choice_standard_scripts: this.props.data && this.props.data.shixun.choice_standard_scripts,
shixunmemoMDvalue: this.props.data.shixun&&this.props.data.shixun.evaluate_script, shixunmemoMDvalue: this.props.data && this.props.data.shixun.evaluate_script,
simichecked: this.props.data.shixun&&this.props.data.shixun.is_secret_repository, simichecked: this.props.data && this.props.data.shixun.is_secret_repository,
shixun_service_configs: this.props.data.shixun&&this.props.data.shixun.shixun_service_configs, shixun_service_configs: this.props.data && this.props.data.shixun.shixun_service_configs,
standard_scripts:this.props.data.shixun&&this.props.data.shixun.standard_scripts, standard_scripts: this.props.data && this.props.data.shixun.standard_scripts,
shixun_service_configlist:this.props.data.shixun&&this.props.data.shixun.shixun_service_configs, shixun_service_configlist: this.props.data && this.props.data.shixun.shixun_service_configs,
}) })
if(this.props.data.shixun&&this.props.data.shixun.choice_standard_scripts===null){ if (this.props.data && this.props.data.shixun.choice_standard_scripts === null) {
this.setState({ this.setState({
choice_standard_scripts:{id: this.props.data.shixun&&this.props.data.shixun.standard_scripts[0].id, value: ""}, choice_standard_scripts: {id: this.props.data && this.props.data.shixun.standard_scripts[0].id, value: ""},
choice_standard_scriptssum:this.props.data.shixun&&this.props.data.shixun.standard_scripts[0].id choice_standard_scriptssum: this.props.data && this.props.data.shixun.standard_scripts[0].id
}) })
this.props.form.setFieldsValue({ this.props.form.setFieldsValue({
selectscripts:this.props.data.shixun&&this.props.data.shixun.standard_scripts[0].id selectscripts: this.props.data && this.props.data.shixun.standard_scripts[0].id
}) })
this.get_mirror_script(this.props.data.shixun&&this.props.data.shixun.standard_scripts[0].id) this.get_mirror_script(this.props.data && this.props.data.shixun.standard_scripts[0].id)
} else { } else {
this.props.form.setFieldsValue({ this.props.form.setFieldsValue({
selectscripts:this.props.data.shixun&&this.props.data.shixun.choice_standard_scripts selectscripts: this.props.data && this.props.data.shixun.choice_standard_scripts
}) })
} }
let newlist = "" let newlist = ""
this.props.data.shixun&&this.props.data.shixun.choice_small_type.map((item, key) => { this.props.data && this.props.data.shixun.choice_small_type.map((item, key) => {
this.props.data.shixun.small_type.map((i,k)=>{ this.props.data && this.props.data.shixun.small_type.map((i, k) => {
if (item === i.id) { if (item === i.id) {
newlist = newlist + `${i.description}` newlist = newlist + `${i.description}`
} }
@ -96,8 +98,8 @@ class Shixuninformation extends Component {
subvalues: newlist subvalues: newlist
}) })
this.props.data.shixun&&this.props.data.shixun.main_type.map((item,key)=>{ this.props.data && this.props.data.shixun.main_type.map((item, key) => {
if(item.id===this.props.data.shixun&&this.props.data.shixun.choice_main_type){ if (item.id === this.props.data && this.props.data.shixun.choice_main_type) {
this.setState({ this.setState({
mainvalues: item.description, mainvalues: item.description,
}) })
@ -105,12 +107,13 @@ class Shixuninformation extends Component {
}) })
this.props.form.setFieldsValue({ this.props.form.setFieldsValue({
name:this.props.data.shixun&&this.props.data.shixun.name, name: this.props.data && this.props.data.shixun.name,
trainee: this.props.data.shixun&&this.props.data.shixun.trainee, trainee: this.props.data && this.props.data.shixun.trainee,
selectleft: this.props.data.shixun&&this.props.data.shixun.choice_main_type, selectleft: this.props.data && this.props.data.shixun.choice_main_type,
selectright:this.props.data.shixun&&this.props.data.shixun.choice_small_type, selectright: this.props.data && this.props.data.shixun.choice_small_type,
}) })
this.contentMdRef.current.setValue(this.props.data.shixun&&this.props.data.shixun.description); this.contentMdRef.current.setValue(this.props.data && this.props.data.shixun.description);
}
} }
} }
} }
@ -754,7 +757,7 @@ class Shixuninformation extends Component {
return isLt150M; return isLt150M;
}, },
} }
let operateauthority = this.props.identity === 1 ? true : this.props.identity < 5 && this.props.data.shixun&&this.props.data.shixun.status == 0 ? true : false; let operateauthority = this.props.identity === 1 ? true : this.props.identity < 5 && this.props.data&&this.props.data.shixun.status == 0 ? true : false;
return ( return (
<div> <div>
<div className="educontent mb50 edu-back-white padding10-20"> <div className="educontent mb50 edu-back-white padding10-20">

@ -6,6 +6,8 @@ import {
Modal Modal
} from 'antd'; } from 'antd';
import './css/TPMsettings.css';
import TopShixuninformation from './Shixuninformation'; import TopShixuninformation from './Shixuninformation';
import Configuration from './Configuration'; import Configuration from './Configuration';
@ -14,8 +16,6 @@ import LearningSettings from './LearningSettings';
import axios from 'axios'; import axios from 'axios';
import './css/TPMsettings.css';
const {TabPane} = Tabs; const {TabPane} = Tabs;
// 处理整点 半点 // 处理整点 半点

Loading…
Cancel
Save