20 #include "containeroptions/containeroptionparser.h" 22 #include "jsonparser.h" 27 ContainerOptionParser::ContainerOptionParser() :
28 m_options(new DynamicContainerOptions())
32 void ContainerOptionParser::readConfigElement(
const json_t *element)
34 if (!json_is_object(element)) {
35 std::string errorMessage(
"Configure entry is not an object");
36 log_error() << errorMessage;
37 throw ContainerOptionParseError(errorMessage);
40 bool writeBufferEnabled =
false;
42 std::string errorMessage(
"Could not parse config due to: 'writeBufferEnabled' not found.");
43 log_error() << errorMessage;
44 throw ContainerOptionParseError(errorMessage);
47 m_options->setWriteBufferEnabled(writeBufferEnabled);
49 if (writeBufferEnabled ==
true) {
50 bool enableTemporaryFilesystemWriteBuffer =
false;
52 "temporaryFileSystemWriteBufferEnabled",
53 enableTemporaryFilesystemWriteBuffer))
55 log_warn() <<
"Could not parse config due to: 'enableTemporaryFilesystemWriteBuffer' not found.";
57 m_options->setTemporaryFileSystemWriteBufferEnabled(enableTemporaryFilesystemWriteBuffer);
59 if (enableTemporaryFilesystemWriteBuffer) {
60 int temporaryFileSystemSize = DEFAULT_TEMPORARY_FILESYSTEM_SIZE;
62 "temporaryFileSystemSize",
63 temporaryFileSystemSize))
65 log_error() <<
"Could not parse config due to: 'temporaryFileSystemSize' not found.";
67 m_options->setTemporaryFileSystemSize(temporaryFileSystemSize);
75 if (config.size() == 0) {
76 std::string errorMessage(
"Empty JSON config strings are not supported.");
77 log_error() << errorMessage;
82 json_t *root = json_loads(config.c_str(), 0, &error);
85 std::string errorMessage(
"Could not parse config: " 86 + std::string(error.text)
88 log_error() << errorMessage;
92 if (!json_is_array(root)) {
93 std::string errorMessage(
"Root JSON element is not an array");
94 log_error() << errorMessage;
103 json_array_foreach(root, index, element) {
104 readConfigElement(element);
112 std::unique_ptr<DynamicContainerOptions> ret = std::move(m_options);
std::unique_ptr< DynamicContainerOptions > parse(const std::string &config)
Parse config needed for starting up the container in a correct manner.
Developers guide to adding a config item:
static bool read(const json_t *element, const char *key, std::string &result)
Reads a string from a JSON Object.