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

K8 update #972

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
108 changes: 108 additions & 0 deletions python/phylanx/ast/deploy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# Copyright (c) 2019 Christopher Taylor
#
# Distributed under the Boost Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

# uses this library: https://github.com/kubernetes-client/python
#
import kubernetes.client
from kubernetes.client import Configuration
from kubernetes.client.apis import core_v1_api
from kubernetes.client.rest import ApiException

# uses this library: https://github.com/litl/backoff
#
import backoff


class deployer(object):
'''
data structure to manage posting physl code
deployments
'''
def __init__(self, physl_str):
self.physl = physl_str

def __call__(self):
pass


class deployedresult(object):
'''
data structure to manage posting physl code
deployments
'''
def __init__(self):
pass

def get(self):
pass


class kubernetes_deployer_result(deployedresult):
'''
data structure to manage getting result of
physl code deployed to a kubernetes cluster
'''
def __init__(self, kubernetes_pod_deploy_response,
kubernetes_config, log_path):
deployedresult.__init__(self)
self.kpod_response = kubernetes_pod_deploy_response
self.kpod_config = kubernetes_config
self.success = False
self.log_path = log_path

if self.kpod_response is not None:
self.success = True

def get(self):
api_instance = kubernetes.client.LogsApi(
kubernetes.client.ApiClient(self.kpod_config))

thread = None
try:
thread = api_instance.log_file_handler_with_http_info(self.logpath)
except ApiException as e:
print("Exception when calling LogsApi->log_file_handler: %s\n" % e)

if thread is not None:
return thread.get()

return None


class kubernetes_deployer(deployer):
'''
data structure to manage posting physl code
to a kubernetes cluster
'''
def __init__(self, physl_str, pod_manifest,
kubernetes_config, base=10, cap=300):
deployer.__init__(self, physl_str)
self.manifest = pod_manifest
self.kpod_config = kubernetes_config
self.name = pod_manifest['metadata']['name']
self.base = base
self.cap = cap

@backoff.on_predicate(backoff.expo, lambda x: x.status.phase != 'Pending')
def post_pod_loop(self):
'''
posts using exponential backoff
'''
return self.api.read_namespaced_pod(
name=self.name, namespace='default')

def __call__(self):
Configuration.set_default(self.kpod_config)
self.api = core_v1_api.CoreV1Api()

resp = None
try:
resp = self.post_pod_loop()
except ApiException as e:
if e.status != 404:
print('unknown error: %s' % (str(e),))
return None

return kubernetes_deployer_result(resp)
7 changes: 6 additions & 1 deletion python/phylanx/ast/physl.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import numpy as np
import phylanx.execution_tree
from phylanx import PhylanxSession
from phylanx.ast.deploy import deployer


def physl_zip(loop):
Expand Down Expand Up @@ -532,7 +533,11 @@ def lazy(self, args=()):
def call(self, args=()):
"""Invoke this Phylanx function, pass along the given arguments"""

return self.lazy(args).eval()
if 'deploy' not in self.kwargs:
return self.lazy(args).eval()

deployer = self.kwargs['deploy']
return deployer(args)

# #############################################################################
# Transducer rules
Expand Down
2 changes: 0 additions & 2 deletions python/phylanx/ast/transducer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from phylanx.ast import generate_ast as generate_phylanx_ast
from phylanx.exceptions import InvalidDecoratorArgumentError


class LambdaExtractor(ast.NodeVisitor):
_ast = None

Expand Down Expand Up @@ -145,7 +144,6 @@ def __call__(self, *args):
result = self.backend.call(map(self.map_decorated, args))

self.__perfdata__ = self.backend.__perfdata__

return result

def generate_ast(self):
Expand Down