Skip to content

Commit 1c47501

Browse files
committed
Altered process to get PSU overlay patches to allow separate filtering of OHS DB19 overlays
1 parent 6d82a07 commit 1c47501

File tree

5 files changed

+411
-36
lines changed

5 files changed

+411
-36
lines changed

imagetool/src/main/java/com/oracle/weblogic/imagetool/aru/AruUtil.java

+34-20
Original file line numberDiff line numberDiff line change
@@ -170,20 +170,8 @@ public List<AruPatch> getRecommendedPatches(FmwInstallerType type, String versio
170170
String userId, String password) throws AruException {
171171
List<AruPatch> result = new ArrayList<>();
172172
for (AruProduct product : type.products()) {
173-
List<AruPatch> patches = getRecommendedPatches(product, version, userId, password);
174-
// temporary, until OHS stops using same release number and product ID for two different installs
175-
if (type == FmwInstallerType.OHS_DB19) {
176-
if (product == AruProduct.OHS) {
177-
patches = patches.stream().filter(p -> p.description().contains(" DB19C "))
178-
.collect(Collectors.toList());
179-
} else if (product == AruProduct.OAM_WG) {
180-
patches = patches.stream().filter(p -> p.description().contains(" DB19c "))
181-
.collect(Collectors.toList());
182-
} else if (product == AruProduct.OSS) {
183-
patches = patches.stream().filter(p -> p.description().contains(" 19C "))
184-
.collect(Collectors.toList());
185-
}
186-
}
173+
List<AruPatch> patches = getRecommendedPatches(type, product, version, userId, password);
174+
187175
if (!patches.isEmpty()) {
188176
patches.forEach(p -> logger.info("IMG-0068", product.description(), p.patchId(), p.description()));
189177
result.addAll(patches);
@@ -205,8 +193,8 @@ public List<AruPatch> getRecommendedPatches(FmwInstallerType type, String versio
205193
* @return the recommended patches for the given product and version
206194
* @throws AruException when response from ARU has an error or fails
207195
*/
208-
List<AruPatch> getRecommendedPatches(AruProduct product, String version, String userId, String password)
209-
throws AruException {
196+
List<AruPatch> getRecommendedPatches(FmwInstallerType type, AruProduct product, String version,
197+
String userId, String password) throws AruException {
210198
logger.entering(product, version);
211199
List<AruPatch> patches = Collections.emptyList();
212200
try {
@@ -218,6 +206,12 @@ List<AruPatch> getRecommendedPatches(AruProduct product, String version, String
218206
} else {
219207
// Get a list of patches applicable to the given product and release number
220208
patches = getReleaseRecommendations(product, releaseNumber, userId, password);
209+
logger.fine("Search for {0} recommended patches returned {1}", product, patches.size());
210+
if (type == FmwInstallerType.OHS_DB19) {
211+
// Workaround for OHS where the DB19 patches and the DB12 patches have the same product/release ID
212+
patches = filterDb19Patches(patches, product);
213+
}
214+
221215
String psuVersion = getPsuVersion(product.description(), patches);
222216
if (psuVersion != null) {
223217
// Check to see if there is a release with the PSU version that contains overlay patches.
@@ -227,11 +221,11 @@ List<AruPatch> getRecommendedPatches(AruProduct product, String version, String
227221
String psuReleaseNumber = getReleaseNumber(product, psuVersion, userId, password);
228222
// If there is a release for the specific PSU, check it for overlay patches
229223
if (!Utils.isEmptyString(psuReleaseNumber)) {
230-
// Debug log - useful to know what was thrown away when "patches" is replaced by the new array
231-
patches.forEach(p -> logger.fine("Discarding recommended patch {0} {1}",
232-
p.patchId(), p.description()));
233224
// Get recommended patches for PSU release (includes PSU overlay patches)
234-
patches = getReleaseRecommendations(product, psuReleaseNumber, userId, password);
225+
List<AruPatch> overlays =
226+
getReleaseRecommendations(product, psuReleaseNumber, userId, password);
227+
logger.fine("Search for PSU {0} overlay patches returned {1}", psuVersion, overlays.size());
228+
patches.addAll(overlays);
235229
} else {
236230
// ARU does not have a release number for the PSU version found (no overlays needed)
237231
logger.fine("PSU release was not found for {0} : {1}", product, psuVersion);
@@ -247,6 +241,25 @@ List<AruPatch> getRecommendedPatches(AruProduct product, String version, String
247241
return patches;
248242
}
249243

244+
/**
245+
* This is a temporary workaround to select DB19 patches from a recommended list of patches.
246+
* Currently, OHS is using the same release number and product ID for two different installs (DB19 and DB12).
247+
* @param patches patches list to filter
248+
* @param product AruProduct that the supplied patches are for
249+
*/
250+
private List<AruPatch> filterDb19Patches(List<AruPatch> patches, AruProduct product) {
251+
List<AruPatch> result = patches;
252+
// temporary, until OHS stops using same release number and product ID for two different installs
253+
if (product == AruProduct.OHS) {
254+
result = patches.stream().filter(p -> p.description().contains(" DB19C ")).collect(Collectors.toList());
255+
} else if (product == AruProduct.OAM_WG) {
256+
result = patches.stream().filter(p -> p.description().contains(" DB19c ")).collect(Collectors.toList());
257+
} else if (product == AruProduct.OSS) {
258+
result = patches.stream().filter(p -> p.description().contains(" 19C ")).collect(Collectors.toList());
259+
}
260+
return result;
261+
}
262+
250263
private String getPsuVersion(String productName, Collection<AruPatch> patches) {
251264
String psuBundle = patches.stream()
252265
.map(AruPatch::psuBundle)
@@ -270,6 +283,7 @@ List<AruPatch> getReleaseRecommendations(AruProduct product, String releaseNumbe
270283
.filter(not(AruPatch::isStackPatchBundle)) // remove the Stack Patch Bundle patch, if returned
271284
// TODO: Need an option for the user to request the Coherence additional feature pack.
272285
.filter(not(AruPatch::isCoherenceFeaturePack)) // remove the Coherence feature pack, if returned
286+
.filter(p -> p.release().equals(releaseNumber))
273287
.collect(Collectors.toList());
274288
}
275289

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright (c) 2024, Oracle and/or its affiliates.
2+
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
3+
4+
package com.oracle.weblogic.imagetool.cli.menu;
5+
6+
/**
7+
* Platform is a menu option that sets the OS and Architecture for the target build.
8+
*/
9+
public enum Platform {
10+
ARM64(541, "linux/arm64", "arm64"), // Linux ARM 64-bit
11+
AMD64(226, "linux/amd64", "amd64"); // Linux AMD 64-bit
12+
13+
private final int aruPlatform;
14+
private final String[] acceptableNames;
15+
16+
/**
17+
* Create Platform definitions.
18+
* @param aruPlatform the ARU code for a given OS/architecture.
19+
* @param acceptableNames the acceptable strings from a command line input that can be mapped to a Platform.
20+
*/
21+
Platform(int aruPlatform, String... acceptableNames) {
22+
this.aruPlatform = aruPlatform;
23+
this.acceptableNames = acceptableNames;
24+
}
25+
26+
/**
27+
* Get the ARU platform code.
28+
* @return the ARU platform code.
29+
*/
30+
public int getAruPlatform() {
31+
return aruPlatform;
32+
}
33+
34+
/**
35+
* Given a string value from the user, get the Enum type.
36+
*
37+
* @param value string value to map to a Platform Enum.
38+
* @return the Platform type found or null if not found.
39+
*/
40+
public Platform fromString(String value) {
41+
for (Platform p: values()) {
42+
for (String name: p.acceptableNames) {
43+
if (name.equalsIgnoreCase(value)) {
44+
return p;
45+
}
46+
}
47+
}
48+
return null;
49+
}
50+
}

imagetool/src/test/java/com/oracle/weblogic/imagetool/aru/AruUtilTest.java

+8-5
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ Document getRecommendedPatchesMetadata(AruProduct product, String releaseNumber,
4545
Document result;
4646
try {
4747
// these release numbers are fake test data from the fake releases.xml found in test/resources
48-
if (releaseNumber.equals("336") || releaseNumber.equals("304")) {
48+
if (releaseNumber.equals("336")) { // 336 == 12.2.1.3.0 (GA release)
4949
result = ResourceUtils.getXmlFromResource("/patches/recommended-patches.xml");
50+
} else if (releaseNumber.equals("304")) { // 304 == 12.2.1.3.200624 (PSU overlay)
51+
result = ResourceUtils.getXmlFromResource("/patches/recommended-patches-304.xml");
5052
} else {
5153
result = ResourceUtils.getXmlFromResource("/patches/no-patches.xml");
5254
}
@@ -70,14 +72,15 @@ Document patchConflictCheck(String payload, String userId, String password) thro
7072
@Test
7173
void testRecommendedPatches() throws Exception {
7274
List<AruPatch> recommendedPatches =
73-
AruUtil.rest().getRecommendedPatches(AruProduct.WLS, "12.2.1.3.0", "x", "x");
74-
assertEquals(5, recommendedPatches.size());
75+
AruUtil.rest().getRecommendedPatches(FmwInstallerType.WLS, AruProduct.WLS, "12.2.1.3.0", "x", "x");
76+
assertEquals(6, recommendedPatches.size());
7577
List<String> bugs = recommendedPatches.stream().map(AruPatch::patchId).collect(Collectors.toList());
7678
assertTrue(bugs.contains("31544340"));
7779
assertTrue(bugs.contains("31535411"));
7880
assertTrue(bugs.contains("31384951"));
7981
assertTrue(bugs.contains("28512225"));
8082
assertTrue(bugs.contains("28278427"));
83+
assertTrue(bugs.contains("11112222"));
8184

8285
// if no recommended patches are found, method should return an empty list (test data does not have 12.2.1.4)
8386
recommendedPatches =
@@ -88,7 +91,7 @@ void testRecommendedPatches() throws Exception {
8891
@Test
8992
void testNoRecommendedPatches() throws Exception {
9093
List<AruPatch> recommendedPatches =
91-
AruUtil.rest().getRecommendedPatches(AruProduct.WLS, "12.2.1.4.0", "x", "x");
94+
AruUtil.rest().getRecommendedPatches(FmwInstallerType.WLS, AruProduct.WLS, "12.2.1.4.0", "x", "x");
9295
assertEquals(0, recommendedPatches.size());
9396
}
9497

@@ -109,7 +112,7 @@ void testReleaseNotFound() throws Exception {
109112
assertEquals(0, latestPsu.size());
110113

111114
List<AruPatch> recommendedPatches =
112-
AruUtil.rest().getRecommendedPatches(AruProduct.WLS, "3.0.0.0.0", "x", "x");
115+
AruUtil.rest().getRecommendedPatches(FmwInstallerType.WLS, AruProduct.WLS, "3.0.0.0.0", "x", "x");
113116
assertEquals(0, recommendedPatches.size());
114117
}
115118

0 commit comments

Comments
 (0)