Commit ad8204f3 authored by YangZhaoJun1's avatar YangZhaoJun1

Merge branch 'master' of http://103.249.252.109:90/lcy/education

parents 9c84a878 f3ad60ac
...@@ -37,5 +37,8 @@ public class BCodeLxc { ...@@ -37,5 +37,8 @@ public class BCodeLxc {
/*workingDir*/ /*workingDir*/
private String workingDir; private String workingDir;
/*章节id*/
private String chapterId;
} }
...@@ -52,13 +52,11 @@ public class BCodeLxcServiceImpl implements BCodeLxcService { ...@@ -52,13 +52,11 @@ public class BCodeLxcServiceImpl implements BCodeLxcService {
@Override @Override
public CommandResult startBCodeLxc(BCodeLxc lxc) { public CommandResult startBCodeLxc(BCodeLxc lxc) {
CommandResult result = null; CommandResult result = null;
List<Integer> ports = null; List<String> ports = null;
/*初始化port 20000 - 30000 */ /*初始化port 20000 - 30000 */
Integer port = global.getLxcInitPort(); Integer port = global.getLxcInitPort();
Integer maxPort = global.getLxcMaxPort(); Integer maxPort = global.getLxcMaxPort();
byte[] portResult = rcRedisServiceImpl.getBytes("lxcPorts"); ports = rcRedisServiceImpl.getList("lxcPorts");
if(null != portResult)
ports = SerializationUtils.deserializer(portResult, List.class);
if(null == ports || 0 == ports.size()) if(null == ports || 0 == ports.size())
ports = new ArrayList<>(); ports = new ArrayList<>();
else else
...@@ -68,10 +66,10 @@ public class BCodeLxcServiceImpl implements BCodeLxcService { ...@@ -68,10 +66,10 @@ public class BCodeLxcServiceImpl implements BCodeLxcService {
result = new CommandResult(ResultCode.FAIL,"端口全部占用,请稍后!",lxc); result = new CommandResult(ResultCode.FAIL,"端口全部占用,请稍后!",lxc);
return result; return result;
} }
ports.add(port); ports.add(port.toString());
/*1.freemarker 生成模板*/ /*1.freemarker 生成模板*/
Map param = new HashMap<>(); Map param = new HashMap<>();
param.put("lxcName",lxc.getUserId()); param.put("lxcName",lxc.getUserId() + "_" + lxc.getSl());
param.put("lxcPort",port); param.put("lxcPort",port);
param.put("lxcPath",lxc.getWorkingDir()); param.put("lxcPath",lxc.getWorkingDir());
...@@ -96,13 +94,15 @@ public class BCodeLxcServiceImpl implements BCodeLxcService { ...@@ -96,13 +94,15 @@ public class BCodeLxcServiceImpl implements BCodeLxcService {
Date endTime = new Date(lxc.getStartDate().getTime() + ( global.getLxcMinu() * 60 * 1000 )); Date endTime = new Date(lxc.getStartDate().getTime() + ( global.getLxcMinu() * 60 * 1000 ));
lxc.setShutdownDate(endTime); lxc.setShutdownDate(endTime);
/*3.redis 放置状态*/ /*3.redis 放置状态*/
rcRedisServiceImpl.setBytes(global.getLxcPrefix() + lxc.getUserId(), String key = global.getLxcPrefix() + "_" + lxc.getUserId();
rcRedisServiceImpl.setBytes(key,
SerializationUtils.serializer(lxc)); SerializationUtils.serializer(lxc));
/*4.定时关闭 */ /*4.定时关闭 */
schedulerFactoryBean.getScheduler(); schedulerFactoryBean.getScheduler();
/*任务参数*/ /*任务参数*/
Map jobParam = new HashMap(); Map jobParam = new HashMap();
jobParam.put("containerName","_" + lxc.getUserId()); jobParam.put("redisKeyId",key);
jobParam.put("containerName",this.getModelProject(lxc.getCode()) + "_" + lxc.getUserId());
jobParam.put("containerPath",destPath); jobParam.put("containerPath",destPath);
jobParam.put("containerPort",port); jobParam.put("containerPort",port);
JobDetail job = JobBuilder.newJob(StopLxcJob.class). JobDetail job = JobBuilder.newJob(StopLxcJob.class).
...@@ -125,9 +125,10 @@ public class BCodeLxcServiceImpl implements BCodeLxcService { ...@@ -125,9 +125,10 @@ public class BCodeLxcServiceImpl implements BCodeLxcService {
log.error(e.getMessage()); log.error(e.getMessage());
} }
/*5.端口放进去 */ /*5.端口放进去 */
ports.add(port); rcRedisServiceImpl.setList("lxcKeys",
rcRedisServiceImpl.setBytes("lxcPorts", key);
SerializationUtils.serializer(ports)); rcRedisServiceImpl.setList("lxcPorts",
port.toString());
return result; return result;
} }
...@@ -138,7 +139,7 @@ public class BCodeLxcServiceImpl implements BCodeLxcService { ...@@ -138,7 +139,7 @@ public class BCodeLxcServiceImpl implements BCodeLxcService {
* @param maxPort * @param maxPort
* @return * @return
*/ */
private synchronized Integer getIdleWithPorts(List<Integer> ports, Integer port, Integer maxPort) { private synchronized Integer getIdleWithPorts(List<String> ports, Integer port, Integer maxPort) {
int choosePort = 0; int choosePort = 0;
/*端口占用满了*/ /*端口占用满了*/
if(ports.size() -1 == maxPort - port) if(ports.size() -1 == maxPort - port)
...@@ -147,7 +148,7 @@ public class BCodeLxcServiceImpl implements BCodeLxcService { ...@@ -147,7 +148,7 @@ public class BCodeLxcServiceImpl implements BCodeLxcService {
for(int i = port ; i < maxPort - port ; i++){ for(int i = port ; i < maxPort - port ; i++){
flag = false; flag = false;
for (int j = 0 ; j < ports.size() ; j++){ for (int j = 0 ; j < ports.size() ; j++){
if(port == ports.get(j)) { if(port == Integer.parseInt(ports.get(j))) {
flag = true; flag = true;
break; break;
} }
...@@ -170,7 +171,7 @@ public class BCodeLxcServiceImpl implements BCodeLxcService { ...@@ -170,7 +171,7 @@ public class BCodeLxcServiceImpl implements BCodeLxcService {
if(global.getJavaProject().equals(code)) if(global.getJavaProject().equals(code))
return "java"; return "java";
else if(global.getHtmlProject().equals(code)) else if(global.getHtmlProject().equals(code))
return "html"; return "apache";
else else
return ""; return "";
} }
......
...@@ -18,6 +18,7 @@ import org.rcisoft.business.bstudent.entity.BStudentDto; ...@@ -18,6 +18,7 @@ import org.rcisoft.business.bstudent.entity.BStudentDto;
import org.rcisoft.common.component.Global; import org.rcisoft.common.component.Global;
import org.rcisoft.core.exception.ServiceException; import org.rcisoft.core.exception.ServiceException;
import org.rcisoft.core.result.CommandResult; import org.rcisoft.core.result.CommandResult;
import org.rcisoft.core.result.ResultExceptionEnum;
import org.rcisoft.core.result.ResultServiceEnums; import org.rcisoft.core.result.ResultServiceEnums;
import org.rcisoft.core.service.RcRedisService; import org.rcisoft.core.service.RcRedisService;
import org.rcisoft.core.service.SerializationUtils; import org.rcisoft.core.service.SerializationUtils;
...@@ -76,13 +77,13 @@ public class BCodeServiceImpl implements BCodeService { ...@@ -76,13 +77,13 @@ public class BCodeServiceImpl implements BCodeService {
return this.readSimpleFile(slId,chapId,CodeType.SIM_JAVA,userInfo,studentCode); return this.readSimpleFile(slId,chapId,CodeType.SIM_JAVA,userInfo,studentCode);
/*java 工程*/ /*java 工程*/
if(examType.equals(global.getJavaProject())) if(examType.equals(global.getJavaProject()))
return this.readProjectFile(slId,chapId,userInfo,studentCode); return this.readProjectFile(slId,chapId,userInfo,studentCode,global.getJavaProject());
/*html 单文件*/ /*html 单文件*/
if(examType.equals(global.getHtmlSimple())) if(examType.equals(global.getHtmlSimple()))
return this.readSimpleFile(slId,chapId,CodeType.SIM_HTML,userInfo,studentCode); return this.readSimpleFile(slId,chapId,CodeType.SIM_HTML,userInfo,studentCode);
/*html 工程*/ /*html 工程*/
if(examType.equals(global.getHtmlProject())) if(examType.equals(global.getHtmlProject()))
return this.readProjectFile(slId,chapId,userInfo,studentCode); return this.readProjectFile(slId,chapId,userInfo,studentCode,global.getHtmlProject());
return null; return null;
} }
...@@ -140,7 +141,8 @@ public class BCodeServiceImpl implements BCodeService { ...@@ -140,7 +141,8 @@ public class BCodeServiceImpl implements BCodeService {
* @param userInfo * @param userInfo
* @return * @return
*/ */
private List<BCodeFile> readProjectFile(String slId, String chapterId, String userInfo, String StudentCode) { private List<BCodeFile> readProjectFile(String slId, String chapterId, String userInfo, String StudentCode,
String examCode) {
BCodeLxc lxc = new BCodeLxc(); BCodeLxc lxc = new BCodeLxc();
Map param = new HashMap<>(); Map param = new HashMap<>();
List<BCodeFile> codeFile = new ArrayList<>(); List<BCodeFile> codeFile = new ArrayList<>();
...@@ -153,8 +155,38 @@ public class BCodeServiceImpl implements BCodeService { ...@@ -153,8 +155,38 @@ public class BCodeServiceImpl implements BCodeService {
+ global.getCOURSE_PROJECT_LOCATION() + File.separator + global.getCOURSE_PROJECT_LOCATION() + File.separator
+ userInfo + File.separator + userInfo + File.separator
+ StudentCode; + StudentCode;
/*工程 容器docker dir*/
String dirPath = global.getBASE_UPLOAD_SERVER_LOCATION() + File.separator
+ global.getCOURSE_LOCATION() + File.separator
+ global.getSL_LOCATION() + File.separator
+ slId + File.separator
+ chapterId +File.separator
+ global.getCOURSE_PROJECT_LOCATION() + File.separator
+ userInfo + File.separator;
lxc.setUserId(userInfo); lxc.setUserId(userInfo);
lxc.setWorkingDir(path); lxc.setWorkingDir(dirPath);
lxc.setCode(examCode);
lxc.setSl(slId);
lxc.setChapterId(chapterId);
/*容器是否已启动*/
byte[] results = rcRedisServiceImpl.getBytes(global.getLxcPrefix() + "_" + lxc.getUserId());
if(null != results) {
lxc = SerializationUtils.deserializer(results, BCodeLxc.class);
/*别的课或别的节已开启容器,返回错误*/
if(null != lxc && (!slId.equals(lxc.getSl()) || !chapterId.equals(lxc.getChapterId()))){
throw new ServiceException(ResultExceptionEnum.EXIST_LXC_SERVER);
}
else if(null != lxc){
/*容器参数*/
param.put("port", lxc.getContainerPort());
param.put("endTime",lxc.getShutdownDate().getTime());
}
/*开启容器*/
else
this.startLxc(param,lxc);
}
else
this.startLxc(param,lxc);
try{ try{
File simplePath = new File(path); File simplePath = new File(path);
BCodeFile simpleCodeFile = null; BCodeFile simpleCodeFile = null;
...@@ -168,22 +200,6 @@ public class BCodeServiceImpl implements BCodeService { ...@@ -168,22 +200,6 @@ public class BCodeServiceImpl implements BCodeService {
//codeFile.add(simpleCodeFile); //codeFile.add(simpleCodeFile);
getFileList(simplePath,codeFile,simpleCodeFile,isFile); getFileList(simplePath,codeFile,simpleCodeFile,isFile);
} }
/*容器是否已启动*/
byte[] results = rcRedisServiceImpl.getBytes(global.getLxcPrefix() + lxc.getUserId());
if(null != results) {
lxc = SerializationUtils.deserializer(results, BCodeLxc.class);
/*已开启*/
if(null != lxc && codeFile.size() > 0){
/*容器参数*/
param.put("port", lxc.getContainerPort());
param.put("endTime",lxc.getShutdownDate().getTime());
}
/*开启容器*/
else
this.startLxc(param,lxc);
}
else
//this.startLxc(param,lxc);
codeFile.get(0).setLxcParam(param); codeFile.get(0).setLxcParam(param);
}catch (Exception e){ }catch (Exception e){
......
package org.rcisoft.business.bcode.task;
import lombok.extern.slf4j.Slf4j;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.rcisoft.business.bcode.model.BCodeLxc;
import org.rcisoft.common.component.Global;
import org.rcisoft.core.command.LxcCommand;
import org.rcisoft.core.result.CommandResult;
import org.rcisoft.core.service.RcRedisService;
import org.rcisoft.core.service.SerializationUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.io.File;
import java.util.Date;
import java.util.List;
/**
* Created by lcy on 18/1/10.
*
*
* 项目启动时,清除已到期的容器
* 解决因 服务器down 而造成的 stopLxcJob 未执行问题
*
*
*/
@Component
@Slf4j
public class ClearLxcJob implements Job {
@Autowired
private RcRedisService rcRedisServiceImpl;
@Autowired
private LxcCommand lxcCommand;
@Autowired
private Global global;
@Override
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
/*所有启动的容器*/
List<String> keys = rcRedisServiceImpl.getList("lxcKeys");
if(null == keys || 0 == keys.size())
return;
/*name*/
for (String key :
keys) {
this.stopLxc(key);
}
}
/**
* 关闭容器
* @param key
*/
private void stopLxc(String key) {
String containerPath = null;
byte[] results = rcRedisServiceImpl.getBytes(key);
BCodeLxc lxc = null;
if (null != results) {
lxc = SerializationUtils.deserializer(results, BCodeLxc.class);
if (null == lxc)
return;
Date shutdown = lxc.getShutdownDate();
/*未到点*/
if(null != shutdown && shutdown.after(new Date()))
return;
/*到点了*/
containerPath = global.getBASE_UPLOAD_SERVER_LOCATION() + File.separator +
global.getLxcDockerfilePath() + File.separator + lxc.getUserId() + File.separator;
/*关闭容器*/
/*2.docker-compose 起容器*/
CommandResult commandResult = null;
commandResult = lxcCommand.startOrDownLxc(containerPath,false);
if(!commandResult.isSuccess())
return;
/*3.移除容器*/
rcRedisServiceImpl.remove(key);
/*4.移除端口*/
rcRedisServiceImpl.removeList("lxcKeys",
key);
rcRedisServiceImpl.removeList("lxcPorts",lxc.getContainerPort() + "");
}
}
}
...@@ -28,9 +28,11 @@ public class StopLxcJob implements Job { ...@@ -28,9 +28,11 @@ public class StopLxcJob implements Job {
@Override @Override
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException { public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
/*1.容器名称*/ /*1.容器名称*/
String redisKeyId = jobExecutionContext.getMergedJobDataMap().getString("redisKeyId");
String containerName = jobExecutionContext.getMergedJobDataMap().getString("containerName"); String containerName = jobExecutionContext.getMergedJobDataMap().getString("containerName");
String containerPath = jobExecutionContext.getMergedJobDataMap().getString("containerPath"); String containerPath = jobExecutionContext.getMergedJobDataMap().getString("containerPath");
String containerPort = jobExecutionContext.getMergedJobDataMap().getString("containerPort"); int containerPort = jobExecutionContext.getMergedJobDataMap().getInt("containerPort");
if(StringUtils.isEmpty(containerName) || StringUtils.isEmpty(containerPath)){ if(StringUtils.isEmpty(containerName) || StringUtils.isEmpty(containerPath)){
log.info("----任务异常----"); log.info("----任务异常----");
return; return;
...@@ -44,7 +46,13 @@ public class StopLxcJob implements Job { ...@@ -44,7 +46,13 @@ public class StopLxcJob implements Job {
/*2.docker-compose 起容器*/ /*2.docker-compose 起容器*/
CommandResult commandResult = null; CommandResult commandResult = null;
commandResult = lxcCommand.startOrDownLxc(containerPath,false); commandResult = lxcCommand.startOrDownLxc(containerPath,false);
/*3.移除端口*/ if(!commandResult.isSuccess())
return;
/*3.移除容器*/
rcRedisServiceImpl.remove(redisKeyId);
/*4.移除端口*/
rcRedisServiceImpl.removeList("lxcKeys",
redisKeyId);
rcRedisServiceImpl.removeList("lxcPorts",containerPort + "");
} }
} }
...@@ -9,7 +9,6 @@ import org.rcisoft.core.entity.IdEntity; ...@@ -9,7 +9,6 @@ import org.rcisoft.core.entity.IdEntity;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.Transient; import javax.persistence.Transient;
import java.util.Date;
/** /**
* Created with CodeGenerator on . * Created with CodeGenerator on .
......
package org.rcisoft.business.listener;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
/**
* Created by lcy on 18/1/19.
*
*
*
* JobDetail job = JobBuilder.newJob(ClearLxcJob.class).
withIdentity(IDENTITY_LXC_GROUP, JOB_LXC_GROUP).
usingJobData(new JobDataMap(new HashMap())).build();
Trigger trigger = TriggerBuilder.newTrigger().forJob(job)
.usingJobData(new JobDataMap(new HashMap()))
.withIdentity(IDENTITY_LXC_GROUP)
.startNow().build();
// 触发器时间设定
Scheduler sched = schedulerFactoryBean.getScheduler();
try {
sched.scheduleJob(job, trigger);
// 启动
if (!sched.isShutdown()) {
sched.start();
}
}catch (Exception e){
log.error(e.getMessage());
}
*/
@Slf4j
public class RcListener implements ServletContextListener {
/*任务组名*/
private static final String JOB_LXC_GROUP = "lxc_clear_job_group";
/*触发器组名*/
private static final String TRIGGER_LXC_GROUP = "lxc_clear_trigger_group";
/*任务 identity*/
private static final String IDENTITY_LXC_GROUP = "lxc_clear_job";
@Autowired
private SchedulerFactoryBean schedulerFactoryBean;
@Override
public void contextDestroyed(ServletContextEvent arg0) {
}
/**
* 执行任务
* @param arg0
*/
@Override
public void contextInitialized(ServletContextEvent arg0) {
}
}
...@@ -4,11 +4,13 @@ import com.alibaba.fastjson.JSON; ...@@ -4,11 +4,13 @@ import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.rcisoft.business.listener.RcListener;
import org.rcisoft.core.exception.ServiceException; import org.rcisoft.core.exception.ServiceException;
import org.rcisoft.core.result.Result; import org.rcisoft.core.result.Result;
import org.rcisoft.core.result.ResultCode; import org.rcisoft.core.result.ResultCode;
import org.rcisoft.core.util.ResultGenerator; import org.rcisoft.core.util.ResultGenerator;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.HttpMessageConverter;
...@@ -237,4 +239,16 @@ public class MvcConfig extends WebMvcConfigurerAdapter { ...@@ -237,4 +239,16 @@ public class MvcConfig extends WebMvcConfigurerAdapter {
ContentNegotiationConfigurer configurer) { ContentNegotiationConfigurer configurer) {
configurer.favorPathExtension(false); configurer.favorPathExtension(false);
} }
/**
* 监听器
* @return
*/
@Bean
public ServletListenerRegistrationBean servletListenerRegistrationBean(){
ServletListenerRegistrationBean servletListenerRegistrationBean = new ServletListenerRegistrationBean();
servletListenerRegistrationBean.setListener(new RcListener());
return servletListenerRegistrationBean;
}
} }
package org.rcisoft.config; package org.rcisoft.config;
import org.rcisoft.core.component.RcJobFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.quartz.SchedulerFactoryBean; import org.springframework.scheduling.quartz.SchedulerFactoryBean;
...@@ -12,6 +14,9 @@ public class QuartzConfig { ...@@ -12,6 +14,9 @@ public class QuartzConfig {
@Autowired
private RcJobFactory rcJobFactory;
/** /**
* attention: * attention:
* Details:定义quartz调度工厂 * Details:定义quartz调度工厂
...@@ -19,6 +24,8 @@ public class QuartzConfig { ...@@ -19,6 +24,8 @@ public class QuartzConfig {
@Bean(name = "scheduler") @Bean(name = "scheduler")
public SchedulerFactoryBean schedulerFactory() { public SchedulerFactoryBean schedulerFactory() {
SchedulerFactoryBean bean = new SchedulerFactoryBean(); SchedulerFactoryBean bean = new SchedulerFactoryBean();
/*可以注入bean*/
bean.setJobFactory(rcJobFactory);
// 用于quartz集群,QuartzScheduler 启动时更新己存在的Job // 用于quartz集群,QuartzScheduler 启动时更新己存在的Job
bean.setOverwriteExistingJobs(true); bean.setOverwriteExistingJobs(true);
// 延时启动,应用启动1秒后 // 延时启动,应用启动1秒后
......
...@@ -44,9 +44,9 @@ public class LxcCommand { ...@@ -44,9 +44,9 @@ public class LxcCommand {
public CommandResult startOrDownLxc(String dest,boolean isStart){ public CommandResult startOrDownLxc(String dest,boolean isStart){
if("1".equals(global.getLxcIsRemote())) if("1".equals(global.getLxcIsRemote()))
return this.startOrDownLxc(dest,true,true); return this.startOrDownLxc(dest,isStart,true);
else else
return this.startOrDownLxc(dest,true,false); return this.startOrDownLxc(dest,isStart,false);
} }
/** /**
...@@ -70,7 +70,7 @@ public class LxcCommand { ...@@ -70,7 +70,7 @@ public class LxcCommand {
Runtime.getRuntime().exec("cd " + dest + " && " + START_LXC_COMMAND); Runtime.getRuntime().exec("cd " + dest + " && " + START_LXC_COMMAND);
else{ else{
if (isRemote) if (isRemote)
remoteExecuteCommand.execute(START_LXC_COMMAND,dest); remoteExecuteCommand.execute(DOWN_LXC_COMMAND,dest);
else else
Runtime.getRuntime().exec("cd " + dest + " && " + DOWN_LXC_COMMAND); Runtime.getRuntime().exec("cd " + dest + " && " + DOWN_LXC_COMMAND);
dirPath.delete(); dirPath.delete();
......
...@@ -21,6 +21,7 @@ public enum ResultExceptionEnum { ...@@ -21,6 +21,7 @@ public enum ResultExceptionEnum {
SERVER_HAS_APP(4007,"服务器仍有关联应用,不可删除"), SERVER_HAS_APP(4007,"服务器仍有关联应用,不可删除"),
OS_HAS_SERVER(4008,"操作系统仍有关联服务器,不可删除"), OS_HAS_SERVER(4008,"操作系统仍有关联服务器,不可删除"),
START_LXC_SERVER(4009,"启动容器失败"), START_LXC_SERVER(4009,"启动容器失败"),
EXIST_LXC_SERVER(4010,"已开始其他课程实验,请先关闭其他课程实验"),
; ;
private Integer code; private Integer code;
......
...@@ -2,6 +2,8 @@ package org.rcisoft.core.service; ...@@ -2,6 +2,8 @@ package org.rcisoft.core.service;
import redis.clients.jedis.Jedis; import redis.clients.jedis.Jedis;
import java.util.List;
/** /**
* Created by lcy on 18/1/8. * Created by lcy on 18/1/8.
*/ */
...@@ -46,4 +48,29 @@ public interface RcRedisService { ...@@ -46,4 +48,29 @@ public interface RcRedisService {
* @return * @return
*/ */
public byte[] getBytes(String key); public byte[] getBytes(String key);
/**
* 清除
* @param key
*/
public void remove(String key);
/**
* 获取list
* @param key
*/
public List getList(String key);
/**
* set list
* @param key
* @param value
*/
public void setList(String key,String value);
/**
* 从 list 中 删除
* @param key
*/
public void removeList(String key,String value);
} }
...@@ -7,6 +7,8 @@ import org.springframework.stereotype.Service; ...@@ -7,6 +7,8 @@ import org.springframework.stereotype.Service;
import redis.clients.jedis.Jedis; import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool; import redis.clients.jedis.JedisPool;
import java.util.List;
/** /**
* Created by lcy on 18/1/8. * Created by lcy on 18/1/8.
*/ */
...@@ -93,4 +95,69 @@ public class RcRedisServiceImpl implements RcRedisService { ...@@ -93,4 +95,69 @@ public class RcRedisServiceImpl implements RcRedisService {
} }
return result; return result;
} }
@Override
public void remove(String key) {
Jedis jedis=null;
try{
jedis = getResource();
jedis.del(key);
log.info("Redis del success - " + key );
} catch (Exception e) {
e.printStackTrace();
log.error("Redis set error: "+ e.getMessage() +" - " + key );
}finally{
returnResource(jedis);
}
}
@Override
public List getList(String key) {
Jedis jedis=null;
List result = null ;
try{
jedis = getResource();
result = jedis.lrange(key, 0, -1);
log.info("Redis get list success - " + key + ", value:" + result);
} catch (Exception e) {
e.printStackTrace();
log.error("Redis set error: "+ e.getMessage() +" - " + key );
}finally{
returnResource(jedis);
}
return result;
}
@Override
public void setList(String key, String value) {
Jedis jedis=null;
try{
jedis = getResource();
jedis.rpush(key, value);
log.info("Redis set list success - " + key + ", value:" + value);
} catch (Exception e) {
e.printStackTrace();
log.error("Redis set error: "+ e.getMessage() +" - " + key + ", value:" + value);
}finally{
returnResource(jedis);
}
}
@Override
public void removeList(String key,String value) {
Jedis jedis=null;
try{
jedis = getResource();
jedis.lrem(key,1,value);
log.info("Redis remove list success - " + key + ", value:" + value);
} catch (Exception e) {
e.printStackTrace();
log.error("Redis set error: "+ e.getMessage() +" - " + key + ", value:" + value);
}finally{
returnResource(jedis);
}
}
} }
...@@ -42,7 +42,7 @@ public class FreemarkerUtil { ...@@ -42,7 +42,7 @@ public class FreemarkerUtil {
/*目录不存在*/ /*目录不存在*/
if(!dirFile.exists()) if(!dirFile.exists())
dirFile.mkdirs(); dirFile.mkdirs();
Template template = freemarkerConfiguration.getTemplate(model); // freeMarker template Template template = freemarkerConfiguration.getTemplate("lxc" + File.separator + model + ".ftl"); // freeMarker template
template.process(param,new FileWriter(new File(destPath + LxcCommand.LXC_SETTING_NAME))); template.process(param,new FileWriter(new File(destPath + LxcCommand.LXC_SETTING_NAME)));
commandResult = new CommandResult(ResultCode.SUCCESS,null,null); commandResult = new CommandResult(ResultCode.SUCCESS,null,null);
}catch (Exception e){ }catch (Exception e){
......
...@@ -13,7 +13,7 @@ server: ...@@ -13,7 +13,7 @@ server:
druid: druid:
url: jdbc:mysql://127.0.0.1:3306/edu_db?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&useSSL=false url: jdbc:mysql://127.0.0.1:3306/edu_db?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&useSSL=false
username: root username: root
password: liuzhichao password: cy
initial-size: 1 initial-size: 1
min-idle: 1 min-idle: 1
max-active: 20 max-active: 20
...@@ -74,7 +74,7 @@ lxc: ...@@ -74,7 +74,7 @@ lxc:
lxc_dockerfilePath: /eduLxc lxc_dockerfilePath: /eduLxc
lxc_initPort: 20001 lxc_initPort: 20001
lxc_maxPort: 30000 lxc_maxPort: 30000
lxc_minu: 30 lxc_minu: 15
lxc_isRemote: 1 lxc_isRemote: 1
springfox: springfox:
documentation: documentation:
...@@ -104,7 +104,7 @@ global: ...@@ -104,7 +104,7 @@ global:
min_password: 6 min_password: 6
max_password: 16 max_password: 16
path: path:
base_upload_server_location: /Users/liuzhichao/eduServer base_upload_server_location: /working/resource/eduServer/
course_location: course course_location: course
lesson_location: lesson lesson_location: lesson
sl_location: sl sl_location: sl
...@@ -141,7 +141,7 @@ global: ...@@ -141,7 +141,7 @@ global:
html_project: '1002' html_project: '1002'
serverLxc: serverLxc:
ip: 127.0.0.1 ip: 192.168.1.130
username: root username: root
password: 123456 password: 123456
...@@ -63,13 +63,10 @@ spring: ...@@ -63,13 +63,10 @@ spring:
max-wait: -1 max-wait: -1
database: 0 database: 0
password: '' password: ''
freemarker:
charset: UTF-8
springfox: suffix: .ftl
documentation: template-loader-path: classpath:/templates/
swagger:
v2:
path: /api-docs
lxc: lxc:
lxc_prefix: lessonLxc lxc_prefix: lessonLxc
...@@ -79,6 +76,12 @@ lxc: ...@@ -79,6 +76,12 @@ lxc:
lxc_maxPort: 30000 lxc_maxPort: 30000
lxc_minu: 30 lxc_minu: 30
lxc_isRemote: 1 lxc_isRemote: 1
springfox:
documentation:
swagger:
v2:
path: /api-docs
jwt: jwt:
header: Authorization header: Authorization
secret: mySecret secret: mySecret
...@@ -138,6 +141,6 @@ global: ...@@ -138,6 +141,6 @@ global:
html_project: '1002' html_project: '1002'
serverLxc: serverLxc:
ip: 127.0.0.1 ip: 192.168.1.130
username: root username: root
password: 123456 password: 123456
\ No newline at end of file
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
<!--滚动策略--> <!--滚动策略-->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!--路径--> <!--路径-->
<fileNamePattern>/Users/liuzhichao/logback/info.%d.log</fileNamePattern> <fileNamePattern>/working/test/info.%d.log</fileNamePattern>
</rollingPolicy> </rollingPolicy>
</appender> </appender>
...@@ -45,7 +45,7 @@ ...@@ -45,7 +45,7 @@
<!--滚动策略--> <!--滚动策略-->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!--路径--> <!--路径-->
<fileNamePattern>/Users/liuzhichao/logback/error.%d.log</fileNamePattern> <fileNamePattern>/working/test/error.%d.log</fileNamePattern>
</rollingPolicy> </rollingPolicy>
</appender> </appender>
<!-- <!--
......
version: '2' version: '2'
services: services:
java: apache:
image: httpd:2.4 image: httpd:2.4
container_name: 'apache_${lxcName}' container_name: 'apache_${lxcName}'
restart: always restart: always
ports: ports:
- '${lxcPort}:80' - '${lxcPort?c}:80'
volumes: volumes:
- ${lxcPath}:/var/www/html/data/ - ${lxcPath}:/var/www/html/data/
\ No newline at end of file
...@@ -5,6 +5,7 @@ services: ...@@ -5,6 +5,7 @@ services:
container_name: 'java_${lxcName}' container_name: 'java_${lxcName}'
restart: always restart: always
ports: ports:
- '${lxcPort}:80' - '${lxcPort?c}:80'
volumes: volumes:
- ${lxcPath}:/var/www/html/data/ - ${lxcPath}:/working/code
\ No newline at end of file command: tail -f /dev/null
\ No newline at end of file
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