Commit b979a3e4 authored by Leigh B Stoller's avatar Leigh B Stoller
Browse files

Better output/error handling, fixing previous revision.

parent 91662a91
......@@ -508,11 +508,9 @@ sub Delete($$)
or return -1;
if ($purge) {
# Delete any associated webtasks too.
DBQueryWarn("delete apt_profile_versions, web_tasks ".
" from apt_profile_versions ".
"left join web_tasks on ".
" web_tasks.object_uuid=apt_profile_versions.uuid ".
# Do not delete the web task here, it is needed to pass status
# back to the web interface during profile creation.
DBQueryWarn("delete from apt_profile_versions ".
"where apt_profile_versions.profileid='$profileid'")
or goto bad;
}
......@@ -547,7 +545,8 @@ sub DeleteVersion($)
{
my ($self) = @_;
DBQueryWarn("lock tables apt_profile_versions write, apt_profiles write")
DBQueryWarn("lock tables apt_profile_versions write, ".
" apt_profiles write, web_tasks write")
or return -1;
my $profileid = $self->profileid();
......@@ -567,10 +566,18 @@ sub DeleteVersion($)
print STDERR "Profile::DeleteVersion: not the head version of $self\n";
goto bad;
}
# Delete leftover webtask.
DBQueryWarn("delete web_tasks from apt_profile_versions ".
"left join web_tasks on ".
" web_tasks.object_uuid=apt_profile_versions.uuid ".
"where apt_profile_versions.profileid='$profileid' and ".
" apt_profile_versions.version='$version'");
goto bad
if (!DBQueryWarn("delete from apt_profile_versions ".
"where profileid='$profileid' and ".
" version='$version'"));
goto bad
if (!DBQueryWarn("update apt_profiles set version=version-1 ".
"where profileid='$profileid' and ".
......
......@@ -150,6 +150,31 @@ elsif ($action ne "create") {
}
my $xmlfile = shift(@ARGV);
#
# Create the webtask object, even though we do not have a profile
# object yet, we will set it below. We use the webtask to pass the
# errors back to the web interface before the profile is created.
#
# Note that if we fail, we want to leave the webtask around for the
# web interface, it will need to delete it.
#
# If doing a snapshot, we always create one since that is the easiest
# way to communicate with the manage_instance script, even if we ran
# this from the command line.
#
if (defined($webtask_id) || $snap) {
if (defined($webtask_id)) {
$webtask = WebTask->Lookup($webtask_id);
}
else {
$webtask = WebTask->Create(undef);
}
if (!defined($webtask)) {
fatal("Could not create webtask for profile");
}
$webtask->AutoStore(1);
}
#
# These are the fields that we allow to come in from the XMLfile.
#
......@@ -417,6 +442,10 @@ else {
}
fatal("Could not create new profile");
}
# Had to wait to do this, see comment above.
$webtask->SetObject($profile->uuid())
if (defined($webtask));
if (!$this_user->IsAdmin()) {
$profile->Publish();
}
......@@ -430,22 +459,6 @@ if (defined($instance)) {
my $imagename = $profile->name();
my $new_uuid = $profile->uuid();
#
# Grab the webtask object so we can watch it. We are looking
# for it to finish, so we can unlock the profile for use. Note
# this always creates a webtask, even if not directed to on the
# commmand line, so that we can communicate with the script we
# call that does the work.
#
if (!defined($webtask)) {
$webtask = WebTask->Create($profile->uuid(), $webtask_id);
if (!defined($webtask)) {
$profile->Delete(1);
fatal("Could not create webtask for snapshot");
}
$webtask->AutoStore(1);
}
if ($profile->Lock()) {
$profile->Delete(1);
fatal("Could not lock new profile");
......@@ -653,17 +666,19 @@ sub DeleteProfile($)
# Version zero is special of course.
#
if ($profile->version()) {
$profile->DeleteVersion(0) == 0 or
$profile->DeleteVersion() == 0 or
fatal("Could not delete profile version");
}
else {
# Purge it. At some point we want to save them.
$profile->Delete(1) == 0 or
fatal("Could not delete profile");
# Kill off object webtask, since we do not do that when purging.
WebTask->DeleteByObject($profile->uuid());
}
# No need for this anymore.
# No need for this anonymous webtask anymore.
$webtask->Delete()
if (!defined($webtask));
if (defined($webtask));
return 0;
uerror:
if (defined($webtask)) {
......
......@@ -44,7 +44,7 @@ function Do_CloneStatus()
}
$profile = Profile::Lookup($ajax_args["uuid"]);
if (!$profile) {
SPITAJAX_ERROR(1, "Unknown profile uuid");
SPITAJAX_ERROR(1, "Clone operation failed, could not create disk image");
return;
}
if ($this_idx != $profile->creator_idx() && !ISADMIN()) {
......@@ -116,19 +116,19 @@ function Do_DeleteProfile()
return;
}
$retval = SUEXEC($this_uid, $profile->pid(),
"webmanage_profile -t " . $webtask->task_id() . " " .
"delete " . $profile->uuid(),
"webmanage_profile delete -t " . $webtask->task_id() .
" " . $profile->uuid(),
SUEXEC_ACTION_IGNORE);
if ($retval != 0) {
$webtask->Refresh();
if ($retval < 0) {
$error = "Internal Error; please try again later\n\n";
$error .= $webtask->output();
$error .= $webtask->TaskValue("output");
SUEXECERROR(SUEXEC_ACTION_CONTINUE);
}
else {
$error = $webtask->output();
$error = $webtask->TaskValue("output");
}
$webtask->Delete();
SPITAJAX_ERROR(1, $error);
......@@ -190,18 +190,18 @@ function Do_PublishProfile()
return;
}
$retval = SUEXEC($this_uid, $profile->pid(),
"webmanage_profile -t " . $webtask->task_id() . " " .
"publish " . $profile->uuid(),
"webmanage_profile publish -t " . $webtask->task_id() .
" " . $profile->uuid(),
SUEXEC_ACTION_IGNORE);
if ($retval != 0) {
$webtask->Refresh();
if ($retval < 0) {
$error = "Internal Error; please try again later\n\n";
$error .= $webtask->output();
$error .= $webtask->TaskValue("output");
SUEXECERROR(SUEXEC_ACTION_CONTINUE);
}
else {
$error = $webtask->output();
$error = $webtask->TaskValue("output");
}
$webtask->Delete();
SPITAJAX_ERROR(1, $error);
......
......@@ -572,19 +572,18 @@ else {
#
# Call out to the backend.
#
$command = "webmanage_profile ";
$webtask = WebTask::CreateAnonymous();
$webtask_id = $webtask->task_id();
$command = "webmanage_profile ";
if ($action == "edit") {
$command .= " update " . $profile->uuid();
$command .= " update -t $webtask_id " . $profile->uuid();
}
else {
$command .= " create";
$command .= " create -t $webtask_id ";
}
if (isset($snapuuid)) {
$command .= " -s " . escapeshellarg($snapuuid);
# We want to pass a webtask id along for tracking the image progress.
$webtask_id = WebTask::GenerateID();
$command .= " -t " . $webtask_id;
}
$command .= " $xmlname";
......@@ -596,18 +595,9 @@ if ($retval) {
SUEXECERROR(SUEXEC_ACTION_CONTINUE);
}
else {
#
# Decode simple XML that is returned.
#
if (isset($webtask_id)) {
$webtask = WebTask::Lookup($webtask_id);
if ($webtask) {
$parsed = simplexml_load_string($webtask->output());
}
}
else {
# We should always use a webtask.
$parsed = simplexml_load_string($suexec_output);
$webtask->Refresh();
if ($webtask->TaskValue("output")) {
$parsed = simplexml_load_string($webtask->TaskValue("output"));
}
if (!$parsed) {
$errors["error"] = "Internal Error; please try again later.";
......@@ -626,6 +616,11 @@ if (count($errors)) {
return;
}
# Done with this, unless doing a snapshot (needed for imaging status).
if (!isset($snapuuid)) {
$webtask->Delete();
}
#
# Need the index to pass back through.
#
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment