summaryrefslogtreecommitdiffstats
path: root/dozentenmodulserver
diff options
context:
space:
mode:
authorralph isenmann2021-11-10 14:00:16 +0100
committerralph isenmann2021-11-10 14:00:16 +0100
commitda4e3ed2dab82bf638e7fdf06cefd6855ae8f9c7 (patch)
tree99ba76f73cda12cfb661a496df44740754ba0fc7 /dozentenmodulserver
parent[client] allow to select data container images in mount config (diff)
downloadtutor-module-da4e3ed2dab82bf638e7fdf06cefd6855ae8f9c7.tar.gz
tutor-module-da4e3ed2dab82bf638e7fdf06cefd6855ae8f9c7.tar.xz
tutor-module-da4e3ed2dab82bf638e7fdf06cefd6855ae8f9c7.zip
[server] update webserver and dbimage; refactoring
Diffstat (limited to 'dozentenmodulserver')
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImage.java2
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/WebServer.java50
2 files changed, 22 insertions, 30 deletions
diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImage.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImage.java
index 62041952..9c39078c 100644
--- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImage.java
+++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImage.java
@@ -1173,7 +1173,7 @@ public class DbImage {
resultJson.addProperty("image_recipe", condev.getContainerRecipe());
resultJson.addProperty("image_repo", condev.getContainerMeta().getImageRepo());
resultJson.addProperty("build_context_method",
- condev.getContainerMeta().getBuildContextMethod());
+ condev.getContainerMeta().getContainerImageContext());
resultJson.addProperty("build_context_url", condev.getContainerMeta().getBuildContextUrl());
break;
}
diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/WebServer.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/WebServer.java
index cc9f8b72..cb7b5bf9 100644
--- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/WebServer.java
+++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/WebServer.java
@@ -41,9 +41,9 @@ import fi.iki.elonen.NanoHTTPD;
public class WebServer extends NanoHTTPD {
private static final Logger LOGGER = Logger.getLogger(WebServer.class);
-
- private static final ThreadPoolExecutor tpe =
- new GrowingThreadPoolExecutor(1, 8, 1, TimeUnit.MINUTES, new LinkedBlockingQueue<Runnable>(16));
+
+ private static final ThreadPoolExecutor tpe = new GrowingThreadPoolExecutor(1, 8, 1, TimeUnit.MINUTES,
+ new LinkedBlockingQueue<Runnable>(16));
private static final Serializer serializer = new Persister();
@@ -93,18 +93,14 @@ public class WebServer extends NanoHTTPD {
return serveMetaData(parts[2]);
if (parts[3].equals("netrules"))
return serveLectureNetRules(parts[2]);
+ if (parts[3].equals("imagemeta"))
+ return serveContainerImageMetaData(parts[2]);
}
return notFound();
}
if (uri.startsWith("/bwlp/container/clusterimages")) {
return serverContainerImages();
}
- if (uri.startsWith("/image/container/")) {
- if (parts.length < 4)
- return badRequest("Bad Request");
- if (parts[3].equals("metadata"))
- return serveContainerImageMetaData(parts[2]);
- }
if (uri.startsWith("/status/fileserver")) {
return serveStatus();
@@ -126,16 +122,14 @@ public class WebServer extends NanoHTTPD {
return new NanoHTTPD.Response(NanoHTTPD.Response.Status.OK, "application/json; charset=utf-8",
Json.serialize(FileServer.instance().getStatus()));
}
-
- private static void tarPutFile(TarOutputStream output, String fileName, String data) throws IOException
- {
+
+ private static void tarPutFile(TarOutputStream output, String fileName, String data) throws IOException {
if (data == null)
return;
tarPutFile(output, fileName, data.getBytes(StandardCharsets.UTF_8));
}
-
- private static void tarPutFile(TarOutputStream output, String fileName, byte[] data) throws IOException
- {
+
+ private static void tarPutFile(TarOutputStream output, String fileName, byte[] data) throws IOException {
if (data == null)
return;
output.putNextEntry(new TarEntry(TarHeader.createHeader(fileName, data.length, Util.unixTime(), false, 0644)));
@@ -172,8 +166,7 @@ public class WebServer extends NanoHTTPD {
if (ld.runScript != null) {
int cnt = 0;
for (RunScript rs : ld.runScript) {
- tarPutFile(output, String.format("adminrun/%04d-%d-%d.%s",
- cnt++, rs.visibility,
+ tarPutFile(output, String.format("adminrun/%04d-%d-%d.%s", cnt++, rs.visibility,
rs.passCreds ? 1 : 0, rs.extension), rs.content);
}
}
@@ -191,10 +184,9 @@ public class WebServer extends NanoHTTPD {
LOGGER.warn("Server overloaded; rejecting VM Metadata request", e2);
return internalServerError();
}
- return new NanoHTTPD.Response(NanoHTTPD.Response.Status.OK, "application/gzip",
- sink);
+ return new NanoHTTPD.Response(NanoHTTPD.Response.Status.OK, "application/gzip", sink);
}
-
+
private Response serveLectureNetRules(String lectureId) {
List<NetRule> list = new ArrayList<>();
boolean defaultAllowed;
@@ -223,13 +215,12 @@ public class WebServer extends NanoHTTPD {
sb.append("IN * 0 REJECT\n");
sb.append("OUT * 0 REJECT\n");
}
- return new NanoHTTPD.Response(NanoHTTPD.Response.Status.OK, "text/plain; charset=utf-8",
- sb.toString());
+ return new NanoHTTPD.Response(NanoHTTPD.Response.Status.OK, "text/plain; charset=utf-8", sb.toString());
}
private String serializeNetShares(List<NetShare> list) {
// openslx.exe expects shares in the following format
- // <path> <letter> <shortcut> <username> <password>
+ // <path> <letter> <shortcut> <username> <password>
// letter is either a drive letter for Windows VMs,
// or a mount point for Linux VMs.
StringBuilder sb = new StringBuilder();
@@ -276,13 +267,13 @@ public class WebServer extends NanoHTTPD {
/**
* Helper for returning "Internal Server Error" Status
- * @param body Message
+ *
+ * @param body Message
*/
public static Response internalServerError(String body) {
- return new NanoHTTPD.Response(NanoHTTPD.Response.Status.INTERNAL_ERROR, "text/plain",
- body);
+ return new NanoHTTPD.Response(NanoHTTPD.Response.Status.INTERNAL_ERROR, "text/plain", body);
}
-
+
public static Response internalServerError() {
return internalServerError("Internal Server Error");
}
@@ -305,9 +296,10 @@ public class WebServer extends NanoHTTPD {
}
/**
- * create a json response with information about existing container images in bwlehrpool
+ * create a json response with information about existing container images in
+ * bwlehrpool
*/
- private Response serverContainerImages () {
+ private Response serverContainerImages() {
try {
return new Response(Response.Status.OK, "application/json; charset=utf-8",
Json.serialize(DbImage.getContainerImageCluster()));