Skip to content

Commit 23ba2cd

Browse files
authored
Merge pull request #974 from pedro-hos/pr-898
Add ability to update WildFly to a specific version of a manifest using wildfly-channels
2 parents 862ba77 + c915134 commit 23ba2cd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+3114
-109
lines changed

integration-tests/src/test/java/org/wildfly/prospero/it/cli/CacheManifestTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ public void revertWithOriginalManifestNotAvailable() throws Exception {
303303
}
304304

305305
private void performUpdate() throws OperationException, ProvisioningException {
306-
try (UpdateAction updateAction = new UpdateAction(outputPath, mavenOptions, new CliConsole(), Collections.emptyList())) {
306+
try (UpdateAction updateAction = new UpdateAction(outputPath, Collections.emptyList(), mavenOptions, new CliConsole())) {
307307
updateAction.performUpdate();
308308
FileUtils.deleteQuietly(mavenSessionManager.getProvisioningRepo().toFile());
309309
}
Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
package org.wildfly.prospero.it.cli;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
import static org.wildfly.prospero.test.TestLocalRepository.GALLEON_PLUGINS_VERSION;
5+
6+
import java.io.IOException;
7+
import java.net.URL;
8+
import java.nio.file.Path;
9+
import java.util.Collections;
10+
import java.util.List;
11+
import java.util.regex.Matcher;
12+
import java.util.regex.Pattern;
13+
14+
import org.apache.commons.lang3.tuple.Pair;
15+
import org.eclipse.aether.artifact.Artifact;
16+
import org.eclipse.aether.artifact.DefaultArtifact;
17+
import org.junit.Before;
18+
import org.junit.Test;
19+
import org.wildfly.channel.Channel;
20+
import org.wildfly.channel.ChannelManifest;
21+
import org.wildfly.channel.Stream;
22+
import org.wildfly.prospero.cli.CliMessages;
23+
import org.wildfly.prospero.cli.ReturnCodes;
24+
import org.wildfly.prospero.cli.commands.CliConstants;
25+
import org.wildfly.prospero.it.ExecutionUtils;
26+
import org.wildfly.prospero.test.BuildProperties;
27+
import org.wildfly.prospero.test.TestInstallation;
28+
import org.wildfly.prospero.test.TestLocalRepository;
29+
30+
public class UpdateToVersionTest extends CliTestBase {
31+
protected static final String COMMONS_IO_VERSION = BuildProperties.getProperty("version.commons-io");
32+
33+
private TestLocalRepository testLocalRepository;
34+
private TestInstallation testInstallation;
35+
private Channel testChannel;
36+
37+
@Before
38+
public void setUp() throws Exception {
39+
testLocalRepository = new TestLocalRepository(temp.newFolder("local-repo").toPath(),
40+
List.of(new URL("https://repo1.maven.org/maven2")));
41+
42+
prepareRequiredArtifacts(testLocalRepository);
43+
44+
testInstallation = new TestInstallation(temp.newFolder("server").toPath());
45+
46+
testLocalRepository.deploy(TestInstallation.fpBuilder("org.test:pack-one:1.0.0")
47+
.addModule("commons-io", "commons-io", COMMONS_IO_VERSION)
48+
.build());
49+
50+
testChannel = new Channel.Builder()
51+
.setName("test-channel")
52+
.addRepository("local-repo", testLocalRepository.getUri().toString())
53+
.setManifestCoordinate("org.test", "test-channel")
54+
.build();
55+
}
56+
57+
@Test
58+
public void installSpecificVersionOfManifest() throws Exception {
59+
testInstallation.install("org.test:pack-one:1.0.0", List.of(testChannel), CliConstants.VERSION, "test-channel::1.0.0");
60+
61+
testInstallation.verifyModuleJar("commons-io", "commons-io", COMMONS_IO_VERSION);
62+
testInstallation.verifyInstallationMetadataPresent();
63+
}
64+
65+
@Test
66+
public void updateServerToNonLatestVersion() throws Exception {
67+
testInstallation.install("org.test:pack-one:1.0.0", List.of(testChannel), CliConstants.VERSION, "test-channel::1.0.0");
68+
69+
testInstallation.update(CliConstants.VERSION, "test-channel::1.0.1");
70+
71+
testInstallation.verifyModuleJar("commons-io", "commons-io", bump(COMMONS_IO_VERSION));
72+
testInstallation.verifyInstallationMetadataPresent();
73+
}
74+
75+
@Test
76+
public void downgradeServerToNonLatestVersion() throws Exception {
77+
testInstallation.install("org.test:pack-one:1.0.0", List.of(testChannel), "--version=test-channel::1.0.1");
78+
79+
testInstallation.update(Collections.emptyList(), "--version=test-channel::1.0.0", CliConstants.YES);
80+
81+
testInstallation.verifyModuleJar("commons-io", "commons-io", COMMONS_IO_VERSION);
82+
testInstallation.verifyInstallationMetadataPresent();
83+
}
84+
85+
@Test
86+
public void updateWithPrepareApplyServerToNonLatestVersion() throws Exception {
87+
testInstallation.install("org.test:pack-one:1.0.0", List.of(testChannel), CliConstants.VERSION, "test-channel::1.0.0");
88+
89+
final Path candidatePath = temp.newFolder("candidate").toPath();
90+
testInstallation.prepareUpdate(candidatePath, CliConstants.VERSION, "test-channel::1.0.1");
91+
testInstallation.apply(candidatePath);
92+
93+
testInstallation.verifyModuleJar("commons-io", "commons-io", bump(COMMONS_IO_VERSION));
94+
testInstallation.verifyInstallationMetadataPresent();
95+
}
96+
97+
@Test
98+
public void warnIfDowngradeServerToNonLatestVersion() throws Exception {
99+
testInstallation.install("org.test:pack-one:1.0.0", List.of(testChannel), "--version=test-channel::1.0.1", "-vv");
100+
101+
testInstallation.updateWithCheck(
102+
List.of(
103+
Pair.of(CliMessages.MESSAGES.continueWithUpdate(), "y"),
104+
Pair.of(CliMessages.MESSAGES.continueWithUpdate(), "y")
105+
),
106+
(ExecutionUtils.ExecutionResult e)-> {
107+
try {
108+
e.assertReturnCode(ReturnCodes.SUCCESS);
109+
assertThat(e.getCommandOutput())
110+
.contains("The update will downgrade following channels:")
111+
.contains(" * test-channel: 1.0.1 -> 1.0.0");
112+
} catch (IOException ex) {
113+
throw new RuntimeException(ex);
114+
}
115+
},
116+
"--version=test-channel::1.0.0", "-vv");
117+
118+
testInstallation.verifyModuleJar("commons-io", "commons-io", COMMONS_IO_VERSION);
119+
testInstallation.verifyInstallationMetadataPresent();
120+
}
121+
122+
@Test
123+
public void rejectDowngradeServerIfVersionNotSpecified() throws Exception {
124+
testInstallation.install("org.test:pack-one:1.0.0", List.of(testChannel), "--version=test-channel::1.0.1", "-vv");
125+
126+
final TestLocalRepository newRepo = new TestLocalRepository(temp.newFolder("downgrade-repo").toPath(), List.of(new URL("https://repo1.maven.org/maven2")));
127+
128+
newRepo.deploy(
129+
new DefaultArtifact("org.test", "test-channel", "manifest", "yaml","1.0.0"),
130+
new ChannelManifest("test-manifest", null, null, List.of(
131+
new Stream("org.wildfly.galleon-plugins", "wildfly-config-gen", GALLEON_PLUGINS_VERSION),
132+
new Stream("org.wildfly.galleon-plugins", "wildfly-galleon-plugins", GALLEON_PLUGINS_VERSION),
133+
new Stream("commons-io", "commons-io", COMMONS_IO_VERSION),
134+
new Stream("org.test", "pack-one", "1.0.0")
135+
)));
136+
137+
testInstallation.updateWithCheck(
138+
Collections.emptyList(),
139+
(ExecutionUtils.ExecutionResult e)-> {
140+
try {
141+
e.assertReturnCode(ReturnCodes.PROCESSING_ERROR);
142+
assertThat(e.getCommandOutput())
143+
.contains("The update will downgrade following channels:")
144+
.contains(" * test-channel: 1.0.1 -> 1.0.0");
145+
} catch (IOException ex) {
146+
throw new RuntimeException(ex);
147+
}
148+
149+
},
150+
"--repositories", newRepo.getUri().toString());
151+
152+
testInstallation.verifyModuleJar("commons-io", "commons-io", COMMONS_IO_VERSION + ".CP-01");
153+
testInstallation.verifyInstallationMetadataPresent();
154+
}
155+
156+
@Test
157+
public void listChannelVersionUpdates() throws Exception {
158+
testInstallation.install("org.test:pack-one:1.0.0", List.of(testChannel), "--version=test-channel::1.0.1", "-vv");
159+
160+
assertThat(testInstallation.listChannelManifestUpdates(false).split("available versions")[1])
161+
.contains("1.0.2")
162+
.doesNotContain("1.0.0", "1.0.1");
163+
}
164+
165+
@Test
166+
public void listAllChannelVersion() throws Exception {
167+
testInstallation.install("org.test:pack-one:1.0.0", List.of(testChannel), "--version=test-channel::1.0.1", "-vv");
168+
169+
assertThat(testInstallation.listChannelManifestUpdates(true).split("available versions")[1])
170+
.contains("1.0.0", "1.0.1", "1.0.2");
171+
}
172+
173+
@Test
174+
public void listUpdatesToSpecificVersion() throws Exception {
175+
testInstallation.install("org.test:pack-one:1.0.0", List.of(testChannel), "--version=test-channel::1.0.0", "-vv");
176+
177+
assertThat(testInstallation.listUpdates(CliConstants.VERSION, "test-channel::1.0.1"))
178+
.containsPattern("commons-io:commons-io\\s+2.18.0\\s+==>\\s+2.18.0.CP-01");
179+
}
180+
181+
private void prepareRequiredArtifacts(TestLocalRepository localRepository) throws Exception {
182+
localRepository.deployGalleonPlugins();
183+
184+
Artifact resolved = localRepository.resolveAndDeploy(new DefaultArtifact("commons-io", "commons-io", "jar", COMMONS_IO_VERSION));
185+
resolved = resolved.setVersion(bump(resolved.getVersion()));
186+
localRepository.deploy(resolved);
187+
localRepository.deploy(resolved.setVersion(bump(resolved.getVersion())));
188+
189+
// deploy test manifests updating the commons-io in each
190+
localRepository.deploy(
191+
new DefaultArtifact("org.test", "test-channel", "manifest", "yaml","1.0.0"),
192+
new ChannelManifest("test-manifest", null, null, List.of(
193+
new Stream("org.wildfly.galleon-plugins", "wildfly-config-gen", GALLEON_PLUGINS_VERSION),
194+
new Stream("org.wildfly.galleon-plugins", "wildfly-galleon-plugins", GALLEON_PLUGINS_VERSION),
195+
new Stream("commons-io", "commons-io", COMMONS_IO_VERSION),
196+
new Stream("org.test", "pack-one", "1.0.0")
197+
)));
198+
199+
testLocalRepository.deploy(
200+
new DefaultArtifact("org.test", "test-channel", "manifest", "yaml","1.0.1"),
201+
new ChannelManifest("test-manifest", null, null, List.of(
202+
new Stream("org.wildfly.galleon-plugins", "wildfly-config-gen", GALLEON_PLUGINS_VERSION),
203+
new Stream("org.wildfly.galleon-plugins", "wildfly-galleon-plugins", GALLEON_PLUGINS_VERSION),
204+
new Stream("commons-io", "commons-io", bump(COMMONS_IO_VERSION)),
205+
new Stream("org.test", "pack-one", "1.0.0")
206+
)));
207+
208+
testLocalRepository.deploy(
209+
new DefaultArtifact("org.test", "test-channel", "manifest", "yaml","1.0.2"),
210+
new ChannelManifest("test-manifest", null, null, List.of(
211+
new Stream("org.wildfly.galleon-plugins", "wildfly-config-gen", GALLEON_PLUGINS_VERSION),
212+
new Stream("org.wildfly.galleon-plugins", "wildfly-galleon-plugins", GALLEON_PLUGINS_VERSION),
213+
new Stream("commons-io", "commons-io", bump(bump(COMMONS_IO_VERSION))),
214+
new Stream("org.test", "pack-one", "1.0.0")
215+
)));
216+
}
217+
218+
private String bump(String version) {
219+
final Pattern pattern = Pattern.compile(".*\\.CP-(\\d{2})");
220+
final Matcher matcher = pattern.matcher(version);
221+
if (matcher.matches()) {
222+
final String suffixVersion = matcher.group(1);
223+
final int ver = Integer.parseInt(suffixVersion) + 1;
224+
final String replaced = version.replace(".CP-" + suffixVersion, String.format(".CP-%02d", ver));
225+
return replaced;
226+
} else {
227+
return version + ".CP-01";
228+
}
229+
}
230+
}

integration-tests/src/test/java/org/wildfly/prospero/it/commonapi/InstallationHistoryActionTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ public void rollbackChangesUsesCache() throws Exception {
489489
}
490490

491491
private UpdateAction updateAction() throws ProvisioningException, OperationException {
492-
return new UpdateAction(outputPath, mavenOptions, new AcceptingConsole(), Collections.emptyList());
492+
return new UpdateAction(outputPath, Collections.emptyList(), mavenOptions, new AcceptingConsole());
493493
}
494494

495495
private Optional<Artifact> readArtifactFromManifest(String groupId, String artifactId) throws IOException, MetadataException {

integration-tests/src/test/java/org/wildfly/prospero/it/commonapi/SimpleProvisionTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ public void updateWildflyCoreDryRun() throws Exception {
194194
provisioningDefinition.resolveChannels(CHANNELS_RESOLVER_FACTORY));
195195

196196
MetadataTestUtils.prepareChannel(outputPath.resolve(MetadataTestUtils.INSTALLER_CHANNELS_FILE_PATH), CHANNEL_COMPONENT_UPDATES, CHANNEL_BASE_CORE_19);
197-
final Set<String> updates = new UpdateAction(outputPath, mavenOptions, new AcceptingConsole(), Collections.emptyList())
197+
final Set<String> updates = new UpdateAction(outputPath, Collections.emptyList(), mavenOptions, new AcceptingConsole())
198198
.findUpdates().getArtifactUpdates().stream()
199199
.map(ArtifactChange::getArtifactName)
200200
.collect(Collectors.toSet());
@@ -258,7 +258,7 @@ public void installWildflyCoreFromInstallationFile() throws Exception {
258258
}
259259

260260
private UpdateAction getUpdateAction() throws ProvisioningException, OperationException {
261-
return new UpdateAction(outputPath, mavenOptions, new AcceptingConsole(), Collections.emptyList());
261+
return new UpdateAction(outputPath, Collections.emptyList(), mavenOptions, new AcceptingConsole());
262262
}
263263

264264
private Optional<Artifact> readArtifactFromManifest(String groupId, String artifactId) throws IOException, MetadataException {

integration-tests/src/test/java/org/wildfly/prospero/it/commonapi/UpdateTest.java

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public void updateWildflyCoreWithNewChannel() throws Exception {
109109
deployManifestFile(mockRepo.toURI().toURL(), updatedManifest, "1.0.1");
110110

111111
// update installation
112-
new UpdateAction(outputPath, mavenOptions, new AcceptingConsole(), Collections.emptyList())
112+
new UpdateAction(outputPath, Collections.emptyList(), mavenOptions, new AcceptingConsole())
113113
.performUpdate();
114114

115115
wildflyCliArtifact = readArtifactFromManifest("org.wildfly.core", "wildfly-cli");
@@ -140,7 +140,7 @@ public void updateWildflyCoreIgnoreChangesInProsperoConfig() throws Exception {
140140
deployManifestFile(mockRepo.toURI().toURL(), updatedChannel, "1.0.1");
141141

142142
// update installation
143-
new UpdateAction(outputPath, mavenOptions, new AcceptingConsole(), Collections.emptyList())
143+
new UpdateAction(outputPath, Collections.emptyList(), mavenOptions, new AcceptingConsole())
144144
.performUpdate();
145145

146146
assertTrue(Files.readString(channelsFile).contains("# test comment"));
@@ -166,7 +166,7 @@ public void prepareUpdateCreatesMarkerFile() throws Exception {
166166

167167
// update installation
168168
final Path preparedUpdatePath = temp.newFolder().toPath();
169-
new UpdateAction(outputPath, mavenOptions, new AcceptingConsole(), Collections.emptyList())
169+
new UpdateAction(outputPath, Collections.emptyList(), mavenOptions, new AcceptingConsole())
170170
.buildUpdate(preparedUpdatePath);
171171

172172
final Path markerFile = preparedUpdatePath.resolve(UPDATE_MARKER_FILE);
@@ -198,8 +198,9 @@ public void updateRequiresOnlyChangedArtifacts() throws Exception {
198198
.setChannelCoordinates(buildConfigWithMockRepo().toPath().toString())
199199
.setOverrideRepositories(Collections.emptyList()) // reset overrides from defaultWfCoreDefinition()
200200
.build();
201+
final List<Channel> channels = provisioningDefinition.resolveChannels(CHANNELS_RESOLVER_FACTORY);
201202
installation.provision(provisioningDefinition.toProvisioningConfig(),
202-
provisioningDefinition.resolveChannels(CHANNELS_RESOLVER_FACTORY));
203+
channels);
203204

204205
// update manifest file
205206
final URL tempRepo = mockTemporaryRepo(true);
@@ -210,9 +211,14 @@ public void updateRequiresOnlyChangedArtifacts() throws Exception {
210211
final MavenOptions offlineOptions = MavenOptions.OFFLINE_NO_CACHE;
211212

212213
// update installation
213-
new UpdateAction(outputPath, offlineOptions, new AcceptingConsole(),
214-
List.of(new Repository("temp", tempRepo.toExternalForm())))
215-
.performUpdate();
214+
final List<Channel> overrideChannels = channels.stream()
215+
.map(c -> new Channel.Builder(c)
216+
.setRepositories(List.of(new Repository("temp", tempRepo.toExternalForm())))
217+
.build())
218+
.collect(Collectors.toList());
219+
try (UpdateAction ua = new UpdateAction(outputPath, overrideChannels, offlineOptions, new AcceptingConsole())) {
220+
ua.performUpdate();
221+
}
216222

217223
Optional<Artifact> wildflyCliArtifact = readArtifactFromManifest("org.wildfly.core", "wildfly-cli");
218224
assertEquals(UPGRADE_VERSION, wildflyCliArtifact.get().getVersion());
@@ -229,13 +235,14 @@ public void candidateFolderHasToBeEmpty() throws Exception {
229235
.setChannelCoordinates(buildConfigWithMockRepo().toPath().toString())
230236
.setOverrideRepositories(Collections.emptyList()) // reset overrides from defaultWfCoreDefinition()
231237
.build();
238+
final List<Channel> channels = provisioningDefinition.resolveChannels(CHANNELS_RESOLVER_FACTORY);
232239
installation.provision(provisioningDefinition.toProvisioningConfig(),
233-
provisioningDefinition.resolveChannels(CHANNELS_RESOLVER_FACTORY));
240+
channels);
234241

235242
// update manifest file
236243
final URL tempRepo = mockTemporaryRepo(true);
237-
final File updatedChannel = upgradeTestArtifactIn(manifestFile);
238-
deployManifestFile(tempRepo, updatedChannel, "1.0.1");
244+
final File updatedManifest = upgradeTestArtifactIn(manifestFile);
245+
deployManifestFile(tempRepo, updatedManifest, "1.0.1");
239246

240247
// offline MSM will disable http(s) repositories and local maven cache
241248
final MavenOptions offlineOptions = MavenOptions.OFFLINE_NO_CACHE;
@@ -244,10 +251,18 @@ public void candidateFolderHasToBeEmpty() throws Exception {
244251
final Path candidateFolder = temp.newFolder("candidate").toPath();
245252
Files.writeString(candidateFolder.resolve("dirty.txt"), "foobar");
246253

254+
final List<Channel> overrideChannels = channels.stream()
255+
.map(c -> new Channel.Builder(c)
256+
.setRepositories(List.of(new Repository("temp", tempRepo.toExternalForm())))
257+
.build())
258+
.collect(Collectors.toList());
259+
247260
assertThatThrownBy(
248-
() -> new UpdateAction(outputPath, offlineOptions, new AcceptingConsole(),
249-
List.of(new Repository("temp", tempRepo.toExternalForm())))
250-
.buildUpdate(candidateFolder))
261+
() -> {
262+
try (UpdateAction ua = new UpdateAction(outputPath, overrideChannels, offlineOptions, new AcceptingConsole())) {
263+
ua.buildUpdate(candidateFolder);
264+
}
265+
})
251266
.isInstanceOf(IllegalArgumentException.class)
252267
.message().contains("Can't install the server into a non empty directory");
253268
}

0 commit comments

Comments
 (0)