summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2015-09-09 12:30:00 +0200
committerSimon Rettberg2015-09-09 12:30:00 +0200
commit901a36d6056ed6ab5ca32f6b4cef0b5589ed720e (patch)
tree113e335c1ed462c84525c3fcccf607385e1eadeb
parent[server] Debug code for mail gen (diff)
downloadtutor-module-901a36d6056ed6ab5ca32f6b4cef0b5589ed720e.tar.gz
tutor-module-901a36d6056ed6ab5ca32f6b4cef0b5589ed720e.tar.xz
tutor-module-901a36d6056ed6ab5ca32f6b4cef0b5589ed720e.zip
[server] Make master server ssl/port configurable
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/App.java18
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbOsVirt.java11
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/util/Configuration.java15
3 files changed, 38 insertions, 6 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 6a4b14c2..425a3384 100644
--- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/App.java
+++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/App.java
@@ -4,7 +4,9 @@ import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.sql.SQLException;
import java.util.Date;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import javax.net.ssl.SSLContext;
@@ -40,6 +42,8 @@ public class App {
public static boolean DEBUG = false;
+ private static final Set<String> failFastMethods = new HashSet<>();
+
public static void main(String[] args) throws TTransportException, NoSuchAlgorithmException, IOException {
//get going and show basic information in log file
BasicConfigurator.configure();
@@ -64,10 +68,16 @@ public class App {
System.exit(1);
}
+ failFastMethods.add("getVirtualizers");
+ failFastMethods.add("getOperatingSystems");
+ failFastMethods.add("getOrganizations");
+
ThriftManager.setMasterErrorCallback(new ErrorCallback() {
@Override
public boolean thriftError(int failCount, String method, Throwable t) {
+ if (failFastMethods.contains(method))
+ return false;
if (failCount > 2 || t == null || !(t instanceof TTransportException)) {
LOGGER.warn("Thrift Client error for " + method + ", FAIL.");
return false;
@@ -82,8 +92,12 @@ public class App {
}
});
- ThriftManager.setMasterServerAddress(SSLContext.getDefault(), // TODO: Use the TLSv1.2 one once the master is ready
- Configuration.getMasterServerAddress(), 9091, 30000);
+ SSLContext ctx = null;
+ if (Configuration.getMasterServerSsl()) {
+ ctx = SSLContext.getDefault();
+ }
+ ThriftManager.setMasterServerAddress(ctx, // TODO: Use the TLSv1.2 one once the master is ready
+ Configuration.getMasterServerAddress(), Configuration.getMasterServerPort(), 30000);
// Load useful things from master server
OrganizationList.get();
diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbOsVirt.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbOsVirt.java
index 5251eec0..a8e24894 100644
--- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbOsVirt.java
+++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbOsVirt.java
@@ -21,13 +21,16 @@ public class DbOsVirt {
public static void storeOsList(List<OperatingSystem> list) throws SQLException {
try (MysqlConnection connection = Database.getConnection()) {
MysqlStatement stmt = connection.prepareStatement("INSERT INTO operatingsystem"
- + " (osid, displayname, architecture) VALUES"
- + " (:osid, :displayname, :architecture)"
- + " ON DUPLICATE KEY UPDATE displayname = VALUES(displayname), architecture = VALUES(architecture)");
+ + " (osid, displayname, architecture, maxmem, maxcpu) VALUES"
+ + " (:osid, :displayname, :architecture, :maxmem, :maxcpu)"
+ + " ON DUPLICATE KEY UPDATE displayname = VALUES(displayname), architecture = VALUES(architecture),"
+ + " maxmem = VALUES(maxmem), maxcpu = VALUES(maxcpu)");
for (OperatingSystem os : list) {
stmt.setInt("osid", os.osId);
stmt.setString("displayname", os.osName);
stmt.setString("architecture", os.architecture);
+ stmt.setInt("maxmem", os.maxMemMb);
+ stmt.setInt("maxcpu", os.maxCores);
stmt.executeUpdate();
}
connection.commit();
@@ -41,7 +44,7 @@ public class DbOsVirt {
try (MysqlConnection connection = Database.getConnection()) {
// Query OSs
MysqlStatement stmt = connection.prepareStatement("SELECT"
- + " osid, displayname, architecture, maxmem, maxcpu" + " FROM operatingsystem");
+ + " osid, displayname, architecture, maxmem, maxcpu FROM operatingsystem");
ResultSet rs = stmt.executeQuery();
List<OperatingSystem> list = new ArrayList<>();
Map<Integer, Map<String, String>> osVirtMappings = getOsVirtMappings(connection);
diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/util/Configuration.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/util/Configuration.java
index 8afc6a8c..b9652a0c 100644
--- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/util/Configuration.java
+++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/util/Configuration.java
@@ -21,6 +21,8 @@ public class Configuration {
private static String dbUsername;
private static String dbPassword;
private static String masterAddress;
+ private static boolean masterSsl = true;
+ private static int masterPort = 9091;
public static boolean load() throws IOException {
// Load configuration from java properties file
@@ -38,6 +40,11 @@ public class Configuration {
dbUsername = prop.getProperty("db.username");
dbPassword = prop.getProperty("db.password");
masterAddress = prop.getProperty("master.address");
+ masterSsl = Boolean.getBoolean(prop.getProperty("master.ssl"));
+ try {
+ masterPort = Integer.parseInt(prop.getProperty("master.port"));
+ } catch (Exception e) {
+ }
// Currently all fields are mandatory but there might be optional settings in the future
return vmStoreBasePath != null && dbUri != null && dbUsername != null && dbPassword != null;
@@ -75,6 +82,14 @@ public class Configuration {
return masterAddress;
}
+ public static boolean getMasterServerSsl() {
+ return masterSsl;
+ }
+
+ public static int getMasterServerPort() {
+ return masterPort;
+ }
+
// Dynamically Computed fields
public static File getCurrentVmStorePath() {