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


PHP DBFarmRole::GetFarmObject方法代码示例

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


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

示例1: __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

示例2: 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

示例3: 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

示例4: 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

示例5: makeDecision

 public function makeDecision(DBFarmRole $dbFarmRole, Scalr_Scaling_FarmRoleMetric $farmRoleMetric, $isInvert = false)
 {
     //
     // Get data from BW sensor
     //
     $dbFarm = $dbFarmRole->GetFarmObject();
     $env = $dbFarm->GetEnvironmentObject();
     $tz = $env->getPlatformConfigValue(ENVIRONMENT_SETTINGS::TIMEZONE);
     if ($tz) {
         $default_tz = @date_default_timezone_get();
         @date_default_timezone_set($tz);
     }
     $currentDate = array((int) date("Hi"), date("D"));
     if ($default_tz) {
         @date_default_timezone_set($default_tz);
     }
     $scaling_period = $this->db->GetRow("SELECT * FROM farm_role_scaling_times WHERE\r\n\t\t\t\t'{$currentDate[0]}' >= start_time AND\r\n\t\t\t\t'{$currentDate[0]}' <= end_time-10 AND\r\n\t\t\t\tINSTR(days_of_week, '{$currentDate[1]}') != 0 AND\r\n\t\t\t\tfarm_roleid = '{$dbFarmRole->ID}'\r\n\t\t\t");
     if ($scaling_period) {
         $this->logger->info("TimeScalingAlgo({$dbFarmRole->FarmID}, {$dbFarmRole->AMIID}) Found scaling period. Total {$scaling_period['instances_count']} instances should be running.");
         $num_instances = $scaling_period['instances_count'];
         //$dbFarmRole->SetSetting(self::PROPERTY_NEED_INSTANCES_IN_CURRENT_PERIOD, $num_instances);
         if ($dbFarmRole->GetRunningInstancesCount() + $dbFarmRole->GetPendingInstancesCount() < $num_instances) {
             return Scalr_Scaling_Decision::UPSCALE;
         } else {
             return Scalr_Scaling_Decision::NOOP;
         }
     } else {
         //$dbFarmRole->SetSetting(self::PROPERTY_NEED_INSTANCES_IN_CURRENT_PERIOD, "");
         if ($dbFarmRole->GetRunningInstancesCount() > $dbFarmRole->GetSetting(DBFarmRole::SETTING_SCALING_MIN_INSTANCES)) {
             return Scalr_Scaling_Decision::DOWNSCALE;
         } else {
             return Scalr_Scaling_Decision::NOOP;
         }
     }
 }
开发者ID:rakesh-mohanta,项目名称:scalr,代码行数:35,代码来源:DateTime.php

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: getDbAccessDetails

 private function getDbAccessDetails(DBFarmRole $dbFarmRole)
 {
     $retval = array('username' => 'scalr', 'password' => '', 'dns' => false);
     if ($dbFarmRole->GetRoleObject()->hasBehavior(ROLE_BEHAVIORS::POSTGRESQL)) {
         $retval['password'] = $dbFarmRole->GetSetting(Scalr_Db_Msr_Postgresql::ROOT_PASSWORD);
         $behavior = ROLE_BEHAVIORS::POSTGRESQL;
     } elseif ($dbFarmRole->GetRoleObject()->hasBehavior(ROLE_BEHAVIORS::REDIS)) {
         if ($dbFarmRole->GetSetting(Scalr_Db_Msr_Redis::USE_PASSWORD) == 1) {
             $ports = @json_decode($dbFarmRole->GetSetting(Scalr_Db_Msr_Redis::PORTS_ARRAY));
             $passwords = @json_decode($dbFarmRole->GetSetting(Scalr_Db_Msr_Redis::PASSWD_ARRAY));
             if (!$ports && !$passwords) {
                 $retval['password'] = $dbFarmRole->GetSetting(Scalr_Db_Msr_Redis::MASTER_PASSWORD);
             } else {
                 foreach ($ports as $i => $port) {
                     $retval['password'] .= "Port {$port}: {$passwords[$i]}<br>";
                 }
             }
         } else {
             $retval['password'] = '<span style="color:red;">Password authentication is disabled</span>';
         }
         $behavior = ROLE_BEHAVIORS::REDIS;
     } elseif ($dbFarmRole->GetRoleObject()->hasBehavior(ROLE_BEHAVIORS::MYSQL2)) {
         $retval['password'] = $dbFarmRole->GetSetting(Scalr_Db_Msr_Mysql2::ROOT_PASSWORD);
         $behavior = ROLE_BEHAVIORS::MYSQL2;
     } elseif ($dbFarmRole->GetRoleObject()->hasBehavior(ROLE_BEHAVIORS::PERCONA)) {
         $retval['password'] = $dbFarmRole->GetSetting(Scalr_Db_Msr_Percona::ROOT_PASSWORD);
         $behavior = ROLE_BEHAVIORS::PERCONA;
     } elseif ($dbFarmRole->GetRoleObject()->hasBehavior(ROLE_BEHAVIORS::MARIADB)) {
         $retval['password'] = $dbFarmRole->GetSetting(Scalr_Db_Msr_Mariadb::ROOT_PASSWORD);
         $behavior = ROLE_BEHAVIORS::MARIADB;
     }
     if (\Scalr::config('scalr.dns.static.enabled')) {
         $retval['dns'] = array('master' => array('private' => "int.master.{$behavior}.{$dbFarmRole->GetFarmObject()->Hash}." . \Scalr::config('scalr.dns.static.domain_name'), 'public' => "ext.master.{$behavior}.{$dbFarmRole->GetFarmObject()->Hash}." . \Scalr::config('scalr.dns.static.domain_name')), 'slave' => array('private' => "int.slave.{$behavior}.{$dbFarmRole->GetFarmObject()->Hash}." . \Scalr::config('scalr.dns.static.domain_name'), 'public' => "ext.slave.{$behavior}.{$dbFarmRole->GetFarmObject()->Hash}." . \Scalr::config('scalr.dns.static.domain_name')));
     }
     return $retval;
 }
