summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJannik Schönartz2021-11-29 00:58:18 +0100
committerJannik Schönartz2021-11-29 00:58:18 +0100
commit9097da596d8f58a72c115a7873794106ef34b5e0 (patch)
treedc8265bddb2b233d7b847d7b67082b51bd14155c
parentAdd script for downloading/merging the edited image (diff)
downloadtmlite-bwlp-9097da596d8f58a72c115a7873794106ef34b5e0.tar.gz
tmlite-bwlp-9097da596d8f58a72c115a7873794106ef34b5e0.tar.xz
tmlite-bwlp-9097da596d8f58a72c115a7873794106ef34b5e0.zip
Rework snapshot task to work with edit id, add file deletion on the client (because runvirt doesn't have enough permission) and add lecture mysql update, to use the new merged versionremote-edit-vm
-rwxr-xr-xscripts/scp-snapshot45
-rw-r--r--src/main/java/org/openslx/taskmanager/tasks/ScpSnapshot.java24
2 files changed, 34 insertions, 35 deletions
diff --git a/scripts/scp-snapshot b/scripts/scp-snapshot
index 48afb9e..0012d58 100755
--- a/scripts/scp-snapshot
+++ b/scripts/scp-snapshot
@@ -1,24 +1,28 @@
#!/bin/bash
-# Working directory has to be owned by taskmanager
+# Those variables need to be manually set
+WEBSUITE_BACKEND="<WEBSUITE_URL>"
+db_user="<DB_USER>"
+db_password="<DB_PASSWORD>"
+
+# Working directory
if [ ! -d /tmp/taskmanager ];then
- mkdir /tmp/taskmanger
+ mkdir /tmp/taskmanager
fi
workdir=/tmp/taskmanager
# For the service, the ssh keys has to be in the /home/taskmanager/.ssh directory
-# identityFile=/root/.ssh/ssh_poolclients
identityFile=~/.ssh/ssh_poolclients
-# Info for loggin into the client
-# Always login as root for now but $TM_USERNAME can be set via the apicall in slx-admin &username=XXX
-user=root
-UUID=$TM_UUID
-
-# Clientip is set during the slx-admin api call clientip=XXX
+# Info for loggin into the client (always login as root for now)
+# Clientip is set during the slx-admin api based on the given editid
client=$TM_CLIENT_IP
+user=root
+EDIT_ID=$TM_EDIT_ID
+LECTURE_ID=$TM_LECTURE_ID
-filePath=/tmp/upload/$UUID.qcow2
+# Path is hardcoded for now
+filePath=/tmp/upload/$EDIT_ID.qcow2
fileName=$(basename $filePath)
# Write ssh fingerprint in known_hosts file
@@ -26,15 +30,14 @@ ssh-keyscan -H $client >> ~/.ssh/known_hosts
# Get filesize via scp
fileSize=$(ssh -q -i $identityFile $user@$client "stat --printf='%s' $filePath")
-fileDestination=$workdir/snapshot_$UUID.qcow2
+fileDestination=$workdir/snapshot_$EDIT_ID.qcow2
script -q -f -c "scp -i $identityFile $user@$client:$filePath $fileDestination" $workdir/typescript > $workdir/progress &
-WEBSUITE_BACKEND="<WEBSUITE_BACKEND_URL>"
lastProgress=""
while true
do
- # Get the last line written by the scp process
+ # Get the last line written by the scp process ( : ctrl + v -> m)
progress=$(tail -n 1 $workdir/progress | tr " " "$" | rev | cut -d "$" -f2 | rev)
# Ignore when the progress didn't change
@@ -49,7 +52,9 @@ do
eta=$(echo $progress | cut -d " " -f5)
# Upload the progress to the bwLehrpool webSuite backend
- curl -X POST https://$WEBSUITE_BACKEND/images/$UUID/versions/upload/progress -H "Content-Type: application/json" -d '{ "fileName": '$fileName', "progress": '$percent', "size": '$size', "speed": '$speed', "eta": '$eta' }'
+ json_template='{ "state": "%s", "fileName": "%s", "percent": "%s", "size": "%s", "speed": "%s", "eta": "%s" }'
+ json_string=$(printf "$json_template" "TRANSFER" "$fileName" "$percent" "$size" "$speed" "$eta")
+ curl -X POST $WEBSUITE_BACKEND/edits/$EDIT_ID/progress -H "Content-Type: application/json" -d "$json_string"
if [ "$percent" == "100%" ]; then
break
@@ -59,16 +64,14 @@ do
lastProgress=$progress
done
-# Upload is finished so delete snapshot on client
+# Upload is finished so delete snapshot and edit.desktop on client
delete=$(ssh -q -i $identityFile $user@$client "rm $filePath")
-
-# DB variables
-db_user="<DB_USER>"
-db_password="<DB_PASSWORD>"
+delete=$(ssh -q -i $identityFile $user@$client "rm /var/lib/lightdm/edit.desktop")
+delete=$(ssh -q -i $identityFile $user@$client "rm /var/lib/lightdm/editsession.id")
# Merge snapshot with image
# 1. Make a copy of the baseimage with rsync (to have progress)
-image_version_uuid=$(mysql -u $db_user --password=$db_password sat -se "SELECT imageversionid from lecture WHERE lectureid='$UUID'")
+image_version_uuid=$(mysql -u $db_user --password=$db_password sat -se "SELECT imageversionid from lecture WHERE lectureid='$LECTURE_ID'")
image_path=$(mysql -u $db_user --password=$db_password sat -se "SELECT filepath from imageversion WHERE imageversionid='$image_version_uuid'")
# TODO: Currently only nfs?
bwlp_store=/srv/openslx/nfs
@@ -91,9 +94,11 @@ image_virtualizerconfig=$(mysql -u $db_user --password=$db_password sat -se "SEL
insert_query="INSERT INTO imageversion (imageversionid, imagebaseid, createtime, expiretime, filesize, filepath, uploaderid, virtualizerconfig, isrestricted, isvalid, isprocessed) VALUES ('$image_uuid','$image_base_uuid',$(date +%s),$image_expire,$image_filesize,'bwlehrpool_store/$image_base_copy','af73720a8be1aace58debedc21d7cb30','$image_virtualizerconfig',0,1,0);"
update_query="UPDATE imagebase SET latestversionid = '$image_uuid' WHERE imagebaseid = '$image_base_uuid';"
+update_lecture_query="UPDATE lecture SET imageversionid = '$image_uuid' WHERE lectureid = '$LECTURE_ID'"
mysql -u $db_user --password=$db_password sat -e "$insert_query"
mysql -u $db_user --password=$db_password sat -e "$update_query"
+mysql -u $db_user --password=$db_password sat -e "$update_lecture_query"
# Delete downloaded /tmp/taskmanager stuff
rm -rf /tmp/taskmanager/*
diff --git a/src/main/java/org/openslx/taskmanager/tasks/ScpSnapshot.java b/src/main/java/org/openslx/taskmanager/tasks/ScpSnapshot.java
index 0fe0c24..9fef1a9 100644
--- a/src/main/java/org/openslx/taskmanager/tasks/ScpSnapshot.java
+++ b/src/main/java/org/openslx/taskmanager/tasks/ScpSnapshot.java
@@ -10,13 +10,11 @@ import com.google.gson.annotations.Expose;
public class ScpSnapshot extends SystemCommandTask
{
@Expose
- private String lectureUuid = null;
- @Expose
- private String username = null;
+ private String editId = null;
@Expose
private String clientIp = null;
@Expose
- private String snapshotPath = null;
+ private String lectureId = null;
private final Output status = new Output();
@@ -25,14 +23,12 @@ public class ScpSnapshot extends SystemCommandTask
protected boolean initTask()
{
this.setStatusObject( this.status );
- if ( this.lectureUuid == null )
- this.lectureUuid = "";
- if ( this.username == null )
- this.username = "";
+ if ( this.editId == null )
+ this.editId = "";
if ( this.clientIp == null )
this.clientIp = "";
- if ( this.snapshotPath == null )
- this.snapshotPath = "";
+ if ( this.lectureId == null )
+ this.lectureId = "";
return true;
}
@@ -44,7 +40,6 @@ public class ScpSnapshot extends SystemCommandTask
"/usr/bin/sudo",
"-n",
"-u", "root",
- // "/bin/bash",
Constants.BASEDIR + "/scripts/scp-snapshot"
};
}
@@ -52,10 +47,9 @@ public class ScpSnapshot extends SystemCommandTask
@Override
protected void initEnvironment( Map<String, String> environment )
{
- environment.put( "TM_UUID", this.lectureUuid );
- environment.put( "TM_USERNAME", this.username);
- environment.put( "TM_CLIENT_IP", this.clientIp);
- environment.put( "TM_SNAPSHOT_PATH", this.snapshotPath);
+ environment.put( "TM_EDIT_ID", this.editId );
+ environment.put( "TM_CLIENT_IP", this.clientIp );
+ environment.put( "TM_LECTURE_ID", this.lectureId);
}
@Override