Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
education
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
李丛阳
education
Commits
4e8cf607
Commit
4e8cf607
authored
Jan 22, 2018
by
李丛阳
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
关闭容器
parent
96f5fb05
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
115 additions
and
3 deletions
+115
-3
BCodeController.java
...rg/rcisoft/business/bcode/controller/BCodeController.java
+32
-0
BCodeLxcService.java
...a/org/rcisoft/business/bcode/service/BCodeLxcService.java
+1
-1
BCodeService.java
...java/org/rcisoft/business/bcode/service/BCodeService.java
+19
-0
BCodeLxcServiceImpl.java
...soft/business/bcode/service/impl/BCodeLxcServiceImpl.java
+18
-2
BCodeServiceImpl.java
...rcisoft/business/bcode/service/impl/BCodeServiceImpl.java
+45
-0
No files found.
src/main/java/org/rcisoft/business/bcode/controller/BCodeController.java
View file @
4e8cf607
...
...
@@ -11,6 +11,7 @@ import org.rcisoft.common.controller.PaginationController;
import
org.rcisoft.core.constant.MessageConstant
;
import
org.rcisoft.core.exception.ServiceException
;
import
org.rcisoft.core.model.PersistModel
;
import
org.rcisoft.core.result.CommandResult
;
import
org.rcisoft.core.result.Result
;
import
org.rcisoft.core.result.ResultServiceEnums
;
import
org.rcisoft.core.util.CompileUtil
;
...
...
@@ -74,6 +75,37 @@ public class BCodeController extends PaginationController {
@ApiOperation
(
value
=
"实验是否启动"
,
notes
=
"实验是否启动"
)
@ApiImplicitParams
({
@ApiImplicitParam
(
name
=
"slId"
,
value
=
"开课ID"
,
required
=
true
,
dataType
=
"varchar"
),
@ApiImplicitParam
(
name
=
"chapId"
,
value
=
"章节ID"
,
required
=
true
,
dataType
=
"varchar"
)})
@GetMapping
(
value
=
"/isStartedExam"
)
public
Result
isStartedExam
(
@RequestParam
(
"slId"
)
String
slId
,
@RequestParam
(
"chapId"
)
String
chapId
){
Integer
result
=
bCodeServiceImpl
.
isOpenLxcFromUser
(
UserUtil
.
getUserInfoProp
(
getToken
(),
UserUtil
.
USER_ID
),
slId
,
chapId
);
return
Result
.
builder
(
new
PersistModel
(
result
),
MessageConstant
.
MESSAGE_ALERT_SUCCESS
,
MessageConstant
.
MESSAGE_ALERT_ERROR
,
result
);
}
@ApiOperation
(
value
=
"关闭实验"
,
notes
=
"关闭实验"
)
@ApiImplicitParams
({
@ApiImplicitParam
(
name
=
"slId"
,
value
=
"开课ID"
,
required
=
true
,
dataType
=
"varchar"
),
@ApiImplicitParam
(
name
=
"chapId"
,
value
=
"章节ID"
,
required
=
true
,
dataType
=
"varchar"
)})
@GetMapping
(
value
=
"/stopExam"
)
public
Result
stopExam
(
@RequestParam
(
"slId"
)
String
slId
,
@RequestParam
(
"chapId"
)
String
chapId
){
CommandResult
result
=
bCodeServiceImpl
.
stopExam
(
UserUtil
.
getUserInfoProp
(
getToken
(),
UserUtil
.
USER_ID
),
slId
,
chapId
);
return
Result
.
builder
(
new
PersistModel
(
result
.
isSuccess
()?
1
:
0
),
result
.
getMessage
(),
result
.
getMessage
(),
result
);
}
@ApiOperation
(
value
=
"保存实验代码"
,
notes
=
"学生保存自己的实验"
)
@ApiImplicitParams
({
@ApiImplicitParam
(
name
=
"slId"
,
value
=
"开课ID"
,
required
=
true
,
dataType
=
"varchar"
),
@ApiImplicitParam
(
name
=
"chapId"
,
value
=
"章节ID"
,
required
=
true
,
dataType
=
"varchar"
),
...
...
src/main/java/org/rcisoft/business/bcode/service/BCodeLxcService.java
View file @
4e8cf607
...
...
@@ -20,7 +20,7 @@ public interface BCodeLxcService {
* 关闭code 容器
* @param lxc
*/
public
void
stopBCodeLxc
(
BCodeLxc
lxc
);
public
CommandResult
stopBCodeLxc
(
BCodeLxc
lxc
);
/**
* 清理 code 容器
...
...
src/main/java/org/rcisoft/business/bcode/service/BCodeService.java
View file @
4e8cf607
...
...
@@ -2,6 +2,7 @@ package org.rcisoft.business.bcode.service;
import
org.rcisoft.business.bcode.model.BCodeFile
;
import
org.rcisoft.business.bcode.model.StudentFile
;
import
org.rcisoft.core.result.CommandResult
;
import
java.util.List
;
...
...
@@ -34,4 +35,22 @@ public interface BCodeService {
String
exportFiles
(
String
slId
,
String
studentId
,
String
type
,
String
slCode
);
List
<
StudentFile
>
queryAllStudentCode
(
String
slId
,
String
chapterId
);
/**
* 判断是否开启
*
* @param userId
* @return 1 未开
* 0 已开
*/
Integer
isOpenLxcFromUser
(
String
userId
,
String
slId
,
String
chapterId
);
/**
* 关闭 实验环境
* @param userId
* @param slId
* @param chapterId
* @return
*/
CommandResult
stopExam
(
String
userId
,
String
slId
,
String
chapterId
);
}
src/main/java/org/rcisoft/business/bcode/service/impl/BCodeLxcServiceImpl.java
View file @
4e8cf607
...
...
@@ -174,8 +174,24 @@ public class BCodeLxcServiceImpl implements BCodeLxcService {
@Override
public
void
stopBCodeLxc
(
BCodeLxc
lxc
)
{
public
CommandResult
stopBCodeLxc
(
BCodeLxc
lxc
)
{
/*1.拼key*/
String
key
=
global
.
getLxcPrefix
()
+
"_"
+
lxc
.
getUserId
();
/*2.拼docker-compose.yml */
String
destPath
=
global
.
getPHYSICAL_UPLOAD_SERVER_LOCATION
()
+
File
.
separator
+
global
.
getLxcDockerfilePath
()
+
File
.
separator
+
lxc
.
getUserId
()
+
File
.
separator
;;
CommandResult
commandResult
=
null
;
commandResult
=
lxcCommand
.
startOrDownLxc
(
destPath
,
false
);
if
(!
commandResult
.
isSuccess
())
return
commandResult
;
/*3.移除容器*/
rcRedisServiceImpl
.
remove
(
key
);
/*4.移除端口*/
rcRedisServiceImpl
.
removeList
(
"lxcKeys"
,
key
);
rcRedisServiceImpl
.
removeList
(
"lxcPorts"
,
lxc
.
getContainerPort
()
+
""
);
return
commandResult
;
}
...
...
src/main/java/org/rcisoft/business/bcode/service/impl/BCodeServiceImpl.java
View file @
4e8cf607
...
...
@@ -18,6 +18,7 @@ import org.rcisoft.business.bstudent.entity.BStudentDto;
import
org.rcisoft.common.component.Global
;
import
org.rcisoft.core.exception.ServiceException
;
import
org.rcisoft.core.result.CommandResult
;
import
org.rcisoft.core.result.ResultCode
;
import
org.rcisoft.core.result.ResultExceptionEnum
;
import
org.rcisoft.core.result.ResultServiceEnums
;
import
org.rcisoft.core.service.RcRedisService
;
...
...
@@ -507,4 +508,48 @@ public class BCodeServiceImpl implements BCodeService {
}
return
studentFiles
;
}
@Override
public
Integer
isOpenLxcFromUser
(
String
userId
,
String
slId
,
String
chapterId
)
{
BCodeLxc
lxc
=
null
;
/*容器是否已启动*/
byte
[]
results
=
rcRedisServiceImpl
.
getBytes
(
global
.
getLxcPrefix
()
+
"_"
+
userId
);
if
(
null
!=
results
)
{
lxc
=
SerializationUtils
.
deserializer
(
results
,
BCodeLxc
.
class
);
/*别的课或别的节已开启容器,返回错误*/
if
(
null
!=
lxc
&&
(!
slId
.
equals
(
lxc
.
getSl
())
||
!
chapterId
.
equals
(
lxc
.
getChapterId
()))){
/*已开*/
return
0
;
}
/*再次打开已开启的容器*/
return
1
;
}
/*未开*/
return
1
;
}
@Override
public
CommandResult
stopExam
(
String
userId
,
String
slId
,
String
chapterId
)
{
BCodeLxc
lxc
=
null
;
/*容器是否已启动*/
byte
[]
results
=
rcRedisServiceImpl
.
getBytes
(
global
.
getLxcPrefix
()
+
"_"
+
userId
);
if
(
null
!=
results
)
{
lxc
=
SerializationUtils
.
deserializer
(
results
,
BCodeLxc
.
class
);
/*别的课或别的节已开启容器,返回错误*/
if
(
null
!=
lxc
&&
(!
slId
.
equals
(
lxc
.
getSl
())
||
!
chapterId
.
equals
(
lxc
.
getChapterId
()))){
/*已开*/
return
new
CommandResult
(
ResultCode
.
FAIL
,
"未开启对应的实验"
,
null
);
}
else
if
(
null
==
lxc
)
return
new
CommandResult
(
ResultCode
.
FAIL
,
"未开启实验"
,
null
);
else
{
/*关闭容器*/
return
bCodeLxcServiceImpl
.
stopBCodeLxc
(
lxc
);
}
}
/*未开*/
return
new
CommandResult
(
ResultCode
.
FAIL
,
"未开启实验"
,
null
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment