diff options
author | Sara Golemon <sara.golemon@mongodb.com> | 2019-01-10 18:42:27 +0000 |
---|---|---|
committer | Sara Golemon <sara.golemon@mongodb.com> | 2019-01-12 03:12:23 +0000 |
commit | 90c1759dab18a2105abaa31cf963c788c05c0e77 (patch) | |
tree | cbe08a55b9e23236c1ddef0ed4e19acfebb48de7 /src/mongo | |
parent | 2677ce10a8034e90c4dd24eb664e81d3316c30aa (diff) | |
download | mongo-90c1759dab18a2105abaa31cf963c788c05c0e77.tar.gz |
SERVER-38934 Remove IDLServerParameter (without storage)
Diffstat (limited to 'src/mongo')
-rw-r--r-- | src/mongo/idl/SConscript | 2 | ||||
-rw-r--r-- | src/mongo/idl/server_parameter.cpp | 35 | ||||
-rw-r--r-- | src/mongo/idl/server_parameter.h | 67 | ||||
-rw-r--r-- | src/mongo/idl/server_parameter_test.cpp | 196 | ||||
-rw-r--r-- | src/mongo/idl/server_parameter_test.h | 62 | ||||
-rw-r--r-- | src/mongo/idl/server_parameter_test.idl | 81 |
6 files changed, 0 insertions, 443 deletions
diff --git a/src/mongo/idl/SConscript b/src/mongo/idl/SConscript index ac53fb52393..d5b54a91486 100644 --- a/src/mongo/idl/SConscript +++ b/src/mongo/idl/SConscript @@ -43,8 +43,6 @@ env.Library( env.CppUnitTest( target='idl_server_parameter_test', source=[ - 'server_parameter_test.cpp', - env.Idlc('server_parameter_test.idl')[0], 'server_parameter_with_storage_test.cpp', env.Idlc('server_parameter_with_storage_test.idl')[0], 'server_parameter_specialized_test.cpp', diff --git a/src/mongo/idl/server_parameter.cpp b/src/mongo/idl/server_parameter.cpp index 01d72e42fc9..c2e4255bed1 100644 --- a/src/mongo/idl/server_parameter.cpp +++ b/src/mongo/idl/server_parameter.cpp @@ -43,20 +43,6 @@ MONGO_INITIALIZER_GROUP(EndServerParameterRegistration, ("BeginServerParameterRegistration"), ("BeginStartupOptionHandling")) -IDLServerParameter::IDLServerParameter(StringData name, ServerParameterType paramType) - : ServerParameter(ServerParameterSet::getGlobal(), - name, - paramType == SPT::kStartupOnly || paramType == SPT::kStartupAndRuntime, - paramType == SPT::kRuntimeOnly || paramType == SPT::kStartupAndRuntime) {} - -void IDLServerParameter::append(OperationContext* opCtx, - BSONObjBuilder& b, - const std::string& name) { - invariant(_appendBSON, - "append() called on IDLServerParamter with no appendBSON implementation"); - _appendBSON(opCtx, &b, name); -} - IDLServerParameterDeprecatedAlias::IDLServerParameterDeprecatedAlias(StringData name, ServerParameter* sp) : ServerParameter(ServerParameterSet::getGlobal(), @@ -69,27 +55,6 @@ IDLServerParameterDeprecatedAlias::IDLServerParameterDeprecatedAlias(StringData } } -Status IDLServerParameter::set(const BSONElement& newValueElement) try { - if (_fromBSON) { - return _fromBSON(newValueElement); - } else { - // Default fallback behavior: Cast to string and use 'from_string' method. - return setFromString(newValueElement.String()); - } -} catch (const AssertionException& ex) { - return {ErrorCodes::BadValue, - str::stream() << "Invalid value '" << newValueElement << "' for setParameter '" - << name() - << "': " - << ex.what()}; -} - -Status IDLServerParameter::setFromString(const std::string& str) { - invariant(_fromString, - "setFromString() called on IDLServerParamter with no setFromString implementation"); - return _fromString(str); -} - void IDLServerParameterDeprecatedAlias::append(OperationContext* opCtx, BSONObjBuilder& b, const std::string& fieldName) { diff --git a/src/mongo/idl/server_parameter.h b/src/mongo/idl/server_parameter.h index a01da364dcb..794bde5761e 100644 --- a/src/mongo/idl/server_parameter.h +++ b/src/mongo/idl/server_parameter.h @@ -51,73 +51,6 @@ namespace mongo { /** - * Specialization of ServerParameter used by IDL generator. - */ -class IDLServerParameter : public ServerParameter { -public: - IDLServerParameter(StringData name, ServerParameterType paramType); - - /** - * Define a callback for populating a BSONObj with the current setting. - */ - using appendBSON_t = void(OperationContext*, BSONObjBuilder*, StringData); - void setAppendBSON(std::function<appendBSON_t> appendBSON) { - _appendBSON = std::move(appendBSON); - } - - /** - * Encode the setting into BSON object. - * - * Typically invoked by {getParameter:...} to produce a dictionary - * of SCP settings. - */ - void append(OperationContext* opCtx, BSONObjBuilder& b, const std::string& name) final; - - /** - * Define a callback for setting the value from a BSONElement. - */ - using fromBSON_t = Status(const BSONElement&); - void setFromBSON(std::function<fromBSON_t> fromBSON) { - _fromBSON = std::move(fromBSON); - } - - /** - * Update the underlying value using a BSONElement. - * - * Allows setting non-basic values (e.g. vector<string>) - * via the {setParameter: ...} call. - */ - Status set(const BSONElement& newValueElement) final; - - /** - * Define a callback for setting the value from a string. - */ - using fromString_t = Status(StringData); - void setFromString(std::function<fromString_t> fromString) { - _fromString = std::move(fromString); - } - - /** - * Update the underlying value from a string. - * - * Typically invoked from commandline --setParameter usage. - */ - Status setFromString(const std::string& str) final; - - /** - * Helper method usable as setAppendBSON() callback when redaction of value is requested. - */ - static void redactedAppendBSON(OperationContext*, BSONObjBuilder* b, StringData name) { - b->append(name, "###"); - } - -protected: - std::function<appendBSON_t> _appendBSON; - std::function<fromBSON_t> _fromBSON; - std::function<fromString_t> _fromString; -}; - -/** * Proxy instance for deprecated aliases of set parameters. */ class IDLServerParameterDeprecatedAlias : public ServerParameter { diff --git a/src/mongo/idl/server_parameter_test.cpp b/src/mongo/idl/server_parameter_test.cpp deleted file mode 100644 index 6a541364b07..00000000000 --- a/src/mongo/idl/server_parameter_test.cpp +++ /dev/null @@ -1,196 +0,0 @@ -/** - * Copyright (C) 2018-present MongoDB, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * <http://www.mongodb.com/licensing/server-side-public-license>. - * - * As a special exception, the copyright holders give permission to link the - * code of portions of this program with the OpenSSL library under certain - * conditions as described in each individual source file and distribute - * linked combinations including the program with the OpenSSL library. You - * must comply with the Server Side Public License in all respects for - * all of the code used other than as permitted herein. If you modify file(s) - * with this exception, you may extend this exception to your version of the - * file(s), but you are not obligated to do so. If you do not wish to do so, - * delete this exception statement from your version. If you delete this - * exception statement from all source files in the program, then also delete - * it in the license file. - */ - -#include "mongo/platform/basic.h" - -#include "mongo/idl/server_parameter.h" -#include "mongo/unittest/unittest.h" - -namespace mongo { -namespace test { - -namespace { -std::string gCustomSetting; -} // namespace - -void customSettingAppendBSON(OperationContext*, BSONObjBuilder* builder, StringData name) { - builder->append(name, gCustomSetting); -} - -Status customSettingFromBSON(const BSONElement& element) { - gCustomSetting = element.String(); - return Status::OK(); -} - -Status customSettingFromString(StringData str) { - gCustomSetting = str.toString(); - return Status::OK(); -} -} // namespace test - -namespace { - -TEST(ServerParameter, setAppendBSON) { - IDLServerParameter param("setAppendBSON"_sd, ServerParameterType::kStartupOnly); - - param.setAppendBSON([](OperationContext*, BSONObjBuilder* builder, StringData name) { - builder->append(name, 42); - }); - BSONObjBuilder builder; - param.append(nullptr, builder, param.name()); - auto obj = builder.obj(); - ASSERT_EQ(obj.nFields(), 1); - ASSERT_EQ(obj[param.name()].Int(), 42); -} - -TEST(ServerParameter, setFromString) { - IDLServerParameter param("setFromString"_sd, ServerParameterType::kStartupOnly); - - param.setFromString([](StringData) { return Status::OK(); }); - ASSERT_OK(param.setFromString("A value")); - - param.setFromString([](StringData) { return Status(ErrorCodes::BadValue, "Can't set me."); }); - ASSERT_NOT_OK(param.setFromString("A value")); -} - -TEST(ServerParameter, setFromBSON) { - IDLServerParameter param("setFromBSON"_sd, ServerParameterType::kStartupOnly); - BSONElement elem; - - param.setFromBSON([](const BSONElement&) { return Status::OK(); }); - ASSERT_OK(param.set(elem)); - - param.setFromBSON( - [](const BSONElement&) { return Status(ErrorCodes::BadValue, "Can't set me."); }); - ASSERT_NOT_OK(param.set(elem)); -} - -TEST(ServerParameter, setFromBSONViaString) { - IDLServerParameter param("setFromBSONViaString"_sd, ServerParameterType::kStartupOnly); - auto obj = BSON("" - << "value"); - auto elem = obj.firstElement(); - - param.setFromString([](StringData) { return Status::OK(); }); - ASSERT_OK(param.set(elem)); - - param.setFromString([](StringData) { return Status(ErrorCodes::BadValue, "Can't set me."); }); - ASSERT_NOT_OK(param.set(elem)); -} - -TEST(ServerParameter, deprecatedAlias) { - IDLServerParameter param("basename"_sd, ServerParameterType::kStartupOnly); - IDLServerParameterDeprecatedAlias alias("aliasname"_sd, ¶m); - std::string value; - param.setFromString([&value](StringData str) { - value = str.toString(); - return Status::OK(); - }); - ASSERT_OK(param.setFromString("alpha")); - ASSERT_EQ("alpha", value); - - ASSERT_OK(alias.setFromString("bravo")); - ASSERT_EQ("bravo", value); -} - -ServerParameter* getServerParameter(const std::string& name) { - const auto& spMap = ServerParameterSet::getGlobal()->getMap(); - const auto& spIt = spMap.find(name); - ASSERT(spIt != spMap.end()); - - auto* sp = spIt->second; - ASSERT(sp); - return sp; -} - -TEST(IDLServerParameter, customSettingTest) { - auto* cst = getServerParameter("customSettingTest"); - ASSERT_OK(cst->setFromString("New Value")); - ASSERT_EQ(test::gCustomSetting, "New Value"); - - auto* cswobson = getServerParameter("customSettingWithoutFromBSON"); - ASSERT_OK(cswobson->set(BSON("" - << "no bson") - .firstElement())); - ASSERT_EQ(test::gCustomSetting, "no bson"); - - auto* depr = getServerParameter("customSettingTestDeprecated"); - ASSERT_OK(depr->setFromString("Value via depr name")); - ASSERT_EQ(test::gCustomSetting, "Value via depr name"); -} - -TEST(IDLServerParameter, customSettingWithRedaction) { - auto* csr = getServerParameter("customSettingWithRedaction"); - ASSERT_OK(csr->setFromString("Secret")); - ASSERT_EQ(test::gCustomSetting, "Secret"); - - BSONObjBuilder b; - csr->append(nullptr, b, csr->name()); - auto obj = b.obj(); - ASSERT_EQ(obj.nFields(), 1); - ASSERT_EQ(obj[csr->name()].String(), "###"); -} - -TEST(IDLServerParameter, customTestOnly) { - auto* cto = getServerParameter("customTestOnlyParameter"); - ASSERT_OK(cto->setFromString("enabled")); - ASSERT_EQ(test::gCustomSetting, "enabled"); - - { - BSONObjBuilder b; - cto->append(nullptr, b, cto->name()); - auto obj = b.obj(); - ASSERT_EQ(obj.nFields(), 1); - ASSERT_EQ(obj[cto->name()].String(), "enabled"); - } - - ServerParameterSet::getGlobal()->disableTestParameters(); - auto* disabled = getServerParameter("customTestOnlyParameter"); - ASSERT_NE(cto, disabled); - ASSERT_EQ(cto->name(), disabled->name()); - - { - BSONObjBuilder b; - disabled->append(nullptr, b, disabled->name()); - auto obj = b.obj(); - ASSERT_EQ(obj.nFields(), 0); - } - - auto status = disabled->setFromString("disabled"); - ASSERT_NOT_OK(status); - ASSERT_EQ(status.code(), ErrorCodes::BadValue); - ASSERT_EQ( - status.reason(), - "setParameter: 'customTestOnlyParameter' is only supported with 'enableTestCommands=true'"); - - ASSERT_EQ(test::gCustomSetting, "enabled"); -} - -} // namespace -} // namespace mongo diff --git a/src/mongo/idl/server_parameter_test.h b/src/mongo/idl/server_parameter_test.h deleted file mode 100644 index 1791b550472..00000000000 --- a/src/mongo/idl/server_parameter_test.h +++ /dev/null @@ -1,62 +0,0 @@ -/** - * Copyright (C) 2018-present MongoDB, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * <http://www.mongodb.com/licensing/server-side-public-license>. - * - * As a special exception, the copyright holders give permission to link the - * code of portions of this program with the OpenSSL library under certain - * conditions as described in each individual source file and distribute - * linked combinations including the program with the OpenSSL library. You - * must comply with the Server Side Public License in all respects for - * all of the code used other than as permitted herein. If you modify file(s) - * with this exception, you may extend this exception to your version of the - * file(s), but you are not obligated to do so. If you do not wish to do so, - * delete this exception statement from your version. If you delete this - * exception statement from all source files in the program, then also delete - * it in the license file. - */ - -#pragma once - -#include "mongo/platform/basic.h" - -#include "mongo/idl/server_parameter.h" - -namespace mongo { -namespace test { - -// The callbacks listed in this file are bound to the set parameter -// "customSettingsTest" defined in server_parameter_test.idl and -// instatiated from server_parater_test.cpp. - -/** - * Appends a single field named {name} to the {builder} object - * with a global string value previously set by one of the subsequent - * two callbacks. - */ -void customSettingAppendBSON(OperationContext*, BSONObjBuilder* builder, StringData name); - -/** - * Sets a global string value from the {element} which is - * expected to be of type String. - */ -Status customSettingFromBSON(const BSONElement& element); - -/** - * Sets a global string value from {str}. - */ -Status customSettingFromString(StringData str); - -} // namespace test -} // namespace mongo diff --git a/src/mongo/idl/server_parameter_test.idl b/src/mongo/idl/server_parameter_test.idl deleted file mode 100644 index 37722830396..00000000000 --- a/src/mongo/idl/server_parameter_test.idl +++ /dev/null @@ -1,81 +0,0 @@ -# Copyright (C) 2018-present MongoDB, Inc. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the Server Side Public License, version 1, -# as published by MongoDB, Inc. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# Server Side Public License for more details. -# -# You should have received a copy of the Server Side Public License -# along with this program. If not, see -# <http://www.mongodb.com/licensing/server-side-public-license>. -# -# As a special exception, the copyright holders give permission to link the -# code of portions of this program with the OpenSSL library under certain -# conditions as described in each individual source file and distribute -# linked combinations including the program with the OpenSSL library. You -# must comply with the Server Side Public License in all respects for -# all of the code used other than as permitted herein. If you modify file(s) -# with this exception, you may extend this exception to your version of the -# file(s), but you are not obligated to do so. If you do not wish to do so, -# delete this exception statement from your version. If you delete this -# exception statement from all source files in the program, then also delete -# it in the license file. -# - -global: - cpp_namespace: "mongo::test" - cpp_includes: - - "mongo/idl/server_parameter_test.h" - -imports: - - "mongo/idl/basic_types.idl" - -server_parameters: - customSettingTest: - set_at: startup - description: "Basic test setting using custom callbacks." - append_bson: "customSettingAppendBSON" - from_bson: "customSettingFromBSON" - from_string: "customSettingFromString" - deprecated_name: "customSettingTestDeprecated" - - customSettingWithoutFromBSON: - set_at: startup - description: "Basic test using default fromBSON callback." - append_bson: "customSettingAppendBSON" - from_string: "customSettingFromString" - - customSettingWithPositiveConditions: - set_at: startup - description: "Testing that conditions are created." - append_bson: "customSettingAppendBSON" - from_string: "customSettingFromString" - condition: - expr: "true" - preprocessor: "1 == 1" - - customSettingWithNegativeConditions: - set_at: startup - description: "Testing that conditions are created." - append_bson: "customSettingAppendBSON" - from_string: "customSettingFromString" - condition: - expr: "false" - preprocessor: "1 == 0" - - customSettingWithRedaction: - set_at: startup - description: "If requested, this setting will reply with ### as value" - from_string: "customSettingFromString" - redact: true - - customTestOnlyParameter: - set_at: startup - description: "That that 'test_only' params get disabled." - append_bson: "customSettingAppendBSON" - from_string: "customSettingFromString" - test_only: true |