本文整理汇总了PHP中DBServer::LoadByLocalIp方法的典型用法代码示例。如果您正苦于以下问题:PHP DBServer::LoadByLocalIp方法的具体用法?PHP DBServer::LoadByLocalIp怎么用?PHP DBServer::LoadByLocalIp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBServer
的用法示例。
在下文中一共展示了DBServer::LoadByLocalIp方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: ListScripts
protected function ListScripts()
{
$ResponseDOMDocument = $this->CreateResponse();
$ScriptsDOMNode = $ResponseDOMDocument->createElement("scripts");
/************/
// Get and Validate Event name
$instance_events = array("hostinit" => "HostInit", "hostup" => "HostUp", "rebootfinish" => "RebootComplete", "newmysqlmaster" => "NewMysqlMasterUp", "ebsvolumeattached" => "EBSVolumeAttached", "blockdeviceattached" => "EBSVolumeAttached", "blockdevicemounted" => "EBSVolumeMounted");
$Reflect = new ReflectionClass("EVENT_TYPE");
$scalr_events = $Reflect->getConstants();
if (!$this->DBServer->IsSupported(0.5)) {
throw new Exception("ami-scripts roles cannot execute scripts anymore. Please upgrade your roles to scalarizr: http://scalr.net/blog/announcements/ami-scripts/");
}
if (!in_array($this->GetArg("event"), $scalr_events)) {
$event_name = $instance_events[strtolower($this->GetArg("event"))];
} else {
$event_name = $this->GetArg("event");
}
if (!$event_name && preg_match("/^(Custom|API)Event-[0-9]+-[0-9]+\$/si", $this->GetArg("event"))) {
$custom_event_name = $this->GetArg("event");
}
try {
if ($this->GetArg("event_id")) {
if (preg_match("/^FRSID-([0-9]+)\$/", $this->GetArg("event_id"), $matches)) {
$scripts = $this->DB->GetAll("SELECT * FROM farm_role_scripts WHERE farmid=? AND id=? ORDER BY order_index ASC", array($this->DBServer->farmId, $matches[1]));
} else {
$event_info = $this->DB->GetRow("SELECT * FROM events WHERE event_id=?", array($this->GetArg("event_id")));
if ($event_info) {
$Event = unserialize($event_info['event_object']);
if ($Event->DBServer) {
if ($Event->DBServer->serverId == $this->DBServer->serverId) {
$is_target = '1';
} else {
$is_target = '0';
}
$scripts = $this->DB->GetAll("SELECT * FROM farm_role_scripts WHERE farmid=? \r\n\t\t\t\t \t\tAND event_name=? AND (target = ? OR (target = ? AND 1 = {$is_target} AND farm_roleid=?) OR (target = ? AND farm_roleid=?)) ORDER BY order_index ASC", array($Event->GetFarmID(), $Event->GetName(), SCRIPTING_TARGET::FARM, SCRIPTING_TARGET::INSTANCE, $Event->DBServer->farmRoleId, SCRIPTING_TARGET::ROLE, $Event->DBServer->farmRoleId));
$TargetDBFarmRole = $Event->DBServer->GetFarmRoleObject();
$target_instance_id = $Event->DBServer->serverId;
} else {
$scripts = $this->DB->GetAll("SELECT * FROM farm_role_scripts WHERE farmid=? \r\n\t\t\t\t \t\tAND event_name=? AND target = ? ORDER BY order_index ASC", array($Event->GetFarmID(), $Event->GetName(), SCRIPTING_TARGET::FARM));
}
}
}
}
} catch (Exception $e) {
return $ResponseDOMDocument;
}
/************/
/***********************************************************/
/** Instance from which request has come **/
try {
$DBFarmRole = $this->DBServer->GetFarmRoleObject();
} catch (Exception $e) {
return $ResponseDOMDocument;
}
$DBFarm = $this->DBServer->GetFarmObject();
if (!$scripts) {
// Check context and get list of scripts
if (!$this->GetArg("target_ip")) {
//
// Build a list of scripts to be executed on that particular instance
//
if ($event_name == EVENT_TYPE::HOST_INIT) {
$this->DBServer->remoteIp = $_SERVER['REMOTE_ADDR'];
$this->DBServer->localIp = $this->GetArg('local_ip');
}
$scripts = $this->DB->GetAll("SELECT * FROM farm_role_scripts WHERE farmid=? AND farm_roleid=? \r\n\t \t\tAND event_name=? ORDER BY order_index ASC", array($this->DBServer->farmId, $DBFarmRole->ID, $event_name));
} else {
if ($event_name == EVENT_TYPE::HOST_INIT && $this->GetArg("target_ip") == $this->GetArg('local_ip')) {
$this->DBServer->remoteIp = $_SERVER['REMOTE_ADDR'];
$this->DBServer->localIp = $this->GetArg('local_ip');
//
// Build a list of scripts to be executed upon event from another instance.
//
$targetDBServer = $this->DBServer;
} else {
//
// Build a list of scripts to be executed upon event from another instance.
//
try {
$targetDBServer = DBServer::LoadByLocalIp($this->GetArg("target_ip"));
} catch (Exception $e) {
return $ResponseDOMDocument;
}
}
if ($this->GetArg("target_ip") == $this->GetArg('local_ip')) {
$is_target = '1';
} else {
$is_target = '0';
}
if (!$targetDBServer) {
exit;
}
try {
$TargetDBFarmRole = $targetDBServer->GetFarmRoleObject();
} catch (Exception $e) {
return $ResponseDOMDocument;
}
$scripts = $this->DB->GetAll("SELECT * FROM farm_role_scripts WHERE farmid=? \r\n\t \t\tAND event_name=? AND (target = ? OR (target = ? AND 1 = {$is_target} AND farm_roleid=?) OR (target = ? AND farm_roleid=?)) ORDER BY order_index ASC", array($this->DBServer->farmId, $event_name, SCRIPTING_TARGET::FARM, SCRIPTING_TARGET::INSTANCE, $TargetDBFarmRole->ID, SCRIPTING_TARGET::ROLE, $TargetDBFarmRole->ID));
}
}
//.........这里部分代码省略.........