GetRoleObject() public method

public GetRoleObject ( ) : DBRole
return DBRole
示例#1
0
文件: Info.php 项目: rickb838/scalr
 public function setMsrSettings($settings)
 {
     if ($settings->volumeConfig) {
         try {
             $storageVolume = Scalr_Storage_Volume::init();
             try {
                 $storageVolume->loadById($settings->volumeConfig->id);
                 $storageVolume->setConfig($settings->volumeConfig);
                 $storageVolume->save();
             } catch (Exception $e) {
                 if (strpos($e->getMessage(), 'not found')) {
                     $storageVolume->loadBy(array('id' => $settings->volumeConfig->id, 'client_id' => $this->dbServer->clientId, 'env_id' => $this->dbServer->envId, 'name' => "'{$this->databaseType}' data volume", 'type' => $this->dbFarmRole->GetSetting(Scalr_Db_Msr::DATA_STORAGE_ENGINE), 'platform' => $this->dbServer->platform, 'size' => $settings->volumeConfig->size, 'fstype' => $settings->volumeConfig->fstype, 'purpose' => $this->databaseType, 'farm_roleid' => $this->dbFarmRole->ID, 'server_index' => $this->dbServer->index));
                     $storageVolume->setConfig($settings->volumeConfig);
                     $storageVolume->save(true);
                 } else {
                     throw $e;
                 }
             }
             $this->dbFarmRole->SetSetting(Scalr_Db_Msr::VOLUME_ID, $storageVolume->id, DBFarmRole::TYPE_LCL);
         } catch (Exception $e) {
             $this->logger->error(new FarmLogMessage($this->dbServer->farmId, "Cannot save storage volume: {$e->getMessage()}"));
         }
     }
     if ($settings->snapshotConfig) {
         try {
             $storageSnapshot = Scalr_Model::init(Scalr_Model::STORAGE_SNAPSHOT);
             try {
                 $storageSnapshot->loadById($settings->snapshotConfig->id);
                 $storageSnapshot->setConfig($settings->snapshotConfig);
                 $storageSnapshot->save();
             } catch (Exception $e) {
                 if (strpos($e->getMessage(), 'not found')) {
                     $storageSnapshot->loadBy(array('id' => $settings->snapshotConfig->id, 'client_id' => $this->dbServer->clientId, 'farm_id' => $this->dbServer->farmId, 'farm_roleid' => $this->dbServer->farmRoleId, 'env_id' => $this->dbServer->envId, 'name' => sprintf(_("'{$this->databaseType}' data bundle #%s"), $settings->snapshotConfig->id), 'type' => $this->dbFarmRole->GetSetting(Scalr_Db_Msr::DATA_STORAGE_ENGINE), 'platform' => $this->dbServer->platform, 'description' => sprintf(_("'{$this->databaseType}' data bundle created on Farm '%s' -> Role '%s'"), $this->dbFarmRole->GetFarmObject()->name, $this->dbFarmRole->GetRoleObject()->name), 'service' => $this->databaseType));
                     $storageSnapshot->setConfig($settings->snapshotConfig);
                     $storageSnapshot->save(true);
                 } else {
                     throw $e;
                 }
             }
             $this->dbFarmRole->SetSetting(Scalr_Db_Msr::SNAPSHOT_ID, $storageSnapshot->id, DBFarmRole::TYPE_LCL);
         } catch (Exception $e) {
             $this->logger->error(new FarmLogMessage($event->DBServer->farmId, "Cannot save storage snapshot: {$e->getMessage()}"));
         }
     }
 }
