From 4eadd87af796b9b670fc69cad792579202bc48c5 Mon Sep 17 00:00:00 2001 From: Michael Petretti Date: Thu, 19 Jun 2014 17:26:19 +0200 Subject: More debugging plus FtpDownloadWorker added. --- .../imagemaster/thrift/iface/FtpCredentials.java | 108 +++++++++++- .../imagemaster/thrift/iface/ImageServer.java | 192 ++++++++++----------- src/main/java/org/openslx/satellitedaemon/App.java | 3 + .../org/openslx/satellitedaemon/db/DbImage.java | 11 ++ .../satellitedaemon/ftp/FtpDownloadWorker.java | 93 ++++++++++ .../satellitedaemon/ftp/ThriftConnection.java | 62 ++++++- 6 files changed, 368 insertions(+), 101 deletions(-) create mode 100644 src/main/java/org/openslx/satellitedaemon/ftp/FtpDownloadWorker.java diff --git a/src/main/java/org/openslx/imagemaster/thrift/iface/FtpCredentials.java b/src/main/java/org/openslx/imagemaster/thrift/iface/FtpCredentials.java index fccb7b3..7b74425 100644 --- a/src/main/java/org/openslx/imagemaster/thrift/iface/FtpCredentials.java +++ b/src/main/java/org/openslx/imagemaster/thrift/iface/FtpCredentials.java @@ -37,6 +37,7 @@ public class FtpCredentials implements org.apache.thrift.TBase, SchemeFactory> schemes = new HashMap, SchemeFactory>(); static { @@ -46,11 +47,13 @@ public class FtpCredentials implements org.apache.thrift.TBase byName = new HashMap(); @@ -69,6 +72,8 @@ public class FtpCredentials implements org.apache.thrift.TBase extends org.apache.thrift.ProcessFunction { - public finshedUpload() { - super("finshedUpload"); + public static class finishedUpload extends org.apache.thrift.ProcessFunction { + public finishedUpload() { + super("finishedUpload"); } - public finshedUpload_args getEmptyArgsInstance() { - return new finshedUpload_args(); + public finishedUpload_args getEmptyArgsInstance() { + return new finishedUpload_args(); } protected boolean isOneway() { return false; } - public finshedUpload_result getResult(I iface, finshedUpload_args args) throws org.apache.thrift.TException { - finshedUpload_result result = new finshedUpload_result(); + public finishedUpload_result getResult(I iface, finishedUpload_args args) throws org.apache.thrift.TException { + finishedUpload_result result = new finishedUpload_result(); try { - result.success = iface.finshedUpload(args.ftpUser, args.imageDescription); + result.success = iface.finishedUpload(args.ftpUser, args.imageDescription); result.setSuccessIsSet(true); } catch (ImageDataException failure) { result.failure = failure; @@ -913,7 +913,7 @@ public class ImageServer { processMap.put("startServerAuthentication", new startServerAuthentication()); processMap.put("serverAuthenticate", new serverAuthenticate()); processMap.put("submitImage", new submitImage()); - processMap.put("finshedUpload", new finshedUpload()); + processMap.put("finishedUpload", new finishedUpload()); processMap.put("getImage", new getImage()); processMap.put("finishedDownload", new finishedDownload()); return processMap; @@ -1261,20 +1261,20 @@ public class ImageServer { } } - public static class finshedUpload extends org.apache.thrift.AsyncProcessFunction { - public finshedUpload() { - super("finshedUpload"); + public static class finishedUpload extends org.apache.thrift.AsyncProcessFunction { + public finishedUpload() { + super("finishedUpload"); } - public finshedUpload_args getEmptyArgsInstance() { - return new finshedUpload_args(); + public finishedUpload_args getEmptyArgsInstance() { + return new finishedUpload_args(); } public AsyncMethodCallback getResultHandler(final AsyncFrameBuffer fb, final int seqid) { final org.apache.thrift.AsyncProcessFunction fcall = this; return new AsyncMethodCallback() { public void onComplete(Boolean o) { - finshedUpload_result result = new finshedUpload_result(); + finishedUpload_result result = new finishedUpload_result(); result.success = o; result.setSuccessIsSet(true); try { @@ -1288,7 +1288,7 @@ public class ImageServer { public void onError(Exception e) { byte msgType = org.apache.thrift.protocol.TMessageType.REPLY; org.apache.thrift.TBase msg; - finshedUpload_result result = new finshedUpload_result(); + finishedUpload_result result = new finishedUpload_result(); if (e instanceof ImageDataException) { result.failure = (ImageDataException) e; result.setFailureIsSet(true); @@ -1314,8 +1314,8 @@ public class ImageServer { return false; } - public void start(I iface, finshedUpload_args args, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws TException { - iface.finshedUpload(args.ftpUser, args.imageDescription,resultHandler); + public void start(I iface, finishedUpload_args args, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws TException { + iface.finishedUpload(args.ftpUser, args.imageDescription,resultHandler); } } @@ -6523,16 +6523,16 @@ public class ImageServer { } - public static class finshedUpload_args implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { - private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("finshedUpload_args"); + public static class finishedUpload_args implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("finishedUpload_args"); private static final org.apache.thrift.protocol.TField FTP_USER_FIELD_DESC = new org.apache.thrift.protocol.TField("ftpUser", org.apache.thrift.protocol.TType.STRING, (short)1); private static final org.apache.thrift.protocol.TField IMAGE_DESCRIPTION_FIELD_DESC = new org.apache.thrift.protocol.TField("imageDescription", org.apache.thrift.protocol.TType.STRUCT, (short)2); private static final Map, SchemeFactory> schemes = new HashMap, SchemeFactory>(); static { - schemes.put(StandardScheme.class, new finshedUpload_argsStandardSchemeFactory()); - schemes.put(TupleScheme.class, new finshedUpload_argsTupleSchemeFactory()); + schemes.put(StandardScheme.class, new finishedUpload_argsStandardSchemeFactory()); + schemes.put(TupleScheme.class, new finishedUpload_argsTupleSchemeFactory()); } public String ftpUser; // required @@ -6608,13 +6608,13 @@ public class ImageServer { tmpMap.put(_Fields.IMAGE_DESCRIPTION, new org.apache.thrift.meta_data.FieldMetaData("imageDescription", org.apache.thrift.TFieldRequirementType.DEFAULT, new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, ImageData.class))); metaDataMap = Collections.unmodifiableMap(tmpMap); - org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(finshedUpload_args.class, metaDataMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(finishedUpload_args.class, metaDataMap); } - public finshedUpload_args() { + public finishedUpload_args() { } - public finshedUpload_args( + public finishedUpload_args( String ftpUser, ImageData imageDescription) { @@ -6626,7 +6626,7 @@ public class ImageServer { /** * Performs a deep copy on other. */ - public finshedUpload_args(finshedUpload_args other) { + public finishedUpload_args(finishedUpload_args other) { if (other.isSetFtpUser()) { this.ftpUser = other.ftpUser; } @@ -6635,8 +6635,8 @@ public class ImageServer { } } - public finshedUpload_args deepCopy() { - return new finshedUpload_args(this); + public finishedUpload_args deepCopy() { + return new finishedUpload_args(this); } @Override @@ -6649,7 +6649,7 @@ public class ImageServer { return this.ftpUser; } - public finshedUpload_args setFtpUser(String ftpUser) { + public finishedUpload_args setFtpUser(String ftpUser) { this.ftpUser = ftpUser; return this; } @@ -6673,7 +6673,7 @@ public class ImageServer { return this.imageDescription; } - public finshedUpload_args setImageDescription(ImageData imageDescription) { + public finishedUpload_args setImageDescription(ImageData imageDescription) { this.imageDescription = imageDescription; return this; } @@ -6745,12 +6745,12 @@ public class ImageServer { public boolean equals(Object that) { if (that == null) return false; - if (that instanceof finshedUpload_args) - return this.equals((finshedUpload_args)that); + if (that instanceof finishedUpload_args) + return this.equals((finishedUpload_args)that); return false; } - public boolean equals(finshedUpload_args that) { + public boolean equals(finishedUpload_args that) { if (that == null) return false; @@ -6781,7 +6781,7 @@ public class ImageServer { } @Override - public int compareTo(finshedUpload_args other) { + public int compareTo(finishedUpload_args other) { if (!getClass().equals(other.getClass())) { return getClass().getName().compareTo(other.getClass().getName()); } @@ -6825,7 +6825,7 @@ public class ImageServer { @Override public String toString() { - StringBuilder sb = new StringBuilder("finshedUpload_args("); + StringBuilder sb = new StringBuilder("finishedUpload_args("); boolean first = true; sb.append("ftpUser:"); @@ -6871,15 +6871,15 @@ public class ImageServer { } } - private static class finshedUpload_argsStandardSchemeFactory implements SchemeFactory { - public finshedUpload_argsStandardScheme getScheme() { - return new finshedUpload_argsStandardScheme(); + private static class finishedUpload_argsStandardSchemeFactory implements SchemeFactory { + public finishedUpload_argsStandardScheme getScheme() { + return new finishedUpload_argsStandardScheme(); } } - private static class finshedUpload_argsStandardScheme extends StandardScheme { + private static class finishedUpload_argsStandardScheme extends StandardScheme { - public void read(org.apache.thrift.protocol.TProtocol iprot, finshedUpload_args struct) throws org.apache.thrift.TException { + public void read(org.apache.thrift.protocol.TProtocol iprot, finishedUpload_args struct) throws org.apache.thrift.TException { org.apache.thrift.protocol.TField schemeField; iprot.readStructBegin(); while (true) @@ -6917,7 +6917,7 @@ public class ImageServer { struct.validate(); } - public void write(org.apache.thrift.protocol.TProtocol oprot, finshedUpload_args struct) throws org.apache.thrift.TException { + public void write(org.apache.thrift.protocol.TProtocol oprot, finishedUpload_args struct) throws org.apache.thrift.TException { struct.validate(); oprot.writeStructBegin(STRUCT_DESC); @@ -6937,16 +6937,16 @@ public class ImageServer { } - private static class finshedUpload_argsTupleSchemeFactory implements SchemeFactory { - public finshedUpload_argsTupleScheme getScheme() { - return new finshedUpload_argsTupleScheme(); + private static class finishedUpload_argsTupleSchemeFactory implements SchemeFactory { + public finishedUpload_argsTupleScheme getScheme() { + return new finishedUpload_argsTupleScheme(); } } - private static class finshedUpload_argsTupleScheme extends TupleScheme { + private static class finishedUpload_argsTupleScheme extends TupleScheme { @Override - public void write(org.apache.thrift.protocol.TProtocol prot, finshedUpload_args struct) throws org.apache.thrift.TException { + public void write(org.apache.thrift.protocol.TProtocol prot, finishedUpload_args struct) throws org.apache.thrift.TException { TTupleProtocol oprot = (TTupleProtocol) prot; BitSet optionals = new BitSet(); if (struct.isSetFtpUser()) { @@ -6965,7 +6965,7 @@ public class ImageServer { } @Override - public void read(org.apache.thrift.protocol.TProtocol prot, finshedUpload_args struct) throws org.apache.thrift.TException { + public void read(org.apache.thrift.protocol.TProtocol prot, finishedUpload_args struct) throws org.apache.thrift.TException { TTupleProtocol iprot = (TTupleProtocol) prot; BitSet incoming = iprot.readBitSet(2); if (incoming.get(0)) { @@ -6982,16 +6982,16 @@ public class ImageServer { } - public static class finshedUpload_result implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { - private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("finshedUpload_result"); + public static class finishedUpload_result implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("finishedUpload_result"); private static final org.apache.thrift.protocol.TField SUCCESS_FIELD_DESC = new org.apache.thrift.protocol.TField("success", org.apache.thrift.protocol.TType.BOOL, (short)0); private static final org.apache.thrift.protocol.TField FAILURE_FIELD_DESC = new org.apache.thrift.protocol.TField("failure", org.apache.thrift.protocol.TType.STRUCT, (short)1); private static final Map, SchemeFactory> schemes = new HashMap, SchemeFactory>(); static { - schemes.put(StandardScheme.class, new finshedUpload_resultStandardSchemeFactory()); - schemes.put(TupleScheme.class, new finshedUpload_resultTupleSchemeFactory()); + schemes.put(StandardScheme.class, new finishedUpload_resultStandardSchemeFactory()); + schemes.put(TupleScheme.class, new finishedUpload_resultTupleSchemeFactory()); } public boolean success; // required @@ -7069,13 +7069,13 @@ public class ImageServer { tmpMap.put(_Fields.FAILURE, new org.apache.thrift.meta_data.FieldMetaData("failure", org.apache.thrift.TFieldRequirementType.DEFAULT, new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRUCT))); metaDataMap = Collections.unmodifiableMap(tmpMap); - org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(finshedUpload_result.class, metaDataMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(finishedUpload_result.class, metaDataMap); } - public finshedUpload_result() { + public finishedUpload_result() { } - public finshedUpload_result( + public finishedUpload_result( boolean success, ImageDataException failure) { @@ -7088,7 +7088,7 @@ public class ImageServer { /** * Performs a deep copy on other. */ - public finshedUpload_result(finshedUpload_result other) { + public finishedUpload_result(finishedUpload_result other) { __isset_bitfield = other.__isset_bitfield; this.success = other.success; if (other.isSetFailure()) { @@ -7096,8 +7096,8 @@ public class ImageServer { } } - public finshedUpload_result deepCopy() { - return new finshedUpload_result(this); + public finishedUpload_result deepCopy() { + return new finishedUpload_result(this); } @Override @@ -7111,7 +7111,7 @@ public class ImageServer { return this.success; } - public finshedUpload_result setSuccess(boolean success) { + public finishedUpload_result setSuccess(boolean success) { this.success = success; setSuccessIsSet(true); return this; @@ -7134,7 +7134,7 @@ public class ImageServer { return this.failure; } - public finshedUpload_result setFailure(ImageDataException failure) { + public finishedUpload_result setFailure(ImageDataException failure) { this.failure = failure; return this; } @@ -7206,12 +7206,12 @@ public class ImageServer { public boolean equals(Object that) { if (that == null) return false; - if (that instanceof finshedUpload_result) - return this.equals((finshedUpload_result)that); + if (that instanceof finishedUpload_result) + return this.equals((finishedUpload_result)that); return false; } - public boolean equals(finshedUpload_result that) { + public boolean equals(finishedUpload_result that) { if (that == null) return false; @@ -7242,7 +7242,7 @@ public class ImageServer { } @Override - public int compareTo(finshedUpload_result other) { + public int compareTo(finishedUpload_result other) { if (!getClass().equals(other.getClass())) { return getClass().getName().compareTo(other.getClass().getName()); } @@ -7286,7 +7286,7 @@ public class ImageServer { @Override public String toString() { - StringBuilder sb = new StringBuilder("finshedUpload_result("); + StringBuilder sb = new StringBuilder("finishedUpload_result("); boolean first = true; sb.append("success:"); @@ -7327,15 +7327,15 @@ public class ImageServer { } } - private static class finshedUpload_resultStandardSchemeFactory implements SchemeFactory { - public finshedUpload_resultStandardScheme getScheme() { - return new finshedUpload_resultStandardScheme(); + private static class finishedUpload_resultStandardSchemeFactory implements SchemeFactory { + public finishedUpload_resultStandardScheme getScheme() { + return new finishedUpload_resultStandardScheme(); } } - private static class finshedUpload_resultStandardScheme extends StandardScheme { + private static class finishedUpload_resultStandardScheme extends StandardScheme { - public void read(org.apache.thrift.protocol.TProtocol iprot, finshedUpload_result struct) throws org.apache.thrift.TException { + public void read(org.apache.thrift.protocol.TProtocol iprot, finishedUpload_result struct) throws org.apache.thrift.TException { org.apache.thrift.protocol.TField schemeField; iprot.readStructBegin(); while (true) @@ -7373,7 +7373,7 @@ public class ImageServer { struct.validate(); } - public void write(org.apache.thrift.protocol.TProtocol oprot, finshedUpload_result struct) throws org.apache.thrift.TException { + public void write(org.apache.thrift.protocol.TProtocol oprot, finishedUpload_result struct) throws org.apache.thrift.TException { struct.validate(); oprot.writeStructBegin(STRUCT_DESC); @@ -7393,16 +7393,16 @@ public class ImageServer { } - private static class finshedUpload_resultTupleSchemeFactory implements SchemeFactory { - public finshedUpload_resultTupleScheme getScheme() { - return new finshedUpload_resultTupleScheme(); + private static class finishedUpload_resultTupleSchemeFactory implements SchemeFactory { + public finishedUpload_resultTupleScheme getScheme() { + return new finishedUpload_resultTupleScheme(); } } - private static class finshedUpload_resultTupleScheme extends TupleScheme { + private static class finishedUpload_resultTupleScheme extends TupleScheme { @Override - public void write(org.apache.thrift.protocol.TProtocol prot, finshedUpload_result struct) throws org.apache.thrift.TException { + public void write(org.apache.thrift.protocol.TProtocol prot, finishedUpload_result struct) throws org.apache.thrift.TException { TTupleProtocol oprot = (TTupleProtocol) prot; BitSet optionals = new BitSet(); if (struct.isSetSuccess()) { @@ -7421,7 +7421,7 @@ public class ImageServer { } @Override - public void read(org.apache.thrift.protocol.TProtocol prot, finshedUpload_result struct) throws org.apache.thrift.TException { + public void read(org.apache.thrift.protocol.TProtocol prot, finishedUpload_result struct) throws org.apache.thrift.TException { TTupleProtocol iprot = (TTupleProtocol) prot; BitSet incoming = iprot.readBitSet(2); if (incoming.get(0)) { diff --git a/src/main/java/org/openslx/satellitedaemon/App.java b/src/main/java/org/openslx/satellitedaemon/App.java index 30382db..7210c47 100644 --- a/src/main/java/org/openslx/satellitedaemon/App.java +++ b/src/main/java/org/openslx/satellitedaemon/App.java @@ -12,6 +12,7 @@ import java.security.cert.CertificateException; import org.apache.log4j.BasicConfigurator; import org.apache.log4j.Logger; import org.openslx.imagemaster.thrift.iface.ServerAuthenticationException; +import org.openslx.satellitedaemon.ftp.FtpDownloadWorker; import org.openslx.satellitedaemon.ftp.FtpUploadWorker; /** @@ -39,5 +40,7 @@ public class App } Thread uploadWorker = new Thread( new FtpUploadWorker() ); uploadWorker.start(); + Thread downloadWorker = new Thread( new FtpDownloadWorker() ); + downloadWorker.start(); } } diff --git a/src/main/java/org/openslx/satellitedaemon/db/DbImage.java b/src/main/java/org/openslx/satellitedaemon/db/DbImage.java index 0ed8efd..5169173 100644 --- a/src/main/java/org/openslx/satellitedaemon/db/DbImage.java +++ b/src/main/java/org/openslx/satellitedaemon/db/DbImage.java @@ -44,5 +44,16 @@ public class DbImage " INNER JOIN m_institution institution ON (institution.institutionID = user.institution)" + " WHERE image_syncMode = 'to_be_published'" ); } + + + public static List getAllMarkedForDownload() + { + return MySQL.findAll( DbImage.class, "SELECT image.GUID_imageID, image.image_name, image.imageVersion, image.image_path," + + " Concat(user.loginName, '@', institution.name) AS userID, image.image_filesize" + + " FROM m_VLData_imageInfo image" + + " INNER JOIN m_user user ON (image.image_owner = user.userID)" + + " INNER JOIN m_institution institution ON (institution.institutionID = user.institution)" + + " WHERE image_syncMode = 'to_be_decentralized'" ); + } } diff --git a/src/main/java/org/openslx/satellitedaemon/ftp/FtpDownloadWorker.java b/src/main/java/org/openslx/satellitedaemon/ftp/FtpDownloadWorker.java new file mode 100644 index 0000000..bcf217f --- /dev/null +++ b/src/main/java/org/openslx/satellitedaemon/ftp/FtpDownloadWorker.java @@ -0,0 +1,93 @@ +package org.openslx.satellitedaemon.ftp; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.security.KeyStore; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.CertificateException; +import java.util.List; + +import javax.net.ssl.KeyManagerFactory; +import javax.net.ssl.TrustManager; +import javax.net.ssl.TrustManagerFactory; + +import org.apache.commons.net.ftp.FTP; +import org.apache.commons.net.ftp.FTPSClient; +import org.apache.log4j.Logger; +import org.openslx.imagemaster.thrift.iface.FtpCredentials; +import org.openslx.satellitedaemon.Globals; +import org.openslx.satellitedaemon.Globals.PropInt; +import org.openslx.satellitedaemon.Globals.PropString; +import org.openslx.satellitedaemon.db.DbImage; + +public class FtpDownloadWorker implements Runnable +{ + private static Logger log = Logger.getLogger( FtpUploadWorker.class ); + + @Override + public void run() + { + while ( true ) { + List imageList = DbImage.getAllMarkedForDownload(); + log.info( "FtpDownloadWorker: imageList Contains " + imageList.size() + " items." ); + for ( DbImage image : imageList ) { + + FtpCredentials ftpc = ThriftConnection.getFtpCredentials( image.guid ); + if ( ftpc == null ) { + log.error( "The FtpCredentials are null" ); + } + + try { + TrustManagerFactory trustManagerFactory = TrustManagerFactory + .getInstance( KeyManagerFactory.getDefaultAlgorithm() ); + KeyStore keystore = KeyStore.getInstance( Globals.getPropertyString( PropString.KEYSTORETYPE ) ); + keystore.load( new FileInputStream( new File( + Globals.getPropertyString( PropString.FTPSKEYSTOREPATH ) ) ), + Globals.getPropertyString( PropString.FTPSKEYSTOREPWD ).toCharArray() ); + trustManagerFactory.init( keystore ); + TrustManager trustManager = trustManagerFactory.getTrustManagers()[0]; + FTPSClient ftpClient = new FTPSClient( "SSL", true ); + ftpClient.setTrustManager( trustManager ); + try { + ftpClient.connect( Globals.getPropertyString( PropString.FTPSERVERIP ), Globals.getPropertyInt( PropInt.FTPPORT ) ); + if ( !ftpClient.login( ftpc.username, ftpc.password ) ) { + log.error( "FTP problem. Coundn't log in!" ); + } + File file = new File( "/tmp/" + image.guid + ".vmdk"); + ftpClient.setFileType( FTP.BINARY_FILE_TYPE ); + log.info( "FtpDownloadWorker: ftpc.filename: " + ftpc.filename ); + InputStream is = ftpClient.retrieveFileStream( ftpc.filename ); + FileOutputStream fos = new FileOutputStream( file ); + int b; + while ((b = is.read()) != -1) { + fos.write( b ); + } + is.close(); + fos.close(); + ThriftConnection.finishedDownload( ftpc.username); + + } catch (IOException e) { + log.error("FtpDownloadWorker: Error creating the FileInputStream"); + } + finally { + ftpClient.disconnect(); + log.info( "FtpDownloadWorker: ftpClient disconnected" ); + } + } catch ( NoSuchAlgorithmException | KeyStoreException | CertificateException | IOException e ) { + log.debug( "FtpDownloadWorker: Problem with Keystore ore FtpsClient creation." ); + } + } + try { + Thread.sleep( 5 * 60 * 1000 ); + } catch ( InterruptedException e ) { + log.error( "FtpUploadWorker: Sleep interrupted" ); + e.printStackTrace(); + } + } + + } +} diff --git a/src/main/java/org/openslx/satellitedaemon/ftp/ThriftConnection.java b/src/main/java/org/openslx/satellitedaemon/ftp/ThriftConnection.java index a2c990f..251e2b3 100644 --- a/src/main/java/org/openslx/satellitedaemon/ftp/ThriftConnection.java +++ b/src/main/java/org/openslx/satellitedaemon/ftp/ThriftConnection.java @@ -84,6 +84,54 @@ public class ThriftConnection } return null; } + + /** + * The method calls getConnection() to check if the connection is ok + * and to get the ServerSessionData. If connection is ok, it returns ftpCredential. + * + * @return returns 'null' if there is a problem. + */ + public static FtpCredentials getFtpCredentials( String uUID ) + { + ImageServer.Client theClient = null; + try { + theClient = getConnection(); + if ( theClient == null ) { + log.error( "Client was null!" ); + return null; + } + + return theClient.getImage( uUID, sSD.sessionId ); + } catch ( TException e ) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch ( UnrecoverableKeyException e ) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch ( InvalidKeyException e ) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch ( NoSuchAlgorithmException e ) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch ( CertificateException e ) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch ( FileNotFoundException e ) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch ( KeyStoreException e ) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch ( SignatureException e ) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch ( IOException e ) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return null; + } /** * This method checks if there is already a working connection. If not, @@ -170,7 +218,19 @@ public class ThriftConnection public static void finishedUpload(String ftpUser, ImageData imageDescription) { try { - client.finshedUpload( ftpUser, imageDescription ); + client.finishedUpload( ftpUser, imageDescription ); + } catch ( ImageDataException e ) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch ( TException e ) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + public static void finishedDownload(String ftpUser) { + try { + client.finishedDownload( ftpUser ); } catch ( ImageDataException e ) { // TODO Auto-generated catch block e.printStackTrace(); -- cgit v1.2.3-55-g7522