Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unused endpoints #656

Draft
wants to merge 24 commits into
base: development
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
dd2d2d5
removed ova-list endpoint
TheMrSheldon Jul 30, 2024
24cf4cf
removed add-software/vm endpoint
TheMrSheldon Jul 30, 2024
ecfad9f
removed code that died with the last change
TheMrSheldon Jul 30, 2024
fe01cb4
removed save_software/vm endpoint
TheMrSheldon Jul 30, 2024
5e3abde
removed delete_software/vm endpoint
TheMrSheldon Jul 30, 2024
8200373
removed unused vm_api endpoints
TheMrSheldon Jul 30, 2024
01a9468
removed tira-admin/reload* endpoints
TheMrSheldon Jul 30, 2024
6c70dc8
removed admin-create-vm, admin-archive-vm and admin-modify-vm endpoints
TheMrSheldon Jul 31, 2024
1514d6d
removed tira-admin/export-participants endpoint
TheMrSheldon Jul 31, 2024
51f3c56
removed tira-admin/import-irds-dataset endpoint
TheMrSheldon Jul 31, 2024
a354f0c
marked all remaining unused endpoints and removed unused imports
TheMrSheldon Jul 31, 2024
e828627
removed unused variables from HybridDatabase
TheMrSheldon Jul 31, 2024
1b7ca87
removed api/snippets-for-tirex-components endpoint
TheMrSheldon Jul 31, 2024
7f7407b
removed host-list endpoint
TheMrSheldon Jul 31, 2024
0f77386
removed dead code from application/src/tira/data/data.py
TheMrSheldon Jul 31, 2024
ca1fab9
removed organizer-list endpoint
TheMrSheldon Aug 1, 2024
cbe1df1
removed api/organizer/:id endpoint
TheMrSheldon Aug 1, 2024
20e1b51
removed api/evaluation/:vmid/:runid endpoint
TheMrSheldon Aug 1, 2024
a9885c7
removed tira-admin/create-group/:vmid endpoint
TheMrSheldon Aug 1, 2024
f8abba8
removed tira-admin/edit-organizer/:orgid endpoint
TheMrSheldon Aug 1, 2024
dd4ee3c
removed tira-admin/add-organizer/:orgid endpoint
TheMrSheldon Aug 1, 2024
907575f
linters happy
TheMrSheldon Aug 1, 2024
5428a6e
isort happy
TheMrSheldon Aug 1, 2024
c2df223
apt update in test ci
TheMrSheldon Aug 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
- name: Install Dependencies
working-directory: ${{github.workspace}}/python-client
run: |
sudo apt-get update
sudo apt-get install -y openjdk-11-jdk
pip3 install .[test,dev]
- name: Running Tests
Expand Down
29 changes: 1 addition & 28 deletions application/src/tira/authentication.py
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to keep the organizer list and add organizer endpoints, as they are conceptually valuable, it can be that they are not embedded in the vuetify UI yet (as this is used not too often) but I then would prefer to incorporate this into the UI soon.

