summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java
diff options
context:
space:
mode:
authorJonathan Bauer2016-04-27 17:24:15 +0200
committerJonathan Bauer2016-04-27 17:24:15 +0200
commita40ddb0a580348d68ff0c515275ffa252b686c1e (patch)
treee2436a05c935fd7b6c408e4cafb5be5dce6e16ce /dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java
parent[server] Fix upload handling if image already exists (diff)
downloadtutor-module-a40ddb0a580348d68ff0c515275ffa252b686c1e.tar.gz
tutor-module-a40ddb0a580348d68ff0c515275ffa252b686c1e.tar.xz
tutor-module-a40ddb0a580348d68ff0c515275ffa252b686c1e.zip
[client] first working draft for published images stuff
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java')
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java88
1 files changed, 50 insertions, 38 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java
index a6584bad..3467e4e9 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java
@@ -407,20 +407,43 @@ public class ThriftActions {
QuickTimer.scheduleOnce(new Task() {
@Override
public void fire() {
- final TransferInformation transInf;
+ // since this function (initDownload) supports both download from the satellite and from the masterserver
+ // we simply try to download from the sat first and if that fails, we try to download from the masterserver
+ // this has the nice side effect, that if a download from the masterserver is requested, it tries
+ // to download that image from the sat first (which is probably faster than from the masterserver)
+ TException transEx = null;
+ String transHost = null;
+ TransferInformation transInf = null;
try {
transInf = ThriftManager.getSatClient().requestDownload(Session.getSatelliteToken(),
imageVersionId);
+ transHost = Session.getSatelliteAddress();
} catch (TException e) {
- ThriftError.showMessage(frame, LOGGER, e, "Die Download-Anfrage ist gescheitert");
+ transEx = e;
+ }
+ if (transInf == null) {
+ // satellite denied download, try master
+ transHost = null;
+ try {
+ transInf = ThriftManager.getMasterClient().downloadImage(Session.getSatelliteToken(),
+ imageVersionId);
+ transHost = App.getMasterServerAddress();
+ } catch (TException e) {
+ transEx = e;
+ }
+ }
+ if (transInf == null) {
+ // both download request failed, show user feedback
+ ThriftError.showMessage(frame, LOGGER, transEx, "Die Download-Anfrage ist gescheitert");
if (callback != null)
callback.downloadInitialized(false);
return;
}
-
+ final String fTransHost = transHost;
+ final TransferInformation fTransInf = transInf;
final DownloadTask dlTask;
try {
- dlTask = new DownloadTask(Session.getSatelliteAddress(), transInf.getPlainPort(),
+ dlTask = new DownloadTask(fTransHost, transInf.getPlainPort(),
transInf.getToken(), tmpDiskFile, imageSize, null);
} catch (FileNotFoundException e) {
Gui.asyncMessageBox(
@@ -463,7 +486,7 @@ public class ThriftActions {
destImage = tmpDiskFile; // Must be Windows...
}
try {
- VmWrapper.wrapVm(destImage, imageName, transInf.getMachineDescription(),
+ VmWrapper.wrapVm(destImage, imageName, fTransInf.getMachineDescription(),
virtualizerId, osId, diskImage);
} catch (MetaDataMissingException | IOException e) {
Gui.asyncMessageBox(
@@ -517,7 +540,8 @@ public class ThriftActions {
* *******************************************************************************/
/**
- * Callback interface for image meta calls
+ * Callback interface for image meta calls.
+ *
*/
public interface ImageMetaCallback {
void fetchedImageDetails(ImageDetailsRead details, Map<String, ImagePermissions> permissions);
@@ -573,37 +597,6 @@ public class ThriftActions {
}
/**
- * NON-BLOCKING Gets the image details and the user-specific permission list
- * of
- * the given imageBaseId. Will return the objects through the given callback
- *
- * @param frame to display user feedback on
- * @param imageBaseId image's id to get the full details of
- * @param callback interface called to return the details back to the gui
- */
- public static void getImageFullDetails(final Frame frame, final String imageBaseId,
- final ImageMetaCallback callback) {
- QuickTimer.scheduleOnce(new Task() {
- ImageDetailsRead details = null;
- Map<String, ImagePermissions> permissions = null;
-
- @Override
- public void fire() {
- details = ThriftActions.getImageDetails(frame, imageBaseId);
- permissions = ThriftActions.getImagePermissions(frame, imageBaseId);
- Gui.asyncExec(new Runnable() {
- @Override
- public void run() {
- if (callback != null) {
- callback.fetchedImageDetails(details, permissions);
- }
- }
- });
- }
- });
- }
-
- /**
* NON-BLOCKING Gets the user-specific permission list for the given
* imageBaseId
*
@@ -1049,7 +1042,26 @@ public class ThriftActions {
}
});
}
-
+ /* *******************************************************************************
+ *
+ * PUBLIC IMAGES
+ *
+ * *******************************************************************************/
+ /**
+ * BLOCKING Gets the image details of an image on the masterserver
+ *
+ * @param imageVersionId
+ * @return ImageDetailsRead if fetching the details worked, null otherwise.
+ */
+ public static ImageDetailsRead getPublishedImageDetails(final String imageBaseId) {
+ ImageDetailsRead data = null;
+ try {
+ data = ThriftManager.getMasterClient().getImageDetails(Session.getMasterToken(), imageBaseId);
+ } catch (TException e) {
+ LOGGER.error("Could not query masterserver for ImagePublishData for version '" + imageBaseId + "':", e);
+ }
+ return data;
+ }
/* *******************************************************************************
*
* PRIVATE HELPERS