diff --git a/arangod/CMakeLists.txt b/arangod/CMakeLists.txt index bb2bcdfe84..4c8ea5b65f 100644 --- a/arangod/CMakeLists.txt +++ b/arangod/CMakeLists.txt @@ -458,6 +458,7 @@ SET(ARANGOD_SOURCES RestServer/EndpointFeature.cpp RestServer/FileDescriptorsFeature.cpp RestServer/FlushFeature.cpp + RestServer/FortuneFeature.cpp RestServer/FrontendFeature.cpp RestServer/InitDatabaseFeature.cpp RestServer/LockfileFeature.cpp diff --git a/arangod/RestServer/FortuneFeature.cpp b/arangod/RestServer/FortuneFeature.cpp new file mode 100644 index 0000000000..64a74f2ba3 --- /dev/null +++ b/arangod/RestServer/FortuneFeature.cpp @@ -0,0 +1,81 @@ +//////////////////////////////////////////////////////////////////////////////// +/// DISCLAIMER +/// +/// Copyright 2016 ArangoDB GmbH, Cologne, Germany +/// +/// Licensed under the Apache License, Version 2.0 (the "License"); +/// you may not use this file except in compliance with the License. +/// You may obtain a copy of the License at +/// +/// http://www.apache.org/licenses/LICENSE-2.0 +/// +/// Unless required by applicable law or agreed to in writing, software +/// distributed under the License is distributed on an "AS IS" BASIS, +/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +/// See the License for the specific language governing permissions and +/// limitations under the License. +/// +/// Copyright holder is ArangoDB GmbH, Cologne, Germany +/// +/// @author Jan Steemann +//////////////////////////////////////////////////////////////////////////////// + +#include "RestServer/FortuneFeature.h" + +#include "Logger/Logger.h" +#include "ProgramOptions/Parameters.h" +#include "ProgramOptions/ProgramOptions.h" +#include "Random/RandomGenerator.h" + +using namespace arangodb; +using namespace arangodb::options; + +namespace { + +static char const* cookies[] = { + "The number of computer scientists in a room is inversely proportional to the number of bugs in their code.", + "Unnamed Law: If it happens, it must be possible.", + "Of course there's no reason for it, it's just our policy.", + "Your mode of life will be changed to ASCII.", + "My program works if i take out the bugs", + "Your lucky number has been disconnected.", + "Any sufficiently advanced bug is indistinguishable from a feature.", + "Real Users hate Real Programmers.", + "Reality is just a crutch for people who can't handle science fiction.", + "You're definitely on their list. The question to ask next is what list it is.", + "Any given program will expand to fill available memory.", + "Steinbach's Guideline for Systems Programming: Never test for an error condition you don't know how to handle.", + "Bug, n: A son of a glitch.", + "Recursion n.: See Recursion.", + "I think we're in trouble. -- Han Solo", + "18,446,744,073,709,551,616 is a big number", + "Civilization, as we know it, will end sometime this evening. See SYSNOTE tomorrow for more information.", + "Everything ends badly. Otherwise it wouldn't end.", + "The moon may be smaller than Earth, but it's further away.", + "Never make anything simple and efficient when a way can be found to make it complex and wonderful.", + "" +}; + +} // namespace + +FortuneFeature::FortuneFeature( + application_features::ApplicationServer& server) + : ApplicationFeature(server, "Fortune"), _fortune(false) { + startsAfter("Bootstrap"); +} + +void FortuneFeature::collectOptions(std::shared_ptr options) { + options->addHiddenOption("fortune", "show fortune cookie on startup", + new BooleanParameter(&_fortune)); +} + +void FortuneFeature::start() { + if (!_fortune) { + return; + } + + uint32_t r = RandomGenerator::interval(sizeof(::cookies) / sizeof(::cookies)[0]); + if (strlen(::cookies[r]) > 0) { + LOG_TOPIC(INFO, Logger::FIXME) << ::cookies[r]; + } +} diff --git a/arangod/RestServer/FortuneFeature.h b/arangod/RestServer/FortuneFeature.h new file mode 100644 index 0000000000..901980064c --- /dev/null +++ b/arangod/RestServer/FortuneFeature.h @@ -0,0 +1,42 @@ +//////////////////////////////////////////////////////////////////////////////// +/// DISCLAIMER +/// +/// Copyright 2016 ArangoDB GmbH, Cologne, Germany +/// +/// Licensed under the Apache License, Version 2.0 (the "License"); +/// you may not use this file except in compliance with the License. +/// You may obtain a copy of the License at +/// +/// http://www.apache.org/licenses/LICENSE-2.0 +/// +/// Unless required by applicable law or agreed to in writing, software +/// distributed under the License is distributed on an "AS IS" BASIS, +/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +/// See the License for the specific language governing permissions and +/// limitations under the License. +/// +/// Copyright holder is ArangoDB GmbH, Cologne, Germany +/// +/// @author Jan Steemann +//////////////////////////////////////////////////////////////////////////////// + +#ifndef APPLICATION_FEATURES_FORTUNE_FEATURE_H +#define APPLICATION_FEATURES_FORTUNE_FEATURE_H 1 + +#include "ApplicationFeatures/ApplicationFeature.h" + +namespace arangodb { +class FortuneFeature final : public application_features::ApplicationFeature { + public: + explicit FortuneFeature(application_features::ApplicationServer&); + + public: + void collectOptions(std::shared_ptr) override final; + void start() override final; + + private: + bool _fortune; +}; +} + +#endif diff --git a/arangod/RestServer/arangod.cpp b/arangod/RestServer/arangod.cpp index c5700ec327..0dc11cbeda 100644 --- a/arangod/RestServer/arangod.cpp +++ b/arangod/RestServer/arangod.cpp @@ -79,6 +79,7 @@ #include "RestServer/EndpointFeature.h" #include "RestServer/FileDescriptorsFeature.h" #include "RestServer/FlushFeature.h" +#include "RestServer/FortuneFeature.h" #include "RestServer/FrontendFeature.h" #include "RestServer/InitDatabaseFeature.h" #include "RestServer/LockfileFeature.h" @@ -180,6 +181,7 @@ static int runServer(int argc, char** argv, ArangoGlobalContext &context) { server.addFeature(new EnvironmentFeature(server)); server.addFeature(new FileDescriptorsFeature(server)); server.addFeature(new FlushFeature(server)); + server.addFeature(new FortuneFeature(server)); server.addFeature(new FoxxQueuesFeature(server)); server.addFeature(new FrontendFeature(server)); server.addFeature(new GeneralServerFeature(server));