Add support for Cassandra
Add connectors for Cassandra Cluster instances with Java and XML-based configuration. Cassandra configuration is obtained using the single-tenant Datastax/Cassandra tile.
This commit is contained in:
committed by
Scott Frederick
parent
1025d64001
commit
0fed877eba
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.service.common;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.cloud.service.BaseServiceInfo;
|
||||
import org.springframework.cloud.service.ServiceInfo.ServiceLabel;
|
||||
|
||||
/**
|
||||
* {@link org.springframework.cloud.service.ServiceInfo} for a Cassandra/Datastax DSE
|
||||
* service.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@ServiceLabel("cassandra")
|
||||
public class CassandraServiceInfo extends BaseServiceInfo {
|
||||
|
||||
private final List<String> contactPoints;
|
||||
private final int port;
|
||||
private final String username;
|
||||
private final String password;
|
||||
|
||||
/**
|
||||
* Creates a new {@link CassandraServiceInfo} using Contact points and port.
|
||||
*
|
||||
* @param id the service-id
|
||||
* @param contactPoints list of contact-points
|
||||
* @param port the port
|
||||
*/
|
||||
public CassandraServiceInfo(String id, List<String> contactPoints, int port) {
|
||||
this(id, contactPoints, port, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link CassandraServiceInfo} using Contact points with a port and
|
||||
* username/password credentials.
|
||||
*
|
||||
* @param id the service-id
|
||||
* @param contactPoints list of contact-points
|
||||
* @param port the port
|
||||
* @param username the user name
|
||||
* @param password the password
|
||||
*/
|
||||
public CassandraServiceInfo(String id, List<String> contactPoints, int port,
|
||||
String username, String password) {
|
||||
super(id);
|
||||
|
||||
this.contactPoints = contactPoints;
|
||||
this.port = port;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
@ServiceProperty(category = "contactpoints")
|
||||
public List<String> getContactPoints() {
|
||||
return contactPoints;
|
||||
}
|
||||
|
||||
@ServiceProperty(category = "port")
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
@ServiceProperty(category = "username")
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
@ServiceProperty(category = "password")
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.service.common;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link CassandraServiceInfo}.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class CassandraServiceInfoUnitTests {
|
||||
|
||||
@Test
|
||||
public void shouldContainContactPointsAndPort() {
|
||||
|
||||
CassandraServiceInfo info = new CassandraServiceInfo("cassandra",
|
||||
Collections.singletonList("10.0.0.1"), 9042);
|
||||
|
||||
assertThat(info.getContactPoints(), hasItem("10.0.0.1"));
|
||||
assertThat(info.getPort(), is(equalTo(9042)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldContainContactPointsAndPortAndCredentials() {
|
||||
|
||||
CassandraServiceInfo info = new CassandraServiceInfo("cassandra",
|
||||
Collections.singletonList("10.0.0.1"), 9042, "walter", "white");
|
||||
|
||||
assertThat(info.getContactPoints(), hasItem("10.0.0.1"));
|
||||
assertThat(info.getPort(), is(equalTo(9042)));
|
||||
assertThat(info.getUsername(), is(equalTo("walter")));
|
||||
assertThat(info.getPassword(), is(equalTo("white")));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user