diff --git a/spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/controller/TaskCtrController.java b/spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/controller/TaskCtrController.java index 5758a4f3e6..f7b51fcc37 100644 --- a/spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/controller/TaskCtrController.java +++ b/spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/controller/TaskCtrController.java @@ -61,9 +61,7 @@ public TaskCtrController(ApplicationConfigurationMetadataResolver metadataResolv public List options() { URI ctrUri = null; try { - ctrUri = new URI(composedTaskRunnerConfigurationProperties.getUri() != null - ? composedTaskRunnerConfigurationProperties.getUri() - : this.taskConfigurationProperties.getComposedTaskRunnerUri()); + ctrUri = new URI(composedTaskRunnerConfigurationProperties.getUri()); } catch (Exception e) { throw new IllegalStateException("Invalid Compose Task Runner Resource", e); } diff --git a/spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/service/impl/DefaultSchedulerService.java b/spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/service/impl/DefaultSchedulerService.java index fd55085039..5652dd8768 100644 --- a/spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/service/impl/DefaultSchedulerService.java +++ b/spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/service/impl/DefaultSchedulerService.java @@ -224,11 +224,7 @@ public void schedule( appRegistration = new AppRegistration( ComposedTaskRunnerConfigurationProperties.COMPOSED_TASK_RUNNER_NAME, ApplicationType.task, - new URI(TaskServiceUtils.getComposedTaskLauncherUri( - this.taskConfigurationProperties, - this.composedTaskRunnerConfigurationProperties) - ) - ); + new URI(this.composedTaskRunnerConfigurationProperties.getUri())); } catch (URISyntaxException e) { throw new IllegalStateException("Invalid Compose Task Runner Resource", e); } @@ -528,8 +524,7 @@ protected Resource getTaskResource(String taskDefinitionName, String version) { AppRegistration appRegistration = null; if (TaskServiceUtils.isComposedTaskDefinition(taskDefinition.getDslText())) { URI composedTaskUri = null; - String composedTaskLauncherUri = TaskServiceUtils.getComposedTaskLauncherUri(this.taskConfigurationProperties, - this.composedTaskRunnerConfigurationProperties); + String composedTaskLauncherUri = this.composedTaskRunnerConfigurationProperties.getUri(); try { composedTaskUri = new URI(composedTaskLauncherUri); } catch (URISyntaxException e) { diff --git a/spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/service/impl/DefaultTaskExecutionInfoService.java b/spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/service/impl/DefaultTaskExecutionInfoService.java index d9a9a2b27e..3a10e661bf 100644 --- a/spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/service/impl/DefaultTaskExecutionInfoService.java +++ b/spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/service/impl/DefaultTaskExecutionInfoService.java @@ -198,8 +198,7 @@ public TaskExecutionInformation findTaskExecutionInformation( try { appRegistration = new AppRegistration(ComposedTaskRunnerConfigurationProperties.COMPOSED_TASK_RUNNER_NAME, ApplicationType.task, - new URI(TaskServiceUtils.getComposedTaskLauncherUri(this.taskConfigurationProperties, - this.composedTaskRunnerConfigurationProperties))); + new URI(this.composedTaskRunnerConfigurationProperties.getUri())); } catch (URISyntaxException e) { throw new IllegalStateException("Invalid Compose Task Runner Resource", e); } diff --git a/spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/service/impl/DefaultTaskExecutionService.java b/spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/service/impl/DefaultTaskExecutionService.java index e288d8d476..99858a32c5 100644 --- a/spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/service/impl/DefaultTaskExecutionService.java +++ b/spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/service/impl/DefaultTaskExecutionService.java @@ -583,7 +583,7 @@ private void handleAccessToken(List commandLineArgs, TaskExecutionInform break; } } - if (TaskServiceUtils.isUseUserAccessToken(this.taskConfigurationProperties, this.composedTaskRunnerConfigurationProperties)) { + if ( this.composedTaskRunnerConfigurationProperties.isUseUserAccessToken()) { useUserAccessToken = true; } if (!containsAccessToken && useUserAccessToken && oauth2TokenUtilsService != null) { diff --git a/spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/service/impl/TaskConfigurationProperties.java b/spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/service/impl/TaskConfigurationProperties.java index 45f0657825..bb0f909383 100644 --- a/spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/service/impl/TaskConfigurationProperties.java +++ b/spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/service/impl/TaskConfigurationProperties.java @@ -22,7 +22,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.cloud.dataflow.core.DataFlowPropertyKeys; -import org.springframework.util.StringUtils; import org.springframework.validation.annotation.Validated; /** @@ -76,21 +75,6 @@ public class TaskConfigurationProperties { private boolean useJsonJobParameters = false; - @Deprecated - public String getComposedTaskRunnerUri() { - logDeprecationWarning("getUri"); - return this.composedTaskRunnerConfigurationProperties.getUri(); - } - - @Deprecated - public void setComposedTaskRunnerUri(String composedTaskRunnerUri) { - logDeprecationWarning("setUri"); - - if (!StringUtils.hasText(this.composedTaskRunnerConfigurationProperties.getUri())) { - this.composedTaskRunnerConfigurationProperties.setUri(composedTaskRunnerUri); - } - } - public DeployerProperties getDeployerProperties() { return deployerProperties; } @@ -107,23 +91,6 @@ public void setAutoCreateTaskDefinitions(boolean autoCreateTaskDefinitions) { this.autoCreateTaskDefinitions = autoCreateTaskDefinitions; } - @Deprecated - public boolean isUseUserAccessToken() { - logDeprecationWarning(); - - return this.composedTaskRunnerConfigurationProperties.isUseUserAccessToken() == null ? false : - this.composedTaskRunnerConfigurationProperties.isUseUserAccessToken(); - } - - @Deprecated - public void setUseUserAccessToken(boolean useUserAccessToken) { - logDeprecationWarning(); - - if (this.composedTaskRunnerConfigurationProperties.isUseUserAccessToken() == null) { - this.composedTaskRunnerConfigurationProperties.setUseUserAccessToken(useUserAccessToken); - } - } - public static class DeployerProperties { private String[] propertyIncludes = new String[0]; diff --git a/spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/service/impl/TaskServiceUtils.java b/spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/service/impl/TaskServiceUtils.java index 56104bec31..7e5705ef2b 100644 --- a/spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/service/impl/TaskServiceUtils.java +++ b/spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/service/impl/TaskServiceUtils.java @@ -380,27 +380,6 @@ static void addImagePullSecretProperty(Map taskDeploymentPropert } } - static String getComposedTaskLauncherUri(TaskConfigurationProperties taskConfigurationProperties, - ComposedTaskRunnerConfigurationProperties composedTaskRunnerConfigurationProperties) { - if(composedTaskRunnerConfigurationProperties != null && - StringUtils.hasText(composedTaskRunnerConfigurationProperties.getUri())) { - return composedTaskRunnerConfigurationProperties.getUri(); - } - - return taskConfigurationProperties.getComposedTaskRunnerUri(); - } - - static boolean isUseUserAccessToken(TaskConfigurationProperties taskConfigurationProperties, - ComposedTaskRunnerConfigurationProperties composedTaskRunnerConfigurationProperties) { - if (composedTaskRunnerConfigurationProperties != null) { - if (composedTaskRunnerConfigurationProperties.isUseUserAccessToken() != null) { - return composedTaskRunnerConfigurationProperties.isUseUserAccessToken(); - } - } - - return taskConfigurationProperties.isUseUserAccessToken(); - } - /** * Converts command lines args into a format acceptable for CTR. *

The input args are copied and entries that begin with {@code 'app.'} diff --git a/spring-cloud-dataflow-server-core/src/test/java/org/springframework/cloud/dataflow/server/service/impl/ComposedTaskRunnerConfigurationPropertiesTests.java b/spring-cloud-dataflow-server-core/src/test/java/org/springframework/cloud/dataflow/server/service/impl/ComposedTaskRunnerConfigurationPropertiesTests.java new file mode 100644 index 0000000000..20e961804d --- /dev/null +++ b/spring-cloud-dataflow-server-core/src/test/java/org/springframework/cloud/dataflow/server/service/impl/ComposedTaskRunnerConfigurationPropertiesTests.java @@ -0,0 +1,65 @@ +/* + * Copyright 2024 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 + * + * https://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.dataflow.server.service.impl; + +import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; + +public class ComposedTaskRunnerConfigurationPropertiesTests { + + private static final String DEFAULT_URI = "https://testuri.something"; + + @Test + void useUserAccessTokenFromCTRPropsTrue() { + ComposedTaskRunnerConfigurationProperties composedTaskRunnerConfigurationProperties = + new ComposedTaskRunnerConfigurationProperties(); + composedTaskRunnerConfigurationProperties.setUseUserAccessToken(true); + assertThat(composedTaskRunnerConfigurationProperties.isUseUserAccessToken()).as("Use user access token should be true").isTrue(); + } + + @Test + void useUserAccessTokenFromCTRPropFalse() { + ComposedTaskRunnerConfigurationProperties composedTaskRunnerConfigurationProperties = + new ComposedTaskRunnerConfigurationProperties(); + composedTaskRunnerConfigurationProperties.setUseUserAccessToken(false); + assertThat(composedTaskRunnerConfigurationProperties.isUseUserAccessToken()).as("Use user access token should be false").isFalse(); + } + + @Test + void useUserAccessTokenFromCTRPropNotSet() { + ComposedTaskRunnerConfigurationProperties composedTaskRunnerConfigurationProperties = + new ComposedTaskRunnerConfigurationProperties(); + assertThat(composedTaskRunnerConfigurationProperties.isUseUserAccessToken()).as("Use user access token should be false").isNull(); + } + + @Test + void uriFromComposedTaskRunnerConfigurationProperties() { + ComposedTaskRunnerConfigurationProperties composedTaskRunnerConfigurationProperties = + new ComposedTaskRunnerConfigurationProperties(); + composedTaskRunnerConfigurationProperties.setUri(DEFAULT_URI); + + assertThat(composedTaskRunnerConfigurationProperties.getUri()).as("DEFAULT_URI is not being returned from properties").isEqualTo(DEFAULT_URI); + } + + @Test + void emptyUriFromComposedTaskRunnerConfigurationProperties() { + ComposedTaskRunnerConfigurationProperties composedTaskRunnerConfigurationProperties = + new ComposedTaskRunnerConfigurationProperties(); + + assertThat(composedTaskRunnerConfigurationProperties.getUri()).as("URI should be empty").isNull(); + } +} diff --git a/spring-cloud-dataflow-server-core/src/test/java/org/springframework/cloud/dataflow/server/service/impl/TaskServiceUtilsTests.java b/spring-cloud-dataflow-server-core/src/test/java/org/springframework/cloud/dataflow/server/service/impl/TaskServiceUtilsTests.java index c2b20eef4a..dbc7db9ac8 100644 --- a/spring-cloud-dataflow-server-core/src/test/java/org/springframework/cloud/dataflow/server/service/impl/TaskServiceUtilsTests.java +++ b/spring-cloud-dataflow-server-core/src/test/java/org/springframework/cloud/dataflow/server/service/impl/TaskServiceUtilsTests.java @@ -267,48 +267,6 @@ void addProvidedImagePullSecret() { assertThat(taskDeploymentProperties.get(imagePullSecretPropertyKey)).as("Invalid imagePullSecret").isEqualTo("regcred"); } - @Test - void composedTaskRunnerUriFromTaskProps() { - ComposedTaskRunnerConfigurationProperties composedTaskRunnerConfigurationProperties = - new ComposedTaskRunnerConfigurationProperties(); - TaskConfigurationProperties taskConfigurationProperties = new TaskConfigurationProperties(); - taskConfigurationProperties.setComposedTaskRunnerConfigurationProperties(composedTaskRunnerConfigurationProperties); - taskConfigurationProperties.setComposedTaskRunnerUri("docker://something"); - - String uri = TaskServiceUtils.getComposedTaskLauncherUri(taskConfigurationProperties, - composedTaskRunnerConfigurationProperties); - - assertThat(uri).as("Invalid task runner URI string").isEqualTo("docker://something"); - } - - @Test - void composedTaskRunnerUriFromCTRProps() { - ComposedTaskRunnerConfigurationProperties composedTaskRunnerConfigurationProperties = - new ComposedTaskRunnerConfigurationProperties(); - composedTaskRunnerConfigurationProperties.setUri("docker://something"); - - String uri = TaskServiceUtils.getComposedTaskLauncherUri(new TaskConfigurationProperties(), - composedTaskRunnerConfigurationProperties); - - assertThat(uri).as("Invalid task runner URI string").isEqualTo("docker://something"); - } - - @Test - void composedTaskRunnerUriFromCTRPropsOverridesTaskProps() { - ComposedTaskRunnerConfigurationProperties composedTaskRunnerConfigurationProperties = - new ComposedTaskRunnerConfigurationProperties(); - composedTaskRunnerConfigurationProperties.setUri("gcr.io://something"); - - TaskConfigurationProperties taskConfigurationProperties = new TaskConfigurationProperties(); - taskConfigurationProperties.setComposedTaskRunnerConfigurationProperties(composedTaskRunnerConfigurationProperties); - taskConfigurationProperties.setComposedTaskRunnerUri("docker://something"); - - String uri = TaskServiceUtils.getComposedTaskLauncherUri(taskConfigurationProperties, - composedTaskRunnerConfigurationProperties); - - assertThat(uri).as("Invalid task runner URI string").isEqualTo("gcr.io://something"); - } - @Test void imagePullSecretNullCTRProperties() { Map taskDeploymentProperties = new HashMap<>(); @@ -316,59 +274,6 @@ void imagePullSecretNullCTRProperties() { assertThat(taskDeploymentProperties.containsKey("deployer.composed-task-runner.kubernetes.imagePullSecret")).as("Task deployment properties should not contain imagePullSecret").isFalse(); } - @Test - void useUserAccessTokenFromCTRPropsEnabled() { - ComposedTaskRunnerConfigurationProperties composedTaskRunnerConfigurationProperties = - new ComposedTaskRunnerConfigurationProperties(); - composedTaskRunnerConfigurationProperties.setUseUserAccessToken(true); - - boolean result = TaskServiceUtils.isUseUserAccessToken(null, composedTaskRunnerConfigurationProperties); - - assertThat(result).as("Use user access token should be true").isTrue(); - } - - @Test - void useUserAccessTokenFromCTRPropsDisabled() { - ComposedTaskRunnerConfigurationProperties composedTaskRunnerConfigurationProperties = - new ComposedTaskRunnerConfigurationProperties(); - composedTaskRunnerConfigurationProperties.setUseUserAccessToken(false); - - boolean result = TaskServiceUtils.isUseUserAccessToken(null, composedTaskRunnerConfigurationProperties); - - assertThat(result).as("Use user access token should be false").isFalse(); - } - - @Test - void useUserAccessTokenFromNullCTRProps() { - TaskConfigurationProperties taskConfigurationProperties = new TaskConfigurationProperties(); - taskConfigurationProperties.setComposedTaskRunnerConfigurationProperties(new ComposedTaskRunnerConfigurationProperties()); - - boolean result = TaskServiceUtils.isUseUserAccessToken(taskConfigurationProperties, null); - - assertThat(result).as("Use user access token should be false").isFalse(); - } - - @Test - void useUserAccessTokenFromTaskProps() { - TaskConfigurationProperties taskConfigurationProperties = new TaskConfigurationProperties(); - taskConfigurationProperties.setComposedTaskRunnerConfigurationProperties(new ComposedTaskRunnerConfigurationProperties()); - taskConfigurationProperties.setUseUserAccessToken(true); - - boolean result = TaskServiceUtils.isUseUserAccessToken(taskConfigurationProperties, null); - - assertThat(result).as("Use user access token should be true").isTrue(); - } - - @Test - void useUserAccessTokenFromTaskPropsDefault() { - TaskConfigurationProperties taskConfigurationProperties = new TaskConfigurationProperties(); - taskConfigurationProperties.setComposedTaskRunnerConfigurationProperties(new ComposedTaskRunnerConfigurationProperties()); - - boolean result = TaskServiceUtils.isUseUserAccessToken(taskConfigurationProperties, null); - - assertThat(result).as("Use user access token should be false").isFalse(); - } - @Test void convertCommandLineArgsToCTRFormat() { validateSingleCTRArgs("app.a.0=foo=bar", "--composed-task-app-arguments.base64_YXBwLmEuMA=foo=bar");