Skip to content

Commit 9795fd0

Browse files
committed
Add API methods that allow to override manifest versions for upgrade ops
1 parent eb9aa65 commit 9795fd0

File tree

3 files changed

+183
-1
lines changed

3 files changed

+183
-1
lines changed
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: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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 String currentVersion;
11+
private final String 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, String currentVersion, String 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 String getCurrentVersion() {
49+
return currentVersion;
50+
}
51+
52+
/**
53+
* @return the new manifest version to be updated to
54+
*/
55+
public String 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+
}

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

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

1919
package org.wildfly.installationmanager.spi;
2020

21+
import org.wildfly.installationmanager.ArtifactChange;
2122
import org.wildfly.installationmanager.CandidateType;
2223
import org.wildfly.installationmanager.FileConflict;
2324
import org.wildfly.installationmanager.InstallationChanges;
2425
import org.wildfly.installationmanager.Channel;
2526
import org.wildfly.installationmanager.HistoryResult;
26-
import org.wildfly.installationmanager.ArtifactChange;
27+
import org.wildfly.installationmanager.InstallationUpdates;
2728
import org.wildfly.installationmanager.ManifestVersion;
2829
import org.wildfly.installationmanager.OperationNotAvailableException;
2930
import org.wildfly.installationmanager.Repository;
@@ -65,6 +66,10 @@ public interface InstallationManager {
6566
/**
6667
* Prepares an updated version of the server installation in {@code candidatePath}.
6768
* If no updates are found, this operation does nothing.
69+
* <p>
70+
* This method throws RuntimeException is the operation would result in subscribed channel manifest being
71+
* downgraded. Use {@link #prepareUpdate(Path candidatePath, List repositories, boolean allowManifestDowngrades)}
72+
* if you want to allow manifest downgrades.
6873
*
6974
* @param candidatePath {@code Path} were the updated version of the server should be located.
7075
* @param repositories List of repositories to be used to prepare this update.If it is null or an empty list,
@@ -75,16 +80,69 @@ public interface InstallationManager {
7580
*/
7681
boolean prepareUpdate(Path candidatePath, List<Repository> repositories) throws Exception;
7782

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

125+
/**
126+
* Lists updates available for the server installation.
127+
*
128+
* @param repositories List of repositories to be used to find the available updates. If it is null or an empty list,
129+
* the default repositories will be used instead.
130+
* @return {@link InstallationUpdates} collections of artifact and channels that are to be updated.
131+
* @throws Exception In case of an error.
132+
*/
133+
InstallationUpdates findInstallationUpdates(List<Repository> repositories) throws Exception;
134+
135+
/**
136+
* Lists updates available for the server installation.
137+
*
138+
* @param repositories List of repositories to be used to find the available updates. If it is null or an empty list,
139+
* the default repositories will be used instead.
140+
* @param manifestVersions Manifest versions to update to. All subscribed channels have to be specified.
141+
* @return {@link InstallationUpdates} collections of artifact and channels that are to be updated.
142+
* @throws Exception In case of an error.
143+
*/
144+
InstallationUpdates findInstallationUpdates(List<Repository> repositories, List<ManifestVersion> manifestVersions) throws Exception;
145+
88146
/**
89147
* Lists channels the server installation is subscribed to.
90148
* If the servers is not subscribed to any channels, empty list is returned.

0 commit comments

Comments
 (0)