mirror of
https://github.com/floci-io/floci-cli.git
synced 2026-12-06 11:38:07 -05:00
fix(services): list only enabled services, and make wait --service wait for one (#94)
The health contract reports each service as "running" (enabled) or "available" (disabled), and the CLI kept every name. So services listed a switched-off service under "(N enabled)", and wait --service returned at once for it. A service reported as "available" is now left out. Any other status, and the array of names, is read as before. The skill's "wait times out" entry names the switched-off case, and plugin.json is bumped. Signed-off-by: soreavis <263610811+soreavis@users.noreply.github.com>
This commit is contained in:
1 parent
5997910340
commit
e94a52da1e
4 files changed
+46
-3
No files matched your search
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"$schema": "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json",
|
||||
"name": "floci",
|
||||
"version": "1.1.0",
|
||||
"version": "1.1.1",
|
||||
"description": "Run, wire up and troubleshoot Floci, the free local emulators for AWS, GCP, Azure and OCI: floci-cli lifecycle, safe wiring of aws, gcloud, az, oci and the SDKs, docker run and Docker Compose files, several instances side by side, lookups in the published docs, and the Floci MCP server for agent tools.",
|
||||
"author": {
|
||||
"name": "Floci",
|
||||
|
||||
@@ -29,6 +29,7 @@ profile with a different `--port` rather than stopping containers you did not st
|
||||
Read `logs`. First pulls of the image and of child images (Lambda runtimes, postgres, k3s) can
|
||||
be slow; raise `--timeout`. `wait --service <name>` waits for one service on AWS, GCP and
|
||||
OCI; an unknown name, or any name on Azure, just times out.
|
||||
`wait --service` on a service switched off (see docker.md) times out as well.
|
||||
|
||||
**Requests reach real cloud**
|
||||
Most common cause is a fresh shell without the `eval`. Re-run the `env` command in the same
|
||||
|
||||
@@ -252,14 +252,16 @@ public class FlociHttpClient {
|
||||
}
|
||||
|
||||
// Older images report services as an array of names; the contract reports a
|
||||
// {name: status} object. Accept both.
|
||||
// {name: status} object, where "available" marks a disabled service. Accept both.
|
||||
private static String[] serviceNames(JsonNode services) {
|
||||
if (services.isArray()) {
|
||||
return MAPPER.convertValue(services, String[].class);
|
||||
}
|
||||
if (services.isObject()) {
|
||||
List<String> names = new ArrayList<>();
|
||||
services.fieldNames().forEachRemaining(names::add);
|
||||
for (var service : services.properties()) {
|
||||
if (!service.getValue().asText().equals("available")) names.add(service.getKey());
|
||||
}
|
||||
return names.toArray(String[]::new);
|
||||
}
|
||||
return new String[0];
|
||||
|
||||
@@ -2,6 +2,8 @@ package io.floci.cli.unit;
|
||||
|
||||
import com.sun.net.httpserver.HttpServer;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.commands.WaitCommand;
|
||||
import io.floci.cli.docker.DockerClient;
|
||||
import io.floci.cli.doctor.CheckResult;
|
||||
import io.floci.cli.doctor.CheckStatus;
|
||||
import io.floci.cli.doctor.checks.EndpointReachableCheck;
|
||||
@@ -13,13 +15,17 @@ import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PrintStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
@@ -307,6 +313,40 @@ class ControlPlaneFallbackTest {
|
||||
assertArrayEquals(new String[]{"s3", "sqs"}, client(ProductProfile.AWS).health().services());
|
||||
}
|
||||
|
||||
/** The contract reports a disabled service as "available": it is left out, and any other status is kept. */
|
||||
@Test
|
||||
void aServiceReportedAsAvailableIsDisabledAndLeftOut() throws Exception {
|
||||
route("GET /_floci/health", 200, "{\"status\":\"UP\",\"cloud\":\"aws\",\"services\":{\"s3\":\"running\",\"sqs\":\"available\",\"sns\":\"running\"}}");
|
||||
assertArrayEquals(new String[]{"s3", "sns"}, client(ProductProfile.AWS).health().services());
|
||||
|
||||
route("GET /_floci/health", 200, HEALTH_UP);
|
||||
assertArrayEquals(new String[]{"storage"}, client(ProductProfile.OCI).health().services());
|
||||
}
|
||||
|
||||
@Test
|
||||
void waitForADisabledServiceTimesOut() {
|
||||
route("GET /_floci/health", 200, "{\"status\":\"UP\",\"cloud\":\"aws\",\"services\":{\"s3\":\"running\",\"sqs\":\"available\"}}");
|
||||
DockerClient noContainer = new DockerClient() {
|
||||
@Override
|
||||
public Optional<ContainerInfo> inspectContainer(String name) {
|
||||
return Optional.empty();
|
||||
}
|
||||
};
|
||||
PrintStream out = System.out;
|
||||
PrintStream err = System.err;
|
||||
ByteArrayOutputStream errBuf = new ByteArrayOutputStream();
|
||||
System.setOut(new PrintStream(new ByteArrayOutputStream()));
|
||||
System.setErr(new PrintStream(errBuf));
|
||||
try {
|
||||
assertEquals(0, new CommandLine(new WaitCommand(ProductProfile.AWS, noContainer)).execute("--service", "s3", "--endpoint", endpoint()));
|
||||
assertEquals(1, new CommandLine(new WaitCommand(ProductProfile.AWS, noContainer)).execute("--service", "sqs", "--timeout", "300ms", "--endpoint", endpoint()));
|
||||
assertTrue(errBuf.toString().contains("Timed out waiting"), errBuf.toString());
|
||||
} finally {
|
||||
System.setOut(out);
|
||||
System.setErr(err);
|
||||
}
|
||||
}
|
||||
|
||||
// ---- doctor ------------------------------------------------------------------------------
|
||||
|
||||
@Test
|
||||
|
||||
Reference in new issue
Block a user