Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
CoTA
cota-backend
Commits
841667fb
Commit
841667fb
authored
3 months ago
by
mamunozgil
Browse files
Options
Download
Email Patches
Plain Diff
Add dynamic paths to test
parent
2eb0ce9c
Pipeline
#10915
passed with stage
in 18 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/main/java/de/hftstuttgart/dtabackend/rest/v1/task/TaskUpload.java
+3
-3
...a/de/hftstuttgart/dtabackend/rest/v1/task/TaskUpload.java
src/main/java/de/hftstuttgart/dtabackend/utils/DockerUtil.java
+38
-9
...ain/java/de/hftstuttgart/dtabackend/utils/DockerUtil.java
src/main/java/de/hftstuttgart/dtabackend/utils/ExecuteTestUtil.java
+3
-3
...ava/de/hftstuttgart/dtabackend/utils/ExecuteTestUtil.java
with
44 additions
and
15 deletions
+44
-15
src/main/java/de/hftstuttgart/dtabackend/rest/v1/task/TaskUpload.java
+
3
-
3
View file @
841667fb
...
...
@@ -33,14 +33,14 @@ public class TaskUpload {
private
static
final
Logger
LOG
=
LogManager
.
getLogger
(
TaskUpload
.
class
);
private
final
RepoUtil
repoUtil
;
private
final
Path
testTmp
Path
;
private
final
Path
assignmentSubmissions
Path
;
private
final
ExecuteTestUtil
executeTestUtil
;
private
final
Tika
tika
;
public
TaskUpload
(
Environment
env
,
RepoUtil
repoUtil
,
ExecuteTestUtil
executeTestUtil
)
{
this
.
repoUtil
=
repoUtil
;
this
.
executeTestUtil
=
executeTestUtil
;
this
.
testTmp
Path
=
Paths
.
get
(
env
.
getProperty
(
"tests.tmp.dir"
));
this
.
assignmentSubmissions
Path
=
Paths
.
get
(
env
.
getProperty
(
"tests.tmp.dir"
));
this
.
tika
=
new
Tika
();
}
...
...
@@ -68,7 +68,7 @@ public class TaskUpload {
private
Path
createWorkDirectory
()
throws
IOException
{
LOG
.
debug
(
"Creating new temporary directory"
);
Path
workDirectory
=
Files
.
createTempDirectory
(
testTmp
Path
,
"dta-submission"
);
Path
workDirectory
=
Files
.
createTempDirectory
(
assignmentSubmissions
Path
,
"dta-submission"
);
LOG
.
debug
(
"Working directory for test: {}"
,
workDirectory
.
toAbsolutePath
());
return
workDirectory
;
}
...
...
This diff is collapsed.
Click to expand it.
src/main/java/de/hftstuttgart/dtabackend/utils/DockerUtil.java
+
38
-
9
View file @
841667fb
...
...
@@ -59,27 +59,56 @@ public class DockerUtil {
image
,
e
.
getMessage
()));
}
LOG
.
debug
(
"creating container"
);
CreateContainerResponse
containerResponse
;
try
{
// Extract paths from binds
String
testPath
=
null
;
String
srcPath
=
null
;
String
resultPath
=
null
;
for
(
Bind
bind
:
binds
)
{
Volume
volume
=
bind
.
getVolume
();
if
(
volume
.
getPath
().
contains
(
"test"
))
{
testPath
=
bind
.
getPath
();
}
else
if
(
volume
.
getPath
().
contains
(
"src"
))
{
srcPath
=
bind
.
getPath
();
}
else
if
(
volume
.
getPath
().
contains
(
"result"
))
{
resultPath
=
bind
.
getPath
();
}
}
if
(
testPath
==
null
||
srcPath
==
null
||
resultPath
==
null
)
{
throw
new
IllegalArgumentException
(
"All required paths (testPath, srcPath, resultPath) must be provided."
);
}
containerResponse
=
dockerClient
.
createContainerCmd
(
"testcontainer"
)
.
withImage
(
image
)
.
withHostConfig
(
HostConfig
.
newHostConfig
()
.
withBinds
(
binds
))
.
withBinds
(
binds
)
)
.
withCmd
(
"java"
,
"-Djava.security.egd=file:/dev/./urandom"
,
"-jar"
,
"/data/app.jar"
,
String
.
format
(
"%s:%s"
,
srcPath
,
testPath
),
"/data/libs/*:/data/test/libs/*"
,
resultPath
)
.
exec
();
}
catch
(
DockerException
e
)
{
LOG
.
error
(
String
.
format
(
"Creating Docker Testrunner container failed with %s"
,
e
.
getMessage
()));
throw
e
;
}
LOG
.
debug
(
String
.
format
(
"container created: %s"
,
containerResponse
.
getId
()));
LOG
.
debug
(
String
.
format
(
"starting container %s"
,
containerResponse
.
getId
()));
dockerClient
.
startContainerCmd
(
containerResponse
.
getId
()).
exec
();
LOG
.
debug
(
String
.
format
(
"retrieving logs for container %s"
,
containerResponse
.
getId
()));
dockerClient
.
logContainerCmd
(
containerResponse
.
getId
())
.
withStdOut
(
true
)
...
...
@@ -92,7 +121,7 @@ public class DockerUtil {
LOG
.
debug
(
String
.
format
(
"LOG: %s"
,
new
String
(
frame
.
getPayload
(),
StandardCharsets
.
UTF_8
)));
}
});
LOG
.
debug
(
String
.
format
(
"waiting for completion of container %s"
,
containerResponse
.
getId
()));
int
ret
=
dockerClient
.
waitContainerCmd
(
containerResponse
.
getId
())
...
...
@@ -100,12 +129,12 @@ public class DockerUtil {
.
awaitCompletion
()
.
awaitStatusCode
();
LOG
.
debug
(
String
.
format
(
"container completed with status %d"
,
ret
));
LOG
.
debug
(
String
.
format
(
"deleting container %s"
,
containerResponse
.
getId
()));
dockerClient
.
removeContainerCmd
(
containerResponse
.
getId
())
.
withRemoveVolumes
(
true
)
.
exec
();
return
ret
;
}
}
}
This diff is collapsed.
Click to expand it.
src/main/java/de/hftstuttgart/dtabackend/utils/ExecuteTestUtil.java
+
3
-
3
View file @
841667fb
...
...
@@ -104,9 +104,9 @@ public class ExecuteTestUtil {
// Start the test-container with professor-given image and submission-specific volume mounts
dockerUtil
.
runContainer
(
image
,
new
Bind
(
testPath
.
toString
(),
new
Volume
(
"
/data/
test"
)),
new
Bind
(
srcPath
.
toString
(),
new
Volume
(
"
/data/
src"
)),
new
Bind
(
resultPath
.
toString
(),
new
Volume
(
"
/data/
result"
))
new
Bind
(
testPath
.
toString
(),
new
Volume
(
"test"
)),
new
Bind
(
srcPath
.
toString
(),
new
Volume
(
"src"
)),
new
Bind
(
resultPath
.
toString
(),
new
Volume
(
"result"
))
);
return
generateResult
(
assignmentId
,
resultPath
,
testPath
);
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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
Menu
Explore
Projects
Groups
Snippets