Use map for deployables, not array (key is the name)
This commit is contained in:
@@ -2,7 +2,7 @@ spring:
|
||||
cloud:
|
||||
launcher:
|
||||
deployables:
|
||||
- name: foo
|
||||
foo:
|
||||
coordinates: com.example:foo:0.0.1-SNAPSHOT
|
||||
port: 8000
|
||||
waitUntilStarted: true
|
||||
|
||||
@@ -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<Deployable> deployables = new ArrayList<>();
|
||||
private Map<String, Deployable> deployables = new LinkedHashMap<>();
|
||||
|
||||
@NotNull
|
||||
private List<String> deploy = new ArrayList<>();
|
||||
@@ -49,11 +52,11 @@ public class DeployerProperties {
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
public List<Deployable> getDeployables() {
|
||||
public Map<String, Deployable> getDeployables() {
|
||||
return this.deployables;
|
||||
}
|
||||
|
||||
public void setDeployables(List<Deployable> deployables) {
|
||||
public void setDeployables(Map<String, Deployable> 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() {
|
||||
|
||||
@@ -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<String> names = new ArrayList<>();
|
||||
for (Deployable deployable : properties.getDeployables()) {
|
||||
names.add(deployable.getName());
|
||||
}
|
||||
Collection<String> 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<Deployable> deployables = new ArrayList<>(properties.getDeployables());
|
||||
ArrayList<Deployable> deployables = new ArrayList<>(properties.getDeployables().values());
|
||||
OrderComparator.sort(deployables);
|
||||
|
||||
logger.debug("Deployables {}", properties.getDeployables());
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user