diff options
Diffstat (limited to 'src')
4 files changed, 27 insertions, 10 deletions
diff --git a/src/main/java/org/openslx/imagemaster/Globals.java b/src/main/java/org/openslx/imagemaster/Globals.java index 9ccaa4e..cfe4cd9 100644 --- a/src/main/java/org/openslx/imagemaster/Globals.java +++ b/src/main/java/org/openslx/imagemaster/Globals.java @@ -38,7 +38,6 @@ public class Globals stream.close(); // check properties - Util.notNullOrEmptyFatal( getImageDir(), "Image directory must be set." ); Util.notNullOrEmptyFatal( getSslKeystoreFile(), "SSL keystore file must be set." ); Util.notNullOrEmptyFatal( getSslKeystoreAlias(), "SSL keystore alias must be set." ); Util.notNullOrEmptyFatal( getSslKeystorePassword(), "SSL keystore password must be set." ); @@ -163,4 +162,10 @@ public class Globals return imgPath; } + public static boolean isReadOnlyMode() + { + return ( getFiletransferPortPlain() <= 0 && getFiletransferPortSsl() <= 0 ) + || Util.isEmpty( getImageDir() ); + } + } diff --git a/src/main/java/org/openslx/imagemaster/serverconnection/ConnectionHandler.java b/src/main/java/org/openslx/imagemaster/serverconnection/ConnectionHandler.java index f3831b0..22c4183 100644 --- a/src/main/java/org/openslx/imagemaster/serverconnection/ConnectionHandler.java +++ b/src/main/java/org/openslx/imagemaster/serverconnection/ConnectionHandler.java @@ -74,11 +74,15 @@ public class ConnectionHandler implements IncomingEvent SSLContext sslContext = SSLContext.getInstance( "TLSv1.2" ); KeyManager[] keyManagers = kmf.getKeyManagers(); sslContext.init( keyManagers, null, null ); - ssl = new Listener( eventHandler, sslContext, Globals.getFiletransferPortSsl(), Globals.getFiletransferTimeout() * 1000 ); - ssl.start(); - plain = new Listener( eventHandler, null, Globals.getFiletransferPortPlain(), Globals.getFiletransferTimeout() * 1000 ); - plain.start(); - // TODO: Bail out/retry if failed, getters for ports + if ( Globals.getFiletransferPortSsl() > 0 ) { + ssl = new Listener( eventHandler, sslContext, Globals.getFiletransferPortSsl(), Globals.getFiletransferTimeout() * 1000 ); + ssl.start(); + } + if ( Globals.getFiletransferPortPlain() > 0 ) { + plain = new Listener( eventHandler, null, Globals.getFiletransferPortPlain(), Globals.getFiletransferTimeout() * 1000 ); + plain.start(); + } + // TODO: Bail out/retry if failed } catch ( Exception e ) { LOGGER.error( "Initialization failed.", e ); System.exit( 2 ); @@ -110,14 +114,14 @@ public class ConnectionHandler implements IncomingEvent public static int getSslPort() { - if ( sslListener.isRunning() ) + if ( sslListener != null && sslListener.isRunning() ) return sslListener.getPort(); return 0; } public static int getPlainPort() { - if ( plainListener.isRunning() ) + if ( plainListener != null && plainListener.isRunning() ) return plainListener.getPort(); return 0; } @@ -147,8 +151,6 @@ public class ConnectionHandler implements IncomingEvent } else { absDestination = new File( Globals.getImageDir(), existing.exImagePath ); } - plainListener.start(); - sslListener.start(); try { transfer = new IncomingTransfer( img, blockHashes, absDestination, getPlainPort(), getSslPort() ); } catch ( FileNotFoundException e ) { diff --git a/src/main/java/org/openslx/imagemaster/serverconnection/IncomingTransfer.java b/src/main/java/org/openslx/imagemaster/serverconnection/IncomingTransfer.java index 7b499be..0950d52 100644 --- a/src/main/java/org/openslx/imagemaster/serverconnection/IncomingTransfer.java +++ b/src/main/java/org/openslx/imagemaster/serverconnection/IncomingTransfer.java @@ -69,6 +69,8 @@ public class IncomingTransfer extends IncomingTransferBase @Override protected boolean hasEnoughFreeSpace() { + if ( Globals.isReadOnlyMode() ) + return false; long space = Globals.getImagePath().getUsableSpace(); return space > MIN_FREE_SPACE_BYTES; } diff --git a/src/main/java/org/openslx/imagemaster/thrift/server/MasterServerHandler.java b/src/main/java/org/openslx/imagemaster/thrift/server/MasterServerHandler.java index d423c36..19ad7e6 100644 --- a/src/main/java/org/openslx/imagemaster/thrift/server/MasterServerHandler.java +++ b/src/main/java/org/openslx/imagemaster/thrift/server/MasterServerHandler.java @@ -263,6 +263,10 @@ public class MasterServerHandler implements MasterServer.Iface public TransferInformation submitImage( String userToken, ImagePublishData img, List<ByteBuffer> blockHashes ) throws TAuthorizationException, TInvocationException, TTransferRejectedException { + // Fallback mode, don't allow up/downloads + if( Globals.isReadOnlyMode() ) { + throw new TTransferRejectedException( "This is a read-only failover master-server. Image up-/downloads are not available." ); + } // Valid submit session? Session session = SessionManager.getSessionFromToken( userToken ); if ( session == null ) @@ -360,6 +364,10 @@ public class MasterServerHandler implements MasterServer.Iface public TransferInformation downloadImage( String sessionId, String imageVersionId ) throws TAuthorizationException, TInvocationException, TNotFoundException, TTransferRejectedException { + // Fallback mode, don't allow up/downloads + if( Globals.isReadOnlyMode() ) { + throw new TTransferRejectedException( "This is a read-only failover master-server. Image up-/downloads are not available." ); + } // Valid submit session? Session session = SessionManager.getSessionFromToken( sessionId ); if ( session == null ) |