From 8f8f8fda9922a75b8ad2e060f10f4876d8d59cfe Mon Sep 17 00:00:00 2001
From: jkuensem <jkuensem@physik.uni-bielefeld.de>
Date: Mon, 20 Jul 2020 16:44:47 +0200
Subject: [PATCH] TMSS-241: remove units from resource models (which should
 always be in SI/base units on the DB level)

---
 .../tmss/tmssapp/migrations/0001_initial.py   | 20 +------------------
 .../src/tmss/tmssapp/models/specification.py  |  5 +----
 SAS/TMSS/src/tmss/tmssapp/populate.py         |  9 +++------
 .../tmss/tmssapp/serializers/specification.py |  7 -------
 .../tmss/tmssapp/viewsets/specification.py    |  5 -----
 SAS/TMSS/src/tmss/urls.py                     |  1 -
 SAS/TMSS/test/tmss_test_data_django_models.py |  8 --------
 SAS/TMSS/test/tmss_test_data_rest.py          | 12 +----------
 8 files changed, 6 insertions(+), 61 deletions(-)

diff --git a/SAS/TMSS/src/tmss/tmssapp/migrations/0001_initial.py b/SAS/TMSS/src/tmss/tmssapp/migrations/0001_initial.py
index fedf0592a12..8a7c77a6b19 100644
--- a/SAS/TMSS/src/tmss/tmssapp/migrations/0001_initial.py
+++ b/SAS/TMSS/src/tmss/tmssapp/migrations/0001_initial.py
@@ -1,4 +1,4 @@
-# Generated by Django 3.0.6 on 2020-07-14 21:50
+# Generated by Django 3.0.6 on 2020-07-20 14:07
 
 from django.conf import settings
 import django.contrib.postgres.fields
@@ -364,19 +364,6 @@ class Migration(migrations.Migration):
                 'abstract': False,
             },
         ),
