本文整理汇总了PHP中DBFarm类的典型用法代码示例。如果您正苦于以下问题:PHP DBFarm类的具体用法?PHP DBFarm怎么用?PHP DBFarm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DBFarm类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: xSaveAction
public function xSaveAction()
{
$this->request->defineParams(array('category' => array('type' => 'string'), 'name' => array('type' => 'string'), 'value' => array('type' => 'json')));
$governance = new Scalr_Governance($this->getEnvironmentId());
$category = $this->getParam('category');
$name = $this->getParam('name');
$value = $this->getParam('value');
if ($category == Scalr_Governance::CATEGORY_GENERAL && $name == Scalr_Governance::GENERAL_LEASE) {
$enabled = (bool) $value['limits']['enableDefaultLeaseDuration'];
unset($value['limits']['enableDefaultLeaseDuration']);
if (!$governance->isEnabled(Scalr_Governance::CATEGORY_GENERAL, Scalr_Governance::GENERAL_LEASE) && $value['enabled'] == 1 && $enabled) {
$dt = new DateTime();
$dt->add(new DateInterval('P' . $value['limits']['defaultLifePeriod'] . 'D'));
$farms = $this->db->GetCol('SELECT id FROM farms WHERE env_id = ? AND status = ?', array($this->getEnvironmentId(), FARM_STATUS::RUNNING));
foreach ($farms as $farmId) {
$farm = DBFarm::LoadByID($farmId);
$farm->SetSetting(DBFarm::SETTING_LEASE_STATUS, 'Active');
$farm->SetSetting(DBFarm::SETTING_LEASE_TERMINATE_DATE, $dt->format('Y-m-d H:i:s'));
$farm->SetSetting(DBFarm::SETTING_LEASE_NOTIFICATION_SEND, '');
$farm->SetSetting(DBFarm::SETTING_LEASE_EXTEND_CNT, 0);
}
}
}
$governance->setValue($category, $name, $value);
$this->response->success('Successfully saved');
}
示例2: farmSave
public static function farmSave(DBFarm $DBFarm, array $roles)
{
foreach ($roles as $DBFarmRole) {
if ($DBFarmRole->Platform != SERVER_PLATFORMS::EUCALYPTUS) {
continue;
}
$location = $DBFarmRole->CloudLocation;
$sshKey = Scalr_Model::init(Scalr_Model::SSH_KEY);
if (!$sshKey->loadGlobalByFarmId($DBFarm->ID, $location)) {
$key_name = "FARM-{$DBFarm->ID}";
$eucaClient = Scalr_Service_Cloud_Eucalyptus::newCloud($DBFarm->GetEnvironmentObject()->getPlatformConfigValue(Modules_Platforms_Eucalyptus::SECRET_KEY, true, $location), $DBFarm->GetEnvironmentObject()->getPlatformConfigValue(Modules_Platforms_Eucalyptus::ACCESS_KEY, true, $location), $DBFarm->GetEnvironmentObject()->getPlatformConfigValue(Modules_Platforms_Eucalyptus::EC2_URL, true, $location));
$result = $eucaClient->CreateKeyPair($key_name);
if ($result->keyMaterial) {
$sshKey->farmId = $DBFarm->ID;
$sshKey->clientId = $DBFarm->ClientID;
$sshKey->envId = $DBFarm->EnvID;
$sshKey->type = Scalr_SshKey::TYPE_GLOBAL;
$sshKey->cloudLocation = $location;
$sshKey->cloudKeyName = $key_name;
$sshKey->platform = SERVER_PLATFORMS::EUCALYPTUS;
$sshKey->setPrivate($result->keyMaterial);
$sshKey->save();
}
}
}
}
示例3: farmSave
public static function farmSave(\DBFarm $DBFarm, array $roles)
{
foreach ($roles as $DBFarmRole) {
if ($DBFarmRole->Platform != \SERVER_PLATFORMS::EC2) {
continue;
}
$location = $DBFarmRole->CloudLocation;
$sshKey = \Scalr_Model::init(\Scalr_Model::SSH_KEY);
if (!$sshKey->loadGlobalByFarmId($DBFarm->EnvID, $DBFarm->ID, $location, \SERVER_PLATFORMS::EC2)) {
$key_name = "FARM-" . $DBFarm->ID . "-" . SCALR_ID;
$aws = $DBFarm->GetEnvironmentObject()->aws($location);
$result = $aws->ec2->keyPair->create($key_name);
if (!empty($result->keyMaterial)) {
$sshKey->farmId = $DBFarm->ID;
$sshKey->envId = $DBFarm->EnvID;
$sshKey->type = \Scalr_SshKey::TYPE_GLOBAL;
$sshKey->cloudLocation = $location;
$sshKey->cloudKeyName = $key_name;
$sshKey->platform = \SERVER_PLATFORMS::EC2;
$sshKey->setPrivate($result->keyMaterial);
$sshKey->save();
}
}
}
}
示例4: StartThread
public function StartThread($farminfo)
{
$db = \Scalr::getDb();
$DBFarm = DBFarm::LoadByID($farminfo['id']);
foreach ($DBFarm->GetFarmRoles() as $DBFarmRole) {
foreach ($DBFarmRole->GetServersByFilter(array('status' => array(SERVER_STATUS::INIT, SERVER_STATUS::RUNNING, SERVER_STATUS::PENDING, SERVER_STATUS::TROUBLESHOOTING)), array()) as $DBServer) {
$launchTime = strtotime($DBServer->dateAdded);
$lastCheckTime = (int) $DBServer->GetProperty(SERVER_PROPERTIES::STATISTICS_LAST_CHECK_TS);
if (!$lastCheckTime) {
$lastCheckTime = $launchTime;
}
$period = round((time() - $lastCheckTime) / 60);
$maxMinutes = date("j") * 24 * 60 - date("H") * 60;
if ($period > $maxMinutes) {
$period = $maxMinutes;
}
$serverType = $DBServer->GetFlavor();
if (!$serverType) {
continue;
}
$db->Execute("INSERT INTO servers_stats SET\n `usage` = ?,\n `instance_type` = ?,\n `env_id` = ?,\n `month` = ?,\n `year` = ?,\n `farm_id` = ?,\n `cloud_location` = ?\n ON DUPLICATE KEY UPDATE `usage` = `usage` + ?\n ", array($period, $serverType, $DBServer->envId, date("m"), date("Y"), $DBServer->farmId, $DBServer->GetCloudLocation(), $period));
$DBServer->SetProperty(SERVER_PROPERTIES::STATISTICS_LAST_CHECK_TS, time());
}
//for each items
}
}
示例5: getFarmObject
/**
* Gets DBFarm object
*
* @return \DBFarm
*/
public function getFarmObject()
{
if (!$this->dbFarm && !empty($this->farmId)) {
$this->dbFarm = \DBFarm::LoadByID($this->farmId);
}
return $this->dbFarm;
}
示例6: OnHostDown
/**
* Release IP address when instance terminated
*
* @param HostDownEvent $event
*/
public function OnHostDown(HostDownEvent $event)
{
if ($event->DBServer->IsRebooting()) {
return;
}
try {
$DBFarm = DBFarm::LoadByID($this->FarmID);
if ($event->replacementDBServer) {
$ip = $this->DB->GetRow("SELECT * FROM elastic_ips WHERE server_id=?", array($event->DBServer->serverId));
if ($ip) {
$aws = $DBFarm->GetEnvironmentObject()->aws($event->DBServer->GetProperty(EC2_SERVER_PROPERTIES::REGION));
try {
// Associates elastic ip address with instance
$aws->ec2->address->associate(new AssociateAddressRequestData($event->replacementDBServer->GetProperty(EC2_SERVER_PROPERTIES::INSTANCE_ID), $ip['ipaddress']));
$this->DB->Execute("UPDATE elastic_ips SET state='1', server_id=? WHERE ipaddress=?", array($event->replacementDBServer->serverId, $ip['ipaddress']));
Scalr::FireEvent($this->FarmID, new IPAddressChangedEvent($event->replacementDBServer, $ip['ipaddress'], $event->replacementDBServer->localIp));
} catch (Exception $e) {
if (!stristr($e->getMessage(), "does not belong to you")) {
throw new Exception($e->getMessage());
}
}
}
} else {
$this->DB->Execute("UPDATE elastic_ips SET state='0', server_id='' WHERE server_id=?", array($event->DBServer->serverId));
}
} catch (Exception $e) {
}
}
示例7: run2
protected function run2($stage)
{
$farms = $this->db->Execute("SELECT farmid, value FROM farm_settings WHERE name='ec2.vpc.id' AND value != '' AND value IS NOT NULL");
while ($farm = $farms->FetchRow()) {
$dbFarm = \DBFarm::LoadByID($farm['farmid']);
$roles = $dbFarm->GetFarmRoles();
foreach ($roles as $dbFarmRole) {
$vpcSubnetId = $dbFarmRole->GetSetting(Entity\FarmRoleSetting::AWS_VPC_SUBNET_ID);
if ($vpcSubnetId && substr($vpcSubnetId, 0, 6) != 'subnet') {
$subnets = json_decode($vpcSubnetId);
$vpcSubnetId = $subnets[0];
}
if ($vpcSubnetId) {
try {
$platform = PlatformFactory::NewPlatform(\SERVER_PLATFORMS::EC2);
$info = $platform->listSubnets(\Scalr_Environment::init()->loadById($dbFarm->EnvID), $dbFarmRole->CloudLocation, $farm['value'], true, $vpcSubnetId);
if ($info && $info['type'] != 'public') {
$routerRole = $dbFarm->GetFarmRoleByBehavior(\ROLE_BEHAVIORS::VPC_ROUTER);
$dbFarmRole->SetSetting(\Scalr_Role_Behavior_Router::ROLE_VPC_SCALR_ROUTER_ID, $routerRole->ID);
$this->console->out("Updating router.scalr.farm_role_id property for Farm Role: %s", $dbFarmRole->ID);
}
} catch (\Exception $e) {
continue;
}
}
}
}
}
示例8: getBackupDetails
private function getBackupDetails($backupId)
{
$links = array();
$backup = Scalr_Db_Backup::init()->loadById($backupId);
$this->user->getPermissions()->validate($backup);
$data = array('backup_id' => $backup->id, 'farm_id' => $backup->farmId, 'type' => ROLE_BEHAVIORS::GetName($backup->service) ? ROLE_BEHAVIORS::GetName($backup->service) : 'unknown', 'date' => Scalr_Util_DateTime::convertTz($backup->dtCreated), 'size' => $backup->size ? round($backup->size / 1024 / 1024, 2) : 0, 'provider' => $backup->provider, 'cloud_location' => $backup->cloudLocation, 'farmName' => DBFarm::LoadByIDOnlyName($backup->farmId));
$downloadParts = $backup->getParts();
foreach ($downloadParts as $part) {
$part['size'] = $part['size'] ? round($part['size'] / 1024 / 1024, 2) : '';
if ($part['size'] == 0) {
$part['size'] = 0.01;
}
if ($data['provider'] == 's3') {
$part['link'] = $this->getS3SignedUrl($part['path']);
} else {
if ($data['provider'] == 'cf') {
if ($backup->platform == SERVER_PLATFORMS::RACKSPACE) {
$part['link'] = $this->getCfSignedUrl($part['path'], $data['cloud_location'], $backup->platform);
} else {
$part['link'] = "swift://{$part['path']}";
}
} else {
continue;
}
}
$part['path'] = pathinfo($part['path']);
$links[$part['number']] = $part;
}
$data['links'] = $links;
return $data;
}
示例9: xRequestResultAction
public function xRequestResultAction()
{
$this->request->defineParams(array('requests' => array('type' => 'json'), 'decision'));
if (!in_array($this->getParam('decision'), array(FarmLease::STATUS_APPROVE, FarmLease::STATUS_DECLINE))) {
throw new Scalr_Exception_Core('Wrong status');
}
foreach ($this->getParam('requests') as $id) {
$req = $this->db->GetRow('SELECT * FROM farm_lease_requests WHERE id = ? LIMIT 1', array($id));
if ($req) {
$dbFarm = DBFarm::LoadByID($req['farm_id']);
$this->user->getPermissions()->validate($dbFarm);
$this->db->Execute('UPDATE farm_lease_requests SET status = ?, answer_comment = ?, answer_user_id = ? WHERE id = ?', array($this->getParam('decision'), $this->getParam('comment'), $this->user->getId(), $id));
try {
$mailer = Scalr::getContainer()->mailer;
if ($dbFarm->ownerId) {
$user = Entity\Account\User::findPk($dbFarm->ownerId);
if (\Scalr::config('scalr.auth_mode') == 'ldap') {
$email = $user->getSetting(Entity\Account\User\UserSetting::NAME_LDAP_EMAIL);
if (!$email) {
$email = $user->email;
}
} else {
$email = $user->email;
}
$mailer->addTo($email);
} else {
$mailer = null;
}
} catch (Exception $e) {
$mailer = null;
}
if ($this->getParam('decision') == FarmLease::STATUS_APPROVE) {
if ($req['request_days'] > 0) {
$dt = $dbFarm->GetSetting(Entity\FarmSetting::LEASE_TERMINATE_DATE);
$dt = new DateTime($dt);
$dt->add(new DateInterval('P' . $req['request_days'] . 'D'));
$dbFarm->SetSetting(Entity\FarmSetting::LEASE_TERMINATE_DATE, $dt->format('Y-m-d H:i:s'));
$dbFarm->SetSetting(Entity\FarmSetting::LEASE_NOTIFICATION_SEND, null);
if ($mailer) {
$mailer->sendTemplate(SCALR_TEMPLATES_PATH . '/emails/farm_lease_non_standard_approve.eml', array('{{farm_name}}' => $dbFarm->Name, '{{user_name}}' => $this->user->getEmail(), '{{comment}}' => $this->getParam('comment'), '{{date}}' => $dt->format('M j, Y'), '{{envName}}' => $dbFarm->GetEnvironmentObject()->name, '{{envId}}' => $dbFarm->GetEnvironmentObject()->id));
}
} else {
$dbFarm->SetSetting(Entity\FarmSetting::LEASE_STATUS, '');
$dbFarm->SetSetting(Entity\FarmSetting::LEASE_TERMINATE_DATE, '');
$dbFarm->SetSetting(Entity\FarmSetting::LEASE_NOTIFICATION_SEND, '');
if ($mailer) {
$mailer->sendTemplate(SCALR_TEMPLATES_PATH . '/emails/farm_lease_non_standard_forever.eml', array('{{farm_name}}' => $dbFarm->Name, '{{user_name}}' => $this->user->getEmail(), '{{comment}}' => $this->getParam('comment'), '{{envName}}' => $dbFarm->GetEnvironmentObject()->name, '{{envId}}' => $dbFarm->GetEnvironmentObject()->id));
}
}
} else {
$dt = new DateTime($dbFarm->GetSetting(Entity\FarmSetting::LEASE_TERMINATE_DATE));
SettingEntity::increase(SettingEntity::LEASE_DECLINED_REQUEST);
if ($mailer) {
$mailer->sendTemplate(SCALR_TEMPLATES_PATH . '/emails/farm_lease_non_standard_decline.eml', array('{{farm_name}}' => $dbFarm->Name, '{{user_name}}' => $this->user->getEmail(), '{{date}}' => $dt->format('M j, Y'), '{{comment}}' => $this->getParam('comment'), '{{envName}}' => $dbFarm->GetEnvironmentObject()->name, '{{envId}}' => $dbFarm->GetEnvironmentObject()->id));
}
}
}
}
$this->response->success();
}
示例10: hasWidgetAccess
/**
* {@inheritdoc}
* @see Scalr_UI_Controller_Dashboard_Widget::hasWidgetAccess
*/
public function hasWidgetAccess($params)
{
if (!empty($params['farmId'])) {
$farm = DBFarm::LoadByID($params['farmId']);
$this->request->restrictFarmAccess($farm, Acl::PERM_FARMS_STATISTICS);
} else {
throw new Scalr_Exception_Core('Farm ID could not be empty');
}
}
示例11: OnFarmTerminated
public function OnFarmTerminated(\FarmTerminatedEvent $event)
{
$dbFarm = \DBFarm::LoadByID($this->FarmID);
foreach ($dbFarm->GetFarmRoles() as $dbFarmRole) {
foreach (\Scalr_Role_Behavior::getListForFarmRole($dbFarmRole) as $bObj) {
$bObj->onFarmTerminated($dbFarmRole);
}
}
}
示例12: getFarmObject
/**
* Gets DBFarm object
*
* @return \DBFarm
*/
public function getFarmObject()
{
try {
if (!$this->dbFarm && !empty($this->farmId)) {
$this->dbFarm = \DBFarm::LoadByID($this->farmId);
}
} catch (Exception $e) {
}
return $this->dbFarm;
}
示例13: ApacheVhostCreate
public function ApacheVhostCreate($DomainName, $FarmID, $FarmRoleID, $DocumentRootDir, $EnableSSL, $SSLPrivateKey = null, $SSLCertificate = null)
{
$this->restrictAccess(Acl::RESOURCE_SERVICES_APACHE);
$validator = new Scalr_Validator();
if ($validator->validateDomain($DomainName) !== true) {
$err[] = _("Domain name is incorrect");
}
$DBFarm = DBFarm::LoadByID($FarmID);
if ($DBFarm->EnvID != $this->Environment->id) {
throw new Exception(sprintf("Farm #%s not found", $FarmID));
}
$this->user->getPermissions()->validate($DBFarm);
$DBFarmRole = DBFarmRole::LoadByID($FarmRoleID);
if ($DBFarm->ID != $DBFarmRole->FarmID) {
throw new Exception(sprintf("FarmRole #%s not found on Farm #%s", $FarmRoleID, $FarmID));
}
if (!$DocumentRootDir) {
throw new Exception(_("DocumentRootDir required"));
}
$options = serialize(array("document_root" => trim($DocumentRootDir), "logs_dir" => "/var/log", "server_admin" => $this->user->getEmail()));
$httpConfigTemplateSSL = @file_get_contents(dirname(__FILE__) . "/../../templates/services/apache/ssl.vhost.tpl");
$httpConfigTemplate = @file_get_contents(dirname(__FILE__) . "/../../templates/services/apache/nonssl.vhost.tpl");
$vHost = Scalr_Service_Apache_Vhost::init();
$vHost->envId = (int) $this->Environment->id;
$vHost->clientId = $this->user->getAccountId();
$vHost->domainName = $DomainName;
$vHost->isSslEnabled = $EnableSSL ? true : false;
$vHost->farmId = $FarmID;
$vHost->farmRoleId = $FarmRoleID;
$vHost->httpdConf = $httpConfigTemplate;
$vHost->templateOptions = $options;
//SSL stuff
if ($vHost->isSslEnabled) {
$cert = new Scalr_Service_Ssl_Certificate();
$cert->envId = $DBFarm->EnvID;
$cert->name = $DomainName;
$cert->privateKey = base64_decode($SSLPrivateKey);
$cert->certificate = base64_decode($SSLCertificate);
$cert->save();
$vHost->sslCertId = $cert->id;
$vHost->httpdConfSsl = $httpConfigTemplateSSL;
} else {
$vHost->sslCertId = 0;
}
$vHost->save();
$servers = $DBFarm->GetServersByFilter(array('status' => array(SERVER_STATUS::INIT, SERVER_STATUS::RUNNING)));
foreach ($servers as $DBServer) {
if ($DBServer->GetFarmRoleObject()->GetRoleObject()->hasBehavior(ROLE_BEHAVIORS::NGINX) || $DBServer->GetFarmRoleObject()->GetRoleObject()->hasBehavior(ROLE_BEHAVIORS::APACHE)) {
$DBServer->SendMessage(new Scalr_Messaging_Msg_VhostReconfigure());
}
}
$response = $this->CreateInitialResponse();
$response->Result = 1;
return $response;
}
示例14: OnHostDown
/**
* Release IP address when instance terminated
*
* @param HostDownEvent $event
*/
public function OnHostDown(\HostDownEvent $event)
{
if ($event->DBServer->IsRebooting()) {
return;
}
try {
$DBFarm = \DBFarm::LoadByID($this->FarmID);
$this->DB->Execute("UPDATE elastic_ips SET state='0', server_id='' WHERE server_id=?", array($event->DBServer->serverId));
} catch (\Exception $e) {
}
}
示例15: __construct
public function __construct(DBServer $dbServer, $port = 8010)
{
$this->dbServer = $dbServer;
$this->port = $port;
if ($this->dbServer->farmId) {
if (DBFarm::LoadByID($this->dbServer->farmId)->GetSetting(DBFarm::SETTING_EC2_VPC_ID)) {
$this->isVPC = true;
}
}
$this->cryptoTool = Scalr_Messaging_CryptoTool::getInstance();
}