本文整理汇总了PHP中Scalr_Role_Behavior::getListForFarmRole方法的典型用法代码示例。如果您正苦于以下问题:PHP Scalr_Role_Behavior::getListForFarmRole方法的具体用法?PHP Scalr_Role_Behavior::getListForFarmRole怎么用?PHP Scalr_Role_Behavior::getListForFarmRole使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Scalr_Role_Behavior
的用法示例。
在下文中一共展示了Scalr_Role_Behavior::getListForFarmRole方法的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: 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();
}
示例5: 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;
}
示例6: onHostUp
/**
* @param Scalr_Messaging_Msg $message
* @param DBServer $dbserver
*/
private function onHostUp($message, $dbserver, $skipStatusCheck = false)
{
if ($dbserver->status == SERVER_STATUS::INIT || $skipStatusCheck) {
$event = new HostUpEvent($dbserver, "");
$dbFarmRole = $dbserver->GetFarmRoleObject();
foreach (Scalr_Role_Behavior::getListForFarmRole($dbFarmRole) as $behavior) {
$behavior->handleMessage($message, $dbserver);
}
//TODO: Move MySQL to MSR
/****** MOVE TO MSR ******/
//TODO: Legacy MySQL code
if ($dbFarmRole->GetRoleObject()->hasBehavior(ROLE_BEHAVIORS::MYSQL)) {
if (!$message->mysql) {
$this->logger->error(sprintf("Strange situation. HostUp message from MySQL behavior doesn't contains `mysql` property. Server %s (%s)", $dbserver->serverId, $dbserver->remoteIp));
return;
}
$mysqlData = $message->mysql;
if ($dbserver->GetProperty(SERVER_PROPERTIES::DB_MYSQL_MASTER)) {
if ($mysqlData->rootPassword) {
$dbFarmRole->SetSetting(DBFarmRole::SETTING_MYSQL_REPL_PASSWORD, $mysqlData->replPassword);
$dbFarmRole->SetSetting(DBFarmRole::SETTING_MYSQL_ROOT_PASSWORD, $mysqlData->rootPassword);
$dbFarmRole->SetSetting(DBFarmRole::SETTING_MYSQL_STAT_PASSWORD, $mysqlData->statPassword);
}
$dbFarmRole->SetSetting(DBFarmRole::SETTING_MYSQL_LOG_FILE, $mysqlData->logFile);
$dbFarmRole->SetSetting(DBFarmRole::SETTING_MYSQL_LOG_POS, $mysqlData->logPos);
if ($dbserver->IsSupported("0.7")) {
//$dbFarmRole->SetSetting(DBFarmRole::SETTING_MYSQL_SNAPSHOT_ID, $mysqlData->snapshotConfig);
//$dbFarmRole->SetSetting(DBFarmRole::SETTING_MYSQL_SNAPSHOT_ID, $mysqlData->volumeConfig);
if ($mysqlData->volumeConfig) {
try {
$storageVolume = Scalr_Storage_Volume::init();
try {
$storageVolume->loadById($mysqlData->volumeConfig->id);
$storageVolume->setConfig($mysqlData->volumeConfig);
$storageVolume->save();
} catch (Exception $e) {
if (strpos($e->getMessage(), 'not found')) {
$storageVolume->loadBy(array('id' => $mysqlData->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' => $mysqlData->volumeConfig->size, 'fstype' => $mysqlData->volumeConfig->fstype, 'purpose' => ROLE_BEHAVIORS::MYSQL, 'farm_roleid' => $dbserver->farmRoleId, 'server_index' => $dbserver->index));
$storageVolume->setConfig($mysqlData->volumeConfig);
$storageVolume->save(true);
} else {
throw $e;
}
}
$dbFarmRole->SetSetting(DBFarmRole::SETTING_MYSQL_SCALR_VOLUME_ID, $storageVolume->id);
} catch (Exception $e) {
$this->logger->error(new FarmLogMessage($event->DBServer->farmId, "Cannot save storage volume: {$e->getMessage()}"));
}
}
if ($mysqlData->snapshotConfig) {
try {
$storageSnapshot = Scalr_Storage_Snapshot::init();
try {
$storageSnapshot->loadById($mysqlData->snapshotConfig->id);
$storageSnapshot->setConfig($mysqlData->snapshotConfig);
$storageSnapshot->save();
} catch (Exception $e) {
if (strpos($e->getMessage(), 'not found')) {
$storageSnapshot->loadBy(array('id' => $mysqlData->snapshotConfig->id, 'client_id' => $dbserver->clientId, 'farm_id' => $dbserver->farmId, 'farm_roleid' => $dbserver->farmRoleId, 'env_id' => $dbserver->envId, 'name' => sprintf(_("MySQL data bundle #%s"), $mysqlData->snapshotConfig->id), 'type' => $dbFarmRole->GetSetting(DBFarmRole::SETTING_MYSQL_DATA_STORAGE_ENGINE), 'platform' => $dbserver->platform, 'description' => sprintf(_("MySQL data bundle created on Farm '%s' -> Role '%s'"), $dbFarmRole->GetFarmObject()->Name, $dbFarmRole->GetRoleObject()->name), 'ismysql' => true, 'service' => ROLE_BEHAVIORS::MYSQL));
$storageSnapshot->setConfig($mysqlData->snapshotConfig);
$storageSnapshot->save(true);
} else {
throw $e;
}
}
$dbFarmRole->SetSetting(DBFarmRole::SETTING_MYSQL_SCALR_SNAPSHOT_ID, $storageSnapshot->id);
} catch (Exception $e) {
$this->logger->error(new FarmLogMessage($event->DBServer->farmId, "Cannot save storage snapshot: {$e->getMessage()}"));
}
}
} else {
/**
* @deprecated
*/
$dbFarmRole->SetSetting(DBFarmRole::SETTING_MYSQL_SNAPSHOT_ID, $mysqlData->snapshotId);
}
}
}
return $event;
} else {
$this->logger->error("Strange situation. Received HostUp message" . " from server '{$dbserver->serverId}' ('{$message->remoteIp})" . " with state {$dbserver->status}!");
}
}
示例7: FarmAddRole
//.........这里部分代码省略.........
$vpcId = $dbFarm->GetSetting(DBFarm::SETTING_EC2_VPC_ID);
if ($vpcId) {
if (!$Configuration['aws.vpc_subnet_id']) {
throw new Exception("Farm configured to run inside VPC. 'aws.vpc_subnet_id' is required");
}
$vpcRegion = $dbFarm->GetSetting(DBFarm::SETTING_EC2_VPC_REGION);
if ($CloudLocation != $vpcRegion) {
throw new Exception(sprintf("Farm configured to run inside VPC in %s region. Only roles in this region are allowed.", $vpcRegion));
}
$vpcGovernance = $governance->getValue('ec2', 'aws.vpc');
$vpcGovernanceIds = $governance->getValue('ec2', 'aws.vpc', 'ids');
$subnets = json_decode($Configuration['aws.vpc_subnet_id'], true);
if (count($subnets) == 0) {
throw new Exception("Subnets list is empty or json is incorrect");
}
$type = false;
foreach ($subnets as $subnetId) {
$platform = PlatformFactory::NewPlatform(SERVER_PLATFORMS::EC2);
$info = $platform->listSubnets($this->Environment, $CloudLocation, $vpcId, true, $subnetId);
if (substr($info['availability_zone'], 0, -1) != $vpcRegion) {
throw new Exception(sprintf("Only subnets from %s region are allowed according to VPC settings", $vpcRegion));
}
if ($vpcGovernance == 1) {
// Check valid subnets
if ($vpcGovernanceIds[$vpcId] && is_array($vpcGovernanceIds[$vpcId]) && !in_array($subnetId, $vpcGovernanceIds[$vpcId])) {
throw new Exception(sprintf("Only %s subnet(s) allowed by governance settings", implode(', ', $vpcGovernanceIds[$vpcId])));
}
// Check if subnets types
if ($vpcGovernanceIds[$vpcId] == "outbound-only") {
if ($info['type'] != 'private') {
throw new Exception("Only private subnets allowed by governance settings");
}
}
if ($vpcGovernanceIds[$vpcId] == "full") {
if ($info['type'] != 'public') {
throw new Exception("Only public subnets allowed by governance settings");
}
}
}
if (!$type) {
$type = $info['type'];
} else {
if ($type != $info['type']) {
throw new Exception("Mix of public and private subnets are not allowed. Please specify only public or only private subnets.");
}
}
}
}
}
if (PlatformFactory::isCloudstack($Platform)) {
$config['cloudstack.security_groups.list'] = json_encode(array('default', \Scalr::config('scalr.aws.security_group_name')));
}
if ($Platform == SERVER_PLATFORMS::GCE) {
$config['gce.network'] = 'default';
$config['gce.on-host-maintenance'] = 'MIGRATE';
}
if ($Configuration[Scalr_Role_Behavior_Chef::ROLE_CHEF_BOOTSTRAP] == 1 && !$Configuration[Scalr_Role_Behavior_Chef::ROLE_CHEF_ENVIRONMENT]) {
$config[Scalr_Role_Behavior_Chef::ROLE_CHEF_ENVIRONMENT] = '_default';
}
$config = array_merge($config, $Configuration);
$this->validateFarmRoleConfiguration($config);
if ($Platform == SERVER_PLATFORMS::GCE) {
$config['gce.cloud-location'] = $CloudLocation;
$config['gce.region'] = substr($CloudLocation, 0, -1);
}
$Alias = $this->stripValue($Alias);
if (strlen($Alias) < 4) {
throw new Exception("Role Alias should be longer than 4 characters");
}
if (!preg_match("/^[A-Za-z0-9]+[A-Za-z0-9-]*[A-Za-z0-9]+\$/si", $Alias)) {
throw new Exception("Alias should start and end with letter or number and contain only letters, numbers and dashes.");
}
if (!$this->Environment->isPlatformEnabled($Platform)) {
throw new Exception("'{$Platform}' cloud is not configured in your environment");
}
$images = $dbRole->__getNewRoleObject()->fetchImagesArray();
$locations = isset($images[$Platform]) ? array_keys($images[$Platform]) : [];
if (!in_array($CloudLocation, $locations) && $Platform != SERVER_PLATFORMS::GCE) {
throw new Exception(sprintf("Role '%s' doesn't have an image configured for cloud location '%s'", $dbRole->name, $CloudLocation));
}
if ($Alias) {
foreach ($dbFarm->GetFarmRoles() as $farmRole) {
if ($farmRole->Alias == $Alias) {
throw new Exception("Selected alias is already used by another role in selected farm");
}
}
}
$dbFarmRole = $dbFarm->AddRole($dbRole, $Platform, $CloudLocation, 1);
$dbFarmRole->Alias = $Alias ? $Alias : $dbRole->name;
foreach ($config as $k => $v) {
$dbFarmRole->SetSetting($k, trim($v), DBFarmRole::TYPE_CFG);
}
foreach (Scalr_Role_Behavior::getListForFarmRole($dbFarmRole) as $behavior) {
$behavior->onFarmSave($dbFarm, $dbFarmRole);
}
$dbFarmRole->Save();
$response = $this->CreateInitialResponse();
$response->FarmRoleID = $dbFarmRole->ID;
return $response;
}
示例8: 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;
}
示例9: FarmAddRole
public function FarmAddRole($Alias, $FarmID, $RoleID, $Platform, $CloudLocation, array $Configuration = array())
{
$this->restrictAccess(Acl::RESOURCE_FARMS, Acl::PERM_FARMS_MANAGE);
try {
$dbFarm = DBFarm::LoadByID($FarmID);
if ($dbFarm->EnvID != $this->Environment->id) {
throw new Exception("N");
}
} catch (Exception $e) {
throw new Exception(sprintf("Farm #%s not found", $FarmID));
}
$this->user->getPermissions()->validate($dbFarm);
$dbFarm->isLocked(true);
$dbRole = DBRole::loadById($RoleID);
if ($dbRole->envId != 0) {
$this->user->getPermissions()->validate($dbRole);
}
foreach ($dbRole->getBehaviors() as $behavior) {
if ($behavior != ROLE_BEHAVIORS::BASE && $behavior != ROLE_BEHAVIORS::CHEF) {
throw new Exception("Only base roles supported to be added to farm via API");
}
}
$config = array('scaling.enabled' => 0, 'scaling.min_instances' => 1, 'scaling.max_instances' => 1, 'scaling.polling_interval' => 2, 'system.timeouts.launch' => 9600, 'system.timeouts.reboot' => 9600);
if (PlatformFactory::isOpenstack($Platform)) {
//TODO:
}
if ($Platform == SERVER_PLATFORMS::EC2) {
$config['aws.security_groups.list'] = json_encode(array('default', \Scalr::config('scalr.aws.security_group_name')));
}
if ($Configuration[Scalr_Role_Behavior_Chef::ROLE_CHEF_BOOTSTRAP] == 1 && !$Configuration[Scalr_Role_Behavior_Chef::ROLE_CHEF_ENVIRONMENT]) {
$config[Scalr_Role_Behavior_Chef::ROLE_CHEF_ENVIRONMENT] = '_default';
}
$config = array_merge($config, $Configuration);
$this->validateFarmRoleConfiguration($config);
$Alias = $this->stripValue($Alias);
if (strlen($Alias) < 4) {
throw new Exception("Role Alias should be longer than 4 characters");
}
if (preg_match("/^[^A-Za-z0-9_-]+\$/", $Alias)) {
throw new Exception("Role Alias should has only 'A-Za-z0-9-_' characters");
}
if (!PlatformFactory::isOpenstack($Platform) && $Platform != SERVER_PLATFORMS::EC2) {
throw new Exception("Only EC2 and Openstack roles are supported by this method");
}
if (!$this->Environment->isPlatformEnabled($Platform)) {
throw new Exception("'{$Platform}' cloud is not configured in your environment");
}
$locations = $dbRole->getCloudLocations($Platform);
if (!in_array($CloudLocation, $locations)) {
throw new Exception(sprintf("Role '%s' doesn't have image configured for cloud location '%s'", $dbRole->name, $CloudLocation));
}
if ($Alias) {
foreach ($dbFarm->GetFarmRoles() as $farmRole) {
if ($farmRole->Alias == $Alias) {
throw new Exception("Selected alias is already used by another role in selected farm");
}
}
}
$dbFarmRole = $dbFarm->AddRole($dbRole, $Platform, $CloudLocation, 1);
$dbFarmRole->Alias = $Alias ? $Alias : $dbRole->name;
foreach ($config as $k => $v) {
$dbFarmRole->SetSetting($k, $v, DBFarmRole::TYPE_CFG);
}
foreach (Scalr_Role_Behavior::getListForFarmRole($dbFarmRole) as $behavior) {
$behavior->onFarmSave($dbFarm, $dbFarmRole);
}
$dbFarmRole->Save();
$response = $this->CreateInitialResponse();
$response->FarmRoleID = $dbFarmRole->ID;
return $response;
}
示例10: OnBeforeHostTerminate
public function OnBeforeHostTerminate(\BeforeHostTerminateEvent $event)
{
try {
$dbFarm = \DBFarm::LoadByID($this->FarmID);
} catch (\Exception $e) {
}
if ($dbFarm) {
$servers = $this->DB->Execute("SELECT * FROM servers WHERE farm_id = ? AND status IN (?,?,?,?)", array($dbFarm->ID, \SERVER_STATUS::INIT, \SERVER_STATUS::RUNNING, \SERVER_STATUS::PENDING_TERMINATE, \SERVER_STATUS::PENDING_SUSPEND));
$event->messageLongestInsert = 0;
while ($server = $servers->FetchRow()) {
$DBServer = \DBServer::load($server);
// We don't need to send beforeHostTerminate event to all "Pending terminate" servers,
// only tu eventServer.
if ($DBServer->status == \SERVER_STATUS::PENDING_TERMINATE) {
if ($DBServer->serverId != $event->DBServer->serverId) {
continue;
}
}
$msg = new \Scalr_Messaging_Msg_BeforeHostTerminate();
$msg->setServerMetaData($event->DBServer);
$msg->suspend = $event->suspend;
$msg = \Scalr_Scripting_Manager::extendMessage($msg, $event, $event->DBServer, $DBServer);
if ($event->DBServer->farmRoleId != 0) {
foreach (\Scalr_Role_Behavior::getListForFarmRole($event->DBServer->GetFarmRoleObject()) as $behavior) {
$msg = $behavior->extendMessage($msg, $event->DBServer);
}
}
$mt = microtime(true);
$DBServer->SendMessage($msg, false, true);
$mtResult = microtime(true) - $mt;
if ($event->messageLongestInsert < $mtResult) {
$event->messageLongestInsert = $mtResult;
}
}
try {
if ($event->DBServer->GetFarmRoleObject()->GetSetting(\Scalr_Db_Msr::SLAVE_TO_MASTER) != 1) {
if ($event->DBServer->GetFarmRoleObject()->GetRoleObject()->getDbMsrBehavior()) {
$this->sendPromoteToMasterMessage($event);
}
}
} catch (\Exception $e) {
}
}
}
示例11: xBuildAction
//.........这里部分代码省略.........
continue;
}
if ($update) {
$dbFarmRole->LaunchIndex = (int) $role['launch_index'];
$dbFarmRole->Alias = $role['alias'];
$dbFarmRole->Save();
}
$usedPlatforms[$role['platform']] = 1;
$oldRoleSettings = $dbFarmRole->GetAllSettings();
// Update virtual farm_role_id with actual value
$scripts = (array) $role['scripting'];
if (count($virtualFarmRoles) > 0) {
array_walk_recursive($scripts, function (&$v, $k) use($virtualFarmRoles) {
if (is_string($v)) {
$v = str_replace(array_keys($virtualFarmRoles), array_values($virtualFarmRoles), $v);
}
});
array_walk_recursive($role['settings'], function (&$v, $k) use($virtualFarmRoles) {
if (is_string($v)) {
$v = str_replace(array_keys($virtualFarmRoles), array_values($virtualFarmRoles), $v);
}
});
}
$dbFarmRole->ClearSettings("chef.");
if (!empty($role['scaling_settings']) && is_array($role['scaling_settings'])) {
foreach ($role['scaling_settings'] as $k => $v) {
$dbFarmRole->SetSetting($k, $v, DBFarmRole::TYPE_CFG);
}
}
foreach ($role['settings'] as $k => $v) {
$dbFarmRole->SetSetting($k, $v, DBFarmRole::TYPE_CFG);
}
/****** Scaling settings ******/
$scalingManager = new Scalr_Scaling_Manager($dbFarmRole);
$scalingManager->setFarmRoleMetrics(is_array($role['scaling']) ? $role['scaling'] : array());
//TODO: optimize this code...
$this->db->Execute("DELETE FROM farm_role_scaling_times WHERE farm_roleid=?", array($dbFarmRole->ID));
// 5 = Time based scaling -> move to constants
if ($role['scaling'][5]) {
foreach ($role['scaling'][5] as $scal_period) {
$chunks = explode(":", $scal_period['id']);
$this->db->Execute("INSERT INTO farm_role_scaling_times SET\n farm_roleid\t\t= ?,\n start_time\t\t= ?,\n end_time\t\t= ?,\n days_of_week\t= ?,\n instances_count\t= ?\n ", array($dbFarmRole->ID, $chunks[0], $chunks[1], $chunks[2], $chunks[3]));
}
}
/*****************/
/* Update role params */
$dbFarmRole->SetParameters((array) $role['params']);
/* End of role params management */
/* Add script options to databse */
$dbFarmRole->SetScripts($scripts, (array) $role['scripting_params']);
/* End of scripting section */
/* Add services configuration */
$dbFarmRole->SetServiceConfigPresets((array) $role['config_presets']);
/* End of scripting section */
/* Add storage configuration */
if (isset($role['storages'])) {
if (isset($role['storages']['configs'])) {
$dbFarmRole->getStorage()->setConfigs($role['storages']['configs']);
}
}
$farmRoleVariables->setValues(is_array($role['variables']) ? $role['variables'] : [], $dbFarmRole->GetRoleID(), $dbFarm->ID, $dbFarmRole->ID, '', false, true);
foreach (Scalr_Role_Behavior::getListForFarmRole($dbFarmRole) as $behavior) {
$behavior->onFarmSave($dbFarm, $dbFarmRole);
}
/**
* Platform specified updates
*/
if ($dbFarmRole->Platform == SERVER_PLATFORMS::EC2) {
\Scalr\Modules\Platforms\Ec2\Helpers\EbsHelper::farmUpdateRoleSettings($dbFarmRole, $oldRoleSettings, $role['settings']);
\Scalr\Modules\Platforms\Ec2\Helpers\EipHelper::farmUpdateRoleSettings($dbFarmRole, $oldRoleSettings, $role['settings']);
\Scalr\Modules\Platforms\Ec2\Helpers\ElbHelper::farmUpdateRoleSettings($dbFarmRole, $oldRoleSettings, $role['settings']);
}
if (in_array($dbFarmRole->Platform, array(SERVER_PLATFORMS::IDCF, SERVER_PLATFORMS::CLOUDSTACK))) {
Scalr\Modules\Platforms\Cloudstack\Helpers\CloudstackHelper::farmUpdateRoleSettings($dbFarmRole, $oldRoleSettings, $role['settings']);
}
$dbFarmRolesList[] = $dbFarmRole;
$newFarmRolesList[] = $dbFarmRole->ID;
}
}
if (!$this->getParam('roleUpdate')) {
foreach ($dbFarm->GetFarmRoles() as $dbFarmRole) {
if (!$dbFarmRole->NewRoleID && !in_array($dbFarmRole->ID, $newFarmRolesList)) {
$dbFarmRole->Delete();
}
}
}
$dbFarm->save();
if (!$client->GetSettingValue(CLIENT_SETTINGS::DATE_FARM_CREATED)) {
$client->SetSettingValue(CLIENT_SETTINGS::DATE_FARM_CREATED, time());
}
if ($this->request->isFarmAllowed($dbFarm, Acl::PERM_FARMS_LAUNCH_TERMINATE) && $this->getParam('launch')) {
$this->user->getPermissions()->validate($dbFarm);
$dbFarm->isLocked();
Scalr::FireEvent($dbFarm->ID, new FarmLaunchedEvent(true, $this->user->id));
$this->response->success('Farm successfully saved and launched');
} else {
$this->response->success('Farm successfully saved');
}
$this->response->data(array('farmId' => $dbFarm->ID, 'isNewFarm' => $bNew));
}
示例12: xBuildAction
//.........这里部分代码省略.........
}
if (!$Validator->IsNotEmpty($dbFarm->Name)) {
throw new Exception(_("Farm name required"));
}
$dbFarm->save();
if (!$dbFarm->GetSetting(DBFarm::SETTING_CRYPTO_KEY)) {
$dbFarm->SetSetting(DBFarm::SETTING_CRYPTO_KEY, Scalr::GenerateRandomKey(40));
}
$usedPlatforms = array();
$dbFarmRolesList = array();
$newFarmRolesList = array();
foreach ($this->getParam('roles') as $role) {
if ($role['farm_role_id']) {
$update = true;
$dbFarmRole = DBFarmRole::LoadByID($role['farm_role_id']);
$dbRole = DBRole::loadById($dbFarmRole->RoleID);
$role['role_id'] = $dbFarmRole->RoleID;
} else {
$update = false;
$dbRole = DBRole::loadById($role['role_id']);
$dbFarmRole = $dbFarm->AddRole($dbRole, $role['platform'], $role['cloud_location'], (int) $role['launch_index']);
}
if ($dbRole->hasBehavior(ROLE_BEHAVIORS::RABBITMQ)) {
$role['settings'][DBFarmRole::SETTING_SCALING_MAX_INSTANCES] = $role['settings'][DBFarmRole::SETTING_SCALING_MIN_INSTANCES];
}
if ($dbFarmRole->NewRoleID) {
continue;
}
if ($update) {
$dbFarmRole->LaunchIndex = (int) $role['launch_index'];
$dbFarmRole->Save();
}
$usedPlatforms[$role['platform']] = 1;
$oldRoleSettings = $dbFarmRole->GetAllSettings();
foreach ($role['scaling_settings'] as $k => $v) {
$dbFarmRole->SetSetting($k, $v);
}
foreach ($role['settings'] as $k => $v) {
$dbFarmRole->SetSetting($k, $v);
}
/****** Scaling settings ******/
$scalingManager = new Scalr_Scaling_Manager($dbFarmRole);
$scalingManager->setFarmRoleMetrics($role['scaling']);
//TODO: optimize this code...
$this->db->Execute("DELETE FROM farm_role_scaling_times WHERE farm_roleid=?", array($dbFarmRole->ID));
// 5 = Time based scaling -> move to constants
if ($role['scaling'][5]) {
foreach ($role['scaling'][5] as $scal_period) {
$chunks = explode(":", $scal_period['id']);
$this->db->Execute("INSERT INTO farm_role_scaling_times SET\n\t\t\t\t\t\tfarm_roleid\t\t= ?,\n\t\t\t\t\t\tstart_time\t\t= ?,\n\t\t\t\t\t\tend_time\t\t= ?,\n\t\t\t\t\t\tdays_of_week\t= ?,\n\t\t\t\t\t\tinstances_count\t= ?\n\t\t\t\t\t", array($dbFarmRole->ID, $chunks[0], $chunks[1], $chunks[2], $chunks[3]));
}
}
/*****************/
/* Update role params */
$dbFarmRole->SetParameters($role['params']);
/* End of role params management */
/* Add script options to databse */
$dbFarmRole->SetScripts($role['scripting']);
/* End of scripting section */
/* Add services configuration */
$dbFarmRole->SetServiceConfigPresets($role['config_presets']);
/* End of scripting section */
Scalr_Helpers_Dns::farmUpdateRoleSettings($dbFarmRole, $oldRoleSettings, $role['settings']);
foreach (Scalr_Role_Behavior::getListForFarmRole($dbFarmRole) as $behavior) {
$behavior->onFarmSave($dbFarm, $dbFarmRole);
}
/**
* Platfrom specified updates
*/
if ($dbFarmRole->Platform == SERVER_PLATFORMS::EC2) {
Modules_Platforms_Ec2_Helpers_Ebs::farmUpdateRoleSettings($dbFarmRole, $oldRoleSettings, $role['settings']);
Modules_Platforms_Ec2_Helpers_Eip::farmUpdateRoleSettings($dbFarmRole, $oldRoleSettings, $role['settings']);
Modules_Platforms_Ec2_Helpers_Elb::farmUpdateRoleSettings($dbFarmRole, $oldRoleSettings, $role['settings']);
}
$dbFarmRolesList[] = $dbFarmRole;
$newFarmRolesList[] = $dbFarmRole->ID;
}
if (!$this->getParam('roleUpdate')) {
foreach ($dbFarm->GetFarmRoles() as $dbFarmRole) {
if (!$dbFarmRole->NewRoleID && !in_array($dbFarmRole->ID, $newFarmRolesList)) {
$dbFarmRole->Delete();
}
}
}
if ($usedPlatforms[SERVER_PLATFORMS::CLOUDSTACK]) {
Modules_Platforms_Cloudstack_Helpers_Cloudstack::farmSave($dbFarm, $dbFarmRolesList);
}
if ($usedPlatforms[SERVER_PLATFORMS::EC2]) {
Modules_Platforms_Ec2_Helpers_Ec2::farmSave($dbFarm, $dbFarmRolesList);
}
if ($usedPlatforms[SERVER_PLATFORMS::EUCALYPTUS]) {
Modules_Platforms_Eucalyptus_Helpers_Eucalyptus::farmSave($dbFarm, $dbFarmRolesList);
}
$dbFarm->save();
if (!$client->GetSettingValue(CLIENT_SETTINGS::DATE_FARM_CREATED)) {
$client->SetSettingValue(CLIENT_SETTINGS::DATE_FARM_CREATED, time());
}
$this->response->success('Farm successfully saved');
$this->response->data(array('farmId' => $dbFarm->ID));
}
示例13: xBuildAction
//.........这里部分代码省略.........
$v = str_replace(array_keys($virtualFarmRoles), array_values($virtualFarmRoles), $v);
}
});
array_walk_recursive($role['settings'], function (&$v, $k) use($virtualFarmRoles) {
if (is_string($v)) {
$v = str_replace(array_keys($virtualFarmRoles), array_values($virtualFarmRoles), $v);
}
});
}
//Audit log start
//!TODO Enable Audit log for Farm Builder
// $auditLog = $this->getEnvironment()->auditLog;
// $docRoleSettingsBefore = new FarmRoleSettingsDocument($oldRoleSettings);
// $docRoleSettingsBefore['farmroleid'] = $dbFarmRole->ID;
// $docRoleSettings = new FarmRoleSettingsDocument(array_merge((array)$role['scaling_settings'], (array)$role['settings']));
// $docRoleSettings['farmroleid'] = $dbFarmRole->ID;
$dbFarmRole->ClearSettings("chef.");
if (!empty($role['scaling_settings']) && is_array($role['scaling_settings'])) {
foreach ($role['scaling_settings'] as $k => $v) {
$dbFarmRole->SetSetting($k, $v, DBFarmRole::TYPE_CFG);
}
}
foreach ($role['settings'] as $k => $v) {
$dbFarmRole->SetSetting($k, $v, DBFarmRole::TYPE_CFG);
}
// $auditLog->log('Farm has been saved', array(AuditLogTags::TAG_UPDATE), $docRoleSettings, $docRoleSettingsBefore);
// unset($docRoleSettings);
// unset($docRoleSettingsBefore);
//Audit log finish
/****** Scaling settings ******/
$scalingManager = new Scalr_Scaling_Manager($dbFarmRole);
$scalingManager->setFarmRoleMetrics(is_array($role['scaling']) ? $role['scaling'] : array());
//TODO: optimize this code...
$this->db->Execute("DELETE FROM farm_role_scaling_times WHERE farm_roleid=?", array($dbFarmRole->ID));
// 5 = Time based scaling -> move to constants
if ($role['scaling'][5]) {
foreach ($role['scaling'][5] as $scal_period) {
$chunks = explode(":", $scal_period['id']);
$this->db->Execute("INSERT INTO farm_role_scaling_times SET\n farm_roleid\t\t= ?,\n start_time\t\t= ?,\n end_time\t\t= ?,\n days_of_week\t= ?,\n instances_count\t= ?\n ", array($dbFarmRole->ID, $chunks[0], $chunks[1], $chunks[2], $chunks[3]));
}
}
/*****************/
/* Update role params */
$dbFarmRole->SetParameters((array) $role['params']);
/* End of role params management */
/* Add script options to databse */
$dbFarmRole->SetScripts($scripts, (array) $role['scripting_params']);
/* End of scripting section */
/* Add services configuration */
$dbFarmRole->SetServiceConfigPresets((array) $role['config_presets']);
/* End of scripting section */
/* Add storage configuration */
//try {
$dbFarmRole->getStorage()->setConfigs((array) $role['storages']['configs']);
//} catch (FarmRoleStorageException $e) {
// $errors[] = array('farm_role_id' => 1, 'tab' => 'storage', 'error' => $e->getMessage());
//}
$farmRoleVariables->setValues($role['variables'], $dbFarmRole->GetRoleID(), $dbFarm->ID, $dbFarmRole->ID, '', false);
Scalr_Helpers_Dns::farmUpdateRoleSettings($dbFarmRole, $oldRoleSettings, $role['settings']);
foreach (Scalr_Role_Behavior::getListForFarmRole($dbFarmRole) as $behavior) {
$behavior->onFarmSave($dbFarm, $dbFarmRole);
}
/**
* Platfrom specified updates
*/
if ($dbFarmRole->Platform == SERVER_PLATFORMS::EC2) {
Modules_Platforms_Ec2_Helpers_Ebs::farmUpdateRoleSettings($dbFarmRole, $oldRoleSettings, $role['settings']);
Modules_Platforms_Ec2_Helpers_Eip::farmUpdateRoleSettings($dbFarmRole, $oldRoleSettings, $role['settings']);
Modules_Platforms_Ec2_Helpers_Elb::farmUpdateRoleSettings($dbFarmRole, $oldRoleSettings, $role['settings']);
}
if (in_array($dbFarmRole->Platform, array(SERVER_PLATFORMS::IDCF, SERVER_PLATFORMS::CLOUDSTACK))) {
Modules_Platforms_Cloudstack_Helpers_Cloudstack::farmUpdateRoleSettings($dbFarmRole, $oldRoleSettings, $role['settings']);
}
$dbFarmRolesList[] = $dbFarmRole;
$newFarmRolesList[] = $dbFarmRole->ID;
}
}
if (!$this->getParam('roleUpdate')) {
foreach ($dbFarm->GetFarmRoles() as $dbFarmRole) {
if (!$dbFarmRole->NewRoleID && !in_array($dbFarmRole->ID, $newFarmRolesList)) {
$dbFarmRole->Delete();
}
}
}
if ($usedPlatforms[SERVER_PLATFORMS::CLOUDSTACK]) {
Modules_Platforms_Cloudstack_Helpers_Cloudstack::farmSave($dbFarm, $dbFarmRolesList);
}
if ($usedPlatforms[SERVER_PLATFORMS::EC2]) {
Modules_Platforms_Ec2_Helpers_Ec2::farmSave($dbFarm, $dbFarmRolesList);
}
if ($usedPlatforms[SERVER_PLATFORMS::EUCALYPTUS]) {
Modules_Platforms_Eucalyptus_Helpers_Eucalyptus::farmSave($dbFarm, $dbFarmRolesList);
}
$dbFarm->save();
if (!$client->GetSettingValue(CLIENT_SETTINGS::DATE_FARM_CREATED)) {
$client->SetSettingValue(CLIENT_SETTINGS::DATE_FARM_CREATED, time());
}
$this->response->success('Farm successfully saved');
$this->response->data(array('farmId' => $dbFarm->ID));
}
示例14: OnBeforeHostTerminate
public function OnBeforeHostTerminate(BeforeHostTerminateEvent $event)
{
$servers = DBFarm::LoadByID($this->FarmID)->GetServersByFilter(array('status' => array(SERVER_STATUS::INIT, SERVER_STATUS::RUNNING, SERVER_STATUS::PENDING_TERMINATE)));
foreach ($servers as $DBServer) {
$msg = new Scalr_Messaging_Msg_BeforeHostTerminate($event->DBServer->GetFarmRoleObject()->GetRoleObject()->getBehaviors(), $event->DBServer->GetFarmRoleObject()->GetRoleObject()->name, $event->DBServer->localIp, $event->DBServer->remoteIp);
$msg->farmRoleId = $event->DBServer->farmRoleId;
$msg->serverId = $event->DBServer->serverId;
$msg->serverIndex = $event->DBServer->serverIndex;
$msg->scripts = $this->getScripts($event, $event->DBServer, $DBServer);
if ($event->DBServer->farmRoleId != 0) {
foreach (Scalr_Role_Behavior::getListForFarmRole($event->DBServer->GetFarmRoleObject()) as $behavior) {
$msg = $behavior->extendMessage($msg, $event->DBServer);
}
}
$DBServer->SendMessage($msg, false, true);
}
try {
if ($event->DBServer->GetFarmRoleObject()->GetRoleObject()->getDbMsrBehavior()) {
$this->sendPromoteToMasterMessage($event);
}
} catch (Exception $e) {
}
}
示例15: GetServerSecurityGroupsList
//.........这里部分代码省略.........
}
/**** Security group for role builder ****/
if ($DBServer->status == SERVER_STATUS::TEMPORARY) {
if (!$aws_sgroups['scalr-rb-system']) {
try {
$EC2Client->CreateSecurityGroup('scalr-rb-system', _("Security group for Roles Builder"));
} catch (Exception $e) {
throw new Exception("GetServerSecurityGroupsList failed: {$e->getMessage()}");
}
$IpPermissionSet = new IpPermissionSetType();
$group_rules = array(array('rule' => 'tcp:22:22:0.0.0.0/0'), array('rule' => 'tcp:8013:8013:0.0.0.0/0'), array('rule' => 'udp:8014:8014:0.0.0.0/0'), array('rule' => 'icmp:-1:-1:0.0.0.0/0'));
foreach ($group_rules as $rule) {
$group_rule = explode(":", $rule["rule"]);
$IpPermissionSet->AddItem($group_rule[0], $group_rule[1], $group_rule[2], null, array($group_rule[3]));
}
// Create security group
$EC2Client->AuthorizeSecurityGroupIngress($DBServer->GetEnvironmentObject()->getPlatformConfigValue(self::ACCOUNT_ID), 'scalr-rb-system', $IpPermissionSet);
}
array_push($retval, 'scalr-rb-system');
return $retval;
}
/**********************************/
// Add Role security group
$role_sec_group = CONFIG::$SECGROUP_PREFIX . $DBServer->GetFarmRoleObject()->GetRoleObject()->name;
$partent_sec_group = CONFIG::$SECGROUP_PREFIX . $DBServer->GetFarmRoleObject()->GetRoleObject()->getRoleHistory();
$new_role_sec_group = "scalr-role." . $DBServer->GetFarmRoleObject()->ID;
/****
* SCALR IP POOL SECURITY GROUP
*/
$scalrSecuritySettings = @parse_ini_file(APPPATH . '/etc/security.ini', true);
if (!$aws_sgroups[$scalrSecuritySettings['ec2']['security_group_name']]) {
try {
$EC2Client->CreateSecurityGroup($scalrSecuritySettings['ec2']['security_group_name'], "Security rules needed by Scalr");
} catch (Exception $e) {
throw new Exception("GetServerSecurityGroupsList failed on scalr.ip-pool: {$e->getMessage()}");
}
$sRules = array(array('rule' => 'tcp:8008:8013:0.0.0.0/0'), array('rule' => 'udp:8014:8014:0.0.0.0/0'), array('rule' => 'tcp:3306:3306:0.0.0.0/0'));
$IpPermissionSet = new IpPermissionSetType();
foreach ($scalrSecuritySettings['ip-pool'] as $name => $ip) {
foreach ($sRules as $rule) {
$group_rule = explode(":", $rule["rule"]);
$IpPermissionSet->AddItem($group_rule[0], $group_rule[1], $group_rule[2], null, array($ip));
}
}
// Create security group
$EC2Client->AuthorizeSecurityGroupIngress($DBServer->GetEnvironmentObject()->getPlatformConfigValue(self::ACCOUNT_ID), $scalrSecuritySettings['ec2']['security_group_name'], $IpPermissionSet);
}
array_push($retval, $scalrSecuritySettings['ec2']['security_group_name']);
/**********************************************/
if ($aws_sgroups[strtolower($role_sec_group)]) {
// OLD System. scalr.%ROLENAME% . Nothing to do
array_push($retval, $role_sec_group);
} else {
if ($aws_sgroups[strtolower($new_role_sec_group)]) {
// NEW System. scalr-role.%FARM_ROLE_ID% . Nothing to do
array_push($retval, $new_role_sec_group);
} else {
try {
$EC2Client->CreateSecurityGroup($new_role_sec_group, sprintf("Security group for FarmRoleID #%s on FarmID #%s", $DBServer->GetFarmRoleObject()->ID, $DBServer->farmId));
} catch (Exception $e) {
throw new Exception("GetServerSecurityGroupsList failed: {$e->getMessage()}");
}
$IpPermissionSet = new IpPermissionSetType();
$group_rules = $DBServer->GetFarmRoleObject()->GetRoleObject()->getSecurityRules();
//
// Check parent security group
//
if (count($group_rules) == 0) {
$group_rules = array(array('rule' => 'tcp:22:22:0.0.0.0/0'), array('rule' => 'icmp:-1:-1:0.0.0.0/0'));
if ($DBServer->GetFarmRoleObject()->GetRoleObject()->hasBehavior(ROLE_BEHAVIORS::MYSQL)) {
$group_rules[] = array('rule' => 'tcp:3306:3306:0.0.0.0/0');
}
if ($DBServer->GetFarmRoleObject()->GetRoleObject()->hasBehavior(ROLE_BEHAVIORS::CASSANDRA)) {
$group_rules[] = array('rule' => 'tcp:7000:7000:0.0.0.0/0');
$group_rules[] = array('rule' => 'tcp:9160:9160:0.0.0.0/0');
}
foreach (Scalr_Role_Behavior::getListForFarmRole($DBServer->GetFarmRoleObject()) as $bObj) {
$bRules = $bObj->getSecurityRules();
foreach ($bRules as $r) {
if ($r) {
$group_rules[] = array('rule' => $r);
}
}
}
}
foreach ($group_rules as $rule) {
$group_rule = explode(":", $rule["rule"]);
$IpPermissionSet->AddItem($group_rule[0], $group_rule[1], $group_rule[2], null, array($group_rule[3]));
}
//Create SG rule to enable communication between instances inside this role
$IpPermissionSet->AddItem('tcp', 0, 65535, array('userId' => $DBServer->GetEnvironmentObject()->getPlatformConfigValue(self::ACCOUNT_ID), 'groupName' => $new_role_sec_group));
$IpPermissionSet->AddItem('udp', 0, 65535, array('userId' => $DBServer->GetEnvironmentObject()->getPlatformConfigValue(self::ACCOUNT_ID), 'groupName' => $new_role_sec_group));
// Create security group
$EC2Client->AuthorizeSecurityGroupIngress($DBServer->GetEnvironmentObject()->getPlatformConfigValue(self::ACCOUNT_ID), $new_role_sec_group, $IpPermissionSet);
$DBServer->GetFarmRoleObject()->SetSetting(DBFarmRole::SETTING_AWS_SECURITY_GROUP, $new_role_sec_group);
array_push($retval, $new_role_sec_group);
}
}
return $retval;
}