mirror of
https://github.com/apache/maven-mvnd.git
synced 2025-10-16 15:34:17 +00:00
Improve status and daemon selection output
This commit is contained in:
@@ -20,6 +20,9 @@ import java.io.InputStream;
|
|||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.ZoneId;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@@ -105,11 +108,13 @@ public class Client {
|
|||||||
try (DaemonRegistry registry = new DaemonRegistry(layout.registry())) {
|
try (DaemonRegistry registry = new DaemonRegistry(layout.registry())) {
|
||||||
boolean status = args.remove("--status");
|
boolean status = args.remove("--status");
|
||||||
if (status) {
|
if (status) {
|
||||||
output.log(String.format(" %36s %5s %5s %7s %s",
|
output.log(String.format(" %36s %7s %5s %7s %s",
|
||||||
"UUID", "PID", "Port", "Status", "Timestamp"));
|
"UUID", "PID", "Port", "Status", "Last activity"));
|
||||||
registry.getAll().forEach(d -> output.log(String.format(" %36s %5s %5s %7s %s",
|
registry.getAll().forEach(d -> output.log(String.format(" %36s %7s %5s %7s %s",
|
||||||
d.getUid(), d.getPid(), d.getAddress(), d.getState(),
|
d.getUid(), d.getPid(), d.getAddress(), d.getState(),
|
||||||
new Date(Math.max(d.getLastIdle(), d.getLastBusy())).toString())));
|
LocalDateTime.ofInstant(
|
||||||
|
Instant.ofEpochMilli(Math.max(d.getLastIdle(), d.getLastBusy())),
|
||||||
|
ZoneId.systemDefault()))));
|
||||||
return new ClientResult<O>(argv, true, output);
|
return new ClientResult<O>(argv, true, output);
|
||||||
}
|
}
|
||||||
boolean stop = args.remove("--stop");
|
boolean stop = args.remove("--stop");
|
||||||
@@ -146,7 +151,7 @@ public class Client {
|
|||||||
|
|
||||||
DaemonConnector connector = new DaemonConnector(layout, registry, this::startDaemon, new MessageSerializer());
|
DaemonConnector connector = new DaemonConnector(layout, registry, this::startDaemon, new MessageSerializer());
|
||||||
List<String> opts = new ArrayList<>();
|
List<String> opts = new ArrayList<>();
|
||||||
DaemonClientConnection daemon = connector.connect(new DaemonCompatibilitySpec(javaHome.toString(), opts));
|
DaemonClientConnection daemon = connector.connect(new DaemonCompatibilitySpec(javaHome, opts));
|
||||||
|
|
||||||
daemon.dispatch(new Message.BuildRequest(
|
daemon.dispatch(new Message.BuildRequest(
|
||||||
args,
|
args,
|
||||||
|
@@ -16,36 +16,42 @@
|
|||||||
package org.jboss.fuse.mvnd.client;
|
package org.jboss.fuse.mvnd.client;
|
||||||
|
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public class DaemonCompatibilitySpec {
|
public class DaemonCompatibilitySpec {
|
||||||
|
|
||||||
private final String javaHome;
|
private final Path javaHome;
|
||||||
private final List<String> options;
|
private final List<String> options;
|
||||||
|
|
||||||
public DaemonCompatibilitySpec(String javaHome, List<String> options) {
|
/**
|
||||||
this.javaHome = javaHome;
|
* @param javaHome make sure the Path is a result of {@link Path#toRealPath(java.nio.file.LinkOption...)}
|
||||||
this.options = options;
|
* @param options the options
|
||||||
|
*/
|
||||||
|
public DaemonCompatibilitySpec(Path javaHome, List<String> options) {
|
||||||
|
this.javaHome = Objects.requireNonNull(javaHome, "javaHome");
|
||||||
|
this.options = Objects.requireNonNull(options, "options");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSatisfiedBy(DaemonInfo daemon) {
|
public Result isSatisfiedBy(DaemonInfo daemon) {
|
||||||
return whyUnsatisfied(daemon) == null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String whyUnsatisfied(DaemonInfo daemon) {
|
|
||||||
if (!javaHomeMatches(daemon)) {
|
if (!javaHomeMatches(daemon)) {
|
||||||
return "Java home is different.\n" + description(daemon);
|
return new Result(false, () -> "Java home is different.\n" + diff(daemon));
|
||||||
} else if (!daemonOptsMatch(daemon)) {
|
|
||||||
return "At least one daemon option is different.\n" + description(daemon);
|
|
||||||
}
|
}
|
||||||
return null;
|
if (!daemonOptsMatch(daemon)) {
|
||||||
|
return new Result(false, () -> "At least one daemon option is different.\n" + diff(daemon));
|
||||||
|
}
|
||||||
|
return new Result(true, () -> {throw new RuntimeException("No reason if DaemonCompatibilityResult.compatible == true");});
|
||||||
}
|
}
|
||||||
|
|
||||||
private String description(DaemonInfo context) {
|
private String diff(DaemonInfo context) {
|
||||||
return "Wanted: " + this + "\n"
|
final StringBuilder sb = new StringBuilder("Wanted: ");
|
||||||
+ "Actual: " + context + "\n";
|
appendFields(sb);
|
||||||
|
sb.append("\nActual: ");
|
||||||
|
context.appendNonKeyFields(sb).append("uid=").append(context.getUid()).append('\n');
|
||||||
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean daemonOptsMatch(DaemonInfo daemon) {
|
private boolean daemonOptsMatch(DaemonInfo daemon) {
|
||||||
@@ -54,16 +60,35 @@ public class DaemonCompatibilitySpec {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean javaHomeMatches(DaemonInfo daemon) {
|
private boolean javaHomeMatches(DaemonInfo daemon) {
|
||||||
return Objects.equals(
|
return javaHome.equals(Paths.get(daemon.getJavaHome()));
|
||||||
Paths.get(daemon.getJavaHome()).normalize(),
|
}
|
||||||
Paths.get(javaHome).normalize());
|
|
||||||
|
StringBuilder appendFields(StringBuilder sb) {
|
||||||
|
return sb.append("javaHome=").append(javaHome)
|
||||||
|
.append(", options=").append(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "DaemonCompatibilitySpec{" +
|
return appendFields(new StringBuilder("DaemonCompatibilitySpec{")).append('}').toString();
|
||||||
"javaHome='" + javaHome + '\'' +
|
}
|
||||||
", daemonOpts=" + options +
|
|
||||||
'}';
|
public static class Result {
|
||||||
|
private final boolean compatible;
|
||||||
|
private final Supplier<String> why;
|
||||||
|
|
||||||
|
Result(boolean compatible, Supplier<String> why) {
|
||||||
|
super();
|
||||||
|
this.compatible = compatible;
|
||||||
|
this.why = why;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isCompatible() {
|
||||||
|
return compatible;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getWhy() {
|
||||||
|
return why.get();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -28,6 +28,7 @@ import java.util.Optional;
|
|||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import org.jboss.fuse.mvnd.client.DaemonCompatibilitySpec.Result;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@@ -179,12 +180,12 @@ public class DaemonConnector {
|
|||||||
private List<DaemonInfo> getCompatibleDaemons(Iterable<DaemonInfo> daemons, DaemonCompatibilitySpec constraint) {
|
private List<DaemonInfo> getCompatibleDaemons(Iterable<DaemonInfo> daemons, DaemonCompatibilitySpec constraint) {
|
||||||
List<DaemonInfo> compatibleDaemons = new LinkedList<>();
|
List<DaemonInfo> compatibleDaemons = new LinkedList<>();
|
||||||
for (DaemonInfo daemon : daemons) {
|
for (DaemonInfo daemon : daemons) {
|
||||||
if (constraint.isSatisfiedBy(daemon)) {
|
final Result result = constraint.isSatisfiedBy(daemon);
|
||||||
|
if (result.isCompatible()) {
|
||||||
compatibleDaemons.add(daemon);
|
compatibleDaemons.add(daemon);
|
||||||
} else {
|
} else {
|
||||||
LOGGER.info("Found daemon {} however it does not match the desired criteria.\n"
|
LOGGER.info("{} daemon {} does not match the desired criteria: "
|
||||||
+ constraint.whyUnsatisfied(daemon) + "\n"
|
+ result.getWhy(), daemon.getState(), daemon.getUid());
|
||||||
+ " Looking for a different daemon...", daemon);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return compatibleDaemons;
|
return compatibleDaemons;
|
||||||
|
@@ -18,6 +18,7 @@ package org.jboss.fuse.mvnd.client;
|
|||||||
import static org.jboss.fuse.mvnd.client.DaemonState.Busy;
|
import static org.jboss.fuse.mvnd.client.DaemonState.Busy;
|
||||||
import static org.jboss.fuse.mvnd.client.DaemonState.Idle;
|
import static org.jboss.fuse.mvnd.client.DaemonState.Idle;
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class DaemonInfo {
|
public class DaemonInfo {
|
||||||
@@ -113,18 +114,20 @@ public class DaemonInfo {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "DaemonInfo{" +
|
final StringBuilder sb = new StringBuilder("DaemonInfo{uid=").append(uid);
|
||||||
"uid='" + uid + '\'' +
|
appendNonKeyFields(sb);
|
||||||
", javaHome='" + javaHome + '\'' +
|
return sb.append('}').toString();
|
||||||
", mavenHome='" + mavenHome + '\'' +
|
}
|
||||||
", pid=" + pid +
|
public StringBuilder appendNonKeyFields(StringBuilder sb) {
|
||||||
", address=" + address +
|
return sb.append("javaHome=").append(javaHome)
|
||||||
", idleTimeout=" + idleTimeout +
|
.append(", options=").append(options)
|
||||||
", locale='" + locale + '\'' +
|
.append(", mavenHome=").append(mavenHome)
|
||||||
", options=" + options +
|
.append(", pid=").append(pid)
|
||||||
", state=" + state +
|
.append(", address=").append(address)
|
||||||
", lastIdle=" + lastIdle +
|
.append(", idleTimeout=").append(idleTimeout)
|
||||||
", lastBusy=" + lastBusy +
|
.append(", locale=").append(locale)
|
||||||
'}';
|
.append(", state=").append(state)
|
||||||
|
.append(", lastIdle=").append(lastIdle)
|
||||||
|
.append(", lastBusy=").append(lastBusy);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,6 +16,7 @@
|
|||||||
package org.jboss.fuse.mvnd.daemon;
|
package org.jboss.fuse.mvnd.daemon;
|
||||||
|
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -24,6 +25,7 @@ import java.util.function.ToLongFunction;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.jboss.fuse.mvnd.client.DaemonCompatibilitySpec;
|
import org.jboss.fuse.mvnd.client.DaemonCompatibilitySpec;
|
||||||
|
import org.jboss.fuse.mvnd.client.DaemonCompatibilitySpec.Result;
|
||||||
import org.jboss.fuse.mvnd.client.DaemonExpirationStatus;
|
import org.jboss.fuse.mvnd.client.DaemonExpirationStatus;
|
||||||
import org.jboss.fuse.mvnd.client.DaemonInfo;
|
import org.jboss.fuse.mvnd.client.DaemonInfo;
|
||||||
import org.jboss.fuse.mvnd.client.DaemonState;
|
import org.jboss.fuse.mvnd.client.DaemonState;
|
||||||
@@ -129,9 +131,10 @@ public class DaemonExpiration {
|
|||||||
static DaemonExpirationStrategy compatible() {
|
static DaemonExpirationStrategy compatible() {
|
||||||
return daemon -> {
|
return daemon -> {
|
||||||
DaemonCompatibilitySpec constraint = new DaemonCompatibilitySpec(
|
DaemonCompatibilitySpec constraint = new DaemonCompatibilitySpec(
|
||||||
daemon.getInfo().getJavaHome(), daemon.getInfo().getOptions());
|
Paths.get(daemon.getInfo().getJavaHome()), daemon.getInfo().getOptions());
|
||||||
long compatible = daemon.getRegistry().getAll().stream()
|
long compatible = daemon.getRegistry().getAll().stream()
|
||||||
.filter(constraint::isSatisfiedBy)
|
.map(constraint::isSatisfiedBy)
|
||||||
|
.filter(Result::isCompatible)
|
||||||
.count();
|
.count();
|
||||||
if (compatible > 1) {
|
if (compatible > 1) {
|
||||||
return new DaemonExpirationResult(GRACEFUL_EXPIRE, "other compatible daemons were started");
|
return new DaemonExpirationResult(GRACEFUL_EXPIRE, "other compatible daemons were started");
|
||||||
|
@@ -24,6 +24,7 @@ import java.lang.reflect.Field;
|
|||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.nio.channels.ServerSocketChannel;
|
import java.nio.channels.ServerSocketChannel;
|
||||||
import java.nio.channels.SocketChannel;
|
import java.nio.channels.SocketChannel;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
@@ -101,7 +102,8 @@ public class Server implements AutoCloseable, Runnable {
|
|||||||
|
|
||||||
List<String> opts = new ArrayList<>();
|
List<String> opts = new ArrayList<>();
|
||||||
long cur = System.currentTimeMillis();
|
long cur = System.currentTimeMillis();
|
||||||
info = new DaemonInfo(uid, System.getProperty("java.home"), layout.mavenHome().toString(),
|
final Path javaHome = Paths.get(System.getProperty("java.home")).toRealPath();
|
||||||
|
info = new DaemonInfo(uid, javaHome.toString(), layout.mavenHome().toString(),
|
||||||
DaemonRegistry.getProcessId(), socket.socket().getLocalPort(),
|
DaemonRegistry.getProcessId(), socket.socket().getLocalPort(),
|
||||||
idleTimeout, Locale.getDefault().toLanguageTag(), opts,
|
idleTimeout, Locale.getDefault().toLanguageTag(), opts,
|
||||||
Busy, cur, cur);
|
Busy, cur, cur);
|
||||||
|
Reference in New Issue
Block a user