diff --git a/frameworks/Python/api_hour/README.md b/frameworks/Python/api_hour/README.md deleted file mode 100644 index 72f27c13f80..00000000000 --- a/frameworks/Python/api_hour/README.md +++ /dev/null @@ -1,30 +0,0 @@ -# AsyncIO/aiohttp/API-Hour Benchmark Test - -This is the AsyncIO/aiohttp/API-Hour portion of a [benchmarking tests suite](../../) -comparing a variety of web development platforms. - -The information below is specific to AsyncIO/API-Hour. For further guidance, -review the [documentation](https://github.com/TechEmpower/FrameworkBenchmarks/wiki). -Also note that there is additional information provided in -the [Python README](../). - -## Test Paths & Sources - -* [JSON Serialization](aiohttp.web/hello/endpoints/world.py): "/json" -* [Single Database Query](aiohttp.web/hello/services/world.py): "/db" -* [Multiple Database Queries](aiohttp.web/hello/services/world.py): "/queries?queries=#"* -* [Fortunes](aiohttp.web/hello/services/world.py): "/fortunes" -* [Database Updates](aiohttp.web/hello/services/world.py): "/updates?queries=#"* -* [Plaintext](aiohttp.web/hello/endpoints/world.py): "/plaintext" - -*Replace # with an actual number. - -## Get Help - -### Community - -* [API-Hour Google Group](https://groups.google.com/forum/#!forum/api-hour) - -### Resources - -* [API-Hour Source Code](https://github.com/Eyepea/API-Hour) diff --git a/frameworks/Python/api_hour/aiohttp.web/LICENSE b/frameworks/Python/api_hour/aiohttp.web/LICENSE deleted file mode 100644 index 41a9656a9c6..00000000000 --- a/frameworks/Python/api_hour/aiohttp.web/LICENSE +++ /dev/null @@ -1,13 +0,0 @@ -Copyright [2015] [Eyepea Dev Team] - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. \ No newline at end of file diff --git a/frameworks/Python/api_hour/aiohttp.web/etc/hello/api_hour/gunicorn_conf.py b/frameworks/Python/api_hour/aiohttp.web/etc/hello/api_hour/gunicorn_conf.py deleted file mode 100644 index 64767c70cc8..00000000000 --- a/frameworks/Python/api_hour/aiohttp.web/etc/hello/api_hour/gunicorn_conf.py +++ /dev/null @@ -1,15 +0,0 @@ -import multiprocessing -import os - -_is_travis = os.environ.get('TRAVIS') == 'true' - -workers = multiprocessing.cpu_count() -if _is_travis: - workers = 2 - -bind = ['0.0.0.0:8080'] -keepalive = 120 -errorlog = '-' -pidfile = '/tmp/api_hour.pid' -pythonpath = 'hello' -backlog = 10240000 diff --git a/frameworks/Python/api_hour/aiohttp.web/etc/hello/api_hour/logging.ini b/frameworks/Python/api_hour/aiohttp.web/etc/hello/api_hour/logging.ini deleted file mode 100644 index 581435cbd23..00000000000 --- a/frameworks/Python/api_hour/aiohttp.web/etc/hello/api_hour/logging.ini +++ /dev/null @@ -1,71 +0,0 @@ -[formatters] -keys=detailed,simple - -[handlers] -keys=console,syslog,smtp - -[loggers] -keys=root,warnings,asyncio,gunicorn,aiohttp,api_hour,hello - -[formatter_simple] -format=%(name)s:%(levelname)s %(asctime)s %(module)s.py => %(message)s - -[formatter_detailed] -format=%(name)s:%(levelname)s %(asctime)s %(module)s.py:%(lineno)d => %(message)s - -[handler_console] -class=StreamHandler -args=(sys.stdout,) -formatter=detailed - -[handler_syslog] -class=handlers.SysLogHandler -args=('/dev/log', handlers.SysLogHandler.LOG_LOCAL6) -formatter=detailed - -[handler_smtp] -class=handlers.SMTPHandler -level=WARN -args=('127.0.0.1', 'gmludo@gmail.com', ['gmludo@gmail.com'], 'hello error on server: hello') -formatter=detailed - -[logger_root] -level=ERROR -handlers=console - -# You can add smtp in handlers list to receive e-mail alerts -[logger_warnings] -level=WARN -handlers=console -qualname=py.warnings -propagate=0 - -[logger_asyncio] -level=WARN -handlers=console -qualname=asyncio -propagate=0 - -[logger_gunicorn] -level=WARN -handlers=console -qualname=gunicorn -propagate=0 - -[logger_aiohttp] -level=WARN -handlers=console -qualname=aiohttp -propagate=0 - -[logger_api_hour] -level=WARN -handlers=console -qualname=api_hour -propagate=0 - -[logger_hello] -level=WARN -handlers=console -qualname=hello -propagate=0 diff --git a/frameworks/Python/api_hour/aiohttp.web/etc/hello/main/main.yaml b/frameworks/Python/api_hour/aiohttp.web/etc/hello/main/main.yaml deleted file mode 100644 index da8536c0c00..00000000000 --- a/frameworks/Python/api_hour/aiohttp.web/etc/hello/main/main.yaml +++ /dev/null @@ -1,22 +0,0 @@ ---- -engines: - pg: - host: tfb-database - port: 5432 - dbname: hello_world - user: benchmarkdbuser - password: benchmarkdbpass - minsize: 22 - maxsize: 22 - mysql: - host: tfb-database - port: 3306 - db: hello_world - user: benchmarkdbuser - pwd: benchmarkdbpass - minsize: 22 - maxsize: 22 -#redis: -# host: tfb-database -# port: 6379 -# poolsize: 40 diff --git a/frameworks/Python/api_hour/aiohttp.web/etc/init.d/hello b/frameworks/Python/api_hour/aiohttp.web/etc/init.d/hello deleted file mode 100755 index 6b5eea7fcee..00000000000 --- a/frameworks/Python/api_hour/aiohttp.web/etc/init.d/hello +++ /dev/null @@ -1,79 +0,0 @@ -#!/bin/sh -# -### BEGIN INIT INFO -# Provides: hello -# Required-Start: $local_fs $remote_fs $network $syslog -# Required-Stop: $local_fs $remote_fs $network $syslog -# Default-Start: 2 3 4 5 -# Default-Stop: 0 1 6 -# Short-Description: Startup daemon script for hello -### END INIT INFO -# -# Author: Ludovic Gasc -set -e - -PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin -DAEMONNAME=hello -RUNDIR=/run/$DAEMONNAME -DAEMON=/opt/hello/${DAEMONNAME}_cli -PIDFILE=/run/lock/${DAEMONNAME}_0 -DAEMON_ARGS="" - -# Exit if the package is not installed -[ -x "$DAEMON" ] || exit 0 - -# Create RUNDIR if it doesn't exist -[ -d "$RUNDIR" ] || mkdir -p "$RUNDIR" - -# Read configuration variable file if it is present -[ -r /etc/default/$NAME ] && . /etc/default/$NAME - -# Load the VERBOSE setting and other rcS variables -[ -f /etc/default/rcS ] && . /etc/default/rcS - -# Define LSB log_* functions. -# Depend on lsb-base (>= 3.0-6) to ensure that this file is present. -. /lib/lsb/init-functions - -case "$1" in - start) - log_daemon_msg "Starting" "$DAEMONNAME" - if start-stop-daemon -b --start --pidfile $PIDFILE --startas $DAEMON -- $DAEMON_ARGS; - then - log_end_msg 0 - else - log_end_msg 1 - fi - ;; - stop) - log_daemon_msg "Stopping" "$DAEMONNAME" - if start-stop-daemon --stop --retry 5 --pidfile $PIDFILE; - then - log_end_msg 0 - else - log_end_msg 1 - fi - ;; - reload|force-reload) - log_daemon_msg "Reloading" "$DAEMONNAME" - if start-stop-daemon --stop --signal 1 --pidfile $PIDFILE --startas $DAEMON; - then - log_end_msg 0 - else - log_end_msg 1 - fi - ;; - restart) - $0 stop - $0 start - ;; - status) - status_of_proc -p $PIDFILE "$DAEMON" $DAEMONNAME && exit 0 || exit $? - ;; - *) - echo "Usage: $0 {start|stop|reload|force-reload|restart|status}" - exit 1 - ;; -esac - -exit 0 diff --git a/frameworks/Python/api_hour/aiohttp.web/etc/rsyslog.conf b/frameworks/Python/api_hour/aiohttp.web/etc/rsyslog.conf deleted file mode 100644 index 10798d600eb..00000000000 --- a/frameworks/Python/api_hour/aiohttp.web/etc/rsyslog.conf +++ /dev/null @@ -1,126 +0,0 @@ -# /etc/rsyslog.conf Configuration file for rsyslog. -# -# For more information see -# /usr/share/doc/rsyslog-doc/html/rsyslog_conf.html - - -################# -#### MODULES #### -################# - -$ModLoad imuxsock # provides support for local system logging -$ModLoad imklog # provides kernel logging support -#$ModLoad immark # provides --MARK-- message capability -$SystemLogRateLimitInterval 1 -$SystemLogRateLimitBurst 1000 - -# provides UDP syslog reception -#$ModLoad imudp -#$UDPServerRun 514 - -# provides TCP syslog reception -#$ModLoad imtcp -#$InputTCPServerRun 514 - - -########################### -#### GLOBAL DIRECTIVES #### -########################### - -# -# Use traditional timestamp format. -# To enable high precision timestamps, comment out the following line. -# -$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat - -# -# Set the default permissions for all log files. -# -$FileOwner root -$FileGroup adm -$FileCreateMode 0640 -$DirCreateMode 0755 -$Umask 0022 - -# -# Where to place spool and state files -# -$WorkDirectory /var/spool/rsyslog - -# -# Include all config files in /etc/rsyslog.d/ -# -$IncludeConfig /etc/rsyslog.d/*.conf - - -############### -#### RULES #### -############### - -# -# First some standard log files. Log by facility. -# -auth,authpriv.* /var/log/auth.log -*.*;auth,authpriv.none;\ - local6.none -/var/log/syslog -#cron.* /var/log/cron.log -daemon.* -/var/log/daemon.log -kern.* -/var/log/kern.log -lpr.* -/var/log/lpr.log -mail.* -/var/log/mail.log -user.* -/var/log/user.log - -local6.* /var/log/hello/hello.log - -# -# Logging for the mail system. Split it up so that -# it is easy to write scripts to parse these files. -# -mail.info -/var/log/mail.info -mail.warn -/var/log/mail.warn -mail.err /var/log/mail.err - -# -# Logging for INN news system. -# -news.crit /var/log/news/news.crit -news.err /var/log/news/news.err -news.notice -/var/log/news/news.notice - -# -# Some "catch-all" log files. -# -*.=debug;\ - auth,authpriv.none;\ - news.none;mail.none;local7.none -/var/log/debug -*.=info;*.=notice;*.=warn;\ - auth,authpriv.none;\ - cron,daemon.none;\ - mail,news.none;local7.none -/var/log/messages - -# -# Emergencies are sent to everybody logged in. -# -*.emerg :omusrmsg:* - -# -# I like to have messages displayed on the console, but only on a virtual -# console I usually leave idle. -# -#daemon,mail.*;\ -# news.=crit;news.=err;news.=notice;\ -# *.=debug;*.=info;\ -# *.=notice;*.=warn /dev/tty8 - -# The named pipe /dev/xconsole is for the `xconsole' utility. To use it, -# you must invoke `xconsole' with the `-file' option: -# -# $ xconsole -file /dev/xconsole [...] -# -# NOTE: adjust the list below, or you'll go crazy if you have a reasonably -# busy site.. -# -daemon.*;mail.*;\ - news.err;\ - *.=debug;*.=info;\ - *.=notice;*.=warn |/dev/xconsole diff --git a/frameworks/Python/api_hour/aiohttp.web/hello/__init__.py b/frameworks/Python/api_hour/aiohttp.web/hello/__init__.py deleted file mode 100644 index d42936daa86..00000000000 --- a/frameworks/Python/api_hour/aiohttp.web/hello/__init__.py +++ /dev/null @@ -1,94 +0,0 @@ -import logging -import asyncio -import os - -import aiopg -import jinja2 -import psycopg2.extras -import aiohttp.web -import aiohttp_jinja2 -import aiomysql -import api_hour - -from . import endpoints - -LOG = logging.getLogger(__name__) - - -class Container(api_hour.Container): - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - # Servers - self.servers['http'] = aiohttp.web.Application(loop=kwargs['loop']) - aiohttp_jinja2.setup(self.servers['http'], loader=jinja2.PackageLoader('hello')) - self.servers['http'].ah_container = self # keep a reference to Container - # routes - self.servers['http'].router.add_route('GET', '/json', endpoints.world.json) - self.servers['http'].router.add_route('GET', '/db', endpoints.world.db) - self.servers['http'].router.add_route('GET', '/db_mysql', endpoints.world.db_mysql) - self.servers['http'].router.add_route('GET', '/queries', endpoints.world.queries) - self.servers['http'].router.add_route('GET', '/queries_mysql', endpoints.world.queries_mysql) - self.servers['http'].router.add_route('GET', '/fortunes', endpoints.world.fortunes) - self.servers['http'].router.add_route('GET', '/fortunes_mysql', endpoints.world.fortunes_mysql) - self.servers['http'].router.add_route('GET', '/updates', endpoints.world.updates) - self.servers['http'].router.add_route('GET', '/updates_mysql', endpoints.world.updates_mysql) - self.servers['http'].router.add_route('GET', '/plaintext', endpoints.world.plaintext) - - def make_servers(self): - return [self.servers['http'].make_handler(logger=self.worker.log, - debug=False, - keep_alive=0, - access_log=None, - access_log_format=self.worker.cfg.access_log_format)] - - @asyncio.coroutine - def start(self): - yield from super().start() - LOG.info('Starting engines...') - print('Starting engines...') - self.engines['pg'] = self.loop.create_task(aiopg.create_pool(host='tfb-database', - port=int(self.config['engines']['pg']['port']), - sslmode='disable', - dbname=self.config['engines']['pg']['dbname'], - user=self.config['engines']['pg']['user'], - password=self.config['engines']['pg']['password'], - cursor_factory=psycopg2.extras.RealDictCursor, - minsize=int(self.config['engines']['pg']['minsize']), - maxsize=int(self.config['engines']['pg']['maxsize']), - loop=self.loop)) - self.engines['mysql'] = self.loop.create_task(aiomysql.create_pool( - host=self.config['engines']['mysql']['host'], - port=self.config['engines']['mysql']['port'], - user=self.config['engines']['mysql']['user'], - password=self.config['engines']['mysql']['pwd'], - db=self.config['engines']['mysql']['db'], - minsize=int(self.config['engines']['mysql']['minsize']), - maxsize=int(self.config['engines']['mysql']['maxsize']), - cursorclass=aiomysql.DictCursor, - charset='utf8', - use_unicode=True, - loop=self.loop)) - yield from asyncio.wait([self.engines['pg']], return_when=asyncio.ALL_COMPLETED) - - LOG.info('All engines ready !') - - @asyncio.coroutine - def stop(self): - LOG.info('Stopping engines...') - if 'pg' in self.engines: - if self.engines['pg'].done(): - self.engines['pg'].result().terminate() - yield from self.engines['pg'].result().wait_closed() - else: - yield from self.engines['pg'].cancel() - if 'mysql' in self.engines: - if self.engines['mysql'].done(): - self.engines['mysql'].result().close() - yield from self.engines['mysql'].result().wait_closed() - else: - yield from self.engines['mysql'].cancel() - if 'redis' in self.engines: - self.engines['redis'].close() - yield from asyncio.sleep(1) # wait redis close connection - LOG.info('All engines stopped !') - yield from super().stop() \ No newline at end of file diff --git a/frameworks/Python/api_hour/aiohttp.web/hello/endpoints/__init__.py b/frameworks/Python/api_hour/aiohttp.web/hello/endpoints/__init__.py deleted file mode 100644 index 72e85908a10..00000000000 --- a/frameworks/Python/api_hour/aiohttp.web/hello/endpoints/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from . import world \ No newline at end of file diff --git a/frameworks/Python/api_hour/aiohttp.web/hello/endpoints/world.py b/frameworks/Python/api_hour/aiohttp.web/hello/endpoints/world.py deleted file mode 100644 index 331e741041e..00000000000 --- a/frameworks/Python/api_hour/aiohttp.web/hello/endpoints/world.py +++ /dev/null @@ -1,86 +0,0 @@ -import logging -import asyncio - -from aiohttp.web import Response -from api_hour.plugins.aiohttp import JSON -import aiohttp_jinja2 - -from ..services import queries_number -from ..services.world import get_random_record, get_random_records, update_random_records, get_fortunes -from ..services import mysql - -LOG = logging.getLogger(__name__) - -@asyncio.coroutine -def json(request): - """Test type 1: JSON serialization""" - return JSON({'message': 'Hello, World!'}) - -@asyncio.coroutine -def db(request): - """Test type 2: Single database query""" - container = request.app.ah_container - - return JSON((yield from get_random_record(container))) - -@asyncio.coroutine -def db_mysql(request): - """Test type 2: Single database query""" - container = request.app.ah_container - - return JSON((yield from mysql.get_random_record(container))) - -@asyncio.coroutine -def queries(request): - """Test type 3: Multiple database queries""" - container = request.app.ah_container - limit = queries_number(request.GET.get('queries', 1)) - - return JSON((yield from get_random_records(container, limit))) - -@asyncio.coroutine -def queries_mysql(request): - """Test type 3: Multiple database queries""" - container = request.app.ah_container - limit = queries_number(request.GET.get('queries', 1)) - - return JSON((yield from mysql.get_random_records(container, limit))) - -@asyncio.coroutine -def fortunes(request): - """Test type 4: Fortunes""" - container = request.app.ah_container - - return aiohttp_jinja2.render_template('fortunes.html.j2', - request, - {'fortunes': (yield from get_fortunes(container))}) - -@asyncio.coroutine -def fortunes_mysql(request): - """Test type 4: Fortunes""" - container = request.app.ah_container - - return aiohttp_jinja2.render_template('fortunes.html.j2', - request, - {'fortunes': (yield from mysql.get_fortunes(container))}) - -@asyncio.coroutine -def updates(request): - """Test type 5: Database updates""" - container = request.app.ah_container - limit = queries_number(request.GET.get('queries', 1)) - - return JSON((yield from update_random_records(container, limit))) - -@asyncio.coroutine -def updates_mysql(request): - """Test type 5: Database updates""" - container = request.app.ah_container - limit = queries_number(request.GET.get('queries', 1)) - - return JSON((yield from mysql.update_random_records(container, limit))) - -@asyncio.coroutine -def plaintext(request): - """Test type 6: Plaintext""" - return Response(text='Hello, World!') \ No newline at end of file diff --git a/frameworks/Python/api_hour/aiohttp.web/hello/services/__init__.py b/frameworks/Python/api_hour/aiohttp.web/hello/services/__init__.py deleted file mode 100644 index 9a1e89c1df7..00000000000 --- a/frameworks/Python/api_hour/aiohttp.web/hello/services/__init__.py +++ /dev/null @@ -1,14 +0,0 @@ -from . import world - -# get from Django hello application -def queries_number(number): - try: - queries = int(number) - except Exception: - queries = 1 - if queries < 1: - queries = 1 - if queries > 500: - queries = 500 - return queries - diff --git a/frameworks/Python/api_hour/aiohttp.web/hello/services/mysql.py b/frameworks/Python/api_hour/aiohttp.web/hello/services/mysql.py deleted file mode 100644 index a681a73a49b..00000000000 --- a/frameworks/Python/api_hour/aiohttp.web/hello/services/mysql.py +++ /dev/null @@ -1,58 +0,0 @@ -import asyncio -from random import randint -from operator import itemgetter - - -@asyncio.coroutine -def get_random_record(container): - with (yield from container.engines['mysql'].result()) as mysql_conn: - cur = yield from mysql_conn.cursor() - yield from cur.execute('SELECT id AS "Id", randomnumber AS "RandomNumber" FROM world WHERE id=%(idx)s LIMIT 1', - {'idx': randint(1, 10000)}) - world = yield from cur.fetchone() - return world - - -@asyncio.coroutine -def get_random_records(container, limit): - results = [] - with (yield from container.engines['mysql'].result()) as mysql_conn: - cur = yield from mysql_conn.cursor() - for i in range(limit): - yield from cur.execute('SELECT id AS "Id", randomnumber AS "RandomNumber" FROM world WHERE id=%(idx)s LIMIT 1', - {'idx': randint(1, 10000)}) - results.append((yield from cur.fetchone())) - - return results - - -@asyncio.coroutine -def update_random_records(container, limit): - results = [] - - with (yield from container.engines['mysql'].result()) as mysql_conn: - cur = yield from mysql_conn.cursor() - for i in range(limit): - yield from cur.execute('SELECT id AS "Id", randomnumber AS "RandomNumber" FROM world WHERE id=%(idx)s LIMIT 1', - {'idx': randint(1, 10000)}) - world = yield from cur.fetchone() - world['RandomNumber'] = randint(1, 10000) - yield from cur.execute('UPDATE world SET randomnumber=%(random_number)s WHERE id=%(idx)s', - {'random_number': world['RandomNumber'], 'idx': world['Id']}) - yield from mysql_conn.commit() - results.append(world) - return results - - -@asyncio.coroutine -def get_fortunes(container): - with (yield from container.engines['mysql'].result()) as mysql_conn: - cur = yield from mysql_conn.cursor() - yield from cur.execute('SELECT * FROM fortune') - fortunes = yield from cur.fetchall() - - fortunes.append({'id': 0, 'message': 'Additional fortune added at request time.'}) - - fortunes.sort(key=itemgetter('message')) - - return fortunes diff --git a/frameworks/Python/api_hour/aiohttp.web/hello/services/world.py b/frameworks/Python/api_hour/aiohttp.web/hello/services/world.py deleted file mode 100644 index bce4a5f5dc9..00000000000 --- a/frameworks/Python/api_hour/aiohttp.web/hello/services/world.py +++ /dev/null @@ -1,55 +0,0 @@ -import asyncio -import sys -from random import randint -from operator import itemgetter - -@asyncio.coroutine -def get_random_record(container): - pg = yield from container.engines['pg'] - - with (yield from pg.cursor()) as cur: - yield from cur.execute('SELECT id AS "Id", randomnumber AS "RandomNumber" FROM world WHERE id=%(idx)s LIMIT 1', - {'idx': randint(1, 10000)}) - world = yield from cur.fetchone() - return world - -@asyncio.coroutine -def get_random_records(container, limit): - pg = yield from container.engines['pg'] - results = [] - with (yield from pg.cursor()) as cur: - for i in range(limit): - yield from cur.execute('SELECT id AS "Id", randomnumber AS "RandomNumber" FROM world WHERE id=%(idx)s LIMIT 1', - {'idx': randint(1, 10000)}) - results.append((yield from cur.fetchone())) - - return results - -@asyncio.coroutine -def update_random_records(container, limit): - results = [] - pg = yield from container.engines['pg'] - with (yield from pg.cursor()) as cur: - for i in range(limit): - yield from cur.execute('SELECT id AS "Id", randomnumber AS "RandomNumber" FROM world WHERE id=%(idx)s LIMIT 1', - {'idx': randint(1, 10000)}) - world = yield from cur.fetchone() - world['RandomNumber'] = randint(1, 10000) - yield from cur.execute('UPDATE world SET randomnumber=%(random_number)s WHERE id=%(idx)s', - {'random_number': world['RandomNumber'], 'idx': world['Id']}) - results.append(world) - return results - -@asyncio.coroutine -def get_fortunes(container): - pg = yield from container.engines['pg'] - - with (yield from pg.cursor()) as cur: - yield from cur.execute('SELECT * FROM fortune') - fortunes = yield from cur.fetchall() - - fortunes.append({'id': 0, 'message': 'Additional fortune added at request time.'}) - - fortunes.sort(key=itemgetter('message')) - - return fortunes diff --git a/frameworks/Python/api_hour/aiohttp.web/hello/templates/fortunes.html.j2 b/frameworks/Python/api_hour/aiohttp.web/hello/templates/fortunes.html.j2 deleted file mode 100644 index f402560b250..00000000000 --- a/frameworks/Python/api_hour/aiohttp.web/hello/templates/fortunes.html.j2 +++ /dev/null @@ -1,20 +0,0 @@ - - - - Fortunes - - - - - - - - {% for fortune in fortunes %} - - - - - {% endfor %} -
idmessage
{{ fortune['id']|e }}{{ fortune['message']|e }}
- - \ No newline at end of file diff --git a/frameworks/Python/api_hour/aiohttp.web/hello/utils/__init__.py b/frameworks/Python/api_hour/aiohttp.web/hello/utils/__init__.py deleted file mode 100644 index f686a6b20d7..00000000000 --- a/frameworks/Python/api_hour/aiohttp.web/hello/utils/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -import logging - -LOG = logging.getLogger(__name__) \ No newline at end of file diff --git a/frameworks/Python/api_hour/api_hour-dbs.dockerfile b/frameworks/Python/api_hour/api_hour-dbs.dockerfile deleted file mode 100644 index 82b79cd47c9..00000000000 --- a/frameworks/Python/api_hour/api_hour-dbs.dockerfile +++ /dev/null @@ -1,14 +0,0 @@ -FROM python:3.6.6-stretch - -ADD ./yocto_http /yocto_http -ADD ./requirements.txt /yocto_http - -WORKDIR /yocto_http - -RUN pip3 install -r /yocto_http/requirements.txt - -WORKDIR /yocto_http - -EXPOSE 8081 - -CMD api_hour -ac hello:Container diff --git a/frameworks/Python/api_hour/api_hour-json.dockerfile b/frameworks/Python/api_hour/api_hour-json.dockerfile deleted file mode 100644 index 94154c18e38..00000000000 --- a/frameworks/Python/api_hour/api_hour-json.dockerfile +++ /dev/null @@ -1,14 +0,0 @@ -FROM python:3.6.6-stretch - -ADD ./yocto_http /yocto_http -ADD ./requirements.txt /yocto_http - -WORKDIR /yocto_http - -RUN pip3 install -r /yocto_http/requirements.txt - -WORKDIR /yocto_http - -EXPOSE 8080 - -CMD api_hour -ac hello:Container diff --git a/frameworks/Python/api_hour/api_hour-mysql.dockerfile b/frameworks/Python/api_hour/api_hour-mysql.dockerfile deleted file mode 100644 index 4fe26f2aaab..00000000000 --- a/frameworks/Python/api_hour/api_hour-mysql.dockerfile +++ /dev/null @@ -1,14 +0,0 @@ -FROM python:3.6.6-stretch - -ADD ./aiohttp.web /aiohttp.web -ADD ./requirements.txt /aiohttp.web - -WORKDIR /aiohttp.web - -RUN pip3 install -r /aiohttp.web/requirements.txt - -WORKDIR /aiohttp.web - -EXPOSE 8080 - -CMD api_hour -ac hello:Container diff --git a/frameworks/Python/api_hour/api_hour-plaintext.dockerfile b/frameworks/Python/api_hour/api_hour-plaintext.dockerfile deleted file mode 100644 index c9515178939..00000000000 --- a/frameworks/Python/api_hour/api_hour-plaintext.dockerfile +++ /dev/null @@ -1,14 +0,0 @@ -FROM python:3.6.6-stretch - -ADD ./yocto_http /yocto_http -ADD ./requirements.txt /yocto_http - -WORKDIR /yocto_http - -RUN pip3 install -r /yocto_http/requirements.txt - -WORKDIR /yocto_http - -EXPOSE 8082 - -CMD api_hour -ac hello:Container diff --git a/frameworks/Python/api_hour/api_hour.dockerfile b/frameworks/Python/api_hour/api_hour.dockerfile deleted file mode 100644 index 4fe26f2aaab..00000000000 --- a/frameworks/Python/api_hour/api_hour.dockerfile +++ /dev/null @@ -1,14 +0,0 @@ -FROM python:3.6.6-stretch - -ADD ./aiohttp.web /aiohttp.web -ADD ./requirements.txt /aiohttp.web - -WORKDIR /aiohttp.web - -RUN pip3 install -r /aiohttp.web/requirements.txt - -WORKDIR /aiohttp.web - -EXPOSE 8080 - -CMD api_hour -ac hello:Container diff --git a/frameworks/Python/api_hour/benchmark_config.json b/frameworks/Python/api_hour/benchmark_config.json deleted file mode 100644 index eb5cb9970b4..00000000000 --- a/frameworks/Python/api_hour/benchmark_config.json +++ /dev/null @@ -1,105 +0,0 @@ -{ - "framework": "api_hour", - "tests": [{ - "default": { - "json_url": "/json", - "db_url": "/db", - "query_url": "/queries?queries=", - "fortune_url": "/fortunes", - "update_url": "/updates?queries=", - "plaintext_url": "/plaintext", - "port": 8080, - "approach": "Realistic", - "classification": "Micro", - "database": "Postgres", - "framework": "api_hour", - "language": "Python", - "flavor": "Python3", - "orm": "Raw", - "platform": "asyncio", - "webserver": "Gunicorn", - "os": "Linux", - "database_os": "Linux", - "display_name": "API-Hour-PG", - "notes": "Python 3 + API-Hour + AsyncIO + aiohttp + PostgreSQL", - "tags": ["broken"] - }, - "mysql": { - "db_url": "/db_mysql", - "query_url": "/queries_mysql?queries=", - "fortune_url": "/fortunes_mysql", - "update_url": "/updates_mysql?queries=", - "port": 8080, - "approach": "Realistic", - "classification": "Micro", - "database": "MySQL", - "framework": "api_hour", - "language": "Python", - "flavor": "Python3", - "orm": "Raw", - "platform": "asyncio", - "webserver": "Gunicorn", - "os": "Linux", - "database_os": "Linux", - "display_name": "API-Hour-MySQL", - "notes": "Python 3 + API-Hour + AsyncIO + aiohttp + MySQL", - "tags": ["broken"] - }, - "json": { - "json_url": "/json", - "port": 8080, - "approach": "Stripped", - "classification": "Platform", - "database": "None", - "framework": "api_hour", - "language": "Python", - "flavor": "Python3", - "orm": "Raw", - "platform": "asyncio", - "webserver": "Gunicorn", - "os": "Linux", - "database_os": "Linux", - "display_name": "API-Hour-yocto", - "notes": "Python 3 + API-Hour + AsyncIO", - "tags": ["broken"] - }, - "dbs": { - "db_url": "/db", - "query_url": "/queries?queries=", - "update_url": "/updates?queries=", - "port": 8081, - "approach": "Stripped", - "classification": "Platform", - "database": "Postgres", - "framework": "api_hour", - "language": "Python", - "flavor": "Python3", - "orm": "Raw", - "platform": "asyncio", - "webserver": "Gunicorn", - "os": "Linux", - "database_os": "Linux", - "display_name": "API-Hour-yocto", - "notes": "Python 3 + API-Hour + AsyncIO", - "tags": ["broken"] - }, - "plaintext": { - "plaintext_url": "/plaintext", - "port": 8082, - "approach": "Stripped", - "classification": "Platform", - "database": "None", - "framework": "api_hour", - "language": "Python", - "flavor": "Python3", - "orm": "Raw", - "platform": "asyncio", - "webserver": "Gunicorn", - "os": "Linux", - "database_os": "Linux", - "display_name": "API-Hour-yocto", - "notes": "Python 3 + API-Hour + AsyncIO", - "tags": ["broken"] - } - }] -} diff --git a/frameworks/Python/api_hour/config.toml b/frameworks/Python/api_hour/config.toml deleted file mode 100644 index aaff808cd3c..00000000000 --- a/frameworks/Python/api_hour/config.toml +++ /dev/null @@ -1,72 +0,0 @@ -[framework] -name = "api_hour" - -[main] -urls.plaintext = "/plaintext" -urls.json = "/json" -urls.db = "/db" -urls.query = "/queries?queries=" -urls.update = "/updates?queries=" -urls.fortune = "/fortunes" -approach = "Realistic" -classification = "Micro" -database = "Postgres" -database_os = "Linux" -os = "Linux" -orm = "Raw" -platform = "asyncio" -webserver = "Gunicorn" -versus = "None" - -[plaintext] -urls.plaintext = "/plaintext" -approach = "Stripped" -classification = "Platform" -database = "None" -database_os = "Linux" -os = "Linux" -orm = "Raw" -platform = "asyncio" -webserver = "Gunicorn" -versus = "None" - -[json] -urls.json = "/json" -approach = "Stripped" -classification = "Platform" -database = "None" -database_os = "Linux" -os = "Linux" -orm = "Raw" -platform = "asyncio" -webserver = "Gunicorn" -versus = "None" - -[dbs] -urls.db = "/db" -urls.query = "/queries?queries=" -urls.update = "/updates?queries=" -approach = "Stripped" -classification = "Platform" -database = "Postgres" -database_os = "Linux" -os = "Linux" -orm = "Raw" -platform = "asyncio" -webserver = "Gunicorn" -versus = "None" - -[mysql] -urls.db = "/db_mysql" -urls.query = "/queries_mysql?queries=" -urls.update = "/updates_mysql?queries=" -urls.fortune = "/fortunes_mysql" -approach = "Realistic" -classification = "Micro" -database = "MySQL" -database_os = "Linux" -os = "Linux" -orm = "Raw" -platform = "asyncio" -webserver = "Gunicorn" -versus = "None" diff --git a/frameworks/Python/api_hour/requirements.txt b/frameworks/Python/api_hour/requirements.txt deleted file mode 100644 index abbbff49f26..00000000000 --- a/frameworks/Python/api_hour/requirements.txt +++ /dev/null @@ -1,19 +0,0 @@ -aiohttp==3.13.3 --e git+https://github.com/Eyepea/aiohttp_jinja2.git@c9675e5c1e1ee7741b30aea8d8fbffcde016c7a0#egg=aiohttp_jinja2-master -aiopg==0.7.0 --e git+https://github.com/Eyepea/API-Hour.git@577abbdcbb8cc2810dad46e260b338b15db4d0e3#egg=api_hour-master -asyncio-redis==0.13.4 -chardet==2.3.0 -gunicorn==23.0.0 -hiredis==0.2.0 -Jinja2==3.1.6 -MarkupSafe==0.23 -piprot==0.9.1 -psycopg2==2.7.5 -PyYAML==5.4 -requests==2.32.4 -requests-futures==0.9.5 -setproctitle==1.1.8 -ujson==1.33 -aiomysql==0.3.0 -PyMySQL==1.1.1 diff --git a/frameworks/Python/api_hour/yocto_http/LICENSE b/frameworks/Python/api_hour/yocto_http/LICENSE deleted file mode 100644 index 41a9656a9c6..00000000000 --- a/frameworks/Python/api_hour/yocto_http/LICENSE +++ /dev/null @@ -1,13 +0,0 @@ -Copyright [2015] [Eyepea Dev Team] - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. \ No newline at end of file diff --git a/frameworks/Python/api_hour/yocto_http/etc/default/hello b/frameworks/Python/api_hour/yocto_http/etc/default/hello deleted file mode 100644 index cc1ca1925fb..00000000000 --- a/frameworks/Python/api_hour/yocto_http/etc/default/hello +++ /dev/null @@ -1,3 +0,0 @@ -# Start the daemon by default, let the user disable it. -START_DAEMON=yes -DAEMON_ARGS="--config_dir=/etc/hello" \ No newline at end of file diff --git a/frameworks/Python/api_hour/yocto_http/etc/hello/api_hour/gunicorn_conf.py b/frameworks/Python/api_hour/yocto_http/etc/hello/api_hour/gunicorn_conf.py deleted file mode 100644 index 029e2fcd673..00000000000 --- a/frameworks/Python/api_hour/yocto_http/etc/hello/api_hour/gunicorn_conf.py +++ /dev/null @@ -1,15 +0,0 @@ -import multiprocessing -import os - -_is_travis = os.environ.get('TRAVIS') == 'true' - -workers = multiprocessing.cpu_count() -if _is_travis: - workers = 2 - -bind = ['0.0.0.0:8080', '0.0.0.0:8081', '0.0.0.0:8082'] -keepalive = 120 -errorlog = '-' -pidfile = '/tmp/api_hour.pid' -pythonpath = 'hello' -backlog = 10240000 \ No newline at end of file diff --git a/frameworks/Python/api_hour/yocto_http/etc/hello/api_hour/logging.ini b/frameworks/Python/api_hour/yocto_http/etc/hello/api_hour/logging.ini deleted file mode 100644 index 581435cbd23..00000000000 --- a/frameworks/Python/api_hour/yocto_http/etc/hello/api_hour/logging.ini +++ /dev/null @@ -1,71 +0,0 @@ -[formatters] -keys=detailed,simple - -[handlers] -keys=console,syslog,smtp - -[loggers] -keys=root,warnings,asyncio,gunicorn,aiohttp,api_hour,hello - -[formatter_simple] -format=%(name)s:%(levelname)s %(asctime)s %(module)s.py => %(message)s - -[formatter_detailed] -format=%(name)s:%(levelname)s %(asctime)s %(module)s.py:%(lineno)d => %(message)s - -[handler_console] -class=StreamHandler -args=(sys.stdout,) -formatter=detailed - -[handler_syslog] -class=handlers.SysLogHandler -args=('/dev/log', handlers.SysLogHandler.LOG_LOCAL6) -formatter=detailed - -[handler_smtp] -class=handlers.SMTPHandler -level=WARN -args=('127.0.0.1', 'gmludo@gmail.com', ['gmludo@gmail.com'], 'hello error on server: hello') -formatter=detailed - -[logger_root] -level=ERROR -handlers=console - -# You can add smtp in handlers list to receive e-mail alerts -[logger_warnings] -level=WARN -handlers=console -qualname=py.warnings -propagate=0 - -[logger_asyncio] -level=WARN -handlers=console -qualname=asyncio -propagate=0 - -[logger_gunicorn] -level=WARN -handlers=console -qualname=gunicorn -propagate=0 - -[logger_aiohttp] -level=WARN -handlers=console -qualname=aiohttp -propagate=0 - -[logger_api_hour] -level=WARN -handlers=console -qualname=api_hour -propagate=0 - -[logger_hello] -level=WARN -handlers=console -qualname=hello -propagate=0 diff --git a/frameworks/Python/api_hour/yocto_http/etc/hello/main/main.yaml b/frameworks/Python/api_hour/yocto_http/etc/hello/main/main.yaml deleted file mode 100644 index 480b7d8ac3f..00000000000 --- a/frameworks/Python/api_hour/yocto_http/etc/hello/main/main.yaml +++ /dev/null @@ -1,10 +0,0 @@ ---- -engines: - pg: - host: tfb-database - port: 5432 - dbname: hello_world - user: benchmarkdbuser - password: benchmarkdbpass - minsize: 22 - maxsize: 22 diff --git a/frameworks/Python/api_hour/yocto_http/etc/init.d/hello b/frameworks/Python/api_hour/yocto_http/etc/init.d/hello deleted file mode 100755 index 6b5eea7fcee..00000000000 --- a/frameworks/Python/api_hour/yocto_http/etc/init.d/hello +++ /dev/null @@ -1,79 +0,0 @@ -#!/bin/sh -# -### BEGIN INIT INFO -# Provides: hello -# Required-Start: $local_fs $remote_fs $network $syslog -# Required-Stop: $local_fs $remote_fs $network $syslog -# Default-Start: 2 3 4 5 -# Default-Stop: 0 1 6 -# Short-Description: Startup daemon script for hello -### END INIT INFO -# -# Author: Ludovic Gasc -set -e - -PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin -DAEMONNAME=hello -RUNDIR=/run/$DAEMONNAME -DAEMON=/opt/hello/${DAEMONNAME}_cli -PIDFILE=/run/lock/${DAEMONNAME}_0 -DAEMON_ARGS="" - -# Exit if the package is not installed -[ -x "$DAEMON" ] || exit 0 - -# Create RUNDIR if it doesn't exist -[ -d "$RUNDIR" ] || mkdir -p "$RUNDIR" - -# Read configuration variable file if it is present -[ -r /etc/default/$NAME ] && . /etc/default/$NAME - -# Load the VERBOSE setting and other rcS variables -[ -f /etc/default/rcS ] && . /etc/default/rcS - -# Define LSB log_* functions. -# Depend on lsb-base (>= 3.0-6) to ensure that this file is present. -. /lib/lsb/init-functions - -case "$1" in - start) - log_daemon_msg "Starting" "$DAEMONNAME" - if start-stop-daemon -b --start --pidfile $PIDFILE --startas $DAEMON -- $DAEMON_ARGS; - then - log_end_msg 0 - else - log_end_msg 1 - fi - ;; - stop) - log_daemon_msg "Stopping" "$DAEMONNAME" - if start-stop-daemon --stop --retry 5 --pidfile $PIDFILE; - then - log_end_msg 0 - else - log_end_msg 1 - fi - ;; - reload|force-reload) - log_daemon_msg "Reloading" "$DAEMONNAME" - if start-stop-daemon --stop --signal 1 --pidfile $PIDFILE --startas $DAEMON; - then - log_end_msg 0 - else - log_end_msg 1 - fi - ;; - restart) - $0 stop - $0 start - ;; - status) - status_of_proc -p $PIDFILE "$DAEMON" $DAEMONNAME && exit 0 || exit $? - ;; - *) - echo "Usage: $0 {start|stop|reload|force-reload|restart|status}" - exit 1 - ;; -esac - -exit 0 diff --git a/frameworks/Python/api_hour/yocto_http/etc/rsyslog.conf b/frameworks/Python/api_hour/yocto_http/etc/rsyslog.conf deleted file mode 100644 index 10798d600eb..00000000000 --- a/frameworks/Python/api_hour/yocto_http/etc/rsyslog.conf +++ /dev/null @@ -1,126 +0,0 @@ -# /etc/rsyslog.conf Configuration file for rsyslog. -# -# For more information see -# /usr/share/doc/rsyslog-doc/html/rsyslog_conf.html - - -################# -#### MODULES #### -################# - -$ModLoad imuxsock # provides support for local system logging -$ModLoad imklog # provides kernel logging support -#$ModLoad immark # provides --MARK-- message capability -$SystemLogRateLimitInterval 1 -$SystemLogRateLimitBurst 1000 - -# provides UDP syslog reception -#$ModLoad imudp -#$UDPServerRun 514 - -# provides TCP syslog reception -#$ModLoad imtcp -#$InputTCPServerRun 514 - - -########################### -#### GLOBAL DIRECTIVES #### -########################### - -# -# Use traditional timestamp format. -# To enable high precision timestamps, comment out the following line. -# -$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat - -# -# Set the default permissions for all log files. -# -$FileOwner root -$FileGroup adm -$FileCreateMode 0640 -$DirCreateMode 0755 -$Umask 0022 - -# -# Where to place spool and state files -# -$WorkDirectory /var/spool/rsyslog - -# -# Include all config files in /etc/rsyslog.d/ -# -$IncludeConfig /etc/rsyslog.d/*.conf - - -############### -#### RULES #### -############### - -# -# First some standard log files. Log by facility. -# -auth,authpriv.* /var/log/auth.log -*.*;auth,authpriv.none;\ - local6.none -/var/log/syslog -#cron.* /var/log/cron.log -daemon.* -/var/log/daemon.log -kern.* -/var/log/kern.log -lpr.* -/var/log/lpr.log -mail.* -/var/log/mail.log -user.* -/var/log/user.log - -local6.* /var/log/hello/hello.log - -# -# Logging for the mail system. Split it up so that -# it is easy to write scripts to parse these files. -# -mail.info -/var/log/mail.info -mail.warn -/var/log/mail.warn -mail.err /var/log/mail.err - -# -# Logging for INN news system. -# -news.crit /var/log/news/news.crit -news.err /var/log/news/news.err -news.notice -/var/log/news/news.notice - -# -# Some "catch-all" log files. -# -*.=debug;\ - auth,authpriv.none;\ - news.none;mail.none;local7.none -/var/log/debug -*.=info;*.=notice;*.=warn;\ - auth,authpriv.none;\ - cron,daemon.none;\ - mail,news.none;local7.none -/var/log/messages - -# -# Emergencies are sent to everybody logged in. -# -*.emerg :omusrmsg:* - -# -# I like to have messages displayed on the console, but only on a virtual -# console I usually leave idle. -# -#daemon,mail.*;\ -# news.=crit;news.=err;news.=notice;\ -# *.=debug;*.=info;\ -# *.=notice;*.=warn /dev/tty8 - -# The named pipe /dev/xconsole is for the `xconsole' utility. To use it, -# you must invoke `xconsole' with the `-file' option: -# -# $ xconsole -file /dev/xconsole [...] -# -# NOTE: adjust the list below, or you'll go crazy if you have a reasonably -# busy site.. -# -daemon.*;mail.*;\ - news.err;\ - *.=debug;*.=info;\ - *.=notice;*.=warn |/dev/xconsole diff --git a/frameworks/Python/api_hour/yocto_http/hello/__init__.py b/frameworks/Python/api_hour/yocto_http/hello/__init__.py deleted file mode 100644 index 51c26b70cce..00000000000 --- a/frameworks/Python/api_hour/yocto_http/hello/__init__.py +++ /dev/null @@ -1,63 +0,0 @@ -import logging -import asyncio -import os - -import aiopg -import jinja2 -import psycopg2.extras -import api_hour - -from . import endpoints -from . import servers -from .utils import yocto_http - -LOG = logging.getLogger(__name__) - - -class Container(api_hour.Container): - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - self.servers['http'] = yocto_http.Application(loop=kwargs['loop']) - self.servers['http'].ah_container = self # keep a reference to Container - # routes - self.servers['http'].add_route('/db', endpoints.world.db) - self.servers['http'].add_route('/queries', endpoints.world.queries) - self.servers['http'].add_route('/fortunes', endpoints.world.fortunes, content_type='text/html; charset=UTF-8') - self.servers['http'].add_route('/updates', endpoints.world.updates) - self.servers['http']['j2_env'] = jinja2.Environment(loader=jinja2.PackageLoader('hello')) - - def make_servers(self): - return [servers.yocto_http.YoctoHttpJson, - self.servers['http'].handler, - servers.yocto_http.YoctoHttpText] - - @asyncio.coroutine - def start(self): - yield from super().start() - LOG.info('Starting engines...') - self.engines['pg'] = self.loop.create_task(aiopg.create_pool(host='tfb-database', - port=int(self.config['engines']['pg']['port']), - sslmode='disable', - dbname=self.config['engines']['pg']['dbname'], - user=self.config['engines']['pg']['user'], - password=self.config['engines']['pg']['password'], - cursor_factory=psycopg2.extras.RealDictCursor, - minsize=int(self.config['engines']['pg']['minsize']), - maxsize=int(self.config['engines']['pg']['maxsize']), - loop=self.loop)) - yield from asyncio.wait([self.engines['pg']], return_when=asyncio.ALL_COMPLETED) - - LOG.info('All engines ready !') - - @asyncio.coroutine - def stop(self): - LOG.info('Stopping engines...') - if 'pg' in self.engines: - if self.engines['pg'].done(): - self.engines['pg'].result().terminate() - yield from self.engines['pg'].result().wait_closed() - else: - yield from self.engines['pg'].cancel() - - LOG.info('All engines stopped !') - yield from super().stop() \ No newline at end of file diff --git a/frameworks/Python/api_hour/yocto_http/hello/endpoints/__init__.py b/frameworks/Python/api_hour/yocto_http/hello/endpoints/__init__.py deleted file mode 100644 index 72e85908a10..00000000000 --- a/frameworks/Python/api_hour/yocto_http/hello/endpoints/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from . import world \ No newline at end of file diff --git a/frameworks/Python/api_hour/yocto_http/hello/endpoints/world.py b/frameworks/Python/api_hour/yocto_http/hello/endpoints/world.py deleted file mode 100644 index cc4f7655542..00000000000 --- a/frameworks/Python/api_hour/yocto_http/hello/endpoints/world.py +++ /dev/null @@ -1,38 +0,0 @@ -import logging -import asyncio -import ujson - -from ..services import queries_number -from ..services.world import get_random_record, get_random_records, update_random_records, get_fortunes - -LOG = logging.getLogger(__name__) - -@asyncio.coroutine -def db(request): - """Test type 2: Single database query""" - container = request.app.ah_container - - return ujson.dumps((yield from get_random_record(container))) - -@asyncio.coroutine -def queries(request): - """Test type 3: Multiple database queries""" - container = request.app.ah_container - limit = queries_number(request.params.get('queries', 1)) - - return ujson.dumps((yield from get_random_records(container, limit))) - -@asyncio.coroutine -def fortunes(request): - """Test type 4: Fortunes""" - container = request.app.ah_container - template = request.app['j2_env'].get_template('fortunes.html.j2') - return template.render({'fortunes': (yield from get_fortunes(container))}) - -@asyncio.coroutine -def updates(request): - """Test type 5: Database updates""" - container = request.app.ah_container - limit = queries_number(request.params.get('queries', 1)) - - return ujson.dumps((yield from update_random_records(container, limit))) \ No newline at end of file diff --git a/frameworks/Python/api_hour/yocto_http/hello/servers/__init__.py b/frameworks/Python/api_hour/yocto_http/hello/servers/__init__.py deleted file mode 100644 index 136bc95b3bb..00000000000 --- a/frameworks/Python/api_hour/yocto_http/hello/servers/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from . import yocto_http \ No newline at end of file diff --git a/frameworks/Python/api_hour/yocto_http/hello/servers/yocto_http.py b/frameworks/Python/api_hour/yocto_http/hello/servers/yocto_http.py deleted file mode 100644 index ae1a6a35679..00000000000 --- a/frameworks/Python/api_hour/yocto_http/hello/servers/yocto_http.py +++ /dev/null @@ -1,23 +0,0 @@ -import asyncio - -import ujson - -from ..utils.yocto_http.utils import generate_http_response - -class YoctoHttpJson(asyncio.Protocol): - def connection_made(self, transport): - self.transport = transport - - def data_received(self, data): - # self.transport.write(data) - payload = ujson.dumps({'message': 'Hello, World!'}) - self.transport.write(generate_http_response(payload)) - -class YoctoHttpText(asyncio.Protocol): - def connection_made(self, transport): - self.transport = transport - - def data_received(self, data): - # self.transport.write(data) - payload = 'Hello, World!' - self.transport.write(generate_http_response(payload, 'text/plain; charset=UTF-8')) \ No newline at end of file diff --git a/frameworks/Python/api_hour/yocto_http/hello/services/__init__.py b/frameworks/Python/api_hour/yocto_http/hello/services/__init__.py deleted file mode 100644 index 9a1e89c1df7..00000000000 --- a/frameworks/Python/api_hour/yocto_http/hello/services/__init__.py +++ /dev/null @@ -1,14 +0,0 @@ -from . import world - -# get from Django hello application -def queries_number(number): - try: - queries = int(number) - except Exception: - queries = 1 - if queries < 1: - queries = 1 - if queries > 500: - queries = 500 - return queries - diff --git a/frameworks/Python/api_hour/yocto_http/hello/services/world.py b/frameworks/Python/api_hour/yocto_http/hello/services/world.py deleted file mode 100644 index ed635a99837..00000000000 --- a/frameworks/Python/api_hour/yocto_http/hello/services/world.py +++ /dev/null @@ -1,55 +0,0 @@ -import asyncio -from random import randint -from operator import itemgetter - -@asyncio.coroutine -def get_random_record(container): - pg = yield from container.engines['pg'] - - with (yield from pg.cursor()) as cur: - yield from cur.execute('SELECT id AS "Id", randomnumber AS "RandomNumber" FROM world WHERE id=%(idx)s LIMIT 1', - {'idx': randint(1, 10000)}) - world = yield from cur.fetchone() - return world - -@asyncio.coroutine -def get_random_records(container, limit): - pg = yield from container.engines['pg'] - results = [] - with (yield from pg.cursor()) as cur: - for i in range(limit): - yield from cur.execute('SELECT id AS "Id", randomnumber AS "RandomNumber" FROM world WHERE id=%(idx)s LIMIT 1', - {'idx': randint(1, 10000)}) - results.append((yield from cur.fetchone())) - - return results - -@asyncio.coroutine -def update_random_records(container, limit): - results = [] - pg = yield from container.engines['pg'] - - with (yield from pg.cursor()) as cur: - for i in range(limit): - yield from cur.execute('SELECT id AS "Id", randomnumber AS "RandomNumber" FROM world WHERE id=%(idx)s LIMIT 1', - {'idx': randint(1, 10000)}) - world = yield from cur.fetchone() - world['RandomNumber'] = randint(1, 10000) - yield from cur.execute('UPDATE world SET randomnumber=%(random_number)s WHERE id=%(idx)s', - {'random_number': world['RandomNumber'], 'idx': world['Id']}) - results.append(world) - return results - -@asyncio.coroutine -def get_fortunes(container): - pg = yield from container.engines['pg'] - - with (yield from pg.cursor()) as cur: - yield from cur.execute('SELECT * FROM fortune') - fortunes = yield from cur.fetchall() - - fortunes.append({'id': 0, 'message': 'Additional fortune added at request time.'}) - - fortunes.sort(key=itemgetter('message')) - - return fortunes \ No newline at end of file diff --git a/frameworks/Python/api_hour/yocto_http/hello/templates/fortunes.html.j2 b/frameworks/Python/api_hour/yocto_http/hello/templates/fortunes.html.j2 deleted file mode 100644 index f402560b250..00000000000 --- a/frameworks/Python/api_hour/yocto_http/hello/templates/fortunes.html.j2 +++ /dev/null @@ -1,20 +0,0 @@ - - - - Fortunes - - - - - - - - {% for fortune in fortunes %} - - - - - {% endfor %} -
idmessage
{{ fortune['id']|e }}{{ fortune['message']|e }}
- - \ No newline at end of file diff --git a/frameworks/Python/api_hour/yocto_http/hello/utils/__init__.py b/frameworks/Python/api_hour/yocto_http/hello/utils/__init__.py deleted file mode 100644 index 905569002c6..00000000000 --- a/frameworks/Python/api_hour/yocto_http/hello/utils/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -import logging - -LOG = logging.getLogger(__name__) diff --git a/frameworks/Python/api_hour/yocto_http/hello/utils/yocto_http/__init__.py b/frameworks/Python/api_hour/yocto_http/hello/utils/yocto_http/__init__.py deleted file mode 100644 index 57ad26ef886..00000000000 --- a/frameworks/Python/api_hour/yocto_http/hello/utils/yocto_http/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from .application import Application \ No newline at end of file diff --git a/frameworks/Python/api_hour/yocto_http/hello/utils/yocto_http/application.py b/frameworks/Python/api_hour/yocto_http/hello/utils/yocto_http/application.py deleted file mode 100644 index c8eb6f05f1c..00000000000 --- a/frameworks/Python/api_hour/yocto_http/hello/utils/yocto_http/application.py +++ /dev/null @@ -1,78 +0,0 @@ -import asyncio -import logging -from collections import OrderedDict - -from .request import Request -from .utils import generate_http_response - -log = logging.getLogger(__name__) - -class Application(dict): - - def __init__(self, default_encoding='utf-8', decode_headers=False, loop=None): - super(Application, self).__init__() - self.default_encoding = default_encoding - if loop is None: - loop = asyncio.get_event_loop() - self.decode_headers = decode_headers - self.loop = loop - self._route = OrderedDict() - - def add_route(self, path, endpoint, content_type='application/json'): - assert callable(endpoint), endpoint - if not asyncio.iscoroutinefunction(endpoint): - endpoint = asyncio.coroutine(endpoint) - endpoint.content_type = content_type - self._route[path] = endpoint - - @asyncio.coroutine - def handler(self, reader, writer): - # while True: - buffer = b'' - while b'\r\n\r\n' not in buffer: - buffer += yield from reader.read(100) - lines = buffer[:-2].decode(self.default_encoding).split('\r\n') - - url = lines[0].split(' ')[1].split('?') - path = url[0] - params = OrderedDict() - if len(url) == 2: - k, v = url[1].split('=', 1) # @TODO: support several parameters - params[k] = v - - # log.info('Received HTTP request from %r for "%s" route', - # writer.get_extra_info('peername'), - # uri) - - headers = {} - if self.decode_headers: - for line in lines: - k, v = line.split(': ', 1) - headers[k] = v - log.debug("HTTP Headers: %r", - headers) - - if path in self._route: - request = Request(app=self, - path=path, - params=params, - headers=headers, - reader=reader, writer=writer, - encoding=self.default_encoding) - try: - response = yield from self._route[path](request) - writer.write(generate_http_response(response, content_type=self._route[path].content_type)) - try: - yield from writer.drain() - except ConnectionError: - pass - except Exception as e: - log.exception(e) - else: - log.error('No route for the request "%s"', path) - writer.write(generate_http_response('')) - try: - yield from writer.drain() - except ConnectionError: - pass - writer.close() diff --git a/frameworks/Python/api_hour/yocto_http/hello/utils/yocto_http/request.py b/frameworks/Python/api_hour/yocto_http/hello/utils/yocto_http/request.py deleted file mode 100644 index 753336e145f..00000000000 --- a/frameworks/Python/api_hour/yocto_http/hello/utils/yocto_http/request.py +++ /dev/null @@ -1,9 +0,0 @@ -class Request: - def __init__(self, app, path, params, headers, reader, writer, encoding='utf-8'): - self.app = app - self.path = path - self.params = params - self.headers = headers - self.reader = reader - self.writer = writer - self.encoding = encoding diff --git a/frameworks/Python/api_hour/yocto_http/hello/utils/yocto_http/utils.py b/frameworks/Python/api_hour/yocto_http/hello/utils/yocto_http/utils.py deleted file mode 100644 index 27dea7d3603..00000000000 --- a/frameworks/Python/api_hour/yocto_http/hello/utils/yocto_http/utils.py +++ /dev/null @@ -1,11 +0,0 @@ -from wsgiref.handlers import format_date_time - -def generate_http_response(payload, content_type='application/json'): - return ("""HTTP/1.1 200 OK -CONTENT-TYPE: %s -CONTENT-LENGTH: %s -CONNECTION: keep-alive -DATE: %s -SERVER: yocto_http/0.0.2 - -%s""" % (content_type, len(payload), format_date_time(None), payload)).encode('utf-8')