예제 #1
0
def test_client_message_too_big(client):
    try:
        client = Client("http://localhost", 'g', max_content_length=1024)
        client.submit("1+1").all().result()
        assert False
    except Exception:
        assert True
    finally:
        client.close()
예제 #2
0
def gremlin_client(request):
    # type: (Any) -> Client
    url = getattr(request.module, 'url', 'ws://localhost:8182/gremlin')
    traversal_source = getattr(request.module, 'traversal_source',
                               'ConfigurationManagementGraph')
    client = Client(url, traversal_source)
    request.addfinalizer(lambda: client.close())
    return client
예제 #3
0
def test_multi_request_in_session(client):
    # Overwrite fixture with session client
    session_id = str(uuid.uuid4())
    client = Client('ws://localhost:45940/gremlin', 'g', session=session_id)

    assert client.submit('x = 1').all().result()[0] == 1
    assert client.submit('x + 2').all().result()[0] == 3

    client.close()

    # attempt reconnect to session and make sure "x" is no longer a thing
    client = Client('ws://localhost:45940/gremlin', 'g', session=session_id)
    try:
        # should fire an exception
        client.submit('x').all().result()
        assert False
    except Exception:
        assert True
예제 #4
0
class InteractiveQueryManager(object):
    def __init__(self, key, frontend_endpoint, object_id):
        self.key = key
        self.type = "gie_manager"
        # graph object id in vineyard
        self.object_id = object_id
        self.graph_url = f"ws://{frontend_endpoint}/gremlin"
        self.client = Client(self.graph_url, "g")
        self.closed = False

    def submit(self, message, bindings=None, request_options=None):
        return self.client.submit(message, bindings, request_options)

    def close(self):
        try:
            self.client.close()
        except Exception:
            pass
        self.closed = True
예제 #5
0
x2 = g.V().both()[1:3].toList()
print(len(x2))
print(x2)

# In[18]:

x3 = g.V().range(1, 10).toList()
print(len(x3))
print(x3)

# In[19]:

x4 = g.V(x3).toList()
print(len(x4))
print(x4)

# In[20]:

x5 = g.V(x3).id().toList()
print(len(x5))
print(x5)

# In[21]:

g.V().range(0, 10).toList()

# In[22]:

# Done and close the client
client.close()
예제 #6
0
class JanusGraph(object):
    def __init__(self):
        self.remote_connection = None
        self.management_connection = None
        self.URL = None
        self.graph = None
        self.connection_keyword_properties = [
            "protocol_factory", "transport_factory", "pool_size",
            "max_workers", "username", "password", "message_serializer",
            "graphson_reader", "graphson_writer"
        ]
        self.args = dict()
        pass

    def connect(self, url="loclahost", port="8182", graph="g", **kwargs):
        self.URL = "ws://{}:{}/gremlin".format(url, port)
        self.graph = graph

        self.args = kwargs

        if not kwargs:

            graphson_reader = JanusGraphSONReader().build()
            graphson_writer = JanusGraphSONWriter().build()

        else:
            kwargs_provided = kwargs.keys()

            if all(k in self.connection_keyword_properties
                   for k in kwargs_provided):
                pass
            else:
                raise AttributeError(
                    "Additional parameters except url, port, graph needs to be the available"
                    "Gremlin client connection parameters. Refer docs")

            if "graphson_reader" in kwargs and "graphson_writer" in kwargs:
                graphson_reader = kwargs["graphson_reader"]
                graphson_writer = kwargs["graphson_writer"]

            else:
                graphson_reader = None
                graphson_writer = None

        args = {
            k: v
            for k, v in self.args.items()
            if k not in ["graphson_reader", "graphson_writer"]
        }

        self.remote_connection = DriverRemoteConnection(
            self.URL,
            self.graph,
            graphson_reader=graphson_reader,
            graphson_writer=graphson_writer,
            **args)

        self.management_connection = Client(self.URL, self.graph, **args)

        return self

    def traversal(self):
        if self.remote_connection is None:
            raise AttributeError(
                "The Graph is not connected to any Remote Graph. Use connect() first."
            )

        g = Graph().traversal().withRemote(self.remote_connection)

        return g

    def openManagement(self):
        if self.management_connection is None:
            raise AttributeError(
                "The Graph is not connected to any Remote Graph. Use connect() first."
            )

        mgmt = JanusGraphManagement(self.management_connection)

        return mgmt

    def close(self):
        self.remote_connection.close()
        self.management_connection.close()
        return True

    def drop(self):
        query = "JanusGraphFactory.drop(graph);"
        result_set = self.management_connection.submit(query)
        future_results = result_set.all()
        results = future_results.result()

        self.close()

        return results