当前位置: 首页>>代码示例>>PHP>>正文


PHP DBFarmRole::ClearSettings方法代码示例

本文整理汇总了PHP中DBFarmRole::ClearSettings方法的典型用法代码示例。如果您正苦于以下问题:PHP DBFarmRole::ClearSettings方法的具体用法?PHP DBFarmRole::ClearSettings怎么用?PHP DBFarmRole::ClearSettings使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DBFarmRole的用法示例。


在下文中一共展示了DBFarmRole::ClearSettings方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: onFarmSave

 public function onFarmSave(DBFarm $dbFarm, DBFarmRole $dbFarmRole)
 {
     try {
         $account = Scalr_Account::init()->loadById($dbFarm->ClientID);
         if (!$account->isFeatureEnabled(Scalr_Limits::FEATURE_CHEF)) {
             $dbFarmRole->ClearSettings("chef.");
             return false;
         }
         $db = Core::GetDBInstance();
         $runListId = $dbFarmRole->GetSetting(self::ROLE_CHEF_RUNLIST_ID);
         $attributes = $dbFarmRole->GetSetting(self::ROLE_CHEF_ATTRIBUTES);
         $checksum = $dbFarmRole->GetSetting(self::ROLE_CHEF_CHECKSUM);
         $chefRoleName = $dbFarmRole->GetSetting(self::ROLE_CHEF_ROLE_NAME);
         $chefServerId = $dbFarmRole->GetSetting(self::ROLE_CHEF_SERVER_ID);
         // Need to remove chef role if chef was disabled for current farmrole
         if (!$runListId && $chefRoleName) {
             $this->removeChefRole($chefServerId, $chefRoleName);
             $dbFarmRole->ClearSettings("chef.");
             return true;
         }
         if ($runListId) {
             $runListInfo = $this->db->GetRow("SELECT chef_server_id, runlist FROM services_chef_runlists WHERE id=?", array($runListId));
             $newChefServerId = $runListInfo['chef_server_id'];
             if ($newChefServerId != $chefServerId && $chefServerId) {
                 // Remove role from old server
                 $this->removeChefRole($chefServerId, $chefRoleName);
                 $createNew = true;
             }
             if (!$chefServerId) {
                 $createNew = true;
             }
             $chefServerInfo = $this->db->GetRow("SELECT * FROM services_chef_servers WHERE id=?", array($runListInfo['chef_server_id']));
             $chefServerInfo['auth_key'] = $this->getCrypto()->decrypt($chefServerInfo['auth_key'], $this->cryptoKey);
             $chefClient = Scalr_Service_Chef_Client::getChef($chefServerInfo['url'], $chefServerInfo['username'], trim($chefServerInfo['auth_key']));
             $roleName = "scalr-{$dbFarmRole->ID}";
             $setSettings = false;
             if ($createNew) {
                 $chefClient->createRole($roleName, $roleName, json_decode($runListInfo['runlist']), json_decode($attributes), $runListInfo['chef_environment']);
                 $setSettings = true;
             } else {
                 if ($dbFarmRole->GetSetting(self::ROLE_CHEF_CHECKSUM) != md5("{$runListInfo['runlist']}.{$attributes}")) {
                     $chefClient->updateRole($roleName, $roleName, json_decode($runListInfo['runlist']), json_decode($attributes), $runListInfo['chef_environment']);
                     $setSettings = true;
                 }
             }
             if ($setSettings) {
                 $dbFarmRole->SetSetting(self::ROLE_CHEF_ROLE_NAME, $roleName);
                 $dbFarmRole->SetSetting(self::ROLE_CHEF_SERVER_ID, $runListInfo['chef_server_id']);
                 $dbFarmRole->SetSetting(self::ROLE_CHEF_CHECKSUM, md5("{$runListInfo['runlist']}.{$attributes}"));
             }
         }
     } catch (Exception $e) {
         throw new Exception("Chef settings error: {$e->getMessage()} ({$e->getTraceAsString()})");
     }
 }
开发者ID:rakesh-mohanta,项目名称:scalr,代码行数:55,代码来源:Chef.php

示例2: farmUpdateRoleSettings

 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, "");
//.........这里部分代码省略.........
开发者ID:rakesh-mohanta,项目名称:scalr,代码行数:101,代码来源:Elb.php


注:本文中的DBFarmRole::ClearSettings方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。