Skip to content

Commit d0a539f

Browse files
authored
Discard Stack Patch Bundle patch numbers and provide warning to the user (#300)
* Discard Stack Patch Bundle patch numbers and provide warning to the user * Moved check for Stack Patch Bundle so that --recommendedPatches and --latestPSU could handle SPB differently
1 parent 89f2b85 commit d0a539f

File tree

12 files changed

+90
-68
lines changed

12 files changed

+90
-68
lines changed

imagetool/src/main/java/com/oracle/weblogic/imagetool/api/model/CommandResponse.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
public class CommandResponse {
99

10-
private int status;
11-
private String message;
12-
private Object[] messageParams;
10+
private final int status;
11+
private final String message;
12+
private final Object[] messageParams;
1313

1414
/**
1515
* For use with PicoCLI to return the response to the command line.

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

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,19 @@ public class AruHttpHelper {
2222
private boolean success;
2323
private Document results;
2424
private String errorMessage;
25-
private AruProduct product;
26-
private String version;
27-
private String userId;
28-
private String password;
29-
private String release;
25+
private final AruProduct product;
26+
private final String userId;
27+
private final String password;
3028

3129
/**
3230
* Constructor encapsulating the information for the ARU search.
3331
*
3432
* @param product ARU product
35-
* @param version of the product
3633
* @param userId ARU user credentials
3734
* @param password ARU password credentials
3835
*/
39-
AruHttpHelper(AruProduct product, String version, String userId, String password) {
36+
AruHttpHelper(AruProduct product, String userId, String password) {
4037
this.product = product;
41-
this.version = version;
4238
this.userId = userId;
4339
this.password = password;
4440
this.success = true;
@@ -52,7 +48,7 @@ public class AruHttpHelper {
5248
* @param password ARU credentials password
5349
*/
5450
AruHttpHelper(String userId, String password) {
55-
this(null, null, userId, password);
51+
this(null, userId, password);
5652
}
5753

5854
/**
@@ -81,34 +77,6 @@ Document results() {
8177
return results;
8278
}
8379

84-
/**
85-
* Return the product version number for the search.
86-
*
87-
* @return product version number
88-
*/
89-
String version() {
90-
return version;
91-
}
92-
93-
/**
94-
* Return the Release number for the category and version.
95-
*
96-
* @return ARU release number
97-
*/
98-
String release() {
99-
return release;
100-
}
101-
102-
/**
103-
* Set the release number for the product category and version.
104-
*
105-
* @param release set the product release number
106-
*/
107-
AruHttpHelper release(String release) {
108-
this.release = release;
109-
return this;
110-
}
111-
11280
/**
11381
* Return the user for the ARU credentials.
11482
*

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

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,14 @@ public boolean isRecommended() {
154154
return "Recommended".equals(lifecycle);
155155
}
156156

157+
public boolean notStackPatchBundle() {
158+
return !isStackPatchBundle();
159+
}
160+
161+
public boolean isStackPatchBundle() {
162+
return description != null && description.contains("STACK PATCH BUNDLE");
163+
}
164+
157165
/**
158166
* Given an XML document with a list of patches, extract each patch into the AruPatch bean and return the list.
159167
* @param patchList an XML document with a list of patches from ARU
@@ -191,11 +199,6 @@ public static List<AruPatch> getPatches(Document patchList, String patchSelector
191199
.downloadHost(XPathUtil.string(nodeList.item(i), "./files/file/download_url/@host"))
192200
.downloadPath(XPathUtil.string(nodeList.item(i), "./files/file/download_url/text()"));
193201

194-
// Stack Patch Bundle (SPB) is not a traditional patch. Patches in SPB are duplicates of recommended.
195-
if (patch.description.contains("STACK PATCH BUNDLE")) {
196-
logger.fine("Discarded Stack Patch Bundle: {0}", patch.description);
197-
continue;
198-
}
199202
int index = patch.downloadPath().indexOf("patch_file=");
200203
if (index < 0) {
201204
throw new XPathExpressionException(Utils.getMessage("IMG-0059", patch.patchId()));
@@ -230,9 +233,11 @@ public static List<AruPatch> getPatches(Document patchList, String patchSelector
230233
public static AruPatch selectPatch(List<AruPatch> patches, String providedVersion, String psuVersion,
231234
String installerVersion) throws VersionNotFoundException {
232235

236+
logger.entering(patches, providedVersion, psuVersion, installerVersion);
233237
AruPatch selected = null;
234238

235239
if (patches.isEmpty()) {
240+
logger.exiting("Patches list is empty");
236241
return null;
237242
}
238243

@@ -248,7 +253,19 @@ public static AruPatch selectPatch(List<AruPatch> patches, String providedVersio
248253
}
249254
} else if (providedVersion != null && !selected.version().equals(providedVersion)) {
250255
throw new VersionNotFoundException(selected.patchId(), providedVersion, patches);
256+
} else {
257+
// the patch has a version from ARU, warn the user if the version doesn't match the target install
258+
if (psuVersion != null) {
259+
if (!selected.version().equals(psuVersion)) {
260+
logger.warning("IMG-0099", selected.patchId(), selected.version(), psuVersion);
261+
}
262+
} else {
263+
if (installerVersion != null && !selected.version().equals(installerVersion)) {
264+
logger.warning("IMG-0099", selected.patchId(), selected.version(), installerVersion);
265+
}
266+
}
251267
}
268+
logger.exiting(selected);
252269
return selected;
253270
}
254271

@@ -267,9 +284,19 @@ public static AruPatch selectPatch(List<AruPatch> patches, String providedVersio
267284
selected = patchMap.get(installerVersion);
268285
}
269286

287+
logger.exiting(selected);
270288
return selected;
271289
}
272290

291+
/**
292+
* Find and remove any Stack Patch Bundle type patches from the list.
293+
* @param patches the list to scan
294+
* @return a new list, with SPB removed
295+
*/
296+
public static List<AruPatch> removeStackPatchBundle(List<AruPatch> patches) {
297+
return patches.stream().filter(AruPatch::notStackPatchBundle).collect(Collectors.toList());
298+
}
299+
273300
@Override
274301
public String toString() {
275302
return patchId + " - " + description;

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,13 @@ List<AruPatch> getLatestPsu(AruProduct product, String version, String userId, S
100100
String releaseNumber = getReleaseNumber(product, version, userId, password);
101101
Document aruRecommendations = getRecommendedPatchesMetadata(product, releaseNumber, userId, password);
102102
logger.exiting();
103-
return AruPatch.getPatches(aruRecommendations, "[./psu_bundle]");
103+
return AruPatch.removeStackPatchBundle(AruPatch.getPatches(aruRecommendations, "[./psu_bundle]"));
104104
} catch (NoPatchesFoundException | ReleaseNotFoundException ex) {
105105
logger.exiting();
106106
return Collections.emptyList();
107107
} catch (IOException | XPathExpressionException e) {
108-
AruException aruE = new AruException(Utils.getMessage("IMG-0032", product.description(), version), e);
109-
logger.throwing(aruE);
110-
throw aruE;
108+
throw logger.throwing(
109+
new AruException(Utils.getMessage("IMG-0032", product.description(), version), e));
111110
}
112111
}
113112

@@ -151,7 +150,7 @@ List<AruPatch> getRecommendedPatches(AruProduct product, String version, String
151150
logger.info("IMG-0067", product.description());
152151
String releaseNumber = getReleaseNumber(product, version, userId, password);
153152
Document aruRecommendations = getRecommendedPatchesMetadata(product, releaseNumber, userId, password);
154-
List<AruPatch> patches = AruPatch.getPatches(aruRecommendations);
153+
List<AruPatch> patches = AruPatch.removeStackPatchBundle(AruPatch.getPatches(aruRecommendations));
155154
String psuVersion = getPsuVersion(patches);
156155
if (!Utils.isEmptyString(psuVersion)) {
157156
patches.forEach(p -> logger.fine("Discarding recommended patch {0} {1}", p.patchId(), p.description()));
@@ -161,7 +160,7 @@ List<AruPatch> getRecommendedPatches(AruProduct product, String version, String
161160
String psuReleaseNumber = getReleaseNumber(product, psuVersion, userId, password);
162161
// get recommended patches for PSU release (Overlay patches are only recommended on the PSU release)
163162
Document psuRecommendation = getRecommendedPatchesMetadata(product, psuReleaseNumber, userId, password);
164-
patches = AruPatch.getPatches(psuRecommendation);
163+
patches = AruPatch.removeStackPatchBundle(AruPatch.getPatches(psuRecommendation));
165164
}
166165
patches.forEach(p -> logger.info("IMG-0068", product.description(), p.patchId(), p.description()));
167166
logger.exiting(patches);
@@ -240,8 +239,6 @@ static void validatePatches(List<InstalledPatch> installedPatches, List<AruPatch
240239
continue;
241240
}
242241

243-
logger.info("IMG-0022", patch.patchId(), patch.releaseName());
244-
245242
payload.append(String.format("<patch_group rel_id=\"%s\">%s</patch_group>",
246243
patch.release(), patch.patchId()));
247244
}
@@ -402,7 +399,7 @@ public List<AruPatch> getPatches(String bugNumber, String userId, String passwor
402399
} catch (NoPatchesFoundException patchEx) {
403400
throw new NoPatchesFoundException(Utils.getMessage("IMG-0086", bugNumber), patchEx);
404401
}
405-
return AruPatch.getPatches(response, "");
402+
return AruPatch.getPatches(response);
406403
}
407404

408405
/**
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (c) 2021, 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.aru;
5+
6+
public class InvalidPatchNumberException extends AruException {
7+
/**
8+
* Specified patch number is invalid for this use case.
9+
*
10+
* @param msg error message
11+
*/
12+
public InvalidPatchNumberException(String msg) {
13+
super(msg);
14+
}
15+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) 2020, 2021, Oracle and/or its affiliates.
22
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33

4-
package com.oracle.weblogic.imagetool.cachestore;
4+
package com.oracle.weblogic.imagetool.aru;
55

66
import java.io.IOException;
77
import java.util.List;

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

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@
2424
import com.oracle.weblogic.imagetool.aru.AruProduct;
2525
import com.oracle.weblogic.imagetool.aru.AruUtil;
2626
import com.oracle.weblogic.imagetool.aru.InstalledPatch;
27+
import com.oracle.weblogic.imagetool.aru.InvalidPatchNumberException;
28+
import com.oracle.weblogic.imagetool.aru.MultiplePatchVersionsException;
2729
import com.oracle.weblogic.imagetool.builder.BuildCommand;
28-
import com.oracle.weblogic.imagetool.cachestore.MultiplePatchVersionsException;
2930
import com.oracle.weblogic.imagetool.cachestore.OPatchFile;
3031
import com.oracle.weblogic.imagetool.cachestore.PatchFile;
3132
import com.oracle.weblogic.imagetool.cli.HelpVersionProvider;
@@ -286,7 +287,7 @@ void handlePatchFiles(FmwInstallerType installerType, List<InstalledPatch> insta
286287

287288
// add user-provided patch list to any patches that were found for latestPsu or recommendedPatches
288289
for (String patchId : patches) {
289-
// if user mistakenly added the OPatch patch to the WLS patch list, skip it
290+
// if user mistakenly added the OPatch patch to the WLS patch list, skip it. WIT updates OPatch anyway
290291
if (OPatchFile.isOPatchPatch(patchId)) {
291292
continue;
292293
}
@@ -298,13 +299,22 @@ void handlePatchFiles(FmwInstallerType installerType, List<InstalledPatch> insta
298299
patchId = patchId.substring(0, split);
299300
}
300301
List<AruPatch> patchVersions = AruUtil.rest().getPatches(patchId, userId, password);
301-
AruPatch selectedVersion = AruPatch.selectPatch(patchVersions, providedVersion, psuVersion,
302-
getInstallerVersion());
303302

304-
if (selectedVersion != null) {
305-
aruPatches.add(selectedVersion);
306-
} else {
307-
throw new MultiplePatchVersionsException(patchId, aruPatches);
303+
// Stack Patch Bundle (SPB) is not a traditional patch. Patches in SPB are duplicates of recommended.
304+
if (patchVersions.stream().anyMatch(AruPatch::isStackPatchBundle)) {
305+
// Do not continue if the user specified a patch number that cannot be applied.
306+
throw logger.throwing(new InvalidPatchNumberException(Utils.getMessage("IMG-0098", patchId)));
307+
}
308+
309+
if (!patchVersions.isEmpty()) {
310+
AruPatch selectedVersion = AruPatch.selectPatch(patchVersions, providedVersion, psuVersion,
311+
getInstallerVersion());
312+
313+
if (selectedVersion != null) {
314+
aruPatches.add(selectedVersion);
315+
} else {
316+
throw logger.throwing(new MultiplePatchVersionsException(patchId, aruPatches));
317+
}
308318
}
309319
}
310320

imagetool/src/main/java/com/oracle/weblogic/imagetool/logging/LoggingFacade.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,11 +484,12 @@ public void severe(String msg, Throwable thrown) {
484484
*
485485
* @param pending an Exception to include in the logged message
486486
*/
487-
public void throwing(Throwable pending) {
487+
public <T extends Throwable> T throwing(T pending) {
488488
if (isFinerEnabled()) {
489489
CallerDetails details = inferCaller();
490490
logger.throwing(details.clazz, details.method, pending);
491491
}
492+
return pending;
492493
}
493494

494495
/**

imagetool/src/main/java/com/oracle/weblogic/imagetool/util/Utils.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,7 @@ public static Properties getBaseImageProperties(String builder, String dockerIma
427427
Utils.copyResourceAsFile(script, contextDir + File.separator + scriptToRun, true);
428428
List<String> imageEnvCmd = Utils.getDockerRunCmd(builder,
429429
contextDir + File.separator + scriptToRun, dockerImage);
430+
logger.info("IMG-0097", dockerImage);
430431
Properties result = Utils.runDockerCommand(imageEnvCmd);
431432
logger.exiting(result);
432433
return result;

imagetool/src/main/resources/ImageTool.properties

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ IMG-0008=Updating OPatch in final image from version {0} to version {1}
1010
IMG-0009=Skipping patch conflict check, no support credentials provided
1111
IMG-0010=Oracle Home will be set to [[cyan: {0}]]
1212
IMG-0011=Installer with key="{0}" is not in the local cache, please download the installer and add it to the cache with "imagetool cache addInstaller ..."
13-
IMG-0012=Validating patches
13+
IMG-0012=Checking for conflicting patches
1414
IMG-0013=Error parsing additional build commands file {0}
1515
IMG-0014=Additional build command section, {0}, was not one of the valid sections: {1}
1616
IMG-0015=Additional build commands, adding {0} lines to section [{1}]
@@ -20,7 +20,7 @@ IMG-0018=Downloading patch [[cyan: {0}]]...
2020
IMG-0019={0} - locating patch number for the latest PSU...
2121
IMG-0020={0} - the latest PSU patch number is [[cyan: {1}]]
2222
IMG-0021=ORACLE_HOME value must be the same in both new and old image in order to rebase the domain
23-
IMG-0022=Validated patch {0} for {1}
23+
IMG-0022=NOT USED
2424
IMG-0023=No PSU recommended for {0}, version {1}
2525
IMG-0024=Cached patch file {0} has an empty path
2626
IMG-0025=No Domain Home in source image. Add DOMAIN_HOME environment variable to source image and try again.
@@ -95,3 +95,6 @@ IMG-0093=Patching skipped. Using CREATE to patch --fromImage with an existing O
9595
IMG-0094=Source image installer type: ([[green: {0}]])
9696
IMG-0095=Unable to parse response for Oracle patches in fromImage: {0}
9797
IMG-0096=Unable to patch image {0}. The installed products could not be identified for patching. The most likely cause is that the registry.xml in this image may be invalid.
98+
IMG-0097=Inspecting {0}, this may take a few minutes if the image is not available locally.
99+
IMG-0098=Patch [[red: {0}]] is a Stack Patch Bundle, not a patch. Remove {0} from --patches and use [[cyan: --recommendedPatches]] instead.
100+
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.

0 commit comments

Comments
 (0)