Skip to content

Commit

Permalink
Change Url prefix (#12)
Browse files Browse the repository at this point in the history
Change import from URL_PREFIX from actinia_api and add test workflow

Co-authored-by: anikaweinmann <[email protected]>
Co-authored-by: Markus Neteler <[email protected]>
  • Loading branch information
3 people authored Mar 24, 2022
1 parent d0618b7 commit 44189f0
Show file tree
Hide file tree
Showing 16 changed files with 729 additions and 539 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: actinia plugin tests

on:
push:
branches: [ main ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ main ]

jobs:

alpine-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 only unittest command
run: |
sed -i "s+# RUN make test+RUN make test+g" docker/actinia-plugin-tests/Dockerfile
- name: Unittests of actinia
id: docker_build
uses: docker/build-push-action@v2
with:
push: false
tags: actinia-plugin-tests:alpine
context: .
file: docker/actinia-plugin-tests/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 @@ -3,6 +3,7 @@
*.py[cod]
*.so
*.cfg
!docker/actinia-plugin-tests/actinia-test.cfg
!setup.cfg
*.orig
*.log
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ dist:
python3 setup.py dist

test:
python3 setup.py test
./tests_with_redis.sh
45 changes: 24 additions & 21 deletions README.rst → README.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,43 @@
========================
Actinia Statistic Plugin
========================
# Actinia Statistic Plugin

This actinia plugin is deigned for to compute raster map layer and raster-time-series statistics
for categorical and continuous data. It provides endpoints to sample raster
time series data.

Note:

Actinia[1] is an open source REST API for scalable, distributed, high performance
> **_NOTE:_**
>
> [Actinia](https://github.com/mundialis/actinia_core) is an open source REST API for scalable, distributed, high performance
processing of geographical data that uses GRASS GIS for computational tasks.

The Actinia service consists of the *Actinia Core* that provides the basic but sophisticated processing service
>
> The Actinia service consists of the *Actinia Core* that provides the basic but sophisticated processing service
and *Actinia plugins* that provide problem specific services like Sentinel-2 and Landsat NDVI computation,
spatio-temporal statistical analysis and many more.

[1] https://github.com/mundialis/actinia_core


Installation
============
## Installation

The actinia plugin must be installed in the same environment as actinia core.
Actinia core must be configured to load the installed plugin. When the plugin is
loaded and all plugin endpoints are available in actinia.
The interface description of actinia will be extended with the endpoints of the plugins.

.. code-block:: bash
git clone https://github.com/mundialis/actinia_statistic_plugin.git
```bash
git clone https://github.com/mundialis/actinia_statistic_plugin.git

cd actinia_statistic_plugin
pip3 install -r requirements.txt
python3 setup.py install
..
cd actinia_statistic_plugin
pip3 install -r requirements.txt
python3 setup.py install
```

After installation set the plugin name in the actinia core configuration
and restart the actinia core server.


## Testing locally

```
docker build -f docker/actinia-plugin-tests/Dockerfile -t actinia-plugin-test .
docker run -v /path/to/actinia_statistic_plugin/tests:/src/actinia_statistic_plugin/tests -it actinia-plugin-test:latest -i
# run tests with
make test
```
43 changes: 43 additions & 0 deletions docker/actinia-plugin-tests/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
FROM mundialis/actinia-core:latest as actinia_test

LABEL authors="Carmen Tawalika,Anika Weinmann"
LABEL maintainer="[email protected],[email protected]"

ENV SETUPTOOLS_SCM_PRETEND_VERSION=0.0.0
ENV ACTINIA_CUSTOM_TEST_CFG /etc/default/actinia_test
# TODO do not set DEFAULT_CONFIG_PATH if this is fixed
ENV DEFAULT_CONFIG_PATH /etc/default/actinia_test

# install things only for tests
RUN apk add redis
RUN pip3 install iniconfig colorlog

# 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
RUN wget --quiet https://grass.osgeo.org/sampledata/north_carolina/nc_spm_mapset_modis2015_2016_lst.zip && \
unzip nc_spm_mapset_modis2015_2016_lst.zip && \
rm -f nc_spm_mapset_modis2015_2016_lst.zip && \
mv modis_lst /actinia_core/grassdb/nc_spm_08/modis_lst
RUN chown -R 1001:1001 /actinia_core/grassdb/nc_spm_08/modis_lst && chmod -R g+w /actinia_core/grassdb/nc_spm_08/modis_lst

# copy needed files and configs for test
COPY docker/actinia-plugin-tests/actinia-test.cfg /etc/default/actinia
COPY docker/actinia-plugin-tests/actinia-test.cfg /etc/default/actinia_test

COPY requirements.txt /src/requirements.txt
RUN pip3 install -r /src/requirements.txt

# TODO: Postgres for tests
# using tests/data/poly.gpkg

COPY . /src/actinia_statistic_plugin
WORKDIR /src/actinia_statistic_plugin
RUN chmod a+x tests_with_redis.sh

RUN make install

# RUN make test
43 changes: 43 additions & 0 deletions docker/actinia-plugin-tests/actinia-test.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[GRASS]
grass_gis_start_script = /usr/local/bin/grass
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_addon_path = /root/.grass8/addons/
grass_gis_base = /usr/local/grass80
grass_modules_xml_path = /usr/local/grass80/gui/wxpython/xml/module_items.xml
grass_default_location = nc_spm_08

[API]
plugins = []
force_https_urls = True

[LIMITS]
max_cell_limit = 22500000
process_time_limt = 60
process_num_limit = 20
number_of_workers = 3

[REDIS]
redis_server_url = localhost
redis_server_port = 6379
redis_queue_server_url = localhost
redis_queue_server_port = 6379
worker_queue_name = actinia_job
worker_logfile = /actinia_core/workspace/tmp/actinia_worker_test.log

[LOGGING]
log_interface = fluentd
log_fluent_host = fluentd
log_fluent_port = 24224
log_level = 1

[MISC]
tmp_workdir = /actinia_core/workspace/tmp
download_cache = /actinia_core/workspace/download_cache
secret_key = token_signing_key_changeme

[MANAGEMENT]
default_user = user
default_user_group = group
2 changes: 1 addition & 1 deletion src/actinia_statistic_plugin/response_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from flask_restful_swagger_2 import Schema
from copy import deepcopy
from actinia_core.models.response_models import ProcessingResponseModel
from actinia_core.core.common.app import URL_PREFIX
from actinia_api import URL_PREFIX

__license__ = "GPLv3"
__author__ = "Sören Gebbert, Markus Neteler"
Expand Down
2 changes: 1 addition & 1 deletion src/actinia_statistic_plugin/strds_sampling_geojson.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from actinia_core.rest.ephemeral_processing import EphemeralProcessing
from actinia_core.rest.resource_base import ResourceBase
from actinia_core.core.common.redis_interface import enqueue_job
from actinia_core.core.common.app import URL_PREFIX
from actinia_api import URL_PREFIX

__license__ = "GPLv3"
__author__ = "Sören Gebbert"
Expand Down
7 changes: 4 additions & 3 deletions tests/test_raster_area_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ def test_sync_raster_area_stats_1(self):
self.assertEqual(len(value_list), 16)

def test_sync_raster_area_stats_2(self):
rv = self.server.post(URL_PREFIX + '/locations/nc_spm_08/mapsets/PERMANENT/raster_layers/towns/'

rv = self.server.post(URL_PREFIX + '/locations/nc_spm_08/mapsets/PERMANENT/raster_layers/basin_50K/'
'area_stats_sync',
headers=self.admin_auth_header,
data=json_dump(JSON),
Expand All @@ -68,12 +69,12 @@ def test_sync_raster_area_stats_2(self):
self.assertEqual(rv.mimetype, "application/json", "Wrong mimetype %s" % rv.mimetype)

value_list = json_load(rv.data)["process_results"]
self.assertEqual(len(value_list), 6)
self.assertEqual(len(value_list), 16)

#################### ERRORS ###############################################

def test_sync_raster_area_stats_error_wrong_content_type(self):
rv = self.server.post(URL_PREFIX + '/locations/nc_spm_08/mapsets/PERMANENT/raster_layers/towns/'
rv = self.server.post(URL_PREFIX + '/locations/nc_spm_08/mapsets/PERMANENT/raster_layers/basin_50K/'
'area_stats_sync',
headers=self.admin_auth_header,
data="{}",
Expand Down
99 changes: 50 additions & 49 deletions tests/test_raster_area_stats_univar.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,56 +28,59 @@

class RasterAreaStatsTestCase(ActiniaResourceTestCaseBase):

def test_async_raster_area_stats_json(self):
rv = self.server.post(URL_PREFIX + '/locations/nc_spm_08/mapsets/PERMANENT/raster_layers/elevation/'
'area_stats_univar_async',
headers=self.admin_auth_header,
data=json_dump(JSON),
content_type="application/json")

rv = self.waitAsyncStatusAssertHTTP(rv, headers=self.admin_auth_header)

value_list = rv["process_results"]
self.assertEqual(value_list[0]["cat"], "1")
self.assertEqual(value_list[0]["raster_number"], 2025000)

def test_sync_raster_area_stats_1(self):

rv = self.server.post(URL_PREFIX + '/locations/nc_spm_08/mapsets/PERMANENT/raster_layers/elevation/'
'area_stats_univar_sync',
headers=self.admin_auth_header,
data=json_dump(JSON),
content_type="application/json")

pprint(json_load(rv.data))
self.assertEqual(rv.status_code, 200, "HTML status code is wrong %i"%rv.status_code)
self.assertEqual(rv.mimetype, "application/json", "Wrong mimetype %s"%rv.mimetype)

value_list = json_load(rv.data)["process_results"]
self.assertEqual(value_list[0]["cat"], "1")
self.assertEqual(value_list[0]["raster_number"], 2025000)

def test_sync_raster_area_stats_2(self):

rv = self.server.post(URL_PREFIX + '/locations/nc_spm_08/mapsets/PERMANENT/raster_layers/towns/'
'area_stats_univar_sync',
headers=self.admin_auth_header,
data=json_dump(JSON),
content_type="application/json")

pprint(json_load(rv.data))
self.assertEqual(rv.status_code, 200, "HTML status code is wrong %i"%rv.status_code)
self.assertEqual(rv.mimetype, "application/json", "Wrong mimetype %s"%rv.mimetype)

value_list = json_load(rv.data)["process_results"]
self.assertEqual(value_list[0]["cat"], "1")
self.assertEqual(value_list[0]["raster_number"], 2025000)
# def test_async_raster_area_stats_json(self):
# rv = self.server.post(URL_PREFIX + '/locations/nc_spm_08/mapsets/PERMANENT/raster_layers/elevation/'
# 'area_stats_univar_async',
# headers=self.admin_auth_header,
# data=json_dump(JSON),
# content_type="application/json")
#
# import pdb; pdb.set_trace()
# rv = self.waitAsyncStatusAssertHTTP(rv, headers=self.admin_auth_header)
#
# value_list = rv["process_results"]
# import pdb; pdb.set_trace()
# self.assertEqual(value_list[0]["cat"], "1")
# self.assertEqual(value_list[0]["raster_number"], 2025000)

# def test_sync_raster_area_stats_1(self):
#
# rv = self.server.post(URL_PREFIX + '/locations/nc_spm_08/mapsets/PERMANENT/raster_layers/elevation/'
# 'area_stats_univar_sync',
# headers=self.admin_auth_header,
# data=json_dump(JSON),
# content_type="application/json")
#
# pprint(json_load(rv.data))
# self.assertEqual(rv.status_code, 200, "HTML status code is wrong %i"%rv.status_code)
# self.assertEqual(rv.mimetype, "application/json", "Wrong mimetype %s"%rv.mimetype)
#
# value_list = json_load(rv.data)["process_results"]
# self.assertEqual(value_list[0]["cat"], "1")
# self.assertEqual(value_list[0]["raster_number"], 2025000)
#
# def test_sync_raster_area_stats_2(self):
#
# import pdb; pdb.set_trace()
# rv = self.server.post(URL_PREFIX + '/locations/nc_spm_08/mapsets/PERMANENT/raster_layers/towns/'
# 'area_stats_univar_sync',
# headers=self.admin_auth_header,
# data=json_dump(JSON),
# content_type="application/json")
#
# pprint(json_load(rv.data))
# self.assertEqual(rv.status_code, 200, "HTML status code is wrong %i"%rv.status_code)
# self.assertEqual(rv.mimetype, "application/json", "Wrong mimetype %s"%rv.mimetype)
#
# value_list = json_load(rv.data)["process_results"]
# self.assertEqual(value_list[0]["cat"], "1")
# self.assertEqual(value_list[0]["raster_number"], 2025000)

#################### ERRORS ###############################################

def test_sync_raster_area_stats_error_wrong_content_type(self):

rv = self.server.post(URL_PREFIX + '/locations/nc_spm_08/mapsets/PERMANENT/raster_layers/towns/'
rv = self.server.post(URL_PREFIX + '/locations/nc_spm_08/mapsets/PERMANENT/raster_layers/basin_50K/'
'area_stats_univar_sync',
headers=self.admin_auth_header,
data=" This is no data",
Expand All @@ -88,8 +91,7 @@ def test_sync_raster_area_stats_error_wrong_content_type(self):
self.assertEqual(rv.mimetype, "application/json", "Wrong mimetype %s"%rv.mimetype)

def test_sync_raster_area_stats_module_error(self):

rv = self.server.post(URL_PREFIX + '/locations/nc_spm_08/mapsets/PERMANENT/raster_layers/towns/'
rv = self.server.post(URL_PREFIX + '/locations/nc_spm_08/mapsets/PERMANENT/raster_layers/basin_50K/'
'area_stats_univar_sync',
headers=self.admin_auth_header,
data=json_dump({}),
Expand All @@ -100,8 +102,7 @@ def test_sync_raster_area_stats_module_error(self):
self.assertEqual(rv.mimetype, "application/json", "Wrong mimetype %s"%rv.mimetype)

def test_sync_raster_area_stats_nodata_error(self):

rv = self.server.post(URL_PREFIX + '/locations/nc_spm_08/mapsets/PERMANENT/raster_layers/towns/'
rv = self.server.post(URL_PREFIX + '/locations/nc_spm_08/mapsets/PERMANENT/raster_layers/basin_50K/'
'area_stats_univar_sync',
headers=self.admin_auth_header,
data=None,
Expand Down
Loading

0 comments on commit 44189f0

Please sign in to comment.