Exemplo n.º 1
0
 public function xGrowStorageAction()
 {
     $dbFarmRole = DBFarmRole::LoadByID($this->getParam('farmRoleId'));
     $this->user->getPermissions()->validate($dbFarmRole->GetFarmObject());
     $behavior = Scalr_Role_Behavior::loadByName($dbFarmRole->GetRoleObject()->getDbMsrBehavior());
     $master = $behavior->getMasterServer($dbFarmRole);
     if ($master) {
         try {
             $volume = Scalr_Storage_Volume::init()->loadById($dbFarmRole->GetSetting(Scalr_Db_Msr::VOLUME_ID));
             if ($volume->type != MYSQL_STORAGE_ENGINE::EBS && $volume->type != MYSQL_STORAGE_ENGINE::RAID_EBS && $volume->type != 'raid') {
                 throw new Exception("Grow feature available only for EBS and RAID storage types");
             }
             if ($volume->size >= (int) $this->getParam('newSize')) {
                 throw new Exception("New size should be greather than current one ({$volume->size} GB)");
             }
             $volumeConfig = $volume->getConfig();
             $platformAccessData = PlatformFactory::NewPlatform($dbFarmRole->Platform)->GetPlatformAccessData($this->environment, $master);
             $newConfig = new stdClass();
             $newConfig->size = $this->getParam('newSize');
             $result = $master->scalarizr->mysql->growStorage($volumeConfig, $newConfig, $platformAccessData);
             // Do not remove. We need to wait a bit before operation will be registered in scalr.
             sleep(2);
             $this->response->data(array('operationId' => $result));
         } catch (Exception $e) {
             throw new Exception("Cannot grow storage: {$e->getMessage()}");
         }
     } else {
         throw new Exception("Impossible to increase storage size. No running master server.");
     }
 }
 public function OnHostDown(HostDownEvent $event)
 {
     if ($event->DBServer->IsRebooting() == 1) {
         $event->exit = 'reboot';
         return;
     }
     if (!$this->FarmID) {
         $event->exit = 'no-farm';
         return;
     }
     $dbFarm = DBFarm::LoadByID($this->FarmID);
     $servers = $dbFarm->GetServersByFilter(array('status' => array(SERVER_STATUS::RUNNING)));
     try {
         $DBFarmRole = $event->DBServer->GetFarmRoleObject();
         $is_synchronize = $DBFarmRole->NewRoleID ? true : false;
     } catch (Exception $e) {
         $is_synchronize = false;
     }
     try {
         $DBRole = DBRole::loadById($event->DBServer->roleId);
     } catch (Exception $e) {
     }
     //HUGE BUG HERE!
     $first_in_role_handled = false;
     $first_in_role_server = null;
     $event->msgExpected = count($servers);
     foreach ($servers as $DBServer) {
         if (!$DBServer instanceof DBServer) {
             continue;
         }
         $isfirstinrole = '0';
         $eventServerIsMaster = $event->DBServer->GetProperty(SERVER_PROPERTIES::DB_MYSQL_MASTER) || $event->DBServer->GetProperty(Scalr_Db_Msr::REPLICATION_MASTER);
         if ($eventServerIsMaster && !$first_in_role_handled) {
             if (!$is_synchronize && $DBServer->farmRoleId == $event->DBServer->farmRoleId) {
                 if (DBRole::loadById($DBServer->roleId)->hasBehavior(ROLE_BEHAVIORS::MYSQL) || DBRole::loadById($DBServer->roleId)->getDbMsrBehavior()) {
                     $first_in_role_handled = true;
                     $first_in_role_server = $DBServer;
                     $isfirstinrole = '1';
                 }
             }
         }
         $msg = new Scalr_Messaging_Msg_HostDown();
         //TODO:
         $msg->behaviour = $DBRole ? $DBRole->getBehaviors() : '*Unknown*';
         $msg->roleName = $DBRole ? $DBRole->name : '*Unknown*';
         $msg->localIp = $event->DBServer->localIp;
         $msg->remoteIp = $event->DBServer->remoteIp;
         $msg->isFirstInRole = $isfirstinrole;
         $msg->serverIndex = $event->DBServer->index;
         $msg->farmRoleId = $event->DBServer->farmRoleId;
         $msg->serverId = $event->DBServer->serverId;
         $msg->cloudLocation = $event->DBServer->GetCloudLocation();
         // If FarmRole was removed from farm, no configuration left
         if ($DBFarmRole) {
             $msg = Scalr_Scripting_Manager::extendMessage($msg, $event, $event->DBServer, $DBServer);
             if ($event->DBServer->farmRoleId != 0) {
                 foreach (Scalr_Role_Behavior::getListForRole(DBRole::loadById($event->DBServer->roleId)) as $behavior) {
                     $msg = $behavior->extendMessage($msg, $event->DBServer);
                 }
             }
         }
         $msg = $DBServer->SendMessage($msg, false, true);
         if ($msg->dbMessageId) {
             $event->msgCreated++;
         }
         $loopServerIsMaster = $DBServer->GetProperty(SERVER_PROPERTIES::DB_MYSQL_MASTER) || $DBServer->GetProperty(Scalr_Db_Msr::REPLICATION_MASTER);
         if ($loopServerIsMaster && $DBServer->status == SERVER_STATUS::RUNNING) {
             $doNotPromoteSlave2Master = true;
         }
     }
     if (!$DBFarmRole) {
         return;
     }
     if ($DBFarmRole->GetRoleObject()->getDbMsrBehavior() && !$doNotPromoteSlave2Master && !$DBFarmRole->GetSetting(Scalr_Db_Msr::SLAVE_TO_MASTER)) {
         $this->sendPromoteToMasterMessage($event);
     }
     //LEGACY MYSQL CODE:
     if ($DBFarmRole->GetRoleObject()->hasBehavior(ROLE_BEHAVIORS::MYSQL)) {
         // If EC2 master down
         if ($event->DBServer->GetProperty(SERVER_PROPERTIES::DB_MYSQL_MASTER) && $DBFarmRole) {
             $master = $dbFarm->GetMySQLInstances(true);
             if ($master[0]) {
                 return;
             }
             $msg = new Scalr_Messaging_Msg_Mysql_PromoteToMaster($DBFarmRole->GetSetting(DBFarmRole::SETTING_MYSQL_ROOT_PASSWORD), $DBFarmRole->GetSetting(DBFarmRole::SETTING_MYSQL_REPL_PASSWORD), $DBFarmRole->GetSetting(DBFarmRole::SETTING_MYSQL_STAT_PASSWORD));
             if ($event->DBServer->IsSupported("0.7")) {
                 if (in_array($event->DBServer->platform, array(SERVER_PLATFORMS::EC2, SERVER_PLATFORMS::CLOUDSTACK, SERVER_PLATFORMS::IDCF, SERVER_PLATFORMS::UCLOUD))) {
                     try {
                         $volume = Scalr_Storage_Volume::init()->loadById($DBFarmRole->GetSetting(DBFarmRole::SETTING_MYSQL_SCALR_VOLUME_ID));
                         $msg->volumeConfig = $volume->getConfig();
                     } catch (Exception $e) {
                         $this->Logger->error(new FarmLogMessage($event->DBServer->farmId, "Cannot create volumeConfig for PromoteToMaster message: {$e->getMessage()}"));
                     }
                 }
             } elseif ($event->DBServer->platform == SERVER_PLATFORMS::EC2) {
                 $msg->volumeId = $DBFarmRole->GetSetting(DBFarmRole::SETTING_MYSQL_MASTER_EBS_VOLUME_ID);
             }
             // Send Mysql_PromoteToMaster to the first server in the same avail zone as old master (if exists)
             // Otherwise send to first in role
             $platform = $event->DBServer->platform;
             if ($platform == SERVER_PLATFORMS::EC2) {
                 $availZone = $event->DBServer->GetProperty(EC2_SERVER_PROPERTIES::AVAIL_ZONE);
             }
             foreach ($servers as $DBServer) {
                 if ($DBServer->serverId == $event->DBServer->serverId) {
                     continue;
                 }
                 if ($platform == SERVER_PLATFORMS::EC2 && $DBServer->GetProperty(EC2_SERVER_PROPERTIES::AVAIL_ZONE) == $availZone || $platform != SERVER_PLATFORMS::EC2) {
                     if (DBRole::loadById($DBServer->roleId)->hasBehavior(ROLE_BEHAVIORS::MYSQL)) {
                         $DBFarmRole->SetSetting(DBFarmRole::SETTING_MYSQL_SLAVE_TO_MASTER, 1);
                         $DBServer->SetProperty(SERVER_PROPERTIES::DB_MYSQL_MASTER, 1);
                         $DBServer->SendMessage($msg, false, true);
                         return;
                     }
                 }
             }
             if ($first_in_role_server) {
                 $DBFarmRole->SetSetting(DBFarmRole::SETTING_MYSQL_SLAVE_TO_MASTER, 1);
                 $first_in_role_server->SetProperty(SERVER_PROPERTIES::DB_MYSQL_MASTER, 1);
                 $first_in_role_server->SendMessage($msg, false, true);
             }
         }
     }
 }
