Skip to content

Commit

Permalink
Merge pull request #60 from actinia-org/location_to_project
Browse files Browse the repository at this point in the history
Rename location to project
  • Loading branch information
anikaweinmann authored Dec 13, 2024
2 parents 4467d93 + 45d5f9c commit 6c07a3a
Show file tree
Hide file tree
Showing 11 changed files with 1,007 additions and 939 deletions.
25 changes: 23 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@ concurrency:
cancel-in-progress: true

jobs:
# Tests for GRASS 8.4
tests:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
# with:
# path: "."
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Tests of actinia-module-plugin
Expand All @@ -34,3 +33,25 @@ jobs:
file: docker/actinia-module-plugin-test/Dockerfile
no-cache: true
# pull: true

# Tests for GRASS 8.3
tests-G83:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Replace run integration test command
run: |
sed -i "s+mundialis/actinia:latest+mundialis/actinia:2.9.2_G83+g" docker/actinia-module-plugin-test/Dockerfile
- name: Tests of actinia-module-plugin
id: docker_build
uses: docker/build-push-action@v6
with:
push: false
tags: actinia-module-plugin-test:alpine
context: .
file: docker/actinia-module-plugin-test/Dockerfile
no-cache: true
# pull: true
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,7 @@ resp.json

# docker
!docker/actinia-module-plugin-test/actinia-module-plugin-test.cfg

# linting with shared config file
ruff-github-workflows.toml
ruff-merged.toml
4 changes: 2 additions & 2 deletions actinia-module.md
Original file line number Diff line number Diff line change
Expand Up @@ -499,8 +499,8 @@ List / Describe combined

Execute module

* POST /locations/{location_name}/processing_export
* POST /locations/{location_name}/mapsets/{mapset_name}/processing (TODO)
* POST /projects/{project_name}/processing_export
* POST /projects/{project_name}/mapsets/{mapset_name}/processing (TODO)

Full API docs

Expand Down
10 changes: 5 additions & 5 deletions src/actinia_module_plugin/api/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,15 +208,15 @@ def __init__(self):
ResourceBase.__init__(self)

@swagger.doc(deepcopy(SCHEMA_DOC_EPHEMERAL_PROCESSING_WITH_EXPORT))
def post(self, location_name):
def post(self, project_name):
"""
Execute a user defined process chain in an ephemeral location/mapset
Execute a user defined process chain in an ephemeral project/mapset
and store the processing results for download.
"""

preprocess_kwargs = {}
preprocess_kwargs["has_json"] = True
preprocess_kwargs["location_name"] = location_name
preprocess_kwargs["project_name"] = project_name

start_job = start_job_ephemeral_processing_with_export

Expand All @@ -236,15 +236,15 @@ def __init__(self):
ResourceBase.__init__(self)

@swagger.doc(deepcopy(SCHEMA_DOC_PERSISTENT_PROCESSING))
def post(self, location_name, mapset_name):
def post(self, project_name, mapset_name):
"""
Execute a user defined process chain that creates a new mapset or
runs in an existing one.
"""

preprocess_kwargs = {}
preprocess_kwargs["has_json"] = True
preprocess_kwargs["location_name"] = location_name
preprocess_kwargs["project_name"] = project_name
preprocess_kwargs["mapset_name"] = mapset_name

start_job = start_job_persistent_processing
Expand Down
76 changes: 38 additions & 38 deletions src/actinia_module_plugin/core/modules/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,41 +66,41 @@
def initGrass(self):
"""
* not using enqueue_job to get always a response
* the function creates a new location cause not all users can access
a location
* the function creates a new project cause not all users can access
a project
"""

