summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Petretti2014-07-29 15:47:44 +0200
committerMichael Petretti2014-07-29 15:47:44 +0200
commitc3b9a0fc154fd9aafe1938356adfe1a46673bbe4 (patch)
treeb869c7da265df28872786d4829aff0800ead236e
parentAdapt to changes in master-sync-shared (diff)
downloadsatellite-daemon-c3b9a0fc154fd9aafe1938356adfe1a46673bbe4.tar.gz
satellite-daemon-c3b9a0fc154fd9aafe1938356adfe1a46673bbe4.tar.xz
satellite-daemon-c3b9a0fc154fd9aafe1938356adfe1a46673bbe4.zip
Exception handling.
-rw-r--r--src/main/java/org/openslx/satellitedaemon/filetransfer/ThriftConnection.java170
1 files changed, 131 insertions, 39 deletions
diff --git a/src/main/java/org/openslx/satellitedaemon/filetransfer/ThriftConnection.java b/src/main/java/org/openslx/satellitedaemon/filetransfer/ThriftConnection.java
index e1b9378..efd5357 100644
--- a/src/main/java/org/openslx/satellitedaemon/filetransfer/ThriftConnection.java
+++ b/src/main/java/org/openslx/satellitedaemon/filetransfer/ThriftConnection.java
@@ -18,11 +18,17 @@ import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;
import org.openslx.imagemaster.crcchecker.CRCFile;
+import org.openslx.imagemaster.thrift.iface.AuthorizationError;
+import org.openslx.imagemaster.thrift.iface.AuthorizationException;
import org.openslx.imagemaster.thrift.iface.DownloadInfos;
import org.openslx.imagemaster.thrift.iface.ImageData;
+import org.openslx.imagemaster.thrift.iface.ImageDataError;
+import org.openslx.imagemaster.thrift.iface.ImageDataException;
import org.openslx.imagemaster.thrift.iface.ImageServer;
import org.openslx.imagemaster.thrift.iface.ServerAuthenticationException;
import org.openslx.imagemaster.thrift.iface.ServerSessionData;
+import org.openslx.imagemaster.thrift.iface.UploadError;
+import org.openslx.imagemaster.thrift.iface.UploadException;
import org.openslx.imagemaster.thrift.iface.UploadInfos;
import org.openslx.satellitedaemon.Globals;
import org.openslx.satellitedaemon.Globals.PropInt;
@@ -71,38 +77,72 @@ public class ThriftConnection
log.info( "First call of submitImage following..." );
crc = new CRCFile( filename );
log.info( "Made CRCFile from " + filename );
- log.info( "crc.getCrcSums( ).size = " + crc.getCrcSums().size());
- log.info( "crc.getMasterSum() : " + crc.getMasterSum());
- for (int i = 0; i < crc.getCrcSums().size() - 1; i++){
- log.info( "crc.getCRCSum() : " + crc.getCRCSum( i ));
- }
+ log.info( "crc.getCrcSums( ).size = " + crc.getCrcSums().size() );
+// log.info( "crc.getMasterSum() : " + crc.getMasterSum() );
+// for ( int i = 0; i < crc.getCrcSums().size() - 1; i++ ) {
+// log.info( "crc.getCRCSum() : " + crc.getCRCSum( i ) );
+// }
return theClient.submitImage( sSD.sessionId, imDat, crc.getCrcSums() );
- } catch ( TException e ) {
- log.error("TException");
- e.printStackTrace();
+ } catch ( ImageDataException e ) {
+ if ( e.isSetNumber() && e.getNumber().equals( ImageDataError.INVALID_DATA ) ) {
+ // Data in the db is not valid
+ // TODO: add e.message into DB;
+ } else {
+ e.printStackTrace();
+ }
+ } catch ( UploadException e ) {
+ if ( e.isSetNumber() && e.getNumber().equals( UploadError.BROKEN_BLOCK ) ) {
+ // A Block was transmitted 20 times unsuccessfully.
+ // TODO: Mark the Image as corrupted.
+ } else if ( e.getNumber().equals( UploadError.INVALID_CRC ) ) {
+ // The CRC sum contained errors
+ crc = new CRCFile( filename );
+ try {
+ if(!crc.isValid()){
+ //TODO: Mark CRC-file as corrupted.
+ }
+ } catch ( IOException e1 ) {
+ log.error( "IOERROR, while reading from CRC File" + filename );
+ }
+ } else {
+ e.printStackTrace();
+ }
+ } catch ( AuthorizationException e ) {
+ if ( e.isSetNumber() && e.getNumber().equals( AuthorizationError.NOT_AUTHENTICATED ) ) {
+ // SessionID is not valid
+ // TODO: Code for new SSID
+ } else if ( e.getNumber().equals( AuthorizationError.NO_PERMISSION ) ) {
+ //Gibts noch gar nicht
+
+ } else {
+ e.printStackTrace();
+ }
} catch ( UnrecoverableKeyException e ) {
- log.error("UnrecoverableKeyException");
+ log.error( "UnrecoverableKeyException" );
e.printStackTrace();
} catch ( InvalidKeyException e ) {
- log.error("InvalidKeyException");
+ log.error( "InvalidKeyException" );
e.printStackTrace();
} catch ( NoSuchAlgorithmException e ) {
- log.error("NoSuchAlgorithmException");
+ log.error( "NoSuchAlgorithmException" );
e.printStackTrace();
} catch ( CertificateException e ) {
- log.error("CertificateException");
+ log.error( "CertificateException" );
e.printStackTrace();
} catch ( FileNotFoundException e ) {
- log.error("FileNotFoundException");
+ log.error( "FileNotFoundException" );
e.printStackTrace();
} catch ( KeyStoreException e ) {
- log.error("KeyStoreException");
+ log.error( "KeyStoreException" );
e.printStackTrace();
} catch ( SignatureException e ) {
- log.error("SignatureException");
+ log.error( "SignatureException" );
e.printStackTrace();
} catch ( IOException e ) {
- log.error("IOException");
+ log.error( "IOException" );
+ e.printStackTrace();
+ } catch ( TException e ) {
+ log.error( "TException" );
e.printStackTrace();
}
return null;
@@ -127,34 +167,66 @@ public class ThriftConnection
return null;
}
// .submitImage needs the List<Integer> from CRCFile.getCRCs() only
- // on the first time called. null afterwards.
+ // on the first time called. null afterwards. --Was the plan. So far not working I guess.
return theClient.submitImage( sSD.sessionId, imDat, crc.getCrcSums() );
- } catch ( TException e ) {
- log.error("TException");
- e.printStackTrace();
+ } catch ( ImageDataException e ) {
+ if ( e.isSetNumber() && e.getNumber().equals( ImageDataError.INVALID_DATA ) ) {
+ // Data in the db is not valid
+ //TODO: add e.message into DB;
+ } else {
+ e.printStackTrace();
+ }
+ } catch ( UploadException e ) {
+ if ( e.isSetNumber() && e.getNumber().equals( UploadError.BROKEN_BLOCK ) ) {
+ // A Block was transmitted 20 times unsuccessfully.
+ // TODO: Mark the Image as corrupted.
+ } else if ( e.getNumber().equals( UploadError.INVALID_CRC ) ) {
+ // The CRC sum contained errors
+ try {
+ if(!crc.isValid()){
+ //TODO: Mark CRC-file as corrupted.
+ }
+ } catch ( IOException e1 ) {
+ log.error( "IOERROR, while reading from CRC File" );
+ }
+ } else {
+ e.printStackTrace();
+ }
+ } catch ( AuthorizationException e ) {
+ if ( e.isSetNumber() && e.getNumber().equals( AuthorizationError.NOT_AUTHENTICATED ) ) {
+ // SessionID is not valid
+ // TODO: Code for new SSID
+ } else if ( e.getNumber().equals( AuthorizationError.NO_PERMISSION ) ) {
+
+ } else {
+ e.printStackTrace();
+ }
} catch ( UnrecoverableKeyException e ) {
- log.error("UnrecoverableKeyException");
+ log.error( "UnrecoverableKeyException" );
e.printStackTrace();
} catch ( InvalidKeyException e ) {
- log.error("InvalidKeyException");
+ log.error( "InvalidKeyException" );
e.printStackTrace();
} catch ( NoSuchAlgorithmException e ) {
- log.error("NoSuchAlgorithmException");
+ log.error( "NoSuchAlgorithmException" );
e.printStackTrace();
} catch ( CertificateException e ) {
- log.error("CertificateException");
+ log.error( "CertificateException" );
e.printStackTrace();
} catch ( FileNotFoundException e ) {
- log.error("FileNotFoundException");
+ log.error( "FileNotFoundException" );
e.printStackTrace();
} catch ( KeyStoreException e ) {
- log.error("KeyStoreException");
+ log.error( "KeyStoreException" );
e.printStackTrace();
} catch ( SignatureException e ) {
- log.error("SignatureException");
+ log.error( "SignatureException" );
e.printStackTrace();
} catch ( IOException e ) {
- log.error("IOException");
+ log.error( "IOException" );
+ e.printStackTrace();
+ } catch ( TException e ) {
+ log.error( "TException" );
e.printStackTrace();
}
return null;
@@ -178,32 +250,52 @@ public class ThriftConnection
}
return theClient.getImage( imDat.guid, sSD.sessionId, range );
- } catch ( TException e ) {
- log.error("TException");
- e.printStackTrace();
+ } catch ( ImageDataException e ) {
+ if ( e.isSetNumber() && e.getNumber().equals( ImageDataError.INVALID_DATA ) ) {
+ // Data in the db is not valid
+ //TODO: add e.message into DB;
+ } else if ( e.getNumber().equals( ImageDataError.UNKNOWN_IMAGE ) ) {
+ // The image requested is not known.
+ //TODO: change field image_syncMode, so the image is not asked for again.
+ // Plus add a note in some way to mark as unknown by Server
+ } else {
+ e.printStackTrace();
+ }
+ } catch ( AuthorizationException e ) {
+ if ( e.isSetNumber() && e.getNumber().equals( AuthorizationError.NOT_AUTHENTICATED ) ) {
+ // SessionID is not valid
+ // TODO: Code for new SSID
+ } else if ( e.getNumber().equals( AuthorizationError.NO_PERMISSION ) ) {
+
+ } else {
+ e.printStackTrace();
+ }
} catch ( UnrecoverableKeyException e ) {
- log.error("UnrecoverableKeyException");
+ log.error( "UnrecoverableKeyException" );
e.printStackTrace();
} catch ( InvalidKeyException e ) {
- log.error("InvalidKeyException");
+ log.error( "InvalidKeyException" );
e.printStackTrace();
} catch ( NoSuchAlgorithmException e ) {
- log.error("NoSuchAlgorithmException");
+ log.error( "NoSuchAlgorithmException" );
e.printStackTrace();
} catch ( CertificateException e ) {
- log.error("CertificateException");
+ log.error( "CertificateException" );
e.printStackTrace();
} catch ( FileNotFoundException e ) {
- log.error("FileNotFoundException");
+ log.error( "FileNotFoundException" );
e.printStackTrace();
} catch ( KeyStoreException e ) {
- log.error("KeyStoreException");
+ log.error( "KeyStoreException" );
e.printStackTrace();
} catch ( SignatureException e ) {
- log.error("SignatureException");
+ log.error( "SignatureException" );
e.printStackTrace();
} catch ( IOException e ) {
- log.error("IOException");
+ log.error( "IOException" );
+ e.printStackTrace();
+ } catch ( TException e ) {
+ log.error( "TException" );
e.printStackTrace();
}
return null;