Exemplo n.º 3
0
 public function getConfiguration(DBServer $dbServer)
 {
     $configuration = new stdClass();
     $configuration->keyfile = $dbServer->GetFarmRoleObject()->GetSetting(self::ROLE_KEYFILE);
     $configuration->volumeConfig = $this->getVolumeConfig($dbServer->GetFarmRoleObject(), $dbServer);
     $configuration->snapshotConfig = $this->getSnapshotConfig($dbServer->GetFarmRoleObject(), $dbServer);
     $configuration->password = $dbServer->GetFarmRoleObject()->GetSetting(self::ROLE_PASSWORD);
     $configuration->replicaSetIndex = $dbServer->GetProperty(self::SERVER_REPLICA_SET_INDEX);
     $configuration->shardIndex = $dbServer->GetProperty(self::SERVER_SHARD_INDEX);
     $configuration->shardsTotal = $dbServer->GetFarmRoleObject()->GetSetting(self::ROLE_SHARDS_COUNT);
     $configuration->replicasPerShard = $dbServer->GetFarmRoleObject()->GetSetting(self::ROLE_REPLICAS_COUNT);
     $mmsApiKey = $dbServer->GetFarmRoleObject()->GetSetting(self::ROLE_MMS_API_KEY);
     if ($mmsApiKey) {
         $configuration->mms = new stdClass();
         $configuration->mms->apiKey = $mmsApiKey;
         $configuration->mms->secretKey = $dbServer->GetFarmRoleObject()->GetSetting(self::ROLE_MMS_SECRET_KEY);
     }
     if ($dbServer->GetFarmRoleObject()->GetSetting(self::ROLE_SSL_ENABLED) == 1) {
         $cert = new Scalr_Service_Ssl_Certificate();
         $cert->loadById($dbServer->GetFarmRoleObject()->GetSetting(self::ROLE_SSL_CERT_ID));
         $configuration->ssl = new stdClass();
         $configuration->ssl->privateKey = $cert->sslPkey;
         $configuration->ssl->certificate = $cert->sslCert;
         $configuration->ssl->privateKeyPassword = $cert->sslPkeyPassword;
     }
     $configServers = $this->db->GetAll("SELECT * FROM services_mongodb_config_servers WHERE\n                `farm_role_id` = ?\n            ", array($dbServer->farmRoleId));
     if (count($configServers) > 0) {
         $configuration->config_servers = array();
         foreach ($configServers as $cs) {
             $itm = new stdClass();
             $itm->id = $cs['config_server_index'];
             $itm->replicaSetIndex = $cs['replica_set_index'];
             $itm->shardIndex = $cs['shard_index'];
             try {
                 $volume = Scalr_Storage_Volume::init()->loadById($cs['volume_id']);
                 $volumeConfig = $volume->getConfig();
             } catch (Exception $e) {
             }
             $itm->volume = $volumeConfig;
             $configuration->config_servers[] = $itm;
         }
     }
     return $configuration;
 }
