Skip to content

Commit

Permalink
Fixed bug where lack of architecture in cache entry prevented patch s…
Browse files Browse the repository at this point in the history
…election
  • Loading branch information
ddsharpe committed Oct 11, 2024
1 parent 6eaac1b commit fdb91ff
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/sonar-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Sonar Scan
run: |
mvn -B sonar:sonar \
-Dsonar.branch.name=main \
-Dsonar.branch.name=${GITHUB_REF##*/} \
-Dsonar.projectKey=oracle_weblogic-image-tool
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

package com.oracle.weblogic.imagetool.aru;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.xml.xpath.XPathExpressionException;

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

Map<String, AruPatch> patchMap = patches.stream().collect(Collectors
.toMap(AruPatch::version, aruPatch -> aruPatch));
Map<String, AruPatch> patchMap = new HashMap<>();
for (AruPatch patch: patches) {
if (patchMap.containsKey(patch.version())) {
throw new IllegalStateException(Utils.getMessage("IMG-0122", patch.patchId(), patch.version()));
}
patchMap.put(patch.version(), patch);
}

// select the correct patch version (priority order: user provided version, PSU version, GA installer version)
if (providedVersion != null) {
// if the user provided a specific version, select the provided version, or fail
Expand Down Expand Up @@ -270,6 +276,7 @@ public static AruPatch selectPatch(List<AruPatch> patches, String providedVersio
* @return true if this patch is applicable to the provided platform.
*/
public boolean isApplicableToTarget(int aruPlatform) {
logger.finer("AruPatch id {0} platform {1} checking against {2}", patchId, platform, aruPlatform);
// if this patch is for platform 2000, always return true, else return true if platforms are equal.
return platform == 2000 || platform == aruPlatform;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,11 @@ private List<AruPatch> getPatchesOffline(String bugNumber) throws CacheStoreExce
if (matcher.groupCount() == 3 && matcher.group(3) != null) {
int aruPlatform = Architecture.fromString(matcher.group(3)).getAruPlatform();
patch.platform(Integer.toString(aruPlatform));
} else {
// architecture was not specified in the cache key, assume generic platform
patch.platform("2000");
}
patch.description("UNAVAILABLE WHILE OFFLINE");
patch.description("description unavailable while working offline");
patchesInCache.add(patch);
}
return patchesInCache;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public class PatchVersionException extends IOException {

/**
* Signals that the bug number provided was not unique, and has multiple versions available.
* Signals that the bug number provided was unavailable for the requested or derived version.
*
* @param bugNumber the bug number that was searched
* @param versionsAvailable the list of versions for patches of that bug
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ String findPsuVersion(AruPatch aruPatch) {
List<AruPatch> resolveUserRequestedPatches(String psuVersion)
throws XPathExpressionException, IOException, AruException {

logger.entering(psuVersion);
List<AruPatch> result = new ArrayList<>(patches.size());
// if the user specified the PSU as a normal bug number in the list of --patches, use that
String effectivePsuVersion = psuVersion;
Expand Down Expand Up @@ -248,6 +249,7 @@ List<AruPatch> resolveUserRequestedPatches(String psuVersion)
result.add(selectedVersion);
}
}
logger.exiting(result);
return result;
}

Expand Down
1 change: 1 addition & 0 deletions imagetool/src/main/resources/ImageTool.properties
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,4 @@ IMG-0118=Failed to clean up intermediate container images for build ID {0}
IMG-0119=All parameters and options provided after the -- will be passed to the container image build command.
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.
IMG-0121=Did not recognize architecture name {0}. Defaulted to AMD64.
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.
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ static void setup(@TempDir Path tempDir)
addToCache(tempDir, "11100003_12.2.1.3.0", "p11100003_122130_Generic.zip");
addToCache(tempDir, "11100007_12.2.1.4.0_arm64", "p11100007_122140_ARM64.zip");
addToCache(tempDir, "11100007_12.2.1.4.0_amd64", "p11100007_122140_AMD64.zip");
addToCache(tempDir, "11100007_12.2.1.4.0", "p11100007_122140_GENERIC.zip");

addToCache(tempDir, "11100008_12.2.1.4.0_arm64", "p11100008_122140_ARM64.zip");
addToCache(tempDir, "11100008_12.2.1.4.0_amd64", "p11100008_122140_AMD64.zip");
addToCache(tempDir, "11100008_12.2.1.4.0", "p11100008_122140_GENERIC.zip");
// disable console logging
LoggingFacade logger = LoggingFactory.getLogger(PatchFile.class);
originalLogLevel = logger.getLevel();
Expand Down Expand Up @@ -454,7 +455,7 @@ void resolveArmFile() throws IOException {

@Test
void findArmPatch() throws Exception {
// 11100007 has multiple patches, 1 ARM, 1 AMD, and 1 GENERIC
// 11100007 has multiple patches, 1 ARM and 1 AMD
String patchId = "11100007";
String version = "12.2.1.4.0";
List<AruPatch> aruPatches = AruUtil.rest().getPatches(patchId, null, null)
Expand All @@ -472,4 +473,16 @@ void findArmPatch() throws Exception {
assertNotNull(filePathFromCache, "Could not find new patch in cache");
assertEquals(filePath, filePathFromCache, "Patch in cache does not match");
}

@Test
void illegalCacheEntry() throws Exception {
// 11100008 has multiple patches, 1 ARM, 1 AMD, and 1 GENERIC, generic and architecture specific cannot coexist
String patchId = "11100008";
String version = "12.2.1.4.0";
List<AruPatch> aruPatches = AruUtil.rest().getPatches(patchId, null, null)
.filter(p -> p.isApplicableToTarget(Architecture.ARM64.getAruPlatform()))
.collect(Collectors.toList());
assertThrows(IllegalStateException.class,
() -> AruPatch.selectPatch(aruPatches, version, null, version));
}
}

0 comments on commit fdb91ff

Please sign in to comment.