开发者ID:sacredwebsite,项目名称:scalr,代码行数:36,代码来源:Manager.php

示例11: 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

示例12: farmUpdateRoleSettings

 public static function farmUpdateRoleSettings(DBFarmRole $DBFarmRole, $oldSettings, $newSettings)
 {
     $db = \Scalr::getDb();
     if (!$newSettings[DBFarmRole::SETTING_AWS_USE_EBS] && $oldSettings[DBFarmRole::SETTING_AWS_USE_EBS]) {
         $db->Execute("DELETE FROM ec2_ebs WHERE farm_roleid = ? AND ismanual='0'", array($DBFarmRole->ID));
         //TODO: Remove Volume?
     }
     $DBFarm = $DBFarmRole->GetFarmObject();
     if ($newSettings[DBFarmRole::SETTING_AWS_USE_EBS] && !$oldSettings[DBFarmRole::SETTING_AWS_USE_EBS]) {
         $servers = $DBFarmRole->GetServersByFilter(array('status' => array(SERVER_STATUS::INIT, SERVER_STATUS::RUNNING)));
         foreach ($servers as $DBServer) {
             if (!$db->GetRow("SELECT id FROM ec2_ebs WHERE server_id=? AND ismanual='0' LIMIT 1", array($DBServer->serverId))) {
                 if (in_array($DBFarmRole->GetSetting(DBFarmRole::SETTING_AWS_EBS_TYPE), array('standard', 'io1'))) {
                     $type = $DBFarmRole->GetSetting(DBFarmRole::SETTING_AWS_EBS_TYPE);
                 } else {
                     $type = 'standard';
                 }
                 $DBEBSVolume = new DBEBSVolume();
                 $DBEBSVolume->attachmentStatus = EC2_EBS_ATTACH_STATUS::CREATING;
                 $DBEBSVolume->isManual = false;
                 $DBEBSVolume->ec2AvailZone = $DBFarmRole->GetSetting(DBFarmRole::SETTING_AWS_AVAIL_ZONE);
                 $DBEBSVolume->ec2Region = $DBFarmRole->CloudLocation;
                 $DBEBSVolume->farmId = $DBFarmRole->FarmID;
                 $DBEBSVolume->farmRoleId = $DBFarmRole->ID;
                 $DBEBSVolume->serverId = $DBServer->serverId;
                 $DBEBSVolume->serverIndex = $DBServer->index;
                 $DBEBSVolume->type = $type;
                 $DBEBSVolume->iops = $DBFarmRole->GetSetting(DBFarmRole::SETTING_AWS_EBS_IOPS);
                 $DBEBSVolume->size = $DBFarmRole->GetSetting(DBFarmRole::SETTING_AWS_EBS_SIZE);
                 $DBEBSVolume->snapId = $DBFarmRole->GetSetting(DBFarmRole::SETTING_AWS_EBS_SNAPID);
                 $DBEBSVolume->mount = $DBFarmRole->GetSetting(DBFarmRole::SETTING_AWS_EBS_MOUNT);
                 $DBEBSVolume->mountPoint = $DBFarmRole->GetSetting(DBFarmRole::SETTING_AWS_EBS_MOUNTPOINT);
                 $DBEBSVolume->mountStatus = $DBFarmRole->GetSetting(DBFarmRole::SETTING_AWS_EBS_MOUNT) ? EC2_EBS_MOUNT_STATUS::AWAITING_ATTACHMENT : EC2_EBS_MOUNT_STATUS::NOT_MOUNTED;
                 $DBEBSVolume->clientId = $DBFarm->ClientID;
                 $DBEBSVolume->envId = $DBFarm->EnvID;
                 $DBEBSVolume->Save();
             }
         }
         if ($newSettings[DBFarmRole::SETTING_AWS_EBS_MOUNTPOINT] != $oldSettings[DBFarmRole::SETTING_AWS_EBS_MOUNTPOINT]) {
             $db->Execute("UPDATE ec2_ebs SET mountpoint=? WHERE farm_roleid=? AND ismanual='0'", array($DBFarmRole->GetSetting(DBFarmRole::SETTING_AWS_EBS_MOUNTPOINT), $DBFarmRole->ID));
         }
     }
 }
