Skip to content

Commit 028b8eb

Browse files
committed
Move minimal service into ESG source.
1 parent daa1327 commit 028b8eb

21 files changed

+167
-146
lines changed

Readme.md

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Energy Management Systems (EMSs), in a sense of software computing optimized ope
88

99
For further information about the framework please consult the [corresponding paper available here](https://arxiv.org/abs/2402.15230). The latter provides further details about motivation and necessity of web-services for EMS applications, an extensive discussion of the technical design underlying the Energy Service Generics framework as well documentation of other relevant aspects.
1010

11-
## Installation
11+
## Usage
1212

1313
After checking out or downloading the source code install the package with:
1414

@@ -53,26 +53,22 @@ Please consider citing us if this software and/or the accompanying [paper](https
5353

5454
## Development Instructions
5555

56-
Recommend way of working on the code is to automatically run the tests in the container. The provided `docker-compose.yml` file is configured accordingly. In order to start the interactive sessions just execute:
56+
The recommend way of working on the code is to run it in a docker container.
5757

58-
```bash
59-
docker compose up -d --build && docker compose logs -f --no-log-prefix
60-
```
61-
62-
This will execute pytest every time a python file has changed. Furthermore it will spin up a minimal instance viable service at http://localhost:8800/. You can use the latter to interactively evaluate your code changes, e.g. if working on settings that influence the interactive documentation (SwaggerUI).
63-
64-
One you are finished get rid of the containers with:
58+
This repo employs a [test-driven development](https://en.wikipedia.org/wiki/Test-driven_development) schema in combination with a script that automatically runs the tests on file changes. In order to start the container execute:
6559

6660
```bash
67-
docker compose down
61+
docker compose -f docker-compose-autotest.yml up --no-log-prefix
6862
```
6963

70-
A shortcut (without building) for executing just the tests is:
64+
Furthermore, a functional service is included for interactive testing. You can use the latter to evaluate your code changes, e.g. if working on settings that influence the interactive documentation (SwaggerUI). The following code will start the service:
7165

7266
```bash
73-
docker compose up --no-log-prefix energy-service-generics-devl-autotest
67+
docker compose -f docker-compose-interactive-test.yml up
7468
```
7569

70+
You can access the interactive API documentation on http://localhost:8800/.
71+
7672
## Contact
7773

7874
Please open a GitHub issue for any inquiry that relates to the source code. Feel free to contact [David Wölfle](https://www.fzi.de/team/david-woelfle/) directly for all other inquiries.

minimal_service/pytest.ini renamed to docker-compose-autotest.yml

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Copyright 2024 FZI Research Center for Information Technology
22
#
3-
# Licensed under the Apache License, Version 2.0 (the "License")#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
55
# You may obtain a copy of the License at
66
#
@@ -15,8 +15,19 @@
1515
# SPDX-FileCopyrightText: 2024 FZI Research Center for Information Technology
1616
# SPDX-License-Identifier: Apache-2.0
1717

18-
[pytest]
19-
20-
filterwarnings =
21-
# This warning is emitted by esg.test and is pointless but cannot be disabled there.
22-
ignore:.+esg\.test.*:pytest.PytestAssertRewriteWarning
18+
services:
19+
energy-service-generics-devl-autotest:
20+
container_name: energy-service-generics-devl-autotest
21+
build:
22+
context: ./source
23+
init: true # Faster shutdown.
24+
entrypoint: [ "auto-pytest" ]
25+
command: [ "energy_service_generics/tests/" ]
26+
tty: true # Colorize output.
27+
restart: unless-stopped
28+
volumes:
29+
- ./source:/source/energy_service_generics/
30+
- ./source/esg:/usr/local/lib/python3.11/site-packages/esg
31+
user: "${USER_ID:-1000}:${GROUP_ID:-1000}"
32+
environment:
33+
- VERSION=latest-devl

docker-compose-interactive-test.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Copyright 2024 FZI Research Center for Information Technology
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# SPDX-FileCopyrightText: 2024 FZI Research Center for Information Technology
16+
# SPDX-License-Identifier: Apache-2.0
17+
18+
volumes:
19+
energy-service-generics-devl-service-celery-broker:
20+
energy-service-generics-devl-service-celery-results:
21+
22+
23+
services:
24+
energy-service-generics-devl-service-api:
25+
container_name: energy-service-generics-devl-service-api
26+
build:
27+
context: ./source
28+
target: esg-service-pandas
29+
init: true # Faster shutdown.
30+
entrypoint: [ "python" ]
31+
command: [ "-m", "esg.service.devl_service.api" ]
32+
restart: unless-stopped
33+
ports:
34+
- 8800:8800
35+
volumes:
36+
- ./source/esg:/usr/local/lib/python3.11/site-packages/esg
37+
- energy-service-generics-devl-service-celery-broker:/celery/broker/
38+
- energy-service-generics-devl-service-celery-results:/celery/results/
39+
environment:
40+
- CELERY__NAME=devl_service
41+
- 'CELERY__BROKER_URL=filesystem://'
42+
- 'CELERY__FS_TRANSPORT_BASE_FOLDER=/celery/'
43+
- VERSION=latest-devl
44+
45+
energy-service-generics-devl-service-worker:
46+
container_name: energy-service-generics-devl-service-worker
47+
build:
48+
context: ./source
49+
target: esg-service-pandas
50+
init: true # Faster shutdown.
51+
entrypoint: [ "celery" ]
52+
command: [ "--app", "esg.service.devl_service.worker", "worker", "--loglevel=INFO" ]
53+
restart: unless-stopped
54+
volumes:
55+
- ./source/esg:/usr/local/lib/python3.11/site-packages/esg
56+
- energy-service-generics-devl-service-celery-broker:/celery/broker/
57+
- energy-service-generics-devl-service-celery-results:/celery/results/
58+
environment:
59+
- CELERY__NAME=devl_service
60+
- 'CELERY__BROKER_URL=filesystem://'
61+
- 'CELERY__FS_TRANSPORT_BASE_FOLDER=/celery/'

docker-compose.yml

Lines changed: 0 additions & 83 deletions
This file was deleted.

minimal_service/.gitignore

Lines changed: 0 additions & 5 deletions
This file was deleted.

minimal_service/celery_broker/Readme.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

minimal_service/celery_results/Readme.md

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
# Minimal Viable Service
1+
# Development Service
22
Here some files that allow the construction of a minimal viable service. It is only intended for development of the package and allows to verify interactively how changes in the source code affect a service, which is particularly important for code segments that are hard to test, like e.g. related to the interactive documentation.
3+
4+
Furthermore, the development service serves as a test case for the generic service tests defined in [esg/test/generic_tests.py](../../test/generic_tests.py).
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"""
2+
Copyright 2024 FZI Research Center for Information Technology
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
16+
SPDX-FileCopyrightText: 2024 FZI Research Center for Information Technology
17+
SPDX-License-Identifier: Apache-2.0
18+
"""

minimal_service/api.py renamed to source/esg/service/devl_service/api.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,23 @@
1515
1616
SPDX-FileCopyrightText: 2024 FZI Research Center for Information Technology
1717
SPDX-License-Identifier: Apache-2.0
18-
"""
1918
20-
from packaging.version import Version
19+
NOTE: Need to change something here? Check if the examples services need to
20+
be adjusted too!
21+
"""
2122

2223
from esg.service.api import API
2324

24-
from data_model import RequestArguments, RequestOutput
25-
from data_model import FittedParameters, Observations
26-
from data_model import FitParameterArguments
27-
from worker import request_task, fit_parameters_task
25+
from .data_model import RequestArguments, RequestOutput
26+
from .data_model import FittedParameters, Observations
27+
from .data_model import FitParameterArguments
28+
from .worker import request_task, fit_parameters_task
2829

2930
api = API(
3031
RequestArguments=RequestArguments,
3132
RequestOutput=RequestOutput,
3233
request_task=request_task,
3334
title="Minimal Viable Service",
34-
version=Version("0.0.1"),
3535
FitParameterArguments=FitParameterArguments,
3636
FittedParameters=FittedParameters,
3737
Observations=Observations,

minimal_service/data_model.py renamed to source/esg/service/devl_service/data_model.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
1616
SPDX-FileCopyrightText: 2024 FZI Research Center for Information Technology
1717
SPDX-License-Identifier: Apache-2.0
18+
19+
NOTE: Need to change something here? Check if the examples services need to
20+
be adjusted too!
1821
"""
1922

2023
from typing import List

minimal_service/fooc.py renamed to source/esg/service/devl_service/fooc.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
1818
SPDX-FileCopyrightText: 2024 FZI Research Center for Information Technology
1919
SPDX-License-Identifier: Apache-2.0
20+
21+
NOTE: Need to change something here? Check if the examples services need to
22+
be adjusted too!
2023
"""
2124

2225
import numpy as np

minimal_service/worker.py renamed to source/esg/service/devl_service/worker.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,19 @@
1717
1818
SPDX-FileCopyrightText: 2024 FZI Research Center for Information Technology
1919
SPDX-License-Identifier: Apache-2.0
20+
21+
NOTE: Need to change something here? Check if the examples services need to
22+
be adjusted too!
2023
"""
2124

2225
from esg.service.worker import celery_app_from_environ
2326
from esg.service.worker import invoke_fit_parameters
2427
from esg.service.worker import invoke_handle_request
2528

26-
from data_model import RequestArguments, RequestOutput
27-
from data_model import FittedParameters, Observations
28-
from data_model import FitParameterArguments
29-
from fooc import fit_parameters, handle_request
29+
from .data_model import RequestArguments, RequestOutput
30+
from .data_model import FittedParameters, Observations
31+
from .data_model import FitParameterArguments
32+
from .fooc import fit_parameters, handle_request
3033

3134
app = celery_app_from_environ()
3235

source/esg/test/generic_tests.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ class GenericMessageSerializationTest:
3434
A generic set of tests to verify that the data can be serialized between
3535
the expected representations.
3636
37+
NOTE: This class is used in `tests/models/*.py`.
38+
Check if the tests there work as expected if working on this code.
39+
3740
Attributes:
3841
-----------
3942
ModelClass : pydantic model class
@@ -136,6 +139,9 @@ class GenericMessageSerializationTestBEMcom(GenericMessageSerializationTest):
136139
Extends `GenericMessageSerializationTest` with tests about serialization
137140
from and to BEMCom message format.
138141
142+
NOTE: This class is used in `tests/models/*.py`.
143+
Check if the tests there work as expected if working on this code.
144+
139145
Attributes:
140146
-----------
141147
ModelClass : pydantic model class
@@ -220,6 +226,9 @@ class GenericWorkerTaskTest(TestClassWithFixtures):
220226
"""
221227
Tests for checking that the worker tasks are correctly implemented.
222228
229+
NOTE: This class is used in `tests/service/devl_service/test_worker.py`.
230+
Check if the tests there work as expected if working on this code.
231+
223232
Attributes:
224233
-----------
225234
fixture_names : list of str
@@ -292,6 +301,9 @@ class GenericFOOCTest(TestClassWithFixtures):
292301
want to add more sophisticated tests for your forecasting or
293302
optimization code.
294303
304+
NOTE: This class is used in `tests/service/devl_service/test_fooc.py`.
305+
Check if the tests there work as expected if working on this code.
306+
295307
Attributes:
296308
-----------
297309
fixture_names : list of str
@@ -362,6 +374,8 @@ class GenericAPITest:
362374
This basically just verifies that the models are wired up correctly as
363375
validating the tasks too would require a full integration with the worker.
364376
377+
NOTE: This class is used in `tests/service/devl_service/test_api.py`.
378+
Check if the tests there work as expected if working on this code.
365379
366380
Attributes:
367381
-----------

0 commit comments

Comments
 (0)