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

Start with parallel processing #1

Merged
merged 47 commits into from
Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
28a1320
start with postgis DB
May 16, 2022
03b7800
zwischenstand
May 18, 2022
af276c1
zwischenstand 2: resourceID is set
May 19, 2022
6565762
zwischenstand
May 20, 2022
d4ab5f6
parallele processierung läuft mit fehler in processierung (map wird n…
May 20, 2022
0d3d658
ephemeral parallel processing is running but to many resources and la…
May 20, 2022
0b8f29d
processing working sync (non parallelt)
May 23, 2022
c806144
working ephemeral processing
May 24, 2022
794fa3e
start with tests
May 25, 2022
1afab11
Apply suggestions from code review
anikaweinmann Jun 1, 2022
d673652
tests are running
Jun 2, 2022
5bb07c2
unittests
Jun 2, 2022
9364924
small changes
Jun 2, 2022
91d3c00
remove persistent processing
Jun 2, 2022
34a1503
update readme
Jun 2, 2022
87d6e62
try to fix test
Jun 2, 2022
1b5ba6b
more logs by different status
Jun 2, 2022
c8c4ed9
try to get more infos of test failure
Jun 2, 2022
e80110e
tests
Jun 2, 2022
f41a9ea
tests
Jun 2, 2022
b77711e
test
Jun 2, 2022
b737473
docker logs in tests
Jun 2, 2022
da8f3b9
docker logs in tests
Jun 2, 2022
c42af09
docker logs in tests
Jun 2, 2022
ed881b4
test running locally
Jun 2, 2022
10f3ffe
linting
Jun 2, 2022
0b09228
linting
Jun 2, 2022
bfd6141
remove volume
Jun 3, 2022
f3f60b3
CT review 1
Jun 8, 2022
3f7f2c7
CT review 2
Jun 8, 2022
93e817a
test workflow
Jun 8, 2022
80a3e35
first cleanup
Jun 29, 2022
114dee3
remove job_description
Jun 29, 2022
894458a
renaming processing_block to batch_processing_block
Jun 29, 2022
eaec58c
renaming to resource_id
Jun 29, 2022
1b5df75
remove message and terraformer_..
Jun 29, 2022
88fa151
rename idpk_jobs in id
Jun 30, 2022
c978d66
remove some job descriptions
Jun 30, 2022
8ad076f
rename actinia_core_response to resource_response
Jun 30, 2022
2b4efeb
remove process
Jun 30, 2022
8c7bf16
renaming jobtabelle.py
Jun 30, 2022
2c73918
flake8
Jun 30, 2022
de43c69
review
Jun 30, 2022
c5e5010
config test
Jul 1, 2022
57dbe35
changing endpoints
Jul 4, 2022
98dea57
remove wsgi file
Jul 21, 2022
1c2bee9
CT review
Jul 21, 2022
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
3 changes: 2 additions & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ exclude = .git,.pycache,build,.eggs

per-file-ignores =
./src/actinia_parallel_plugin/wsgi.py: F401
./tests/test_resource_base.py: F401
./tests/test_resource_base.py: F401
./src/actinia_parallel_plugin/core/persistent_processing.py: E501
47 changes: 24 additions & 23 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,30 @@ on:

jobs:

integration-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Start containers
run: docker-compose -f "docker/docker-compose-test.yml" up -d --build

- name: List running docker
run: docker ps

- name: Docker logs actinia
run: docker logs docker_actinia-test_1

- name: Docker logs postgis
run: docker logs docker_postgis-test_1

- name: Run integration test
run: docker exec -t docker_actinia-test_1 sh /usr/bin/run_unittests.sh
# run: docker exec -t docker_actinia-test_1 sh /usr/bin/run_integration_tests.sh

- name: Stop containers
run: docker-compose -f "docker/docker-compose-test.yml" down

unittests:
runs-on: ubuntu-latest
steps:
Expand All @@ -31,26 +55,3 @@ jobs:
file: docker/actinia-parallel-plugin-test/Dockerfile
no-cache: true
# pull: true

integration-tests:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
# with:
# path: "."
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Replace run integration test command
run: |
sed -i "s+# RUN make test+RUN make integrationtest+g" docker/actinia-parallel-plugin-test/Dockerfile
- name: Integration tests of actinia-parallel-plugin
id: docker_build
uses: docker/build-push-action@v2
with:
push: false
tags: actinia-parallel-plugin-test:alpine
context: .
file: docker/actinia-parallel-plugin-test/Dockerfile
no-cache: true
# pull: true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ __pycache__/*
.cache/*
.*.swp
*/.ipynb_checkpoints/*
.coverage.*

# Project files
.ropeproject
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ dist:
python3 setup.py dist

test:
./tests_with_redis.sh
python3 setup.py test

unittest:
python3 setup.py test --addopts "-m unittest"

devtest:
./tests_with_redis.sh dev
python3 setup.py test --addopts "-m 'dev'"

integrationtest:
./tests_with_redis.sh integrationtest
python3 setup.py test --addopts "-m 'integrationtest'"
85 changes: 70 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# actinia-parallel-plugin

This is an example plugin for [actinia-core](https://github.com/mundialis/actinia_core) which adds a "Hello World" endpoint to actinia-core.
This is the actinia-parallel-plugin for [actinia-core](https://github.com/mundialis/actinia_core) which adds parallel processing endpoints to actinia.

You can run actinia-parallel-plugin as an actinia-core plugin.

Expand All @@ -20,14 +20,6 @@ docker network prune
docker-compose -f docker/docker-compose.yml up -d
```

### Requesting helloworld endpoint
You can test the plugin and request the `/helloworld` endpoint, e.g. with:
```
curl -u actinia-gdi:actinia-gdi -X GET http://localhost:8088/api/v3/processing_parallel | jq

curl -u actinia-gdi:actinia-gdi -H 'accept: application/json' -H 'Content-Type: application/json' -X POST http://localhost:8088/api/v3/processing_parallel -d '{"name": "test"}' | jq
```

## DEV setup
For a DEV setup you can use the docker/docker-compose.yml:
```
Expand All @@ -38,6 +30,15 @@ docker-compose -f docker/docker-compose.yml run --rm --service-ports --entrypoin
(cd /src/actinia-parallel-plugin && python3 setup.py install)
# start actinia-core with your plugin
gunicorn -b 0.0.0.0:8088 -w 1 --access-logfile=- -k gthread actinia_core.main:flask_app

# or for debugging in one line with reset
reset && (cd /src/actinia-parallel-plugin && python3 setup.py install) && gunicorn -b 0.0.0.0:8088 -w 3 --access-logfile=- -k gthread actinia_core.main:flask_app
```

### PostGIS
Connect to PostGIS DB from actinia-core docker container:
```
psql -U actinia -h postgis -d gis
```

### Hints
Expand All @@ -60,10 +61,11 @@ rm -rf /usr/lib/python3.8/site-packages/actinia_parallel_plugin.wsgi-*.egg
You can run the tests in the actinia test docker:

```
docker build -f docker/actinia-parallel-plugin-test/Dockerfile -t actinia-parallel-plugin-test .
docker run -it actinia-parallel-plugin-test -i
docker-compose -f docker/docker-compose-test.yml build
docker-compose -f docker/docker-compose-test.yml up -d

cd /src/actinia-parallel-plugin/
# exec docker and run tests manually
docker exec -it docker_actinia-test_1 sh

# run all tests
make test
Expand All @@ -73,8 +75,61 @@ make unittest
# run only integrationtests
make integrationtest

# run only tests which are marked for development with the decorator '@pytest.mark.dev'
make devtest
# or run tests outside of docker container
docker exec -it docker_actinia-test_1 sh /usr/bin/run_integration_tests.sh
docker exec -it docker_actinia-test_1 sh /usr/bin/run_unittests.sh

docker-compose -f docker/docker-compose-test.yml down
```

You can also run the tests in the GHA workflows locally via [act](https://github.com/nektos/act).
To run docker-compose inside a workflow [act_base](https://github.com/lucasctrl/act_base) can be used.
With these you can run the following to run the tests:
```
# list all workflows
act -l

# run workflow
act -j integration-tests -P ubuntu-latest=lucasalt/act_base:latest
act -j unittests -P ubuntu-latest=lucasalt/act_base:latest
```


## Examples

### Requesting batch job and job endpoints
```
# request batch job
curl -u actinia-gdi:actinia-gdi -X GET http://localhost:8088/api/v3/processing_parallel/batchjobs/1 | jq
# request job
curl -u actinia-gdi:actinia-gdi -X GET http://localhost:8088/api/v3/processing_parallel/jobs/1 | jq
```

### Start parallel batch job
#### Ephemeral processing
You can start a parallel **ephemeral** batch job via:
```
# parallel ephemeral processing
curl -u actinia-gdi:actinia-gdi -X POST -H 'Content-Type: application/json' -d @test_postbodies/parallel_ephemeral_processing.json http://localhost:8088/api/v3/locations/nc_spm_08_grass7_root/processing_parallel | jq
```
Attention:
* The individual process chains must be "independent" of each other, since
createBatch is designed as an ephemeral process.

TODOs:
* exporter in PC
* using stdout/export in PC of next block

#### Persistent processing
You can also start a **persistent** batch job via:
```
# parallel persistent processing (TODO!!!)
curl -u actinia-gdi:actinia-gdi -X POST -H 'Content-Type: application/json' -d @test_postbodies/parallel_processing.json http://localhost:8088/api/v3/locations/nc_spm_08_grass7_root/mapsets/test_mapset/processing_parallel | jq
```
Hereby, the parallel started process chains will be computed in mapsets with
the suffix `_parallel_{NUMBER}` (see the example process chains in
`test_postbodies/parallel_persistent_processing.json`).
So if you want to use a mapset in a later step, you have to pay attention to
the naming of the mapset.

##
TODOs: alles
anikaweinmann marked this conversation as resolved.
Show resolved Hide resolved
24 changes: 18 additions & 6 deletions docker/actinia-parallel-plugin-test/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,25 @@ ENV ACTINIA_CUSTOM_TEST_CFG /etc/default/actinia-parallel-plugin-test
ENV DEFAULT_CONFIG_PATH /etc/default/actinia-parallel-plugin-test

# install things only for tests
# RUN apk add postgresql
# RUN apk add docker openrc
RUN apk add redis
RUN pip3 install iniconfig colorlog pwgen
# RUN rc-update add docker boot
# RUN service docker start
# RUN docker pull kartoza/postgis
anikaweinmann marked this conversation as resolved.
Show resolved Hide resolved


# COPY docker/actinia-parallel-plugin-test/start.sh /src/start.sh

ENTRYPOINT ["/bin/sh"]
CMD ["/src/start.sh"]

# # add data for tests
# RUN wget --quiet https://grass.osgeo.org/sampledata/north_carolina/nc_spm_08_micro.zip && \
# unzip nc_spm_08_micro.zip && \
# rm -f nc_spm_08_micro.zip && \
# mv nc_spm_08_micro /actinia_core/grassdb/nc_spm_08
# add data for tests
RUN wget --quiet https://grass.osgeo.org/sampledata/north_carolina/nc_spm_08_micro.zip && \
unzip nc_spm_08_micro.zip && \
rm -f nc_spm_08_micro.zip && \
mv nc_spm_08_micro /actinia_core/grassdb/nc_spm_08
# RUN grass -e -c 'EPSG:4326' /actinia_core/grassdb/latlong_wgs84

# copy needed files and configs for test
Expand All @@ -31,7 +37,13 @@ COPY . /src/actinia-parallel-plugin/

WORKDIR /src/actinia-parallel-plugin/

RUN chmod a+x tests_with_redis.sh
RUN make install

ENV SETUPTOOLS_SCM_PRETEND_VERSION=0.0

COPY docker/actinia-parallel-plugin-test/run_integration_tests.sh /usr/bin/run_integration_tests.sh
RUN chmod a+x /usr/bin/run_integration_tests.sh
COPY docker/actinia-parallel-plugin-test/run_unittests.sh /usr/bin/run_unittests.sh
RUN chmod a+x /usr/bin/run_unittests.sh

# RUN make test
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ grass_database = /actinia_core/grassdb
grass_user_database = /actinia_core/userdata
grass_tmp_database = /actinia_core/workspace/temp_db
grass_resource_dir = /actinia_core/resources
grass_gis_base = /usr/local/grass80
grass_gis_base = /usr/local/grass
grass_gis_start_script = /usr/local/bin/grass
grass_addon_path = /root/.grass8/addons/

Expand All @@ -12,7 +12,8 @@ plugins = ["actinia_parallel_plugin"]
force_https_urls = True

[REDIS]
redis_server_url = localhost
redis_server_url = redis-test
redis_server_pw = pass
redis_server_port = 6379
worker_queue_name = actinia_job
worker_logfile = /actinia_core/workspace/tmp/actinia_worker_test.log
Expand All @@ -22,3 +23,12 @@ tmp_workdir = /actinia_core/workspace/tmp
download_cache = /actinia_core/workspace/download_cache
secret_key = token_signing_key_changeme
save_interim_results = False

[JOBTABLE]
host = postgis-test
port = 5432
database = gis
user = actinia
schema = actinia
table = tab_jobs
id_field = idpk_jobs
3 changes: 3 additions & 0 deletions docker/actinia-parallel-plugin-test/run_integration_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

python3 setup.py test --addopts "-m 'integrationtest'"
3 changes: 3 additions & 0 deletions docker/actinia-parallel-plugin-test/run_unittests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

python3 setup.py test --addopts "-m 'unittest'"
11 changes: 10 additions & 1 deletion docker/actinia.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ grass_database = /actinia_core/grassdb
grass_user_database = /actinia_core/userdata
grass_tmp_database = /actinia_core/workspace/temp_db
grass_resource_dir = /actinia_core/resources
grass_gis_base = /usr/local/grass80
grass_gis_base = /usr/local/grass
grass_gis_start_script = /usr/local/bin/grass
grass_addon_path = /root/.grass8/addons/

Expand All @@ -26,3 +26,12 @@ tmp_workdir = /actinia_core/workspace/tmp
download_cache = /actinia_core/workspace/download_cache
secret_key = token_signing_key_changeme
save_interim_results = True

[JOBTABLE]
host = postgis
port = 5432
database = gis
user = actinia
schema = actinia
table = tab_jobs
id_field = idpk_jobs
58 changes: 58 additions & 0 deletions docker/docker-compose-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
version: "3"
services:

actinia-test:
build:
context: ..
dockerfile: docker/actinia-parallel-plugin-test/Dockerfile
volumes:
- ..:/src/actinia-parallel-plugin/.
ports:
- "8088:8088"
environment:
- JOBTABLE_PW=actinia
depends_on:
- redis-test
- postgis-test
cap_add:
- SYS_PTRACE
networks:
- actinia-test

redis-test:
image: redis:5.0.4-alpine
volumes:
- ./redis_data:/data
environment:
- REDIS_PASS_FILE=/data/config/.redis
command: [
"sh", "-c",
'
docker-entrypoint.sh
"/data/config/redis.conf"
--requirepass "$$(cat $$REDIS_PASS_FILE)"
'
]
ports:
- "6379:6379"
networks:
- actinia-test

postgis-test:
image: postgis/postgis:14-3.2-alpine
# network_mode: host
environment:
POSTGRES_USER: actinia
POSTGRES_PASSWORD: actinia
volumes:
- ./postgresql_init_data:/docker-entrypoint-initdb.d
# - ./postgresql_data:/var/lib/postgresql/data:Z
networks:
- actinia-test


networks:
actinia-test:
ipam:
config:
- subnet: 172.18.0.0/26
Loading