• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Scalr_Model类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: farmSave

 public static function farmSave(\DBFarm $DBFarm, array $roles)
 {
     foreach ($roles as $DBFarmRole) {
         if ($DBFarmRole->Platform != \SERVER_PLATFORMS::EC2) {
             continue;
         }
         $location = $DBFarmRole->CloudLocation;
         $sshKey = \Scalr_Model::init(\Scalr_Model::SSH_KEY);
         if (!$sshKey->loadGlobalByFarmId($DBFarm->EnvID, $DBFarm->ID, $location, \SERVER_PLATFORMS::EC2)) {
             $key_name = "FARM-" . $DBFarm->ID . "-" . SCALR_ID;
             $aws = $DBFarm->GetEnvironmentObject()->aws($location);
             $result = $aws->ec2->keyPair->create($key_name);
             if (!empty($result->keyMaterial)) {
                 $sshKey->farmId = $DBFarm->ID;
                 $sshKey->envId = $DBFarm->EnvID;
                 $sshKey->type = \Scalr_SshKey::TYPE_GLOBAL;
                 $sshKey->cloudLocation = $location;
                 $sshKey->cloudKeyName = $key_name;
                 $sshKey->platform = \SERVER_PLATFORMS::EC2;
                 $sshKey->setPrivate($result->keyMaterial);
                 $sshKey->save();
             }
         }
     }
 }
开发者ID:rickb838,项目名称:scalr,代码行数:25,代码来源:Ec2Helper.php


示例2: getEnvironmentObject

 /**
  * @return Scalr_Environment
  */
 public function getEnvironmentObject()
 {
     if (!$this->environment) {
         $this->environment = Scalr_Model::init(Scalr_Model::ENVIRONMENT)->loadById($this->envId);
     }
     return $this->environment;
 }
开发者ID:mheydt,项目名称:scalr,代码行数:10,代码来源:class.DBEBSVolume.php


示例3: farmSave

 public static function farmSave(DBFarm $DBFarm, array $roles)
 {
     foreach ($roles as $DBFarmRole) {
         if ($DBFarmRole->Platform != SERVER_PLATFORMS::EUCALYPTUS) {
             continue;
         }
         $location = $DBFarmRole->CloudLocation;
         $sshKey = Scalr_Model::init(Scalr_Model::SSH_KEY);
         if (!$sshKey->loadGlobalByFarmId($DBFarm->ID, $location)) {
             $key_name = "FARM-{$DBFarm->ID}";
             $eucaClient = Scalr_Service_Cloud_Eucalyptus::newCloud($DBFarm->GetEnvironmentObject()->getPlatformConfigValue(Modules_Platforms_Eucalyptus::SECRET_KEY, true, $location), $DBFarm->GetEnvironmentObject()->getPlatformConfigValue(Modules_Platforms_Eucalyptus::ACCESS_KEY, true, $location), $DBFarm->GetEnvironmentObject()->getPlatformConfigValue(Modules_Platforms_Eucalyptus::EC2_URL, true, $location));
             $result = $eucaClient->CreateKeyPair($key_name);
             if ($result->keyMaterial) {
                 $sshKey->farmId = $DBFarm->ID;
                 $sshKey->clientId = $DBFarm->ClientID;
                 $sshKey->envId = $DBFarm->EnvID;
                 $sshKey->type = Scalr_SshKey::TYPE_GLOBAL;
                 $sshKey->cloudLocation = $location;
                 $sshKey->cloudKeyName = $key_name;
                 $sshKey->platform = SERVER_PLATFORMS::EUCALYPTUS;
                 $sshKey->setPrivate($result->keyMaterial);
                 $sshKey->save();
             }
         }
     }
 }
开发者ID:rakesh-mohanta,项目名称:scalr,代码行数:26,代码来源:Eucalyptus.php


示例4: delete

 /**
  * {@inheritdoc}
  * @see Scalr_Model::delete()
  */
 public function delete($id = null)
 {
     if ($this->db->GetOne('SELECT COUNT(*) FROM apache_vhosts WHERE ssl_cert_id = ?', array($this->id)) > 0) {
         throw new Scalr_Exception_Core(sprintf('Certificate "%s" is used by apache virtual host(s)', $this->name));
     }
     parent::delete();
 }
开发者ID:rickb838,项目名称:scalr,代码行数:11,代码来源:Certificate.php


