Skip to content

Commit 016b9a9

Browse files
authored
updated handling for OPatch selection from ARU. Allows for selection without Recommended flag. (#320)
1 parent c77b25a commit 016b9a9

File tree

5 files changed

+313
-26
lines changed

5 files changed

+313
-26
lines changed

imagetool/src/main/java/com/oracle/weblogic/imagetool/cachestore/OPatchFile.java

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@
99
import java.util.List;
1010
import java.util.Set;
1111
import java.util.stream.Collectors;
12-
import java.util.stream.Stream;
1312
import javax.xml.xpath.XPathExpressionException;
1413

1514
import com.oracle.weblogic.imagetool.aru.AruException;
1615
import com.oracle.weblogic.imagetool.aru.AruPatch;
1716
import com.oracle.weblogic.imagetool.aru.AruUtil;
17+
import com.oracle.weblogic.imagetool.aru.NoPatchesFoundException;
18+
import com.oracle.weblogic.imagetool.aru.VersionNotFoundException;
1819
import com.oracle.weblogic.imagetool.logging.LoggingFacade;
1920
import com.oracle.weblogic.imagetool.logging.LoggingFactory;
2021
import com.oracle.weblogic.imagetool.util.Utils;
@@ -53,32 +54,44 @@ public static OPatchFile getInstance(String patchId, String userid, String passw
5354

5455
List<AruPatch> patches = AruUtil.rest().getPatches(patchNumber, userid, password);
5556
if (!isOffline(userid, password)) {
56-
// if working online with ARU metadata, filter results based on availability and ARU recommendation
57-
Stream<AruPatch> filteredList = patches.stream().filter(AruPatch::isOpenAccess);
57+
// if working online with ARU metadata, filter results based on access flag (discard protected versions)
58+
patches = patches.stream().filter(AruPatch::isOpenAccess).collect(Collectors.toList());
59+
logger.fine("Found {0} OPatch versions for id {1}", patches.size(), patchNumber);
60+
} else {
61+
// if working offline, update the placeholder in the list to have the provided version or the latest cached
62+
AruPatch offlinePatch = patches.get(0);
5863
if (providedVersion == null) {
59-
// When the user did not provide a specific version, try to reduce the patch list to one patch.
60-
// There should only be ONE recommended patch/install for OPatch
61-
filteredList = filteredList.filter(AruPatch::isRecommended);
64+
offlinePatch.version(getLatestCachedVersion(cache, patchNumber));
65+
} else {
66+
offlinePatch.version(providedVersion);
6267
}
63-
patches = filteredList.collect(Collectors.toList());
6468
}
6569

6670
// For the OPatch use case, only the provided version (--opatchBugNumber) is used to "select" a patch.
6771
// selectPatch will return null if there is more than one patch in the patches list.
68-
AruPatch selectedPatch = AruPatch.selectPatch(patches, providedVersion, null, null);
69-
70-
if (selectedPatch != null) {
71-
// if offline, find the latest OPatch version available in the cache
72-
if (isOffline(userid, password) && providedVersion == null) {
73-
selectedPatch.version(getLatestCachedVersion(cache, patchNumber));
72+
//AruPatch selectedPatch = AruPatch.selectPatch(patches, providedVersion, null, null);
73+
74+
AruPatch selectedPatch;
75+
if (patches.isEmpty()) {
76+
throw new NoPatchesFoundException(Utils.getMessage("IMG-0057", patchNumber));
77+
} else if (providedVersion != null) {
78+
String finalProvidedVersion = providedVersion;
79+
selectedPatch = patches.stream()
80+
.filter(p -> finalProvidedVersion.equals(p.version())).findAny().orElse(null);
81+
if (selectedPatch == null) {
82+
logger.severe("IMG-0101", providedVersion);
83+
throw new VersionNotFoundException(patchNumber, providedVersion, patches);
7484
}
7585
} else {
76-
// select first recommended patch
86+
// Sort the patches list from highest to lowest (newest to oldest)
7787
List<AruPatch> sortedList = patches.stream().sorted(Comparator.reverseOrder()).collect(Collectors.toList());
78-
selectedPatch = sortedList.get(0);
79-
logger.warning("IMG-0057", selectedPatch.version(), sortedList.stream()
80-
.map(s -> s.patchId() + "_" + s.version())
81-
.collect(Collectors.joining(", ")));
88+
// Select the first recommended patch, if there is one marked as recommended
89+
selectedPatch = sortedList.stream().filter(AruPatch::isRecommended).findFirst().orElse(null);
90+
if (selectedPatch == null) {
91+
// nothing is marked as recommended, return the newest (highest numbered) patch
92+
selectedPatch = sortedList.stream().findFirst().orElse(null);
93+
// since patches list cannot be empty here, this findFirst should never return null
94+
}
8295
}
8396
logger.exiting(selectedPatch);
8497
return new OPatchFile(selectedPatch, userid, password);

imagetool/src/main/resources/ImageTool.properties

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ IMG-0053=[[brightgreen: Build successful.]] Build time={0}s. Image tag={1}
5555
IMG-0054=[[brightgreen: Dry run complete.]] No image created.
5656
IMG-0055=RunRCU can only be used when creating a new domain. Please try --wdtOperation=CREATE or removing --wdtRunRCU.
5757
IMG-0056=Patch {0} is not in the cache store and you have not provided Oracle Support credentials. Please provide --user with one of the password options or populate the cache store manually.
58-
IMG-0057=Currently, Oracle has marked more than one version of OPatch as recommended, selecting the first recommendatation, {0}. To override the default selection, use the --opatchBugNumber command line option with one of the recommended versions: {1}
58+
IMG-0057=Unable to find any OPatch versions for bug ID {0}. Please file an bug/issue if this issue persists.
5959
IMG-0058=A patch cannot have an empty/null bug number: {0}
6060
IMG-0059=Invalid response from Oracle ARU, unable to locate download URL for {0}
6161
IMG-0060=Adding patch [[cyan: {0}]] to cache, path={1}
@@ -98,4 +98,5 @@ IMG-0096=Unable to patch image {0}. The installed products could not be identifi
9898
IMG-0097=Inspecting {0}, this may take a few minutes if the image is not available locally.
9999
IMG-0098=Patch [[red: {0}]] is a Stack Patch Bundle, not a patch. Remove {0} from --patches and use [[cyan: --recommendedPatches]] instead.
100100
IMG-0099=Patch [[red: {0}]] is only for version {1} and may not be applicable to the target version {2}. Check Oracle Support, there may be another patch number for version {2}. Or check the OPatch output for results for this image.
101-
IMG-0100=Missing argument --fromImage. Update requires an image to be updated. Use --fromImage to specify the image to build on.
101+
IMG-0100=Missing argument --fromImage. Update requires an image to be updated. Use --fromImage to specify the image to build on.
102+
IMG-0101=The version of OPatch that you requested is not available: {0}

imagetool/src/test/java/com/oracle/weblogic/imagetool/cachestore/PatchFileTest.java

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ public TestAruUtil() throws IOException {
9090
responseCache.put("1110002", getResource("/patch-1110002.xml"));
9191
responseCache.put("1110003", getResource("/patch-1110003.xml"));
9292
responseCache.put("28186730", getResource("/patch-28186730.xml"));
93+
responseCache.put("2818673x", getResource("/patch-2818673x.xml"));
9394
}
9495

9596
@Override
@@ -343,18 +344,18 @@ void opatchDefaultTest() throws Exception {
343344
* There are 5 versions of the OPatch patch.
344345
* The user does not specify a version.
345346
* Expected:
346-
* The recommended patch from ARU should be selected.
347+
* The recommended OPatch version from ARU should be selected.
347348
*/
348349

349350
// 28186730 has multiple patches available, but none are specified
350-
String patchId = "28186730";
351+
String patchId = null;
351352
OPatchFile patchFile = OPatchFile.getInstance(patchId, "x", "x", cacheStore);
352353

353354
String filePath = patchFile.resolve(cacheStore);
354355

355356
assertNotNull(filePath, "Patch resolve() failed to get file path from XML");
356-
assertEquals("13.9.4.2.5", patchFile.getVersion(), "wrong version selected");
357-
String filePathFromCache = cacheStore.getValueFromCache(patchId + "_13.9.4.2.5");
357+
assertEquals("13.9.4.2.4", patchFile.getVersion(), "wrong version selected");
358+
String filePathFromCache = cacheStore.getValueFromCache("28186730_13.9.4.2.4");
358359
assertNotNull(filePathFromCache, "Could not find new patch in cache");
359360
assertEquals(filePath, filePathFromCache, "Patch in cache does not match");
360361
}
@@ -366,7 +367,7 @@ void opatchProvidedVersionTest() throws Exception {
366367
* There are 5 versions of the OPatch patch.
367368
* The user specifies a specific version.
368369
* Expected:
369-
* The provided version of the patch is selected.
370+
* The provided version of OPatch is selected.
370371
*/
371372

372373
// 28186730 has multiple patches available, but none are specified
@@ -391,4 +392,29 @@ void opatchProvidedWrongVersionTest() {
391392
assertThrows(VersionNotFoundException.class, () ->
392393
OPatchFile.getInstance(patchId, "x", "x", cacheStore));
393394
}
395+
396+
397+
@Test
398+
void opatchNoRecommendedTest() throws Exception {
399+
/*
400+
* Condition:
401+
* There are 5 versions of the OPatch patch.
402+
* None are marked as life_cycle = Recommended.
403+
* The user does not specify a specific version.
404+
* Expected:
405+
* The newest OPatch from ARU should be selected.
406+
*/
407+
408+
// 28186730 has multiple patches available, but none are specified
409+
String patchId = "2818673x";
410+
OPatchFile patchFile = OPatchFile.getInstance(patchId, "x", "x", cacheStore);
411+
412+
String filePath = patchFile.resolve(cacheStore);
413+
414+
assertNotNull(filePath, "Patch resolve() failed to get file path from XML");
415+
assertEquals("13.9.4.2.5", patchFile.getVersion(), "wrong version selected");
416+
String filePathFromCache = cacheStore.getValueFromCache("28186730_13.9.4.2.5");
417+
assertNotNull(filePathFromCache, "Could not find new patch in cache");
418+
assertEquals(filePath, filePathFromCache, "Patch in cache does not match");
419+
}
394420
}

imagetool/src/test/resources/patch-28186730.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
<translations_available>No</translations_available>
3535
<classification id="174">General</classification>
3636
<patch_classification id="174">General</patch_classification>
37-
<life_cycle id="175">Recommended</life_cycle>
37+
<!-- <life_cycle id="175">Recommended</life_cycle>-->
3838
<support_level id="G">General Support</support_level>
3939
<entitlements>
4040
<entitlement code="SW"/>

0 commit comments

Comments
 (0)