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'
|
|
|
|
|
|
skip_before_filter :verify_authenticity_token, :only => [:training_task_status]
|
|
|
|
|
|
before_filter :require_login, :except => [:training_task_status]
|
2017-05-08 15:28:35 +08:00
|
|
|
|
before_filter :find_myshixun, :only => [:show, :myshixun_reset]
|
|
|
|
|
|
|
2017-05-11 17:04:13 +08:00
|
|
|
|
include ApplicationHelper
|
|
|
|
|
|
|
2017-05-08 15:28:35 +08:00
|
|
|
|
def myshixun_reset
|
|
|
|
|
|
ActiveRecord::Base.transaction do
|
2017-05-11 10:26:37 +08:00
|
|
|
|
begin
|
2017-05-11 16:56:32 +08:00
|
|
|
|
jenkins_shixuns = Redmine::Configuration['jenkins_shixuns']
|
2017-05-11 10:26:37 +08:00
|
|
|
|
shixun = @myshixun.shixun
|
2017-05-12 15:20:09 +08:00
|
|
|
|
myshixun_job = Base64.encode64("myshixun_#{@myshixun.id}")
|
2017-05-11 10:26:37 +08:00
|
|
|
|
@myshixun.destroy
|
|
|
|
|
|
myshixun_member = @myshixun
|
|
|
|
|
|
repository = @myshixun.repository
|
|
|
|
|
|
repository.destroy
|
2017-05-11 17:19:13 +08:00
|
|
|
|
g = Gitlab.client
|
|
|
|
|
|
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
|
2017-05-24 10:11:45 +08:00
|
|
|
|
raise("实训云平台繁忙(繁忙等级:87)")
|
2017-05-11 17:19:13 +08:00
|
|
|
|
end
|
|
|
|
|
|
end
|
2017-05-21 18:04:22 +08:00
|
|
|
|
params = {:jobName => "#{myshixun_job}"}
|
2017-05-11 10:26:37 +08:00
|
|
|
|
uri = URI("#{jenkins_shixuns}/jenkins-exec/game/deleteJob")
|
|
|
|
|
|
res = uri_exec uri, params
|
2017-05-21 17:17:56 +08:00
|
|
|
|
if (res && res['code'] != 0)
|
2017-05-24 10:11:45 +08:00
|
|
|
|
raise("实训云平台繁忙(繁忙等级:89)")
|
2017-05-21 17:17:56 +08:00
|
|
|
|
end
|
2017-05-19 20:49:33 +08:00
|
|
|
|
redirect_to shixun_exec_shixun_path(shixun)
|
2017-05-11 16:44:24 +08:00
|
|
|
|
rescue Exception => e
|
2017-05-24 10:11:45 +08:00
|
|
|
|
flash[:error] = "实训云平台繁忙(繁忙等级:89)"
|
2017-05-19 20:49:33 +08:00
|
|
|
|
redirect_to myshixun_path(@myshixun)
|
2017-05-11 16:44:24 +08:00
|
|
|
|
logger.error("myshixun reset failed #{e}")
|
2017-05-11 10:26:37 +08:00
|
|
|
|
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-05-12 21:07:52 +08:00
|
|
|
|
outPut = Base64.urlsafe_decode64(jsonTestDetails['outPut'].strip().gsub(" ", "+")).force_encoding("utf-8") unless jsonTestDetails['outPut'].blank?
|
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-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-05-03 14:14:05 +08:00
|
|
|
|
actual_output = Base64.urlsafe_decode64(j_test_set['output'].gsub(" ", "+")).force_encoding("utf-8") unless j_test_set['output'].blank?
|
2017-04-21 11:01:57 +08:00
|
|
|
|
output = Output.where(:game_id => game.id, :test_set_position => j_test_set['caseId'].to_i).first
|
2017-05-12 21:07:52 +08:00
|
|
|
|
logger.info("#############{outPut}")
|
2017-04-20 17:19:18 +08:00
|
|
|
|
if output.nil?
|
|
|
|
|
|
game_outputs = Output.create(:code => status, :game_id => game_id, :out_put => outPut, :test_set_position => j_test_set['caseId'],
|
2017-05-05 16:14:35 +08:00
|
|
|
|
:actual_output => actual_output, :result => j_test_set['passed'].to_i, :is_public => j_test_set['isPublic'].to_i)
|
2017-04-20 17:19:18 +08:00
|
|
|
|
else
|
2017-05-04 16:59:40 +08:00
|
|
|
|
output.update_attributes(:code => status, :out_put => outPut, :actual_output => actual_output, :result => j_test_set['passed'].to_i)
|
2017-04-20 17:19:18 +08:00
|
|
|
|
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-05-15 16:37:46 +08:00
|
|
|
|
game.update_attributes(:status => 2, :final_score => challenge.score, :end_time => Time.now)
|
2017-05-14 15:28:18 +08:00
|
|
|
|
end
|
|
|
|
|
|
else
|
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
|