Exemplo n.º 4
0
 public function getVolumeConfig(DBFarmRole $dbFarmRole, DBServer $dbServer)
 {
     try {
         $volume = Scalr_Storage_Volume::init()->loadByFarmRoleServer($dbFarmRole->ID, $dbServer->index, $this->behavior);
         $volumeConfig = $volume->getConfig();
     } catch (Exception $e) {
     }
     if (!$volumeConfig) {
         $volumeConfig = new stdClass();
         $volumeConfig->type = $dbFarmRole->GetSetting(static::ROLE_DATA_STORAGE_ENGINE);
         switch ($volumeConfig->type) {
             case MYSQL_STORAGE_ENGINE::EPH:
                 if ($dbFarmRole->Platform == SERVER_PLATFORMS::RACKSPACE) {
                     $storageProvider = 'cf';
                     $volumeConfig->disk = new stdClass();
                     $volumeConfig->disk->type = 'loop';
                     $volumeConfig->disk->size = '75%root';
                 } elseif ($dbFarmRole->isOpenstack()) {
                     $storageProvider = 'swift';
                     $volumeConfig->disk = new stdClass();
                     $volumeConfig->disk->type = 'loop';
                     $volumeConfig->disk->size = '75%root';
                 } elseif ($dbFarmRole->Platform == SERVER_PLATFORMS::GCE) {
                     $storageProvider = 'gcs';
                     $volumeConfig->disk = array('type' => 'gce_ephemeral', 'name' => 'ephemeral-disk-0');
                     $volumeConfig->size = "80%";
                 } elseif ($dbFarmRole->Platform == SERVER_PLATFORMS::EC2) {
                     /*
                      * NOT SUPPORTED
                     $storageProvider = 's3';
                     
                     $volumeConfig->disk = $this->dbFarmRole->GetSetting(Scalr_Db_Msr::DATA_STORAGE_EPH_DISK);
                     $volumeConfig->size = "80%";
                     */
                 }
                 $volumeConfig->snap_backend = sprintf("%s://scalr-%s-%s/data-bundles/%s/%s", $storageProvider, $dbFarmRole->GetFarmObject()->EnvID, $dbFarmRole->CloudLocation, $dbFarmRole->FarmID, $this->behavior);
                 $volumeConfig->vg = $this->behavior;
                 break;
             default:
                 $volumeConfig->size = $dbFarmRole->GetSetting(static::ROLE_DATA_STORAGE_EBS_SIZE);
                 break;
         }
     }
     return $volumeConfig;
 }