开发者ID:recipe,项目名称:scalr,代码行数:43,代码来源:Ebs.php

示例13: farmUpdateRoleSettings

 public static function farmUpdateRoleSettings(DBFarmRole $DBFarmRole, $oldSettings, $newSettings)
 {
     $db = Core::GetDBInstance();
     $DBFarm = $DBFarmRole->GetFarmObject();
     if (!$oldSettings[DBFarmRole::SETTING_AWS_USE_ELASIC_IPS] && $newSettings[DBFarmRole::SETTING_AWS_USE_ELASIC_IPS]) {
         $servers = $DBFarmRole->GetServersByFilter(array('status' => SERVER_STATUS::RUNNING));
         if (count($servers) == 0) {
             return;
         }
         $AmazonEC2Client = Scalr_Service_Cloud_Aws::newEc2($DBFarmRole->CloudLocation, $DBFarm->GetEnvironmentObject()->getPlatformConfigValue(Modules_Platforms_Ec2::PRIVATE_KEY), $DBFarm->GetEnvironmentObject()->getPlatformConfigValue(Modules_Platforms_Ec2::CERTIFICATE));
         foreach ($servers as $DBServer) {
             $address = $AmazonEC2Client->AllocateAddress();
             $db->Execute("INSERT INTO elastic_ips SET env_id=?, farmid=?, farm_roleid=?, ipaddress=?, state='0', instance_id='', clientid=?, instance_index=?", array($DBServer->envId, $DBServer->farmId, $DBServer->farmRoleId, $address->publicIp, $DBServer->clientId, $DBServer->index));
             Logger::getLogger(__CLASS__)->info(sprintf(_("Allocated new IP: %s"), $address->publicIp));
             // Waiting...
             Logger::getLogger(__CLASS__)->debug(_("Waiting 5 seconds..."));
             sleep(5);
             $assign_retries = 1;
             while (true) {
                 try {
                     // Associate elastic ip address with instance
                     $AmazonEC2Client->AssociateAddress($DBServer->GetProperty(EC2_SERVER_PROPERTIES::INSTANCE_ID), $address->publicIp);
                 } catch (Exception $e) {
                     if (!stristr($e->getMessage(), "does not belong to you") || $assign_retries == 3) {
                         throw new Exception($e->getMessage());
                     } else {
                         // Waiting...
                         Logger::getLogger(__CLASS__)->debug(_("Waiting 2 seconds..."));
                         sleep(2);
                         $assign_retries++;
                         continue;
                     }
                 }
                 break;
             }
             Logger::getLogger(__CLASS__)->info(sprintf(_("IP: %s assigned to instance '%s'"), $address->publicIp, $DBServer->serverId));
             // Update leastic IPs table
             $db->Execute("UPDATE elastic_ips SET state='1', server_id=? WHERE ipaddress=?", array($DBServer->serverId, $address->publicIp));
             Scalr::FireEvent($DBFarmRole->FarmID, new IPAddressChangedEvent($DBServer, $address->publicIp));
         }
     }
 }
开发者ID:rakesh-mohanta,项目名称:scalr,代码行数:42,代码来源:Eip.php

