Commit 02eddb58 authored by davebshow's avatar davebshow
Browse files

0.0.4 changes in dev branch

parent 4ff741a1
# aiogremlin 0.0.2 [(gizmo grew up)](https://pypi.python.org/pypi/gizmo/0.1.12)
# aiogremlin 0.0.4 [(gizmo grew up)](https://pypi.python.org/pypi/gizmo/0.1.12)
`aiogremlin` is a **Python 3** driver for the the [Tinkerpop 3 Gremlin Server](http://www.tinkerpop.com/docs/3.0.0.M7/#gremlin-server). This module is built on [Asyncio](https://docs.python.org/3/library/asyncio.html). By default it uses the [aiohttp](http://aiohttp.readthedocs.org/en/v0.15.3/index.html) websocket client , but it is easy to plug in a different implementation. `aiogremlin` is currently in **alpha** mode, but all major functionality has test coverage.
......
......@@ -3,4 +3,4 @@ from .connection import (WebsocketPool, AiohttpFactory, BaseFactory,
BaseConnection)
from .client import GremlinClient, create_client
from .exceptions import RequestError, GremlinServerError, SocketClientError
__version__ = "0.0.3dev"
__version__ = "0.0.4dev"
......@@ -5,10 +5,9 @@ import ssl
import uuid
import aiohttp
import ujson
from aiogremlin.connection import WebsocketPool
from aiogremlin.log import client_logger
from aiogremlin.log import client_logger, INFO
from aiogremlin.protocol import gremlin_response_parser, GremlinWriter
......@@ -16,12 +15,13 @@ from aiogremlin.protocol import gremlin_response_parser, GremlinWriter
def create_client(uri='ws://localhost:8182/', loop=None, ssl=None,
protocol=None, lang="gremlin-groovy", op="eval",
processor="", pool=None, factory=None, poolsize=10,
timeout=None, **kwargs):
timeout=None, verbose=False, **kwargs):
pool = WebsocketPool(uri,
factory=factory,
poolsize=poolsize,
timeout=timeout,
loop=loop)
loop=loop,
verbose=verbose)
yield from pool.init_pool()
......@@ -33,7 +33,8 @@ def create_client(uri='ws://localhost:8182/', loop=None, ssl=None,
op=op,
processor=processor,
pool=pool,
factory=factory)
factory=factory,
verbose=verbose)
class GremlinClient:
......@@ -41,7 +42,7 @@ class GremlinClient:
def __init__(self, uri='ws://localhost:8182/', loop=None, ssl=None,
protocol=None, lang="gremlin-groovy", op="eval",
processor="", pool=None, factory=None, poolsize=10,
timeout=None, **kwargs):
timeout=None, verbose=True, **kwargs):
"""
"""
self.uri = uri
......@@ -62,6 +63,8 @@ class GremlinClient:
self.pool = pool or WebsocketPool(uri, factory=factory,
poolsize=poolsize, timeout=timeout, loop=self._loop)
self.factory = factory or self.pool.factory
if verbose:
client_logger.setLevel(INFO)
@property
def loop(self):
......@@ -88,7 +91,7 @@ class GremlinClient:
lang = lang or self.lang
op = op or self.op
processor = processor or self.processor
message = ujson.dumps({
message = {
"requestId": str(uuid.uuid4()),
"op": op,
"processor": processor,
......@@ -97,7 +100,11 @@ class GremlinClient:
"bindings": bindings,
"language": lang
}
})
}
if processor == "session":
message["args"]["session"] = str(uuid.uuid4())
client_logger.info(
"Session ID: {}".format(message["args"]["session"]))
if connection is None:
connection = yield from self.pool.connect(self.uri, loop=self.loop)
writer = GremlinWriter(connection)
......
......@@ -102,17 +102,15 @@ class WebsocketPool:
try:
socket = yield from self.factory.connect(uri, pool=self,
loop=loop)
except:
raise
else:
conn_logger.info("New connection on socket: {} at {}".format(
socket, uri))
finally:
self.num_connecting -= 1
if not socket.closed:
conn_logger.info("New connection on socket: {} at {}".format(
socket, uri))
self.active_conns.add(socket)
# Untested.
elif num_retries > 0:
conn_logger.warning("Got bad socket, retry...")
socket = yield from self.connect(uri, loop, num_retries - 1)
else:
raise RuntimeError("Unable to connect, max retries exceeded.")
......
......@@ -39,6 +39,7 @@ class GremlinWriter:
@asyncio.coroutine
def write(self, message, binary=True, mime_type="application/json"):
message = ujson.dumps(message)
if binary:
message = self._set_message_header(message, mime_type)
yield from self._connection.send(message, binary)
......
......@@ -27,7 +27,7 @@ def run(client, count, concurrency, loop):
assert resp[0].data[0] == result, resp[0].data[0]
processed_count += 1
except Exception:
continue
raise
for i in range(count):
rnd1 = random.randint(1, 9)
......@@ -102,8 +102,8 @@ if __name__ == "__main__":
client = loop.run_until_complete(
aiogremlin.create_client(loop=loop, poolsize=poolsize))
try:
print("Runs: {}. Warmups: {}. Messages: {}. Concurrency: {}.".format(
num_tests, num_warmups, num_mssg, concurr))
print("Runs: {}. Warmups: {}. Messages: {}. Concurrency: {}. Poolsize: {}".format(
num_tests, num_warmups, num_mssg, concurr, poolsize))
main = main(client, num_tests, num_mssg, concurr, num_warmups, loop)
loop.run_until_complete(main)
finally:
......
0.0.1 - 4/2015: Birth!
0.0.2 - 5/1/2015: Added an init_pool method and a create_client constructor.
0.0.3 - 5/2/2015: Using ujson for serialization.
0.0.4 - 5/12/2015: Added support for sessions.
......@@ -3,7 +3,7 @@ from setuptools import setup
setup(
name="aiogremlin",
version="0.0.3",
version="0.0.4",
url="",
license="MIT",
author="davebshow",
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment