Skip to content
This repository was archived by the owner on May 14, 2025. It is now read-only.

Commit c33aa71

Browse files
author
Corneil du Plessis
committed
Simplified and renamed AppBootSchemaVersion.
1 parent 649e766 commit c33aa71

File tree

11 files changed

+102
-128
lines changed

11 files changed

+102
-128
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright 2023 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+
17+
package org.springframework.cloud.dataflow.core;
18+
19+
import java.util.Arrays;
20+
21+
/**
22+
* Defines the possible schema versions that currently map to Spring {@code "Boot"}. A registered application can only support one schema version.
23+
*
24+
* <p>Each value defines the supported Spring Boot version that represents the changes in the schemas or Spring Batch and Task.</p>
25+
*
26+
* @author Chris Bono
27+
* @author Corneil du Plessis
28+
*/
29+
public enum AppBootSchemaVersion {
30+
31+
BOOT2("2"),
32+
BOOT3( "3");
33+
34+
private String bootVersion;
35+
36+
AppBootSchemaVersion(String bootVersion) {
37+
this.bootVersion = bootVersion;
38+
}
39+
public static AppBootSchemaVersion defaultVersion() {
40+
return BOOT2;
41+
}
42+
public static AppBootSchemaVersion fromBootVersion(String bootVersion) {
43+
return Arrays.stream(AppBootSchemaVersion.values())
44+
.filter((bv) -> bv.bootVersion.equals(bootVersion))
45+
.findFirst().orElseThrow(() -> new IllegalArgumentException("Invalid AppBootSchemaVersion:" + bootVersion));
46+
}
47+
48+
public String getBootVersion() {
49+
return this.bootVersion;
50+
}
51+
52+
@Override
53+
public String toString() {
54+
return "AppBootVersion{bootVersion='" + this.bootVersion + "'}";
55+
}
56+
}

spring-cloud-dataflow-core/src/main/java/org/springframework/cloud/dataflow/core/AppBootVersion.java

Lines changed: 0 additions & 77 deletions
This file was deleted.

spring-cloud-dataflow-core/src/test/java/org/springframework/cloud/dataflow/core/AppBootVersionTests.java

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,41 +22,34 @@
2222
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
2323

2424
/**
25-
* Unit tests for {@link AppBootVersion}.
25+
* Unit tests for {@link AppBootSchemaVersion}.
2626
*
2727
* @author Chris Bono
2828
*/
2929
public class AppBootVersionTests {
3030

3131
@Test
3232
void bootVersion2() {
33-
assertThat(AppBootVersion.BOOT2.getBootVersion()).isEqualTo("2");
34-
assertThat(AppBootVersion.BOOT2.getDescription()).isEqualTo("Boot 2 Tasks/Jobs");
35-
assertThat(AppBootVersion.BOOT2.getTaskPrefix()).isNull();
36-
assertThat(AppBootVersion.BOOT2.getBatchPrefix()).isNull();
37-
assertThat(AppBootVersion.BOOT2.toString()).isEqualTo(
38-
"AppBootVersion{description='Boot 2 Tasks/Jobs', bootVersion='2', taskPrefix='null', batchPrefix='null'}");
33+
assertThat(AppBootSchemaVersion.BOOT2.getBootVersion()).isEqualTo("2");
3934
}
4035

4136
@Test
4237
void bootVersion3() {
43-
assertThat(AppBootVersion.BOOT3.getBootVersion()).isEqualTo("3");
44-
assertThat(AppBootVersion.BOOT3.getDescription()).isEqualTo("Boot 3 Tasks/Jobs");
45-
assertThat(AppBootVersion.BOOT3.getTaskPrefix()).isEqualTo("BOOT3_TASK_");
46-
assertThat(AppBootVersion.BOOT3.getBatchPrefix()).isEqualTo("BOOT3_BATCH_");
47-
assertThat(AppBootVersion.BOOT3.toString()).isEqualTo(
48-
"AppBootVersion{description='Boot 3 Tasks/Jobs', bootVersion='3', taskPrefix='BOOT3_TASK_', batchPrefix='BOOT3_BATCH_'}");
49-
38+
assertThat(AppBootSchemaVersion.BOOT3.getBootVersion()).isEqualTo("3");
5039
}
5140

5241
@Test
5342
void fromBootVersion() {
54-
assertThat(AppBootVersion.fromBootVersion("2")).isEqualTo(AppBootVersion.BOOT2);
55-
assertThat(AppBootVersion.fromBootVersion("3")).isEqualTo(AppBootVersion.BOOT3);
56-
assertThatIllegalArgumentException().isThrownBy(() -> AppBootVersion.fromBootVersion(null))
57-
.withMessage("Unsupported bootVersion: null");
58-
assertThatIllegalArgumentException().isThrownBy(() -> AppBootVersion.fromBootVersion("4"))
59-
.withMessage("Unsupported bootVersion: 4");
60-
}
43+
assertThat(AppBootSchemaVersion.fromBootVersion("2")).isEqualTo(AppBootSchemaVersion.BOOT2);
44+
assertThatIllegalArgumentException().isThrownBy(() -> AppBootSchemaVersion.fromBootVersion("Boot2")).withMessage("Invalid AppBootSchemaVersion:Boot2");
45+
assertThatIllegalArgumentException().isThrownBy(() -> AppBootSchemaVersion.fromBootVersion("boot2")).withMessage("Invalid AppBootSchemaVersion:boot2");
46+
assertThatIllegalArgumentException().isThrownBy(() -> AppBootSchemaVersion.fromBootVersion("BOOT2")).withMessage("Invalid AppBootSchemaVersion:BOOT2");
6147

48+
assertThat(AppBootSchemaVersion.fromBootVersion("3")).isEqualTo(AppBootSchemaVersion.BOOT3);
49+
assertThatIllegalArgumentException().isThrownBy(() -> AppBootSchemaVersion.fromBootVersion("Boot3")).withMessage("Invalid AppBootSchemaVersion:Boot3");
50+
assertThatIllegalArgumentException().isThrownBy(() -> AppBootSchemaVersion.fromBootVersion("boot3")).withMessage("Invalid AppBootSchemaVersion:boot3");
51+
assertThatIllegalArgumentException().isThrownBy(() -> AppBootSchemaVersion.fromBootVersion("BOOT3")).withMessage("Invalid AppBootSchemaVersion:BOOT3");
52+
53+
assertThatIllegalArgumentException().isThrownBy(() -> AppBootSchemaVersion.fromBootVersion(null)).withMessage("Invalid AppBootSchemaVersion:null");
54+
}
6255
}

