实训服务器配置

dev_forum
daiao 5 years ago
parent e3dbe6c573
commit 1044209d4f

@ -427,6 +427,24 @@ class ApplicationController < ActionController::Base
container.to_json container.to_json
end end
# 实训中间层pod配置
def shixun_container_limit shixun
container = []
shixun.shixun_service_configs.each do |config|
mirror = config.mirror_repository
if mirror.name.present?
container << {:image => mirror.name,
:cpuLimit => config.cpu_limit,
:cpuRequest => config.lower_cpu_limit,
:memoryLimit => "#{config.memory_limit}M",
:memoryRequest => "#{config.request_limit}M",
:resourceLimit => "#{config.resource_limit}K",
:type => mirror.try(:main_type) == "1" ? "main" : "sub"}
end
end
container.to_json
end
# 毕设任务列表的赛选 # 毕设任务列表的赛选
def course_work(task, **option) def course_work(task, **option)
logger.info("#############{option}") logger.info("#############{option}")

@ -154,7 +154,7 @@ class ChallengesController < ApplicationController
current_myshixun = @shixun.current_myshixun(current_user.id) current_myshixun = @shixun.current_myshixun(current_user.id)
@challenges = @shixun.challenges.includes(:games).where("games.user_id" => (current_myshixun ? current_user.id : nil)) @challenges = @shixun.challenges.includes(:games).where("games.user_id" => (current_myshixun ? current_user.id : nil))
@editable = current_user.manager_of_shixun?(@shixun) && @shixun.status == 0 @editable = @shixun.status == 0 # before_action有判断权限如果没发布则肯定是管理人员
@user = current_user @user = current_user
end end
@ -290,7 +290,7 @@ class ChallengesController < ApplicationController
def challenge_params def challenge_params
params.require(:challenge).permit(:subject, :task_pass, :difficulty, :score, :st, :modify_time, :test_set_average, params.require(:challenge).permit(:subject, :task_pass, :difficulty, :score, :st, :modify_time, :test_set_average,
:path, :exec_path, :show_type, :original_picture_path, :test_set_score, :path, :exec_path, :show_type, :original_picture_path, :test_set_score,
:expect_picture_path, :picture_path, :web_route, :answer) :expect_picture_path, :picture_path, :web_route, :answer, :exec_time)
end end
def chooce_params def chooce_params

@ -33,7 +33,7 @@ class GamesController < ApplicationController
is_teacher = @user.is_teacher? is_teacher = @user.is_teacher?
# 实训超时设置 # 实训超时设置
time_limit = @shixun.exec_time time_limit = game_challenge.exec_time
# 上一关、下一关 # 上一关、下一关
prev_game = @game.prev_of_current_game(@shixun.id, @game.myshixun_id, game_challenge.position) prev_game = @game.prev_of_current_game(@shixun.id, @game.myshixun_id, game_challenge.position)
@ -66,7 +66,7 @@ class GamesController < ApplicationController
shixun_tomcat = edu_setting('cloud_bridge') shixun_tomcat = edu_setting('cloud_bridge')
service_host = edu_setting('vnc_url') service_host = edu_setting('vnc_url')
uri = "#{shixun_tomcat}/bridge/vnc/getvnc" uri = "#{shixun_tomcat}/bridge/vnc/getvnc"
params = {tpiID: @myshixun.id, :containers => "#{Base64.urlsafe_encode64(container_limit(@shixun.mirror_repositories))}"} params = {tpiID: @myshixun.id, :containers => "#{Base64.urlsafe_encode64(shixun_container_limit(@shixun))}"}
res = uri_post uri, params res = uri_post uri, params
if res && res['code'].to_i != 0 if res && res['code'].to_i != 0
raise("实训云平台繁忙繁忙等级99") raise("实训云平台繁忙繁忙等级99")
@ -547,7 +547,7 @@ class GamesController < ApplicationController
br_params = {:tpiID => "#{@myshixun.id}", :tpiGitURL => "#{gitUrl}", :buildID => "#{@game.id}", br_params = {:tpiID => "#{@myshixun.id}", :tpiGitURL => "#{gitUrl}", :buildID => "#{@game.id}",
:instanceChallenge => "#{step}", :testCases => "#{testCases}", :resubmit => "#{resubmit}", :instanceChallenge => "#{step}", :testCases => "#{testCases}", :resubmit => "#{resubmit}",
:times => params[:first].to_i, :podType => @shixun.webssh, :content_modified => content_modified, :times => params[:first].to_i, :podType => @shixun.webssh, :content_modified => content_modified,
:containers => "#{Base64.urlsafe_encode64(container_limit(@shixun.mirror_repositories))}", :containers => "#{Base64.urlsafe_encode64(shixun_container_limit(@shixun))}",
:persistenceName => @shixun.identifier, :tpmScript => "#{tpmScript}", :persistenceName => @shixun.identifier, :tpmScript => "#{tpmScript}",
:timeLimit => "#{@shixun.exec_time}", :isPublished => (@shixun.status < 2 ? 0 : 1) } :timeLimit => "#{@shixun.exec_time}", :isPublished => (@shixun.status < 2 ? 0 : 1) }

