2017-05-03 14:14:05 +08:00
|
|
|
|
# encoding: utf-8
|
2017-04-07 10:16:13 +08:00
|
|
|
|
class MyshixunsController < ApplicationController
|
|
|
|
|
|
layout 'base_myshixun'
|
2017-07-07 17:27:36 +08:00
|
|
|
|
skip_before_filter :verify_authenticity_token, :only => [:training_task_status, :close_webssh]
|
|
|
|
|
|
before_filter :require_login, :except => [:training_task_status, :close_webssh]
|
|
|
|
|
|
before_filter :check_authentication, :except => [:training_task_status, :close_webssh]
|
|
|
|
|
|
before_filter :find_myshixun, :only => [:show, :myshixun_reset, :open_webssh]
|
|
|
|
|
|
|
2017-05-08 15:28:35 +08:00
|
|
|
|
|
2017-05-11 17:04:13 +08:00
|
|
|
|
include ApplicationHelper
|
|
|
|
|
|
|
2017-06-18 14:40:37 +08:00
|
|
|
|
# 将代码重置到开启状态
|
|
|
|
|
|
# 方法:使用文件更新,非Git重置
|
|
|
|
|
|
def code_reset
|
|
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def code_reset_success
|
|
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
2017-07-06 11:32:13 +08:00
|
|
|
|
# 连接webssh
|
|
|
|
|
|
def open_webssh
|
|
|
|
|
|
username = Redmine::Configuration['webssh_username']
|
|
|
|
|
|
password = Redmine::Configuration['webssh_password']
|
|
|
|
|
|
begin
|
2017-08-04 14:19:22 +08:00
|
|
|
|
shixun_tomcat = Redmine::Configuration['shixun_tomcat']
|
2017-08-13 10:48:05 +08:00
|
|
|
|
uri = "#{shixun_tomcat}/bridge/webssh/getConnectInfo"
|
2017-07-06 11:32:13 +08:00
|
|
|
|
user_id = User.current.id
|
2017-08-11 20:45:51 +08:00
|
|
|
|
params = {tpiID:@myshixun.id, operationEnvironment:@myshixun.shixun.try(:language)}
|
2017-07-06 11:32:13 +08:00
|
|
|
|
res = uri_exec uri, params
|
|
|
|
|
|
if res && res['code'].to_i != 0
|
|
|
|
|
|
raise("实训云平台繁忙(繁忙等级:92)")
|
|
|
|
|
|
end
|
2017-07-07 14:12:40 +08:00
|
|
|
|
render :json => {:host => res['address'], :port => res['port'], :username => username, :password => password, :game_id => @myshixun.id}
|
2017-07-06 11:32:13 +08:00
|
|
|
|
rescue Exception => e
|
|
|
|
|
|
logger.error(e)
|
2017-07-06 16:13:46 +08:00
|
|
|
|
render :json => {:error => e.try(:message)}
|
|
|
|
|
|
# @message = e.try(:message)
|
2017-07-06 11:32:13 +08:00
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# 断开webssh连接
|
|
|
|
|
|
def close_webssh
|
|
|
|
|
|
username = Redmine::Configuration['webssh_username']
|
|
|
|
|
|
password = Redmine::Configuration['webssh_password']
|
|
|
|
|
|
begin
|
2017-08-04 14:19:22 +08:00
|
|
|
|
shixun_tomcat = Redmine::Configuration['shixun_tomcat']
|
2017-08-13 10:48:05 +08:00
|
|
|
|
uri = "#{shixun_tomcat}/bridge/webssh/deleteSSH"
|
2017-07-06 11:32:13 +08:00
|
|
|
|
user_id = User.current.id
|
2017-07-25 16:55:52 +08:00
|
|
|
|
logger.info("#############################")
|
|
|
|
|
|
logger.info("game_id:" + @_params[:id])
|
2017-08-11 20:45:51 +08:00
|
|
|
|
params = {tpiID:@_params[:id]} # @_params[:id] 是webssh传过来的gameId
|
2017-07-06 11:32:13 +08:00
|
|
|
|
res = uri_exec uri, params
|
|
|
|
|
|
if res && res['code'].to_i != 0
|
|
|
|
|
|
raise("实训云平台繁忙(繁忙等级:93)")
|
|
|
|
|
|
end
|
2017-07-14 15:03:08 +08:00
|
|
|
|
render :jsonp => {:host => res['address'], :port => res['port'], :username => username, :password => password}
|
2017-07-06 11:32:13 +08:00
|
|
|
|
rescue Exception => e
|
|
|
|
|
|
logger.error(e)
|
|
|
|
|
|
@message = e.try(:message)
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
|
2017-06-18 14:40:37 +08:00
|
|
|
|
# 实训重置只更新脚本
|
2017-05-08 15:28:35 +08:00
|
|
|
|
def myshixun_reset
|
2017-06-20 17:27:19 +08:00
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
|
|
begin
|
2017-06-28 14:24:57 +08:00
|
|
|
|
g = Gitlab.client
|
2017-08-04 14:19:22 +08:00
|
|
|
|
shixun_tomcat = Redmine::Configuration['shixun_tomcat']
|
2017-06-20 17:27:19 +08:00
|
|
|
|
shixun = @myshixun.shixun
|
2017-08-06 15:34:24 +08:00
|
|
|
|
myshixun_job = Base64.urlsafe_encode64("myshixun_#{@myshixun.id}")
|
2017-06-30 22:41:29 +08:00
|
|
|
|
StudentWork.where(:myshixun_id => @myshixun.id).update_all(:myshixun_id => nil, :work_status => 0)
|
2017-06-20 17:27:19 +08:00
|
|
|
|
@myshixun.destroy
|
|
|
|
|
|
myshixun_member = @myshixun
|
|
|
|
|
|
repository = @myshixun.repository
|
|
|
|
|
|
repository.destroy
|
|
|
|
|
|
g_project = g.project(@myshixun.gpid)
|
|
|
|
|
|
unless g_project.id.nil?
|
|
|
|
|
|
git_rep = g.delete_project(@myshixun.gpid)
|
|
|
|
|
|
logger.info("### delete repository result is #{git_rep}")
|
|
|
|
|
|
if git_rep != true
|
|
|
|
|
|
raise("实训云平台繁忙(繁忙等级:87)")
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
2017-06-26 18:20:28 +08:00
|
|
|
|
redirect_to shixun_exec_shixun_path(shixun, :type => 1)
|
2017-06-20 17:27:19 +08:00
|
|
|
|
rescue Exception => e
|
|
|
|
|
|
flash[:error] = "实训云平台繁忙(繁忙等级:89)"
|
2017-06-28 14:24:57 +08:00
|
|
|
|
g.delete_project(@myshixun.gpid) if !g_project.try(:id).nil?
|
2017-06-20 17:27:19 +08:00
|
|
|
|
redirect_to myshixun_path(@myshixun)
|
|
|
|
|
|
logger.error("myshixun reset failed #{e}")
|
|
|
|
|
|
raise ActiveRecord::Rollback
|
|
|
|
|
|
end
|
2017-05-08 15:28:35 +08:00
|
|
|
|
end
|
|
|
|
|
|
end
|
2017-04-07 10:16:13 +08:00
|
|
|
|
|
|
|
|
|
|
# taskId 即返回的game id
|
2017-04-18 10:22:28 +08:00
|
|
|
|
# 返回结果:params [:stauts] 0 表示成功,其它则失败
|
2017-04-07 10:16:13 +08:00
|
|
|
|
# msg 错误信息
|
|
|
|
|
|
# output 为测试用户编译输出结果
|
|
|
|
|
|
# myshixun:status 1为完成实训
|
2017-04-18 10:22:28 +08:00
|
|
|
|
# @jenkins: caseId对应test_set的position,passed: 1表示成功,0表示失败
|
2017-05-10 10:43:23 +08:00
|
|
|
|
# resubmit 1:表示已通关后重新评测;0:表示非重新评测
|
|
|
|
|
|
# retry_status 0:初始值;1:重新评测失败;2:重新评测成功
|
2017-04-07 10:16:13 +08:00
|
|
|
|
def training_task_status
|
2017-04-18 10:22:28 +08:00
|
|
|
|
jsonTestDetails = JSON.parse(params[:jsonTestDetails])
|
|
|
|
|
|
status = jsonTestDetails['status']
|
|
|
|
|
|
game_id = jsonTestDetails['buildID']
|
2017-05-10 10:43:23 +08:00
|
|
|
|
resubmit = jsonTestDetails['resubmit']
|
2017-08-10 14:33:34 +08:00
|
|
|
|
outPut = tran_base64_decode64(jsonTestDetails['outPut'])
|
2017-04-18 10:22:28 +08:00
|
|
|
|
jenkins_testsets = jsonTestDetails['msg']
|
2017-04-16 10:16:36 +08:00
|
|
|
|
# message = Base64.decode64(params[:msg]) unless params[:msg].blank?
|
2017-08-10 14:33:34 +08:00
|
|
|
|
logger.info(outPut)
|
2017-04-18 10:22:28 +08:00
|
|
|
|
game = Game.find(game_id)
|
|
|
|
|
|
challenge = game.challenge
|
|
|
|
|
|
unless jenkins_testsets.blank?
|
|
|
|
|
|
jenkins_testsets.each do |j_test_set|
|
2017-08-10 14:33:34 +08:00
|
|
|
|
actual_output = tran_base64_decode64(j_test_set['output'])
|
2017-08-08 16:41:14 +08:00
|
|
|
|
game_outputs = Output.create(:code => status, :game_id => game_id, :out_put => outPut, :test_set_position => j_test_set['caseId'],
|
|
|
|
|
|
:actual_output => actual_output, :result => j_test_set['passed'].to_i, :query_index => game.query_index)
|
|
|
|
|
|
|
|
|
|
|
|
# output = Output.where(:game_id => game.id, :test_set_position => j_test_set['caseId'].to_i).first
|
|
|
|
|
|
# logger.info("#############{outPut}")
|
|
|
|
|
|
# if output.nil?
|
|
|
|
|
|
# game_outputs = Output.create(:code => status, :game_id => game_id, :out_put => outPut, :test_set_position => j_test_set['caseId'],
|
|
|
|
|
|
# :actual_output => actual_output, :result => j_test_set['passed'].to_i)
|
|
|
|
|
|
# else
|
|
|
|
|
|
# output.update_attributes(:code => status, :out_put => outPut, :actual_output => actual_output, :result => j_test_set['passed'].to_i)
|
|
|
|
|
|
# end
|
2017-04-18 10:22:28 +08:00
|
|
|
|
end
|
|
|
|
|
|
end
|
2017-05-14 15:28:18 +08:00
|
|
|
|
if status == "0"
|
2017-05-18 19:48:54 +08:00
|
|
|
|
if !resubmit.blank?
|
2017-05-15 16:37:46 +08:00
|
|
|
|
game.update_attributes(:retry_status => 2, :resubmit_identifier => resubmit)
|
2017-05-14 15:28:18 +08:00
|
|
|
|
else
|
2017-06-14 09:55:57 +08:00
|
|
|
|
game.update_attributes(:status => 2, :end_time => Time.now)
|
2017-06-14 16:29:26 +08:00
|
|
|
|
unless game.answer_open? # 如果没有查看答案,则获得该关卡得分
|
2017-06-14 09:55:57 +08:00
|
|
|
|
game.update_attribute(:final_score, challenge.score)
|
2017-06-12 17:23:05 +08:00
|
|
|
|
end
|
2017-05-14 15:28:18 +08:00
|
|
|
|
end
|
2017-06-18 14:40:37 +08:00
|
|
|
|
else # status == "-1" 表示返回结果错误
|
2017-05-18 14:07:08 +08:00
|
|
|
|
if !resubmit.blank?
|
2017-05-15 16:37:46 +08:00
|
|
|
|
game.update_attributes(:retry_status => 1, :resubmit_identifier => resubmit)
|
2017-05-14 15:28:18 +08:00
|
|
|
|
else
|
|
|
|
|
|
game.update_attribute(:status, 0)
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
2017-04-18 10:22:28 +08:00
|
|
|
|
render :json => {:data => "success"}
|
2017-04-07 10:16:13 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def show
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
|
format.html{redirect_to myshixun_game_path(@myshixun.current_task, :myshixun_id => @myshixun)}
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
# Find myshixun of id params[:id]
|
|
|
|
|
|
def find_myshixun
|
2017-04-26 10:19:04 +08:00
|
|
|
|
@myshixun = Myshixun.find_by_identifier(params[:id])
|
2017-04-07 10:16:13 +08:00
|
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
|
|
render_404
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|