8000 merge latest master · forumjava/spring-data-cassandra@f834ba1 · GitHub
[go: up one dir, main page]

Skip to content

Commit f834ba1

Browse files
committed
merge latest master
2 parents 1f4b84c + d348f35 commit f834ba1

File tree

8 files changed

+254
-26
lines changed

8 files changed

+254
-26
lines changed

spring-cassandra/src/main/java/org/springframework/cassandra/config/CassandraClusterFactoryBean.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,11 @@
3939

4040
import com.datastax.driver.core.AuthProvider;
4141
import com.datastax.driver.core.Cluster;
42+
import com.datastax.driver.core.Host;
43+
import com.datastax.driver.core.LatencyTracker;
4244
import com.datastax.driver.core.PoolingOptions;
4345
import com.datastax.driver.core.ProtocolOptions.Compression;
46+
import com.datastax.driver.core.SSLOptions;
4447
import com.datastax.driver.core.Session;
4548
import com.datastax.driver.core.SocketOptions;
4649
import com.datastax.driver.core.policies.LoadBalancingPolicy;
@@ -61,6 +64,7 @@ public class CassandraClusterFactoryBean implements FactoryBean<Cluster>, Initia
6164
public static final boolean DEFAULT_METRICS_ENABLED = true;
6265
public static final boolean DEFAULT_DEFERRED_INITIALIZATION = false;
6366
public static final boolean DEFAULT_JMX_REPORTING_ENABLED = true;
67+
public static final boolean DEFAULT_SSL_ENABLED = false;
6468
public static final int DEFAULT_PORT = 9042;
6569

6670
protected static final Logger log = LoggerFactory.getLogger(CassandraClusterFactoryBean.class);
@@ -84,6 +88,10 @@ public class CassandraClusterFactoryBean implements FactoryBean<Cluster>, Initia
8488
private boolean metricsEnabled = DEFAULT_METRICS_ENABLED;
8589
private boolean deferredInitialization = DEFAULT_DEFERRED_INITIALIZATION;
8690
private boolean jmxReportingEnabled = DEFAULT_JMX_REPORTING_ENABLED;
91+
private boolean sslEnabled = DEFAULT_SSL_ENABLED;
92+
private SSLOptions sslOptions;
93+
private Host.StateListener hostStateListener;
94+
private LatencyTracker latencyTracker;
8795
private Set<KeyspaceActionSpecification<?>> keyspaceSpecifications = new HashSet<KeyspaceActionSpecification<?>>();
8896
private List<CreateKeyspaceSpecification> keyspaceCreations = new ArrayList<CreateKeyspaceSpecification>();
8997
private List<DropKeyspaceSpecification> keyspaceDrops = new ArrayList<DropKeyspaceSpecification>();
@@ -167,8 +175,24 @@ public void afterPropertiesSet() throws Exception {
167175
builder.withoutJMXReporting();
168176
}
169177

178+
if (sslEnabled) {
179+
if (sslOptions == null) {
180+
builder.withSSL();
181+
} else {
182+
builder.withSSL(sslOptions);
183+
}
184+
}
185+
170186
cluster = builder.build();
171187

188+
if (hostStateListener != null) {
189+
cluster.register(hostStateListener);
190+
}
191+
192+
if (latencyTracker != null) {
193+
cluster.register(latencyTracker);
194+
}
195+
172196
generateSpecificationsFromFactoryBeans();
173197

174198
executeSpecsAndScripts(keyspaceCreations, startupScripts);
@@ -373,4 +397,32 @@ public void setDeferredInitialization(boolean deferredInitialization) {
373397
public void setJmxReportingEnabled(boolean jmxReportingEnabled) {
374398
this.jmxReportingEnabled = jmxReportingEnabled;
375399
}
400+
401+
/**
402+
* @param sslEnabled The sslEnabled to set.
403+
*/
404+
public void setSslEnabled(boolean sslEnabled) {
405+
this.sslEnabled = sslEnabled;
406+
}
407+
408+
/**
409+
* @param sslOptions The sslOptions to set.
410+
*/
411+
public void setSslOptions(SSLOptions sslOptions) {
412+
this.sslOptions = sslOptions;
413+
}
414+
415+
/**
416+
* @param hostStateListener The hostStateListener to set.
417+
*/
418+
public void setHostStateListener(Host.StateListener hostStateListener) {
419+
this.hostStateListener = hostStateListener;
420+
}
421+
422+
/**
423+
* @param latencyTracker The latencyTracker to set.
424+
*/
425+
public void setLatencyTracker(LatencyTracker latencyTracker) {
426+
this.latencyTracker = latencyTracker;
427+
}
376428
}

