kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 5ae0bc16ca8c5214d1b1081a08a218868a9aa7173c7c1b4e9b333cd2e8809b2c |
|---|---|
| Author | Dan Jatnieks <danj@datastax.com> · 2016-04-29 17:31 +02:00 |
| Committer | Alexandre Dutra <alexandre.dutra@datastax.com> · 2016-04-29 17:42 +02:00 |
| Parents | 6d192516fada |
6 files changed
modified changelog/README.md +1 −0
| @@ -19,6 +19,7 @@ | ||
| 19 | 19 | - [bug] JAVA-1137: Incorrect string returned by DataType.asFunctionParameterString() for collections and tuples. |
| 20 | 20 | - [bug] JAVA-1046: (Dynamic)CompositeTypes need to be parsed as string literal, not blob. |
| 21 | 21 | - [improvement] JAVA-1164: Clarify documentation on Host.listenAddress and broadcastAddress. |
| 22 | +- [improvement] JAVA-1171: Add Host method to determine if DSE Graph is enabled. | |
| 22 | 23 | |
| 23 | 24 | Merged from 2.1 branch: |
| 24 | 25 |
modified driver-core/src/main/java/com/datastax/driver/core/ControlConnection.java +9 −0
| @@ -506,6 +506,10 @@ | ||
| 506 | 506 | String dseWorkload = row.getString("workload"); |
| 507 | 507 | host.setDseWorkload(dseWorkload); |
| 508 | 508 | } |
| 509 | + if (row.getColumnDefinitions().contains("graph")) { | |
| 510 | + boolean isDseGraph = row.getBool("graph"); | |
| 511 | + host.setDseGraphEnabled(isDseGraph); | |
| 512 | + } | |
| 509 | 513 | if (row.getColumnDefinitions().contains("dse_version")) { |
| 510 | 514 | String dseVersion = row.getString("dse_version"); |
| 511 | 515 | host.setDseVersion(dseVersion); |
| @@ -575,6 +579,7 @@ | ||
| 575 | 579 | List<InetAddress> listenAddresses = new ArrayList<InetAddress>(); |
| 576 | 580 | List<Set<String>> allTokens = new ArrayList<Set<String>>(); |
| 577 | 581 | List<String> dseVersions = new ArrayList<String>(); |
| 582 | + List<Boolean> dseGraphEnabled = new ArrayList<Boolean>(); | |
| 578 | 583 | List<String> dseWorkloads = new ArrayList<String>(); |
| 579 | 584 | |
| 580 | 585 | for (Row row : peersFuture.get()) { |
| @@ -593,6 +598,8 @@ | ||
| 593 | 598 | listenAddresses.add(listenAddress); |
| 594 | 599 | String dseWorkload = row.getColumnDefinitions().contains("workload") ? row.getString("workload") : null; |
| 595 | 600 | dseWorkloads.add(dseWorkload); |
| 601 | + Boolean isDseGraph = row.getColumnDefinitions().contains("graph") ? row.getBool("graph") : null; | |
| 602 | + dseGraphEnabled.add(isDseGraph); | |
| 596 | 603 | String dseVersion = row.getColumnDefinitions().contains("dse_version") ? row.getString("dse_version") : null; |
| 597 | 604 | dseVersions.add(dseVersion); |
| 598 | 605 | } |
| @@ -626,6 +633,8 @@ | ||
| 626 | 633 | host.setDseVersion(dseVersions.get(i)); |
| 627 | 634 | if (dseWorkloads.get(i) != null) |
| 628 | 635 | host.setDseWorkload(dseWorkloads.get(i)); |
| 636 | + if (dseGraphEnabled.get(i) != null) | |
| 637 | + host.setDseGraphEnabled(dseGraphEnabled.get(i)); | |
| 629 | 638 | |
| 630 | 639 | if (metadataEnabled && partitioner != null && !allTokens.get(i).isEmpty()) |
| 631 | 640 | tokenMap.put(host, allTokens.get(i)); |
modified driver-core/src/main/java/com/datastax/driver/core/Host.java +14 −0
| @@ -75,6 +75,7 @@ | ||
| 75 | 75 | private volatile Set<Token> tokens; |
| 76 | 76 | |
| 77 | 77 | private volatile String dseWorkload; |
| 78 | + private volatile boolean dseGraphEnabled; | |
| 78 | 79 | private volatile VersionNumber dseVersion; |
| 79 | 80 | |
| 80 | 81 | // ClusterMetadata keeps one Host object per inet address and we rely on this (more precisely, |
| @@ -132,6 +133,10 @@ | ||
| 132 | 133 | this.dseWorkload = dseWorkload; |
| 133 | 134 | } |
| 134 | 135 | |
| 136 | + void setDseGraphEnabled(boolean dseGraphEnabled) { | |
| 137 | + this.dseGraphEnabled = dseGraphEnabled; | |
| 138 | + } | |
| 139 | + | |
| 135 | 140 | /** |
| 136 | 141 | * Returns the address that the driver will use to connect to the node. |
| 137 | 142 | * <p/> |
| @@ -269,6 +274,15 @@ | ||
| 269 | 274 | return dseWorkload; |
| 270 | 275 | } |
| 271 | 276 | |
| 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 | + | |
| 272 | 286 | /** |
| 273 | 287 | * Returns the tokens that this host owns. |
| 274 | 288 | * |
modified driver-core/src/test/java/com/datastax/driver/core/HostAssert.java +10 −0
| @@ -150,6 +150,16 @@ | ||
| 150 | 150 | return this; |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | + public HostAssert hasDseGraph() { | |
| 154 | + assertThat(actual.isDseGraphEnabled()).isTrue(); | |
| 155 | + return this; | |
| 156 | + } | |
| 157 | + | |
| 158 | + public HostAssert hasNoDseGraph() { | |
| 159 | + assertThat(actual.isDseGraphEnabled()).isFalse(); | |
| 160 | + return this; | |
| 161 | + } | |
| 162 | + | |
| 153 | 163 | public HostAssert hasListenAddress(InetAddress address) { |
| 154 | 164 | assertThat(actual.getListenAddress()).isNotNull().isEqualTo(address); |
| 155 | 165 | return this; |
modified driver-core/src/test/java/com/datastax/driver/core/HostMetadataIntegrationTest.java +79 −1
| @@ -80,7 +80,7 @@ | ||
| 80 | 80 | * @test_category host:metadata |
| 81 | 81 | * @jira_ticket JAVA-1042 |
| 82 | 82 | */ |
| 83 | - @Test(groups = "short'") | |
| 83 | + @Test(groups = "short") | |
| 84 | 84 | public void should_parse_dse_workload_and_version_if_available() { |
| 85 | 85 | // given: A 5 node cluster with all nodes having a workload and dse_version except node 2. |
| 86 | 86 | ScassandraCluster scassandraCluster = ScassandraCluster.builder() |
| @@ -206,6 +206,84 @@ | ||
| 206 | 206 | } |
| 207 | 207 | } |
| 208 | 208 | |
| 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 | + | |
| 209 | 287 | /** |
| 210 | 288 | * Validates that {@link Host#getBroadcastAddress()} is set for all hosts (control host or not) in the default |
| 211 | 289 | * 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 @@ | ||
| 300 | 300 | addPeerInfo(row, dc, n + 1, "release_version", getPeerInfo(dc, n + 1, "release_version", "2.1.8")); |
| 301 | 301 | addPeerInfo(row, dc, n + 1, "tokens", ImmutableSet.of(tokens.get(n))); |
| 302 | 302 | addPeerInfo(row, dc, n + 1, "schema_version", schemaVersion); |
| 303 | + addPeerInfo(row, dc, n + 1, "graph", false); | |
| 303 | 304 | |
| 304 | 305 | // These columns might not always be present, we don't have to specify them in the scassandra |
| 305 | 306 | // column metadata as it will default them to text columns. |
| @@ -317,6 +318,7 @@ | ||
| 317 | 318 | addPeerInfo(row, dc, n + 1, "tokens", ImmutableSet.of(Long.toString(tokens.get(n)))); |
| 318 | 319 | addPeerInfo(row, dc, n + 1, "host_id", UUIDs.random()); |
| 319 | 320 | addPeerInfo(row, dc, n + 1, "schema_version", schemaVersion); |
| 321 | + addPeerInfo(row, dc, n + 1, "graph", false); | |
| 320 | 322 | |
| 321 | 323 | addPeerInfoIfExists(row, dc, n + 1, "listen_address"); |
| 322 | 324 | addPeerInfoIfExists(row, dc, n + 1, "dse_version"); |
| @@ -407,6 +409,7 @@ | ||
| 407 | 409 | column("tokens", set(TEXT)), |
| 408 | 410 | column("listen_address", INET), |
| 409 | 411 | column("host_id", UUID), |
| 412 | + column("graph", BOOLEAN), | |
| 410 | 413 | column("schema_version", UUID) |
| 411 | 414 | }; |
| 412 | 415 | |
| @@ -422,6 +425,7 @@ | ||
| 422 | 425 | column("rack", TEXT), |
| 423 | 426 | column("release_version", TEXT), |
| 424 | 427 | column("tokens", set(TEXT)), |
| 428 | + column("graph", BOOLEAN), | |
| 425 | 429 | column("schema_version", UUID) |
| 426 | 430 | }; |
| 427 | 431 |