Skip to content

Commit 15fea2b

Browse files
authored
Choose latest OPatch when multiple versions of OPatch are recommended (#242)
1 parent 745b73c commit 15fea2b

File tree

5 files changed

+19
-7
lines changed

5 files changed

+19
-7
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* Metadata for a patch, as defined by ARU.
2222
* Simple bean for holding metadata obtained from ARU for a given patch ID and version.
2323
*/
24-
public class AruPatch {
24+
public class AruPatch implements Comparable<AruPatch> {
2525
private static final LoggingFacade logger = LoggingFactory.getLogger(AruPatch.class);
2626

2727
private String patchId;
@@ -268,6 +268,9 @@ public static AruPatch selectPatch(List<AruPatch> patches, String providedVersio
268268
@Override
269269
public String toString() {
270270
return patchId + " - " + description;
271+
}
271272

273+
public int compareTo(AruPatch obj) {
274+
return version.compareTo(obj.version);
272275
}
273276
}

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import java.io.FileNotFoundException;
77
import java.io.IOException;
8+
import java.util.Comparator;
89
import java.util.List;
910
import java.util.Set;
1011
import java.util.stream.Collectors;
@@ -62,18 +63,25 @@ public static OPatchFile getInstance(String patchId, String userid, String passw
6263
patches = filteredList.collect(Collectors.toList());
6364
}
6465

66+
// For the OPatch use case, only the provided version (--opatchBugNumber) is used to "select" a patch.
67+
// selectPatch will return null if there is more than one patch in the patches list.
6568
AruPatch selectedPatch = AruPatch.selectPatch(patches, providedVersion, null, null);
6669

6770
if (selectedPatch != null) {
6871
// if offline, find the latest OPatch version available in the cache
6972
if (isOffline(userid, password) && providedVersion == null) {
7073
selectedPatch.version(getLatestCachedVersion(cache, patchNumber));
7174
}
72-
logger.exiting(selectedPatch);
73-
return new OPatchFile(selectedPatch, userid, password);
7475
} else {
75-
throw new MultiplePatchVersionsException(patchNumber, patches);
76+
// select first recommended patch
77+
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(", ")));
7682
}
83+
logger.exiting(selectedPatch);
84+
return new OPatchFile(selectedPatch, userid, password);
7785
}
7886

7987
private static boolean isOffline(String userid, String password) {

imagetool/src/main/resources/ImageTool.properties

Lines changed: 1 addition & 1 deletion
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=Could not locate patch ID {0} from Oracle
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}
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}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,8 @@ void opatchDefaultTest() throws Exception {
353353
String filePath = patchFile.resolve(cacheStore);
354354

355355
assertNotNull(filePath, "Patch resolve() failed to get file path from XML");
356-
assertEquals("13.9.4.2.4", patchFile.getVersion(), "wrong version selected");
357-
String filePathFromCache = cacheStore.getValueFromCache(patchId + "_13.9.4.2.4");
356+
assertEquals("13.9.4.2.5", patchFile.getVersion(), "wrong version selected");
357+
String filePathFromCache = cacheStore.getValueFromCache(patchId + "_13.9.4.2.5");
358358
assertNotNull(filePathFromCache, "Could not find new patch in cache");
359359
assertEquals(filePath, filePathFromCache, "Patch in cache does not match");
360360
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +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>
3738
<support_level id="G">General Support</support_level>
3839
<entitlements>
3940
<entitlement code="SW"/>

0 commit comments

Comments
 (0)