diff --git a/spring-cloud-launcher/spring-cloud-launcher-cli/src/test/resources/cloud-test.yml b/spring-cloud-launcher/spring-cloud-launcher-cli/src/test/resources/cloud-test.yml index f2911d3..7c68477 100644 --- a/spring-cloud-launcher/spring-cloud-launcher-cli/src/test/resources/cloud-test.yml +++ b/spring-cloud-launcher/spring-cloud-launcher-cli/src/test/resources/cloud-test.yml @@ -2,7 +2,7 @@ spring: cloud: launcher: deployables: - - name: foo + foo: coordinates: com.example:foo:0.0.1-SNAPSHOT port: 8000 waitUntilStarted: true diff --git a/spring-cloud-launcher/spring-cloud-launcher-deployer/src/main/java/org/springframework/cloud/launcher/deployer/DeployerProperties.java b/spring-cloud-launcher/spring-cloud-launcher-deployer/src/main/java/org/springframework/cloud/launcher/deployer/DeployerProperties.java index 1d0e8e6..92a9d9c 100644 --- a/spring-cloud-launcher/spring-cloud-launcher-deployer/src/main/java/org/springframework/cloud/launcher/deployer/DeployerProperties.java +++ b/spring-cloud-launcher/spring-cloud-launcher-deployer/src/main/java/org/springframework/cloud/launcher/deployer/DeployerProperties.java @@ -17,8 +17,11 @@ package org.springframework.cloud.launcher.deployer; import java.util.ArrayList; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; +import javax.annotation.PostConstruct; import javax.validation.constraints.NotNull; import org.hibernate.validator.constraints.NotEmpty; @@ -32,7 +35,7 @@ import org.springframework.core.Ordered; public class DeployerProperties { @NotNull - private List deployables = new ArrayList<>(); + private Map deployables = new LinkedHashMap<>(); @NotNull private List deploy = new ArrayList<>(); @@ -49,11 +52,11 @@ public class DeployerProperties { this.list = list; } - public List getDeployables() { + public Map getDeployables() { return this.deployables; } - public void setDeployables(List deployables) { + public void setDeployables(Map deployables) { this.deployables = deployables; } @@ -72,6 +75,16 @@ public class DeployerProperties { public void setStatusSleepMillis(int statusSleepMillis) { this.statusSleepMillis = statusSleepMillis; } + + @PostConstruct + public void init() { + for (String name : deployables.keySet()) { + Deployable deployable = deployables.get(name); + if (deployable.getName()==null) { + deployable.setName(name); + } + } + } @Override public String toString() { diff --git a/spring-cloud-launcher/spring-cloud-launcher-deployer/src/main/java/org/springframework/cloud/launcher/deployer/DeployerThread.java b/spring-cloud-launcher/spring-cloud-launcher-deployer/src/main/java/org/springframework/cloud/launcher/deployer/DeployerThread.java index c74e2cb..43622a5 100644 --- a/spring-cloud-launcher/spring-cloud-launcher-deployer/src/main/java/org/springframework/cloud/launcher/deployer/DeployerThread.java +++ b/spring-cloud-launcher/spring-cloud-launcher-deployer/src/main/java/org/springframework/cloud/launcher/deployer/DeployerThread.java @@ -67,7 +67,7 @@ public class DeployerThread extends Thread { private String[] args; - public DeployerThread(ClassLoader classLoader, String[] args) { + public DeployerThread(ClassLoader classLoader, String... args) { super("spring-cloud-launcher"); this.args = args; setContextClassLoader(classLoader); @@ -94,10 +94,7 @@ public class DeployerThread extends Thread { private void list() { DeployerProperties properties = loadCloudProperties(); if (!properties.getDeployables().isEmpty()) { - Collection names = new ArrayList<>(); - for (Deployable deployable : properties.getDeployables()) { - names.add(deployable.getName()); - } + Collection names = new ArrayList<>(properties.getDeployables().keySet()); System.out.println(StringUtils.collectionToDelimitedString(names, " ")); } } @@ -188,7 +185,7 @@ public class DeployerThread extends Thread { DeployerProperties properties = context.getBean(DeployerProperties.class); - ArrayList deployables = new ArrayList<>(properties.getDeployables()); + ArrayList deployables = new ArrayList<>(properties.getDeployables().values()); OrderComparator.sort(deployables); logger.debug("Deployables {}", properties.getDeployables()); diff --git a/spring-cloud-launcher/spring-cloud-launcher-deployer/src/main/resources/cloud.yml b/spring-cloud-launcher/spring-cloud-launcher-deployer/src/main/resources/cloud.yml index e2629dd..7dd9151 100644 --- a/spring-cloud-launcher/spring-cloud-launcher-deployer/src/main/resources/cloud.yml +++ b/spring-cloud-launcher/spring-cloud-launcher-deployer/src/main/resources/cloud.yml @@ -5,33 +5,33 @@ spring: cloud: launcher: deployables: - - name: configserver + configserver: coordinates: ${dt.pre}configserver:${dt.ver} port: 8888 waitUntilStarted: true order: -100 - - name: dataflow + dataflow: coordinates: ${dt.pre}dataflow:${dt.ver} port: 9393 - - name: eureka + eureka: coordinates: ${dt.pre}eureka:${dt.ver} port: 8761 message: To see the dashboard open http://localhost:8761 - - name: h2 + h2: coordinates: ${dt.pre}h2:${dt.ver} port: 9095 message: Connect on jdbc:h2:tcp://localhost:9096/./target/test, web console at http://localhost:9095 waitUntilStarted: true order: -50 - - name: hystrixdashboard + hystrixdashboard: coordinates: ${dt.pre}hystrixdashboard:${dt.ver} port: 7979 - - name: kafka + kafka: coordinates: ${dt.pre}kafka:${dt.ver} port: 9091 waitUntilStarted: true order: -200 - - name: zipkin + zipkin: coordinates: ${dt.pre}zipkin:${dt.ver} port: 9411 order: 0 diff --git a/spring-cloud-launcher/spring-cloud-launcher-deployer/src/test/java/org/springframework/cloud/launcher/deployer/DeployerThreadTests.java b/spring-cloud-launcher/spring-cloud-launcher-deployer/src/test/java/org/springframework/cloud/launcher/deployer/DeployerThreadTests.java new file mode 100644 index 0000000..de2c2c5 --- /dev/null +++ b/spring-cloud-launcher/spring-cloud-launcher-deployer/src/test/java/org/springframework/cloud/launcher/deployer/DeployerThreadTests.java @@ -0,0 +1,39 @@ +/* + * Copyright 2013-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.launcher.deployer; + +import static org.hamcrest.CoreMatchers.containsString; +import static org.junit.Assert.assertThat; + +import org.junit.Rule; +import org.junit.Test; + +/** + * @author Spencer Gibb + */ +public class DeployerThreadTests { + + @Rule + public OutputCapture output = new OutputCapture(); + + @Test + public void testCreateClassLoaderAndListDeployables() throws Exception { + new DeployerThread(DeployerThread.class.getClassLoader(), "--launcher.list=true").run();; + assertThat(output.toString(), containsString("configserver")); + } + +} diff --git a/spring-cloud-launcher/spring-cloud-launcher-deployer/src/test/java/org/springframework/cloud/launcher/deployer/OutputCapture.java b/spring-cloud-launcher/spring-cloud-launcher-deployer/src/test/java/org/springframework/cloud/launcher/deployer/OutputCapture.java new file mode 100644 index 0000000..7721962 --- /dev/null +++ b/spring-cloud-launcher/spring-cloud-launcher-deployer/src/test/java/org/springframework/cloud/launcher/deployer/OutputCapture.java @@ -0,0 +1,127 @@ +/* + * Copyright 2012-2014 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.launcher.deployer; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.io.PrintStream; + +import org.junit.rules.TestRule; +import org.junit.runner.Description; +import org.junit.runners.model.Statement; + +/** + * Capture output from System.out and System.err. + * + * @author Phillip Webb + */ +public class OutputCapture implements TestRule { + + private CaptureOutputStream captureOut; + + private CaptureOutputStream captureErr; + + private ByteArrayOutputStream copy; + + @Override + public Statement apply(final Statement base, Description description) { + return new Statement() { + @Override + public void evaluate() throws Throwable { + captureOutput(); + try { + base.evaluate(); + } + finally { + releaseOutput(); + } + } + }; + } + + protected void captureOutput() { + this.copy = new ByteArrayOutputStream(); + this.captureOut = new CaptureOutputStream(System.out, this.copy); + this.captureErr = new CaptureOutputStream(System.err, this.copy); + System.setOut(new PrintStream(this.captureOut)); + System.setErr(new PrintStream(this.captureErr)); + } + + protected void releaseOutput() { + System.setOut(this.captureOut.getOriginal()); + System.setErr(this.captureErr.getOriginal()); + this.copy = null; + } + + public void flush() { + try { + this.captureOut.flush(); + this.captureErr.flush(); + } + catch (IOException ex) { + // ignore + } + } + + @Override + public String toString() { + flush(); + return this.copy.toString(); + } + + private static class CaptureOutputStream extends OutputStream { + + private final PrintStream original; + + private final OutputStream copy; + + CaptureOutputStream(PrintStream original, OutputStream copy) { + this.original = original; + this.copy = copy; + } + + @Override + public void write(int b) throws IOException { + this.copy.write(b); + this.original.write(b); + this.original.flush(); + } + + @Override + public void write(byte[] b) throws IOException { + write(b, 0, b.length); + } + + @Override + public void write(byte[] b, int off, int len) throws IOException { + this.copy.write(b, off, len); + this.original.write(b, off, len); + } + + public PrintStream getOriginal() { + return this.original; + } + + @Override + public void flush() throws IOException { + this.copy.flush(); + this.original.flush(); + } + } + +}