本文整理汇总了PHP中DBFarmRole类的典型用法代码示例。如果您正苦于以下问题:PHP DBFarmRole类的具体用法?PHP DBFarmRole怎么用?PHP DBFarmRole使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DBFarmRole类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:sacredwebsite,项目名称:scalr,代码行数:34,代码来源:BandWidth.php
示例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'));
}
开发者ID:scalr,项目名称:scalr,代码行数:40,代码来源:class.ServerCreateInfo.php
示例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;
}
开发者ID:mheydt,项目名称:scalr,代码行数:35,代码来源:LoadAverage.php
示例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);
}
开发者ID:mheydt,项目名称:scalr,代码行数:34,代码来源:BandWidth.php
示例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;
}
开发者ID:rakesh-mohanta,项目名称:scalr,代码行数:28,代码来源:LoadAverage.php
示例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);
}
开发者ID:rakesh-mohanta,项目名称:scalr,代码行数:12,代码来源:Sqs.php
示例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;
}
开发者ID:rakesh-mohanta,项目名称:scalr,代码行数:51,代码来源:Custom.php
示例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;
}
}
}
开发者ID:mheydt,项目名称:scalr,代码行数:31,代码来源:DateTime.php
示例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;
}
开发者ID:scalr,项目名称:scalr,代码行数:49,代码来源:BandWidth.php
示例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);
}
开发者ID:mheydt,项目名称:scalr,代码行数:32,代码来源:Tasks.php
示例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);
}
开发者ID:rakesh-mohanta,项目名称:scalr,代码行数:32,代码来源:FarmRoleMetric.php
示例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)));
}
}
开发者ID:mheydt,项目名称:scalr,代码行数:60,代码来源:Configurations.php
示例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);
}
开发者ID:rakesh-mohanta,项目名称:scalr,代码行数:30,代码来源:Tasks.php
示例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;
}
}
}
}
}
开发者ID:sacredwebsite,项目名称:scalr,代码行数:31,代码来源:CloudstackObserver.php
示例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;
}
开发者ID:sacredwebsite,项目名称:scalr,代码行数:46,代码来源:LoadAverage.php
示例16: getFarmRoleStaticIps
private function getFarmRoleStaticIps($cloudLocation, $farmRoleId)
{
$gceClient = $this->getGceClient($this->environment);
$projectId = $this->environment->getPlatformConfigValue(GoogleCEPlatformModule::PROJECT_ID);
$map = array();
if ($farmRoleId) {
$dbFarmRole = DBFarmRole::LoadByID($farmRoleId);
$this->user->getPermissions()->validate($dbFarmRole);
$maxInstances = $dbFarmRole->GetSetting(DBFarmRole::SETTING_SCALING_MAX_INSTANCES);
for ($i = 1; $i <= $maxInstances; $i++) {
$map[] = array('serverIndex' => $i);
}
$servers = $dbFarmRole->GetServersByFilter();
for ($i = 0; $i < count($servers); $i++) {
if ($servers[$i]->status != SERVER_STATUS::TERMINATED && $servers[$i]->status != SERVER_STATUS::TROUBLESHOOTING && $servers[$i]->index) {
$map[$servers[$i]->index - 1]['serverIndex'] = $servers[$i]->index;
$map[$servers[$i]->index - 1]['serverId'] = $servers[$i]->serverId;
$map[$servers[$i]->index - 1]['remoteIp'] = $servers[$i]->remoteIp;
$map[$servers[$i]->index - 1]['instanceId'] = $servers[$i]->GetProperty(GCE_SERVER_PROPERTIES::SERVER_NAME);
}
}
$ips = $this->db->GetAll('SELECT ipaddress, instance_index FROM elastic_ips WHERE farm_roleid = ?', array($dbFarmRole->ID));
for ($i = 0; $i < count($ips); $i++) {
$map[$ips[$i]['instance_index'] - 1]['elasticIp'] = $ips[$i]['ipaddress'];
}
}
$response = $gceClient->addresses->listAddresses($projectId, $cloudLocation);
$ips = array();
/* @var $ip \Google_Service_Compute_Address */
foreach ($response as $ip) {
var_dump($ip);
$itm = array('ipAddress' => $ip->address);
$info = $this->db->GetRow("\n SELECT * FROM elastic_ips WHERE ipaddress = ? LIMIT 1\n ", array($itm['ipAddress']));
if ($info) {
try {
if ($info['server_id'] && $itm['instanceId']) {
$dbServer = DBServer::LoadByID($info['server_id']);
if ($dbServer->GetProperty(EC2_SERVER_PROPERTIES::INSTANCE_ID) != $itm['instanceId']) {
for ($i = 0; $i < count($map); $i++) {
if ($map[$i]['elasticIp'] == $itm['ipAddress']) {
$map[$i]['warningInstanceIdDoesntMatch'] = true;
}
}
}
}
$farmRole = DBFarmRole::LoadByID($info['farm_roleid']);
$this->user->getPermissions()->validate($farmRole);
$itm['roleName'] = $farmRole->GetRoleObject()->name;
$itm['farmName'] = $farmRole->GetFarmObject()->Name;
$itm['serverIndex'] = $info['instance_index'];
} catch (Exception $e) {
}
}
//TODO: Mark Router EIP ad USED
$ips[] = $itm;
}
return array('map' => $map, 'ips' => $ips);
}
开发者ID:rickb838,项目名称:scalr,代码行数:58,代码来源:Gce.php
示例17: xGetFarmRoleStaticIpsAction
public function xGetFarmRoleStaticIpsAction($region, $cloudLocation, $farmRoleId)
{
$p = PlatformFactory::NewPlatform(SERVER_PLATFORMS::GCE);
$gceClient = $p->getClient($this->environment);
$projectId = $this->environment->keychain(SERVER_PLATFORMS::GCE)->properties[Entity\CloudCredentialsProperty::GCE_PROJECT_ID];
$map = [];
if ($farmRoleId) {
$dbFarmRole = DBFarmRole::LoadByID($farmRoleId);
$this->user->getPermissions()->validate($dbFarmRole);
$maxInstances = $dbFarmRole->GetSetting(Entity\FarmRoleSetting::SCALING_MAX_INSTANCES);
for ($i = 1; $i <= $maxInstances; $i++) {
$map[] = array('serverIndex' => $i);
}
$servers = $dbFarmRole->GetServersByFilter();
for ($i = 0, $c = count($servers); $i < $c; $i++) {
if ($servers[$i]->status != SERVER_STATUS::TERMINATED && $servers[$i]->index) {
$map[$servers[$i]->index - 1]['serverIndex'] = $servers[$i]->index;
$map[$servers[$i]->index - 1]['serverId'] = $servers[$i]->serverId;
$map[$servers[$i]->index - 1]['remoteIp'] = $servers[$i]->remoteIp;
$map[$servers[$i]->index - 1]['instanceId'] = $servers[$i]->GetProperty(GCE_SERVER_PROPERTIES::SERVER_NAME);
}
}
$ips = $this->db->GetAll('SELECT ipaddress, instance_index FROM elastic_ips WHERE farm_roleid = ?', array($dbFarmRole->ID));
for ($i = 0, $c = count($ips); $i < $c; $i++) {
$map[$ips[$i]['instance_index'] - 1]['elasticIp'] = $ips[$i]['ipaddress'];
}
}
$response = $gceClient->addresses->listAddresses($projectId, $region);
$ips = [];
/* @var $ip \Google_Service_Compute_Address */
foreach ($response as $ip) {
$itm = array('ipAddress' => $ip->getAddress(), 'description' => $ip->getDescription());
if ($ip->status == 'IN_USE') {
$itm['instanceId'] = substr(strrchr($ip->users[0], "/"), 1);
}
$info = $this->db->GetRow("SELECT * FROM elastic_ips WHERE ipaddress = ? LIMIT 1", [$itm['ipAddress']]);
if ($info) {
try {
if ($info['server_id'] == $itm['instanceId']) {
for ($i = 0, $c = count($map); $i < $c; $i++) {
if ($map[$i]['elasticIp'] == $itm['ipAddress']) {
$map[$i]['warningInstanceIdDoesntMatch'] = true;
}
}
}
$farmRole = DBFarmRole::LoadByID($info['farm_roleid']);
$this->user->getPermissions()->validate($farmRole);
$itm['roleName'] = $farmRole->Alias;
$itm['farmName'] = $farmRole->GetFarmObject()->Name;
$itm['serverIndex'] = $info['instance_index'];
} catch (Exception $e) {
}
}
//Invar: Mark Router EIP ad USED
$ips[] = $itm;
}
$this->response->data(['data' => ['staticIps' => ['map' => $map, 'ips' => $ips]]]);
}
开发者ID:scalr,项目名称:scalr,代码行数:58,代码来源:Gce.php
示例18: makeDecision
public function makeDecision(DBFarmRole $dbFarmRole, Scalr_Scaling_FarmRoleMetric $farmRoleMetric, $isInvert = false)
{
if ($farmRoleMetric->lastValue > $farmRoleMetric->getSetting('max')) {
$retval = Scalr_Scaling_Decision::UPSCALE;
} elseif ($farmRoleMetric->lastValue < $farmRoleMetric->getSetting('min')) {
$retval = Scalr_Scaling_Decision::DOWNSCALE;
}
if (!$retval) {
return Scalr_Scaling_Decision::NOOP;
} else {
if ($isInvert) {
if ($retval == Scalr_Scaling_Decision::UPSCALE) {
$retval = Scalr_Scaling_Decision::DOWNSCALE;
} else {
$retval = Scalr_Scaling_Decision::UPSCALE;
}
}
if ($retval == Scalr_Scaling_Decision::UPSCALE) {
if ($dbFarmRole->GetRunningInstancesCount() + $dbFarmRole->GetPendingInstancesCount() >= $dbFarmRole->GetSetting(Entity\FarmRoleSetting::SCALING_MAX_INSTANCES)) {
$retval = Scalr_Scaling_Decision::NOOP;
}
}
if ($retval == Scalr_Scaling_Decision::DOWNSCALE) {
if ($dbFarmRole->GetRunningInstancesCount() <= $dbFarmRole->GetSetting(Entity\FarmRoleSetting::SCALING_MIN_INSTANCES)) {
$retval = Scalr_Scaling_Decision::NOOP;
}
}
$isSzr = true;
if ($retval == Scalr_Scaling_Decision::UPSCALE && ($dbFarmRole->GetPendingInstancesCount() > 5 && !$isSzr)) {
return Scalr_Scaling_Decision::NOOP;
} else {
return $retval;
}
}
}
开发者ID:mheydt,项目名称:scalr,代码行数:35,代码来源:Sensor.php
示例19: ListFarmRoleParams
public function ListFarmRoleParams()
{
$farmRoleId = $this->GetArg("farm-role-id");
if (!$farmRoleId) {
throw new Exception("'farm-role-id' required");
}
$dbFarmRole = DBFarmRole::LoadByID($farmRoleId);
if ($dbFarmRole->FarmID != $this->DBServer->farmId) {
throw new Exception("You can request this information ONLY for roles within server farm");
}
$ResponseDOMDocument = $this->CreateResponse();
// Base configuration
if ($this->DBServer->farmRoleId == $farmRoleId) {
$data = Scalr_Role_Behavior::loadByName(ROLE_BEHAVIORS::BASE)->getBaseConfiguration($this->DBServer);
foreach ((array) $data as $k => $v) {
$bodyEl = $this->serialize($v, $k, $ResponseDOMDocument);
$ResponseDOMDocument->documentElement->appendChild($bodyEl);
}
}
$role = $dbFarmRole->GetRoleObject();
$behaviors = $role->getBehaviors();
foreach ($behaviors as $behavior) {
$data = null;
if ($behavior == ROLE_BEHAVIORS::MONGODB || $behavior == ROLE_BEHAVIORS::CHEF || $behavior == ROLE_BEHAVIORS::HAPROXY || $behavior == ROLE_BEHAVIORS::NGINX || $behavior == ROLE_BEHAVIORS::RABBITMQ || $behavior == ROLE_BEHAVIORS::APACHE || $behavior == ROLE_BEHAVIORS::VPC_ROUTER) {
$data = Sca
|
请发表评论