示例#2
0
 private function getDbAccessDetails(DBFarmRole $dbFarmRole)
 {
     $retval = array('username' => 'scalr', 'password' => '', 'dns' => false);
     if ($dbFarmRole->GetRoleObject()->hasBehavior(ROLE_BEHAVIORS::POSTGRESQL)) {
         $retval['password'] = $dbFarmRole->GetSetting(Scalr_Db_Msr_Postgresql::ROOT_PASSWORD);
         $behavior = ROLE_BEHAVIORS::POSTGRESQL;
     } elseif ($dbFarmRole->GetRoleObject()->hasBehavior(ROLE_BEHAVIORS::REDIS)) {
         if ($dbFarmRole->GetSetting(Scalr_Db_Msr_Redis::USE_PASSWORD) == 1) {
             $ports = @json_decode($dbFarmRole->GetSetting(Scalr_Db_Msr_Redis::PORTS_ARRAY));
             $passwords = @json_decode($dbFarmRole->GetSetting(Scalr_Db_Msr_Redis::PASSWD_ARRAY));
             if (!$ports && !$passwords) {
                 $retval['password'] = $dbFarmRole->GetSetting(Scalr_Db_Msr_Redis::MASTER_PASSWORD);
             } else {
                 foreach ($ports as $i => $port) {
                     $retval['password'] .= "Port {$port}: {$passwords[$i]}<br>";
                 }
             }
         } else {
             $retval['password'] = '******';
         }
         $behavior = ROLE_BEHAVIORS::REDIS;
     } elseif ($dbFarmRole->GetRoleObject()->hasBehavior(ROLE_BEHAVIORS::MYSQL2)) {
         $retval['password'] = $dbFarmRole->GetSetting(Scalr_Db_Msr_Mysql2::ROOT_PASSWORD);
         $behavior = ROLE_BEHAVIORS::MYSQL2;
     } elseif ($dbFarmRole->GetRoleObject()->hasBehavior(ROLE_BEHAVIORS::PERCONA)) {
         $retval['password'] = $dbFarmRole->GetSetting(Scalr_Db_Msr_Percona::ROOT_PASSWORD);
         $behavior = ROLE_BEHAVIORS::PERCONA;
     } elseif ($dbFarmRole->GetRoleObject()->hasBehavior(ROLE_BEHAVIORS::MARIADB)) {
         $retval['password'] = $dbFarmRole->GetSetting(Scalr_Db_Msr_Mariadb::ROOT_PASSWORD);
         $behavior = ROLE_BEHAVIORS::MARIADB;
     }
     if (\Scalr::config('scalr.dns.static.enabled')) {
         $retval['dns'] = array('master' => array('private' => "int.master.{$behavior}.{$dbFarmRole->GetFarmObject()->Hash}." . \Scalr::config('scalr.dns.static.domain_name'), 'public' => "ext.master.{$behavior}.{$dbFarmRole->GetFarmObject()->Hash}." . \Scalr::config('scalr.dns.static.domain_name')), 'slave' => array('private' => "int.slave.{$behavior}.{$dbFarmRole->GetFarmObject()->Hash}." . \Scalr::config('scalr.dns.static.domain_name'), 'public' => "ext.slave.{$behavior}.{$dbFarmRole->GetFarmObject()->Hash}." . \Scalr::config('scalr.dns.static.domain_name')));
     }
     return $retval;
 }
 /**
  * 
  * @param string $platform (From SERVER_PLATFORMS class)
  * @param integer $farmid
  * @param integer $farm_roleid
  * @param integer $index
  * @return void
  */
 public function __construct($platform, DBFarmRole $DBFarmRole, $index = null, $role_id = null)
 {
     $this->platform = $platform;
     $this->dbFarmRole = $DBFarmRole;
     $this->index = $index;
     $this->roleId = $role_id === null ? $this->dbFarmRole->RoleID : $role_id;
     if ($DBFarmRole) {
         $this->envId = $DBFarmRole->GetFarmObject()->EnvID;
     }
     //Refletcion
     $Reflect = new ReflectionClass(DBServer::$platformPropsClasses[$this->platform]);
     foreach ($Reflect->getConstants() as $k => $v) {
         $this->platformProps[] = $v;
     }
     if ($DBFarmRole) {
         switch ($this->platform) {
             case SERVER_PLATFORMS::NIMBULA:
                 break;
             case SERVER_PLATFORMS::EUCALYPTUS:
                 $this->SetProperties(array(EUCA_SERVER_PROPERTIES::REGION => $DBFarmRole->CloudLocation));
                 break;
             case SERVER_PLATFORMS::OPENSTACK:
                 $this->SetProperties(array(OPENSTACK_SERVER_PROPERTIES::CLOUD_LOCATION => $DBFarmRole->CloudLocation));
                 break;
             case SERVER_PLATFORMS::RACKSPACE:
                 $this->SetProperties(array(RACKSPACE_SERVER_PROPERTIES::DATACENTER => $DBFarmRole->CloudLocation));
                 break;
             case SERVER_PLATFORMS::CLOUDSTACK:
                 $this->SetProperties(array(CLOUDSTACK_SERVER_PROPERTIES::CLOUD_LOCATION => $DBFarmRole->CloudLocation));
                 break;
             case SERVER_PLATFORMS::EC2:
                 $this->SetProperties(array(EC2_SERVER_PROPERTIES::AVAIL_ZONE => $DBFarmRole->GetSetting(DBFarmRole::SETTING_AWS_AVAIL_ZONE), EC2_SERVER_PROPERTIES::REGION => $DBFarmRole->CloudLocation));
                 break;
             case SERVER_PLATFORMS::RDS:
                 $this->SetProperties(array(RDS_SERVER_PROPERTIES::AVAIL_ZONE => $DBFarmRole->GetSetting(DBFarmRole::SETTING_RDS_AVAIL_ZONE), RDS_SERVER_PROPERTIES::REGION => $DBFarmRole->CloudLocation, RDS_SERVER_PROPERTIES::INSTANCE_CLASS => $DBFarmRole->GetSetting(DBFarmRole::SETTING_RDS_INSTANCE_CLASS), RDS_SERVER_PROPERTIES::STORAGE => $DBFarmRole->GetSetting(DBFarmRole::SETTING_RDS_STORAGE), RDS_SERVER_PROPERTIES::INSTANCE_ENGINE => $DBFarmRole->GetSetting(DBFarmRole::SETTING_RDS_INSTANCE_ENGINE), RDS_SERVER_PROPERTIES::MASTER_USER => $DBFarmRole->GetSetting(DBFarmRole::SETTING_RDS_MASTER_USER), RDS_SERVER_PROPERTIES::MASTER_PASS => $DBFarmRole->GetSetting(DBFarmRole::SETTING_RDS_MASTER_PASS), RDS_SERVER_PROPERTIES::MULTI_AZ => $DBFarmRole->GetSetting(DBFarmRole::SETTING_RDS_MULTI_AZ), RDS_SERVER_PROPERTIES::PORT => $DBFarmRole->GetSetting(DBFarmRole::SETTING_RDS_PORT)));
                 break;
         }
         $this->SetProperties(array(SERVER_PROPERTIES::SZR_VESION => $DBFarmRole->GetRoleObject()->szrVersion));
     } else {
         $this->SetProperties(array(SERVER_PROPERTIES::SZR_VESION => '0.5.0'));
     }
 }
