diff options
author | ralph isenmann | 2022-02-23 18:24:30 +0100 |
---|---|---|
committer | ralph isenmann | 2022-02-23 18:24:30 +0100 |
commit | 7152b47a47b91bbd39cd50384dae4e3be3987c4c (patch) | |
tree | c6651a514411703df81f2e077af7a0c2787bc9db /dozentenmodulserver/src | |
parent | [CLIENT] fix layout in image type chooser (diff) | |
download | tutor-module-7152b47a47b91bbd39cd50384dae4e3be3987c4c.tar.gz tutor-module-7152b47a47b91bbd39cd50384dae4e3be3987c4c.tar.xz tutor-module-7152b47a47b91bbd39cd50384dae4e3be3987c4c.zip |
[SERVER] enable DockerFeature
- checks also if required value in db exists
Diffstat (limited to 'dozentenmodulserver/src')
3 files changed, 51 insertions, 8 deletions
diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/App.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/App.java index b63c0fa0..bb48207f 100644 --- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/App.java +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/App.java @@ -54,10 +54,6 @@ public class App { Configurator.initialize(new DefaultConfiguration()); } - AppUtil.logHeader(LOGGER, App.NAME, App.class.getPackage().getImplementationVersion()); - AppUtil.logProperty(LOGGER, "rpc.version", Long.toString(Version.VERSION)); - AppUtil.logProperty(LOGGER, "server.features", SupportedFeatures.getFeatureString()); - // get Configuration try { LOGGER.info("Loading configuration"); @@ -67,6 +63,10 @@ public class App { System.exit(1); } + AppUtil.logHeader(LOGGER, App.NAME, App.class.getPackage().getImplementationVersion()); + AppUtil.logProperty(LOGGER, "rpc.version", Long.toString(Version.VERSION)); + AppUtil.logProperty(LOGGER, "server.features", SupportedFeatures.getFeatureString()); + // Update database schema if applicable try { Updater.updateDatabase(); diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/SupportedFeatures.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/SupportedFeatures.java index a454fc21..c40037cc 100644 --- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/SupportedFeatures.java +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/SupportedFeatures.java @@ -1,5 +1,6 @@ package org.openslx.bwlp.sat; +import org.openslx.bwlp.sat.database.mappers.DbHelper; import org.openslx.sat.thrift.version.Feature; public class SupportedFeatures { @@ -13,10 +14,8 @@ public class SupportedFeatures { registerFeature(Feature.SERVER_SIDE_COPY); registerFeature(Feature.LECTURE_FILTER_LDAP); registerFeature(Feature.CONFIGURE_USB); - // TODO Docker Container currently not as a release Feature. Needs Update of Database. - // Enable Feature by adding ("docker", "Docker") to virtualizer table - // and rebuild Server with enabled Feature and replace jar on Sat. -// registerFeature(Feature.DOCKER_CONTAINER); + // add docker feature, but check datebase if available + registerFeatureIf(Feature.DOCKER_CONTAINER); } public static String getFeatureString() { @@ -31,4 +30,16 @@ public class SupportedFeatures { } } + private static void registerFeatureIf(Feature feature) { + switch (feature) { + case DOCKER_CONTAINER: + if (DbHelper.isDockerContainerAvailable()) + registerFeature(feature); + break; + + default: + break; + } + } + } diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbHelper.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbHelper.java new file mode 100644 index 00000000..a7e2a191 --- /dev/null +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbHelper.java @@ -0,0 +1,32 @@ +package org.openslx.bwlp.sat.database.mappers; + +import java.sql.ResultSet; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.openslx.bwlp.sat.database.Database; +import org.openslx.bwlp.sat.database.MysqlConnection; +import org.openslx.bwlp.sat.database.MysqlStatement; + +public class DbHelper { + + private static final Logger LOGGER = LogManager.getLogger(DbHelper.class); + + public static boolean isDockerContainerAvailable(){ + + try (MysqlConnection connection = Database.getConnection()) { + MysqlStatement stmt = connection.prepareStatement( + "SELECT *FROM virtualizer WHERE virtid = \"docker\""); + ResultSet rs = stmt.executeQuery(); + + if (!rs.isBeforeFirst()) { + // no data, do not enable. + return false; + } + return true; + } catch (Exception e) { + LOGGER.error("Query failed in DbHelper.isDockerContainerAvailable()", e); + return false; + } + } +} |