Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
java: [ '8', '11' ]
java: [ '17' ]
name: Java ${{ matrix.Java }} build
steps:
- uses: actions/checkout@v2
- name: Set up JDK
uses: actions/setup-java@v2
uses: actions/setup-java@v3
with:
java-version: ${{ matrix.java }}
distribution: adopt
Expand Down
2 changes: 1 addition & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ You can access the stable release from maven central using the coordinates
<dependency>
<groupId>io.pivotal.cfenv</groupId>
<artifactId>java-cfenv-boot</artifactId>
<version>2.4.0</version>
<version>3.0.0</version>
</dependency>
----

Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
buildscript {
ext {
jmockitVersion = "1.49"
springBootVersion = "2.6.6"
jmockitVersion = "1.49.2"
springBootVersion = "3.1.0"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@ plugins {
}

ext {
springFrameworkVersion = "5.3.8"
javaApi = "https://docs.oracle.com/javase/8/docs/api/"
if (JavaVersion.current() >= JavaVersion.VERSION_11) {
javaApi = "https://docs.oracle.com/en/java/javase/11/docs/api"
}
springFrameworkVersion = "6.0.9"
javaApi = "https://docs.oracle.com/javase/17/docs/api/"
javadocLinks = [
javaApi,
"https://docs.spring.io/spring-framework/docs/${springFrameworkVersion}/javadoc-api/"
Expand All @@ -23,7 +20,7 @@ java {
withJavadocJar()
withSourcesJar()
toolchain {
languageVersion = JavaLanguageVersion.of(8)
languageVersion = JavaLanguageVersion.of(17)
}
}

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
org.gradle.parallel=true

group=io.pivotal.cfenv
version=2.4.3-SNAPSHOT
version=3.0.0-SNAPSHOT
onlyShowStandardStreamsOnTestFailure=false

2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion java-cfenv-boot-pivotal-sso/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dependencies {

testImplementation project(':java-cfenv-test-support')
testImplementation "junit:junit"
testImplementation "org.jmockit:jmockit:${jmockitVersion}"
testImplementation "com.github.hazendaz.jmockit:jmockit:${jmockitVersion}"

testRuntimeOnly('org.junit.vintage:junit-vintage-engine') {
exclude group: 'org.hamcrest', module: 'hamcrest-core'
Expand Down
24 changes: 24 additions & 0 deletions java-cfenv-boot/README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
=== Redis
Type: `redis`
Disable Property: `cfenv.service.redis.enabled`

==== Spring Boot 3 properties

| Property | Value |
|-------------------------------------------|---------------------------|
| `spring.data.redis.host` | `{host}` |
| `spring.data.redis.password` | `{password}` |
| `spring.data.redis.port` | `{port}` |
| `spring.data.redis.ssl` | `{ssl}` |

Not supported, compared to `spring-cloud-bindings`:

| Property | Value |
|-------------------------------------------|---------------------------|
| `spring.data.redis.client-name` | `{client-name}` |
| `spring.data.redis.cluster.max-redirects` | `{cluster.max-redirects}` |
| `spring.data.redis.cluster.nodes` | `{cluster.nodes}` |
| `spring.data.redis.database` | `{database}` |
| `spring.data.redis.sentinel.master` | `{sentinel.master}` |
| `spring.data.redis.sentinel.nodes` | `{sentinel.nodes}` |
| `spring.data.redis.url` | `{url}` |
2 changes: 1 addition & 1 deletion java-cfenv-boot/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ dependencies {

testImplementation testFixtures(project(':java-cfenv'))
testImplementation project(':java-cfenv-test-support')
testImplementation "org.jmockit:jmockit:${jmockitVersion}"
testImplementation "com.github.hazendaz.jmockit:jmockit:${jmockitVersion}"

testRuntimeOnly('org.junit.vintage:junit-vintage-engine') {
exclude group: 'org.hamcrest', module: 'hamcrest-core'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,36 +28,37 @@
*/
public class CassandraCfEnvProcessor implements CfEnvProcessor {

@Override
public boolean accept(CfService service) {
boolean serviceIsBound = service.existsByTagIgnoreCase("cassandra") &&
cassandraCredentialsPresent(service.getCredentials().getMap());
if (serviceIsBound) {
ConnectorLibraryDetector.assertNoConnectorLibrary();
}
return serviceIsBound;
}

@Override
public void process(CfCredentials cfCredentials, Map<String, Object> properties) {
properties.put("spring.data.cassandra.username", cfCredentials.getUsername());
properties.put("spring.data.cassandra.password", cfCredentials.getPassword());
properties.put("spring.data.cassandra.port", cfCredentials.getMap().get("cqlsh_port"));
ArrayList<String> contactPoints = (ArrayList<String>) cfCredentials.getMap().get("node_ips");
properties.put("spring.data.cassandra.contact-points",
StringUtils.collectionToCommaDelimitedString(contactPoints));

}

private boolean cassandraCredentialsPresent(Map<String, Object> credentials) {
return credentials != null &&
credentials.containsKey("cqlsh_port") &&
credentials.containsKey("node_ips");
}

@Override
public CfEnvProcessorProperties getProperties() {
return CfEnvProcessorProperties.builder().propertyPrefixes("spring.data.cassandra")
.serviceName("Cassandra").build();
}
private static final String PREFIX = "spring.cassandra";

@Override
public boolean accept(CfService service) {
boolean serviceIsBound = service.existsByTagIgnoreCase("cassandra") &&
cassandraCredentialsPresent(service.getCredentials().getMap());
if (serviceIsBound) {
ConnectorLibraryDetector.assertNoConnectorLibrary();
}
return serviceIsBound;
}

@Override
public void process(CfCredentials cfCredentials, Map<String, Object> properties) {
properties.put(PREFIX + ".username", cfCredentials.getUsername());
properties.put(PREFIX + ".password", cfCredentials.getPassword());
properties.put(PREFIX + ".port", cfCredentials.getMap().get("cqlsh_port"));
ArrayList<String> contactPoints = (ArrayList<String>) cfCredentials.getMap().get("node_ips");
properties.put(PREFIX + ".contact-points",
StringUtils.collectionToCommaDelimitedString(contactPoints));
}

@Override
public CfEnvProcessorProperties getProperties() {
return CfEnvProcessorProperties.builder().propertyPrefixes(PREFIX)
.serviceName("Cassandra").build();
}

static boolean cassandraCredentialsPresent(Map<String, Object> credentials) {
return credentials != null &&
credentials.containsKey("cqlsh_port") &&
credentials.containsKey("node_ips");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.cloud.CloudPlatform;
import org.springframework.boot.context.config.ConfigFileApplicationListener;
import org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor;
import org.springframework.boot.context.event.ApplicationPreparedEvent;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
Expand All @@ -47,7 +47,7 @@ public class CfDataSourceEnvironmentPostProcessor implements CfServiceEnablingEn
private static int invocationCount;

// After ConfigFileApplicationListener so values from files can be used here
private int order = ConfigFileApplicationListener.DEFAULT_ORDER + 1;
private int order = ConfigDataEnvironmentPostProcessor.ORDER + 1;

@Override
public int getOrder() {
Expand All @@ -64,7 +64,7 @@ public void postProcessEnvironment(ConfigurableEnvironment environment,
increaseInvocationCount();
if (CloudPlatform.CLOUD_FOUNDRY.isActive(environment)) {
CfJdbcEnv cfJdbcEnv = new CfJdbcEnv();
CfJdbcService cfJdbcService = null;
CfJdbcService cfJdbcService;
try {
cfJdbcService = cfJdbcEnv.findJdbcService();
cfJdbcService = this.isEnabled(cfJdbcService, environment) ? cfJdbcService : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.cloud.CloudPlatform;
import org.springframework.boot.context.config.ConfigFileApplicationListener;
import org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor;
import org.springframework.boot.context.event.ApplicationPreparedEvent;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
Expand Down Expand Up @@ -57,7 +57,7 @@ public class CfEnvironmentPostProcessor implements
private static int invocationCount;

// After ConfigFileApplicationListener so values from files can be used here
private int order = ConfigFileApplicationListener.DEFAULT_ORDER + 1;
private int order = ConfigDataEnvironmentPostProcessor.ORDER + 1;

public CfEnvironmentPostProcessor() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,54 +31,54 @@
*/
public class RedisCfEnvProcessor implements CfEnvProcessor {

private static String[] redisSchemes = { "redis", "rediss" };
private final static String[] redisSchemes = {"redis", "rediss"};

@Override
public boolean accept(CfService service) {
boolean serviceIsBound = service.existsByTagIgnoreCase("redis") ||
service.existsByLabelStartsWith("rediscloud") ||
service.existsByUriSchemeStartsWith(redisSchemes) ||
service.existsByCredentialsContainsUriField(redisSchemes);
if (serviceIsBound) {
ConnectorLibraryDetector.assertNoConnectorLibrary();
}
return serviceIsBound;
}
private static final String PREFIX = "spring.data.redis";

@Override
public void process(CfCredentials cfCredentials, Map<String, Object> properties) {
String uri = cfCredentials.getUri(redisSchemes);
@Override
public boolean accept(CfService service) {
boolean serviceIsBound = service.existsByTagIgnoreCase("redis") ||
service.existsByLabelStartsWith("rediscloud") ||
service.existsByUriSchemeStartsWith(redisSchemes) ||
service.existsByCredentialsContainsUriField(redisSchemes);
if (serviceIsBound) {
ConnectorLibraryDetector.assertNoConnectorLibrary();
}
return serviceIsBound;
}

if (uri == null) {
properties.put("spring.redis.host", cfCredentials.getHost());
properties.put("spring.redis.password", cfCredentials.getPassword());
@Override
public void process(CfCredentials cfCredentials, Map<String, Object> properties) {
String uri = cfCredentials.getUri(redisSchemes);

Optional<String> tlsPort = Optional.ofNullable(cfCredentials.getString("tls_port"));
if (tlsPort.isPresent()) {
properties.put("spring.redis.port", tlsPort.get());
properties.put("spring.redis.ssl", "true");
}
else {
properties.put("spring.redis.port", cfCredentials.getPort());
}
}
else {
UriInfo uriInfo = new UriInfo(uri);
properties.put("spring.redis.host", uriInfo.getHost());
properties.put("spring.redis.port", uriInfo.getPort());
properties.put("spring.redis.password", uriInfo.getPassword());
if (uriInfo.getScheme().equals("rediss")) {
properties.put("spring.redis.ssl", "true");
}
}
}
if (uri == null) {
properties.put(PREFIX + ".host", cfCredentials.getHost());
properties.put(PREFIX + ".password", cfCredentials.getPassword());

@Override
public CfEnvProcessorProperties getProperties() {
return CfEnvProcessorProperties.builder()
.propertyPrefixes("spring.redis")
.serviceName("Redis")
.build();
}
Optional<String> tlsPort = Optional.ofNullable(cfCredentials.getString("tls_port"));
if (tlsPort.isPresent()) {
properties.put(PREFIX + ".port", tlsPort.get());
properties.put(PREFIX + ".ssl", "true");
} else {
properties.put(PREFIX + ".port", cfCredentials.getPort());
}
} else {
UriInfo uriInfo = new UriInfo(uri);
properties.put(PREFIX + ".host", uriInfo.getHost());
properties.put(PREFIX + ".port", uriInfo.getPort());
properties.put(PREFIX + ".password", uriInfo.getPassword());
if (uriInfo.getScheme().equals("rediss")) {
properties.put(PREFIX + ".ssl", "true");
}
}
}

@Override
public CfEnvProcessorProperties getProperties() {
return CfEnvProcessorProperties.builder()
.propertyPrefixes(PREFIX)
.serviceName("Redis")
.build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,38 +30,45 @@
*/
public class CassandraCfEnvProcessorTests extends AbstractCfEnvTests {

public static final String SPRING_CASSANDRA = "spring.cassandra";

@Test
public void simpleService() {
mockVcapServicesWithNames("io/pivotal/cfenv/spring/boot/test-cassandra-service.json");
Environment environment = getEnvironment();
assertThat(environment.getProperty("spring.data.cassandra.username")).isNull();
assertThat(environment.getProperty("spring.data.cassandra.password")).isNull();
assertThat(environment.getProperty("spring.data.cassandra.port")).isEqualTo("9042");
assertThat(environment.getProperty("spring.data.cassandra.contact-points")).contains("1.2.3.4","5.6.7.8");
assertThat(environment.getProperty(SPRING_CASSANDRA + ".username")).isNull();
assertThat(environment.getProperty(SPRING_CASSANDRA + ".password")).isNull();
assertThat(environment.getProperty(SPRING_CASSANDRA + ".port")).isEqualTo("9042");
assertThat(environment.getProperty(SPRING_CASSANDRA + ".contact-points")).contains("1.2.3.4","5.6.7.8");
}

@Test
public void simpleServiceUserNamePassword() {
mockVcapServicesWithNames("io/pivotal/cfenv/spring/boot/test-cassandra-with-credentials.json");
Environment environment = getEnvironment();
assertThat(environment.getProperty("spring.data.cassandra.username")).isEqualTo("user");
assertThat(environment.getProperty("spring.data.cassandra.password")).isEqualTo("pass");
assertThat(environment.getProperty("spring.data.cassandra.port")).isEqualTo("9042");
assertThat(environment.getProperty("spring.data.cassandra.contact-points")).contains("1.2.3.4");
assertThat(environment.getProperty(SPRING_CASSANDRA + ".username")).isEqualTo("user");
assertThat(environment.getProperty(SPRING_CASSANDRA + ".password")).isEqualTo("pass");
assertThat(environment.getProperty(SPRING_CASSANDRA + ".port")).isEqualTo("9042");
assertThat(environment.getProperty(SPRING_CASSANDRA + ".contact-points")).contains("1.2.3.4");
}

@Test
public void serviceNotValid() {
mockVcapServicesWithNames("io/pivotal/cfenv/spring/boot/test-cassandra-missing-required-fields.json");
Environment environment = getEnvironment();
assertThat(environment.getProperty("spring.data.cassandra.username")).isNull();
assertThat(environment.getProperty("spring.data.cassandra.password")).isNull();
assertThat(environment.getProperty("spring.data.cassandra.port")).isNull();
assertThat(environment.getProperty("spring.data.cassandra.contact-points")).isNull();
assertThat(environment.getProperty(SPRING_CASSANDRA + ".username")).isNull();
assertThat(environment.getProperty(SPRING_CASSANDRA + ".password")).isNull();
assertThat(environment.getProperty(SPRING_CASSANDRA + ".port")).isNull();
assertThat(environment.getProperty(SPRING_CASSANDRA + ".contact-points")).isNull();
}

@Test
public void testGetProperties() {
assertThat(new CassandraCfEnvProcessor().getProperties().getPropertyPrefixes()).isEqualTo(SPRING_CASSANDRA);
assertThat(new CassandraCfEnvProcessor().getProperties().getServiceName()).isEqualTo("Cassandra");
}

private void mockVcapServicesWithNames(String fileName) {
CfEnvMock.configure().vcapServicesResource(fileName).mock();

}
}
Loading