Skip to content

Commit 13eb26a

Browse files
[Fixes #227] Delete legacy upload code (#239)
* [Fixes #227] Cleanup not-user code * [Fixes #227] Fix test
1 parent 2ca3058 commit 13eb26a

File tree

3 files changed

+2
-68
lines changed

3 files changed

+2
-68
lines changed

importer/orchestrator.py

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import logging
2-
import os
32
from typing import Optional
43
from uuid import UUID
54

@@ -9,9 +8,8 @@
98
from django.utils import timezone
109
from django.utils.module_loading import import_string
1110
from django_celery_results.models import TaskResult
12-
from geonode.base.enumerations import STATE_INVALID, STATE_PROCESSED, STATE_RUNNING
1311
from geonode.resource.models import ExecutionRequest
14-
from geonode.upload.models import Upload
12+
from geonode.storage.manager import storage_manager
1513
from rest_framework import serializers
1614

1715
from importer.api.exception import ImportException
@@ -30,13 +28,8 @@ class ImportOrchestrator:
3028
it call the next step of the import pipeline
3129
Params:
3230
33-
enable_legacy_upload_status default=True: if true, will save the upload progress
34-
also in the legacy upload system
3531
"""
3632

37-
def __init__(self, enable_legacy_upload_status=True) -> None:
38-
self.enable_legacy_upload_status = enable_legacy_upload_status
39-
4033
def get_handler(self, _data) -> Optional[BaseHandler]:
4134
"""
4235
If is part of the supported format, return the handler which can handle the import
@@ -172,7 +165,6 @@ def set_as_failed(self, execution_id, reason=None, delete_file=True):
172165
finished=timezone.now(),
173166
last_updated=timezone.now(),
174167
log=reason,
175-
legacy_status=STATE_INVALID,
176168
)
177169
# delete
178170
if delete_file:
@@ -194,7 +186,6 @@ def set_as_partially_failed(self, execution_id, reason=None):
194186
finished=timezone.now(),
195187
last_updated=timezone.now(),
196188
log=f"The execution is completed, but the following layers are not imported: \n {', '.join(reason)}. Check the logs for additional infos",
197-
legacy_status=STATE_INVALID,
198189
)
199190

200191
def set_as_completed(self, execution_id):
@@ -206,7 +197,6 @@ def set_as_completed(self, execution_id):
206197
status=ExecutionRequest.STATUS_FINISHED,
207198
finished=timezone.now(),
208199
last_updated=timezone.now(),
209-
legacy_status=STATE_PROCESSED,
210200
)
211201