示例5: onCreateDataBundleResult

 public static function onCreateDataBundleResult(Scalr_Messaging_Msg $message, DBServer $dbServer)
 {
     $dbFarm = $dbServer->GetFarmObject();
     $dbFarmRole = $dbServer->GetFarmRoleObject();
     $dbFarmRole->SetSetting(Scalr_Db_Msr::DATA_BUNDLE_LAST_TS, time());
     $dbFarmRole->SetSetting(Scalr_Db_Msr::DATA_BUNDLE_IS_RUNNING, 0);
     //$dbFarmRole->SetSetting(Scalr_Db_Msr::DATA_BUNDLE_SERVER_ID, "");
     $dbSettings = $message->{$message->dbType};
     if ($dbSettings->snapshotConfig) {
         try {
             $snapshot = Scalr_Model::init(Scalr_Model::STORAGE_SNAPSHOT);
             $snapshot->loadBy(array('id' => $dbSettings->snapshotConfig->id, 'client_id' => $dbServer->clientId, 'env_id' => $dbServer->envId, 'name' => "Automatical '{$message->dbType}' data bundle", 'type' => $dbFarmRole->GetSetting(Scalr_Db_Msr::DATA_STORAGE_ENGINE), 'platform' => $dbServer->platform, 'description' => "'{$message->dbType}' data bundle created automatically by Scalr", 'service' => $message->dbType));
             $snapshot->setConfig($dbSettings->snapshotConfig);
             $snapshot->save(true);
             $dbFarmRole->SetSetting(Scalr_Db_Msr::SNAPSHOT_ID, $snapshot->id);
             if ($message->dbType == self::DB_TYPE_MYSQL) {
                 $dbFarmRole->SetSetting(Scalr_Db_Msr_Mysql::LOG_FILE, $dbSettings->logFile);
                 $dbFarmRole->SetSetting(Scalr_Db_Msr_Mysql::LOG_POS, $dbSettings->logPos);
             } elseif ($message->dbType == self::DB_TYPE_POSTGRESQL) {
                 $dbFarmRole->SetSetting(Scalr_Db_Msr_Postgresql::XLOG_LOCATION, $dbSettings->currentXlogLocation);
             } elseif ($message->dbType == self::DB_TYPE_REDIS) {
                 //Nothing todo
             }
         } catch (Exception $e) {
             Logger::getLogger(__CLASS__)->error(new FarmLogMessage($dbServer->farmId, "Cannot save storage snapshot: {$e->getMessage()}"));
         }
     }
 }
开发者ID:rakesh-mohanta,项目名称:scalr,代码行数:28,代码来源:Msr.php


示例6: save

 /**
  * {@inheritdoc}
  * @see Scalr_Model::save()
  */
 public function save($forceInsert = false)
 {
     if (!$this->id) {
         $forceInsert = true;
         $this->id = Scalr::GenerateUID(true);
     }
     parent::save($forceInsert);
 }
开发者ID:mheydt,项目名称:scalr,代码行数:12,代码来源:DeploymentTask.php


