Skip to content

Commit cea4ef7

Browse files
authored
Merge pull request #16 from oracle/opatchfix
Opatchfix
2 parents 614814d + 92265e8 commit cea4ef7

File tree

16 files changed

+173
-265
lines changed

16 files changed

+173
-265
lines changed

imagetool/src/main/java/com/oracle/weblogic/imagetool/api/meta/CacheStore.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,4 @@ public interface CacheStore {
6666
*/
6767
Map<String, String> getCacheItems();
6868

69-
/**
70-
* Set cache directory to new location.
71-
*
72-
* @param value a directory path
73-
* @return true if successful
74-
*/
75-
boolean setCacheDir(String value);
7669
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ private CommandResponse validateAndAddToCache(String patchNumber, String passwor
109109
*/
110110
private CommandResponse addToCache(String patchNumber) {
111111
String key = AbstractFile.generateKey(patchNumber, version);
112+
113+
// Check if it is an Opatch patch
114+
String opatchNumber = Utils.getOpatchVersionFromZip(location.toAbsolutePath().toString());
115+
if (opatchNumber != null) {
116+
int lastSeparator = key.lastIndexOf(CacheStore.CACHE_KEY_SEPARATOR);
117+
key = key.substring(0,lastSeparator) + CacheStore.CACHE_KEY_SEPARATOR + Constants.OPATCH_PATCH_TYPE;
118+
}
112119
cacheStore.addToCache(key, location.toAbsolutePath().toString());
113120
String msg = String.format("Added Patch entry %s=%s for %s", key, location.toAbsolutePath(), type);
114121
logger.info(msg);

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
ListCacheItems.class,
2525
AddInstallerEntry.class,
2626
AddPatchEntry.class,
27-
GetCacheDir.class,
28-
SetCacheDir.class,
2927
AddEntry.class,
3028
DeleteEntry.class,
3129
HelpCommand.class

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public DeleteEntry(boolean isCLIMode) {
3131
public CommandResponse call() {
3232
if (!Utils.isEmptyString(key)) {
3333
if (Constants.CACHE_DIR_KEY.equals(key.toLowerCase())) {
34-
return new CommandResponse(-1, "Error: Cannot delete cache.dir entry. Use setCacheDir instead");
34+
return new CommandResponse(0, "Cannot delete key: " + key);
3535
} else if (Constants.DELETE_ALL_FOR_SURE.equalsIgnoreCase(key)) {
3636
Map<String, String> allEntries = cacheStore.getCacheItems();
3737
//allEntries.remove(CACHE_DIR_KEY);

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

Lines changed: 0 additions & 58 deletions
This file was deleted.

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ private List<String> handleInstallerFiles(Path tmpDir) throws Exception {
171171
List<String> handlePatchFiles(Path tmpDir, Path tmpPatchesDir) throws Exception {
172172
logger.finer("Entering CreateImage.handlePatchFiles: " + tmpDir.toAbsolutePath().toString());
173173
if ((latestPSU || !patches.isEmpty()) && Utils.compareVersions(installerVersion, Constants.DEFAULT_WLS_VERSION) == 0) {
174-
addOPatch1394ToImage(tmpDir);
174+
addOPatch1394ToImage(tmpDir, opatchBugNumber);
175175
}
176176
//we need a local installerVersion variable for the command line Option. so propagate to super.
177177
super.installerVersion = installerVersion;
@@ -396,7 +396,7 @@ private void copyResponseFilesToDir(String dirPath) throws IOException {
396396
private DomainType domainType;
397397

398398
@Option(
399-
names = "--run_rcu",
399+
names = "--wdtRunRCU",
400400
description = "whether to run rcu to create the required database schemas"
401401
)
402402
private boolean rcu_run_flag = false;
@@ -410,4 +410,12 @@ private void copyResponseFilesToDir(String dirPath) throws IOException {
410410
private Path wdtDomainHome;
411411

412412

413+
@Option(
414+
names = {"--opatchBugNumber"},
415+
description = "use this opatch patch bug number",
416+
defaultValue = "28186730"
417+
)
418+
private String opatchBugNumber;
419+
420+
413421
}

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,14 @@ void handleProxyUrls() throws IOException {
173173
Utils.setProxyIfRequired(httpProxyUrl, httpsProxyUrl, nonProxyHosts);
174174
}
175175

176-
void addOPatch1394ToImage(Path tmpDir) throws Exception {
177-
String filePath = new PatchFile(useCache, "opatch", "13.9.4.0.0", "28186730", userId, password).resolve(cacheStore);
176+
void addOPatch1394ToImage(Path tmpDir, String opatchBugNumber) throws Exception {
177+
// opatch patch now is in the format #####_opatch in the cache store
178+
// So the version passing to the constructor of PatchFile is also "opatch".
179+
// since opatch releases is on it's own and there is not really a patch to opatch
180+
// and the version is embedded in the zip file version.txt
181+
182+
String filePath =
183+
new PatchFile(useCache, Constants.OPATCH_PATCH_TYPE, Constants.OPATCH_PATCH_TYPE, opatchBugNumber, userId, password).resolve(cacheStore);
178184
Files.copy(Paths.get(filePath), Paths.get(tmpDir.toAbsolutePath().toString(), new File(filePath).getName()));
179185
filterStartTags.add("OPATCH_1394");
180186
if (this instanceof CreateImage) {

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

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@
1111
import com.oracle.weblogic.imagetool.util.Constants;
1212
import com.oracle.weblogic.imagetool.util.Utils;
1313
import com.oracle.weblogic.imagetool.util.ValidationResult;
14-
import picocli.CommandLine.Command;
15-
import picocli.CommandLine.Option;
1614

1715
import java.io.File;
16+
import java.io.IOException;
1817
import java.nio.file.Files;
1918
import java.nio.file.Path;
2019
import java.nio.file.Paths;
@@ -26,9 +25,11 @@
2625
import java.util.List;
2726
import java.util.Properties;
2827
import java.util.Set;
29-
import java.util.logging.FileHandler;
3028
import java.util.logging.Logger;
3129

30+
import picocli.CommandLine.Command;
31+
import picocli.CommandLine.Option;
32+
3233
@Command(
3334
name = "update",
3435
description = "Update WebLogic docker image with selected patches",
@@ -88,9 +89,29 @@ public CommandResponse call() throws Exception {
8889
installerVersion = baseImageProperties.getProperty("WLS_VERSION", Constants.DEFAULT_WLS_VERSION);
8990

9091
String opatchVersion = baseImageProperties.getProperty("OPATCH_VERSION");
92+
93+
// We need to find out the actual version number of the opatchBugNumber - what if useCache=always ?
94+
String opatchBugNumberVersion = "";
95+
96+
if (useCache == CachePolicy.ALWAYS) {
97+
String opatchFile = cacheStore.getValueFromCache(opatchBugNumber + "_opatch");
98+
if (opatchFile != null ) {
99+
opatchBugNumberVersion = Utils.getOpatchVersionFromZip(opatchFile);
100+
logger.info(String.format("OPatch patch number %s cached file %s version %s", opatchBugNumber,
101+
opatchFile, opatchBugNumberVersion ));
102+
} else {
103+
String msg = String.format("OPatch patch number --opatchBugNumber %s cannot be found in cache",
104+
opatchBugNumber);
105+
logger.severe(msg);
106+
throw new IOException(msg);
107+
}
108+
} else {
109+
opatchBugNumberVersion = ARUUtil.getOPatchVersionByBugNumber(opatchBugNumber, userId, password);
110+
}
111+
91112
opatch_1394_required = (latestPSU || !patches.isEmpty()) &&
92-
(Utils.compareVersions(installerVersion, Constants.DEFAULT_WLS_VERSION) >= 0 &&
93-
Utils.compareVersions(opatchVersion, "13.9.4.0.0") < 0);
113+
(Utils.compareVersions(installerVersion, Constants.DEFAULT_WLS_VERSION) >= 0 &&
114+
Utils.compareVersions(opatchVersion, opatchBugNumberVersion) < 0);
94115

95116
//Do not update or install packages in offline only mode
96117
if (useCache != CachePolicy.ALWAYS) {
@@ -164,7 +185,7 @@ public CommandResponse call() throws Exception {
164185
@Override
165186
List<String> handlePatchFiles(Path tmpDir, Path tmpPatchesDir) throws Exception {
166187
if (opatch_1394_required) {
167-
addOPatch1394ToImage(tmpDir);
188+
addOPatch1394ToImage(tmpDir, opatchBugNumber);
168189
}
169190
return super.handlePatchFiles(tmpDir, tmpPatchesDir);
170191
}
@@ -176,5 +197,12 @@ List<String> handlePatchFiles(Path tmpDir, Path tmpPatchesDir) throws Exception
176197
)
177198
private String fromImage;
178199

200+
@Option(
201+
names = {"--opatchBugNumber"},
202+
description = "use this opatch patch bug number",
203+
defaultValue = "28186730"
204+
)
205+
private String opatchBugNumber;
206+
179207
private boolean opatch_1394_required = false;
180208
}

imagetool/src/main/java/com/oracle/weblogic/imagetool/impl/meta/CacheStoreFactory.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ public class CacheStoreFactory implements Supplier<CacheStore> {
1818

1919
static {
2020
cashStoreMap.put(Constants.FILE_CACHE, FileCacheStore.CACHE_STORE);
21-
cashStoreMap.put(Constants.PREF_CACHE, PreferenceCacheStore.CACHE_STORE);
2221
}
2322

2423
public CacheStore getCacheStore(String backingType) {
@@ -27,13 +26,6 @@ public CacheStore getCacheStore(String backingType) {
2726

2827
@Override
2928
public CacheStore get() {
30-
String backingType = null;
31-
try {
32-
backingType = System.getenv(Constants.CACHE_STORE_TYPE);
33-
backingType = Utils.isEmptyString(backingType) ? System.getProperty(Constants.CACHE_STORE_TYPE, Constants.FILE_CACHE) : backingType;
34-
} catch (Exception e) {
35-
e.printStackTrace();
36-
}
37-
return getCacheStore(backingType);
29+
return FileCacheStore.CACHE_STORE;
3830
}
3931
}

imagetool/src/main/java/com/oracle/weblogic/imagetool/impl/meta/FileCacheStore.java

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,17 @@
66

77
import com.oracle.weblogic.imagetool.api.meta.CacheStore;
88
import com.oracle.weblogic.imagetool.util.Constants;
9+
import com.oracle.weblogic.imagetool.util.Utils;
910

1011
import java.io.BufferedReader;
1112
import java.io.File;
1213
import java.io.FileOutputStream;
1314
import java.io.FileReader;
1415
import java.io.IOException;
15-
import java.nio.file.Paths;
1616
import java.time.LocalDateTime;
1717
import java.util.Map;
1818
import java.util.Objects;
1919
import java.util.Properties;
20-
import java.util.prefs.BackingStoreException;
21-
import java.util.prefs.Preferences;
2220
import java.util.stream.Collectors;
2321
import java.util.stream.Stream;
2422

@@ -28,18 +26,11 @@ public enum FileCacheStore implements CacheStore {
2826

2927
private final Properties properties = new Properties();
3028
private String metadataPath;
31-
private final String DEFAULT_CACHE_DIR = Paths.get(System.getProperty("user.home"), "cache")
32-
.toAbsolutePath().toString();
33-
private final Preferences preferences = Preferences.userRoot().node(Constants.WEBLOGIC_IMAGETOOL);
3429

3530
FileCacheStore() {
3631
try {
37-
metadataPath = preferences.get(Constants.METADATA_PREF_KEY, null);
38-
if (metadataPath == null || metadataPath.isEmpty()) {
39-
metadataPath = String.format("%s%s%s", DEFAULT_CACHE_DIR, File.separator, Constants.DEFAULT_META_FILE);
40-
preferences.put(Constants.METADATA_PREF_KEY, metadataPath);
41-
preferences.flush();
42-
}
32+
String userCacheDir = Utils.getCacheDir();
33+
metadataPath = String.format("%s%s%s", userCacheDir, File.separator, Constants.DEFAULT_META_FILE);
4334
File metadataFile = new File(metadataPath);
4435
if (metadataFile.exists() && metadataFile.isFile()) {
4536
loadProperties(metadataFile);
@@ -48,7 +39,7 @@ public enum FileCacheStore implements CacheStore {
4839
metadataFile.createNewFile();
4940
}
5041
if (properties.getProperty(Constants.CACHE_DIR_KEY) == null) {
51-
properties.put(Constants.CACHE_DIR_KEY, DEFAULT_CACHE_DIR);
42+
properties.put(Constants.CACHE_DIR_KEY, userCacheDir);
5243
persistToDisk();
5344
}
5445
File cacheDir = new File(properties.getProperty(Constants.CACHE_DIR_KEY));
@@ -63,7 +54,7 @@ public enum FileCacheStore implements CacheStore {
6354

6455
@Override
6556
public String getCacheDir() {
66-
return properties.getProperty(Constants.CACHE_DIR_KEY, DEFAULT_CACHE_DIR);
57+
return properties.getProperty(Constants.CACHE_DIR_KEY);
6758
}
6859

6960
@Override
@@ -138,26 +129,5 @@ private void loadProperties(File propsFile) {
138129
}
139130
}
140131

141-
public boolean setCacheDir(String cacheDirPath) {
142-
if (cacheDirPath != null) {
143-
properties.put(Constants.CACHE_DIR_KEY, cacheDirPath);
144-
try {
145-
metadataPath = getCacheDir() + File.separator + Constants.DEFAULT_META_FILE;
146-
File metaDataFile = new File(metadataPath);
147-
if (metaDataFile.exists() && metaDataFile.isFile()) {
148-
loadProperties(metaDataFile);
149-
} else {
150-
metaDataFile.getParentFile().mkdirs();
151-
metaDataFile.createNewFile();
152-
}
153-
preferences.put(Constants.METADATA_PREF_KEY, metadataPath);
154-
preferences.flush();
155-
return persistToDisk();
156-
} catch (BackingStoreException | IOException e) {
157-
e.printStackTrace();
158-
}
159-
}
160-
return false;
161-
}
162132

163133
}

0 commit comments

Comments
 (0)