Refactored for CloudFoundry Support

This commit adds on an abstraction for the providing unique command line
arugements for each worker.  It also updates the partitioned job sample
to be able to successfully be run on CloudFoundry.

Resolves spring-cloud/spring-cloud-task#193

Updated based on comments
This commit is contained in:
Michael Minella
2016-08-22 11:46:29 -04:00
committed by Glenn Renfro
parent c14d2efca3
commit 025c447b89
15 changed files with 402 additions and 46 deletions

View File

@@ -149,7 +149,7 @@ public class DeployerPartitionHandlerTests {
AppDefinition appDefinition = request.getDefinition();
assertEquals("partitionedJobTask:partitionedJob:step1:partition1", appDefinition.getName());
assertEquals("partitionedJobTask", appDefinition.getName());
assertTrue(request.getCommandlineArguments().contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID, "1")));
assertTrue(request.getCommandlineArguments().contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID, "4")));
assertTrue(request.getCommandlineArguments().contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME, "step1")));
@@ -362,7 +362,7 @@ public class DeployerPartitionHandlerTests {
AppDefinition appDefinition = request.getDefinition();
assertEquals("partitionedJobTask:partitionedJob:step1:partition1", appDefinition.getName());
assertEquals("partitionedJobTask", appDefinition.getName());
assertTrue(request.getCommandlineArguments().contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID, "1")));
assertTrue(request.getCommandlineArguments().contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID, "4")));
assertTrue(request.getCommandlineArguments().contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME, "step1")));
@@ -426,7 +426,7 @@ public class DeployerPartitionHandlerTests {
AppDefinition appDefinition = request.getDefinition();
assertEquals("partitionedJobTask:partitionedJob:step1:partition1", appDefinition.getName());
assertEquals("partitionedJobTask", appDefinition.getName());
assertTrue(request.getCommandlineArguments().contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID, "1")));
assertTrue(request.getCommandlineArguments().contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID, "4")));
assertTrue(request.getCommandlineArguments().contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME, "step1")));
@@ -608,7 +608,7 @@ public class DeployerPartitionHandlerTests {
AppDefinition appDefinition = request.getDefinition();
assertEquals("partitionedJobTask:partitionedJob:step1:partition1", appDefinition.getName());
assertEquals("partitionedJobTask", appDefinition.getName());
assertTrue(request.getCommandlineArguments().contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID, "1")));
assertTrue(request.getCommandlineArguments().contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID, "4")));
assertTrue(request.getCommandlineArguments().contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME, "step1")));
@@ -661,7 +661,27 @@ public class DeployerPartitionHandlerTests {
Collections.sort(allRequests, new Comparator<AppDeploymentRequest>() {
@Override
public int compare(AppDeploymentRequest o1, AppDeploymentRequest o2) {
return o1.getDefinition().getName().compareTo(o2.getDefinition().getName());
List<String> commandlineArguments = o1.getCommandlineArguments();
String o1Command = "";
for (String commandlineArgument : commandlineArguments) {
if(commandlineArgument.contains(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID)) {
o1Command = commandlineArgument;
break;
}
}
commandlineArguments = o2.getCommandlineArguments();
String o2Command = "";
for (String commandlineArgument : commandlineArguments) {
if(commandlineArgument.contains(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID)) {
o2Command = commandlineArgument;
break;
}
}
return o1Command.compareTo(o2Command);
}
});
@@ -671,7 +691,7 @@ public class DeployerPartitionHandlerTests {
assertEquals(0, request.getDeploymentProperties().size());
AppDefinition appDefinition = request.getDefinition();
assertEquals("partitionedJobTask:partitionedJob:step1:partition" + (i - 3), appDefinition.getName());
assertEquals("partitionedJobTask", appDefinition.getName());
assertTrue(request.getCommandlineArguments().contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID, "1")));
assertTrue(request.getCommandlineArguments().contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID, String.valueOf(i))));
assertTrue(request.getCommandlineArguments().contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME, "step1")));

View File

@@ -0,0 +1,45 @@
/*
* 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.task.batch.partition;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* @author Michael Minella
*/
public class NoOpEnvironmentVariablesProviderTests {
private NoOpEnvironmentVariablesProvider provider;
@Before
public void setUp() {
this.provider = new NoOpEnvironmentVariablesProvider();
}
@Test
public void test() {
Map<String, String> environmentVariables = this.provider.getEnvironmentVariables(null);
assertNotNull(environmentVariables);
assertTrue(environmentVariables.isEmpty());
Map<String, String> environmentVariables2 = this.provider.getEnvironmentVariables(null);
assertTrue(environmentVariables == environmentVariables2);
}
}

View File

@@ -0,0 +1,46 @@
/*
* 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.task.batch.partition;
import java.util.Arrays;
import java.util.List;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* @author Michael Minella
*/
public class PassThroughCommandLineArgsProviderTests {
@Test(expected = IllegalArgumentException.class)
public void testNull() {
new PassThroughCommandLineArgsProvider(null);
}
@Test
public void test() {
List<String> args = Arrays.asList("foo", "bar", "baz");
CommandLineArgsProvider provider = new PassThroughCommandLineArgsProvider(args);
List<String> commandLineArgs = provider.getCommandLineArgs(null);
assertEquals("foo", commandLineArgs.get(0));
assertEquals("bar", commandLineArgs.get(1));
assertEquals("baz", commandLineArgs.get(2));
}
}

View File

@@ -0,0 +1,50 @@
/*
* 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.task.batch.partition;
import java.util.Arrays;
import java.util.List;
import org.junit.Test;
import org.springframework.cloud.task.repository.TaskExecution;
import static org.junit.Assert.assertEquals;
/**
* @author Michael Minella
*/
public class SimpleCommandLineArgsProviderTests {
@Test(expected = IllegalArgumentException.class)
public void testNullConstructorArg() {
new SimpleCommandLineArgsProvider(null);
}
@Test
public void test() {
TaskExecution taskExecution = new TaskExecution();
taskExecution.setArguments(Arrays.asList("foo", "bar", "baz"));
CommandLineArgsProvider provider = new SimpleCommandLineArgsProvider(taskExecution);
List<String> commandLineArgs = provider.getCommandLineArgs(null);
assertEquals("foo", commandLineArgs.get(0));
assertEquals("bar", commandLineArgs.get(1));
assertEquals("baz", commandLineArgs.get(2));
}
}