public function OnBeforeHostTerminate(BeforeHostTerminateEvent $event)
 {
     try {
         $dbFarm = DBFarm::LoadByID($this->FarmID);
     } catch (Exception $e) {
     }
     if ($dbFarm) {
         $servers = $dbFarm->GetServersByFilter(array('status' => array(SERVER_STATUS::INIT, SERVER_STATUS::RUNNING, SERVER_STATUS::PENDING_TERMINATE, SERVER_STATUS::PENDING_SUSPEND)));
         foreach ($servers as $DBServer) {
             // We don't need to send beforeHostTerminate event to all "Pending terminate" servers,
             // only tu eventServer.
             if ($DBServer->status == SERVER_STATUS::PENDING_TERMINATE) {
                 if ($DBServer->serverId != $event->DBServer->serverId) {
                     continue;
                 }
             }
             $msg = new Scalr_Messaging_Msg_BeforeHostTerminate();
             $msg->setServerMetaData($event->DBServer);
             $msg->suspend = $event->suspend;
             $msg = Scalr_Scripting_Manager::extendMessage($msg, $event, $event->DBServer, $DBServer);
             if ($event->DBServer->farmRoleId != 0) {
                 foreach (Scalr_Role_Behavior::getListForFarmRole($event->DBServer->GetFarmRoleObject()) as $behavior) {
                     $msg = $behavior->extendMessage($msg, $event->DBServer);
                 }
             }
             $DBServer->SendMessage($msg, false, true);
         }
         try {
             if ($event->DBServer->GetFarmRoleObject()->GetSetting(Scalr_Db_Msr::SLAVE_TO_MASTER) != 1) {
                 if ($event->DBServer->GetFarmRoleObject()->GetRoleObject()->getDbMsrBehavior()) {
                     $this->sendPromoteToMasterMessage($event);
                 }
             }
         } catch (Exception $e) {
         }
     }
 }
Пример #2
0
 public function OnBeforeHostTerminate(\BeforeHostTerminateEvent $event)
 {
     try {
         $dbFarm = \DBFarm::LoadByID($this->FarmID);
     } catch (\Exception $e) {
     }
     if ($dbFarm) {
         $servers = $this->DB->Execute("SELECT * FROM servers WHERE farm_id = ? AND status IN (?,?,?,?)", array($dbFarm->ID, \SERVER_STATUS::INIT, \SERVER_STATUS::RUNNING, \SERVER_STATUS::PENDING_TERMINATE, \SERVER_STATUS::PENDING_SUSPEND));
         $event->messageLongestInsert = 0;
         while ($server = $servers->FetchRow()) {
             $DBServer = \DBServer::load($server);
             // We don't need to send beforeHostTerminate event to all "Pending terminate" servers,
             // only tu eventServer.
             if ($DBServer->status == \SERVER_STATUS::PENDING_TERMINATE) {
                 if ($DBServer->serverId != $event->DBServer->serverId) {
                     continue;
                 }
             }
             $msg = new \Scalr_Messaging_Msg_BeforeHostTerminate();
             $msg->setServerMetaData($event->DBServer);
             $msg->suspend = $event->suspend;
             $msg = \Scalr_Scripting_Manager::extendMessage($msg, $event, $event->DBServer, $DBServer);
             if ($event->DBServer->farmRoleId != 0) {
                 foreach (\Scalr_Role_Behavior::getListForFarmRole($event->DBServer->GetFarmRoleObject()) as $behavior) {
                     $msg = $behavior->extendMessage($msg, $event->DBServer);
                 }
             }
             $mt = microtime(true);
             $DBServer->SendMessage($msg, false, true);
             $mtResult = microtime(true) - $mt;
             if ($event->messageLongestInsert < $mtResult) {
                 $event->messageLongestInsert = $mtResult;
             }
         }
         try {
             if ($event->DBServer->GetFarmRoleObject()->GetSetting(\Scalr_Db_Msr::SLAVE_TO_MASTER) != 1) {
                 if ($event->DBServer->GetFarmRoleObject()->GetRoleObject()->getDbMsrBehavior()) {
                     $this->sendPromoteToMasterMessage($event);
                 }
             }
         } catch (\Exception $e) {
         }
     }
 }