本文整理汇总了PHP中DBFarmRole::LoadByID方法的典型用法代码示例。如果您正苦于以下问题:PHP DBFarmRole::LoadByID方法的具体用法?PHP DBFarmRole::LoadByID怎么用?PHP DBFarmRole::LoadByID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBFarmRole
的用法示例。
在下文中一共展示了DBFarmRole::LoadByID方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: xSaveAction
public function xSaveAction()
{
//TODO: Think about WebSockets
$this->request->defineParams(array('config' => array('type' => 'json')));
$farmRole = DBFarmRole::LoadByID($this->getParam('farmRoleId'));
$this->user->getPermissions()->validate($farmRole);
$behavior = $this->getParam('behavior');
$updateFarmRoleSettings = false;
if (!$farmRole->GetRoleObject()->hasBehavior($behavior)) {
throw new Exception("Behavior not assigned to this role");
}
$config = array();
foreach ($this->getParam('config') as $conf) {
if (!$config[$conf['configFile']]) {
$config[$conf['configFile']] = array();
}
if ($config[$conf['configFile']][$conf['key']] === null) {
$config[$conf['configFile']][$conf['key']] = $conf['value'];
} else {
throw new Exception("Variable {$conf['key']} from {$conf['configFile']} already defined. Please remove second definition");
}
}
// Update master
if ($this->getParam('masterServerId')) {
$dbServer = DBServer::LoadByID($this->getParam('masterServerId'));
$this->user->getPermissions()->validate($dbServer);
if ($dbServer->farmRoleId != $farmRole->ID) {
throw new Exception("Server not found");
}
if ($dbServer->status != SERVER_STATUS::RUNNING) {
throw new Exception("Master server is not running. Config cannot be applied.");
}
$this->setConfig($dbServer, $behavior, $config);
$servers = 0;
$savedServers = 1;
$updateFarmRoleSettings = true;
foreach ($farmRole->GetServersByFilter(array('status' => array(SERVER_STATUS::RUNNING, SERVER_STATUS::INIT))) as $server) {
$servers++;
try {
if ($server->serverId == $dbServer->serverId) {
continue;
}
$this->setConfig($server, $behavior, $config);
$savedServers++;
} catch (Exception $e) {
$warn[] = sprintf("Cannot update configuration on %s (%s): %s", $server->serverId, $server->remoteIp, $e->getMessage());
}
}
} else {
$updateFarmRoleSettings = true;
}
if ($updateFarmRoleSettings) {
$farmRole->SetServiceConfiguration($behavior, $config);
}
if (!$warn) {
$this->response->success(sprintf("Config successfully applied on %s of %s servers", $savedServers, $servers));
} else {
$this->response->warning(sprintf("Config was applied on %s of %s servers: %s", $savedServers, $servers, implode("\n", $warn)));
}
}
示例2: xListTasksAction
public function xListTasksAction()
{
$this->request->defineParams(array('sort' => array('type' => 'json', 'default' => array('property' => 'dtadded', 'direction' => 'DESC'))));
$sql = "SELECT id FROM dm_deployment_tasks WHERE status !='" . Scalr_Dm_DeploymentTask::STATUS_ARCHIVED . "' AND env_id = '{$this->getEnvironmentId()}'";
$response = $this->buildResponseFromSql($sql, array("id"));
foreach ($response["data"] as $k => $row) {
$data = false;
try {
$deploymentTask = Scalr_Dm_DeploymentTask::init()->loadById($row['id']);
$application = $deploymentTask->getApplication();
try {
$dbServer = DBServer::LoadByID($deploymentTask->serverId);
$serverIndex = $dbServer->index;
} catch (Exception $e) {
}
$data = array('id' => $deploymentTask->id, 'application_name' => $application->name, 'application_id' => $deploymentTask->applicationId, 'server_id' => $deploymentTask->serverId, 'server_index' => $serverIndex, 'remote_path' => $deploymentTask->remotePath, 'status' => $deploymentTask->status, 'dtadded' => $deploymentTask->dtAdded ? Scalr_Util_DateTime::convertTz($deploymentTask->dtAdded) : "", 'dtdeployed' => $deploymentTask->dtDeployed ? Scalr_Util_DateTime::convertTz($deploymentTask->dtDeployed) : "Never");
try {
$dbFarmRole = DBFarmRole::LoadByID($deploymentTask->farmRoleId);
$data['farm_roleid'] = $dbFarmRole->ID;
$data['role_name'] = $dbFarmRole->GetRoleObject()->name;
$data['farm_id'] = $dbFarmRole->FarmID;
$data['farm_name'] = $dbFarmRole->GetFarmObject()->Name;
} catch (Exception $e) {
}
} catch (Exception $e) {
}
$response["data"][$k] = $data;
}
$this->response->data($response);
}
示例3: xListTasksAction
public function xListTasksAction()
{
$this->request->defineParams(array('sort' => array('type' => 'json', 'default' => array('property' => 'dtadded', 'direction' => 'DESC'))));
$sql = "\n SELECT\n dt.id, dma.name AS application_name, servers.index AS server_index, farms.name AS farm_name, roles.name AS role_name,\n dt.status AS status, dt.dtadded AS dtadded\n FROM dm_deployment_tasks dt\n LEFT JOIN dm_applications dma ON dt.dm_application_id = dma.id\n LEFT JOIN servers ON servers.id = dt.server_id\n LEFT JOIN farms ON servers.farm_id = farms.id\n LEFT JOIN roles ON servers.farm_roleid = roles.id\n WHERE dt.`status` != ? AND dt.env_id = ?\n ";
$args = array(Scalr_Dm_DeploymentTask::STATUS_ARCHIVED, $this->getEnvironmentId());
list($sql, $args) = $this->request->prepareFarmSqlQuery($sql, $args, 'farms');
$response = $this->buildResponseFromSql2($sql, array('id', 'application_name', 'farm_name', 'role_name', 'server_index', 'status', 'dtadded', 'dtdeployed'), array(), $args);
foreach ($response["data"] as $k => $row) {
$data = false;
try {
$deploymentTask = Scalr_Dm_DeploymentTask::init()->loadById($row['id']);
$application = $deploymentTask->getApplication();
try {
$dbServer = DBServer::LoadByID($deploymentTask->serverId);
$serverIndex = $dbServer->index;
} catch (Exception $e) {
}
$data = array('id' => $deploymentTask->id, 'application_name' => $application->name, 'application_id' => $deploymentTask->applicationId, 'server_id' => $deploymentTask->serverId, 'server_index' => $serverIndex, 'remote_path' => $deploymentTask->remotePath, 'status' => $deploymentTask->status, 'dtadded' => $deploymentTask->dtAdded ? Scalr_Util_DateTime::convertTz($deploymentTask->dtAdded) : "", 'dtdeployed' => $deploymentTask->dtDeployed ? Scalr_Util_DateTime::convertTz($deploymentTask->dtDeployed) : "Never");
try {
$dbFarmRole = DBFarmRole::LoadByID($deploymentTask->farmRoleId);
$data['farm_roleid'] = $dbFarmRole->ID;
$data['role_name'] = $dbFarmRole->GetRoleObject()->name;
$data['farm_id'] = $dbFarmRole->FarmID;
$data['farm_name'] = $dbFarmRole->GetFarmObject()->Name;
} catch (Exception $e) {
}
} catch (Exception $e) {
}
$response["data"][$k] = $data;
}
$this->response->data($response);
}
示例4: getScalingDecision
function getScalingDecision()
{
$algo = Scalr_Scaling_Algorithm::get($this->getMetric()->algorithm);
$sensor = Scalr_Scaling_Sensor::get($this->getMetric()->alias);
$dbFarmRole = DBFarmRole::LoadByID($this->farmRoleId);
if ($sensor) {
try {
$sensorValue = $sensor->getValue($dbFarmRole, $this);
} catch (Exception $e) {
$this->logger->warn(new FarmLogMessage($dbFarmRole->FarmID, sprintf("Unable to read Scaling Metric value: %s", $e->getMessage())));
return Scalr_Scaling_Decision::NOOP;
}
$this->logger->info(sprintf(_("Raw sensor value (id: %s, metric_id: %s, metric name: %s): %s"), $this->id, $this->metricId, $this->getMetric()->name, serialize($sensorValue)));
switch ($this->getMetric()->calcFunction) {
default:
$value = $sensorValue[0];
break;
case "avg":
$value = count($sensorValue) != 0 ? @array_sum($sensorValue) / count($sensorValue) : 0;
break;
case "sum":
$value = @array_sum($sensorValue);
break;
}
$this->lastValue = round($value, 5);
$this->save();
$invert = $sensor->isInvert;
} else {
$invert = false;
}
return $algo->makeDecision($dbFarmRole, $this, $invert);
}
示例5: OnFarmTerminated
/**
* Release used elastic IPs if farm terminated
*
* @param FarmTerminatedEvent $event
*/
public function OnFarmTerminated(\FarmTerminatedEvent $event)
{
$this->Logger->info(sprintf(_("Keep elastic IPs: %s"), $event->KeepElasticIPs));
if ($event->KeepElasticIPs == 1) {
return;
}
$DBFarm = \DBFarm::LoadByID($this->FarmID);
$ips = $this->DB->GetAll("SELECT * FROM elastic_ips WHERE farmid=?", array($this->FarmID));
if (count($ips) > 0) {
foreach ($ips as $ip) {
try {
$DBFarmRole = \DBFarmRole::LoadByID($ip['farm_roleid']);
if (in_array($DBFarmRole->Platform, array(\SERVER_PLATFORMS::CLOUDSTACK, \SERVER_PLATFORMS::IDCF))) {
$cs = $DBFarm->GetEnvironmentObject()->cloudstack($DBFarmRole->Platform);
$cs->disassociateIpAddress($ip['allocation_id']);
$this->DB->Execute("DELETE FROM elastic_ips WHERE ipaddress=?", array($ip['ipaddress']));
}
} catch (\Exception $e) {
if (!stristr($e->getMessage(), "does not belong to you")) {
$this->Logger->error(sprintf(_("Cannot release elastic IP %s from farm %s: %s"), $ip['ipaddress'], $DBFarm->Name, $e->getMessage()));
continue;
}
}
}
}
}
示例6: xGetFarmRoleStaticIpsAction
public function xGetFarmRoleStaticIpsAction($region, $cloudLocation, $farmRoleId)
{
$p = PlatformFactory::NewPlatform(SERVER_PLATFORMS::GCE);
$gceClient = $p->getClient($this->environment);
$projectId = $this->environment->keychain(SERVER_PLATFORMS::GCE)->properties[Entity\CloudCredentialsProperty::GCE_PROJECT_ID];
$map = [];
if ($farmRoleId) {
$dbFarmRole = DBFarmRole::LoadByID($farmRoleId);
$this->user->getPermissions()->validate($dbFarmRole);
$maxInstances = $dbFarmRole->GetSetting(Entity\FarmRoleSetting::SCALING_MAX_INSTANCES);
for ($i = 1; $i <= $maxInstances; $i++) {
$map[] = array('serverIndex' => $i);
}
$servers = $dbFarmRole->GetServersByFilter();
for ($i = 0, $c = count($servers); $i < $c; $i++) {
if ($servers[$i]->status != SERVER_STATUS::TERMINATED && $servers[$i]->index) {
$map[$servers[$i]->index - 1]['serverIndex'] = $servers[$i]->index;
$map[$servers[$i]->index - 1]['serverId'] = $servers[$i]->serverId;
$map[$servers[$i]->index - 1]['remoteIp'] = $servers[$i]->remoteIp;
$map[$servers[$i]->index - 1]['instanceId'] = $servers[$i]->GetProperty(GCE_SERVER_PROPERTIES::SERVER_NAME);
}
}
$ips = $this->db->GetAll('SELECT ipaddress, instance_index FROM elastic_ips WHERE farm_roleid = ?', array($dbFarmRole->ID));
for ($i = 0, $c = count($ips); $i < $c; $i++) {
$map[$ips[$i]['instance_index'] - 1]['elasticIp'] = $ips[$i]['ipaddress'];
}
}
$response = $gceClient->addresses->listAddresses($projectId, $region);
$ips = [];
/* @var $ip \Google_Service_Compute_Address */
foreach ($response as $ip) {
$itm = array('ipAddress' => $ip->getAddress(), 'description' => $ip->getDescription());
if ($ip->status == 'IN_USE') {
$itm['instanceId'] = substr(strrchr($ip->users[0], "/"), 1);
}
$info = $this->db->GetRow("SELECT * FROM elastic_ips WHERE ipaddress = ? LIMIT 1", [$itm['ipAddress']]);
if ($info) {
try {
if ($info['server_id'] == $itm['instanceId']) {
for ($i = 0, $c = count($map); $i < $c; $i++) {
if ($map[$i]['elasticIp'] == $itm['ipAddress']) {
$map[$i]['warningInstanceIdDoesntMatch'] = true;
}
}
}
$farmRole = DBFarmRole::LoadByID($info['farm_roleid']);
$this->user->getPermissions()->validate($farmRole);
$itm['roleName'] = $farmRole->Alias;
$itm['farmName'] = $farmRole->GetFarmObject()->Name;
$itm['serverIndex'] = $info['instance_index'];
} catch (Exception $e) {
}
}
//Invar: Mark Router EIP ad USED
$ips[] = $itm;
}
$this->response->data(['data' => ['staticIps' => ['map' => $map, 'ips' => $ips]]]);
}
示例7: getFarmRoleStaticIps
private function getFarmRoleStaticIps($cloudLocation, $farmRoleId)
{
$gceClient = $this->getGceClient($this->environment);
$projectId = $this->environment->getPlatformConfigValue(GoogleCEPlatformModule::PROJECT_ID);
$map = array();
if ($farmRoleId) {
$dbFarmRole = DBFarmRole::LoadByID($farmRoleId);
$this->user->getPermissions()->validate($dbFarmRole);
$maxInstances = $dbFarmRole->GetSetting(DBFarmRole::SETTING_SCALING_MAX_INSTANCES);
for ($i = 1; $i <= $maxInstances; $i++) {
$map[] = array('serverIndex' => $i);
}
$servers = $dbFarmRole->GetServersByFilter();
for ($i = 0; $i < count($servers); $i++) {
if ($servers[$i]->status != SERVER_STATUS::TERMINATED && $servers[$i]->status != SERVER_STATUS::TROUBLESHOOTING && $servers[$i]->index) {
$map[$servers[$i]->index - 1]['serverIndex'] = $servers[$i]->index;
$map[$servers[$i]->index - 1]['serverId'] = $servers[$i]->serverId;
$map[$servers[$i]->index - 1]['remoteIp'] = $servers[$i]->remoteIp;
$map[$servers[$i]->index - 1]['instanceId'] = $servers[$i]->GetProperty(GCE_SERVER_PROPERTIES::SERVER_NAME);
}
}
$ips = $this->db->GetAll('SELECT ipaddress, instance_index FROM elastic_ips WHERE farm_roleid = ?', array($dbFarmRole->ID));
for ($i = 0; $i < count($ips); $i++) {
$map[$ips[$i]['instance_index'] - 1]['elasticIp'] = $ips[$i]['ipaddress'];
}
}
$response = $gceClient->addresses->listAddresses($projectId, $cloudLocation);
$ips = array();
/* @var $ip \Google_Service_Compute_Address */
foreach ($response as $ip) {
var_dump($ip);
$itm = array('ipAddress' => $ip->address);
$info = $this->db->GetRow("\n SELECT * FROM elastic_ips WHERE ipaddress = ? LIMIT 1\n ", array($itm['ipAddress']));
if ($info) {
try {
if ($info['server_id'] && $itm['instanceId']) {
$dbServer = DBServer::LoadByID($info['server_id']);
if ($dbServer->GetProperty(EC2_SERVER_PROPERTIES::INSTANCE_ID) != $itm['instanceId']) {
for ($i = 0; $i < count($map); $i++) {
if ($map[$i]['elasticIp'] == $itm['ipAddress']) {
$map[$i]['warningInstanceIdDoesntMatch'] = true;
}
}
}
}
$farmRole = DBFarmRole::LoadByID($info['farm_roleid']);
$this->user->getPermissions()->validate($farmRole);
$itm['roleName'] = $farmRole->GetRoleObject()->name;
$itm['farmName'] = $farmRole->GetFarmObject()->Name;
$itm['serverIndex'] = $info['instance_index'];
} catch (Exception $e) {
}
}
//TODO: Mark Router EIP ad USED
$ips[] = $itm;
}
return array('map' => $map, 'ips' => $ips);
}
示例8: ListFarmRoleParams
public function ListFarmRoleParams()
{
$farmRoleId = $this->GetArg("farm-role-id");
if (!$farmRoleId) {
throw new Exception("'farm-role-id' required");
}
$dbFarmRole = DBFarmRole::LoadByID($farmRoleId);
if ($dbFarmRole->FarmID != $this->DBServer->farmId) {
throw new Exception("You can request this information ONLY for roles within server farm");
}
$ResponseDOMDocument = $this->CreateResponse();
// Base configuration
if ($this->DBServer->farmRoleId == $farmRoleId) {
$data = Scalr_Role_Behavior::loadByName(ROLE_BEHAVIORS::BASE)->getBaseConfiguration($this->DBServer);
foreach ((array) $data as $k => $v) {
$bodyEl = $this->serialize($v, $k, $ResponseDOMDocument);
$ResponseDOMDocument->documentElement->appendChild($bodyEl);
}
}
$role = $dbFarmRole->GetRoleObject();
$behaviors = $role->getBehaviors();
foreach ($behaviors as $behavior) {
$data = null;
if ($behavior == ROLE_BEHAVIORS::MONGODB || $behavior == ROLE_BEHAVIORS::CHEF || $behavior == ROLE_BEHAVIORS::HAPROXY || $behavior == ROLE_BEHAVIORS::NGINX || $behavior == ROLE_BEHAVIORS::RABBITMQ || $behavior == ROLE_BEHAVIORS::APACHE || $behavior == ROLE_BEHAVIORS::VPC_ROUTER) {
$data = Scalr_Role_Behavior::loadByName($behavior)->getConfiguration($this->DBServer);
}
if ($data === null) {
if ($behavior == ROLE_BEHAVIORS::CF_CLOUD_CONTROLLER) {
$data = new stdClass();
$data->version = $dbFarmRole->GetSetting(Scalr_Role_Behavior_CfCloudController::ROLE_VERSION);
} else {
if ($behavior == ROLE_BEHAVIORS::MYSQL) {
$data = new stdClass();
$data->logFile = $dbFarmRole->GetSetting(DBFarmRole::SETTING_MYSQL_LOG_FILE);
$data->logPos = $dbFarmRole->GetSetting(DBFarmRole::SETTING_MYSQL_LOG_POS);
$data->rootPassword = $dbFarmRole->GetSetting(DBFarmRole::SETTING_MYSQL_ROOT_PASSWORD);
$data->replPassword = $dbFarmRole->GetSetting(DBFarmRole::SETTING_MYSQL_REPL_PASSWORD);
$data->statPassword = $dbFarmRole->GetSetting(DBFarmRole::SETTING_MYSQL_STAT_PASSWORD);
$data->replicationMaster = (int) $this->DBServer->GetProperty(SERVER_PROPERTIES::DB_MYSQL_MASTER);
//TODO: Storage
} else {
try {
$dbMsrInfo = Scalr_Db_Msr_Info::init($dbFarmRole, $this->DBServer, $behavior);
$data = $dbMsrInfo->getMessageProperties();
} catch (Exception $e) {
}
}
}
}
if ($data) {
$bodyEl = $this->serialize($data, $behavior, $ResponseDOMDocument);
$ResponseDOMDocument->documentElement->appendChild($bodyEl);
}
}
return $ResponseDOMDocument;
}
示例9: 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;
}
示例10: getScalingDecision
function getScalingDecision()
{
$algo = Entity\ScalingMetric::getAlgorithm($this->getMetric()->algorithm);
$sensor = Scalr_Scaling_Sensor::get($this->getMetric()->alias);
$dbFarmRole = DBFarmRole::LoadByID($this->farmRoleId);
if ($sensor) {
try {
$sensorValue = $sensor->getValue($dbFarmRole, $this);
if ($sensorValue === false) {
return Scalr_Scaling_Decision::NOOP;
}
} catch (Exception $e) {
$this->logger->warn(new FarmLogMessage($dbFarmRole->FarmID, sprintf("Unable to read Scaling Metric (%s) on farmrole %s value: %s", $this->getMetric()->alias, $dbFarmRole->ID, $e->getMessage())));
return Scalr_Scaling_Decision::NOOP;
}
$this->logger->debug(sprintf(_("Raw sensor value (id: %s, metric_id: %s, metric name: %s): %s"), $this->id, $this->metricId, $this->getMetric()->name, json_encode($sensorValue)));
switch ($this->getMetric()->calcFunction) {
case Entity\ScalingMetric::CALC_FUNCTION_AVERAGE:
$value = is_array($sensorValue) && count($sensorValue) != 0 ? @array_sum($sensorValue) / count($sensorValue) : 0;
break;
case Entity\ScalingMetric::CALC_FUNCTION_SUM:
$value = @array_sum($sensorValue);
break;
case Entity\ScalingMetric::CALC_FUNCTION_MAXIMUM:
$value = @max($sensorValue);
break;
case Entity\ScalingMetric::CALC_FUNCTION_MINIMUM:
$value = @min($sensorValue);
break;
default:
$value = $sensorValue[0];
}
$this->lastValue = round($value, 5);
// Sets the Server time to avoid differences between Database and Server time
$this->dtLastPolled = time();
$this->save(false, ['settings', 'metric_id']);
$invert = $sensor instanceof Scalr_Scaling_Sensors_Custom ? $this->getMetric()->isInvert : $sensor->isInvert;
} else {
$invert = false;
}
if ($this->getMetric()->name == 'DateAndTime') {
$decision = $algo->makeDecision($dbFarmRole, $this, $invert);
$this->instancesNumber = $algo->instancesNumber;
$this->lastValue = isset($algo->lastValue) ? $algo->lastValue : null;
return $decision;
} elseif ($this->getMetric()->name == 'FreeRam') {
if ($this->lastValue == 0) {
return Scalr_Scaling_Decision::NOOP;
} else {
return $algo->makeDecision($dbFarmRole, $this, $invert);
}
} else {
return $algo->makeDecision($dbFarmRole, $this, $invert);
}
}
示例11: Run
public function Run()
{
$container = Scalr::getContainer();
$db = $container->adodb;
$services = $db->Execute("SELECT * FROM farm_role_cloud_services");
while ($service = $services->FetchRow()) {
$dbFarmRole = DBFarmRole::LoadByID($service['farm_role_id']);
if (!$dbFarmRole->GetSetting(DBFarmRole::SETTING_AWS_ELB_ENABLED)) {
$dbFarmRole->SetSetting(DBFarmRole::SETTING_AWS_ELB_ENABLED, 1);
$dbFarmRole->SetSetting(DBFarmRole::SETTING_AWS_ELB_ID, $service['id']);
}
}
}
示例12: getScalingDecision
function getScalingDecision()
{
$algo = Entity\ScalingMetric::getAlgorithm($this->getMetric()->algorithm);
$sensor = Scalr_Scaling_Sensor::get($this->getMetric()->alias);
$dbFarmRole = DBFarmRole::LoadByID($this->farmRoleId);
if ($sensor) {
try {
$sensorValue = $sensor->getValue($dbFarmRole, $this);
if ($sensorValue === false) {
return Scalr_Scaling_Decision::NOOP;
}
} catch (Exception $e) {
$this->logger->warn(new FarmLogMessage($dbFarmRole->FarmID, sprintf("Unable to read Scaling Metric (%s) on farmrole %s value: %s", $this->getMetric()->alias, $dbFarmRole->ID, $e->getMessage())));
return Scalr_Scaling_Decision::NOOP;
}
$this->logger->info(sprintf(_("Raw sensor value (id: %s, metric_id: %s, metric name: %s): %s"), $this->id, $this->metricId, $this->getMetric()->name, serialize($sensorValue)));
switch ($this->getMetric()->calcFunction) {
default:
$value = $sensorValue[0];
break;
case "avg":
$value = is_array($sensorValue) && count($sensorValue) != 0 ? @array_sum($sensorValue) / count($sensorValue) : 0;
break;
case "sum":
$value = @array_sum($sensorValue);
break;
case "max":
$value = @max($sensorValue);
break;
}
$this->lastValue = round($value, 5);
$this->save();
$invert = $sensor->isInvert;
} else {
$invert = false;
}
if ($this->getMetric()->name == 'DateAndTime') {
$decision = $algo->makeDecision($dbFarmRole, $this, $invert);
$this->instancesNumber = $algo->instancesNumber;
$this->lastValue = $algo->lastValue;
return $decision;
} elseif ($this->getMetric()->name == 'FreeRam') {
if ($this->lastValue == 0) {
return Scalr_Scaling_Decision::NOOP;
} else {
return $algo->makeDecision($dbFarmRole, $this, $invert);
}
} else {
return $algo->makeDecision($dbFarmRole, $this, $invert);
}
}
示例13: findFarmRoleService
/**
* @param integer $envId
* @param string $serviceId
* @return \Scalr\Farm\Role\FarmRoleService|boolean
*/
public static function findFarmRoleService($envId, $serviceId)
{
$db = \Scalr::getDb();
$service = $db->GetRow("SELECT id, farm_role_id FROM farm_role_cloud_services WHERE id = ? AND env_id = ?", array($serviceId, $envId));
if ($service) {
try {
$dbFarmRole = \DBFarmRole::LoadByID($service['farm_role_id']);
return new self($dbFarmRole, $service['id']);
} catch (\Exception $e) {
return false;
}
}
return false;
}
示例14: ListFarmRoleParamsJson
public function ListFarmRoleParamsJson()
{
$farmRoleId = $this->GetArg("farm-role-id");
if (!$farmRoleId) {
throw new Exception("'farm-role-id' required");
}
$dbFarmRole = DBFarmRole::LoadByID($farmRoleId);
if ($dbFarmRole->FarmID != $this->DBServer->farmId) {
throw new Exception("You can request this information ONLY for roles within server farm");
}
$result = new stdClass();
// Base configuration
if ($this->DBServer->farmRoleId == $farmRoleId) {
$data = Scalr_Role_Behavior::loadByName(ROLE_BEHAVIORS::BASE)->getBaseConfiguration($this->DBServer);
foreach ((array) $data as $k => $v) {
$result->{$k} = $v;
}
}
$role = $dbFarmRole->GetRoleObject();
$behaviors = $role->getBehaviors();
foreach ($behaviors as $behavior) {
$data = null;
if ($behavior == ROLE_BEHAVIORS::MONGODB || $behavior == ROLE_BEHAVIORS::CHEF || $behavior == ROLE_BEHAVIORS::HAPROXY || $behavior == ROLE_BEHAVIORS::NGINX || $behavior == ROLE_BEHAVIORS::RABBITMQ || $behavior == ROLE_BEHAVIORS::APACHE || $behavior == ROLE_BEHAVIORS::VPC_ROUTER) {
$data = Scalr_Role_Behavior::loadByName($behavior)->getConfiguration($this->DBServer);
}
if ($data === null) {
if ($behavior == ROLE_BEHAVIORS::MYSQL) {
$data = new stdClass();
$data->logFile = $dbFarmRole->GetSetting(DBFarmRole::SETTING_MYSQL_LOG_FILE);
$data->logPos = $dbFarmRole->GetSetting(DBFarmRole::SETTING_MYSQL_LOG_POS);
$data->rootPassword = $dbFarmRole->GetSetting(DBFarmRole::SETTING_MYSQL_ROOT_PASSWORD);
$data->replPassword = $dbFarmRole->GetSetting(DBFarmRole::SETTING_MYSQL_REPL_PASSWORD);
$data->statPassword = $dbFarmRole->GetSetting(DBFarmRole::SETTING_MYSQL_STAT_PASSWORD);
$data->replicationMaster = (int) $this->DBServer->GetProperty(SERVER_PROPERTIES::DB_MYSQL_MASTER);
} else {
try {
$dbMsrInfo = Scalr_Db_Msr_Info::init($dbFarmRole, $this->DBServer, $behavior);
$data = $dbMsrInfo->getMessageProperties();
} catch (Exception $e) {
}
}
}
if ($data) {
$result->{$behavior} = $data;
}
}
return $result;
}
示例15: FarmGetDetails
public function FarmGetDetails($FarmID)
{
$response = parent::FarmGetDetails($FarmID);
foreach ($response->FarmRoleSet->Item as &$item) {
$dbFarmRole = DBFarmRole::LoadByID($item->ID);
$item->{"CloudLocation"} = $dbFarmRole->CloudLocation;
if ($dbFarmRole->GetRoleObject()->hasBehavior(ROLE_BEHAVIORS::MYSQL)) {
$item->{"MySQLProperties"} = new stdClass();
$item->{"MySQLProperties"}->{"LastBackupTime"} = $dbFarmRole->GetSetting(DBFarmRole::SETTING_MYSQL_LAST_BCP_TS);
$item->{"MySQLProperties"}->{"LastBundleTime"} = $dbFarmRole->GetSetting(DBFarmRole::SETTING_MYSQL_LAST_BUNDLE_TS);
$item->{"MySQLProperties"}->{"IsBackupRunning"} = $dbFarmRole->GetSetting(DBFarmRole::SETTING_MYSQL_IS_BCP_RUNNING);
$item->{"MySQLProperties"}->{"IsBundleRunning"} = $dbFarmRole->GetSetting(DBFarmRole::SETTING_MYSQL_IS_BUNDLE_RUNNING);
}
}
return $response;
}