SCT-12 Creates the SCSt sink that can launch tasks.
resolves spring-cloud/spring-cloud-task#12
This commit is contained in:
committed by
Michael Minella
parent
f35f8ef52d
commit
aad0a0b1ee
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* 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 io.spring;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.cloud.stream.annotation.EnableBinding;
|
||||
import org.springframework.cloud.stream.messaging.Processor;
|
||||
import org.springframework.cloud.task.launcher.TaskLaunchRequest;
|
||||
import org.springframework.integration.annotation.Transformer;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* A processor that takes the maven repository coordinates and datasource configuration
|
||||
* for a task and sends a {@link TaskLaunchRequest} message to a task sink.
|
||||
*
|
||||
* @author Glenn Renfro
|
||||
*/
|
||||
@EnableBinding(Processor.class)
|
||||
@EnableConfigurationProperties(TaskProcessorProperties.class)
|
||||
public class TaskProcessor {
|
||||
|
||||
@Autowired
|
||||
private TaskProcessorProperties processorProperties;
|
||||
|
||||
@Transformer(inputChannel = Processor.INPUT, outputChannel = Processor.OUTPUT)
|
||||
public Object setupRequest(String message) {
|
||||
Map<String, String> properties = new HashMap<String,String>();
|
||||
if(StringUtils.hasText(processorProperties.getDataSourceUrl())){
|
||||
properties.put("spring_datasource_url",processorProperties.getDataSourceUrl());
|
||||
}
|
||||
if(StringUtils.hasText(processorProperties.getDataSourceDriverClassName())){
|
||||
properties.put("spring_datasource_driverClassName",processorProperties.getDataSourceDriverClassName());
|
||||
}
|
||||
if(StringUtils.hasText(processorProperties.getDataSourceUserName())){
|
||||
properties.put("spring_datasource_username",processorProperties.getDataSourceUserName());
|
||||
}
|
||||
if(StringUtils.hasText(processorProperties.getDataSourcePassword())){
|
||||
properties.put("spring_datasource_password",processorProperties.getDataSourcePassword());
|
||||
}
|
||||
properties.put("payload", message);
|
||||
|
||||
TaskLaunchRequest request = new TaskLaunchRequest(processorProperties.getArtifact(),
|
||||
processorProperties.getGroup(), processorProperties.getVersion(), processorProperties.getExtension(),
|
||||
processorProperties.getClassifiers(), properties);
|
||||
|
||||
return new GenericMessage<TaskLaunchRequest>(request);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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 io.spring;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* @author Glenn Renfro
|
||||
*/
|
||||
@SpringBootApplication
|
||||
public class TaskProcessorApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(TaskProcessorApplication.class, args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* 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 io.spring;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
/**
|
||||
* @author Glenn Renfro
|
||||
*/
|
||||
@ConfigurationProperties
|
||||
public class TaskProcessorProperties {
|
||||
|
||||
private static final String DEFAULT_GROUP = "io.spring";
|
||||
|
||||
private static final String DEFAULT_ARTIFACT = "timestamp-task";
|
||||
|
||||
private static final String DEFAULT_VERSION = "1.0.0.BUILD-SNAPSHOT";
|
||||
|
||||
private static final String DEFAULT_EXTENSION = "jar";
|
||||
|
||||
|
||||
private String group = DEFAULT_GROUP;
|
||||
|
||||
private String artifact = DEFAULT_ARTIFACT;
|
||||
|
||||
private String version = DEFAULT_VERSION;
|
||||
|
||||
private String extension = DEFAULT_EXTENSION;
|
||||
|
||||
private String classifiers;
|
||||
|
||||
private String dataSourceUrl;
|
||||
|
||||
private String dataSourceDriverClassName;
|
||||
|
||||
private String dataSourceUserName;
|
||||
|
||||
private String dataSourcePassword;
|
||||
|
||||
|
||||
public String getExtension() {
|
||||
return extension;
|
||||
}
|
||||
|
||||
public void setExtension(String extension) {
|
||||
this.extension = extension;
|
||||
}
|
||||
|
||||
public String getClassifiers() {
|
||||
return classifiers;
|
||||
}
|
||||
|
||||
public void setClassifiers(String classifiers) {
|
||||
this.classifiers = classifiers;
|
||||
}
|
||||
|
||||
public String getDataSourceUrl() {
|
||||
return dataSourceUrl;
|
||||
}
|
||||
|
||||
public void setDataSourceUrl(String dataSourceUrl) {
|
||||
this.dataSourceUrl = dataSourceUrl;
|
||||
}
|
||||
|
||||
public String getDataSourceDriverClassName() {
|
||||
return dataSourceDriverClassName;
|
||||
}
|
||||
|
||||
public void setDataSourceDriverClassName(String dataSourceDriverClassName) {
|
||||
this.dataSourceDriverClassName = dataSourceDriverClassName;
|
||||
}
|
||||
|
||||
public String getDataSourceUserName() {
|
||||
return dataSourceUserName;
|
||||
}
|
||||
|
||||
public void setDataSourceUserName(String dataSourceUserName) {
|
||||
this.dataSourceUserName = dataSourceUserName;
|
||||
}
|
||||
|
||||
public String getDataSourcePassword() {
|
||||
return dataSourcePassword;
|
||||
}
|
||||
|
||||
public void setDataSourcePassword(String dataSourcePassword) {
|
||||
this.dataSourcePassword = dataSourcePassword;
|
||||
}
|
||||
|
||||
public void setGroup(String group) {
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
public String getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
public String getArtifact() {
|
||||
return artifact;
|
||||
}
|
||||
|
||||
public void setArtifact(String artifact) {
|
||||
this.artifact = artifact;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user