Skip to content

Commit 8f703e8

Browse files
authored
Merge pull request #45 from TomasHofman/EAP7-2291
Add API methods that allow to override manifest versions for upgrade ops
2 parents eb9aa65 + bb75cfa commit 8f703e8

File tree

5 files changed

+294
-1
lines changed

5 files changed

+294
-1
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package org.wildfly.installationmanager;
2+
3+
import java.util.List;
4+
5+
/**
6+
* Provides list of available manifest versions for given channel.
7+
*/
8+
public class AvailableManifestVersions {
9+
10+
private final String channelName;
11+
private final String location;
12+
private final ManifestVersionPair currentVersion;
13+
private final List<ManifestVersionPair> availableVersions;
14+
15+
public AvailableManifestVersions(String channelName, String location, ManifestVersionPair currentVersion, List<ManifestVersionPair> availableVersions) {
16+
this.channelName = channelName;
17+
this.location = location;
18+
this.currentVersion = currentVersion;
19+
this.availableVersions = availableVersions;
20+
}
21+
22+
public String getChannelName() {
23+
return channelName;
24+
}
25+
26+
public String getLocation() {
27+
return location;
28+
}
29+
30+
public ManifestVersionPair getCurrentVersion() {
31+
return currentVersion;
32+
}
33+
34+
public List<ManifestVersionPair> getAvailableVersions() {
35+
return availableVersions;
36+
}
37+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* JBoss, Home of Professional Open Source.
3+
* Copyright 2023 Red Hat, Inc., and individual contributors
4+
* as indicated by the @author tags.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package org.wildfly.installationmanager;
20+
21+
import java.util.Collections;
22+
import java.util.List;
23+
import java.util.Objects;
24+
25+
/**
26+
* Represents possible incoming updates applicable to the installation.
27+
*/
28+
public class InstallationUpdates {
29+
30+
private final List<ArtifactChange> artifactUpdates;
31+
private final List<ManifestVersionChange> manifestUpdates;
32+
33+
/**
34+
* Constructor
35+
* @param artifactUpdates list of artifact changes or empty list if no changes found
36+
* @param manifestUpdates list of channel manifest version changes or empty list if no changes found
37+
*/
38+
public InstallationUpdates(List<ArtifactChange> artifactUpdates, List<ManifestVersionChange> manifestUpdates) {
39+
Objects.requireNonNull(artifactUpdates);
40+
Objects.requireNonNull(manifestUpdates);
41+
42+
this.artifactUpdates = Collections.unmodifiableList(artifactUpdates);
43+
this.manifestUpdates = Collections.unmodifiableList(manifestUpdates);
44+
}
45+
46+
/**
47+
* @return list of artifact changes or empty list if no changes found
48+
*/
49+
public List<ArtifactChange> artifactUpdates() {
50+
return artifactUpdates;
51+
}
52+
53+
/**
54+
* @return list of channel manifest version changes or empty list if no changes found
55+
*/
56+
public List<ManifestVersionChange> manifestUpdates() {
57+
return manifestUpdates;
58+
}
59+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package org.wildfly.installationmanager;
2+
3+
/**
4+
* Represents possible Channel Manifest version change that would happen if user proceeds with an update operation.
5+
*/
6+
public class ManifestVersionChange {
7+
8+
private final String channelName;
9+
private final String location;
10+
private final ManifestVersionPair currentVersion;
11+
private final ManifestVersionPair newVersion;
12+
private final boolean isDowngrade;
13+
14+
/**
15+
* Constructor
16+
*
17+
* @param channelName name of the channel associated with a manifest which is to be updated
18+
* @param location manifest location (Maven GA(V) or URL)
19+
* @param currentVersion current manifest version
20+
* @param newVersion the new manifest version to be updated to
21+
* @param isDowngrade is this version change considered a downgrade?
22+
*/
23+
public ManifestVersionChange(String channelName, String location, ManifestVersionPair currentVersion, ManifestVersionPair newVersion, boolean isDowngrade) {
24+
this.channelName = channelName;
25+
this.location = location;
26+
this.currentVersion = currentVersion;
27+
this.newVersion = newVersion;
28+
this.isDowngrade = isDowngrade;
29+
}
30+
31+
/**
32+
* @return name of the channel associated with a manifest which is to be updated
33+
*/
34+
public String getChannelName() {
35+
return channelName;
36+
}
37+
38+
/**
39+
* @return manifest location (Maven GA(V) or URL)
40+
*/
41+
public String getLocation() {
42+
return location;
43+
}
44+
45+
/**
46+
* @return current manifest version
47+
*/
48+
public ManifestVersionPair getCurrentVersion() {
49+
return currentVersion;
50+
}
51+
52+
/**
53+
* @return the new manifest version to be updated to
54+
*/
55+
public ManifestVersionPair getNewVersion() {
56+
return newVersion;
57+
}
58+
59+
/**
60+
* @return is this version change considered a downgrade?
61+
*/
62+
public boolean isDowngrade() {
63+
return isDowngrade;
64+
}
65+
66+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package org.wildfly.installationmanager;
2+
3+
import java.util.Objects;
4+
5+
/**
6+
* Wraps a pair of manifest physical/logical version strings.
7+
*/
8+
public class ManifestVersionPair {
9+
private final String physicalVersion;
10+
private final String logicalVersion;
11+
12+
/**
13+
* Pair of physical / logical version strings.
14+
*
15+
* @param physicalVersion version string, either a maven artifact version for Maven-based channels,
16+
* or a URL for URL-based channels
17+
* @param logicalVersion descriptive version string intended for human understanding, optional
18+
*/
19+
public ManifestVersionPair(String physicalVersion, String logicalVersion) {
20+
this.physicalVersion = physicalVersion;
21+
this.logicalVersion = logicalVersion;
22+
}
23+
24+
/**
25+
* @return descriptive version string intended for human understanding, optional
26+
*/
27+
public String getLogicalVersion() {
28+
return logicalVersion;
29+
}
30+
31+
/**
32+
* @return physicalVersion version string, either a maven artifact version for Maven-based channels,
33+
* or a URL for URL-based channels
34+
*/
35+
public String getPhysicalVersion() {
36+
return physicalVersion;
37+
}
38+
39+
@Override
40+
public String toString() {
41+
return "ManifestVersionPair{" +
42+
"physicalVersion='" + physicalVersion + '\'' +
43+
", logicalVersion='" + logicalVersion + '\'' +
44+
'}';
45+
}
46+
47+
@Override
48+
public boolean equals(Object o) {
49+
if (o == null || getClass() != o.getClass()) return false;
50+
51+
ManifestVersionPair that = (ManifestVersionPair) o;
52+
return Objects.equals(physicalVersion, that.physicalVersion) && Objects.equals(logicalVersion, that.logicalVersion);
53+
}
54+
55+
@Override
56+
public int hashCode() {
57+
int result = Objects.hashCode(physicalVersion);
58+
result = 31 * result + Objects.hashCode(logicalVersion);
59+
return result;
60+
}
61+
}

src/main/java/org/wildfly/installationmanager/spi/InstallationManager.java

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@
1818

1919
package org.wildfly.installationmanager.spi;
2020

21+
import org.wildfly.installationmanager.ArtifactChange;
22+
import org.wildfly.installationmanager.AvailableManifestVersions;
2123
import org.wildfly.installationmanager.CandidateType;
2224
import org.wildfly.installationmanager.FileConflict;
2325
import org.wildfly.installationmanager.InstallationChanges;
2426
import org.wildfly.installationmanager.Channel;
2527
import org.wildfly.installationmanager.HistoryResult;
26-
import org.wildfly.installationmanager.ArtifactChange;
28+
import org.wildfly.installationmanager.InstallationUpdates;
2729
import org.wildfly.installationmanager.ManifestVersion;
2830
import org.wildfly.installationmanager.OperationNotAvailableException;
2931
import org.wildfly.installationmanager.Repository;
@@ -65,6 +67,10 @@ public interface InstallationManager {
6567
/**
6668
* Prepares an updated version of the server installation in {@code candidatePath}.
6769
* If no updates are found, this operation does nothing.
70+
* <p>
71+
* This method throws RuntimeException is the operation would result in subscribed channel manifest being
72+
* downgraded. Use {@link #prepareUpdate(Path candidatePath, List repositories, boolean allowManifestDowngrades)}
73+
* if you want to allow manifest downgrades.
6874
*
6975
* @param candidatePath {@code Path} were the updated version of the server should be located.
7076
* @param repositories List of repositories to be used to prepare this update.If it is null or an empty list,
@@ -75,16 +81,80 @@ public interface InstallationManager {
7581
*/
7682
boolean prepareUpdate(Path candidatePath, List<Repository> repositories) throws Exception;
7783

84+
/**
85+
* Prepares an updated version of the server installation in {@code candidatePath}.
86+
* If no updates are found, this operation does nothing.
87+
*
88+
* @param candidatePath {@code Path} were the updated version of the server should be located.
89+
* @param repositories List of repositories to be used to prepare this update.If it is null or an empty list,
90+
* the default repositories will be used instead.
91+
* @param allowManifestDowngrades are manifest downgrades allowed? An attempt do downgrade will result in RuntimeException being thrown if this is false.
92+
* @return true if the update candidate was generated, false if candidate was no generated due to not finding any pending updates
93+
* @throws IllegalArgumentException if the Path is not writable.
94+
* @throws Exception In case of an error.
95+
*/
96+
boolean prepareUpdate(Path candidatePath, List<Repository> repositories, boolean allowManifestDowngrades) throws Exception;
97+
98+
/**
99+
* Prepares an updated version of the server installation in {@code candidatePath}.
100+
* If no updates are found, this operation does nothing.
101+
*
102+
* @param candidatePath {@code Path} were the updated version of the server should be located.
103+
* @param repositories List of repositories to be used to prepare this update.If it is null or an empty list,
104+
* the default repositories will be used instead.
105+
* @param manifestVersions Manifest versions to update to. All subscribed channels have to be specified.
106+
* @param allowManifestDowngrades are manifest downgrades allowed? An attempt do downgrade will result in RuntimeException being thrown if this is false.
107+
* @return true if the update candidate was generated, false if candidate was no generated due to not finding any pending updates
108+
* @throws IllegalArgumentException if the Path is not writable.
109+
* @throws Exception In case of an error.
110+
*/
111+
boolean prepareUpdate(Path candidatePath, List<Repository> repositories, List<ManifestVersion> manifestVersions, boolean allowManifestDowngrades) throws Exception;
112+
78113
/**
79114
* Lists updates available for the server installation.
80115
*
116+
* @deprecated Deprecated in favour of {@link #findInstallationUpdates(List repositories)}, which returns info
117+
* about upgraded manifests, as well as upgraded artifacts.
118+
*
81119
* @param repositories List of repositories to be used to find the available updates. If it is null or an empty list,
82120
* the default repositories will be used instead.
83121
* @return list of {@code ArtifactChange} available for update.
84122
* @throws Exception In case of an error.
85123
*/
86124
List<ArtifactChange> findUpdates(List<Repository> repositories) throws Exception;
87125

126+
/**
127+
* Lists updates available for the server installation.
128+
*
129+
* @param repositories List of repositories to be used to find the available updates. If it is null or an empty list,
130+
* the default repositories will be used instead.
131+
* @return {@link InstallationUpdates} collections of artifact and Wildfly Channel manifests that can be updated.
132+
* @throws Exception In case of an error.
133+
*/
134+
InstallationUpdates findInstallationUpdates(List<Repository> repositories) throws Exception;
135+
136+
/**
137+
* Lists updates available for the server installation.
138+
*
139+
* @param repositories List of repositories to be used to find the available updates. If it is null or an empty list,
140+
* the default repositories will be used instead.
141+
* @param manifestVersions Manifest versions to update to. All subscribed channels have to be specified.
142+
* @return {@link InstallationUpdates} collections of artifact and Wildfly Channel manifests that can be updated.
143+
* @throws Exception In case of an error.
144+
*/
145+
InstallationUpdates findInstallationUpdates(List<Repository> repositories, List<ManifestVersion> manifestVersions) throws Exception;
146+
147+
/**
148+
* Lists possible upgrades for subscribed manifests. The results may not include manifests for which no upgrades
149+
* are available. Only Maven-based manifests are returned, no upgrades are be listed for URL-based manifests.
150+
*
151+
* @param repositories List of repositories to be used to find the available updates. If it is null or an empty list,
152+
* the default repositories will be used instead.
153+
* @param includeDowngrades If true, manifest versions lower than currently used manifest version will be listed as well.
154+
* @return list of AvailableManifestVersions objects containing manifest info and list of available manifest versions.
155+
*/
156+
List<AvailableManifestVersions> findAvailableManifestVersions(List<Repository> repositories, boolean includeDowngrades) throws Exception;
157+
88158
/**
89159
* Lists channels the server installation is subscribed to.
90160
* If the servers is not subscribed to any channels, empty list is returned.

0 commit comments

Comments
 (0)