-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- support parsing a YAML file to configure server - docker image support Signed-off-by: Yifan Yuan <[email protected]> ,
- Loading branch information
Showing
8 changed files
with
279 additions
and
42 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# // { | ||
# // "serverConfig": { | ||
# // "uds": "/var/run/stream_conv.sock", | ||
# // "workdir": "/tmp/stream_conv" | ||
# // }, | ||
# // "logConfig": { | ||
# // "level": 0, | ||
# // "mode": "stdout" | ||
# // } | ||
# // } | ||
globalConfig: | ||
servAddr: /var/run/stream_conv.sock | ||
workDir: /tmp/stream_conv | ||
logConfig: | ||
level: 0 | ||
mode: stdout | ||
rotateNum: 3 | ||
limitSizeMB: 10 | ||
path: /var/log/overlaybd/stream_convertor.log |
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
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
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
Copyright The Overlaybd Authors | ||
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. | ||
*/ | ||
#pragma once | ||
|
||
#include <string> | ||
#include <vector> | ||
#include "config_utils.h" | ||
|
||
namespace App { | ||
|
||
struct LogConfigPara : public App::ConfigGroup { | ||
APPCFG_CLASS | ||
APPCFG_PARA(level, uint32_t, 1); | ||
APPCFG_PARA(path, std::string, "/var/log/overlaybd/stream-convertor.log"); | ||
APPCFG_PARA(limitSizeMB, uint32_t, 10); | ||
APPCFG_PARA(rotateNum, int, 3); | ||
APPCFG_PARA(mode, std::string, "stdout"); | ||
}; | ||
|
||
// struct ServerConfigPara : public App::ConfigGroup { | ||
// APPCFG_CLASS | ||
|
||
// }; | ||
|
||
struct GlobalConfigPara : public App::ConfigGroup { | ||
APPCFG_CLASS; | ||
APPCFG_PARA(servAddr, std::string, "/var/run/stream_conv.sock"); | ||
APPCFG_PARA(workDir, std::string, "/tmp/stream_conv"); | ||
//APPCFG_PARA(ServerConfig, ServerConfigPara); | ||
APPCFG_PARA(logConfig, LogConfigPara); | ||
}; | ||
|
||
struct AppConfig : public App::ConfigGroup { | ||
APPCFG_CLASS | ||
|
||
APPCFG_PARA(globalConfig, GlobalConfigPara); | ||
}; | ||
|
||
} // namespace ImageConfigNS |
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 |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#pragma once | ||
#include <photon/common/utility.h> | ||
#include <yaml-cpp/yaml.h> | ||
#include <iostream> | ||
#include <string> | ||
#include <type_traits> | ||
#include <vector> | ||
|
||
namespace App { | ||
|
||
struct ConfigGroup : public YAML::Node { | ||
ConfigGroup() = default; | ||
ConfigGroup(const YAML::Node &node) : YAML::Node(node){}; | ||
ConfigGroup(const std::string &filename) { | ||
parseYAML(std::move(filename)); | ||
} | ||
|
||
void parseYAML(const std::string &fn) { | ||
Clone(YAML::LoadFile(fn)); | ||
} | ||
|
||
static size_t charfilter(char *dst, const char *src, char extract, size_t maxlen = 256UL) { | ||
size_t i; | ||
for (i = 0; (*src) && i < maxlen; i++, src++) { | ||
while (*src == '-') { | ||
src++; | ||
} | ||
if (!(*src)) | ||
break; | ||
dst[i] = *(src); | ||
} | ||
dst[i] = 0; | ||
return i; | ||
} | ||
}; | ||
|
||
#define APPCFG_PARA(ParaName, ParaType, ...) \ | ||
inline ParaType ParaName() const { \ | ||
return operator[](#ParaName).as<ParaType>(__VA_ARGS__); \ | ||
} | ||
|
||
#define APPCFG_CLASS using ConfigGroup::ConfigGroup; | ||
|
||
// merge two yaml nodes | ||
// generate new node with full data | ||
static YAML::Node mergeConfig(const YAML::Node &lhs, const YAML::Node &rhs) { | ||
// if one of nodes is not type of map | ||
// just return rhs | ||
if (lhs.Type() != YAML::NodeType::Map || rhs.Type() != YAML::NodeType::Map) | ||
return YAML::Clone(rhs); | ||
// both are map, merge two maps | ||
YAML::Node ret = YAML::Clone(lhs); | ||
for (auto &node : rhs) { | ||
auto key = node.first.as<std::string>(); | ||
if (ret[key].IsDefined()) { | ||
// if key exists in lhs, merge recursivily | ||
ret[key] = mergeConfig(lhs[key], node.second); | ||
} else { | ||
// just add as new key | ||
ret[key] = Clone(node.second); | ||
} | ||
} | ||
return ret; | ||
} | ||
|
||
} // namespace App | ||
|
||
namespace YAML { | ||
|
||
template <typename T> | ||
struct convert { | ||
template <ENABLE_IF_BASE_OF(App::ConfigGroup, T)> | ||
static Node encode(const T &rhs) { | ||
return rhs; | ||
} | ||
|
||
template <ENABLE_IF_BASE_OF(App::ConfigGroup, T)> | ||
static bool decode(const Node &node, T &rhs) { | ||
rhs = T(node); | ||
return true; | ||
} | ||
}; | ||
|
||
} // namespace YAML |
Oops, something went wrong.