-        migrations.CreateModel(
-            name='ResourceUnit',
-            fields=[
-                ('tags', django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=128), blank=True, default=list, help_text='User-defined search keywords for object.', size=8)),
-                ('created_at', models.DateTimeField(auto_now_add=True, help_text='Moment of object creation.')),
-                ('updated_at', models.DateTimeField(auto_now=True, help_text='Moment of last object update.')),
-                ('description', models.CharField(help_text='A longer description of this object.', max_length=255)),
-                ('name', models.CharField(help_text='Human-readable name of this object.', max_length=128, primary_key=True, serialize=False)),
-            ],
-            options={
-                'abstract': False,
-            },
-        ),
         migrations.CreateModel(
             name='Role',
             fields=[
@@ -1001,11 +988,6 @@ class Migration(migrations.Migration):
             name='project',
             field=models.ForeignKey(help_text='Project to which this scheduling set belongs.', on_delete=django.db.models.deletion.PROTECT, related_name='scheduling_sets', to='tmssapp.Project'),
         ),
-        migrations.AddField(
-            model_name='resourcetype',
-            name='resource_unit',
-            field=models.ForeignKey(help_text='Unit of current resource.', on_delete=django.db.models.deletion.PROTECT, related_name='resource_types', to='tmssapp.ResourceUnit'),
-        ),
         migrations.AddField(
             model_name='projectquota',
             name='project',
diff --git a/SAS/TMSS/src/tmss/tmssapp/models/specification.py b/SAS/TMSS/src/tmss/tmssapp/models/specification.py
index 34b5b981e3f..ec60e4693db 100644
--- a/SAS/TMSS/src/tmss/tmssapp/models/specification.py
+++ b/SAS/TMSS/src/tmss/tmssapp/models/specification.py
@@ -294,12 +294,9 @@ class ProjectQuota(Model):
 
 
 class ResourceType(NamedCommonPK):
-    resource_unit = ForeignKey('ResourceUnit', related_name="resource_types", on_delete=PROTECT, help_text='Unit of current resource.')
-
-
-class ResourceUnit(NamedCommonPK):
     pass
 
+
 class SchedulingSet(NamedCommon):
     generator_doc = JSONField(null=True, help_text='Parameters for the generator (NULLable).')
     generator_template = ForeignKey('GeneratorTemplate', on_delete=SET_NULL, null=True, help_text='Generator for the scheduling units in this set (NULLable).')
diff --git a/SAS/TMSS/src/tmss/tmssapp/populate.py b/SAS/TMSS/src/tmss/tmssapp/populate.py
index fbb1aa3e017..05ce47208c7 100644
--- a/SAS/TMSS/src/tmss/tmssapp/populate.py
+++ b/SAS/TMSS/src/tmss/tmssapp/populate.py
@@ -207,12 +207,9 @@ def populate_projects(apps, schema_editor):
 
 
 def populate_resources(apps, schema_editor):
-    ru_bytes = ResourceUnit.objects.create(name="bytes", description="Bytes")
-    ru_hours = ResourceUnit.objects.create(name="hours", description="duration in hours")
-
-    ResourceType.objects.create(name="lta_storage", description="Amount of storage in LTA", resource_unit=ru_bytes)
-    ResourceType.objects.create(name="cep_storage", description="Amount of storage at CEP processing cluster", resource_unit=ru_bytes)
-    ResourceType.objects.create(name="cep_processing_hours", description="Number of processing hours for CEP processing cluster", resource_unit=ru_hours)
+    ResourceType.objects.create(name="lta_storage", description="Amount of storage in the LTA (in bytes)")
+    ResourceType.objects.create(name="cep_storage", description="Amount of storage on the CEP processing cluster (in bytes)")
+    ResourceType.objects.create(name="cep_processing_hours", description="Processing time on the CEP processing cluster (in seconds)")
 
 
 def populate_misc(apps, schema_editor):
diff --git a/SAS/TMSS/src/tmss/tmssapp/serializers/specification.py b/SAS/TMSS/src/tmss/tmssapp/serializers/specification.py
index 3a3a3fa3f8b..89dc4d9016d 100644
--- a/SAS/TMSS/src/tmss/tmssapp/serializers/specification.py
+++ b/SAS/TMSS/src/tmss/tmssapp/serializers/specification.py
@@ -186,13 +186,6 @@ class ProjectQuotaSerializer(RelationalHyperlinkedModelSerializer):
         extra_fields = ['resource_type']
 
 
-class ResourceUnitSerializer(RelationalHyperlinkedModelSerializer):
-    class Meta:
-        model = models.ResourceUnit
-        fields = '__all__'
-        extra_fields = ['name']
-
-
 class ResourceTypeSerializer(RelationalHyperlinkedModelSerializer):
     class Meta:
         model = models.ResourceType
diff --git a/SAS/TMSS/src/tmss/tmssapp/viewsets/specification.py b/SAS/TMSS/src/tmss/tmssapp/viewsets/specification.py
index 5b9443860cf..2dd4033c9a9 100644
--- a/SAS/TMSS/src/tmss/tmssapp/viewsets/specification.py
+++ b/SAS/TMSS/src/tmss/tmssapp/viewsets/specification.py
@@ -147,11 +147,6 @@ class CopyReasonViewSet(LOFARViewSet):
     queryset = models.CopyReason.objects.all()
     serializer_class = serializers.CopyReasonSerializer
 
-
-class ResourceUnitViewSet(LOFARViewSet):
-    queryset = models.ResourceUnit.objects.all()
-    serializer_class = serializers.ResourceUnitSerializer
-
     
 class TaskConnectorTypeViewSet(LOFARViewSet):
     queryset = models.TaskConnectorType.objects.all()
diff --git a/SAS/TMSS/src/tmss/urls.py b/SAS/TMSS/src/tmss/urls.py
index ba637bdea81..e49755be62a 100644
--- a/SAS/TMSS/src/tmss/urls.py
+++ b/SAS/TMSS/src/tmss/urls.py
@@ -104,7 +104,6 @@ router.register(r'default_task_relation_selection_template', viewsets.DefaultTas
 # instances
 router.register(r'cycle', viewsets.CycleViewSet)
 router.register(r'project', viewsets.ProjectViewSet)
-router.register(r'resource_unit', viewsets.ResourceUnitViewSet)
 router.register(r'resource_type', viewsets.ResourceTypeViewSet)
 router.register(r'project_quota', viewsets.ProjectQuotaViewSet)
 router.register(r'setting', viewsets.SettingViewSet)
diff --git a/SAS/TMSS/test/tmss_test_data_django_models.py b/SAS/TMSS/test/tmss_test_data_django_models.py
index 2d8a16334f7..e9db5ec6fd3 100644
--- a/SAS/TMSS/test/tmss_test_data_django_models.py
+++ b/SAS/TMSS/test/tmss_test_data_django_models.py
@@ -111,18 +111,10 @@ def Project_test_data() -> dict:
                "expert": True,
                "filler": False}
 
-def ResourceUnit_test_data() -> dict:
-    return  {
-        "tags": [],
-        "description": 'my description ' + str(uuid.uuid4()),
-        "name": 'my_resource_unit_' + str(uuid.uuid4()),
-        }
-
 def ResourceType_test_data() -> dict:
     return  {
         "tags": [],
         "description": 'my description ' + str(uuid.uuid4()),
-        "resource_unit": models.ResourceUnit.objects.create(**ResourceUnit_test_data()),
         "name": 'my_resource_type_' + str(uuid.uuid4()),
      }
 
diff --git a/SAS/TMSS/test/tmss_test_data_rest.py b/SAS/TMSS/test/tmss_test_data_rest.py
index 5e83ad35086..a75637c6c48 100644
--- a/SAS/TMSS/test/tmss_test_data_rest.py
+++ b/SAS/TMSS/test/tmss_test_data_rest.py
@@ -144,20 +144,10 @@ class TMSSRESTTestDataCreator():
                 "private_data": True,
                 "cycles": []}
 
-    def ResourceUnit(self):
-            return  {
-                "tags": [],
-                "description": 'my description ' + str(uuid.uuid4()),
-                "name": 'my_resource_unit_' + str(uuid.uuid4())
-            }
-
-    def ResourceType(self, description="my resource_type description", resource_url=None):
-        if resource_url is None:
-            resource_url = self.post_data_and_get_url(self.ResourceUnit(), '/resource_unit/')
+    def ResourceType(self, description="my resource_type description"):
         return {
             "tags": [],
             "description": description,
-            "resource_unit": resource_url,
             "name": 'my_resource_type_' + str(uuid.uuid4())
         }
 
-- 
GitLab