Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Define and throw simgrid::VmFailureException.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 2 Jul 2019 13:47:05 +0000 (15:47 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 2 Jul 2019 14:12:21 +0000 (16:12 +0200)
include/simgrid/Exception.hpp
src/plugins/vm/VirtualMachineImpl.cpp
src/plugins/vm/VmLiveMigration.cpp
src/plugins/vm/s4u_VirtualMachine.cpp

index 8c1e0f7..39002a8 100644 (file)
@@ -169,6 +169,16 @@ public:
   }
 };
 
   }
 };
 
+/** Exception raised when a VM fails */
+class VmFailureException : public xbt_ex {
+public:
+  VmFailureException(simgrid::xbt::ThrowPoint&& throwpoint, std::string&& message)
+      : xbt_ex(std::move(throwpoint), std::move(message))
+  {
+    category = vm_error;
+  }
+};
+
 /** Exception raised when something got canceled before completion */
 class CancelException : public xbt_ex {
 public:
 /** Exception raised when something got canceled before completion */
 class CancelException : public xbt_ex {
 public:
index 191d5cf..b7b2002 100644 (file)
@@ -4,9 +4,9 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "src/plugins/vm/VirtualMachineImpl.hpp"
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "src/plugins/vm/VirtualMachineImpl.hpp"
+#include "simgrid/Exception.hpp"
 #include "src/include/surf/surf.hpp"
 #include "src/kernel/activity/ExecImpl.hpp"
 #include "src/include/surf/surf.hpp"
 #include "src/kernel/activity/ExecImpl.hpp"
-#include "xbt/asserts.h" // xbt_log_no_loc
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_vm, surf, "Logging specific to the SURF VM module");
 
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_vm, surf, "Logging specific to the SURF VM module");
 
