Skip to content

Commit

Permalink
Move apidocs (#337)
Browse files Browse the repository at this point in the history
* reactivate redis queue

* rename variable

* make queue type configurable

* enhance dev setup for redis queue

* lint

* move user_auth

* move user auth

* move base_login

* move map_layer_base

* move renderer_base

* move resource_base

* fix relative imports

* lint

* first splitup: raster_colors

* splitup download_cache_management

* splitup ephemeral_custom_processing

* splitup ephemeral_processing_with_export

* splitup ephemeral_processing

* splitup renderer_base

* splitup persistent_processing

* splitup location_management

* splitup map_layer_management

* splitup mapset_management

* splitup persistent_mapset_merger

* splitup process_validation

* splitup raster_export

* splitup raster_layer

* splitup raster_legend

* lint

* splitup raster_renderer

* splitup resource_storage_management

* splitup strds_management

* splitup strds_raster_management

* splitup strds_renderer

* splitup vector_layer

* splitup vector_renderer

* lint

* move api docs to actinia-api repo

* move from actinia_api import URL_PREFIX to actinia-api repo

* renaming

* change actinia-api version in dockerfiles

* URL_PREFIX in test from testsuite

* do not change tests

* update README

* make inheritance more clear

* add readme

* fix import

Co-authored-by: anikaweinmann <aweinmann@mundialis.de>
  • Loading branch information
mmacata and anikaweinmann authored Apr 1, 2022
1 parent d9b9f11 commit 3292c19
Show file tree
Hide file tree
Showing 33 changed files with 126 additions and 2,840 deletions.
2 changes: 1 addition & 1 deletion docker/actinia-core-alpine/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ ENV GDAL_CACHEMAX=2000
ENV GRASS_COMPRESSOR=ZSTD
ENV GRASS_SKIP_MAPSET_OWNER_CHECK 1
ENV GISBASE ""
ENV ACTINIA_API_VERSION 3.0.1
ENV ACTINIA_API_VERSION 3.1.0

USER root

Expand Down
4 changes: 3 additions & 1 deletion docker/actinia-core-tests/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ FROM mundialis/actinia-core:2.0.0 as actinia_test
LABEL authors="Carmen Tawalika,Anika Weinmann"
LABEL maintainer="tawalika@mundialis.de,weinmann@mundialis.de"

ENV ACTINIA_API_VERSION 3.1.0

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
Expand All @@ -27,7 +29,7 @@ RUN wget --quiet https://grass.osgeo.org/sampledata/north_carolina/nc_spm_mapset
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

RUN pip3 install actinia-api@https://github.com/mundialis/actinia-api/releases/download/2.0.0/actinia_api-2.0.0-py3-none-any.whl
RUN pip3 install actinia-api@https://github.com/mundialis/actinia-api/releases/download/${ACTINIA_API_VERSION}/actinia_api-${ACTINIA_API_VERSION}-py3-none-any.whl

# copy needed files and configs for test
COPY docker/actinia-core-alpine/actinia.cfg /etc/default/actinia
Expand Down
5 changes: 3 additions & 2 deletions src/actinia_core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Some other modules outside of core folder are concerned as well.
| actinia_core.rest.persistent_processing | SCHEMA_DOC |
| actinia_core.rest.base.resource_base | ResourceBase |
| actinia_core.core.common.api_logger | log_api_call |
| actinia_core.core.common.app | auth, flask_api, flask_app, URL_PREFIX |
| actinia_core.core.common.app | auth, flask_api, flask_app |
| actinia_core.core.common.aws_sentinel_interface | AWSSentinel2AInterface |
| actinia_core.core.common.config | global_config, Configuration, DEFAULT_CONFIG_PATH |
| actinia_core.core.common.exceptions | AsyncProcessError |
Expand All @@ -47,6 +47,7 @@ Some other modules outside of core folder are concerned as well.
| actinia_core.core.common.user | ActiniaUser |
| actinia_core.core.redis_user | RedisUserInterface |

URL_PREFIX moved to actinia_api
------------

### Complete list of where modules are used and what exactly is imported
Expand All @@ -67,7 +68,7 @@ actinia_core.processing.common.ephemeral_processing_with_export import start_job
actinia_core.rest.ephemeral_processing_with_export import SCHEMA_DOC
actinia_core.processing.common.persistent_processing import start_job
actinia_core.rest.persistent_processing import SCHEMA_DOC
actinia_core.core.common.app import URL_PREFIX
actinia_api import URL_PREFIX
actinia_core.core.common.config import Configuration
actinia_core.core.common.process_chain import GrassModule
/# from actinia_core.core.common.process_queue import create_process_queue
Expand Down
7 changes: 2 additions & 5 deletions src/actinia_core/core/common/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,13 @@
from flask import Flask
from flask_restful_swagger_2 import Api

from actinia_api import API_VERSION, URL_PREFIX

__license__ = "GPLv3"
__author__ = "Sören Gebbert, Julia Haas"
__copyright__ = "Copyright 2016-2021, Sören Gebbert and mundialis GmbH & Co. KG"
__maintainer__ = "mundialis"

API_VERSION = "v3"

# This is the URL prefix that must be used in the tests
URL_PREFIX = "/api/%s" % API_VERSION


flask_app = Flask(__name__)
# allows endpoints with and without trailing slashes
Expand Down
4 changes: 3 additions & 1 deletion src/actinia_core/health_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@
__maintainer__ = "Sören Gebbert"
__email__ = "soerengebbert@googlemail.com"

from actinia_core.core.common.app import flask_app, URL_PREFIX
from flask import make_response
from actinia_api import URL_PREFIX

from actinia_core.core.common.app import flask_app

# This is a simple endpoint to check the health of the Actinia Core server
# This is needed by Google load balancer
Expand Down
2 changes: 1 addition & 1 deletion src/actinia_core/models/process_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"""
from flask_restful_swagger_2 import Schema
from copy import deepcopy
from actinia_core.core.common.app import URL_PREFIX
from actinia_api import URL_PREFIX

__license__ = "GPLv3"
__author__ = "Sören Gebbert, Carmen Tawalika"
Expand Down
3 changes: 2 additions & 1 deletion src/actinia_core/models/response_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
from flask import jsonify
from flask_restful_swagger_2 import Schema
from copy import deepcopy
from actinia_core.core.common.app import URL_PREFIX
from actinia_api import URL_PREFIX

from actinia_core.core.common.process_chain import GrassModule

__license__ = "GPLv3"
Expand Down
35 changes: 4 additions & 31 deletions src/actinia_core/rest/api_log_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
from flask import jsonify, make_response
from flask_restful import Resource
from flask_restful_swagger_2 import swagger
from actinia_api.swagger2.actinia_core.schemas.api_log_management import ApiLogListModel
from actinia_api.swagger2.actinia_core.apidocs import api_log_management
from actinia_api.swagger2.actinia_core.schemas.api_log_management import \
ApiLogListModel

from actinia_core.core.common.app import auth
from actinia_core.core.common.api_logger import ApiLogger
Expand Down Expand Up @@ -61,36 +63,7 @@ def __init__(self):
self.user_id = g.user.get_id()
self.user_role = g.user.get_role()

@swagger.doc({
'tags': ['API Log'],
'description': 'Get a list of all API calls that have been called by the '
'provided user. Admin and superadmin roles can list API '
'calls from any user. A user role can only list API calls '
'from itself. '
'Minimum required user role: user.',
'parameters': [
{
'name': 'user_id',
'description': 'The unique user name/id',
'required': True,
'in': 'path',
'type': 'string'
}
],
'responses': {
'200': {
'description': 'Returned a list of all API calls that have been '
'called by the provided user.',
'schema': ApiLogListModel
},
'400': {
'description': 'The error message why API log gathering did not '
'succeeded',
'schema': SimpleResponseModel
}
}
})
@swagger.doc(api_log_management.get_doc)
def get(self, user_id):
"""Get a list of all API calls that have been called by the provided user."""

Expand Down
36 changes: 3 additions & 33 deletions src/actinia_core/rest/download_cache_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@
from flask import jsonify, make_response
from flask_restful_swagger_2 import swagger
import pickle
from actinia_api.swagger2.actinia_core.apidocs import download_cache_management
from actinia_core.rest.base.resource_base import ResourceBase
from actinia_core.core.common.redis_interface import enqueue_job
from actinia_core.models.response_models import \
StorageResponseModel, ProcessingResponseModel
from actinia_core.core.common.api_logger import log_api_call
from actinia_core.rest.base.user_auth import very_admin_role
from actinia_core.rest.base.user_auth import check_user_permissions
Expand All @@ -51,22 +50,7 @@ class SyncDownloadCacheResource(ResourceBase):
decorators = [log_api_call, check_user_permissions,
very_admin_role, auth.login_required]

@swagger.doc({
'tags': ['Cache Management'],
'description': 'Get the current size of the download cache. '
'Minimum required user role: admin.',
'responses': {
'200': {
'description': 'The current state of the download cache',
'schema': StorageResponseModel
},
'400': {
'description': 'The error message why cache information '
'gathering did not succeeded',
'schema': ProcessingResponseModel
}
}
})
@swagger.doc(download_cache_management.get_doc)
def get(self):
"""Get the current size of the download cache"""
rdc = self.preprocess(has_json=False, has_xml=False)
Expand All @@ -79,21 +63,7 @@ def get(self):

return make_response(jsonify(response_model), http_code)

@swagger.doc({
'tags': ['Cache Management'],
'description': 'Clean the download cache and remove all cached data. '
'Minimum required user role: admin.',
'responses': {
'200': {
'description': 'Processing status of cache deletion',
'schema': StorageResponseModel
},
'400': {
'description': 'The error message why cache cleaning did not succeeded',
'schema': ProcessingResponseModel
}
}
})
@swagger.doc(download_cache_management.delete_doc)
def delete(self):
"""Clean the download cache and remove all cached data"""
rdc = self.preprocess(has_json=False, has_xml=False)
Expand Down
79 changes: 5 additions & 74 deletions src/actinia_core/rest/ephemeral_processing_with_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,11 @@
import pickle
from flask import jsonify, make_response

from copy import deepcopy
from flask_restful_swagger_2 import swagger
from actinia_api.swagger2.actinia_core.apidocs import \
ephemeral_processing_with_export
from actinia_core.rest.base.resource_base import ResourceBase
from actinia_core.core.common.redis_interface import enqueue_job
from actinia_core.core.common.process_chain import ProcessChainModel
from actinia_core.models.response_models import \
ProcessingResponseModel, ProcessingErrorResponseModel
from actinia_core.processing.common.ephemeral_processing_with_export \
import start_job

Expand All @@ -45,73 +43,6 @@
__email__ = "info@mundialis.de"


DESCR = """Execute a user defined process chain in an ephemeral database
and provide the generated resources as downloadable files via URL's.
Minimum required user role: user.
The process chain is executed asynchronously. The provided status URL
in the response must be polled to gain information about the processing
progress and finishing status.
**Note**
Make sure that the process chain definition identifies all raster, vector or
space-time datasets correctly with name and mapset: name@mapset if you use
data from other mapsets in the specified location.
All required mapsets will be identified by analysing the input parameter
of all module descriptions in the provided process chain
and mounted read-only into the ephemeral database that is used for processing.
The persistent database will not be modified. The ephemeral database will be
removed after processing.
Use the URL's provided in the finished response to download the resource that
were specified in the process chain for export.
**Note**
The endpoint allows the creation of STAC ITEMS through the
ACTINIA STAC PLUGIN the STAC item is stored in a dedicated
CATALOG following the standard from STAC specification (https://stacspec.org/)
"""


SCHEMA_DOC = {
'tags': ['Processing'],
'description': DESCR,
'consumes': ['application/json'],
'parameters': [
{
'name': 'location_name',
'description': 'The location name that contains the data that should '
'be processed',
'required': True,
'in': 'path',
'type': 'string',
'default': 'nc_spm_08'
},
{
'name': 'process_chain',
'description': 'The process chain that should be executed',
'required': True,
'in': 'body',
'schema': ProcessChainModel
}
],
'responses': {
'200': {
'description': 'The result of the process chain execution',
'schema': ProcessingResponseModel
},
'400': {
'description': 'The error message and a detailed log why process '
'chain execution did not succeeded',
'schema': ProcessingErrorResponseModel
}
}
}


class AsyncEphemeralExportResource(ResourceBase):
"""
This class represents a resource that runs asynchronous processing tasks in
Expand All @@ -120,7 +51,7 @@ class AsyncEphemeralExportResource(ResourceBase):
def __init__(self, resource_id=None, iteration=None, post_url=None):
ResourceBase.__init__(self, resource_id, iteration, post_url)

@swagger.doc(deepcopy(SCHEMA_DOC))
@swagger.doc(ephemeral_processing_with_export.post_doc)
def post(self, location_name):
"""Execute a user defined process chain in an ephemeral location/mapset
and store the processing results for download.
Expand All @@ -144,7 +75,7 @@ class AsyncEphemeralExportS3Resource(ResourceBase):
def __init__(self):
ResourceBase.__init__(self)

@swagger.doc(deepcopy(SCHEMA_DOC))
@swagger.doc(ephemeral_processing_with_export.post_doc)
def post(self, location_name):
"""Execute a user defined process chain in an ephemeral location/mapset and
store the processing result in an Amazon S3 bucket
Expand All @@ -167,7 +98,7 @@ class AsyncEphemeralExportGCSResource(ResourceBase):
def __init__(self):
ResourceBase.__init__(self)

@swagger.doc(deepcopy(SCHEMA_DOC))
@swagger.doc(ephemeral_processing_with_export.post_doc)
def post(self, location_name):
"""Execute a user defined process chain in an ephemeral location/mapset
and store the processing result in an Google cloud storage bucket
Expand Down
Loading

0 comments on commit 3292c19

Please sign in to comment.