示例#4
0
 public function makeDecision(DBFarmRole $dbFarmRole, Scalr_Scaling_FarmRoleMetric $farmRoleMetric, $isInvert = false)
 {
     if ($farmRoleMetric->lastValue > $farmRoleMetric->getSetting('max')) {
         $retval = Scalr_Scaling_Decision::UPSCALE;
     } elseif ($farmRoleMetric->lastValue < $farmRoleMetric->getSetting('min')) {
         $retval = Scalr_Scaling_Decision::DOWNSCALE;
     }
     if (!$retval) {
         return Scalr_Scaling_Decision::NOOP;
     } else {
         if ($isInvert) {
             if ($retval == Scalr_Scaling_Decision::UPSCALE) {
                 $retval = Scalr_Scaling_Decision::DOWNSCALE;
             } else {
                 $retval = Scalr_Scaling_Decision::UPSCALE;
             }
         }
         if ($retval == Scalr_Scaling_Decision::UPSCALE) {
             if ($dbFarmRole->GetRunningInstancesCount() + $dbFarmRole->GetPendingInstancesCount() >= $dbFarmRole->GetSetting(DBFarmRole::SETTING_SCALING_MAX_INSTANCES)) {
                 $retval = Scalr_Scaling_Decision::NOOP;
             }
         }
         if ($retval == Scalr_Scaling_Decision::DOWNSCALE) {
             if ($dbFarmRole->GetRunningInstancesCount() <= $dbFarmRole->GetSetting(DBFarmRole::SETTING_SCALING_MIN_INSTANCES)) {
                 $retval = Scalr_Scaling_Decision::NOOP;
             }
         }
         $isSzr = $dbFarmRole->GetRoleObject()->isSupported("0.5");
         if ($retval == Scalr_Scaling_Decision::UPSCALE && ($dbFarmRole->GetPendingInstancesCount() > 5 && !$isSzr)) {
             return Scalr_Scaling_Decision::NOOP;
         } else {
             //if ($isSzr && $dbFarmRole->GetPendingInstancesCount() > 10)
             //return Scalr_Scaling_Decision::NOOP;
             //else
             return $retval;
         }
     }
 }
