summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Bauer2015-07-23 15:49:35 +0200
committerJonathan Bauer2015-07-23 15:49:35 +0200
commitf068347d653491ef12bfce5cdaf249b9ecbbb758 (patch)
tree4937dcf23f923379fdf544d4c0c7b3e834aeec49
parent[client] push permissions to sat when wizard finishes (diff)
parent[client] Cleaned up layout code of gui a bit. (diff)
downloadtutor-module-f068347d653491ef12bfce5cdaf249b9ecbbb758.tar.gz
tutor-module-f068347d653491ef12bfce5cdaf249b9ecbbb758.tar.xz
tutor-module-f068347d653491ef12bfce5cdaf249b9ecbbb758.zip
Merge branch 'v1.1' of git.openslx.org:openslx-ng/tutor-module into v1.1
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageListWindowLayout.java7
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LectureListWindowLayout.java8
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LoginWindowLayout.java3
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/MainMenuWindowLayout.java18
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/VirtualizerNoticeWindowLayout.java15
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/ImageWizard.java21
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/ImageCustomPermissionPageLayout.java1
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/ImageMetaDataPageLayout.java1
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageMetaDataPage.java21
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageUploadPage.java83
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/state/UploadWizardState.java9
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImage.java38
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/ActiveUpload.java47
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/FileServer.java13
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/ServerHandler.java22
15 files changed, 162 insertions, 145 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageListWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageListWindowLayout.java
index be0f74ca..6397c820 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageListWindowLayout.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageListWindowLayout.java
@@ -63,9 +63,7 @@ public abstract class ImageListWindowLayout extends CompositePage {
// -- info group with title and text --
Composite infoComposite = new Composite(this, SWT.BORDER);
- GridData infoGridData = new GridData(SWT.FILL, SWT.FILL, true, false);
- infoGridData.horizontalSpan = 2;
- infoComposite.setLayoutData(infoGridData);
+ infoComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
// layout for the items of the group
infoComposite.setLayout(new GridLayout(1, false));
@@ -94,10 +92,9 @@ public abstract class ImageListWindowLayout extends CompositePage {
// -- group for the filter --
Group filterGroup = new Group(tableGroup, SWT.BORDER);
filterGroup.setText(filterGroupLabel);
- GridData fgGridData = new GridData(SWT.FILL, SWT.TOP, true, false);
+ GridData fgGridData = new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1);
fgGridData.minimumWidth = 400;
fgGridData.widthHint = 800;
- fgGridData.horizontalSpan = 2;
filterGroup.setLayoutData(fgGridData);
filterGroup.setLayout(new GridLayout());
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LectureListWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LectureListWindowLayout.java
index 9bfbe3ee..6ce50dc2 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LectureListWindowLayout.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LectureListWindowLayout.java
@@ -62,9 +62,7 @@ public abstract class LectureListWindowLayout extends CompositePage {
// -- info group with title and text --
Composite infoComposite = new Composite(this, SWT.BORDER);
- GridData infoGridData = new GridData(SWT.FILL, SWT.FILL, true, false);
- infoGridData.horizontalSpan = 2;
- infoComposite.setLayoutData(infoGridData);
+ infoComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
// layout for the items of the group
infoComposite.setLayout(new GridLayout(1, false));
@@ -93,10 +91,9 @@ public abstract class LectureListWindowLayout extends CompositePage {
// -- group for the filter --
Group filterGroup = new Group(tableGroup, SWT.BORDER);
filterGroup.setText(filterGroupLabel);
- GridData fgGridData = new GridData(SWT.FILL, SWT.TOP, true, false);
+ GridData fgGridData = new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1);
fgGridData.minimumWidth = 400;
fgGridData.widthHint = 800;
- fgGridData.horizontalSpan = 2;
filterGroup.setLayoutData(fgGridData);
filterGroup.setLayout(new GridLayout());
@@ -117,7 +114,6 @@ public abstract class LectureListWindowLayout extends CompositePage {
tableViewer.setContentProvider(ArrayContentProvider.getInstance());
-
// create, modify and delete buttons
Composite buttonComposite = new Composite(tableGroup, SWT.NONE);
GridData buttonCompositeGridData = new GridData(SWT.FILL, SWT.FILL, true, false);
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LoginWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LoginWindowLayout.java
index 14a88860..ae665e23 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LoginWindowLayout.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LoginWindowLayout.java
@@ -71,8 +71,7 @@ public abstract class LoginWindowLayout extends Composite {
Label titlePicture = new Label(this, SWT.NONE);
titlePicture.setImage(loadImage());
- GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
- gridData.horizontalSpan = 2;
+ GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
gridData.horizontalAlignment = SWT.CENTER;
titlePicture.setLayoutData(gridData);
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/MainMenuWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/MainMenuWindowLayout.java
index 46656667..92708cad 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/MainMenuWindowLayout.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/MainMenuWindowLayout.java
@@ -55,35 +55,29 @@ public abstract class MainMenuWindowLayout extends CompositePage {
Group vmGroup = new Group(this, SWT.NONE);
vmGroup.setLayout(new GridLayout());
vmGroup.setText("VMs");
- GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
- vmGroup.setLayoutData(gridData);
+ vmGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
vmButton = new Button(vmGroup, SWT.PUSH);
vmButton.setText("VM - Übersicht");
- gridData = new GridData(SWT.CENTER, SWT.CENTER, true, true);
- vmButton.setLayoutData(gridData);
+ vmButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));
Label vmInfoLabel = new Label(vmGroup, SWT.NONE);
vmInfoLabel.setText(vmInfo);
- gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
- vmInfoLabel.setLayoutData(gridData);
+ vmInfoLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
//g group for the lecture selection
Group lecturesGroup = new Group(this, SWT.NONE);
lecturesGroup.setLayout(new GridLayout());
lecturesGroup.setText("Veranstaltungen");
- gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
- lecturesGroup.setLayoutData(gridData);
+ lecturesGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
lecturesButton = new Button(lecturesGroup, SWT.PUSH);
lecturesButton.setText("Veranstanstaltungen");
- gridData = new GridData(SWT.CENTER, SWT.CENTER, true, true);
- lecturesButton.setLayoutData(gridData);
+ lecturesButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));
Label lecturesInfoLabel = new Label(lecturesGroup, SWT.NONE);
lecturesInfoLabel.setText(lecturesInfo);
- gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
- lecturesInfoLabel.setLayoutData(gridData);
+ lecturesInfoLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
}
}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/VirtualizerNoticeWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/VirtualizerNoticeWindowLayout.java
index ef6818d7..0227d701 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/VirtualizerNoticeWindowLayout.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/VirtualizerNoticeWindowLayout.java
@@ -44,14 +44,12 @@ public abstract class VirtualizerNoticeWindowLayout extends Composite {
// infotext
Label infoLabel = new Label(this, SWT.NONE | SWT.WRAP);
infoLabel.setText(infoText);
- GridData gridData = new GridData(GridData.FILL, GridData.BEGINNING, true, false);
- infoLabel.setLayoutData(gridData);
+ infoLabel.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true, false));
// composite for the windows vmware-download button
Composite windowsComposite = new Composite(this, SWT.NONE);
windowsComposite.setLayout(new GridLayout());
- gridData = new GridData(GridData.FILL, GridData.BEGINNING, true, false);
- windowsComposite.setLayoutData(gridData);
+ windowsComposite.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true, false));
new Label(windowsComposite, SWT.NONE).setText("Windows:");
windowsDLButton = new Button(windowsComposite, SWT.PUSH);
@@ -60,8 +58,7 @@ public abstract class VirtualizerNoticeWindowLayout extends Composite {
// composite for the linux vmware-download button
Composite linuxComposite = new Composite(this, SWT.NONE);
linuxComposite.setLayout(new GridLayout());
- gridData = new GridData(GridData.FILL, GridData.BEGINNING, true, false);
- linuxComposite.setLayoutData(gridData);
+ linuxComposite.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true, false));
new Label(windowsComposite, SWT.NONE).setText("Linux:");
linuxDLButton = new Button(windowsComposite, SWT.PUSH);
@@ -69,13 +66,11 @@ public abstract class VirtualizerNoticeWindowLayout extends Composite {
readCheck = new Button(this, SWT.CHECK);
readCheck.setText("Diese Benachrichtigung nicht mehr anzeigen.");
- gridData = new GridData(GridData.BEGINNING, GridData.END, false, false);
- readCheck.setLayoutData(gridData);
+ readCheck.setLayoutData(new GridData(GridData.BEGINNING, GridData.END, false, false));
continueButton = new Button(this, SWT.PUSH);
continueButton.setText("Weiter");
- gridData = new GridData(GridData.BEGINNING, GridData.END, false, false);
- continueButton.setLayoutData(gridData);
+ continueButton.setLayoutData(new GridData(GridData.BEGINNING, GridData.END, false, false));
}
} \ No newline at end of file
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/ImageWizard.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/ImageWizard.java
index 1ae87ce0..2cc21ec4 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/ImageWizard.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/ImageWizard.java
@@ -75,7 +75,6 @@ public class ImageWizard extends Wizard {
LOGGER.error("Invalid state!");
return false;
} else {
- LOGGER.debug(uploadWizardState.toString());
// TODO run the actually request over external threaded class
try {
// push to sat
@@ -175,27 +174,13 @@ public class ImageWizard extends Wizard {
return false;
}
}
- if (uploadWizardState.virtualizer == null) {
- LOGGER.error("No virtualizer set in state!");
+ if (uploadWizardState.meta == null) {
+ LOGGER.error("No vm meta data set in state!");
return false;
- } else {
- if (!(uploadWizardState.virtualizer.isSetVirtId()
- && uploadWizardState.virtualizer.isSetVirtName())) {
- LOGGER.error("Virtualizer has missing fields: " + uploadWizardState.virtualizer.toString());
- return false;
- }
}
if (uploadWizardState.permissions == null) {
LOGGER.error("No permissions set in state!");
return false;
- } else {
- if (!(uploadWizardState.permissions.isSetAdmin()
- && uploadWizardState.permissions.isSetDownload()
- && uploadWizardState.permissions.isSetEdit()
- && uploadWizardState.permissions.isSetLink())) {
- LOGGER.error("Virtualizer has missing fields: " + uploadWizardState.selectedOs.toString());
- return false;
- }
}
if (uploadWizardState.permissionList == null) {
LOGGER.error("No share mode set in state!");
@@ -219,7 +204,7 @@ public class ImageWizard extends Wizard {
uploadWizardState.name,
uploadWizardState.description,
uploadWizardState.selectedOs.getOsId(),
- uploadWizardState.virtualizer.getVirtId(),
+ uploadWizardState.meta.getVirtualizer().getVirtId(),
uploadWizardState.isTemplate,
uploadWizardState.permissions,
uploadWizardState.shareMode);
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/ImageCustomPermissionPageLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/ImageCustomPermissionPageLayout.java
index 7a56b016..311f6684 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/ImageCustomPermissionPageLayout.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/ImageCustomPermissionPageLayout.java
@@ -1,6 +1,5 @@
package org.openslx.dozmod.gui.wizard.layout;
-import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/ImageMetaDataPageLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/ImageMetaDataPageLayout.java
index b9b6c211..ccc66190 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/ImageMetaDataPageLayout.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/ImageMetaDataPageLayout.java
@@ -58,7 +58,6 @@ public abstract class ImageMetaDataPageLayout extends WizardPage {
Label descriptionCation = new Label(container, SWT.NONE);
descriptionCation.setText("Beschreibung:");
descriptionText = new Text(container, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL);
- gd = new GridData(GridData.FILL_HORIZONTAL);
gd.heightHint = 80;
descriptionText.setLayoutData(gd);
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageMetaDataPage.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageMetaDataPage.java
index 686c98aa..33195398 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageMetaDataPage.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageMetaDataPage.java
@@ -22,18 +22,17 @@ public class ImageMetaDataPage extends ImageMetaDataPageLayout {
private final static Logger LOGGER = Logger.getLogger(ImageMetaDataPage.class);
- private UploadWizardState uploadWizardState;
+ private UploadWizardState state;
public ImageMetaDataPage(UploadWizardState uploadWizardState) {
super();
- this.uploadWizardState = uploadWizardState;
+ this.state = uploadWizardState;
setPageComplete(false);
setMessage("Bitte wählen Sie das Betriebssystem aus und fügen Sie eine Beschreibung hinzu.");
// HACK set fixed uploadWizardState to test functions
uploadWizardState.isTemplate = false;
uploadWizardState.permissions = new ImagePermissions(true, false, true, false);
uploadWizardState.shareMode = ShareMode.LOCAL;
- uploadWizardState.virtualizer = MetaDataCache.getVirtualizers().get(0);
}
@Override
@@ -93,25 +92,25 @@ public class ImageMetaDataPage extends ImageMetaDataPageLayout {
readPermissionsCheck.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- uploadWizardState.permissions.download = readPermissionsCheck.getSelection();
+ state.permissions.download = readPermissionsCheck.getSelection();
}
});
linkPermissionsCheck.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- uploadWizardState.permissions.link = linkPermissionsCheck.getSelection();
+ state.permissions.link = linkPermissionsCheck.getSelection();
}
});
writePermissionsCheck.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- uploadWizardState.permissions.edit = writePermissionsCheck.getSelection();
+ state.permissions.edit = writePermissionsCheck.getSelection();
}
});
adminPermissionsCheck.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- uploadWizardState.permissions.admin = adminPermissionsCheck.getSelection();
+ state.permissions.admin = adminPermissionsCheck.getSelection();
}
});
// -- end checkboxes for permissions --
@@ -128,9 +127,9 @@ public class ImageMetaDataPage extends ImageMetaDataPageLayout {
if (!currentlyVisible && visible) {
LOGGER.debug("Entering page...");
// Preselect OS if possible
- if (uploadWizardState.selectedOs == null && uploadWizardState.detectedOs != null) {
+ if (state.selectedOs == null && state.detectedOs != null) {
for (int i = 0; i < osCombo.getItemCount(); ++i) {
- if (uploadWizardState.detectedOs.getOsName().equals(osCombo.getItem(i))) {
+ if (state.detectedOs.getOsName().equals(osCombo.getItem(i))) {
osCombo.select(i);
break;
}
@@ -178,7 +177,7 @@ public class ImageMetaDataPage extends ImageMetaDataPageLayout {
}
} else {
// OS selected, save it to state
- uploadWizardState.selectedOs = (OperatingSystem) osCombo.getData(osCombo.getItem(selectionIndex));
+ state.selectedOs = (OperatingSystem) osCombo.getData(osCombo.getItem(selectionIndex));
if (descriptionInput.isEmpty()) {
// OS set, no description
setMessage("Fügen Sie eine Beschreibung hinzu.");
@@ -188,7 +187,7 @@ public class ImageMetaDataPage extends ImageMetaDataPageLayout {
}
}
// always save the description input, even if empty.
- uploadWizardState.description = descriptionInput;
+ state.description = descriptionInput;
// final step: check if we can continue or not
setPageComplete(selectionIndex != -1 && !descriptionInput.isEmpty());
}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageUploadPage.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageUploadPage.java
index 4f9ed944..041627d9 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageUploadPage.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageUploadPage.java
@@ -36,7 +36,7 @@ public class ImageUploadPage extends ImageUploadPageLayout {
private final static Logger LOGGER = Logger.getLogger(ImageUploadPage.class);
- private UploadWizardState uploadWizardState;
+ private UploadWizardState state;
protected final boolean editExistingImage;
private String lastDetectedName = null;
@@ -44,7 +44,7 @@ public class ImageUploadPage extends ImageUploadPageLayout {
super();
setPageComplete(false);
this.editExistingImage = editExistingImage;
- this.uploadWizardState = uploadWizardState;
+ this.state = uploadWizardState;
setMessage("Bitte wählen Sie eine virtuelle Maschine zum Hochladen aus.");
}
@@ -56,9 +56,8 @@ public class ImageUploadPage extends ImageUploadPageLayout {
@Override
public void keyReleased(KeyEvent e) {
if (!imageNameTextField.getText().isEmpty()) {
- setPageComplete(uploadWizardState.descriptionFile != null
- && uploadWizardState.uuid != null
- && uploadWizardState.transferInformation != null);
+ setPageComplete(state.descriptionFile != null && state.uuid != null
+ && state.transferInformation != null);
} else
setPageComplete(false);
}
@@ -113,21 +112,20 @@ public class ImageUploadPage extends ImageUploadPageLayout {
private void vmxSelected(File file) {
Config.setUploadPath(file.getParent());
- VmwareMetaData meta = null;
try {
- meta = new VmwareMetaData(MetaDataCache.getOperatingSystems(), file);
+ state.meta = new VmwareMetaData(MetaDataCache.getOperatingSystems(), file);
} catch (IOException e) {
MainWindow.showMessageBox("Konnte " + file.getPath() + " nicht lesen", MessageType.ERROR, LOGGER,
e);
setPageComplete(false);
return;
}
- if (meta == null || meta.getDisplayName() == null) {
+ if (state.meta == null || state.meta.getDisplayName() == null) {
setErrorMessage("Keine gültige vmx-Datei ausgewählt!");
setPageComplete(false);
return;
}
- List<HardDisk> hdds = meta.getHdds();
+ List<HardDisk> hdds = state.meta.getHdds();
if (hdds.size() == 0 || hdds.get(0).diskImage == null) {
setErrorMessage("Die gewählte VM enthält keine HDD");
setPageComplete(false);
@@ -148,7 +146,7 @@ public class ImageUploadPage extends ImageUploadPageLayout {
vmDiskFileInfo = new File(vmxBaseDirectory, hdds.get(0).diskImage);
}
if (vmDiskFileInfo.canRead()) {
- uploadWizardState.diskFile = vmDiskFileInfo;
+ state.diskFile = vmDiskFileInfo;
} else {
setErrorMessage("'" + vmDiskFileInfo.getPath() + "' kann nicht gelesen werden!");
setPageComplete(false);
@@ -156,18 +154,19 @@ public class ImageUploadPage extends ImageUploadPageLayout {
}
// vmx ok, set it as our description file
- uploadWizardState.descriptionFile = file;
+ state.descriptionFile = file;
// User didn't enter a name yet or didn't change it -> set
String txtName = imageNameTextField.getText();
if (txtName.isEmpty() || txtName.equals(lastDetectedName)) {
- imageNameTextField.setText(meta.getDisplayName());
+ imageNameTextField.setText(state.meta.getDisplayName());
}
- lastDetectedName = meta.getDisplayName();
+ lastDetectedName = state.meta.getDisplayName();
- uploadWizardState.detectedOs = meta.getOs();
+ state.detectedOs = state.meta.getOs();
imageFileTextField.setText(file.getAbsolutePath());
// let the user know the upload is ready
+ setErrorMessage(null);
setMessage("Sie können jetzt den Upload starten!");
startUploadButton.setEnabled(true);
startUploadButton.setFocus();
@@ -207,7 +206,7 @@ public class ImageUploadPage extends ImageUploadPageLayout {
private void createAndUploadImage() {
// first get the image name from the field
// (either auto filled by VmwareMetaData or by user)
- uploadWizardState.name = imageNameTextField.getText();
+ state.name = imageNameTextField.getText();
// schedule task to create the image if we have no UUID
// and to request the upload once we received that UUID.
@@ -215,41 +214,40 @@ public class ImageUploadPage extends ImageUploadPageLayout {
@Override
public void fire() {
// -- create image --
- if (uploadWizardState.uuid == null) {
+ if (state.uuid == null) {
LOGGER.debug("Creating image...");
try {
- uploadWizardState.uuid = ThriftManager.getSatClient().createImage(
- Session.getSatelliteToken(), uploadWizardState.name);
+ state.uuid = ThriftManager.getSatClient().createImage(Session.getSatelliteToken(),
+ state.name);
} catch (Exception e) {
LOGGER.error("Error while creating image: ", e);
}
}
- if (uploadWizardState.transferInformation == null && uploadWizardState.uuid != null) {
+ if (state.transferInformation == null && state.uuid != null) {
// -- request upload --
LOGGER.debug("Requesting upload...");
try {
- uploadWizardState.transferInformation = ThriftManager.getSatClient()
- .requestImageVersionUpload(Session.getSatelliteToken(),
- uploadWizardState.uuid, uploadWizardState.diskFile.length(), null);
+ state.transferInformation = ThriftManager.getSatClient().requestImageVersionUpload(
+ Session.getSatelliteToken(), state.uuid, state.diskFile.length(), null,
+ state.meta.getFilteredDefinition());
} catch (Exception e) {
- LOGGER.error("Error while requesting download for: " + uploadWizardState.uuid, e);
+ LOGGER.error("Error while requesting download for: " + state.uuid, e);
}
}
- if (uploadWizardState.uploadTask == null && uploadWizardState.transferInformation != null
- && uploadWizardState.uuid != null) {
+ if (state.uploadTask == null && state.transferInformation != null && state.uuid != null) {
// do actually start the upload now
- LOGGER.debug("Starting upload for : " + uploadWizardState.diskFile.toPath());
+ LOGGER.debug("Starting upload for : " + state.diskFile.toPath());
try {
- uploadWizardState.uploadTask = new UploadTask(Session.getSatelliteAddress(),
- uploadWizardState.transferInformation.getPlainPort(),
- uploadWizardState.transferInformation.getToken(), uploadWizardState.diskFile);
+ state.uploadTask = new UploadTask(Session.getSatelliteAddress(),
+ state.transferInformation.getPlainPort(),
+ state.transferInformation.getToken(), state.diskFile);
} catch (FileNotFoundException e) {
MainWindow.showMessageBox("Cannot upload file: Not found", MessageType.ERROR, LOGGER,
e);
return;
}
// -- add listener for upload status/progress --
- uploadWizardState.uploadTask.addListener(new TransferEventListener() {
+ state.uploadTask.addListener(new TransferEventListener() {
@Override
public void update(final TransferEvent event) {
final TransferEventListener listener = this;
@@ -262,7 +260,7 @@ public class ImageUploadPage extends ImageUploadPageLayout {
});
}
});
- new Thread(uploadWizardState.uploadTask).start();
+ new Thread(state.uploadTask).start();
}
Gui.display.asyncExec(new Runnable() {
@Override
@@ -296,18 +294,18 @@ public class ImageUploadPage extends ImageUploadPageLayout {
imageFileBrowseButton.setEnabled(false);
imageFileTextField.setEnabled(false);
// -- check image creation --
- if (uploadWizardState.uuid == null) {
+ if (state.uuid == null) {
LOGGER.debug("No UUID in upload state!");
setErrorMessage("Konnte das Image nicht auf dem Satelliten erstellen!");
- } else if (uploadWizardState.transferInformation == null) {
+ } else if (state.transferInformation == null) {
LOGGER.debug("No transfer information in upload state!");
setErrorMessage("Fehler bei der Upload-Anfrage!");
- } else if (uploadWizardState.uploadTask != null) {
+ } else if (state.uploadTask != null) {
cancelUpload.setVisible(true);
blockProgressBar.setVisible(true);
setMessage("Der Upload wurde gestartet");
}
- setPageComplete(uploadWizardState.uploadTask != null);
+ setPageComplete(state.uploadTask != null);
}
/**
@@ -318,8 +316,8 @@ public class ImageUploadPage extends ImageUploadPageLayout {
*/
private void processTransferStatus(TransferEventListener listener, TransferEvent event) {
if (getControl().isDisposed()) {
- if (uploadWizardState.uploadTask != null) {
- uploadWizardState.uploadTask.removeListener(listener);
+ if (state.uploadTask != null) {
+ state.uploadTask.removeListener(listener);
}
return;
}
@@ -337,12 +335,12 @@ public class ImageUploadPage extends ImageUploadPageLayout {
MainWindow.showMessageBox("Upload abgeschlossen.", MessageType.INFO, LOGGER, null);
break;
case ERROR:
- if (uploadWizardState.uploadTask != null && uploadWizardState.uploadTask.isCanceled())
+ if (state.uploadTask != null && state.uploadTask.isCanceled())
return;
if (MainWindow.showMessageBox("Fehler beim Upload: " + event.errorMessage
+ "\nNochmal versuchen?", MessageType.ERROR_RETRY, LOGGER, null)) {
// user wants to try again, just reset transferInformation ...
- uploadWizardState.uploadTask = null;
+ state.uploadTask = null;
// ... since this function will then do the upload process again.
createAndUploadImage();
}
@@ -363,13 +361,12 @@ public class ImageUploadPage extends ImageUploadPageLayout {
@Override
public void fire() {
try {
- ThriftManager.getSatClient().cancelUpload(
- uploadWizardState.transferInformation.getToken());
+ ThriftManager.getSatClient().cancelUpload(state.transferInformation.getToken());
} catch (Exception e) {
- LOGGER.debug("Remote error while canceling upload for " + uploadWizardState.uuid, e);
+ LOGGER.debug("Remote error while canceling upload for " + state.uuid, e);
}
// Then cancel the task
- uploadWizardState.uploadTask.cancel();
+ state.uploadTask.cancel();
Gui.asyncExec(new Runnable() {
@Override
public void run() {
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/state/UploadWizardState.java b/dozentenmodul/src/main/java/org/openslx/dozmod/state/UploadWizardState.java
index 35494c83..22dffd88 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/state/UploadWizardState.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/state/UploadWizardState.java
@@ -7,8 +7,8 @@ import org.openslx.bwlp.thrift.iface.ImagePermissions;
import org.openslx.bwlp.thrift.iface.OperatingSystem;
import org.openslx.bwlp.thrift.iface.ShareMode;
import org.openslx.bwlp.thrift.iface.TransferInformation;
-import org.openslx.bwlp.thrift.iface.Virtualizer;
import org.openslx.dozmod.filetransfer.UploadTask;
+import org.openslx.util.vm.VmMetaData;
public class UploadWizardState {
// -- Objects of the GUI itself --
@@ -26,8 +26,6 @@ public class UploadWizardState {
public File diskFile = null;
// flags an image as a template
public Boolean isTemplate = null;
- // virtualizer for this image (vmware, vbox..)
- public Virtualizer virtualizer = null;
// permissions assigned to that image by the user
// TODO: defaults per sat
public ImagePermissions permissions = null;
@@ -49,4 +47,9 @@ public class UploadWizardState {
* The upload task representing this new VM
*/
public UploadTask uploadTask = null;
+
+ /**
+ * Meta data (description file content) of this VM
+ */
+ public VmMetaData meta = null;
}
diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImage.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImage.java
index adf0f26c..9b6b7966 100644
--- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImage.java
+++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImage.java
@@ -160,10 +160,7 @@ public class DbImage {
stmt.setString("imagebaseid", imageBaseId);
ResultSet rs = stmt.executeQuery();
if (!rs.next()) {
- LOGGER.info("Image " + imageBaseId + " not found");
throw new TNotFoundException();
- } else {
- LOGGER.info("Image " + imageBaseId + " found");
}
return resultSetToSummary(rs);
}
@@ -211,7 +208,6 @@ public class DbImage {
stmt.setString("userid", user.userId);
stmt.executeUpdate();
connection.commit();
- LOGGER.info("Created image '" + imageUuid + "'");
return imageUuid;
} catch (SQLException e) {
LOGGER.error("Query failed in DbImage.createImage()", e);
@@ -317,19 +313,29 @@ public class DbImage {
* @param imageVersionId UUID of image version
* @param image meta data to set
* @throws SQLException
+ * @throws TNotFoundException
*/
public static void updateImageVersion(UserInfo user, String imageVersionId, ImageVersionWrite image)
- throws SQLException {
+ throws SQLException, TNotFoundException {
try (MysqlConnection connection = Database.getConnection()) {
- MysqlStatement stmt = connection.prepareStatement("UPDATE imageversion v, imagebase b SET"
- + " v.isenabled = :isenabled, v.isrestricted = :isrestricted,"
+ String baseId = getBaseIdForVersionId(connection, imageVersionId);
+ if (baseId == null)
+ throw new TNotFoundException();
+ // First update version table
+ MysqlStatement stmtVersion = connection.prepareStatement("UPDATE imageversion v SET"
+ + " v.isenabled = :isenabled, v.isrestricted = :isrestricted"
+ + " WHERE v.imageversionid = :versionid");
+ stmtVersion.setString("versionid", imageVersionId);
+ stmtVersion.setBoolean("isenabled", image.isEnabled);
+ stmtVersion.setBoolean("isrestricted", image.isRestricted);
+ stmtVersion.executeUpdate();
+ // Then base table
+ MysqlStatement stmtBase = connection.prepareStatement("UPDATE imagebase b SET"
+ " b.updaterid = :userid, b.updatetime = UNIX_TIMESTAMP()"
- + " WHERE v.imageversionid = :versionid AND v.imagebaseid = b.imagebaseid");
- stmt.setString("versionid", imageVersionId);
- stmt.setString("userid", user.userId);
- stmt.setBoolean("isenabled", image.isEnabled);
- stmt.setBoolean("isrestricted", image.isRestricted);
- stmt.executeUpdate();
+ + " WHERE b.imagebaseid = :baseid");
+ stmtBase.setString("userid", user.userId);
+ stmtBase.setString("baseid", baseId);
+ stmtBase.executeUpdate();
connection.commit();
} catch (SQLException e) {
LOGGER.error("Query failed in DbImage.updateImageVersion()", e);
@@ -374,7 +380,9 @@ public class DbImage {
}
}
- public static void createImageVersion(String imageBaseId, String imageVersionId, UserInfo owner, long fileSize, String filePath, ImageVersionWrite versionSettings, ChunkList chunks) throws SQLException {
+ public static void createImageVersion(String imageBaseId, String imageVersionId, UserInfo owner,
+ long fileSize, String filePath, ImageVersionWrite versionSettings, ChunkList chunks,
+ byte[] machineDescription) throws SQLException {
try (MysqlConnection connection = Database.getConnection()) {
final long nowSecs = System.currentTimeMillis() / 1000;
MysqlStatement stmt = connection.prepareStatement("INSERT INTO imageversion"
@@ -395,7 +403,7 @@ public class DbImage {
stmt.setBoolean("isvalid", true); // TODO
stmt.setBoolean("isprocessed", false);
stmt.setBinary("mastersha1", null); // TODO
- stmt.setString("virtualizerconfig", null); // TODO
+ stmt.setBinary("virtualizerconfig", machineDescription);
stmt.executeUpdate();
// TODO: Write chunk hashes to DB
connection.commit();
diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/ActiveUpload.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/ActiveUpload.java
index 08d0d30f..92c2b2d7 100644
--- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/ActiveUpload.java
+++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/ActiveUpload.java
@@ -8,6 +8,7 @@ import java.nio.ByteBuffer;
import java.sql.SQLException;
import java.util.List;
import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.log4j.Logger;
import org.openslx.bwlp.sat.database.mappers.DbImage;
@@ -68,10 +69,21 @@ public class ActiveUpload {
*/
private final String uploadId;
+ /**
+ * Description of this VM - binary dump of e.g. the *.vmx file (VMware)
+ */
+ private final byte[] machineDescription;
+
+ /**
+ * Indicated whether the version information was written to db already.
+ * Disallow setVersionData in that case.
+ */
+ private final AtomicBoolean versionWrittenToDb = new AtomicBoolean();
+
// TODO: Use HashList for verification
public ActiveUpload(String uploadId, UserInfo owner, ImageDetailsRead image, File destinationFile,
- long fileSize, List<ByteBuffer> sha1Sums) throws FileNotFoundException {
+ long fileSize, List<ByteBuffer> sha1Sums, byte[] machineDescription) throws FileNotFoundException {
this.destinationFile = destinationFile;
this.outFile = new RandomAccessFile(destinationFile, "rw");
this.chunks = new ChunkList(fileSize, sha1Sums);
@@ -79,15 +91,27 @@ public class ActiveUpload {
this.image = image;
this.fileSize = fileSize;
this.uploadId = uploadId;
+ this.machineDescription = machineDescription;
}
/**
* Set meta data for this image version.
*
+ * @param user
+ *
* @param data
*/
- public synchronized void setVersionData(ImageVersionWrite data) {
- versionSettings = data;
+ public boolean setVersionData(UserInfo user, ImageVersionWrite data) {
+ synchronized (versionWrittenToDb) {
+ if (versionWrittenToDb.get()) {
+ return false;
+ }
+ if (!user.userId.equals(owner.userId)) {
+ return false;
+ }
+ versionSettings = data;
+ return true;
+ }
}
/**
@@ -155,9 +179,9 @@ public class ActiveUpload {
* Called when the upload finished.
*/
private synchronized void finishUpload() {
- if (state != TransferState.WORKING)
- return;
synchronized (outFile) {
+ if (state != TransferState.WORKING)
+ return;
Util.safeClose(outFile);
state = TransferState.FINISHED;
}
@@ -193,8 +217,11 @@ public class ActiveUpload {
// Now insert meta data into DB
try {
- DbImage.createImageVersion(image.imageBaseId, uploadId, owner, fileSize, relPath,
- versionSettings, chunks);
+ synchronized (versionWrittenToDb) {
+ DbImage.createImageVersion(image.imageBaseId, uploadId, owner, fileSize, relPath,
+ versionSettings, chunks, machineDescription);
+ versionWrittenToDb.set(true);
+ }
} catch (SQLException e) {
LOGGER.error("Error finishing upload: Inserting version to DB failed", e);
state = TransferState.ERROR;
@@ -271,10 +298,14 @@ public class ActiveUpload {
}
}
- public TransferStatus getStatus() {
+ public synchronized TransferStatus getStatus() {
return new TransferStatus(chunks.getStatusArray(), state);
}
+ public String getId() {
+ return uploadId;
+ }
+
// TODO: Clean up old stale uploads
}
diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/FileServer.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/FileServer.java
index 3abc5f98..0869612f 100644
--- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/FileServer.java
+++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/FileServer.java
@@ -32,8 +32,9 @@ public class FileServer implements IncomingEvent {
* Listener for incoming unencrypted connections
*/
private final Listener plainListener = new Listener(this, null, 9092, Constants.TRANSFER_TIMEOUT); // TODO: Config
-
- private final ThreadPoolExecutor transferPool = new ThreadPoolExecutor(2, Constants.MAX_UPLOADS + Constants.MAX_DOWNLOADS, 1, TimeUnit.MINUTES, new ArrayBlockingQueue<Runnable>(1));
+
+ private final ThreadPoolExecutor transferPool = new ThreadPoolExecutor(2, Constants.MAX_UPLOADS
+ + Constants.MAX_DOWNLOADS, 1, TimeUnit.MINUTES, new ArrayBlockingQueue<Runnable>(1));
/**
* All currently running uploads, indexed by token
@@ -84,8 +85,8 @@ public class FileServer implements IncomingEvent {
return uploads.get(uploadToken);
}
- public String createNewUserUpload(UserInfo owner, ImageDetailsRead image, long fileSize, List<ByteBuffer> sha1Sums)
- throws TTransferRejectedException {
+ public ActiveUpload createNewUserUpload(UserInfo owner, ImageDetailsRead image, long fileSize,
+ List<ByteBuffer> sha1Sums, byte[] machineDescription) throws TTransferRejectedException {
Iterator<ActiveUpload> it = uploads.values().iterator();
int activeUploads = 0;
while (it.hasNext()) {
@@ -109,14 +110,14 @@ public class FileServer implements IncomingEvent {
String key = UUID.randomUUID().toString();
ActiveUpload upload;
try {
- upload = new ActiveUpload(key, owner, image, destinationFile, fileSize, sha1Sums);
+ upload = new ActiveUpload(key, owner, image, destinationFile, fileSize, sha1Sums, machineDescription);
} catch (FileNotFoundException e) {
LOGGER.error("Could not open destination file for writing", e);
throw new TTransferRejectedException("Destination file not writable!");
}
uploads.put(key, upload);
- return key;
+ return upload;
}
public int getPlainPort() {
diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/ServerHandler.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/ServerHandler.java
index 45373ae4..0c26081b 100644
--- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/ServerHandler.java
+++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/ServerHandler.java
@@ -68,8 +68,8 @@ public class ServerHandler implements SatelliteServer.Iface {
@Override
public TransferInformation requestImageVersionUpload(String userToken, String imageBaseId, long fileSize,
- List<ByteBuffer> blockHashes) throws TTransferRejectedException, TAuthorizationException,
- TInternalServerError, TNotFoundException {
+ List<ByteBuffer> blockHashes, ByteBuffer machineDescription) throws TTransferRejectedException,
+ TAuthorizationException, TInternalServerError, TNotFoundException, TException {
UserInfo user = SessionManager.getOrFail(userToken);
User.canEditBaseImageOrFail(user, imageBaseId);
ImageDetailsRead image;
@@ -78,8 +78,16 @@ public class ServerHandler implements SatelliteServer.Iface {
} catch (SQLException e) {
throw new TInternalServerError();
}
- String transferId = fileServer.createNewUserUpload(user, image, fileSize, blockHashes);
- return new TransferInformation(transferId, fileServer.getPlainPort(), fileServer.getSslPort());
+ byte[] mDesc = machineDescription == null ? null : machineDescription.array();
+ ActiveUpload transfer = fileServer.createNewUserUpload(user, image, fileSize, blockHashes, mDesc);
+ return new TransferInformation(transfer.getId(), fileServer.getPlainPort(), fileServer.getSslPort());
+ }
+
+ @Override
+ public ByteBuffer getMachineDescription(String userToken, String imageVersionId)
+ throws TAuthorizationException, TInternalServerError, TNotFoundException, TException {
+ // TODO Auto-generated method stub
+ return null;
}
@Override
@@ -225,6 +233,12 @@ public class ServerHandler implements SatelliteServer.Iface {
public void updateImageVersion(String userToken, String imageVersionId, ImageVersionWrite image)
throws TAuthorizationException, TInternalServerError, TNotFoundException {
UserInfo user = SessionManager.getOrFail(userToken);
+ // Special case: Version is still being uploaded, so there's no entry yet - remember for later
+ ActiveUpload upload = fileServer.getUploadByToken(imageVersionId);
+ if (upload != null && upload.setVersionData(user, image)) {
+ return;
+ }
+ // Normal case - version already exists
User.canEditImageVersionOrFail(user, imageVersionId);
try {
// Do not allow editing remote images