Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/main/java/org/codelibs/fess/setup/Diagnostics.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,31 @@ public static List<String> distinctLines(final String text) {
}

/**
* Reports the engine version, and whether the cluster agrees on one.
* Reports the engine version, whether the cluster agrees on one, and whether it is the one
* whose plugins "install opensearch-plugins" installs.
*
* <p>An engine only accepts a plugin built for exactly its own version, so on any other engine
* that command fails unless it is given {@code --version}. Such an engine can run Fess with the
* plugins of its own version, so this is a warning.</p>
*
* @param versions the distinct versions the nodes report
* @param pluginVersion the plugin version "install opensearch-plugins" installs without {@code --version}
* @return the check
*/
public static Check engineVersion(final List<String> versions) {
public static Check engineVersion(final List<String> versions, final String pluginVersion) {
if (versions.isEmpty()) {
return new Check(Status.FAIL, "engine version", "no node reported a version");
}
if (versions.size() > 1) {
// Fess talks to whichever node answers, so a mixed cluster is not a detail.
return new Check(Status.WARN, "engine version", "nodes disagree: " + String.join(", ", versions));
}
return new Check(Status.OK, "engine version", versions.get(0));
final String version = versions.get(0);
if (!version.equals(pluginVersion)) {
return new Check(Status.WARN, "engine version", version + " (this Fess installs the engine plugins for OpenSearch "
+ pluginVersion + "; for this engine, fess-setup install opensearch-plugins needs --version " + version + ")");
}
return new Check(Status.OK, "engine version", version);
}

/**
Expand Down
12 changes: 9 additions & 3 deletions src/main/java/org/codelibs/fess/setup/FessSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -895,9 +895,10 @@ private static int check(final Map<String, String> options, final Map<String, Co
try {
Downloader.readString(URI.create(url));
checks.add(new Diagnostics.Check(Diagnostics.Status.OK, "reachable", "yes"));
checks.add(
Diagnostics.engineVersion(Diagnostics.distinctLines(Downloader.readString(URI.create(url + "/_cat/nodes?h=version")))));
final ComponentDefinition opensearch = definitions.get("opensearch");
checks.add(
Diagnostics.engineVersion(Diagnostics.distinctLines(Downloader.readString(URI.create(url + "/_cat/nodes?h=version"))),
bundledPluginVersion(opensearch)));
final List<String> required = opensearch.list("plugin.artifacts").stream().map(FessSetup::artifactIdOf).toList();
checks.add(Diagnostics.enginePlugins(required,
Diagnostics.distinctLines(Downloader.readString(URI.create(url + "/_cat/plugins?h=component")))));
Expand Down Expand Up @@ -1407,10 +1408,15 @@ static void removePlugins(final ComponentDefinition definition, final Path home,
}
}

/** The version of the engine plugins that this build installs unless {@code --version} names another. */
private static String bundledPluginVersion(final ComponentDefinition opensearch) {
return opensearch.get("plugin.version");
}

private static void installPlugins(final ComponentDefinition definition, final Path home, final Map<String, String> options,
final PrintStream out) throws SetupException {
final String repository = definition.get("plugin.repository");
final String version = options.getOrDefault("version", definition.get("plugin.version"));
final String version = options.getOrDefault("version", bundledPluginVersion(definition));
final List<String> artifacts = definition.list("plugin.artifacts");
// Report every plugin that cannot be installed, not just the first: an old installation
// has all four at the wrong version, and fixing them one run at a time would take four runs.
Expand Down
21 changes: 18 additions & 3 deletions src/test/java/org/codelibs/fess/setup/DiagnosticsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,30 @@ public void test_distinctLines() {
*/
@Test
public void test_engineVersion_reportsAMixedCluster() {
final Check ok = Diagnostics.engineVersion(List.of("3.8.0"));
final Check ok = Diagnostics.engineVersion(List.of("3.8.0"), "3.8.0");
assertEquals(Status.OK, ok.status());
assertTrue(ok.detail().contains("3.8.0"), ok.detail());

final Check mixed = Diagnostics.engineVersion(List.of("3.8.0", "2.19.1"));
final Check mixed = Diagnostics.engineVersion(List.of("3.8.0", "2.19.1"), "3.8.0");
assertEquals(Status.WARN, mixed.status());
assertTrue(mixed.detail().contains("2.19.1"), mixed.detail());

assertEquals(Status.FAIL, Diagnostics.engineVersion(List.of()).status());
assertEquals(Status.FAIL, Diagnostics.engineVersion(List.of(), "3.8.0").status());
}

/**
* "install opensearch-plugins" fails on an engine of another version, a patch release included,
* so the check must not call such an engine fine.
*/
@Test
public void test_engineVersion_reportsAnEngineThatTheBundledPluginsDoNotFit() {
final Check older = Diagnostics.engineVersion(List.of("3.10.0"), "3.10.1");
assertEquals(Status.WARN, older.status());
assertTrue(older.detail().startsWith("3.10.0 "), older.detail());
assertTrue(older.detail().contains("OpenSearch 3.10.1"), older.detail());
assertTrue(older.detail().contains("--version 3.10.0"), older.detail());

assertEquals(Status.WARN, Diagnostics.engineVersion(List.of("3.10.2"), "3.10.1").status());
}

@Test
Expand Down
54 changes: 54 additions & 0 deletions src/test/java/org/codelibs/fess/setup/FessSetupTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.InetSocketAddress;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
Expand All @@ -35,6 +38,8 @@
import org.junit.jupiter.api.condition.OS;
import org.junit.jupiter.api.io.TempDir;

import com.sun.net.httpserver.HttpServer;

public class FessSetupTest {

@TempDir
Expand All @@ -56,6 +61,55 @@ private String err() {
return err.toString(StandardCharsets.UTF_8);
}

/** Answers what "check" asks an engine of the given version that has the four plugins. */
private static HttpServer startEngine(final String version) throws IOException {
final HttpServer server = HttpServer.create(new InetSocketAddress("127.0.0.1", 0), 0);
server.createContext("/", exchange -> {
final String body = switch (exchange.getRequestURI().getPath()) {
case "/_cat/nodes" -> version + "\n";
case "/_cat/plugins" -> "analysis-extension\nanalysis-fess\nconfigsync\nminhash\n";
case "/_cat/shards" -> "";
default -> "{}";
};
final byte[] bytes = body.getBytes(StandardCharsets.UTF_8);
exchange.sendResponseHeaders(200, bytes.length == 0 ? -1 : bytes.length);
try (OutputStream os = exchange.getResponseBody()) {
os.write(bytes);
}
});
server.start();
return server;
}

private int check(final String engineVersion) throws IOException {
final HttpServer server = startEngine(engineVersion);
try {
return run("check", "--url", "http://127.0.0.1:" + server.getAddress().getPort(), "--dest", tempDir.toString());
} finally {
server.stop(0);
}
}

@Test
public void test_check_warnsAboutAnEngineThatTheBundledPluginsDoNotFit() throws Exception {
final String bundled = FessSetup.loadDefinitions().get("opensearch").get("plugin.version");

assertEquals(0, check("3.10.0"), err());

assertTrue(out().contains("WARN engine version"), out());
assertTrue(out().contains("3.10.0 (this Fess installs the engine plugins for OpenSearch " + bundled), out());
assertTrue(out().contains("Usable, with warnings."), out());
assertFalse(out().contains("Everything checks out."), out());
}

@Test
public void test_check_acceptsTheEngineTheBundledPluginsAreBuiltFor() throws Exception {
assertEquals(0, check(FessSetup.loadDefinitions().get("opensearch").get("plugin.version")), err());

assertTrue(out().contains("OK engine version"), out());
assertTrue(out().contains("Everything checks out."), out());
}

@Test
public void test_noArguments_printsUsage() {
assertEquals(2, run());
Expand Down
Loading