Skip to content

Commit

Permalink
Rest api (first version) (#2)
Browse files Browse the repository at this point in the history
* First version of OSCAR manager
  • Loading branch information
Alfonso Pérez authored Oct 1, 2018
1 parent 5353fc6 commit f5fbc20
Show file tree
Hide file tree
Showing 26 changed files with 1,911 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ test/*.zip
.p*
*.pyc
*.zip*
.settings/
*.log
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM python:3-alpine

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

COPY requirements.txt /usr/src/app/

RUN pip3 install --no-cache-dir -r requirements.txt

COPY . /usr/src/app

EXPOSE 8080

ENTRYPOINT ["python3"]

CMD ["-m", "swagger_server"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
- Deploy the cluster! Example with Amazon EC2:
```
./ec3 launch mycluster kubernetes_oscar ubuntu-ec2 -a auth.txt
```
```
Empty file added examples/imagemagick/README.md
Empty file.
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
connexion == 1.1.15
python_dateutil == 2.6.0
setuptools >= 21.0.0
35 changes: 35 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# coding: utf-8

import sys
from setuptools import setup, find_packages

NAME = "swagger_server"
VERSION = "1.0.0"

# To install the library, run the following
#
# python setup.py install
#
# prerequisite: setuptools
# http://pypi.python.org/pypi/setuptools

REQUIRES = ["connexion"]

setup(
name=NAME,
version=VERSION,
description="On-premises Serverless Container-aware ARchitectures API Gateway",
author_email="",
url="",
keywords=["Swagger", "On-premises Serverless Container-aware ARchitectures API Gateway"],
install_requires=REQUIRES,
packages=find_packages(),
package_data={'': ['swagger/swagger.yaml']},
include_package_data=True,
entry_points={
'console_scripts': ['swagger_server=__main__:main']},
long_description="""\
OSCAR API documentation
"""
)

18 changes: 18 additions & 0 deletions src/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# SCAR - Serverless Container-aware ARchitectures
# Copyright (C) 2011 - GRyCAP - Universitat Politecnica de Valencia
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.


__all__ = ['cmdtemplate','request','utils']
73 changes: 73 additions & 0 deletions src/cmdtemplate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# SCAR - Serverless Container-aware ARchitectures
# Copyright (C) 2011 - GRyCAP - Universitat Politecnica de Valencia
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import abc
from enum import Enum

class CallType(Enum):
INIT = "init"
INVOKE = "invoke"
RUN = "run"
UPDATE = "update"
LS = "ls"
RM = "rm"
LOG = "log"
PUT = "put"
GET = "get"

class Commands(metaclass=abc.ABCMeta):
''' All the different cloud provider controllers must inherit
from this class to ensure that the commands are defined consistently'''

@abc.abstractmethod
def init(self):
pass

@abc.abstractmethod
def invoke(self):
pass

@abc.abstractmethod
def run(self):
pass

@abc.abstractmethod
def update(self):
pass

@abc.abstractmethod
def ls(self):
pass

@abc.abstractmethod
def rm(self):
pass

@abc.abstractmethod
def log(self):
pass

@abc.abstractmethod
def put(self):
pass

@abc.abstractmethod
def get(self):
pass

@abc.abstractmethod
def parse_arguments(self, args):
pass
18 changes: 18 additions & 0 deletions src/providers/openfaas/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# SCAR - Serverless Container-aware ARchitectures
# Copyright (C) 2011 - GRyCAP - Universitat Politecnica de Valencia
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.


__all__ = ['controller']
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,3 @@ def launch_user_script():
os.makedirs(output_folder, exist_ok=True)
launch_user_script()
upload_output()


86 changes: 86 additions & 0 deletions src/providers/openfaas/controller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# SCAR - Serverless Container-aware ARchitectures
# Copyright (C) 2011 - GRyCAP - Universitat Politecnica de Valencia
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from src.cmdtemplate import Commands
import src.utils as utils
import requests
from flask import Response

def flask_response(func):
'''
Decorator used to create a flask Response
'''
def wrapper(*args, **kwargs):
r = func(*args, **kwargs)
kwargs = {'response' : r.content, 'status' : str(r.status_code), 'headers' : r.headers.items()}
return Response(**kwargs)
return wrapper

class OpenFaas(Commands):

functions_path = '/system/functions'
function_info = '/system/function/'
invoke_req_response_function = '/function/'
invoke_async_function = '/async-function/'
system_info = '/system/info'

def __init__(self):
self.endpoint = utils.get_environment_variable("OPENFAAS_URL")

@flask_response
def ls(self, function_name=None):
path = self.functions_path
if function_name:
path = self.function_info + function_name
return requests.get(self.endpoint + path)

@flask_response
def init(self, **kwargs):
print(kwargs)
path = self.functions_path
r = requests.post(self.endpoint + path, json=kwargs)
return r

@flask_response
def invoke(self, function_name, body, asynch=False):
path = self.invoke_req_response_function
if asynch:
path = self.invoke_async_function
return requests.post(self.endpoint + path + function_name, data=body)

def run(self):
pass

def update(self):
pass

@flask_response
def rm(self, function_name):
payload = { 'functionName' : function_name }
return requests.delete(self.endpoint + self.functions_path, json=payload)

def log(self):
pass

def put(self):
pass

def get(self):
pass

def parse_arguments(self, args):
pass

Loading

0 comments on commit f5fbc20

Please sign in to comment.