当前位置: 首页>>代码示例>>PHP>>正文


PHP Scalr_Role_Behavior::getListForRole方法代码示例

本文整理汇总了PHP中Scalr_Role_Behavior::getListForRole方法的典型用法代码示例。如果您正苦于以下问题:PHP Scalr_Role_Behavior::getListForRole方法的具体用法?PHP Scalr_Role_Behavior::getListForRole怎么用?PHP Scalr_Role_Behavior::getListForRole使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Scalr_Role_Behavior的用法示例。


在下文中一共展示了Scalr_Role_Behavior::getListForRole方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: OnHostDown

 public function OnHostDown(HostDownEvent $event)
 {
     if ($event->DBServer->IsRebooting() == 1) {
         $event->exit = 'reboot';
         return;
     }
     if (!$this->FarmID) {
         $event->exit = 'no-farm';
         return;
     }
     $dbFarm = DBFarm::LoadByID($this->FarmID);
     $servers = $dbFarm->GetServersByFilter(array('status' => array(SERVER_STATUS::RUNNING)));
     try {
         $DBFarmRole = $event->DBServer->GetFarmRoleObject();
         $is_synchronize = $DBFarmRole->NewRoleID ? true : false;
     } catch (Exception $e) {
         $is_synchronize = false;
     }
     try {
         $DBRole = DBRole::loadById($event->DBServer->roleId);
     } catch (Exception $e) {
     }
     //HUGE BUG HERE!
     $first_in_role_handled = false;
     $first_in_role_server = null;
     $event->msgExpected = count($servers);
     foreach ($servers as $DBServer) {
         if (!$DBServer instanceof DBServer) {
             continue;
         }
         $isfirstinrole = '0';
         $eventServerIsMaster = $event->DBServer->GetProperty(SERVER_PROPERTIES::DB_MYSQL_MASTER) || $event->DBServer->GetProperty(Scalr_Db_Msr::REPLICATION_MASTER);
         if ($eventServerIsMaster && !$first_in_role_handled) {
             if (!$is_synchronize && $DBServer->farmRoleId == $event->DBServer->farmRoleId) {
                 if (DBRole::loadById($DBServer->roleId)->hasBehavior(ROLE_BEHAVIORS::MYSQL) || DBRole::loadById($DBServer->roleId)->getDbMsrBehavior()) {
                     $first_in_role_handled = true;
                     $first_in_role_server = $DBServer;
                     $isfirstinrole = '1';
                 }
             }
         }
         $msg = new Scalr_Messaging_Msg_HostDown();
         //TODO:
         $msg->behaviour = $DBRole ? $DBRole->getBehaviors() : '*Unknown*';
         $msg->roleName = $DBRole ? $DBRole->name : '*Unknown*';
         $msg->localIp = $event->DBServer->localIp;
         $msg->remoteIp = $event->DBServer->remoteIp;
         $msg->isFirstInRole = $isfirstinrole;
         $msg->serverIndex = $event->DBServer->index;
         $msg->farmRoleId = $event->DBServer->farmRoleId;
         $msg->serverId = $event->DBServer->serverId;
         $msg->cloudLocation = $event->DBServer->GetCloudLocation();
         // If FarmRole was removed from farm, no configuration left
         if ($DBFarmRole) {
             $msg = Scalr_Scripting_Manager::extendMessage($msg, $event, $event->DBServer, $DBServer);
             if ($event->DBServer->farmRoleId != 0) {
                 foreach (Scalr_Role_Behavior::getListForRole(DBRole::loadById($event->DBServer->roleId)) as $behavior) {
                     $msg = $behavior->extendMessage($msg, $event->DBServer);
                 }
             }
         }
         $msg = $DBServer->SendMessage($msg, false, true);
         if ($msg->dbMessageId) {
             $event->msgCreated++;
         }
         $loopServerIsMaster = $DBServer->GetProperty(SERVER_PROPERTIES::DB_MYSQL_MASTER) || $DBServer->GetProperty(Scalr_Db_Msr::REPLICATION_MASTER);
         if ($loopServerIsMaster && $DBServer->status == SERVER_STATUS::RUNNING) {
             $doNotPromoteSlave2Master = true;
         }
     }
     if (!$DBFarmRole) {
         return;
     }
     if ($DBFarmRole->GetRoleObject()->getDbMsrBehavior() && !$doNotPromoteSlave2Master && !$DBFarmRole->GetSetting(Scalr_Db_Msr::SLAVE_TO_MASTER)) {
         $this->sendPromoteToMasterMessage($event);
     }
     //LEGACY MYSQL CODE:
     if ($DBFarmRole->GetRoleObject()->hasBehavior(ROLE_BEHAVIORS::MYSQL)) {
         // If EC2 master down
         if ($event->DBServer->GetProperty(SERVER_PROPERTIES::DB_MYSQL_MASTER) && $DBFarmRole) {
             $master = $dbFarm->GetMySQLInstances(true);
             if ($master[0]) {
                 return;
             }
             $msg = new Scalr_Messaging_Msg_Mysql_PromoteToMaster($DBFarmRole->GetSetting(DBFarmRole::SETTING_MYSQL_ROOT_PASSWORD), $DBFarmRole->GetSetting(DBFarmRole::SETTING_MYSQL_REPL_PASSWORD), $DBFarmRole->GetSetting(DBFarmRole::SETTING_MYSQL_STAT_PASSWORD));
             if ($event->DBServer->IsSupported("0.7")) {
                 if (in_array($event->DBServer->platform, array(SERVER_PLATFORMS::EC2, SERVER_PLATFORMS::CLOUDSTACK, SERVER_PLATFORMS::IDCF, SERVER_PLATFORMS::UCLOUD))) {
                     try {
                         $volume = Scalr_Storage_Volume::init()->loadById($DBFarmRole->GetSetting(DBFarmRole::SETTING_MYSQL_SCALR_VOLUME_ID));
                         $msg->volumeConfig = $volume->getConfig();
                     } catch (Exception $e) {
                         $this->Logger->error(new FarmLogMessage($event->DBServer->farmId, "Cannot create volumeConfig for PromoteToMaster message: {$e->getMessage()}"));
                     }
                 }
             } elseif ($event->DBServer->platform == SERVER_PLATFORMS::EC2) {
                 $msg->volumeId = $DBFarmRole->GetSetting(DBFarmRole::SETTING_MYSQL_MASTER_EBS_VOLUME_ID);
             }
             // Send Mysql_PromoteToMaster to the first server in the same avail zone as old master (if exists)
             // Otherwise send to first in role
             $platform = $event->DBServer->platform;
//.........这里部分代码省略.........
开发者ID:rickb838,项目名称:scalr,代码行数:101,代码来源:class.MessagingEventObserver.php


注:本文中的Scalr_Role_Behavior::getListForRole方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。