示例14: __construct

 /**
  * 
  * @param string $platform (From SERVER_PLATFORMS class)
  * @param integer $farmid
  * @param integer $farm_roleid
  * @param integer $index
  * @return void
  */
 public function __construct($platform, DBFarmRole $DBFarmRole, $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) {
         switch ($this->platform) {
             case SERVER_PLATFORMS::NIMBULA:
                 break;
             case SERVER_PLATFORMS::EUCALYPTUS:
                 $this->SetProperties(array(EUCA_SERVER_PROPERTIES::REGION => $DBFarmRole->CloudLocation));
                 break;
             case SERVER_PLATFORMS::OPENSTACK:
                 $this->SetProperties(array(OPENSTACK_SERVER_PROPERTIES::CLOUD_LOCATION => $DBFarmRole->CloudLocation));
                 break;
             case SERVER_PLATFORMS::RACKSPACE:
                 $this->SetProperties(array(RACKSPACE_SERVER_PROPERTIES::DATACENTER => $DBFarmRole->CloudLocation));
                 break;
             case SERVER_PLATFORMS::CLOUDSTACK:
                 $this->SetProperties(array(CLOUDSTACK_SERVER_PROPERTIES::CLOUD_LOCATION => $DBFarmRole->CloudLocation));
                 break;
             case SERVER_PLATFORMS::EC2:
                 $this->SetProperties(array(EC2_SERVER_PROPERTIES::AVAIL_ZONE => $DBFarmRole->GetSetting(DBFarmRole::SETTING_AWS_AVAIL_ZONE), EC2_SERVER_PROPERTIES::REGION => $DBFarmRole->CloudLocation));
                 break;
             case SERVER_PLATFORMS::RDS:
                 $this->SetProperties(array(RDS_SERVER_PROPERTIES::AVAIL_ZONE => $DBFarmRole->GetSetting(DBFarmRole::SETTING_RDS_AVAIL_ZONE), RDS_SERVER_PROPERTIES::REGION => $DBFarmRole->CloudLocation, RDS_SERVER_PROPERTIES::INSTANCE_CLASS => $DBFarmRole->GetSetting(DBFarmRole::SETTING_RDS_INSTANCE_CLASS), RDS_SERVER_PROPERTIES::STORAGE => $DBFarmRole->GetSetting(DBFarmRole::SETTING_RDS_STORAGE), RDS_SERVER_PROPERTIES::INSTANCE_ENGINE => $DBFarmRole->GetSetting(DBFarmRole::SETTING_RDS_INSTANCE_ENGINE), RDS_SERVER_PROPERTIES::MASTER_USER => $DBFarmRole->GetSetting(DBFarmRole::SETTING_RDS_MASTER_USER), RDS_SERVER_PROPERTIES::MASTER_PASS => $DBFarmRole->GetSetting(DBFarmRole::SETTING_RDS_MASTER_PASS), RDS_SERVER_PROPERTIES::MULTI_AZ => $DBFarmRole->GetSetting(DBFarmRole::SETTING_RDS_MULTI_AZ), RDS_SERVER_PROPERTIES::PORT => $DBFarmRole->GetSetting(DBFarmRole::SETTING_RDS_PORT)));
                 break;
         }
         $this->SetProperties(array(SERVER_PROPERTIES::SZR_VESION => $DBFarmRole->GetRoleObject()->szrVersion));
     } else {
         $this->SetProperties(array(SERVER_PROPERTIES::SZR_VESION => '0.5.0'));
     }
 }
开发者ID:rakesh-mohanta,项目名称:scalr,代码行数:50,代码来源:class.ServerCreateInfo.php

示例15: 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 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;
             }
         }
         if ($DBServer->IsSupported('0.13.0')) {
             $szrClient = Scalr_Net_Scalarizr_Client::getClient($DBServer, Scalr_Net_Scalarizr_Client::NAMESPACE_SYSTEM, $DBServer->getPort(DBServer::PORT_API));
             $ramUsage = $szrClient->memInfo();
             $ram = (double) $ramUsage->total_free;
             if ($farmRoleMetric->getSetting(self::SETTING_USE_CACHED)) {
                 $ram = $ram + (double) $ramUsage->cached;
             }
         } else {
             $port = $DBServer->GetProperty(SERVER_PROPERTIES::SZR_SNMP_PORT);
             $this->snmpClient->connect($DBServer->remoteIp, $port ? $port : 161, $dbFarm->Hash, null, null, false);
             $res = $this->snmpClient->get($this->snmpOids['memswap']);
             preg_match_all("/[0-9]+/si", $res, $matches);
             $ram = (double) $matches[0][0];
             if ($farmRoleMetric->getSetting(self::SETTING_USE_CACHED)) {
                 $res = $this->snmpClient->get($this->snmpOids['cachedram']);
                 preg_match_all("/[0-9]+/si", $res, $matches);
                 $cram = (double) $matches[0][0];
                 $ram = $ram + $cram;
             }
         }
         $retval[] = round($ram / 1024, 2);
     }
     return $retval;
 }
开发者ID:recipe,项目名称:scalr,代码行数:39,代码来源:FreeRam.php


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