Skip to content

Commit 0c54839

Browse files
jshum2479ddsharpe
authored andcommitted
change patching implementation
* change how we handle patches * add patches conflict check for create image * Fix cache addPatch to accept new patch id format and remove validation * update doc to standardized patch number format * update doc and add rigid patch number pattern when using cache addPatch * change cache to ALWAYS and no other policy. useCache is now a hidden option. If no user credentials are provided then it will failed if the needed patch is not in the cache. --latestPSU always requires credentials. * optimize import, fix missing constructor super call and missing mustache * report validation message error * fix documentation * code cleanup * fix doc * fix help text for patchid * Change validatePatchIds not to thrown exception * remove download installer code * format error message according to the format requirement * refine error message * fix wdt complaining java_home not set for wdt * Fix volume mount issue when updating image where the local builddir is on nfs system. This also eliminate the problem with a remote docker daemob * rename domainType to wdtDomainType * Fix how the bash command is built for checking image info * Fix opatch lsinventory to use base64 output to properties instead of file * Add failure check for lsinventory result * Correct doc and error message for failure to cleanup temp directory * fix error message format
1 parent 704dc9c commit 0c54839

File tree

17 files changed

+504
-336
lines changed

17 files changed

+504
-336
lines changed

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public abstract class AbstractFile implements FileResolver {
2020
protected CachePolicy cachePolicy;
2121
protected String userId;
2222
protected String password;
23+
private final static Logger logger = Logger.getLogger(AbstractFile.class.getName());
2324

2425
public AbstractFile(String id, String version, CachePolicy cachePolicy, String userId, String password) {
2526
this.key = generateKey(id, version);
@@ -28,8 +29,24 @@ public AbstractFile(String id, String version, CachePolicy cachePolicy, String u
2829
this.password = password;
2930
}
3031

31-
public static String generateKey(String id, String version) {
32-
return id + CacheStore.CACHE_KEY_SEPARATOR + version;
32+
public String generateKey(String id, String version) {
33+
34+
// Note: this will be invoked by InstallerFile or PatchFile
35+
// for patches there are specific format, currently installers are
36+
// wls, fmw, jdk.
37+
//
38+
//
39+
String mykey = id;
40+
if (id == null) { // should never happens
41+
mykey = id + CacheStore.CACHE_KEY_SEPARATOR + version;
42+
} else if (id.indexOf('_') < 0) {
43+
if (version != null) {
44+
mykey = mykey + CacheStore.CACHE_KEY_SEPARATOR + version;
45+
}
46+
}
47+
48+
logger.finest("AbstractFile generating key returns " + mykey);
49+
return mykey;
3350
}
3451

3552
public static boolean isFileOnDisk(String filePath) {

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,18 @@
66
package com.oracle.weblogic.imagetool.api.model;
77

88
/**
9+
* @Deprecated
10+
* This is subject to removal and there is no need to use it
11+
* The logic is changed to use the presence of userId and password to
12+
* determine whether to access online if the item is not in the cache.
13+
* It allows the cache is just a store and nothing more
14+
*
915
* first - Use cache entries and download artifacts if required
1016
* always - Use only cache entries and never download artifacts
1117
* never - Ignore cache entries and always download artifacts
1218
*/
1319
public enum CachePolicy {
14-
FIRST("first"),
15-
ALWAYS("always"),
16-
NEVER("never");
20+
ALWAYS("always");
1721

1822
private String value;
1923

imagetool/src/main/java/com/oracle/weblogic/imagetool/cli/cache/AddPatchEntry.java

Lines changed: 20 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,20 @@
55
package com.oracle.weblogic.imagetool.cli.cache;
66

77
import com.oracle.weblogic.imagetool.api.meta.CacheStore;
8-
import com.oracle.weblogic.imagetool.api.model.AbstractFile;
98
import com.oracle.weblogic.imagetool.api.model.CommandResponse;
109
import com.oracle.weblogic.imagetool.api.model.WLSInstallerType;
11-
import com.oracle.weblogic.imagetool.util.ARUUtil;
1210
import com.oracle.weblogic.imagetool.util.Constants;
13-
import com.oracle.weblogic.imagetool.util.SearchResult;
1411
import com.oracle.weblogic.imagetool.util.Utils;
15-
import com.oracle.weblogic.imagetool.util.XPathUtil;
16-
import org.apache.commons.codec.digest.DigestUtils;
17-
import org.w3c.dom.Document;
18-
import picocli.CommandLine.Command;
19-
import picocli.CommandLine.Option;
2012

21-
import java.io.FileInputStream;
22-
import java.io.IOException;
2313
import java.nio.file.Files;
2414
import java.nio.file.Path;
15+
import java.util.ArrayList;
16+
import java.util.List;
2517
import java.util.logging.Logger;
2618

19+
import picocli.CommandLine.Command;
20+
import picocli.CommandLine.Option;
21+
2722
@Command(
2823
name = "addPatch",
2924
description = "Add cache entry for wls|fmw patch or psu",
@@ -42,24 +37,17 @@ public AddPatchEntry(boolean isCLIMode) {
4237

4338
@Override
4439
public CommandResponse call() throws Exception {
45-
String password = handlePasswordOptions();
4640

4741
if (patchId != null && !patchId.isEmpty()
4842
&& location != null && Files.exists(location)
4943
&& Files.isRegularFile(location)) {
5044

51-
String patchNumber;
52-
if (patchId.matches(Constants.PATCH_ID_REGEX)) {
53-
patchNumber = patchId.substring(1);
54-
} else {
55-
return new CommandResponse(-1, "Invalid patch id format: " + patchId);
56-
}
57-
if (userId != null && !userId.isEmpty() && password != null && !password.isEmpty() ) {
58-
return validateAndAddToCache(patchNumber, password);
59-
} else {
60-
logger.info("Skipping patch validation, username and password were not provided");
61-
return addToCache(patchNumber);
45+
List<String> patches = new ArrayList<>();
46+
patches.add(patchId);
47+
if (!Utils.validatePatchIds(patches, true)) {
48+
return new CommandResponse(-1, "Patch ID validation failed");
6249
}
50+
return addToCache(patchId);
6351
}
6452

6553
String msg = "Invalid arguments";
@@ -81,25 +69,7 @@ public CommandResponse call() throws Exception {
8169
* @throws Exception if the ARU call to get patch details failed
8270
*/
8371
private CommandResponse validateAndAddToCache(String patchNumber, String password) throws Exception {
84-
boolean matches = false;
85-
86-
SearchResult searchResult = ARUUtil.getPatchDetail(type.toString(), version, patchNumber, userId, password);
87-
88-
if (searchResult.isSuccess()) {
89-
Document document = searchResult.getResults();
90-
String patchDigest = XPathUtil.applyXPathReturnString(document, "string"
91-
+ "(/results/patch[1]/files/file/digest[@type='SHA-256']/text())");
92-
String localDigest = DigestUtils.sha256Hex(new FileInputStream(location.toFile()));
93-
94-
if (localDigest.equalsIgnoreCase(patchDigest)) {
95-
return addToCache(patchNumber);
96-
} else {
97-
return new CommandResponse(-1, String.format(
98-
"Local file sha-256 digest %s != patch digest %s", localDigest, patchDigest));
99-
}
100-
}
101-
102-
return new CommandResponse(-1, String.format("Unable to find patchId %s on Oracle Support", patchId));
72+
return addToCache(patchNumber);
10373
}
10474

10575
/**
@@ -108,33 +78,31 @@ private CommandResponse validateAndAddToCache(String patchNumber, String passwor
10878
* @return CLI command response
10979
*/
11080
private CommandResponse addToCache(String patchNumber) {
111-
String key = AbstractFile.generateKey(patchNumber, version);
81+
logger.info("adding key " + patchNumber);
82+
String key = patchNumber;
11283

11384
// Check if it is an Opatch patch
11485
String opatchNumber = Utils.getOpatchVersionFromZip(location.toAbsolutePath().toString());
11586
if (opatchNumber != null) {
11687
int lastSeparator = key.lastIndexOf(CacheStore.CACHE_KEY_SEPARATOR);
11788
key = key.substring(0,lastSeparator) + CacheStore.CACHE_KEY_SEPARATOR + Constants.OPATCH_PATCH_TYPE;
11889
}
90+
logger.info("adding key " + key);
91+
if (cacheStore.getValueFromCache(key) != null ) {
92+
String error = String.format("Cache key %s already exists, remove it first", key);
93+
logger.severe(error);
94+
throw new IllegalArgumentException(error);
95+
}
11996
cacheStore.addToCache(key, location.toAbsolutePath().toString());
12097
String msg = String.format("Added Patch entry %s=%s for %s", key, location.toAbsolutePath(), type);
12198
logger.info(msg);
12299
return new CommandResponse(0, msg);
123100
}
124101

125-
/**
126-
* Determines the support password by parsing the possible three input options
127-
*
128-
* @return String form of password
129-
* @throws IOException in case of error
130-
*/
131-
private String handlePasswordOptions() throws IOException {
132-
return Utils.getPasswordFromInputs(passwordStr, passwordFile, passwordEnv);
133-
}
134102

135103
@Option(
136104
names = {"--patchId"},
137-
description = "Patch number. Ex: p28186730",
105+
description = "Patch number. Ex: 28186730",
138106
required = true
139107
)
140108
private String patchId;
@@ -147,13 +115,6 @@ private String handlePasswordOptions() throws IOException {
147115
)
148116
private WLSInstallerType type;
149117

150-
@Option(
151-
names = {"--version"},
152-
description = "version of mw this patch is for. Ex: 12.2.1.3.0",
153-
required = true,
154-
defaultValue = Constants.DEFAULT_WLS_VERSION
155-
)
156-
private String version;
157118

158119
@Option(
159120
names = {"--path"},
@@ -162,31 +123,4 @@ private String handlePasswordOptions() throws IOException {
162123
)
163124
private Path location;
164125

165-
@Option(
166-
names = {"--user"},
167-
paramLabel = "<support email>",
168-
description = "Oracle Support email id"
169-
)
170-
private String userId;
171-
172-
@Option(
173-
names = {"--password"},
174-
paramLabel = "<password for support user id>",
175-
description = "Password for support userId"
176-
)
177-
String passwordStr;
178-
179-
@Option(
180-
names = {"--passwordEnv"},
181-
paramLabel = "<environment variable>",
182-
description = "environment variable containing the support password"
183-
)
184-
String passwordEnv;
185-
186-
@Option(
187-
names = {"--passwordFile"},
188-
paramLabel = "<password file>",
189-
description = "path to file containing just the password"
190-
)
191-
Path passwordFile;
192126
}

0 commit comments

Comments
 (0)