示例7: OnStartForking

 public function OnStartForking()
 {
     $db = Core::GetDBInstance(null, true);
     // selects rows where the snapshot's time has come to create new snapshot.
     $resultset = $db->Execute("SELECT * FROM autosnap_settings \r\n\t\t\t\t\t\tWHERE (UNIX_TIMESTAMP(DATE_ADD(dtlastsnapshot, INTERVAL period HOUR)) < UNIX_TIMESTAMP(NOW())\r\n\t\t\t\t\t\tOR dtlastsnapshot IS NULL)\r\n\t\t\t\t\t\tAND objectid \t!= '0' \r\n\t\t\t\t\t\tAND object_type = ?", array(AUTOSNAPSHOT_TYPE::RDSSnap));
     while ($snapshotsSettings = $resultset->FetchRow()) {
         try {
             $environment = Scalr_Model::init(Scalr_Model::ENVIRONMENT)->loadById($snapshotsSettings['env_id']);
             $AmazonRDSClient = Scalr_Service_Cloud_Aws::newRds($environment->getPlatformConfigValue(Modules_Platforms_Ec2::ACCESS_KEY), $environment->getPlatformConfigValue(Modules_Platforms_Ec2::SECRET_KEY), $snapshotsSettings['region']);
             // Check instance. If instance wasn't found then delete current recrod from settings table
             try {
                 $AmazonRDSClient->DescribeDBInstances($snapshotsSettings['objectid']);
             } catch (Exception $e) {
                 if (stristr($e->getMessage(), "not found") || stristr($e->getMessage(), "not a valid") || stristr($e->getMessage(), "security token included in the request is invalid")) {
                     $db->Execute("DELETE FROM autosnap_settings WHERE id = ?", array($snapshotsSettings['id']));
                 }
                 $this->Logger->error(sprintf(_("RDS instance %s was not found. Auto-snapshot settings for this \r\n\t\t\t\t\t\t\t\tinstance will be deleted. %s."), $snapshotsSettings['objectid'], $e->getMessage()));
                 throw $e;
             }
             // snapshot random unique name
             $snapshotId = "scalr-auto-" . dechex(microtime(true) * 10000) . rand(0, 9);
             try {
                 // Create new snapshot
                 $AmazonRDSClient->CreateDBSnapshot($snapshotId, $snapshotsSettings['objectid']);
                 // update last snapshot creation date in settings
                 $db->Execute("UPDATE autosnap_settings SET last_snapshotid=?, dtlastsnapshot=NOW() WHERE id=?", array($snapshotId, $snapshotsSettings['id']));
                 // create new snapshot record in DB
                 $db->Execute("INSERT INTO rds_snaps_info SET \r\n\t\t\t\t\t\t\tsnapid\t\t= ?,\r\n\t\t\t\t\t\t\tcomment\t\t= ?,\r\n\t\t\t\t\t\t\tdtcreated\t= NOW(),\r\n\t\t\t\t\t\t\tregion\t\t= ?,\r\n\t\t\t\t\t\t\tautosnapshotid = ?", array($snapshotId, _("Auto snapshot"), $snapshotsSettings['region'], $snapshotsSettings['id']));
             } catch (Exception $e) {
                 $this->Logger->warn(sprintf(_("Cannot create RDS snapshot: %s."), $e->getMessage()));
             }
             // Remove old snapshots
             if ($snapshotsSettings['rotate'] != 0) {
                 $oldSnapshots = $db->GetAll("SELECT * FROM rds_snaps_info WHERE autosnapshotid = ? ORDER BY id ASC", array($snapshotsSettings['id']));
                 if (count($oldSnapshots) > $snapshotsSettings['rotate']) {
                     while (count($oldSnapshots) > $snapshotsSettings['rotate']) {
                         // takes the oldest snapshot ...
                         $deletingSnapshot = array_shift($oldSnapshots);
                         try {
                             // and deletes it from amazon and from DB
                             $AmazonRDSClient->DeleteDBSnapshot($deletingSnapshot['snapid']);
                             $db->Execute("DELETE FROM rds_snaps_info WHERE id = ?", array($deletingSnapshot['id']));
                         } catch (Exception $e) {
                             if (stristr($e->getMessage(), "not found") || stristr($e->getMessage(), "not a valid")) {
                                 $db->Execute("DELETE FROM rds_snaps_info WHERE id = ?", array($deletingSnapshot['id']));
                             }
                             $this->Logger->error(sprintf(_("DBsnapshot %s for RDS instance %s was not found \r\n\t\t\t\t\t\t\t\t\t\t\t\tand cannot be deleted . %s."), $deletingSnapshot['snapid'], $snapshotsSettings['objectid'], $e->getMessage()));
                         }
                     }
                 }
             }
         } catch (Exception $e) {
             $this->Logger->warn(sprintf(_("Cannot create snapshot for RDS Instance %s. %s"), $snapshotsSettings['objectid'], $e->getMessage()));
         }
     }
 }
开发者ID:rakesh-mohanta,项目名称:scalr,代码行数:56,代码来源:class.RDSMaintenanceProcess.php


