Convert thread to an actual application

User can now use spring boot CLI as before or alternatively just
java -jar the deployer app.
This commit is contained in:
Dave Syer
2016-12-15 14:43:48 +00:00
parent e3a0dc8395
commit 7e31e9b36c
7 changed files with 75 additions and 81 deletions

View File

@@ -16,8 +16,17 @@
package org.springframework.cloud.launcher.deployer;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.env.YamlPropertySourceLoader;
import org.springframework.cloud.deployer.spi.app.AppDeployer;
import org.springframework.cloud.deployer.spi.app.AppStatus;
@@ -37,14 +46,6 @@ import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.util.StringUtils;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import static org.springframework.util.StringUtils.collectionToCommaDelimitedString;
/**
@@ -102,8 +103,7 @@ public class Deployer {
logger.debug("Deployables {}", properties.getDeployables());
for (Deployable deployable : deployables) {
deployInternal(deployer, resourceLoader, deployable,
properties, environment);
deployInternal(deployer, resourceLoader, deployable, properties, environment);
}
for (Deployable deployable : deployables) {
@@ -251,10 +251,11 @@ public class Deployer {
private PropertySource<?> extractPropertySource(String path) {
PropertySource<?> source = null;
Resource resource = new ClassPathResource("config" + path, DeployerThread.class);
Resource resource = new ClassPathResource("config" + path,
DeployerApplication.class);
source = loadPropertySource(resource, path);
if (source == null) {
resource = new ClassPathResource(path, DeployerThread.class);
resource = new ClassPathResource(path, DeployerApplication.class);
source = loadPropertySource(resource, path);
}
if (source == null) {

View File

@@ -16,8 +16,14 @@
package org.springframework.cloud.launcher.deployer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.Banner.Mode;
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
@@ -27,31 +33,27 @@ import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
/**
* @author Spencer Gibb
*/
public class DeployerThread extends Thread {
public class DeployerApplication {
private static final Logger logger = LoggerFactory.getLogger(DeployerThread.class);
private static final Logger logger = LoggerFactory
.getLogger(DeployerApplication.class);
private static final String DEFAULT_VERSION = "1.2.3.BUILD-SNAPSHOT";
private static final String DEFAULT_VERSION = "1.3.0.BUILD-SNAPSHOT";
private String[] args;
public DeployerThread(ClassLoader classLoader, String... args) {
super("spring-cloud-launcher");
public DeployerApplication(String... args) {
this.args = args;
setContextClassLoader(classLoader);
setDaemon(true);
}
@Override
public void run() {
public static void main(String[] args) {
new DeployerApplication(args).run();
}
void run() {
List<String> list = Arrays.asList(this.args);
if (list.contains("--launcher.list=true")) {
quiet();
@@ -64,9 +66,10 @@ public class DeployerThread extends Thread {
private void quiet() {
try {
LogbackLoggingSystem.get(ClassUtils.getDefaultClassLoader()).setLogLevel("ROOT",
LogLevel.OFF);
} catch (Exception e) {
LogbackLoggingSystem.get(ClassUtils.getDefaultClassLoader())
.setLogLevel("ROOT", LogLevel.OFF);
}
catch (Exception e) {
logger.error("Unable to turn of ROOT logger for quiet()", e);
}
}
@@ -98,7 +101,7 @@ public class DeployerThread extends Thread {
}
private String getVersion() {
Package pkg = DeployerThread.class.getPackage();
Package pkg = DeployerApplication.class.getPackage();
return (pkg != null ? pkg.getImplementationVersion() : DEFAULT_VERSION);
}

View File

@@ -25,26 +25,28 @@ import static org.junit.Assert.assertThat;
/**
* @author Spencer Gibb
*/
public class DeployerThreadTests {
public class DeployerApplicationTests {
@Rule
public OutputCapture output = new OutputCapture();
@Test
public void testCreateClassLoaderAndListDeployables() throws Exception {
new DeployerThread(DeployerThread.class.getClassLoader(), "--launcher.list=true").run();;
new DeployerApplication("--launcher.list=true").run();
assertThat(output.toString(), containsString("configserver"));
}
@Test
public void testNonOptionArgsPassedDown() throws Exception {
new DeployerThread(DeployerThread.class.getClassLoader(), "--launcher.list=true", "--spring.profiles.active=test").run();
new DeployerApplication("--launcher.list=true", "--spring.profiles.active=test")
.run();
assertThat(output.toString(), containsString("foo"));
}
@Test
public void testInvalidDeployableFails() throws Exception {
new DeployerThread(DeployerThread.class.getClassLoader(), "--launcher.deploy=foo,bar").run();
assertThat(output.toString(), containsString("The following are not valid: 'foo,bar'"));
new DeployerApplication("--launcher.deploy=foo,bar").run();
assertThat(output.toString(),
containsString("The following are not valid: 'foo,bar'"));
}
}