This commit is contained in:
crschnick
2025-03-05 20:37:49 +00:00
parent aaaaa3f003
commit f9c1b751f2
6 changed files with 18 additions and 14 deletions

View File

@@ -19,6 +19,7 @@ public class ContainerStoreState extends ShellStoreState {
String imageName;
String containerState;
Boolean shellMissing;
@Override
public DataStoreState mergeCopy(DataStoreState newer) {
@@ -32,5 +33,6 @@ public class ContainerStoreState extends ShellStoreState {
super.mergeBuilder(css, b);
b.containerState(useNewer(containerState, css.getContainerState()));
b.imageName(useNewer(imageName, css.getImageName()));
b.shellMissing(useNewer(shellMissing, css.getShellMissing()));
}
}

View File

@@ -15,6 +15,7 @@ import lombok.Value;
import java.util.Arrays;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@Value
public class ShellStoreFormat {
@@ -35,7 +36,7 @@ public class ShellStoreFormat {
@SuppressWarnings("unchecked")
public static <T extends ShellStoreState> ObservableValue<String> shellStore(
StoreSection section, Function<T, String> f) {
StoreSection section, Function<T, String[]> f) {
return BindingsHelper.map(section.getWrapper().getPersistentState(), o -> {
var s = (T) o;
var info = f.apply(s);
@@ -61,11 +62,11 @@ public class ShellStoreFormat {
.format();
}
var joined = Stream.concat(Stream.of(s.getTtyState() != null && s.getTtyState() != ShellTtyState.NONE ? "TTY" : null), Arrays.stream(info)).toArray(String[]::new);
return new ShellStoreFormat(
LicenseProvider.get().checkOsName(s.getOsName()),
formattedOsName(s.getOsName()),
s.getTtyState() != null && s.getTtyState() != ShellTtyState.NONE ? "TTY" : null,
info)
joined)
.format();
});
}

View File

@@ -83,8 +83,9 @@ public class IncusContainerStoreProvider implements ShellStoreProvider {
@Override
public ObservableValue<String> informationString(StoreSection section) {
return ShellStoreFormat.shellStore(
section, (ContainerStoreState s) -> DataStoreFormatter.capitalize(s.getContainerState()));
var c = (ContainerStoreState) section.getWrapper().getPersistentState().getValue();
var missing = c.getShellMissing() != null && c.getShellMissing() ? "No shell available" : null;
return ShellStoreFormat.shellStore(section, (ContainerStoreState s) -> new String[] {missing, s.getContainerState()});
}
@Override

View File

@@ -80,8 +80,9 @@ public class LxdContainerStoreProvider implements ShellStoreProvider {
@Override
public ObservableValue<String> informationString(StoreSection section) {
return ShellStoreFormat.shellStore(
section, (ContainerStoreState s) -> DataStoreFormatter.capitalize(s.getContainerState()));
var c = (ContainerStoreState) section.getWrapper().getPersistentState().getValue();
var missing = c.getShellMissing() != null && c.getShellMissing() ? "No shell available" : null;
return ShellStoreFormat.shellStore(section, (ContainerStoreState s) -> new String[] {missing, s.getContainerState()});
}
@Override

View File

@@ -155,16 +155,13 @@ public class PodmanContainerStore
return;
}
var stateBuilder = getState().toBuilder();
stateBuilder.running(false);
var hasShell = throwable.getMessage() == null
|| !throwable.getMessage().contains("OCI runtime exec failed");
if (!hasShell) {
stateBuilder.containerState("No shell available");
} else {
stateBuilder.containerState("Connection failed");
var stateBuilder = getState().toBuilder();
stateBuilder.shellMissing(true);
setState(stateBuilder.build());
}
setState(stateBuilder.build());
});
return pc;
}

View File

@@ -81,7 +81,9 @@ public class PodmanContainerStoreProvider implements ShellStoreProvider {
@Override
public ObservableValue<String> informationString(StoreSection section) {
return ShellStoreFormat.shellStore(section, (ContainerStoreState s) -> s.getContainerState());
var c = (ContainerStoreState) section.getWrapper().getPersistentState().getValue();
var missing = c.getShellMissing() != null && c.getShellMissing() ? "No shell available" : null;
return ShellStoreFormat.shellStore(section, (ContainerStoreState s) -> new String[] {missing, s.getContainerState()});
}
@Override