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

initial k8 support #779

Open
wants to merge 3 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
55 changes: 55 additions & 0 deletions python/phylanx/ast/clusters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# 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)

'''
see this documentation:

https://kubernetes.io/docs/tasks/administer-cluster/access-cluster-api/#accessing-the-cluster-api
https://kubernetes.io/docs/tasks/inject-data-application/define-environment-variable-container/
https://github.com/kubernetes-client/python/blob/master/examples/exec.py
'''

import requests
from base64 import b64encode

class cluster(object):
def __init_(self, args):
self.args = args

def send(self):
raise NotImplementedError("cluster::send not implemented.")

class k8cluster(cluster):
def __init__(self, args):
cluster.__init__(self, args)

@overrides(cluster)
def sends(self, physl_ir_str):
if 'jobconfig' not in self.args:
raise Error("k8cluster jobconfig not defined.")
if 'url' not in self.args:
raise Error("k8cluster url not defined.")

env_ir = [ {'name' : 'PHYSL_IR', 'value' : b64encode(physl_ir_str) } ]

if 'env' not in self.args['jobconfig']['spec']['containers']:
self.args['jobconfig']['spec']['containers']['env'] = list()

self.args['jobconfig']['spec']['containers']['env'].append(env_ir)

resp = requests.post(url=self.args['url'], args=self.args['jobconfig'])
return resp.json()

def create_cluster(args):
if 'type' not in args:
raise Error("create_cluster type not defined.")

cluster_type = args['type']

if 'jobconfig' not in args:
raise Error("create_cluster jobconfig not defined.")

if cluster_type == 'k8' or cluster_type == 'kubernetes':
return k8cluster(args['jobconfig'])
15 changes: 11 additions & 4 deletions python/phylanx/ast/transducer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
from phylanx import execution_tree
from phylanx.ast import generate_ast as generate_phylanx_ast
from phylanx.exceptions import InvalidDecoratorArgumentError

from phylanx.clusters import create_cluster

def Phylanx(__phylanx_arg=None, **kwargs):
class __PhylanxDecorator(object):
def __init__(self, f):
"""
:function:f the decorated funtion.
"""
valid_kwargs = ['debug', 'target', 'compiler_state', 'performance']
valid_kwargs = ['debug', 'target', 'compiler_state', 'performance', 'cluster']

self.backends_map = {'PhySL': PhySL, 'OpenSCoP': OpenSCoP}
self.backend = self.get_backend(kwargs.get('target'))
Expand All @@ -36,6 +36,12 @@ def __init__(self, f):
else:
kwargs['fglobals'] = f.__globals__

# determine if code is sent to a remote cluster
#
self.remote = None
if 'cluster' in kwargs.keys():
self.remote = create_cluster(kwargs['cluster'])

python_src = self.get_python_src(f)
python_ast = self.get_python_ast(python_src, f)

Expand Down Expand Up @@ -79,10 +85,11 @@ def __call__(self, *args):
raise NotImplementedError(
"OpenSCoP kernels are not yet callable.")

result = self.backend.call(args)
if self.remote is not None or self.remote != None:
return self.remote.send(self.__src__)

result = self.backend.call(args)
self.__perfdata__ = self.backend.__perfdata__

return result

def generate_ast(self):
Expand Down