本文整理汇总了PHP中DBFarmRole类的典型用法代码示例。如果您正苦于以下问题:PHP DBFarmRole类的具体用法?PHP DBFarmRole怎么用?PHP DBFarmRole使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DBFarmRole类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getValue
public function getValue(DBFarmRole $dbFarmRole, Scalr_Scaling_FarmRoleMetric $farmRoleMetric)
{
$servers = $dbFarmRole->GetServersByFilter(array('status' => SERVER_STATUS::RUNNING));
$DBFarm = $dbFarmRole->GetFarmObject();
if (count($servers) == 0) {
return 0;
}
$_roleBW = array();
$retval = array();
foreach ($servers as $DBServer) {
$port = $DBServer->GetProperty(SERVER_PROPERTIES::SZR_SNMP_PORT);
$type = $farmRoleMetric->getSetting(self::SETTING_BW_TYPE);
if (!$type) {
$type = 'outbound';
}
$this->snmpClient->connect($DBServer->remoteIp, $port ? $port : 161, $DBFarm->Hash, null, null, false);
preg_match_all("/[0-9]+/si", $this->snmpClient->get($this->snmpOids[$type]), $matches);
$bw_out = (double) $matches[0][0];
$bw = round($bw_out / 1024 / 1024, 2);
$_roleBW[] = $bw;
}
$roleBW = round(array_sum($_roleBW) / count($_roleBW), 2);
if ($farmRoleMetric->getSetting(self::SETTING_BW_LAST_VALUE_RAW) !== null && $farmRoleMetric->getSetting(self::SETTING_BW_LAST_VALUE_RAW) !== '') {
$time = time() - $farmRoleMetric->dtLastPolled;
$bandwidth_usage = ($roleBW - (double) $farmRoleMetric->getSetting(self::SETTING_BW_LAST_VALUE_RAW)) * 8;
$bandwidth_channel_usage = $bandwidth_usage / $time;
// in Mbits/sec
$retval = round($bandwidth_channel_usage, 2);
} else {
$retval = 0;
}
$farmRoleMetric->setSetting(self::SETTING_BW_LAST_VALUE_RAW, $roleBW);
return array($retval);
}
示例2: __construct
/**
* Constructor
*
* @param string $platform Platform
* @param DBFarmRole $DBFarmRole optional Farm Role object
* @param int $index optional Server index within the Farm Role scope
* @param string $role_id optional Identifier of the Role
*/
public function __construct($platform, DBFarmRole $DBFarmRole = null, $index = null, $role_id = null)
{
$this->platform = $platform;
$this->dbFarmRole = $DBFarmRole;
$this->index = $index;
$this->roleId = $role_id === null ? $this->dbFarmRole->RoleID : $role_id;
if ($DBFarmRole) {
$this->envId = $DBFarmRole->GetFarmObject()->EnvID;
}
//Refletcion
$Reflect = new ReflectionClass(DBServer::$platformPropsClasses[$this->platform]);
foreach ($Reflect->getConstants() as $k => $v) {
$this->platformProps[] = $v;
}
if ($DBFarmRole) {
if (PlatformFactory::isOpenstack($this->platform)) {
$this->SetProperties(array(OPENSTACK_SERVER_PROPERTIES::CLOUD_LOCATION => $DBFarmRole->CloudLocation));
} elseif (PlatformFactory::isCloudstack($this->platform)) {
$this->SetProperties(array(CLOUDSTACK_SERVER_PROPERTIES::CLOUD_LOCATION => $DBFarmRole->CloudLocation));
} else {
switch ($this->platform) {
case SERVER_PLATFORMS::GCE:
$this->SetProperties(array(GCE_SERVER_PROPERTIES::CLOUD_LOCATION => $DBFarmRole->CloudLocation));
break;
case SERVER_PLATFORMS::EC2:
$this->SetProperties(array(EC2_SERVER_PROPERTIES::REGION => $DBFarmRole->CloudLocation));
break;
}
}
}
$this->SetProperties(array(SERVER_PROPERTIES::SZR_VESION => '0.20.0'));
}
示例3: getValue
public function getValue(DBFarmRole $dbFarmRole, Scalr_Scaling_FarmRoleMetric $farmRoleMetric)
{
$servers = $dbFarmRole->GetServersByFilter(array('status' => SERVER_STATUS::RUNNING));
$dbFarm = $dbFarmRole->GetFarmObject();
$roleLA = 0;
if (count($servers) == 0) {
return false;
}
$retval = array();
foreach ($servers as $DBServer) {
if ($dbFarmRole->GetSetting(Entity\FarmRoleSetting::SCALING_EXCLUDE_DBMSR_MASTER) == 1) {
$isMaster = $DBServer->GetProperty(SERVER_PROPERTIES::DB_MYSQL_MASTER) == 1 || $DBServer->GetProperty(Scalr_Db_Msr::REPLICATION_MASTER) == 1;
if ($isMaster) {
continue;
}
}
try {
$period = $farmRoleMetric->getSetting(self::SETTING_LA_PERIOD);
$index = 0;
if ($period == 15) {
$index = 2;
} elseif ($period == 5) {
$index = 1;
}
$la = $DBServer->scalarizr->system->loadAverage();
if ($la[$index] !== null && $la[$index] !== false) {
$la = (double) number_format($la[$index], 2);
}
$retval[] = $la;
} catch (Exception $e) {
\Scalr::getContainer()->logger(__CLASS__)->warn(new FarmLogMessage($DBServer->farmId, sprintf("Unable to read LoadAverage value from server %s: %s", $DBServer->getNameByConvention(), $e->getMessage()), $DBServer->serverId));
}
}
return count($retval) > 0 ? $retval : false;
}
示例4: getValue
public function getValue(DBFarmRole $dbFarmRole, Scalr_Scaling_FarmRoleMetric $farmRoleMetric)
{
$servers = $dbFarmRole->GetServersByFilter(array('status' => SERVER_STATUS::RUNNING));
$DBFarm = $dbFarmRole->GetFarmObject();
if (count($servers) == 0) {
return 0;
}
$roleBWRaw = array();
$retval = array();
foreach ($servers as $DBServer) {
$type = $farmRoleMetric->getSetting(self::SETTING_BW_TYPE) == 'inbound' ? 'receive' : 'transmit';
$netStat = (array) $DBServer->scalarizr->system->netStat();
foreach ($netStat as $interface => $usage) {
if ($interface != 'lo') {
break;
}
}
if ($usage) {
array_push($roleBWRaw, round($usage->{$type}->bytes / 1024 / 1024, 2));
}
}
$roleBW = round(array_sum($roleBWRaw) / count($roleBWRaw), 2);
if ($farmRoleMetric->getSetting(self::SETTING_BW_LAST_VALUE_RAW) !== null && $farmRoleMetric->getSetting(self::SETTING_BW_LAST_VALUE_RAW) !== '') {
$time = time() - $farmRoleMetric->dtLastPolled;
$bandwidthUsage = ($roleBW - (double) $farmRoleMetric->getSetting(self::SETTING_BW_LAST_VALUE_RAW)) * 8;
$bandwidthChannelUsage = $bandwidthUsage / $time;
// in Mbits/sec
$retval = round($bandwidthChannelUsage, 2);
} else {
$retval = 0;
}
$farmRoleMetric->setSetting(self::SETTING_BW_LAST_VALUE_RAW, $roleBW);
return array($retval);
}
示例5: getValue
public function getValue(DBFarmRole $dbFarmRole, Scalr_Scaling_FarmRoleMetric $farmRoleMetric)
{
$servers = $dbFarmRole->GetServersByFilter(array('status' => SERVER_STATUS::RUNNING));
$dbFarm = $dbFarmRole->GetFarmObject();
$roleLA = 0;
if (count($servers) == 0) {
return false;
}
$retval = array();
foreach ($servers as $DBServer) {
if ($dbFarmRole->GetSetting(DBFarmRole::SETTING_SCALING_EXCLUDE_DBMSR_MASTER) == 1) {
$isMaster = $DBServer->GetProperty(SERVER_PROPERTIES::DB_MYSQL_MASTER) == 1 || $DBServer->GetProperty(Scalr_Db_Msr::REPLICATION_MASTER) == 1;
if ($isMaster) {
continue;
}
}
$port = $DBServer->GetProperty(SERVER_PROPERTIES::SZR_SNMP_PORT);
$period = $farmRoleMetric->getSetting(self::SETTING_LA_PERIOD);
if (!$period) {
$period = '15';
}
$this->snmpClient->connect($DBServer->remoteIp, $port ? $port : 161, $dbFarm->Hash, null, null, false);
$res = $this->snmpClient->get($this->snmpOids[$period]);
$la = (double) $res;
$retval[] = $la;
}
return $retval;
}
示例6: getValue
public function getValue(DBFarmRole $dbFarmRole, Scalr_Scaling_FarmRoleMetric $farmRoleMetric)
{
$dbFarm = $dbFarmRole->GetFarmObject();
$AmazonSQS = AmazonSQS::GetInstance($dbFarm->GetEnvironmentObject()->getPlatformConfigValue(Modules_Platforms_Ec2::ACCESS_KEY), $dbFarm->GetEnvironmentObject()->getPlatformConfigValue(Modules_Platforms_Ec2::SECRET_KEY));
try {
$res = $AmazonSQS->GetQueueAttributes($farmRoleMetric->getSetting(self::SETTING_QUEUE_NAME));
$retval = $res['ApproximateNumberOfMessages'];
} catch (Exception $e) {
throw new Exception(sprintf("SQSScalingSensor failed during SQS request: %s", $e->getMessage()));
}
return array($retval);
}
示例7: getValue
public function getValue(DBFarmRole $dbFarmRole, Scalr_Scaling_FarmRoleMetric $farmRoleMetric)
{
$servers = $dbFarmRole->GetServersByFilter(array('status' => SERVER_STATUS::RUNNING));
$dbFarm = $dbFarmRole->GetFarmObject();
$retval = array();
if (count($servers) == 0) {
return false;
}
foreach ($servers as $DBServer) {
$port = $DBServer->GetProperty(SERVER_PROPERTIES::SZR_SNMP_PORT);
// Think about global cache
$this->snmpClient->connect($DBServer->remoteIp, $port ? $port : 161, $dbFarm->Hash, 7, null, true);
$res = $this->snmpClient->getFullTree(".1.3.6.1.4.1.36632.5");
$result = array();
foreach ($res as $oid => $value) {
preg_match("/^(.*?)\\.36632\\.5\\.1\\.([0-9]+)\\.([0-9]+)\$/", $oid, $matches);
switch ($matches[2]) {
case "1":
//index
$result['index'][$matches[3]] = $value;
break;
case "2":
//metric_id
$result['metric_id'][$matches[3]] = $value;
break;
case "3":
//metric_name
$result['metric_name'][$matches[3]] = $value;
break;
case "4":
//metric_value
$result['metric_value'][$matches[3]] = $value;
break;
case "5":
//error
$result['error'][$matches[3]] = $value;
break;
}
}
foreach ($result['metric_id'] as $index => $metric_id) {
if ($metric_id == $farmRoleMetric->metricId) {
if ($result['error'][$index]) {
throw new Exception(sprintf(_("%s metric error on '%s' (%s): %s"), $result['metric_name'][$index], $DBServer->serverId, $DBServer->remoteIp, $result['error'][$index]));
}
$retval[] = $result['metric_value'][$index];
break;
}
}
}
return $retval;
}
示例8: makeDecision
public function makeDecision(DBFarmRole $dbFarmRole, Scalr_Scaling_FarmRoleMetric $farmRoleMetric, $isInvert = false)
{
// Get data from BW sensor
$dbFarm = $dbFarmRole->GetFarmObject();
$tz = $dbFarm->GetSetting(Entity\FarmSetting::TIMEZONE);
$date = new DateTime();
if ($tz) {
$date->setTimezone(new DateTimeZone($tz));
}
$currentDate = array((int) $date->format("Hi"), $date->format("D"));
$scaling_period = $this->db->GetRow("\n SELECT * FROM farm_role_scaling_times\n WHERE '{$currentDate[0]}' >= start_time\n AND '{$currentDate[0]}' <= end_time\n AND INSTR(days_of_week, '{$currentDate[1]}') != 0\n AND farm_roleid = '{$dbFarmRole->ID}'\n LIMIT 1\n ");
if ($scaling_period) {
$this->logger->info("TimeScalingAlgo({$dbFarmRole->FarmID}, {$dbFarmRole->ID}) Found scaling period. Total {$scaling_period['instances_count']} instances should be running.");
$this->instancesNumber = $scaling_period['instances_count'];
$this->lastValue = "(" . implode(' / ', $currentDate) . ") {$scaling_period['start_time']} - {$scaling_period['end_time']} = {$scaling_period['instances_count']}";
if ($dbFarmRole->GetRunningInstancesCount() + $dbFarmRole->GetPendingInstancesCount() < $this->instancesNumber) {
return Scalr_Scaling_Decision::UPSCALE;
} elseif ($dbFarmRole->GetRunningInstancesCount() + $dbFarmRole->GetPendingInstancesCount() > $this->instancesNumber) {
return Scalr_Scaling_Decision::DOWNSCALE;
} else {
return Scalr_Scaling_Decision::NOOP;
}
} else {
if ($dbFarmRole->GetRunningInstancesCount() > $dbFarmRole->GetSetting(Entity\FarmRoleSetting::SCALING_MIN_INSTANCES)) {
$this->lastValue = "No period defined. Using Min instances setting.";
return Scalr_Scaling_Decision::DOWNSCALE;
} else {
return Scalr_Scaling_Decision::NOOP;
}
}
}
示例9: getValue
public function getValue(DBFarmRole $dbFarmRole, Scalr_Scaling_FarmRoleMetric $farmRoleMetric)
{
$curTime = time();
$newData = [];
$servers = $dbFarmRole->GetServersByFilter(['status' => SERVER_STATUS::RUNNING]);
if (!empty($farmRoleMetric->dtLastPolled)) {
$interval = $curTime - $farmRoleMetric->dtLastPolled;
if ($interval < 1) {
// The service was started less than one second ago
return false;
}
}
$mbitsPerInterface = [];
foreach ($servers as $DBServer) {
$type = $farmRoleMetric->getSetting(self::SETTING_BW_TYPE) == 'inbound' ? 'receive' : 'transmit';
$netStat = (array) $DBServer->scalarizr->system->netStat();
foreach ($netStat as $interface => $usage) {
if ($interface != 'lo' && !empty($usage)) {
$totalBytes = round($usage->{$type}->bytes);
$dataKey = $DBServer->serverId . '-' . $interface . '-' . $type;
$newData[$dataKey] = $totalBytes;
if (isset($interval)) {
if (is_array($farmRoleMetric->lastData) && array_key_exists($dataKey, $farmRoleMetric->lastData)) {
$lastTotalBytes = intval($farmRoleMetric->lastData[$dataKey]);
$usedBytes = $totalBytes - $lastTotalBytes;
if ($usedBytes > 0) {
$usedMBits = $usedBytes * 8 / 1024 / 1024 / $interval;
array_push($mbitsPerInterface, round($usedMBits, 2));
} else {
// The last value is considered to be incorrect as the server has been restarted
$missStep = true;
}
} else {
// The last value hasn't been set yet
$missStep = true;
}
}
}
}
}
$farmRoleMetric->lastData = $newData;
if (!isset($interval) || !empty($missStep)) {
// Sets the Server time to avoid differences between Database and Server time
$farmRoleMetric->dtLastPolled = $curTime;
$farmRoleMetric->save(false, ['settings', 'metric_id']);
return false;
}
return $mbitsPerInterface;
}
示例10: xListTasksAction
public function xListTasksAction()
{
$this->request->defineParams(array('sort' => array('type' => 'json', 'default' => array('property' => 'dtadded', 'direction' => 'DESC'))));
$sql = "\n SELECT\n dt.id, dma.name AS application_name, servers.index AS server_index, farms.name AS farm_name, roles.name AS role_name,\n dt.status AS status, dt.dtadded AS dtadded\n FROM dm_deployment_tasks dt\n LEFT JOIN dm_applications dma ON dt.dm_application_id = dma.id\n LEFT JOIN servers ON servers.id = dt.server_id\n LEFT JOIN farms ON servers.farm_id = farms.id\n LEFT JOIN roles ON servers.farm_roleid = roles.id\n WHERE dt.`status` != ? AND dt.env_id = ?\n ";
$args = array(Scalr_Dm_DeploymentTask::STATUS_ARCHIVED, $this->getEnvironmentId());
list($sql, $args) = $this->request->prepareFarmSqlQuery($sql, $args, 'farms');
$response = $this->buildResponseFromSql2($sql, array('id', 'application_name', 'farm_name', 'role_name', 'server_index', 'status', 'dtadded', 'dtdeployed'), array(), $args);
foreach ($response["data"] as $k => $row) {
$data = false;
try {
$deploymentTask = Scalr_Dm_DeploymentTask::init()->loadById($row['id']);
$application = $deploymentTask->getApplication();
try {
$dbServer = DBServer::LoadByID($deploymentTask->serverId);
$serverIndex = $dbServer->index;
} catch (Exception $e) {
}
$data = array('id' => $deploymentTask->id, 'application_name' => $application->name, 'application_id' => $deploymentTask->applicationId, 'server_id' => $deploymentTask->serverId, 'server_index' => $serverIndex, 'remote_path' => $deploymentTask->remotePath, 'status' => $deploymentTask->status, 'dtadded' => $deploymentTask->dtAdded ? Scalr_Util_DateTime::convertTz($deploymentTask->dtAdded) : "", 'dtdeployed' => $deploymentTask->dtDeployed ? Scalr_Util_DateTime::convertTz($deploymentTask->dtDeployed) : "Never");
try {
$dbFarmRole = DBFarmRole::LoadByID($deploymentTask->farmRoleId);
$data['farm_roleid'] = $dbFarmRole->ID;
$data['role_name'] = $dbFarmRole->GetRoleObject()->name;
$data['farm_id'] = $dbFarmRole->FarmID;
$data['farm_name'] = $dbFarmRole->GetFarmObject()->Name;
} catch (Exception $e) {
}
} catch (Exception $e) {
}
$response["data"][$k] = $data;
}
$this->response->data($response);
}
示例11: getScalingDecision
function getScalingDecision()
{
$algo = Scalr_Scaling_Algorithm::get($this->getMetric()->algorithm);
$sensor = Scalr_Scaling_Sensor::get($this->getMetric()->alias);
$dbFarmRole = DBFarmRole::LoadByID($this->farmRoleId);
if ($sensor) {
try {
$sensorValue = $sensor->getValue($dbFarmRole, $this);
} catch (Exception $e) {
$this->logger->warn(new FarmLogMessage($dbFarmRole->FarmID, sprintf("Unable to read Scaling Metric value: %s", $e->getMessage())));
return Scalr_Scaling_Decision::NOOP;
}
$this->logger->info(sprintf(_("Raw sensor value (id: %s, metric_id: %s, metric name: %s): %s"), $this->id, $this->metricId, $this->getMetric()->name, serialize($sensorValue)));
switch ($this->getMetric()->calcFunction) {
default:
$value = $sensorValue[0];
break;
case "avg":
$value = count($sensorValue) != 0 ? @array_sum($sensorValue) / count($sensorValue) : 0;
break;
case "sum":
$value = @array_sum($sensorValue);
break;
}
$this->lastValue = round($value, 5);
$this->save();
$invert = $sensor->isInvert;
} else {
$invert = false;
}
return $algo->makeDecision($dbFarmRole, $this, $invert);
}
示例12: xSaveAction
public function xSaveAction()
{
//TODO: Think about WebSockets
$this->request->defineParams(array('config' => array('type' => 'json')));
$farmRole = DBFarmRole::LoadByID($this->getParam('farmRoleId'));
$this->user->getPermissions()->validate($farmRole);
$behavior = $this->getParam('behavior');
$updateFarmRoleSettings = false;
if (!$farmRole->GetRoleObject()->hasBehavior($behavior)) {
throw new Exception("Behavior not assigned to this role");
}
$config = array();
foreach ($this->getParam('config') as $conf) {
if (!$config[$conf['configFile']]) {
$config[$conf['configFile']] = array();
}
if ($config[$conf['configFile']][$conf['key']] === null) {
$config[$conf['configFile']][$conf['key']] = $conf['value'];
} else {
throw new Exception("Variable {$conf['key']} from {$conf['configFile']} already defined. Please remove second definition");
}
}
// Update master
if ($this->getParam('masterServerId')) {
$dbServer = DBServer::LoadByID($this->getParam('masterServerId'));
$this->user->getPermissions()->validate($dbServer);
if ($dbServer->farmRoleId != $farmRole->ID) {
throw new Exception("Server not found");
}
if ($dbServer->status != SERVER_STATUS::RUNNING) {
throw new Exception("Master server is not running. Config cannot be applied.");
}
$this->setConfig($dbServer, $behavior, $config);
$servers = 0;
$savedServers = 1;
$updateFarmRoleSettings = true;
foreach ($farmRole->GetServersByFilter(array('status' => array(SERVER_STATUS::RUNNING, SERVER_STATUS::INIT))) as $server) {
$servers++;
try {
if ($server->serverId == $dbServer->serverId) {
continue;
}
$this->setConfig($server, $behavior, $config);
$savedServers++;
} catch (Exception $e) {
$warn[] = sprintf("Cannot update configuration on %s (%s): %s", $server->serverId, $server->remoteIp, $e->getMessage());
}
}
} else {
$updateFarmRoleSettings = true;
}
if ($updateFarmRoleSettings) {
$farmRole->SetServiceConfiguration($behavior, $config);
}
if (!$warn) {
$this->response->success(sprintf("Config successfully applied on %s of %s servers", $savedServers, $servers));
} else {
$this->response->warning(sprintf("Config was applied on %s of %s servers: %s", $savedServers, $servers, implode("\n", $warn)));
}
}
示例13: xListTasksAction
public function xListTasksAction()
{
$this->request->defineParams(array('sort' => array('type' => 'json', 'default' => array('property' => 'dtadded', 'direction' => 'DESC'))));
$sql = "SELECT id FROM dm_deployment_tasks WHERE status !='" . Scalr_Dm_DeploymentTask::STATUS_ARCHIVED . "' AND env_id = '{$this->getEnvironmentId()}'";
$response = $this->buildResponseFromSql($sql, array("id"));
foreach ($response["data"] as $k => $row) {
$data = false;
try {
$deploymentTask = Scalr_Dm_DeploymentTask::init()->loadById($row['id']);
$application = $deploymentTask->getApplication();
try {
$dbServer = DBServer::LoadByID($deploymentTask->serverId);
$serverIndex = $dbServer->index;
} catch (Exception $e) {
}
$data = array('id' => $deploymentTask->id, 'application_name' => $application->name, 'application_id' => $deploymentTask->applicationId, 'server_id' => $deploymentTask->serverId, 'server_index' => $serverIndex, 'remote_path' => $deploymentTask->remotePath, 'status' => $deploymentTask->status, 'dtadded' => $deploymentTask->dtAdded ? Scalr_Util_DateTime::convertTz($deploymentTask->dtAdded) : "", 'dtdeployed' => $deploymentTask->dtDeployed ? Scalr_Util_DateTime::convertTz($deploymentTask->dtDeployed) : "Never");
try {
$dbFarmRole = DBFarmRole::LoadByID($deploymentTask->farmRoleId);
$data['farm_roleid'] = $dbFarmRole->ID;
$data['role_name'] = $dbFarmRole->GetRoleObject()->name;
$data['farm_id'] = $dbFarmRole->FarmID;
$data['farm_name'] = $dbFarmRole->GetFarmObject()->Name;
} catch (Exception $e) {
}
} catch (Exception $e) {
}
$response["data"][$k] = $data;
}
$this->response->data($response);
}
示例14: OnFarmTerminated
/**
* Release used elastic IPs if farm terminated
*
* @param FarmTerminatedEvent $event
*/
public function OnFarmTerminated(\FarmTerminatedEvent $event)
{
$this->Logger->info(sprintf(_("Keep elastic IPs: %s"), $event->KeepElasticIPs));
if ($event->KeepElasticIPs == 1) {
return;
}
$DBFarm = \DBFarm::LoadByID($this->FarmID);
$ips = $this->DB->GetAll("SELECT * FROM elastic_ips WHERE farmid=?", array($this->FarmID));
if (count($ips) > 0) {
foreach ($ips as $ip) {
try {
$DBFarmRole = \DBFarmRole::LoadByID($ip['farm_roleid']);
if (in_array($DBFarmRole->Platform, array(\SERVER_PLATFORMS::CLOUDSTACK, \SERVER_PLATFORMS::IDCF))) {
$cs = $DBFarm->GetEnvironmentObject()->cloudstack($DBFarmRole->Platform);
$cs->disassociateIpAddress($ip['allocation_id']);
$this->DB->Execute("DELETE FROM elastic_ips WHERE ipaddress=?", array($ip['ipaddress']));
}
} catch (\Exception $e) {
if (!stristr($e->getMessage(), "does not belong to you")) {
$this->Logger->error(sprintf(_("Cannot release elastic IP %s from farm %s: %s"), $ip['ipaddress'], $DBFarm->Name, $e->getMessage()));
continue;
}
}
}
}
}
示例15: getValue
public function getValue(DBFarmRole $dbFarmRole, Scalr_Scaling_FarmRoleMetric $farmRoleMetric)
{
$servers = $dbFarmRole->GetServersByFilter(array('status' => SERVER_STATUS::RUNNING));
$dbFarm = $dbFarmRole->GetFarmObject();
$roleLA = 0;
if (count($servers) == 0) {
return false;
}
$retval = array();
foreach ($servers as $DBServer) {
if ($dbFarmRole->GetSetting(DBFarmRole::SETTING_SCALING_EXCLUDE_DBMSR_MASTER) == 1) {
$isMaster = $DBServer->GetProperty(SERVER_PROPERTIES::DB_MYSQL_MASTER) == 1 || $DBServer->GetProperty(Scalr_Db_Msr::REPLICATION_MASTER) == 1;
if ($isMaster) {
continue;
}
}
try {
if ($DBServer->IsSupported('0.13.0')) {
$period = $farmRoleMetric->getSetting(self::SETTING_LA_PERIOD);
$index = 0;
if ($period == 15) {
$index = 2;
} elseif ($period == 5) {
$index = 1;
}
$la = $DBServer->scalarizr->system->loadAverage();
if ($la[$index] !== null && $la[$index] !== false) {
$la = (double) number_format($la[$index], 2);
}
} else {
$port = $DBServer->GetProperty(SERVER_PROPERTIES::SZR_SNMP_PORT);
$period = $farmRoleMetric->getSetting(self::SETTING_LA_PERIOD);
if (!$period) {
$period = '15';
}
$this->snmpClient->connect($DBServer->remoteIp, $port ? $port : 161, $dbFarm->Hash, null, null, false);
$res = $this->snmpClient->get($this->snmpOids[$period]);
$la = (double) $res;
}
$retval[] = $la;
} catch (Exception $e) {
Logger::getLogger(__CLASS__)->warn(new FarmLogMessage($DBServer->farmId, sprintf("Unable to read LoadAverage value from server %s: %s", $DBServer->remoteIp, $e->getMessage())));
}
}
return count($retval) > 0 ? $retval : false;
}