You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
educoder/app/controllers/jupyters_controller.rb

97 lines
3.0 KiB

require 'base64'
5 years ago
5 years ago
class JupytersController < ApplicationController
5 years ago
include JupyterService
before_action :shixun, only: [:open, :open1, :test, :save]
def import_with_tpm
shixun = Shixun.find_by(identifier: params[:identifier])
upload_file = params["file"] || params["#{params[:file_param_name]}"] # 这里的file_param_name是为了方便其他插件名称
uid_logger("#########################file_params####{params["#{params[:file]}"]}")
raise "未上传文件" unless upload_file
content = Base64.encode64(upload_file.tempfile.read)
# upload to server
shixun_tomcat = edu_setting('cloud_bridge')
uri = "#{shixun_tomcat}/bridge/jupyter/update"
tpiID = "tpm#{shixun.id}"
params = {tpiID: tpiID, content: content}
logger.info "test_juypter: uri->#{uri}, params->#{params}"
res = uri_post uri, params
if res && res['code'].to_i != 0
raise("实训云平台繁忙繁忙等级100")
end
render json: {status: 0}
end
def save_with_tpi
5 years ago
myshixun = Myshixun.find_by(identifier: params[:identifier])
jupyter_save_with_game(myshixun, params[:jupyter_port])
render json: {status: 0}
end
def save_with_tpm
shixun = Shixun.find_by(identifier: params[:identifier])
jupyter_save_with_shixun(shixun, params[:jupyter_port])
render json: {status: 0}
end
def get_info_with_tpi
5 years ago
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
def get_info_with_tpm
shixun = Shixun.find_by(identifier: params[:identifier])
url = jupyter_url_with_shixun(shixun)
port = jupyter_port_with_shixun(shixun)
render json: {status: 0, url: url, port: port}
end
5 years ago
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
def active_with_tpm
shixun = Shixun.find_by(identifier: params[:identifier])
jupyter_active_tpm(shixun)
render json: {status: 0}
end
def active_with_tpi
myshixun = Myshixun.find_by(identifier: params[:identifier])
5 years ago
jupyter_active_tpi(myshixun)
render json: {status: 0}
end
5 years ago
def timeinfo_with_tpm
shixun = Shixun.find_by(identifier: params[:identifier])
info = jupyter_timeinfo_tpm(shixun)
render json: {status: 0}.merge(info)
end
def timeinfo_with_tpi
myshixun = Myshixun.find_by(identifier: params[:identifier])
5 years ago
info = jupyter_timeinfo_tpi(myshixun)
render json: {status: 0}.merge(info)
end
end