Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 2024.3.1: Datasource Config #72

Merged
merged 25 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
6a464cf
Parse config from new flexible YAML format.
josephbirkner Jul 9, 2024
4528da0
Small fixes to YAML processing.
josephbirkner Jul 9, 2024
aabe7c5
Ensure that Node 16 is used when building for manylinux.
josephbirkner Jul 9, 2024
f8a5cba
Fix ctest flag --no-tests=error.
josephbirkner Jul 10, 2024
bf7a893
Activate tests on macOS.
josephbirkner Jul 10, 2024
55867de
Add logic for watching the datasources in the config file.
josephbirkner Jul 10, 2024
e47aee2
Small bugfixes.
josephbirkner Jul 11, 2024
028ace9
Added config service test and essential bugfixes.
josephbirkner Jul 11, 2024
6af5489
Integrate CLI with DataSourceConfigService.
josephbirkner Jul 12, 2024
60474c2
Deprecate serve -e and -d options.
josephbirkner Jul 12, 2024
10ee3bb
Catch any datasource constructor exception.
josephbirkner Jul 12, 2024
f8863bc
Additional armor for the config file watch thread.
josephbirkner Jul 12, 2024
ea09ead
Replace semaphore with atomic bool for cross-platform compatibility.
josephbirkner Jul 12, 2024
8e2f35d
Fix sonar complaints.
josephbirkner Jul 12, 2024
94b0205
Change some message log levels to debug.
josephbirkner Jul 16, 2024
5fc8489
Recreate all datasources when the config is changed.
josephbirkner Jul 18, 2024
1b0f085
Update config docs.
josephbirkner Jul 18, 2024
3540f25
Incorporate PR feedbaack.
josephbirkner Jul 18, 2024
571bad8
Log config file load errors.
josephbirkner Jul 18, 2024
cc2d933
Add test for config loading.
josephbirkner Jul 18, 2024
628e78a
Use promise/future in test.
josephbirkner Jul 18, 2024
a496049
Fix config test.
josephbirkner Jul 18, 2024
e16fb29
Pass missing flag in mapget.run()
josephbirkner Jul 18, 2024
f2f723e
Fix string init list.
josephbirkner Jul 18, 2024
0dc2805
Eat this, MSVC!
josephbirkner Jul 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .github/workflows/cmake.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ jobs:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
runs-on: ubuntu-latest
container: ghcr.io/klebert-engineering/manylinux-cpp17-py${{ matrix.python-version }}:2023.1
container: ghcr.io/klebert-engineering/manylinux-cpp17-py${{ matrix.python-version }}-x86_64:2024.1
env:
ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true
SCCACHE_GHA_ENABLED: "true"
steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -48,7 +49,7 @@ jobs:
timeout-minutes: 30
run: |
. ./venv/bin/activate
ctest --preset conan-release -C Release --verbose --no-test=fail
ctest --preset conan-release -C Release --verbose --no-tests=error
- name: Deploy
uses: actions/upload-artifact@v2
with:
Expand Down Expand Up @@ -89,6 +90,7 @@ jobs:
-DPython3_FIND_FRAMEWORK=LAST \
-DCMAKE_C_COMPILER_LAUNCHER=sccache \
-DCMAKE_CXX_COMPILER_LAUNCHER=sccache \
-DMAPGET_ENABLE_TESTING=ON \
-GNinja
cmake --build --preset conan-release
cd build/Release
Expand All @@ -114,4 +116,4 @@ jobs:
- name: Test
timeout-minutes: 30
run: |
ctest --preset conan-release -C Release --verbose --no-test=fail
ctest --preset conan-release -C Release --verbose --no-tests=error
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
cmake --build --preset conan-debug
- name: Run Test
run: |
ctest --preset conan-debug -C Debug --verbose --no-test=fail
ctest --preset conan-debug -C Debug --verbose --no-tests=error
- name: Run Gcovr
run: |
mkdir coverage
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ cmake_policy(SET CMP0117 NEW)

project(mapget CXX)

set(MAPGET_VERSION 2024.3)
set(MAPGET_VERSION 2024.3.1)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand Down
34 changes: 31 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,40 @@ mapget serve --help

(or `python -m mapget --help` for the Python package).

The `mapget` executable can parse a config file with arguments supported by the command line interface. The path to the config file can be provided to `mapget` via command line by specifying the `--config` parameter.
The `mapget` executable can parse a `YAML`-based config file. The path to the config file can be provided to `mapget` via command line by specifying the `--config` parameter.
The config file may have two top-level keys which are used by mapget: The `sources` key and the `mapget` key.

### The `mapget` YAML key

Under the `mapget` YAML key, any config options which can also be set via the command line may be set.
Note, that changes in this section are not applied while mapget is running, you will need to restart it.
Sample configuration files can be found under `examples/config`:

- [sample-first-datasource.toml](examples/config/sample-first-datasource.toml) and [sample-second-datasource.toml](examples/config/sample-second-datasource.toml) will configure mapget to run a simple datasource with sample data. Note: the two formats in config files for subcommand parameters can be used interchangeably.
- [sample-service.toml](examples/config/sample-service.toml) to execute the `mapget serve` command. The instance will fetch and serve data from sources started with `sample-*-datasource.toml` configs above.
- [sample-first-datasource.yaml](examples/config/sample-first-datasource.yaml) and [sample-second-datasource.yaml](examples/config/sample-second-datasource.yaml) will configure mapget to run a simple datasource with sample data. Note: the two formats in config files for subcommand parameters can be used interchangeably.
- [sample-service.yaml](examples/config/sample-service.yaml) to execute the `mapget serve` command. The instance will fetch and serve data from sources started with `sample-*-datasource.toml` configs above.

