Commit e7a0c25d authored by YangZhaoJun1's avatar YangZhaoJun1

项目重新启动,容器的定时关闭任务

parent 78532c09
/*
Navicat MySQL Data Transfer
Source Server : 127.0.0.1_3306
Source Server Version : 50717
Source Host : localhost:3306
Source Database : edu_db
Target Server Type : MYSQL
Target Server Version : 50717
File Encoding : 65001
Date: 2018-05-03 16:25:33
*/
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for b_term
-- ----------------------------
DROP TABLE IF EXISTS `b_term`;
CREATE TABLE `b_term` (
`business_id` varchar(64) COLLATE utf8_bin NOT NULL COMMENT '主键',
`start_date` date DEFAULT NULL COMMENT '学期开始时间',
`end_date` date DEFAULT NULL COMMENT '学期结束时间',
`is_start` varchar(1) COLLATE utf8_bin DEFAULT '1' COMMENT '是否启动(0:未启动,1:启动)',
`create_by` varchar(64) COLLATE utf8_bin DEFAULT NULL COMMENT '创建者',
`update_by` varchar(64) COLLATE utf8_bin DEFAULT NULL COMMENT '更新者',
`del_flag` varchar(1) COLLATE utf8_bin DEFAULT NULL COMMENT '删除标记(0:正常;1:删除;2:审核)',
`flag` varchar(1) COLLATE utf8_bin DEFAULT NULL COMMENT '启用标记(0:停用;1:启用)',
`remarks` varchar(64) COLLATE utf8_bin DEFAULT NULL COMMENT '备注',
`code` varchar(30) COLLATE utf8_bin DEFAULT NULL,
`update_date` datetime DEFAULT NULL,
`create_date` datetime DEFAULT NULL,
`name` varchar(64) COLLATE utf8_bin DEFAULT NULL,
`week` varchar(5) COLLATE utf8_bin DEFAULT NULL,
PRIMARY KEY (`business_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
-- ----------------------------
-- Records of b_term
-- ----------------------------
INSERT INTO `b_term` VALUES ('0050f6db450f49c9acb0661718dddaaf', '2018-03-01', '2018-03-16', '1', '333e421d32d9425ea99afce95b603902', '333e421d32d9425ea99afce95b603902', '0', '1', null, '0962', '2018-03-26 05:44:29', '2018-03-26 02:02:04', '09621', null);
INSERT INTO `b_term` VALUES ('03dc80913874416f821e572bc95807d4', '2018-03-26', '2018-04-02', '1', '333e421d32d9425ea99afce95b603902', '333e421d32d9425ea99afce95b603902', '0', '1', null, '123', '2018-04-02 07:38:35', '2018-04-02 01:36:45', '123', null);
INSERT INTO `b_term` VALUES ('1df01eb5e86c41078df79bbe73792316', '2018-03-05', '2018-03-08', '1', '333e421d32d9425ea99afce95b603902', '333e421d32d9425ea99afce95b603902', '0', '1', null, '00998877', '2018-03-27 02:54:59', '2018-03-26 07:22:09', '00998877', null);
INSERT INTO `b_term` VALUES ('239fffb95400435e8956a6141792dde8', '2018-03-28', '2018-03-31', '1', '333e421d32d9425ea99afce95b603902', '333e421d32d9425ea99afce95b603902', '0', '1', null, '1', '2018-04-02 02:13:07', '2018-03-20 01:18:15', '1', null);
INSERT INTO `b_term` VALUES ('378eeff2f09342fb9adf184d3a096bd0', '2018-03-20', '2018-03-27', '0', '333e421d32d9425ea99afce95b603902', '333e421d32d9425ea99afce95b603902', '0', '1', null, '1232', '2018-04-02 01:24:08', '2018-03-27 07:57:16', '21321', null);
INSERT INTO `b_term` VALUES ('3d1e4d0dc3dd44a5834280a811aae53d', '2018-03-01', '2018-03-31', '1', '333e421d32d9425ea99afce95b603902', '333e421d32d9425ea99afce95b603902', '0', '1', null, '00002018', '2018-03-27 02:44:31', '2018-03-22 06:10:07', '新版测试', null);
INSERT INTO `b_term` VALUES ('671cf867a71244bba9b5f886da5959af', '2018-03-28', '2018-04-04', '0', '333e421d32d9425ea99afce95b603902', '333e421d32d9425ea99afce95b603902', '0', '1', null, '323', '2018-04-04 03:30:04', '2018-04-04 03:30:04', '323', null);
INSERT INTO `b_term` VALUES ('86e9e50b95ad4fc191d005a38d07c91c', '2018-03-02', '2018-07-16', '1', '333e421d32d9425ea99afce95b603902', '333e421d32d9425ea99afce95b603902', '0', '1', null, '201801', '2018-02-28 07:07:11', '2018-02-26 09:13:33', '2017-2018学年第二学期', null);
INSERT INTO `b_term` VALUES ('997885abb5824438914c67b460777418', '2018-03-09', '2019-04-01', '1', '333e421d32d9425ea99afce95b603902', '333e421d32d9425ea99afce95b603902', '0', '1', null, '20180309TEST', '2018-03-09 01:52:18', '2018-03-09 01:52:16', '前端测试', null);
INSERT INTO `b_term` VALUES ('acf001431ad644908bb7589320610f1b', '2018-02-05', '2018-04-27', '1', '333e421d32d9425ea99afce95b603902', '333e421d32d9425ea99afce95b603902', '0', '1', null, '20182018', '2018-03-21 06:29:19', '2018-03-19 09:03:20', '测试学期', '12');
INSERT INTO `b_term` VALUES ('b60e37ecdede4de388b8bc99716320a6', '2018-03-03', '2018-04-10', '1', '333e421d32d9425ea99afce95b603902', '333e421d32d9425ea99afce95b603902', '0', '1', null, '963', '2018-04-03 05:41:00', '2018-04-03 03:08:28', '963', null);
INSERT INTO `b_term` VALUES ('bf5852e55bb3494c96db4ba03b5a1fea', '2018-04-02', '2018-04-08', '0', '333e421d32d9425ea99afce95b603902', '333e421d32d9425ea99afce95b603902', '0', '1', null, '111111', '2018-04-08 08:51:54', '2018-04-08 08:51:54', '111111', null);
INSERT INTO `b_term` VALUES ('f0e7e41f024f4580b8ff968405e12046', '2018-04-09', '2018-04-09', '0', '333e421d32d9425ea99afce95b603902', '333e421d32d9425ea99afce95b603902', '0', '1', null, '865', '2018-04-02 07:46:40', '2018-04-02 02:09:28', '59633想', null);
...@@ -72,7 +72,8 @@ public class BCodeLxcServiceImpl implements BCodeLxcService { ...@@ -72,7 +72,8 @@ public class BCodeLxcServiceImpl implements BCodeLxcService {
port = this.getIdleWithPorts(ports,port,maxPort); port = this.getIdleWithPorts(ports,port,maxPort);
logger.info("<port>:"+port); logger.info("<port>:"+port);
portSSH = this.getIdleWithPorts(ports,portSSH,maxPortSSH); //portSSH = this.getIdleWithPorts(ports,portSSH,maxPortSSH);
portSSH = port + 10000;
logger.info("<portSSH>:"+portSSH); logger.info("<portSSH>:"+portSSH);
} }
...@@ -114,8 +115,8 @@ public class BCodeLxcServiceImpl implements BCodeLxcService { ...@@ -114,8 +115,8 @@ public class BCodeLxcServiceImpl implements BCodeLxcService {
return result; return result;
} }
if(global.getJavaProject().equals(lxc.getCode())) /*if(global.getJavaProject().equals(lxc.getCode()))
port = portSSH; port = portSSH;*/
lxc.setContainerPort(port); lxc.setContainerPort(port);
lxc.setStartDate(new Date()); lxc.setStartDate(new Date());
lxc.setTotalMin(global.getLxcMinu()); lxc.setTotalMin(global.getLxcMinu());
......
package org.rcisoft.business.bcode.task; package org.rcisoft.business.bcode.task;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.quartz.Job; import org.quartz.*;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.rcisoft.business.bcode.model.BCodeLxc; import org.rcisoft.business.bcode.model.BCodeLxc;
import org.rcisoft.common.component.Global; import org.rcisoft.common.component.Global;
import org.rcisoft.core.command.LxcCommand; import org.rcisoft.core.command.LxcCommand;
import org.rcisoft.core.result.CommandResult; import org.rcisoft.core.result.CommandResult;
import org.rcisoft.core.service.RcRedisService; import org.rcisoft.core.service.RcRedisService;
import org.rcisoft.core.service.SerializationUtils; import org.rcisoft.core.service.SerializationUtils;
import org.rcisoft.core.util.TaskUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.io.File; import java.io.File;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* Created by lcy on 18/1/10. * Created by lcy on 18/1/10.
...@@ -30,6 +32,9 @@ import java.util.List; ...@@ -30,6 +32,9 @@ import java.util.List;
@Slf4j @Slf4j
public class ClearLxcJob implements Job { public class ClearLxcJob implements Job {
/*任务组名*/
private static final String JOB_LXC_GROUP = "lxc_job_group";
@Autowired @Autowired
private RcRedisService rcRedisServiceImpl; private RcRedisService rcRedisServiceImpl;
...@@ -39,6 +44,9 @@ public class ClearLxcJob implements Job { ...@@ -39,6 +44,9 @@ public class ClearLxcJob implements Job {
@Autowired @Autowired
private Global global; private Global global;
@Autowired
private SchedulerFactoryBean schedulerFactoryBean;
@Override @Override
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException { public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
...@@ -68,7 +76,25 @@ public class ClearLxcJob implements Job { ...@@ -68,7 +76,25 @@ public class ClearLxcJob implements Job {
Date shutdown = lxc.getShutdownDate(); Date shutdown = lxc.getShutdownDate();
/*未到点*/ /*未到点*/
if(null != shutdown && shutdown.after(new Date())) { if(null != shutdown && shutdown.after(new Date())) {
/*todo 重新定时-------关闭*/ /*启动路径*/
String dockerPath = global.getPHYSICAL_UPLOAD_SERVER_LOCATION() +
global.getLxcDockerfilePath() + "/" + lxc.getUserId() + "/";
/*任务参数*/
Map jobParam = new HashMap();
jobParam.put("redisKeyId",key);
jobParam.put("containerName",this.getModelProject(lxc.getCode()) + "_" + lxc.getUserId());
jobParam.put("containerPath",dockerPath);
jobParam.put("containerPort",lxc.getContainerPort());
JobDetail job = JobBuilder.newJob(StopLxcJob.class).
withIdentity(global.getLxcPrefix() + lxc.getUserId(), JOB_LXC_GROUP).
usingJobData(new JobDataMap(jobParam)).build();
Trigger trigger = TriggerBuilder.newTrigger().forJob(job)
.usingJobData(new JobDataMap(jobParam))
.withIdentity(global.getLxcPrefix() + lxc.getUserId())
.startAt(lxc.getShutdownDate()).build();
// 触发器时间设定
/*触发器*/
TaskUtil.startSchedule(schedulerFactoryBean.getScheduler(),trigger,job);
return; return;
} }
...@@ -90,4 +116,19 @@ public class ClearLxcJob implements Job { ...@@ -90,4 +116,19 @@ public class ClearLxcJob implements Job {
key); key);
rcRedisServiceImpl.removeList("lxcPorts",lxc.getContainerPort() + ""); rcRedisServiceImpl.removeList("lxcPorts",lxc.getContainerPort() + "");
} }
/**
* 或许模型
* @param code
* @return
*/
private String getModelProject(String code) {
if(global.getJavaProject().equals(code))
return "java";
else if(global.getHtmlProject().equals(code))
return "apache";
else
return "";
}
} }
...@@ -40,6 +40,8 @@ pagehelper: ...@@ -40,6 +40,8 @@ pagehelper:
spring: spring:
jackson: jackson:
default-property-inclusion: non_null default-property-inclusion: non_null
date-format: yyyy-MM-dd
time-zone: GMT+8
http: http:
# encoding: # encoding:
# force: true # force: true
...@@ -103,7 +105,14 @@ global: ...@@ -103,7 +105,14 @@ global:
student: /default/student.png student: /default/student.png
teacher: /default/teacher.png teacher: /default/teacher.png
carousel: /default/carousel.jpg carousel: /default/carousel.jpg
lk:
publicalias: publiccert
storePwd: rcrtcyedu2
subject: edu2
licPath: /lk/license.lic
pubPath: /lk/publicCerts.store
password: password:
default: 123456
min_password: 6 min_password: 6
max_password: 16 max_password: 16
path: path:
...@@ -130,6 +139,7 @@ global: ...@@ -130,6 +139,7 @@ global:
cource_code_location: code cource_code_location: code
cource_project_location: project cource_project_location: project
student_code_location: studentCode student_code_location: studentCode
xml_location: /xmlTemp
other: other:
server_url: http://106.2.3.134:10180/eduServer server_url: http://106.2.3.134:10180/eduServer
is_server_linux: 1 is_server_linux: 1
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment