Skip to content

Commit 86ab9de

Browse files
kuldeep-singh-twfabapp2
authored andcommitted
Migrate Cassandra configuration to Spring Boot 3.0 in yaml and properties format
1 parent e122a74 commit 86ab9de

File tree

8 files changed

+171
-1
lines changed

8 files changed

+171
-1
lines changed

applications/spring-shell/src/test/java/org/springframework/sbm/BootUpgrade_27_30_IntegrationTest.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,17 @@ private void verifyYamlConfigurationUpdate() {
225225
" certificate-location: classpath:saml/idpone.crt\n" +
226226
" entity-id: https://idpone.com\n" +
227227
" sso-url: https://idpone.com\n" +
228+
" cassandra:\n" +
229+
" keyspaceName: testKeySpace\n" +
230+
" contactPoints: localhost\n" +
231+
" port: 9042\n" +
232+
" username: testusername\n" +
233+
" schemaAction: NONE\n" +
234+
" request:\n" +
235+
" timeout: 10s\n" +
236+
" connection:\n" +
237+
" connectTimeout: 10s\n" +
238+
" initQueryTimeout: 10s\n" +
228239
" elasticsearch.connection-timeout: '1000'\n" +
229240
" elasticsearch.webclient.max-in-memory-size: '122'\n" +
230241
" elasticsearch.password: abc\n" +
@@ -282,7 +293,16 @@ private void verifyPropertyConfigurationUpdate() {
282293
"spring.datasource.driverClassName=org.h2.Driver\n" +
283294
"spring.datasource.username=sa\n" +
284295
"spring.datasource.password=password\n" +
285-
"spring.jpa.database-platform=org.hibernate.dialect.H2Dialect\n");
296+
"spring.jpa.database-platform=org.hibernate.dialect.H2Dialect\n" +
297+
"\n" +
298+
"spring.cassandra.keyspace-name=testKeySpace\n" +
299+
"spring.cassandra.port=9042\n" +
300+
"spring.cassandra.contact-points=localhost\n" +
301+
"spring.cassandra.username=testusername\n" +
302+
"spring.cassandra.schema-action=NONE\n" +
303+
"spring.cassandra.request.timeout=10s\n" +
304+
"spring.cassandra.connection.connect-timeout=10s\n" +
305+
"spring.cassandra.connection.init-query-timeout=10s\n");
286306
}
287307

288308
private void verifyParentPomVersion() {

applications/spring-shell/src/test/java/org/springframework/sbm/BootUpgrade_27_30_MultiModule_IntegrationTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,17 @@ private void verifyYamlConfigurationUpdate() {
9898
" certificate-location: classpath:saml/idpone.crt\n" +
9999
" entity-id: https://idpone.com\n" +
100100
" sso-url: https://idpone.com\n" +
101+
" cassandra:\n" +
102+
" keyspaceName: testKeySpace\n" +
103+
" contactPoints: localhost\n" +
104+
" port: 9042\n" +
105+
" username: testusername\n" +
106+
" schemaAction: NONE\n" +
107+
" request:\n" +
108+
" timeout: 10s\n" +
109+
" connection:\n" +
110+
" connectTimeout: 10s\n" +
111+
" initQueryTimeout: 10s\n" +
101112
" elasticsearch.connection-timeout: '1000'\n" +
102113
" elasticsearch.webclient.max-in-memory-size: '122'\n" +
103114
" elasticsearch.password: abc\n" +
@@ -154,6 +165,16 @@ private void verifyPropertyConfigurationUpdate() {
154165
"spring.datasource.username=sa\n" +
155166
"spring.datasource.password=password\n" +
156167
"spring.jpa.database-platform=org.hibernate.dialect.H2Dialect\n" +
168+
"\n" +
169+
"spring.cassandra.keyspace-name=testKeySpace\n" +
170+
"spring.cassandra.port=9042\n" +
171+
"spring.cassandra.contact-points=localhost\n" +
172+
"spring.cassandra.username=testusername\n" +
173+
"spring.cassandra.schema-action=NONE\n" +
174+
"spring.cassandra.request.timeout=10s\n" +
175+
"spring.cassandra.connection.connect-timeout=10s\n" +
176+
"spring.cassandra.connection.init-query-timeout=10s\n" +
177+
"spring.jpa.database-platform=org.hibernate.dialect.H2Dialect\n" +
157178
"logging.pattern.dateformat=yyyy-MM-dd HH:mm:ss.SSS\n");
158179
}
159180

applications/spring-shell/src/test/resources/testcode/boot-migration-27-30-multi-module/spring-app/src/main/resources/application.properties

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,12 @@ spring.datasource.driverClassName=org.h2.Driver
119119
spring.datasource.username=sa
120120
spring.datasource.password=password
121121
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
122+
123+
spring.data.cassandra.keyspace-name=testKeySpace
124+
spring.data.cassandra.port=9042
125+
spring.data.cassandra.contact-points=localhost
126+
spring.data.cassandra.username=testusername
127+
spring.data.cassandra.schema-action=NONE
128+
spring.data.cassandra.request.timeout=10s
129+
spring.data.cassandra.connection.connect-timeout=10s
130+
spring.data.cassandra.connection.init-query-timeout=10s

applications/spring-shell/src/test/resources/testcode/boot-migration-27-30-multi-module/spring-app/src/main/resources/application.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,17 @@ spring:
8585
socket-timeout: '100'
8686
max-in-memory-size: '122'
8787
username: testUser
88+
cassandra:
89+
keyspaceName: testKeySpace
90+
contactPoints: localhost
91+
port: 9042
92+
username: testusername
93+
schemaAction: NONE
94+
request:
95+
timeout: 10s
96+
connection:
97+
connectTimeout: 10s
98+
initQueryTimeout: 10s
8899
h2:
89100
console:
90101
path: "/tmp"

applications/spring-shell/src/test/resources/testcode/boot-migration-27-30/src/main/resources/application.properties

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,12 @@ spring.datasource.driverClassName=org.h2.Driver
119119
spring.datasource.username=sa
120120
spring.datasource.password=password
121121
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
122+
123+
spring.data.cassandra.keyspace-name=testKeySpace
124+
spring.data.cassandra.port=9042
125+
spring.data.cassandra.contact-points=localhost
126+
spring.data.cassandra.username=testusername
127+
spring.data.cassandra.schema-action=NONE
128+
spring.data.cassandra.request.timeout=10s
129+
spring.data.cassandra.connection.connect-timeout=10s
130+
spring.data.cassandra.connection.init-query-timeout=10s

applications/spring-shell/src/test/resources/testcode/boot-migration-27-30/src/main/resources/application.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,17 @@ spring:
8585
socket-timeout: '100'
8686
max-in-memory-size: '122'
8787
username: testUser
88+
cassandra:
89+
keyspaceName: testKeySpace
90+
contactPoints: localhost
91+
port: 9042
92+
username: testusername
93+
schemaAction: NONE
94+
request:
95+
timeout: 10s
96+
connection:
97+
connectTimeout: 10s
98+
initQueryTimeout: 10s
8899
h2:
89100
console:
90101
path: "/tmp"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright 2021 - 2022 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+
* https://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.sbm.boot.upgrade_27_30;
17+
18+
import org.jetbrains.annotations.NotNull;
19+
import org.openrewrite.ExecutionContext;
20+
import org.openrewrite.Recipe;
21+
import org.openrewrite.TreeVisitor;
22+
import org.openrewrite.properties.PropertiesVisitor;
23+
import org.openrewrite.properties.tree.Properties;
24+
25+
public class CassandraApplicationPropertiesMove extends Recipe {
26+
private final static String REGEX_PATTERN = "(spring)(\\.data)(\\.cassandra\\..*)";
27+
28+
@Override
29+
public String getDisplayName() {
30+
return "Moves spring.data.cassandra.* properties to spring.cassandra.*";
31+
}
32+
33+
@Override
34+
public String getDescription() {
35+
return "Renames spring.data.cassandra.(any) to spring.cassandra.(any)";
36+
}
37+
38+
@Override
39+
protected TreeVisitor<?, ExecutionContext> getVisitor() {
40+
41+
return new PropertiesVisitor<ExecutionContext>() {
42+
43+
@Override
44+
public Properties visitEntry(Properties.Entry entry, ExecutionContext executionContext) {
45+
46+
if (entry.getKey().matches(REGEX_PATTERN)) {
47+
return super.visitEntry(updateEntry(entry), executionContext);
48+
}
49+
50+
return super.visitEntry(entry, executionContext);
51+
}
52+
53+
@NotNull
54+
private Properties.Entry updateEntry(Properties.Entry entry) {
55+
return entry.withKey(entry.getKey().replaceAll(REGEX_PATTERN, "$1$3"));
56+
}
57+
};
58+
}
59+
}

components/sbm-recipes-boot-upgrade/src/main/resources/recipes/boot-2.7-3.0-dependency-version-update.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,36 @@
147147
recipeList:
148148
- org.springframework.sbm.boot.upgrade_27_30.SamlRelyingPartyPropertyApplicationPropertiesMove
149149
150+
- type: org.springframework.sbm.engine.recipe.OpenRewriteDeclarativeRecipeAdapter
151+
condition:
152+
type: org.springframework.sbm.boot.common.conditions.IsSpringBootProject
153+
versionPattern: "3\\.0\\..*"
154+
description: Migrate Cassandra configuration to Spring Boot 3.0 in yaml format
155+
openRewriteRecipe: |-
156+
type: specs.openrewrite.org/v1beta/recipe
157+
name: org.openrewrite.java.spring.boot2.SpringBootPropertiesManual_2_7
158+
displayName: Migrate Cassandra configuration to Spring Boot 3.0 in yaml format
159+
description: Renames spring.data.cassandra.(any) to spring.cassandra.(any)
160+
recipeList:
161+
- org.openrewrite.yaml.ChangePropertyKey:
162+
oldPropertyKey: spring.data.cassandra
163+
newPropertyKey: spring.cassandra
164+
165+
- type: org.springframework.sbm.engine.recipe.OpenRewriteDeclarativeRecipeAdapter
166+
condition:
167+
type: org.springframework.sbm.boot.common.conditions.IsSpringBootProject
168+
versionPattern: "3\\.0\\..*"
169+
description: Migrate Cassandra configuration to Spring Boot 3.0 in properties format
170+
openRewriteRecipe: |-
171+
type: specs.openrewrite.org/v1beta/recipe
172+
name: org.openrewrite.java.spring.boot2.SpringBootPropertiesManual_2_7
173+
displayName: Migrate Cassandra properties to Spring Boot 3.0 in properties
174+
description: Renames spring.data.cassandra.(any) to spring.cassandra.(any)
175+
recipeList:
176+
- org.openrewrite.properties.ChangePropertyKey:
177+
oldPropertyKey: spring.data.cassandra
178+
newPropertyKey: spring.cassandra
179+
150180
- type: org.springframework.sbm.engine.recipe.OpenRewriteDeclarativeRecipeAdapter
151181
condition:
152182
type: org.springframework.sbm.boot.common.conditions.IsSpringBootProject

0 commit comments

Comments
 (0)