本文整理汇总了PHP中DBFarmRole::GetSetting方法的典型用法代码示例。如果您正苦于以下问题:PHP DBFarmRole::GetSetting方法的具体用法?PHP DBFarmRole::GetSetting怎么用?PHP DBFarmRole::GetSetting使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBFarmRole
的用法示例。
在下文中一共展示了DBFarmRole::GetSetting方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
}
}
示例2: 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;
}
示例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(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;
}
示例4: 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;
}
}
}
示例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;
}
}
}
示例6: 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));
}
}
}
示例7: createDataBundle
public function createDataBundle(DBFarmRole $dbFarmRole, array $params = array())
{
if (!$params['dataBundleType']) {
$params['dataBundleType'] = 'full';
}
if ($params['compressor'] === null) {
$params['compressor'] = 'gzip';
}
//$params['useSlave']
if ($dbFarmRole->GetSetting(Scalr_Db_Msr::DATA_BUNDLE_IS_RUNNING) == 1) {
throw new Exception("Data bundle already in progress");
}
$currentServer = $this->getServerForDataBundle($dbFarmRole, $params['useSlave']);
if (!$currentServer) {
throw new Exception("No suitable server for data bundle");
}
$message = new Scalr_Messaging_Msg_DbMsr_CreateDataBundle();
$storageType = $dbFarmRole->GetSetting(Scalr_Db_Msr::DATA_STORAGE_ENGINE);
$storageGeneration = $storageType == 'lvm' ? 2 : 1;
if ($dbFarmRole->isOpenstack()) {
$driver = 'swift';
} else {
switch ($dbFarmRole->Platform) {
case SERVER_PLATFORMS::EC2:
$driver = 's3';
break;
case SERVER_PLATFORMS::GCE:
$driver = 'gcs';
break;
}
}
if ($storageGeneration == 2) {
$behavior = $dbFarmRole->GetRoleObject()->getDbMsrBehavior();
if (!isset($message->{$behavior})) {
$message->{$behavior} = new stdClass();
}
$message->{$behavior}->backup = new stdClass();
$message->{$behavior}->backup->type = 'xtrabackup';
$message->{$behavior}->backup->compressor = $params['compressor'];
$message->{$behavior}->backup->backupType = $params['dataBundleType'];
$message->{$behavior}->backup->cloudfsTarget = sprintf("%s://scalr-%s-%s-%s/data-bundles/%s/%s/", $driver, SCALR_ID, $dbFarmRole->GetFarmObject()->EnvID, $dbFarmRole->CloudLocation, $dbFarmRole->FarmID, $behavior);
if ($params['dataBundleType'] == 'incremental') {
$previousManifest = $this->db->GetOne("SELECT manifest FROM storage_restore_configs WHERE farm_roleid = ? ORDER BY id DESC LIMIT 1", array($dbFarmRole->ID));
$message->{$behavior}->backup->prevCloudfsSource = $previousManifest;
}
}
$message->storageType = $storageType;
$currentServer->SendMessage($message);
$dbFarmRole->SetSetting(Scalr_Db_Msr::getConstant("DATA_BUNDLE_IS_RUNNING"), 1, DBFarmRole::TYPE_LCL);
$dbFarmRole->SetSetting(Scalr_Db_Msr::getConstant("DATA_BUNDLE_RUNNING_TS"), time(), DBFarmRole::TYPE_LCL);
$dbFarmRole->SetSetting(Scalr_Db_Msr::getConstant("DATA_BUNDLE_SERVER_ID"), $currentServer->serverId, DBFarmRole::TYPE_LCL);
}
示例8: getPmaDetails
private function getPmaDetails(DBFarmRole $dbFarmRole)
{
$retval = array('configured' => false);
if ($dbFarmRole->GetSetting(DBFarmRole::SETTING_MYSQL_PMA_USER)) {
$retval['configured'] = true;
} else {
$errmsg = $dbFarmRole->GetSetting(DBFarmRole::SETTING_MYSQL_PMA_REQUEST_ERROR);
if (!$errmsg) {
$time = $dbFarmRole->GetSetting(DBFarmRole::SETTING_MYSQL_PMA_REQUEST_TIME);
if ($time) {
if ($time + 3600 < time()) {
$retval['accessError'] = _("Scalr didn't receive auth info from MySQL instance. Please check that MySQL running and Scalr has access to it.");
} else {
$retval['accessSetupInProgress'] = true;
}
}
} else {
$retval['accessError'] = $errmsg;
}
}
return $retval;
}
示例9: 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(DBFarmRole::SETTING_SCALING_MAX_INSTANCES)) {
$retval = Scalr_Scaling_Decision::NOOP;
}
}
if ($retval == Scalr_Scaling_Decision::DOWNSCALE) {
if ($dbFarmRole->GetRunningInstancesCount() <= $dbFarmRole->GetSetting(DBFarmRole::SETTING_SCALING_MIN_INSTANCES)) {
$retval = Scalr_Scaling_Decision::NOOP;
}
}
$isSzr = $dbFarmRole->GetRoleObject()->isSupported("0.5");
if ($retval == Scalr_Scaling_Decision::UPSCALE && ($dbFarmRole->GetPendingInstancesCount() > 5 && !$isSzr)) {
return Scalr_Scaling_Decision::NOOP;
} else {
//if ($isSzr && $dbFarmRole->GetPendingInstancesCount() > 10)
//return Scalr_Scaling_Decision::NOOP;
//else
return $retval;
}
}
}
示例10: onFarmSave
public function onFarmSave(DBFarm $dbFarm, DBFarmRole $dbFarmRole)
{
$vpcId = $dbFarm->GetSetting(Entity\FarmSetting::EC2_VPC_ID);
if (!$vpcId) {
//REMOVE VPC RELATED SETTINGS
return;
}
if ($dbFarmRole->GetSetting(self::ROLE_VPC_ROUTER_CONFIGURED) == 1) {
// ALL OBJECTS ALREADY CONFIGURED
return true;
}
$aws = $dbFarm->GetEnvironmentObject()->aws($dbFarmRole->CloudLocation);
$niId = $dbFarmRole->GetSetting(self::ROLE_VPC_NID);
// If there is no public IP allocate it and associate with NI
$publicIp = $dbFarmRole->GetSetting(self::ROLE_VPC_IP);
if ($niId && !$publicIp) {
$filter = array(array('name' => AddressFilterNameType::networkInterfaceId(), 'value' => $niId));
$addresses = $aws->ec2->address->describe(null, null, $filter);
$address = $addresses->get(0);
$associate = false;
if (!$address) {
$address = $aws->ec2->address->allocate('vpc');
$associate = true;
}
$publicIp = $address->publicIp;
if ($associate) {
$associateAddressRequestData = new AssociateAddressRequestData();
$associateAddressRequestData->networkInterfaceId = $niId;
$associateAddressRequestData->allocationId = $address->allocationId;
$associateAddressRequestData->allowReassociation = true;
//Associate PublicIP with NetworkInterface
$aws->ec2->address->associate($associateAddressRequestData);
}
$dbFarmRole->SetSetting(self::ROLE_VPC_IP, $publicIp, Entity\FarmRoleSetting::TYPE_LCL);
$dbFarmRole->SetSetting(self::ROLE_VPC_AID, $address->allocationId, Entity\FarmRoleSetting::TYPE_LCL);
}
$dbFarmRole->SetSetting(self::ROLE_VPC_ROUTER_CONFIGURED, 1, Entity\FarmRoleSetting::TYPE_LCL);
}
示例11: __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'));
}
}
示例12: onFarmSave
public function onFarmSave(DBFarm $dbFarm, DBFarmRole $dbFarmRole)
{
try {
$account = Scalr_Account::init()->loadById($dbFarm->ClientID);
if (!$account->isFeatureEnabled(Scalr_Limits::FEATURE_CHEF)) {
$dbFarmRole->ClearSettings("chef.");
return false;
}
$db = Core::GetDBInstance();
$runListId = $dbFarmRole->GetSetting(self::ROLE_CHEF_RUNLIST_ID);
$attributes = $dbFarmRole->GetSetting(self::ROLE_CHEF_ATTRIBUTES);
$checksum = $dbFarmRole->GetSetting(self::ROLE_CHEF_CHECKSUM);
$chefRoleName = $dbFarmRole->GetSetting(self::ROLE_CHEF_ROLE_NAME);
$chefServerId = $dbFarmRole->GetSetting(self::ROLE_CHEF_SERVER_ID);
// Need to remove chef role if chef was disabled for current farmrole
if (!$runListId && $chefRoleName) {
$this->removeChefRole($chefServerId, $chefRoleName);
$dbFarmRole->ClearSettings("chef.");
return true;
}
if ($runListId) {
$runListInfo = $this->db->GetRow("SELECT chef_server_id, runlist FROM services_chef_runlists WHERE id=?", array($runListId));
$newChefServerId = $runListInfo['chef_server_id'];
if ($newChefServerId != $chefServerId && $chefServerId) {
// Remove role from old server
$this->removeChefRole($chefServerId, $chefRoleName);
$createNew = true;
}
if (!$chefServerId) {
$createNew = true;
}
$chefServerInfo = $this->db->GetRow("SELECT * FROM services_chef_servers WHERE id=?", array($runListInfo['chef_server_id']));
$chefServerInfo['auth_key'] = $this->getCrypto()->decrypt($chefServerInfo['auth_key'], $this->cryptoKey);
$chefClient = Scalr_Service_Chef_Client::getChef($chefServerInfo['url'], $chefServerInfo['username'], trim($chefServerInfo['auth_key']));
$roleName = "scalr-{$dbFarmRole->ID}";
$setSettings = false;
if ($createNew) {
$chefClient->createRole($roleName, $roleName, json_decode($runListInfo['runlist']), json_decode($attributes), $runListInfo['chef_environment']);
$setSettings = true;
} else {
if ($dbFarmRole->GetSetting(self::ROLE_CHEF_CHECKSUM) != md5("{$runListInfo['runlist']}.{$attributes}")) {
$chefClient->updateRole($roleName, $roleName, json_decode($runListInfo['runlist']), json_decode($attributes), $runListInfo['chef_environment']);
$setSettings = true;
}
}
if ($setSettings) {
$dbFarmRole->SetSetting(self::ROLE_CHEF_ROLE_NAME, $roleName);
$dbFarmRole->SetSetting(self::ROLE_CHEF_SERVER_ID, $runListInfo['chef_server_id']);
$dbFarmRole->SetSetting(self::ROLE_CHEF_CHECKSUM, md5("{$runListInfo['runlist']}.{$attributes}"));
}
}
} catch (Exception $e) {
throw new Exception("Chef settings error: {$e->getMessage()} ({$e->getTraceAsString()})");
}
}
示例13: buildStorageSettings
protected function buildStorageSettings()
{
if ($this->dbFarmRole->GetSetting(Scalr_Db_Msr::VOLUME_ID) && $this->replicationMaster) {
try {
$volume = Scalr_Storage_Volume::init()->loadById($this->dbFarmRole->GetSetting(Scalr_Db_Msr::VOLUME_ID));
$this->volumeConfig = $volume->getConfig();
} catch (Exception $e) {
}
}
/***
* For Rackspace we ALWAYS need snapsjot_config for mysql
* ***/
if ($this->dbFarmRole->GetSetting(Scalr_Db_Msr::SNAPSHOT_ID)) {
try {
$snapshotConfig = Scalr_Model::init(Scalr_Model::STORAGE_SNAPSHOT)->loadById($this->dbFarmRole->GetSetting(Scalr_Db_Msr::SNAPSHOT_ID));
$this->snapshotConfig = $snapshotConfig->getConfig();
if ($this->snapshotConfig) {
if ($this->snapshotConfig->type == MYSQL_STORAGE_ENGINE::EPH) {
if ($this->dbFarmRole->Platform == SERVER_PLATFORMS::EC2) {
if (!isset($this->snapshotConfig->disk)) {
$this->snapshotConfig->disk = new stdClass();
}
$this->snapshotConfig->disk->device = $this->dbFarmRole->GetSetting(Scalr_Db_Msr::DATA_STORAGE_EPH_DISK);
}
}
}
} catch (Exception $e) {
$this->logger->error(new FarmLogMessage($this->dbServer->farmId, "Cannot get snaphotConfig for hostInit message: {$e->getMessage()}"));
}
}
//TODO:
/** If new role and there is no volume, we need to create a new one **/
if ($this->replicationMaster) {
if (!$this->volumeConfig) {
$this->volumeConfig = $this->getFreshVolumeConfig();
} else {
if ($this->volumeConfig->type == MYSQL_STORAGE_ENGINE::EPH) {
if ($this->dbFarmRole->Platform == SERVER_PLATFORMS::EC2 && !$this->volumeConfig->disks) {
$this->volumeConfig->disk->device = $this->dbFarmRole->GetSetting(Scalr_Db_Msr::DATA_STORAGE_EPH_DISK);
}
}
}
} else {
$this->volumeConfig = $this->getFreshVolumeConfig();
}
}
示例14: 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;
}
示例15: buildStorageSettings
protected function buildStorageSettings()
{
if ($this->dbFarmRole->GetSetting(Scalr_Db_Msr::VOLUME_ID) && $this->replicationMaster) {
try {
$volume = Scalr_Storage_Volume::init()->loadById($this->dbFarmRole->GetSetting(Scalr_Db_Msr::VOLUME_ID));
$this->volumeConfig = $volume->getConfig();
} catch (Exception $e) {
}
}
/***
* For Rackspace we ALWAYS need snapsjot_config for mysql
* ***/
if ($this->dbFarmRole->GetSetting(Scalr_Db_Msr::SNAPSHOT_ID)) {
try {
$snapshotConfig = Scalr_Model::init(Scalr_Model::STORAGE_SNAPSHOT)->loadById($this->dbFarmRole->GetSetting(Scalr_Db_Msr::SNAPSHOT_ID));
$this->snapshotConfig = $snapshotConfig->getConfig();
if ($this->snapshotConfig) {
if ($this->snapshotConfig->type == MYSQL_STORAGE_ENGINE::EPH) {
if ($this->dbFarmRole->Platform == SERVER_PLATFORMS::EC2) {
if (!isset($this->snapshotConfig->disk)) {
$this->snapshotConfig->disk = new stdClass();
}
$this->snapshotConfig->disk->device = $this->dbFarmRole->GetSetting(Scalr_Db_Msr::DATA_STORAGE_EPH_DISK);
}
}
}
} catch (Exception $e) {
$this->logger->error(new FarmLogMessage($this->dbServer->farmId, "Cannot get snaphotConfig for hostInit message: {$e->getMessage()}", !empty($this->dbServer->serverId) ? $this->dbServer->serverId : null));
}
}
if ($this->replicationMaster && $this->volumeConfig) {
$this->volumeConfig->recreateIfMissing = (int) $this->dbFarmRole->GetSetting(Scalr_Role_DbMsrBehavior::ROLE_DATA_STORAGE_RECREATE_IF_MISSING);
if ($this->volumeConfig->type == MYSQL_STORAGE_ENGINE::EPH) {
if ($this->dbFarmRole->Platform == SERVER_PLATFORMS::EC2 && !$this->volumeConfig->disks) {
$this->volumeConfig->disk->device = $this->dbFarmRole->GetSetting(Scalr_Db_Msr::DATA_STORAGE_EPH_DISK);
}
}
} else {
$this->volumeConfig = $this->getFreshVolumeConfig();
}
}