From 7cf423ef58e741c63c908945d3e3f19ace0f78c2 Mon Sep 17 00:00:00 2001 From: Bartosz Spyrko-Smietanko Date: Wed, 17 Apr 2024 13:55:26 +0100 Subject: [PATCH] When subscribing server, force download of specific version of feature pack --- .../wildfly/prospero/it/cli/GenerateTest.java | 43 +++++-------------- .../actions/SubscribeNewServerAction.java | 7 ++- 2 files changed, 15 insertions(+), 35 deletions(-) diff --git a/integration-tests/src/test/java/org/wildfly/prospero/it/cli/GenerateTest.java b/integration-tests/src/test/java/org/wildfly/prospero/it/cli/GenerateTest.java index a49e56a27..78ab1e9be 100644 --- a/integration-tests/src/test/java/org/wildfly/prospero/it/cli/GenerateTest.java +++ b/integration-tests/src/test/java/org/wildfly/prospero/it/cli/GenerateTest.java @@ -19,7 +19,6 @@ import org.eclipse.aether.DefaultRepositorySystemSession; import org.eclipse.aether.RepositorySystem; -import org.eclipse.aether.artifact.Artifact; import org.eclipse.aether.artifact.DefaultArtifact; import org.eclipse.aether.resolution.ArtifactRequest; import org.eclipse.aether.resolution.ArtifactResolutionException; @@ -30,8 +29,8 @@ import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.wildfly.channel.ChannelManifest; -import org.wildfly.channel.ChannelManifestMapper; import org.wildfly.channel.Stream; +import org.wildfly.channel.version.VersionMatcher; import org.wildfly.prospero.api.KnownFeaturePacks; import org.wildfly.prospero.cli.ReturnCodes; import org.wildfly.prospero.cli.commands.CliConstants; @@ -45,17 +44,16 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; -import java.net.MalformedURLException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardCopyOption; import java.util.ArrayList; -import java.util.List; import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; +import static org.junit.Assert.assertTrue; + public class GenerateTest { private static final String PRODUCT = "wildfly"; @@ -90,35 +88,12 @@ public void testInstallWithProvisionConfig() throws Exception { // check the metadata existence Path manifestPath = ProsperoMetadataUtils.manifestPath(serverDir); Path configurationPath = ProsperoMetadataUtils.configurationPath(serverDir); - Assert.assertTrue(Files.exists(manifestPath)); + assertTrue(Files.exists(manifestPath)); ChannelManifest manifest = ManifestYamlSupport.parse(manifestPath.toFile()); - Assert.assertTrue(manifest.getStreams().contains(new Stream("org.wildfly.core", "wildfly-server", "20.0.1.Final"))); - Assert.assertTrue(Files.exists(configurationPath)); + assertTrue(manifest.getStreams().contains(new Stream("org.wildfly.core", "wildfly-server", "20.0.1.Final"))); + assertTrue(Files.exists(configurationPath)); ProsperoConfig prosperoConfig = ProsperoConfig.readConfig(serverDir.resolve(ProsperoMetadataUtils.METADATA_DIR)); - Assert.assertTrue(prosperoConfig.getChannels().size() > 0); - Path manifestPathCopy = serverDir.resolve(ProsperoMetadataUtils.METADATA_DIR).resolve("manifest-" + PRODUCT + "-" + VERSION + ".yaml"); - Assert.assertTrue(Files.exists(manifestPathCopy)); - Assert.assertTrue(prosperoConfig.getChannels().stream() - .anyMatch(c -> { - try { - return c.getManifestCoordinate() != null && c.getManifestCoordinate().getUrl() != null && - c.getManifestCoordinate().getUrl().equals(manifestPathCopy.toUri().toURL()); - } catch (MalformedURLException e) { - throw new RuntimeException(e); - } - })); - - // update stream in metadata, test with upgrade vertx-core from 4.3.4 to 4.3.6 - final Artifact upgrade = new DefaultArtifact("io.vertx", "vertx-core", "jar", "4.3.6"); - final List updatedStreams = manifest.getStreams().stream() - .map(s -> { - if (s.getGroupId().equals(upgrade.getGroupId()) && s.getArtifactId().equals(upgrade.getArtifactId())) { - return new Stream(upgrade.getGroupId(), upgrade.getArtifactId(), upgrade.getVersion()); - } else { - return s; - } - }).collect(Collectors.toList()); - Files.writeString(manifestPathCopy, ChannelManifestMapper.toYaml(new ChannelManifest(manifest.getName(), manifest.getId(), manifest.getDescription(), updatedStreams))); + Assert.assertFalse(prosperoConfig.getChannels().isEmpty()); // run upgrade ExecutionUtils.prosperoExecution(CliConstants.Commands.UPDATE, CliConstants.Commands.PERFORM, @@ -129,7 +104,9 @@ public void testInstallWithProvisionConfig() throws Exception { // check the vertx-core stream in manifest manifest = ManifestYamlSupport.parse(manifestPath.toFile()); - Assert.assertTrue(manifest.getStreams().contains(new Stream("io.vertx", "vertx-core", "4.3.6"))); + assertTrue(VersionMatcher.COMPARATOR.compare("20.0.1.Final", manifest.getStreams().stream() + .filter(s->s.getGroupId().equals("org.wildfly.core") && s.getArtifactId().equals("wildfly-server")) + .map(Stream::getVersion).findFirst().get()) < 0); } private void downloadAndUnzipServer() throws ProvisioningException, ArtifactResolutionException, IOException { diff --git a/prospero-common/src/main/java/org/wildfly/prospero/actions/SubscribeNewServerAction.java b/prospero-common/src/main/java/org/wildfly/prospero/actions/SubscribeNewServerAction.java index 6be37a84c..bcefe61c4 100644 --- a/prospero-common/src/main/java/org/wildfly/prospero/actions/SubscribeNewServerAction.java +++ b/prospero-common/src/main/java/org/wildfly/prospero/actions/SubscribeNewServerAction.java @@ -54,11 +54,12 @@ public SubscribeNewServerAction(MavenOptions mvnOptions, Console console) throws public GenerateResult generateServerMetadata(List channels, FeaturePackLocation loc) throws IOException, ProvisioningException, OperationException { Path tempDir = Files.createTempDirectory("tmp-prov-"); - boolean manifestCoordDefined = channels.stream().anyMatch(c -> c.getManifestCoordinate() != null); + tempDir.toFile().deleteOnExit(); try (GalleonEnvironment galleonEnv = GalleonEnvironment .builder(tempDir, channels, mavenSessionManager, false) - .setArtifactDirectResolve(!manifestCoordDefined) + // forces the feature pack artifact to be downloaded directly and not go through channel version resolution + .setArtifactDirectResolve(true) .setConsole(console) .build()) { @@ -72,6 +73,8 @@ public GenerateResult generateServerMetadata(List channels, FeaturePack throw new ArtifactResolutionException(ProsperoLogger.ROOT_LOGGER.unableToResolve(), e, e.getUnresolvedArtifacts(), e.getAttemptedRepositories(), mavenSessionManager.isOffline()); } + + boolean manifestCoordDefined = channels.stream().anyMatch(c -> c.getManifestCoordinate() != null); return new GenerateResult(tempDir, channels, galleonEnv.getChannelSession().getRecordedChannel(), manifestCoordDefined); } }