Exemplo n.º 5
0
 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();
     }
 }
Exemplo n.º 6
0
 /**
  * @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));
     }
 }
Exemplo n.º 7
0
 public static function onPromoteToMasterResult(Scalr_Messaging_Msg_DbMsr_PromoteToMasterResult $message, DBServer $dbServer)
 {
     $dbFarm = $dbServer->GetFarmObject();
     $dbFarmRole = $dbServer->GetFarmRoleObject();
     $dbFarmRole->SetSetting(Scalr_Db_Msr::SLAVE_TO_MASTER, 0);
     if ($message->status == Scalr_Messaging_Msg_Mysql_PromoteToMasterResult::STATUS_FAILED) {
         $dbServer->SetProperty(Scalr_Db_Msr::REPLICATION_MASTER, 0);
         return false;
     }
     $dbSettings = $message->{$message->dbType};
     //Update volumeCondig
     if ($dbSettings->volumeConfig) {
         try {
             $storageVolume = Scalr_Storage_Volume::init();
             try {
                 $storageVolume->loadById($dbSettings->volumeConfig->id);
                 $storageVolume->setConfig($dbSettings->volumeConfig);
                 $storageVolume->save();
             } catch (Exception $e) {
                 if (strpos($e->getMessage(), 'not found')) {
                     $storageVolume->loadBy(array('id' => $dbSettings->volumeConfig->id, 'client_id' => $dbServer->clientId, 'env_id' => $dbServer->envId, 'name' => "'{$message->dbType}' data volume", 'type' => $dbFarmRole->GetSetting(Scalr_Db_Msr::DATA_STORAGE_ENGINE), 'platform' => $dbServer->platform, 'size' => $dbSettings->volumeConfig->size, 'fstype' => $dbSettings->volumeConfig->fstype, 'purpose' => $message->dbType, 'farm_roleid' => $dbFarmRole->ID, 'server_index' => $dbServer->index));
                     $storageVolume->setConfig($dbSettings->volumeConfig);
                     $storageVolume->save(true);
                 } else {
                     throw $e;
                 }
             }
         } catch (Exception $e) {
             Logger::getLogger(__CLASS__)->error(new FarmLogMessage($dbServer->farmId, "Cannot save storage volume: {$e->getMessage()}"));
         }
     }
     self::onCreateDataBundleResult($message, $dbServer);
     return true;
 }
Exemplo n.º 8
0
 public function getVolumeConfig(DBFarmRole $dbFarmRole, DBServer $dbServer)
 {
     $r = new ReflectionClass($this);
     if ($r->hasConstant("ROLE_VOLUME_ID")) {
         if ($dbFarmRole->GetSetting(static::ROLE_VOLUME_ID)) {
             try {
                 $volume = Scalr_Storage_Volume::init()->loadById($dbFarmRole->GetSetting(static::ROLE_VOLUME_ID));
                 $volumeConfig = $volume->getConfig();
             } catch (Exception $e) {
             }
         }
         if (!$volumeConfig) {
             $volumeConfig = new stdClass();
             $volumeConfig->type = $dbFarmRole->GetSetting(static::ROLE_DATA_STORAGE_ENGINE);
             if (in_array($dbFarmRole->GetSetting(static::ROLE_DATA_STORAGE_ENGINE), array(MYSQL_STORAGE_ENGINE::EBS, MYSQL_STORAGE_ENGINE::CSVOL))) {
                 $volumeConfig->size = $dbFarmRole->GetSetting(static::ROLE_DATA_STORAGE_EBS_SIZE);
             } elseif ($dbFarmRole->GetSetting(static::ROLE_DATA_STORAGE_ENGINE) == MYSQL_STORAGE_ENGINE::EPH) {
                 $volumeConfig->snap_backend = sprintf("cf://scalr-%s-%s/data-bundles/%s/%s", $dbServer->envId, $dbServer->GetCloudLocation(), $dbFarmRole->FarmID, $this->behavior);
                 $volumeConfig->vg = $this->behavior;
                 $volumeConfig->disk = new stdClass();
                 $volumeConfig->disk->type = 'loop';
                 $volumeConfig->disk->size = '75%root';
             }
         }
         return $volumeConfig;
     } else {
         return false;
     }
 }
Exemplo n.º 9
0
 public function xGrowStorageAction()
 {
     $dbFarmRole = DBFarmRole::LoadByID($this->getParam('farmRoleId'));
     $this->user->getPermissions()->validate($dbFarmRole->GetFarmObject());
     $textBehavior = $dbFarmRole->GetRoleObject()->getDbMsrBehavior();
     $behavior = Scalr_Role_Behavior::loadByName($textBehavior);
     $master = $behavior->getMasterServer($dbFarmRole);
     /* @var $master \DBServer */
     if ($master) {
         $port = $master->getPort(\DBServer::PORT_API);
         try {
             $volume = Scalr_Storage_Volume::init()->loadById($dbFarmRole->GetSetting(Scalr_Db_Msr::VOLUME_ID));
             if ($volume->type != MYSQL_STORAGE_ENGINE::EBS && $volume->type != MYSQL_STORAGE_ENGINE::RAID_EBS && $volume->type != 'raid') {
                 throw new Exception("Grow feature available only for EBS and RAID storage types");
             }
             if ($this->getParam('newSize') && $volume->size >= (int) $this->getParam('newSize')) {
                 throw new Exception("New size should be greather than current one ({$volume->size} GB)");
             }
             $volumeConfig = $volume->getConfig();
             $platformAccessData = PlatformFactory::NewPlatform($dbFarmRole->Platform)->GetPlatformAccessData($this->environment, $master);
             $newConfig = new stdClass();
             if ($this->getParam('newSize')) {
                 $newConfig->size = $this->getParam('newSize');
             }
             if ($this->getParam('volumeType')) {
                 $newConfig->volumeType = $this->getParam('volumeType');
             }
             if ($this->getParam('iops')) {
                 $newConfig->iops = $this->getParam('iops');
             }
             switch ($textBehavior) {
                 case ROLE_BEHAVIORS::REDIS:
                     $operationId = $master->scalarizr->redis->growStorage($volumeConfig, $newConfig, $platformAccessData);
                     break;
                 case ROLE_BEHAVIORS::POSTGRESQL:
                     $operationId = $master->scalarizr->postgresql->growStorage($volumeConfig, $newConfig, $platformAccessData);
                     break;
                 default:
                     $operationId = $master->scalarizr->mysql->growStorage($volumeConfig, $newConfig, $platformAccessData);
                     break;
             }
             $this->response->data(['serverId' => $master->serverId, 'operationId' => $operationId]);
         } catch (Exception $e) {
             throw new Exception("Cannot grow storage: {$e->getMessage()}");
         }
     } else {
         throw new Exception("Impossible to increase storage size. No running master server.");
     }
 }