@ -217,7 +217,7 @@ class MyshixunsController < ApplicationController
shixun_tomcat = edu_setting('tomcat_webssh') shixun_tomcat = edu_setting('tomcat_webssh')
uri = "#{shixun_tomcat}/bridge/webssh/getConnectInfo" uri = "#{shixun_tomcat}/bridge/webssh/getConnectInfo"
params = {tpiID:@myshixun.id, podType:@myshixun.shixun.try(:webssh), params = {tpiID:@myshixun.id, podType:@myshixun.shixun.try(:webssh),
containers:(Base64.urlsafe_encode64(container_limit @myshixun.shixun.mirror_repositories))} containers:(Base64.urlsafe_encode64(shixun_container_limit @myshixun.shixun))}
res = uri_post uri, params res = uri_post uri, params
if res && res['code'].to_i != 0 if res && res['code'].to_i != 0
tip_exception("实训云平台繁忙繁忙等级92") tip_exception("实训云平台繁忙繁忙等级92")

@ -315,9 +315,13 @@ class ShixunsController < ApplicationController
# 镜像-实训关联表 # 镜像-实训关联表
ShixunMirrorRepository.create!(:shixun_id => @shixun.id, :mirror_repository_id => main_type.to_i) if main_type.present? ShixunMirrorRepository.create!(:shixun_id => @shixun.id, :mirror_repository_id => main_type.to_i) if main_type.present?
# 实训主镜像服务配置
ShixunServiceConfig.create!(:shixun_id => @shixun.id, :mirror_repository_id => main_type.to_i)
if sub_type.present? if sub_type.present?
sub_type.each do |mirror| sub_type.each do |mirror|
ShixunMirrorRepository.create!(:shixun_id => @shixun.id, :mirror_repository_id => mirror) ShixunMirrorRepository.create!(:shixun_id => @shixun.id, :mirror_repository_id => mirror)
# 实训子镜像服务配置
ShixunServiceConfig.create!(:shixun_id => @shixun.id, :mirror_repository_id => mirror)
end end
end end
@ -395,6 +399,18 @@ class ShixunsController < ApplicationController
use_scope = 0 use_scope = 0
end end
@shixun.update_attributes!(:use_scope => use_scope) @shixun.update_attributes!(:use_scope => use_scope)
# 超级管理员和运营人员才能保存 中间层服务器pod信息的配置
if current_user.admin? || current_user.business?
@shixun.shixun_service_configs.destroy_all
params[:mirror_id].each_with_index do |mirror_id, index|
ShixunServiceConfig.create!(:shixun_id => @shixun.id,
:cpu_limit => params[:cpu_limit][index],
:lower_cpu_limit => params[:lower_cpu_limit][index],
:memory_limit => params[:memory_limit][index],
:request_limit => params[:request_limit][index],
:mirror_repository_id => mirror_id)
end
end
rescue Exception => e rescue Exception => e
uid_logger_error(e.message) uid_logger_error(e.message)
tip_exception("实训保存失败") tip_exception("实训保存失败")

@ -20,7 +20,7 @@ class Challenge < ApplicationRecord
# acts_as_attachable # acts_as_attachable
scope :base_attrs, -> { select([:id, :subject, :position, :shixun_id, :st, :score, :path, :task_pass, :modify_time, scope :base_attrs, -> { select([:id, :subject, :position, :shixun_id, :st, :score, :path, :task_pass, :modify_time,
:web_route, :answer]) } :web_route, :answer, :exec_time]) }
scope :choose_type, -> { where(st: 1) } scope :choose_type, -> { where(st: 1) }
scope :practice_type, -> { where(st: 0) } scope :practice_type, -> { where(st: 0) }

@ -30,6 +30,8 @@ class Shixun < ApplicationRecord
has_one :shixun_info, dependent: :destroy has_one :shixun_info, dependent: :destroy
belongs_to :user belongs_to :user
# 实训服务配置
has_many :shixun_service_configs, :dependent => :destroy
scope :search_by_name, ->(keyword) { where("name like ? or description like ? ", scope :search_by_name, ->(keyword) { where("name like ? or description like ? ",

@ -0,0 +1,4 @@
class ShixunServiceConfig < ApplicationRecord
belongs_to :shixun
belongs_to :mirror_repository
end

@ -7,7 +7,7 @@ json.chooses do
end end
if @tab == 0 if @tab == 0
# 本关任务tab的编辑模式 # 本关任务tab的编辑模式
json.(@challenge, :id, :subject, :task_pass, :difficulty, :score) json.(@challenge, :id, :subject, :task_pass, :difficulty, :score, :exec_time)
json.tags @challenge.challenge_tags.map(&:name) json.tags @challenge.challenge_tags.map(&:name)
elsif @tab == 1 elsif @tab == 1
# 评测设置的编辑模式 # 评测设置的编辑模式

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe ShixunServiceConfig, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end
Loading…
Cancel
Save