Skip to content

Commit 0a5cd0e

Browse files
committed
Merge branch 'cache-patch-fix' into 'main'
Fixed bug where lack of architecture in cache entry prevented patch selection See merge request weblogic-cloud/weblogic-image-tool!490
2 parents 6eaac1b + fdb91ff commit 0a5cd0e

File tree

7 files changed

+35
-9
lines changed

7 files changed

+35
-9
lines changed

.github/workflows/sonar-branch.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
- name: Sonar Scan
2828
run: |
2929
mvn -B sonar:sonar \
30-
-Dsonar.branch.name=main \
30+
-Dsonar.branch.name=${GITHUB_REF##*/} \
3131
-Dsonar.projectKey=oracle_weblogic-image-tool
3232
env:
3333
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

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

+10-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
package com.oracle.weblogic.imagetool.aru;
55

6+
import java.util.HashMap;
67
import java.util.List;
78
import java.util.Map;
8-
import java.util.stream.Collectors;
99
import java.util.stream.Stream;
1010
import javax.xml.xpath.XPathExpressionException;
1111

@@ -237,8 +237,14 @@ public static AruPatch selectPatch(List<AruPatch> patches, String providedVersio
237237
logger.entering(patches, providedVersion, psuVersion, installerVersion);
238238
AruPatch selected = null;
239239

240-
Map<String, AruPatch> patchMap = patches.stream().collect(Collectors
241-
.toMap(AruPatch::version, aruPatch -> aruPatch));
240+
Map<String, AruPatch> patchMap = new HashMap<>();
241+
for (AruPatch patch: patches) {
242+
if (patchMap.containsKey(patch.version())) {
243+
throw new IllegalStateException(Utils.getMessage("IMG-0122", patch.patchId(), patch.version()));
244+
}
245+
patchMap.put(patch.version(), patch);
246+
}
247+
242248
// select the correct patch version (priority order: user provided version, PSU version, GA installer version)
243249
if (providedVersion != null) {
244250
// if the user provided a specific version, select the provided version, or fail
@@ -270,6 +276,7 @@ public static AruPatch selectPatch(List<AruPatch> patches, String providedVersio
270276
* @return true if this patch is applicable to the provided platform.
271277
*/
272278
public boolean isApplicableToTarget(int aruPlatform) {
279+
logger.finer("AruPatch id {0} platform {1} checking against {2}", patchId, platform, aruPlatform);
273280
// if this patch is for platform 2000, always return true, else return true if platforms are equal.
274281
return platform == 2000 || platform == aruPlatform;
275282
}

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -518,8 +518,11 @@ private List<AruPatch> getPatchesOffline(String bugNumber) throws CacheStoreExce
518518
if (matcher.groupCount() == 3 && matcher.group(3) != null) {
519519
int aruPlatform = Architecture.fromString(matcher.group(3)).getAruPlatform();
520520
patch.platform(Integer.toString(aruPlatform));
521+
} else {
522+
// architecture was not specified in the cache key, assume generic platform
523+
patch.platform("2000");
521524
}
522-
patch.description("UNAVAILABLE WHILE OFFLINE");
525+
patch.description("description unavailable while working offline");
523526
patchesInCache.add(patch);
524527
}
525528
return patchesInCache;

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
public class PatchVersionException extends IOException {
1313

1414
/**
15-
* Signals that the bug number provided was not unique, and has multiple versions available.
15+
* Signals that the bug number provided was unavailable for the requested or derived version.
1616
*
1717
* @param bugNumber the bug number that was searched
1818
* @param versionsAvailable the list of versions for patches of that bug

imagetool/src/main/java/com/oracle/weblogic/imagetool/cli/menu/CommonPatchingOptions.java

+2
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ String findPsuVersion(AruPatch aruPatch) {
211211
List<AruPatch> resolveUserRequestedPatches(String psuVersion)
212212
throws XPathExpressionException, IOException, AruException {
213213

214+
logger.entering(psuVersion);
214215
List<AruPatch> result = new ArrayList<>(patches.size());
215216
// if the user specified the PSU as a normal bug number in the list of --patches, use that
216217
String effectivePsuVersion = psuVersion;
@@ -248,6 +249,7 @@ List<AruPatch> resolveUserRequestedPatches(String psuVersion)
248249
result.add(selectedVersion);
249250
}
250251
}
252+
logger.exiting(result);
251253
return result;
252254
}
253255

imagetool/src/main/resources/ImageTool.properties

+1
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,4 @@ IMG-0118=Failed to clean up intermediate container images for build ID {0}
120120
IMG-0119=All parameters and options provided after the -- will be passed to the container image build command.
121121
IMG-0120=Retries exhausted, unable to download patch from Oracle. Try again later or manually add the patch to the cache to skip this download step.
122122
IMG-0121=Did not recognize architecture name {0}. Defaulted to AMD64.
123+
IMG-0122=Invalid patch {0} for version {1}. A patch cannot be both generic and architecture specific. Remove the invalid entry from the cache, like {0}_{1}_xxx64.

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

+16-3
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ static void setup(@TempDir Path tempDir)
6868
addToCache(tempDir, "11100003_12.2.1.3.0", "p11100003_122130_Generic.zip");
6969
addToCache(tempDir, "11100007_12.2.1.4.0_arm64", "p11100007_122140_ARM64.zip");
7070
addToCache(tempDir, "11100007_12.2.1.4.0_amd64", "p11100007_122140_AMD64.zip");
71-
addToCache(tempDir, "11100007_12.2.1.4.0", "p11100007_122140_GENERIC.zip");
72-
71+
addToCache(tempDir, "11100008_12.2.1.4.0_arm64", "p11100008_122140_ARM64.zip");
72+
addToCache(tempDir, "11100008_12.2.1.4.0_amd64", "p11100008_122140_AMD64.zip");
73+
addToCache(tempDir, "11100008_12.2.1.4.0", "p11100008_122140_GENERIC.zip");
7374
// disable console logging
7475
LoggingFacade logger = LoggingFactory.getLogger(PatchFile.class);
7576
originalLogLevel = logger.getLevel();
@@ -454,7 +455,7 @@ void resolveArmFile() throws IOException {
454455

455456
@Test
456457
void findArmPatch() throws Exception {
457-
// 11100007 has multiple patches, 1 ARM, 1 AMD, and 1 GENERIC
458+
// 11100007 has multiple patches, 1 ARM and 1 AMD
458459
String patchId = "11100007";
459460
String version = "12.2.1.4.0";
460461
List<AruPatch> aruPatches = AruUtil.rest().getPatches(patchId, null, null)
@@ -472,4 +473,16 @@ void findArmPatch() throws Exception {
472473
assertNotNull(filePathFromCache, "Could not find new patch in cache");
473474
assertEquals(filePath, filePathFromCache, "Patch in cache does not match");
474475
}
476+
477+
@Test
478+
void illegalCacheEntry() throws Exception {
479+
// 11100008 has multiple patches, 1 ARM, 1 AMD, and 1 GENERIC, generic and architecture specific cannot coexist
480+
String patchId = "11100008";
481+
String version = "12.2.1.4.0";
482+
List<AruPatch> aruPatches = AruUtil.rest().getPatches(patchId, null, null)
483+
.filter(p -> p.isApplicableToTarget(Architecture.ARM64.getAruPlatform()))
484+
.collect(Collectors.toList());
485+
assertThrows(IllegalStateException.class,
486+
() -> AruPatch.selectPatch(aruPatches, version, null, version));
487+
}
475488
}

0 commit comments

Comments
 (0)