示例8: OnHostInit

 /**
  * Upload S3cmd config file, AWS private key and certificate to instance aftre instance boot.
  * Also execute hostInit hooks from hooks/hostInit folder
  *
  * @param array $instanceinfo
  * @param string $local_ip
  * @param string $remote_ip
  * @param string $public_key
  */
 public function OnHostInit(HostInitEvent $event)
 {
     if ($event->DBServer->IsSupported("0.5")) {
         $this->Logger->info("Scalarizr instance. Skipping SSH observer...");
         return true;
     }
     if ($event->DBServer->platform != SERVER_PLATFORMS::EC2) {
         return true;
     }
     // Get farm info and client info from database;
     $DBFarm = DBFarm::LoadByID($this->FarmID);
     $DBRole = DBRole::loadById($event->DBServer->roleId);
     // Get Role info
     $ssh_port = $DBRole->getProperty(DBRole::PROPERTY_SSH_PORT) ? $DBRole->getProperty(DBRole::PROPERTY_SSH_PORT) : 22;
     // Generate s3cmd config file
     $s3cfg = CONFIG::$S3CFG_TEMPLATE;
     $s3cfg = str_replace("[access_key]", $DBFarm->GetEnvironmentObject()->getPlatformConfigValue(Modules_Platforms_Ec2::ACCESS_KEY), $s3cfg);
     $s3cfg = str_replace("[secret_key]", $DBFarm->GetEnvironmentObject()->getPlatformConfigValue(Modules_Platforms_Ec2::SECRET_KEY), $s3cfg);
     $s3cfg = str_replace("\r\n", "\n", $s3cfg);
     // Prepare public key for SSH connection
     $pub_key_file = tempnam("/tmp", "AWSK");
     $res = file_put_contents($pub_key_file, $event->PublicKey);
     $this->Logger->debug("Creating temporary file for public key: {$res}");
     try {
         $key = Scalr_Model::init(Scalr_Model::SSH_KEY)->loadGlobalByFarmId($event->DBServer->farmId, $event->DBServer->GetFarmRoleObject()->CloudLocation);
         if (!$key) {
             throw new Exception(_("There is no SSH key for server: {$event->DBServer->serverId}"));
         }
     } catch (Exception $e) {
         throw new Exception("Cannot init SshKey object: {$e->getMessage()}");
     }
     // Prepare private key for SSH connection
     $priv_key_file = tempnam("/tmp", "AWSK");
     $res = file_put_contents($priv_key_file, $key->getPrivate());
     $this->Logger->debug("Creating temporary file for private key: {$res}");
     // Connect to SSH
     $SSH2 = new Scalr_Net_Ssh2_Client();
     $SSH2->addPubkey("root", $pub_key_file, $priv_key_file);
     if ($SSH2->connect($event->ExternalIP, $ssh_port)) {
         // Upload keys and s3 config to instance
         $res = $SSH2->sendFile("/etc/aws/keys/pk.pem", $DBFarm->GetEnvironmentObject()->getPlatformConfigValue(Modules_Platforms_Ec2::PRIVATE_KEY), "w+", false);
         $res2 = $SSH2->sendFile("/etc/aws/keys/cert.pem", $DBFarm->GetEnvironmentObject()->getPlatformConfigValue(Modules_Platforms_Ec2::CERTIFICATE), "w+", false);
         $res3 = $SSH2->sendFile("/etc/aws/keys/s3cmd.cfg", $s3cfg, "w+", false);
         // remove temporary files
         @unlink($pub_key_file);
         @unlink($priv_key_file);
     } else {
         // remove temporary files
         @unlink($pub_key_file);
         @unlink($priv_key_file);
         Logger::getLogger(LOG_CATEGORY::FARM)->warn(new FarmLogMessage($this->FarmID, "Cannot upload ec2 keys to '{$event->DBServer->serverId}' instance. Failed to connect to SSH '{$event->ExternalIP}:{$ssh_port}'"));
         throw new Exception("Cannot upload keys on '{$event->DBServer->serverId}'. Failed to connect to '{$event->ExternalIP}:{$ssh_port}'.");
     }
 }
开发者ID:rakesh-mohanta,项目名称:scalr,代码行数:63,代码来源:class.SSHWorker.php


示例9: save

 /**
  * {@inheritdoc}
  * @see Scalr_Model::save()
  */
 public function save($forceInsert = false)
 {
     parent::save($forceInsert);
     // Save parts
     if ($this->isPartsChanged && $this->id) {
         $this->db->Execute("DELETE FROM services_db_backup_parts WHERE backup_id = ?", array($this->id));
         foreach ($this->parts as $n => $part) {
             $this->db->Execute("INSERT INTO services_db_backup_parts SET\n                    `backup_id` \t= ?,\n                    `path`\t\t\t= ?,\n                    `size`\t\t\t= ?,\n                    `seq_number`\t= ?\n                ", array($this->id, $part['path'], $part['size'], $n + 1));
         }
     }
     return $this;
 }
开发者ID:mheydt,项目名称:scalr,代码行数:16,代码来源:Backup.php


示例10: setFarmRoleMetrics

 function setFarmRoleMetrics($metrics)
 {
     foreach ($this->farmRoleMetrics as $id => $farmRoleMetric) {
         if (!$metrics[$farmRoleMetric->metricId]) {
             $farmRoleMetric->delete();
             unset($this->farmRoleMetrics[$farmRoleMetric->metricId]);
         }
     }
     foreach ($metrics as $metric_id => $metric_settings) {
         if (!$this->farmRoleMetrics[$metric_id]) {
             $this->farmRoleMetrics[$metric_id] = Scalr_Model::init(Scalr_Model::SCALING_FARM_ROLE_METRIC);
             $this->farmRoleMetrics[$metric_id]->metricId = $metric_id;
             $this->farmRoleMetrics[$metric_id]->farmRoleId = $this->dbFarmRole->ID;
         }
         $this->farmRoleMetrics[$metric_id]->setSettings($metric_settings);
         $this->farmRoleMetrics[$metric_id]->save();
     }
 }
开发者ID:recipe,项目名称:scalr,代码行数:18,代码来源:Manager.php


