Skip to content
This repository was archived by the owner on May 6, 2024. It is now read-only.

Commit a9707e5

Browse files
Merge branch 'Master-Container' into DEV
2 parents 669edc5 + 3b25e27 commit a9707e5

File tree

4 files changed

+27
-8
lines changed

4 files changed

+27
-8
lines changed

pytaskmanager/node/DockerManager.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import os
55
import pathlib
66

7-
87
from typing import NamedTuple
98

109
class Result(NamedTuple):
@@ -28,7 +27,7 @@ class DockerManager(object):
2827
# TODO validate that allowed repositoy is used
2928
# TODO authenticate to docker repository... from the config-file
3029

31-
def __init__(self, allowed_repositories, tasks_dir, server_api_url):
30+
def __init__(self, allowed_repositories, tasks_dir, server_info):
3231
"""Initialization of DockerManager creates docker connection and
3332
sets some default values.
3433
@@ -45,7 +44,7 @@ def __init__(self, allowed_repositories, tasks_dir, server_api_url):
4544
self.__tasks_dir = tasks_dir
4645

4746
# master container need to know where they can post tasks to
48-
self.__server_url = server_api_url
47+
self.__server_info = server_info
4948

5049
def create_bind(self, filename, result_id, filecontents):
5150
input_path = self.__create_file(filename, result_id, filecontents)
@@ -140,7 +139,9 @@ def run(self, result_id: int, image: str, database_uri: str,
140139
# define enviroment variables for the docker-container
141140
environment_variables = {
142141
"DATABASE_URI": database_uri,
143-
"HOST": self.__server_url
142+
"HOST": self.__server_info.host,
143+
"PORT": self.__server_info.port,
144+
"API_PATH": self.__server_info.path
144145
}
145146
self.log.debug(f"Environment={environment_variables}")
146147

pytaskmanager/node/FlaskIO.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,16 @@
44
import jwt
55
import datetime
66

7+
from typing import NamedTuple
8+
79
module_name = __name__.split('.')[1]
810

11+
class ServerInfo(NamedTuple):
12+
"""Data-class to store the server info"""
13+
host: str
14+
port: int
15+
path: str
16+
917
class ClientBaseProtocol(object):
1018
"""Implemention base protocols for communicating with server instance"""
1119

@@ -160,6 +168,10 @@ def host(self):
160168
def port(self):
161169
return self.__port
162170

171+
@property
172+
def path(self):
173+
return self.__api_path
174+
163175
@property
164176
def base_path(self):
165177
if self.__port:

pytaskmanager/node/__init__.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
from pytaskmanager import util
2222
from pytaskmanager.node.DockerManager import DockerManager
23-
from pytaskmanager.node.FlaskIO import ClientNodeProtocol
23+
from pytaskmanager.node.FlaskIO import ClientNodeProtocol, ServerInfo
2424

2525
def name():
2626
return __name__.split('.')[-1]
@@ -98,11 +98,17 @@ def __init__(self, ctx):
9898
self.log.debug("fetching tasks that were posted while offline")
9999
self.__sync_task_que_with_server()
100100

101+
server_info = ServerInfo(
102+
host=self.flaskIO.host,
103+
port=self.flaskIO.port,
104+
path=self.flaskIO.path
105+
)
106+
101107
# TODO read allowed repositories from the config file
102108
self.__docker = DockerManager(
103109
allowed_repositories=[],
104110
tasks_dir=self.ctx.data_dir,
105-
server_api_url=self.flaskIO.host
111+
server_info=server_info
106112
)
107113

108114
# send results to the server when they come available.

pytaskmanager/server/resource/collaboration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
from pytaskmanager.server import db
1818
from pytaskmanager.server.resource._schema import CollaborationSchema, TaskSchema
19-
from pytaskmanager.server.resource import with_user_or_node, with_user
19+
from pytaskmanager.server.resource import with_user_or_node, with_user, only_for
2020

2121
module_name = __name__.split('.')[-1]
2222
log = logging.getLogger(module_name)
@@ -163,7 +163,7 @@ def delete(self, id):
163163
class CollaborationOrganization(Resource):
164164
"""Resource for /api/collaboration/<int:id>/organization."""
165165

166-
@with_user
166+
@only_for(["node","user","container"])
167167
@swag_from(str(Path(r"swagger/get_collaboration_organization.yaml")), endpoint='collaboration_with_id_organization')
168168
def get(self, id):
169169
"""Return organizations for a specific collaboration."""

0 commit comments

Comments
 (0)