Scalr\Observer\DBEventObserver::OnHostDown PHP Method

OnHostDown() public method

See also: Scalr\Observer\AbstractEventObserver::OnHostDown()
public OnHostDown ( HostDownEvent $event )
$event HostDownEvent
    public function OnHostDown(HostDownEvent $event)
    {
        if ($event->isSuspended) {
            $event->DBServer->SetProperties([SERVER_PROPERTIES::REBOOTING => 0]);
            $event->DBServer->update(['status' => SERVER_STATUS::SUSPENDED, 'remoteIp' => "", 'localIp' => ""]);
        }
        if ($event->DBServer->IsRebooting()) {
            return;
        }
        $this->DB->Execute("UPDATE servers_history SET scu_collecting = '0' WHERE server_id = ?", array($event->DBServer->serverId));
        //TODO: move to alerts;
        $this->DB->Execute("UPDATE server_alerts SET status='resolved' WHERE server_id = ?", array($event->DBServer->serverId));
        try {
            $DBFarmRole = $event->DBServer->GetFarmRoleObject();
            if ($DBFarmRole->GetSetting(Entity\FarmRoleSetting::MYSQL_BCP_SERVER_ID) == $event->DBServer->serverId) {
                $DBFarmRole->SetSetting(Entity\FarmRoleSetting::MYSQL_IS_BCP_RUNNING, 0, Entity\FarmRoleSetting::TYPE_LCL);
            }
            if ($DBFarmRole->GetSetting(Entity\FarmRoleSetting::MYSQL_BUNDLE_SERVER_ID) == $event->DBServer->serverId) {
                $DBFarmRole->SetSetting(Entity\FarmRoleSetting::MYSQL_IS_BUNDLE_RUNNING, 0, Entity\FarmRoleSetting::TYPE_LCL);
            }
            if ($DBFarmRole->GetSetting(Scalr_Db_Msr::DATA_BACKUP_SERVER_ID) == $event->DBServer->serverId) {
                $DBFarmRole->SetSetting(Scalr_Db_Msr::DATA_BACKUP_IS_RUNNING, 0, Entity\FarmRoleSetting::TYPE_LCL);
            }
            if ($DBFarmRole->GetSetting(Scalr_Db_Msr::DATA_BUNDLE_SERVER_ID) == $event->DBServer->serverId) {
                $DBFarmRole->SetSetting(Scalr_Db_Msr::DATA_BUNDLE_IS_RUNNING, 0, Entity\FarmRoleSetting::TYPE_LCL);
            }
        } catch (Exception $e) {
        }
        //Check active bundle task:
        $bundle_task_id = $this->DB->GetOne("SELECT id FROM bundle_tasks WHERE server_id=? AND status IN (?,?) LIMIT 1", [$event->DBServer->serverId, SERVER_SNAPSHOT_CREATION_STATUS::PENDING, SERVER_SNAPSHOT_CREATION_STATUS::IN_PROGRESS]);
        if ($bundle_task_id && $event->DBServer->platform != SERVER_PLATFORMS::GCE) {
            $BundleTask = BundleTask::LoadById($bundle_task_id);
            $BundleTask->SnapshotCreationFailed("Server was terminated before image was created.");
        }
    }