本文整理汇总了PHP中Scalr_Role_Behavior类的典型用法代码示例。如果您正苦于以下问题:PHP Scalr_Role_Behavior类的具体用法?PHP Scalr_Role_Behavior怎么用?PHP Scalr_Role_Behavior使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Scalr_Role_Behavior类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: OnHostDown
public function OnHostDown(\HostDownEvent $event)
{
$dbServer = $event->DBServer;
if ($dbServer->farmRoleId != 0) {
try {
$dbFarmRole = $dbServer->GetFarmRoleObject();
} catch (\Exception $e) {
return false;
}
foreach (\Scalr_Role_Behavior::getListForFarmRole($dbFarmRole) as $bObj) {
$bObj->onHostDown($dbServer, $event);
}
//Storage
if (!$event->isSuspended) {
try {
$storage = new FarmRoleStorage($dbFarmRole);
$storageConfigs = $storage->getConfigs();
if (empty($storageConfigs)) {
return true;
}
foreach ($storageConfigs as $config) {
//Check for existing volume
$dbVolume = FarmRoleStorageDevice::getByConfigIdAndIndex($config->id, $dbServer->index);
if ($dbVolume && !$config->reUse) {
$dbVolume->status = FarmRoleStorageDevice::STATUS_ZOMBY;
$dbVolume->save();
}
}
} catch (\Exception $e) {
$this->logger->error(new \FarmLogMessage($dbServer, "Marking storage for disposal failed: {$e->getMessage()}"));
}
}
}
}
示例2: 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);
}
}
}
示例3: OnHostDown
public function OnHostDown(HostDownEvent $event)
{
$dbServer = $event->DBServer;
if ($dbServer->farmRoleId != 0) {
try {
$dbFarmRole = $dbServer->GetFarmRoleObject();
} catch (Exception $e) {
return false;
}
foreach (Scalr_Role_Behavior::getListForFarmRole($dbFarmRole) as $bObj) {
$bObj->onHostDown($dbServer);
}
}
}
示例4: 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;
}
示例5: xTroubleshootAction
public function xTroubleshootAction()
{
$this->request->defineParams(array('serverId'));
$dbServer = DBServer::LoadByID($this->getParam('serverId'));
$this->user->getPermissions()->validate($dbServer);
$dbServer->status = SERVER_STATUS::TROUBLESHOOTING;
$dbServer->Save();
// Send before host terminate to the server to detach all used volumes.
$msg = new Scalr_Messaging_Msg_BeforeHostTerminate($dbServer);
if ($dbServer->farmRoleId != 0) {
foreach (Scalr_Role_Behavior::getListForFarmRole($dbServer->GetFarmRoleObject()) as $behavior) {
$msg = $behavior->extendMessage($msg, $dbServer);
}
}
$dbServer->SendMessage($msg);
Scalr::FireEvent($dbServer->farmId, new HostDownEvent($dbServer));
$this->response->success();
}
示例6: makeScalingDecition
/**
*
* @return Scalr_Scaling_Decision
*/
function makeScalingDecition()
{
/*
Base Scaling
*/
foreach (Scalr_Role_Behavior::getListForFarmRole($this->dbFarmRole) as $behavior) {
$result = $behavior->makeUpscaleDecision($this->dbFarmRole);
if ($result === false) {
continue;
} else {
return $result;
}
}
$farm_pending_instances = $this->db->GetOne("SELECT COUNT(*) FROM servers WHERE farm_id=? AND status IN (?,?,?)", array($this->dbFarmRole->FarmID, SERVER_STATUS::PENDING, SERVER_STATUS::INIT, SERVER_STATUS::PENDING_LAUNCH));
if ($this->dbFarmRole->GetFarmObject()->RolesLaunchOrder == 1 && $farm_pending_instances > 0) {
if ($this->dbFarmRole->GetRunningInstancesCount() == 0) {
$this->logger->info("{$farm_pending_instances} instances in pending state. Launch roles one-by-one. Waiting...");
return Scalr_Scaling_Decision::STOP_SCALING;
}
}
/*
Metrics scaling
*/
foreach ($this->getFarmRoleMetrics() as $farmRoleMetric) {
$scalingMetricDecision = $farmRoleMetric->getScalingDecision();
$this->logger->info(sprintf(_("Metric: %s. Decision: %s. Last value: %s"), $farmRoleMetric->getMetric()->name, $scalingMetricDecision, $farmRoleMetric->lastValue));
$scalingMetricName = $farmRoleMetric->getMetric()->name;
$scalingMetricInstancesCount = null;
if ($scalingMetricName == 'DateAndTime') {
$scalingMetricInstancesCount = $farmRoleMetric->instancesNumber;
}
$this->decisonInfo = '1';
if ($scalingMetricDecision == Scalr_Scaling_Decision::NOOP) {
continue;
}
Logger::getLogger(LOG_CATEGORY::FARM)->info(new FarmLogMessage($this->dbFarmRole->FarmID, sprintf("%s: Role '%s' on farm '%s'. Metric name: %s. Last metric value: %s.", $scalingMetricDecision, $this->dbFarmRole->Alias ? $this->dbFarmRole->Alias : $this->dbFarmRole->GetRoleObject()->name, $this->dbFarmRole->GetFarmObject()->Name, $farmRoleMetric->getMetric()->name, $farmRoleMetric->lastValue)));
if ($scalingMetricDecision != Scalr_Scaling_Decision::NOOP) {
break;
}
}
$isDbMsr = $this->dbFarmRole->GetRoleObject()->hasBehavior(ROLE_BEHAVIORS::MYSQL) || $this->dbFarmRole->GetRoleObject()->getDbMsrBehavior();
$needOneByOneLaunch = $this->dbFarmRole->GetRoleObject()->hasBehavior(ROLE_BEHAVIORS::RABBITMQ) || $this->dbFarmRole->GetRoleObject()->hasBehavior(ROLE_BEHAVIORS::MONGODB);
// Check do we need upscale to min instances count
$roleTotalInstances = $this->dbFarmRole->GetRunningInstancesCount() + $this->dbFarmRole->GetPendingInstancesCount();
$maxInstances = $this->dbFarmRole->GetSetting(DBFarmRole::SETTING_SCALING_MAX_INSTANCES);
$minInstances = $this->dbFarmRole->GetSetting(DBFarmRole::SETTING_SCALING_MIN_INSTANCES);
if ($roleTotalInstances < $minInstances) {
if ($needOneByOneLaunch) {
$pendingTerminateInstances = count($this->dbFarmRole->GetServersByFilter(array('status' => SERVER_STATUS::PENDING_TERMINATE)));
// If we launching DbMSR instances. Master should be running.
if ($this->dbFarmRole->GetPendingInstancesCount() == 0 && !$pendingTerminateInstances) {
$this->logger->info(_("Increasing number of running instances to fit min instances setting"));
$this->decisonInfo = '2';
return Scalr_Scaling_Decision::UPSCALE;
} else {
$this->logger->info(_("Found servers in Pending or PendingTerminate state. Waiting..."));
return Scalr_Scaling_Decision::NOOP;
}
} elseif ($isDbMsr) {
// If we launching DbMSR instances. Master should be running.
if ($this->dbFarmRole->GetRunningInstancesCount() > 0 || $this->dbFarmRole->GetPendingInstancesCount() == 0) {
$this->logger->info(_("Increasing number of running instances to fit min instances setting"));
$this->decisonInfo = '3';
return Scalr_Scaling_Decision::UPSCALE;
} else {
$this->logger->info(_("Waiting for running master"));
return Scalr_Scaling_Decision::NOOP;
}
} else {
$this->logger->info(_("Increasing number of running instances to fit min instances setting"));
$this->decisonInfo = '4';
return Scalr_Scaling_Decision::UPSCALE;
}
} elseif ($maxInstances && $this->dbFarmRole->GetRunningInstancesCount() > $maxInstances) {
// Need to check Date&Time based scaling. Otherwise Scalr downscale role every time.
if ($scalingMetricInstancesCount) {
if ($this->dbFarmRole->GetRunningInstancesCount() > $scalingMetricInstancesCount) {
$this->logger->info(_("Decreasing number of running instances to fit DateAndTime scaling settings ({$scalingMetricInstancesCount})"));
$this->decisonInfo = '5';
return Scalr_Scaling_Decision::DOWNSCALE;
}
} else {
$this->logger->info(_("Decreasing number of running instances to fit max instances setting ({$scalingMetricInstancesCount})"));
$this->decisonInfo = '6';
return Scalr_Scaling_Decision::DOWNSCALE;
}
}
return $scalingMetricDecision ? $scalingMetricDecision : Scalr_Scaling_Decision::NOOP;
}
示例7: getBehaviorsRecords
private function getBehaviorsRecords(DBServer $dbServer)
{
$records = array();
if ($dbServer->farmRoleId != 0) {
foreach (Scalr_Role_Behavior::getListForFarmRole($dbServer->GetFarmRoleObject()) as $behavior) {
$records = array_merge($records, (array) $behavior->getDnsRecords($dbServer));
}
}
return $records;
}
示例8: GetServerSecurityGroupsList
//.........这里部分代码省略.........
$sgList[$roleBuilderSgName] = $securityGroupId;
} catch (Exception $e) {
throw new Exception(sprintf(_("Cannot create security group '%s': %s"), $roleBuilderSgName, $e->getMessage()));
}
}
array_push($retval, $sgList[$groupName]);
//Check scalr-farm.* security group
} elseif (stripos($groupName, 'scalr-farm.') === 0) {
if (!isset($sgList[$groupName])) {
try {
$securityGroupId = $ec2->securityGroup->create($groupName, sprintf("Security group for FarmID N%s", $DBServer->farmId), $vpcId);
sleep(2);
$userIdGroupPairList = new UserIdGroupPairList(new UserIdGroupPairData($DBServer->GetEnvironmentObject()->keychain(SERVER_PLATFORMS::EC2)->properties[Entity\CloudCredentialsProperty::AWS_ACCOUNT_ID], null, $groupName));
$ec2->securityGroup->authorizeIngress(array(new IpPermissionData('tcp', 0, 65535, null, $userIdGroupPairList), new IpPermissionData('udp', 0, 65535, null, $userIdGroupPairList)), $securityGroupId);
$sgList[$groupName] = $securityGroupId;
} catch (Exception $e) {
throw new Exception(sprintf(_("Cannot create security group '%s': %s"), $groupName, $e->getMessage()));
}
}
array_push($retval, $sgList[$groupName]);
//Check scalr-role.* security group
} elseif (stripos($groupName, 'scalr-role.') === 0) {
if (!isset($sgList[$groupName])) {
try {
$securityGroupId = $ec2->securityGroup->create($groupName, sprintf("Security group for FarmRoleID N%s on FarmID N%s", $DBServer->GetFarmRoleObject()->ID, $DBServer->farmId), $vpcId);
sleep(2);
// DB rules
$dbRules = $DBServer->GetFarmRoleObject()->GetRoleObject()->getSecurityRules();
$groupRules = array();
foreach ($dbRules as $rule) {
$groupRules[CryptoTool::hash($rule['rule'])] = $rule;
}
// Behavior rules
foreach (\Scalr_Role_Behavior::getListForFarmRole($DBServer->GetFarmRoleObject()) as $bObj) {
$bRules = $bObj->getSecurityRules();
foreach ($bRules as $r) {
if ($r) {
$groupRules[CryptoTool::hash($r)] = array('rule' => $r);
}
}
}
// Default rules
$userIdGroupPairList = new UserIdGroupPairList(new UserIdGroupPairData($DBServer->GetEnvironmentObject()->keychain(SERVER_PLATFORMS::EC2)->properties[Entity\CloudCredentialsProperty::AWS_ACCOUNT_ID], null, $groupName));
$rules = array(new IpPermissionData('tcp', 0, 65535, null, $userIdGroupPairList), new IpPermissionData('udp', 0, 65535, null, $userIdGroupPairList));
foreach ($groupRules as $rule) {
$group_rule = explode(":", $rule["rule"]);
$rules[] = new IpPermissionData($group_rule[0], $group_rule[1], $group_rule[2], new IpRangeData($group_rule[3]));
}
$ec2->securityGroup->authorizeIngress($rules, $securityGroupId);
$sgList[$groupName] = $securityGroupId;
} catch (Exception $e) {
throw new Exception(sprintf(_("Cannot create security group '%s': %s"), $groupName, $e->getMessage()));
}
}
array_push($retval, $sgList[$groupName]);
} elseif ($groupName == \Scalr::config('scalr.aws.security_group_name')) {
if (!isset($sgList[$groupName])) {
try {
$securityGroupId = $ec2->securityGroup->create($groupName, "Security rules needed by Scalr", $vpcId);
$ipRangeList = new IpRangeList();
foreach (\Scalr::config('scalr.aws.ip_pool') as $ip) {
$ipRangeList->append(new IpRangeData($ip));
}
// TODO: Open only FOR VPC ranges
$ipRangeList->append(new IpRangeData('10.0.0.0/8'));
sleep(2);
示例9: makeScalingDecision
/**
* Makes a decision to scale farm
*
* @return Scalr_Scaling_Decision
*/
function makeScalingDecision()
{
/**
* Base Scaling
*/
foreach (Scalr_Role_Behavior::getListForFarmRole($this->dbFarmRole) as $behavior) {
$result = $behavior->makeUpscaleDecision($this->dbFarmRole);
if ($result === false) {
continue;
} else {
return $result;
}
}
$farmPendingInstances = $this->db->GetOne("SELECT COUNT(*) FROM servers WHERE farm_id=? AND status IN (?,?,?)", array($this->dbFarmRole->FarmID, SERVER_STATUS::PENDING, SERVER_STATUS::INIT, SERVER_STATUS::PENDING_LAUNCH));
if ($this->dbFarmRole->GetFarmObject()->RolesLaunchOrder == 1 && $farmPendingInstances > 0) {
if ($this->dbFarmRole->GetRunningInstancesCount() == 0) {
$this->logger->info("{$farmPendingInstances} instances in pending state. Launch roles one-by-one. Waiting...");
return Scalr_Scaling_Decision::STOP_SCALING;
}
}
$scalingMetricDecision = null;
$scalingMetricInstancesCount = null;
$this->logger->info(sprintf(_("%s scaling rules configured"), count($this->farmRoleMetrics)));
if (isset($this->farmRoleMetrics[Entity\ScalingMetric::METRIC_DATE_AND_TIME_ID])) {
$dateAndTimeMetric = $this->farmRoleMetrics[Entity\ScalingMetric::METRIC_DATE_AND_TIME_ID];
try {
$scalingMetricDecision = $dateAndTimeMetric->getScalingDecision();
} catch (Exception $e) {
$this->logger->error("Scaling error in deciding metric '{$dateAndTimeMetric->getMetric()->name}' for farm role '{$this->dbFarmRole->FarmID}:{$this->dbFarmRole->Alias}': {$e->getMessage()}");
}
$scalingMetricName = $dateAndTimeMetric->getMetric()->name;
$scalingMetricInstancesCount = $dateAndTimeMetric->instancesNumber;
$this->decisonInfo = '1';
if ($scalingMetricDecision !== Scalr_Scaling_Decision::NOOP) {
$this->logDecisionInfo($scalingMetricDecision, $scalingMetricName, $dateAndTimeMetric->lastValue);
return $scalingMetricDecision;
}
}
/**
* Metrics scaling
*/
$farmRoleMetrics = array_diff_key($this->farmRoleMetrics, [Entity\ScalingMetric::METRIC_DATE_AND_TIME_ID => null]);
if (!empty($farmRoleMetrics)) {
$checkAllMetrics = $this->dbFarmRole->GetSetting(Entity\FarmRoleSetting::SCALING_DOWN_ONLY_IF_ALL_METRICS_TRUE);
$variousDecisions = false;
/* @var $farmRoleMetric Scalr_Scaling_FarmRoleMetric */
foreach ($farmRoleMetrics as $farmRoleMetric) {
try {
$newDecision = $farmRoleMetric->getScalingDecision();
} catch (Exception $e) {
$this->logger->error("Scaling error in deciding metric '{$farmRoleMetric->getMetric()->name}' for farm role '{$this->dbFarmRole->FarmID}:{$this->dbFarmRole->Alias}': {$e->getMessage()}");
continue;
}
if (isset($scalingMetricDecision)) {
if ($newDecision != $scalingMetricDecision) {
$variousDecisions = true;
}
}
$scalingMetricDecision = $newDecision;
$scalingMetricName = $farmRoleMetric->getMetric()->name;
$this->decisonInfo = '1';
switch ($scalingMetricDecision) {
case Scalr_Scaling_Decision::NOOP:
continue;
case Scalr_Scaling_Decision::DOWNSCALE:
if (!$checkAllMetrics) {
break 2;
}
continue;
case Scalr_Scaling_Decision::UPSCALE:
break 2;
}
}
if (isset($scalingMetricDecision) && !($scalingMetricDecision == Scalr_Scaling_Decision::DOWNSCALE && $checkAllMetrics && $variousDecisions)) {
$this->logDecisionInfo($scalingMetricDecision, $scalingMetricName, isset($farmRoleMetric) ? $farmRoleMetric->lastValue : null);
} else {
$scalingMetricDecision = Scalr_Scaling_Decision::NOOP;
}
}
return $this->getFinalDecision($scalingMetricDecision, $scalingMetricInstancesCount);
}
示例10: xAddReplicaSetAction
public function xAddReplicaSetAction()
{
$dbFarmRole = $this->getFarmRole();
if ($dbFarmRole->GetSetting(Scalr_Role_Behavior_MongoDB::ROLE_CLUSTER_STATUS) != Scalr_Role_Behavior_MongoDB::STATUS_ACTIVE) {
throw new Exception("You cannot add replica set from non-active cluster");
}
$replicasCount = $dbFarmRole->GetSetting(Scalr_Role_Behavior_MongoDB::ROLE_REPLICAS_COUNT);
$dbFarmRole->SetSetting(Scalr_Role_Behavior_MongoDB::ROLE_REPLICAS_COUNT, $replicasCount + 1);
Scalr_Role_Behavior::loadByName(ROLE_BEHAVIORS::MONGODB)->log($dbFarmRole, sprintf("Requested new replica set. Adding #%s replica set to the cluster", $replicasCount + 1));
$this->response->success('Replica successfully added. It may take a few minutes before it becomes available.');
}
示例11: statusAction
public function statusAction()
{
$this->request->defineParams(array('farmId' => array('type' => 'int'), 'farmRoleId' => array('type' => 'int'), 'type'));
$dbFarm = DBFarm::LoadByID($this->getParam('farmId'));
$this->user->getPermissions()->validate($dbFarm);
if ($this->getParam('farmRoleId')) {
$dbFarmRole = DBFarmRole::LoadByID($this->getParam('farmRoleId'));
if ($dbFarmRole->FarmID != $dbFarm->ID) {
throw new Exception("Role not found");
}
} elseif ($this->getParam('type')) {
foreach ($dbFarm->GetFarmRoles() as $sDbFarmRole) {
if ($sDbFarmRole->GetRoleObject()->hasBehavior($this->getParam('type'))) {
$dbFarmRole = $sDbFarmRole;
break;
}
}
if (!$dbFarmRole) {
throw new Exception("Role not found");
}
} else {
throw new Scalr_UI_Exception_NotFound();
}
$data = array('farmRoleId' => $dbFarmRole->ID, 'farmHash' => $dbFarm->Hash, 'pmaAccessConfigured' => false, 'staticDnsSupported' => \Scalr::config('scalr.dns.static.enabled'));
$data['backupsNotSupported'] = in_array($dbFarmRole->Platform, array(SERVER_PLATFORMS::CLOUDSTACK, SERVER_PLATFORMS::IDCF));
if ($dbFarmRole->GetSetting(Entity\FarmRoleSetting::MYSQL_PMA_USER)) {
$data['pmaAccessConfigured'] = true;
} else {
$errmsg = $dbFarmRole->GetSetting(Entity\FarmRoleSetting::MYSQL_PMA_REQUEST_ERROR);
if (!$errmsg) {
$time = $dbFarmRole->GetSetting(Entity\FarmRoleSetting::MYSQL_PMA_REQUEST_TIME);
if ($time) {
if ($time + 3600 < time()) {
$data['pmaAccessError'] = _("Scalr didn't receive auth info from MySQL instance. Please check that MySQL running and Scalr has access to it.");
} else {
$data['pmaAccessSetupInProgress'] = true;
}
}
} else {
$data['pmaAccessError'] = $errmsg;
}
}
//TODO: Legacy code. Move to DB_MSR
if ($dbFarmRole->GetRoleObject()->hasBehavior(ROLE_BEHAVIORS::MYSQL)) {
$data['dbType'] = Scalr_Db_Msr::DB_TYPE_MYSQL;
$data['dtLastBundle'] = $dbFarmRole->GetSetting(Entity\FarmRoleSetting::MYSQL_LAST_BUNDLE_TS) ? Scalr_Util_DateTime::convertTz((int) $dbFarmRole->GetSetting(Entity\FarmRoleSetting::MYSQL_LAST_BUNDLE_TS), 'd M Y \\a\\t H:i:s') : 'Never';
$data['dtLastBackup'] = $dbFarmRole->GetSetting(Entity\FarmRoleSetting::MYSQL_LAST_BCP_TS) ? Scalr_Util_DateTime::convertTz((int) $dbFarmRole->GetSetting(Entity\FarmRoleSetting::MYSQL_LAST_BCP_TS), 'd M Y \\a\\t H:i:s') : 'Never';
$data['additionalInfo']['MasterUsername'] = 'scalr';
$data['additionalInfo']['MasterPassword'] = $dbFarmRole->GetSetting(Entity\FarmRoleSetting::MYSQL_ROOT_PASSWORD);
$slaveNumber = 0;
foreach ($dbFarmRole->GetServersByFilter() as $dbServer) {
if ($dbServer->status != SERVER_STATUS::RUNNING) {
//TODO:
continue;
}
if ($dbServer->GetProperty(SERVER_PROPERTIES::DB_MYSQL_MASTER) == 1) {
$data['isBundleRunning'] = $dbFarmRole->GetSetting(Entity\FarmRoleSetting::MYSQL_IS_BUNDLE_RUNNING);
$data['bundleServerId'] = $dbFarmRole->GetSetting(Entity\FarmRoleSetting::MYSQL_BUNDLE_SERVER_ID);
}
$data['isBackupRunning'] = $dbFarmRole->GetSetting(Entity\FarmRoleSetting::MYSQL_IS_BCP_RUNNING);
$data['backupServerId'] = $dbFarmRole->GetSetting(Entity\FarmRoleSetting::MYSQL_BCP_SERVER_ID);
try {
$isCloudstack = in_array($dbFarmRole->Platform, array(SERVER_PLATFORMS::CLOUDSTACK, SERVER_PLATFORMS::IDCF));
$isMaster = $dbServer->GetProperty(SERVER_PROPERTIES::DB_MYSQL_MASTER) == 1;
if (!$isCloudstack) {
$rStatus = $this->getMySqlReplicationStatus($isMaster ? 'MASTER' : 'SLAVE', $dbServer->remoteIp, 'scalr_stat', $dbFarmRole->GetSetting(Entity\FarmRoleSetting::MYSQL_STAT_PASSWORD));
}
if ($isMaster) {
$MasterPosition = $rStatus['Position'];
$master_ip = $dbServer->remoteIp;
$master_iid = $dbServer->serverId;
} else {
$num = ++$slaveNumber;
$SlavePosition = $rStatus['Exec_Master_Log_Pos'];
}
$d = array("serverId" => $dbServer->serverId, "localIp" => $dbServer->localIp, "remoteIp" => $dbServer->remoteIp, "replicationRole" => $isMaster ? 'Master' : "Slave #{$num}");
if (!$isCloudstack) {
$d['data'] = $rStatus;
$d['masterPosition'] = $MasterPosition;
$d['slavePosition'] = $SlavePosition;
}
$data["replicationStatus"][] = $d;
} catch (Exception $e) {
$data["replicationStatus"][] = array("serverId" => $dbServer->serverId, "localIp" => $dbServer->localIp, "remoteIp" => $dbServer->remoteIp, "error" => $e->msg ? $e->msg : $e->getMessage(), "replicationRole" => $isMaster ? 'Master' : 'Slave');
}
}
} else {
$data['dbType'] = $dbFarmRole->GetRoleObject()->getDbMsrBehavior();
if (!$data['dbType']) {
$this->response->failure("Unknown db type");
}
$behavior = Scalr_Role_Behavior::loadByName($data['dbType']);
$masterServer = $behavior->getMasterServer($dbFarmRole);
// Get Stoarge usage
$size = array('total' => -1, 'used' => -1, 'free' => -1);
if ($masterServer) {
try {
$port = $masterServer->GetProperty(SERVER_PROPERTIES::SZR_API_PORT);
if (!$port) {
$port = 8010;
//.........这里部分代码省略.........
示例12: GetServerSecurityGroupsList
//.........这里部分代码省略.........
throw new \Exception("Cannot get list of security groups (1): {$e->getMessage()}");
}
foreach ($checkGroups as $groupName) {
// Check default SG
if ($groupName == 'default') {
array_push($retval, $sgList[$groupName]);
// Check Roles builder SG
} elseif ($groupName == 'scalr-rb-system') {
if (!isset($sgList[$groupName])) {
try {
$securityGroupId = $ec2->securityGroup->create('scalr-rb-system', "Security group for Roles Builder", $vpcId);
$ipRangeList = new IpRangeList();
foreach (\Scalr::config('scalr.aws.ip_pool') as $ip) {
$ipRangeList->append(new IpRangeData($ip));
}
sleep(2);
$ec2->securityGroup->authorizeIngress(array(new IpPermissionData('tcp', 22, 22, $ipRangeList), new IpPermissionData('tcp', 8008, 8013, $ipRangeList)), $securityGroupId);
$sgList['scalr-rb-system'] = $securityGroupId;
} catch (\Exception $e) {
throw new \Exception(sprintf(_("Cannot create security group '%s': %s"), 'scalr-rb-system', $e->getMessage()));
}
}
array_push($retval, $sgList[$groupName]);
//Check scalr-farm.* security group
} elseif (stripos($groupName, 'scalr-farm.') === 0) {
if (!isset($sgList[$groupName])) {
try {
$securityGroupId = $ec2->securityGroup->create($groupName, sprintf("Security group for FarmID N%s", $DBServer->farmId), $vpcId);
sleep(2);
$userIdGroupPairList = new UserIdGroupPairList(new UserIdGroupPairData($DBServer->GetEnvironmentObject()->getPlatformConfigValue(self::ACCOUNT_ID), null, $groupName));
$ec2->securityGroup->authorizeIngress(array(new IpPermissionData('tcp', 0, 65535, null, $userIdGroupPairList), new IpPermissionData('udp', 0, 65535, null, $userIdGroupPairList)), $securityGroupId);
$sgList[$groupName] = $securityGroupId;
} catch (\Exception $e) {
throw new \Exception(sprintf(_("Cannot create security group '%s': %s"), $groupName, $e->getMessage()));
}
}
array_push($retval, $sgList[$groupName]);
//Check scalr-role.* security group
} elseif (stripos($groupName, 'scalr-role.') === 0) {
if (!isset($sgList[$groupName])) {
try {
$securityGroupId = $ec2->securityGroup->create($groupName, sprintf("Security group for FarmRoleID N%s on FarmID N%s", $DBServer->GetFarmRoleObject()->ID, $DBServer->farmId), $vpcId);
sleep(2);
// DB rules
$dbRules = $DBServer->GetFarmRoleObject()->GetRoleObject()->getSecurityRules();
$groupRules = array();
foreach ($dbRules as $rule) {
$groupRules[\Scalr_Util_CryptoTool::hash($rule['rule'])] = $rule;
}
// Behavior rules
foreach (\Scalr_Role_Behavior::getListForFarmRole($DBServer->GetFarmRoleObject()) as $bObj) {
$bRules = $bObj->getSecurityRules();
foreach ($bRules as $r) {
if ($r) {
$groupRules[\Scalr_Util_CryptoTool::hash($r)] = array('rule' => $r);
}
}
}
// Default rules
$userIdGroupPairList = new UserIdGroupPairList(new UserIdGroupPairData($DBServer->GetEnvironmentObject()->getPlatformConfigValue(self::ACCOUNT_ID), null, $groupName));
$rules = array(new IpPermissionData('tcp', 0, 65535, null, $userIdGroupPairList), new IpPermissionData('udp', 0, 65535, null, $userIdGroupPairList));
foreach ($groupRules as $rule) {
$group_rule = explode(":", $rule["rule"]);
$rules[] = new IpPermissionData($group_rule[0], $group_rule[1], $group_rule[2], new IpRangeData($group_rule[3]));
}
$ec2->securityGroup->authorizeIngress($rules, $securityGroupId);
$sgList[$groupName] = $securityGroupId;
} catch (\Exception $e) {
throw new \Exception(sprintf(_("Cannot create security group '%s': %s"), $groupName, $e->getMessage()));
}
}
array_push($retval, $sgList[$groupName]);
} elseif ($groupName == \Scalr::config('scalr.aws.security_group_name')) {
if (!isset($sgList[$groupName])) {
try {
$securityGroupId = $ec2->securityGroup->create($groupName, "Security rules needed by Scalr", $vpcId);
$ipRangeList = new IpRangeList();
foreach (\Scalr::config('scalr.aws.ip_pool') as $ip) {
$ipRangeList->append(new IpRangeData($ip));
}
// TODO: Open only FOR VPC ranges
$ipRangeList->append(new IpRangeData('10.0.0.0/8'));
sleep(2);
$ec2->securityGroup->authorizeIngress(array(new IpPermissionData('tcp', 3306, 3306, $ipRangeList), new IpPermissionData('tcp', 8008, 8013, $ipRangeList), new IpPermissionData('udp', 8014, 8014, $ipRangeList)), $securityGroupId);
$sgList[$groupName] = $securityGroupId;
} catch (\Exception $e) {
throw new \Exception(sprintf(_("Cannot create security group '%s': %s"), $groupName, $e->getMessage()));
}
}
array_push($retval, $sgList[$groupName]);
} else {
if (!isset($sgList[$groupName])) {
throw new \Exception(sprintf(_("Security group '%s' is not found"), $groupName));
} else {
array_push($retval, $sgList[$groupName]);
}
}
}
return $retval;
}
示例13: 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();
// Add volumes information
try {
if ($this->DBServer->farmRoleId == $farmRoleId) {
$storage = new FarmRoleStorage($dbFarmRole);
$vols = $storage->getVolumesConfigs($this->DBServer->index);
$volumes = array();
foreach ($vols as $i => $volume) {
if ($volume->id) {
$volumes[] = $volume;
}
}
$bodyEl = $this->serialize($volumes, 'volumes', $ResponseDOMDocument);
$ResponseDOMDocument->documentElement->appendChild($bodyEl);
}
} catch (Exception $e) {
$this->Logger->fatal("ListFarmRoleParams::Storage: {$e->getMessage()}");
}
$role = $dbFarmRole->GetRoleObject();
$behaviors = $role->getBehaviors();
foreach ($behaviors as $behavior) {
$data = null;
if ($behavior == ROLE_BEHAVIORS::MONGODB) {
$data = Scalr_Role_Behavior::loadByName($behavior)->getConfiguration($this->DBServer);
}
if ($behavior == ROLE_BEHAVIORS::CHEF) {
$data = Scalr_Role_Behavior::loadByName($behavior)->getConfiguration($this->DBServer);
}
if ($behavior == ROLE_BEHAVIORS::HAPROXY) {
$data = Scalr_Role_Behavior::loadByName($behavior)->getConfiguration($this->DBServer);
}
if ($behavior == ROLE_BEHAVIORS::NGINX) {
$data = Scalr_Role_Behavior::loadByName($behavior)->getConfiguration($this->DBServer);
}
if ($behavior == ROLE_BEHAVIORS::RABBITMQ) {
$data = Scalr_Role_Behavior::loadByName($behavior)->getConfiguration($this->DBServer);
}
if ($behavior == ROLE_BEHAVIORS::APACHE) {
$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;
}
示例14: extendMessage
public function extendMessage(Scalr_Messaging_Msg $message, DBServer $dbServer)
{
$message = parent::extendMessage($message, $dbServer);
switch (get_class($message)) {
case "Scalr_Messaging_Msg_HostInitResponse":
$message->router = $this->getConfiguration($dbServer);
}
return $message;
}
示例15: extendMessage
public function extendMessage(Scalr_Messaging_Msg $message, DBServer $dbServer)
{
$message = parent::extendMessage($message, $dbServer);
switch (get_class($message)) {
case "Scalr_Messaging_Msg_HostInitResponse":
$message->cfCloudController = new stdClass();
$message->cfCloudController->volumeConfig = $this->getVolumeConfig($dbServer->GetFarmRoleObject(), $dbServer);
break;
}
return $message;
}