spring-cloud-dataflow-registry/src/main/java/org/springframework/cloud/dataflow/registry/service/DefaultAppRegistryService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ public List<AppRegistration> importAll(boolean overwrite, Resource... resources)
399399
String[] typeName = lineSplit[0].split("\\.");
400400
if (typeName.length < 2 || typeName.length > 3) {
401401
throw new IllegalArgumentException("Invalid format for app key '" + lineSplit[0]
402-
+ "'in file. Must be <type>.<name> or <type>.<name>.metadata");
402+
+ "'in file. Must be <type>.<name> or <type>.<name>.metadata or <type>.<name>.bootVersion");
403403
}
404404
String type = typeName[0].trim();
405405
String name = typeName[1].trim();

spring-cloud-dataflow-rest-client/src/main/java/org/springframework/cloud/dataflow/rest/client/AppRegistryOperations.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import java.util.Properties;
2020

21-
import org.springframework.cloud.dataflow.core.AppBootVersion;
21+
import org.springframework.cloud.dataflow.core.AppBootSchemaVersion;
2222
import org.springframework.cloud.dataflow.core.ApplicationType;
2323
import org.springframework.cloud.dataflow.rest.resource.AppRegistrationResource;
2424
import org.springframework.cloud.dataflow.rest.resource.DetailedAppRegistrationResource;
@@ -83,7 +83,7 @@ public interface AppRegistryOperations {
8383
* @param metadataUri URI for the application metadata artifact
8484
* @param force if {@code true}, overwrites a pre-existing registration
8585
* @return the new app registration
86-
* @deprecated in favor of {@link #register(String, ApplicationType, AppBootVersion, String, String, boolean)}
86+
* @deprecated in favor of {@link #register(String, ApplicationType, AppBootSchemaVersion, String, String, boolean)}
8787
*/
8888
@Deprecated
8989
AppRegistrationResource register(String name, ApplicationType type, String uri, String metadataUri, boolean force);
@@ -99,7 +99,7 @@ public interface AppRegistryOperations {
9999
* @param force if {@code true}, overwrites a pre-existing registration
100100
* @return the new app registration
101101
*/
102-
AppRegistrationResource register(String name, ApplicationType type, AppBootVersion bootVersion, String uri, String metadataUri, boolean force);
102+
AppRegistrationResource register(String name, ApplicationType type, AppBootSchemaVersion bootVersion, String uri, String metadataUri, boolean force);
103103

104104
/**
105105
* Register an application name, type and version with its Maven coordinates.
@@ -111,7 +111,7 @@ public interface AppRegistryOperations {
111111
* @param metadataUri URI for the application metadata artifact
112112
* @param force if {@code true}, overwrites a pre-existing registration
113113
* @return the new app registration
114-
* @deprecated in favor of {@link #register(String, ApplicationType, AppBootVersion, String, String, String, boolean)}
114+
* @deprecated in favor of {@link #register(String, ApplicationType, AppBootSchemaVersion, String, String, String, boolean)}
115115
*/
116116
@Deprecated
117117
AppRegistrationResource register(String name, ApplicationType type, String version, String uri,
@@ -129,8 +129,8 @@ AppRegistrationResource register(String name, ApplicationType type, String versi
129129
* @param force if {@code true}, overwrites a pre-existing registration
130130
* @return the new app registration
131131
*/
132-
AppRegistrationResource register(String name, ApplicationType type, AppBootVersion bootVersion, String version, String uri,
133-
String metadataUri, boolean force);
132+
AppRegistrationResource register(String name, ApplicationType type, AppBootSchemaVersion bootVersion, String version, String uri,
133+
String metadataUri, boolean force);
134134

135135
/**
136136
* Unregister an application name and type.

spring-cloud-dataflow-rest-client/src/main/java/org/springframework/cloud/dataflow/rest/client/AppRegistryTemplate.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import java.util.Properties;
2020

21-
import org.springframework.cloud.dataflow.core.AppBootVersion;
21+
import org.springframework.cloud.dataflow.core.AppBootSchemaVersion;
2222
import org.springframework.cloud.dataflow.core.ApplicationType;
2323
import org.springframework.cloud.dataflow.rest.resource.AppRegistrationResource;
2424
import org.springframework.cloud.dataflow.rest.resource.DetailedAppRegistrationResource;
@@ -115,11 +115,11 @@ public DetailedAppRegistrationResource info(String name, ApplicationType type, S
115115

116116
@Override
117117
public AppRegistrationResource register(String name, ApplicationType type, String uri, String metadataUri, boolean force) {
118-
return register(name, type, (AppBootVersion) null, uri, metadataUri, force);
118+
return register(name, type, (AppBootSchemaVersion) null, uri, metadataUri, force);
119119
}
120120

121121
@Override
122-
public AppRegistrationResource register(String name, ApplicationType type, AppBootVersion bootVersion,
122+
public AppRegistrationResource register(String name, ApplicationType type, AppBootSchemaVersion bootVersion,
123123
String uri, String metadataUri, boolean force) {
124124
MultiValueMap<String, Object> values = valuesForRegisterPost(bootVersion, uri, metadataUri, force);
125125
return restTemplate.postForObject(appsLink.getHref() + "/{type}/{name}", values,
@@ -129,19 +129,19 @@ public AppRegistrationResource register(String name, ApplicationType type, AppBo
129129
@Override
130130
public AppRegistrationResource register(String name, ApplicationType type, String version, String uri,
131131
String metadataUri, boolean force) {
132-
return this.register(name, type, AppBootVersion.BOOT2, version, uri, metadataUri, force);
132+
return this.register(name, type, null, version, uri, metadataUri, force);
133133
}
134134

135135
@Override
136-
public AppRegistrationResource register(String name, ApplicationType type, AppBootVersion bootVersion,
136+
public AppRegistrationResource register(String name, ApplicationType type, AppBootSchemaVersion bootVersion,
137137
String version, String uri, String metadataUri, boolean force) {
138138
MultiValueMap<String, Object> values = valuesForRegisterPost(bootVersion, uri, metadataUri, force);
139139
return restTemplate.postForObject(appsLink.getHref() + "/{type}/{name}/{version}", values,
140140
AppRegistrationResource.class, type, name, version);
141141
}
142142

143-
private MultiValueMap<String, Object> valuesForRegisterPost(AppBootVersion bootVersion, String uri,
144-
String metadataUri, boolean force) {
143+
private MultiValueMap<String, Object> valuesForRegisterPost(AppBootSchemaVersion bootVersion, String uri,
144+
String metadataUri, boolean force) {
145145
MultiValueMap<String, Object> values = new LinkedMultiValueMap<>();
146146
values.add("uri", uri);
147147
if (metadataUri != null) {

spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/config/web/WebConfiguration.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
3535
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
3636
import org.springframework.boot.web.servlet.ServletContextInitializer;
37-
import org.springframework.cloud.dataflow.core.AppBootVersion;
37+
import org.springframework.cloud.dataflow.core.AppBootSchemaVersion;
3838
import org.springframework.cloud.dataflow.rest.support.jackson.ISO8601DateFormatWithMilliSeconds;
3939
import org.springframework.cloud.dataflow.rest.support.jackson.Jackson2DataflowModule;
4040
import org.springframework.context.ApplicationListener;
@@ -62,6 +62,7 @@
6262
* @author David Turanski
6363
* @author Michael Wirth
6464
* @author Chris Bono
65+
* @author Corneil du Plessis
6566
*/
6667
@Configuration(proxyBeanMethods = false)
6768
@ConditionalOnWebApplication
@@ -143,11 +144,11 @@ public void onApplicationEvent(ContextClosedEvent event) {
143144
}
144145
}
145146

146-
static class AppBootVersionConverter implements Converter<String, AppBootVersion> {
147+
static class AppBootVersionConverter implements Converter<String, AppBootSchemaVersion> {
147148

148149
@Override
149-
public AppBootVersion convert(String value) {
150-
return AppBootVersion.fromBootVersion(value);
150+
public AppBootSchemaVersion convert(String value) {
151+
return value != null ? AppBootSchemaVersion.fromBootVersion(value) : null;
151152
}
152153
}
153154

spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/controller/AppRegistryController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
import org.springframework.boot.configurationmetadata.ConfigurationMetadataProperty;
3737
import org.springframework.cloud.dataflow.configuration.metadata.ApplicationConfigurationMetadataResolver;
38-
import org.springframework.cloud.dataflow.core.AppBootVersion;
38+
import org.springframework.cloud.dataflow.core.AppBootSchemaVersion;
3939
import org.springframework.cloud.dataflow.core.AppRegistration;
4040
import org.springframework.cloud.dataflow.core.ApplicationType;
4141
import org.springframework.cloud.dataflow.core.StreamAppDefinition;
@@ -233,7 +233,7 @@ public void register(
233233
@PathVariable("type") ApplicationType type,
234234
@PathVariable("name") String name,
235235
@PathVariable("version") String version,
236-
@RequestParam(name = "bootVersion", required = false) AppBootVersion bootVersion,
236+
@RequestParam(name = "bootVersion", required = false) AppBootSchemaVersion bootVersion,
237237
@RequestParam("uri") String uri,
238238
@RequestParam(name = "metadata-uri", required = false) String metadataUri,
239239
@RequestParam(value = "force", defaultValue = "false") boolean force) {
@@ -259,7 +259,7 @@ public void register(
259259
public void register(
260260
@PathVariable("type") ApplicationType type,
261261
@PathVariable("name") String name,
262-
@RequestParam(name = "bootVersion", required = false) AppBootVersion bootVersion,
262+
@RequestParam(name = "boot-version", required = false) AppBootSchemaVersion bootVersion,
263263
@RequestParam("uri") String uri,
264264
@RequestParam(name = "metadata-uri", required = false) String metadataUri,
265265
@RequestParam(value = "force", defaultValue = "false") boolean force) {

spring-cloud-dataflow-shell-core/src/main/java/org/springframework/cloud/dataflow/shell/command/AppRegistryCommands.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
import org.springframework.beans.factory.annotation.Autowired;
2828
import org.springframework.boot.configurationmetadata.ConfigurationMetadataProperty;
29-
import org.springframework.cloud.dataflow.core.AppBootVersion;
29+
import org.springframework.cloud.dataflow.core.AppBootSchemaVersion;
3030
import org.springframework.cloud.dataflow.core.ApplicationType;
3131
import org.springframework.cloud.dataflow.rest.client.AppRegistryOperations;
3232
import org.springframework.cloud.dataflow.rest.resource.AppRegistrationResource;
@@ -242,13 +242,13 @@ public String defaultApplication(
242242
public String register(
243243
@ShellOption(value = { "", "--name" }, help = "the name for the registered application") String name,
244244
@ShellOption(help = "the type for the registered application", valueProvider = EnumValueProvider.class) ApplicationType type,
245-
@ShellOption(value = { "--bootVersion" }, help = "the boot version to use for the registered application", defaultValue = "2") AppBootVersion bootVersion,
245+
@ShellOption(value = { "-bv", "--bootVersion" }, help = "the boot version to use for the registered application", defaultValue = ShellOption.NULL) AppBootSchemaVersion bootVersion,
246246
@ShellOption(help = "URI for the application artifact") String uri,
247-
@ShellOption(value = { "--metadata-uri", "--metadataUri"}, help = "Metadata URI for the application artifact", defaultValue = ShellOption.NULL) String metadataUri,
247+
@ShellOption(value = { "-m", "--metadata-uri", "--metadataUri"}, help = "Metadata URI for the application artifact", defaultValue = ShellOption.NULL) String metadataUri,
248248
@ShellOption(help = "force update if application is already registered (only if not in use)", defaultValue = "false") boolean force) {
249249
appRegistryOperations().register(name, type, bootVersion, uri, metadataUri, force);
250250
return String.format(("Successfully registered application '%s:%s%s"), type, name,
251-
bootVersion == AppBootVersion.BOOT2 ? "" : " (boot " + bootVersion.getBootVersion() + ")");
251+
bootVersion == null ? "" : " (boot " + bootVersion.getBootVersion() + ")");
252252
}
253253

254254
@ShellMethod(key = LIST_APPLICATIONS, value = "List all registered applications")

0 commit comments

Comments
 (0)