diff options
author | Michael Petretti | 2014-06-03 11:12:54 +0200 |
---|---|---|
committer | Michael Petretti | 2014-06-03 11:12:54 +0200 |
commit | 7a51454a562a5efbb793e26d32bfea66f64ef9ad (patch) | |
tree | 535b9442e6d80cdbed3c6dab00623f803fdb7d86 | |
parent | Fixed most ToDo's. (diff) | |
download | satellite-daemon-7a51454a562a5efbb793e26d32bfea66f64ef9ad.tar.gz satellite-daemon-7a51454a562a5efbb793e26d32bfea66f64ef9ad.tar.xz satellite-daemon-7a51454a562a5efbb793e26d32bfea66f64ef9ad.zip |
Moved more things to the Globals.java class.
3 files changed, 33 insertions, 28 deletions
diff --git a/src/main/java/org/openslx/satellitedaemon/App.java b/src/main/java/org/openslx/satellitedaemon/App.java index 490ceba..c5bad11 100644 --- a/src/main/java/org/openslx/satellitedaemon/App.java +++ b/src/main/java/org/openslx/satellitedaemon/App.java @@ -35,16 +35,6 @@ public class App log.error( "Could not load config file. Quitting." ); System.exit( 1 ); } - // // TODO: A Thread that starts the call for new credentials and the upload - // // whenever a new image was sceduled in the db. - // ImageData imDat = new ImageData( UUID.randomUUID().toString(), 113, - // "TestImage", System.currentTimeMillis(), System.currentTimeMillis(), "me", "anyThing", - // true, false, "best", "theVeryBest", 1024 ); - // FtpCredentials ftpc = ThriftConnection.getFtpCredentials(imDat); - // Util.notNullFatal( ftpc, "ftpc was null" ); - // FtpImageUploader ftpIU = new FtpImageUploader( ftpc ); - // Util.notNullFatal( ftpIU, "ftpIU was null" ); - // ftpIU.connectTest(); Thread uploadWorker = new Thread( new FtpUploadWorker() ); uploadWorker.start(); } diff --git a/src/main/java/org/openslx/satellitedaemon/Globals.java b/src/main/java/org/openslx/satellitedaemon/Globals.java index ae631f1..8fe87c5 100644 --- a/src/main/java/org/openslx/satellitedaemon/Globals.java +++ b/src/main/java/org/openslx/satellitedaemon/Globals.java @@ -13,16 +13,19 @@ public class Globals /** * If there are more ints or Strings which should be added to config/global.properties, * add to suiting enum, add a 'case' to getPropertyInt/String() and add checks to - * propertiesValid() + * propertiesValid(). + * + * As an Example, if you want the value of the FTPSERVERIP you have to call + * Globals.getPropertyString( PropString.FTPSERVERIP ) which returns a string. */ public static enum PropInt { - FTPPORT + FTPPORT // More int's? Add them separated with "," } - + public static enum PropString - { - FTPSERVERIP + { // More strings's? Add them separated with "," + FTPSERVERIP, KEYSTORETYPE, FTPSKEYSTOREPATH, FTPSKEYSTOREPWD } public static boolean loadProperties() throws IOException @@ -30,7 +33,7 @@ public class Globals if ( loadedProperties ) return false; - // Load properties + // Load all entries of the config file into properties BufferedInputStream stream = new BufferedInputStream( new FileInputStream( "config/global.properties" ) ); properties.load( stream ); stream.close(); @@ -38,6 +41,7 @@ public class Globals return true; } + // Calling public static int getPropertyInt( Globals.PropInt props ) { String result = null; @@ -55,7 +59,7 @@ public class Globals return Integer.valueOf( result ); } - + public static String getPropertyString( Globals.PropString props ) { String result = null; @@ -64,6 +68,15 @@ public class Globals case FTPSERVERIP: result = properties.getProperty( "ftp_server_ip" ); break; + case KEYSTORETYPE: + result = properties.getProperty( "keyStore_type" ); + break; + case FTPSKEYSTOREPATH: + result = properties.getProperty( "path_to_ftps_keyStore" ); + break; + case FTPSKEYSTOREPWD: + result = properties.getProperty( "ftps_keyStore_password" ); + break; default: result = ""; break; @@ -73,9 +86,15 @@ public class Globals public static boolean propertiesValid() { - if (Globals.getPropertyInt( PropInt.FTPPORT ) == 0 + if ( Globals.getPropertyInt( PropInt.FTPPORT ) == 0 || Globals.getPropertyString( PropString.FTPSERVERIP ).isEmpty() - || Globals.getPropertyString( PropString.FTPSERVERIP ) == null) { + || Globals.getPropertyString( PropString.FTPSERVERIP ) == null + || Globals.getPropertyString( PropString.KEYSTORETYPE ).isEmpty() + || Globals.getPropertyString( PropString.KEYSTORETYPE ) == null + || Globals.getPropertyString( PropString.FTPSKEYSTOREPATH ).isEmpty() + || Globals.getPropertyString( PropString.FTPSKEYSTOREPATH ) == null + || Globals.getPropertyString( PropString.FTPSKEYSTOREPWD ).isEmpty() + || Globals.getPropertyString( PropString.FTPSKEYSTOREPWD ) == null ) { return false; } else { diff --git a/src/main/java/org/openslx/satellitedaemon/ftp/FtpUploadWorker.java b/src/main/java/org/openslx/satellitedaemon/ftp/FtpUploadWorker.java index 91d4e9c..73ec705 100644 --- a/src/main/java/org/openslx/satellitedaemon/ftp/FtpUploadWorker.java +++ b/src/main/java/org/openslx/satellitedaemon/ftp/FtpUploadWorker.java @@ -44,7 +44,7 @@ public class FtpUploadWorker implements Runnable true, false, "best", "theVeryBest", 1024 ); FtpCredentials ftpc = ThriftConnection.getFtpCredentials( imDat ); - if (ftpc == null) { + if ( ftpc == null ) { log.error( "The FtpCredentials are null" ); } @@ -52,10 +52,10 @@ public class FtpUploadWorker implements Runnable // ToDo: Add everything with the keyStores to config/global.properties TrustManagerFactory trustManagerFactory = TrustManagerFactory .getInstance( KeyManagerFactory.getDefaultAlgorithm() ); - KeyStore keystore = KeyStore.getInstance( "JKS" ); + KeyStore keystore = KeyStore.getInstance( Globals.getPropertyString( PropString.KEYSTORETYPE ) ); keystore.load( new FileInputStream( new File( - "/home/michael/satellite-daemon/config/ftpsid.jks" ) ), - "password".toCharArray() ); // TODO: define relative path, eg. "config/masterserver_cert.jks" + Globals.getPropertyString( PropString.FTPSKEYSTOREPATH ) ) ), + Globals.getPropertyString( PropString.FTPSKEYSTOREPWD ).toCharArray() ); trustManagerFactory.init( keystore ); TrustManager trustManager = trustManagerFactory.getTrustManagers()[0]; FTPSClient ftpClient = new FTPSClient( "SSL", true ); @@ -63,11 +63,8 @@ public class FtpUploadWorker implements Runnable try { ftpClient.connect( Globals.getPropertyString( PropString.FTPSERVERIP ), Globals.getPropertyInt( PropInt.FTPPORT ) ); if ( !ftpClient.login( ftpc.username, ftpc.password ) ) { - throw new ConnectException( "Could not login." ); // TODO: Should not throw exception, otherwise we'd exit the run() method + log.error( "FTP problem. Coundn't log in!" ); } - // System.out.println( "Connected to " + nilsIp + ":" + ftpPort - // + ". Reply code: " + ftpClient.getReplyCode() ); - // TODO: Where do I find the path to the db-image? <-- in DbImage. It's relative, base path should come from config/???.properties (global static config class, see masterserver's Globals class) File file = new File( imageList.get( 0 ).path ); FileInputStream fis = new FileInputStream( file ); @@ -91,5 +88,4 @@ public class FtpUploadWorker implements Runnable } } - } |