### The `sources` YAML key

Under the `sources` YAML key, you can configure datasources which are going to be served.
Note, that changes from the sources section are going to be applied immediately once the config
file is saved. This means, you can add and/or remove sources while mapget is running.
This section has the following format: The `sources` key must have a list. Each entry in the list
represents a datasource. The entry must have a `type` key, which denotes the specific datasource
constructor to call. You may register additional datasource types using the
`DatasourceConfigService` from `mapget/service/config.h`. By default, the following datasource types are supported:

| Data Source Type | Required Configurations | Optional Configurations |
|-------------------------|-------------------------|-----------------------------|
| `DataSourceHost` | `url` | N/A |
| `DataSourceProcess` | `cmd` | N/A |

For example, the following would be a valid configuration:

```yaml
sources:
- type: DataSourceProcess
cmd: cpp-sample-http-datasource
```

### Cache

Expand Down
2 changes: 1 addition & 1 deletion deps.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ if (MAPGET_WITH_WHEEL)
FetchContent_MakeAvailable(python-cmake-wheel)
endif()

set(BUILD_TESTING NO CACHE BOOL "")
set(BUILD_TESTING OFF CACHE BOOL "" FORCE)
FetchContent_Declare(tiny-process-library
GIT_REPOSITORY "https://gitlab.com/eidheim/tiny-process-library"
GIT_TAG v2.0.4
Expand Down
13 changes: 0 additions & 13 deletions examples/config/sample-first-datasource.toml

This file was deleted.

13 changes: 13 additions & 0 deletions examples/config/sample-first-datasource.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# mapget: A client/server application for map data retrieval.
mapget:
# From: trace, debug, info, warn, error, critical. Overrides MAPGET_LOG_LEVEL.
log-level: trace
fetch:
# Server to connect to in format <host:port>.
server: 127.0.0.1:61852
# Map to retrieve.
map: Tropico
# Layer of the map to retrieve.
layer: WayLayer
# Tile of the map to retrieve. Can be specified multiple times.
tile: 12345
14 changes: 0 additions & 14 deletions examples/config/sample-second-datasource.toml

This file was deleted.

13 changes: 13 additions & 0 deletions examples/config/sample-second-datasource.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# mapget: A client/server application for map data retrieval.
mapget:
# From: trace, debug, info, warn, error, critical. Overrides MAPGET_LOG_LEVEL.
log-level: trace
fetch:
# Server to connect to in format <host:port>.
server: 127.0.0.1:61852
# Map to retrieve.
map: TestMap
# Layer of the map to retrieve.
layer: WayLayer
# Tile of the map to retrieve. Can be specified multiple times.
tile: 12345
19 changes: 0 additions & 19 deletions examples/config/sample-service.toml

This file was deleted.

15 changes: 15 additions & 0 deletions examples/config/sample-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# mapget: A client/server application for map data retrieval.
mapget:
# From: trace, debug, info, warn, error, critical. Overrides MAPGET_LOG_LEVEL.
log-level: trace
serve:
# Port to start the server on. Default is 0.
port: 61852
# Datasources for the server in format <host:port>. Can be specified multiple times.
datasource-host: ["127.0.0.1:61853", "127.0.0.1:61854"]
# Using a persistent cache.
cache-type: rocksdb
# Datasource executable paths, including arguments, for the server. Can be specified multiple times.
# datasource-exe: ...
# Serve a static web application, in the format [<url-scope>:]<filesystem-path>.
# webapp: ...
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ namespace mapget
class RemoteDataSource : public DataSource
{
public:
/**
* Construct from joint host:port string.
*/
static std::shared_ptr<RemoteDataSource> fromHostPort(std::string const& hostPort);

/**
* Construct a DataSource with the host and port of
* a running DataSourceServer. Throws if the connection
Expand Down
9 changes: 9 additions & 0 deletions libs/http-datasource/src/datasource-client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,15 @@ std::vector<LocateResponse> RemoteDataSource::locate(const LocateRequest& req)
return responseVector;
}

std::shared_ptr<RemoteDataSource> RemoteDataSource::fromHostPort(const std::string& hostPort)
{
auto delimiterPos = hostPort.find(':');
std::string dsHost = hostPort.substr(0, delimiterPos);
int dsPort = std::stoi(hostPort.substr(delimiterPos + 1, hostPort.size()));
log().info("Connecting to datasource at {}:{}.", dsHost, dsPort);
return std::make_shared<RemoteDataSource>(dsHost, dsPort);
}

RemoteDataSourceProcess::RemoteDataSourceProcess(std::string const& commandLine)
{
auto stderrCallback = [this](const char* bytes, size_t n)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace mapget {
class HttpService : public HttpServer, public Service
{
public:
explicit HttpService(Cache::Ptr cache = std::make_shared<MemCache>());
explicit HttpService(Cache::Ptr cache = std::make_shared<MemCache>(), bool watchConfig = false);
~HttpService() override;

protected:
Expand Down
Loading
Loading