summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/satellitedaemon/filetransfer/ThriftConnection.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/openslx/satellitedaemon/filetransfer/ThriftConnection.java')
-rw-r--r--src/main/java/org/openslx/satellitedaemon/filetransfer/ThriftConnection.java220
1 files changed, 119 insertions, 101 deletions
diff --git a/src/main/java/org/openslx/satellitedaemon/filetransfer/ThriftConnection.java b/src/main/java/org/openslx/satellitedaemon/filetransfer/ThriftConnection.java
index a719c21..de8d3f9 100644
--- a/src/main/java/org/openslx/satellitedaemon/filetransfer/ThriftConnection.java
+++ b/src/main/java/org/openslx/satellitedaemon/filetransfer/ThriftConnection.java
@@ -47,6 +47,9 @@ public class ThriftConnection {
private static ServerSessionData sSD = null;
private static Logger log = Logger.getLogger(ThriftConnection.class);
private static CrcFile crc = null;
+
+ // counter for counting how often getUploadInfos was called.
+ private static int counter = 0;
/***********************************************************************************************/
/**
@@ -68,18 +71,33 @@ public class ThriftConnection {
log.error("Client was null!");
return null;
}
- // .submitImage needs the List<Integer> from CRCFile.getCRCs() only
- // on the first time called. null afterwards.
- 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 ) );
- // }
- return theClient
- .submitImage(sSD.sessionId, imDat, crc.getCrcSums());
+
+ if (counter == 0) {
+ // method called for the first time.
+ // .submitImage needs the List<Integer> from CRCFile.getCRCs() only
+ // on the first time called. null afterwards.
+ 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 ) );
+ // }
+
+ // increment counter.
+ counter++;
+ return theClient
+ .submitImage(sSD.sessionId, imDat, crc.getCrcSums());
+ } else {
+ // method not called for the first time.
+ // .submitImage needs the List<Integer> from CRCFile.getCRCs() only
+ // on the first time called. null afterwards. --Was the plan. So far
+ // not working I guess.
+ counter++;
+ return theClient
+ .submitImage(sSD.sessionId, imDat, null);
+ }
} catch (ImageDataException e) {
if (e.isSetNumber()
&& e.getNumber().equals(ImageDataError.INVALID_DATA)) {
@@ -150,95 +168,95 @@ public class ThriftConnection {
return null;
}
- /***********************************************************************************************/
- /**
- * Method for getting UploadeInfos when CRCsum was already transfered on
- * first call. The method calls getConnection() to check if the connection
- * is ok and to get the ServerSessionData. If connection is ok, it calls
- * submitImage with sSD.sessionId, imDat and !!null!!
- *
- * @return returns 'null' if there is a problem.
- */
- public static UploadInfos getUploadInfos(ImageData imDat) {
- ImageServer.Client theClient = null;
- try {
- theClient = getConnection();
- if (theClient == null) {
- log.error("Client was null!");
- return null;
- }
- // .submitImage needs the List<Integer> from CRCFile.getCRCs() only
- // 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 (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");
- e.printStackTrace();
- } catch (InvalidKeyException e) {
- log.error("InvalidKeyException");
- e.printStackTrace();
- } catch (NoSuchAlgorithmException e) {
- log.error("NoSuchAlgorithmException");
- e.printStackTrace();
- } catch (CertificateException e) {
- log.error("CertificateException");
- e.printStackTrace();
- } catch (FileNotFoundException e) {
- log.error("FileNotFoundException");
- e.printStackTrace();
- } catch (KeyStoreException e) {
- log.error("KeyStoreException");
- e.printStackTrace();
- } catch (SignatureException e) {
- log.error("SignatureException");
- e.printStackTrace();
- } catch (IOException e) {
- log.error("IOException");
- e.printStackTrace();
- } catch (TException e) {
- log.error("TException");
- e.printStackTrace();
- }
- return null;
- }
-
+// /***********************************************************************************************/
+// /**
+// * Method for getting UploadeInfos when CRCsum was already transfered on
+// * first call. The method calls getConnection() to check if the connection
+// * is ok and to get the ServerSessionData. If connection is ok, it calls
+// * submitImage with sSD.sessionId, imDat and !!null!!
+// *
+// * @return returns 'null' if there is a problem.
+// */
+// public static UploadInfos getUploadInfos(ImageData imDat) {
+// ImageServer.Client theClient = null;
+// try {
+// theClient = getConnection();
+// if (theClient == null) {
+// log.error("Client was null!");
+// return null;
+// }
+// // .submitImage needs the List<Integer> from CRCFile.getCRCs() only
+// // 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 (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");
+// e.printStackTrace();
+// } catch (InvalidKeyException e) {
+// log.error("InvalidKeyException");
+// e.printStackTrace();
+// } catch (NoSuchAlgorithmException e) {
+// log.error("NoSuchAlgorithmException");
+// e.printStackTrace();
+// } catch (CertificateException e) {
+// log.error("CertificateException");
+// e.printStackTrace();
+// } catch (FileNotFoundException e) {
+// log.error("FileNotFoundException");
+// e.printStackTrace();
+// } catch (KeyStoreException e) {
+// log.error("KeyStoreException");
+// e.printStackTrace();
+// } catch (SignatureException e) {
+// log.error("SignatureException");
+// e.printStackTrace();
+// } catch (IOException e) {
+// log.error("IOException");
+// e.printStackTrace();
+// } catch (TException e) {
+// log.error("TException");
+// e.printStackTrace();
+// }
+// return null;
+// }
+//
/***********************************************************************************************/
/**
* Method for getting DonwloadInfos. Calls getConnection if client was null.