本文整理汇总了PHP中DBFarm::LoadByID方法的典型用法代码示例。如果您正苦于以下问题:PHP DBFarm::LoadByID方法的具体用法?PHP DBFarm::LoadByID怎么用?PHP DBFarm::LoadByID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBFarm
的用法示例。
在下文中一共展示了DBFarm::LoadByID方法的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: 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
}
}
示例3: 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) {
}
}
示例4: 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;
}
}
}
}
}
示例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: 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();
}
示例7: 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);
}
}
}
示例8: 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');
}
}
示例9: 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;
}
示例10: 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;
}
示例11: __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::getContainer()->srzcrypto($this->dbServer->GetKey(true));
}
示例12: 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) {
}
}
示例13: __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();
}
示例14: OnHostInit
/**
* Upload S3cmd config file, AWS private key and certificate to instance aftre instance boot.
* Also execute hostInit hooks from hooks/hostInit folder
*
* @param array $instanceinfo
* @param string $local_ip
* @param string $remote_ip
* @param string $public_key
*/
public function OnHostInit(HostInitEvent $event)
{
if ($event->DBServer->IsSupported("0.5")) {
$this->Logger->info("Scalarizr instance. Skipping SSH observer...");
return true;
}
if ($event->DBServer->platform != SERVER_PLATFORMS::EC2) {
return true;
}
// Get farm info and client info from database;
$DBFarm = DBFarm::LoadByID($this->FarmID);
$DBRole = DBRole::loadById($event->DBServer->roleId);
// Get Role info
$ssh_port = $DBRole->getProperty(DBRole::PROPERTY_SSH_PORT) ? $DBRole->getProperty(DBRole::PROPERTY_SSH_PORT) : 22;
// Generate s3cmd config file
$s3cfg = CONFIG::$S3CFG_TEMPLATE;
$s3cfg = str_replace("[access_key]", $DBFarm->GetEnvironmentObject()->getPlatformConfigValue(Modules_Platforms_Ec2::ACCESS_KEY), $s3cfg);
$s3cfg = str_replace("[secret_key]", $DBFarm->GetEnvironmentObject()->getPlatformConfigValue(Modules_Platforms_Ec2::SECRET_KEY), $s3cfg);
$s3cfg = str_replace("\r\n", "\n", $s3cfg);
// Prepare public key for SSH connection
$pub_key_file = tempnam("/tmp", "AWSK");
$res = file_put_contents($pub_key_file, $event->PublicKey);
$this->Logger->debug("Creating temporary file for public key: {$res}");
try {
$key = Scalr_Model::init(Scalr_Model::SSH_KEY)->loadGlobalByFarmId($event->DBServer->farmId, $event->DBServer->GetFarmRoleObject()->CloudLocation);
if (!$key) {
throw new Exception(_("There is no SSH key for server: {$event->DBServer->serverId}"));
}
} catch (Exception $e) {
throw new Exception("Cannot init SshKey object: {$e->getMessage()}");
}
// Prepare private key for SSH connection
$priv_key_file = tempnam("/tmp", "AWSK");
$res = file_put_contents($priv_key_file, $key->getPrivate());
$this->Logger->debug("Creating temporary file for private key: {$res}");
// Connect to SSH
$SSH2 = new Scalr_Net_Ssh2_Client();
$SSH2->addPubkey("root", $pub_key_file, $priv_key_file);
if ($SSH2->connect($event->ExternalIP, $ssh_port)) {
// Upload keys and s3 config to instance
$res = $SSH2->sendFile("/etc/aws/keys/pk.pem", $DBFarm->GetEnvironmentObject()->getPlatformConfigValue(Modules_Platforms_Ec2::PRIVATE_KEY), "w+", false);
$res2 = $SSH2->sendFile("/etc/aws/keys/cert.pem", $DBFarm->GetEnvironmentObject()->getPlatformConfigValue(Modules_Platforms_Ec2::CERTIFICATE), "w+", false);
$res3 = $SSH2->sendFile("/etc/aws/keys/s3cmd.cfg", $s3cfg, "w+", false);
// remove temporary files
@unlink($pub_key_file);
@unlink($priv_key_file);
} else {
// remove temporary files
@unlink($pub_key_file);
@unlink($priv_key_file);
Logger::getLogger(LOG_CATEGORY::FARM)->warn(new FarmLogMessage($this->FarmID, "Cannot upload ec2 keys to '{$event->DBServer->serverId}' instance. Failed to connect to SSH '{$event->ExternalIP}:{$ssh_port}'"));
throw new Exception("Cannot upload keys on '{$event->DBServer->serverId}'. Failed to connect to '{$event->ExternalIP}:{$ssh_port}'.");
}
}
示例15: getContent
public function getContent($params = array())
{
$this->request->restrictAccess(Acl::RESOURCE_FARMS_STATISTICS);
$STATS_URL = 'http://monitoring.scalr.net';
if (!empty($params['farmid'])) {
$dbFarm = DBFarm::LoadByID($params['farmid']);
$this->user->getPermissions()->validate($dbFarm);
}
$content = @file_get_contents("{$STATS_URL}/server/statistics.php?" . http_build_query(array('version' => 2, 'task' => 'get_stats_image_url', 'farmid' => $params['farmid'], 'watchername' => $params['watchername'], 'graph_type' => $params['graph_type'], 'role' => $params['role'])));
return json_decode($content);
}