summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Petretti2014-05-12 15:24:04 +0200
committerMichael Petretti2014-05-12 15:24:04 +0200
commit3265140340c2131dc3ffe18b0f9483d391053c51 (patch)
tree3ebae6881c8351741c064aa0f3a9570b3f25402e
parentImplement getAllMarkedForUpload in DbImage class (diff)
downloadsatellite-daemon-3265140340c2131dc3ffe18b0f9483d391053c51.tar.gz
satellite-daemon-3265140340c2131dc3ffe18b0f9483d391053c51.tar.xz
satellite-daemon-3265140340c2131dc3ffe18b0f9483d391053c51.zip
Improvement of FtpConnection Class.
-rw-r--r--src/main/java/org/openslx/satellitedaemon/App.java7
-rw-r--r--src/main/java/org/openslx/satellitedaemon/ftp/FtpConnection.java (renamed from src/main/java/org/openslx/satellitedaemon/ftp/GetFtpCredentials.java)53
2 files changed, 43 insertions, 17 deletions
diff --git a/src/main/java/org/openslx/satellitedaemon/App.java b/src/main/java/org/openslx/satellitedaemon/App.java
index 26aa899..073e2e8 100644
--- a/src/main/java/org/openslx/satellitedaemon/App.java
+++ b/src/main/java/org/openslx/satellitedaemon/App.java
@@ -9,7 +9,8 @@ import java.security.cert.CertificateException;
import org.openslx.imagemaster.thrift.iface.FtpCredentials;
import org.openslx.imagemaster.thrift.iface.ServerAuthenticationException;
import org.openslx.satellitedaemon.ftp.FtpImageUploader;
-import org.openslx.satellitedaemon.ftp.GetFtpCredentials;
+import org.openslx.satellitedaemon.ftp.FtpConnection;
+import org.openslx.satellitedaemon.util.Util;
/**
* Main class for uploading images from the HS-Server to the Satellite Server.
@@ -22,8 +23,10 @@ public class App
// TODO: A Thread that starts the call for new credentials and the upload
// whenever a new image was sceduled in the db.
- FtpCredentials ftpc = GetFtpCredentials.getFtpCredentials();
+ FtpCredentials ftpc = FtpConnection.getFtpCredentials();
+ Util.notNullFatal( ftpc, "ftpc was null" );
FtpImageUploader ftpIU = new FtpImageUploader( ftpc );
+ Util.notNullFatal( ftpIU, "ftpIU was null" );
ftpIU.connectTest();
}
diff --git a/src/main/java/org/openslx/satellitedaemon/ftp/GetFtpCredentials.java b/src/main/java/org/openslx/satellitedaemon/ftp/FtpConnection.java
index 2fdeb66..fa0b040 100644
--- a/src/main/java/org/openslx/satellitedaemon/ftp/GetFtpCredentials.java
+++ b/src/main/java/org/openslx/satellitedaemon/ftp/FtpConnection.java
@@ -1,7 +1,3 @@
-// TODO: rename crative
-// some kind of check if Socket connection is still running when get FtpCredentials is called, otherwise open new
-// how: Sketch: make a getClient method. empty the static. getFtpCredentials calls getClient, which checks if every thing is ok, if not make it if not possible blame network
-
package org.openslx.satellitedaemon.ftp;
import java.io.FileNotFoundException;
@@ -26,34 +22,63 @@ import org.openslx.imagemaster.thrift.iface.ImageServer;
import org.openslx.imagemaster.thrift.iface.ServerAuthenticationException;
import org.openslx.imagemaster.thrift.iface.ServerSessionData;
import org.openslx.satellitedaemon.util.EncryptWithServerIdPublicKey;
+import org.openslx.satellitedaemon.util.Util;
-public class GetFtpCredentials
+/**
+ * Handles the authentication with the Satellite Server and sends the FtpCredentials, which
+ * are necessary for the upload of the image.
+ */
+public class FtpConnection
{
private static ImageServer.Client client = null;
// TODO: All of the Strings and int's should not fall from sky.
static String nilsIp = "132.230.4.23";
static int thriftPort = 9090;
- /**
- * Handles the authentication with the Satellite Server and sends the FtpCredentials, which
- * are necessary for the upload of the image.
- */
- static {
+ private static ImageServer.Client getConnection()
+ {
+ ImageServer.Client theClient = null;
+ if ( client == null ) {
+ theClient = newClient();
+ } else {
+ theClient = client;
+ }
+ boolean isAuthenticated = false;
+ try {
+ isAuthenticated = theClient.ping();
+ } catch ( TException x ) {
+ theClient = newClient();
+ if (theClient==null){
+ return null;
+ }
+ }
+ if ( !isAuthenticated ) {
+// TODO: a server authentication.
+ }
+ return theClient;
+ }
+
+ private static ImageServer.Client newClient()
+ {
+ ImageServer.Client newClient = null;
try {
TTransport transport;
transport = new TSocket( nilsIp, thriftPort ); // Nils IP
transport.open();
TProtocol protocol = new TBinaryProtocol( transport );
-
- client = new ImageServer.Client( protocol );
+ newClient = new ImageServer.Client( protocol );
} catch ( TException x ) {
x.printStackTrace();
+ return null;
}
+ return newClient;
}
public static FtpCredentials getFtpCredentials() throws ServerAuthenticationException
{
try {
+ client = getConnection();
+ Util.notNullFatal( client, "Client is null. Maybe a Network error." );
String toEncrypt = client.startServerAuthentication( "uni-freiburg.de" );
// System.out.println( toEncrypt );
EncryptWithServerIdPublicKey rse = new EncryptWithServerIdPublicKey( "serverid", "password",
@@ -61,11 +86,9 @@ public class GetFtpCredentials
byte[] byteArray = rse.encryptString( toEncrypt );
ServerSessionData sSD = client.serverAuthenticate(
"uni-freiburg.de", ByteBuffer.wrap( byteArray ) );
-
- // TODO: Should be able to get the necessary strings ect. from the DB.
ImageData imDat = new ImageData( UUID.randomUUID().toString(), 113,
"TestImage", System.currentTimeMillis(), System.currentTimeMillis(), "me", "anyThing",
- true, false, "theBest", "theVeryBest", 1024 );
+ true, false, "best", "theVeryBest", 1024 );
return client.submitImage( sSD.sessionId, imDat );
} catch ( InvalidKeyException e ) {