本文整理汇总了PHP中DBServer::GetFarmObject方法的典型用法代码示例。如果您正苦于以下问题:PHP DBServer::GetFarmObject方法的具体用法?PHP DBServer::GetFarmObject怎么用?PHP DBServer::GetFarmObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBServer
的用法示例。
在下文中一共展示了DBServer::GetFarmObject方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getConfiguration
public function getConfiguration(DBServer $dbServer)
{
$configuration = new stdClass();
$configuration->proxies = json_decode($dbServer->GetFarmRoleObject()->GetSetting(self::ROLE_PROXIES), true);
$dbFarm = $dbServer->GetFarmObject();
if (count($configuration->proxies) > 0) {
foreach ($configuration->proxies as &$proxy) {
if (count($proxy['backends']) > 0) {
foreach ($proxy['backends'] as &$backend) {
if (isset($backend['farm_role_alias']) && !empty($backend['farm_role_alias'])) {
$backend['farm_role_id'] = $dbFarm->GetFarmRoleIdByAlias($backend['farm_role_alias']);
}
}
}
}
}
return $configuration;
}
示例2: hasAccessServer
/**
* Checks whether specified server can be accessed by the user
*
* @param \DBServer $dbServer The DBServer object
* @return boolean Returns true if specified server can be accessed by the user
* @throws \Scalr_Exception_Core
*/
public function hasAccessServer(\DBServer $dbServer)
{
$access = $this->hasAccessEnvironment($dbServer->envId);
if ($access && !empty($dbServer->farmId) && ($dbFarm = $dbServer->GetFarmObject()) instanceof \DBFarm) {
$access = $this->hasAccessFarm($dbFarm);
}
return $access;
}
示例3: onPromoteToMasterResult
public static function onPromoteToMasterResult(Scalr_Messaging_Msg_DbMsr_PromoteToMasterResult $message, DBServer $dbServer)
{
$dbFarm = $dbServer->GetFarmObject();
$dbFarmRole = $dbServer->GetFarmRoleObject();
$dbFarmRole->SetSetting(Scalr_Db_Msr::SLAVE_TO_MASTER, 0);
if ($message->status == Scalr_Messaging_Msg_Mysql_PromoteToMasterResult::STATUS_FAILED) {
$dbServer->SetProperty(Scalr_Db_Msr::REPLICATION_MASTER, 0);
return false;
}
$dbSettings = $message->{$message->dbType};
//Update volumeCondig
if ($dbSettings->volumeConfig) {
try {
$storageVolume = Scalr_Storage_Volume::init();
try {
$storageVolume->loadById($dbSettings->volumeConfig->id);
$storageVolume->setConfig($dbSettings->volumeConfig);
$storageVolume->save();
} catch (Exception $e) {
if (strpos($e->getMessage(), 'not found')) {
$storageVolume->loadBy(array('id' => $dbSettings->volumeConfig->id, 'client_id' => $dbServer->clientId, 'env_id' => $dbServer->envId, 'name' => "'{$message->dbType}' data volume", 'type' => $dbFarmRole->GetSetting(Scalr_Db_Msr::DATA_STORAGE_ENGINE), 'platform' => $dbServer->platform, 'size' => $dbSettings->volumeConfig->size, 'fstype' => $dbSettings->volumeConfig->fstype, 'purpose' => $message->dbType, 'farm_roleid' => $dbFarmRole->ID, 'server_index' => $dbServer->index));
$storageVolume->setConfig($dbSettings->volumeConfig);
$storageVolume->save(true);
} else {
throw $e;
}
}
} catch (Exception $e) {
Logger::getLogger(__CLASS__)->error(new FarmLogMessage($dbServer->farmId, "Cannot save storage volume: {$e->getMessage()}"));
}
}
self::onCreateDataBundleResult($message, $dbServer);
return true;
}
示例4: onMysql_PromoteToMasterResult
/**
* @param Scalr_Messaging_Msg_Mysql_PromoteToMasterResult $message
* @param DBServer $dbserver
*/
private function onMysql_PromoteToMasterResult($message, DBServer $dbserver)
{
$dbserver->GetFarmRoleObject()->SetSetting(DBFarmRole::SETTING_MYSQL_SLAVE_TO_MASTER, 0);
if ($message->status == Scalr_Messaging_Msg_Mysql_PromoteToMasterResult::STATUS_OK) {
$dbFarm = $dbserver->GetFarmObject();
$dbFarmRole = $dbserver->GetFarmRoleObject();
$oldMaster = $dbFarm->GetMySQLInstances(true);
if ($dbserver->IsSupported("0.7")) {
if ($message->volumeConfig) {
try {
$storageVolume = Scalr_Storage_Volume::init();
try {
$storageVolume->loadById($message->volumeConfig->id);
$storageVolume->setConfig($message->volumeConfig);
$storageVolume->save();
} catch (Exception $e) {
if (strpos($e->getMessage(), 'not found')) {
$storageVolume->loadBy(array('id' => $message->volumeConfig->id, 'client_id' => $dbserver->clientId, 'env_id' => $dbserver->envId, 'name' => "MySQL data volume", 'type' => $dbFarmRole->GetSetting(DBFarmRole::SETTING_MYSQL_DATA_STORAGE_ENGINE), 'platform' => $dbserver->platform, 'size' => $message->volumeConfig->size, 'fstype' => $message->volumeConfig->fstype, 'purpose' => ROLE_BEHAVIORS::MYSQL, 'farm_roleid' => $dbserver->farmRoleId, 'server_index' => $dbserver->index));
$storageVolume->setConfig($message->volumeConfig);
$storageVolume->save(true);
} else {
throw $e;
}
}
} catch (Exception $e) {
$this->logger->error(new FarmLogMessage($dbserver->farmId, "Cannot save storage volume: {$e->getMessage()}"));
}
}
if ($message->snapshotConfig) {
try {
$snapshot = Scalr_Model::init(Scalr_Model::STORAGE_SNAPSHOT);
$snapshot->loadBy(array('id' => $message->snapshotConfig->id, 'client_id' => $dbserver->clientId, 'env_id' => $dbserver->envId, 'name' => "Automatical MySQL data bundle", 'type' => $dbFarmRole->GetSetting(DBFarmRole::SETTING_MYSQL_DATA_STORAGE_ENGINE), 'platform' => $dbserver->platform, 'description' => "MySQL data bundle created automatically by Scalr", 'ismysql' => true));
$snapshot->setConfig($message->snapshotConfig);
$snapshot->save(true);
$dbFarmRole->SetSetting(DBFarmRole::SETTING_MYSQL_SCALR_SNAPSHOT_ID, $snapshot->id);
$dbFarmRole->SetSetting(DBFarmRole::SETTING_MYSQL_LOG_FILE, $message->logFile);
$dbFarmRole->SetSetting(DBFarmRole::SETTING_MYSQL_LOG_POS, $message->logPos);
} catch (Exception $e) {
$this->logger->error(new FarmLogMessage($dbserver->farmId, "Cannot save storage snapshot: {$e->getMessage()}"));
}
}
} else {
// TODO: delete old slave volume if new one was created
$dbFarmRole->SetSetting(DBFarmRole::SETTING_MYSQL_MASTER_EBS_VOLUME_ID, $message->volumeId);
}
return new NewMysqlMasterUpEvent($dbserver, "", $oldMaster[0]);
} elseif ($message->status == Scalr_Messaging_Msg_Mysql_PromoteToMasterResult::STATUS_FAILED) {
$dbserver->SetProperty(SERVER_PROPERTIES::DB_MYSQL_MASTER, 0);
$dbserver->SetProperty(Scalr_Db_Msr::REPLICATION_MASTER, 0);
// XXX: Need to do smth
$this->logger->error(sprintf("Promote to Master failed for server %s. Last error: %s", $dbserver->serverId, $message->lastError));
}
}
示例5: hasReadOnlyAccessServer
/**
* Checks whether user read only access to specified server
*
* @param \DBServer $dbServer The DBServer object
* @return boolean Returns true if specified server can be accessed by the user
* @throws \Scalr_Exception_Core
*/
public function hasReadOnlyAccessServer(\DBServer $dbServer)
{
$access = $this->hasAccessEnvironment($dbServer->envId);
if ($access) {
if (!empty($dbServer->farmId)) {
if (($dbFarm = $dbServer->GetFarmObject()) instanceof \DBFarm) {
$access = $this->hasAccessFarm($dbFarm);
}
} else {
$access = $this->user->getAclRolesByEnvironment($this->envId)->isAllowed(Acl::RESOURCE_IMAGES_ENVIRONMENT, Acl::PERM_IMAGES_ENVIRONMENT_MANAGE);
}
}
return $access;
}
示例6: hasAccessServer
/**
* Checks whether specified server can be accessed by the user
*
* @param \DBServer $dbServer The DBServer object
* @return boolean Returns true if specified server can be accessed by the user
* @throws \Scalr_Exception_Core
*/
public function hasAccessServer(\DBServer $dbServer)
{
$access = $this->hasAccessEnvironment($dbServer->envId);
if ($access) {
if (!empty($dbServer->farmId)) {
if (($dbFarm = $dbServer->GetFarmObject()) instanceof \DBFarm) {
$access = $this->hasAccessFarm($dbFarm, Acl::PERM_FARMS_SERVERS);
}
} else {
$access = $this->user->getAclRolesByEnvironment($this->envId)->isAllowed(Acl::RESOURCE_FARMS_ROLES, Acl::PERM_FARMS_ROLES_CREATE);
}
}
return $access;
}
示例7: LaunchServer
/**
* {@inheritdoc}
* @see IPlatformModule::LaunchServer()
*/
public function LaunchServer(DBServer $DBServer, Scalr_Server_LaunchOptions $launchOptions = null)
{
$runInstanceRequest = new RunInstancesRequestData(isset($launchOptions->imageId) ? $launchOptions->imageId : null, 1, 1);
$environment = $DBServer->GetEnvironmentObject();
$placementData = null;
$noSecurityGroups = false;
if (!$launchOptions) {
$launchOptions = new Scalr_Server_LaunchOptions();
$DBRole = DBRole::loadById($DBServer->roleId);
$dbFarmRole = $DBServer->GetFarmRoleObject();
$runInstanceRequest->setMonitoring($dbFarmRole->GetSetting(DBFarmRole::SETTING_AWS_ENABLE_CW_MONITORING));
$launchOptions->imageId = $DBRole->getImageId(SERVER_PLATFORMS::EC2, $dbFarmRole->CloudLocation);
// Need OS Family to get block device mapping for OEL roles
$imageInfo = $DBRole->getImageDetails(SERVER_PLATFORMS::EC2, $dbFarmRole->CloudLocation);
$launchOptions->osFamily = $imageInfo['os_family'];
$launchOptions->cloudLocation = $dbFarmRole->CloudLocation;
$akiId = $DBServer->GetProperty(EC2_SERVER_PROPERTIES::AKIID);
if (!$akiId) {
$akiId = $dbFarmRole->GetSetting(DBFarmRole::SETTING_AWS_AKI_ID);
}
if ($akiId) {
$runInstanceRequest->kernelId = $akiId;
}
$ariId = $DBServer->GetProperty(EC2_SERVER_PROPERTIES::ARIID);
if (!$ariId) {
$ariId = $dbFarmRole->GetSetting(DBFarmRole::SETTING_AWS_ARI_ID);
}
if ($ariId) {
$runInstanceRequest->ramdiskId = $ariId;
}
$i_type = $dbFarmRole->GetSetting(DBFarmRole::SETTING_AWS_INSTANCE_TYPE);
if (!$i_type) {
$DBRole = DBRole::loadById($DBServer->roleId);
$i_type = $DBRole->getProperty(EC2_SERVER_PROPERTIES::INSTANCE_TYPE);
}
$launchOptions->serverType = $i_type;
if ($dbFarmRole->GetSetting(DBFarmRole::SETTING_AWS_EBS_OPTIMIZED) == 1) {
$runInstanceRequest->ebsOptimized = true;
} else {
$runInstanceRequest->ebsOptimized = false;
}
foreach ($DBServer->GetCloudUserData() as $k => $v) {
$u_data .= "{$k}={$v};";
}
$runInstanceRequest->userData = base64_encode(trim($u_data, ";"));
$vpcId = $dbFarmRole->GetFarmObject()->GetSetting(DBFarm::SETTING_EC2_VPC_ID);
if ($vpcId) {
if ($DBRole->hasBehavior(ROLE_BEHAVIORS::VPC_ROUTER)) {
$networkInterface = new InstanceNetworkInterfaceSetRequestData();
$networkInterface->networkInterfaceId = $dbFarmRole->GetSetting(Scalr_Role_Behavior_Router::ROLE_VPC_NID);
$networkInterface->deviceIndex = 0;
$networkInterface->deleteOnTermination = false;
$runInstanceRequest->setNetworkInterface($networkInterface);
$noSecurityGroups = true;
} else {
$vpcSubnetId = $dbFarmRole->GetSetting(DBFarmRole::SETTING_AWS_VPC_SUBNET_ID);
$vpcInternetAccess = $dbFarmRole->GetSetting(DBFarmRole::SETTING_AWS_VPC_INTERNET_ACCESS);
if (!$vpcSubnetId) {
$aws = $environment->aws($launchOptions->cloudLocation);
$subnet = $this->AllocateNewSubnet($aws->ec2, $vpcId, $dbFarmRole->GetSetting(DBFarmRole::SETTING_AWS_VPC_AVAIL_ZONE), 24);
try {
$subnet->createTags(array(array('key' => "scalr-id", 'value' => SCALR_ID), array('key' => "scalr-sn-type", 'value' => $vpcInternetAccess), array('key' => "Name", 'value' => 'Scalr System Subnet')));
} catch (Exception $e) {
}
try {
$routeTableId = $dbFarmRole->GetSetting(DBFarmRole::SETTING_AWS_VPC_ROUTING_TABLE_ID);
Logger::getLogger('VPC')->warn(new FarmLogMessage($DBServer->farmId, "Internet access: {$vpcInternetAccess}"));
if (!$routeTableId) {
if ($vpcInternetAccess == Scalr_Role_Behavior_Router::INTERNET_ACCESS_OUTBOUND) {
$routerRole = $DBServer->GetFarmObject()->GetFarmRoleByBehavior(ROLE_BEHAVIORS::VPC_ROUTER);
if (!$routerRole) {
if (\Scalr::config('scalr.instances_connection_policy') != 'local') {
throw new Exception("Outbound access require VPC router role in farm");
}
}
$networkInterfaceId = $routerRole->GetSetting(Scalr_Role_Behavior_Router::ROLE_VPC_NID);
Logger::getLogger('EC2')->warn(new FarmLogMessage($DBServer->farmId, "Requesting outbound routing table. NID: {$networkInterfaceId}"));
$routeTableId = $this->getRoutingTable($vpcInternetAccess, $aws, $networkInterfaceId, $vpcId);
Logger::getLogger('EC2')->warn(new FarmLogMessage($DBServer->farmId, "Routing table ID: {$routeTableId}"));
} elseif ($vpcInternetAccess == Scalr_Role_Behavior_Router::INTERNET_ACCESS_FULL) {
$routeTableId = $this->getRoutingTable($vpcInternetAccess, $aws, null, $vpcId);
}
}
$aws->ec2->routeTable->associate($routeTableId, $subnet->subnetId);
} catch (Exception $e) {
Logger::getLogger('EC2')->warn(new FarmLogMessage($DBServer->farmId, "Removing allocated subnet, due to routing table issues"));
$aws->ec2->subnet->delete($subnet->subnetId);
throw $e;
}
$vpcSubnetId = $subnet->subnetId;
$dbFarmRole->SetSetting(DBFarmRole::SETTING_AWS_VPC_SUBNET_ID, $vpcSubnetId, DBFarmRole::TYPE_LCL);
}
if ($vpcSubnetId) {
$runInstanceRequest->subnetId = $vpcSubnetId;
} else {
throw new Exception("Unable to define subnetId for role in VPC");
//.........这里部分代码省略.........