Elffuss BraidHub

kikocis/java-driver public

Merge pull request #658 from datastax/java1171

JAVA-1171: Add Host method to determine if DSE Graph is enabled.
Changeset0e48b8881002fb86ac504f0cf5539d5b272ba627929c2348ec924a3bb9326997
AuthorAlexandre Dutra <adutra@users.noreply.github.com> · 2016-05-02 17:13 +02:00
CommitterAlexandre Dutra <adutra@users.noreply.github.com> · 2016-05-02 17:13 +02:00
Parents6639672315a2, 5ae0bc16ca8c

Browse the files at this changeset

6 files changed

modified changelog/README.md +1 −0
@@ -19,6 +19,7 @@
1919 - [bug] JAVA-1137: Incorrect string returned by DataType.asFunctionParameterString() for collections and tuples.
2020 - [bug] JAVA-1046: (Dynamic)CompositeTypes need to be parsed as string literal, not blob.
2121 - [improvement] JAVA-1164: Clarify documentation on Host.listenAddress and broadcastAddress.
22+- [improvement] JAVA-1171: Add Host method to determine if DSE Graph is enabled.
2223
2324 Merged from 2.1 branch:
2425
modified driver-core/src/main/java/com/datastax/driver/core/ControlConnection.java +9 −0
@@ -506,6 +506,10 @@
506506 String dseWorkload = row.getString("workload");
507507 host.setDseWorkload(dseWorkload);
508508 }
509+ if (row.getColumnDefinitions().contains("graph")) {
510+ boolean isDseGraph = row.getBool("graph");
511+ host.setDseGraphEnabled(isDseGraph);
512+ }
509513 if (row.getColumnDefinitions().contains("dse_version")) {
510514 String dseVersion = row.getString("dse_version");
511515 host.setDseVersion(dseVersion);
@@ -575,6 +579,7 @@
575579 List<InetAddress> listenAddresses = new ArrayList<InetAddress>();
576580 List<Set<String>> allTokens = new ArrayList<Set<String>>();
577581 List<String> dseVersions = new ArrayList<String>();
582+ List<Boolean> dseGraphEnabled = new ArrayList<Boolean>();
578583 List<String> dseWorkloads = new ArrayList<String>();
579584
580585 for (Row row : peersFuture.get()) {
@@ -595,6 +600,8 @@
595600 listenAddresses.add(listenAddress);
596601 String dseWorkload = row.getColumnDefinitions().contains("workload") ? row.getString("workload") : null;
597602 dseWorkloads.add(dseWorkload);
603+ Boolean isDseGraph = row.getColumnDefinitions().contains("graph") ? row.getBool("graph") : null;
604+ dseGraphEnabled.add(isDseGraph);
598605 String dseVersion = row.getColumnDefinitions().contains("dse_version") ? row.getString("dse_version") : null;
599606 dseVersions.add(dseVersion);
600607 }
@@ -628,6 +635,8 @@
628635 host.setDseVersion(dseVersions.get(i));
629636 if (dseWorkloads.get(i) != null)
630637 host.setDseWorkload(dseWorkloads.get(i));
638+ if (dseGraphEnabled.get(i) != null)
639+ host.setDseGraphEnabled(dseGraphEnabled.get(i));
631640
632641 if (metadataEnabled && partitioner != null && !allTokens.get(i).isEmpty())
633642 tokenMap.put(host, allTokens.get(i));
modified driver-core/src/main/java/com/datastax/driver/core/Host.java +14 −0
@@ -75,6 +75,7 @@
7575 private volatile Set<Token> tokens;
7676
7777 private volatile String dseWorkload;
78+ private volatile boolean dseGraphEnabled;
7879 private volatile VersionNumber dseVersion;
7980
8081 // ClusterMetadata keeps one Host object per inet address and we rely on this (more precisely,
@@ -132,6 +133,10 @@
132133 this.dseWorkload = dseWorkload;
133134 }
134135
136+ void setDseGraphEnabled(boolean dseGraphEnabled) {
137+ this.dseGraphEnabled = dseGraphEnabled;
138+ }
139+
135140 /**
136141 * Returns the address that the driver will use to connect to the node.
137142 * <p/>
@@ -269,6 +274,15 @@
269274 return dseWorkload;
270275 }
271276
277+ /**
278+ * Returns whether the host is running DSE Graph.
279+ *
280+ * @return whether the node is running DSE Graph.
281+ */
282+ public boolean isDseGraphEnabled() {
283+ return dseGraphEnabled;
284+ }
285+
272286 /**
273287 * Returns the tokens that this host owns.
274288 *
modified driver-core/src/test/java/com/datastax/driver/core/HostAssert.java +10 −0
@@ -161,6 +161,16 @@
161161 return this;
162162 }
163163
164+ public HostAssert hasDseGraph() {
165+ assertThat(actual.isDseGraphEnabled()).isTrue();
166+ return this;
167+ }
168+
169+ public HostAssert hasNoDseGraph() {
170+ assertThat(actual.isDseGraphEnabled()).isFalse();
171+ return this;
172+ }
173+
164174 public HostAssert hasListenAddress(InetAddress address) {
165175 assertThat(actual.getListenAddress()).isNotNull().isEqualTo(address);
166176 return this;
modified driver-core/src/test/java/com/datastax/driver/core/HostMetadataIntegrationTest.java +79 −1
@@ -80,7 +80,7 @@
8080 * @test_category host:metadata
8181 * @jira_ticket JAVA-1042
8282 */
83- @Test(groups = "short'")
83+ @Test(groups = "short")
8484 public void should_parse_dse_workload_and_version_if_available() {
8585 // given: A 5 node cluster with all nodes having a workload and dse_version except node 2.
8686 ScassandraCluster scassandraCluster = ScassandraCluster.builder()
@@ -206,6 +206,84 @@
206206 }
207207 }
208208
209+ /**
210+ * Validates that {@link Host#isDseGraphEnabled()} returns the value defined in the <code>graph</code> columns if
211+ * it is present in <code>system.local</code> or <code>system.peers</code> otherwise it returns false.
212+ *
213+ * @test_category host:metadata
214+ * @jira_ticket JAVA-1171
215+ */
216+ @Test(groups = "short")
217+ public void should_parse_dse_graph_if_available() {
218+ // given: A 3 node cluster with all nodes having a graph value except node 2.
219+ ScassandraCluster scassandraCluster = ScassandraCluster.builder()
220+ .withIpPrefix(TestUtils.IP_PREFIX)
221+ .withNodes(3)
222+ .forcePeerInfo(1, 1, "graph", true)
223+ .forcePeerInfo(1, 3, "graph", false)
224+ .build();
225+
226+ Cluster cluster = Cluster.builder()
227+ .addContactPoints(scassandraCluster.address(1).getAddress())
228+ .withPort(scassandraCluster.getBinaryPort())
229+ .withNettyOptions(nonQuietClusterCloseOptions)
230+ .build();
231+
232+ try {
233+ scassandraCluster.init();
234+ // when: initializing a cluster instance.
235+ cluster.init();
236+
237+ // then:
238+ // - node 1 should have graph.
239+ // - node 2 and node 3 should not have graph.
240+ assertThat(cluster).host(1).hasDseGraph();
241+ assertThat(cluster).host(2).hasNoDseGraph();
242+ assertThat(cluster).host(3).hasNoDseGraph();
243+ } finally {
244+ cluster.close();
245+ scassandraCluster.stop();
246+ }
247+ }
248+
249+ /**
250+ * Validates that {@link Host#isDseGraphEnabled()} returns false if the <code>graph</code> column is not present
251+ * in <code>system.local</code> for the control host.
252+ *
253+ * @test_category host:metadata
254+ * @jira_ticket JAVA-1171
255+ */
256+ @Test(groups = "short")
257+ public void should_not_parse_dse_graph_if_not_present_in_local_table() {
258+ // given: A cluster with node 1 (control host) not having graph set, and node 2 with it set.
259+ ScassandraCluster scassandraCluster = ScassandraCluster.builder()
260+ .withIpPrefix(TestUtils.IP_PREFIX)
261+ .withNodes(2)
262+ .forcePeerInfo(1, 2, "graph", true)
263+ .build();
264+
265+ Cluster cluster = Cluster.builder()
266+ .addContactPoints(scassandraCluster.address(1).getAddress())
267+ .withPort(scassandraCluster.getBinaryPort())
268+ .withNettyOptions(nonQuietClusterCloseOptions)
269+ .build();
270+
271+ try {
272+ scassandraCluster.init();
273+ // when: initializing a cluster instance.
274+ cluster.init();
275+
276+ // then:
277+ // - node 1 should have no graph.
278+ // - node 2 should have graph.
279+ assertThat(cluster).host(1).hasNoDseGraph();
280+ assertThat(cluster).host(2).hasDseGraph();
281+ } finally {
282+ cluster.close();
283+ scassandraCluster.stop();
284+ }
285+ }
286+
209287 /**
210288 * Validates that {@link Host#getBroadcastAddress()} is set for all hosts (control host or not) in the default
211289 * case of a cluster, as the broadcast address is derived from <code>broadcast_address</code> in
modified driver-core/src/test/java/com/datastax/driver/core/ScassandraCluster.java +4 −0
@@ -300,6 +300,7 @@
300300 addPeerInfo(row, dc, n + 1, "release_version", getPeerInfo(dc, n + 1, "release_version", "2.1.8"));
301301 addPeerInfo(row, dc, n + 1, "tokens", ImmutableSet.of(tokens.get(n)));
302302 addPeerInfo(row, dc, n + 1, "schema_version", schemaVersion);
303+ addPeerInfo(row, dc, n + 1, "graph", false);
303304
304305 // These columns might not always be present, we don't have to specify them in the scassandra
305306 // column metadata as it will default them to text columns.
@@ -317,6 +318,7 @@
317318 addPeerInfo(row, dc, n + 1, "tokens", ImmutableSet.of(Long.toString(tokens.get(n))));
318319 addPeerInfo(row, dc, n + 1, "host_id", UUIDs.random());
319320 addPeerInfo(row, dc, n + 1, "schema_version", schemaVersion);
321+ addPeerInfo(row, dc, n + 1, "graph", false);
320322
321323 addPeerInfoIfExists(row, dc, n + 1, "listen_address");
322324 addPeerInfoIfExists(row, dc, n + 1, "dse_version");
@@ -407,6 +409,7 @@
407409 column("tokens", set(TEXT)),
408410 column("listen_address", INET),
409411 column("host_id", UUID),
412+ column("graph", BOOLEAN),
410413 column("schema_version", UUID)
411414 };
412415
@@ -422,6 +425,7 @@
422425 column("rack", TEXT),
423426 column("release_version", TEXT),
424427 column("tokens", set(TEXT)),
428+ column("graph", BOOLEAN),
425429 column("schema_version", UUID)
426430 };
427431