示例#5
0
文件: MongoDB.php 项目: recipe/scalr
 public function setSnapshotConfig($snapshotConfig, DBFarmRole $dbFarmRole, DBServer $dbServer)
 {
     try {
         $storageSnapshot = Scalr_Storage_Snapshot::init();
         try {
             $storageSnapshot->loadById($snapshotConfig->id);
             $storageSnapshot->setConfig($snapshotConfig);
             $storageSnapshot->save();
         } catch (Exception $e) {
             if (strpos($e->getMessage(), 'not found')) {
                 $storageSnapshot->loadBy(array('id' => $snapshotConfig->id, 'client_id' => $dbServer->clientId, 'farm_id' => $dbServer->farmId, 'farm_roleid' => $dbServer->farmRoleId, 'env_id' => $dbServer->envId, 'name' => sprintf(_("%s data bundle #%s"), $this->behavior, $snapshotConfig->id), 'type' => $dbFarmRole->GetSetting(static::ROLE_DATA_STORAGE_ENGINE), 'platform' => $dbServer->platform, 'description' => sprintf(_("{$this->behavior} data bundle created on Farm '%s' -> Role '%s'"), $dbFarmRole->GetFarmObject()->Name, $dbFarmRole->GetRoleObject()->name), 'service' => $this->behavior));
                 $storageSnapshot->setConfig($snapshotConfig);
                 $storageSnapshot->save(true);
             } else {
                 throw $e;
             }
         }
         $this->db->Execute("INSERT INTO services_mongodb_snapshots_map SET\n                    farm_roleid = ?,\n                    shard_index = ?,\n                    snapshot_id = ? ON DUPLICATE KEY UPDATE snapshot_id = ?\n                ", array($dbFarmRole->ID, $dbServer->GetProperty(self::SERVER_SHARD_INDEX), $snapshotConfig->id, $snapshotConfig->id));
     } catch (Exception $e) {
         $this->logger->error(new FarmLogMessage($dbFarmRole->FarmID, "Cannot save storage volume: {$e->getMessage()}"));
     }
 }
示例#6
0
 public function setSnapshotConfig($snapshotConfig, DBFarmRole $dbFarmRole, DBServer $dbServer)
 {
     try {
         $storageSnapshot = Scalr_Storage_Snapshot::init();
         try {
             $storageSnapshot->loadById($snapshotConfig->id);
             $storageSnapshot->setConfig($snapshotConfig);
             $storageSnapshot->save();
         } catch (Exception $e) {
             if (strpos($e->getMessage(), 'not found')) {
                 $storageSnapshot->loadBy(array('id' => $snapshotConfig->id, 'client_id' => $dbServer->clientId, 'farm_id' => $dbServer->farmId, 'farm_roleid' => $dbServer->farmRoleId, 'env_id' => $dbServer->envId, 'name' => sprintf(_("%s data bundle #%s"), $this->behavior, $snapshotConfig->id), 'type' => $dbFarmRole->GetSetting(static::ROLE_DATA_STORAGE_ENGINE), 'platform' => $dbServer->platform, 'description' => sprintf(_("{$this->behavior} data bundle created on Farm '%s' -> Role '%s'"), $dbFarmRole->GetFarmObject()->Name, $dbFarmRole->GetRoleObject()->name), 'service' => $this->behavior));
                 $storageSnapshot->setConfig($snapshotConfig);
                 $storageSnapshot->save(true);
             } else {
                 throw $e;
             }
         }
         $dbFarmRole->SetSetting(static::ROLE_SNAPSHOT_ID, $storageSnapshot->id, DBFarmRole::TYPE_LCL);
     } catch (Exception $e) {
         $this->logger->error(new FarmLogMessage($dbFarmRole->FarmID, "Cannot save storage volume: {$e->getMessage()}"));
     }
 }
