Skip to content

Commit f240a6d

Browse files
author
Ganeshwara Herawan Hananda
authored
Support KGMS 1.5.2 (#14)
## What is the goal of this PR? 1. Support connecting to KGMS 1.5.2: ``` GraknClient kgms = new GraknClient(String address, String username, String password); ``` 2. Added missing `maven_dependencies()` call in `WORKSPACE`. ## What are the changes implemented in this PR? When opening a session, `username` and `password` are supplied in the `Session.Open.Req` gRPC message.
1 parent 3d0d893 commit f240a6d

File tree

5 files changed

+47
-15
lines changed

5 files changed

+47
-15
lines changed

GraknClient.java

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,24 @@ public class GraknClient implements AutoCloseable {
8787
public static final String DEFAULT_URI = "localhost:48555";
8888

8989
private ManagedChannel channel;
90+
private String username;
91+
private String password;
9092
private Keyspaces keyspaces;
9193

9294
public GraknClient() {
9395
this(DEFAULT_URI);
9496
}
9597

9698
public GraknClient(String address) {
99+
this(address, null, null);
100+
}
101+
102+
public GraknClient(String address, String username, String password) {
97103
SimpleURI parsedURI = new SimpleURI(address);
98104
channel = ManagedChannelBuilder.forAddress(parsedURI.getHost(), parsedURI.getPort())
99105
.usePlaintext(true).build();
106+
this.username = username;
107+
this.password = password;
100108
keyspaces = new Keyspaces(channel);
101109
}
102110

@@ -116,7 +124,7 @@ public void close() {
116124
}
117125

118126
public Session session(String keyspace) {
119-
return new Session(channel, keyspace);
127+
return new Session(channel, username, password, keyspace);
120128
}
121129

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

134-
private final ManagedChannel channel;
135-
private final String keyspace;
136-
private final SessionServiceGrpc.SessionServiceBlockingStub sessionStub;
137-
private final String sessionId;
138-
private boolean isOpen;
142+
protected ManagedChannel channel;
143+
private String username;
144+
private String password;
145+
protected String keyspace;
146+
protected SessionServiceGrpc.SessionServiceBlockingStub sessionStub;
147+
protected String sessionId;
148+
protected boolean isOpen;
139149

140-
private Session(ManagedChannel channel, String keyspace) {
150+
protected Session() {
151+
}
152+
153+
private Session(ManagedChannel channel, String username, String password, String keyspace) {
141154
if (!Validator.isValidKeyspaceName(keyspace)) {
142155
throw GraknClientException.invalidKeyspaceName(keyspace);
143156
}
157+
this.username = username;
158+
this.password = password;
144159
this.keyspace = keyspace;
145160
this.channel = channel;
146161
this.sessionStub = SessionServiceGrpc.newBlockingStub(channel);
147162

148-
SessionProto.Session.Open.Res response = sessionStub.open(RequestBuilder.Session.open(keyspace));
163+
SessionProto.Session.Open.Req.Builder open = RequestBuilder.Session.open(keyspace).newBuilderForType();
164+
if (username != null) {
165+
open = open.setUsername(username);
166+
}
167+
if (password != null) {
168+
open = open.setPassword(password);
169+
}
170+
open = open.setKeyspace(keyspace);
171+
172+
SessionProto.Session.Open.Res response = sessionStub.open(open.build());
149173
sessionId = response.getSessionId();
150174
isOpen = true;
151175
}
@@ -172,7 +196,6 @@ public Keyspace keyspace() {
172196
* Remote implementation of grakn.core.api.Transaction that communicates with a Grakn server using gRPC.
173197
*/
174198
public static class Transaction implements grakn.core.api.Transaction {
175-
176199
private final Session session;
177200
private final Type type;
178201
private final Transceiver transceiver;
@@ -183,7 +206,7 @@ public static class Builder implements grakn.core.api.Transaction.Builder {
183206
private GraknClient.Session session;
184207
private String sessionId;
185208

186-
Builder(ManagedChannel channel, GraknClient.Session session, String sessionId) {
209+
public Builder(ManagedChannel channel, GraknClient.Session session, String sessionId) {
187210
this.channel = channel;
188211
this.session = session;
189212
this.sessionId = sessionId;
@@ -200,9 +223,9 @@ public GraknClient.Transaction write() {
200223
}
201224

202225
private Transaction(ManagedChannel channel, Session session, String sessionId, Type type) {
226+
this.transceiver = Transceiver.create(SessionServiceGrpc.newStub(channel));
203227
this.session = session;
204228
this.type = type;
205-
this.transceiver = Transceiver.create(SessionServiceGrpc.newStub(channel));
206229
transceiver.send(RequestBuilder.Transaction.open(sessionId, type));
207230
responseOrThrow();
208231
}
@@ -541,7 +564,7 @@ public static final class Keyspaces {
541564

542565
private KeyspaceServiceBlockingStub keyspaceBlockingStub;
543566

544-
private Keyspaces(ManagedChannel channel) {
567+
public Keyspaces(ManagedChannel channel) {
545568
keyspaceBlockingStub = KeyspaceServiceGrpc.newBlockingStub(channel);
546569
}
547570

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.5.0
1+
1.5.2

WORKSPACE

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ graknlabs_build_tools_ci_pip_install = "pip_install")
6666
graknlabs_build_tools_ci_pip_install()
6767

6868

69+
#####################################
70+
# Load Java dependencies from Maven #
71+
#####################################
72+
73+
load("//dependencies/maven:dependencies.bzl", "maven_dependencies")
74+
maven_dependencies()
75+
76+
6977
##########################
7078
# Load GRPC dependencies #
7179
##########################

dependencies/graknlabs/dependencies.bzl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ def graknlabs_build_tools():
2626
)
2727

2828
def graknlabs_grakn_core():
29+
# TODO: move back to graknlabs
2930
git_repository(
3031
name = "graknlabs_grakn_core",
3132
remote = "https://github.com/graknlabs/grakn",
32-
tag = "1.5.0" # sync-marker: do not remove this comment, this is used for sync-dependencies by @graknlabs_grakn_core
33+
commit = "51df272ef6ccea84bff51d272b242a4b5072e813" # sync-marker: do not remove this comment, this is used for sync-dependencies by @graknlabs_grakn_core
3334
)

test/GraknClientIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import grakn.core.concept.answer.ConceptSet;
3838
import grakn.core.concept.answer.ConceptSetMeasure;
3939
import grakn.core.concept.answer.Numeric;
40+
import grakn.core.concept.printer.Printer;
4041
import grakn.core.concept.thing.Attribute;
4142
import grakn.core.concept.thing.Entity;
4243
import grakn.core.concept.thing.Relation;
@@ -48,7 +49,6 @@
4849
import grakn.core.concept.type.Role;
4950
import grakn.core.concept.type.SchemaConcept;
5051
import grakn.core.concept.type.Type;
51-
import grakn.core.graql.printer.Printer;
5252
import grakn.core.rule.GraknTestServer;
5353
import grakn.core.server.exception.SessionException;
5454
import grakn.core.server.keyspace.KeyspaceImpl;

0 commit comments

Comments
 (0)