Update TaskLaunchRequest to use URI
Update examples to use apps instead of modules resolves spring-cloud/spring-cloud-task#146
This commit is contained in:
@@ -18,11 +18,13 @@ package org.springframework.cloud.task.launcher;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Request that contains the maven repository and property information required by the
|
||||
@@ -33,76 +35,37 @@ import org.springframework.util.StringUtils;
|
||||
public class TaskLaunchRequest implements Serializable{
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private String artifact;
|
||||
private String taskGroupId;
|
||||
private String taskVersion;
|
||||
private String taskExtension;
|
||||
private String taskClassifier;
|
||||
private String uri;
|
||||
private List<String> commandlineArguments;
|
||||
private Map<String, String> properties;
|
||||
|
||||
/**
|
||||
* Constructor for the TaskLaunchRequest;
|
||||
* @param artifact is maven artifact coordinate for the task. Must not be empty nor null.
|
||||
* @param taskGroupId is maven groupId coordinate for the task. Must not be empty nor null.
|
||||
* @param taskVersion is maven version coordinate for the task. Must not be empty nor null.
|
||||
* @param taskExtension is maven extension coordinate for the task.
|
||||
* @param taskClassifier is maven classifier coordinate for the task.
|
||||
* @param uri the URI to the task artifact to be launched.
|
||||
* @param commandlineArguments list of commandlineArguments to be used by the task
|
||||
* @param properties is the environment variables for this task.
|
||||
*/
|
||||
public TaskLaunchRequest(String artifact, String taskGroupId, String taskVersion,
|
||||
String taskExtension, String taskClassifier,
|
||||
public TaskLaunchRequest(String uri, List<String> commandlineArguments,
|
||||
Map<String, String> properties) {
|
||||
Assert.hasText(artifact, "artifact must not be empty nor null.");
|
||||
Assert.hasText(taskGroupId, "taskGroupID must not be empty nor null.");
|
||||
Assert.hasText(taskVersion, "taskVersion must not be empty nor null.");
|
||||
Assert.hasText(taskExtension, "taskExtension must not be empty nor null.");
|
||||
Assert.hasText(uri, "uri must not be empty nor null.");
|
||||
|
||||
this.artifact = artifact;
|
||||
this.taskGroupId = taskGroupId;
|
||||
this.taskVersion = taskVersion;
|
||||
this.taskExtension = taskExtension;
|
||||
this.taskClassifier = taskClassifier;
|
||||
this.uri = uri;
|
||||
this.commandlineArguments = (commandlineArguments == null) ? new ArrayList<String>() : commandlineArguments;
|
||||
this.properties = properties == null ? new HashMap() : properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the group maven coordinate for the task.
|
||||
* @return group maven coordinate for the task.
|
||||
* Returns the current uri to the artifact for this launch request.
|
||||
*/
|
||||
public String getTaskGroupId() {
|
||||
return taskGroupId;
|
||||
public String getUri() {
|
||||
return uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the version maven coordinate for the task.
|
||||
* @return version maven coordinate for the task.
|
||||
* Returns an unmodifiable list of parameters that will be used for the task execution
|
||||
*/
|
||||
public String getTaskVersion() {
|
||||
return taskVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the extension maven coordinate for the task.
|
||||
* @return extension maven coordinate for the task.
|
||||
*/
|
||||
public String getTaskExtension() {
|
||||
return taskExtension;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the classifier maven coordinate for the task.
|
||||
* @return classifier maven coordinate for the task.
|
||||
*/
|
||||
public String getTaskClassifier() {
|
||||
return taskClassifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the artifact maven coordinate for the task.
|
||||
* @return artifact maven coordinate for the task.
|
||||
*/
|
||||
public String getArtifact() {
|
||||
return artifact;
|
||||
public List<String> getCommandlineArguments() {
|
||||
return Collections.unmodifiableList(commandlineArguments);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -116,12 +79,11 @@ public class TaskLaunchRequest implements Serializable{
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String coordinates = taskGroupId + ":" + artifact + ":" + taskVersion ;
|
||||
if(StringUtils.hasText(taskClassifier)){
|
||||
coordinates = coordinates + ":" + taskClassifier;
|
||||
}
|
||||
coordinates = coordinates + ":" + taskExtension;
|
||||
return coordinates;
|
||||
return "TaskLaunchRequest{" +
|
||||
"uri='" + uri + '\'' +
|
||||
", commandlineArguments=" + commandlineArguments +
|
||||
", properties=" + properties +
|
||||
'}';
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -135,19 +97,10 @@ public class TaskLaunchRequest implements Serializable{
|
||||
|
||||
TaskLaunchRequest that = (TaskLaunchRequest) o;
|
||||
|
||||
if (!artifact.equals(that.artifact)){
|
||||
if (!uri.equals(that.uri)){
|
||||
return false;
|
||||
}
|
||||
if (!taskGroupId.equals(that.taskGroupId)){
|
||||
return false;
|
||||
}
|
||||
if (!taskVersion.equals(that.taskVersion)){
|
||||
return false;
|
||||
}
|
||||
if (!taskExtension.equals(that.taskExtension)){
|
||||
return false;
|
||||
}
|
||||
if (taskClassifier != null ? !taskClassifier.equals(that.taskClassifier) : that.taskClassifier != null){
|
||||
if (!(commandlineArguments != null ? commandlineArguments.equals(that.commandlineArguments) : that.commandlineArguments == null)){
|
||||
return false;
|
||||
}
|
||||
return properties != null ? properties.equals(that.properties) : that.properties == null;
|
||||
@@ -156,11 +109,8 @@ public class TaskLaunchRequest implements Serializable{
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = artifact != null ? artifact.hashCode() : 0;
|
||||
result = 31 * result + (taskGroupId != null ? taskGroupId.hashCode() : 0);
|
||||
result = 31 * result + (taskVersion != null ? taskVersion.hashCode() : 0);
|
||||
result = 31 * result + (taskExtension != null ? taskExtension.hashCode() : 0);
|
||||
result = 31 * result + (taskClassifier != null ? taskClassifier.hashCode() : 0);
|
||||
int result = uri != null ? uri.hashCode() : 0;
|
||||
result = 31 * result + (commandlineArguments != null ? commandlineArguments.hashCode() : 0);
|
||||
result = 31 * result + (properties != null ? properties.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -16,13 +16,21 @@
|
||||
|
||||
package org.springframework.cloud.task.launcher;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.cloud.deployer.resource.maven.MavenProperties;
|
||||
import org.springframework.cloud.deployer.resource.maven.MavenResourceLoader;
|
||||
import org.springframework.cloud.deployer.resource.support.DelegatingResourceLoader;
|
||||
import org.springframework.cloud.deployer.spi.local.LocalDeployerProperties;
|
||||
import org.springframework.cloud.deployer.spi.local.LocalTaskLauncher;
|
||||
import org.springframework.cloud.deployer.spi.task.TaskLauncher;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
|
||||
/**
|
||||
* Creates the appropriate Task Launcher Configuration based on the TaskLauncher
|
||||
@@ -44,4 +52,25 @@ public class TaskLauncherConfiguration {
|
||||
}
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MavenResourceLoader mavenResourceLoader(MavenProperties properties) {
|
||||
return new MavenResourceLoader(properties);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(DelegatingResourceLoader.class)
|
||||
public DelegatingResourceLoader delegatingResourceLoader(MavenResourceLoader mavenResourceLoader) {
|
||||
Map<String, ResourceLoader> loaders = new HashMap<>();
|
||||
loaders.put("maven", mavenResourceLoader);
|
||||
return new DelegatingResourceLoader(loaders);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MavenProperties mavenProperties() {
|
||||
return new MavenConfigurationProperties();
|
||||
}
|
||||
|
||||
@ConfigurationProperties(prefix = "maven")
|
||||
static class MavenConfigurationProperties extends MavenProperties {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,15 +19,17 @@ package org.springframework.cloud.task.launcher;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cloud.deployer.resource.maven.MavenResource;
|
||||
import org.springframework.cloud.deployer.resource.support.DelegatingResourceLoader;
|
||||
import org.springframework.cloud.deployer.spi.core.AppDefinition;
|
||||
import org.springframework.cloud.deployer.spi.core.AppDeploymentRequest;
|
||||
import org.springframework.cloud.deployer.spi.task.TaskLauncher;
|
||||
import org.springframework.cloud.stream.annotation.EnableBinding;
|
||||
import org.springframework.cloud.stream.messaging.Sink;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.integration.annotation.ServiceActivator;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
|
||||
/**
|
||||
* A sink stream application that launches a tasks.
|
||||
*
|
||||
@@ -42,6 +44,9 @@ public class TaskLauncherSink {
|
||||
@Autowired
|
||||
public TaskLauncher taskLauncher;
|
||||
|
||||
@Autowired
|
||||
private DelegatingResourceLoader delegatingResourceLoader;
|
||||
|
||||
/**
|
||||
* Launches a task upon the receipt of a valid TaskLaunchRequest.
|
||||
* @param request is a TaskLaunchRequest containing the information required to launch
|
||||
@@ -55,15 +60,9 @@ public class TaskLauncherSink {
|
||||
private void launchTask(TaskLaunchRequest taskLaunchRequest) {
|
||||
Assert.notNull(taskLauncher, "TaskLauncher has not been initialized");
|
||||
logger.info("Launching Task for the following resource " + taskLaunchRequest);
|
||||
MavenResource resource = new MavenResource.Builder()
|
||||
.artifactId(taskLaunchRequest.getArtifact())
|
||||
.groupId(taskLaunchRequest.getTaskGroupId())
|
||||
.version(taskLaunchRequest.getTaskVersion())
|
||||
.extension(taskLaunchRequest.getTaskExtension())
|
||||
.classifier(taskLaunchRequest.getTaskClassifier())
|
||||
.build();
|
||||
AppDefinition definition = new AppDefinition(taskLaunchRequest.getArtifact(), taskLaunchRequest.getProperties());
|
||||
AppDeploymentRequest request = new AppDeploymentRequest(definition, resource);
|
||||
Resource resource = delegatingResourceLoader.getResource(taskLaunchRequest.getUri());
|
||||
AppDefinition definition = new AppDefinition("Task-" + taskLaunchRequest.hashCode(), taskLaunchRequest.getProperties());
|
||||
AppDeploymentRequest request = new AppDeploymentRequest(definition, resource, null, taskLaunchRequest.getCommandlineArguments());
|
||||
taskLauncher.launch(request);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user