Exemplo n.º 10
0
 /**
  * @param   int     $farmRoleId
  * @param   int     $newSize        optional
  * @param   string  $volumeType     optional
  * @param   int     $iops           optional
  * @throws  Exception
  */
 public function xGrowStorageAction($farmRoleId, $newSize = 0, $volumeType = '', $iops = 0)
 {
     $this->request->restrictAccess(Acl::RESOURCE_DB_DATABASE_STATUS, Acl::PERM_DB_DATABASE_STATUS_MANAGE);
     $dbFarmRole = DBFarmRole::LoadByID($farmRoleId);
     $this->user->getPermissions()->validate($dbFarmRole->GetFarmObject());
     $textBehavior = $dbFarmRole->GetRoleObject()->getDbMsrBehavior();
     $behavior = Scalr_Role_Behavior::loadByName($textBehavior);
     $master = $behavior->getMasterServer($dbFarmRole);
     /* @var $master \DBServer */
     if ($master) {
         $port = $master->getPort(\DBServer::PORT_API);
         try {
             $volume = Scalr_Storage_Volume::init()->loadById($dbFarmRole->GetSetting(Scalr_Db_Msr::VOLUME_ID));
             if ($volume->type != MYSQL_STORAGE_ENGINE::EBS && $volume->type != MYSQL_STORAGE_ENGINE::RAID_EBS && $volume->type != 'raid') {
                 throw new Exception("Grow feature available only for EBS and RAID storage types");
             }
             if ($newSize && $volume->size >= $newSize) {
                 throw new Exception("New size should be greather than current one ({$volume->size} GB)");
             }
             $volumeConfig = $volume->getConfig();
             $platformAccessData = PlatformFactory::NewPlatform($dbFarmRole->Platform)->GetPlatformAccessData($this->environment, $master);
             $newConfig = new stdClass();
             if ($newSize) {
                 $newConfig->size = $newSize;
             }
             if ($volumeType) {
                 $newConfig->volumeType = $volumeType;
             }
             if ($iops && ($volumeType == 'io1' || !$volumeType && $volumeConfig->volumeType == 'io1')) {
                 $newConfig->iops = $iops;
             }
             switch ($textBehavior) {
                 case ROLE_BEHAVIORS::REDIS:
                     $operationId = $master->scalarizr->redis->growStorage($volumeConfig, $newConfig, $platformAccessData);
                     break;
                 case ROLE_BEHAVIORS::POSTGRESQL:
                     $operationId = $master->scalarizr->postgresql->growStorage($volumeConfig, $newConfig, $platformAccessData);
                     break;
                 default:
                     $operationId = $master->scalarizr->mysql->growStorage($volumeConfig, $newConfig, $platformAccessData);
                     break;
             }
             $dbFarmRole->SetSetting(Entity\FarmRoleSetting::STORAGE_GROW_OPERATION_ID, $operationId);
             $dbFarmRole->SetSetting(Entity\FarmRoleSetting::STORAGE_GROW_SERVER_ID, $master->serverId);
             $dbFarmRole->SetSetting(Entity\FarmRoleSetting::STORAGE_GROW_LAST_ERROR, '');
             $this->response->data(['serverId' => $master->serverId, 'operationId' => $operationId]);
         } catch (Exception $e) {
             throw new Exception("Cannot grow storage: {$e->getMessage()}");
         }
     } else {
         throw new Exception("Impossible to increase storage size. No running master server.");
     }
 }
