|
|
|
@ -1,4 +1,3 @@
|
|
|
|
|
require 'net/http'
|
|
|
|
|
|
|
|
|
|
class JupytersController < ApplicationController
|
|
|
|
|
include JupyterService
|
|
|
|
@ -6,8 +5,8 @@ class JupytersController < ApplicationController
|
|
|
|
|
before_action :shixun, only: [:open, :open1, :test, :save]
|
|
|
|
|
|
|
|
|
|
def save_with_tpi
|
|
|
|
|
game = Game.find_by(identifier: params[:identifier])
|
|
|
|
|
jupyter_save_with_game(game, params[:jupyter_port])
|
|
|
|
|
myshixun = Myshixun.find_by(identifier: params[:identifier])
|
|
|
|
|
jupyter_save_with_game(myshixun, params[:jupyter_port])
|
|
|
|
|
render json: {status: 0}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
@ -18,9 +17,9 @@ class JupytersController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def get_info_with_tpi
|
|
|
|
|
game = Game.find_by(identifier: params[:identifier])
|
|
|
|
|
url = jupyter_url_with_game(game)
|
|
|
|
|
port = jupyter_port_with_game(game)
|
|
|
|
|
myshixun = Myshixun.find_by(identifier: params[:identifier])
|
|
|
|
|
url = jupyter_url_with_game(myshixun)
|
|
|
|
|
port = jupyter_port_with_game(myshixun)
|
|
|
|
|
render json: {status: 0, url: url, port: port}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
@ -32,89 +31,4 @@ class JupytersController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def open
|
|
|
|
|
#打开tpm - juypter接口
|
|
|
|
|
shixun = @shixun
|
|
|
|
|
shixun_tomcat = edu_setting('cloud_bridge')
|
|
|
|
|
uri = "#{shixun_tomcat}/bridge/jupyter/get"
|
|
|
|
|
tpiID = "tpm#{shixun.id}"
|
|
|
|
|
params = {tpiID: tpiID, :containers => "#{Base64.urlsafe_encode64(shixun_container_limit(shixun))}"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
logger.info "test_juypter: uri->#{uri}, params->#{params}"
|
|
|
|
|
|
|
|
|
|
res = uri_post uri, params
|
|
|
|
|
|
|
|
|
|
logger.info "test_juypter: #{res}"
|
|
|
|
|
|
|
|
|
|
render plain: "https://#{res['port']}.jupyter.educoder.net/notebooks/data/workspace/myshixun_#{tpiID}/01.ipynb"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def open1
|
|
|
|
|
## 打开tpi
|
|
|
|
|
game = Game.find(2170158)
|
|
|
|
|
shixun = game.myshixun.shixun
|
|
|
|
|
shixun_tomcat = edu_setting('cloud_bridge')
|
|
|
|
|
uri = "#{shixun_tomcat}/bridge/jupyter/get"
|
|
|
|
|
|
|
|
|
|
tpiID = game.myshixun.id
|
|
|
|
|
params = {tpiID: tpiID, :containers => "#{Base64.urlsafe_encode64(shixun_container_limit(shixun))}"}
|
|
|
|
|
res = uri_post uri, params
|
|
|
|
|
|
|
|
|
|
logger.info "test_juypter: #{res}"
|
|
|
|
|
|
|
|
|
|
if res && res['code'].to_i != 0
|
|
|
|
|
raise("实训云平台繁忙(繁忙等级:99)")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
repo_save_path = game.myshixun.repo_save_path
|
|
|
|
|
|
|
|
|
|
render plain: "https://#{res['port']}.jupyter.educoder.net/notebooks/data/workspace/myshixun_#{tpiID}/#{repo_save_path}/01.ipynb"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test
|
|
|
|
|
render plain: 'test'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def save()
|
|
|
|
|
# 保存01.ipy
|
|
|
|
|
|
|
|
|
|
author_name = current_user.real_name
|
|
|
|
|
author_email = current_user.git_mail
|
|
|
|
|
message = "User submitted"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#https://47526.jupyter.educoder.net/nbconvert/notebook/data/workspace/myshixun_570461/f2ef5p798r20191210163135/01.ipynb?download=true
|
|
|
|
|
src_url = URI("https://47519.jupyter.educoder.net/nbconvert/notebook/data/workspace/myshixun_tpm3575/01.ipynb?download=true")
|
|
|
|
|
response = Net::HTTP.get_response(src_url)
|
|
|
|
|
|
|
|
|
|
if response.code.to_i != 200
|
|
|
|
|
raise("获取文件内容失败:#{response.code}")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
content = response.body
|
|
|
|
|
|
|
|
|
|
c = GitService.update_file(repo_path: @shixun.repo_path,
|
|
|
|
|
file_path: "01.ipynb",
|
|
|
|
|
message: message,
|
|
|
|
|
content: content,
|
|
|
|
|
author_name: author_name,
|
|
|
|
|
author_email: author_email)
|
|
|
|
|
|
|
|
|
|
render plain: 'save: #{c.size}'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
def shixun
|
|
|
|
|
@shixun = Shixun.find(3575)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
end
|