示例#7
0
 private function performDbMsrAction($action, DBFarmRole $dbFarmRole, $tz)
 {
     $timeouted = false;
     if ($dbFarmRole->GetSetting(Scalr_Db_Msr::getConstant("DATA_{$action}_ENABLED")) && $dbFarmRole->GetSetting(Scalr_Db_Msr::getConstant("DATA_{$action}_EVERY")) != 0) {
         if ($dbFarmRole->GetSetting(Scalr_Db_Msr::getConstant("DATA_{$action}_IS_RUNNING")) == 1) {
             // Wait for timeout time * 2 (Example: NIVs problem with big mysql snapshots)
             // We must wait for running bundle process.
             $timeout = $dbFarmRole->GetSetting(Scalr_Db_Msr::getConstant("DATA_{$action}_EVERY")) * (3600 * 2);
             $lastTs = $dbFarmRole->GetSetting(Scalr_Db_Msr::getConstant("DATA_{$action}_RUNNING_TS"));
             if ($lastTs + $timeout < time()) {
                 $timeouted = true;
             }
             if ($timeouted) {
                 $dbFarmRole->SetSetting(Scalr_Db_Msr::getConstant("DATA_{$action}_IS_RUNNING"), 0, DBFarmRole::TYPE_LCL);
             }
         } else {
             /*
              * Check bundle window
              */
             $period = $dbFarmRole->GetSetting(Scalr_Db_Msr::getConstant("DATA_{$action}_EVERY"));
             $timeout = $period * 3600;
             $lastActionTime = $dbFarmRole->GetSetting(Scalr_Db_Msr::getConstant("DATA_{$action}_LAST_TS"));
             $performAction = false;
             if ($period % 24 == 0) {
                 if ($lastActionTime) {
                     $days = $period / 24;
                     $dateTime = new DateTime(null, new DateTimeZone($tz));
                     $currentDate = (int) $dateTime->format("Ymd");
                     $dateTime->setTimestamp(strtotime("+{$days} day", $lastActionTime));
                     $nextDate = (int) $dateTime->format("Ymd");
                     if ($nextDate > $currentDate) {
                         return;
                     }
                 }
                 $pbwFrom = (int) ($dbFarmRole->GetSetting(Scalr_Db_Msr::getConstant("DATA_{$action}_TIMEFRAME_START_HH")) . $dbFarmRole->GetSetting(Scalr_Db_Msr::getConstant("DATA_{$action}_TIMEFRAME_START_MM")));
                 $pbwTo = (int) ($dbFarmRole->GetSetting(Scalr_Db_Msr::getConstant("DATA_{$action}_TIMEFRAME_END_HH")) . $dbFarmRole->GetSetting(Scalr_Db_Msr::getConstant("DATA_{$action}_TIMEFRAME_END_MM")));
                 if ($pbwFrom && $pbwTo) {
                     $dateTime = new DateTime(null, new DateTimeZone($tz));
                     $currentTime = (int) $dateTime->format("Hi");
                     //$current_time = (int)date("Hi");
                     //BUG HERE: 22:00 - 6:00 - doesn't work
                     if ($pbwFrom <= $currentTime && $pbwTo >= $currentTime) {
                         $performAction = true;
                     }
                 } else {
                     $performAction = true;
                 }
             } else {
                 //Check timeout
                 if ($lastActionTime + $timeout < time()) {
                     $performAction = true;
                 }
             }
             if ($performAction) {
                 $behavior = Scalr_Role_Behavior::loadByName($dbFarmRole->GetRoleObject()->getDbMsrBehavior());
                 if ($action == 'BUNDLE') {
                     $behavior->createDataBundle($dbFarmRole, array('compressor' => $dbFarmRole->GetSetting(Scalr_Role_DbMsrBehavior::ROLE_DATA_BUNDLE_COMPRESSION), 'useSlave' => $dbFarmRole->GetSetting(Scalr_Role_DbMsrBehavior::ROLE_DATA_BUNDLE_USE_SLAVE)));
                 }
                 if ($action == 'BACKUP') {
                     $behavior->createBackup($dbFarmRole);
                 }
             }
         }
     }
 }
