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

Support KGMS 1.5.2 #14

Merged
merged 11 commits into from
Apr 19, 2019
47 changes: 35 additions & 12 deletions GraknClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,24 @@ public class GraknClient implements AutoCloseable {
public static final String DEFAULT_URI = "localhost:48555";

private ManagedChannel channel;
private String username;
private String password;
private Keyspaces keyspaces;

public GraknClient() {
this(DEFAULT_URI);
}

public GraknClient(String address) {
this(address, null, null);
}

public GraknClient(String address, String username, String password) {
SimpleURI parsedURI = new SimpleURI(address);
channel = ManagedChannelBuilder.forAddress(parsedURI.getHost(), parsedURI.getPort())
.usePlaintext(true).build();
this.username = username;
this.password = password;
keyspaces = new Keyspaces(channel);
}

Expand All @@ -116,7 +124,7 @@ public void close() {
}

public Session session(String keyspace) {
return new Session(channel, keyspace);
return new Session(channel, username, password, keyspace);
}

public Keyspaces keyspaces() {
Expand All @@ -131,21 +139,37 @@ public Keyspaces keyspaces() {
*/
public static class Session implements grakn.core.api.Session {

private final ManagedChannel channel;
private final String keyspace;
private final SessionServiceGrpc.SessionServiceBlockingStub sessionStub;
private final String sessionId;
private boolean isOpen;
protected ManagedChannel channel;
private String username;
private String password;
protected String keyspace;
protected SessionServiceGrpc.SessionServiceBlockingStub sessionStub;
protected String sessionId;
protected boolean isOpen;

private Session(ManagedChannel channel, String keyspace) {
protected Session() {
}

private Session(ManagedChannel channel, String username, String password, String keyspace) {
if (!Validator.isValidKeyspaceName(keyspace)) {
throw GraknClientException.invalidKeyspaceName(keyspace);
}
this.username = username;
this.password = password;
this.keyspace = keyspace;
this.channel = channel;
this.sessionStub = SessionServiceGrpc.newBlockingStub(channel);

SessionProto.Session.Open.Res response = sessionStub.open(RequestBuilder.Session.open(keyspace));
SessionProto.Session.Open.Req.Builder open = RequestBuilder.Session.open(keyspace).newBuilderForType();
if (username != null) {
open = open.setUsername(username);
}
if (password != null) {
open = open.setPassword(password);
}
open = open.setKeyspace(keyspace);

SessionProto.Session.Open.Res response = sessionStub.open(open.build());
sessionId = response.getSessionId();
isOpen = true;
}
Expand All @@ -172,7 +196,6 @@ public Keyspace keyspace() {
* Remote implementation of grakn.core.api.Transaction that communicates with a Grakn server using gRPC.
*/
public static class Transaction implements grakn.core.api.Transaction {

private final Session session;
private final Type type;
private final Transceiver transceiver;
Expand All @@ -183,7 +206,7 @@ public static class Builder implements grakn.core.api.Transaction.Builder {
private GraknClient.Session session;
private String sessionId;

Builder(ManagedChannel channel, GraknClient.Session session, String sessionId) {
public Builder(ManagedChannel channel, GraknClient.Session session, String sessionId) {
this.channel = channel;
this.session = session;
this.sessionId = sessionId;
Expand All @@ -200,9 +223,9 @@ public GraknClient.Transaction write() {
}

private Transaction(ManagedChannel channel, Session session, String sessionId, Type type) {
this.transceiver = Transceiver.create(SessionServiceGrpc.newStub(channel));
this.session = session;
this.type = type;
this.transceiver = Transceiver.create(SessionServiceGrpc.newStub(channel));
transceiver.send(RequestBuilder.Transaction.open(sessionId, type));
responseOrThrow();
}
Expand Down Expand Up @@ -541,7 +564,7 @@ public static final class Keyspaces {

private KeyspaceServiceBlockingStub keyspaceBlockingStub;

private Keyspaces(ManagedChannel channel) {
public Keyspaces(ManagedChannel channel) {
keyspaceBlockingStub = KeyspaceServiceGrpc.newBlockingStub(channel);
}

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.5.0
1.5.2
8 changes: 8 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ graknlabs_build_tools_ci_pip_install = "pip_install")
graknlabs_build_tools_ci_pip_install()


#####################################
# Load Java dependencies from Maven #
#####################################

load("//dependencies/maven:dependencies.bzl", "maven_dependencies")
maven_dependencies()


##########################
# Load GRPC dependencies #
##########################
Expand Down
3 changes: 2 additions & 1 deletion dependencies/graknlabs/dependencies.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ def graknlabs_build_tools():
)

def graknlabs_grakn_core():
# TODO: move back to graknlabs
git_repository(
name = "graknlabs_grakn_core",
remote = "https://github.com/graknlabs/grakn",
tag = "1.5.0" # sync-marker: do not remove this comment, this is used for sync-dependencies by @graknlabs_grakn_core
commit = "51df272ef6ccea84bff51d272b242a4b5072e813" # sync-marker: do not remove this comment, this is used for sync-dependencies by @graknlabs_grakn_core
)
2 changes: 1 addition & 1 deletion test/GraknClientIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import grakn.core.concept.answer.ConceptSet;
import grakn.core.concept.answer.ConceptSetMeasure;
import grakn.core.concept.answer.Numeric;
import grakn.core.concept.printer.Printer;
import grakn.core.concept.thing.Attribute;
import grakn.core.concept.thing.Entity;
import grakn.core.concept.thing.Relation;
Expand All @@ -48,7 +49,6 @@
import grakn.core.concept.type.Role;
import grakn.core.concept.type.SchemaConcept;
import grakn.core.concept.type.Type;
import grakn.core.graql.printer.Printer;
import grakn.core.rule.GraknTestServer;
import grakn.core.server.exception.SessionException;
import grakn.core.server.keyspace.KeyspaceImpl;
Expand Down