# check if location exists
location_name = "location_for_listing_modules_" + str(uuid.uuid4())
# '/actinia_core/grassdb/location_for_listing_modules'
location = os.path.join(global_config.GRASS_DATABASE, location_name)
# Check the location path
if os.path.isdir(location):
# check if project exists
project_name = "project_for_listing_modules_" + str(uuid.uuid4())
# '/actinia_core/grassdb/project_for_listing_modules'
project = os.path.join(global_config.GRASS_DATABASE, project_name)
# Check the project path
if os.path.isdir(project):
msg = (
"Unable to create location. "
"Location <%s> exists in global database." % location_name
"Unable to create project. "
"Project <%s> exists in global database." % project_name
)
return self.get_error_response(message=msg)
# Check also for the user database
# '/actinia_core/userdata/superadmin/location_for_listing_modules'
location = os.path.join(
self.grass_user_data_base, self.user_group, location_name
# '/actinia_core/userdata/superadmin/project_for_listing_modules'
project = os.path.join(
self.grass_user_data_base, self.user_group, project_name
)
# Check the location path
if os.path.isdir(location):
# Check the project path
if os.path.isdir(project):
msg = (
"Unable to create location. "
"Location <%s> exists in user database." % location_name
"Unable to create project. "
"Project <%s> exists in user database." % project_name
)
return self.get_error_response(message=msg)

# create new location cause not each user can access a location
# create new project cause not each user can access a project
if not os.path.isdir(
os.path.join(self.grass_user_data_base, self.user_group)
):
os.mkdir(os.path.join(self.grass_user_data_base, self.user_group))
os.mkdir(location)
mapset = os.path.join(location, "PERMANENT")
os.mkdir(project)
mapset = os.path.join(project, "PERMANENT")
os.mkdir(mapset)
with open(os.path.join(mapset, "DEFAULT_WIND"), "w") as out:
wind = (
Expand Down Expand Up @@ -134,30 +134,30 @@ def initGrass(self):
)
out.write(wind)

return location_name
return project_name


def deinitGrass(self, location_name):
def deinitGrass(self, project_name):
"""
* the function deletes above location
* the function deletes above project
"""
# remove location
location = os.path.join(global_config.GRASS_DATABASE, location_name)
if os.path.isdir(location):
shutil.rmtree(location)
location = os.path.join(
self.grass_user_data_base, self.user_group, location_name
# remove project
project = os.path.join(global_config.GRASS_DATABASE, project_name)
if os.path.isdir(project):
shutil.rmtree(project)
project = os.path.join(
self.grass_user_data_base, self.user_group, project_name
)
if os.path.isdir(location):
shutil.rmtree(location)
if os.path.isdir(project):
shutil.rmtree(project)
# del
# self.user_credentials["permissions"]['accessible_datasets'][location_name]
# self.user_credentials["permissions"]['accessible_datasets'][project_name]


class EphemeralModuleLister(EphemeralProcessing):
"""
Overwrites EphemeralProcessing from actinia_core to bypass permission
check for modules and temporary location, needed for self-description
check for modules and temporary project, needed for self-description
"""

def __init__(self, *args, pc):
Expand Down Expand Up @@ -188,20 +188,20 @@ def run_process_chain(self, process_chain):
"""
Used to list all GRASS modules, to describe a certain GRASS module
and to generate actinia module description out of containing GRASS modules.
ATTENTION! This call skips permission checks, so temporary location can be
ATTENTION! This call skips permission checks, so temporary project can be
used. If user is not allowed to use GRASS modules used here, this will be
allowed in these cases.
"""

location_name = initGrass(self)
project_name = initGrass(self)

# self.user_credentials["permissions"]['accessible_datasets'][location_name]
# self.user_credentials["permissions"]['accessible_datasets'][project_name]
# = ['PERMANENT']

rdc = self.preprocess(
has_json=False,
has_xml=False,
location_name=location_name,
project_name=project_name,
mapset_name="PERMANENT",
)

Expand All @@ -215,6 +215,6 @@ def list_modules(*args, process_chain=process_chain):
else:
http_code, response_model = pickle.loads(self.response_data)

deinitGrass(self, location_name)
deinitGrass(self, project_name)

return response_model
46 changes: 35 additions & 11 deletions src/actinia_module_plugin/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
Add endpoints to flask app with endpoint definitions and routes
"""

__author__ = "Carmen Tawalika"
__copyright__ = "2018-2021 mundialis GmbH & Co. KG"
__author__ = "Carmen Tawalika, Anika Weinmann"
__copyright__ = "2018-2024 mundialis GmbH & Co. KG"
__license__ = "Apache-2.0"


Expand All @@ -45,6 +45,36 @@
from actinia_module_plugin.api.actinia_templates import ActiniaTemplate
from actinia_module_plugin.api.actinia_templates import ActiniaTemplateId

from actinia_core.endpoints import get_endpoint_class_name


def create_project_endpoints(apidoc, projects_url_part="projects"):
"""
Function to add resources with "projects" inside the endpoint url.
Args:
apidoc (flask_restful_swagger_2.Api): Flask api
projects_url_part (str): The name of the projects inside the endpoint
URL; to add deprecated location endpoints set
it to "locations"
"""

apidoc.add_resource(
GdiAsyncEphemeralExportResource,
f"/{projects_url_part}/<string:project_name>/processing_export",
endpoint=get_endpoint_class_name(
GdiAsyncEphemeralExportResource, projects_url_part
),
)
apidoc.add_resource(
GdiAsyncPersistentResource,
f"/{projects_url_part}/<string:project_name>/mapsets/"
"<string:mapset_name>/processing",
endpoint=get_endpoint_class_name(
GdiAsyncPersistentResource, projects_url_part
),
)


def create_endpoints(flask_api):
# app = flask_api.app
Expand Down Expand Up @@ -76,15 +106,9 @@ def create_endpoints(flask_api):
apidoc.add_resource(ListVirtualModules, "/modules")
apidoc.add_resource(DescribeVirtualModule, "/modules/<module>")

apidoc.add_resource(
GdiAsyncEphemeralExportResource,
"/locations/<string:location_name>/processing_export",
)

apidoc.add_resource(
GdiAsyncPersistentResource,
"/locations/<string:location_name>/mapsets/<string:mapset_name>/processing",
)
# add deprecated location and project endpoints
create_project_endpoints(apidoc)
create_project_endpoints(apidoc, projects_url_part="locations")

apidoc.add_resource(ActiniaTemplate, "/actinia_templates")
apidoc.add_resource(ActiniaTemplateId, "/actinia_templates/<template_id>")
Expand Down
Loading

0 comments on commit 6c07a3a

Please sign in to comment.