示例11: handleWork

 function handleWork($deploymentTaskId)
 {
     try {
         $deploymentTask = Scalr_Model::init(Scalr_Model::DM_DEPLOYMENT_TASK)->loadById($deploymentTaskId);
         try {
             $dbServer = DBServer::LoadByID($deploymentTask->serverId);
         } catch (Exception $e) {
             $deploymentTask->status = Scalr_Dm_DeploymentTask::STATUS_ARCHIVED;
             return;
         }
         switch ($deploymentTask->status) {
             case Scalr_Dm_DeploymentTask::STATUS_PENDING:
                 $deploymentTask->deploy();
                 break;
             case Scalr_Dm_DeploymentTask::STATUS_DEPLOYING:
                 //TODO:
                 break;
         }
     } catch (Exception $e) {
         var_dump($e->getMessage());
     }
 }
开发者ID:rakesh-mohanta,项目名称:scalr,代码行数:22,代码来源:DeployManager.php


示例12: setFarmRoleMetrics

 function setFarmRoleMetrics($metrics)
 {
     foreach ($this->farmRoleMetrics as $id => $farmRoleMetric) {
         if (!$metrics[$farmRoleMetric->metricId]) {
             $farmRoleMetric->delete();
             unset($this->farmRoleMetrics[$farmRoleMetric->metricId]);
         }
     }
     foreach ($metrics as $metric_id => $metric_settings) {
         if (!is_array($metric_settings)) {
             continue;
         }
         if (!$this->farmRoleMetrics[$metric_id]) {
             $this->farmRoleMetrics[$metric_id] = Scalr_Model::init(Scalr_Model::SCALING_FARM_ROLE_METRIC);
             $this->farmRoleMetrics[$metric_id]->metricId = $metric_id;
             $this->farmRoleMetrics[$metric_id]->farmRoleId = $this->dbFarmRole->ID;
         }
         $this->farmRoleMetrics[$metric_id]->clearSettings();
         $this->farmRoleMetrics[$metric_id]->setSettings($metric_settings);
         $this->farmRoleMetrics[$metric_id]->save(false, array('dtlastpolled', 'last_value', 'last_data'));
     }
 }
开发者ID:scalr,项目名称:scalr,代码行数:22,代码来源:Manager.php


