Skip to content

Commit 8b56f49

Browse files
author
Ganeshwara Hananda
authored
Add Grakn Cluster support (#111)
## What is the goal of this PR? We have added Grakn Cluster support. A user can connect to a cluster of Grakn Cluster instances using the `--cluster` flag: ``` ./grakn console --cluster 172.0.01:1729 ``` ## What are the changes implemented in this PR? - Adds a new flag `--cluster` for connecting to Grakn Cluster - Update client-java to the version which supports Grakn Cluster
1 parent 8981d8f commit 8b56f49

File tree

5 files changed

+44
-19
lines changed

5 files changed

+44
-19
lines changed

.grabl/automation.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ build:
4747
export ARTIFACT_PASSWORD=$REPO_GRAKN_PASSWORD
4848
bazel run @graknlabs_dependencies//distribution/artifact:create-netrc
4949
bazel run @graknlabs_dependencies//tool/checkstyle:test-coverage
50-
bazel build --config=rbe //...
50+
bazel build //...
5151
dependencies/maven/update.sh
5252
git diff --exit-code dependencies/maven/artifacts.snapshot
5353
deploy-artifact-snapshot:

GraknConsole.java

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,29 @@
1818
package grakn.console;
1919

2020
import grakn.client.Grakn;
21+
import grakn.client.GraknClient;
2122
import grakn.client.common.exception.GraknClientException;
2223
import grakn.client.concept.answer.ConceptMap;
2324
import grakn.client.concept.answer.ConceptMapGroup;
2425
import grakn.client.concept.answer.Numeric;
2526
import grakn.client.concept.answer.NumericGroup;
26-
import grakn.client.GraknClient;
2727
import graql.lang.Graql;
2828
import graql.lang.common.exception.GraqlException;
29-
import graql.lang.query.GraqlQuery;
29+
import graql.lang.query.GraqlCompute;
3030
import graql.lang.query.GraqlDefine;
31-
import graql.lang.query.GraqlUndefine;
32-
import graql.lang.query.GraqlInsert;
3331
import graql.lang.query.GraqlDelete;
32+
import graql.lang.query.GraqlInsert;
3433
import graql.lang.query.GraqlMatch;
35-
import graql.lang.query.GraqlCompute;
34+
import graql.lang.query.GraqlQuery;
35+
import graql.lang.query.GraqlUndefine;
3636
import org.jline.reader.LineReader;
3737
import org.jline.reader.LineReaderBuilder;
3838
import org.jline.terminal.Terminal;
3939
import org.jline.terminal.TerminalBuilder;
4040
import org.jline.utils.InfoCmp;
4141
import picocli.CommandLine;
4242

43+
import javax.annotation.Nullable;
4344
import java.io.IOException;
4445
import java.nio.charset.StandardCharsets;
4546
import java.nio.file.Files;
@@ -53,8 +54,8 @@
5354
public class GraknConsole {
5455
private static final String COPYRIGHT =
5556
"\n" +
56-
"Welcome to Grakn Console. You are now in Grakn Wonderland!\n" +
57-
"Copyright (C) 2021 Grakn Labs\n";
57+
"Welcome to Grakn Console. You are now in Grakn Wonderland!\n" +
58+
"Copyright (C) 2021 Grakn Labs\n";
5859
private final CommandLineOptions options;
5960
private final Printer printer;
6061
private Terminal terminal;
@@ -72,13 +73,25 @@ public GraknConsole(CommandLineOptions options, Printer printer) {
7273

7374
public void run() {
7475
printer.info(COPYRIGHT);
75-
try (Grakn.Client client = new GraknClient(options.address())) {
76+
try (Grakn.Client client = createGraknClient(options)) {
7677
runRepl(client);
7778
} catch (GraknClientException e) {
7879
printer.error(e.getMessage());
7980
}
8081
}
8182

83+
private Grakn.Client createGraknClient(CommandLineOptions options) {
84+
Grakn.Client client;
85+
if (options.server() != null) {
86+
client = GraknClient.core(options.server());
87+
} else if (options.cluster() != null) {
88+
client = GraknClient.cluster(options.cluster());
89+
} else {
90+
client = GraknClient.core();
91+
}
92+
return client;
93+
}
94+
8295
private void runRepl(Grakn.Client client) {
8396
LineReader reader = LineReaderBuilder.builder()
8497
.terminal(terminal)
@@ -263,13 +276,25 @@ private static CommandLineOptions parseCommandLine(String[] args) {
263276

264277
@CommandLine.Command(name = "grakn console", mixinStandardHelpOptions = true, version = {grakn.console.Version.VERSION})
265278
public static class CommandLineOptions {
279+
266280
@CommandLine.Option(names = {"--server"},
267-
defaultValue = GraknClient.DEFAULT_URI,
268-
description = "Server address to which the console will connect to")
269-
private String address;
281+
description = "Grakn Core address to which Console will connect to")
282+
private @Nullable
283+
String server;
284+
285+
@Nullable
286+
public String server() {
287+
return server;
288+
}
289+
290+
@CommandLine.Option(names = {"--cluster"},
291+
description = "Grakn Cluster address to which Console will connect to")
292+
private @Nullable
293+
String cluster;
270294

271-
public String address() {
272-
return address;
295+
@Nullable
296+
public String cluster() {
297+
return cluster;
273298
}
274299
}
275300
}

common/Printer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
import grakn.client.concept.thing.Thing;
2929
import grakn.client.concept.type.RoleType;
3030
import grakn.client.concept.type.Type;
31-
import graql.lang.pattern.variable.Reference;
3231
import graql.lang.common.GraqlToken;
32+
import graql.lang.pattern.variable.Reference;
3333
import org.jline.utils.AttributedString;
3434
import org.jline.utils.AttributedStyle;
3535

@@ -60,7 +60,7 @@ public void conceptMap(ConceptMap conceptMap, Grakn.Transaction tx) {
6060
}
6161

6262
public void conceptMapGroup(ConceptMapGroup answer, Grakn.Transaction tx) {
63-
for (ConceptMap conceptMap: answer.conceptMaps()) {
63+
for (ConceptMap conceptMap : answer.conceptMaps()) {
6464
out.println(conceptDisplayString(answer.owner(), tx) + " => " + conceptMapDisplayString(conceptMap, tx));
6565
}
6666
}
@@ -76,7 +76,7 @@ public void numericGroup(NumericGroup answer, Grakn.Transaction tx) {
7676
private String conceptMapDisplayString(ConceptMap conceptMap, Grakn.Transaction tx) {
7777
StringBuilder sb = new StringBuilder();
7878
sb.append("{ ");
79-
for (Map.Entry<String, Concept> entry: conceptMap.map().entrySet()) {
79+
for (Map.Entry<String, Concept> entry : conceptMap.map().entrySet()) {
8080
Reference.Name variable = Reference.named(entry.getKey());
8181
Concept concept = entry.getValue();
8282
sb.append(variable.syntax());

conf/logback/logback.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@
1515
~ along with this program. If not, see <https://www.gnu.org/licenses/>.
1616
-->
1717
<configuration debug="false">
18-
<root level="OFF" />
18+
<root level="OFF"/>
1919
</configuration>

dependencies/graknlabs/repositories.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@ def graknlabs_client_java():
3535
git_repository(
3636
name = "graknlabs_client_java",
3737
remote = "https://github.com/graknlabs/client-java",
38-
commit = "0ae01423da842b47669929975d50de307567fc2e", # sync-marker: do not remove this comment, this is used for sync-dependencies by @graknlabs_client_java
38+
commit = "d41db8972e07b5574482b008137ad152f38e919f", # sync-marker: do not remove this comment, this is used for sync-dependencies by @graknlabs_client_java
3939
)

0 commit comments

Comments
 (0)