Skip to content

Commit

Permalink
Merge pull request #199 from ICRAR/LIU-284
Browse files Browse the repository at this point in the history
Liu 284 - Automatic deployment option detection
  • Loading branch information
pritchardn committed Nov 3, 2022
2 parents 5eade9c + 3eef05a commit 4ce5235
Show file tree
Hide file tree
Showing 19 changed files with 508 additions and 419 deletions.
6 changes: 6 additions & 0 deletions daliuge-common/dlg/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ def shutdown_node_manager(self):
def get_log_file(self, sessionId):
return self._request(f"/sessions/{sessionId}/logs", "GET")

def get_submission_method(self):
return self._get_json("/submission_method")


class CompositeManagerClient(BaseDROPManagerClient):
def nodes(self):
Expand All @@ -252,6 +255,9 @@ def add_node(self, node):
def remove_node(self, node):
self._DELETE(f"/node/{node}")

def get_submission_method(self):
return self._get_json("/submission_method")


class DataIslandManagerClient(CompositeManagerClient):
"""
Expand Down
30 changes: 30 additions & 0 deletions daliuge-common/dlg/common/deployment_methods.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#
# ICRAR - International Centre for Radio Astronomy Research
# (c) UWA - The University of Western Australia, 2015
# Copyright by UWA (in the framework of the ICRAR)
# All rights reserved
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307 USA
#

from enum import Enum


class DeploymentMethods(str, Enum):
SERVER = "SERVER",
BROWSER = "BROWSER",
HELM = "HELM",
OOD = "OOD"
40 changes: 40 additions & 0 deletions daliuge-common/dlg/common/k8s_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#
# ICRAR - International Centre for Radio Astronomy Research
# (c) UWA - The University of Western Australia, 2016
# Copyright by UWA (in the framework of the ICRAR)
# All rights reserved
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307 USA
#


import re
import subprocess


def check_k8s_env():
"""
Makes sure kubectl can be called and is accessible.
"""
try:
output = subprocess.run(
["kubectl version"], capture_output=True, shell=True
).stdout
output = output.decode(encoding="utf-8").replace("\n", "")
pattern = re.compile(r"^Client Version:.*Server Version:.*")
return re.match(pattern, output)
except subprocess.SubprocessError:
return False
4 changes: 4 additions & 0 deletions daliuge-common/dlg/common/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ def check_port(host, port, timeout=0, checking_open=True, return_socket=False):
)
return not checking_open

except socket.gaierror:
logger.debug("Endpoint service %s:%d not known", host, port)
return not checking_open

except socket.error as e:

# If the connection becomes suddenly closed from the server-side.
Expand Down
14 changes: 0 additions & 14 deletions daliuge-engine/dlg/deploy/deployment_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,20 +113,6 @@ def list_as_string(s):
return _parse_list_tokens(iter(_list_tokenizer(s)))


def check_k8s_env():
"""
Makes sure kubectl can be called and is accessible.
"""
try:
output = subprocess.run(
["kubectl version"], capture_output=True, shell=True
).stdout
pattern = re.compile(r"^Client Version:.*\nServer Version:.*")
return re.match(pattern, output.decode(encoding="utf-8"))
except subprocess.SubprocessError:
return False


def find_numislands(physical_graph_template_file):
"""
Given the physical graph data extract the graph name and the total number of
Expand Down
2 changes: 1 addition & 1 deletion daliuge-engine/dlg/deploy/helm_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@
find_service_ips,
find_pod_ips,
wait_for_pods,
check_k8s_env,
)
from dlg.dropmake import pg_generator
from dlg.restutils import RestClient
from dlg.common.k8s_utils import check_k8s_env

logger = logging.getLogger(__name__)

Expand Down
14 changes: 13 additions & 1 deletion daliuge-engine/dlg/manager/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import json
import logging
import os
import re
import tarfile
import threading

Expand All @@ -54,6 +55,7 @@
from ..restserver import RestServer
from ..restutils import RestClient, RestClientException
from .session import generateLogFileName
from dlg.common.deployment_methods import DeploymentMethods

logger = logging.getLogger(__name__)

Expand All @@ -75,9 +77,14 @@ def fwrapper(*args, **kwargs):
if res is not None:
bottle.response.content_type = "application/json"
# set CORS headers
origin = bottle.request.headers.raw("Origin")
if origin is None:
origin = "http://localhost:8084"
elif not re.match(r"http://((localhost)|(127.0.0.1)):80[0-9][0-9]", origin):
origin = "http://localhost:8084"
bottle.response.headers[
"Access-Control-Allow-Origin"
] = "http://localhost:8084"
] = origin
bottle.response.headers["Access-Control-Allow-Credentials"] = "true"
bottle.response.headers[
"Access-Control-Allow-Methods"
Expand Down Expand Up @@ -145,6 +152,7 @@ def __init__(self, dm, maxreqsize=10):

# Mappings
app = self.app
app.get("/api/submission_method", callback=self.submit_methods)
app.post("/api/stop", callback=self.stop_manager)
app.post("/api/sessions", callback=self.createSession)
app.get("/api/sessions", callback=self.getSessions)
Expand Down Expand Up @@ -187,6 +195,10 @@ def initializeSpecifics(self, app):
The default implementation does nothing.
"""

@daliuge_aware
def submit_methods(self):
return {"methods": [DeploymentMethods.BROWSER]}

def _stop_manager(self):
self.dm.shutdown()
self.stop()
Expand Down
2 changes: 1 addition & 1 deletion daliuge-engine/test/deploy/test_helm_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import unittest

import yaml
from dlg.deploy.deployment_utils import check_k8s_env
from dlg.common.k8s_utils import check_k8s_env

if check_k8s_env():
from dlg.common.version import version as dlg_version
Expand Down
6 changes: 6 additions & 0 deletions daliuge-engine/test/manager/test_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

from dlg import exceptions
from dlg.common import Categories
from dlg.common.deployment_methods import DeploymentMethods
from dlg.exceptions import InvalidGraphException

from dlg.manager import constants
Expand Down Expand Up @@ -268,3 +269,8 @@ def test_reprostatus_get(self):
response = c.session_repro_status(sid)
self.assertTrue(response)
c.destroySession(sid)

def test_submit_method(self):
c = NodeManagerClient(hostname)
response = c.get_submission_method()
self.assertEqual({"methods": [DeploymentMethods.BROWSER]}, response)
Loading

0 comments on commit 4ce5235

Please sign in to comment.