示例13: array

 $farmid = (int) $req_farmid;
 $watchername = $req_watchername;
 $graph_type = $req_graph_type;
 $role_name = $req_role_name ? $req_role_name : $req_role;
 if ($req_version == 2) {
     if ($role_name != 'FARM' && !stristr($role_name, "INSTANCE_")) {
         $role_name = "FR_{$role_name}";
     }
 }
 $farminfo = $db->GetRow("SELECT status, id, env_id FROM farms WHERE id=?", array($farmid));
 if ($farminfo["status"] != FARM_STATUS::RUNNING) {
     $result = array("success" => false, "msg" => _("Statistics not available for terminated farm"));
 } else {
     if ($farminfo['clientid'] != 0) {
         define("SCALR_SERVER_TZ", date("T"));
         $env = Scalr_Model::init(Scalr_Model::ENVIRONMENT)->loadById($farminfo['env_id']);
         $tz = $env->getPlatformConfigValue(ENVIRONMENT_SETTINGS::TIMEZONE);
         if ($tz) {
             date_default_timezone_set($tz);
         }
     }
     $graph_info = GetGraphicInfo($graph_type);
     $image_path = APPPATH . "/cache/stats/{$farmid}/{$role_name}.{$watchername}.{$graph_type}.gif";
     $farm_rrddb_dir = CONFIG::$RRD_DB_DIR . "/{$farminfo['id']}";
     $rrddbpath = "{$farm_rrddb_dir}/{$role_name}/{$watchername}/db.rrd";
     CONFIG::$RRD_GRAPH_STORAGE_TYPE = RRD_STORAGE_TYPE::LOCAL_FS;
     if (file_exists($rrddbpath)) {
         try {
             GenerateGraph($farmid, $role_name, $rrddbpath, $watchername, $graph_type, $image_path);
             $url = str_replace(array("%fid%", "%rn%", "%wn%"), array($farmid, $role_name, $watchername), CONFIG::$RRD_STATS_URL);
             $url = "{$url}{$graph_type}.gif";
开发者ID:rakesh-mohanta,项目名称:scalr,代码行数:31,代码来源:statistics.php


示例14: onMysql_PromoteToMasterResult

 /**
  * @param Scalr_Messaging_Msg_Mysql_PromoteToMasterResult $message
  * @param DBServer $dbserver
  */
 private function onMysql_PromoteToMasterResult($message, DBServer $dbserver)
 {
     $dbserver->GetFarmRoleObject()->SetSetting(DBFarmRole::SETTING_MYSQL_SLAVE_TO_MASTER, 0);
     if ($message->status == Scalr_Messaging_Msg_Mysql_PromoteToMasterResult::STATUS_OK) {
         $dbFarm = $dbserver->GetFarmObject();
         $dbFarmRole = $dbserver->GetFarmRoleObject();
         $oldMaster = $dbFarm->GetMySQLInstances(true);
         if ($dbserver->IsSupported("0.7")) {
             if ($message->volumeConfig) {
                 try {
                     $storageVolume = Scalr_Storage_Volume::init();
                     try {
                         $storageVolume->loadById($message->volumeConfig->id);
                         $storageVolume->setConfig($message->volumeConfig);
                         $storageVolume->save();
                     } catch (Exception $e) {
                         if (strpos($e->getMessage(), 'not found')) {
                             $storageVolume->loadBy(array('id' => $message->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' => $message->volumeConfig->size, 'fstype' => $message->volumeConfig->fstype, 'purpose' => ROLE_BEHAVIORS::MYSQL, 'farm_roleid' => $dbserver->farmRoleId, 'server_index' => $dbserver->index));
                             $storageVolume->setConfig($message->volumeConfig);
                             $storageVolume->save(true);
                         } else {
                             throw $e;
                         }
                     }
                 } catch (Exception $e) {
                     $this->logger->error(new FarmLogMessage($dbserver->farmId, "Cannot save storage volume: {$e->getMessage()}"));
                 }
             }
             if ($message->snapshotConfig) {
                 try {
                     $snapshot = Scalr_Model::init(Scalr_Model::STORAGE_SNAPSHOT);
                     $snapshot->loadBy(array('id' => $message->snapshotConfig->id, 'client_id' => $dbserver->clientId, 'env_id' => $dbserver->envId, 'name' => "Automatical MySQL data bundle", 'type' => $dbFarmRole->GetSetting(DBFarmRole::SETTING_MYSQL_DATA_STORAGE_ENGINE), 'platform' => $dbserver->platform, 'description' => "MySQL data bundle created automatically by Scalr", 'ismysql' => true));
                     $snapshot->setConfig($message->snapshotConfig);
                     $snapshot->save(true);
                     $dbFarmRole->SetSetting(DBFarmRole::SETTING_MYSQL_SCALR_SNAPSHOT_ID, $snapshot->id);
                     $dbFarmRole->SetSetting(DBFarmRole::SETTING_MYSQL_LOG_FILE, $message->logFile);
                     $dbFarmRole->SetSetting(DBFarmRole::SETTING_MYSQL_LOG_POS, $message->logPos);
                 } catch (Exception $e) {
                     $this->logger->error(new FarmLogMessage($dbserver->farmId, "Cannot save storage snapshot: {$e->getMessage()}"));
                 }
             }
         } else {
             // TODO: delete old slave volume if new one was created
             $dbFarmRole->SetSetting(DBFarmRole::SETTING_MYSQL_MASTER_EBS_VOLUME_ID, $message->volumeId);
         }
         return new NewMysqlMasterUpEvent($dbserver, "", $oldMaster[0]);
     } elseif ($message->status == Scalr_Messaging_Msg_Mysql_PromoteToMasterResult::STATUS_FAILED) {
         $dbserver->SetProperty(SERVER_PROPERTIES::DB_MYSQL_MASTER, 0);
         $dbserver->SetProperty(Scalr_Db_Msr::REPLICATION_MASTER, 0);
         // XXX: Need to do smth
         $this->logger->error(sprintf("Promote to Master failed for server %s. Last error: %s", $dbserver->serverId, $message->lastError));
     }
 }
开发者ID:rakesh-mohanta,项目名称:scalr,代码行数:57,代码来源:ScalarizrMessaging.php


示例15: DmApplicationDeploy

 public function DmApplicationDeploy($ApplicationID, $FarmRoleID, $RemotePath)
 {
     $this->restrictAccess(Acl::RESOURCE_DEPLOYMENTS_APPLICATIONS);
     $application = Scalr_Model::init(Scalr_Model::DM_APPLICATION)->loadById($ApplicationID);
     if ($application->envId != $this->Environment->id) {
         throw new Exception("Aplication not found in database");
     }
     $dbFarmRole = DBFarmRole::LoadByID($FarmRoleID);
     if ($dbFarmRole->GetFarmObject()->EnvID != $this->Environment->id) {
         throw new Exception("Farm Role not found in database");
     }
     $this->user->getPermissions()->validate($dbFarmRole);
     $servers = $dbFarmRole->GetServersByFilter(array('status' => SERVER_STATUS::RUNNING));
     if (count($servers) == 0) {
         throw new Exception("There is no running servers on selected farm/role");
     }
     $response = $this->CreateInitialResponse();
     $response->DeploymentTasksSet = new stdClass();
     $response->DeploymentTasksSet->Item = array();
     foreach ($servers as $dbServer) {
         $taskId = Scalr_Dm_DeploymentTask::getId($ApplicationID, $dbServer->serverId, $RemotePath);
         $deploymentTask = Scalr_Model::init(Scalr_Model::DM_DEPLOYMENT_TASK);
         if (!$taskId) {
             try {
                 if (!$dbServer->IsSupported("0.7.38")) {
                     throw new Exception("Scalr agent installed on this server doesn't support deployments. Please update it to the latest version");
                 }
                 $deploymentTask->create($FarmRoleID, $ApplicationID, $dbServer->serverId, Scalr_Dm_DeploymentTask::TYPE_API, $RemotePath, $this->Environment->id);
             } catch (Exception $e) {
                 $itm = new stdClass();
                 $itm->ServerID = $dbServer->serverId;
                 $itm->ErrorMessage = $e->getMessage();
                 $response->DeploymentTasksSet->Item[] = $itm;
                 continue;
             }
         } else {
             $deploymentTask->loadById($taskId);
             $deploymentTask->status = Scalr_Dm_DeploymentTask::STATUS_PENDING;
             $deploymentTask->log("Re-deploying application. Status: pending");
             $deploymentTask->save();
         }
         $itm = new stdClass();
         $itm->ServerID = $dbServer->serverId;
         $itm->DeploymentTaskID = $deploymentTask->id;
         $itm->FarmRoleID = $deploymentTask->farmRoleId;
         $itm->RemotePath = $deploymentTask->remotePath;
         $itm->Status = $deploymentTask->status;
         $response->DeploymentTasksSet->Item[] = $itm;
     }
     return $response;
 }
开发者ID:rickb838,项目名称:scalr,代码行数:51,代码来源:class.ScalrAPI_2_3_0.php


示例16: save

 /**
  * {@inheritdoc}
  * @see Scalr_Model::save()
  */
 public function save($forceInsert = false)
 {
     return parent::save($forceInsert);
 }
开发者ID:mheydt,项目名称:scalr,代码行数:8,代码来源:Vhost.php


示例17: save

 /**
  * {@inheritdoc}
  * @see Scalr_Model::save()
  */
 public function save($forceInsert = false)
 {
     $ret = parent::save($forceInsert);
     if ($this->id && \Scalr::getContainer()->analytics->enabled) {
         \Scalr::getContainer()->analytics->tags->syncValue($this->accountId, \Scalr\Stats\CostAnalytics\Entity\TagEntity::TAG_ID_USER, $this->id, $this->fullname ?: $this->email);
     }
     return $ret;
 }
开发者ID:rickb838,项目名称:scalr,代码行数:12,代码来源:User.php


示例18: handleWork

 function handleWork($farmRoleId)
 {
     try {
         $dbFarmRole = DBFarmRole::LoadByID($farmRoleId);
         $dbFarm = $dbFarmRole->GetFarmObject();
         $env = Scalr_Model::init(Scalr_Model::ENVIRONMENT)->loadById($dbFarm->EnvID);
         $tz = $env->getPlatformConfigValue(Scalr_Environment::SETTING_TIMEZONE);
         if (!$tz) {
             $tz = date_default_timezone_get();
         }
         $farmTz = $dbFarm->GetSetting(DBFarm::SETTING_TIMEZONE);
         if ($farmTz) {
             $tz = $farmTz;
         }
         //skip terminated farms
         if ($dbFarm->Status != FARM_STATUS::RUNNING) {
             return;
         }
     } catch (Exception $e) {
         return;
     }
     //********* Check Replication status *********/
     //TODO:
     //********* Bundle database data ***********/
     $this->performDbMsrAction('BUNDLE', $dbFarmRole, $tz);
     $backupsNotSupported = in_array($dbFarmRole->Platform, array(SERVER_PLATFORMS::CLOUDSTACK, SERVER_PLATFORMS::IDCF, SERVER_PLATFORMS::UCLOUD));
     //********* Backup database data ***********/
     if (!$backupsNotSupported) {
         $this->performDbMsrAction('BACKUP', $dbFarmRole, $tz);
     }
 }
开发者ID:rickb838,项目名称:scalr,代码行数:31,代码来源:DbMsrMaintenance.php


示例19: delete

 /**
  * {@inheritdoc}
  * @see Scalr_Model::delete()
  */
 public function delete($id = null)
 {
     if ($this->db->GetOne("SELECT COUNT(*) FROM farms WHERE env_id = ?", array($this->id))) {
         throw new Exception("Cannot remove environment. You need to remove all your farms first.");
     }
     if ($this->db->GetOne("SELECT COUNT(*) FROM client_environments WHERE client_id = ?", array($this->clientId)) < 2) {
         throw new Exception('At least one environment should be in account. You cannot remove the last one.');
     }
     parent::delete();
     try {
         $this->db->Execute("DELETE FROM client_environment_properties WHERE env_id=?", array($this->id));
         $this->db->Execute("DELETE FROM apache_vhosts WHERE env_id=?", array($this->id));
         $this->db->Execute("DELETE FROM autosnap_settings WHERE env_id=?", array($this->id));
         $this->db->Execute("DELETE FROM bundle_tasks WHERE env_id=?", array($this->id));
         $this->db->Execute("DELETE FROM dm_applications WHERE env_id=?", array($this->id));
         $this->db->Execute("DELETE FROM dm_deployment_tasks WHERE env_id=?", array($this->id));
         $this->db->Execute("DELETE FROM dm_sources WHERE env_id=?", array($this->id));
         $this->db->Execute("DELETE FROM dns_zones WHERE env_id=?", array($this->id));
         $this->db->Execute("DELETE FROM ec2_ebs WHERE env_id=?", array($this->id));
         $this->db->Execute("DELETE FROM elastic_ips WHERE env_id=?", array($this->id));
         $this->db->Execute("DELETE FROM farms WHERE env_id=?", array($this->id));
         $this->db->Execute("DELETE FROM roles WHERE env_id=?", array($this->id));
         $this->db->Execute("DELETE FROM servers WHERE env_id=?", array($this->id));
         $this->db->Execute("DELETE FROM ssh_keys WHERE env_id=?", array($this->id));
         $this->db->Execute('DELETE FROM `account_team_envs` WHERE env_id = ?', array($this->id));
         $this->db->Execute('DELETE FROM `global_variables` WHERE env_id = ?', array($this->id));
     } catch (Exception $e) {
         throw new Exception(sprintf(_("Cannot delete record. Error: %s"), $e->getMessage()), $e->getCode());
     }
 }
开发者ID:recipe,项目名称:scalr,代码行数:34,代码来源:Environment.php


示例20: buildStorageSettings

 protected function buildStorageSettings()
 {
     if ($this->dbFarmRole->GetSetting(Scalr_Db_Msr::VOLUME_ID) && $this->replicationMaster) {
         try {
             $volume = Scalr_Storage_Volume::init()->loadById($this->dbFarmRole->GetSetting(Scalr_Db_Msr::VOLUME_ID));
             $this->volumeConfig = $volume->getConfig();
         } catch (Exception $e) {
         }
     }
     /***
      * For Rackspace we ALWAYS need snapsjot_config for mysql
      * ***/
     if ($this->dbFarmRole->GetSetting(Scalr_Db_Msr::SNAPSHOT_ID)) {
         try {
             $snapshotConfig = Scalr_Model::init(Scalr_Model::STORAGE_SNAPSHOT)->loadById($this->dbFarmRole->GetSetting(Scalr_Db_Msr::SNAPSHOT_ID));
             $this->snapshotConfig = $snapshotConfig->getConfig();
             if ($this->snapshotConfig) {
                 if ($this->snapshotConfig->type == MYSQL_STORAGE_ENGINE::EPH) {
                     if ($this->dbFarmRole->Platform == SERVER_PLATFORMS::EC2) {
                         if (!isset($this->snapshotConfig->disk)) {
                             $this->snapshotConfig->disk = new stdClass();
                         }
                         $this->snapshotConfig->disk->device = $this->dbFarmRole->GetSetting(Scalr_Db_Msr::DATA_STORAGE_EPH_DISK);
                     }
                 }
             }
         } catch (Exception $e) {
             $this->logger->error(new FarmLogMessage($this->dbServer->farmId, "Cannot get snaphotConfig for hostInit message: {$e->getMessage()}"));
         }
     }
     if ($this->replicationMaster && $this->volumeConfig) {
         $this->volumeConfig->recreateIfMissing = (int) $this->dbFarmRole->GetSetting(Scalr_Role_DbMsrBehavior::ROLE_DATA_STORAGE_RECREATE_IF_MISSING);
         if ($this->volumeConfig->type == MYSQL_STORAGE_ENGINE::EPH) {
             if ($this->dbFarmRole->Platform == SERVER_PLATFORMS::EC2 && !$this->volumeConfig->disks) {
                 $this->volumeConfig->disk->device = $this->dbFarmRole->GetSetting(Scalr_Db_Msr::DATA_STORAGE_EPH_DISK);
             }
         }
     } else {
         $this->volumeConfig = $this->getFreshVolumeConfig();
     }
 }
开发者ID:rickb838,项目名称:scalr,代码行数:41,代码来源:Info.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Scalr_Role_Behavior类代码示例发布时间:2022-05-23
下一篇:
PHP Scalr_Environment类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap