isc::data::ConstElementPtr
StatsMgr::statisticSetMaxSampleAgeHandler(const std::string& /*name*/,
- const isc::data::ConstElementPtr& params) {
+ const isc::data::ConstElementPtr& params) {
std::string name, error;
StatsDuration duration;
if (!getStatName(params, name, error)) {
if (instance().setMaxSampleAge(name, duration)) {
return (createAnswer(CONTROL_RESULT_SUCCESS,
"Statistic '" + name + "' duration limit is set."));
- //"Statistic '" + name + "' duration limit is set to " + std::to_string(duration) + "."));
} else {
return (createAnswer(CONTROL_RESULT_ERROR,
"No '" + name + "' statistic found"));
isc::data::ConstElementPtr
StatsMgr::statisticSetMaxSampleCountHandler(const std::string& /*name*/,
- const isc::data::ConstElementPtr& params) {
+ const isc::data::ConstElementPtr& params) {
std::string name, error;
uint32_t max_samples;
if (!getStatName(params, name, error)) {
if (instance().setMaxSampleCount(name, max_samples)) {
return (createAnswer(CONTROL_RESULT_SUCCESS,
"Statistic '" + name + "' count limit is set."));
- //"Statistic '" + name + "' count limit is set to " + std::to_string(max_samples) + "."));
} else {
return (createAnswer(CONTROL_RESULT_ERROR,
"No '" + name + "' statistic found"));
bool
StatsMgr::getStatDuration(const isc::data::ConstElementPtr& params,
- StatsDuration& duration,
- std::string& reason) {
+ StatsDuration& duration,
+ std::string& reason) {
if (!params) {
reason = "Missing mandatory 'duration' parameters.";
return (false);
int64_t minutes = stat_minutes->intValue();
int64_t seconds = stat_seconds->intValue();
int64_t milliseconds = stat_milliseconds->intValue();
- duration = boost::posix_time::time_duration(hours,minutes,seconds,milliseconds);
+ duration = boost::posix_time::time_duration(hours, minutes, seconds, milliseconds);
return (true);
}
bool
StatsMgr::getStatMaxSamples(const isc::data::ConstElementPtr& params,
- uint32_t& max_samples,
- std::string& reason) {
+ uint32_t& max_samples,
+ std::string& reason) {
if (!params) {
- reason = "Missing mandatory 'max_samples' parameter.";
+ reason = "Missing mandatory 'max-samples' parameter.";
return (false);
}
- ConstElementPtr stat_max_samples = params->get("max_samples");
+ ConstElementPtr stat_max_samples = params->get("max-samples");
if (!stat_max_samples) {
- reason = "Missing mandatory 'max_samples' parameter.";
+ reason = "Missing mandatory 'max-samples' parameter.";
return (false);
}
if (stat_max_samples->getType() != Element::integer) {
- reason = "'max_samples' parameter expected to be an integer.";
+ reason = "'max-samples' parameter expected to be an integer.";
return (false);
}
statisticRemoveHandler(const std::string& name,
const isc::data::ConstElementPtr& params);
- /// @brief Handles statistic-setMaxSampleAge command
+ /// @brief Handles statistic-set-max-sample-age command
///
/// This method handles statistic-setMaxSampleAge command, which set max_sample_age
/// limit of a given statistic and leaves max_sample_count disabled.
/// @return answer containing information about current statistic's limits
static isc::data::ConstElementPtr
statisticSetMaxSampleAgeHandler(const std::string& name,
- const isc::data::ConstElementPtr& params);
+ const isc::data::ConstElementPtr& params);
- /// @brief Handles statistic-setMaxSampleAge command
+ /// @brief Handles statistic-set-max-sample-age command
///
/// This method handles statistic-setMaxSampleAge command, which set max_sample_age
/// limit of a given statistic and leaves max_sample_age disabled.
/// Example params structure:
/// {
/// "name": "packets-received",
- /// "max_samples": 15
+ /// "max-samples": 15
/// }
///
/// @param name name of the command (ignored, should be "statistic-setMaxSampleCount")
- /// @param params structure containing a map that contains "name" and "max_samples"
+ /// @param params structure containing a map that contains "name" and "max-samples"
/// @return answer containing information about current statistic's limits
static isc::data::ConstElementPtr
statisticSetMaxSampleCountHandler(const std::string& name,
- const isc::data::ConstElementPtr& params);
+ const isc::data::ConstElementPtr& params);
/// @brief Handles statistic-get-all command
///
/// @param reason [out] failure reason (if error is detected)
/// @return true (if everything is ok), false otherwise
static bool getStatDuration(const isc::data::ConstElementPtr& params,
- StatsDuration& duration,
- std::string& reason);
+ StatsDuration& duration,
+ std::string& reason);
/// @brief Utility method that attempts to extract count limit for
/// a given statistic
///
/// This method attempts to extract count limit for a given statistic
/// from the params structure.
- /// It is expected to be a map that contains 'max_samples' element,
+ /// It is expected to be a map that contains 'max-samples' element,
/// that is of type int. If present as expected, statistic count
/// limit (max_samples) is set and true is returned.
/// If missing or is of incorrect type, the reason is specified in reason
/// @param reason [out] failure reason (if error is detected)
/// @return true (if everything is ok), false otherwise
static bool getStatMaxSamples(const isc::data::ConstElementPtr& params,
- uint32_t& max_samples,
- std::string& reason);
+ uint32_t& max_samples,
+ std::string& reason);
// This is a global context. All statistics will initially be stored here.
StatContextPtr global_;
EXPECT_EQ(0, StatsMgr::instance().count());
}
-// This test checks whether statistic-setMaxSampleAge command really set
+// This test checks whether statistic-set-max-sample-age command really set
// max_sample_age limit correctly.
TEST_F(StatsMgrTest, commandSetMaxSampleAge) {
StatsMgr::instance().setValue("alpha", static_cast<int64_t>(1234));
params->set("milliseconds", Element::create(0));
ConstElementPtr rsp =
- StatsMgr::instance().statisticSetMaxSampleAgeHandler("statistic-setMaxSampleAge", params);
+ StatsMgr::instance().statisticSetMaxSampleAgeHandler("statistic-set-max-sample-age", params);
int status_code;
ASSERT_NO_THROW(parseAnswer(status_code, rsp));
EXPECT_EQ(CONTROL_RESULT_SUCCESS, status_code);
EXPECT_EQ(StatsMgr::instance().getSize("alpha"), 5);
}
-// Test checks if statistic-setMaxSampleAge is able to handle:
+// Test checks if statistic-set-max-sample-age is able to handle:
// - a request without parameters
// - a request without at least one of duration parameters
// - a request with missing statistic name
// Case 1: a request without parameters
ConstElementPtr rsp =
- StatsMgr::instance().statisticSetMaxSampleAgeHandler("statistic-setMaxSampleAge", ElementPtr());
+ StatsMgr::instance().statisticSetMaxSampleAgeHandler("statistic-set-max-sample-age", ElementPtr());
int status_code;
ASSERT_NO_THROW(parseAnswer(status_code, rsp));
EXPECT_EQ(status_code, CONTROL_RESULT_ERROR);
ElementPtr params = Element::createMap();
params->set("seconds", Element::create(2));
params->set("milliseconds", Element::create(3));
- rsp = StatsMgr::instance().statisticSetMaxSampleAgeHandler("statistic-setMaxSampleAge", params);
+ rsp = StatsMgr::instance().statisticSetMaxSampleAgeHandler("statistic-set-max-sample-age", params);
ASSERT_NO_THROW(parseAnswer(status_code, rsp));
EXPECT_EQ(status_code, CONTROL_RESULT_ERROR);
params->set("minutes", Element::create(1));
params->set("seconds", Element::create(2));
params->set("milliseconds", Element::create(3));
- rsp = StatsMgr::instance().statisticSetMaxSampleAgeHandler("statistic-setMaxSampleAge", params);
+ rsp = StatsMgr::instance().statisticSetMaxSampleAgeHandler("statistic-set-max-sample-age", params);
ASSERT_NO_THROW(parseAnswer(status_code, rsp));
EXPECT_EQ(status_code, CONTROL_RESULT_ERROR);
// Case 4: a request for non-existing statistic
params->set("name", Element::create("alpha"));
- rsp = StatsMgr::instance().statisticSetMaxSampleAgeHandler("statistic-setMaxSampleAge", params);
+ rsp = StatsMgr::instance().statisticSetMaxSampleAgeHandler("statistic-set-max-sample-age", params);
EXPECT_EQ("{ \"result\": 1, \"text\": \"No 'alpha' statistic found\" }",
rsp->str());
}
-// This test checks whether statistic-setMaxSampleCount command really set
+// This test checks whether statistic-set-max-sample-count command really set
// max_sample_count limit correctly.
TEST_F(StatsMgrTest, commandSetMaxSampleCount) {
StatsMgr::instance().setValue("alpha", static_cast<int64_t>(1234));
ElementPtr params = Element::createMap();
params->set("name", Element::create("alpha"));
- params->set("max_samples", Element::create(15));
+ params->set("max-samples", Element::create(15));
ConstElementPtr rsp =
- StatsMgr::instance().statisticSetMaxSampleCountHandler("statistic-setMaxSampleCount", params);
+ StatsMgr::instance().statisticSetMaxSampleCountHandler("statistic-set-max-sample-count", params);
int status_code;
ASSERT_NO_THROW(parseAnswer(status_code, rsp));
EXPECT_EQ(CONTROL_RESULT_SUCCESS, status_code);
EXPECT_EQ(StatsMgr::instance().getSize("alpha"), 15);
}
-// Test checks if statistic-setMaxSampleAge is able to handle:
+// Test checks if statistic-set-max-sample-age is able to handle:
// - a request without parameters
-// - a request without max_samples parameter
+// - a request without max-samples parameter
// - a request with missing statistic name
// - a request for non-existing statistic.
TEST_F(StatsMgrTest, commandSetMaxSampleCountNegative) {
// Case 1: a request without parameters
ConstElementPtr rsp =
- StatsMgr::instance().statisticSetMaxSampleCountHandler("statistic-setMaxSampleCount", ElementPtr());
+ StatsMgr::instance().statisticSetMaxSampleCountHandler("statistic-set-max-sample-count", ElementPtr());
int status_code;
ASSERT_NO_THROW(parseAnswer(status_code, rsp));
EXPECT_EQ(status_code, CONTROL_RESULT_ERROR);
- // Case 2: a request without max_samples parameter
+ // Case 2: a request without max-samples parameter
ElementPtr params = Element::createMap();
params->set("name", Element::create("beta"));
- rsp = StatsMgr::instance().statisticSetMaxSampleCountHandler("statistic-setMaxSampleCount", params);
+ rsp = StatsMgr::instance().statisticSetMaxSampleCountHandler("statistic-set-max-sample-count", params);
ASSERT_NO_THROW(parseAnswer(status_code, rsp));
EXPECT_EQ(status_code, CONTROL_RESULT_ERROR);
// Case 3: a request with missing statistic name
params = Element::createMap();
- params->set("max_samples", Element::create(10));
- rsp = StatsMgr::instance().statisticSetMaxSampleCountHandler("statistic-setMaxSampleCount", params);
+ params->set("max-samples", Element::create(10));
+ rsp = StatsMgr::instance().statisticSetMaxSampleCountHandler("statistic-set-max-sample-count", params);
ASSERT_NO_THROW(parseAnswer(status_code, rsp));
EXPECT_EQ(status_code, CONTROL_RESULT_ERROR);
// Case 4: a request for non-existing statistic
params->set("name", Element::create("alpha"));
- rsp = StatsMgr::instance().statisticSetMaxSampleCountHandler("statistic-setMaxSampleCount", params);
+ rsp = StatsMgr::instance().statisticSetMaxSampleCountHandler("statistic-set-max-sample-count", params);
EXPECT_EQ("{ \"result\": 1, \"text\": \"No 'alpha' statistic found\" }",
rsp->str());
}