示例#8
0
 public static function farmUpdateRoleSettings(DBFarmRole $DBFarmRole, $oldSettings, $newSettings)
 {
     try {
         $DBFarm = $DBFarmRole->GetFarmObject();
         $Client = Client::Load($DBFarm->ClientID);
         $AmazonELB = Scalr_Service_Cloud_Aws::newElb($DBFarmRole->CloudLocation, $DBFarm->GetEnvironmentObject()->getPlatformConfigValue(Modules_Platforms_Ec2::ACCESS_KEY), $DBFarm->GetEnvironmentObject()->getPlatformConfigValue(Modules_Platforms_Ec2::SECRET_KEY));
         // Load balancer settings
         if ($newSettings[DBFarmRole::SETTING_BALANCING_USE_ELB] == 1) {
             // Listeners
             $DBFarmRole->ClearSettings("lb.role.listener");
             $ELBListenersList = new ELBListenersList();
             $li = 0;
             foreach ($newSettings as $sk => $sv) {
                 if (stristr($sk, "lb.role.listener")) {
                     $li++;
                     $listener_chunks = explode("#", $sv);
                     $ELBListenersList->AddListener($listener_chunks[0], $listener_chunks[1], $listener_chunks[2], $listener_chunks[3]);
                     $DBFarmRole->SetSetting("lb.role.listener.{$li}", $sv);
                 }
             }
             $avail_zones = array();
             $avail_zones_setting_hash = "";
             foreach ($newSettings as $skey => $sval) {
                 if (preg_match("/^lb.avail_zone.(.*)?\$/", $skey, $macthes)) {
                     if ($macthes[1] != 'hash' && $macthes[1] != '.hash') {
                         if ($sval == 1) {
                             array_push($avail_zones, $macthes[1]);
                         }
                         $avail_zones_setting_hash .= "[{$macthes[1]}:{$sval}]";
                     }
                 }
             }
             if (!$DBFarmRole->GetSetting(DBFarmRole::SETTING_BALANCING_HOSTNAME)) {
                 $elb_name = sprintf("scalr-%s-%s", $DBFarm->Hash, rand(100, 999));
                 //CREATE NEW ELB
                 $elb_dns_name = $AmazonELB->CreateLoadBalancer($elb_name, $avail_zones, $ELBListenersList);
                 if ($elb_dns_name) {
                     $DBFarmRole->SetSetting(DBFarmRole::SETTING_BALANCING_HOSTNAME, $elb_dns_name);
                     $DBFarmRole->SetSetting(DBFarmRole::SETTING_BALANCING_NAME, $elb_name);
                     $DBFarmRole->SetSetting(DBFarmRole::SETTING_BALANCING_AZ_HASH, $avail_zones_setting_hash);
                     $register_servers = true;
                 }
             }
             if ($DBFarmRole->GetSetting(DBFarmRole::SETTING_BALANCING_NAME)) {
                 $ELBHealthCheckType = new ELBHealthCheckType($newSettings[DBFarmRole::SETTING_BALANCING_HC_TARGET], $newSettings[DBFarmRole::SETTING_BALANCING_HC_HTH], $newSettings[DBFarmRole::SETTING_BALANCING_HC_INTERVAL], $newSettings[DBFarmRole::SETTING_BALANCING_HC_TIMEOUT], $newSettings[DBFarmRole::SETTING_BALANCING_HC_UTH]);
                 $hash = md5(serialize($ELBHealthCheckType));
                 if ($elb_name || $hash != $DBFarmRole->GetSetting(DBFarmRole::SETTING_BALANCING_HC_HASH)) {
                     //UPDATE CURRENT ELB
                     $AmazonELB->ConfigureHealthCheck($DBFarmRole->GetSetting(DBFarmRole::SETTING_BALANCING_NAME), $ELBHealthCheckType);
                     $DBFarmRole->SetSetting(DBFarmRole::SETTING_BALANCING_HC_HASH, $hash);
                 }
                 // Configure AVAIL zones for the LB
                 if (!$elb_name && $avail_zones_setting_hash != $DBFarmRole->GetSetting(DBFarmRole::SETTING_BALANCING_AZ_HASH)) {
                     $info = $AmazonELB->DescribeLoadBalancers(array($DBFarmRole->GetSetting(DBFarmRole::SETTING_BALANCING_NAME)));
                     $elb = $info->DescribeLoadBalancersResult->LoadBalancerDescriptions->member;
                     $c = (array) $elb->AvailabilityZones;
                     if (!is_array($c['member'])) {
                         $c_zones = array($c['member']);
                     } else {
                         $c_zones = $c['member'];
                     }
                     $add_avail_zones = array();
                     $rem_avail_zones = array();
                     foreach ($newSettings as $skey => $sval) {
                         if (preg_match("/^lb.avail_zone.(.*)?\$/", $skey, $m)) {
                             if ($sval == 1 && !in_array($m[1], $c_zones)) {
                                 array_push($add_avail_zones, $m[1]);
                             }
                             if ($sval == 0 && in_array($m[1], $c_zones)) {
                                 array_push($rem_avail_zones, $m[1]);
                             }
                         }
                     }
                     if (count($add_avail_zones) > 0) {
                         $AmazonELB->EnableAvailabilityZonesForLoadBalancer($DBFarmRole->GetSetting(DBFarmRole::SETTING_BALANCING_NAME), $add_avail_zones);
                     }
                     if (count($rem_avail_zones) > 0) {
                         $AmazonELB->DisableAvailabilityZonesForLoadBalancer($DBFarmRole->GetSetting(DBFarmRole::SETTING_BALANCING_NAME), $rem_avail_zones);
                     }
                     $DBFarmRole->SetSetting(DBFarmRole::SETTING_BALANCING_AZ_HASH, $avail_zones_setting_hash);
                 }
             }
             if ($register_servers) {
                 $servers = $DBFarmRole->GetServersByFilter(array('status' => SERVER_STATUS::RUNNING));
                 $instances = array();
                 foreach ($servers as $DBServer) {
                     $instances[] = $DBServer->GetProperty(EC2_SERVER_PROPERTIES::INSTANCE_ID);
                 }
                 if (count($instances) > 0) {
                     $AmazonELB->RegisterInstancesWithLoadBalancer($DBFarmRole->GetSetting(DBFarmRole::SETTING_BALANCING_NAME), $instances);
                 }
             }
         } else {
             if ($oldSettings[DBFarmRole::SETTING_BALANCING_HOSTNAME]) {
                 try {
                     $AmazonELB->DeleteLoadBalancer($DBFarmRole->GetSetting(DBFarmRole::SETTING_BALANCING_NAME));
                 } catch (Exception $e) {
                 }
                 $DBFarmRole->SetSetting(DBFarmRole::SETTING_BALANCING_NAME, "");
                 $DBFarmRole->SetSetting(DBFarmRole::SETTING_BALANCING_HOSTNAME, "");
                 $DBFarmRole->SetSetting(DBFarmRole::SETTING_BALANCING_USE_ELB, "0");
                 $DBFarmRole->SetSetting(DBFarmRole::SETTING_BALANCING_HC_HASH, "");
                 $DBFarmRole->ClearSettings("lb.avail_zone");
                 $DBFarmRole->ClearSettings("lb.healthcheck");
                 $DBFarmRole->ClearSettings("lb.role.listener");
             }
         }
     } catch (Exception $e) {
         throw new Exception("Error with ELB on Role '{$DBFarmRole->GetRoleObject()->name}': {$e->getMessage()}");
     }
 }