-
Notifications
You must be signed in to change notification settings - Fork 285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[MultiDB]: throwing exception when database_config.json doesn't exist #319
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9993672
[MultiDB]: throwing exception when database_config.json doesn't exist…
dzhangalibaba 727a538
update file name
dzhangalibaba cf3fac9
address code format
dzhangalibaba 5c18e59
add UT and logs
dzhangalibaba cc58463
fix typo
dzhangalibaba 1579a18
fix typo
dzhangalibaba File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
#include <system_error> | ||
#include <fstream> | ||
#include "json.hpp" | ||
#include "logger.h" | ||
|
||
#include "common/dbconnector.h" | ||
#include "common/redisreply.h" | ||
|
@@ -17,8 +18,14 @@ namespace swss { | |
|
||
void SonicDBConfig::initialize(const string &file) | ||
{ | ||
|
||
SWSS_LOG_ENTER(); | ||
|
||
if (m_init) | ||
{ | ||
SWSS_LOG_ERROR("SonicDBConfig already initialized"); | ||
throw runtime_error("SonicDBConfig already initialized"); | ||
} | ||
|
||
ifstream i(file); | ||
if (i.good()) | ||
|
@@ -47,48 +54,55 @@ void SonicDBConfig::initialize(const string &file) | |
} | ||
catch (domain_error& e) | ||
{ | ||
SWSS_LOG_ERROR("key doesn't exist in json object, NULL value has no iterator >> %s\n", e.what()); | ||
throw runtime_error("key doesn't exist in json object, NULL value has no iterator >> " + string(e.what())); | ||
} | ||
catch (exception &e) | ||
{ | ||
SWSS_LOG_ERROR("Sonic database config file syntax error >> %s\n", e.what()); | ||
throw runtime_error("Sonic database config file syntax error >> " + string(e.what())); | ||
} | ||
} | ||
else | ||
{ | ||
SWSS_LOG_ERROR("Sonic database config file doesn't exist at %s\n", file.c_str()); | ||
throw runtime_error("Sonic database config file doesn't exist at " + file); | ||
} | ||
} | ||
|
||
string SonicDBConfig::getDbInst(const string &dbName) | ||
{ | ||
if (!m_init) | ||
initialize(); | ||
return m_db_info[dbName].first; | ||
return m_db_info.at(dbName).first; | ||
} | ||
|
||
int SonicDBConfig::getDbId(const string &dbName) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Add a unit test case for non existing dbName #Closed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. DONE. Added all five API test cases. |
||
{ | ||
if (!m_init) | ||
initialize(); | ||
return m_db_info[dbName].second; | ||
return m_db_info.at(dbName).second; | ||
} | ||
|
||
string SonicDBConfig::getDbSock(const string &dbName) | ||
{ | ||
if (!m_init) | ||
initialize(); | ||
return m_inst_info[getDbInst(dbName)].first; | ||
return m_inst_info.at(getDbInst(dbName)).first; | ||
} | ||
|
||
string SonicDBConfig::getDbHostname(const string &dbName) | ||
{ | ||
if (!m_init) | ||
initialize(); | ||
return m_inst_info[getDbInst(dbName)].second.first; | ||
return m_inst_info.at(getDbInst(dbName)).second.first; | ||
} | ||
|
||
int SonicDBConfig::getDbPort(const string &dbName) | ||
{ | ||
if (!m_init) | ||
initialize(); | ||
return m_inst_info[getDbInst(dbName)].second.second; | ||
return m_inst_info.at(getDbInst(dbName)).second.second; | ||
} | ||
|
||
constexpr const char *SonicDBConfig::DEFAULT_SONIC_DB_CONFIG_FILE; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a unit test case for non existing dbName #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DONE. Added all five API test cases.