@@ -173,10 +173,11 @@ VirtualMachineImpl::~VirtualMachineImpl()
 void VirtualMachineImpl::suspend(smx_actor_t issuer)
 {
   if (get_state() != s4u::VirtualMachine::state::RUNNING)
 void VirtualMachineImpl::suspend(smx_actor_t issuer)
 {
   if (get_state() != s4u::VirtualMachine::state::RUNNING)
-    THROWF(vm_error, 0, "Cannot suspend VM %s: it is not running.", piface_->get_cname());
+    throw VmFailureException(XBT_THROW_POINT,
+                             xbt::string_printf("Cannot suspend VM %s: it is not running.", piface_->get_cname()));
   if (issuer->get_host() == piface_)
   if (issuer->get_host() == piface_)
-    THROWF(vm_error, 0, "Actor %s cannot suspend the VM %s in which it runs", issuer->get_cname(),
-           piface_->get_cname());
+    throw VmFailureException(XBT_THROW_POINT, xbt::string_printf("Actor %s cannot suspend the VM %s in which it runs",
+                                                                 issuer->get_cname(), piface_->get_cname()));
 
   XBT_DEBUG("suspend VM(%s), where %zu processes exist", piface_->get_cname(), process_list_.size());
 
 
   XBT_DEBUG("suspend VM(%s), where %zu processes exist", piface_->get_cname(), process_list_.size());
 
@@ -195,7 +196,8 @@ void VirtualMachineImpl::suspend(smx_actor_t issuer)
 void VirtualMachineImpl::resume()
 {
   if (get_state() != s4u::VirtualMachine::state::SUSPENDED)
 void VirtualMachineImpl::resume()
 {
   if (get_state() != s4u::VirtualMachine::state::SUSPENDED)
-    THROWF(vm_error, 0, "Cannot resume VM %s: it was not suspended", piface_->get_cname());
+    throw VmFailureException(XBT_THROW_POINT,
+                             xbt::string_printf("Cannot resume VM %s: it was not suspended", piface_->get_cname()));
 
   XBT_DEBUG("Resume VM %s, containing %zu processes.", piface_->get_cname(), process_list_.size());
 
 
   XBT_DEBUG("Resume VM %s, containing %zu processes.", piface_->get_cname(), process_list_.size());
 
index 460e9f4..08add03 100644 (file)
@@ -324,14 +324,21 @@ void sg_vm_migrate(simgrid::s4u::VirtualMachine* vm, simgrid::s4u::Host* dst_pm)
   simgrid::s4u::Host* src_pm = vm->get_pm();
 
   if (not src_pm->is_on())
   simgrid::s4u::Host* src_pm = vm->get_pm();
 
   if (not src_pm->is_on())
-    THROWF(vm_error, 0, "Cannot migrate VM '%s' from host '%s', which is offline.", vm->get_cname(),
-           src_pm->get_cname());
+    throw simgrid::VmFailureException(
+        XBT_THROW_POINT, simgrid::xbt::string_printf("Cannot migrate VM '%s' from host '%s', which is offline.",
+                                                     vm->get_cname(), src_pm->get_cname()));
   if (not dst_pm->is_on())
   if (not dst_pm->is_on())
-    THROWF(vm_error, 0, "Cannot migrate VM '%s' to host '%s', which is offline.", vm->get_cname(), dst_pm->get_cname());
+    throw simgrid::VmFailureException(
+        XBT_THROW_POINT, simgrid::xbt::string_printf("Cannot migrate VM '%s' to host '%s', which is offline.",
+                                                     vm->get_cname(), dst_pm->get_cname()));
   if (vm->get_state() != simgrid::s4u::VirtualMachine::state::RUNNING)
   if (vm->get_state() != simgrid::s4u::VirtualMachine::state::RUNNING)
-    THROWF(vm_error, 0, "Cannot migrate VM '%s' that is not running yet.", vm->get_cname());
+    throw simgrid::VmFailureException(
+        XBT_THROW_POINT,
+        simgrid::xbt::string_printf("Cannot migrate VM '%s' that is not running yet.", vm->get_cname()));
   if (vm->get_impl()->is_migrating_)
   if (vm->get_impl()->is_migrating_)
-    THROWF(vm_error, 0, "Cannot migrate VM '%s' that is already migrating.", vm->get_cname());
+    throw simgrid::VmFailureException(
+        XBT_THROW_POINT,
+        simgrid::xbt::string_printf("Cannot migrate VM '%s' that is already migrating.", vm->get_cname()));
 
   vm->get_impl()->is_migrating_ = true;
   simgrid::s4u::VirtualMachine::on_migration_start(*vm);
 
   vm->get_impl()->is_migrating_ = true;
   simgrid::s4u::VirtualMachine::on_migration_start(*vm);
index 0a927af..7dd96b8 100644 (file)
@@ -3,6 +3,7 @@
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
+#include "simgrid/Exception.hpp"
 #include "simgrid/s4u/Actor.hpp"
 #include "simgrid/vm.h"
 #include "src/include/surf/surf.hpp"
 #include "simgrid/s4u/Actor.hpp"
 #include "simgrid/vm.h"
 #include "src/include/surf/surf.hpp"
@@ -84,8 +85,9 @@ void VirtualMachine::start()
       if (vm_ramsize > pm_ramsize - total_ramsize_of_vms) {
         XBT_WARN("cannot start %s@%s due to memory shortage: vm_ramsize %ld, free %ld, pm_ramsize %ld (bytes).",
                  this->get_cname(), pm->get_cname(), vm_ramsize, pm_ramsize - total_ramsize_of_vms, pm_ramsize);
       if (vm_ramsize > pm_ramsize - total_ramsize_of_vms) {
         XBT_WARN("cannot start %s@%s due to memory shortage: vm_ramsize %ld, free %ld, pm_ramsize %ld (bytes).",
                  this->get_cname(), pm->get_cname(), vm_ramsize, pm_ramsize - total_ramsize_of_vms, pm_ramsize);
-        THROWF(vm_error, 0, "Memory shortage on host '%s', VM '%s' cannot be started", pm->get_cname(),
-               this->get_cname());
+        throw VmFailureException(XBT_THROW_POINT,
+                                 xbt::string_printf("Memory shortage on host '%s', VM '%s' cannot be started",
+                                                    pm->get_cname(), this->get_cname()));
       }
     }
 
       }
     }