Exemplo n.º 11
0
 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();
         } catch (Exception $e) {
             $this->logger->error(new FarmLogMessage($this->dbServer->farmId, "Cannot get snaphotConfig for hostInit message: {$e->getMessage()}"));
         }
     }
     //TODO:
     /** If new role and there is no volume, we need to create a new one **/
     if ($this->replicationMaster && !$this->volumeConfig) {
         $this->volumeConfig = new stdClass();
         $this->volumeConfig->type = $this->dbFarmRole->GetSetting(Scalr_Db_Msr::DATA_STORAGE_ENGINE);
         // For any Block storage APIs
         if ($this->volumeConfig->type == MYSQL_STORAGE_ENGINE::RAID_EBS) {
             $this->volumeConfig->type = 'raid';
             $this->volumeConfig->vg = $this->databaseType;
             $this->volumeConfig->level = $this->dbFarmRole->GetSetting(Scalr_Db_Msr::DATA_STORAGE_RAID_LEVEL);
             $this->volumeConfig->disks = array();
             for ($i = 1; $i <= $this->dbFarmRole->GetSetting(Scalr_Db_Msr::DATA_STORAGE_RAID_DISKS_COUNT); $i++) {
                 $dsk = new stdClass();
                 $dsk->type = 'ebs';
                 $dsk->size = $this->dbFarmRole->GetSetting(Scalr_Db_Msr::DATA_STORAGE_RAID_DISK_SIZE);
                 $this->volumeConfig->disks[] = $dsk;
             }
             $this->volumeConfig->snapPv = new stdClass();
             $this->volumeConfig->snapPv->type = 'ebs';
             $this->volumeConfig->snapPv->size = 1;
         } else {
             if ($this->volumeConfig->type != MYSQL_STORAGE_ENGINE::EPH && $this->volumeConfig->type != MYSQL_STORAGE_ENGINE::RAID_EBS) {
                 $this->volumeConfig->size = $this->dbFarmRole->GetSetting(Scalr_Db_Msr::DATA_STORAGE_EBS_SIZE);
             } else {
                 if ($this->volumeConfig->type == MYSQL_STORAGE_ENGINE::EPH) {
                     if ($this->dbFarmRole->Platform == SERVER_PLATFORMS::RACKSPACE) {
                         $this->volumeConfig->snap_backend = sprintf("cf://scalr-%s-%s/data-bundles/%s/%s", $this->dbFarmRole->GetFarmObject()->EnvID, $this->dbFarmRole->CloudLocation, $this->dbFarmRole->FarmID, $this->databaseType);
                         $this->volumeConfig->vg = $this->databaseType;
                         $this->volumeConfig->disk = new stdClass();
                         $this->volumeConfig->disk->type = 'loop';
                         $this->volumeConfig->disk->size = '75%root';
                     } elseif ($this->dbFarmRole->Platform == SERVER_PLATFORMS::EC2) {
                         $this->volumeConfig->snap_backend = sprintf("s3://scalr-%s-%s/data-bundles/%s/%s", $this->dbFarmRole->GetFarmObject()->EnvID, $this->dbFarmRole->CloudLocation, $this->dbFarmRole->FarmID, $this->databaseType);
                         $this->volumeConfig->vg = $this->databaseType;
                         $this->volumeConfig->disk = $this->dbFarmRole->GetSetting(Scalr_Db_Msr::DATA_STORAGE_EPH_DISK);
                         $this->volumeConfig->size = "80%";
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 12
0
 public function xGrowStorageAction()
 {
     $dbFarmRole = DBFarmRole::LoadByID($this->getParam('farmRoleId'));
     $this->user->getPermissions()->validate($dbFarmRole->GetFarmObject());
     $behavior = Scalr_Role_Behavior::loadByName($dbFarmRole->GetRoleObject()->getDbMsrBehavior());
     $master = $behavior->getMasterServer($dbFarmRole);
     if ($master) {
         $port = $master->GetProperty(SERVER_PROPERTIES::SZR_API_PORT);
         if (!$port) {
             $port = 8010;
         }
         try {
             $client = Scalr_Net_Scalarizr_Client::getClient($master, Scalr_Net_Scalarizr_Client::NAMESPACE_MYSQL, $port);
             $volume = Scalr_Storage_Volume::init()->loadById($dbFarmRole->GetSetting(Scalr_Db_Msr::VOLUME_ID));
             if ($volume->type != MYSQL_STORAGE_ENGINE::EBS && $volume->type != MYSQL_STORAGE_ENGINE::RAID_EBS && $volume->type != 'raid') {
                 throw new Exception("Grow feature available only for EBS and RAID storage types");
             }
             if ($volume->size >= (int) $this->getParam('newSize')) {
                 throw new Exception("New size should be greather than current one ({$volume->size} GB)");
             }
             $volumeConfig = $volume->getConfig();
             $platformAccessData = PlatformFactory::NewPlatform($dbFarmRole->Platform)->GetPlatformAccessData($this->environment, $master);
             $operationId = $client->growStorage($volumeConfig, $this->getParam('newSize'), $platformAccessData);
             $master->operations->add($operationId, Operations::MYSQL_GROW_VOLUME);
             $this->response->data(array('operationId' => $operationId));
         } catch (Exception $e) {
             throw new Exception("Cannot grow storage: {$e->getMessage()}");
         }
     } else {
         throw new Exception("Impossible to increase storage size. No running master server.");
     }
 }