public function setMsrSettings($settings) { if ($this->replicationMaster) { parent::setMsrSettings($settings); $roleSettings = array(Scalr_Db_Msr_Mysql2::REPL_PASSWORD => $settings->replPassword, Scalr_Db_Msr_Mysql2::ROOT_PASSWORD => $settings->rootPassword, Scalr_Db_Msr_Mysql2::STAT_PASSWORD => $settings->statPassword, Scalr_Db_Msr_Mysql2::LOG_POS => $settings->logPos, Scalr_Db_Msr_Mysql2::LOG_FILE => $settings->logFile); foreach ($roleSettings as $name => $value) { $this->dbFarmRole->SetSetting($name, $value, Entity\FarmRoleSetting::TYPE_LCL); } } }
public function setMsrSettings($settings) { if ($this->replicationMaster) { parent::setMsrSettings($settings); $roleSettings = array(Scalr_Db_Msr_Postgresql::ROOT_USERNAME => $settings->rootUser, Scalr_Db_Msr_Postgresql::ROOT_PASSWORD => $settings->rootPassword, Scalr_Db_Msr_Postgresql::ROOT_SSH_PRIV_KEY => $settings->rootSshPrivateKey, Scalr_Db_Msr_Postgresql::ROOT_SSH_PUB_KEY => $settings->rootSshPublicKey, Scalr_Db_Msr_Postgresql::XLOG_LOCATION => $settings->currentXlogLocation); foreach ($roleSettings as $name => $value) { $this->dbFarmRole->SetSetting($name, $value, DBFarmRole::TYPE_LCL); } } }
public function setMsrSettings($settings) { if ($this->replicationMaster) { parent::setMsrSettings($settings); $roleSettings = array(Scalr_Db_Msr_Redis::MASTER_PASSWORD => $settings->masterPassword); foreach ($roleSettings as $name => $value) { $this->dbFarmRole->SetSetting($name, $value); } } }
public function ListFarmRoleParamsJson() { $farmRoleId = $this->GetArg("farm-role-id"); if (!$farmRoleId) { throw new Exception("'farm-role-id' required"); } $dbFarmRole = DBFarmRole::LoadByID($farmRoleId); if ($dbFarmRole->FarmID != $this->DBServer->farmId) { throw new Exception("You can request this information ONLY for roles within server farm"); } $result = new stdClass(); // Base configuration if ($this->DBServer->farmRoleId == $farmRoleId) { $data = Scalr_Role_Behavior::loadByName(ROLE_BEHAVIORS::BASE)->getBaseConfiguration($this->DBServer); foreach ((array) $data as $k => $v) { $result->{$k} = $v; } } $role = $dbFarmRole->GetRoleObject(); $behaviors = $role->getBehaviors(); foreach ($behaviors as $behavior) { $data = null; if ($behavior == ROLE_BEHAVIORS::MONGODB || $behavior == ROLE_BEHAVIORS::CHEF || $behavior == ROLE_BEHAVIORS::HAPROXY || $behavior == ROLE_BEHAVIORS::NGINX || $behavior == ROLE_BEHAVIORS::RABBITMQ || $behavior == ROLE_BEHAVIORS::APACHE || $behavior == ROLE_BEHAVIORS::VPC_ROUTER) { $data = Scalr_Role_Behavior::loadByName($behavior)->getConfiguration($this->DBServer); } if ($data === null) { if ($behavior == ROLE_BEHAVIORS::MYSQL) { $data = new stdClass(); $data->logFile = $dbFarmRole->GetSetting(DBFarmRole::SETTING_MYSQL_LOG_FILE); $data->logPos = $dbFarmRole->GetSetting(DBFarmRole::SETTING_MYSQL_LOG_POS); $data->rootPassword = $dbFarmRole->GetSetting(DBFarmRole::SETTING_MYSQL_ROOT_PASSWORD); $data->replPassword = $dbFarmRole->GetSetting(DBFarmRole::SETTING_MYSQL_REPL_PASSWORD); $data->statPassword = $dbFarmRole->GetSetting(DBFarmRole::SETTING_MYSQL_STAT_PASSWORD); $data->replicationMaster = (int) $this->DBServer->GetProperty(SERVER_PROPERTIES::DB_MYSQL_MASTER); } else { try { $dbMsrInfo = Scalr_Db_Msr_Info::init($dbFarmRole, $this->DBServer, $behavior); $data = $dbMsrInfo->getMessageProperties(); } catch (Exception $e) { } } } if ($data) { $result->{$behavior} = $data; } } return $result; }
public function setMsrSettings($settings) { if ($this->replicationMaster) { parent::setMsrSettings($settings); $roleSettings = array(Scalr_Db_Msr_Redis::MASTER_PASSWORD => $settings->masterPassword); if ($settings->ports) { $roleSettings[Scalr_Db_Msr_Redis::PORTS_ARRAY] = @json_encode($settings->ports); } if ($settings->passwords) { $roleSettings[Scalr_Db_Msr_Redis::PASSWD_ARRAY] = @json_encode($settings->passwords); } foreach ($roleSettings as $name => $value) { $this->dbFarmRole->SetSetting($name, $value, DBFarmRole::TYPE_LCL); } } }
private function sendNewDbMsrMasterUpMessage(DBServer $newMasterServer) { $dbFarmRole = $newMasterServer->GetFarmRoleObject(); $servers = $dbFarmRole->GetServersByFilter(array('status' => array(SERVER_STATUS::INIT, SERVER_STATUS::RUNNING))); $dbType = $newMasterServer->GetFarmRoleObject()->GetRoleObject()->getDbMsrBehavior(); $props = Scalr_Db_Msr_Info::init($dbFarmRole, $newMasterServer, $dbType)->getMessageProperties(); foreach ($servers as $dbServer) { $msg = new Scalr_Messaging_Msg_DbMsr_NewMasterUp($dbFarmRole->GetRoleObject()->getBehaviors(), $dbFarmRole->GetRoleObject()->name, $newMasterServer->localIp, $newMasterServer->remoteIp, $dbType); $msg->{$dbType} = new stdClass(); $msg->{$dbType}->snapshotConfig = $props->snapshotConfig; foreach (Scalr_Role_Behavior::getListForFarmRole($dbFarmRole) as $behavior) { $msg = $behavior->extendMessage($msg, $dbServer); } $dbServer->SendMessage($msg); } }
private function sendNewDbMsrMasterUpMessage(\DBServer $newMasterServer, $event) { $dbFarmRole = $newMasterServer->GetFarmRoleObject(); $servers = $dbFarmRole->GetServersByFilter(array('status' => array(\SERVER_STATUS::INIT, \SERVER_STATUS::RUNNING))); $dbType = $newMasterServer->GetFarmRoleObject()->GetRoleObject()->getDbMsrBehavior(); $props = \Scalr_Db_Msr_Info::init($dbFarmRole, $newMasterServer, $dbType)->getMessageProperties(); foreach ($servers as $dbServer) { $msg = new \Scalr_Messaging_Msg_DbMsr_NewMasterUp($dbType); $msg->setServerMetaData($newMasterServer); $msg->{$dbType} = new \stdClass(); $msg->{$dbType}->snapshotConfig = $props->snapshotConfig; foreach (\Scalr_Role_Behavior::getListForFarmRole($dbFarmRole) as $behavior) { $msg = $behavior->extendMessage($msg, $dbServer); } $dbServer->SendMessage($msg, false, true); } }
public function handleMessage(Scalr_Messaging_Msg $message, DBServer $dbServer) { try { $dbFarmRole = $dbServer->GetFarmRoleObject(); } catch (Exception $e) { } switch (get_class($message)) { case "Scalr_Messaging_Msg_HostUp": if ($message->dbType && in_array($message->dbType, array(ROLE_BEHAVIORS::REDIS, ROLE_BEHAVIORS::POSTGRESQL, ROLE_BEHAVIORS::MYSQL2))) { $dbMsrInfo = Scalr_Db_Msr_Info::init($dbFarmRole, $dbServer, $message->dbType); $dbMsrInfo->setMsrSettings($message->{$message->dbType}); } break; case "Scalr_Messaging_Msg_DbMsr_PromoteToMasterResult": if (Scalr_Db_Msr::onPromoteToMasterResult($message, $dbServer)) { Scalr::FireEvent($dbServer->farmId, new NewDbMsrMasterUpEvent($dbServer)); } break; case "Scalr_Messaging_Msg_DbMsr_CreateDataBundleResult": if ($message->status == "ok") { Scalr_Db_Msr::onCreateDataBundleResult($message, $dbServer); } else { $dbFarmRole->SetSetting(Scalr_Db_Msr::DATA_BUNDLE_IS_RUNNING, 0); //TODO: store last error } break; case "Scalr_Messaging_Msg_DbMsr_CreateBackupResult": if ($message->status == "ok") { Scalr_Db_Msr::onCreateBackupResult($message, $dbServer); } else { $dbFarmRole->SetSetting(Scalr_Db_Msr::DATA_BACKUP_IS_RUNNING, 0); //TODO: store last error } break; } }
function addDbMsrInfo(Scalr_Db_Msr_Info $msrInfo) { $this->dbType = $msrInfo->databaseType; $this->{$msrInfo->databaseType} = $msrInfo->getMessageProperties(); }
public function handleMessage(Scalr_Messaging_Msg $message, DBServer $dbServer) { parent::handleMessage($message, $dbServer); try { $dbFarmRole = $dbServer->GetFarmRoleObject(); $storageType = $dbFarmRole->GetSetting(Scalr_Db_Msr::DATA_STORAGE_ENGINE); $storageGeneration = $storageType == 'lvm' ? 2 : 1; } catch (Exception $e) { } switch (get_class($message)) { case "Scalr_Messaging_Msg_HostUp": if ($message->dbType && in_array($message->dbType, array(ROLE_BEHAVIORS::REDIS, ROLE_BEHAVIORS::POSTGRESQL, ROLE_BEHAVIORS::MYSQL2, ROLE_BEHAVIORS::PERCONA, ROLE_BEHAVIORS::MARIADB))) { $dbMsrInfo = Scalr_Db_Msr_Info::init($dbFarmRole, $dbServer, $message->dbType); $dbMsrInfo->setMsrSettings($message->{$message->dbType}); if ($message->{$message->dbType}->snapshotConfig) { $dbFarmRole->SetSetting(self::ROLE_NO_DATA_BUNDLE_FOR_SLAVES, 0, DBFarmRole::TYPE_LCL); } if ($message->{$message->dbType}->restore) { $this->db->Execute("INSERT INTO storage_restore_configs SET farm_roleid = ?, dtadded=NOW(), manifest = ?", array($dbFarmRole->ID, $message->{$message->dbType}->restore->cloudfsSource)); $dbFarmRole->SetSetting(self::ROLE_NO_DATA_BUNDLE_FOR_SLAVES, 0, DBFarmRole::TYPE_LCL); $dbFarmRole->SetSetting(Scalr_Db_Msr::DATA_BUNDLE_LAST_TS, time(), DBFarmRole::TYPE_LCL); $dbFarmRole->SetSetting(Scalr_Db_Msr::DATA_BUNDLE_IS_RUNNING, 0, DBFarmRole::TYPE_LCL); } if ($message->{$message->dbType}->masterPassword) { $dbFarmRole->SetSetting(self::ROLE_MASTER_PASSWORD, $message->{$message->dbType}->masterPassword, DBFarmRole::TYPE_LCL); } } break; case "Scalr_Messaging_Msg_DbMsr_PromoteToMasterResult": if ($message->{$message->dbType}->restore) { $this->db->Execute("INSERT INTO storage_restore_configs SET farm_roleid = ?, dtadded=NOW(), manifest = ?", array($dbFarmRole->ID, $message->{$message->dbType}->restore->cloudfsSource)); $dbFarmRole->SetSetting(self::ROLE_NO_DATA_BUNDLE_FOR_SLAVES, 0, DBFarmRole::TYPE_LCL); } if (Scalr_Db_Msr::onPromoteToMasterResult($message, $dbServer)) { if ($message->{$this->behavior}->snapshotConfig) { $dbFarmRole->SetSetting(self::ROLE_NO_DATA_BUNDLE_FOR_SLAVES, 0, DBFarmRole::TYPE_LCL); } Scalr::FireEvent($dbServer->farmId, new NewDbMsrMasterUpEvent($dbServer)); } break; case "Scalr_Messaging_Msg_DbMsr_CreateDataBundleResult": if ($message->status == "ok") { if (isset($message->{$message->dbType}->restore) && isset($message->{$message->dbType}->restore->backupType)) { $t = $message->{$message->dbType}->restore; if ($t->backupType == 'incremental') { $parentManifest = $this->db->GetOne("\n SELECT manifest FROM storage_restore_configs WHERE farm_roleid = ? ORDER BY id DESC LIMIT 1\n ", array($dbFarmRole->ID)); } $this->db->Execute("\n INSERT INTO storage_restore_configs SET farm_roleid = ?, dtadded=NOW(), manifest = ?, type = ?, parent_manifest = ?\n ", array($dbFarmRole->ID, $t->cloudfsSource, $t->backupType, $parentManifest)); unset($t); } $dbFarmRole->SetSetting(self::ROLE_NO_DATA_BUNDLE_FOR_SLAVES, 0, DBFarmRole::TYPE_LCL); Scalr_Db_Msr::onCreateDataBundleResult($message, $dbServer); } else { $dbFarmRole->SetSetting(Scalr_Db_Msr::DATA_BUNDLE_IS_RUNNING, 0, DBFarmRole::TYPE_LCL); // TODO: store last error } $this->updateBackupHistory($dbServer, 'bundle', $message->status, $message->lastError); break; case "Scalr_Messaging_Msg_DbMsr_CreateBackupResult": if ($message->status == "ok") { Scalr_Db_Msr::onCreateBackupResult($message, $dbServer); } else { $dbFarmRole->SetSetting(Scalr_Db_Msr::DATA_BACKUP_IS_RUNNING, 0, DBFarmRole::TYPE_LCL); } $this->updateBackupHistory($dbServer, 'backup', $message->status, $message->lastError); break; } }
public function ListFarmRoleParams() { $farmRoleId = $this->GetArg("farm-role-id"); if (!$farmRoleId) { throw new Exception("'farm-role-id' required"); } $dbFarmRole = DBFarmRole::LoadByID($farmRoleId); if ($dbFarmRole->FarmID != $this->DBServer->farmId) { throw new Exception("You can request this information ONLY for roles within server farm"); } $ResponseDOMDocument = $this->CreateResponse(); // Add volumes information try { if ($this->DBServer->farmRoleId == $farmRoleId) { $storage = new FarmRoleStorage($dbFarmRole); $vols = $storage->getVolumesConfigs($this->DBServer->index); $volumes = array(); foreach ($vols as $i => $volume) { if ($volume->id) { $volumes[] = $volume; } } $bodyEl = $this->serialize($volumes, 'volumes', $ResponseDOMDocument); $ResponseDOMDocument->documentElement->appendChild($bodyEl); } } catch (Exception $e) { $this->Logger->fatal("ListFarmRoleParams::Storage: {$e->getMessage()}"); } $role = $dbFarmRole->GetRoleObject(); $behaviors = $role->getBehaviors(); foreach ($behaviors as $behavior) { $data = null; if ($behavior == ROLE_BEHAVIORS::MONGODB) { $data = Scalr_Role_Behavior::loadByName($behavior)->getConfiguration($this->DBServer); } if ($behavior == ROLE_BEHAVIORS::CHEF) { $data = Scalr_Role_Behavior::loadByName($behavior)->getConfiguration($this->DBServer); } if ($behavior == ROLE_BEHAVIORS::HAPROXY) { $data = Scalr_Role_Behavior::loadByName($behavior)->getConfiguration($this->DBServer); } if ($behavior == ROLE_BEHAVIORS::NGINX) { $data = Scalr_Role_Behavior::loadByName($behavior)->getConfiguration($this->DBServer); } if ($behavior == ROLE_BEHAVIORS::RABBITMQ) { $data = Scalr_Role_Behavior::loadByName($behavior)->getConfiguration($this->DBServer); } if ($behavior == ROLE_BEHAVIORS::APACHE) { $data = Scalr_Role_Behavior::loadByName($behavior)->getConfiguration($this->DBServer); } if ($data === null) { if ($behavior == ROLE_BEHAVIORS::CF_CLOUD_CONTROLLER) { $data = new stdClass(); $data->version = $dbFarmRole->GetSetting(Scalr_Role_Behavior_CfCloudController::ROLE_VERSION); } else { if ($behavior == ROLE_BEHAVIORS::MYSQL) { $data = new stdClass(); $data->logFile = $dbFarmRole->GetSetting(DBFarmRole::SETTING_MYSQL_LOG_FILE); $data->logPos = $dbFarmRole->GetSetting(DBFarmRole::SETTING_MYSQL_LOG_POS); $data->rootPassword = $dbFarmRole->GetSetting(DBFarmRole::SETTING_MYSQL_ROOT_PASSWORD); $data->replPassword = $dbFarmRole->GetSetting(DBFarmRole::SETTING_MYSQL_REPL_PASSWORD); $data->statPassword = $dbFarmRole->GetSetting(DBFarmRole::SETTING_MYSQL_STAT_PASSWORD); $data->replicationMaster = (int) $this->DBServer->GetProperty(SERVER_PROPERTIES::DB_MYSQL_MASTER); //TODO: Storage } else { try { $dbMsrInfo = Scalr_Db_Msr_Info::init($dbFarmRole, $this->DBServer, $behavior); $data = $dbMsrInfo->getMessageProperties(); } catch (Exception $e) { } } } } if ($data) { $bodyEl = $this->serialize($data, $behavior, $ResponseDOMDocument); $ResponseDOMDocument->documentElement->appendChild($bodyEl); } } return $ResponseDOMDocument; }
public function ListFarmRoleParams() { $farmRoleId = $this->GetArg("farm-role-id"); if (!$farmRoleId) { throw new Exception("'farm-role-id' required"); } $dbFarmRole = DBFarmRole::LoadByID($farmRoleId); if ($dbFarmRole->FarmID != $this->DBServer->farmId) { throw new Exception("You can request this information ONLY for roles within server farm"); } $ResponseDOMDocument = $this->CreateResponse(); // Base configuration if ($this->DBServer->farmRoleId == $farmRoleId) { $data = Scalr_Role_Behavior::loadByName(ROLE_BEHAVIORS::BASE)->getBaseConfiguration($this->DBServer); foreach ((array) $data as $k => $v) { $bodyEl = $this->serialize($v, $k, $ResponseDOMDocument); $ResponseDOMDocument->documentElement->appendChild($bodyEl); } } $role = $dbFarmRole->GetRoleObject(); $behaviors = $role->getBehaviors(); foreach ($behaviors as $behavior) { $data = null; if ($behavior == ROLE_BEHAVIORS::MONGODB || $behavior == ROLE_BEHAVIORS::CHEF || $behavior == ROLE_BEHAVIORS::HAPROXY || $behavior == ROLE_BEHAVIORS::NGINX || $behavior == ROLE_BEHAVIORS::RABBITMQ || $behavior == ROLE_BEHAVIORS::APACHE || $behavior == ROLE_BEHAVIORS::VPC_ROUTER) { $data = Scalr_Role_Behavior::loadByName($behavior)->getConfiguration($this->DBServer); } if ($data === null) { if ($behavior == ROLE_BEHAVIORS::CF_CLOUD_CONTROLLER) { $data = new stdClass(); $data->version = $dbFarmRole->GetSetting(Scalr_Role_Behavior_CfCloudController::ROLE_VERSION); } else { if ($behavior == ROLE_BEHAVIORS::MYSQL) { $data = new stdClass(); $data->logFile = $dbFarmRole->GetSetting(Entity\FarmRoleSetting::MYSQL_LOG_FILE); $data->logPos = $dbFarmRole->GetSetting(Entity\FarmRoleSetting::MYSQL_LOG_POS); $data->rootPassword = $dbFarmRole->GetSetting(Entity\FarmRoleSetting::MYSQL_ROOT_PASSWORD); $data->replPassword = $dbFarmRole->GetSetting(Entity\FarmRoleSetting::MYSQL_REPL_PASSWORD); $data->statPassword = $dbFarmRole->GetSetting(Entity\FarmRoleSetting::MYSQL_STAT_PASSWORD); $data->replicationMaster = (int) $this->DBServer->GetProperty(SERVER_PROPERTIES::DB_MYSQL_MASTER); //TODO: Storage } else { try { $dbMsrInfo = Scalr_Db_Msr_Info::init($dbFarmRole, $this->DBServer, $behavior); $data = $dbMsrInfo->getMessageProperties(); } catch (Exception $e) { } } } } if ($data) { $bodyEl = $this->serialize($data, $behavior, $ResponseDOMDocument); $ResponseDOMDocument->documentElement->appendChild($bodyEl); } } return $ResponseDOMDocument; }