Original file line number Diff line number Diff line change
Expand Up @@ -371,27 +371,6 @@ def user_is_organizer_for_endpoint(

organizer_ids = self.get_organizer_ids(request)

if path == "/api/organizer-list" and (
role == auth.ROLE_PARTICIPANT or role == auth.ROLE_ADMIN or role == auth.ROLE_USER or role == auth.ROLE_TIRA
):
return True

if path.startswith("/tira-admin/add-organizer/"):
existing_organizer_ids = set([i["organizer_id"] for i in model.get_organizer_list()])
orga_name = path.split("/tira-admin/add-organizer/")[1]

return (
len(orga_name.split("/")) == 1
and orga_name not in existing_organizer_ids
and organizer_id_from_params == orga_name
and (
role == auth.ROLE_PARTICIPANT
or role == auth.ROLE_ADMIN
or role == auth.ROLE_USER
or role == auth.ROLE_TIRA
)
)

if not organizer_ids or len(organizer_ids) < 1:
return False

Expand Down Expand Up @@ -426,18 +405,12 @@ def user_is_organizer_for_endpoint(
pass

return (
path == "/api/organizer-list"
or (task and "organizer_id" in task and task["organizer_id"] in organizer_ids)
(task and "organizer_id" in task and task["organizer_id"] in organizer_ids)
or (
organizer_id_from_params
and organizer_id_from_params in organizer_ids
and path in set(f"/tira-admin/{i}/create-task" for i in organizer_ids)
)
or (
organizer_id_from_params
and organizer_id_from_params in organizer_ids
and path in set(f"/tira-admin/edit-organizer/{i}" for i in organizer_ids)
)
or (
organizer_id_from_run_id
and organizer_id_from_run_id in organizer_ids
Expand Down
130 changes: 0 additions & 130 deletions application/src/tira/data/FileDatabase.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import logging
import re
from datetime import datetime
from datetime import datetime as dt
from datetime import timezone
from pathlib import Path
from shutil import rmtree
from typing import _T, Optional
Expand Down Expand Up @@ -45,8 +42,6 @@ class FileDatabase(object):
organizers_file_path = tira_root / Path("model/organizers/organizers.prototext")
vm_list_file = tira_root / Path("model/virtual-machines/virtual-machines.txt")
vm_dir_path = tira_root / Path("model/virtual-machines")
host_list_file = tira_root / Path("model/virtual-machine-hosts/virtual-machine-hosts.txt")
ova_dir = tira_root / Path("data/virtual-machine-templates/")
datasets_dir_path = tira_root / Path("model/datasets")
softwares_dir_path = tira_root / Path("model/softwares")
data_path = tira_root / Path("data/datasets")
Expand Down Expand Up @@ -90,25 +85,6 @@ def build_model(self):
self._build_software_relations()
self._build_software_counts()

def reload_vms(self):
"""reload VM and user data from the export format of the model"""
self._parse_vm_list()

def reload_datasets(self):
"""reload dataset data from the export format of the model"""
self._parse_dataset_list()

def reload_tasks(self):
"""reload task data from the export format of the model"""
self._parse_task_list()
self._build_task_relations()
self._build_software_relations()
self._build_software_counts()

def reload_runs(self, vm_id):
"""reload run data for a VM from the export format of the model"""
raise NotImplementedError("Not Implemented: Runs are loaded on access when using FileDatabase")

def _parse_organizer_list(self):
"""Parse the PB Database and extract all hosts.
:return: a dict {hostId: {"name", "years"}
Expand Down Expand Up @@ -244,17 +220,6 @@ def _load_vm(self, vm_id):
"""load a vm object from vm_dir_path"""
return Parse(open(self.vm_dir_path / f"{vm_id}.prototext").read(), modelpb.VirtualMachine())

def _load_softwares(self, task_id, vm_id):
softwares_dir = self.softwares_dir_path / task_id / vm_id
softwares_dir.mkdir(parents=True, exist_ok=True)
software_file = softwares_dir / "softwares.prototext"
if not software_file.exists():
software_file.touch()

return Parse(
open(self.softwares_dir_path / task_id / vm_id / "softwares.prototext", "r").read(), modelpb.Softwares()
)

def _load_run(self, dataset_id, vm_id, run_id, return_deleted: bool = False):
run_dir = self.RUNS_DIR_PATH / dataset_id / vm_id / run_id
if not (run_dir / "run.bin").exists():
Expand Down Expand Up @@ -337,11 +302,6 @@ def _save_review(self, dataset_id, vm_id, run_id, review):
open(review_path / "run-review.prototext", "w").write(str(review))
open(review_path / "run-review.bin", "wb").write(review.SerializeToString())

def _save_softwares(self, task_id, vm_id, softwares):
with open(self.softwares_dir_path / task_id / vm_id / "softwares.prototext", "w+") as prototext_file:
# update file
prototext_file.write(str(softwares))

def _save_run(self, dataset_id, vm_id, run_id, run):
run_dir = self.RUNS_DIR_PATH / dataset_id / vm_id / run_id
run_dir.mkdir(parents=True, exist_ok=True)
Expand Down Expand Up @@ -421,40 +381,6 @@ def add_dataset(self, task_id, dataset_id, dataset_type, dataset_name):

return [str(nd) for nd in new_dirs]

def _add_software(self, task_id, vm_id):
# TODO crashes if software prototext does not exist.
software = modelpb.Softwares.Software()
s = self._load_softwares(task_id, vm_id)
try:
last_software_count = re.search(r"\d+$", s.softwares[-1].id)
software_count = int(last_software_count.group()) + 1 if last_software_count else None
if software_count is None:
# invalid software id value
return False

software.id = f"software{software_count}"
software.count = str(software_count)

except IndexError:
# no software present yet
software.id = "software1"
software.count = "1"

software.command = ""
software.workingDirectory = ""
software.dataset = "None"
software.run = ""
software.creationDate = datetime.now(timezone.utc).strftime("%a %b %d %X %Z %Y")
software.lastEditDate = software.creationDate
software.deleted = False

s.softwares.append(software)
self._save_softwares(task_id, vm_id, s)

software_list = self.software.get(f"{task_id}${vm_id}", [])
software_list.append(software)
self.software[f"{task_id}${vm_id}"] = software_list

def add_evaluator(self, vm_id, task_id, dataset_id, dataset_type, command, working_directory, measures):
"""TODO documentation"""
evaluator_id = f"{dataset_id}-evaluator"
Expand Down Expand Up @@ -531,48 +457,6 @@ def update(x, y):
run.deleted = update(run.deleted, deleted)
self._save_run(dataset_id, vm_id, run_id, run)

def update_software(
self,
task_id,
vm_id,
software_id,
command: Optional[str] = None,
working_directory: Optional[str] = None,
dataset: Optional[str] = None,
run: Optional[str] = None,
deleted: bool = False,
):
def update(x, y):
return y if y is not None else x

s = self._load_softwares(task_id, vm_id)
for software in s.softwares:
if software.id == software_id:
software.command = update(software.command, command)
software.workingDirectory = update(software.workingDirectory, working_directory)
software.dataset = update(software.dataset, dataset)
software.run = update(software.run, run)
software.deleted = update(software.deleted, deleted)
software.lastEditDate = datetime.now(timezone.utc).strftime("%a %b %d %X %Z %Y")

self._save_softwares(task_id, vm_id, s)
software_list = [user_software for user_software in s.softwares if not user_software.deleted]
self.software[f"{task_id}${vm_id}"] = software_list
return software

# TODO add option to truly delete the software.
def delete_software(self, task_id, vm_id, software_id):
s = self._load_softwares(task_id, vm_id)

for software in s.softwares:
if software.id == software_id:
break
else:
raise TiraModelWriteError(f"Software does not exist: {task_id}, {vm_id}, {software_id}")
software_list = [software for software in s.softwares if not software.deleted]
self.software[f"{task_id}${vm_id}"] = software_list
self._save_softwares(task_id, vm_id, s)

def delete_run(self, dataset_id, vm_id, run_id):
run_dir = Path(self.RUNS_DIR_PATH / dataset_id / vm_id / run_id)
rmtree(run_dir)
Expand Down Expand Up @@ -660,12 +544,6 @@ def get_organizer(self, organizer_id: str):
# TODO should return as dict
return self.organizers[organizer_id]

def get_host_list(self) -> list:
return list(open(self.host_list_file, "r").readlines())

def get_ova_list(self) -> list:
return [f"{ova_file.stem}.ova" for ova_file in self.ova_dir.glob("*.ova")]

def get_vm_list(self):
"""load the vm-info file which stores all active vms as such:
<hostname>\t<vm_id>[\t<state>]\n
Expand Down Expand Up @@ -901,14 +779,6 @@ def get_software_with_runs(self, task_id, vm_id):
# ------------------------------------------------------------
# add methods to add new data to the model
# ------------------------------------------------------------

def add_software(self, task_id: str, vm_id: str):
try:
self._add_software(task_id, vm_id)
except FileNotFoundError as e:
logger.exception(f"Exception while adding software ({task_id}, {vm_id}): {e}")
raise TiraModelWriteError(f"Failed to write VM {vm_id}")

def update_review(
self,
dataset_id,
Expand Down
Loading
Loading