Add Application Name to TaskLaunchRequest for launched task

resolves #238
This commit is contained in:
Glenn Renfro
2016-11-02 09:26:00 -04:00
committed by Michael Minella
parent cc1f971f3e
commit 4a1a2c3c88
11 changed files with 139 additions and 51 deletions

View File

@@ -23,8 +23,10 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/**
* Request that contains the maven repository and property information required by the
@@ -39,6 +41,7 @@ public class TaskLaunchRequest implements Serializable{
private List<String> commandlineArguments;
private Map<String, String> environmentProperties;
private Map<String, String> deploymentProperties;
private String applicationName;
/**
* Constructor for the TaskLaunchRequest;
@@ -46,16 +49,21 @@ public class TaskLaunchRequest implements Serializable{
* @param commandlineArguments list of commandlineArguments to be used by the task
* @param environmentProperties are the environment variables for this task.
* @param deploymentProperties are the variables used to setup task on the platform.
* @param applicationName name to be applied to the launched task. If set
* to null then the launched task name will be "Task-<hash code of the
* TaskLaunchRequest>.
*/
public TaskLaunchRequest(String uri, List<String> commandlineArguments,
Map<String, String> environmentProperties,
Map<String, String> deploymentProperties) {
Map<String, String> environmentProperties,
Map<String, String> deploymentProperties,
String applicationName) {
Assert.hasText(uri, "uri must not be empty nor null.");
this.uri = uri;
this.commandlineArguments = (commandlineArguments == null) ? new ArrayList<String>() : commandlineArguments;
this.environmentProperties = environmentProperties == null ? new HashMap<String, String>() : environmentProperties;
this.deploymentProperties = deploymentProperties == null ? new HashMap<String, String>() : deploymentProperties;
setApplicationName(applicationName);
}
/**
@@ -90,6 +98,26 @@ public class TaskLaunchRequest implements Serializable{
return deploymentProperties;
}
/**
* Returns the name that will be associated with the launched task.
*
* @return string containing the application name.
*/
public String getApplicationName() {
return applicationName;
}
/**
* Sets the name to be applied to the launched task. If set
* to null then the launched task name will be "Task-<unique id>".
*
* @param applicationName the name to be
*/
public void setApplicationName(String applicationName) {
this.applicationName = !StringUtils.hasText(applicationName) ? "Task-" +
UUID.randomUUID().toString() : applicationName;
}
@Override
public String toString() {
return "TaskLaunchRequest{" +

View File

@@ -62,7 +62,7 @@ public class TaskLauncherSink {
Assert.notNull(this.taskLauncher, "TaskLauncher has not been initialized");
logger.info("Launching Task for the following resource " + taskLaunchRequest);
Resource resource = this.resourceLoader.getResource(taskLaunchRequest.getUri());
AppDefinition definition = new AppDefinition("Task-" + taskLaunchRequest.hashCode(), taskLaunchRequest.getEnvironmentProperties());
AppDefinition definition = new AppDefinition(taskLaunchRequest.getApplicationName(), taskLaunchRequest.getEnvironmentProperties());
AppDeploymentRequest request = new AppDeploymentRequest(definition, resource, taskLaunchRequest.getDeploymentProperties(), taskLaunchRequest.getCommandlineArguments());
this.taskLauncher.launch(request);
}