212202
def evaluate_execution_progress(
@@ -301,7 +291,6 @@ def create_execution_request(
301291
step: str,
302292
input_params: dict = {},
303293
resource=None,
304-
legacy_upload_name="",
305294
action=None,
306295
name=None,
307296
source=None,
@@ -320,29 +309,12 @@ def create_execution_request(
320309
name=name,
321310
source=source,
322311
)
323-
if self.enable_legacy_upload_status:
324-
# getting the package name from the base_filename
325-
Upload.objects.create(
326-
name=legacy_upload_name
327-
or os.path.basename(input_params.get("files", {}).get("base_file")),
328-
state=STATE_RUNNING,
329-
user=user,
330-
metadata={
331-
**{
332-
"func_name": func_name,
333-
"step": step,
334-
"exec_id": str(execution.exec_id),
335-
},
336-
**input_params,
337-
},
338-
)
339312
return execution.exec_id
340313

341314
def update_execution_request_status(
342315
self,
343316
execution_id,
344317
status=None,
345-
legacy_status=STATE_RUNNING,
346318
celery_task_request=None,
347319
**kwargs,
348320
):
@@ -355,12 +327,6 @@ def update_execution_request_status(
355327

356328
ExecutionRequest.objects.filter(exec_id=execution_id).update(**kwargs)
357329

358-
if self.enable_legacy_upload_status:
359-
Upload.objects.filter(metadata__contains=execution_id).update(
360-
state=legacy_status,
361-
complete=True,
362-
metadata={**kwargs, **{"exec_id": execution_id}},
363-
)
364330
if celery_task_request:
365331
TaskResult.objects.filter(task_id=celery_task_request.id).update(
366332
task_args=celery_task_request.args
@@ -376,4 +342,4 @@ def _last_step(self, execution_id, handler_module_path):
376342
return self.load_handler(handler_module_path).perform_last_step(execution_id)
377343

378344

379-
orchestrator = ImportOrchestrator(enable_legacy_upload_status=False)
345+
orchestrator = ImportOrchestrator()

importer/tests/unit/test_orchestrator.py

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@
1010
from importer.handlers.base import BaseHandler
1111
from importer.handlers.shapefile.serializer import ShapeFileSerializer
1212
from importer.orchestrator import ImportOrchestrator
13-
from geonode.upload.models import Upload
1413
from django.utils import timezone
1514
from django_celery_results.models import TaskResult
1615
from geonode.assets.handlers import asset_handler_registry
1716

18-
from geonode.base import enumerations as enum
1917
from geonode.resource.models import ExecutionRequest
2018

2119
# Create your tests here.
@@ -103,8 +101,6 @@ def test_create_execution_request(self):
103101
self.assertEqual(count + 1, ExecutionRequest.objects.count())
104102
self.assertDictEqual(input_files, exec_obj.input_params)
105103
self.assertEqual(exec_obj.STATUS_READY, exec_obj.status)
106-
# check that also the legacy is created
107-
self.assertIsNotNone(Upload.objects.get(metadata__icontains=exec_id))
108104

109105
@patch("importer.orchestrator.importer_app.tasks.get")
110106
def test_perform_next_step(self, mock_celery):
@@ -184,7 +180,6 @@ def test_perform_with_error_set_invalid_status(self, mock_celery):
184180
_excec = ExecutionRequest.objects.filter(exec_id=_id).first()
185181
self.assertIsNotNone(_excec)
186182
self.assertEqual(ExecutionRequest.STATUS_FAILED, _excec.status)
187-
self.assertIsNotNone(Upload.objects.get(metadata__icontains=_id))
188183

189184
def test_set_as_failed(self):
190185
# creating the temporary file that will be deleted
@@ -227,14 +222,8 @@ def test_set_as_failed(self):
227222
self.assertTrue(req.status, ExecutionRequest.STATUS_FAILED)
228223
self.assertTrue(req.log, "automatic test")
229224
self.assertFalse(os.path.exists(fake_path))
230-
# check legacy execution status
231-
legacy = Upload.objects.filter(metadata__contains=_uuid)
232-
self.assertTrue(legacy.exists())
233-
self.assertEqual(legacy.first().state, enum.STATE_INVALID)
234-
235225
# cleanup
236226
req.delete()
237-
legacy.delete()
238227

239228
def test_set_as_completed(self):
240229
# we need to create first the execution
@@ -254,14 +243,8 @@ def test_set_as_completed(self):
254243
req = ExecutionRequest.objects.get(exec_id=_uuid)
255244
self.assertTrue(req.status, ExecutionRequest.STATUS_FINISHED)
256245

257-
# check legacy execution status
258-
legacy = Upload.objects.filter(metadata__contains=_uuid)
259-
self.assertTrue(legacy.exists())
260-
self.assertEqual(legacy.first().state, enum.STATE_PROCESSED)
261-
262246
# cleanup
263247
req.delete()
264-
legacy.delete()
265248

266249
def test_update_execution_request_status(self):
267250
# we need to create first the execution
@@ -287,14 +270,8 @@ def test_update_execution_request_status(self):
287270
self.assertTrue(req.func_name, "function_name")
288271
self.assertTrue(req.step, "step_here")
289272

290-
# check legacy execution status
291-
legacy = Upload.objects.filter(metadata__contains=_uuid)
292-
self.assertTrue(legacy.exists())
293-
self.assertEqual(legacy.first().state, enum.STATE_RUNNING)
294-
295273
# cleanup
296274
req.delete()
297-
legacy.delete()
298275

299276
def test_evaluate_execution_progress_should_continue_if_some_task_is_not_finished(
300277
self,
@@ -306,7 +283,6 @@ def test_evaluate_execution_progress_should_continue_if_some_task_is_not_finishe
306283
user=get_user_model().objects.first(),
307284
func_name="test",
308285
step="test",
309-
legacy_upload_name="test",
310286
)
311287
)
312288

@@ -360,7 +336,6 @@ def test_evaluate_execution_progress_should_fail_if_one_task_is_failed(self):
360336
user=get_user_model().objects.first(),
361337
func_name="test",
362338
step="test",
363-
legacy_upload_name="test",
364339
input_params={
365340
"asset_id": asset.id,
366341
"asset_module_path": f"{asset.__module__}.{asset.__class__.__name__}",
@@ -389,7 +364,6 @@ def test_evaluate_execution_progress_should_set_as_completed(self):
389364
user=get_user_model().objects.first(),
390365
func_name="test",
391366
step="test",
392-
legacy_upload_name="test",
393367
)
394368
)
395369

importer/tests/unit/test_task.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ def setUp(self):
5757
user=get_user_model().objects.get(username=self.user),
5858
func_name="dummy_func",
5959
step="dummy_step",
60-
legacy_upload_name="dummy",
6160
input_params={
6261
"files": {"base_file": self.existing_file},
6362
# "overwrite_existing_layer": True,
@@ -97,7 +96,6 @@ def test_import_resource_should_rase_exp_if_is_invalid(
9796
user=get_user_model().objects.get(username=user),
9897
func_name="dummy_func",
9998
step="dummy_step",
100-
legacy_upload_name="dummy",
10199
input_params={"files": self.existing_file, "store_spatial_files": True},
102100
)
103101

@@ -131,7 +129,6 @@ def test_import_resource_should_work(
131129
user=get_user_model().objects.get(username=user),
132130
func_name="dummy_func",
133131
step="dummy_step",
134-
legacy_upload_name="dummy",
135132
input_params={"files": self.existing_file, "store_spatial_files": True},
136133
)
137134

@@ -203,7 +200,6 @@ def test_publish_resource_if_overwrite_should_call_the_publishing(
203200
user=get_user_model().objects.get(username=self.user),
204201
func_name="dummy_func",
205202
step="dummy_step",
206-
legacy_upload_name="dummy",
207203
input_params={
208204
"files": {"base_file": self.existing_file},
209205
"overwrite_existing_layer": True,
@@ -258,7 +254,6 @@ def test_publish_resource_if_overwrite_should_not_call_the_publishing(
258254
user=get_user_model().objects.get(username=self.user),
259255
func_name="dummy_func",
260256
step="dummy_step",
261-
legacy_upload_name="dummy",
262257
input_params={
263258
"files": {"base_file": self.existing_file},
264259
"overwrite_existing_layer": True,
@@ -531,7 +526,6 @@ def setUp(self):
531526
user=get_user_model().objects.get(username=self.user),
532527
func_name="dummy_func",
533528
step="dummy_step",
534-
legacy_upload_name="dummy",
535529
input_params={
536530
"files": {"base_file": self.existing_file},
537531
# "overwrite_existing_layer": True,

0 commit comments

Comments
 (0)