spring-cassandra/src/main/java/org/springframework/cassandra/config/xml/CassandraClusterParser.java

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,6 @@ protected void doParse(Element element, ParserContext context, BeanDefinitionBui
110110
builder.addPropertyValue("compressionType", compression);
111111
}
112112

113-
String authProvider = element.getAttribute("auth-info-provider-ref");
114-
if (StringUtils.hasText(authProvider)) {
115-
builder.addPropertyReference("authProvider", authProvider);
116-
}
117-
118113
String username = element.getAttribute("username");
119114
if (StringUtils.hasText(username)) {
120115
builder.addPropertyValue("username", username);
@@ -140,6 +135,16 @@ protected void doParse(Element element, ParserContext context, BeanDefinitionBui
140135
builder.addPropertyValue("jmxReportingEnabled", jmxReportingEnabled);
141136
}
142137

138+
String sslEnabled = element.getAttribute("sslEnabled");
139+
if (StringUtils.hasText(sslEnabled)) {
140+
builder.addPropertyValue("sslEnabled", sslEnabled);
141+
}
142+
143+
String authProvider = element.getAttribute("auth-info-provider-ref");
144+
if (StringUtils.hasText(authProvider)) {
145+
builder.addPropertyReference("authProvider", authProvider);
146+
}
147+
143148
String loadBalancingPolicy = element.getAttribute("load-balancing-policy-ref");
144149
if (StringUtils.hasText(loadBalancingPolicy)) {
145150
builder.addPropertyReference("loadBalancingPolicy", loadBalancingPolicy);
@@ -155,6 +160,21 @@ protected void doParse(Element element, ParserContext context, BeanDefinitionBui
155160
builder.addPropertyReference("retryPolicy", retryPolicy);
156161
}
157162

163+
String sslOptions = element.getAttribute("ssl-options-ref");
164+
if (StringUtils.hasText(sslOptions)) {
165+
builder.addPropertyReference("sslOptions", sslOptions);
166+
}
167+
168+
String hostStateListener = element.getAttribute("host-state-listener-ref");
169+
if (StringUtils.hasText(hostStateListener)) {
170+
builder.addPropertyReference("hostStateListener", hostStateListener);
171+
}
172+
173+
String latencyTracker = element.getAttribute("latency-tracker-ref");
174+
if (StringUtils.hasText(latencyTracker)) {
175+
builder.addPropertyReference("latencyTracker", latencyTracker);
176+
}
177+
158178
parseChildElements(element, context, builder);
159179
}
160180

spring-cassandra/src/main/resources/org/springframework/cassandra/config/spring-cassandra-1.0.xsd

Lines changed: 80 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -136,23 +136,6 @@ The protocol compression option. Default is "NONE".
136136
</xsd:annotation>
137137
</xsd:attribute>
138138

139-
<xsd:attribute name="auth-info-provider-ref" use="optional">
140-
<xsd:annotation>
141-
<xsd:documentation><![CDATA[
142-
AuthInfoProvider implementation.
143-
]]></xsd:documentation>
144-
</xsd:annotation>
145-
<xsd:simpleType>
146-
<xsd:annotation>
147-
<xsd:appinfo>
148-
<tool:annotation kind="ref">
149-
<tool:assignable-to type="com.datastax.driver.core.AuthInfoProvider" />
150-
</tool:annotation>
151-
</xsd:appinfo>
152-
</xsd:annotation>
153-
<xsd:union memberTypes="xsd:string" />
154-
</xsd:simpleType>
155-
</xsd:attribute>
156139
<xsd:attribute name="username" type="xsd:string" use="optional">
157140
<xsd:annotation>
158141
<xsd:documentation><![CDATA[
@@ -189,7 +172,31 @@ Determine if we defer initalizing the cluster until a connection is requested. D
189172
]]></xsd:documentation>
190173
</xsd:annotation>
191174
</xsd:attribute>
192-
<xsd:attribute name="load-balancing-policy-ref" use="optional">
175+
<xsd:attribute name="sslEnabled" type="xsd:string" default="false">
176+
<xsd:annotation>
177+
<xsd:documentation><![CDATA[
178+
Determine if SSL is used for Cassandra communication. Defaults to false.
179+
]]></xsd:documentation>
180+
</xsd:annotation>
181+
</xsd:attribute>
182+
<xsd:attribute name="auth-info-provider-ref" use="optional">
183+
<xsd:annotation>
184+
<xsd:documentation><![CDATA[
185+
AuthInfoProvider implementation.
186+
]]></xsd:documentation>
187+
</xsd:annotation>
188+
<xsd:simpleType>
189+
<xsd:annotation>
190+
<xsd:appinfo>
191+
<tool:annotation kind="ref">
192+
<tool:assignable-to type="com.datastax.driver.core.AuthInfoProvider" />
193+
</tool:annotation>
194+
</xsd:appinfo>
195+
</xsd:annotation>
196+
<xsd:union memberTypes="xsd:string" />
197+
</xsd:simpleType>
198+
</xsd:attribute>
199+
<xsd:attribute name="load-balancing-policy-ref" use="optional">
193200
<xsd:annotation>
194201
<xsd:documentation><![CDATA[
195202
LoadBalancingPolicy implementation.
@@ -243,6 +250,60 @@ RetryPolicy implementation.
243250
<xsd:union memberTypes="xsd:string" />
244251
</xsd:simpleType>
245252
</xsd:attribute>
253+
<xsd:attribute name="ssl-options-ref" use="optional">
254+
<xsd:annotation>
255+
<xsd:documentation><![CDATA[
256+
Custom SSL Options. sslEnabled must be true for sslOptions to be used.
257+
]]></xsd:documentation>
258+
</xsd:annotation>
259+
<xsd:simpleType>
260+
<xsd:annotation>
261+
<xsd:appinfo>
262+
<tool:annotation kind="ref">
263+
<tool:assignable-to
264+
type="com.datastax.driver.core.SSLOptions" />
265+
</tool:annotation>
266+
</xsd:appinfo>
267+
</xsd:annotation>
268+
<xsd:union memberTypes="xsd:string" />
269+
</xsd:simpleType>
270+
</xsd:attribute>
271+
<xsd:attribute name="host-state-listener-ref" use="optional">
272+
<xsd:annotation>
273+
<xsd:documentation><![CDATA[
274+
Custom Host State Listener for the Cassandra Cluster.
275+
]]></xsd:documentation>
276+
</xsd:annotation>
277+
<xsd:simpleType>
278+
<xsd:annotation>
279+
<xsd:appinfo>
280+
<tool:annotation kind="ref">
281+
<tool:assignable-to
282+
type="com.datastax.driver.core.Host.StateListener" />
283+
</tool:annotation>
284+
</xsd:appinfo>
285+
</xsd:annotation>
286+
<xsd:union memberTypes="xsd:string" />
287+
</xsd:simpleType>
288+
</xsd:attribute>
289+
<xsd:attribute name="latency-tracker-ref" use="optional">
290+
<xsd:annotation>
291+
<xsd:documentation><![CDATA[
292+
Custom Latency Tracker for the Cassandra Cluster.
293+
]]></xsd:documentation>
294+
</xsd:annotation>
295+
<xsd:simpleType>
296+
<xsd:annotation>
297+
<xsd:appinfo>
298+
<tool:annotation kind="ref">
299+
<tool:assignable-to
300+
type="com.datastax.driver.core.LatencyTracker" />
301+
</tool:annotation>
302+
</xsd:appinfo>
303+
</xsd:annotation>
304+
<xsd:union memberTypes="xsd:string" />
305+
</xsd:simpleType>
306+
</xsd:attribute>
246307
</xsd:complexType>
247308
<xsd:simpleType name="clusterRef" final="union">
248309
<xsd:annotation>
@@ -479,7 +540,7 @@ Provides the ability to specify replication factors by data center.
479540
default="SimpleStrategy">
480541
<xsd:annotation>
481542
<xsd:documentation><![CDATA[
482-
The name of the replication class; default is "SimpleStrategy".
543+
The name of the replication class; default is "SIMPLE_STRATEGY".
483544
]]></xsd:documentation>
484545
</xsd:annotation>
485546
</xsd:attribute>

spring-cassandra/src/test/java/org/springframework/cassandra/test/integration/AbstractEmbeddedCassandraIntegrationTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ public class AbstractEmbeddedCassandraIntegrationTest {
2424
static Logger log = LoggerFactory.getLogger(AbstractEmbeddedCassandraIntegrationTest.class);
2525

2626
protected static final BuildProperties PROPS = new BuildProperties();
27-
2827
protected static final String CASSANDRA_CONFIG = "spring-cassandra.yaml";
2928
protected static final String CASSANDRA_HOST = "localhost";
3029
protected static final int CASSANDRA_NATIVE_PORT = PROPS.getCassandraPort();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright 2011-2014 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.cassandra.test.integration.config.xml;
17+
18+
import org.slf4j.Logger;
19+
import org.slf4j.LoggerFactory;
20+
21+
import com.datastax.driver.core.Host;
22+
import com.datastax.driver.core.Host.StateListener;
23+
24+
/**
25+
* @author David Webb
26+
*
27+
*/
28+
public class TestHostStateListener implements StateListener {
29+
30+
private final static Logger log = LoggerFactory.getLogger(TestHostStateListener.class);
31+
32+
@Override
33+
public void onAdd(Host host) {
34+
log.info("Host Added: " + host.getAddress());
35+
}
36+
37+
@Override
38+
public void onUp(Host host) {
39+
log.info("Host Up: " + host.getAddress());
40+
}
41+
42+
@Override
43+
public void onDown(Host host) {
44+
log.info("Host Down: " + host.getAddress());
45+
}
46+
47+
@Override
48+
public void onRemove(Host host) {
49+
log.info("Host Removed: " + host.getAddress());
50+
}
51+
52+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2011-2014 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.cassandra.test.integration.config.xml;
17+
18+
import org.slf4j.Logger;
19+
import org.slf4j.LoggerFactory;
20+
21+
import com.datastax.driver.core.Host;
22+
import com.datastax.driver.core.LatencyTracker;
23+
24+
/**
25+
* @author David Webb
26+
*
27+
*/
28+
public class TestLatencyTracker implements LatencyTracker {
29+
30+
private final static Logger log = LoggerFactory.getLogger(TestLatencyTracker.class);
31+
32+
@Override
33+
public void update(Host host, long newLatencyNanos) {
34+
log.info("Latency Tracker: " + host.getAddress() + ", " + newLatencyNanos + " nanoseconds.");
35+
}
36+
37+
}

spring-cassandra/src/test/resources/org/springframework/cassandra/test/integration/config/xml/PropertyPlaceholderNamespaceCreatingXmlConfigTest-context.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
</bean>
2222

2323
<bean id="retryPolicy" class="com.datastax.driver.core.policies.DowngradingConsistencyRetryPolicy" />
24+
25+
<bean id="hostStateListener" class="org.springframework.cassandra.test.integration.config.xml.TestHostStateListener"/>
26+
27+
<bean id="latencyTracker" class="org.springframework.cassandra.test.integration.config.xml.TestLatencyTracker"/>
2428

2529
<cassandra:cluster id="cassandra-cluster"
2630
contactPoints="${cluster.contactPoints}" port="${cluster.port}"
@@ -29,7 +33,9 @@
2933
deferredInitialization="${cluster.deferredInit}" metricsEnabled="${cluster.metricsEnabled}"
3034
jmxReportingEnabled="${cluster.jmxReportingEnabled}"
3135
reconnection-policy-ref="reconnectionPolicy"
32-
retry-policy-ref="retryPolicy">
36+
retry-policy-ref="retryPolicy"
37+
host-state-listener-ref="hostStateListener"
38+
latency-tracker-ref="latencyTracker">
3339
<cassandra:local-pooling-options
3440
min-simultaneous-requests="${local.min.requests}"
3541
max-simultaneous-requests="${local.max.requests}"

spring-cassandra/src/test/resources/org/springframework/cassandra/test/integration/config/xml/ppncxct.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ cluster.deferredInit=true
55
cluster.metricsEnabled=false
66
cluster.jmxReportingEnabled=false
77
cluster.reconnection.delayMillis=5000
8+
cluster.sslEnabled= true
89
keyspace.name=ppncxct
910
keyspace.action=CREATE
1011
dc1.name=DCJAX

0 commit comments

Comments
 (0)
0